codex-supervisor-mcp 0.14.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +37 -45
- package/README.md +37 -45
- package/package.json +2 -2
- package/skills/codex-supervisor/SKILL.md +88 -91
- package/src/app/acceptance.js +5 -5
- package/src/app/auto-cleanup.js +6 -5
- package/src/app/cleanup-facts.js +21 -16
- package/src/app/cleanup-plan.js +22 -20
- package/src/app/context-compiler.js +2 -1
- package/src/app/dispatch.js +17 -15
- package/src/app/followup.js +5 -4
- package/src/app/land-chain.js +5 -4
- package/src/app/landing.js +8 -8
- package/src/app/ownership.js +1 -1
- package/src/app/rebase.js +1 -1
- package/src/app/restore-worktree.js +2 -1
- package/src/app/resume.js +11 -6
- package/src/app/worktree-setup.js +58 -16
- package/src/domain/acceptance-spec.js +1 -1
- package/src/domain/failure-class.js +36 -4
- package/src/domain/prompt.js +7 -7
- package/src/domain/status.js +15 -2
- package/src/domain/thread-health.js +2 -2
- package/src/domain/worker-branch.js +6 -0
- package/src/domain/worker-changes.js +3 -3
- package/src/domain/worker-preflight.js +2 -1
- package/src/infra/cleanup-hint.js +1 -1
- package/src/infra/crash-guard.js +44 -0
- package/src/infra/external-output.js +2 -2
- package/src/infra/git.js +35 -4
- package/src/infra/sandbox-roots.js +1 -1
- package/src/infra/store/event-body.js +82 -0
- package/src/infra/store/events.js +9 -6
- package/src/infra/store/reconcile.js +4 -3
- package/src/infra/store/tasks.js +15 -1
- package/src/infra/update/auto-update-worker.js +3 -3
- package/src/infra/update/auto-update.js +4 -4
- package/src/infra/update/update-check.js +3 -3
- package/src/infra/workspace-kind.js +8 -8
- package/src/infra/worktree.js +4 -3
- package/src/interface/bin/acceptance-cli.js +4 -4
- package/src/interface/bin/monitor.jsx +6 -6
- package/src/interface/bin/setup.js +3 -3
- package/src/interface/bin/stage.js +2 -2
- package/src/interface/bin/web-server.js +2 -0
- package/src/interface/mcp/{tools → handlers}/delivery.js +30 -62
- package/src/interface/mcp/handlers/dispatch.js +233 -0
- package/src/interface/mcp/{tools → handlers}/facts.js +30 -65
- package/src/interface/mcp/handlers/overview.js +106 -0
- package/src/interface/mcp/{tools → handlers}/results.js +31 -60
- package/src/interface/mcp/{tools → handlers}/review.js +16 -36
- package/src/interface/mcp/{tools → handlers}/wait.js +13 -17
- package/src/interface/mcp/server.js +20 -50
- package/src/interface/mcp/tools/deliver.js +48 -0
- package/src/interface/mcp/tools/dispatch.js +78 -257
- package/src/interface/mcp/tools/optional.js +57 -0
- package/src/interface/mcp/tools/read.js +115 -0
- package/src/interface/mcp/tools/run.js +57 -0
- package/src/interface/mcp/tools/shapes.js +66 -0
- package/src/interface/mcp/tools/track.js +84 -0
- package/src/interface/mcp/views/task.js +8 -7
- package/src/interface/web/views.js +5 -2
- package/src/run-host/entry.js +3 -0
- package/src/run-host/finalize.js +8 -1
- package/src/run-host/launch.js +7 -7
- package/src/run-host/live-run.js +2 -0
- package/src/run-host/streams.js +28 -5
- package/src/run-host/track.js +5 -2
- package/src/runners/codex/tool-guard.js +6 -6
- package/web/dist/assets/{index-fJQbspTY.js → index-BnV-AYYI.js} +1 -1
- package/web/dist/assets/index-f8esISCp.css +2 -0
- package/web/dist/index.html +2 -2
- package/src/domain/overview-delta.js +0 -77
- package/src/interface/mcp/tools/overview.js +0 -202
- package/src/interface/mcp/tools/poll.js +0 -58
- package/web/dist/assets/index-DI1hLMxE.css +0 -2
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { runAcceptance } from "../../../app/acceptance.js";
|
|
2
|
+
import { createCodexWorker } from "../../../app/dispatch.js";
|
|
3
|
+
import { createFollowupWorker } from "../../../app/followup.js";
|
|
4
|
+
import { resumeCodexWorker } from "../../../app/resume.js";
|
|
5
|
+
import { readPreflightResult } from "../../../domain/worker-preflight.js";
|
|
6
|
+
import { runGit } from "../../../infra/git.js";
|
|
7
|
+
import { getTask } from "../../../infra/store/tasks.js";
|
|
8
|
+
import { baseBehind } from "../../../infra/worktree.js";
|
|
9
|
+
import { errorResult, textResult } from "../result.js";
|
|
10
|
+
import { acceptanceInput, workspaceSetupInput } from "../schemas.js";
|
|
11
|
+
import { withUpdate } from "../update-state.js";
|
|
12
|
+
import { receipt } from "../views/task.js";
|
|
13
|
+
import { randomUUID } from "node:crypto";
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
|
|
16
|
+
export const checkAcceptanceOp = {
|
|
17
|
+
input: z.object({
|
|
18
|
+
cwd: z.string().min(1), acceptance: acceptanceInput,
|
|
19
|
+
baseRef: z.string().min(1).optional(), timeoutMs: z.number().int().min(1000).max(1800000).default(600000)
|
|
20
|
+
}),
|
|
21
|
+
handler: async ({ cwd, acceptance, baseRef = "HEAD", timeoutMs }) => {
|
|
22
|
+
let base;
|
|
23
|
+
try {
|
|
24
|
+
base = runGit(cwd, ["rev-parse", "--verify", `${baseRef}^{commit}`], { timeout: 10000 });
|
|
25
|
+
} catch {
|
|
26
|
+
return textResult({ error: "invalid_base_ref", phase: "preflight", reason: `workspace.base_ref does not resolve in ${cwd}`, proves_worker_completion: false });
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const commands = Array.isArray(acceptance) ? acceptance : [acceptance];
|
|
30
|
+
const warnings = commands.filter((check) => typeof check === "string" && /(?:failures|errors)\s*=\s*\d/.test(check)).map(() => "failure-count checks do not prove baseline test identities or required execution; use structured evidence");
|
|
31
|
+
const result = await runAcceptance(commands, { cwd, timeoutMs, baseCommit: base, taskId: `preflight-${randomUUID()}` });
|
|
32
|
+
return textResult({ ...result, phase: "preflight", base_commit: base, proves_worker_completion: false, warnings });
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return errorResult(error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const preflightCodexWorkerOp = {
|
|
40
|
+
input: z.object({
|
|
41
|
+
title: z.string().optional(),
|
|
42
|
+
cwd: z.string().min(1),
|
|
43
|
+
sandbox: z.enum(["read-only", "workspace-write", "danger-full-access"]).default("workspace-write"),
|
|
44
|
+
model: z.string().optional(),
|
|
45
|
+
reasoningEffort: z.enum(["minimal", "low", "medium", "high"]).default("high"),
|
|
46
|
+
skipGitRepoCheck: z.boolean().default(true),
|
|
47
|
+
ownedPaths: z.array(z.string().min(1)),
|
|
48
|
+
forbid: z.array(z.string().min(1)).max(100).optional(),
|
|
49
|
+
allowedCommands: z.array(z.string().min(1)).max(100).optional(),
|
|
50
|
+
context: z.array(z.object({ path: z.string().min(1), sha256: z.string().regex(/^[a-f0-9]{64}$/).optional() })).max(20).optional(),
|
|
51
|
+
contracts: z.array(z.string().min(1).max(2000)).max(20).optional(),
|
|
52
|
+
networkAccess: z.boolean().default(false),
|
|
53
|
+
writableRoots: z.array(z.string().min(1)).max(20).optional(),
|
|
54
|
+
maxRunMs: z.number().int().min(1000).max(86400000).optional(),
|
|
55
|
+
maxTotalMs: z.number().int().min(1000).max(604800000).optional(),
|
|
56
|
+
baseRef: z.string().min(1).optional(),
|
|
57
|
+
workspaceKind: z.enum(["git_worktree", "read_only_in_place", "scratch", "in_place_write"]).optional(),
|
|
58
|
+
inPlaceAuthorization: z.string().min(1).max(2000).optional(),
|
|
59
|
+
workspaceSetup: workspaceSetupInput.optional(),
|
|
60
|
+
probeCommands: z.array(z.string().min(1)).min(1).max(20)
|
|
61
|
+
}),
|
|
62
|
+
handler: async (input) => {
|
|
63
|
+
try {
|
|
64
|
+
const task = [
|
|
65
|
+
"Runtime environment preflight. Do not edit files, create files, install packages, dispatch workers or call MCP tools.",
|
|
66
|
+
"Run every command below exactly once, in the listed order, without wrapping it in another shell command.",
|
|
67
|
+
"If any command is denied, missing, times out or exits nonzero, stop and quote the raw error under Not done / risks.",
|
|
68
|
+
"Commands:",
|
|
69
|
+
...input.probeCommands.map((command) => `- ${command}`)
|
|
70
|
+
].join("\n");
|
|
71
|
+
const record = await createCodexWorker({
|
|
72
|
+
...input,
|
|
73
|
+
title: input.title ? `Preflight: ${input.title}` : "Runtime environment preflight",
|
|
74
|
+
task,
|
|
75
|
+
goal: { objective: `Prove the requested Codex worker runtime environment before dispatching ${input.title ?? "the dependent worker"}` },
|
|
76
|
+
acceptance: null,
|
|
77
|
+
preflight: { probeCommands: input.probeCommands }
|
|
78
|
+
});
|
|
79
|
+
return textResult(withUpdate({ ...receipt(record), preflight: { status: "running", probe_commands: input.probeCommands } }));
|
|
80
|
+
} catch (error) {
|
|
81
|
+
return errorResult(error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const getWorkerPreflightOp = {
|
|
87
|
+
input: z.object({ task_id: z.string().min(1) }),
|
|
88
|
+
handler: async ({ task_id }) => {
|
|
89
|
+
const task = await getTask(task_id);
|
|
90
|
+
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
91
|
+
return textResult(readPreflightResult(task));
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const createCodexWorkerOp = {
|
|
96
|
+
input: z.object({
|
|
97
|
+
title: z.string().optional(),
|
|
98
|
+
task: z.string().min(1),
|
|
99
|
+
cwd: z.string().min(1),
|
|
100
|
+
session_id: z.string().min(1).optional(),
|
|
101
|
+
// What this batch is about, in one line, so a reader of the store sees
|
|
102
|
+
// "给 12 个接口补单测" instead of a bare session id. Set it on
|
|
103
|
+
// the first dispatch of a session; later dispatches may omit it.
|
|
104
|
+
session_title: z.string().min(1).max(120).optional(),
|
|
105
|
+
session_note: z.string().min(1).max(2000).optional(),
|
|
106
|
+
sandbox: z.enum(["read-only", "workspace-write", "danger-full-access"]).default("workspace-write"),
|
|
107
|
+
model: z.string().optional(),
|
|
108
|
+
reasoningEffort: z.enum(["minimal", "low", "medium", "high"]).default("high"),
|
|
109
|
+
skipGitRepoCheck: z.boolean().default(true),
|
|
110
|
+
// Empty is the promise that nothing lands: a read-only verifier, or a
|
|
111
|
+
// research worker that reads, fetches and reports but merges nothing.
|
|
112
|
+
ownedPaths: z.array(z.string().min(1)),
|
|
113
|
+
forbid: z.array(z.string().min(1)).max(100).optional(),
|
|
114
|
+
allowedCommands: z.array(z.string().min(1)).max(100).optional(),
|
|
115
|
+
context: z.array(z.object({ path: z.string().min(1), sha256: z.string().regex(/^[a-f0-9]{64}$/).optional() })).max(20).optional(),
|
|
116
|
+
contracts: z.array(z.string().min(1).max(2000)).max(20).optional(),
|
|
117
|
+
externalOutputs: z.array(z.object({ path: z.string().min(1), sha256: z.string().regex(/^[a-f0-9]{64}$/).optional() })).max(20).optional(),
|
|
118
|
+
networkAccess: z.boolean().default(false),
|
|
119
|
+
// Extra absolute directories the sandbox may write. The OS cache
|
|
120
|
+
// directory is already writable; this is for toolchains that keep a
|
|
121
|
+
// cache somewhere else (~/.m2, ~/.gradle, a vendored mirror).
|
|
122
|
+
writableRoots: z.array(z.string().min(1)).max(20).optional(),
|
|
123
|
+
maxRunMs: z.number().int().min(1000).max(86400000).optional(),
|
|
124
|
+
maxTotalMs: z.number().int().min(1000).max(604800000).optional(),
|
|
125
|
+
goal: z.object({
|
|
126
|
+
objective: z.string().min(1),
|
|
127
|
+
tokenBudget: z.number().int().positive().optional()
|
|
128
|
+
}),
|
|
129
|
+
dependsOn: z.array(z.string().min(1)).optional(),
|
|
130
|
+
// Which commit the worktree is cut from. Defaults to the repository's
|
|
131
|
+
// HEAD; pass a branch, tag or sha to build on work that is not on the
|
|
132
|
+
// main line yet (for example another worker's branch).
|
|
133
|
+
baseRef: z.string().min(1).optional(),
|
|
134
|
+
workspaceKind: z.enum(["git_worktree", "read_only_in_place", "scratch", "in_place_write"]).optional(),
|
|
135
|
+
inPlaceAuthorization: z.string().min(1).max(2000).optional(),
|
|
136
|
+
workspaceSetup: workspaceSetupInput.optional(),
|
|
137
|
+
// A successful preflight_worker task id. When present, this worker
|
|
138
|
+
// is refused unless base commit and the complete runtime contract match.
|
|
139
|
+
preflight_id: z.string().min(1).optional(),
|
|
140
|
+
// Shell commands that decide whether the work is done. The supervisor
|
|
141
|
+
// runs them in the worktree after codex exits; each must exit 0.
|
|
142
|
+
acceptance: acceptanceInput.optional(),
|
|
143
|
+
acceptanceTimeoutMs: z.number().int().min(1000).max(1800000).optional()
|
|
144
|
+
}),
|
|
145
|
+
handler: async (input) => {
|
|
146
|
+
try {
|
|
147
|
+
const record = await createCodexWorker({
|
|
148
|
+
...input,
|
|
149
|
+
preflightId: input.preflight_id ?? null,
|
|
150
|
+
sessionId: input.session_id ?? null,
|
|
151
|
+
sessionTitle: input.session_title ?? null,
|
|
152
|
+
sessionNote: input.session_note ?? null
|
|
153
|
+
});
|
|
154
|
+
return textResult(withUpdate(receipt(record)));
|
|
155
|
+
} catch (error) {
|
|
156
|
+
return errorResult(error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const createCodexFollowupWorkerOp = {
|
|
162
|
+
input: z.object({
|
|
163
|
+
task_id: z.string().min(1),
|
|
164
|
+
followup_prompt: z.string().min(1),
|
|
165
|
+
session_id: z.string().min(1).optional(),
|
|
166
|
+
session_title: z.string().min(1).max(120).optional(),
|
|
167
|
+
session_note: z.string().min(1).max(2000).optional(),
|
|
168
|
+
title: z.string().optional(),
|
|
169
|
+
cwd: z.string().optional(),
|
|
170
|
+
sandbox: z.enum(["read-only", "workspace-write", "danger-full-access"]).optional(),
|
|
171
|
+
model: z.string().optional(),
|
|
172
|
+
reasoningEffort: z.enum(["minimal", "low", "medium", "high"]).default("high"),
|
|
173
|
+
ownedPaths: z.array(z.string().min(1)).optional(),
|
|
174
|
+
forbid: z.array(z.string().min(1)).max(100).optional(),
|
|
175
|
+
allowedCommands: z.array(z.string().min(1)).max(100).optional(),
|
|
176
|
+
context: z.array(z.object({ path: z.string().min(1), sha256: z.string().regex(/^[a-f0-9]{64}$/).optional() })).max(20).optional(),
|
|
177
|
+
contracts: z.array(z.string().min(1).max(2000)).max(20).optional(),
|
|
178
|
+
externalOutputs: z.array(z.object({ path: z.string().min(1), sha256: z.string().regex(/^[a-f0-9]{64}$/).optional() })).max(20).optional(),
|
|
179
|
+
networkAccess: z.boolean().optional(),
|
|
180
|
+
writableRoots: z.array(z.string().min(1)).max(20).optional(),
|
|
181
|
+
maxRunMs: z.number().int().min(1000).max(86400000).optional(),
|
|
182
|
+
maxTotalMs: z.number().int().min(1000).max(604800000).optional(),
|
|
183
|
+
workspaceKind: z.enum(["git_worktree", "read_only_in_place", "scratch", "in_place_write"]).optional(),
|
|
184
|
+
inPlaceAuthorization: z.string().min(1).max(2000).optional(),
|
|
185
|
+
workspaceSetup: workspaceSetupInput.optional(),
|
|
186
|
+
goal: z
|
|
187
|
+
.object({
|
|
188
|
+
objective: z.string().min(1),
|
|
189
|
+
tokenBudget: z.number().int().positive().optional()
|
|
190
|
+
})
|
|
191
|
+
.optional(),
|
|
192
|
+
baseRef: z.string().min(1).optional(),
|
|
193
|
+
// Left out, the parent's acceptance commands are inherited; given, they
|
|
194
|
+
// replace them, and an empty list clears them.
|
|
195
|
+
acceptance: acceptanceInput.optional(),
|
|
196
|
+
acceptanceTimeoutMs: z.number().int().min(1000).max(1800000).optional()
|
|
197
|
+
}),
|
|
198
|
+
handler: async ({ task_id, followup_prompt, session_id, session_title, session_note, ...options }) => {
|
|
199
|
+
try {
|
|
200
|
+
const record = await createFollowupWorker({
|
|
201
|
+
taskId: task_id,
|
|
202
|
+
followupPrompt: followup_prompt,
|
|
203
|
+
sessionId: session_id ?? null,
|
|
204
|
+
sessionTitle: session_title ?? null,
|
|
205
|
+
sessionNote: session_note ?? null,
|
|
206
|
+
...options
|
|
207
|
+
});
|
|
208
|
+
return textResult(receipt(record));
|
|
209
|
+
} catch (error) {
|
|
210
|
+
return errorResult(error);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export const resumeCodexWorkerOp = {
|
|
216
|
+
input: z.object({
|
|
217
|
+
task_id: z.string().min(1),
|
|
218
|
+
prompt: z.string().min(1),
|
|
219
|
+
rebaseOnto: z.string().min(1).optional(),
|
|
220
|
+
context: z.array(z.object({ path: z.string().min(1), sha256: z.string().regex(/^[a-f0-9]{64}$/).optional() })).max(20).optional(),
|
|
221
|
+
// Replaces the stored acceptance commands for this and later runs; an
|
|
222
|
+
// empty list clears them. Left out, the stored commands stay.
|
|
223
|
+
acceptance: acceptanceInput.optional()
|
|
224
|
+
}),
|
|
225
|
+
handler: async ({ task_id, prompt, rebaseOnto, acceptance, context }) => {
|
|
226
|
+
try {
|
|
227
|
+
const record = await resumeCodexWorker({ taskId: task_id, prompt, rebaseOnto: rebaseOnto ?? null, acceptance, context });
|
|
228
|
+
return textResult({ ...receipt(record), rebase: record.rebase ?? null, base_behind: baseBehind(record.project_root, record.base_commit) });
|
|
229
|
+
} catch (error) {
|
|
230
|
+
return errorResult(error);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
@@ -7,14 +7,9 @@ import { runIdFor } from "../../../infra/store/db.js";
|
|
|
7
7
|
import { clip, errorResult, textResult } from "../result.js";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
|
|
10
|
-
export const
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
title: "Get worker context snapshot metadata",
|
|
14
|
-
description: "Read the latest worker-only context snapshot metadata for one task. Returns fact IDs, token estimate and excluded categories, never the capsule text or raw history.",
|
|
15
|
-
inputSchema: { task_id: z.string().min(1) }
|
|
16
|
-
},
|
|
17
|
-
async ({ task_id }) => {
|
|
10
|
+
export const getContextSnapshotMetaOp = {
|
|
11
|
+
input: z.object({ task_id: z.string().min(1) }),
|
|
12
|
+
handler: async ({ task_id }) => {
|
|
18
13
|
const task = await getTask(task_id);
|
|
19
14
|
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
20
15
|
const snapshot = await latestContextSnapshotForTask(task_id);
|
|
@@ -34,49 +29,34 @@ export const getContextSnapshotMetaTool = [
|
|
|
34
29
|
}
|
|
35
30
|
});
|
|
36
31
|
}
|
|
37
|
-
|
|
32
|
+
};
|
|
38
33
|
|
|
39
|
-
export const
|
|
40
|
-
|
|
41
|
-
{
|
|
42
|
-
title: "Get one verified or candidate fact",
|
|
43
|
-
description: "Read one fact by ID for audit. Facts are never automatically expanded into the main thread's context.",
|
|
44
|
-
inputSchema: { fact_id: z.string().uuid() }
|
|
45
|
-
},
|
|
46
|
-
async ({ fact_id }) => {
|
|
34
|
+
export const getFactOp = {
|
|
35
|
+
input: z.object({ fact_id: z.string().uuid() }),
|
|
36
|
+
handler: async ({ fact_id }) => {
|
|
47
37
|
const fact = await getFact(fact_id);
|
|
48
38
|
if (!fact) return textResult({ error: "fact_not_found", fact_id });
|
|
49
39
|
return textResult({ fact, effective_state: await getFactEffectiveState(fact_id) ?? fact.state });
|
|
50
40
|
}
|
|
51
|
-
|
|
41
|
+
};
|
|
52
42
|
|
|
53
|
-
export const
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
title: "Get one retained evidence artifact",
|
|
57
|
-
description: "Read one supervisor-managed artifact by ID for audit. This is explicit evidence retrieval and never expands a worker context capsule into the main thread.",
|
|
58
|
-
inputSchema: { artifact_id: z.string().uuid(), maxChars: z.number().int().min(0).max(100000).default(12000) }
|
|
59
|
-
},
|
|
60
|
-
async ({ artifact_id, maxChars }) => {
|
|
43
|
+
export const getArtifactOp = {
|
|
44
|
+
input: z.object({ artifact_id: z.string().uuid(), maxChars: z.number().int().min(0).max(100000).default(12000) }),
|
|
45
|
+
handler: async ({ artifact_id, maxChars }) => {
|
|
61
46
|
const artifact = await getArtifact(artifact_id);
|
|
62
47
|
if (!artifact) return textResult({ error: "artifact_not_found", artifact_id });
|
|
63
48
|
return textResult({ artifact: await readArtifact(artifact_id, maxChars) });
|
|
64
49
|
}
|
|
65
|
-
|
|
50
|
+
};
|
|
66
51
|
|
|
67
|
-
export const
|
|
68
|
-
|
|
69
|
-
{
|
|
70
|
-
title: "Promote a candidate worker fact",
|
|
71
|
-
description: "Explicitly promote one candidate fact after main-thread review. The worker cannot call this: promotion writes a new verified fact with an audit event; repo scope requires watched paths.",
|
|
72
|
-
inputSchema: {
|
|
52
|
+
export const promoteWorkerFactOp = {
|
|
53
|
+
input: z.object({
|
|
73
54
|
fact_id: z.string().uuid(),
|
|
74
55
|
scope: z.enum(["work_item", "repo_verified"]).default("work_item"),
|
|
75
56
|
watchedPaths: z.array(z.string().min(1)).max(100).optional(),
|
|
76
57
|
expiresAt: z.string().datetime().optional()
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
async ({ fact_id, scope, watchedPaths, expiresAt }) => {
|
|
58
|
+
}),
|
|
59
|
+
handler: async ({ fact_id, scope, watchedPaths, expiresAt }) => {
|
|
80
60
|
try {
|
|
81
61
|
const source = await getFact(fact_id);
|
|
82
62
|
if (!source) return textResult({ error: "fact_not_found", fact_id });
|
|
@@ -99,16 +79,11 @@ export const promoteWorkerFactTool = [
|
|
|
99
79
|
return errorResult(error);
|
|
100
80
|
}
|
|
101
81
|
}
|
|
102
|
-
|
|
82
|
+
};
|
|
103
83
|
|
|
104
|
-
export const
|
|
105
|
-
|
|
106
|
-
{
|
|
107
|
-
title: "Revoke a candidate or verified worker fact",
|
|
108
|
-
description: "Explicitly revoke one candidate or verified fact after audit. Revoked facts are excluded from search and worker capsules; the revocation is appended to the worker event log.",
|
|
109
|
-
inputSchema: { fact_id: z.string().uuid(), reason: z.string().min(1).max(2000) }
|
|
110
|
-
},
|
|
111
|
-
async ({ fact_id, reason }) => {
|
|
84
|
+
export const revokeWorkerFactOp = {
|
|
85
|
+
input: z.object({ fact_id: z.string().uuid(), reason: z.string().min(1).max(2000) }),
|
|
86
|
+
handler: async ({ fact_id, reason }) => {
|
|
112
87
|
try {
|
|
113
88
|
const source = await getFact(fact_id);
|
|
114
89
|
if (!source) return textResult({ error: "fact_not_found", fact_id });
|
|
@@ -123,16 +98,11 @@ export const revokeWorkerFactTool = [
|
|
|
123
98
|
return errorResult(error);
|
|
124
99
|
}
|
|
125
100
|
}
|
|
126
|
-
|
|
101
|
+
};
|
|
127
102
|
|
|
128
|
-
export const
|
|
129
|
-
|
|
130
|
-
{
|
|
131
|
-
title: "Get a worker evidence index",
|
|
132
|
-
description: "Return bounded event metadata and retained artifact IDs for one worker. It does not return raw history, prompts or a worker context capsule; use get_artifact or get_codex_worker_events for a selected item.",
|
|
133
|
-
inputSchema: { task_id: z.string().min(1), limit: z.number().int().min(1).max(100).default(30) }
|
|
134
|
-
},
|
|
135
|
-
async ({ task_id, limit }) => {
|
|
103
|
+
export const getWorkerEvidenceOp = {
|
|
104
|
+
input: z.object({ task_id: z.string().min(1), limit: z.number().int().min(1).max(100).default(30) }),
|
|
105
|
+
handler: async ({ task_id, limit }) => {
|
|
136
106
|
const task = await getTask(task_id);
|
|
137
107
|
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
138
108
|
const events = await readTaskEventRecords(task_id, limit);
|
|
@@ -149,7 +119,7 @@ export const getWorkerEvidenceTool = [
|
|
|
149
119
|
}))
|
|
150
120
|
});
|
|
151
121
|
}
|
|
152
|
-
|
|
122
|
+
};
|
|
153
123
|
|
|
154
124
|
function decodeFactCursor(cursor, taskId, query) {
|
|
155
125
|
if (!cursor) return 0;
|
|
@@ -178,19 +148,14 @@ function factFreshForTask(task, fact) {
|
|
|
178
148
|
}
|
|
179
149
|
}
|
|
180
150
|
|
|
181
|
-
export const
|
|
182
|
-
|
|
183
|
-
{
|
|
184
|
-
title: "Search verified worker facts in scope",
|
|
185
|
-
description: "Search only verified facts relevant to one task: its own work, explicit dependencies and path-matched repository facts. Returns compact summaries, coverage and a cursor; never raw events, reports, prompts or worker capsules.",
|
|
186
|
-
inputSchema: {
|
|
151
|
+
export const searchWorkerFactsOp = {
|
|
152
|
+
input: z.object({
|
|
187
153
|
task_id: z.string().min(1),
|
|
188
154
|
query: z.string().max(500).default(""),
|
|
189
155
|
limit: z.number().int().min(1).max(50).default(20),
|
|
190
156
|
cursor: z.string().min(1).optional()
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
async ({ task_id, query, limit, cursor }) => {
|
|
157
|
+
}),
|
|
158
|
+
handler: async ({ task_id, query, limit, cursor }) => {
|
|
194
159
|
const task = await getTask(task_id);
|
|
195
160
|
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
196
161
|
try {
|
|
@@ -236,4 +201,4 @@ export const searchWorkerFactsTool = [
|
|
|
236
201
|
return errorResult(error);
|
|
237
202
|
}
|
|
238
203
|
}
|
|
239
|
-
|
|
204
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { buildHostGoalSync } from "../../../domain/prompt.js";
|
|
2
|
+
import { ACTIVE_STATUSES } from "../../../domain/status.js";
|
|
3
|
+
import { truncateEventStrings } from "../../../domain/truncate.js";
|
|
4
|
+
import { getSession, upsertSession } from "../../../infra/store/sessions.js";
|
|
5
|
+
import { getTask, readTasksBySession, searchTasks } from "../../../infra/store/tasks.js";
|
|
6
|
+
import { restoreEventBodies } from "../../../infra/store/event-body.js";
|
|
7
|
+
import { listTaskEventKinds, readTaskEvents } from "../../../infra/store/events.js";
|
|
8
|
+
import { errorResult, textResult } from "../result.js";
|
|
9
|
+
import { acceptanceCheck } from "../schemas.js";
|
|
10
|
+
import { workRow } from "../views/overview.js";
|
|
11
|
+
import { statusView } from "../views/task.js";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
|
|
14
|
+
export const getSessionWorksOp = {
|
|
15
|
+
input: z.object({
|
|
16
|
+
session_id: z.string().min(1)
|
|
17
|
+
}),
|
|
18
|
+
handler: async ({ session_id }) => {
|
|
19
|
+
const tasks = await readTasksBySession(session_id);
|
|
20
|
+
const meta = await getSession(session_id);
|
|
21
|
+
return textResult({
|
|
22
|
+
session_id,
|
|
23
|
+
title: meta?.title ?? null,
|
|
24
|
+
note: meta?.note ?? null,
|
|
25
|
+
objective: meta?.objective ?? null,
|
|
26
|
+
default_acceptance: meta?.default_acceptance ?? [],
|
|
27
|
+
approval_state: meta?.approval_state ?? "approved",
|
|
28
|
+
policy_revision: meta?.policy_revision ?? 0,
|
|
29
|
+
count: tasks.length,
|
|
30
|
+
active: tasks.filter((task) => ACTIVE_STATUSES.has(task.status)).length,
|
|
31
|
+
works: tasks.map(workRow)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const describeSessionOp = {
|
|
37
|
+
input: z.object({
|
|
38
|
+
session_id: z.string().min(1),
|
|
39
|
+
title: z.string().min(1).max(120).optional(),
|
|
40
|
+
note: z.string().min(1).max(2000).optional(),
|
|
41
|
+
objective: z.string().min(1).max(5000).optional(),
|
|
42
|
+
default_acceptance: z.array(acceptanceCheck).max(10).optional(),
|
|
43
|
+
approval_state: z.enum(["approved", "waiting_user"]).optional(),
|
|
44
|
+
expected_revision: z.number().int().nonnegative().optional()
|
|
45
|
+
}),
|
|
46
|
+
handler: async ({ session_id, title, note, objective, default_acceptance, approval_state, expected_revision }) => {
|
|
47
|
+
try {
|
|
48
|
+
const row = await upsertSession({
|
|
49
|
+
id: session_id, title: title ?? null, note: note ?? null, objective,
|
|
50
|
+
defaultAcceptance: default_acceptance, approvalState: approval_state, expectedRevision: expected_revision
|
|
51
|
+
});
|
|
52
|
+
return textResult({ ...row, session_id, host_goal_sync: buildHostGoalSync(row) });
|
|
53
|
+
} catch (error) { return errorResult(error); }
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const searchWorksOp = {
|
|
58
|
+
input: z.object({
|
|
59
|
+
query: z.string().min(1),
|
|
60
|
+
limit: z.number().int().positive().max(100).default(20)
|
|
61
|
+
}),
|
|
62
|
+
handler: async ({ query, limit }) => {
|
|
63
|
+
const tasks = await searchTasks(query, limit);
|
|
64
|
+
return textResult({
|
|
65
|
+
query,
|
|
66
|
+
count: tasks.length,
|
|
67
|
+
works: tasks.map(workRow)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const getCodexWorkerStatusOp = {
|
|
73
|
+
input: z.object({
|
|
74
|
+
task_id: z.string().min(1),
|
|
75
|
+
includePrompt: z.boolean().default(false),
|
|
76
|
+
promptMaxChars: z.number().int().min(0).max(1000000).default(5000)
|
|
77
|
+
}),
|
|
78
|
+
handler: async ({ task_id, includePrompt, promptMaxChars }) => {
|
|
79
|
+
const task = await getTask(task_id);
|
|
80
|
+
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
81
|
+
return textResult(statusView(task, { includePrompt, promptMaxChars }));
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const getCodexWorkerEventsOp = {
|
|
86
|
+
input: z.object({
|
|
87
|
+
task_id: z.string().min(1),
|
|
88
|
+
limit: z.number().int().min(1).max(1000).default(100),
|
|
89
|
+
maxChars: z.number().int().min(0).max(1000000).optional(),
|
|
90
|
+
kinds: z.array(z.string().min(1)).optional()
|
|
91
|
+
}),
|
|
92
|
+
handler: async ({ task_id, limit, maxChars, kinds }) => {
|
|
93
|
+
const task = await getTask(task_id);
|
|
94
|
+
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
95
|
+
const stored = await readTaskEvents(task_id, limit, kinds ?? null);
|
|
96
|
+
// Large bodies live in the run log only; max_chars then cuts the whole event, as it always did.
|
|
97
|
+
const events = await restoreEventBodies(stored, task.run_log);
|
|
98
|
+
const trimmed = maxChars === undefined ? events : events.map((event) => truncateEventStrings(event, maxChars));
|
|
99
|
+
return textResult({
|
|
100
|
+
task_id,
|
|
101
|
+
count: trimmed.length,
|
|
102
|
+
available_kinds: await listTaskEventKinds(task_id),
|
|
103
|
+
events: trimmed
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
};
|