agent-supervisor-mcp 0.0.0-stage → 2.0.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/LICENSE +21 -0
- package/README.en.md +208 -0
- package/README.md +206 -2
- package/package.json +76 -4
- package/skills/agent-supervisor/SKILL.md +139 -0
- package/src/app/acceptance.js +263 -0
- package/src/app/auto-cleanup.js +91 -0
- package/src/app/cancel.js +57 -0
- package/src/app/cleanup-facts.js +101 -0
- package/src/app/cleanup-plan.js +166 -0
- package/src/app/compose.js +17 -0
- package/src/app/context-compiler.js +83 -0
- package/src/app/dispatch.js +398 -0
- package/src/app/followup.js +104 -0
- package/src/app/land-chain.js +134 -0
- package/src/app/landing.js +357 -0
- package/src/app/ownership.js +57 -0
- package/src/app/rebase.js +216 -0
- package/src/app/restore-worktree.js +51 -0
- package/src/app/resume.js +179 -0
- package/src/app/run-state.js +26 -0
- package/src/app/settled.js +28 -0
- package/src/app/side-chat.js +370 -0
- package/src/app/sse.js +20 -0
- package/src/app/start-run.js +77 -0
- package/src/app/verify-push.js +114 -0
- package/src/app/worktree-setup.js +218 -0
- package/src/domain/acceptance-baseline.js +65 -0
- package/src/domain/acceptance-spec.js +30 -0
- package/src/domain/cleanup-policy.js +44 -0
- package/src/domain/command-outcome.js +6 -0
- package/src/domain/failure-class.js +63 -0
- package/src/domain/owned-changes.js +27 -0
- package/src/domain/prompt.js +161 -0
- package/src/domain/side-turn-view.js +73 -0
- package/src/domain/status.js +50 -0
- package/src/domain/thread-health.js +33 -0
- package/src/domain/truncate.js +148 -0
- package/src/domain/worker-branch.js +6 -0
- package/src/domain/worker-changes.js +58 -0
- package/src/domain/worker-env.js +14 -0
- package/src/domain/worker-preflight.js +167 -0
- package/src/domain/worker-report.js +85 -0
- package/src/domain/worker-report.schema.json +10 -0
- package/src/infra/bin-resolver.js +287 -0
- package/src/infra/cleanup-hint.js +29 -0
- package/src/infra/crash-guard.js +44 -0
- package/src/infra/external-output.js +29 -0
- package/src/infra/git.js +61 -0
- package/src/infra/handoff.js +38 -0
- package/src/infra/paths.js +34 -0
- package/src/infra/process.js +59 -0
- package/src/infra/sandbox-roots.js +106 -0
- package/src/infra/skill-sync.js +109 -0
- package/src/infra/stage-store.js +39 -0
- package/src/infra/store/db.js +265 -0
- package/src/infra/store/event-body.js +82 -0
- package/src/infra/store/events.js +149 -0
- package/src/infra/store/facts.js +338 -0
- package/src/infra/store/reconcile.js +173 -0
- package/src/infra/store/records.js +171 -0
- package/src/infra/store/runner-readers.js +16 -0
- package/src/infra/store/schema.js +306 -0
- package/src/infra/store/sessions.js +138 -0
- package/src/infra/store/tasks.js +351 -0
- package/src/infra/update/auto-update-worker.js +186 -0
- package/src/infra/update/auto-update.js +143 -0
- package/src/infra/update/update-check.js +246 -0
- package/src/infra/workspace-kind.js +165 -0
- package/src/infra/worktree.js +361 -0
- package/src/interface/bin/acceptance-cli.js +62 -0
- package/src/interface/bin/cleanup.js +81 -0
- package/src/interface/bin/monitor.jsx +301 -0
- package/src/interface/bin/setup.js +342 -0
- package/src/interface/bin/stage.js +17 -0
- package/src/interface/bin/web-server.js +53 -0
- package/src/interface/mcp/handlers/delivery.js +165 -0
- package/src/interface/mcp/handlers/dispatch.js +236 -0
- package/src/interface/mcp/handlers/facts.js +204 -0
- package/src/interface/mcp/handlers/overview.js +106 -0
- package/src/interface/mcp/handlers/results.js +262 -0
- package/src/interface/mcp/handlers/review.js +115 -0
- package/src/interface/mcp/handlers/wait.js +141 -0
- package/src/interface/mcp/meta.js +7 -0
- package/src/interface/mcp/result.js +34 -0
- package/src/interface/mcp/schemas.js +24 -0
- package/src/interface/mcp/server.js +64 -0
- package/src/interface/mcp/tools/deliver.js +48 -0
- package/src/interface/mcp/tools/dispatch.js +90 -0
- 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 +67 -0
- package/src/interface/mcp/tools/track.js +84 -0
- package/src/interface/mcp/update-state.js +34 -0
- package/src/interface/mcp/views/overview.js +183 -0
- package/src/interface/mcp/views/task.js +224 -0
- package/src/interface/web/app.js +226 -0
- package/src/interface/web/views.js +227 -0
- package/src/mcp-server.js +4 -0
- package/src/run-host/entry.js +26 -0
- package/src/run-host/finalize.js +243 -0
- package/src/run-host/launch.js +49 -0
- package/src/run-host/live-run.js +76 -0
- package/src/run-host/outcome-facts.js +61 -0
- package/src/run-host/streams.js +102 -0
- package/src/run-host/track.js +132 -0
- package/src/runners/claude/adapter.js +118 -0
- package/src/runners/claude/events.js +100 -0
- package/src/runners/claude/tool-guard.js +48 -0
- package/src/runners/codex/adapter.js +157 -0
- package/src/runners/codex/chat-chunks.js +97 -0
- package/src/runners/codex/event-parser.js +266 -0
- package/src/runners/codex/goal-store.js +54 -0
- package/src/runners/codex/mcp-config.js +39 -0
- package/src/runners/codex/tool-guard.js +184 -0
- package/src/runners/contract-check.js +82 -0
- package/src/runners/contract.js +53 -0
- package/src/runners/registry.js +45 -0
- package/web/dist/assets/index-D-A2xlpx.js +154 -0
- package/web/dist/assets/index-f8esISCp.css +2 -0
- package/web/dist/index.html +15 -0
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { branchOf } from "../../../domain/worker-branch.js";
|
|
2
|
+
import { ensureTaskWorktree } from "../../../app/restore-worktree.js";
|
|
3
|
+
import { askWorker, endSideSession, latestSideTurn } from "../../../app/side-chat.js";
|
|
4
|
+
import { isGoalNeedingAttention, TERMINAL_STATUSES } from "../../../domain/status.js";
|
|
5
|
+
import { truncateMiddleChars, truncateReport } from "../../../domain/truncate.js";
|
|
6
|
+
import { getTask, recordTerminalChangedFiles } from "../../../infra/store/tasks.js";
|
|
7
|
+
import { readAgentMessages } from "../../../infra/store/events.js";
|
|
8
|
+
import { baseBehind, readTaskChanges, readWorktreeDiff, splitPatchHunks, workspaceSetupIgnorePaths, worktreeRef } from "../../../infra/worktree.js";
|
|
9
|
+
import { summarizeVerification } from "../../../runners/codex/event-parser.js";
|
|
10
|
+
import { readNativeGoal } from "../../../infra/store/runner-readers.js";
|
|
11
|
+
import { loadRunner } from "../../../runners/registry.js";
|
|
12
|
+
import { textResult } from "../result.js";
|
|
13
|
+
import { buildWorkerSummary, externalOutputView, reportView, runEvidenceView } from "../views/overview.js";
|
|
14
|
+
import { acceptanceView } from "../views/task.js";
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
|
|
17
|
+
// A runner with no native goal, or one this process cannot load, has none to read.
|
|
18
|
+
async function nativeGoalRead(task) {
|
|
19
|
+
const runner = await loadRunner(task.worker).catch(() => null);
|
|
20
|
+
return runner?.capabilities.native_goal ? runner.nativeGoalState(task.thread_id) : { state: "unsupported", goal: null };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const getWorkerGoalOp = {
|
|
24
|
+
input: z.object({
|
|
25
|
+
task_id: z.string().min(1)
|
|
26
|
+
}),
|
|
27
|
+
handler: async ({ task_id }) => {
|
|
28
|
+
const task = await getTask(task_id);
|
|
29
|
+
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
30
|
+
return textResult({
|
|
31
|
+
task_id,
|
|
32
|
+
thread_id: task.thread_id,
|
|
33
|
+
status: task.status,
|
|
34
|
+
objective: task.goal_objective,
|
|
35
|
+
token_budget: task.goal_token_budget,
|
|
36
|
+
goal_status: task.goal_status,
|
|
37
|
+
needs_attention: isGoalNeedingAttention(task.goal_status),
|
|
38
|
+
native_goal: readNativeGoal(task.thread_id, task.worker),
|
|
39
|
+
native_goal_read: await nativeGoalRead(task)
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const getWorkerSummaryOp = {
|
|
45
|
+
input: z.object({
|
|
46
|
+
task_id: z.string().min(1)
|
|
47
|
+
}),
|
|
48
|
+
handler: async ({ task_id }) => {
|
|
49
|
+
const task = await getTask(task_id);
|
|
50
|
+
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
51
|
+
const summary = buildWorkerSummary(task, readNativeGoal(task.thread_id, task.worker));
|
|
52
|
+
// Cache the worktree diff on the row once the worker is done, so the
|
|
53
|
+
// overview's count stops lagging. A running row is the runner's to write.
|
|
54
|
+
if (TERMINAL_STATUSES.has(task.status) && summary.changed_files.length !== (task.changed_files ?? []).length) {
|
|
55
|
+
await recordTerminalChangedFiles(task.id, summary.changed_files);
|
|
56
|
+
}
|
|
57
|
+
return textResult(summary);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const getWorkerResultOp = {
|
|
62
|
+
input: z.object({
|
|
63
|
+
task_id: z.string().min(1),
|
|
64
|
+
limit: z.number().int().min(1).max(20).default(1),
|
|
65
|
+
// Per report, UTF-8 bytes. 0 means no clipping.
|
|
66
|
+
maxChars: z.number().int().min(0).max(1000000).default(6000),
|
|
67
|
+
includeFiles: z.boolean().default(false)
|
|
68
|
+
}),
|
|
69
|
+
handler: async ({ task_id, limit, maxChars, includeFiles }) => {
|
|
70
|
+
const task = await getTask(task_id);
|
|
71
|
+
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
72
|
+
let reports = await readAgentMessages(task_id, limit);
|
|
73
|
+
let source = "event_stream";
|
|
74
|
+
if (reports.length === 0 && task.last_message) {
|
|
75
|
+
// Older rows can predate this tool, but the task row keeps the newest
|
|
76
|
+
// report even when the stream query finds nothing.
|
|
77
|
+
reports = [task.last_message];
|
|
78
|
+
source = "task_row";
|
|
79
|
+
}
|
|
80
|
+
const reportBytes = reports.map((text) => Buffer.byteLength(text, "utf8"));
|
|
81
|
+
const clipped = maxChars === 0 ? reports : reports.map((text) => truncateReport(text, maxChars));
|
|
82
|
+
const truncated = clipped.some((text, index) => text !== reports[index]);
|
|
83
|
+
const changed = readTaskChanges(task);
|
|
84
|
+
const behind = task.worktree_path ? baseBehind(task.project_root, task.base_commit) : null;
|
|
85
|
+
// A worker that ran in place has no worktree to diff, so this list is
|
|
86
|
+
// the only record of what it touched; it is never hidden for those.
|
|
87
|
+
const listFiles = includeFiles || !task.worktree_path;
|
|
88
|
+
return textResult({
|
|
89
|
+
task_id,
|
|
90
|
+
title: task.title,
|
|
91
|
+
status: task.status,
|
|
92
|
+
phase: task.phase ?? null,
|
|
93
|
+
exit_code: task.exit_code ?? null,
|
|
94
|
+
thread_id: task.thread_id,
|
|
95
|
+
session_id: task.session_id ?? null,
|
|
96
|
+
workspace_kind: task.workspace_kind ?? "legacy",
|
|
97
|
+
worktree_path: task.worktree_path,
|
|
98
|
+
goal_status: task.goal_status,
|
|
99
|
+
attention_reason: task.attention_reason ?? null,
|
|
100
|
+
run_evidence: runEvidenceView(task),
|
|
101
|
+
structured_report: reportView(task, maxChars),
|
|
102
|
+
input_context: task.input_context ?? null,
|
|
103
|
+
external_outputs: externalOutputView(task, maxChars || 6000),
|
|
104
|
+
changed_file_count: changed.length,
|
|
105
|
+
changed_files: listFiles ? changed : undefined,
|
|
106
|
+
base_commit: task.base_commit ?? null,
|
|
107
|
+
base_behind: behind,
|
|
108
|
+
landed: task.landed_at ? { at: task.landed_at, head: task.landed_head ?? null } : null,
|
|
109
|
+
acceptance: acceptanceView(task, behind),
|
|
110
|
+
verification: summarizeVerification(task),
|
|
111
|
+
report_count: clipped.length,
|
|
112
|
+
report_bytes: reportBytes,
|
|
113
|
+
truncated,
|
|
114
|
+
next_step: truncated
|
|
115
|
+
? `a report was clipped to ${maxChars} bytes; call again with max_chars: ${Math.max(...reportBytes)} (or 0) to read it whole`
|
|
116
|
+
: null,
|
|
117
|
+
reports: clipped,
|
|
118
|
+
source,
|
|
119
|
+
error: task.error ?? null,
|
|
120
|
+
completed_at: task.completed_at ?? null
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Cleanup keeps the branch; the diff is read from a worktree cut from it
|
|
126
|
+
// again. Null when the worktree is there, a refusal when it cannot come back.
|
|
127
|
+
async function restoreRefusal(task) {
|
|
128
|
+
try {
|
|
129
|
+
await ensureTaskWorktree(task);
|
|
130
|
+
return null;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
return textResult({ error: error.code ?? "worktree_restore_failed", task_id: task.id, reason: error.message.split("\n")[0] });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export const getWorkerDiffOp = {
|
|
137
|
+
input: z.object({
|
|
138
|
+
task_id: z.string().min(1),
|
|
139
|
+
maxChars: z.number().int().min(0).max(1000000).optional(),
|
|
140
|
+
file: z.string().min(1).optional(),
|
|
141
|
+
hunk: z.number().int().min(0).optional(),
|
|
142
|
+
pageSize: z.number().int().min(1).max(20).default(4),
|
|
143
|
+
cursor: z.string().min(1).optional(),
|
|
144
|
+
paths: z.array(z.string().min(1)).optional()
|
|
145
|
+
}),
|
|
146
|
+
handler: async ({ task_id, maxChars, file, hunk, pageSize, cursor, paths }) => {
|
|
147
|
+
const task = await getTask(task_id);
|
|
148
|
+
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
149
|
+
if (!task.worktree_path) {
|
|
150
|
+
return textResult({ error: "no_worktree", task_id, external_outputs: externalOutputView(task, maxChars), reason: "this worker ran in place (its cwd is not a git repository or the worktree could not be created), so there is no isolated diff to read; call get_worker with include result and include_files: true for the files it touched" });
|
|
151
|
+
}
|
|
152
|
+
const refusal = await restoreRefusal(task);
|
|
153
|
+
if (refusal) return refusal;
|
|
154
|
+
if (!file && maxChars !== undefined) {
|
|
155
|
+
const diff = readWorktreeDiff(task.worktree_path, worktreeRef(task), { maxChars, paths: paths ?? [], ignorePaths: workspaceSetupIgnorePaths(task) });
|
|
156
|
+
return textResult({
|
|
157
|
+
task_id,
|
|
158
|
+
title: task.title,
|
|
159
|
+
status: task.status,
|
|
160
|
+
worktree_path: task.worktree_path,
|
|
161
|
+
branch: branchOf(task),
|
|
162
|
+
...diff,
|
|
163
|
+
external_outputs: externalOutputView(task, maxChars)
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
const diffOptions = { maxChars: 10_000_000, paths: paths ?? [], ignorePaths: workspaceSetupIgnorePaths(task) };
|
|
167
|
+
const diff = readWorktreeDiff(task.worktree_path, worktreeRef(task), diffOptions);
|
|
168
|
+
if (diff.error) return textResult({ ...diff, task_id });
|
|
169
|
+
const files = diff.files.map((entry) => {
|
|
170
|
+
const parsed = splitPatchHunks(entry);
|
|
171
|
+
const { path, status, from, additions, deletions } = entry;
|
|
172
|
+
return { path, status, from, additions, deletions, hunk_count: parsed.hunks.length };
|
|
173
|
+
});
|
|
174
|
+
const base = {
|
|
175
|
+
task_id,
|
|
176
|
+
title: task.title,
|
|
177
|
+
status: task.status,
|
|
178
|
+
worktree_path: task.worktree_path,
|
|
179
|
+
branch: branchOf(task),
|
|
180
|
+
...diff,
|
|
181
|
+
files,
|
|
182
|
+
external_outputs: externalOutputView(task, maxChars || 6000)
|
|
183
|
+
};
|
|
184
|
+
if (!file) return textResult({ ...base, summary_only: true, next_step: "choose files[].path, then request file plus hunk or cursor" });
|
|
185
|
+
const selected = diff.files.find((entry) => entry.path === file);
|
|
186
|
+
if (!selected) return textResult({ error: "diff_file_not_found", task_id, file, files });
|
|
187
|
+
const parsed = splitPatchHunks(selected);
|
|
188
|
+
let offset = 0;
|
|
189
|
+
if (cursor) {
|
|
190
|
+
try {
|
|
191
|
+
const value = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
192
|
+
if (value.task_id !== task_id || value.file !== file || !Number.isInteger(value.offset) || value.offset < 0) throw new Error("mismatch");
|
|
193
|
+
offset = value.offset;
|
|
194
|
+
} catch {
|
|
195
|
+
return textResult({ error: "invalid_diff_cursor", task_id, file });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (hunk !== undefined) offset = hunk;
|
|
199
|
+
if (offset >= parsed.hunks.length) return textResult({ error: "diff_hunk_not_found", task_id, file, hunk: offset, hunk_count: parsed.hunks.length });
|
|
200
|
+
let remaining = maxChars ?? 24000;
|
|
201
|
+
const hunks = [];
|
|
202
|
+
for (let index = offset; index < parsed.hunks.length && hunks.length < pageSize; index += 1) {
|
|
203
|
+
if (remaining <= 0) break;
|
|
204
|
+
const item = parsed.hunks[index];
|
|
205
|
+
const patchText = item.patch.length > remaining ? truncateMiddleChars(item.patch, remaining) : item.patch;
|
|
206
|
+
hunks.push({ ...item, patch: patchText, truncated: patchText.length < item.patch.length });
|
|
207
|
+
remaining -= patchText.length;
|
|
208
|
+
}
|
|
209
|
+
const nextOffset = offset + hunks.length;
|
|
210
|
+
const nextCursor = nextOffset < parsed.hunks.length
|
|
211
|
+
? Buffer.from(JSON.stringify({ task_id, file, offset: nextOffset })).toString("base64url")
|
|
212
|
+
: null;
|
|
213
|
+
return textResult({
|
|
214
|
+
...base,
|
|
215
|
+
file: {
|
|
216
|
+
path: selected.path, status: selected.status, from: selected.from,
|
|
217
|
+
additions: selected.additions, deletions: selected.deletions, hunk_count: parsed.hunks.length
|
|
218
|
+
},
|
|
219
|
+
hunks,
|
|
220
|
+
next_cursor: nextCursor,
|
|
221
|
+
summary_only: false
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export const askCodexWorkerOp = {
|
|
227
|
+
input: z.object({
|
|
228
|
+
task_id: z.string().min(1),
|
|
229
|
+
question: z.string().min(1).optional(),
|
|
230
|
+
timeoutMs: z.number().int().min(1000).max(600000).default(110000),
|
|
231
|
+
maxChars: z.number().int().min(0).max(1000000).default(8000),
|
|
232
|
+
fresh: z.boolean().default(false),
|
|
233
|
+
end: z.boolean().default(false)
|
|
234
|
+
}),
|
|
235
|
+
handler: async ({ task_id, question, timeoutMs, maxChars, fresh, end }) => {
|
|
236
|
+
const task = await getTask(task_id);
|
|
237
|
+
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
238
|
+
const clipAnswer = (state) => {
|
|
239
|
+
if (state?.turn?.answer && maxChars !== undefined) state.turn.answer = truncateMiddleChars(state.turn.answer, maxChars);
|
|
240
|
+
return state;
|
|
241
|
+
};
|
|
242
|
+
if (end) {
|
|
243
|
+
const ended = await endSideSession(task_id);
|
|
244
|
+
return textResult({ task_id, ...ended });
|
|
245
|
+
}
|
|
246
|
+
if (!question) {
|
|
247
|
+
return textResult({ task_id, ...clipAnswer(await latestSideTurn(task_id)) });
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
const state = clipAnswer(await askWorker({ task, question, timeoutMs, fresh }));
|
|
251
|
+
const next = state.timed_out
|
|
252
|
+
? `The side turn is still running; call ask_worker again with only task_id to read the answer when it lands.`
|
|
253
|
+
: null;
|
|
254
|
+
return textResult({ task_id, ...state, next_step: next });
|
|
255
|
+
} catch (error) {
|
|
256
|
+
if (error.code === "busy") {
|
|
257
|
+
return textResult({ task_id, error: "busy", reason: error.message, ...clipAnswer(await latestSideTurn(task_id)) });
|
|
258
|
+
}
|
|
259
|
+
return textResult({ task_id, error: error.code ?? "side_turn_failed", reason: error.message });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createCodexWorker } from "../../../app/dispatch.js";
|
|
2
|
+
import { appendTaskEvent } from "../../../infra/store/events.js";
|
|
3
|
+
import { createReviewAssignment, getReviewByVerifierTask, recordJsonArtifact, recordReviewFinding, resolveReviewFinding } from "../../../infra/store/records.js";
|
|
4
|
+
import { getTask } from "../../../infra/store/tasks.js";
|
|
5
|
+
import { runIdFor } from "../../../infra/store/db.js";
|
|
6
|
+
import { errorResult, textResult } from "../result.js";
|
|
7
|
+
import { isSettled } from "../../../app/settled.js";
|
|
8
|
+
import { receipt } from "../views/task.js";
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
|
|
12
|
+
export const createIndependentVerifierOp = {
|
|
13
|
+
input: z.object({ task_id: z.string().min(1), title: z.string().min(1).max(120).optional() }),
|
|
14
|
+
handler: async ({ task_id, title }) => {
|
|
15
|
+
try {
|
|
16
|
+
const subject = await getTask(task_id);
|
|
17
|
+
if (!subject) return textResult({ error: "task_not_found", task_id });
|
|
18
|
+
if (!isSettled(subject)) return textResult({ error: "review_subject_active", task_id, reason: "wait for the worker and any acceptance to settle before independent review" });
|
|
19
|
+
const sourceRoot = subject.worktree_path ?? subject.project_root;
|
|
20
|
+
const verifier = await createCodexWorker({
|
|
21
|
+
title: title ?? `Independent review: ${subject.title ?? subject.id}`,
|
|
22
|
+
task: [
|
|
23
|
+
"Independently verify the target worker's objective from the current source tree and Git state.",
|
|
24
|
+
`Target task ID: ${subject.id}`,
|
|
25
|
+
`Target objective: ${subject.goal_objective ?? subject.title ?? "unspecified"}`,
|
|
26
|
+
`Inspect root: ${sourceRoot}`,
|
|
27
|
+
"Do not trust or request the target worker's report. Do not inspect candidate facts. Do not edit files, use network, create workers or call MCP tools.",
|
|
28
|
+
"Return whether the stated objective is met, the exact evidence you inspected, and any unresolved gap."
|
|
29
|
+
].join("\n"),
|
|
30
|
+
cwd: sourceRoot,
|
|
31
|
+
workspaceKind: "read_only_in_place",
|
|
32
|
+
sandbox: "read-only",
|
|
33
|
+
ownedPaths: [],
|
|
34
|
+
networkAccess: false,
|
|
35
|
+
goal: { objective: `Independently verify worker ${subject.id} without relying on its self-report` }
|
|
36
|
+
});
|
|
37
|
+
const fingerprint = createHash("sha256").update(JSON.stringify({
|
|
38
|
+
task_id: subject.id,
|
|
39
|
+
run: subject.run_count ?? 0,
|
|
40
|
+
base_sha: subject.base_commit ?? null,
|
|
41
|
+
worktree: sourceRoot,
|
|
42
|
+
updated_at: subject.updated_at ?? null,
|
|
43
|
+
changed_files: subject.changed_files ?? []
|
|
44
|
+
})).digest("hex");
|
|
45
|
+
const review = await createReviewAssignment({
|
|
46
|
+
subjectTaskId: subject.id,
|
|
47
|
+
verifierTaskId: verifier.id,
|
|
48
|
+
subjectRunId: runIdFor(subject.id, subject.run_count ?? 1),
|
|
49
|
+
subjectBaseSha: subject.base_commit ?? null,
|
|
50
|
+
subjectFingerprint: fingerprint
|
|
51
|
+
});
|
|
52
|
+
return textResult({ ...receipt(verifier), review });
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return errorResult(error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const recordIndependentFindingOp = {
|
|
60
|
+
input: z.object({ verifier_task_id: z.string().min(1), verdict: z.enum(["passes", "fails", "inconclusive"]), reason: z.string().min(1).max(4000) }),
|
|
61
|
+
handler: async ({ verifier_task_id, verdict, reason }) => {
|
|
62
|
+
try {
|
|
63
|
+
const review = await getReviewByVerifierTask(verifier_task_id);
|
|
64
|
+
if (!review) return textResult({ error: "review_not_found", verifier_task_id });
|
|
65
|
+
if (review.status !== "pending") return textResult({ error: "review_not_pending", verifier_task_id, status: review.status });
|
|
66
|
+
const verifier = await getTask(verifier_task_id);
|
|
67
|
+
if (!verifier || !isSettled(verifier)) return textResult({ error: "verifier_not_settled", verifier_task_id });
|
|
68
|
+
const subject = await getTask(review.subject_task_id);
|
|
69
|
+
if (!subject) return textResult({ error: "review_subject_not_found", task_id: review.subject_task_id });
|
|
70
|
+
const artifact = await recordJsonArtifact({
|
|
71
|
+
runId: runIdFor(verifier.id, verifier.run_count ?? 1),
|
|
72
|
+
type: "independent_review_finding",
|
|
73
|
+
value: {
|
|
74
|
+
review_id: review.id, subject_task_id: subject.id, verifier_task_id, verdict, reason,
|
|
75
|
+
verifier_run: verifier.run_count ?? 1, recorded_at: new Date().toISOString()
|
|
76
|
+
},
|
|
77
|
+
securityClass: "internal"
|
|
78
|
+
});
|
|
79
|
+
const event = await appendTaskEvent(subject.id, { type: "supervisor.independent_finding", review_id: review.id, verifier_task_id, verdict, reason, artifact_id: artifact.id }, {
|
|
80
|
+
runId: review.subject_run_id ?? runIdFor(subject.id, subject.run_count ?? 1), actor: "main_thread"
|
|
81
|
+
});
|
|
82
|
+
const recorded = await recordReviewFinding({
|
|
83
|
+
verifierTaskId: verifier_task_id, verdict, reason, evidenceArtifactId: artifact.id, findingEventId: event.id
|
|
84
|
+
});
|
|
85
|
+
return textResult({ review: recorded, artifact_id: artifact.id });
|
|
86
|
+
} catch (error) {
|
|
87
|
+
return errorResult(error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const resolveIndependentFindingOp = {
|
|
93
|
+
input: z.object({ verifier_task_id: z.string().min(1), resolution: z.string().min(1).max(4000) }),
|
|
94
|
+
handler: async ({ verifier_task_id, resolution }) => {
|
|
95
|
+
try {
|
|
96
|
+
const review = await resolveReviewFinding({ verifierTaskId: verifier_task_id, resolution });
|
|
97
|
+
if (!review) return textResult({ error: "review_not_recorded", verifier_task_id });
|
|
98
|
+
const subject = await getTask(review.subject_task_id);
|
|
99
|
+
if (subject) await appendTaskEvent(subject.id, { type: "supervisor.independent_finding_resolved", review_id: review.id, verifier_task_id, resolution }, {
|
|
100
|
+
runId: review.subject_run_id ?? runIdFor(subject.id, subject.run_count ?? 1), actor: "main_thread"
|
|
101
|
+
});
|
|
102
|
+
return textResult({ review });
|
|
103
|
+
} catch (error) {
|
|
104
|
+
return errorResult(error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const getIndependentReviewOp = {
|
|
110
|
+
input: z.object({ verifier_task_id: z.string().min(1) }),
|
|
111
|
+
handler: async ({ verifier_task_id }) => {
|
|
112
|
+
const review = await getReviewByVerifierTask(verifier_task_id);
|
|
113
|
+
return textResult(review ? { review } : { error: "review_not_found", verifier_task_id });
|
|
114
|
+
}
|
|
115
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { acceptanceVerdict } from "../../../app/acceptance.js";
|
|
2
|
+
import { ACTIVE_STATUSES } from "../../../domain/status.js";
|
|
3
|
+
import { truncateEventStrings } from "../../../domain/truncate.js";
|
|
4
|
+
import { getTasks } from "../../../infra/store/tasks.js";
|
|
5
|
+
import { restoreEventBodies } from "../../../infra/store/event-body.js";
|
|
6
|
+
import { readTaskEvents } from "../../../infra/store/events.js";
|
|
7
|
+
import { reconcileDetachedActiveTasks } from "../../../infra/store/reconcile.js";
|
|
8
|
+
import { readTaskChanges } from "../../../infra/worktree.js";
|
|
9
|
+
import { clip, sleep, textResult } from "../result.js";
|
|
10
|
+
import { withUpdate } from "../update-state.js";
|
|
11
|
+
import { isSettled } from "../../../app/settled.js";
|
|
12
|
+
import { compactLiveness, summarizeTask } from "../views/task.js";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
|
|
15
|
+
// Polls until the selected workers settle, the budget runs out or the client
|
|
16
|
+
// cancels. Returns whether the client cancelled.
|
|
17
|
+
async function pollUntilSettled({ task_ids, mode, pollMs, emitProgress }, { startedAt, effectiveTimeoutMs }, extra) {
|
|
18
|
+
const progressToken = extra?._meta?.progressToken;
|
|
19
|
+
let lastProgressAt = -Infinity;
|
|
20
|
+
while (Date.now() - startedAt < effectiveTimeoutMs) {
|
|
21
|
+
if (extra?.signal.aborted) return true;
|
|
22
|
+
await reconcileDetachedActiveTasks();
|
|
23
|
+
const tasks = (await getTasks(task_ids)).filter(Boolean);
|
|
24
|
+
const settledCount = tasks.filter(isSettled).length;
|
|
25
|
+
const isDone = mode === "any" ? settledCount > 0 : settledCount === task_ids.length;
|
|
26
|
+
if (isDone) break;
|
|
27
|
+
const elapsed = Date.now() - startedAt;
|
|
28
|
+
if (emitProgress && progressToken != null && elapsed - lastProgressAt >= 30000) {
|
|
29
|
+
await extra.sendNotification({ method: "notifications/progress", params: {
|
|
30
|
+
progressToken, progress: elapsed, total: effectiveTimeoutMs,
|
|
31
|
+
message: `${settledCount}/${task_ids.length} workers settled; wait budget only`
|
|
32
|
+
} }).catch(() => {});
|
|
33
|
+
lastProgressAt = elapsed;
|
|
34
|
+
}
|
|
35
|
+
await sleep(Math.min(pollMs, Math.max(0, effectiveTimeoutMs - (Date.now() - startedAt))));
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function budgetExhaustedHint(effectiveTimeoutMs) {
|
|
41
|
+
const budgetLabel =
|
|
42
|
+
effectiveTimeoutMs >= 60000
|
|
43
|
+
? `${Math.round(effectiveTimeoutMs / 60000)}-minute`
|
|
44
|
+
: `${Math.round(effectiveTimeoutMs / 1000)}-second`;
|
|
45
|
+
return `Workers are still running; the ${budgetLabel} wait budget ran out. Reuse the same task_ids for a short wait, or schedule poll_workers for long monitoring. Set allow_long_wait only after verifying the client's MCP timeout supports the requested budget; do not start another long wait while a background wait is active.`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function compactWorkerRow(task) {
|
|
49
|
+
return {
|
|
50
|
+
id: task.id,
|
|
51
|
+
title: clip(task.title, 60),
|
|
52
|
+
status: task.status,
|
|
53
|
+
phase: task.phase ?? null,
|
|
54
|
+
exit_code: task.exit_code ?? null,
|
|
55
|
+
changed_file_count: readTaskChanges(task).length,
|
|
56
|
+
acceptance: acceptanceVerdict(task),
|
|
57
|
+
...compactLiveness(task),
|
|
58
|
+
updated_at: task.updated_at ?? null
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function fullWorkerRows(tasks, { includeEvents, eventLimit, eventMaxChars, eventKinds }) {
|
|
63
|
+
return Promise.all(
|
|
64
|
+
tasks.map(async (task) => ({
|
|
65
|
+
...summarizeTask(task),
|
|
66
|
+
recent_events: includeEvents
|
|
67
|
+
? await readTaskEvents(task.id, eventLimit, eventKinds ?? null)
|
|
68
|
+
.then((stored) => restoreEventBodies(stored, task.run_log))
|
|
69
|
+
.then((events) => (eventMaxChars === undefined ? events : events.map((event) => truncateEventStrings(event, eventMaxChars))))
|
|
70
|
+
: undefined
|
|
71
|
+
}))
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function waitForWorkers(input, extra) {
|
|
76
|
+
const { task_ids, mode, timeoutMinutes, timeoutMs, allowLongWait, includeEvents, compact: requestedCompact } = input;
|
|
77
|
+
const compact = requestedCompact ?? !includeEvents;
|
|
78
|
+
const startedAt = Date.now();
|
|
79
|
+
const requestedTimeoutMs = timeoutMs ?? timeoutMinutes * 60 * 1000;
|
|
80
|
+
const effectiveTimeoutMs = allowLongWait ? requestedTimeoutMs : Math.min(requestedTimeoutMs, 60000);
|
|
81
|
+
const clientCancelled = await pollUntilSettled(input, { startedAt, effectiveTimeoutMs }, extra);
|
|
82
|
+
|
|
83
|
+
await reconcileDetachedActiveTasks();
|
|
84
|
+
const tasks = (await getTasks(task_ids)).filter(Boolean);
|
|
85
|
+
const missingIds = task_ids.filter((taskId) => !tasks.some((task) => task.id === taskId));
|
|
86
|
+
const settledTasks = tasks.filter(isSettled);
|
|
87
|
+
const timedOut =
|
|
88
|
+
mode === "any" ? settledTasks.length === 0 : settledTasks.length !== task_ids.length;
|
|
89
|
+
const summaries = await fullWorkerRows(tasks, input);
|
|
90
|
+
|
|
91
|
+
return textResult(withUpdate({
|
|
92
|
+
mode,
|
|
93
|
+
timed_out: timedOut,
|
|
94
|
+
still_running: timedOut,
|
|
95
|
+
termination_reason: clientCancelled ? "client_cancelled" : timedOut ? "budget_exhausted" : "settled",
|
|
96
|
+
next_step: timedOut ? budgetExhaustedHint(effectiveTimeoutMs) : null,
|
|
97
|
+
waited_ms: Date.now() - startedAt,
|
|
98
|
+
timeout_ms: effectiveTimeoutMs,
|
|
99
|
+
requested_timeout_ms: requestedTimeoutMs,
|
|
100
|
+
timeout_capped: effectiveTimeoutMs !== requestedTimeoutMs,
|
|
101
|
+
timeout_minutes: Math.round(effectiveTimeoutMs / 60000),
|
|
102
|
+
missing_ids: missingIds,
|
|
103
|
+
completed_count: tasks.filter((task) => task.status === "completed").length,
|
|
104
|
+
failed_count: tasks.filter((task) => task.status === "failed").length,
|
|
105
|
+
cancelled_count: tasks.filter((task) => task.status === "cancelled").length,
|
|
106
|
+
lost_count: tasks.filter((task) => task.status === "lost").length,
|
|
107
|
+
timed_out_count: tasks.filter((task) => task.status === "timed_out").length,
|
|
108
|
+
active_count: tasks.filter((task) => ACTIVE_STATUSES.has(task.status)).length,
|
|
109
|
+
acceptance_failed_count: tasks.filter((task) => task.acceptance_results?.passed === false).length,
|
|
110
|
+
workers: compact ? tasks.map(compactWorkerRow) : summaries
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const waitCodexWorkersOp = {
|
|
115
|
+
input: z.object({
|
|
116
|
+
task_ids: z.array(z.string().min(1)).min(1),
|
|
117
|
+
mode: z.enum(["any", "all"]).default("all"),
|
|
118
|
+
timeoutMinutes: z.number().int().min(1).max(360).default(1),
|
|
119
|
+
timeoutMs: z.number().int().min(1000).max(21600000).optional(),
|
|
120
|
+
allowLongWait: z.boolean().default(false),
|
|
121
|
+
pollMs: z.number().int().min(250).max(10000).default(1000),
|
|
122
|
+
emitProgress: z.boolean().default(false),
|
|
123
|
+
// Off by default. A wait is the call clients background and then replay
|
|
124
|
+
// as a notification, so its payload has to stay small; ten events per
|
|
125
|
+
// worker was the bulk of it. Ask for events explicitly, or read
|
|
126
|
+
// get_worker (include events) for one worker.
|
|
127
|
+
includeEvents: z.boolean().default(false),
|
|
128
|
+
eventLimit: z.number().int().min(1).max(50).default(10),
|
|
129
|
+
// Events used to come back whole: one command event can carry a heredoc
|
|
130
|
+
// that is tens of KB, and ten of those made a single wait response
|
|
131
|
+
// unreadable. The default bounds each string; pass a bigger number when
|
|
132
|
+
// you actually want the raw text.
|
|
133
|
+
eventMaxChars: z.number().int().min(0).max(1000000).default(800),
|
|
134
|
+
eventKinds: z.array(z.string().min(1)).optional(),
|
|
135
|
+
// The smallest useful answer: one line per worker, for a caller that
|
|
136
|
+
// only wants to know who is done. Everything else comes from
|
|
137
|
+
// get_worker (include result) / get_worker_diff afterwards.
|
|
138
|
+
compact: z.boolean().optional()
|
|
139
|
+
}),
|
|
140
|
+
handler: waitForWorkers
|
|
141
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
// Report the real package version. This string had drifted to 0.4.0 while the
|
|
4
|
+
// package shipped 0.5.x, so the handshake named a version nobody was running.
|
|
5
|
+
export const packageVersion = JSON.parse(
|
|
6
|
+
readFileSync(new URL("../../../package.json", import.meta.url), "utf8")
|
|
7
|
+
).version;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function textResult(value) {
|
|
2
|
+
return {
|
|
3
|
+
content: [
|
|
4
|
+
{
|
|
5
|
+
type: "text",
|
|
6
|
+
text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
|
|
7
|
+
}
|
|
8
|
+
]
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function clip(value, maxChars) {
|
|
13
|
+
if (value === null || value === undefined) return null;
|
|
14
|
+
const text = String(value);
|
|
15
|
+
return text.length <= maxChars ? text : `${text.slice(0, maxChars)}…`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function sleep(ms) {
|
|
19
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function errorDetails(details) {
|
|
23
|
+
return { files: details.files ?? [], git: details.git ?? null, base_commit: details.base_commit ?? null, head: details.head ?? null };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function errorResult(error) {
|
|
27
|
+
return textResult({
|
|
28
|
+
error: error.code ?? "error",
|
|
29
|
+
message: error.message,
|
|
30
|
+
...(error.conflicts ? { conflicts: error.conflicts } : {}),
|
|
31
|
+
...(error.details?.preflight ? { preflight: error.details.preflight } : {}),
|
|
32
|
+
...(error.details ? errorDetails(error.details) : {})
|
|
33
|
+
});
|
|
34
|
+
}
|