@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
package/src/lobby/planner.ts
CHANGED
|
@@ -25,11 +25,11 @@ import { runPiAgent, spawnPiProcess, type PiStreamEvent, type ProcessRunner } fr
|
|
|
25
25
|
import { describeToolCall } from "../pi/activity.ts";
|
|
26
26
|
import { appendMetrics, type MetricRecord } from "../state/metrics.ts";
|
|
27
27
|
import { savePlannedTask, type IssueRef, type PlannedTask } from "../state/backlog.ts";
|
|
28
|
-
import {
|
|
29
|
-
import { KEEP_WHOLE, MAX_SPLIT_REVISIONS, partBrief, partInfo, parseSplit, splitFailedQuestion, splitProblems, splitPrompt, splitQuestion, splitRequest, type SplitProposal } from "./split.ts";
|
|
30
|
-
import type { AskQuestion, AskResult } from "../ask/types.ts";
|
|
28
|
+
import type { AskResult } from "../ask/types.ts";
|
|
31
29
|
import { PANEL_MEMBERS, type PanelMember } from "../schemas/configuration.ts";
|
|
32
30
|
import { truncate } from "../text.ts";
|
|
31
|
+
import { dataRoot } from "../state/project.ts";
|
|
32
|
+
import { designRecordBlock, designStanding, styleFields, styleQuestions, type DesignField, type DesignStanding } from "../knowledge/design-record.ts";
|
|
33
33
|
import type { LobbyFeed } from "./feed.ts";
|
|
34
34
|
import type { LobbyRunProfile } from "./profile.ts";
|
|
35
35
|
import { MAX_QUESTIONS } from "./ask.ts";
|
|
@@ -77,6 +77,8 @@ export interface AskedQuestion {
|
|
|
77
77
|
export interface PanelQuestion extends AskedQuestion {
|
|
78
78
|
/** DEV, DESIGN, QA, RESEARCH or ORACLE. */
|
|
79
79
|
from: string;
|
|
80
|
+
/** A style question: the design record field its answer is recorded under. */
|
|
81
|
+
record?: DesignField;
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
/** One of the panel's questions as the user's reply settled it: answered, or left open (`answer` absent). */
|
|
@@ -105,6 +107,8 @@ export interface PlannerReply {
|
|
|
105
107
|
title?: string;
|
|
106
108
|
questions: AskedQuestion[];
|
|
107
109
|
plan?: string;
|
|
110
|
+
/** Seats the oracle calls back for the next round; after the first round only these (and pinned ones) sit. */
|
|
111
|
+
consult?: PanelMember[];
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
/** A seat's reply: whether its domain is settled, its questions and what the plan must respect. */
|
|
@@ -112,6 +116,8 @@ export interface MemberReply {
|
|
|
112
116
|
status: "open" | "ready";
|
|
113
117
|
questions: AskedQuestion[];
|
|
114
118
|
notes: string[];
|
|
119
|
+
/** DESIGN: the open design record fields this work touches, for the engine to ask (`## Style`). */
|
|
120
|
+
style?: DesignField[];
|
|
115
121
|
}
|
|
116
122
|
|
|
117
123
|
export interface MemberState {
|
|
@@ -366,7 +372,15 @@ export function parsePlannerReply(text: string): PlannerReply {
|
|
|
366
372
|
const plan = parts.get("plan") ?? parts.get("draft plan");
|
|
367
373
|
let questions = questionItems(parts.get("questions"));
|
|
368
374
|
if (parts.size === 0 && text.trim()) questions = [{ text: text.trim(), options: [] }];
|
|
369
|
-
|
|
375
|
+
const consult = consultSeats(parts.get("consult"));
|
|
376
|
+
return { status, questions, ...(title ? { title } : {}), ...(plan ? { plan } : {}), ...(consult.length > 0 ? { consult } : {}) };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** The seats a `## Consult` section names (DEV, DESIGN, QA, RESEARCH or their domain names). */
|
|
380
|
+
function consultSeats(body: string | undefined): PanelMember[] {
|
|
381
|
+
if (!body) return [];
|
|
382
|
+
const named = new Set((body.match(/[A-Za-z]+/g) ?? []).map((word) => word.toLowerCase()));
|
|
383
|
+
return PANEL_MEMBERS.filter((member) => named.has(member) || named.has(MEMBER_LABELS[member].toLowerCase()));
|
|
370
384
|
}
|
|
371
385
|
|
|
372
386
|
/** Read a seat's reply the same forgiving way: a READY seat asks nothing. */
|
|
@@ -375,7 +389,8 @@ export function parseMemberReply(text: string): MemberReply {
|
|
|
375
389
|
const ready = /\bready\b/i.test(parts.get("status") ?? "");
|
|
376
390
|
let questions = ready ? [] : questionItems(parts.get("questions"));
|
|
377
391
|
if (parts.size === 0 && text.trim()) questions = [{ text: text.trim(), options: [] }];
|
|
378
|
-
|
|
392
|
+
const style = styleFields(parts.get("style"));
|
|
393
|
+
return { status: ready ? "ready" : "open", questions, notes: listItems(parts.get("notes")), ...(style.length > 0 ? { style } : {}) };
|
|
379
394
|
}
|
|
380
395
|
|
|
381
396
|
function optionLines(options: readonly PanelOption[], marks = false): string[] {
|
|
@@ -470,7 +485,7 @@ export function settledBlock(settled: readonly SettledQuestion[]): string {
|
|
|
470
485
|
|
|
471
486
|
/** The seats' output for the oracle: each seat's status, questions and notes, or its failure. */
|
|
472
487
|
export function panelSection(outcomes: readonly MemberOutcome[]): string {
|
|
473
|
-
if (outcomes.length === 0) return "## Panel this round\n\nNo domain seats this round; you are planning alone.";
|
|
488
|
+
if (outcomes.length === 0) return "## Panel this round\n\nNo domain seats this round; you are planning alone. Name a seat under ## Consult to hear from it next round.";
|
|
474
489
|
const blocks = outcomes.map((outcome) => {
|
|
475
490
|
const label = MEMBER_LABELS[outcome.member];
|
|
476
491
|
if (!outcome.reply) return `### ${label} — no answer this round (${outcome.error ?? "failed"})`;
|
|
@@ -864,119 +879,12 @@ export class PlanningSession {
|
|
|
864
879
|
return this.saved;
|
|
865
880
|
}
|
|
866
881
|
|
|
867
|
-
/** Save
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
if (
|
|
871
|
-
const
|
|
872
|
-
|
|
873
|
-
// Part 1 is saved last of all timestamps' newest, so the newest-first pending list reads in part order.
|
|
874
|
-
const parts = proposal.tasks.map((task, index) => savePlannedTask(this.deps.root, this.deps.configDir, {
|
|
875
|
-
title: task.title,
|
|
876
|
-
brief: partBrief({ plan, steps, proposal, index }),
|
|
877
|
-
...(this.seed ? { issue: this.seed.issue } : {}),
|
|
878
|
-
split: partInfo(proposal, index, group),
|
|
879
|
-
panel: this.panel,
|
|
880
|
-
}, new Date(now.getTime() + (proposal.tasks.length - index))));
|
|
881
|
-
this.savedParts = parts;
|
|
882
|
-
this.saved = parts[0];
|
|
883
|
-
this.deps.feed?.log(ORACLE_LABEL, `split the plan into ${parts.length} tasks: ${parts.map((part) => part.id).join(", ")}`, "success");
|
|
884
|
-
this.deps.onChange?.();
|
|
885
|
-
return parts;
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
/**
|
|
889
|
-
* The oracle's proposal for splitting the plan: run, read, and checked
|
|
890
|
-
* against the rules (once more with the problems when it breaks one).
|
|
891
|
-
* `feedback` is the user's change request on an earlier proposal. A string
|
|
892
|
-
* is the reason there is no proposal.
|
|
893
|
-
*/
|
|
894
|
-
private async proposeSplit(plan: string, steps: readonly string[], feedback: { previous: SplitProposal; words: string } | undefined, signal: AbortSignal): Promise<SplitProposal | string> {
|
|
895
|
-
const profile = this.deps.profile();
|
|
896
|
-
const title = this.title ?? "the plan";
|
|
897
|
-
let rejected: string[] = [];
|
|
898
|
-
let reason = "";
|
|
899
|
-
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
900
|
-
this.step = attempt === 0 ? "deciding how to split the plan" : "fixing the split";
|
|
901
|
-
this.deps.onChange?.();
|
|
902
|
-
const lead = await this.run(ORACLE_LABEL, "planner", profile, {
|
|
903
|
-
task: splitRequest({ title, plan, steps, ...(feedback ? { revision: feedback } : {}), ...(rejected.length > 0 ? { rejected } : {}) }),
|
|
904
|
-
systemPrompt: splitPrompt(profile.instructions),
|
|
905
|
-
tools: this.tools(PLANNER_TOOLS),
|
|
906
|
-
}, signal, (step) => (this.step = step));
|
|
907
|
-
if (signal.aborted) throw new Error("stopped");
|
|
908
|
-
if (lead.status !== "success") return lead.error ?? lead.status;
|
|
909
|
-
try {
|
|
910
|
-
const proposal = parseSplit(lead.output);
|
|
911
|
-
rejected = splitProblems(proposal, steps.length);
|
|
912
|
-
if (rejected.length === 0) return proposal;
|
|
913
|
-
reason = rejected[0]!;
|
|
914
|
-
} catch (error) {
|
|
915
|
-
rejected = [(error as Error).message];
|
|
916
|
-
reason = rejected[0]!;
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
return reason;
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
/**
|
|
923
|
-
* Save the plan as a pending task; when it has more steps than
|
|
924
|
-
* `splitAbove`, first let the oracle propose splitting it into up to five
|
|
925
|
-
* tasks and let the user decide: take it, keep the plan whole, or say what to
|
|
926
|
-
* change (the oracle revises, a few times). Nothing the user leaves open is
|
|
927
|
-
* decided for them: a questionnaire they put away saves nothing. Returns the
|
|
928
|
-
* notice for the lobby.
|
|
929
|
-
*/
|
|
930
|
-
async saveWithSplit(ask: (questions: AskQuestion[], signal: AbortSignal) => Promise<AskResult>, options: { splitAbove: number }): Promise<string> {
|
|
931
|
-
const plan = this.reply?.plan;
|
|
932
|
-
if (!plan) throw new Error("there is no draft plan to save yet");
|
|
933
|
-
const steps = planSteps(plan);
|
|
934
|
-
const unagreed = this.reply?.status === "ready" ? "" : " (the panel had not agreed yet)";
|
|
935
|
-
const whole = () => `saved ${this.save().id} to the pending tasks — start it from the Tasks tab${unagreed}`;
|
|
936
|
-
if (options.splitAbove <= 0 || steps.length <= options.splitAbove) return whole();
|
|
937
|
-
if (this.busy) return "the panel is still working — save again once it is done, and the oracle will look at splitting this plan";
|
|
938
|
-
const controller = new AbortController();
|
|
939
|
-
this.controller = controller;
|
|
940
|
-
this.status = "thinking";
|
|
941
|
-
this.error = undefined;
|
|
942
|
-
this.deps.onChange?.();
|
|
943
|
-
try {
|
|
944
|
-
let proposal = await this.proposeSplit(plan, steps, undefined, controller.signal);
|
|
945
|
-
if (typeof proposal === "string") {
|
|
946
|
-
const reason = proposal;
|
|
947
|
-
this.deps.feed?.log(ORACLE_LABEL, `could not split the plan — ${reason.split("\n")[0]}`, "warning");
|
|
948
|
-
this.step = "waiting for you";
|
|
949
|
-
const answer = (await ask([splitFailedQuestion(reason)], controller.signal)).answers[0];
|
|
950
|
-
if (controller.signal.aborted) throw new Error("stopped");
|
|
951
|
-
return answer?.answer === "Save it as one task" ? whole() : "the plan was not saved — ctrl+s tries again";
|
|
952
|
-
}
|
|
953
|
-
for (let revisions = 0; ; revisions += 1) {
|
|
954
|
-
this.step = "waiting for you";
|
|
955
|
-
this.deps.onChange?.();
|
|
956
|
-
const result = await ask([splitQuestion({ stepCount: steps.length, proposal, steps, revisions })], controller.signal);
|
|
957
|
-
// A stopped questionnaire comes back empty too; it was stopped, not left open.
|
|
958
|
-
if (controller.signal.aborted) throw new Error("stopped");
|
|
959
|
-
const answer = result.answers[0];
|
|
960
|
-
if (!answer) return "the split question was left open, so nothing was saved — ctrl+s asks again";
|
|
961
|
-
if (answer.kind === "option") {
|
|
962
|
-
if (answer.answer === KEEP_WHOLE) return whole();
|
|
963
|
-
const parts = this.saveParts(proposal);
|
|
964
|
-
return `split into ${parts.length} tasks — ${parts.map((part) => part.id).join(", ")}; start them from the Tasks tab, in order${unagreed}`;
|
|
965
|
-
}
|
|
966
|
-
if (revisions >= MAX_SPLIT_REVISIONS) return `that was the last revision, and nothing was saved — ctrl+s asks again and the oracle starts over`;
|
|
967
|
-
const revised = await this.proposeSplit(plan, steps, { previous: proposal, words: answer.answer ?? "" }, controller.signal);
|
|
968
|
-
if (typeof revised === "string") return `the oracle could not apply that (${revised.split("\n")[0]}) — nothing was saved; ctrl+s asks again`;
|
|
969
|
-
proposal = revised;
|
|
970
|
-
}
|
|
971
|
-
} catch (error) {
|
|
972
|
-
if (controller.signal.aborted) return "stopped — nothing was saved";
|
|
973
|
-
return `could not save the plan: ${(error as Error).message}`;
|
|
974
|
-
} finally {
|
|
975
|
-
this.status = "idle";
|
|
976
|
-
this.step = undefined;
|
|
977
|
-
this.controller = undefined;
|
|
978
|
-
this.deps.onChange?.();
|
|
979
|
-
}
|
|
882
|
+
/** Save the plan as a pending task; returns the notice for the lobby. */
|
|
883
|
+
savePlan(): string {
|
|
884
|
+
if (!this.reply?.plan) throw new Error("there is no draft plan to save yet");
|
|
885
|
+
if (this.busy) return "the panel is still working — save again once it is done";
|
|
886
|
+
const unagreed = this.reply.status === "ready" ? "" : " (the panel had not agreed yet)";
|
|
887
|
+
return `saved ${this.save().id} to the pending tasks — start it from the Tasks tab${unagreed}`;
|
|
980
888
|
}
|
|
981
889
|
|
|
982
890
|
private stepKey(who: string): string {
|
|
@@ -1066,8 +974,9 @@ export class PlanningSession {
|
|
|
1066
974
|
const member = state.member;
|
|
1067
975
|
const label = MEMBER_LABELS[member];
|
|
1068
976
|
const profile = this.deps.memberProfile?.(member) ?? this.deps.profile();
|
|
977
|
+
const record = member === "designer" ? this.design() : undefined;
|
|
1069
978
|
const request = {
|
|
1070
|
-
task: `${transcript}\n\nYou are ${label} on the planning panel${roundNote(this.turns, this.limit)}: ask your seat's open questions, or declare READY.`,
|
|
979
|
+
task: `${transcript}${record ? `\n\n${designRecordBlock(record, "planning")}` : ""}\n\nYou are ${label} on the planning panel${roundNote(this.turns, this.limit)}: ask your seat's open questions, or declare READY.`,
|
|
1071
980
|
systemPrompt: memberPrompt(member, profile.instructions),
|
|
1072
981
|
tools: this.tools(member === "researcher" ? RESEARCH_PANEL_TOOLS : PLANNER_TOOLS),
|
|
1073
982
|
};
|
|
@@ -1103,8 +1012,10 @@ export class PlanningSession {
|
|
|
1103
1012
|
const limit = this.limit;
|
|
1104
1013
|
const mode = roundMode(this.turns, limit);
|
|
1105
1014
|
this.mode = mode;
|
|
1015
|
+
// The seats sit the first round; after it only the ones the oracle calls back (or the user pins) do.
|
|
1106
1016
|
// At and past the limit the oracle works alone: the seats have had their rounds.
|
|
1107
|
-
const
|
|
1017
|
+
const called = new Set(this.reply?.consult ?? []);
|
|
1018
|
+
const eligible = mode !== "normal" ? [] : PANEL_MEMBERS.filter((member) => this.seats.has(member) && (this.turns === 1 || this.pins.has(member) || called.has(member)));
|
|
1108
1019
|
this.members = [];
|
|
1109
1020
|
this.satOut = new Map();
|
|
1110
1021
|
this.step = "reading the conversation";
|
|
@@ -1212,7 +1123,8 @@ export class PlanningSession {
|
|
|
1212
1123
|
if (!jev?.enabled("answers")) return;
|
|
1213
1124
|
this.step = "checking for obvious answers";
|
|
1214
1125
|
this.deps.onChange?.();
|
|
1215
|
-
|
|
1126
|
+
// Style questions are the user's taste: never answered for them.
|
|
1127
|
+
const candidates = this.questions.flatMap((question, index) => question.record ? [] : [{ question, index }]).map(({ question, index }) => {
|
|
1216
1128
|
const recommended = recommendedOption(question);
|
|
1217
1129
|
return { index, from: question.from, text: question.text, options: question.options.map((option) => ({ label: optionLabel(option), description: option.description })), recommended: recommended ? optionLabel(recommended) : "" };
|
|
1218
1130
|
});
|
|
@@ -1236,14 +1148,28 @@ export class PlanningSession {
|
|
|
1236
1148
|
* recommended option and recorded in the plan's Assumptions, and a plan
|
|
1237
1149
|
* that exists is READY.
|
|
1238
1150
|
*/
|
|
1151
|
+
/** Where the project's design stands: the record, what the code settles, and what is open. */
|
|
1152
|
+
private design(): DesignStanding {
|
|
1153
|
+
return designStanding(dataRoot(this.deps.root, this.deps.configDir), this.deps.root);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/** The style questions DESIGN asked for, limited to fields still open: once settled, never asked again. */
|
|
1157
|
+
private styleAsks(outcomes: readonly MemberOutcome[]): PanelQuestion[] {
|
|
1158
|
+
const wanted = outcomes.find((outcome) => outcome.member === "designer")?.reply?.style ?? [];
|
|
1159
|
+
if (wanted.length === 0) return [];
|
|
1160
|
+
const open = new Set(this.design().gaps);
|
|
1161
|
+
return styleQuestions(wanted.filter((field) => open.has(field))).map((question) => ({ ...question, from: MEMBER_LABELS.designer }));
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1239
1164
|
private finishRound(outcomes: readonly MemberOutcome[], lead: RunOutcome, mode: RoundMode): void {
|
|
1240
1165
|
const reply = lead.status === "success" ? parsePlannerReply(lead.output) : undefined;
|
|
1241
1166
|
const seatQuestions = outcomes.flatMap((outcome) => (outcome.reply?.questions ?? []).map((question) => ({ ...question, from: MEMBER_LABELS[outcome.member] })));
|
|
1242
|
-
const
|
|
1167
|
+
const style = mode === "normal" ? this.styleAsks(outcomes) : [];
|
|
1168
|
+
const { asked, repeats } = withoutSettled([...roundQuestions(reply, seatQuestions), ...style], this.settled);
|
|
1243
1169
|
let questions = asked;
|
|
1244
1170
|
if (repeats.length > 0) this.deps.feed?.log(ORACLE_LABEL, `held back ${repeats.length} question${repeats.length === 1 ? "" : "s"} you already settled: ${repeats.map((question) => brief(question.text, 60)).join("; ")}`, "info");
|
|
1245
1171
|
const seatsReady = outcomes.every((outcome) => outcome.reply?.status === "ready");
|
|
1246
|
-
let ready = Boolean(reply && reply.status === "ready" && seatsReady);
|
|
1172
|
+
let ready = Boolean(reply && reply.status === "ready" && seatsReady && !questions.some((question) => question.record));
|
|
1247
1173
|
if (reply) {
|
|
1248
1174
|
// A round without a plan keeps the previous draft.
|
|
1249
1175
|
let plan = reply.plan ?? this.reply?.plan;
|
package/src/lobby/prompts.ts
CHANGED
|
@@ -5,22 +5,16 @@
|
|
|
5
5
|
* `node:*`): the web page imports this file directly.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export const TAB_IDS = ["lobby", "tasks", "plan", "
|
|
8
|
+
export const TAB_IDS = ["lobby", "tasks", "plan", "knowledge"] as const;
|
|
9
9
|
export type TabId = (typeof TAB_IDS)[number];
|
|
10
10
|
|
|
11
11
|
export const TAB_LABELS: Record<TabId, string> = {
|
|
12
12
|
lobby: "Lobby",
|
|
13
13
|
tasks: "Tasks",
|
|
14
14
|
plan: "Plan",
|
|
15
|
-
git: "Git",
|
|
16
15
|
knowledge: "Knowledge",
|
|
17
16
|
};
|
|
18
17
|
|
|
19
|
-
/** The tabs on show; issues are available inside Git. */
|
|
20
|
-
export function visibleTabs(_issues: boolean): TabId[] {
|
|
21
|
-
return [...TAB_IDS];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
18
|
/** A question answered in another window of the page (or put away) before this one's answer arrived. */
|
|
25
19
|
export const ANSWERED_ELSEWHERE = "already answered in another window";
|
|
26
20
|
|
package/src/lobby/runtime.ts
CHANGED
|
@@ -20,12 +20,9 @@ import { classifier, effortFor, hintsFor, scriptsPickerFor } from "../classifier
|
|
|
20
20
|
import { checkThinking } from "../pi/model-support.ts";
|
|
21
21
|
import type { Asker } from "../ask/types.ts";
|
|
22
22
|
import { ChatAgents } from "./chat-agents.ts";
|
|
23
|
-
import { execCommand, IssuesState } from "./issues.ts";
|
|
24
|
-
import { PullsState } from "./pulls.ts";
|
|
25
|
-
import { PullReviews } from "./pr-review.ts";
|
|
26
23
|
import { KnowledgeBook } from "./knowledge.ts";
|
|
27
24
|
import type { LobbyService } from "./host.ts";
|
|
28
|
-
import { backgroundSessions, carryHandOff, chatProfile, chatReplied, chatHistoryLines, createLobbyService, lobbyNotify, lobbyProfile, plannerDeps, resumeSession,
|
|
25
|
+
import { backgroundSessions, carryHandOff, chatProfile, chatReplied, chatHistoryLines, createLobbyService, lobbyNotify, lobbyProfile, plannerDeps, resumeSession, seatProfile, setServiceState, savePlan as serviceSavePlan, answerPanel as serviceAnswerPanel } from "./service.ts";
|
|
29
26
|
import { lobbyTopics } from "./topics.ts";
|
|
30
27
|
export { backgroundSessions, setSessionLauncher } from "./service.ts";
|
|
31
28
|
import { deliverComments, onOwnerEvent } from "../pi/owner.ts";
|
|
@@ -43,9 +40,6 @@ export interface Runtime {
|
|
|
43
40
|
/** The lobby chat's agents other than the oracle, answering one at a time. */
|
|
44
41
|
chat: ChatAgents;
|
|
45
42
|
planner?: PlanningSession;
|
|
46
|
-
issues: IssuesState;
|
|
47
|
-
pulls: PullsState;
|
|
48
|
-
reviews: PullReviews;
|
|
49
43
|
knowledge: KnowledgeBook;
|
|
50
44
|
unsubscribeFeed?: () => void;
|
|
51
45
|
/** Puts the panel's questions to the user: the web page's questionnaire unless a test sets another. */
|
|
@@ -79,13 +73,12 @@ export async function answerPanel(state: Runtime | undefined = runtime): Promise
|
|
|
79
73
|
return serviceAnswerPanel(state);
|
|
80
74
|
}
|
|
81
75
|
|
|
82
|
-
/** What the lobby is running now (a chat agent's reply, a
|
|
76
|
+
/** What the lobby is running now (a chat agent's reply, a planning round), in words, or undefined. */
|
|
83
77
|
export function lobbyWorkRunning(): string | undefined {
|
|
84
78
|
const state = runtime;
|
|
85
79
|
if (!state) return undefined;
|
|
86
80
|
if (state.chat.running) return "A chat reply";
|
|
87
81
|
if (state.planner?.busy) return "A planning round";
|
|
88
|
-
if (state.reviews.busy) return "A pull request review";
|
|
89
82
|
return undefined;
|
|
90
83
|
}
|
|
91
84
|
|
|
@@ -108,7 +101,6 @@ function shutdown(carryOn: boolean): void {
|
|
|
108
101
|
setServiceState(undefined);
|
|
109
102
|
state.unsubscribeFeed?.();
|
|
110
103
|
state.chat.cancelAll();
|
|
111
|
-
state.reviews.cancelAll();
|
|
112
104
|
state.planner?.cancel();
|
|
113
105
|
onRunUpdates(undefined);
|
|
114
106
|
}
|
|
@@ -130,9 +122,6 @@ export function startLobbyService(pi: ExtensionAPI, ctx: ExtensionContext, confi
|
|
|
130
122
|
asking: false,
|
|
131
123
|
workspace: { name: basename(ctx.cwd) || ctx.cwd },
|
|
132
124
|
readingWorkspace: false,
|
|
133
|
-
issues: new IssuesState(execCommand, ctx.cwd, () => lobbyTopics.bump("issues")),
|
|
134
|
-
pulls: new PullsState(execCommand, ctx.cwd, () => lobbyTopics.bump("git")),
|
|
135
|
-
reviews: undefined as unknown as PullReviews,
|
|
136
125
|
chat: undefined as unknown as ChatAgents,
|
|
137
126
|
knowledge: new KnowledgeBook({
|
|
138
127
|
root,
|
|
@@ -142,19 +131,6 @@ export function startLobbyService(pi: ExtensionAPI, ctx: ExtensionContext, confi
|
|
|
142
131
|
sessionId: () => ctx.sessionManager.getSessionId(),
|
|
143
132
|
}),
|
|
144
133
|
};
|
|
145
|
-
state.reviews = new PullReviews({
|
|
146
|
-
cwd: ctx.cwd,
|
|
147
|
-
root,
|
|
148
|
-
configDir,
|
|
149
|
-
exec: execCommand,
|
|
150
|
-
profile: () => reviewProfile(state),
|
|
151
|
-
stallTimeoutMs: workflow.stallTimeoutMs,
|
|
152
|
-
toolStallTimeoutMs: workflow.toolStallTimeoutMs,
|
|
153
|
-
feed: lobbyFeed,
|
|
154
|
-
onChange: () => lobbyTopics.bump("git"),
|
|
155
|
-
notify: (message, level) => lobbyNotify(state, message, level),
|
|
156
|
-
classifier: classifier(),
|
|
157
|
-
});
|
|
158
134
|
state.chat = new ChatAgents({
|
|
159
135
|
cwd: ctx.cwd,
|
|
160
136
|
root,
|
package/src/lobby/service.ts
CHANGED
|
@@ -14,9 +14,12 @@ import { cancelTaskExecutions } from "../execution/task-cancellation.ts";
|
|
|
14
14
|
import { refreshReview, deferReview } from "../delivery/review.ts";
|
|
15
15
|
import { deliver, type DeliveryRequest } from "../delivery/operations.ts";
|
|
16
16
|
import { deliveryStore, deliveryTask } from "../delivery/store.ts";
|
|
17
|
-
import { execCommand } from "./
|
|
17
|
+
import { execCommand } from "./exec.ts";
|
|
18
18
|
import { releaseAttachments } from "../state/attachments.ts";
|
|
19
|
-
import { loadConfig, readDataRoots, saveConfig as writeConfig } from "../state/project.ts";
|
|
19
|
+
import { dataRoot, loadConfig, readDataRoots, saveConfig as writeConfig } from "../state/project.ts";
|
|
20
|
+
import { choiceValue, recordDesignChoices } from "../knowledge/design-record.ts";
|
|
21
|
+
import type { AskResult } from "../ask/types.ts";
|
|
22
|
+
import type { PanelQuestion } from "./planner.ts";
|
|
20
23
|
import { knowledgeQuestion } from "./knowledge.ts";
|
|
21
24
|
import { addPlanComment, editComment, readPlanComments, type PlanComment } from "../state/comments.ts";
|
|
22
25
|
import { isAutoMode } from "../state/auto.ts";
|
|
@@ -29,7 +32,7 @@ import { applyStatus, currentZenTask, taskSnapshot } from "../pi/ui.ts";
|
|
|
29
32
|
import { taskName } from "../text.ts";
|
|
30
33
|
import { describeWorkspace } from "../execution/workspace.ts";
|
|
31
34
|
import { stripStartFlags } from "../pi/start-flags.ts";
|
|
32
|
-
import { checkThinking, modelRef, resolveChatProfile, resolveLobbyProfile, resolvePanelProfile,
|
|
35
|
+
import { checkThinking, modelRef, resolveChatProfile, resolveLobbyProfile, resolvePanelProfile, supportedThinking } from "../pi/model-support.ts";
|
|
33
36
|
import { modelLookup } from "../pi/tools.ts";
|
|
34
37
|
import { startPlannedTask, startTask } from "../pi/start-task.ts";
|
|
35
38
|
import { deliverComments, setAuto } from "../pi/owner.ts";
|
|
@@ -41,7 +44,7 @@ import { availableClassifiers, classifier, effortFor, hintsFor } from "../classi
|
|
|
41
44
|
import { cleanSessionName, launchPi, SessionRegistry, type BackgroundSession, type SessionLauncher } from "./sessions.ts";
|
|
42
45
|
import { askForSession } from "./session-questions.ts";
|
|
43
46
|
import { SessionChats } from "./session-files.ts";
|
|
44
|
-
import { answerMessage, questionnaires, settledQuestions } from "./ask.ts";
|
|
47
|
+
import { answerMessage, questionnaires, settledQuestions, styleAnswers } from "./ask.ts";
|
|
45
48
|
import { askUser } from "../ask/web.ts";
|
|
46
49
|
import type { Asker } from "../ask/types.ts";
|
|
47
50
|
import { PlanningSession, type PlannerDeps, type PlannerSeed } from "./planner.ts";
|
|
@@ -50,6 +53,7 @@ import { carryOnMessage, resumeRoute, RESUMED_DECISION, type Drivers } from "./r
|
|
|
50
53
|
import { archivePlan as archivePlanOnDisk, deletePlan as deletePlanOnDisk, isPlanId, previousPlans, readPlan, type PlanRecord, type PlanSummary } from "../state/plan-history.ts";
|
|
51
54
|
import { applyMasterModel } from "../pi/model-settings.ts";
|
|
52
55
|
import { grantableSkills, grantableTools } from "../pi/grants.ts";
|
|
56
|
+
import { piCommands, sendPiCommand } from "./pi-commands.ts";
|
|
53
57
|
import { lobbyTopics } from "./topics.ts";
|
|
54
58
|
import type { LobbyAgentKind, PanelMember } from "../schemas/configuration.ts";
|
|
55
59
|
import type { LiveSession, LobbyService, SwitchTarget } from "./host.ts";
|
|
@@ -156,10 +160,7 @@ function toOracle(state: Runtime, text: string): LobbySendResult {
|
|
|
156
160
|
const busy = !state.ctx.isIdle();
|
|
157
161
|
const command = parseLobbyCommand(text);
|
|
158
162
|
if (command) return lobbyCommand(state, command.command, command.rest);
|
|
159
|
-
if (text.startsWith("/"))
|
|
160
|
-
state.pi.sendUserMessage(text, { expandPromptTemplates: true, ...(busy ? { deliverAs: "followUp" as const } : {}) });
|
|
161
|
-
return `sent ${text.split(/\s+/)[0]} to pi`;
|
|
162
|
-
}
|
|
163
|
+
if (text.trimStart().startsWith("/")) return sendPiCommand(state.pi, state.ctx, text);
|
|
163
164
|
// A task in this session: the oracle drives it, and what you say goes to it.
|
|
164
165
|
if (currentZenTask()) return toMaster(state, text);
|
|
165
166
|
const mention = parseMention(text);
|
|
@@ -843,15 +844,6 @@ function deleteTask(state: Runtime, taskId: string, where: "list" | "archive"):
|
|
|
843
844
|
return `deleted ${taskId} for good`;
|
|
844
845
|
}
|
|
845
846
|
|
|
846
|
-
/** What a pull request review runs on: QA's model, thinking and grants. */
|
|
847
|
-
export function reviewProfile(state: Runtime) {
|
|
848
|
-
return resolveReviewProfile(loadConfig(), {
|
|
849
|
-
lookup: modelLookup(state.ctx),
|
|
850
|
-
sessionModel: sessionModel(state.ctx),
|
|
851
|
-
warn: (message) => lobbyNotify(state, message, "warning"),
|
|
852
|
-
});
|
|
853
|
-
}
|
|
854
|
-
|
|
855
847
|
export function seatProfile(state: Runtime, member: PanelMember) {
|
|
856
848
|
return resolvePanelProfile(loadConfig(), member, {
|
|
857
849
|
lookup: modelLookup(state.ctx),
|
|
@@ -955,13 +947,9 @@ function panelAsker(state: Runtime): Asker {
|
|
|
955
947
|
export async function savePlan(state: Runtime | undefined): Promise<string> {
|
|
956
948
|
const session = state?.planner;
|
|
957
949
|
if (!state || !session) return "no planning session";
|
|
958
|
-
if (state.asking) return "a questionnaire is already open";
|
|
959
|
-
state.asking = true;
|
|
960
950
|
try {
|
|
961
|
-
|
|
962
|
-
return await session.saveWithSplit((questions, signal) => asker(questions, state.ctx, signal, "planner"), { splitAbove: loadConfig().lobby.splitPlanAbove });
|
|
951
|
+
return session.savePlan();
|
|
963
952
|
} finally {
|
|
964
|
-
state.asking = false;
|
|
965
953
|
lobbyTopics.bump("planner");
|
|
966
954
|
}
|
|
967
955
|
}
|
|
@@ -995,8 +983,9 @@ export async function answerPanel(state: Runtime | undefined): Promise<string> {
|
|
|
995
983
|
session.answered = [];
|
|
996
984
|
return "nothing was answered — the questions stay open";
|
|
997
985
|
}
|
|
986
|
+
const recorded = recordStyleAnswers(state, session.questions, session.answered);
|
|
998
987
|
void session.send(message, settledQuestions(session.questions, session.answered));
|
|
999
|
-
return
|
|
988
|
+
return `answers sent — the panel is on the next round${recorded > 0 ? ` · ${recorded} design choice${recorded === 1 ? "" : "s"} recorded` : ""}`;
|
|
1000
989
|
} catch (error) {
|
|
1001
990
|
return `could not put the questions: ${(error as Error).message}`;
|
|
1002
991
|
} finally {
|
|
@@ -1005,6 +994,21 @@ export async function answerPanel(state: Runtime | undefined): Promise<string> {
|
|
|
1005
994
|
}
|
|
1006
995
|
}
|
|
1007
996
|
|
|
997
|
+
/** The user's answers to style questions go into the design record, so no agent asks them again. Returns how many. */
|
|
998
|
+
function recordStyleAnswers(state: Runtime, questions: readonly PanelQuestion[], results: readonly AskResult[]): number {
|
|
999
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
1000
|
+
const choices = styleAnswers(questions, results).map(({ field, answer }) => ({ field, value: choiceValue(field, answer), by: "you" as const, date }));
|
|
1001
|
+
if (choices.length === 0) return 0;
|
|
1002
|
+
try {
|
|
1003
|
+
recordDesignChoices(dataRoot(state.root, state.configDir), choices);
|
|
1004
|
+
lobbyTopics.bump("knowledge");
|
|
1005
|
+
return choices.length;
|
|
1006
|
+
} catch (error) {
|
|
1007
|
+
lobbyFeed.log("DESIGN", `could not record the design choices — ${(error as Error).message}`, "error");
|
|
1008
|
+
return 0;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1008
1012
|
/** Read the repository name and branch again, off the render path; the title repaints when they changed. */
|
|
1009
1013
|
function refreshWorkspace(state: Runtime): void {
|
|
1010
1014
|
if (state.readingWorkspace) return;
|
|
@@ -1068,6 +1072,7 @@ export function createLobbyService(state: Runtime): LobbyService {
|
|
|
1068
1072
|
comments: (taskId) => readPlanComments(state.root, state.configDir, taskId),
|
|
1069
1073
|
metrics: () => readMetrics(state.root, state.configDir),
|
|
1070
1074
|
classifierMetrics: () => readClassifierMetrics(state.root, state.configDir),
|
|
1075
|
+
commands: () => piCommands(state.pi),
|
|
1071
1076
|
toOracle: (text) => toOracle(state, text),
|
|
1072
1077
|
askKnowledge: (text) => {
|
|
1073
1078
|
state.pi.sendUserMessage(knowledgeQuestion(text, readDataRoots(state.root, state.configDir)), state.ctx.isIdle() ? undefined : { deliverAs: "followUp" });
|
|
@@ -1119,15 +1124,11 @@ export function createLobbyService(state: Runtime): LobbyService {
|
|
|
1119
1124
|
},
|
|
1120
1125
|
classifierModels: () => availableClassifiers().map((model) => ({ id: model.id, label: model.label })),
|
|
1121
1126
|
grants: () => ({ mcpTools: grantableTools(state.pi), skills: grantableSkills(state.root, state.pi) }),
|
|
1122
|
-
issuesEnabled: () => loadConfig().lobby.issues,
|
|
1123
1127
|
recovered: () => state.recovered,
|
|
1124
1128
|
seatLabel: (member) => {
|
|
1125
1129
|
const profile = seatProfile(state, member);
|
|
1126
1130
|
return `${profile.model ?? "session model"} · ${profile.thinking}`;
|
|
1127
1131
|
},
|
|
1128
|
-
issues: state.issues,
|
|
1129
|
-
pulls: state.pulls,
|
|
1130
|
-
reviews: state.reviews,
|
|
1131
1132
|
knowledge: state.knowledge,
|
|
1132
1133
|
profileLabel: (kind) => {
|
|
1133
1134
|
const profile = lobbyProfile(state, kind);
|
package/src/lobby/topics.ts
CHANGED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/** Task-local background validation. Briefs and persistent notes remain separate. */
|
|
2
|
+
import { contentHash } from "../knowledge/file-notes.ts";
|
|
3
|
+
|
|
4
|
+
export interface EvidenceHint {
|
|
5
|
+
id: string;
|
|
6
|
+
scope: "file" | "repository";
|
|
7
|
+
source: string;
|
|
8
|
+
fingerprint: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface FreshnessInvalidation {
|
|
12
|
+
assignmentId: string;
|
|
13
|
+
revision: number;
|
|
14
|
+
hintIds: string[];
|
|
15
|
+
pause: true;
|
|
16
|
+
recheckCompletedWork: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface EvidenceRevision {
|
|
20
|
+
revision: number;
|
|
21
|
+
pending: number;
|
|
22
|
+
invalid: Set<string>;
|
|
23
|
+
completed: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type EvidenceStatus = "unverified hints" | "verified" | "invalidated" | "superseded";
|
|
27
|
+
|
|
28
|
+
/** File-local checks never establish current callers, coverage or broad behavior. */
|
|
29
|
+
export async function verifyEvidenceHint(cwd: string, hint: EvidenceHint, currentTree: () => Promise<string | undefined>): Promise<boolean> {
|
|
30
|
+
const fingerprint = hint.scope === "file" ? await contentHash(cwd, hint.source) : await currentTree();
|
|
31
|
+
return fingerprint !== undefined && fingerprint === hint.fingerprint;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class EvidenceFreshness {
|
|
35
|
+
private readonly revisions = new Map<string, EvidenceRevision>();
|
|
36
|
+
private readonly checks = new Map<string, Promise<boolean>>();
|
|
37
|
+
|
|
38
|
+
private readonly check: (hint: EvidenceHint) => Promise<boolean>;
|
|
39
|
+
private readonly notify: (event: FreshnessInvalidation) => void | Promise<void>;
|
|
40
|
+
|
|
41
|
+
constructor(check: (hint: EvidenceHint) => Promise<boolean>, notify: (event: FreshnessInvalidation) => void | Promise<void>) {
|
|
42
|
+
this.check = check;
|
|
43
|
+
this.notify = notify;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Launch alongside dispatch; await the returned promise before accepting work. */
|
|
47
|
+
start(input: { assignmentId: string; revision: number; hints: readonly EvidenceHint[] }): Promise<void> {
|
|
48
|
+
const previous = this.revisions.get(input.assignmentId);
|
|
49
|
+
if (previous && (previous.revision > input.revision || (previous.revision === input.revision && !previous.completed))) {
|
|
50
|
+
throw new Error("Freshness checks require an increasing assignment revision or a completed dispatch retry.");
|
|
51
|
+
}
|
|
52
|
+
const hints = [...new Map(input.hints.map((hint) => [hint.id, { ...hint }])).values()];
|
|
53
|
+
const state: EvidenceRevision = { revision: input.revision, pending: hints.length, invalid: new Set(), completed: false };
|
|
54
|
+
this.revisions.set(input.assignmentId, state);
|
|
55
|
+
// A failed status delivery must not end the acceptance barrier while other checks still run.
|
|
56
|
+
return Promise.allSettled(hints.map((hint) => this.validate(input.assignmentId, state, hint))).then((results) => {
|
|
57
|
+
const failure = results.find((result) => result.status === "rejected");
|
|
58
|
+
if (failure?.status === "rejected") throw failure.reason;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
completed(assignmentId: string, revision: number): void {
|
|
63
|
+
const state = this.revisions.get(assignmentId);
|
|
64
|
+
if (state?.revision === revision) state.completed = true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
status(assignmentId: string, revision: number): EvidenceStatus {
|
|
68
|
+
const state = this.revisions.get(assignmentId);
|
|
69
|
+
if (state?.revision !== revision) return "superseded";
|
|
70
|
+
if (state.invalid.size) return "invalidated";
|
|
71
|
+
return state.pending ? "unverified hints" : "verified";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
canAccept(assignmentId: string, revision: number): boolean {
|
|
75
|
+
return this.status(assignmentId, revision) === "verified";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private sharedCheck(hint: EvidenceHint): Promise<boolean> {
|
|
79
|
+
const key = JSON.stringify([hint.scope, hint.source, hint.fingerprint]);
|
|
80
|
+
const existing = this.checks.get(key);
|
|
81
|
+
if (existing) return existing;
|
|
82
|
+
const pending = Promise.resolve().then(() => this.check(hint)).catch(() => false);
|
|
83
|
+
this.checks.set(key, pending);
|
|
84
|
+
void pending.then(() => { if (this.checks.get(key) === pending) this.checks.delete(key); });
|
|
85
|
+
return pending;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private async validate(assignmentId: string, state: EvidenceRevision, hint: EvidenceHint): Promise<void> {
|
|
89
|
+
const valid = await this.sharedCheck(hint);
|
|
90
|
+
if (this.revisions.get(assignmentId) !== state) return;
|
|
91
|
+
state.pending -= 1;
|
|
92
|
+
if (valid) return;
|
|
93
|
+
state.invalid.add(hint.id);
|
|
94
|
+
await this.notify({ assignmentId, revision: state.revision, hintIds: [hint.id], pause: true, recheckCompletedWork: state.completed });
|
|
95
|
+
}
|
|
96
|
+
}
|