@a-t-h-i/bot-lobby 0.6.61 → 0.6.63
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.md +8 -8
- package/package.json +2 -1
- package/prompts/designer.md +25 -15
- package/prompts/master.md +284 -491
- package/prompts/panel.md +7 -0
- package/prompts/planner.md +15 -4
- package/prompts/qa.md +5 -1
- package/prompts/worker.md +0 -7
- package/scripts/builtin/affected_packages.mjs +106 -0
- package/scripts/builtin/check_changed.mjs +51 -0
- package/scripts/builtin/check_contract_breakage.mjs +118 -0
- package/scripts/builtin/circular_dependency_check.mjs +79 -0
- package/scripts/builtin/code_duplication_check.mjs +86 -0
- package/scripts/builtin/diff_summary.mjs +62 -0
- package/scripts/builtin/failure_digest.mjs +107 -0
- package/scripts/builtin/find_generated_files.mjs +79 -0
- package/scripts/builtin/find_symbol.mjs +81 -0
- package/scripts/builtin/find_test_fixtures.mjs +73 -0
- package/scripts/builtin/find_tests_for.mjs +12 -0
- package/scripts/builtin/lib/common.mjs +267 -0
- package/scripts/builtin/outline_file.mjs +77 -0
- package/scripts/builtin/project_commands.mjs +49 -0
- package/scripts/builtin/recent_changes.mjs +14 -0
- package/scripts/builtin/repo_map.mjs +65 -0
- package/scripts/builtin/run_changed_tests.mjs +48 -0
- package/src/delivery/transport.ts +1 -1
- package/src/desk/client-extension.ts +1 -31
- package/src/desk/ipc.ts +1 -11
- package/src/desk/session.ts +4 -101
- package/src/execution/agent-runner.ts +50 -8
- package/src/execution/assigned-session.ts +263 -0
- package/src/execution/assignment-discovery.ts +128 -0
- package/src/execution/assignment-policy.ts +46 -0
- package/src/execution/assignment.ts +175 -0
- package/src/execution/delegation.ts +9 -94
- package/src/execution/pi-runner.ts +99 -9
- package/src/harness/instructions.ts +1 -1
- package/src/index.ts +3 -0
- package/src/knowledge/design-record.ts +394 -0
- package/src/knowledge/file-notes.ts +36 -8
- package/src/lobby/ask.ts +6 -0
- package/src/lobby/exec.ts +28 -0
- package/src/lobby/host.ts +2 -11
- package/src/lobby/pi-commands.ts +83 -0
- package/src/lobby/planner.ts +50 -124
- package/src/lobby/prompts.ts +1 -7
- package/src/lobby/runtime.ts +2 -26
- package/src/lobby/service.ts +28 -27
- package/src/lobby/topics.ts +0 -2
- package/src/master/evidence-freshness.ts +96 -0
- package/src/master/master.ts +248 -74
- package/src/master/scout-cache.ts +1 -1
- package/src/master/scout-lock.ts +44 -0
- package/src/master/scout-prefetch.ts +78 -0
- package/src/pi/activity.ts +2 -0
- package/src/pi/assignment-guard.ts +157 -0
- package/src/pi/delegation.ts +2 -21
- package/src/pi/model-support.ts +0 -6
- package/src/pi/start-task.ts +18 -7
- package/src/pi/tools.ts +41 -8
- package/src/roles/scout.ts +3 -1
- package/src/roles/worker.ts +107 -5
- package/src/schemas/configuration.ts +11 -45
- package/src/schemas/findings.ts +3 -0
- package/src/schemas/task.ts +30 -12
- package/src/scripts/library.ts +31 -1
- package/src/scripts/pick.ts +31 -15
- package/src/state/archive.ts +10 -0
- package/src/state/checkpoint.ts +0 -1
- package/src/state/gitignore.ts +39 -0
- package/src/state/persistence.ts +56 -0
- package/src/state/recovery.ts +33 -1
- package/src/webui/api/index.ts +6 -35
- package/src/webui/api/retention.ts +44 -0
- package/src/webui/api/status.ts +5 -6
- package/src/webui/dev/fake-service.ts +8 -117
- package/src/webui/dev/fixtures.ts +2 -16
- package/src/webui/protocol.ts +3 -142
- package/src/workflow/draft-assignments.ts +118 -0
- package/src/workflow/workflow.ts +271 -214
- package/webui/dist/assets/{CodeSurface-BtzJOVyH.js → CodeSurface-CdyiJTYa.js} +1 -1
- package/webui/dist/assets/{TerminalView-Cz-KNWsq.js → TerminalView-D2nbR2J1.js} +1 -1
- package/webui/dist/assets/index-BTyu99rI.css +2 -0
- package/webui/dist/assets/index-BUGK22Z6.js +112 -0
- package/webui/dist/build.json +32 -68
- package/webui/dist/index.html +2 -2
- package/prompts/expert.md +0 -17
- package/prompts/goal-check.md +0 -44
- package/prompts/pr-review.md +0 -62
- package/prompts/splitter.md +0 -58
- package/src/execution/worker-trees.ts +0 -396
- package/src/lobby/issues.ts +0 -219
- package/src/lobby/pr-review.ts +0 -366
- package/src/lobby/pulls.ts +0 -250
- package/src/lobby/split.ts +0 -262
- package/src/master/goal-check.ts +0 -115
- package/src/webui/api/gh-error.ts +0 -17
- package/src/webui/api/git.ts +0 -98
- package/src/webui/api/issues.ts +0 -50
- package/webui/dist/assets/index-D5fvY8f8.js +0 -112
- package/webui/dist/assets/index-DFvk8ADr.css +0 -2
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The in-process guard for a worker running a structured assignment. The
|
|
3
|
+
* engine passes the assignment's replacement tool allowlist, its files and
|
|
4
|
+
* its discovery ledger through `BOT_LOBBY_ASSIGNMENT`; inside the pi process
|
|
5
|
+
* this guard:
|
|
6
|
+
*
|
|
7
|
+
* - reapplies the allowlist before every run and checks the declared tools
|
|
8
|
+
* (the active set and the tools in each provider request) against it,
|
|
9
|
+
* writing an attestation the engine requires after the run, and stopping
|
|
10
|
+
* the worker when an unauthorized declaration survives;
|
|
11
|
+
* - blocks every call outside the allowlist, direct, discovered or nested
|
|
12
|
+
* (codemode scripts' calls arrive here too), so codemode never reaches an
|
|
13
|
+
* unselected MCP tool;
|
|
14
|
+
* - charges discovery lookups (reads of unassigned files, searches, listings)
|
|
15
|
+
* one by one against the persisted ledger, under its lock, so concurrent and
|
|
16
|
+
* nested calls count separately and a retry keeps what was spent;
|
|
17
|
+
* - refuses edits to files the assignment does not mark edit or create.
|
|
18
|
+
*
|
|
19
|
+
* Shell use is instruction-governed: a `bash` call is never charged or
|
|
20
|
+
* blocked here (only an exact assigned verification command is named free).
|
|
21
|
+
*/
|
|
22
|
+
import { mkdirSync, renameSync, writeFileSync } from "node:fs";
|
|
23
|
+
import { dirname, resolve } from "node:path";
|
|
24
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
25
|
+
import { consumeAssignmentDiscovery } from "../execution/assignment-discovery.ts";
|
|
26
|
+
|
|
27
|
+
export const ASSIGNMENT_ENV = "BOT_LOBBY_ASSIGNMENT";
|
|
28
|
+
|
|
29
|
+
/** What the engine hands the worker's process; host-authored, never from model output. */
|
|
30
|
+
export interface AssignmentGuardSpec {
|
|
31
|
+
taskDir: string;
|
|
32
|
+
assignmentId: string;
|
|
33
|
+
revision: number;
|
|
34
|
+
/** The replacement allowlist, sorted and deduplicated. */
|
|
35
|
+
tools: string[];
|
|
36
|
+
cwd: string;
|
|
37
|
+
files: { path: string; access: "reference" | "edit" | "create" }[];
|
|
38
|
+
verification: string[];
|
|
39
|
+
/** Where the guard writes what it saw and enforced, for the engine to check after the run. */
|
|
40
|
+
attestation: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface AssignmentAttestation {
|
|
44
|
+
assignmentId: string;
|
|
45
|
+
revision: number;
|
|
46
|
+
allowed: string[];
|
|
47
|
+
declared: string[];
|
|
48
|
+
/** Tools a script could reach by name; every call to one outside the allowlist is blocked. */
|
|
49
|
+
blockedCallable: string[];
|
|
50
|
+
unauthorized: string[];
|
|
51
|
+
ok: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Tools that look things up; each call (outside the assigned files) is one discovery lookup. */
|
|
55
|
+
export const DISCOVERY_TOOLS: readonly string[] = ["grep", "find", "ls", "tool_search", "search_knowledge", "find_relevant_files"];
|
|
56
|
+
const EDIT_TOOLS = new Set(["edit", "write"]);
|
|
57
|
+
|
|
58
|
+
export function parseAssignmentGuard(raw: string | undefined): AssignmentGuardSpec | undefined {
|
|
59
|
+
if (!raw) return undefined;
|
|
60
|
+
const spec = JSON.parse(raw) as AssignmentGuardSpec;
|
|
61
|
+
const valid = typeof spec?.taskDir === "string" && typeof spec.assignmentId === "string" && Number.isSafeInteger(spec.revision) && Array.isArray(spec.tools)
|
|
62
|
+
&& typeof spec.cwd === "string" && Array.isArray(spec.files) && Array.isArray(spec.verification) && typeof spec.attestation === "string";
|
|
63
|
+
if (!valid) throw new Error("Invalid bot-lobby assignment guard.");
|
|
64
|
+
return spec;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function inputPath(input: unknown): string | undefined {
|
|
68
|
+
const record = (input ?? {}) as { path?: unknown; file_path?: unknown };
|
|
69
|
+
const path = record.path ?? record.file_path;
|
|
70
|
+
return typeof path === "string" && path.trim() ? path.trim().replace(/^@/, "") : undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Tool names a provider request declares, across the payload shapes pi's providers send. */
|
|
74
|
+
export function payloadToolNames(payload: unknown): string[] | undefined {
|
|
75
|
+
const tools = (payload as { tools?: unknown } | undefined)?.tools;
|
|
76
|
+
if (!Array.isArray(tools)) return undefined;
|
|
77
|
+
return tools.map((tool) => {
|
|
78
|
+
const entry = tool as { name?: unknown; function?: { name?: unknown }; functionDeclarations?: { name?: unknown }[] };
|
|
79
|
+
return typeof entry.name === "string" ? entry.name : typeof entry.function?.name === "string" ? entry.function.name : "";
|
|
80
|
+
}).filter(Boolean);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Drop undeclared tools from a provider payload; other shapes pass through untouched. */
|
|
84
|
+
function filterPayload(payload: unknown, allowed: ReadonlySet<string>): unknown {
|
|
85
|
+
const record = payload as { tools?: unknown[] };
|
|
86
|
+
if (!Array.isArray(record?.tools)) return payload;
|
|
87
|
+
const tools = record.tools.filter((tool) => {
|
|
88
|
+
const entry = tool as { name?: unknown; function?: { name?: unknown } };
|
|
89
|
+
const name = typeof entry.name === "string" ? entry.name : typeof entry.function?.name === "string" ? entry.function.name : undefined;
|
|
90
|
+
return name === undefined || allowed.has(name);
|
|
91
|
+
});
|
|
92
|
+
return tools.length === record.tools.length ? payload : { ...record, tools };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type GuardDecision = { block: true; reason: string; terminate?: boolean } | { charge: number } | undefined;
|
|
96
|
+
|
|
97
|
+
/** The pure part of the call check: allowlist, edit scope, and how many lookups the call costs. */
|
|
98
|
+
export function checkAssignedCall(spec: AssignmentGuardSpec, name: string, input: unknown): GuardDecision {
|
|
99
|
+
if (!spec.tools.includes(name)) return { block: true, reason: `${name} is not selected for assignment ${spec.assignmentId}. Add a tools need ({"kind":"tools", ...}) to your report and continue with the work it does not affect.` };
|
|
100
|
+
const path = inputPath(input);
|
|
101
|
+
const target = path ? resolve(spec.cwd, path) : undefined;
|
|
102
|
+
const assigned = target ? spec.files.find((file) => resolve(spec.cwd, file.path) === target) : undefined;
|
|
103
|
+
if (EDIT_TOOLS.has(name)) {
|
|
104
|
+
if (assigned && assigned.access !== "reference") return undefined;
|
|
105
|
+
return { block: true, reason: `${path ?? "That file"} is not an edit or create path of assignment ${spec.assignmentId}. Finding a file does not let you edit it: add a files need ({"kind":"files", ...}) to your report.` };
|
|
106
|
+
}
|
|
107
|
+
if (name === "read") return assigned ? undefined : { charge: 1 };
|
|
108
|
+
if (name === "bash") return undefined;
|
|
109
|
+
return DISCOVERY_TOOLS.includes(name) ? { charge: 1 } : undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function writeAttestation(path: string, attestation: AssignmentAttestation): void {
|
|
113
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
114
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
115
|
+
writeFileSync(temporary, `${JSON.stringify(attestation)}\n`, { mode: 0o600 });
|
|
116
|
+
renameSync(temporary, path);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function registerAssignmentGuard(pi: ExtensionAPI, spec = parseAssignmentGuard(process.env[ASSIGNMENT_ENV])): void {
|
|
120
|
+
if (!spec) return;
|
|
121
|
+
const allowed = new Set(spec.tools);
|
|
122
|
+
let failure: string | undefined;
|
|
123
|
+
|
|
124
|
+
pi.on("before_agent_start", (_event, ctx) => {
|
|
125
|
+
// Reapply: a restored conversation or another extension may have widened the active set.
|
|
126
|
+
pi.setActiveTools(pi.getActiveTools().filter((name) => allowed.has(name)));
|
|
127
|
+
const declared = [...new Set(pi.getActiveTools())].sort();
|
|
128
|
+
const unauthorized = declared.filter((name) => !allowed.has(name));
|
|
129
|
+
const scripted = declared.includes("codemode") ? pi.getAllTools().filter((tool) => tool.exposure === "codemode" || tool.exposure === "deferred").map((tool) => tool.name) : [];
|
|
130
|
+
const blockedCallable = [...new Set(scripted.filter((name) => !allowed.has(name)))].sort();
|
|
131
|
+
writeAttestation(spec.attestation, { assignmentId: spec.assignmentId, revision: spec.revision, allowed: [...allowed].sort(), declared, blockedCallable, unauthorized, ok: unauthorized.length === 0 });
|
|
132
|
+
if (unauthorized.length > 0) {
|
|
133
|
+
failure = `Assigned execution compatibility: ${unauthorized.join(", ")} stayed declared after the allowlist was reapplied; the worker was stopped.`;
|
|
134
|
+
ctx.abort();
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
pi.on("before_provider_request", (event) => {
|
|
139
|
+
if (failure) throw new Error(failure);
|
|
140
|
+
const names = payloadToolNames(event.payload);
|
|
141
|
+
if (!names || names.every((name) => allowed.has(name))) return undefined;
|
|
142
|
+
return filterPayload(event.payload, allowed);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
pi.on("tool_call", async (event) => {
|
|
146
|
+
if (failure) return { block: true, reason: failure, terminate: true };
|
|
147
|
+
const decision = checkAssignedCall(spec, event.toolName, event.input);
|
|
148
|
+
if (!decision || !("charge" in decision)) return decision;
|
|
149
|
+
try {
|
|
150
|
+
await consumeAssignmentDiscovery(spec.taskDir, spec.assignmentId, spec.revision, decision.charge);
|
|
151
|
+
return undefined;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
154
|
+
return { block: true, reason: `${reason}. Work with your assigned files; add a discovery need ({"kind":"discovery", ...}) to your report for anything else.` };
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
package/src/pi/delegation.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
2
|
import { Type } from "typebox";
|
|
4
3
|
import { createDeskClient } from "../desk/ipc.ts";
|
|
5
|
-
import { AGENT_ENV, DELEGATION_ENV, DELEGATE_TOOL,
|
|
4
|
+
import { AGENT_ENV, DELEGATION_ENV, DELEGATE_TOOL, MAX_CHILDREN, type AgentPolicy } from "../execution/delegation.ts";
|
|
6
5
|
import { loadConfig } from "../state/project.ts";
|
|
7
6
|
import { isSubagentProcess } from "./quiet.ts";
|
|
8
7
|
|
|
9
8
|
export function allowedAgentTool(policy: AgentPolicy, name: string, readOnlyHint?: boolean, hidden = false): boolean {
|
|
10
9
|
if (hidden) return false;
|
|
11
10
|
if (name.startsWith("mcp__")) return policy.mcpTools.includes(name) && (!policy.readOnly || readOnlyHint === true);
|
|
12
|
-
if (
|
|
11
|
+
if (name === DELEGATE_TOOL && policy.depth > 1) return false;
|
|
13
12
|
return policy.tools.includes(name);
|
|
14
13
|
}
|
|
15
14
|
|
|
@@ -68,22 +67,4 @@ export function registerDelegation(pi: ExtensionAPI): void {
|
|
|
68
67
|
} finally { signal?.removeEventListener("abort", cancel); }
|
|
69
68
|
},
|
|
70
69
|
});
|
|
71
|
-
pi.registerTool({
|
|
72
|
-
name: EXPERT_TOOL,
|
|
73
|
-
label: "Ask an expert",
|
|
74
|
-
description: `Ask a stronger model for advice on a hard step: a bug you cannot find after a real attempt, a tricky algorithm, an unfamiliar API, or a choice you are unsure of. Say what you are trying to do, what you tried and what happened, and point to the files and lines. It reads the repository and answers; it does not change anything, and you still do the work. At most ${MAX_CONSULTS} per step.`,
|
|
75
|
-
parameters: Type.Object({ question: Type.String({ minLength: 1, maxLength: 6000, description: "The question, with what you tried and the files and lines involved" }) }),
|
|
76
|
-
executionMode: "sequential",
|
|
77
|
-
async execute(_id, params, signal) {
|
|
78
|
-
signal?.throwIfAborted();
|
|
79
|
-
const consultId = randomUUID();
|
|
80
|
-
const cancel = () => { void client.request({ op: "cancel_consult", consultId }); };
|
|
81
|
-
signal?.addEventListener("abort", cancel, { once: true });
|
|
82
|
-
try {
|
|
83
|
-
const answer = await client.request({ op: "consult", text: params.question, consultId }, 0);
|
|
84
|
-
if (!answer.ok) throw new Error(answer.text);
|
|
85
|
-
return { content: [{ type: "text", text: `Expert advice:\n${answer.text}` }], details: undefined };
|
|
86
|
-
} finally { signal?.removeEventListener("abort", cancel); }
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
70
|
}
|
package/src/pi/model-support.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { clampThinkingLevel, getSupportedThinkingLevels, type Api, type Model, type ModelThinkingLevel } from "@earendil-works/pi-ai";
|
|
2
2
|
import {
|
|
3
3
|
agentProfile,
|
|
4
|
-
expertProfile,
|
|
5
4
|
isThinkingLevel,
|
|
6
5
|
lobbyAgentProfile,
|
|
7
6
|
panelMemberProfile,
|
|
@@ -110,11 +109,6 @@ function resolveRunProfile(profile: RunProfile, label: string, options: Resolver
|
|
|
110
109
|
return { ...profile, model, thinking: check.level };
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
/** The model ask_expert consults on: the expert setting's, else the oracle's, else the session's; thinking clamped to it. */
|
|
114
|
-
export function resolveExpertProfile(config: BotLobbyConfig, options: ResolverOptions): { model?: string; thinking: string } {
|
|
115
|
-
const { model, thinking } = resolveRunProfile(expertProfile(config), "Expert consult", options);
|
|
116
|
-
return { ...(model ? { model } : {}), thinking };
|
|
117
|
-
}
|
|
118
112
|
|
|
119
113
|
/** A lobby agent's model, thinking and grants. */
|
|
120
114
|
export function resolveLobbyProfile(config: BotLobbyConfig, kind: LobbyAgentKind, options: ResolverOptions): RunProfile {
|
package/src/pi/start-task.ts
CHANGED
|
@@ -8,7 +8,8 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
|
|
|
8
8
|
import { createTask, taskRequest, type Task, type TaskTrack, type TaskTriage, type TrackPath } from "../schemas/task.ts";
|
|
9
9
|
import type { Domain } from "../schemas/agent.ts";
|
|
10
10
|
import { chooseTrack, qaRequired, rosterWords, trackLine, trackSummary } from "../workflow/track.ts";
|
|
11
|
-
import { startFromAgreedPlan } from "../workflow/workflow.ts";
|
|
11
|
+
import { prefetchScouts, startFromAgreedPlan } from "../workflow/workflow.ts";
|
|
12
|
+
import { workflowDeps } from "./tools.ts";
|
|
12
13
|
import { lobbyFeed } from "../lobby/feed.ts";
|
|
13
14
|
import { createTaskDir, ensureProjectStructure, loadTask, nextTaskId, ownedTask, saveTask, taskDirFor } from "../state/persistence.ts";
|
|
14
15
|
import { detectProjectRoot, loadConfig } from "../state/project.ts";
|
|
@@ -21,7 +22,8 @@ import { setAutoMode } from "../state/auto.ts";
|
|
|
21
22
|
import { listPlannedTasks, loadPlannedTask, markPlannedTaskStarted, plannedTaskRequest, type PlannedTask } from "../state/backlog.ts";
|
|
22
23
|
import { triageFor } from "../classifier/instance.ts";
|
|
23
24
|
import { freshContextOn, markContext } from "./fresh-context.ts";
|
|
24
|
-
import { createWorkspace, gitLine } from "../execution/workspace.ts";
|
|
25
|
+
import { createWorkspace, gitLine, taskCwd } from "../execution/workspace.ts";
|
|
26
|
+
import { draftAssignments, draftAssignmentsNote } from "../workflow/draft-assignments.ts";
|
|
25
27
|
import type { GitIsolation } from "../schemas/configuration.ts";
|
|
26
28
|
|
|
27
29
|
function uniqueTaskId(root: string, configDir: string, request: string): string {
|
|
@@ -53,7 +55,7 @@ function fastSteps(track: TaskTrack): string[] {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
/** A task from an agreed plan: straight to building its steps; QA only when it took part in the panel. */
|
|
56
|
-
function plannedSteps(task: Task): string[] {
|
|
58
|
+
function plannedSteps(task: Task, cwd?: string): string[] {
|
|
57
59
|
const qa = qaRequired(task);
|
|
58
60
|
const steps = [
|
|
59
61
|
'Delegate the plan\'s steps now with orchestrate action=implement, opening each task with "Step N:" and briefing it in full from the plan. Give one domain its consecutive steps in one call, and run independent domains together with assignments.',
|
|
@@ -68,10 +70,11 @@ function plannedSteps(task: Task): string[] {
|
|
|
68
70
|
out.length > 0 ? `Only the members who sat on the panel work on it (${rosterWords(task.track?.roster ?? [])}). ${rosterWords(out)} sat out, so give ${out.length === 1 ? "it" : "them"} nothing; if a step truly needs one, ask the user with orchestrate action=track (the roster with it, and why).` : "",
|
|
69
71
|
...steps.map((step, index) => `${index + 1}. ${step}`),
|
|
70
72
|
"If the code contradicts the plan, amend it with action=plan (the plan with the change made) and tell the user in one line, rather than starting over.",
|
|
73
|
+
cwd && task.plan ? draftAssignmentsNote(draftAssignments(task.plan, cwd)) : "",
|
|
71
74
|
].filter(Boolean);
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
export function kickoff(task: Task, options: { fastTrack?: boolean } = {}): string {
|
|
77
|
+
export function kickoff(task: Task, options: { fastTrack?: boolean; cwd?: string; scouting?: readonly Domain[] } = {}): string {
|
|
75
78
|
const track = task.track;
|
|
76
79
|
const head = [
|
|
77
80
|
`A bot-lobby task is active: ${task.id}`,
|
|
@@ -83,13 +86,15 @@ export function kickoff(task: Task, options: { fastTrack?: boolean } = {}): stri
|
|
|
83
86
|
"",
|
|
84
87
|
];
|
|
85
88
|
if (track?.path === "fast") return [...head, ...fastSteps(track)].join("\n");
|
|
86
|
-
if (task.approvedPlan && task.plan && task.state === "planning") return [...head, ...plannedSteps(task)].join("\n");
|
|
89
|
+
if (task.approvedPlan && task.plan && task.state === "planning") return [...head, ...plannedSteps(task, options.cwd)].join("\n");
|
|
87
90
|
const fastAllowed = Boolean(track) && options.fastTrack !== false && track?.userChoice !== "full" && track?.source !== "plan";
|
|
88
91
|
return [
|
|
89
92
|
...head,
|
|
90
93
|
"Drive it with the orchestrate tool:",
|
|
91
94
|
"1. clarify if the request is genuinely ambiguous,",
|
|
92
|
-
|
|
95
|
+
options.scouting && options.scouting.length > 0
|
|
96
|
+
? `2. scout the domains the request touches: a scout over ${options.scouting.join(", ")} started with the task, and your first scout call covering them (without a pointed instruction is fine) returns its findings,`
|
|
97
|
+
: "2. scout the domains the request touches,",
|
|
93
98
|
"3. synthesize the findings and propose a short `- ` bullet list for approval.",
|
|
94
99
|
"Do not implement anything before the user approves the proposal.",
|
|
95
100
|
...(fastAllowed ? ["If it is in fact a small, clear, low-risk change, take the fast track instead: orchestrate action=track track=fast with a reason."] : []),
|
|
@@ -175,8 +180,14 @@ export async function startTask(pi: ExtensionAPI, ctx: ExtensionContext, configD
|
|
|
175
180
|
ctx.ui.notify(`bot-lobby ${task.id} started`, "info");
|
|
176
181
|
// The oracle takes the task on with a clean context: nothing said before the kickoff is sent to its model.
|
|
177
182
|
if (freshContextOn()) markContext(pi, { kind: "start", taskId: task.id, at: Date.now() });
|
|
183
|
+
// The full workflow scouts first: start it now, so the findings are on their way while the oracle reads the request.
|
|
184
|
+
// It is only a head start: anything that stops it leaves the oracle to scout as before.
|
|
185
|
+
let scouting: Domain[] = [];
|
|
186
|
+
try { scouting = prefetchScouts(task, config, () => workflowDeps(ctx, configDir, undefined, undefined)); }
|
|
187
|
+
catch { scouting = []; }
|
|
188
|
+
if (scouting.length > 0) lobbyFeed.log("LOBBY", `${task.id}: scouting ${scouting.join(", ")} while the oracle reads the request`, "info");
|
|
178
189
|
// A kickoff while pi is still busy (another turn) queues behind it instead of throwing.
|
|
179
|
-
pi.sendUserMessage(kickoff(task, { fastTrack: config.workflow.fastTrack }), ctx.isIdle() ? undefined : { deliverAs: "followUp" });
|
|
190
|
+
pi.sendUserMessage(kickoff(task, { fastTrack: config.workflow.fastTrack, cwd: taskCwd(task, ctx.cwd), scouting }), ctx.isIdle() ? undefined : { deliverAs: "followUp" });
|
|
180
191
|
return task;
|
|
181
192
|
}
|
|
182
193
|
|
package/src/pi/tools.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { askChoice, askText, askUser, canAsk } from "../ask/web.ts";
|
|
|
13
13
|
import type { AskQuestion } from "../ask/types.ts";
|
|
14
14
|
import { unescapeBreaks } from "../lobby/blocks.ts";
|
|
15
15
|
import { isQuiet } from "./quiet.ts";
|
|
16
|
-
import { checkThinking, createProfileResolver, modelRef,
|
|
16
|
+
import { checkThinking, createProfileResolver, modelRef, type ModelLookup } from "./model-support.ts";
|
|
17
17
|
import { agentName, describeRun } from "./run-summary.ts";
|
|
18
18
|
import { lintFeed } from "../workflow/lint.ts";
|
|
19
19
|
import { qaRiskLine } from "../classifier/qa-risk.ts";
|
|
@@ -26,6 +26,31 @@ import {
|
|
|
26
26
|
type WorkflowResult,
|
|
27
27
|
} from "../workflow/workflow.ts";
|
|
28
28
|
|
|
29
|
+
export const WorkerAssignmentSchema = Type.Object({
|
|
30
|
+
id: Type.String({ minLength: 1 }),
|
|
31
|
+
revision: Type.Integer({ minimum: 1 }),
|
|
32
|
+
objective: Type.String({ minLength: 1 }),
|
|
33
|
+
actions: Type.Array(Type.Object({ step: Type.Integer({ minimum: 1 }), instruction: Type.String({ minLength: 1 }) }, { additionalProperties: false }), { minItems: 1 }),
|
|
34
|
+
files: Type.Array(Type.Object({
|
|
35
|
+
path: Type.String({ minLength: 1 }),
|
|
36
|
+
access: StringEnum(["reference", "edit", "create"] as const),
|
|
37
|
+
purpose: Type.String({ minLength: 1 }),
|
|
38
|
+
}, { additionalProperties: false }), { minItems: 1 }),
|
|
39
|
+
contracts: Type.Array(Type.String({ minLength: 1 })),
|
|
40
|
+
constraints: Type.Array(Type.String({ minLength: 1 })),
|
|
41
|
+
exclusions: Type.Array(Type.String({ minLength: 1 })),
|
|
42
|
+
tools: Type.Array(Type.Object({ name: Type.String({ minLength: 1 }), purpose: Type.String({ minLength: 1 }) }, { additionalProperties: false })),
|
|
43
|
+
verification: Type.Array(Type.String({ minLength: 1 }), { minItems: 1 }),
|
|
44
|
+
evidence: Type.Array(Type.String({ minLength: 1 })),
|
|
45
|
+
completedWork: Type.Array(Type.String({ minLength: 1 })),
|
|
46
|
+
needs: Type.Array(Type.Object({
|
|
47
|
+
kind: StringEnum(["files", "tools", "discovery", "decision"] as const),
|
|
48
|
+
reason: Type.String({ minLength: 1 }),
|
|
49
|
+
requested: Type.Array(Type.String({ minLength: 1 }), { minItems: 1 }),
|
|
50
|
+
}, { additionalProperties: false })),
|
|
51
|
+
discoveryLimit: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
52
|
+
}, { additionalProperties: false });
|
|
53
|
+
|
|
29
54
|
const OrchestrateSchema = Type.Object({
|
|
30
55
|
action: StringEnum(ORCHESTRATE_ACTIONS, { description: "Workflow step to run" }),
|
|
31
56
|
taskId: Type.Optional(Type.String({ description: "Task id; defaults to the active task. For knowledge/compact, omit to update project facts without changing a task." })),
|
|
@@ -37,30 +62,39 @@ const OrchestrateSchema = Type.Object({
|
|
|
37
62
|
concerns: Type.Optional(Type.Array(Type.String(), { description: "propose: concerns raised while challenging the request" })),
|
|
38
63
|
plan: Type.Optional(Type.String({ description: "plan: the detailed internal plan (while implementing or reviewing, the full revised plan that replaces it). Every step names its files, its concrete actions and its done criteria, and the contracts between domains are written out; no decision is left to the workers" })),
|
|
39
64
|
domain: Type.Optional(Type.String({ description: "implement/research: designer, backend, or qa" })),
|
|
40
|
-
task: Type.Optional(Type.String({ description: "implement:
|
|
65
|
+
task: Type.Optional(Type.String({ description: "implement: legacy worker instruction, or optional Step N label alongside the authoritative workerAssignment" })),
|
|
66
|
+
workerAssignment: Type.Optional(WorkerAssignmentSchema),
|
|
41
67
|
assignments: Type.Optional(
|
|
42
68
|
Type.Array(
|
|
43
69
|
Type.Object({
|
|
44
70
|
domain: Type.String({ description: "designer, backend, or qa" }),
|
|
45
|
-
task: Type.String({ description: "
|
|
71
|
+
task: Type.Optional(Type.String({ description: "Optional step label; the structured workerAssignment is the authoritative brief" })),
|
|
72
|
+
workerAssignment: Type.Optional(WorkerAssignmentSchema),
|
|
46
73
|
}),
|
|
47
74
|
{ description: "implement: run several domains in parallel (distinct domains); workers share files through the file desk" },
|
|
48
75
|
),
|
|
49
76
|
),
|
|
77
|
+
discoveryAllowance: Type.Optional(Type.Object({
|
|
78
|
+
assignmentId: Type.String({ minLength: 1 }),
|
|
79
|
+
revision: Type.Integer({ minimum: 1 }),
|
|
80
|
+
decisionId: Type.String({ minLength: 1 }),
|
|
81
|
+
reason: Type.String({ minLength: 1 }),
|
|
82
|
+
limit: Type.Integer({ minimum: 0 }),
|
|
83
|
+
}, { additionalProperties: false, description: "decide: master-only audited discovery allowance for the current persisted assignment revision" })),
|
|
50
84
|
approvalId: Type.Optional(Type.String({ description: "resolve_approval: the approval id from a worker result" })),
|
|
51
85
|
decision: Type.Optional(
|
|
52
86
|
StringEnum(["approved", "rejected"] as const, { description: "resolve_approval: approve or reject the request" }),
|
|
53
87
|
),
|
|
54
|
-
note: Type.Optional(Type.String({ description: "resolve_approval: rationale, or what to do instead when rejected" })),
|
|
88
|
+
note: Type.Optional(Type.String({ description: "resolve_approval: rationale, or what to do instead when rejected; design: user when the user stated the choice (an agent's choice otherwise)" })),
|
|
55
89
|
reason: Type.Optional(Type.String({ description: "block: why the task cannot continue; track: why the task takes that path or needs those members; complete: why gaps the goal check named are deliberate (the user agreed)" })),
|
|
56
90
|
track: Type.Optional(
|
|
57
91
|
StringEnum(["fast", "full"] as const, { description: "track: fast (straight to the roster's agents, no scouts, proposal or plan; QA only for tests) or full (the whole workflow)" }),
|
|
58
92
|
),
|
|
59
93
|
roster: Type.Optional(Type.Array(Type.String(), { description: "track: who takes part — any of designer, backend, qa, researcher" })),
|
|
60
|
-
text: Type.Optional(Type.String({ description: "decide/complete/knowledge/script: the decision, completion summary, knowledge text, or the
|
|
94
|
+
text: Type.Optional(Type.String({ description: "decide/complete/knowledge/script/design: the decision, completion summary, knowledge text, the script itself, or the design value" })),
|
|
61
95
|
message: Type.Optional(Type.String({ description: "complete: the commit message for the agents' changes, which the engine commits (only their files): a first line of 72 characters or fewer saying what changed, at most three short lines below it" })),
|
|
62
96
|
file: Type.Optional(Type.String({ description: "compact: the knowledge file to rewrite, e.g. knowledge.md; script: a script a worker drafted, to save instead of text" })),
|
|
63
|
-
name: Type.Optional(Type.String({ description: "script: the file name, what it does in snake_case with its language's extension (seed_public_holidays.py, run_changed_tests.sh)" })),
|
|
97
|
+
name: Type.Optional(Type.String({ description: "script: the file name, what it does in snake_case with its language's extension (seed_public_holidays.py, run_changed_tests.sh); design: the field (spacing, radius, borders, shadows, hover, motion)" })),
|
|
64
98
|
purpose: Type.Optional(Type.String({ description: "script: one line on what the script does" })),
|
|
65
99
|
usage: Type.Optional(Type.String({ description: "script: the command that runs it, with its arguments" })),
|
|
66
100
|
kind: Type.Optional(
|
|
@@ -88,7 +122,7 @@ const DESCRIPTION = [
|
|
|
88
122
|
"plan, or amend it later with the full revised plan), implement (delegate a step to a domain worker, or several domains in parallel with assignments), qa (final quality gate and the only",
|
|
89
123
|
"review), knowledge (record approved project knowledge or a decision; works without a task),"
|
|
90
124
|
+ "bookmark (manage the task's assignment bookmark list: op=add|remove|pin|unpin|exclude with refs — reference ids from search_knowledge — and optionally domain and note),",
|
|
91
|
-
"compact (replace a knowledge file with a rewritten version, archiving the old one; works without a task; disperse domain-relevant facts to action=knowledge (domain=designer|backend|qa) first), script (save a script to the shared scripts library, or replace one, for a job that comes back; works without a task),",
|
|
125
|
+
"compact (replace a knowledge file with a rewritten version, archiving the old one; works without a task; disperse domain-relevant facts to action=knowledge (domain=designer|backend|qa) first), script (save a script to the shared scripts library, or replace one, for a job that comes back; works without a task), design (record a visual choice in the design record: name=field, text=value; works without a task),",
|
|
92
126
|
"resolve_approval (approve or reject a request), complete (declare the task done after the gates",
|
|
93
127
|
"pass, then ask the user to confirm merging and pushing main and removing its worktree), block/resume (escalate or continue),",
|
|
94
128
|
"track (the task's path and who takes part: show it, or correct it with",
|
|
@@ -130,7 +164,6 @@ export function workflowDeps(
|
|
|
130
164
|
sessionModel: ctx.model ? modelRef(ctx.model) : undefined,
|
|
131
165
|
warn,
|
|
132
166
|
}),
|
|
133
|
-
expert: resolveExpertProfile(config, { lookup: modelLookup(ctx), sessionModel: ctx.model ? modelRef(ctx.model) : undefined, warn }),
|
|
134
167
|
sessionId: ctx.sessionManager.getSessionId(),
|
|
135
168
|
signal,
|
|
136
169
|
onUpdate,
|
package/src/roles/scout.ts
CHANGED
|
@@ -15,7 +15,9 @@ export const scoutSpec: RoleSpec = {
|
|
|
15
15
|
"Use `- ` bullets. `## Relevant Files` entries are `- \\`path:start-end\\` — reason`, with the lines of the code that matters",
|
|
16
16
|
"(`path:42` for one line, the bare `path` only when the whole file does), so the worker opens the exact place.",
|
|
17
17
|
"`## Confidence` is exactly one of `High`, `Medium`, `Low`.",
|
|
18
|
-
"Keep the whole response under 400 words. Report uncertainty; do not implement.",
|
|
18
|
+
"Keep the whole response under 400 words per selected domain. Report uncertainty; do not implement.",
|
|
19
|
+
"For an explicitly shared multi-domain investigation, repeat these sections under `# Domain: <domain>` for each selected domain.",
|
|
20
|
+
"Preserve domain attribution and include contracts, callers and relevant tests in Findings and Relevant Files.",
|
|
19
21
|
"An optional `## Pushback` (`**Request:**`, `**Reason:**`, optional `**Alternative:**`) flags a change you",
|
|
20
22
|
"believe is wrong, with your reason; keep it separate from your findings.",
|
|
21
23
|
].join(" "),
|
package/src/roles/worker.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AssignmentExpansionRequest, WorkerAssignment } from "../execution/assignment.ts";
|
|
1
2
|
import type { Domain, RoleSpec } from "../schemas/agent.ts";
|
|
2
3
|
import type { Blocker } from "../schemas/task.ts";
|
|
3
4
|
import type { FileChange, KnowledgeProposal, ScriptProposal, WorkerResult } from "../schemas/findings.ts";
|
|
@@ -86,9 +87,81 @@ export function realAsks(items: readonly string[]): string[] {
|
|
|
86
87
|
return items.filter((item) => !NOTHING.test(item.trim()));
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
/** Find the end of one JSON container without treating braces in strings as delimiters. */
|
|
91
|
+
function jsonEnd(text: string, start: number): number {
|
|
92
|
+
let depth = 0;
|
|
93
|
+
let quoted = false;
|
|
94
|
+
let escaped = false;
|
|
95
|
+
for (let i = start; i < text.length; i++) {
|
|
96
|
+
const char = text[i];
|
|
97
|
+
if (quoted) {
|
|
98
|
+
if (escaped) escaped = false;
|
|
99
|
+
else if (char === "\\") escaped = true;
|
|
100
|
+
else if (char === '"') quoted = false;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (char === '"') quoted = true;
|
|
104
|
+
else if (char === "{" || char === "[") depth++;
|
|
105
|
+
else if ((char === "}" || char === "]") && --depth === 0) return i + 1;
|
|
106
|
+
}
|
|
107
|
+
return text.length;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Notes can contain prose plus standalone JSON objects, optionally fenced. */
|
|
111
|
+
function expansionJson(notes: string): string[] {
|
|
112
|
+
const candidates: string[] = [];
|
|
113
|
+
const plain = notes.replace(/```(?:json)?[ \t]*\r?\n([\s\S]*?)(?:```|$)/gi, (_block, body: string) => {
|
|
114
|
+
candidates.push(body.trim());
|
|
115
|
+
return "\n";
|
|
116
|
+
});
|
|
117
|
+
const starts = /(?:^|\n)[ \t]*(?:[-*][ \t]+)?(?=[{[])/g;
|
|
118
|
+
let match: RegExpExecArray | null;
|
|
119
|
+
while ((match = starts.exec(plain))) {
|
|
120
|
+
const start = match.index + match[0].length;
|
|
121
|
+
const end = jsonEnd(plain, start);
|
|
122
|
+
candidates.push(plain.slice(start, end));
|
|
123
|
+
starts.lastIndex = end;
|
|
124
|
+
}
|
|
125
|
+
return candidates;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function expansionIssue(value: unknown): string | undefined {
|
|
129
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return "must be an object";
|
|
130
|
+
const need = value as Record<string, unknown>;
|
|
131
|
+
const unknown = Object.keys(need).find((key) => !["kind", "reason", "requested"].includes(key));
|
|
132
|
+
if (unknown) return `unknown key ${unknown}; only kind, reason and requested are allowed`;
|
|
133
|
+
if (typeof need.kind !== "string" || !["files", "tools", "discovery", "decision"].includes(need.kind)) {
|
|
134
|
+
return "kind must be files, tools, discovery or decision";
|
|
135
|
+
}
|
|
136
|
+
if (typeof need.reason !== "string" || !need.reason.trim()) return "reason must be nonempty text";
|
|
137
|
+
if (!Array.isArray(need.requested) || need.requested.length === 0 ||
|
|
138
|
+
need.requested.some((item: unknown) => typeof item !== "string" || !item.trim())) {
|
|
139
|
+
return "requested must be a nonempty array of nonempty strings";
|
|
140
|
+
}
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function parseExpansions(notes: string): { needs: AssignmentExpansionRequest[]; issues: string[] } {
|
|
145
|
+
const needs: AssignmentExpansionRequest[] = [];
|
|
146
|
+
const issues: string[] = [];
|
|
147
|
+
for (const [index, candidate] of expansionJson(notes).entries()) {
|
|
148
|
+
try {
|
|
149
|
+
const value: unknown = JSON.parse(candidate);
|
|
150
|
+
const issue = expansionIssue(value);
|
|
151
|
+
if (issue) issues.push(`Notes expansion request ${index + 1}: ${issue}`);
|
|
152
|
+
else needs.push(value as AssignmentExpansionRequest);
|
|
153
|
+
} catch {
|
|
154
|
+
issues.push(`Notes expansion request ${index + 1}: invalid JSON; provide a standalone request object`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { needs, issues };
|
|
158
|
+
}
|
|
159
|
+
|
|
89
160
|
/** Parse a worker's markdown into a structured result (never throws). */
|
|
90
161
|
export function parseWorkerResult(domain: Domain, raw: string, now = new Date().toISOString()): WorkerResult {
|
|
91
162
|
const sections = parseSections(raw);
|
|
163
|
+
const notes = findSection(sections, "notes") ?? "";
|
|
164
|
+
const { needs } = parseExpansions(notes);
|
|
92
165
|
return {
|
|
93
166
|
domain,
|
|
94
167
|
role: "worker",
|
|
@@ -98,7 +171,8 @@ export function parseWorkerResult(domain: Domain, raw: string, now = new Date().
|
|
|
98
171
|
return { path: file.path, change: file.reason };
|
|
99
172
|
}),
|
|
100
173
|
verification: findSection(sections, "verification") ?? "",
|
|
101
|
-
notes
|
|
174
|
+
notes,
|
|
175
|
+
...(needs.length > 0 ? { needs } : {}),
|
|
102
176
|
blockers: parseBlockers(sections, domain, now),
|
|
103
177
|
knowledgeProposals: parseKnowledgeProposals(domain, findSection(sections, "knowledge proposals")),
|
|
104
178
|
scriptProposals: parseScriptProposals(domain, findSection(sections, "script proposals")),
|
|
@@ -109,13 +183,41 @@ export function parseWorkerResult(domain: Domain, raw: string, now = new Date().
|
|
|
109
183
|
};
|
|
110
184
|
}
|
|
111
185
|
|
|
186
|
+
/** Assignment-specific content belongs in the user instruction, not the shared system prefix. */
|
|
187
|
+
export function assignmentPrompt(assignment: WorkerAssignment): string {
|
|
188
|
+
return [
|
|
189
|
+
"## Validated master assignment",
|
|
190
|
+
JSON.stringify(assignment, null, 2),
|
|
191
|
+
"Actions are numbered and authoritative. Begin with assigned files; paths and purposes are provided, not file bodies.",
|
|
192
|
+
"Read current contents before editing; re-read after file handover. Reference paths are read-only. Only edit/create paths authorize changes.",
|
|
193
|
+
`Discovery allowance: ${assignment.discoveryLimit ?? 2} total targeted lookups. Each nested or batched discovery call counts separately; retries and revisions do not reset consumed allowance. Assigned-file reads and assigned verification are exempt. Shell discovery follows the same limit.`,
|
|
194
|
+
"Discovery never authorizes editing a newly found file. Tools listed here are a replacement selection intersected with existing grants; an empty list grants no tools. Codemode does not grant unselected nested or MCP tools.",
|
|
195
|
+
"If files, tools, discovery allowance or decisions are missing, report each expansion request under Notes as a standalone JSON object (optionally in a json fence), with exactly these keys: {\"kind\":\"files|tools|discovery|decision\",\"reason\":\"why needed\",\"requested\":[\"exact path, tool, allowance or decision\"]}. Continue unaffected work; do not expand permissions yourself.",
|
|
196
|
+
"Report completed work and evidence, outstanding needs, and one Brief Check per verification criterion. Reference-only work may succeed without edits; do not make artificial changes. Every changed file still requires verification.",
|
|
197
|
+
].join("\n\n");
|
|
198
|
+
}
|
|
199
|
+
|
|
112
200
|
/** Report contract deviations so the Master does not accept unverified work. */
|
|
113
|
-
export function validateWorkerResult(result: WorkerResult): string[] {
|
|
114
|
-
const issues
|
|
201
|
+
export function validateWorkerResult(result: WorkerResult, assignment?: WorkerAssignment): string[] {
|
|
202
|
+
const issues = parseExpansions(result.notes).issues;
|
|
203
|
+
if (result.needs !== undefined) {
|
|
204
|
+
if (!Array.isArray(result.needs)) issues.push("needs must be an array of expansion requests");
|
|
205
|
+
else result.needs.forEach((need, index) => {
|
|
206
|
+
const issue = expansionIssue(need);
|
|
207
|
+
if (issue) issues.push(`needs[${index}]: ${issue}`);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
115
210
|
if (!result.completed) issues.push("missing Completed section");
|
|
116
|
-
if (result.filesChanged.length > 0 && !result.verification) issues.push("changed files without verification");
|
|
211
|
+
if (result.filesChanged.length > 0 && !result.verification?.trim()) issues.push("changed files without verification");
|
|
117
212
|
const claimedNothing = /no changes|nothing to change|no modifications/i.test(result.raw);
|
|
118
|
-
|
|
213
|
+
const referenceOnly = assignment !== undefined && assignment.files.every((file) => file.access === "reference");
|
|
214
|
+
if (assignment) {
|
|
215
|
+
const writable = new Set(assignment.files.filter((file) => file.access !== "reference").map((file) => file.path));
|
|
216
|
+
for (const file of result.filesChanged) {
|
|
217
|
+
if (!writable.has(file.path)) issues.push(`changed file outside assignment edit/create paths: ${file.path}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (result.filesChanged.length === 0 && result.blockers.length === 0 && !claimedNothing && !referenceOnly) {
|
|
119
221
|
issues.push("no files changed and no blocker reported");
|
|
120
222
|
}
|
|
121
223
|
return issues;
|