@a5c-ai/babysitter-sdk 5.0.1-staging.686c8b317 → 5.0.1-staging.69cb593ea

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.
Files changed (52) hide show
  1. package/dist/cli/commands/detectExistingRun.d.ts +14 -0
  2. package/dist/cli/commands/detectExistingRun.d.ts.map +1 -0
  3. package/dist/cli/commands/detectExistingRun.js +89 -0
  4. package/dist/cli/commands/instructions.d.ts.map +1 -1
  5. package/dist/cli/commands/instructions.js +24 -44
  6. package/dist/cli/main/argPositionals.d.ts.map +1 -1
  7. package/dist/cli/main/argPositionals.js +1 -0
  8. package/dist/cli/main/dispatchRunSession.d.ts.map +1 -1
  9. package/dist/cli/main/dispatchRunSession.js +2 -0
  10. package/dist/cli/main/program.js +1 -1
  11. package/dist/cli/main/runAssignProcess.d.ts +3 -0
  12. package/dist/cli/main/runAssignProcess.d.ts.map +1 -0
  13. package/dist/cli/main/runAssignProcess.js +169 -0
  14. package/dist/cli/main/runCommands.d.ts +1 -0
  15. package/dist/cli/main/runCommands.d.ts.map +1 -1
  16. package/dist/cli/main/runCommands.js +3 -1
  17. package/dist/cli/main/runCreate.d.ts.map +1 -1
  18. package/dist/cli/main/runCreate.js +31 -27
  19. package/dist/cli/main/usage.d.ts.map +1 -1
  20. package/dist/cli/main/usage.js +2 -1
  21. package/dist/cli/render/events/index.d.ts.map +1 -1
  22. package/dist/cli/render/events/index.js +2 -0
  23. package/dist/cli/render/events/processAssigned.d.ts +3 -0
  24. package/dist/cli/render/events/processAssigned.d.ts.map +1 -0
  25. package/dist/cli/render/events/processAssigned.js +22 -0
  26. package/dist/harness/amuxFallbackMetadata.d.ts.map +1 -1
  27. package/dist/harness/amuxFallbackMetadata.js +8 -1
  28. package/dist/harness/install.d.ts.map +1 -1
  29. package/dist/harness/install.js +12 -1
  30. package/dist/harness/unified/adapter.d.ts.map +1 -1
  31. package/dist/harness/unified/adapter.js +31 -0
  32. package/dist/mcp/tools/discovery.js +6 -6
  33. package/dist/mcp/tools/runs.js +18 -18
  34. package/dist/mcp/tools/sessions.js +16 -16
  35. package/dist/mcp/tools/tasks.js +13 -13
  36. package/dist/prompts/parts/runCreation.d.ts.map +1 -1
  37. package/dist/prompts/parts/runCreation.js +2 -1
  38. package/dist/prompts/templates/quick-reference.md +5 -0
  39. package/dist/prompts/templates/run-creation.md +45 -1
  40. package/dist/runtime/createRun.d.ts.map +1 -1
  41. package/dist/runtime/createRun.js +5 -3
  42. package/dist/runtime/orchestrateIteration.d.ts.map +1 -1
  43. package/dist/runtime/orchestrateIteration.js +3 -0
  44. package/dist/runtime/types.d.ts +2 -1
  45. package/dist/runtime/types.d.ts.map +1 -1
  46. package/dist/storage/index.d.ts +1 -1
  47. package/dist/storage/index.d.ts.map +1 -1
  48. package/dist/storage/index.js +2 -1
  49. package/dist/storage/runFiles.d.ts +1 -0
  50. package/dist/storage/runFiles.d.ts.map +1 -1
  51. package/dist/storage/runFiles.js +5 -0
  52. package/package.json +12 -10
@@ -0,0 +1,14 @@
1
+ export interface ExistingRunInfo {
2
+ runId: string;
3
+ runDir: string;
4
+ processId: string;
5
+ isBareRun: boolean;
6
+ entrypoint: {
7
+ importPath: string;
8
+ exportName?: string;
9
+ };
10
+ completionProof?: string;
11
+ }
12
+ export declare function detectExistingRun(): Promise<ExistingRunInfo | undefined>;
13
+ export declare function formatExistingRunBlock(existingRun: ExistingRunInfo): string;
14
+ //# sourceMappingURL=detectExistingRun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detectExistingRun.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/detectExistingRun.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CA0B9E;AAED,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,eAAe,GAAG,MAAM,CAiB3E"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.detectExistingRun = detectExistingRun;
37
+ exports.formatExistingRunBlock = formatExistingRunBlock;
38
+ const node_fs_1 = require("node:fs");
39
+ const path = __importStar(require("node:path"));
40
+ const config_1 = require("../../config");
41
+ async function detectExistingRun() {
42
+ try {
43
+ const runsDir = (0, config_1.resolveRunsDir)();
44
+ const entries = await node_fs_1.promises.readdir(runsDir, { withFileTypes: true });
45
+ const dirs = entries.filter((e) => e.isDirectory()).map((e) => e.name).sort().reverse();
46
+ for (const runId of dirs.slice(0, 5)) {
47
+ const runFile = path.join(runsDir, runId, "run.json");
48
+ try {
49
+ const raw = await node_fs_1.promises.readFile(runFile, "utf8");
50
+ const meta = JSON.parse(raw);
51
+ const entrypoint = meta["entrypoint"];
52
+ const processId = meta["processId"] ?? "";
53
+ const isBareRun = entrypoint?.importPath === "bare-run";
54
+ return {
55
+ runId,
56
+ runDir: path.join(runsDir, runId),
57
+ processId,
58
+ isBareRun,
59
+ entrypoint: { importPath: entrypoint?.importPath ?? "", exportName: entrypoint?.exportName },
60
+ completionProof: meta["completionProof"]
61
+ ?? meta["metadata"]?.["completionProof"],
62
+ };
63
+ }
64
+ catch {
65
+ continue;
66
+ }
67
+ }
68
+ }
69
+ catch { /* no runs dir */ }
70
+ return undefined;
71
+ }
72
+ function formatExistingRunBlock(existingRun) {
73
+ return [
74
+ '## Existing Run State',
75
+ '',
76
+ `- Run ID: \`${existingRun.runId}\``,
77
+ `- Run Dir: \`${existingRun.runDir}\``,
78
+ `- Process ID: \`${existingRun.processId}\``,
79
+ `- Bare Run: \`${existingRun.isBareRun}\``,
80
+ `- Entrypoint: \`${existingRun.entrypoint.importPath}${existingRun.entrypoint.exportName ? '#' + existingRun.entrypoint.exportName : ''}\``,
81
+ '',
82
+ existingRun.isBareRun
83
+ ? `**This is a bare run.** Use \`run:assign-process ${existingRun.runDir} --entry <path>#<export>\` to assign a process before iterating.`
84
+ : `This run already has a process assigned. Use \`run:iterate ${existingRun.runDir} --json\` to continue.`,
85
+ '',
86
+ '---',
87
+ '',
88
+ ].join('\n');
89
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAmCH,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,eAAe,GAAG,gBAAgB,GAAG,aAAa,GAAG,qBAAqB,CAAC;IACvF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAwND;;GAEG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAkIjB"}
1
+ {"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoCH,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,eAAe,GAAG,gBAAgB,GAAG,aAAa,GAAG,qBAAqB,CAAC;IACvF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AA4MD;;GAEG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAwGjB"}
@@ -16,6 +16,7 @@ const registry_1 = require("../../harness/registry");
16
16
  const discovery_1 = require("../../harness/discovery");
17
17
  const parse_1 = require("../../session/parse");
18
18
  const contextShared_1 = require("../../prompts/contextShared");
19
+ const detectExistingRun_1 = require("./detectExistingRun");
19
20
  const COMPOSERS = {
20
21
  "babysit-skill": {
21
22
  fn: prompts_1.composeBabysitSkillPrompt,
@@ -169,18 +170,6 @@ async function tryResolveProcessLibraryRoot() {
169
170
  }
170
171
  return {};
171
172
  }
172
- /**
173
- * Detect whether the session-start hook has actually run by checking for the
174
- * session state file it creates (`<stateDir>/<sessionId>.md`).
175
- *
176
- * The definitive signal is now the PID-scoped session marker written by the
177
- * session-start hook; absence of the marker (even when env vars like
178
- * GEMINI_SESSION_ID / CODEX_SESSION_ID / AGENT_SESSION_ID are present)
179
- * usually means hooks did not fire. Env-var-only resolution is a fallback
180
- * path that may bind to stale IDs inherited from ancestor shells, so it
181
- * cannot be trusted as proof that hooks are active. The hook writes the
182
- * state file as a side effect of `babysitter hook:run --hook-type session-start`.
183
- */
184
173
  function detectHooksActive(harness) {
185
174
  const adapter = (0, registry_1.getAdapterByName)(harness);
186
175
  if (!adapter)
@@ -230,9 +219,9 @@ async function handleInstructionsCommand(args) {
230
219
  // Resolve the active process-library root before composing the prompt
231
220
  const libraryInfo = await tryResolveProcessLibraryRoot();
232
221
  // Detect whether hooks are actually active in this session.
233
- // If the session-start hook never ran (no breadcrumb file), override
234
- // hookDriven to false so the agent drives the loop in-turn.
235
- const hooksActive = detectHooksActive(resolvedHarness.harness);
222
+ // hookDriven=false when: non-interactive mode, or session-start hook never ran.
223
+ // Non-interactive mode never has hooks — the agent must drive the loop in-turn.
224
+ const hooksActive = args.interactive !== false && detectHooksActive(resolvedHarness.harness);
236
225
  const hookOverride = {};
237
226
  if (!hooksActive) {
238
227
  hookOverride.hookDriven = false;
@@ -243,6 +232,7 @@ async function handleInstructionsCommand(args) {
243
232
  // scheduled reporting, local-dev relaxations).
244
233
  const executionContext = (0, prompts_1.detectExecutionContext)();
245
234
  const capabilityFlags = (0, prompts_1.deriveCapabilityFlags)(executionContext);
235
+ const existingRun = await (0, detectExistingRun_1.detectExistingRun)();
246
236
  const ctx = factory({
247
237
  interactive: args.interactive,
248
238
  ...libraryInfo,
@@ -272,41 +262,31 @@ async function handleInstructionsCommand(args) {
272
262
  executionContext,
273
263
  capabilityFlags,
274
264
  suggestedProcesses: (0, prompts_1.processPathsForCapabilities)(capabilityFlags),
265
+ existingRun: existingRun ?? null,
275
266
  content,
276
267
  partsIncluded: composer.partsIncluded,
277
268
  }, null, 2));
278
269
  }
279
270
  else {
280
- for (const warning of resolvedHarness.warnings) {
271
+ for (const warning of resolvedHarness.warnings)
281
272
  console.error(`[instructions] Warning: ${warning}`);
282
- }
283
- if (!hooksActive && ctx.hookDriven !== false) {
284
- // Context factory defaulted hookDriven to true, but we overrode it.
285
- // This is a no-op because the override already happened, but it
286
- // clarifies the JSON output. The text output is self-explanatory
287
- // from the generated instructions.
288
- }
289
- const activeCapabilities = Object.entries(capabilityFlags)
290
- .filter(([, v]) => v === true)
291
- .map(([k]) => k);
292
- const contextHeader = [
293
- '## Execution Context',
294
- '',
295
- `- CI: \`${executionContext.ci}\``,
296
- `- Trigger: \`${executionContext.trigger}\``,
297
- executionContext.branch.ref ? `- Branch: \`${executionContext.branch.ref}\`` : undefined,
298
- executionContext.repo ? `- Repo: \`${executionContext.repo.owner}/${executionContext.repo.name}\`` : undefined,
299
- executionContext.actor ? `- Actor: \`${executionContext.actor.login}\`${executionContext.actor.isBot ? ' (bot)' : ''}` : undefined,
300
- '',
301
- `Active context capabilities: ${activeCapabilities.length > 0 ? activeCapabilities.map(c => `\`${c}\``).join(', ') : '_(none)_'}`,
302
- '',
303
- 'When selecting library processes to dispatch, prefer those whose triggers match the active capabilities above.',
304
- '',
305
- '---',
306
- '',
307
- ].filter((l) => l !== undefined).join('\n');
308
- const processGuide = (0, prompts_1.renderCapabilityProcessGuide)(capabilityFlags);
309
- console.log(contextHeader + processGuide + content);
273
+ console.log(formatTextOutput(executionContext, capabilityFlags, existingRun, content));
310
274
  }
311
275
  return 0;
312
276
  }
277
+ function formatTextOutput(executionContext, capabilityFlags, existingRun, content) {
278
+ const caps = Object.entries(capabilityFlags).filter(([, v]) => v).map(([k]) => k);
279
+ const header = [
280
+ '## Execution Context', '',
281
+ `- CI: \`${executionContext.ci}\``,
282
+ `- Trigger: \`${executionContext.trigger}\``,
283
+ executionContext.branch.ref ? `- Branch: \`${executionContext.branch.ref}\`` : undefined,
284
+ executionContext.repo ? `- Repo: \`${executionContext.repo.owner}/${executionContext.repo.name}\`` : undefined,
285
+ executionContext.actor ? `- Actor: \`${executionContext.actor.login}\`${executionContext.actor.isBot ? ' (bot)' : ''}` : undefined,
286
+ '', `Active context capabilities: ${caps.length > 0 ? caps.map(c => `\`${c}\``).join(', ') : '_(none)_'}`,
287
+ '', 'When selecting library processes to dispatch, prefer those whose triggers match the active capabilities above.', '', '---', '',
288
+ ].filter((l) => l !== undefined).join('\n');
289
+ const guide = (0, prompts_1.renderCapabilityProcessGuide)(capabilityFlags);
290
+ const runBlock = existingRun ? (0, detectExistingRun_1.formatExistingRunBlock)(existingRun) : '';
291
+ return header + guide + runBlock + content;
292
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"argPositionals.d.ts","sourceRoot":"","sources":["../../../src/cli/main/argPositionals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,QA4F5E"}
1
+ {"version":3,"file":"argPositionals.d.ts","sourceRoot":"","sources":["../../../src/cli/main/argPositionals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,QA6F5E"}
@@ -9,6 +9,7 @@ function applyPositionalArgs(parsed, positionals) {
9
9
  [parsed.runDirArg, parsed.effectId] = positionals;
10
10
  return;
11
11
  case "task:list":
12
+ case "run:assign-process":
12
13
  case "run:status":
13
14
  case "run:iterate":
14
15
  case "run:events":
@@ -1 +1 @@
1
- {"version":3,"file":"dispatchRunSession.d.ts","sourceRoot":"","sources":["../../../src/cli/main/dispatchRunSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAmD1C,wBAAsB,wBAAwB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAM9F"}
1
+ {"version":3,"file":"dispatchRunSession.d.ts","sourceRoot":"","sources":["../../../src/cli/main/dispatchRunSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAoD1C,wBAAsB,wBAAwB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAM9F"}
@@ -66,6 +66,8 @@ async function executeRunTaskCommand(parsed) {
66
66
  switch (parsed.command) {
67
67
  case "run:create":
68
68
  return await (0, runCommands_1.handleRunCreate)(parsed);
69
+ case "run:assign-process":
70
+ return await (0, runCommands_1.handleRunAssignProcess)(parsed);
69
71
  case "run:rebuild-state":
70
72
  return await (0, runCommands_1.handleRunRebuildState)(parsed);
71
73
  case "run:repair-journal":
@@ -51,7 +51,7 @@ exports.HARNESS_INSTALL_COMMANDS = [
51
51
  "harness:install-plugin",
52
52
  ];
53
53
  const SHARED_VALID_COMMANDS = [
54
- "run:create", "run:status", "run:iterate", "run:events", "run:rebuild-state", "run:repair-journal",
54
+ "run:create", "run:assign-process", "run:status", "run:iterate", "run:events", "run:rebuild-state", "run:repair-journal",
55
55
  "task:post", "task:cancel", "task:list", "task:show",
56
56
  "log", "hook:log", "hook:run", "skill:discover", "skill:fetch-remote",
57
57
  "process-library:clone", "process-library:update", "process-library:use", "process-library:active",
@@ -0,0 +1,3 @@
1
+ import type { ParsedArgs } from "./types";
2
+ export declare function handleRunAssignProcess(parsed: ParsedArgs): Promise<number>;
3
+ //# sourceMappingURL=runAssignProcess.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runAssignProcess.d.ts","sourceRoot":"","sources":["../../../src/cli/main/runAssignProcess.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAU1C,wBAAsB,sBAAsB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAoIhF"}
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.handleRunAssignProcess = handleRunAssignProcess;
37
+ const path = __importStar(require("node:path"));
38
+ const runFiles_1 = require("../../storage/runFiles");
39
+ const journal_1 = require("../../storage/journal");
40
+ const lock_1 = require("../../storage/lock");
41
+ const args_1 = require("./args");
42
+ const runSupport_1 = require("./runSupport");
43
+ const usage_1 = require("./usage");
44
+ async function handleRunAssignProcess(parsed) {
45
+ if (!parsed.runDirArg) {
46
+ console.error("run:assign-process requires a <runDir> positional argument");
47
+ console.error(usage_1.USAGE);
48
+ return 1;
49
+ }
50
+ if (!parsed.entrySpecifier) {
51
+ console.error("--entry is required for run:assign-process");
52
+ console.error(usage_1.USAGE);
53
+ return 1;
54
+ }
55
+ let entrypoint;
56
+ try {
57
+ entrypoint = (0, runSupport_1.parseEntrypointSpecifier)(parsed.entrySpecifier);
58
+ }
59
+ catch (error) {
60
+ console.error(error instanceof Error ? error.message : String(error));
61
+ return 1;
62
+ }
63
+ const runsDir = (0, args_1.collapseDoubledA5cRuns)(path.resolve(parsed.runsDir));
64
+ const runDir = (0, args_1.resolveRunDir)(runsDir, parsed.runDirArg);
65
+ const absoluteImportPath = path.resolve(entrypoint.importPath);
66
+ const resolvedEntry = (0, runSupport_1.formatResolvedEntrypoint)(absoluteImportPath, entrypoint.exportName);
67
+ (0, runSupport_1.logVerbose)("run:assign-process", parsed, {
68
+ runDir,
69
+ entry: resolvedEntry,
70
+ processId: parsed.processId,
71
+ force: parsed.sessionForce,
72
+ dryRun: parsed.dryRun,
73
+ json: parsed.json,
74
+ });
75
+ let metadata;
76
+ try {
77
+ metadata = await (0, runFiles_1.readRunMetadata)(runDir);
78
+ }
79
+ catch (error) {
80
+ const err = error;
81
+ if (err.code === "ENOENT") {
82
+ const message = `Run directory not found: ${runDir}`;
83
+ if (parsed.json) {
84
+ console.log(JSON.stringify({ error: "RUN_NOT_FOUND", message }));
85
+ }
86
+ else {
87
+ console.error(message);
88
+ }
89
+ return 1;
90
+ }
91
+ throw error;
92
+ }
93
+ const isBareRun = metadata.entrypoint.importPath === "bare-run";
94
+ if (!isBareRun && !parsed.sessionForce) {
95
+ const message = `Run already has a process assigned (entrypoint: ${metadata.entrypoint.importPath}). Use --force to override.`;
96
+ if (parsed.json) {
97
+ console.log(JSON.stringify({ error: "PROCESS_ALREADY_ASSIGNED", message, currentEntrypoint: metadata.entrypoint }));
98
+ }
99
+ else {
100
+ console.error(message);
101
+ }
102
+ return 1;
103
+ }
104
+ try {
105
+ await (0, runSupport_1.validateProcessEntrypoint)(absoluteImportPath, entrypoint.exportName);
106
+ }
107
+ catch (error) {
108
+ console.error(error instanceof Error ? error.message : String(error));
109
+ return 1;
110
+ }
111
+ const processId = parsed.processId ?? metadata.processId;
112
+ if (parsed.dryRun) {
113
+ const summary = {
114
+ dryRun: true,
115
+ runDir,
116
+ runId: metadata.runId,
117
+ entry: resolvedEntry,
118
+ processId,
119
+ previousEntrypoint: metadata.entrypoint,
120
+ force: parsed.sessionForce ?? false,
121
+ };
122
+ if (parsed.json) {
123
+ console.log(JSON.stringify(summary, null, 2));
124
+ }
125
+ else {
126
+ console.log(`[run:assign-process] dry-run runDir=${runDir} entry=${resolvedEntry} processId=${processId}`);
127
+ }
128
+ return 0;
129
+ }
130
+ await (0, lock_1.withRunLock)(runDir, "run:assign-process", async () => {
131
+ const current = await (0, runFiles_1.readRunMetadata)(runDir);
132
+ const previousEntrypoint = { ...current.entrypoint };
133
+ current.entrypoint = {
134
+ importPath: absoluteImportPath,
135
+ exportName: entrypoint.exportName,
136
+ };
137
+ current.processPath = absoluteImportPath;
138
+ current.processId = processId;
139
+ if (parsed.processRevision) {
140
+ current.processRevision = parsed.processRevision;
141
+ }
142
+ await (0, runFiles_1.writeRunMetadata)(runDir, current);
143
+ await (0, journal_1.appendEvent)({
144
+ runDir,
145
+ eventType: "PROCESS_ASSIGNED",
146
+ event: {
147
+ processId,
148
+ entrypoint: current.entrypoint,
149
+ previousEntrypoint,
150
+ force: parsed.sessionForce ?? false,
151
+ },
152
+ });
153
+ });
154
+ const updatedMetadata = await (0, runFiles_1.readRunMetadata)(runDir);
155
+ if (parsed.json) {
156
+ console.log(JSON.stringify({
157
+ runId: updatedMetadata.runId,
158
+ runDir,
159
+ entry: resolvedEntry,
160
+ processId,
161
+ previousEntrypoint: metadata.entrypoint,
162
+ assigned: true,
163
+ }, null, 2));
164
+ }
165
+ else {
166
+ console.log(`[run:assign-process] runId=${updatedMetadata.runId} runDir=${runDir} entry=${resolvedEntry} processId=${processId}`);
167
+ }
168
+ return 0;
169
+ }
@@ -1,3 +1,4 @@
1
1
  export { handleRunCreate, handleRunRebuildState, handleRunRepairJournal, } from "./runCreate";
2
+ export { handleRunAssignProcess } from "./runAssignProcess";
2
3
  export { handleRunEvents, handleRunIterate, handleRunStatus } from "./runInspection";
3
4
  //# sourceMappingURL=runCommands.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runCommands.d.ts","sourceRoot":"","sources":["../../../src/cli/main/runCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"runCommands.d.ts","sourceRoot":"","sources":["../../../src/cli/main/runCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleRunStatus = exports.handleRunIterate = exports.handleRunEvents = exports.handleRunRepairJournal = exports.handleRunRebuildState = exports.handleRunCreate = void 0;
3
+ exports.handleRunStatus = exports.handleRunIterate = exports.handleRunEvents = exports.handleRunAssignProcess = exports.handleRunRepairJournal = exports.handleRunRebuildState = exports.handleRunCreate = void 0;
4
4
  var runCreate_1 = require("./runCreate");
5
5
  Object.defineProperty(exports, "handleRunCreate", { enumerable: true, get: function () { return runCreate_1.handleRunCreate; } });
6
6
  Object.defineProperty(exports, "handleRunRebuildState", { enumerable: true, get: function () { return runCreate_1.handleRunRebuildState; } });
7
7
  Object.defineProperty(exports, "handleRunRepairJournal", { enumerable: true, get: function () { return runCreate_1.handleRunRepairJournal; } });
8
+ var runAssignProcess_1 = require("./runAssignProcess");
9
+ Object.defineProperty(exports, "handleRunAssignProcess", { enumerable: true, get: function () { return runAssignProcess_1.handleRunAssignProcess; } });
8
10
  var runInspection_1 = require("./runInspection");
9
11
  Object.defineProperty(exports, "handleRunEvents", { enumerable: true, get: function () { return runInspection_1.handleRunEvents; } });
10
12
  Object.defineProperty(exports, "handleRunIterate", { enumerable: true, get: function () { return runInspection_1.handleRunIterate; } });
@@ -1 +1 @@
1
- {"version":3,"file":"runCreate.d.ts","sourceRoot":"","sources":["../../../src/cli/main/runCreate.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C,wBAAsB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAkMzE;AAYD,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAmC/E;AAED,wBAAsB,sBAAsB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAiGhF"}
1
+ {"version":3,"file":"runCreate.d.ts","sourceRoot":"","sources":["../../../src/cli/main/runCreate.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C,wBAAsB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAsMzE;AAYD,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAmC/E;AAED,wBAAsB,sBAAsB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAiGhF"}
@@ -50,27 +50,27 @@ const runSupport_1 = require("./runSupport");
50
50
  const runState_1 = require("./runState");
51
51
  const usage_1 = require("./usage");
52
52
  async function handleRunCreate(parsed) {
53
- if (!parsed.processId) {
54
- console.error("--process-id is required for run:create");
55
- console.error(usage_1.USAGE);
56
- return 1;
57
- }
58
- if (!parsed.entrySpecifier) {
59
- console.error("--entry is required for run:create");
53
+ // --entry is optional for bare runs (no process attached)
54
+ const isBareRun = !parsed.entrySpecifier;
55
+ if (!parsed.processId && !isBareRun) {
56
+ console.error("--process-id is required for run:create (unless creating a bare run without --entry)");
60
57
  console.error(usage_1.USAGE);
61
58
  return 1;
62
59
  }
63
60
  let entrypoint;
64
- try {
65
- entrypoint = (0, runSupport_1.parseEntrypointSpecifier)(parsed.entrySpecifier);
66
- }
67
- catch (error) {
68
- console.error(error instanceof Error ? error.message : String(error));
69
- return 1;
61
+ if (!isBareRun) {
62
+ try {
63
+ const specifier = parsed.entrySpecifier ?? "";
64
+ entrypoint = (0, runSupport_1.parseEntrypointSpecifier)(specifier);
65
+ }
66
+ catch (error) {
67
+ console.error(error instanceof Error ? error.message : String(error));
68
+ return 1;
69
+ }
70
70
  }
71
71
  const runsDir = (0, args_1.collapseDoubledA5cRuns)(path.resolve(parsed.runsDir));
72
- const absoluteImportPath = path.resolve(entrypoint.importPath);
73
- const resolvedEntry = (0, runSupport_1.formatResolvedEntrypoint)(absoluteImportPath, entrypoint.exportName);
72
+ const absoluteImportPath = entrypoint ? path.resolve(entrypoint.importPath) : undefined;
73
+ const resolvedEntry = absoluteImportPath ? (0, runSupport_1.formatResolvedEntrypoint)(absoluteImportPath, entrypoint?.exportName) : "bare-run";
74
74
  (0, runSupport_1.logVerbose)("run:create", parsed, {
75
75
  runsDir,
76
76
  processId: parsed.processId,
@@ -119,12 +119,14 @@ async function handleRunCreate(parsed) {
119
119
  }
120
120
  return 0;
121
121
  }
122
- try {
123
- await (0, runSupport_1.validateProcessEntrypoint)(absoluteImportPath, entrypoint.exportName);
124
- }
125
- catch (error) {
126
- console.error(error instanceof Error ? error.message : String(error));
127
- return 1;
122
+ if (!isBareRun && absoluteImportPath) {
123
+ try {
124
+ await (0, runSupport_1.validateProcessEntrypoint)(absoluteImportPath, entrypoint?.exportName);
125
+ }
126
+ catch (error) {
127
+ console.error(error instanceof Error ? error.message : String(error));
128
+ return 1;
129
+ }
128
130
  }
129
131
  const requestedHarness = parsed.harness ?? (parsed.sessionId ? (0, harness_1.getAdapter)().name : undefined);
130
132
  const result = await (0, createRun_1.createRun)({
@@ -134,11 +136,13 @@ async function handleRunCreate(parsed) {
134
136
  prompt: parsed.prompt,
135
137
  harness: requestedHarness,
136
138
  processRevision: parsed.processRevision,
137
- process: {
138
- processId: parsed.processId,
139
- importPath: absoluteImportPath,
140
- exportName: entrypoint.exportName,
141
- },
139
+ ...(!isBareRun && absoluteImportPath && parsed.processId ? {
140
+ process: {
141
+ processId: parsed.processId,
142
+ importPath: absoluteImportPath,
143
+ exportName: entrypoint?.exportName,
144
+ },
145
+ } : {}),
142
146
  inputs,
143
147
  ...(parsed.interactive === false ? { metadata: { nonInteractive: true } } : {}),
144
148
  });
@@ -185,7 +189,7 @@ async function handleRunCreate(parsed) {
185
189
  const discoverPluginRoot = parsed.pluginRoot ?? adapter?.resolvePluginRoot(parsed);
186
190
  if (discoverPluginRoot) {
187
191
  try {
188
- const processDiscovery = (0, skill_1.discoverFromProcessFile)({ processFilePath: absoluteImportPath, pluginRoot: discoverPluginRoot });
192
+ const processDiscovery = absoluteImportPath ? (0, skill_1.discoverFromProcessFile)({ processFilePath: absoluteImportPath, pluginRoot: discoverPluginRoot }) : undefined;
189
193
  if (processDiscovery) {
190
194
  discoveredSkills = processDiscovery.skills;
191
195
  discoveredAgents = processDiscovery.agents;
@@ -1 +1 @@
1
- {"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../../src/cli/main/usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AA2I1D,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,UAAyB,GAAG,MAAM,CAa5F;AAED,eAAO,MAAM,WAAW,QAAqC,CAAC;AAC9D,eAAO,MAAM,WAAW,QAAqC,CAAC;AAC9D,eAAO,MAAM,KAAK,QAAc,CAAC"}
1
+ {"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../../src/cli/main/usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AA4I1D,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,UAAyB,GAAG,MAAM,CAa5F;AAED,eAAO,MAAM,WAAW,QAAqC,CAAC;AAC9D,eAAO,MAAM,WAAW,QAAqC,CAAC;AAC9D,eAAO,MAAM,KAAK,QAAc,CAAC"}
@@ -4,7 +4,8 @@ exports.USAGE = exports.HUMAN_USAGE = exports.AGENT_USAGE = void 0;
4
4
  exports.formatUsage = formatUsage;
5
5
  const program_1 = require("./program");
6
6
  function coreAgentUsage(commandName) {
7
- return ` ${commandName} run:create --process-id <id> --entry <path#export> [--inputs <file>] [--run-id <id>] [--process-revision <rev>] [--request <id>] [--prompt <text>] [--harness <name>] [--session-id <id>] [--non-interactive] [--json] [--dry-run]
7
+ return ` ${commandName} run:create --process-id <id> [--entry <path#export>] [--inputs <file>] [--run-id <id>] [--process-revision <rev>] [--request <id>] [--prompt <text>] [--harness <name>] [--session-id <id>] [--non-interactive] [--json] [--dry-run]
8
+ ${commandName} run:assign-process <runDir> --entry <path#export> [--process-id <id>] [--process-revision <rev>] [--force] [--json] [--dry-run]
8
9
  ${commandName} run:status <runDir> [--json]
9
10
  ${commandName} run:events <runDir> [--json] [--limit <n>] [--reverse] [--filter-type <type>]
10
11
  ${commandName} run:rebuild-state <runDir> [--json] [--dry-run]
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/render/events/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAU5C,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAM9D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/render/events/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAW5C,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAM9D"}
@@ -4,11 +4,13 @@ exports.renderEventMessage = renderEventMessage;
4
4
  const ansi_1 = require("../ansi");
5
5
  const effectRequested_1 = require("./effectRequested");
6
6
  const effectResolved_1 = require("./effectResolved");
7
+ const processAssigned_1 = require("./processAssigned");
7
8
  const runCompleted_1 = require("./runCompleted");
8
9
  const runCreated_1 = require("./runCreated");
9
10
  const runFailed_1 = require("./runFailed");
10
11
  const EVENT_RENDERERS = {
11
12
  RUN_CREATED: runCreated_1.renderRunCreatedMessage,
13
+ PROCESS_ASSIGNED: processAssigned_1.renderProcessAssignedMessage,
12
14
  EFFECT_REQUESTED: effectRequested_1.renderEffectRequestedMessage,
13
15
  EFFECT_RESOLVED: effectResolved_1.renderEffectResolvedMessage,
14
16
  RUN_COMPLETED: runCompleted_1.renderRunCompletedMessage,
@@ -0,0 +1,3 @@
1
+ import type { JournalEvent } from "./types";
2
+ export declare function renderProcessAssignedMessage(event: JournalEvent): string;
3
+ //# sourceMappingURL=processAssigned.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processAssigned.d.ts","sourceRoot":"","sources":["../../../../src/cli/render/events/processAssigned.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAmBxE"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderProcessAssignedMessage = renderProcessAssignedMessage;
4
+ const ansi_1 = require("../ansi");
5
+ function renderProcessAssignedMessage(event) {
6
+ const { processId, entrypoint, previousEntrypoint, force } = event.data;
7
+ const lines = [
8
+ `${(0, ansi_1.colorize)("✔ assigned", ansi_1.colors.green)} ${(0, ansi_1.colorize)("PROCESS_ASSIGNED", ansi_1.colors.bold)}`,
9
+ (0, ansi_1.colorize)(` ${event.recordedAt}`, ansi_1.colors.dim),
10
+ ];
11
+ if (processId)
12
+ lines.push(` Process: ${String(processId)}`);
13
+ if (entrypoint?.importPath) {
14
+ const entry = entrypoint.exportName ? `${entrypoint.importPath}#${entrypoint.exportName}` : entrypoint.importPath;
15
+ lines.push(` Entry: ${(0, ansi_1.colorize)(entry, ansi_1.colors.cyan)}`);
16
+ }
17
+ if (previousEntrypoint?.importPath)
18
+ lines.push(` Previous: ${String(previousEntrypoint.importPath)}`);
19
+ if (force)
20
+ lines.push(` Force: ${(0, ansi_1.colorize)("true", ansi_1.colors.yellow)}`);
21
+ return lines.join("\n");
22
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"amuxFallbackMetadata.d.ts","sourceRoot":"","sources":["../../src/harness/amuxFallbackMetadata.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAmM1D,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAiC,CAAC"}
1
+ {"version":3,"file":"amuxFallbackMetadata.d.ts","sourceRoot":"","sources":["../../src/harness/amuxFallbackMetadata.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAwM1D,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAiC,CAAC"}