@agent-vm/agent-vm-worker 0.0.20

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 (138) hide show
  1. package/LICENSE +21 -0
  2. package/dist/config/worker-config.d.ts +158 -0
  3. package/dist/config/worker-config.d.ts.map +1 -0
  4. package/dist/config/worker-config.js +280 -0
  5. package/dist/config/worker-config.js.map +1 -0
  6. package/dist/context/gather-context.d.ts +9 -0
  7. package/dist/context/gather-context.d.ts.map +1 -0
  8. package/dist/context/gather-context.js +72 -0
  9. package/dist/context/gather-context.js.map +1 -0
  10. package/dist/coordinator/coordinator-helpers.d.ts +13 -0
  11. package/dist/coordinator/coordinator-helpers.d.ts.map +1 -0
  12. package/dist/coordinator/coordinator-helpers.js +63 -0
  13. package/dist/coordinator/coordinator-helpers.js.map +1 -0
  14. package/dist/coordinator/coordinator-types.d.ts +25 -0
  15. package/dist/coordinator/coordinator-types.d.ts.map +1 -0
  16. package/dist/coordinator/coordinator-types.js +2 -0
  17. package/dist/coordinator/coordinator-types.js.map +1 -0
  18. package/dist/coordinator/coordinator.d.ts +4 -0
  19. package/dist/coordinator/coordinator.d.ts.map +1 -0
  20. package/dist/coordinator/coordinator.js +74 -0
  21. package/dist/coordinator/coordinator.js.map +1 -0
  22. package/dist/coordinator/task-runner.d.ts +5 -0
  23. package/dist/coordinator/task-runner.d.ts.map +1 -0
  24. package/dist/coordinator/task-runner.js +310 -0
  25. package/dist/coordinator/task-runner.js.map +1 -0
  26. package/dist/git/git-operations.d.ts +33 -0
  27. package/dist/git/git-operations.d.ts.map +1 -0
  28. package/dist/git/git-operations.js +109 -0
  29. package/dist/git/git-operations.js.map +1 -0
  30. package/dist/index.d.ts +25 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +23 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/main.d.ts +11 -0
  35. package/dist/main.d.ts.map +1 -0
  36. package/dist/main.js +140 -0
  37. package/dist/main.js.map +1 -0
  38. package/dist/plan-phase/plan-cycle.d.ts +27 -0
  39. package/dist/plan-phase/plan-cycle.d.ts.map +1 -0
  40. package/dist/plan-phase/plan-cycle.js +83 -0
  41. package/dist/plan-phase/plan-cycle.js.map +1 -0
  42. package/dist/prompt/message-builders.d.ts +44 -0
  43. package/dist/prompt/message-builders.d.ts.map +1 -0
  44. package/dist/prompt/message-builders.js +83 -0
  45. package/dist/prompt/message-builders.js.map +1 -0
  46. package/dist/prompt/prompt-assembler.d.ts +11 -0
  47. package/dist/prompt/prompt-assembler.d.ts.map +1 -0
  48. package/dist/prompt/prompt-assembler.js +34 -0
  49. package/dist/prompt/prompt-assembler.js.map +1 -0
  50. package/dist/prompt/prompt-defaults.d.ts +10 -0
  51. package/dist/prompt/prompt-defaults.d.ts.map +1 -0
  52. package/dist/prompt/prompt-defaults.js +200 -0
  53. package/dist/prompt/prompt-defaults.js.map +1 -0
  54. package/dist/server.d.ts +32 -0
  55. package/dist/server.d.ts.map +1 -0
  56. package/dist/server.js +75 -0
  57. package/dist/server.js.map +1 -0
  58. package/dist/shared/phase-names.d.ts +8 -0
  59. package/dist/shared/phase-names.d.ts.map +1 -0
  60. package/dist/shared/phase-names.js +11 -0
  61. package/dist/shared/phase-names.js.map +1 -0
  62. package/dist/shared/repo-location.d.ts +13 -0
  63. package/dist/shared/repo-location.d.ts.map +1 -0
  64. package/dist/shared/repo-location.js +9 -0
  65. package/dist/shared/repo-location.js.map +1 -0
  66. package/dist/shared/review-result.d.ts +17 -0
  67. package/dist/shared/review-result.d.ts.map +1 -0
  68. package/dist/shared/review-result.js +12 -0
  69. package/dist/shared/review-result.js.map +1 -0
  70. package/dist/shared/skill-types.d.ts +7 -0
  71. package/dist/shared/skill-types.d.ts.map +1 -0
  72. package/dist/shared/skill-types.js +6 -0
  73. package/dist/shared/skill-types.js.map +1 -0
  74. package/dist/shared/stderr.d.ts +2 -0
  75. package/dist/shared/stderr.d.ts.map +1 -0
  76. package/dist/shared/stderr.js +4 -0
  77. package/dist/shared/stderr.js.map +1 -0
  78. package/dist/state/event-log.d.ts +4 -0
  79. package/dist/state/event-log.d.ts.map +1 -0
  80. package/dist/state/event-log.js +67 -0
  81. package/dist/state/event-log.js.map +1 -0
  82. package/dist/state/task-event-types.d.ts +280 -0
  83. package/dist/state/task-event-types.d.ts.map +1 -0
  84. package/dist/state/task-event-types.js +106 -0
  85. package/dist/state/task-event-types.js.map +1 -0
  86. package/dist/state/task-state.d.ts +35 -0
  87. package/dist/state/task-state.d.ts.map +1 -0
  88. package/dist/state/task-state.js +191 -0
  89. package/dist/state/task-state.js.map +1 -0
  90. package/dist/validation-runner/verification-runner.d.ts +30 -0
  91. package/dist/validation-runner/verification-runner.d.ts.map +1 -0
  92. package/dist/validation-runner/verification-runner.js +196 -0
  93. package/dist/validation-runner/verification-runner.js.map +1 -0
  94. package/dist/work-executor/codex-executor.d.ts +9 -0
  95. package/dist/work-executor/codex-executor.d.ts.map +1 -0
  96. package/dist/work-executor/codex-executor.js +159 -0
  97. package/dist/work-executor/codex-executor.js.map +1 -0
  98. package/dist/work-executor/executor-factory.d.ts +4 -0
  99. package/dist/work-executor/executor-factory.d.ts.map +1 -0
  100. package/dist/work-executor/executor-factory.js +17 -0
  101. package/dist/work-executor/executor-factory.js.map +1 -0
  102. package/dist/work-executor/executor-interface.d.ts +33 -0
  103. package/dist/work-executor/executor-interface.d.ts.map +1 -0
  104. package/dist/work-executor/executor-interface.js +2 -0
  105. package/dist/work-executor/executor-interface.js.map +1 -0
  106. package/dist/work-executor/local-tool-mcp-server.d.ts +8 -0
  107. package/dist/work-executor/local-tool-mcp-server.d.ts.map +1 -0
  108. package/dist/work-executor/local-tool-mcp-server.js +187 -0
  109. package/dist/work-executor/local-tool-mcp-server.js.map +1 -0
  110. package/dist/work-executor/persistent-thread.d.ts +16 -0
  111. package/dist/work-executor/persistent-thread.d.ts.map +1 -0
  112. package/dist/work-executor/persistent-thread.js +37 -0
  113. package/dist/work-executor/persistent-thread.js.map +1 -0
  114. package/dist/work-phase/controller-tools/controller-tool-support.d.ts +19 -0
  115. package/dist/work-phase/controller-tools/controller-tool-support.d.ts.map +1 -0
  116. package/dist/work-phase/controller-tools/controller-tool-support.js +92 -0
  117. package/dist/work-phase/controller-tools/controller-tool-support.js.map +1 -0
  118. package/dist/work-phase/controller-tools/git-pull-default-tool.d.ts +10 -0
  119. package/dist/work-phase/controller-tools/git-pull-default-tool.d.ts.map +1 -0
  120. package/dist/work-phase/controller-tools/git-pull-default-tool.js +36 -0
  121. package/dist/work-phase/controller-tools/git-pull-default-tool.js.map +1 -0
  122. package/dist/work-phase/controller-tools/git-push-tool.d.ts +10 -0
  123. package/dist/work-phase/controller-tools/git-push-tool.d.ts.map +1 -0
  124. package/dist/work-phase/controller-tools/git-push-tool.js +45 -0
  125. package/dist/work-phase/controller-tools/git-push-tool.js.map +1 -0
  126. package/dist/work-phase/validation-tool.d.ts +11 -0
  127. package/dist/work-phase/validation-tool.d.ts.map +1 -0
  128. package/dist/work-phase/validation-tool.js +25 -0
  129. package/dist/work-phase/validation-tool.js.map +1 -0
  130. package/dist/work-phase/work-cycle.d.ts +28 -0
  131. package/dist/work-phase/work-cycle.d.ts.map +1 -0
  132. package/dist/work-phase/work-cycle.js +122 -0
  133. package/dist/work-phase/work-cycle.js.map +1 -0
  134. package/dist/wrapup-phase/wrapup-runner.d.ts +30 -0
  135. package/dist/wrapup-phase/wrapup-runner.d.ts.map +1 -0
  136. package/dist/wrapup-phase/wrapup-runner.js +91 -0
  137. package/dist/wrapup-phase/wrapup-runner.js.map +1 -0
  138. package/package.json +57 -0
@@ -0,0 +1,200 @@
1
+ export const DEFAULT_BASE_INSTRUCTIONS = `You are an agent operating inside a sandboxed VM. You have access to the repository workspace mounted at /workspace. All outbound network requests go through a mediation proxy.
2
+
3
+ ## Security
4
+ - You do not have access to GitHub tokens, SSH keys, or other credentials. The host controller handles authenticated git operations.
5
+ - Never print, exfiltrate, or try to discover credentials.
6
+ - Do not run git push. Use the git-push tool when you need to push an agent branch.
7
+
8
+ ## Workspace
9
+ - Work only inside the workspace directories listed in your task.
10
+ - Do not modify the .git directory directly.
11
+ - Preserve unrelated user or agent changes.
12
+
13
+ ## Git commits
14
+ - You may stage and commit with git add and git commit.
15
+ - Branches you create must be prefixed with {branchPrefix}.
16
+ - Use conventional commit messages such as feat:, fix:, refactor:, test:, docs:, or chore:.
17
+
18
+ ## Controller tools
19
+ - git-push pushes the current branch via the controller. The VM has no real GitHub token; push auth is handled host-side.
20
+ - git-pull-default updates the local protected/default branch via the controller and reports drift.
21
+ - gh pr create is available for PR creation after git-push succeeds. GitHub API traffic is mediated by the controller proxy.
22
+ - The VM env var GITHUB_TOKEN is a Gondolin mediation placeholder, NOT the real token. gh must see SOME token to skip its login check, so always invoke gh with GH_TOKEN="$GITHUB_TOKEN" prefixed:
23
+ GH_TOKEN="$GITHUB_TOKEN" gh pr create --base <default> --title "..." --body "..."
24
+ - The proxy strips the placeholder and injects the real token at the wire level. You never handle the real token directly.
25
+
26
+ ## Mediated secrets
27
+
28
+ The same mediation pattern applies to every credential surfaced into your env. The value you see is a Gondolin placeholder; the proxy swaps it for the real secret on outbound requests to the allowed hosts declared in zone config. Never print, log, or try to inspect the value.
29
+
30
+ Default mediated env vars for worker zones:
31
+ - GITHUB_TOKEN: for github.com / api.github.com
32
+ - OPENAI_API_KEY: for api.openai.com
33
+
34
+ If your task needs another credential, it must be declared in the zone secrets with injection: "http-mediation" and the relevant allowed host. Without that declaration, no auth flows.
35
+
36
+ If NPM_AUTH_TOKEN is configured for registry.npmjs.org and the repo needs private npm packages, configure npm at task runtime rather than expecting the gateway image to contain auth files:
37
+
38
+ \`\`\`bash
39
+ printf '//registry.npmjs.org/:_authToken=\${NPM_AUTH_TOKEN}\\n' > "$HOME/.npmrc"
40
+ \`\`\`
41
+
42
+ The single quotes preserve the literal template so npm substitutes it from the environment during registry calls. Do not inline the env var with double quotes or bake .npmrc into an image.
43
+
44
+ ## Output discipline
45
+ - Keep prose brief.
46
+ - When asked for JSON, return only JSON with no markdown fence or prose wrapper.`;
47
+ export const DEFAULT_PLAN_AGENT_INSTRUCTIONS = `You are the PLAN agent. Produce an implementation plan for the task.
48
+
49
+ ## Inputs
50
+ - Spec: the user's requested change.
51
+ - Repositories: repo URLs, branches, and workspace paths.
52
+ - Repo summary: gathered codebase context when available.
53
+ - Context: extra task metadata.
54
+
55
+ ## Expected work
56
+ - Explain what should change and why.
57
+ - Name the files or modules likely involved.
58
+ - Order the steps so a work agent can execute them.
59
+ - Include validation that will prove the work.
60
+ - Call out real risks and non-goals.
61
+
62
+ ## Do not
63
+ - Write code.
64
+ - Run commands.
65
+ - Invent requirements.
66
+
67
+ ## Return format
68
+ { "plan": "plan text" }`;
69
+ export const DEFAULT_PLAN_REVIEWER_INSTRUCTIONS = `You are the PLAN REVIEWER. Review the plan against the spec and repo context.
70
+
71
+ ## What to find
72
+ - Missing requirements.
73
+ - Incorrect assumptions about the codebase.
74
+ - Ambiguous steps that could be implemented two different ways.
75
+ - Scope creep or needless abstraction.
76
+ - Real failure modes the plan ignores.
77
+
78
+ ## Severity
79
+ - critical: must address for correctness or spec compliance.
80
+ - suggestion: meaningful improvement.
81
+ - nitpick: style or wording only.
82
+
83
+ ## Do not
84
+ - Rewrite the plan yourself.
85
+ - Block on implementation details the work agent can resolve.
86
+
87
+ ## Return format
88
+ {
89
+ "approved": true,
90
+ "summary": "1-3 sentences",
91
+ "comments": [
92
+ { "file": "plan", "severity": "critical", "comment": "..." }
93
+ ]
94
+ }`;
95
+ export const DEFAULT_WORK_AGENT_INSTRUCTIONS = `You are the WORK agent. Implement the approved plan.
96
+
97
+ ## Inputs
98
+ - Spec: the original task.
99
+ - Approved plan: the implementation plan.
100
+ - Plan review commentary: advisory feedback.
101
+ - Validation commands: project checks available through run_validation.
102
+
103
+ ## Tools
104
+ - You may call run_validation to check your work. It is optional and not required; the reviewer will run validation too.
105
+
106
+ ## Expected flow
107
+ - Read the relevant code before editing.
108
+ - Make the smallest coherent changes that satisfy the plan.
109
+ - Commit logical chunks when useful.
110
+ - Return a concise summary of the turn.
111
+
112
+ ## Do not
113
+ - Run git push.
114
+ - Expand beyond the plan without saying why.
115
+
116
+ ## Return format
117
+ { "summary": "...", "commitShas": [], "remainingConcerns": "" }`;
118
+ export const DEFAULT_WORK_REVIEWER_INSTRUCTIONS = `You are the WORK REVIEWER. Review the current diff against the spec and plan.
119
+
120
+ ## Mandatory tool call
121
+ - You MUST call run_validation exactly once before returning your review.
122
+ - Include the command-result array from the tool in validationResults.
123
+ - If no validation commands are configured, run_validation returns [] and validationResults must be [].
124
+ - Do not wrap validationResults in a tool envelope, a nested array, a string, or prose. It must be an array of objects with name, passed, exitCode, output, and optional logPath.
125
+
126
+ ## What to find
127
+ - Correctness bugs.
128
+ - Missing tests or failing validation.
129
+ - Security or secret-handling issues.
130
+ - Scope drift from the plan.
131
+ - Maintainability issues that matter now.
132
+
133
+ ## Severity
134
+ - critical: broken behavior, failed validation, security issue, or clear plan divergence.
135
+ - suggestion: meaningful improvement.
136
+ - nitpick: style only.
137
+
138
+ ## Return format
139
+ {
140
+ "approved": true,
141
+ "summary": "1-3 sentences",
142
+ "comments": [],
143
+ "validationResults": [{ "name": "test", "passed": true, "exitCode": 0, "output": "", "logPath": "optional path" }]
144
+ }`;
145
+ export const DEFAULT_WRAPUP_INSTRUCTIONS = `You are in the WRAPUP phase. The work cycle has completed.
146
+
147
+ ## Tools
148
+ - git-pull-default tool: refresh the local default/protected branch and inspect drift.
149
+ - git-push tool: push the current agent branch through the controller.
150
+ - gh CLI: use GH_TOKEN="$GITHUB_TOKEN" gh pr create from shell after git-push succeeds.
151
+
152
+ ## Your job
153
+ Ship the work that was already implemented. You are a fresh wrapup thread with explicit handoff context from the work agent. You are not here to redesign the solution or make broad new edits. Use the original task, the work-agent summary, and the git context in your prompt to create the PR.
154
+
155
+ ## How to ship
156
+ 1. Inspect the current branch and git state. You should be on an agent/* branch with committed work.
157
+ 2. If work is uncommitted, make a normal local commit with a clear conventional commit message.
158
+ 3. Call git-pull-default to update the local protected/default branch and see whether your branch is behind.
159
+ 4. If the default branch moved, decide whether a rebase or merge is needed. Resolve any conflicts locally, then commit the resolution.
160
+ 5. Call git-push. If it returns success=false, read the message and fix the git state instead of pretending the push worked.
161
+ 6. After git-push succeeds, run gh pr create from the shell. Use a clear title and body based on the work summary.
162
+ - IMPORTANT: gh short-circuits with a login prompt unless GH_TOKEN is set. The VM env has GITHUB_TOKEN set to a mediation placeholder. Always invoke gh with that placeholder copied into GH_TOKEN:
163
+ GH_TOKEN="$GITHUB_TOKEN" gh pr create --base <default> --title "..." --body "..."
164
+ The controller proxy injects the real token at the wire level.
165
+ 7. Return JSON with the PR URL, branch name, pushed commit SHAs if known, and a concise summary.
166
+
167
+ ## Expected successful path
168
+ - You call git-pull-default and confirm default-branch drift.
169
+ - You call git-push and confirm the controller pushed the agent branch.
170
+ - You run GH_TOKEN="$GITHUB_TOKEN" gh pr create and capture the GitHub PR URL.
171
+ - You return JSON with prUrl, branchName, pushedCommits, and summary.
172
+
173
+ ## Important rules
174
+ - The VM has no real GitHub token. Never run raw git push. Always use git-push.
175
+ - gh pr create is allowed; GitHub HTTP traffic is mediated by the controller proxy. Use GH_TOKEN="$GITHUB_TOKEN" prefix with gh.
176
+ - Do not call run_validation here. The work phase already handled validation.
177
+ - Do not call git-push while on the protected/default branch. Create or switch to an agent/* branch first.
178
+
179
+ ## Do not
180
+ - Run git push.
181
+ - Call run_validation here.
182
+ - Start unrelated cleanup.
183
+ - Modify files unless git-pull-default reveals a real conflict or missing commit.
184
+
185
+ ## Return format
186
+ { "summary": "wrapup result", "prUrl": "https://github.com/org/repo/pull/1", "branchName": "agent/name", "pushedCommits": ["sha"] }`;
187
+ const DEFAULTS_BY_ROLE = {
188
+ 'plan-agent': DEFAULT_PLAN_AGENT_INSTRUCTIONS,
189
+ 'plan-reviewer': DEFAULT_PLAN_REVIEWER_INSTRUCTIONS,
190
+ 'work-agent': DEFAULT_WORK_AGENT_INSTRUCTIONS,
191
+ 'work-reviewer': DEFAULT_WORK_REVIEWER_INSTRUCTIONS,
192
+ wrapup: DEFAULT_WRAPUP_INSTRUCTIONS,
193
+ };
194
+ export function resolveRoleInstructions(role, configValue) {
195
+ return configValue ?? DEFAULTS_BY_ROLE[role];
196
+ }
197
+ export function interpolateBaseInstructions(branchPrefix) {
198
+ return DEFAULT_BASE_INSTRUCTIONS.replaceAll('{branchPrefix}', branchPrefix);
199
+ }
200
+ //# sourceMappingURL=prompt-defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-defaults.js","sourceRoot":"","sources":["../../src/prompt/prompt-defaults.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iFA6CwC,CAAC;AAElF,MAAM,CAAC,MAAM,+BAA+B,GAAG;;;;;;;;;;;;;;;;;;;;;wBAqBvB,CAAC;AAEzB,MAAM,CAAC,MAAM,kCAAkC,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;EAyBhD,CAAC;AAEH,MAAM,CAAC,MAAM,+BAA+B,GAAG;;;;;;;;;;;;;;;;;;;;;;gEAsBiB,CAAC;AAEjE,MAAM,CAAC,MAAM,kCAAkC,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BhD,CAAC;AAEH,MAAM,CAAC,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oIAyCyF,CAAC;AAErI,MAAM,gBAAgB,GAAG;IACxB,YAAY,EAAE,+BAA+B;IAC7C,eAAe,EAAE,kCAAkC;IACnD,YAAY,EAAE,+BAA+B;IAC7C,eAAe,EAAE,kCAAkC;IACnD,MAAM,EAAE,2BAA2B;CACJ,CAAC;AAEjC,MAAM,UAAU,uBAAuB,CAAC,IAAU,EAAE,WAA0B;IAC7E,OAAO,WAAW,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,YAAoB;IAC/D,OAAO,yBAAyB,CAAC,UAAU,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { Hono } from 'hono';
2
+ import { z } from 'zod';
3
+ import type { TaskState } from './state/task-state.js';
4
+ export declare const createTaskRequestSchema: z.ZodObject<{
5
+ taskId: z.ZodString;
6
+ prompt: z.ZodString;
7
+ repos: z.ZodDefault<z.ZodArray<z.ZodObject<{
8
+ repoUrl: z.ZodString;
9
+ baseBranch: z.ZodString;
10
+ workspacePath: z.ZodString;
11
+ }, z.core.$strip>>>;
12
+ context: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
13
+ }, z.core.$strip>;
14
+ export interface ServerDeps {
15
+ readonly getActiveTaskId: () => string | null;
16
+ readonly getActiveTaskStatus: () => string | null;
17
+ readonly getTaskState: (taskId: string) => TaskState | undefined;
18
+ readonly submitTask: (input: z.infer<typeof createTaskRequestSchema>) => Promise<{
19
+ taskId: string;
20
+ status: 'accepted';
21
+ }>;
22
+ readonly closeTask: (taskId: string) => Promise<{
23
+ status: 'closed';
24
+ }>;
25
+ readonly getUptime: () => number;
26
+ readonly getExecutorInfo: () => {
27
+ readonly provider: string;
28
+ readonly model: string;
29
+ };
30
+ }
31
+ export declare function createApp(deps: ServerDeps): Hono;
32
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAoBvD,eAAO,MAAM,uBAAuB;;;;;;;;;iBAKlC,CAAC;AAEH,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,eAAe,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC9C,QAAQ,CAAC,mBAAmB,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAClD,QAAQ,CAAC,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,SAAS,GAAG,SAAS,CAAC;IACjE,QAAQ,CAAC,UAAU,EAAE,CACpB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,KAC1C,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;IACrD,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,MAAM,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC;IACtE,QAAQ,CAAC,SAAS,EAAE,MAAM,MAAM,CAAC;IACjC,QAAQ,CAAC,eAAe,EAAE,MAAM;QAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;KACvB,CAAC;CACF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAmEhD"}
package/dist/server.js ADDED
@@ -0,0 +1,75 @@
1
+ import { zValidator } from '@hono/zod-validator';
2
+ import { Hono } from 'hono';
3
+ import { z } from 'zod';
4
+ import { repoLocationSchema } from './shared/repo-location.js';
5
+ import { writeStderr } from './shared/stderr.js';
6
+ import { isTerminal } from './state/task-state.js';
7
+ function validationErrorHook(result, context) {
8
+ if (!result.success) {
9
+ return context.json({
10
+ error: 'invalid-request',
11
+ details: result.error?.issues ?? [],
12
+ }, 400);
13
+ }
14
+ }
15
+ export const createTaskRequestSchema = z.object({
16
+ taskId: z.string().min(1),
17
+ prompt: z.string().min(1),
18
+ repos: z.array(repoLocationSchema).default([]),
19
+ context: z.record(z.string(), z.unknown()).default({}),
20
+ });
21
+ export function createApp(deps) {
22
+ const app = new Hono();
23
+ app.get('/health', (context) => context.json({
24
+ status: 'ok',
25
+ activeTask: deps.getActiveTaskId(),
26
+ activeTaskStatus: deps.getActiveTaskStatus(),
27
+ uptime: deps.getUptime(),
28
+ executor: deps.getExecutorInfo(),
29
+ }));
30
+ app.post('/tasks', zValidator('json', createTaskRequestSchema, validationErrorHook), async (context) => {
31
+ try {
32
+ if (deps.getActiveTaskId() !== null) {
33
+ return context.json({
34
+ error: 'task-already-active',
35
+ activeTaskId: deps.getActiveTaskId(),
36
+ }, 409);
37
+ }
38
+ const result = await deps.submitTask(context.req.valid('json'));
39
+ return context.json(result, 201);
40
+ }
41
+ catch (error) {
42
+ const message = error instanceof Error ? error.message : String(error);
43
+ writeStderr(`[server] Failed to submit task: ${message}`);
44
+ return context.json({ error: 'task-submission-failed' }, 500);
45
+ }
46
+ });
47
+ app.get('/tasks/:id', (context) => {
48
+ const taskState = deps.getTaskState(context.req.param('id'));
49
+ if (!taskState) {
50
+ return context.json({ error: 'task-not-found' }, 404);
51
+ }
52
+ return context.json(taskState);
53
+ });
54
+ app.post('/tasks/:id/close', async (context) => {
55
+ const taskId = context.req.param('id');
56
+ const taskState = deps.getTaskState(taskId);
57
+ if (!taskState) {
58
+ return context.json({ error: 'task-not-found' }, 404);
59
+ }
60
+ if (isTerminal(taskState)) {
61
+ return context.json({ error: 'task-is-terminal', status: taskState.status }, 410);
62
+ }
63
+ try {
64
+ const result = await deps.closeTask(taskId);
65
+ return context.json(result, 200);
66
+ }
67
+ catch (error) {
68
+ const message = error instanceof Error ? error.message : String(error);
69
+ writeStderr(`[server] Failed to close task ${taskId}: ${message}`);
70
+ return context.json({ error: 'task-close-failed' }, 500);
71
+ }
72
+ });
73
+ return app;
74
+ }
75
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE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CAAC;QAC1D,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const phaseNameByConfigKey: {
2
+ readonly plan: "plan";
3
+ readonly work: "work";
4
+ readonly wrapup: "wrapup";
5
+ };
6
+ export declare const phaseNames: readonly ["plan", "work", "wrapup"];
7
+ export type ConfigPhaseKey = keyof typeof phaseNameByConfigKey;
8
+ //# sourceMappingURL=phase-names.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phase-names.d.ts","sourceRoot":"","sources":["../../src/shared/phase-names.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;CAIvB,CAAC;AAEX,eAAO,MAAM,UAAU,qCAIb,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,oBAAoB,CAAC"}
@@ -0,0 +1,11 @@
1
+ export const phaseNameByConfigKey = {
2
+ plan: 'plan',
3
+ work: 'work',
4
+ wrapup: 'wrapup',
5
+ };
6
+ export const phaseNames = [
7
+ phaseNameByConfigKey.plan,
8
+ phaseNameByConfigKey.work,
9
+ phaseNameByConfigKey.wrapup,
10
+ ];
11
+ //# sourceMappingURL=phase-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phase-names.js","sourceRoot":"","sources":["../../src/shared/phase-names.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG;IACnC,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;CACP,CAAC;AAEX,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB,oBAAoB,CAAC,IAAI;IACzB,oBAAoB,CAAC,IAAI;IACzB,oBAAoB,CAAC,MAAM;CAClB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ export declare const repoTargetSchema: z.ZodObject<{
3
+ repoUrl: z.ZodString;
4
+ baseBranch: z.ZodString;
5
+ }, z.core.$strip>;
6
+ export type RepoTarget = z.infer<typeof repoTargetSchema>;
7
+ export declare const repoLocationSchema: z.ZodObject<{
8
+ repoUrl: z.ZodString;
9
+ baseBranch: z.ZodString;
10
+ workspacePath: z.ZodString;
11
+ }, z.core.$strip>;
12
+ export type RepoLocation = z.infer<typeof repoLocationSchema>;
13
+ //# sourceMappingURL=repo-location.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo-location.d.ts","sourceRoot":"","sources":["../../src/shared/repo-location.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,gBAAgB;;;iBAG3B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,eAAO,MAAM,kBAAkB;;;;iBAE7B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { z } from 'zod';
2
+ export const repoTargetSchema = z.object({
3
+ repoUrl: z.string().min(1),
4
+ baseBranch: z.string().min(1),
5
+ });
6
+ export const repoLocationSchema = repoTargetSchema.extend({
7
+ workspacePath: z.string().min(1),
8
+ });
9
+ //# sourceMappingURL=repo-location.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo-location.js","sourceRoot":"","sources":["../../src/shared/repo-location.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC7B,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,MAAM,CAAC;IACzD,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAChC,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { z } from 'zod';
2
+ export declare const reviewResultSchema: z.ZodObject<{
3
+ approved: z.ZodBoolean;
4
+ comments: z.ZodArray<z.ZodObject<{
5
+ file: z.ZodString;
6
+ line: z.ZodOptional<z.ZodNumber>;
7
+ severity: z.ZodEnum<{
8
+ critical: "critical";
9
+ suggestion: "suggestion";
10
+ nitpick: "nitpick";
11
+ }>;
12
+ comment: z.ZodString;
13
+ }, z.core.$strip>>;
14
+ summary: z.ZodString;
15
+ }, z.core.$strip>;
16
+ export type ReviewResult = z.infer<typeof reviewResultSchema>;
17
+ //# sourceMappingURL=review-result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"review-result.d.ts","sourceRoot":"","sources":["../../src/shared/review-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;iBAW7B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ export const reviewResultSchema = z.object({
3
+ approved: z.boolean(),
4
+ comments: z.array(z.object({
5
+ file: z.string(),
6
+ line: z.number().optional(),
7
+ severity: z.enum(['critical', 'suggestion', 'nitpick']),
8
+ comment: z.string(),
9
+ })),
10
+ summary: z.string(),
11
+ });
12
+ //# sourceMappingURL=review-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"review-result.js","sourceRoot":"","sources":["../../src/shared/review-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;IACrB,QAAQ,EAAE,CAAC,CAAC,KAAK,CAChB,CAAC,CAAC,MAAM,CAAC;QACR,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC3B,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;QACvD,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;KACnB,CAAC,CACF;IACD,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ export declare const skillReferenceSchema: z.ZodObject<{
3
+ name: z.ZodString;
4
+ path: z.ZodString;
5
+ }, z.core.$strip>;
6
+ export type SkillReference = z.infer<typeof skillReferenceSchema>;
7
+ //# sourceMappingURL=skill-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-types.d.ts","sourceRoot":"","sources":["../../src/shared/skill-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,oBAAoB;;;iBAG/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+ export const skillReferenceSchema = z.object({
3
+ name: z.string().min(1),
4
+ path: z.string().min(1),
5
+ });
6
+ //# sourceMappingURL=skill-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-types.js","sourceRoot":"","sources":["../../src/shared/skill-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CACvB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function writeStderr(message: string): void;
2
+ //# sourceMappingURL=stderr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stderr.d.ts","sourceRoot":"","sources":["../../src/shared/stderr.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAEjD"}
@@ -0,0 +1,4 @@
1
+ export function writeStderr(message) {
2
+ process.stderr.write(`${message}\n`);
3
+ }
4
+ //# sourceMappingURL=stderr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stderr.js","sourceRoot":"","sources":["../../src/shared/stderr.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,OAAe;IAC1C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { TaskEvent, TimestampedEvent } from './task-event-types.js';
2
+ export declare function appendEvent(filePath: string, event: TaskEvent): Promise<void>;
3
+ export declare function replayEvents(filePath: string): Promise<readonly TimestampedEvent[]>;
4
+ //# sourceMappingURL=event-log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-log.d.ts","sourceRoot":"","sources":["../../src/state/event-log.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAUzE,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAcnF;AAED,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,gBAAgB,EAAE,CAAC,CAyCzF"}
@@ -0,0 +1,67 @@
1
+ import fs from 'node:fs/promises';
2
+ import { dirname } from 'node:path';
3
+ import { writeStderr } from '../shared/stderr.js';
4
+ function isTimestampedEvent(value) {
5
+ if (typeof value !== 'object' || value === null)
6
+ return false;
7
+ if (!('ts' in value) || !('data' in value))
8
+ return false;
9
+ if (typeof value.ts !== 'string')
10
+ return false;
11
+ if (typeof value.data !== 'object' || value.data === null)
12
+ return false;
13
+ return 'event' in value.data;
14
+ }
15
+ export async function appendEvent(filePath, event) {
16
+ try {
17
+ await fs.mkdir(dirname(filePath), { recursive: true });
18
+ const timestampedEvent = {
19
+ ts: new Date().toISOString(),
20
+ data: event,
21
+ };
22
+ await fs.appendFile(filePath, `${JSON.stringify(timestampedEvent)}\n`, 'utf-8');
23
+ }
24
+ catch (error) {
25
+ throw new Error(`Failed to append event to ${filePath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
26
+ }
27
+ }
28
+ export async function replayEvents(filePath) {
29
+ let fileContents;
30
+ try {
31
+ fileContents = await fs.readFile(filePath, 'utf-8');
32
+ }
33
+ catch (error) {
34
+ if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
35
+ return [];
36
+ }
37
+ throw error;
38
+ }
39
+ const lines = fileContents.split('\n').filter((line) => line.trim() !== '');
40
+ if (lines.length === 0) {
41
+ return [];
42
+ }
43
+ const events = [];
44
+ for (let lineIndex = 0; lineIndex < lines.length; lineIndex += 1) {
45
+ const line = lines[lineIndex];
46
+ if (!line)
47
+ continue;
48
+ const isLastLine = lineIndex === lines.length - 1;
49
+ try {
50
+ const parsedJson = JSON.parse(line);
51
+ if (!isTimestampedEvent(parsedJson)) {
52
+ throw new Error(`Invalid event structure at line ${lineIndex + 1}`);
53
+ }
54
+ events.push(parsedJson);
55
+ }
56
+ catch (error) {
57
+ if (isLastLine) {
58
+ writeStderr(`Skipping incomplete final line in ${filePath}: ${line.slice(0, 50)}...`);
59
+ }
60
+ else {
61
+ throw new Error(`Corrupt event at line ${lineIndex + 1} in ${filePath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
62
+ }
63
+ }
64
+ }
65
+ return events;
66
+ }
67
+ //# sourceMappingURL=event-log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-log.js","sourceRoot":"","sources":["../../src/state/event-log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,SAAS,kBAAkB,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACzD,IAAI,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC/C,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACxE,OAAO,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC;AAC9B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAgB,EAAE,KAAgB;IACnE,IAAI,CAAC;QACJ,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACvD,MAAM,gBAAgB,GAAqB;YAC1C,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YAC5B,IAAI,EAAE,KAAK;SACX,CAAC;QACF,MAAM,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,IAAI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