@a5c-ai/babysitter-sdk 0.0.184-staging.b13bcbcb → 0.0.184-staging.f2d9bb68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/harnessCreateRun.d.ts.map +1 -1
- package/dist/cli/commands/harnessCreateRun.js +2 -4
- package/dist/cli/commands/harnessPhase1.d.ts +4 -2
- package/dist/cli/commands/harnessPhase1.d.ts.map +1 -1
- package/dist/cli/commands/harnessPhase1.js +105 -55
- package/dist/cli/commands/harnessPhase2.d.ts +6 -0
- package/dist/cli/commands/harnessPhase2.d.ts.map +1 -1
- package/dist/cli/commands/harnessPhase2.js +987 -870
- package/dist/cli/commands/harnessPrompts.d.ts +2 -2
- package/dist/cli/commands/harnessPrompts.d.ts.map +1 -1
- package/dist/cli/commands/harnessPrompts.js +9 -4
- package/dist/cli/commands/harnessResumeRun.js +1 -1
- package/dist/cli/commands/harnessUtils.d.ts +12 -1
- package/dist/cli/commands/harnessUtils.d.ts.map +1 -1
- package/dist/cli/commands/harnessUtils.js +51 -17
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +48 -88
- package/dist/harness/claudeCode.d.ts.map +1 -1
- package/dist/harness/claudeCode.js +29 -7
- package/dist/harness/discovery.d.ts.map +1 -1
- package/dist/harness/discovery.js +12 -1
- package/dist/harness/index.d.ts +1 -0
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +3 -1
- package/dist/harness/internal.d.ts +13 -0
- package/dist/harness/internal.d.ts.map +1 -0
- package/dist/harness/internal.js +151 -0
- package/dist/harness/pi.d.ts.map +1 -1
- package/dist/harness/pi.js +8 -2
- package/dist/harness/piWrapper.d.ts +1 -0
- package/dist/harness/piWrapper.d.ts.map +1 -1
- package/dist/harness/piWrapper.js +69 -2
- package/dist/harness/registry.d.ts.map +1 -1
- package/dist/harness/registry.js +2 -0
- package/dist/interaction/askUserQuestion.d.ts +1 -0
- package/dist/interaction/askUserQuestion.d.ts.map +1 -1
- package/dist/interaction/askUserQuestion.js +103 -93
- package/dist/prompts/commandTemplates.d.ts +4 -0
- package/dist/prompts/commandTemplates.d.ts.map +1 -0
- package/dist/prompts/commandTemplates.js +32 -0
- package/dist/prompts/index.d.ts +1 -0
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +4 -1
- package/dist/prompts/templates/commands/assimilate.md +47 -0
- package/dist/prompts/templates/commands/cleanup.md +32 -0
- package/dist/prompts/templates/commands/contrib.md +40 -0
- package/dist/prompts/templates/commands/doctor.md +426 -0
- package/dist/prompts/templates/commands/forever.md +11 -0
- package/dist/prompts/templates/commands/project-install.md +25 -0
- package/dist/prompts/templates/commands/retrospect.md +68 -0
- package/dist/prompts/templates/commands/user-install.md +24 -0
- package/dist/prompts/templates/effects.md +3 -0
- package/dist/prompts/templates/process-creation.md +1 -1
- package/dist/prompts/templates/task-examples.md +4 -0
- package/dist/runtime/createRun.d.ts.map +1 -1
- package/dist/runtime/createRun.js +4 -0
- package/dist/runtime/types.d.ts +1 -0
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/storage/createRunDir.d.ts.map +1 -1
- package/dist/storage/createRunDir.js +1 -0
- package/dist/storage/journal.d.ts.map +1 -1
- package/dist/storage/journal.js +21 -1
- package/dist/storage/types.d.ts +2 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/package.json +4 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harnessCreateRun.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/harnessCreateRun.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,KAAK,oBAAoB,EAY1B,MAAM,gBAAgB,CAAC;AAMxB,YAAY,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,mDAAmD;AACnD,YAAY,EAAE,oBAAoB,IAAI,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAIxD,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"harnessCreateRun.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/harnessCreateRun.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,KAAK,oBAAoB,EAY1B,MAAM,gBAAgB,CAAC;AAMxB,YAAY,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,mDAAmD;AACnD,YAAY,EAAE,oBAAoB,IAAI,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAIxD,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,MAAM,CAAC,CAoGjB;AAED,qDAAqD;AACrD,eAAO,MAAM,mBAAmB,+BAAyB,CAAC"}
|
|
@@ -50,9 +50,7 @@ async function handleHarnessCreateRun(parsed) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
const discovered = await (0, harnessUtils_1.discoverHarnesses)();
|
|
53
|
-
const selectedHarnessName = preferredHarness
|
|
54
|
-
? "oh-my-pi"
|
|
55
|
-
: "pi";
|
|
53
|
+
const selectedHarnessName = preferredHarness ?? "internal";
|
|
56
54
|
const compressionConfig = (0, harnessUtils_1.loadSessionCompressionConfig)(workspace);
|
|
57
55
|
const promptContext = (0, harnessUtils_1.buildPromptContext)({
|
|
58
56
|
workspace,
|
|
@@ -68,7 +66,7 @@ async function handleHarnessCreateRun(parsed) {
|
|
|
68
66
|
const workDir = workspace ?? process.cwd();
|
|
69
67
|
processPath = await (0, harnessPhase1_1.runProcessDefinitionPhase)({
|
|
70
68
|
prompt: prompt,
|
|
71
|
-
|
|
69
|
+
outputDir: (0, harnessPhase1_1.getProcessOutputDir)(workDir),
|
|
72
70
|
workspace: workDir,
|
|
73
71
|
model,
|
|
74
72
|
interactive,
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import * as readline from "node:readline";
|
|
8
8
|
import { type ExternalWorkspaceAssessment, type CompressionConfig, type HarnessPromptContext as SessionCreatePromptContext } from "./harnessUtils";
|
|
9
|
+
export declare function getProcessOutputDir(workDir: string): string;
|
|
10
|
+
/** @deprecated Use getProcessOutputDir instead */
|
|
9
11
|
export declare function getGeneratedProcessPath(workDir: string): string;
|
|
10
12
|
export declare function execShellEffect(command: string, args: string[], cwd?: string): Promise<{
|
|
11
13
|
stdout: string;
|
|
@@ -18,7 +20,7 @@ export declare function extractJsonObjectFromText(text: string): string | null;
|
|
|
18
20
|
export declare function coerceAgentResultValue(taskDef: Record<string, unknown>, output: string): unknown;
|
|
19
21
|
export declare function buildExternalProcessDefinitionPrompt(args: {
|
|
20
22
|
prompt: string;
|
|
21
|
-
|
|
23
|
+
outputDir: string;
|
|
22
24
|
workspace?: string;
|
|
23
25
|
promptContext: SessionCreatePromptContext;
|
|
24
26
|
workspaceAssessment: ExternalWorkspaceAssessment;
|
|
@@ -29,7 +31,7 @@ export declare function buildExternalProcessConformancePrompt(args: {
|
|
|
29
31
|
}): string;
|
|
30
32
|
export declare function runProcessDefinitionPhase(args: {
|
|
31
33
|
prompt: string;
|
|
32
|
-
|
|
34
|
+
outputDir: string;
|
|
33
35
|
workspace?: string;
|
|
34
36
|
model?: string;
|
|
35
37
|
interactive: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harnessPhase1.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/harnessPhase1.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAa1C,OAAO,EAIL,KAAK,2BAA2B,EAEhC,KAAK,iBAAiB,EAGtB,KAAK,oBAAoB,IAAI,0BAA0B,
|
|
1
|
+
{"version":3,"file":"harnessPhase1.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/harnessPhase1.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAa1C,OAAO,EAIL,KAAK,2BAA2B,EAEhC,KAAK,iBAAiB,EAGtB,KAAK,oBAAoB,IAAI,0BAA0B,EAyBxD,MAAM,gBAAgB,CAAC;AAkBxB,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,kDAAkD;AAClD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/D;AA0HD,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAyB/D;AA85BD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAmDzE;AAED,wBAAgB,sCAAsC,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,CAU/F;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgBrE;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAwBhG;AAiHD,wBAAgB,oCAAoC,CAAC,IAAI,EAAE;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,0BAA0B,CAAC;IAC1C,mBAAmB,EAAE,2BAA2B,CAAC;CAClD,GAAG,MAAM,CA+ET;AAED,wBAAgB,qCAAqC,CAAC,IAAI,EAAE;IAC1D,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,MAAM,CA4BT;AAmND,wBAAsB,yBAAyB,CAAC,IAAI,EAAE;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,EAAE,EAAE,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC5C,aAAa,EAAE,0BAA0B,CAAC;IAC1C,mBAAmB,EAAE,MAAM,CAAC;CAC7B,GAAG,OAAO,CAAC,MAAM,CAAC,CAmjBlB"}
|
|
@@ -39,6 +39,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
39
39
|
};
|
|
40
40
|
})();
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.getProcessOutputDir = getProcessOutputDir;
|
|
42
43
|
exports.getGeneratedProcessPath = getGeneratedProcessPath;
|
|
43
44
|
exports.execShellEffect = execShellEffect;
|
|
44
45
|
exports.buildAgentPrompt = buildAgentPrompt;
|
|
@@ -70,8 +71,12 @@ const dynamicImportModule = (() => {
|
|
|
70
71
|
return new Function("specifier", "return import(specifier);");
|
|
71
72
|
})();
|
|
72
73
|
// ── Process File Utilities ───────────────────────────────────────────
|
|
74
|
+
function getProcessOutputDir(workDir) {
|
|
75
|
+
return path.join(workDir, ".a5c", "processes");
|
|
76
|
+
}
|
|
77
|
+
/** @deprecated Use getProcessOutputDir instead */
|
|
73
78
|
function getGeneratedProcessPath(workDir) {
|
|
74
|
-
return
|
|
79
|
+
return getProcessOutputDir(workDir);
|
|
75
80
|
}
|
|
76
81
|
function looksLikeProcessDefinitionSource(source) {
|
|
77
82
|
const normalized = source.trim();
|
|
@@ -111,6 +116,7 @@ function extractMentionedProcessPaths(text, workspace) {
|
|
|
111
116
|
/([A-Za-z]:[\\/][^\r\n"'`]+?\.m?js)\b/g,
|
|
112
117
|
/((?:\.{0,2}[\\/]|\/)[^\r\n"'`]+?\.m?js)\b/g,
|
|
113
118
|
/\b([A-Za-z0-9_.\-\\/]+generated-process\.m?js)\b/g,
|
|
119
|
+
/\b(\.a5c[\\/]processes[\\/][A-Za-z0-9_.-]+\.m?js)\b/g,
|
|
114
120
|
];
|
|
115
121
|
const matches = new Set();
|
|
116
122
|
for (const pattern of patterns) {
|
|
@@ -1029,16 +1035,21 @@ function coerceAgentResultValue(taskDef, output) {
|
|
|
1029
1035
|
}
|
|
1030
1036
|
// ── Process Recovery ─────────────────────────────────────────────────
|
|
1031
1037
|
async function recoverProcessDefinitionFromOutputs(args) {
|
|
1032
|
-
const
|
|
1038
|
+
const resolvedDir = path.resolve(args.outputDir);
|
|
1039
|
+
// Check if any .js/.mjs files already exist in the output directory
|
|
1033
1040
|
try {
|
|
1034
|
-
await
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1041
|
+
const entries = await node_fs_1.promises.readdir(resolvedDir);
|
|
1042
|
+
const processFiles = entries.filter((e) => /\.m?js$/.test(e));
|
|
1043
|
+
if (processFiles.length > 0) {
|
|
1044
|
+
const candidatePath = path.join(resolvedDir, processFiles[0]);
|
|
1045
|
+
return {
|
|
1046
|
+
processPath: candidatePath,
|
|
1047
|
+
summary: "Recovered from missing process-definition tool report by scanning the output directory.",
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1039
1050
|
}
|
|
1040
1051
|
catch {
|
|
1041
|
-
//
|
|
1052
|
+
// directory may not exist yet
|
|
1042
1053
|
}
|
|
1043
1054
|
for (const output of args.outputs) {
|
|
1044
1055
|
for (const candidatePath of extractMentionedProcessPaths(output, args.workspace)) {
|
|
@@ -1059,10 +1070,12 @@ async function recoverProcessDefinitionFromOutputs(args) {
|
|
|
1059
1070
|
if (!extracted || !looksLikeProcessDefinitionSource(extracted)) {
|
|
1060
1071
|
continue;
|
|
1061
1072
|
}
|
|
1062
|
-
|
|
1063
|
-
|
|
1073
|
+
const recoveredName = `recovered-process-${Date.now()}.mjs`;
|
|
1074
|
+
const recoveredPath = path.join(resolvedDir, recoveredName);
|
|
1075
|
+
await node_fs_1.promises.mkdir(resolvedDir, { recursive: true });
|
|
1076
|
+
await node_fs_1.promises.writeFile(recoveredPath, extracted, "utf8");
|
|
1064
1077
|
return {
|
|
1065
|
-
processPath:
|
|
1078
|
+
processPath: recoveredPath,
|
|
1066
1079
|
summary: "Recovered process-definition output by writing a JavaScript code block returned by the agent.",
|
|
1067
1080
|
};
|
|
1068
1081
|
}
|
|
@@ -1070,10 +1083,12 @@ async function recoverProcessDefinitionFromOutputs(args) {
|
|
|
1070
1083
|
if (!looksLikeProcessDefinitionSource(output)) {
|
|
1071
1084
|
continue;
|
|
1072
1085
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1086
|
+
const recoveredName = `recovered-process-${Date.now()}.mjs`;
|
|
1087
|
+
const recoveredPath = path.join(resolvedDir, recoveredName);
|
|
1088
|
+
await node_fs_1.promises.mkdir(resolvedDir, { recursive: true });
|
|
1089
|
+
await node_fs_1.promises.writeFile(recoveredPath, output.trim(), "utf8");
|
|
1075
1090
|
return {
|
|
1076
|
-
processPath:
|
|
1091
|
+
processPath: recoveredPath,
|
|
1077
1092
|
summary: "Recovered process-definition output by writing the agent's direct JavaScript response.",
|
|
1078
1093
|
};
|
|
1079
1094
|
}
|
|
@@ -1092,7 +1107,7 @@ async function recoverReportedProcessDefinition(args) {
|
|
|
1092
1107
|
return args.state.report;
|
|
1093
1108
|
}
|
|
1094
1109
|
const recovered = await recoverProcessDefinitionFromOutputs({
|
|
1095
|
-
|
|
1110
|
+
outputDir: args.outputDir,
|
|
1096
1111
|
workspace: args.workspace,
|
|
1097
1112
|
outputs: args.outputs,
|
|
1098
1113
|
});
|
|
@@ -1135,7 +1150,7 @@ function buildExternalProcessDefinitionPrompt(args) {
|
|
|
1135
1150
|
"Task:",
|
|
1136
1151
|
`- User request: ${args.prompt}`,
|
|
1137
1152
|
`- Workspace: ${workspace}`,
|
|
1138
|
-
`-
|
|
1153
|
+
`- Process output directory: ${path.resolve(args.outputDir)}`,
|
|
1139
1154
|
`- Workspace assessment: ${args.workspaceAssessment.kind} (${workspaceSummary})`,
|
|
1140
1155
|
"",
|
|
1141
1156
|
"Requirements:",
|
|
@@ -1171,7 +1186,7 @@ function buildExternalProcessDefinitionPrompt(args) {
|
|
|
1171
1186
|
"- External harnesses do not provide PI sandbox guardrails for their own tool execution. Keep security-sensitive shell work on the internal PI worker by using shell effects without routing them to an external harness.",
|
|
1172
1187
|
"",
|
|
1173
1188
|
"Output rules:",
|
|
1174
|
-
"-
|
|
1189
|
+
`- Choose a descriptive kebab-case filename (e.g. "user-auth-tdd.mjs", "data-pipeline-setup.js") and write the file to the process output directory.`,
|
|
1175
1190
|
"- Return a short summary that confirms what you wrote and the final path.",
|
|
1176
1191
|
"- Do not rely on AskUserQuestion or babysitter_report_process_definition. Those tools are not available here.",
|
|
1177
1192
|
"- Do not return pseudocode, placeholders, or a plan without writing the file.",
|
|
@@ -1241,7 +1256,7 @@ function buildInternalProcessConformancePrompt(args) {
|
|
|
1241
1256
|
"- Shell tasks must use `kind: \"shell\"` with `shell: { command: \"...\" }`.",
|
|
1242
1257
|
"- Do not introduce `kind: \"node\"` task definitions in generated or repaired processes. If logic would have been a node task, convert it to an `agent` or `skill` task instead.",
|
|
1243
1258
|
"- The exported `process(inputs, ctx)` function must call tasks with `await ctx.task(definedTask, args)`.",
|
|
1244
|
-
"- Use `babysitter_write_process_definition` to rewrite the
|
|
1259
|
+
"- Use `babysitter_write_process_definition` with the `filename` parameter to rewrite the process file in the output directory.",
|
|
1245
1260
|
"- After rewriting the file, call `babysitter_report_process_definition` exactly once with the same path.",
|
|
1246
1261
|
"- Do not answer with plain text only.",
|
|
1247
1262
|
].join("\n");
|
|
@@ -1275,7 +1290,7 @@ async function _runExternalProcessDefinitionPhase(args) {
|
|
|
1275
1290
|
(0, harnessUtils_1.writeVerboseBlock)(args.verbose, args.json, label, value, maxChars);
|
|
1276
1291
|
};
|
|
1277
1292
|
(0, harnessUtils_1.emitProgress)({ phase: "1", status: "started", harness: `${args.selectedHarnessName} (headless)` }, args.json, args.verbose);
|
|
1278
|
-
writeVerbose(`[phase1 setup] workspace=${path.resolve(args.workspace ?? process.cwd())} model=${args.model ?? "(default)"}
|
|
1293
|
+
writeVerbose(`[phase1 setup] workspace=${path.resolve(args.workspace ?? process.cwd())} model=${args.model ?? "(default)"} outputDir=${path.resolve(args.outputDir)} harness=${args.selectedHarnessName}`);
|
|
1279
1294
|
const workspaceAssessment = await assessWorkspaceForExternalAuthoring(args.workspace);
|
|
1280
1295
|
writeVerboseData("phase1 workspace assessment", workspaceAssessment);
|
|
1281
1296
|
const invokeProcessAuthor = async (label, prompt, timeout) => {
|
|
@@ -1295,13 +1310,13 @@ async function _runExternalProcessDefinitionPhase(args) {
|
|
|
1295
1310
|
};
|
|
1296
1311
|
await invokeProcessAuthor("phase1 initial", buildExternalProcessDefinitionPrompt({
|
|
1297
1312
|
prompt: args.prompt,
|
|
1298
|
-
|
|
1313
|
+
outputDir: args.outputDir,
|
|
1299
1314
|
workspace: args.workspace,
|
|
1300
1315
|
promptContext: args.promptContext,
|
|
1301
1316
|
workspaceAssessment,
|
|
1302
1317
|
}), 900_000);
|
|
1303
1318
|
let report = await recoverProcessDefinitionFromOutputs({
|
|
1304
|
-
|
|
1319
|
+
outputDir: args.outputDir,
|
|
1305
1320
|
workspace: args.workspace,
|
|
1306
1321
|
outputs: phaseOutputs,
|
|
1307
1322
|
});
|
|
@@ -1310,12 +1325,13 @@ async function _runExternalProcessDefinitionPhase(args) {
|
|
|
1310
1325
|
}
|
|
1311
1326
|
if (!report) {
|
|
1312
1327
|
await invokeProcessAuthor("phase1 recovery", [
|
|
1313
|
-
`Write the full process file now to ${args.
|
|
1328
|
+
`Write the full process file now to the output directory ${args.outputDir}.`,
|
|
1329
|
+
"Choose a descriptive kebab-case filename (e.g. recovered-process.mjs).",
|
|
1314
1330
|
"Do not describe the plan only; materialize the file in the workspace.",
|
|
1315
1331
|
"After writing it, return either a concise summary or the full file in a ```javascript fenced block.",
|
|
1316
1332
|
].join("\n"), 300_000);
|
|
1317
1333
|
report = await recoverProcessDefinitionFromOutputs({
|
|
1318
|
-
|
|
1334
|
+
outputDir: args.outputDir,
|
|
1319
1335
|
workspace: args.workspace,
|
|
1320
1336
|
outputs: phaseOutputs,
|
|
1321
1337
|
});
|
|
@@ -1325,12 +1341,12 @@ async function _runExternalProcessDefinitionPhase(args) {
|
|
|
1325
1341
|
}
|
|
1326
1342
|
if (!report) {
|
|
1327
1343
|
await invokeProcessAuthor("phase1 final recovery", [
|
|
1328
|
-
`Final recovery step: write the complete JavaScript process file to ${args.
|
|
1344
|
+
`Final recovery step: write the complete JavaScript process file to the output directory ${args.outputDir}.`,
|
|
1329
1345
|
"Return the full file in a ```javascript fenced block after it exists on disk.",
|
|
1330
1346
|
"Do not omit the file write.",
|
|
1331
1347
|
].join("\n"), 300_000);
|
|
1332
1348
|
report = await recoverProcessDefinitionFromOutputs({
|
|
1333
|
-
|
|
1349
|
+
outputDir: args.outputDir,
|
|
1334
1350
|
workspace: args.workspace,
|
|
1335
1351
|
outputs: phaseOutputs,
|
|
1336
1352
|
});
|
|
@@ -1376,27 +1392,29 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1376
1392
|
{
|
|
1377
1393
|
name: "babysitter_write_process_definition",
|
|
1378
1394
|
label: "Write Process Definition",
|
|
1379
|
-
description: "Write the final JavaScript process file to the
|
|
1395
|
+
description: "Write the final JavaScript process file to the process output directory with a descriptive filename.",
|
|
1380
1396
|
parameters: typebox_1.Type.Object({
|
|
1381
1397
|
source: typebox_1.Type.String(),
|
|
1382
|
-
|
|
1398
|
+
filename: typebox_1.Type.String(),
|
|
1383
1399
|
}),
|
|
1384
1400
|
execute: async (_toolCallId, params) => {
|
|
1385
|
-
const
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
if (
|
|
1390
|
-
throw new harnessUtils_1.BabysitterRuntimeError("
|
|
1401
|
+
const filename = params.filename;
|
|
1402
|
+
if (!/\.m?js$/.test(filename)) {
|
|
1403
|
+
throw new harnessUtils_1.BabysitterRuntimeError("ProcessDefinitionInvalidFilename", `Filename must end in .js or .mjs, got: ${filename}`, { category: harnessUtils_1.ErrorCategory.Validation });
|
|
1404
|
+
}
|
|
1405
|
+
if (/[/\\]/.test(filename) || filename.includes("..")) {
|
|
1406
|
+
throw new harnessUtils_1.BabysitterRuntimeError("ProcessDefinitionInvalidFilename", `Filename must be a simple name without path separators or '..', got: ${filename}`, { category: harnessUtils_1.ErrorCategory.Validation });
|
|
1391
1407
|
}
|
|
1408
|
+
const resolvedDir = path.resolve(args.outputDir);
|
|
1409
|
+
const resolvedPath = path.join(resolvedDir, filename);
|
|
1392
1410
|
const normalizedSource = normalizeProcessDefinitionSource(params.source);
|
|
1393
1411
|
writeVerboseData("phase1 tool babysitter_write_process_definition", {
|
|
1394
|
-
processPath:
|
|
1412
|
+
processPath: resolvedPath,
|
|
1395
1413
|
sourcePreview: (0, harnessUtils_1.truncateForVerboseLog)(normalizedSource, 600),
|
|
1396
1414
|
});
|
|
1397
|
-
await node_fs_1.promises.mkdir(
|
|
1398
|
-
await node_fs_1.promises.writeFile(
|
|
1399
|
-
return (0, harnessUtils_1.formatToolResult)({ processPath:
|
|
1415
|
+
await node_fs_1.promises.mkdir(resolvedDir, { recursive: true });
|
|
1416
|
+
await node_fs_1.promises.writeFile(resolvedPath, normalizedSource, "utf8");
|
|
1417
|
+
return (0, harnessUtils_1.formatToolResult)({ processPath: resolvedPath }, "Process definition written.");
|
|
1400
1418
|
},
|
|
1401
1419
|
},
|
|
1402
1420
|
{
|
|
@@ -1504,16 +1522,16 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1504
1522
|
},
|
|
1505
1523
|
});
|
|
1506
1524
|
const mergedCustomTools = [...customTools, ...agenticTools];
|
|
1507
|
-
(0, harnessUtils_1.emitProgress)({ phase: "1", status: "started", harness: "
|
|
1508
|
-
writeVerbose(`[phase1 setup] workspace=${path.resolve(args.workspace ?? process.cwd())} model=${args.model ?? "(default)"}
|
|
1525
|
+
(0, harnessUtils_1.emitProgress)({ phase: "1", status: "started", harness: "internal (agentic)" }, args.json, args.verbose);
|
|
1526
|
+
writeVerbose(`[phase1 setup] workspace=${path.resolve(args.workspace ?? process.cwd())} model=${args.model ?? "(default)"} outputDir=${path.resolve(args.outputDir)}`);
|
|
1509
1527
|
writeVerboseData("phase1 tools", mergedCustomTools.map((tool) => ({
|
|
1510
1528
|
name: tool.name,
|
|
1511
1529
|
label: tool.label,
|
|
1512
1530
|
})));
|
|
1513
1531
|
const workspaceAssessment = await assessWorkspaceForExternalAuthoring(args.workspace);
|
|
1514
1532
|
writeVerboseData("phase1 workspace assessment", workspaceAssessment);
|
|
1515
|
-
const processDefinitionSystemPrompt = await (0, harnessPrompts_1.buildProcessDefinitionSystemPrompt)(args.
|
|
1516
|
-
const initialMetaPrompt = (0, harnessPrompts_1.buildProcessDefinitionUserPrompt)(args.prompt, args.
|
|
1533
|
+
const processDefinitionSystemPrompt = await (0, harnessPrompts_1.buildProcessDefinitionSystemPrompt)(args.outputDir, args.promptContext, args.interactive);
|
|
1534
|
+
const initialMetaPrompt = (0, harnessPrompts_1.buildProcessDefinitionUserPrompt)(args.prompt, args.outputDir, {
|
|
1517
1535
|
interactive: args.interactive,
|
|
1518
1536
|
workspaceAssessment: workspaceAssessment.kind,
|
|
1519
1537
|
workspaceEntries: workspaceAssessment.entries,
|
|
@@ -1522,7 +1540,7 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1522
1540
|
writeVerboseData("phase1 initial prompt", initialMetaPrompt);
|
|
1523
1541
|
const phase1ToolsMode = workspaceAssessment.kind === "empty"
|
|
1524
1542
|
? "default"
|
|
1525
|
-
: "
|
|
1543
|
+
: "coding";
|
|
1526
1544
|
session = (0, harnessUtils_1.createPiSession)({
|
|
1527
1545
|
workspace: args.workspace,
|
|
1528
1546
|
model: args.model,
|
|
@@ -1550,10 +1568,18 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1550
1568
|
const result = await (0, harnessUtils_1.promptPiWithRetry)({
|
|
1551
1569
|
session,
|
|
1552
1570
|
message: initialMetaPrompt,
|
|
1553
|
-
timeout:
|
|
1571
|
+
timeout: harnessUtils_1.PI_PARENT_PROMPT_TIMEOUT_MS,
|
|
1554
1572
|
label: "phase1 initial",
|
|
1555
1573
|
writeVerbose,
|
|
1556
1574
|
writeVerboseData,
|
|
1575
|
+
}).catch((err) => {
|
|
1576
|
+
const isTimeout = err instanceof harnessUtils_1.BabysitterRuntimeError &&
|
|
1577
|
+
(err.name === "PiTimeoutError" || (err.message ?? "").includes("timed out"));
|
|
1578
|
+
if (isTimeout) {
|
|
1579
|
+
writeVerbose("[phase1] Pi prompt timed out, converting to failure result");
|
|
1580
|
+
return { success: false, output: `Pi prompt timed out: ${err instanceof Error ? err.message : String(err)}` };
|
|
1581
|
+
}
|
|
1582
|
+
throw err;
|
|
1557
1583
|
});
|
|
1558
1584
|
phaseOutputs.push(result.output);
|
|
1559
1585
|
if (unsubscribe)
|
|
@@ -1564,7 +1590,7 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1564
1590
|
writeVerboseData("phase1 agent failure output", result.output);
|
|
1565
1591
|
const recovered = await recoverReportedProcessDefinition({
|
|
1566
1592
|
state,
|
|
1567
|
-
|
|
1593
|
+
outputDir: args.outputDir,
|
|
1568
1594
|
workspace: args.workspace,
|
|
1569
1595
|
outputs: phaseOutputs,
|
|
1570
1596
|
verbose: args.verbose,
|
|
@@ -1582,7 +1608,7 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1582
1608
|
writeVerboseProcessDefinitionRecovery(args.json);
|
|
1583
1609
|
const recoveryPrompt = [
|
|
1584
1610
|
"Recovery step:",
|
|
1585
|
-
`- Write the
|
|
1611
|
+
`- Write the process file now to the output directory ${args.outputDir} using babysitter_write_process_definition with a descriptive filename.`,
|
|
1586
1612
|
"- Then call babysitter_report_process_definition exactly once.",
|
|
1587
1613
|
"- Do not just describe the process in plain text.",
|
|
1588
1614
|
].join("\n");
|
|
@@ -1590,17 +1616,25 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1590
1616
|
const recovery = await (0, harnessUtils_1.promptPiWithRetry)({
|
|
1591
1617
|
session,
|
|
1592
1618
|
message: recoveryPrompt,
|
|
1593
|
-
timeout:
|
|
1619
|
+
timeout: harnessUtils_1.PI_PARENT_PROMPT_TIMEOUT_MS,
|
|
1594
1620
|
label: "phase1 recovery",
|
|
1595
1621
|
writeVerbose,
|
|
1596
1622
|
writeVerboseData,
|
|
1623
|
+
}).catch((err) => {
|
|
1624
|
+
const isTimeout = err instanceof harnessUtils_1.BabysitterRuntimeError &&
|
|
1625
|
+
(err.name === "PiTimeoutError" || (err.message ?? "").includes("timed out"));
|
|
1626
|
+
if (isTimeout) {
|
|
1627
|
+
writeVerbose("[phase1 recovery] Pi prompt timed out, converting to failure result");
|
|
1628
|
+
return { success: false, output: `Pi prompt timed out: ${err instanceof Error ? err.message : String(err)}` };
|
|
1629
|
+
}
|
|
1630
|
+
throw err;
|
|
1597
1631
|
});
|
|
1598
1632
|
phaseOutputs.push(recovery.output);
|
|
1599
1633
|
if (!recovery.success) {
|
|
1600
1634
|
writeVerboseData("phase1 recovery failure output", recovery.output);
|
|
1601
1635
|
const recovered = await recoverReportedProcessDefinition({
|
|
1602
1636
|
state,
|
|
1603
|
-
|
|
1637
|
+
outputDir: args.outputDir,
|
|
1604
1638
|
workspace: args.workspace,
|
|
1605
1639
|
outputs: phaseOutputs,
|
|
1606
1640
|
verbose: args.verbose,
|
|
@@ -1619,7 +1653,7 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1619
1653
|
writeVerbose("[phase1 recovery] attempting host-side recovery from agent outputs");
|
|
1620
1654
|
await recoverReportedProcessDefinition({
|
|
1621
1655
|
state,
|
|
1622
|
-
|
|
1656
|
+
outputDir: args.outputDir,
|
|
1623
1657
|
workspace: args.workspace,
|
|
1624
1658
|
outputs: phaseOutputs,
|
|
1625
1659
|
verbose: args.verbose,
|
|
@@ -1629,7 +1663,7 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1629
1663
|
if (!state.report?.processPath) {
|
|
1630
1664
|
const finalRecoveryPrompt = [
|
|
1631
1665
|
"Final recovery step:",
|
|
1632
|
-
`- Write the
|
|
1666
|
+
`- Write the process file to the output directory ${args.outputDir} using babysitter_write_process_definition with a descriptive filename.`,
|
|
1633
1667
|
"- If you already wrote it, do not rewrite unnecessarily.",
|
|
1634
1668
|
"- Call babysitter_report_process_definition exactly once after the file exists.",
|
|
1635
1669
|
"- Do not answer with plain text only.",
|
|
@@ -1639,17 +1673,25 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1639
1673
|
const finalRecovery = await (0, harnessUtils_1.promptPiWithRetry)({
|
|
1640
1674
|
session,
|
|
1641
1675
|
message: finalRecoveryPrompt,
|
|
1642
|
-
timeout:
|
|
1676
|
+
timeout: harnessUtils_1.PI_PARENT_PROMPT_TIMEOUT_MS,
|
|
1643
1677
|
label: "phase1 final recovery",
|
|
1644
1678
|
writeVerbose,
|
|
1645
1679
|
writeVerboseData,
|
|
1680
|
+
}).catch((err) => {
|
|
1681
|
+
const isTimeout = err instanceof harnessUtils_1.BabysitterRuntimeError &&
|
|
1682
|
+
(err.name === "PiTimeoutError" || (err.message ?? "").includes("timed out"));
|
|
1683
|
+
if (isTimeout) {
|
|
1684
|
+
writeVerbose("[phase1 final recovery] Pi prompt timed out, converting to failure result");
|
|
1685
|
+
return { success: false, output: `Pi prompt timed out: ${err instanceof Error ? err.message : String(err)}` };
|
|
1686
|
+
}
|
|
1687
|
+
throw err;
|
|
1646
1688
|
});
|
|
1647
1689
|
phaseOutputs.push(finalRecovery.output);
|
|
1648
1690
|
if (!finalRecovery.success) {
|
|
1649
1691
|
writeVerboseData("phase1 final recovery failure output", finalRecovery.output);
|
|
1650
1692
|
const recovered = await recoverReportedProcessDefinition({
|
|
1651
1693
|
state,
|
|
1652
|
-
|
|
1694
|
+
outputDir: args.outputDir,
|
|
1653
1695
|
workspace: args.workspace,
|
|
1654
1696
|
outputs: phaseOutputs,
|
|
1655
1697
|
verbose: args.verbose,
|
|
@@ -1665,7 +1707,7 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1665
1707
|
}
|
|
1666
1708
|
await recoverReportedProcessDefinition({
|
|
1667
1709
|
state,
|
|
1668
|
-
|
|
1710
|
+
outputDir: args.outputDir,
|
|
1669
1711
|
workspace: args.workspace,
|
|
1670
1712
|
outputs: phaseOutputs,
|
|
1671
1713
|
verbose: args.verbose,
|
|
@@ -1708,10 +1750,18 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1708
1750
|
const repair = await (0, harnessUtils_1.promptPiWithRetry)({
|
|
1709
1751
|
session,
|
|
1710
1752
|
message: conformancePrompt,
|
|
1711
|
-
timeout:
|
|
1753
|
+
timeout: harnessUtils_1.PI_PARENT_PROMPT_TIMEOUT_MS,
|
|
1712
1754
|
label: "phase1 conformance repair",
|
|
1713
1755
|
writeVerbose,
|
|
1714
1756
|
writeVerboseData,
|
|
1757
|
+
}).catch((err) => {
|
|
1758
|
+
const isTimeout = err instanceof harnessUtils_1.BabysitterRuntimeError &&
|
|
1759
|
+
(err.name === "PiTimeoutError" || (err.message ?? "").includes("timed out"));
|
|
1760
|
+
if (isTimeout) {
|
|
1761
|
+
writeVerbose("[phase1 conformance repair] Pi prompt timed out, converting to failure result");
|
|
1762
|
+
return { success: false, output: `Pi prompt timed out: ${err instanceof Error ? err.message : String(err)}` };
|
|
1763
|
+
}
|
|
1764
|
+
throw err;
|
|
1715
1765
|
});
|
|
1716
1766
|
phaseOutputs.push(repair.output);
|
|
1717
1767
|
if (!repair.success) {
|
|
@@ -1727,7 +1777,7 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1727
1777
|
phase: "1",
|
|
1728
1778
|
status: "completed",
|
|
1729
1779
|
processPath: state.report.processPath,
|
|
1730
|
-
harness: "
|
|
1780
|
+
harness: "internal (agentic)",
|
|
1731
1781
|
}, args.json, args.verbose);
|
|
1732
1782
|
return state.report.processPath;
|
|
1733
1783
|
}
|
|
@@ -1742,7 +1792,7 @@ async function runProcessDefinitionPhase(args) {
|
|
|
1742
1792
|
(0, harnessUtils_1.emitProgress)({
|
|
1743
1793
|
phase: "1",
|
|
1744
1794
|
status: "failed",
|
|
1745
|
-
harness: "
|
|
1795
|
+
harness: "internal (agentic)",
|
|
1746
1796
|
error: error instanceof Error ? error.message : String(error),
|
|
1747
1797
|
}, args.json, args.verbose);
|
|
1748
1798
|
throw error;
|
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import * as readline from "node:readline";
|
|
9
9
|
import { type ResolveEffectResult, type CompressionConfig, type HarnessDiscoveryResult, type HarnessPromptContext as SessionCreatePromptContext, type EffectAction, PiSessionHandle } from "./harnessUtils";
|
|
10
|
+
/**
|
|
11
|
+
* Maximum number of consecutive Pi prompt timeouts before the orchestration
|
|
12
|
+
* run is failed. A single timeout is recoverable — the loop simply continues
|
|
13
|
+
* — but repeated timeouts indicate a persistent infrastructure issue.
|
|
14
|
+
*/
|
|
15
|
+
export declare const MAX_CONSECUTIVE_TIMEOUTS = 3;
|
|
10
16
|
export declare function resolveEffect(action: EffectAction, harnessName: string, options: {
|
|
11
17
|
workspace?: string;
|
|
12
18
|
model?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harnessPhase2.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/harnessPhase2.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAkB1C,OAAO,EAOL,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAI3B,KAAK,oBAAoB,IAAI,0BAA0B,EACvD,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"harnessPhase2.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/harnessPhase2.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAkB1C,OAAO,EAOL,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAI3B,KAAK,oBAAoB,IAAI,0BAA0B,EACvD,KAAK,YAAY,EA+BjB,eAAe,EAIhB,MAAM,gBAAgB,CAAC;AAQxB;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAO1C,wBAAsB,aAAa,CACjC,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE;IACP,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAC9C,EACD,SAAS,CAAC,EAAE,eAAe,GAAG,IAAI,EAClC,UAAU,CAAC,EAAE,sBAAsB,EAAE,EACrC,EAAE,CAAC,EAAE,QAAQ,CAAC,SAAS,GAAG,IAAI,EAC9B,IAAI,CAAC,EAAE,OAAO,EACd,sBAAsB,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,GACtE,OAAO,CAAC,mBAAmB,CAAC,CAwO9B;AAuOD,wBAAsB,qBAAqB,CAAC,IAAI,EAAE;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,EAAE,EAAE,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;IAC9B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,sBAAsB,EAAE,CAAC;IACrC,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC5C,aAAa,EAAE,0BAA0B,CAAC;IAC1C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC,MAAM,CAAC,CAs+ClB"}
|