@a5c-ai/babysitter-sdk 5.0.1-staging.ff2c19f9 → 5.0.1-staging.ff407b73

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 (148) hide show
  1. package/README.md +68 -0
  2. package/dist/cli/commands/breakpointRules.d.ts.map +1 -1
  3. package/dist/cli/commands/breakpointRules.js +30 -27
  4. package/dist/cli/commands/compressOutputHelpers.d.ts.map +1 -1
  5. package/dist/cli/commands/compressOutputHelpers.js +18 -2
  6. package/dist/cli/commands/costStats.d.ts.map +1 -1
  7. package/dist/cli/commands/costStats.js +35 -27
  8. package/dist/cli/commands/harness/install.d.ts +2 -3
  9. package/dist/cli/commands/harness/install.d.ts.map +1 -1
  10. package/dist/cli/commands/harness/install.js +11 -10
  11. package/dist/cli/commands/health/checks.d.ts.map +1 -1
  12. package/dist/cli/commands/health/checks.js +4 -3
  13. package/dist/cli/commands/health/environment.d.ts.map +1 -1
  14. package/dist/cli/commands/health/environment.js +11 -1
  15. package/dist/cli/commands/hooks/run.d.ts.map +1 -1
  16. package/dist/cli/commands/hooks/run.js +3 -2
  17. package/dist/cli/commands/instructions.d.ts +1 -1
  18. package/dist/cli/commands/instructions.d.ts.map +1 -1
  19. package/dist/cli/commands/instructions.js +71 -5
  20. package/dist/cli/commands/runIterate.d.ts.map +1 -1
  21. package/dist/cli/commands/runIterate.js +2 -35
  22. package/dist/cli/commands/session/associate.d.ts.map +1 -1
  23. package/dist/cli/commands/session/associate.js +4 -36
  24. package/dist/cli/commands/session/iterationMessage.d.ts.map +1 -1
  25. package/dist/cli/commands/session/iterationMessage.js +9 -54
  26. package/dist/cli/commands/session/resume.d.ts.map +1 -1
  27. package/dist/cli/commands/session/resume.js +6 -16
  28. package/dist/cli/commands/skill.d.ts.map +1 -1
  29. package/dist/cli/commands/skill.js +2 -1
  30. package/dist/cli/commands/tokensStats.d.ts.map +1 -1
  31. package/dist/cli/commands/tokensStats.js +36 -28
  32. package/dist/cli/main/argFlagParsers.d.ts.map +1 -1
  33. package/dist/cli/main/argFlagParsers.js +2 -1
  34. package/dist/cli/main/args.d.ts.map +1 -1
  35. package/dist/cli/main/args.js +4 -27
  36. package/dist/cli/main/dispatchHarness.js +1 -1
  37. package/dist/cli/main/dispatchRunSession.js +0 -10
  38. package/dist/cli/main/runCreate.js +2 -2
  39. package/dist/cli/main/runSupport.d.ts +9 -1
  40. package/dist/cli/main/runSupport.d.ts.map +1 -1
  41. package/dist/cli/main/runSupport.js +71 -1
  42. package/dist/cli/main/usage.d.ts.map +1 -1
  43. package/dist/cli/main/usage.js +42 -38
  44. package/dist/config/configValidation.d.ts.map +1 -1
  45. package/dist/config/configValidation.js +2 -1
  46. package/dist/config/defaults.d.ts +2 -0
  47. package/dist/config/defaults.d.ts.map +1 -1
  48. package/dist/config/defaults.js +3 -1
  49. package/dist/config/index.d.ts +3 -2
  50. package/dist/config/index.d.ts.map +1 -1
  51. package/dist/config/index.js +15 -2
  52. package/dist/config/runs.d.ts +22 -0
  53. package/dist/config/runs.d.ts.map +1 -0
  54. package/dist/config/runs.js +192 -0
  55. package/dist/harness/adapters/cursor.d.ts +1 -0
  56. package/dist/harness/adapters/cursor.d.ts.map +1 -1
  57. package/dist/harness/adapters/cursor.js +34 -0
  58. package/dist/harness/amuxFallbackMetadata.d.ts.map +1 -1
  59. package/dist/harness/amuxFallbackMetadata.js +62 -37
  60. package/dist/harness/amuxMetadata.d.ts.map +1 -1
  61. package/dist/harness/amuxMetadata.js +2 -1
  62. package/dist/harness/discovery.d.ts +21 -1
  63. package/dist/harness/discovery.d.ts.map +1 -1
  64. package/dist/harness/discovery.js +55 -0
  65. package/dist/harness/hooks/runState.d.ts.map +1 -1
  66. package/dist/harness/hooks/runState.js +12 -23
  67. package/dist/harness/hooks/sessionBinding.d.ts.map +1 -1
  68. package/dist/harness/hooks/sessionBinding.js +3 -6
  69. package/dist/harness/hooks/stopHookContinuation.d.ts.map +1 -1
  70. package/dist/harness/hooks/stopHookContinuation.js +8 -16
  71. package/dist/harness/hooks/stopHookHandler.d.ts.map +1 -1
  72. package/dist/harness/hooks/stopHookHandler.js +2 -1
  73. package/dist/harness/hooks/utils.js +3 -3
  74. package/dist/harness/index.d.ts +1 -1
  75. package/dist/harness/index.d.ts.map +1 -1
  76. package/dist/harness/index.js +2 -1
  77. package/dist/harness/install.d.ts +1 -0
  78. package/dist/harness/install.d.ts.map +1 -1
  79. package/dist/harness/install.js +63 -0
  80. package/dist/harness/installSupport.d.ts.map +1 -1
  81. package/dist/harness/installSupport.js +19 -0
  82. package/dist/harness/types.d.ts +7 -0
  83. package/dist/harness/types.d.ts.map +1 -1
  84. package/dist/harness/unified/subprocess.d.ts.map +1 -1
  85. package/dist/harness/unified/subprocess.js +3 -0
  86. package/dist/mcp/tools/sessions.d.ts.map +1 -1
  87. package/dist/mcp/tools/sessions.js +2 -8
  88. package/dist/mcp/util/resolve-run-dir.d.ts +1 -1
  89. package/dist/mcp/util/resolve-run-dir.d.ts.map +1 -1
  90. package/dist/mcp/util/resolve-run-dir.js +3 -39
  91. package/dist/prompts/compose.js +1 -1
  92. package/dist/prompts/templates/effects.md +1 -1
  93. package/dist/prompts/templates/iteration.md +1 -1
  94. package/dist/prompts/templates/results-posting.md +2 -2
  95. package/dist/prompts/templates/run-creation.md +2 -2
  96. package/dist/prompts/templates/run-overlap-detection.md +6 -4
  97. package/dist/prompts/templates/task-examples.md +7 -7
  98. package/dist/prompts/templates/task-kinds.md +7 -3
  99. package/dist/runtime/commitEffectResult.d.ts.map +1 -1
  100. package/dist/runtime/commitEffectResult.js +5 -2
  101. package/dist/runtime/createRun.d.ts.map +1 -1
  102. package/dist/runtime/createRun.js +28 -14
  103. package/dist/runtime/index.d.ts +2 -1
  104. package/dist/runtime/index.d.ts.map +1 -1
  105. package/dist/runtime/index.js +8 -1
  106. package/dist/runtime/intrinsics/subprocess.d.ts +5 -0
  107. package/dist/runtime/intrinsics/subprocess.d.ts.map +1 -0
  108. package/dist/runtime/intrinsics/subprocess.js +56 -0
  109. package/dist/runtime/intrinsics/task.d.ts +1 -0
  110. package/dist/runtime/intrinsics/task.d.ts.map +1 -1
  111. package/dist/runtime/orchestrateIteration.d.ts.map +1 -1
  112. package/dist/runtime/orchestrateIteration.js +8 -2
  113. package/dist/runtime/policy/engine.d.ts +4 -0
  114. package/dist/runtime/policy/engine.d.ts.map +1 -0
  115. package/dist/runtime/policy/engine.js +97 -0
  116. package/dist/runtime/policy/index.d.ts +3 -1
  117. package/dist/runtime/policy/index.d.ts.map +1 -1
  118. package/dist/runtime/policy/index.js +9 -1
  119. package/dist/runtime/policy/logging.d.ts +6 -0
  120. package/dist/runtime/policy/logging.d.ts.map +1 -0
  121. package/dist/runtime/policy/logging.js +43 -0
  122. package/dist/runtime/policy/types.d.ts +4 -0
  123. package/dist/runtime/policy/types.d.ts.map +1 -1
  124. package/dist/runtime/processContext.d.ts +3 -0
  125. package/dist/runtime/processContext.d.ts.map +1 -1
  126. package/dist/runtime/processContext.js +3 -0
  127. package/dist/runtime/replay/createReplayEngine.d.ts +1 -0
  128. package/dist/runtime/replay/createReplayEngine.d.ts.map +1 -1
  129. package/dist/runtime/replay/createReplayEngine.js +26 -0
  130. package/dist/runtime/runLifecycleState.d.ts +7 -0
  131. package/dist/runtime/runLifecycleState.d.ts.map +1 -0
  132. package/dist/runtime/runLifecycleState.js +54 -0
  133. package/dist/runtime/types.d.ts +33 -1
  134. package/dist/runtime/types.d.ts.map +1 -1
  135. package/dist/session/cleanup.d.ts.map +1 -1
  136. package/dist/session/cleanup.js +26 -21
  137. package/dist/session/types.d.ts +1 -1
  138. package/dist/session/types.d.ts.map +1 -1
  139. package/dist/storage/createRunDir.d.ts.map +1 -1
  140. package/dist/storage/createRunDir.js +1 -0
  141. package/dist/storage/types.d.ts +14 -0
  142. package/dist/storage/types.d.ts.map +1 -1
  143. package/dist/tasks/defineTask.d.ts +28 -0
  144. package/dist/tasks/defineTask.d.ts.map +1 -1
  145. package/dist/tasks/defineTask.js +42 -1
  146. package/dist/tasks/types.d.ts +18 -3
  147. package/dist/tasks/types.d.ts.map +1 -1
  148. package/package.json +20 -6
@@ -11,6 +11,7 @@ const instrumentation_1 = require("./instrumentation");
11
11
  const registry_1 = require("../tasks/registry");
12
12
  const serializer_1 = require("../tasks/serializer");
13
13
  const tasks_1 = require("../storage/tasks");
14
+ const stateCache_1 = require("./replay/stateCache");
14
15
  async function commitEffectResult(options) {
15
16
  return await (0, lock_1.withRunLock)(options.runDir, "runtime:commitEffectResult", async () => {
16
17
  guardResultPayload(options);
@@ -69,6 +70,7 @@ async function commitEffectResult(options) {
69
70
  stderrRef,
70
71
  resolvedAt: resolvedEvent.recordedAt,
71
72
  });
73
+ await (0, stateCache_1.rebuildStateCache)(options.runDir, { reason: "post_effect_resolution" });
72
74
  (0, instrumentation_1.emitRuntimeMetric)(options.logger, "commit.effect", {
73
75
  effectId: options.effectId,
74
76
  invocationKey: record.invocationKey,
@@ -108,7 +110,7 @@ async function commitEffectCancellation(options) {
108
110
  metadata: { cancelled: true, reason: options.reason },
109
111
  },
110
112
  });
111
- await (0, journal_1.appendEvent)({
113
+ const cancelledEvent = await (0, journal_1.appendEvent)({
112
114
  runDir: options.runDir,
113
115
  eventType: "EFFECT_CANCELLED",
114
116
  event: {
@@ -116,10 +118,11 @@ async function commitEffectCancellation(options) {
116
118
  reason: options.reason,
117
119
  },
118
120
  });
121
+ await (0, stateCache_1.rebuildStateCache)(options.runDir, { reason: "post_effect_cancellation" });
119
122
  registry_1.globalTaskRegistry.resolveEffect(options.effectId, {
120
123
  status: "cancelled",
121
124
  resultRef,
122
- resolvedAt: new Date().toISOString(),
125
+ resolvedAt: cancelledEvent.recordedAt,
123
126
  });
124
127
  (0, instrumentation_1.emitRuntimeMetric)(options.logger, "commit.effect.cancel", {
125
128
  effectId: options.effectId,
@@ -1 +1 @@
1
- {"version":3,"file":"createRun.d.ts","sourceRoot":"","sources":["../../src/runtime/createRun.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAKjE,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAsGnF"}
1
+ {"version":3,"file":"createRun.d.ts","sourceRoot":"","sources":["../../src/runtime/createRun.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAMjE,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAmHnF"}
@@ -14,15 +14,25 @@ const ulids_1 = require("../storage/ulids");
14
14
  const runtime_1 = require("./hooks/runtime");
15
15
  const schemaValidator_1 = require("./schemaValidator");
16
16
  const exceptions_1 = require("./exceptions");
17
+ const config_1 = require("../config");
17
18
  async function createRun(options) {
18
19
  const runId = options.runId ?? (0, ulids_1.nextUlid)();
19
20
  validateRunId(runId);
20
- const runsDir = path_1.default.resolve(options.runsDir);
21
+ const runsDir = path_1.default.resolve(options.runsDir ?? (0, config_1.resolveRunsDir)());
21
22
  const runDir = (0, paths_1.getRunDir)(runsDir, runId);
22
23
  const normalizedEntrypoint = normalizeEntrypoint(runDir, options.process.importPath, options.process.exportName);
23
24
  const requestId = options.request ?? options.process.processId ?? runId;
24
25
  const providedProof = typeof options.metadata?.completionProof === "string" ? options.metadata.completionProof : undefined;
25
26
  const completionProof = providedProof ?? crypto_1.default.randomBytes(16).toString("hex");
27
+ const nestedMetadata = options.nested
28
+ ? {
29
+ parentRunId: options.nested.parentRunId,
30
+ ...(options.nested.parentEffectId ? { parentEffectId: options.nested.parentEffectId } : {}),
31
+ ...(options.nested.parentInvocationKey ? { parentInvocationKey: options.nested.parentInvocationKey } : {}),
32
+ ...(options.nested.sessionId ? { sessionId: options.nested.sessionId } : {}),
33
+ ...(options.nested.shareSession !== undefined ? { shareSession: options.nested.shareSession } : {}),
34
+ }
35
+ : undefined;
26
36
  // Validate inputs against inputSchema if both are provided
27
37
  if (options.inputSchema && options.inputs !== undefined) {
28
38
  const validation = (0, schemaValidator_1.validateAgainstSchema)(options.inputs, options.inputSchema);
@@ -32,6 +42,7 @@ async function createRun(options) {
32
42
  }
33
43
  const extraMetadata = {
34
44
  ...options.metadata,
45
+ ...(options.governance ? { governance: options.governance } : {}),
35
46
  completionProof,
36
47
  };
37
48
  const { metadata } = await (0, createRunDir_1.createRunDir)({
@@ -40,6 +51,7 @@ async function createRun(options) {
40
51
  request: requestId,
41
52
  processId: options.process.processId,
42
53
  harness: options.harness,
54
+ nested: nestedMetadata,
43
55
  processRevision: options.processRevision,
44
56
  layoutVersion: options.layoutVersion,
45
57
  inputs: options.inputs,
@@ -62,6 +74,9 @@ async function createRun(options) {
62
74
  if (metadata.harness) {
63
75
  eventPayload.harness = metadata.harness;
64
76
  }
77
+ if (metadata.nested) {
78
+ eventPayload.nested = metadata.nested;
79
+ }
65
80
  if (metadata.processRevision) {
66
81
  eventPayload.processRevision = metadata.processRevision;
67
82
  }
@@ -86,19 +101,18 @@ async function createRun(options) {
86
101
  const entryString = metadata.entrypoint.exportName
87
102
  ? `${metadata.entrypoint.importPath}#${metadata.entrypoint.exportName}`
88
103
  : metadata.entrypoint.importPath;
89
- // Call hook from project root (parent of .a5c dir) where plugins/ is located
90
- // runDir is like: /path/to/project/.a5c/runs/<runId>
91
- // So we need 3 levels up: runs -> .a5c -> project
92
- const projectRoot = path_1.default.dirname(path_1.default.dirname(path_1.default.dirname(runDir)));
93
- await (0, runtime_1.callRuntimeHook)("on-run-start", {
94
- runId,
95
- processId: metadata.processId,
96
- entry: entryString,
97
- inputs: options.inputs,
98
- }, {
99
- cwd: projectRoot,
100
- logger: options.logger,
101
- });
104
+ const projectRoot = (0, config_1.resolveProjectRootForRun)(runDir, metadata.entrypoint?.importPath);
105
+ if (!options.nested?.skipRunStartHook) {
106
+ await (0, runtime_1.callRuntimeHook)("on-run-start", {
107
+ runId,
108
+ processId: metadata.processId,
109
+ entry: entryString,
110
+ inputs: options.inputs,
111
+ }, {
112
+ cwd: projectRoot,
113
+ logger: options.logger,
114
+ });
115
+ }
102
116
  return {
103
117
  runId,
104
118
  runDir,
@@ -12,6 +12,7 @@ export { ErrorCategory, BabysitterRuntimeError, EffectRequestedError, EffectPend
12
12
  export { replaySchemaVersion } from "./constants";
13
13
  export { applyStrategy } from "./parallelStrategies";
14
14
  export type { ParallelStrategyName, ParallelStrategyOptions, ParallelStrategyResult, } from "./parallelStrategies";
15
- export type { PolicyRuleKind, PolicyConditionOp, PolicyAction, PolicyCondition, PolicyRule, StatefulPolicyRule, PolicyEvaluationContext, PolicyDecision, PolicyDecisionLog, PolicyEngine, PolicyDecisionReporter, } from "./policy";
15
+ export type { PolicyRuleKind, PolicyConditionOp, PolicyAction, PolicyCondition, PolicyRule, StatefulPolicyRule, PolicyEvaluationContext, PolicyDecision, PolicyDecisionLog, PolicyEngine, PolicyDecisionReporter, RuntimeGovernanceConfig, } from "./policy";
16
16
  export { isStatefulRule } from "./policy";
17
+ export { createPolicyEngine, createPolicyDecisionReporter, logPolicyDecision, readPolicyDecisionLog, resolvePolicyDecisionLogDir, matchCondition, } from "./policy";
17
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,yBAAyB,EACzB,2BAA2B,EAC3B,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,eAAe,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,YAAY,EACZ,yBAAyB,EACzB,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,WAAW,EACX,UAAU,EACV,sBAAsB,EACtB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,YAAY,EACV,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM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C;AAC9B,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC5B,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,cAAc,GACf,MAAM,UAAU,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isStatefulRule = exports.applyStrategy = exports.replaySchemaVersion = exports.rehydrateSerializedError = exports.isBabysitterError = exports.isIntrinsicError = exports.toStructuredError = exports.formatNextSteps = exports.formatErrorWithContext = exports.suggestFix = exports.suggestFlag = exports.suggestCommand = exports.RunFailedError = exports.ParallelPendingError = exports.EffectCancelledError = exports.EffectPendingError = exports.EffectRequestedError = exports.BabysitterRuntimeError = exports.ErrorCategory = exports.hashInvocationKey = exports.ReplayCursor = exports.writeStateCache = exports.rebuildStateCache = exports.readStateCache = exports.normalizeSnapshot = exports.normalizeJournalHead = exports.journalHeadsEqual = exports.buildEffectIndex = exports.createStateCacheSnapshot = exports.STATE_CACHE_SCHEMA_VERSION = exports.requireProcessContext = exports.getActiveProcessContext = exports.withProcessContext = exports.createProcessContext = exports.createReplayEngine = exports.commitEffectCancellation = exports.commitEffectResult = exports.orchestrateIteration = exports.createRun = void 0;
3
+ exports.matchCondition = exports.resolvePolicyDecisionLogDir = exports.readPolicyDecisionLog = exports.logPolicyDecision = exports.createPolicyDecisionReporter = exports.createPolicyEngine = exports.isStatefulRule = exports.applyStrategy = exports.replaySchemaVersion = exports.rehydrateSerializedError = exports.isBabysitterError = exports.isIntrinsicError = exports.toStructuredError = exports.formatNextSteps = exports.formatErrorWithContext = exports.suggestFix = exports.suggestFlag = exports.suggestCommand = exports.RunFailedError = exports.ParallelPendingError = exports.EffectCancelledError = exports.EffectPendingError = exports.EffectRequestedError = exports.BabysitterRuntimeError = exports.ErrorCategory = exports.hashInvocationKey = exports.ReplayCursor = exports.writeStateCache = exports.rebuildStateCache = exports.readStateCache = exports.normalizeSnapshot = exports.normalizeJournalHead = exports.journalHeadsEqual = exports.buildEffectIndex = exports.createStateCacheSnapshot = exports.STATE_CACHE_SCHEMA_VERSION = exports.requireProcessContext = exports.getActiveProcessContext = exports.withProcessContext = exports.createProcessContext = exports.createReplayEngine = exports.commitEffectCancellation = exports.commitEffectResult = exports.orchestrateIteration = exports.createRun = void 0;
4
4
  var createRun_1 = require("./createRun");
5
5
  Object.defineProperty(exports, "createRun", { enumerable: true, get: function () { return createRun_1.createRun; } });
6
6
  var orchestrateIteration_1 = require("./orchestrateIteration");
@@ -52,3 +52,10 @@ var parallelStrategies_1 = require("./parallelStrategies");
52
52
  Object.defineProperty(exports, "applyStrategy", { enumerable: true, get: function () { return parallelStrategies_1.applyStrategy; } });
53
53
  var policy_1 = require("./policy");
54
54
  Object.defineProperty(exports, "isStatefulRule", { enumerable: true, get: function () { return policy_1.isStatefulRule; } });
55
+ var policy_2 = require("./policy");
56
+ Object.defineProperty(exports, "createPolicyEngine", { enumerable: true, get: function () { return policy_2.createPolicyEngine; } });
57
+ Object.defineProperty(exports, "createPolicyDecisionReporter", { enumerable: true, get: function () { return policy_2.createPolicyDecisionReporter; } });
58
+ Object.defineProperty(exports, "logPolicyDecision", { enumerable: true, get: function () { return policy_2.logPolicyDecision; } });
59
+ Object.defineProperty(exports, "readPolicyDecisionLog", { enumerable: true, get: function () { return policy_2.readPolicyDecisionLog; } });
60
+ Object.defineProperty(exports, "resolvePolicyDecisionLogDir", { enumerable: true, get: function () { return policy_2.resolvePolicyDecisionLogDir; } });
61
+ Object.defineProperty(exports, "matchCondition", { enumerable: true, get: function () { return policy_2.matchCondition; } });
@@ -0,0 +1,5 @@
1
+ import { TaskInvokeOptions } from "../../tasks/types";
2
+ import { SubprocessInvocation, SubprocessResult } from "../types";
3
+ import { TaskIntrinsicContext } from "./task";
4
+ export declare function runSubprocessIntrinsic(invocation: SubprocessInvocation, context: TaskIntrinsicContext, options?: TaskInvokeOptions): Promise<SubprocessResult>;
5
+ //# sourceMappingURL=subprocess.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subprocess.d.ts","sourceRoot":"","sources":["../../../src/runtime/intrinsics/subprocess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAElE,OAAO,EAAoB,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AA6ChE,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,oBAAoB,EAChC,OAAO,EAAE,oBAAoB,EAC7B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,gBAAgB,CAAC,CAkB3B"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSubprocessIntrinsic = runSubprocessIntrinsic;
4
+ const exceptions_1 = require("../exceptions");
5
+ const task_1 = require("./task");
6
+ const SUBPROCESS_TASK_ID = "__sdk.subprocess";
7
+ const subprocessTask = {
8
+ id: SUBPROCESS_TASK_ID,
9
+ build(args) {
10
+ const invocation = args.invocation;
11
+ const subprocess = {
12
+ processPath: invocation.processPath,
13
+ exportName: invocation.exportName,
14
+ processId: invocation.processId,
15
+ prompt: invocation.prompt,
16
+ inputs: invocation.inputs,
17
+ inputSchema: invocation.inputSchema,
18
+ outputSchema: invocation.outputSchema,
19
+ harness: invocation.harness,
20
+ model: invocation.model,
21
+ maxIterations: invocation.maxIterations,
22
+ shareSession: invocation.shareSession !== false,
23
+ metadata: invocation.metadata,
24
+ };
25
+ return {
26
+ kind: "subprocess",
27
+ title: args.label,
28
+ metadata: {
29
+ subprocess: true,
30
+ processPath: invocation.processPath,
31
+ processId: invocation.processId,
32
+ harness: invocation.harness,
33
+ model: invocation.model,
34
+ maxIterations: invocation.maxIterations,
35
+ shareSession: invocation.shareSession !== false,
36
+ },
37
+ subprocess,
38
+ };
39
+ },
40
+ };
41
+ function runSubprocessIntrinsic(invocation, context, options) {
42
+ if (context.subprocessSupport !== "babysitter-agent") {
43
+ throw new exceptions_1.RunFailedError("Subprocess effects are only supported when the run is iterated by babysitter-agent.", {
44
+ runId: context.runId,
45
+ processId: context.processId,
46
+ subprocessSupport: context.subprocessSupport ?? "disabled",
47
+ });
48
+ }
49
+ const label = options?.label ?? invocation.processId ?? invocation.processPath;
50
+ return (0, task_1.runTaskIntrinsic)({
51
+ task: subprocessTask,
52
+ args: { invocation, label },
53
+ invokeOptions: { ...options, label },
54
+ context,
55
+ });
56
+ }
@@ -12,6 +12,7 @@ export interface TaskIntrinsicContext {
12
12
  replayCursor: ReplayCursor;
13
13
  now: () => Date;
14
14
  logger?: ProcessLogger;
15
+ subprocessSupport?: "disabled" | "babysitter-agent";
15
16
  policyEngine?: PolicyEngine;
16
17
  reportPolicyDecision?: PolicyDecisionReporter;
17
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../../src/runtime/intrinsics/task.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EACV,WAAW,EAEX,aAAa,EAEb,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAOlB,OAAO,KAAK,EACV,sBAAsB,EACtB,YAAY,EAEb,MAAM,iBAAiB,CAAC;AASzB,wBAAgB,wBAAwB,IAAI,MAAM,CAAmC;AACrF,wBAAgB,0BAA0B,IAAI,IAAI,CAAgC;AAElF,MAAM,WAAW,oBAAoB;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W,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;IAC3B,GAAG,EAAE,MAAM,IAAI,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,iBAAiB,CAAC,EAAE,UAAU,GAAG,kBAAkB,CAAC;IACpD,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,oBAAoB,CAAC,EAAE,sBAAsB,CAAC;CAC/C;AAED,MAAM,WAAW,0BAA0B,CAAC,KAAK,EAAE,OAAO;IACxD,IAAI,EAAE,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAClC,IAAI,EAAE,KAAK,CAAC;IACZ,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EACnD,OAAO,EAAE,0BAA0B,CAAC,KAAK,EAAE,OAAO,CAAC,GAClD,OAAO,CAAC,OAAO,CAAC,CAmBlB"}
@@ -1 +1 @@
1
- {"version":3,"file":"orchestrateIteration.d.ts","sourceRoot":"","sources":["../../src/runtime/orchestrateIteration.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAGnB,MAAM,SAAS,CAAC;AAajB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAWvD,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,CAsGhG"}
1
+ {"version":3,"file":"orchestrateIteration.d.ts","sourceRoot":"","sources":["../../src/runtime/orchestrateIteration.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAGnB,MAAM,SAAS,CAAC;AAcjB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAWvD,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,CAsGhG"}
@@ -54,6 +54,7 @@ const errorUtils_1 = require("./errorUtils");
54
54
  const instrumentation_1 = require("./instrumentation");
55
55
  const runtime_1 = require("./hooks/runtime");
56
56
  const task_1 = require("./intrinsics/task");
57
+ const config_1 = require("../config");
57
58
  const orchestrateHelpers_1 = require("./orchestrateHelpers");
58
59
  // Re-export for backward compatibility
59
60
  var orchestrateHelpers_2 = require("./orchestrateHelpers");
@@ -78,7 +79,7 @@ async function orchestrateIteration(options) {
78
79
  const inputs = options.inputs ?? engine.inputs;
79
80
  let finalStatus = "failed";
80
81
  const logger = engine.internalContext.logger ?? options.logger;
81
- const projectRoot = path_1.default.dirname(path_1.default.dirname(path_1.default.dirname(options.runDir)));
82
+ const projectRoot = (0, config_1.resolveProjectRootForRun)(options.runDir, engine.metadata.entrypoint?.importPath);
82
83
  await (0, runtime_1.callRuntimeHook)("on-iteration-start", { runId: engine.runId, iteration: engine.replayCursor.value }, { cwd: projectRoot, logger });
83
84
  let capturedStrayEffect = null;
84
85
  const strayEffectHandler = (reason) => { if ((0, orchestrateHelpers_1.asWaitingResult)(reason))
@@ -195,7 +196,12 @@ async function loadProcessFunction(options, defaults, runDir) {
195
196
  }
196
197
  async function initializeReplayEngine(options, nowFn, iterationStartedAt) {
197
198
  try {
198
- return await (0, createReplayEngine_1.createReplayEngine)({ runDir: options.runDir, now: nowFn, logger: options.logger });
199
+ return await (0, createReplayEngine_1.createReplayEngine)({
200
+ runDir: options.runDir,
201
+ now: nowFn,
202
+ logger: options.logger,
203
+ subprocessSupport: options.subprocessSupport,
204
+ });
199
205
  }
200
206
  catch (error) {
201
207
  (0, instrumentation_1.emitRuntimeMetric)(options.logger, "replay.iteration", { duration_ms: Date.now() - iterationStartedAt, status: "failed", runDir: options.runDir, phase: "initialize", error: error instanceof Error ? error.message : String(error) });
@@ -0,0 +1,4 @@
1
+ import type { PolicyRule, PolicyCondition, PolicyEvaluationContext, PolicyEngine } from "./types";
2
+ export declare function matchCondition(condition: PolicyCondition, context: PolicyEvaluationContext): boolean;
3
+ export declare function createPolicyEngine(rules: PolicyRule[]): PolicyEngine;
4
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/runtime/policy/engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EACf,uBAAuB,EAEvB,YAAY,EACb,MAAM,SAAS,CAAC;AAejB,wBAAgB,cAAc,CAAC,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAkCpG;AASD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,YAAY,CA6CpE"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchCondition = matchCondition;
4
+ exports.createPolicyEngine = createPolicyEngine;
5
+ const types_1 = require("./types");
6
+ function resolveField(context, fieldPath) {
7
+ const parts = fieldPath.split(".");
8
+ let current = context;
9
+ for (const part of parts) {
10
+ if (current == null || typeof current !== "object") {
11
+ return undefined;
12
+ }
13
+ current = current[part];
14
+ }
15
+ return current;
16
+ }
17
+ function matchCondition(condition, context) {
18
+ const fieldValue = resolveField(context, condition.field);
19
+ if (fieldValue === undefined || fieldValue === null) {
20
+ return false;
21
+ }
22
+ switch (condition.op) {
23
+ case "eq":
24
+ return String(fieldValue) === condition.value;
25
+ case "neq":
26
+ return String(fieldValue) !== condition.value;
27
+ case "gt":
28
+ return typeof fieldValue === "number" && fieldValue > Number(condition.value);
29
+ case "lt":
30
+ return typeof fieldValue === "number" && fieldValue < Number(condition.value);
31
+ case "gte":
32
+ return typeof fieldValue === "number" && fieldValue >= Number(condition.value);
33
+ case "lte":
34
+ return typeof fieldValue === "number" && fieldValue <= Number(condition.value);
35
+ case "contains":
36
+ if (Array.isArray(fieldValue)) {
37
+ return fieldValue.includes(condition.value);
38
+ }
39
+ return String(fieldValue).includes(condition.value);
40
+ case "matches":
41
+ try {
42
+ return new RegExp(condition.value).test(String(fieldValue));
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ default:
48
+ return false;
49
+ }
50
+ }
51
+ function ruleMatches(rule, context) {
52
+ if ((0, types_1.isStatefulRule)(rule)) {
53
+ return rule.shouldMatch(context);
54
+ }
55
+ return matchCondition(rule.condition, context);
56
+ }
57
+ function createPolicyEngine(rules) {
58
+ const denyRules = rules.filter((rule) => rule.action === "deny").sort((a, b) => b.priority - a.priority);
59
+ const warnRules = rules.filter((rule) => rule.action === "warn").sort((a, b) => b.priority - a.priority);
60
+ const allowRules = rules.filter((rule) => rule.action === "allow").sort((a, b) => b.priority - a.priority);
61
+ return {
62
+ rules: Object.freeze([...rules]),
63
+ evaluate(context) {
64
+ const warnings = [];
65
+ for (const rule of denyRules) {
66
+ if (ruleMatches(rule, context)) {
67
+ return {
68
+ allowed: false,
69
+ rule,
70
+ reason: `Denied by rule ${rule.id}`,
71
+ warnings,
72
+ };
73
+ }
74
+ }
75
+ for (const rule of warnRules) {
76
+ if (ruleMatches(rule, context)) {
77
+ warnings.push(`Warning from rule ${rule.id}: ${rule.metadata?.reason ?? rule.kind}`);
78
+ }
79
+ }
80
+ for (const rule of allowRules) {
81
+ if (ruleMatches(rule, context)) {
82
+ return {
83
+ allowed: true,
84
+ rule,
85
+ reason: `Allowed by rule ${rule.id}`,
86
+ warnings,
87
+ };
88
+ }
89
+ }
90
+ return {
91
+ allowed: true,
92
+ reason: "Allowed by default policy",
93
+ warnings,
94
+ };
95
+ },
96
+ };
97
+ }
@@ -1,3 +1,5 @@
1
- export type { PolicyRuleKind, PolicyConditionOp, PolicyAction, PolicyCondition, PolicyRule, StatefulPolicyRule, PolicyEvaluationContext, PolicyDecision, PolicyDecisionLog, PolicyEngine, PolicyDecisionReporter, } from "./types";
1
+ export type { PolicyRuleKind, PolicyConditionOp, PolicyAction, PolicyCondition, PolicyRule, StatefulPolicyRule, PolicyEvaluationContext, PolicyDecision, PolicyDecisionLog, PolicyEngine, PolicyDecisionReporter, RuntimeGovernanceConfig, } from "./types";
2
2
  export { isStatefulRule } from "./types";
3
+ export { createPolicyEngine, matchCondition } from "./engine";
4
+ export { createPolicyDecisionReporter, logPolicyDecision, readPolicyDecisionLog, resolvePolicyDecisionLogDir, } from "./logging";
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/policy/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,sBAAsB,GACvB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/policy/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,WAAW,CAAC"}
@@ -1,5 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isStatefulRule = void 0;
3
+ exports.resolvePolicyDecisionLogDir = exports.readPolicyDecisionLog = exports.logPolicyDecision = exports.createPolicyDecisionReporter = exports.matchCondition = exports.createPolicyEngine = exports.isStatefulRule = void 0;
4
4
  var types_1 = require("./types");
5
5
  Object.defineProperty(exports, "isStatefulRule", { enumerable: true, get: function () { return types_1.isStatefulRule; } });
6
+ var engine_1 = require("./engine");
7
+ Object.defineProperty(exports, "createPolicyEngine", { enumerable: true, get: function () { return engine_1.createPolicyEngine; } });
8
+ Object.defineProperty(exports, "matchCondition", { enumerable: true, get: function () { return engine_1.matchCondition; } });
9
+ var logging_1 = require("./logging");
10
+ Object.defineProperty(exports, "createPolicyDecisionReporter", { enumerable: true, get: function () { return logging_1.createPolicyDecisionReporter; } });
11
+ Object.defineProperty(exports, "logPolicyDecision", { enumerable: true, get: function () { return logging_1.logPolicyDecision; } });
12
+ Object.defineProperty(exports, "readPolicyDecisionLog", { enumerable: true, get: function () { return logging_1.readPolicyDecisionLog; } });
13
+ Object.defineProperty(exports, "resolvePolicyDecisionLogDir", { enumerable: true, get: function () { return logging_1.resolvePolicyDecisionLogDir; } });
@@ -0,0 +1,6 @@
1
+ import type { PolicyDecisionLog, PolicyDecisionReporter, RuntimeGovernanceConfig } from "./types";
2
+ export declare function resolvePolicyDecisionLogDir(runId: string, governance?: RuntimeGovernanceConfig): string;
3
+ export declare function logPolicyDecision(logDir: string, entry: PolicyDecisionLog): Promise<void>;
4
+ export declare function readPolicyDecisionLog(logDir: string): Promise<PolicyDecisionLog[]>;
5
+ export declare function createPolicyDecisionReporter(runId: string, governance?: RuntimeGovernanceConfig): PolicyDecisionReporter;
6
+ //# sourceMappingURL=logging.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../../src/runtime/policy/logging.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAIjB,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,uBAAuB,GAAG,MAAM,CAGvG;AAED,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG/F;AAED,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAcxF;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,uBAAuB,GACnC,sBAAsB,CAKxB"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolvePolicyDecisionLogDir = resolvePolicyDecisionLogDir;
7
+ exports.logPolicyDecision = logPolicyDecision;
8
+ exports.readPolicyDecisionLog = readPolicyDecisionLog;
9
+ exports.createPolicyDecisionReporter = createPolicyDecisionReporter;
10
+ const node_fs_1 = require("node:fs");
11
+ const node_path_1 = __importDefault(require("node:path"));
12
+ const config_1 = require("../../config");
13
+ const LOG_FILENAME = "governance-decisions.jsonl";
14
+ function resolvePolicyDecisionLogDir(runId, governance) {
15
+ const logRoot = governance?.auditLogDir ? node_path_1.default.resolve(governance.auditLogDir) : (0, config_1.getGlobalLogDir)();
16
+ return node_path_1.default.join(logRoot, runId);
17
+ }
18
+ async function logPolicyDecision(logDir, entry) {
19
+ await node_fs_1.promises.mkdir(logDir, { recursive: true });
20
+ await node_fs_1.promises.appendFile(node_path_1.default.join(logDir, LOG_FILENAME), JSON.stringify(entry) + "\n", "utf8");
21
+ }
22
+ async function readPolicyDecisionLog(logDir) {
23
+ try {
24
+ const content = await node_fs_1.promises.readFile(node_path_1.default.join(logDir, LOG_FILENAME), "utf8");
25
+ return content
26
+ .split("\n")
27
+ .filter((line) => line.trim().length > 0)
28
+ .map((line) => JSON.parse(line));
29
+ }
30
+ catch (error) {
31
+ const err = error;
32
+ if (err.code === "ENOENT") {
33
+ return [];
34
+ }
35
+ throw error;
36
+ }
37
+ }
38
+ function createPolicyDecisionReporter(runId, governance) {
39
+ const logDir = resolvePolicyDecisionLogDir(runId, governance);
40
+ return async (entry) => {
41
+ await logPolicyDecision(logDir, entry);
42
+ };
43
+ }
@@ -48,4 +48,8 @@ export interface PolicyEngine {
48
48
  evaluate(context: PolicyEvaluationContext): PolicyDecision;
49
49
  }
50
50
  export type PolicyDecisionReporter = (entry: PolicyDecisionLog) => void | Promise<void>;
51
+ export interface RuntimeGovernanceConfig {
52
+ policyRules?: PolicyRule[];
53
+ auditLogDir?: string;
54
+ }
51
55
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/runtime/policy/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,YAAY,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAC5F,MAAM,MAAM,iBAAiB,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,GAAG,UAAU,GAAG,SAAS,CAAC;AACpG,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AAErD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,iBAAiB,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,cAAc,CAAC;IACrB,SAAS,EAAE,eAAe,CAAC;IAC3B,MAAM,EAAE,YAAY,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,kBAAmB,SAAQ,UAAU;IACpD,WAAW,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC;CACxD;AAED,wBAAg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AAuB,CAAC;IACjC,QAAQ,EAAE,cAAc,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,uBAAuB,GAAG,cAAc,CAAC;CAC5D;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAExF,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
@@ -11,6 +11,8 @@ export interface ProcessContextInit extends Omit<TaskIntrinsicContext, "now"> {
11
11
  recordedLogSeqs?: Set<number>;
12
12
  /** When true, breakpoints are auto-approved without human interaction. */
13
13
  nonInteractive?: boolean;
14
+ /** Internal-only gate for babysitter-agent owned subprocess orchestration. */
15
+ subprocessSupport?: "disabled" | "babysitter-agent";
14
16
  }
15
17
  export interface InternalProcessContext extends TaskIntrinsicContext {
16
18
  processId: string;
@@ -21,6 +23,7 @@ export interface InternalProcessContext extends TaskIntrinsicContext {
21
23
  recordedLogSeqs: Set<number>;
22
24
  /** When true, breakpoints are auto-approved without human interaction. */
23
25
  nonInteractive: boolean;
26
+ subprocessSupport: "disabled" | "babysitter-agent";
24
27
  }
25
28
  export interface CreateProcessContextResult {
26
29
  context: ProcessContext;
@@ -1 +1 @@
1
- {"version":3,"file":"processContext.d.ts","sourceRoot":"","sources":["../../src/runtime/processContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAO3E,OAAO,EAAE,cAAc,EAAmB,MAAM,SAAS,CAAC;AAM1D,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC;IAC3E,SAAS,EAAE,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C,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,0EAA0E;IAC1E,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,8EAA8E;IAC9E,iBAAiB,CAAC,EAAE,UAAU,GAAG,kBAAkB,CAAC;CACrD;AAED,MAAM,WAAW,sBAAuB,SAAQ,oBAAoB;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,IAAI,CAAC;IAChB,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,0EAA0E;IAC1E,cAAc,EAAE,OAAO,CAAC;IACxB,iBAAiB,EAAE,UAAU,GAAG,kBAAkB,CAAC;CACpD;AAID,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,cAAc,CAAC;IACxB,eAAe,EAAE,sBAAsB,CAAC;CACzC;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,kBAAkB,GAAG,0BAA0B,CAuGzF;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,QAAQ,EAAE,sBAAsB,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE5G;AAED,wBAAgB,uBAAuB,IAAI,sBAAsB,GAAG,SAAS,CAE5E;AAED,wBAAgB,qBAAqB,IAAI,sBAAsB,CAM9D"}
@@ -42,6 +42,7 @@ const task_1 = require("./intrinsics/task");
42
42
  const breakpoint_1 = require("./intrinsics/breakpoint");
43
43
  const sleep_1 = require("./intrinsics/sleep");
44
44
  const orchestratorTask_1 = require("./intrinsics/orchestratorTask");
45
+ const subprocess_1 = require("./intrinsics/subprocess");
45
46
  const hook_1 = require("./intrinsics/hook");
46
47
  const dispatcher_1 = require("../hooks/dispatcher");
47
48
  const parallel_1 = require("./intrinsics/parallel");
@@ -59,6 +60,7 @@ function createProcessContext(init) {
59
60
  logSeq: 0,
60
61
  recordedLogSeqs: init.recordedLogSeqs ?? new Set(),
61
62
  nonInteractive: init.nonInteractive ?? false,
63
+ subprocessSupport: init.subprocessSupport ?? "disabled",
62
64
  };
63
65
  const parallelHelpers = {
64
66
  all: (thunks) => (0, parallel_1.runParallelAll)(thunks),
@@ -75,6 +77,7 @@ function createProcessContext(init) {
75
77
  breakpoint: (payload, options) => (0, breakpoint_1.runBreakpointIntrinsic)(payload, internal, options),
76
78
  sleepUntil: (target, options) => (0, sleep_1.runSleepIntrinsic)(target, internal, options),
77
79
  orchestratorTask: (payload, options) => (0, orchestratorTask_1.runOrchestratorTaskIntrinsic)(payload, internal, options),
80
+ subprocess: (invocation, options) => (0, subprocess_1.runSubprocessIntrinsic)(invocation, internal, options),
78
81
  hook: (hookType, payload, options) => (0, hook_1.runHookIntrinsic)(hookType, payload, internal, options),
79
82
  parallel: parallelHelpers,
80
83
  // Always provide a callable logger to processes so `ctx.log(...)` never throws.
@@ -8,6 +8,7 @@ export interface CreateReplayEngineOptions {
8
8
  runDir: string;
9
9
  now?: () => Date;
10
10
  logger?: (...args: any[]) => void;
11
+ subprocessSupport?: "disabled" | "babysitter-agent";
11
12
  }
12
13
  export interface ReplayEngine {
13
14
  runId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"createReplayEngine.d.ts","sourceRoot":"","sources":["../../../src/runtime/replay/createReplayEngine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAgB,MAAM,qBAAqB,CAAC;AAIhE,OAAO,EAAoB,WAAW,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAwB,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAGjF,OAAO,EAAwD,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAExG,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,MAA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AI,CAAC;IAEjB,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAClC,iBAAiB,CAAC,EAAE,UAAU,GAAG,kBAAkB,CAAC;CACrD;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,WAAW,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,eAAe,EAAE,sBAAsB,CAAC;IACxC,UAAU,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACvC,YAAY,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;CAC3F;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,YAAY,CAAC,CAmElG"}
@@ -44,6 +44,7 @@ const processContext_1 = require("../processContext");
44
44
  const constants_1 = require("../constants");
45
45
  const exceptions_1 = require("../exceptions");
46
46
  const stateCache_1 = require("./stateCache");
47
+ const policy_1 = require("../policy");
47
48
  async function createReplayEngine(options) {
48
49
  const metadata = await (0, runFiles_1.readRunMetadata)(options.runDir);
49
50
  ensureCompatibleLayout(metadata.layoutVersion, options.runDir);
@@ -76,6 +77,11 @@ async function createReplayEngine(options) {
76
77
  const recordedLogSeqs = await readRecordedLogSeqs(options.runDir);
77
78
  const replayCursor = new replayCursor_1.ReplayCursor();
78
79
  const processId = metadata.processId ?? metadata.request ?? metadata.runId;
80
+ const governance = readRuntimeGovernanceConfig(metadata);
81
+ const policyEngine = governance ? (0, policy_1.createPolicyEngine)(governance.policyRules ?? []) : undefined;
82
+ const reportPolicyDecision = governance
83
+ ? (0, policy_1.createPolicyDecisionReporter)(metadata.runId, governance)
84
+ : undefined;
79
85
  const { context, internalContext } = (0, processContext_1.createProcessContext)({
80
86
  runId: metadata.runId,
81
87
  runDir: options.runDir,
@@ -86,6 +92,9 @@ async function createReplayEngine(options) {
86
92
  logger: options.logger,
87
93
  recordedLogSeqs,
88
94
  nonInteractive: Boolean(metadata.nonInteractive),
95
+ subprocessSupport: options.subprocessSupport,
96
+ policyEngine,
97
+ reportPolicyDecision,
89
98
  });
90
99
  return {
91
100
  runId: metadata.runId,
@@ -161,3 +170,20 @@ function ensureCompatibleLayout(layoutVersion, runDir) {
161
170
  });
162
171
  }
163
172
  }
173
+ function readRuntimeGovernanceConfig(metadata) {
174
+ const candidate = metadata.governance;
175
+ if (!candidate || typeof candidate !== "object" || Array.isArray(candidate)) {
176
+ return undefined;
177
+ }
178
+ const record = candidate;
179
+ const policyRules = Array.isArray(record.policyRules)
180
+ ? record.policyRules.filter((rule) => (Boolean(rule) && typeof rule === "object" && !Array.isArray(rule)))
181
+ : undefined;
182
+ const auditLogDir = typeof record.auditLogDir === "string" && record.auditLogDir.trim()
183
+ ? record.auditLogDir
184
+ : undefined;
185
+ return {
186
+ ...(policyRules ? { policyRules } : {}),
187
+ ...(auditLogDir ? { auditLogDir } : {}),
188
+ };
189
+ }