fix: drives
This commit is contained in:
1 parent
0d79b1f706
commit
b74f7cd3d9
11 files changed
+598
-16
No files matched your search
@@ -0,0 +1,79 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const READ_TOOLS = ['list-dir', 'read-file', 'find-files', 'search-files'];
|
||||
const WRITE_TOOLS = ['write-file', 'update-file', 'multi-edit'];
|
||||
|
||||
const parentSystem = `You must execute the given task to completion.
|
||||
You don't revise, you don't ideate. You execute and build. All the information has already been gathered and evaluted before presenting it to you, you go straight to the code and update exactly as instructed.
|
||||
If the goal involves a complex plan, split it into independent parts and use the \`delegate\` tool to give each part to a fresh subagent, saving your own context.
|
||||
Do not delegate trivial single-step work; do it yourself. Work iteratively until the task is fully implemented.
|
||||
CONSTRAINTS:
|
||||
- Prefer reading only files present in the prompt.
|
||||
- Do not test anything beyond syntax nor run any command.
|
||||
- Extrapolating requirements or inferring updates is FORBIDDEN. If insufficient context, terminate.
|
||||
`;
|
||||
|
||||
const childSystem = `Your goal is to execute the specific instruction you were given.
|
||||
Your task was asigned autonomously by a coordinator. Focus only on your assigned part.
|
||||
Note: task is terminated after 20 turns, reasoning traces are not persisted after agent turns.
|
||||
CONSTRAINTS:
|
||||
- You must ONLY read files mentioned in your instruction, and only explore to find them.
|
||||
`;
|
||||
|
||||
function resolveInstruction (input) {
|
||||
if (input.prompt) return input.prompt;
|
||||
|
||||
const candidates = ['prompt.md', 'prompt.txt', 'prompt', 'plan.md', 'report.md'];
|
||||
for (const name of candidates) {
|
||||
const file = path.resolve(Gral.path, '.gral', name);
|
||||
if (fs.existsSync(file)) {
|
||||
console.log("Prompt read from: " + name);
|
||||
return fs.readFileSync(file, 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("Instruction required.");
|
||||
}
|
||||
|
||||
// Delegate tool: spawn a subagent with the same permissions, but no delegate tool.
|
||||
const delegate = {
|
||||
name: 'delegate',
|
||||
description: 'Spawn a subagent to execute a specific part of the plan. Use it to split complex plans into parts and save context. The subagent has the same file permissions but cannot delegate further.',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
prompt: { type: 'string', description: 'The specific instruction the subagent must execute.' },
|
||||
},
|
||||
required: ['prompt'],
|
||||
},
|
||||
handler: async (args) => {
|
||||
const res = await Gral.run({
|
||||
instruction: childSystem,
|
||||
messages: [{ role: 'user', content: args.prompt }],
|
||||
agentId: 7,
|
||||
read: true,
|
||||
write: true,
|
||||
defaultTools: [...READ_TOOLS, ...WRITE_TOOLS],
|
||||
// no `delegate` tool: the subagent cannot delegate further
|
||||
});
|
||||
return res;
|
||||
},
|
||||
};
|
||||
|
||||
export default async function build (input) {
|
||||
const instruction = resolveInstruction(input);
|
||||
|
||||
let res = await Gral.run({
|
||||
instruction: parentSystem,
|
||||
messages: [{ role: 'user', content: instruction }],
|
||||
agentId: 7,
|
||||
read: true,
|
||||
write: true,
|
||||
defaultTools: [...READ_TOOLS, ...WRITE_TOOLS],
|
||||
tools: [delegate],
|
||||
maxIter: 64,
|
||||
});
|
||||
|
||||
console.log(res);
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const system = `The user is probably asking for either information, a review, or general suggestions.
|
||||
You can only read files, you're forbidden from writing any file, only respond to the user after light research.
|
||||
Only read up to 10 files. If more context is needed, submit your response regardless with all the information available. Your maximum iteration count is 20, you should NEVER reach it, ideally stay under 5 iterations.
|
||||
`;
|
||||
|
||||
function resolvePrompt (input) {
|
||||
if (input.prompt) return input.prompt;
|
||||
|
||||
const candidates = ['prompt.md', 'prompt.txt', 'prompt'];
|
||||
for (const name of candidates) {
|
||||
const file = path.resolve(Gral.path, '.gral', name);
|
||||
if (fs.existsSync(file)) {
|
||||
return fs.readFileSync(file, 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("Prompt required.");
|
||||
}
|
||||
|
||||
export default async function research (input) {
|
||||
const prompt = resolvePrompt(input);
|
||||
|
||||
let res = await Gral.run({
|
||||
instruction: system,
|
||||
// input gets bumped to the front of the convo every turn
|
||||
// pass as message instead
|
||||
messages: [{role: "user", content: prompt}],
|
||||
agentId: 7,
|
||||
read: true,
|
||||
write: [],
|
||||
defaultTools: ['list-dir', 'read-file', 'find-files', 'search-files'],
|
||||
});
|
||||
|
||||
console.log(res);
|
||||
};
|
||||
@@ -0,0 +1,62 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const system = `Your goal is to write a research report based on the given prompt.
|
||||
Use the \`submit-report\` function when you have gathered all information.
|
||||
You can only read from \`docs\` and from the source code directories \`backend/src\` and \`frontend/src\`. Exploration in any other location is forbidden.
|
||||
Only read up to 10 files. If more context is needed, submit the report regardless with all the information available. This is the breakpoint to work iteratively wit hthe user
|
||||
Note: task is terminated after 20 turns, reasoning traces are not persisted after agent turns.
|
||||
`;
|
||||
|
||||
function resolvePrompt (input) {
|
||||
if (input.prompt) return input.prompt;
|
||||
|
||||
const candidates = ['prompt.md', 'prompt.txt', 'prompt'];
|
||||
for (const name of candidates) {
|
||||
const file = path.resolve(Gral.path, '.gral', name);
|
||||
if (fs.existsSync(file)) {
|
||||
return fs.readFileSync(file, 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("Prompt required.");
|
||||
}
|
||||
|
||||
function writeReport(content) {
|
||||
fs.writeFileSync(path.resolve(Gral.path, '.gral/report.md'), content);
|
||||
}
|
||||
|
||||
export default async function research (input) {
|
||||
const prompt = resolvePrompt(input);
|
||||
|
||||
let done = false;
|
||||
|
||||
let res = await Gral.run({
|
||||
instruction: system,
|
||||
input: prompt,
|
||||
agentId: 7,
|
||||
tools: [{
|
||||
name: 'submit-report',
|
||||
description: 'Submit a markdown report as your task deliverable.',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
content: { type: 'string' },
|
||||
},
|
||||
required: ['content'],
|
||||
},
|
||||
handler: (args) => {
|
||||
done = true;
|
||||
writeReport(args.content);
|
||||
}
|
||||
}],
|
||||
read: ['docs', 'frontend/src', 'backend/src'],
|
||||
write: [],
|
||||
defaultTools: ['list-dir', 'read-file', 'find-files', 'search-files'],
|
||||
|
||||
maxIter: 99,
|
||||
verify: () => done,
|
||||
});
|
||||
|
||||
console.log(res);
|
||||
};
|
||||
Reference in new issue
Block a user