agentplane 0.3.8 → 0.3.10

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 (268) hide show
  1. package/assets/AGENTS.md +4 -2
  2. package/assets/agents/CODER.json +1 -1
  3. package/assets/policy/dod.core.md +1 -1
  4. package/assets/policy/governance.md +3 -0
  5. package/assets/policy/incidents.md +22 -11
  6. package/assets/policy/workflow.branch_pr.md +2 -0
  7. package/assets/policy/workflow.direct.md +3 -1
  8. package/dist/.build-manifest.json +323 -128
  9. package/dist/cli/bootstrap-guide.d.ts +1 -0
  10. package/dist/cli/bootstrap-guide.d.ts.map +1 -1
  11. package/dist/cli/bootstrap-guide.js +19 -1
  12. package/dist/cli/command-invocations.d.ts.map +1 -1
  13. package/dist/cli/command-invocations.js +2 -0
  14. package/dist/cli/command-snippets.d.ts +2 -0
  15. package/dist/cli/command-snippets.d.ts.map +1 -1
  16. package/dist/cli/command-snippets.js +2 -0
  17. package/dist/cli/run-cli/command-catalog/core.d.ts +1 -1
  18. package/dist/cli/run-cli/command-catalog/core.d.ts.map +1 -1
  19. package/dist/cli/run-cli/command-catalog/core.js +10 -0
  20. package/dist/cli/run-cli/command-catalog.d.ts +1 -1
  21. package/dist/cli/run-cli/command-catalog.d.ts.map +1 -1
  22. package/dist/cli/run-cli/commands/config.d.ts.map +1 -1
  23. package/dist/cli/run-cli/commands/config.js +13 -0
  24. package/dist/cli/run-cli.js +2 -2
  25. package/dist/cli/run-cli.test-helpers.d.ts.map +1 -1
  26. package/dist/cli/run-cli.test-helpers.js +34 -8
  27. package/dist/commands/backend.d.ts.map +1 -1
  28. package/dist/commands/backend.js +4 -0
  29. package/dist/commands/hooks/index.d.ts.map +1 -1
  30. package/dist/commands/hooks/index.js +8 -4
  31. package/dist/commands/incidents/advise.command.d.ts +15 -0
  32. package/dist/commands/incidents/advise.command.d.ts.map +1 -0
  33. package/dist/commands/incidents/advise.command.js +139 -0
  34. package/dist/commands/incidents/collect.command.d.ts +11 -0
  35. package/dist/commands/incidents/collect.command.d.ts.map +1 -0
  36. package/dist/commands/incidents/collect.command.js +67 -0
  37. package/dist/commands/incidents/incidents.command.d.ts +5 -0
  38. package/dist/commands/incidents/incidents.command.d.ts.map +1 -0
  39. package/dist/commands/incidents/incidents.command.js +21 -0
  40. package/dist/commands/incidents/shared.d.ts +42 -0
  41. package/dist/commands/incidents/shared.d.ts.map +1 -0
  42. package/dist/commands/incidents/shared.js +107 -0
  43. package/dist/commands/pr/check.d.ts.map +1 -1
  44. package/dist/commands/pr/check.js +73 -2
  45. package/dist/commands/pr/integrate/cmd.d.ts.map +1 -1
  46. package/dist/commands/pr/integrate/cmd.js +4 -0
  47. package/dist/commands/pr/integrate/internal/merge.d.ts +4 -0
  48. package/dist/commands/pr/integrate/internal/merge.d.ts.map +1 -1
  49. package/dist/commands/pr/integrate/internal/merge.js +23 -2
  50. package/dist/commands/pr/integrate/internal/prepare.d.ts.map +1 -1
  51. package/dist/commands/pr/integrate/internal/prepare.js +26 -1
  52. package/dist/commands/pr/internal/note-store.d.ts +18 -0
  53. package/dist/commands/pr/internal/note-store.d.ts.map +1 -0
  54. package/dist/commands/pr/internal/note-store.js +66 -0
  55. package/dist/commands/pr/internal/pr-paths.d.ts +3 -0
  56. package/dist/commands/pr/internal/pr-paths.d.ts.map +1 -1
  57. package/dist/commands/pr/internal/pr-paths.js +3 -0
  58. package/dist/commands/pr/internal/review-template.d.ts +24 -4
  59. package/dist/commands/pr/internal/review-template.d.ts.map +1 -1
  60. package/dist/commands/pr/internal/review-template.js +188 -33
  61. package/dist/commands/pr/internal/sync.d.ts +32 -0
  62. package/dist/commands/pr/internal/sync.d.ts.map +1 -0
  63. package/dist/commands/pr/internal/sync.js +258 -0
  64. package/dist/commands/pr/note.d.ts.map +1 -1
  65. package/dist/commands/pr/note.js +37 -4
  66. package/dist/commands/pr/open.d.ts.map +1 -1
  67. package/dist/commands/pr/open.js +7 -54
  68. package/dist/commands/pr/pr.command.d.ts.map +1 -1
  69. package/dist/commands/pr/pr.command.js +6 -3
  70. package/dist/commands/pr/update.d.ts.map +1 -1
  71. package/dist/commands/pr/update.js +5 -79
  72. package/dist/commands/recipes/impl/apply.d.ts +1 -1
  73. package/dist/commands/recipes/impl/apply.d.ts.map +1 -1
  74. package/dist/commands/recipes/impl/apply.js +1 -1
  75. package/dist/commands/recipes/impl/commands/cache-prune.d.ts.map +1 -1
  76. package/dist/commands/recipes/impl/commands/cache-prune.js +14 -0
  77. package/dist/commands/recipes/impl/commands/explain.js +1 -1
  78. package/dist/commands/recipes/impl/commands/install.d.ts.map +1 -1
  79. package/dist/commands/recipes/impl/commands/install.js +3 -2
  80. package/dist/commands/recipes/impl/commands/list-remote.d.ts.map +1 -1
  81. package/dist/commands/recipes/impl/commands/list-remote.js +1 -0
  82. package/dist/commands/recipes/impl/commands/remove.d.ts.map +1 -1
  83. package/dist/commands/recipes/impl/commands/remove.js +9 -1
  84. package/dist/commands/recipes/impl/installed-recipes.d.ts +1 -1
  85. package/dist/commands/recipes/impl/installed-recipes.d.ts.map +1 -1
  86. package/dist/commands/recipes/impl/installed-recipes.js +2 -1
  87. package/dist/commands/recipes/impl/project-installed-recipes.d.ts +1 -1
  88. package/dist/commands/recipes/impl/project-installed-recipes.d.ts.map +1 -1
  89. package/dist/commands/recipes/impl/project-installed-recipes.js +2 -1
  90. package/dist/commands/recipes/impl/resolver.d.ts +1 -1
  91. package/dist/commands/recipes/impl/resolver.d.ts.map +1 -1
  92. package/dist/commands/recipes/impl/resolver.js +1 -1
  93. package/dist/commands/recipes.d.ts +4 -4
  94. package/dist/commands/recipes.d.ts.map +1 -1
  95. package/dist/commands/recipes.js +3 -3
  96. package/dist/commands/release/apply.command.d.ts.map +1 -1
  97. package/dist/commands/release/apply.command.js +9 -0
  98. package/dist/commands/release.test-helpers.d.ts +14 -0
  99. package/dist/commands/release.test-helpers.d.ts.map +1 -1
  100. package/dist/commands/release.test-helpers.js +14 -3
  101. package/dist/commands/shared/approval-requirements.d.ts +5 -7
  102. package/dist/commands/shared/approval-requirements.d.ts.map +1 -1
  103. package/dist/commands/shared/approval-requirements.js +3 -73
  104. package/dist/commands/shared/network-approval.d.ts +2 -0
  105. package/dist/commands/shared/network-approval.d.ts.map +1 -1
  106. package/dist/commands/shared/network-approval.js +1 -1
  107. package/dist/commands/shared/pr-meta.d.ts +9 -0
  108. package/dist/commands/shared/pr-meta.d.ts.map +1 -1
  109. package/dist/commands/shared/pr-meta.js +27 -3
  110. package/dist/commands/shared/task-backend.d.ts +2 -0
  111. package/dist/commands/shared/task-backend.d.ts.map +1 -1
  112. package/dist/commands/shared/task-local-freshness.d.ts +13 -0
  113. package/dist/commands/shared/task-local-freshness.d.ts.map +1 -0
  114. package/dist/commands/shared/task-local-freshness.js +20 -0
  115. package/dist/commands/shared/task-mutation.d.ts +2 -0
  116. package/dist/commands/shared/task-mutation.d.ts.map +1 -1
  117. package/dist/commands/shared/task-mutation.js +7 -0
  118. package/dist/commands/task/block.d.ts.map +1 -1
  119. package/dist/commands/task/block.js +1 -0
  120. package/dist/commands/task/close-shared.d.ts.map +1 -1
  121. package/dist/commands/task/close-shared.js +1 -0
  122. package/dist/commands/task/finish-shared.d.ts.map +1 -1
  123. package/dist/commands/task/finish-shared.js +5 -2
  124. package/dist/commands/task/finish.d.ts.map +1 -1
  125. package/dist/commands/task/finish.js +24 -0
  126. package/dist/commands/task/new.d.ts.map +1 -1
  127. package/dist/commands/task/new.js +69 -29
  128. package/dist/commands/task/set-status.d.ts.map +1 -1
  129. package/dist/commands/task/set-status.js +1 -0
  130. package/dist/commands/task/shared/transition-command.d.ts +2 -0
  131. package/dist/commands/task/shared/transition-command.d.ts.map +1 -1
  132. package/dist/commands/task/shared/transition-command.js +1 -0
  133. package/dist/commands/task/start-ready.d.ts.map +1 -1
  134. package/dist/commands/task/start-ready.js +12 -1
  135. package/dist/commands/task/start.d.ts.map +1 -1
  136. package/dist/commands/task/start.js +11 -0
  137. package/dist/commands/task/verify-record.d.ts.map +1 -1
  138. package/dist/commands/task/verify-record.js +27 -0
  139. package/dist/commands/upgrade.d.ts.map +1 -1
  140. package/dist/commands/upgrade.js +6 -1
  141. package/dist/policy/engine.d.ts +3 -1
  142. package/dist/policy/engine.d.ts.map +1 -1
  143. package/dist/policy/engine.js +5 -6
  144. package/dist/policy/taxonomy.d.ts +17 -0
  145. package/dist/policy/taxonomy.d.ts.map +1 -0
  146. package/dist/policy/taxonomy.js +302 -0
  147. package/dist/policy/types.d.ts +2 -1
  148. package/dist/policy/types.d.ts.map +1 -1
  149. package/dist/runner/artifacts.d.ts.map +1 -1
  150. package/dist/runner/artifacts.js +2 -0
  151. package/dist/runner/context/base-prompts.d.ts +25 -0
  152. package/dist/runner/context/base-prompts.d.ts.map +1 -1
  153. package/dist/runner/context/base-prompts.js +182 -54
  154. package/dist/runner/context/recipe-context.d.ts.map +1 -1
  155. package/dist/runner/context/recipe-context.js +5 -0
  156. package/dist/runner/types.d.ts +12 -0
  157. package/dist/runner/types.d.ts.map +1 -1
  158. package/dist/runner/usecases/scenario-materialize-task.d.ts.map +1 -1
  159. package/dist/runner/usecases/scenario-materialize-task.js +81 -11
  160. package/dist/runner/usecases/task-run-inspect.d.ts.map +1 -1
  161. package/dist/runner/usecases/task-run-inspect.js +9 -7
  162. package/dist/runner/usecases/task-run-lifecycle-shared.d.ts.map +1 -1
  163. package/dist/runner/usecases/task-run-lifecycle-shared.js +8 -6
  164. package/dist/runner/usecases/task-run.d.ts.map +1 -1
  165. package/dist/runner/usecases/task-run.js +59 -12
  166. package/dist/runtime/approvals/index.d.ts +3 -0
  167. package/dist/runtime/approvals/index.d.ts.map +1 -0
  168. package/dist/runtime/approvals/index.js +1 -0
  169. package/dist/runtime/approvals/runtime.d.ts +12 -0
  170. package/dist/runtime/approvals/runtime.d.ts.map +1 -0
  171. package/dist/runtime/approvals/runtime.js +154 -0
  172. package/dist/runtime/approvals/types.d.ts +31 -0
  173. package/dist/runtime/approvals/types.d.ts.map +1 -0
  174. package/dist/runtime/approvals/types.js +1 -0
  175. package/dist/runtime/behavior/index.d.ts +3 -0
  176. package/dist/runtime/behavior/index.d.ts.map +1 -0
  177. package/dist/runtime/behavior/index.js +1 -0
  178. package/dist/runtime/behavior/resolve.d.ts +7 -0
  179. package/dist/runtime/behavior/resolve.d.ts.map +1 -0
  180. package/dist/runtime/behavior/resolve.js +66 -0
  181. package/dist/runtime/behavior/types.d.ts +25 -0
  182. package/dist/runtime/behavior/types.d.ts.map +1 -0
  183. package/dist/runtime/behavior/types.js +1 -0
  184. package/dist/runtime/capabilities/backend.d.ts +7 -0
  185. package/dist/runtime/capabilities/backend.d.ts.map +1 -0
  186. package/dist/runtime/capabilities/backend.js +104 -0
  187. package/dist/runtime/capabilities/index.d.ts +6 -0
  188. package/dist/runtime/capabilities/index.d.ts.map +1 -0
  189. package/dist/runtime/capabilities/index.js +4 -0
  190. package/dist/runtime/capabilities/recipe.d.ts +10 -0
  191. package/dist/runtime/capabilities/recipe.d.ts.map +1 -0
  192. package/dist/runtime/capabilities/recipe.js +123 -0
  193. package/dist/runtime/capabilities/registry.d.ts +6 -0
  194. package/dist/runtime/capabilities/registry.d.ts.map +1 -0
  195. package/dist/runtime/capabilities/registry.js +69 -0
  196. package/dist/runtime/capabilities/runner.d.ts +8 -0
  197. package/dist/runtime/capabilities/runner.d.ts.map +1 -0
  198. package/dist/runtime/capabilities/runner.js +73 -0
  199. package/dist/runtime/capabilities/types.d.ts +28 -0
  200. package/dist/runtime/capabilities/types.d.ts.map +1 -0
  201. package/dist/runtime/capabilities/types.js +1 -0
  202. package/dist/runtime/execution-profile/index.d.ts +3 -0
  203. package/dist/runtime/execution-profile/index.d.ts.map +1 -0
  204. package/dist/runtime/execution-profile/index.js +1 -0
  205. package/dist/runtime/execution-profile/resolve.d.ts +9 -0
  206. package/dist/runtime/execution-profile/resolve.d.ts.map +1 -0
  207. package/dist/runtime/execution-profile/resolve.js +80 -0
  208. package/dist/runtime/execution-profile/types.d.ts +27 -0
  209. package/dist/runtime/execution-profile/types.d.ts.map +1 -0
  210. package/dist/runtime/execution-profile/types.js +1 -0
  211. package/dist/runtime/explain/index.d.ts +3 -0
  212. package/dist/runtime/explain/index.d.ts.map +1 -0
  213. package/dist/runtime/explain/index.js +1 -0
  214. package/dist/runtime/explain/resolve.d.ts +14 -0
  215. package/dist/runtime/explain/resolve.d.ts.map +1 -0
  216. package/dist/runtime/explain/resolve.js +50 -0
  217. package/dist/runtime/explain/types.d.ts +28 -0
  218. package/dist/runtime/explain/types.d.ts.map +1 -0
  219. package/dist/runtime/explain/types.js +1 -0
  220. package/dist/runtime/harness/index.d.ts +4 -0
  221. package/dist/runtime/harness/index.d.ts.map +1 -0
  222. package/dist/runtime/harness/index.js +2 -0
  223. package/dist/runtime/harness/resolve-from-command-context.d.ts +4 -0
  224. package/dist/runtime/harness/resolve-from-command-context.d.ts.map +1 -0
  225. package/dist/runtime/harness/resolve-from-command-context.js +11 -0
  226. package/dist/runtime/harness/resolve.d.ts +13 -0
  227. package/dist/runtime/harness/resolve.d.ts.map +1 -0
  228. package/dist/runtime/harness/resolve.js +146 -0
  229. package/dist/runtime/harness/types.d.ts +65 -0
  230. package/dist/runtime/harness/types.d.ts.map +1 -0
  231. package/dist/runtime/harness/types.js +1 -0
  232. package/dist/runtime/incidents/index.d.ts +3 -0
  233. package/dist/runtime/incidents/index.d.ts.map +1 -0
  234. package/dist/runtime/incidents/index.js +1 -0
  235. package/dist/runtime/incidents/resolve.d.ts +26 -0
  236. package/dist/runtime/incidents/resolve.d.ts.map +1 -0
  237. package/dist/runtime/incidents/resolve.js +437 -0
  238. package/dist/runtime/incidents/types.d.ts +72 -0
  239. package/dist/runtime/incidents/types.d.ts.map +1 -0
  240. package/dist/runtime/incidents/types.js +1 -0
  241. package/dist/runtime/protocol/index.d.ts +3 -0
  242. package/dist/runtime/protocol/index.d.ts.map +1 -0
  243. package/dist/runtime/protocol/index.js +2 -0
  244. package/dist/runtime/protocol/resolve.d.ts +16 -0
  245. package/dist/runtime/protocol/resolve.d.ts.map +1 -0
  246. package/dist/runtime/protocol/resolve.js +36 -0
  247. package/dist/runtime/protocol/types.d.ts +36 -0
  248. package/dist/runtime/protocol/types.d.ts.map +1 -0
  249. package/dist/runtime/protocol/types.js +1 -0
  250. package/dist/runtime/task-intake/index.d.ts +3 -0
  251. package/dist/runtime/task-intake/index.d.ts.map +1 -0
  252. package/dist/runtime/task-intake/index.js +1 -0
  253. package/dist/runtime/task-intake/resolve.d.ts +48 -0
  254. package/dist/runtime/task-intake/resolve.d.ts.map +1 -0
  255. package/dist/runtime/task-intake/resolve.js +316 -0
  256. package/dist/runtime/task-intake/types.d.ts +117 -0
  257. package/dist/runtime/task-intake/types.d.ts.map +1 -0
  258. package/dist/runtime/task-intake/types.js +1 -0
  259. package/dist/shared/protected-paths.d.ts +4 -0
  260. package/dist/shared/protected-paths.d.ts.map +1 -1
  261. package/dist/shared/protected-paths.js +4 -4
  262. package/dist/usecases/context/resolve-context.d.ts +55 -6
  263. package/dist/usecases/context/resolve-context.d.ts.map +1 -1
  264. package/dist/usecases/context/resolve-context.js +96 -6
  265. package/dist/usecases/task/task-list-usecase.d.ts.map +1 -1
  266. package/dist/usecases/task/task-list-usecase.js +8 -2
  267. package/dist/usecases/task/task-new-usecase.js +4 -4
  268. package/package.json +2 -3
@@ -1,6 +1,7 @@
1
1
  import path from "node:path";
2
2
  import { loadCommandContext } from "../../commands/shared/task-backend.js";
3
3
  import { CliError } from "../../shared/errors.js";
4
+ import { makeReadOnlyUsecaseContext } from "../../usecases/context/resolve-context.js";
4
5
  import { createRunnerAdapter } from "../adapters/index.js";
5
6
  import { runnerAdapterCancelledResult } from "../adapters/shared.js";
6
7
  import { evolveRunnerRunState } from "../artifacts.js";
@@ -139,14 +140,15 @@ export function buildSyntheticCancelledState(opts) {
139
140
  });
140
141
  }
141
142
  export async function loadExistingRunnerExecution(opts) {
142
- const ctx = opts.ctx ??
143
+ const command = opts.ctx ??
143
144
  (await loadCommandContext({ cwd: opts.cwd, rootOverride: opts.rootOverride ?? null }));
145
+ const executionContext = await makeReadOnlyUsecaseContext(command);
144
146
  if (opts.require_task_doing !== false) {
145
- assertCurrentTaskDoing(opts.task_id, await ctx.taskBackend.getTask(opts.task_id));
147
+ assertCurrentTaskDoing(opts.task_id, await executionContext.backend.task_backend.getTask(opts.task_id));
146
148
  }
147
149
  const repository = RunnerRunRepository.forTaskRun({
148
- git_root: ctx.resolvedProject.gitRoot,
149
- workflow_dir: ctx.config.paths.workflow_dir,
150
+ git_root: executionContext.repo.git_root,
151
+ workflow_dir: executionContext.repo.workflow_dir,
150
152
  task_id: opts.task_id,
151
153
  run_id: opts.run_id,
152
154
  });
@@ -160,10 +162,10 @@ export async function loadExistingRunnerExecution(opts) {
160
162
  }
161
163
  assertRunnerBundleMatchesTask(record.bundle, opts.task_id, opts.run_id);
162
164
  assertRunnerTaskExecutable(record.bundle);
163
- const adapter = createRunnerAdapter(ctx.config);
165
+ const adapter = createRunnerAdapter(executionContext.config);
164
166
  const invocation = await adapter.prepare(record.bundle);
165
167
  return {
166
- ctx,
168
+ ctx: executionContext.command,
167
169
  bundle: record.bundle,
168
170
  invocation,
169
171
  state: record.state,
@@ -1 +1 @@
1
- {"version":3,"file":"task-run.d.ts","sourceRoot":"","sources":["../../../src/runner/usecases/task-run.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAgBhG,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,2BAA2B,GAAG;IACxC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,UAAU,EAAE,gBAAgB,CAAC;IAC7B,KAAK,EAAE,cAAc,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,2BAA2B,GAAG;IACtE,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAiGF,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAc5E;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,mBAAmB,EAC3B,UAAU,CAAC,EAAE,gBAAgB,GAC5B,MAAM,CAiCR;AAED,wBAAsB,0BAA0B,CAAC,IAAI,EAAE;IACrD,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAmFvC;AAED,wBAAsB,0BAA0B,CAAC,IAAI,EAAE;IACrD,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAgDvC"}
1
+ {"version":3,"file":"task-run.d.ts","sourceRoot":"","sources":["../../../src/runner/usecases/task-run.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAuBhG,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,2BAA2B,GAAG;IACxC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,UAAU,EAAE,gBAAgB,CAAC;IAC7B,KAAK,EAAE,cAAc,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,2BAA2B,GAAG;IACtE,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAkHF,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAc5E;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,mBAAmB,EAC3B,UAAU,CAAC,EAAE,gBAAgB,GAC5B,MAAM,CAiCR;AAED,wBAAsB,0BAA0B,CAAC,IAAI,EAAE;IACrD,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAoHvC;AAED,wBAAsB,0BAA0B,CAAC,IAAI,EAAE;IACrD,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAgDvC"}
@@ -1,6 +1,11 @@
1
1
  import { exitCodeForError } from "../../cli/exit-codes.js";
2
2
  import { loadCommandContext } from "../../commands/shared/task-backend.js";
3
3
  import { CliError } from "../../shared/errors.js";
4
+ import { resolveRunnerAdapterCapabilityRegistry } from "../../runtime/capabilities/index.js";
5
+ import { consumeExecutionProfileBudget } from "../../runtime/execution-profile/index.js";
6
+ import { appendFrameworkExplainBehaviorInputs, } from "../../runtime/explain/index.js";
7
+ import { buildFrameworkProtocolSurface } from "../../runtime/protocol/index.js";
8
+ import { makeReadOnlyUsecaseContext } from "../../usecases/context/resolve-context.js";
4
9
  import { evolveRunnerRunState } from "../artifacts.js";
5
10
  import { createRunnerAdapter } from "../adapters/index.js";
6
11
  import { readRecipeRunProfile } from "../adapters/recipe-run-profile.js";
@@ -11,7 +16,6 @@ import { createRunnerRunId } from "../run-id.js";
11
16
  import { persistRunnerOutcomeToTask } from "../task-state.js";
12
17
  import { RunnerRunRepository } from "../run-repository.js";
13
18
  import { resolveTaskRunnerPaths } from "../task-run-paths.js";
14
- import { resolveRunnerTimeoutPolicy, resolveRunnerTracePolicy } from "../config.js";
15
19
  import { normalizeRecipeArtifactPrefixes } from "../result-manifest-policy.js";
16
20
  import { RUNNER_API_VERSION, RUNNER_BUNDLE_SCHEMA_VERSION, } from "../types.js";
17
21
  class RunnerPreparationCliError extends CliError {
@@ -28,6 +32,18 @@ class RunnerPreparationCliError extends CliError {
28
32
  this.state = opts.state;
29
33
  }
30
34
  }
35
+ function collectFrameworkExplainBehaviorInputs(prompts) {
36
+ return prompts.flatMap((prompt) => prompt.resolution
37
+ ? [
38
+ {
39
+ id: prompt.id,
40
+ category: "prompt",
41
+ ...(prompt.source ? { source: prompt.source } : {}),
42
+ resolution: prompt.resolution,
43
+ },
44
+ ]
45
+ : []);
46
+ }
31
47
  function isEnforcedCapabilityLevel(level) {
32
48
  return level === "native" || level === "wrapper";
33
49
  }
@@ -148,21 +164,39 @@ export function renderTaskRunnerBootstrap(bundle, invocation) {
148
164
  ].join("\n");
149
165
  }
150
166
  export async function prepareTaskRunnerExecution(opts) {
151
- const ctx = opts.ctx ??
167
+ const command = opts.ctx ??
152
168
  (await loadCommandContext({ cwd: opts.cwd, rootOverride: opts.rootOverride ?? null }));
169
+ const executionContext = await makeReadOnlyUsecaseContext(command);
170
+ const target = opts.target ?? { kind: "task", task_id: opts.task_id };
171
+ void executionContext.policy.evaluate({
172
+ action: target.kind === "recipe_scenario" ? "scenario_execute" : "task_run",
173
+ config: executionContext.config,
174
+ taskId: opts.task_id,
175
+ git: { stagedPaths: [] },
176
+ });
177
+ let executionProfile = consumeExecutionProfileBudget({
178
+ runtime: executionContext.executionProfile,
179
+ phase: "discovery",
180
+ });
153
181
  const taskEnvelope = await assembleRunnerTaskContext({
154
- ctx,
182
+ ctx: executionContext.command,
155
183
  cwd: opts.cwd,
156
184
  rootOverride: opts.rootOverride ?? null,
157
185
  task_id: opts.task_id,
158
186
  });
159
187
  const base_prompts = await collectRunnerBasePrompts({
160
- git_root: taskEnvelope.repository.git_root,
188
+ git_root: executionContext.repo.git_root,
161
189
  owner_id: taskEnvelope.task.data.owner,
162
- agents_dir: ctx.config.paths.agents_dir,
190
+ agents_dir: executionContext.harness.workflow.paths.agents_dir,
163
191
  recipe: opts.recipe,
192
+ harness: executionContext.harness,
193
+ execution_profile: executionProfile,
164
194
  });
165
- const adapter = createRunnerAdapter(ctx.config);
195
+ const framework_explain = appendFrameworkExplainBehaviorInputs(executionContext.frameworkExplain, collectFrameworkExplainBehaviorInputs(base_prompts));
196
+ const framework_protocol = buildFrameworkProtocolSurface({
197
+ explain: framework_explain,
198
+ });
199
+ const adapter = createRunnerAdapter(executionContext.config);
166
200
  const configured_adapter_id = adapter.id === "custom" ? "custom" : "codex";
167
201
  const run_id = opts.run_id ?? createRunnerRunId();
168
202
  const artifact_paths = resolveTaskRunnerPaths({
@@ -174,8 +208,10 @@ export async function prepareTaskRunnerExecution(opts) {
174
208
  const bundle = {
175
209
  schema_version: RUNNER_BUNDLE_SCHEMA_VERSION,
176
210
  runner_api_version: RUNNER_API_VERSION,
177
- target: opts.target ?? { kind: "task", task_id: opts.task_id },
211
+ target,
178
212
  base_prompts,
213
+ framework_explain,
214
+ framework_protocol,
179
215
  repository: taskEnvelope.repository,
180
216
  task: taskEnvelope.task,
181
217
  recipe: opts.recipe,
@@ -184,21 +220,32 @@ export async function prepareTaskRunnerExecution(opts) {
184
220
  mode: opts.mode,
185
221
  run_id,
186
222
  artifact_paths,
187
- trace_policy: resolveRunnerTracePolicy(ctx.config),
188
- timeout_policy: resolveRunnerTimeoutPolicy(ctx.config),
223
+ profile_runtime: executionProfile,
224
+ trace_policy: executionProfile.runner.trace_policy,
225
+ timeout_policy: executionProfile.runner.timeout_policy,
189
226
  approvals: {
190
- require_plan: ctx.config.agents?.approvals.require_plan,
191
- require_verify: ctx.config.agents?.approvals.require_verify,
192
- require_network: ctx.config.agents?.approvals.require_network,
227
+ require_plan: executionContext.approvals.require_plan,
228
+ require_verify: executionContext.approvals.require_verify,
229
+ require_network: executionContext.approvals.require_network,
193
230
  },
194
231
  },
195
232
  };
233
+ executionProfile = consumeExecutionProfileBudget({
234
+ runtime: bundle.execution.profile_runtime ?? executionProfile,
235
+ phase: "implementation",
236
+ });
237
+ bundle.execution.profile_runtime = executionProfile;
196
238
  bundle.execution.adapter_capabilities = adapter.describeCapabilities(bundle);
197
239
  bundle.execution.policy_decision = buildRunnerPolicyDecision({
198
240
  adapter_id: bundle.execution.adapter_id,
199
241
  capabilities: bundle.execution.adapter_capabilities,
200
242
  recipe: bundle.recipe,
201
243
  });
244
+ bundle.execution.adapter_capability_registry = resolveRunnerAdapterCapabilityRegistry({
245
+ adapter_id: bundle.execution.adapter_id,
246
+ capabilities: bundle.execution.adapter_capabilities,
247
+ requested: bundle.execution.policy_decision.requested,
248
+ });
202
249
  assertRunnerTaskExecutable(bundle);
203
250
  try {
204
251
  assertRunnerPolicyCompatibility(bundle);
@@ -0,0 +1,3 @@
1
+ export type { ApprovalDecisionSource, ApprovalRequest, ApprovalRequirement, ApprovalResolveOptions, ApprovalRuntimeOptions, EffectiveApprovalSettings, } from "./types.js";
2
+ export { ApprovalRuntime, createApprovalRuntime, resolveEffectiveApprovalSettings, } from "./runtime.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/approvals/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,sBAAsB,EACtB,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,gCAAgC,GACjC,MAAM,cAAc,CAAC"}
@@ -0,0 +1 @@
1
+ export { ApprovalRuntime, createApprovalRuntime, resolveEffectiveApprovalSettings, } from "./runtime.js";
@@ -0,0 +1,12 @@
1
+ import type { AgentplaneConfig } from "@agentplaneorg/core";
2
+ import type { ApprovalRequest, ApprovalRequirement, ApprovalRuntimeOptions, ApprovalResolveOptions, EffectiveApprovalSettings } from "./types.js";
3
+ export declare function resolveEffectiveApprovalSettings(config: AgentplaneConfig): EffectiveApprovalSettings;
4
+ export declare class ApprovalRuntime {
5
+ private readonly config;
6
+ private readonly policy;
7
+ constructor(opts: ApprovalRuntimeOptions);
8
+ resolve(opts: ApprovalResolveOptions): ApprovalRequirement;
9
+ ensure(opts: ApprovalRequest): Promise<ApprovalRequirement>;
10
+ }
11
+ export declare function createApprovalRuntime(opts: ApprovalRuntimeOptions): ApprovalRuntime;
12
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/runtime/approvals/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAM5D,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAEpB,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,gBAAgB,GACvB,yBAAyB,CAuB3B;AAmGD,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;gBAE1B,IAAI,EAAE,sBAAsB;IAKxC,OAAO,CAAC,IAAI,EAAE,sBAAsB,GAAG,mBAAmB;IASpD,MAAM,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;CA0BlE;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,sBAAsB,GAAG,eAAe,CAEnF"}
@@ -0,0 +1,154 @@
1
+ import { promptYesNo } from "../../cli/prompts.js";
2
+ import { PolicyEngine } from "../../policy/engine.js";
3
+ import { CliError } from "../../shared/errors.js";
4
+ export function resolveEffectiveApprovalSettings(config) {
5
+ const approvals = config.agents?.approvals;
6
+ const base = {
7
+ require_plan: approvals?.require_plan === true,
8
+ require_network: approvals?.require_network === true,
9
+ require_verify: approvals?.require_verify === true,
10
+ require_force: approvals?.require_force === true,
11
+ };
12
+ if (config.execution.profile === "conservative") {
13
+ return {
14
+ ...base,
15
+ require_network: true,
16
+ require_force: true,
17
+ };
18
+ }
19
+ return base;
20
+ }
21
+ function resolveRequirement(opts) {
22
+ const approvals = resolveEffectiveApprovalSettings(opts.config);
23
+ const decision = opts.policy.evaluate({
24
+ action: opts.action,
25
+ config: opts.config,
26
+ taskId: opts.taskId ?? "",
27
+ git: { stagedPaths: [] },
28
+ });
29
+ const classification = decision.action;
30
+ const configuredNetwork = opts.config.agents?.approvals?.require_network === true;
31
+ const configuredForce = opts.config.agents?.approvals?.require_force === true;
32
+ const conservativeProfile = opts.config.execution.profile === "conservative";
33
+ switch (classification.approval) {
34
+ case "network_access": {
35
+ return {
36
+ action: classification,
37
+ approvals,
38
+ required: approvals.require_network === true,
39
+ source: approvals.require_network
40
+ ? configuredNetwork
41
+ ? "config"
42
+ : conservativeProfile
43
+ ? "execution_profile"
44
+ : "none"
45
+ : "none",
46
+ reason: "Network access requires explicit approval",
47
+ };
48
+ }
49
+ case "force_action": {
50
+ return {
51
+ action: classification,
52
+ approvals,
53
+ required: approvals.require_force === true,
54
+ source: approvals.require_force
55
+ ? configuredForce
56
+ ? "config"
57
+ : conservativeProfile
58
+ ? "execution_profile"
59
+ : "none"
60
+ : "none",
61
+ reason: "Force action requires explicit approval",
62
+ };
63
+ }
64
+ case "policy_write": {
65
+ return {
66
+ action: classification,
67
+ approvals,
68
+ required: false,
69
+ source: "builtin",
70
+ reason: "Policy writes require explicit approval",
71
+ };
72
+ }
73
+ case "config_write": {
74
+ return {
75
+ action: classification,
76
+ approvals,
77
+ required: false,
78
+ source: "builtin",
79
+ reason: "Config writes require explicit approval",
80
+ };
81
+ }
82
+ case "dangerous_fs": {
83
+ return {
84
+ action: classification,
85
+ approvals,
86
+ required: false,
87
+ source: "builtin",
88
+ reason: "Potentially dangerous file operations require approval",
89
+ };
90
+ }
91
+ case "git_push": {
92
+ return {
93
+ action: classification,
94
+ approvals,
95
+ required: false,
96
+ source: "builtin",
97
+ reason: "Git push requires explicit approval",
98
+ };
99
+ }
100
+ default: {
101
+ return {
102
+ action: classification,
103
+ approvals,
104
+ required: false,
105
+ source: "none",
106
+ reason: `${classification.summary} does not require an approval gate`,
107
+ };
108
+ }
109
+ }
110
+ }
111
+ export class ApprovalRuntime {
112
+ config;
113
+ policy;
114
+ constructor(opts) {
115
+ this.config = opts.config;
116
+ this.policy = opts.policy ?? new PolicyEngine();
117
+ }
118
+ resolve(opts) {
119
+ return resolveRequirement({
120
+ config: this.config,
121
+ action: opts.action,
122
+ taskId: opts.taskId,
123
+ policy: this.policy,
124
+ });
125
+ }
126
+ async ensure(opts) {
127
+ const requirement = this.resolve({
128
+ action: opts.action,
129
+ taskId: opts.taskId,
130
+ });
131
+ if (!requirement.required || opts.yes)
132
+ return requirement;
133
+ const interactive = opts.interactive ?? Boolean(process.stdin.isTTY);
134
+ if (!interactive) {
135
+ throw new CliError({
136
+ exitCode: 3,
137
+ code: "E_VALIDATION",
138
+ message: `${requirement.reason} (pass --yes): ${opts.reason}`,
139
+ });
140
+ }
141
+ const approved = await promptYesNo(`Allow ${opts.action}? ${opts.reason}`, false);
142
+ if (!approved) {
143
+ throw new CliError({
144
+ exitCode: 3,
145
+ code: "E_VALIDATION",
146
+ message: `${requirement.reason} denied: ${opts.reason}`,
147
+ });
148
+ }
149
+ return requirement;
150
+ }
151
+ }
152
+ export function createApprovalRuntime(opts) {
153
+ return new ApprovalRuntime(opts);
154
+ }
@@ -0,0 +1,31 @@
1
+ import type { AgentplaneConfig } from "@agentplaneorg/core";
2
+ import type { PolicyEngine } from "../../policy/engine.js";
3
+ import type { PolicyActionDescriptor, PolicyActionId } from "../../policy/taxonomy.js";
4
+ export type EffectiveApprovalSettings = {
5
+ require_plan: boolean;
6
+ require_network: boolean;
7
+ require_verify: boolean;
8
+ require_force: boolean;
9
+ };
10
+ export type ApprovalDecisionSource = "none" | "config" | "execution_profile" | "builtin";
11
+ export type ApprovalRequirement = {
12
+ action: PolicyActionDescriptor;
13
+ required: boolean;
14
+ reason: string;
15
+ source: ApprovalDecisionSource;
16
+ approvals: EffectiveApprovalSettings;
17
+ };
18
+ export type ApprovalResolveOptions = {
19
+ action: PolicyActionId;
20
+ taskId?: string;
21
+ };
22
+ export type ApprovalRequest = ApprovalResolveOptions & {
23
+ yes: boolean;
24
+ reason: string;
25
+ interactive?: boolean;
26
+ };
27
+ export type ApprovalRuntimeOptions = {
28
+ config: AgentplaneConfig;
29
+ policy?: PolicyEngine;
30
+ };
31
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/runtime/approvals/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAEvF,MAAM,MAAM,yBAAyB,GAAG;IACtC,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,QAAQ,GAAG,mBAAmB,GAAG,SAAS,CAAC;AAEzF,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,sBAAsB,CAAC;IAC/B,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,sBAAsB,CAAC;IAC/B,SAAS,EAAE,yBAAyB,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,sBAAsB,GAAG;IACrD,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,gBAAgB,CAAC;IACzB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export { resolveBehavior, stripBehaviorValue } from "./resolve.js";
2
+ export type { BehaviorCandidate, BehaviorLayer, BehaviorResolutionEntry, BehaviorResolutionTrace, ResolvedBehavior, } from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/behavior/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACnE,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
@@ -0,0 +1 @@
1
+ export { resolveBehavior, stripBehaviorValue } from "./resolve.js";
@@ -0,0 +1,7 @@
1
+ import type { BehaviorCandidate, BehaviorResolutionTrace, ResolvedBehavior } from "./types.js";
2
+ export declare function resolveBehavior<TValue, TMetadata = Record<string, unknown>>(opts: {
3
+ key: string;
4
+ candidates: readonly BehaviorCandidate<TValue, TMetadata>[];
5
+ }): ResolvedBehavior<TValue, TMetadata>;
6
+ export declare function stripBehaviorValue<TValue, TMetadata>(resolved: ResolvedBehavior<TValue, TMetadata>): BehaviorResolutionTrace<TMetadata>;
7
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../src/runtime/behavior/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EAGjB,uBAAuB,EACvB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAyDpB,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE;IACjF,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,SAAS,iBAAiB,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC;CAC7D,GAAG,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,CAyBtC;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAClD,QAAQ,EAAE,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,GAC5C,uBAAuB,CAAC,SAAS,CAAC,CAOpC"}
@@ -0,0 +1,66 @@
1
+ const BEHAVIOR_LAYER_RANK = {
2
+ harness: 0,
3
+ extension: 1,
4
+ user: 2,
5
+ builtin: 3,
6
+ };
7
+ function normalizeKey(key) {
8
+ const normalized = key.trim();
9
+ if (!normalized) {
10
+ throw new Error("Behavior resolution requires a non-empty key.");
11
+ }
12
+ return normalized;
13
+ }
14
+ function rankCandidates(candidates) {
15
+ return candidates.map((candidate, index) => ({
16
+ ...candidate,
17
+ order: candidate.order ?? 0,
18
+ index,
19
+ }));
20
+ }
21
+ function compareCandidates(left, right) {
22
+ return (BEHAVIOR_LAYER_RANK[left.layer] - BEHAVIOR_LAYER_RANK[right.layer] ||
23
+ left.order - right.order ||
24
+ left.source.localeCompare(right.source) ||
25
+ left.index - right.index);
26
+ }
27
+ function toTraceEntry(candidate, selected) {
28
+ return {
29
+ layer: candidate.layer,
30
+ source: candidate.source,
31
+ order: candidate.order,
32
+ selected,
33
+ ...(candidate.metadata ? { metadata: structuredClone(candidate.metadata) } : {}),
34
+ };
35
+ }
36
+ export function resolveBehavior(opts) {
37
+ const key = normalizeKey(opts.key);
38
+ if (opts.candidates.length === 0) {
39
+ throw new Error(`Behavior resolution requires at least one candidate: ${key}`);
40
+ }
41
+ const ranked = rankCandidates(opts.candidates).toSorted(compareCandidates);
42
+ const winner = ranked[0];
43
+ if (!winner) {
44
+ throw new Error(`Behavior resolution lost its winner unexpectedly: ${key}`);
45
+ }
46
+ const trace = ranked.map((candidate, index) => toTraceEntry(candidate, index === 0));
47
+ const [winnerTrace, ...conflicts] = trace;
48
+ if (!winnerTrace) {
49
+ throw new Error(`Behavior resolution trace is unexpectedly empty: ${key}`);
50
+ }
51
+ return {
52
+ key,
53
+ value: winner.value,
54
+ winner: winnerTrace,
55
+ conflicts,
56
+ trace,
57
+ };
58
+ }
59
+ export function stripBehaviorValue(resolved) {
60
+ return {
61
+ key: resolved.key,
62
+ winner: resolved.winner,
63
+ conflicts: resolved.conflicts,
64
+ trace: resolved.trace,
65
+ };
66
+ }
@@ -0,0 +1,25 @@
1
+ export type BehaviorLayer = "harness" | "extension" | "user" | "builtin";
2
+ export type BehaviorCandidate<TValue, TMetadata = Record<string, unknown>> = {
3
+ layer: BehaviorLayer;
4
+ source: string;
5
+ value: TValue;
6
+ order?: number;
7
+ metadata?: TMetadata;
8
+ };
9
+ export type BehaviorResolutionEntry<TMetadata = Record<string, unknown>> = {
10
+ layer: BehaviorLayer;
11
+ source: string;
12
+ order: number;
13
+ selected: boolean;
14
+ metadata?: TMetadata;
15
+ };
16
+ export type BehaviorResolutionTrace<TMetadata = Record<string, unknown>> = {
17
+ key: string;
18
+ winner: BehaviorResolutionEntry<TMetadata>;
19
+ conflicts: BehaviorResolutionEntry<TMetadata>[];
20
+ trace: BehaviorResolutionEntry<TMetadata>[];
21
+ };
22
+ export type ResolvedBehavior<TValue, TMetadata = Record<string, unknown>> = BehaviorResolutionTrace<TMetadata> & {
23
+ value: TValue;
24
+ };
25
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/runtime/behavior/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,GAAG,SAAS,CAAC;AAEzE,MAAM,MAAM,iBAAiB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC3E,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,uBAAuB,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACzE,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,uBAAuB,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACzE,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;IAC3C,SAAS,EAAE,uBAAuB,CAAC,SAAS,CAAC,EAAE,CAAC;IAChD,KAAK,EAAE,uBAAuB,CAAC,SAAS,CAAC,EAAE,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAC1B,MAAM,EACN,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACjC,uBAAuB,CAAC,SAAS,CAAC,GAAG;IACvC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { TaskBackendCapabilities } from "../../backends/task-backend.js";
2
+ import type { AgentplaneCapabilityRegistry } from "./types.js";
3
+ export declare function resolveTaskBackendCapabilityRegistry(opts: {
4
+ backend_id: string;
5
+ capabilities: TaskBackendCapabilities | null | undefined;
6
+ }): AgentplaneCapabilityRegistry;
7
+ //# sourceMappingURL=backend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../../src/runtime/capabilities/backend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAG9E,OAAO,KAAK,EAA6B,4BAA4B,EAAE,MAAM,YAAY,CAAC;AA8E1F,wBAAgB,oCAAoC,CAAC,IAAI,EAAE;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,uBAAuB,GAAG,IAAI,GAAG,SAAS,CAAC;CAC1D,GAAG,4BAA4B,CAsD/B"}
@@ -0,0 +1,104 @@
1
+ import { createCapabilityRegistry } from "./registry.js";
2
+ const BOOLEAN_CAPABILITY_FIELDS = [
3
+ {
4
+ field: "reads_from_projection_by_default",
5
+ summary: "Reads task data from the projection by default",
6
+ },
7
+ {
8
+ field: "writes_task_readmes",
9
+ summary: "Writes task README documents through the backend",
10
+ },
11
+ {
12
+ field: "supports_task_revisions",
13
+ summary: "Supports backend task revisions",
14
+ },
15
+ {
16
+ field: "supports_revision_guarded_writes",
17
+ summary: "Supports revision-guarded writes",
18
+ },
19
+ {
20
+ field: "may_access_network_on_read",
21
+ summary: "May access the network while reading tasks",
22
+ },
23
+ {
24
+ field: "may_access_network_on_write",
25
+ summary: "May access the network while writing tasks",
26
+ },
27
+ {
28
+ field: "supports_projection_refresh",
29
+ summary: "Supports projection refresh",
30
+ },
31
+ {
32
+ field: "supports_push_sync",
33
+ summary: "Supports push synchronization",
34
+ },
35
+ {
36
+ field: "supports_snapshot_export",
37
+ summary: "Supports projection or task snapshot export",
38
+ },
39
+ ];
40
+ const VALUE_CAPABILITY_FIELDS = [
41
+ { field: "canonical_source", summary: "Canonical task source mode" },
42
+ { field: "projection", summary: "Projection storage mode" },
43
+ { field: "projection_read_mode", summary: "Projection read mode" },
44
+ ];
45
+ function source(backendId) {
46
+ return {
47
+ id: "backend",
48
+ detail: backendId,
49
+ };
50
+ }
51
+ function fieldId(backendId, field) {
52
+ return `backend.${backendId}.${field}`;
53
+ }
54
+ export function resolveTaskBackendCapabilityRegistry(opts) {
55
+ if (!opts.capabilities) {
56
+ return createCapabilityRegistry([
57
+ {
58
+ id: fieldId(opts.backend_id, "capabilities"),
59
+ kind: "backend_field",
60
+ availability: "unavailable",
61
+ source: source(opts.backend_id),
62
+ summary: "Declared task backend capabilities",
63
+ reason: "The task backend did not expose a capability descriptor.",
64
+ metadata: { backend_id: opts.backend_id },
65
+ },
66
+ ]);
67
+ }
68
+ const entries = [];
69
+ for (const field of VALUE_CAPABILITY_FIELDS) {
70
+ const value = opts.capabilities[field.field];
71
+ entries.push({
72
+ id: fieldId(opts.backend_id, field.field),
73
+ kind: "backend_field",
74
+ availability: value === undefined ? "unavailable" : "available",
75
+ source: source(opts.backend_id),
76
+ summary: field.summary,
77
+ value,
78
+ ...(value === undefined
79
+ ? {
80
+ reason: "The task backend omitted this capability field.",
81
+ }
82
+ : {}),
83
+ metadata: { backend_id: opts.backend_id, field: field.field },
84
+ });
85
+ }
86
+ for (const field of BOOLEAN_CAPABILITY_FIELDS) {
87
+ const value = opts.capabilities[field.field];
88
+ entries.push({
89
+ id: fieldId(opts.backend_id, field.field),
90
+ kind: "backend_field",
91
+ availability: value ? "available" : "unavailable",
92
+ source: source(opts.backend_id),
93
+ summary: field.summary,
94
+ value,
95
+ ...(value
96
+ ? {}
97
+ : {
98
+ reason: "The task backend declares this feature unavailable.",
99
+ }),
100
+ metadata: { backend_id: opts.backend_id, field: field.field },
101
+ });
102
+ }
103
+ return createCapabilityRegistry(entries);
104
+ }
@@ -0,0 +1,6 @@
1
+ export { createCapabilityRegistry, getCapabilityEntries, listCapabilities, mergeCapabilityRegistries, } from "./registry.js";
2
+ export { resolveTaskBackendCapabilityRegistry } from "./backend.js";
3
+ export { resolveRecipeCapabilityRegistry } from "./recipe.js";
4
+ export { resolveRunnerAdapterCapabilityRegistry } from "./runner.js";
5
+ export type { AgentplaneCapabilityAvailability, AgentplaneCapabilityEntry, AgentplaneCapabilityFilter, AgentplaneCapabilityKind, AgentplaneCapabilityRegistry, AgentplaneCapabilitySourceId, AgentplaneCapabilitySourceRef, } from "./types.js";
6
+ //# sourceMappingURL=index.d.ts.map