@lysyi3m/sidecar 1.10.0 → 1.11.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/dist/src/cases/items.js +129 -30
- package/dist/src/cases/state.js +2 -2
- package/dist/src/dashboard/pages.js +23 -10
- package/dist/src/mcp/server.js +101 -50
- package/dist/src/mcp/tools.js +16 -6
- package/dist/src/turns/prompt.js +19 -4
- package/dist/src/turns/runner.js +10 -4
- package/package.json +1 -1
package/dist/src/cases/items.js
CHANGED
|
@@ -1,22 +1,40 @@
|
|
|
1
1
|
// Review items. An item is one point the navigator raised: a flag, or an opinion's main point. Each
|
|
2
|
-
// tracks whether the navigator itself has accepted how the driver settled it. One reducer, applied
|
|
3
|
-
// the dashboard all read its result. See
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// tracks whether the navigator itself has accepted how the driver settled it. One reducer, applied
|
|
3
|
+
// by fold() event by event; tools, prompts and the dashboard all read its result. See
|
|
4
|
+
// docs/design.md → Review.
|
|
5
|
+
// `reviewBudget` in config.json limits the automatic reviews per item and stage: past it, an
|
|
6
|
+
// unsettled item waits for the user. How many items one turn reviews is set by the prompt bound alone.
|
|
6
7
|
export const REVIEW_STATUSES = ["confirmed", "reopened", "held"];
|
|
7
8
|
/**
|
|
8
9
|
* How far a decision has got. A decision without a state is ready.
|
|
9
|
-
* - ready: the resolution exists — a fix in the workspace, a rejection, an explanation
|
|
10
|
-
* - planned: accepted, but the
|
|
10
|
+
* - ready: the resolution exists — a fix in the workspace, a rejection, an explanation.
|
|
11
|
+
* - planned: a proposal: accepted, but the action is not made yet. The navigator agrees to it first.
|
|
11
12
|
* - deferred: the point moves out of this case, for later work or for the user.
|
|
12
13
|
*/
|
|
13
14
|
export const DECISION_STATES = ["ready", "planned", "deferred"];
|
|
14
15
|
export const decisionState = (e) => e.state === "planned" || e.state === "deferred" ? e.state : "ready";
|
|
16
|
+
export const stageOf = (decision) => decisionState(decision) === "planned" ? "agreement" : "done";
|
|
17
|
+
/** Whether a decision records the user's own answer, and whether the user made it final. */
|
|
18
|
+
export const fromUser = (e) => e.source === "user";
|
|
19
|
+
const isFinal = (e) => fromUser(e) && e.final === true;
|
|
15
20
|
// An event's payload fields are unchecked on read: a field that is no array reads as none.
|
|
16
21
|
const list = (value) => (Array.isArray(value) ? value : []);
|
|
17
22
|
export const flagsOf = (e) => list(e.flags);
|
|
18
23
|
export const reviewsOf = (e) => list(e.reviews);
|
|
19
24
|
export const reviewTargetsOf = (e) => list(e.reviewTargets);
|
|
25
|
+
// Agreements and their targets are separate fields, so code that predates them never reads an
|
|
26
|
+
// agreement as a confirmed resolution: to it, an agreed point is still planned.
|
|
27
|
+
export const agreementsOf = (e) => list(e.agreements);
|
|
28
|
+
export const agreementTargetsOf = (e) => list(e.agreementTargets);
|
|
29
|
+
const newItem = (fields) => ({
|
|
30
|
+
reviews: [],
|
|
31
|
+
reviewTurns: 0,
|
|
32
|
+
agreementTurns: 0,
|
|
33
|
+
userFloor: { agreement: 0, done: 0 },
|
|
34
|
+
userAnswers: [],
|
|
35
|
+
status: "open",
|
|
36
|
+
...fields,
|
|
37
|
+
});
|
|
20
38
|
/** Folds one event into the items. `askOf` finds an ask event by id. */
|
|
21
39
|
export function applyItemEvent(items, e, askOf) {
|
|
22
40
|
if (e.kind === "opinion") {
|
|
@@ -30,50 +48,68 @@ export function applyItemEvent(items, e, askOf) {
|
|
|
30
48
|
if (!ask?.review &&
|
|
31
49
|
(e.verdict === "disagree" || e.verdict === "needs-info") &&
|
|
32
50
|
(legacy || flags.length === 0)) {
|
|
33
|
-
items.set(askId, {
|
|
51
|
+
items.set(askId, newItem({
|
|
34
52
|
ref: askId,
|
|
35
53
|
kind: "opinion",
|
|
36
54
|
...(legacy ? { severity: String(e.severity) } : {}),
|
|
37
55
|
point: String(e.body),
|
|
38
56
|
question: String(ask?.body ?? ""),
|
|
39
57
|
raisedN: e.n,
|
|
40
|
-
|
|
41
|
-
reviewTurns: 0,
|
|
42
|
-
status: "open",
|
|
43
|
-
});
|
|
58
|
+
}));
|
|
44
59
|
}
|
|
45
60
|
for (const flag of flags) {
|
|
46
|
-
items.set(flag.id, {
|
|
61
|
+
items.set(flag.id, newItem({
|
|
47
62
|
ref: flag.id,
|
|
48
63
|
kind: "flag",
|
|
49
64
|
severity: flag.severity,
|
|
50
65
|
point: flag.body,
|
|
51
66
|
raisedN: e.n,
|
|
52
|
-
|
|
53
|
-
reviewTurns: 0,
|
|
54
|
-
status: "open",
|
|
55
|
-
});
|
|
67
|
+
}));
|
|
56
68
|
}
|
|
57
|
-
// The runner stores the turn's targets with its opinion; each one used a
|
|
69
|
+
// The runner stores the turn's targets with its opinion; each one used a turn of its stage.
|
|
58
70
|
for (const target of reviewTargetsOf(e)) {
|
|
59
71
|
const item = items.get(target.ref);
|
|
60
72
|
if (item)
|
|
61
73
|
item.reviewTurns++;
|
|
62
74
|
}
|
|
75
|
+
for (const target of agreementTargetsOf(e)) {
|
|
76
|
+
const item = items.get(target.ref);
|
|
77
|
+
if (item)
|
|
78
|
+
item.agreementTurns++;
|
|
79
|
+
}
|
|
63
80
|
for (const review of reviewsOf(e)) {
|
|
64
81
|
const item = items.get(review.ref);
|
|
65
82
|
if (!item)
|
|
66
83
|
continue;
|
|
67
84
|
// A review without a decision to match applies to nothing.
|
|
68
85
|
const applied = item.decision !== undefined && item.decision.n === review.decisionN;
|
|
69
|
-
item.reviews.push({ opinionN: e.n, applied });
|
|
86
|
+
item.reviews.push({ opinionN: e.n, applied, stage: "done" });
|
|
70
87
|
if (!applied)
|
|
71
88
|
continue;
|
|
89
|
+
item.resolved = review.status === "confirmed";
|
|
72
90
|
item.status =
|
|
73
91
|
review.status === "confirmed" && decisionState(item.decision) === "deferred"
|
|
74
92
|
? "deferred"
|
|
75
93
|
: review.status;
|
|
76
94
|
}
|
|
95
|
+
for (const review of agreementsOf(e)) {
|
|
96
|
+
const item = items.get(review.ref);
|
|
97
|
+
if (!item)
|
|
98
|
+
continue;
|
|
99
|
+
const decision = item.decision;
|
|
100
|
+
const applied = decision !== undefined &&
|
|
101
|
+
decision.n === review.decisionN &&
|
|
102
|
+
stageOf(decision) === "agreement";
|
|
103
|
+
item.reviews.push({ opinionN: e.n, applied, stage: "agreement" });
|
|
104
|
+
if (!applied)
|
|
105
|
+
continue;
|
|
106
|
+
if (review.status === "confirmed") {
|
|
107
|
+
item.agreement = { decision: decision, by: "navigator", opinionN: e.n };
|
|
108
|
+
item.status = "agreed";
|
|
109
|
+
}
|
|
110
|
+
else
|
|
111
|
+
item.status = review.status;
|
|
112
|
+
}
|
|
77
113
|
return;
|
|
78
114
|
}
|
|
79
115
|
if (e.kind === "decision" && typeof e.ref === "string") {
|
|
@@ -81,28 +117,91 @@ export function applyItemEvent(items, e, askOf) {
|
|
|
81
117
|
if (!item)
|
|
82
118
|
return;
|
|
83
119
|
item.decision = e;
|
|
84
|
-
|
|
120
|
+
const stage = stageOf(e);
|
|
121
|
+
// Each new answer from the user buys one more round at its stage, and an answer that proposes
|
|
122
|
+
// an action buys that action's review too. A repeated answer buys nothing.
|
|
123
|
+
if (fromUser(e) && !item.userAnswers.includes(String(e.body))) {
|
|
124
|
+
item.userAnswers.push(String(e.body));
|
|
125
|
+
item.userAnswerAt = { agreement: item.agreementTurns, done: item.reviewTurns };
|
|
126
|
+
item.userFloor[stage] = turnsAt(item, stage) + 1;
|
|
127
|
+
if (stage === "agreement")
|
|
128
|
+
item.userFloor.done = item.reviewTurns + 1;
|
|
129
|
+
}
|
|
130
|
+
if (stage === "agreement") {
|
|
131
|
+
// A new proposal needs agreement of its own; the user's final word is that agreement.
|
|
132
|
+
if (isFinal(e)) {
|
|
133
|
+
item.agreement = { decision: e, by: "user" };
|
|
134
|
+
item.status = "agreed";
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
delete item.agreement;
|
|
138
|
+
item.status = "planned";
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// A new resolution replaces the confirmed one: until it is reviewed, nothing is resolved.
|
|
143
|
+
item.resolved = isFinal(e);
|
|
144
|
+
item.status = !isFinal(e)
|
|
145
|
+
? "addressed"
|
|
146
|
+
: decisionState(e) === "deferred"
|
|
147
|
+
? "deferred"
|
|
148
|
+
: "user-decided";
|
|
85
149
|
}
|
|
86
150
|
}
|
|
151
|
+
/** The stage the item's latest decision is in; an undecided item is reviewed as a resolution. */
|
|
152
|
+
export const itemStage = (item) => (item.decision ? stageOf(item.decision) : "done");
|
|
153
|
+
const turnsAt = (item, stage) => stage === "agreement" ? item.agreementTurns : item.reviewTurns;
|
|
154
|
+
/** The turns a stage may use: the budget, or, once the user has answered, what the user granted. */
|
|
155
|
+
const allowance = (item, stage, budget) => item.userAnswerAt ? item.userFloor[stage] : budget;
|
|
156
|
+
const used = (item, stage, budget) => turnsAt(item, stage) >= allowance(item, stage, budget);
|
|
157
|
+
/** The turns the item's current stage may use. */
|
|
158
|
+
export const reviewAllowance = (item, budget) => allowance(item, itemStage(item), budget);
|
|
159
|
+
/**
|
|
160
|
+
* Whether the item's reviews are spent: a decision on it now is never reviewed. Its current stage
|
|
161
|
+
* may have used its turns, or the other stage may have ended unsettled with its turns used — a
|
|
162
|
+
* point left for the user does not return to review through a decision at the other stage. A stage
|
|
163
|
+
* ends settled with an agreed proposal or a confirmed resolution. The user's answer waives what came
|
|
164
|
+
* before it.
|
|
165
|
+
*/
|
|
166
|
+
export function reviewsSpent(item, budget) {
|
|
167
|
+
const stage = itemStage(item);
|
|
168
|
+
const other = stage === "agreement" ? "done" : "agreement";
|
|
169
|
+
const otherEnded = used(item, other, budget) &&
|
|
170
|
+
turnsAt(item, other) > (item.userAnswerAt?.[other] ?? -1) &&
|
|
171
|
+
!(other === "agreement" ? item.agreement : item.resolved);
|
|
172
|
+
return used(item, stage, budget) || otherEnded;
|
|
173
|
+
}
|
|
174
|
+
/** The turns the item's current stage has used. */
|
|
175
|
+
export const reviewsUsed = (item) => turnsAt(item, itemStage(item));
|
|
176
|
+
const WAITING = new Set(["planned", "addressed", "reopened"]);
|
|
87
177
|
/**
|
|
88
|
-
* An item's status under a review budget. A point awaiting
|
|
89
|
-
* spent is left for the user: no further review can settle it.
|
|
178
|
+
* An item's status under a review budget. A point awaiting the navigator or reopened once its
|
|
179
|
+
* stage's turns are spent is left for the user: no further review can settle it.
|
|
180
|
+
*/
|
|
181
|
+
export const itemStatus = (item, budget) => WAITING.has(item.status) && reviewsSpent(item, budget) ? "exhausted" : item.status;
|
|
182
|
+
/**
|
|
183
|
+
* Items whose latest decision awaits the navigator, oldest decision first: a resolution to review
|
|
184
|
+
* or a proposal to agree to.
|
|
90
185
|
*/
|
|
91
|
-
export const itemStatus = (item, budget) => (item.status === "addressed" || item.status === "reopened") && item.reviewTurns >= budget
|
|
92
|
-
? "exhausted"
|
|
93
|
-
: item.status;
|
|
94
|
-
/** Whether a point's reviews are spent: a decision on it now is never reviewed. */
|
|
95
|
-
export const reviewsSpent = (item, budget) => item.reviewTurns >= budget;
|
|
96
|
-
/** Items whose latest decision awaits the navigator's review, oldest decision first. */
|
|
97
186
|
export function awaitingReview(items, budget) {
|
|
98
187
|
return [...items.values()]
|
|
99
|
-
.filter((i) =>
|
|
188
|
+
.filter((i) => {
|
|
189
|
+
const status = itemStatus(i, budget);
|
|
190
|
+
return status === "addressed" || status === "planned";
|
|
191
|
+
})
|
|
100
192
|
.sort((a, b) => a.decision.n - b.decision.n);
|
|
101
193
|
}
|
|
102
|
-
/**
|
|
194
|
+
/** Whether a status settles its point: the navigator confirmed it, or the user decided it. */
|
|
195
|
+
export const isSettled = (status) => status === "confirmed" || status === "user-decided";
|
|
196
|
+
/** Items not settled: everything but confirmed and user-decided. */
|
|
103
197
|
export function unsettled(items) {
|
|
104
|
-
return [...items.values()].filter((i) => i.status
|
|
198
|
+
return [...items.values()].filter((i) => !isSettled(i.status));
|
|
105
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Whether the case's work is complete: every point settled, or deferred with the navigator's
|
|
202
|
+
* consent. An agreed point is not: its action is still pending.
|
|
203
|
+
*/
|
|
204
|
+
export const complete = (items) => [...items.values()].every((i) => isSettled(i.status) || i.status === "deferred");
|
|
106
205
|
/**
|
|
107
206
|
* Keeps the reviews a reply may record: one per target ref, for targets the turn was shown. An
|
|
108
207
|
* invented or repeated ref is dropped; an omitted target stays awaiting review.
|
package/dist/src/cases/state.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyItemEvent, reviewTargetsOf } from "./items.js";
|
|
1
|
+
import { agreementTargetsOf, applyItemEvent, reviewTargetsOf, } from "./items.js";
|
|
2
2
|
import { askUsage } from "./usage.js";
|
|
3
3
|
export const CASE_STATUSES = ["open", "closed"];
|
|
4
4
|
/** The case's state as the tools, the CLI and the dashboard name it. */
|
|
@@ -68,7 +68,7 @@ export function fold(events) {
|
|
|
68
68
|
runnerPid: Number(e.runnerPid),
|
|
69
69
|
runnerStart: e.runnerStart ?? null,
|
|
70
70
|
hardDeadline: Number(e.hardDeadline),
|
|
71
|
-
reviewTargets: reviewTargetsOf(e),
|
|
71
|
+
reviewTargets: [...reviewTargetsOf(e), ...agreementTargetsOf(e)],
|
|
72
72
|
started: e,
|
|
73
73
|
});
|
|
74
74
|
break;
|
|
@@ -2,7 +2,7 @@ import { homedir } from "node:os";
|
|
|
2
2
|
import { effortLabel, modelLabel } from "../adapters/index.js";
|
|
3
3
|
import { html, raw } from "./html.js";
|
|
4
4
|
import { MARKS, markUrl } from "./marks.js";
|
|
5
|
-
import { decisionState, flagsOf, reviewsOf } from "../cases/items.js";
|
|
5
|
+
import { agreementsOf, decisionState, flagsOf, fromUser, isSettled, reviewsOf, } from "../cases/items.js";
|
|
6
6
|
import { SIDECAR_VERSION } from "../lib/version.js";
|
|
7
7
|
import { foundNothingToReview } from "../turns/prompt.js";
|
|
8
8
|
// The dashboard's markup, rendered on the server from the view model. Every element the live
|
|
@@ -267,7 +267,7 @@ function caseHead(model) {
|
|
|
267
267
|
const views = [...items.values()];
|
|
268
268
|
const opinions = [...state.asks.values()].filter((a) => a.terminal?.kind === "opinion").length;
|
|
269
269
|
const flags = views.filter((v) => v.item.kind === "flag").length;
|
|
270
|
-
const unsettled = views.filter((v) => v.status
|
|
270
|
+
const unsettled = views.filter((v) => !isSettled(v.status)).length;
|
|
271
271
|
// Points the agents could not settle between them: the user decides each one.
|
|
272
272
|
const standing = views
|
|
273
273
|
.filter((v) => v.status === "held" || v.status === "exhausted")
|
|
@@ -343,9 +343,11 @@ const anchorOf = (n, model) => {
|
|
|
343
343
|
};
|
|
344
344
|
const ITEM_CHIP = {
|
|
345
345
|
open: { label: "open", tone: "alert" },
|
|
346
|
-
planned: { label: "
|
|
346
|
+
planned: { label: "proposed", tone: "quiet" },
|
|
347
|
+
agreed: { label: "agreed, action pending", tone: "quiet" },
|
|
347
348
|
addressed: { label: "awaiting navigator", tone: "quiet" },
|
|
348
349
|
confirmed: { label: "confirmed", tone: "ok" },
|
|
350
|
+
"user-decided": { label: "decided by the user", tone: "ok" },
|
|
349
351
|
deferred: { label: "deferred", tone: "alert" },
|
|
350
352
|
reopened: { label: "reopened", tone: "alert" },
|
|
351
353
|
held: { label: "standing disagreement", tone: "alert" },
|
|
@@ -413,7 +415,7 @@ ${foot}
|
|
|
413
415
|
function opinionEntry(e, model) {
|
|
414
416
|
const askId = String(e.askId);
|
|
415
417
|
const isReview = model.state.asks.get(askId)?.event.review === true;
|
|
416
|
-
const settled = (id) => model.items.get(id)?.status
|
|
418
|
+
const settled = (id) => isSettled(model.items.get(id)?.status);
|
|
417
419
|
const points = [...flagsOf(e).map((f) => f.id), ...(model.items.has(askId) ? [askId] : [])];
|
|
418
420
|
const tags = [
|
|
419
421
|
"opinion",
|
|
@@ -422,16 +424,22 @@ function opinionEntry(e, model) {
|
|
|
422
424
|
];
|
|
423
425
|
const flags = flagsOf(e).map((flag) => html `<div class="flag" id="flag-${flag.id}"${settled(flag.id) ? raw(" data-settled") : ""}><span class="flag-id">${flag.id}</span><div class="flag-text">${prose(flag.body)}</div><div class="flag-status">${severityChip(flag.severity)}${itemState(flag.id, model)}</div></div>`);
|
|
424
426
|
const limits = Array.isArray(e.limits) ? e.limits : [];
|
|
425
|
-
const
|
|
427
|
+
const tagged = [
|
|
428
|
+
...agreementsOf(e).map((r) => ({ r, stage: "agreement" })),
|
|
429
|
+
...reviewsOf(e).map((r) => ({ r, stage: "done" })),
|
|
430
|
+
];
|
|
431
|
+
const reviews = tagged.map(({ r, stage }) => {
|
|
426
432
|
// A review of a decision since replaced is history: it says nothing about the point now.
|
|
427
|
-
const applied = model.items.get(r.ref)?.item.reviews.find((h) => h.opinionN === e.n
|
|
428
|
-
|
|
433
|
+
const applied = model.items.get(r.ref)?.item.reviews.find((h) => h.opinionN === e.n && h.stage === stage)
|
|
434
|
+
?.applied ?? false;
|
|
435
|
+
const label = stage === "agreement" && r.status === "confirmed" ? "agreed" : r.status;
|
|
436
|
+
return html `<div class="flag"><span class="flag-id">${refFor(r.ref, model)}</span><div class="flag-text">${prose(r.body)}</div><div class="flag-status">${stage === "agreement" ? html `<span class="dim">proposal</span>` : ""}<span class="chip ${!applied ? "is-quiet" : r.status === "confirmed" ? "is-ok" : "is-alert"}">${label}</span>${applied ? "" : html `<span class="dim">of an earlier decision</span>`}</div></div>`;
|
|
429
437
|
});
|
|
430
438
|
return entry(e, { id: `ask-${askId}-opinion`, marker: "navigator", tags }, html `<div class="card navigator">
|
|
431
439
|
${cardHead("Navigator", model.state.opened.navigator, isReview ? "Review" : "Opinion", [html `<span>re</span>`, ref(`#ask-${askId}`, e.askId)])}
|
|
432
440
|
<div class="verdict"><span class="chip ${VERDICT_CLASS[String(e.verdict)] ?? ""}">${e.verdict}</span>${e.severity !== undefined ? severityChip(e.severity) : ""}${model.items.has(askId) ? itemState(askId, model) : ""}</div>
|
|
433
441
|
<div class="card-text">${prose(e.body)}</div>
|
|
434
|
-
${reviews.length ? html `<section class="flags"><h3 class="flags-title"><span class="label">Reviews</span><span class="dim">of the driver's decisions on earlier points</span></h3>${reviews}</section>` : ""}
|
|
442
|
+
${reviews.length ? html `<section class="flags"><h3 class="flags-title"><span class="label">Reviews</span><span class="dim">of the driver's proposals and decisions on earlier points</span></h3>${reviews}</section>` : ""}
|
|
435
443
|
${flags.length ? html `<section class="flags"><h3 class="flags-title"><span class="label">Flags</span><span class="dim">one per finding; each stays open until the navigator confirms a decision on it</span></h3>${flags}</section>` : ""}
|
|
436
444
|
${limits.length ? html `<section class="flags"><h3 class="flags-title"><span class="label">Limits</span><span class="dim">what the navigator could not check</span></h3><ul class="limits">${limits.map((l) => html `<li>${prose(l)}</li>`)}</ul></section>` : ""}
|
|
437
445
|
${turnFoot(model.state.asks.get(askId)?.usage, String(model.state.opened.navigator))}
|
|
@@ -459,7 +467,9 @@ function noteEntry(events, model) {
|
|
|
459
467
|
const state = e.kind === "decision" ? decisionState(e) : "ready";
|
|
460
468
|
const kind = [
|
|
461
469
|
e.kind === "decision" ? "Decision" : "Note",
|
|
462
|
-
...(state === "ready" ? [] : [state]),
|
|
470
|
+
...(state === "ready" ? [] : [state === "planned" ? "proposal" : state]),
|
|
471
|
+
...(e.kind === "decision" && fromUser(e) ? ["the user's answer"] : []),
|
|
472
|
+
...(e.kind === "decision" && fromUser(e) && e.final === true ? ["final"] : []),
|
|
463
473
|
...(events.length > 1 ? [`${events.length} points`] : []),
|
|
464
474
|
].join(" · ");
|
|
465
475
|
return entry(e, { id: `e${e.n}`, marker: "driver" }, html `${events.slice(1).map((x) => html `<span class="anchor" id="e${x.n}"></span>`)}<div class="card compact">
|
|
@@ -480,7 +490,10 @@ function sameRecord(group, next) {
|
|
|
480
490
|
typeof first.ref === "string" &&
|
|
481
491
|
typeof next.ref === "string" &&
|
|
482
492
|
next.body === first.body &&
|
|
483
|
-
(next.kind !== "decision" ||
|
|
493
|
+
(next.kind !== "decision" ||
|
|
494
|
+
(decisionState(next) === decisionState(first) &&
|
|
495
|
+
next.source === first.source &&
|
|
496
|
+
next.final === first.final)) &&
|
|
484
497
|
Date.parse(next.ts) - Date.parse(first.ts) < 1000);
|
|
485
498
|
}
|
|
486
499
|
function failedEntry(e, model) {
|
package/dist/src/mcp/server.js
CHANGED
|
@@ -5,7 +5,7 @@ import { adapters, findAdapter, getNavigator, preferredNavigator, selectableNavi
|
|
|
5
5
|
import { loadConfig } from "../config.js";
|
|
6
6
|
import { processAlive, startTime } from "../lib/proc.js";
|
|
7
7
|
import { SIDECAR_VERSION } from "../lib/version.js";
|
|
8
|
-
import { awaitingReview, flagsOf, itemStatus, reviewsOf,
|
|
8
|
+
import { agreementsOf, agreementTargetsOf, awaitingReview, complete, flagsOf, fromUser, isSettled, itemStage, itemStatus, reviewsOf, reviewAllowance, reviewsUsed, reviewTargetsOf, unsettled, } from "../cases/items.js";
|
|
9
9
|
import { caseStatus, fold } from "../cases/state.js";
|
|
10
10
|
import { Store } from "../cases/store.js";
|
|
11
11
|
import { cancelTurn, dispatchAsk, reconcile, waitForOutcome, } from "../turns/dispatch.js";
|
|
@@ -301,13 +301,13 @@ export class SidecarServer {
|
|
|
301
301
|
return;
|
|
302
302
|
const reviewBudget = this.#reviewBudget();
|
|
303
303
|
if (awaitingReview(s.items, reviewBudget).length === 0)
|
|
304
|
-
throw new NothingToReview(this.#unsettled(s, reviewBudget)
|
|
304
|
+
throw new NothingToReview(this.#unsettled(s, reviewBudget));
|
|
305
305
|
});
|
|
306
306
|
return { caseId, dispatched };
|
|
307
307
|
}
|
|
308
308
|
catch (err) {
|
|
309
309
|
if (err instanceof NothingToReview)
|
|
310
|
-
return { caseId, nothing: nothingToReview(err.unsettled
|
|
310
|
+
return { caseId, nothing: nothingToReview(err.unsettled) };
|
|
311
311
|
throw err;
|
|
312
312
|
}
|
|
313
313
|
});
|
|
@@ -357,7 +357,7 @@ export class SidecarServer {
|
|
|
357
357
|
const budget = this.#reviewBudget();
|
|
358
358
|
return {
|
|
359
359
|
case_id: caseId,
|
|
360
|
-
...nothingToReview(this.#unsettled(state, budget)
|
|
360
|
+
...nothingToReview(this.#unsettled(state, budget)),
|
|
361
361
|
ask_id: String(e.askId),
|
|
362
362
|
};
|
|
363
363
|
}
|
|
@@ -376,6 +376,16 @@ export class SidecarServer {
|
|
|
376
376
|
#unsettled(state, budget = this.#reviewBudget()) {
|
|
377
377
|
return unsettled(state.items).map((i) => itemSummary(i, budget));
|
|
378
378
|
}
|
|
379
|
+
/** The settled points, with who settled each: with the unsettled ones, every point's outcome. */
|
|
380
|
+
#settled(state, budget = this.#reviewBudget()) {
|
|
381
|
+
return [...state.items.values()]
|
|
382
|
+
.filter((i) => isSettled(i.status))
|
|
383
|
+
.map((i) => ({
|
|
384
|
+
ref: i.ref,
|
|
385
|
+
status: itemStatus(i, budget),
|
|
386
|
+
decided_by: i.decision && fromUser(i.decision) ? "user" : "driver",
|
|
387
|
+
}));
|
|
388
|
+
}
|
|
379
389
|
/**
|
|
380
390
|
* Records a decision or a note. Several refs record the same text once per ref: one decision may
|
|
381
391
|
* settle several points, and each point is still reviewed on its own. A bad ref records nothing;
|
|
@@ -384,6 +394,10 @@ export class SidecarServer {
|
|
|
384
394
|
async record(input) {
|
|
385
395
|
if (input.kind === "note" && input.state !== undefined)
|
|
386
396
|
throw new ToolError("state applies to decisions only");
|
|
397
|
+
if (input.kind === "note" && input.source !== undefined)
|
|
398
|
+
throw new ToolError("source applies to decisions only");
|
|
399
|
+
if (input.final && input.source !== "user")
|
|
400
|
+
throw new ToolError("final applies to the user's own answer: pass source=user");
|
|
387
401
|
const refs = input.ref === undefined
|
|
388
402
|
? [undefined]
|
|
389
403
|
: [...new Set(Array.isArray(input.ref) ? input.ref : [input.ref])];
|
|
@@ -400,7 +414,13 @@ export class SidecarServer {
|
|
|
400
414
|
throw new ToolError(`case ${caseId} has no point or ask ${ref}`);
|
|
401
415
|
return input.kind === "decision" ? item : undefined;
|
|
402
416
|
});
|
|
403
|
-
const state = input.kind === "decision"
|
|
417
|
+
const state = input.kind === "decision"
|
|
418
|
+
? {
|
|
419
|
+
state: input.state ?? "ready",
|
|
420
|
+
...(input.source ? { source: input.source } : {}),
|
|
421
|
+
...(input.final ? { final: true } : {}),
|
|
422
|
+
}
|
|
423
|
+
: {};
|
|
404
424
|
return refs.map((ref, i) => ({
|
|
405
425
|
n: append({
|
|
406
426
|
author: "driver",
|
|
@@ -412,21 +432,32 @@ export class SidecarServer {
|
|
|
412
432
|
item: items[i],
|
|
413
433
|
}));
|
|
414
434
|
});
|
|
415
|
-
const points = recorded.flatMap((r) => (r.item ? [r.item] : []));
|
|
416
435
|
const reviewBudget = this.#reviewBudget();
|
|
417
436
|
const n = Array.isArray(input.ref) ? recorded.map((r) => r.n) : recorded[0].n;
|
|
437
|
+
// Read back: a user's answer may have granted a round the item held before did not.
|
|
438
|
+
const after = input.kind === "decision" ? fold(await this.#store.read(caseId)) : undefined;
|
|
439
|
+
const points = recorded.flatMap((r) => {
|
|
440
|
+
const item = r.item && after?.items.get(r.item.ref);
|
|
441
|
+
return item ? [item] : [];
|
|
442
|
+
});
|
|
418
443
|
const many = (list, one, more) => (list.length > 1 ? more : one);
|
|
419
|
-
const
|
|
444
|
+
const are = (list) => many(list, "is", "are");
|
|
445
|
+
const refsWith = (status) => points.filter((i) => itemStatus(i, reviewBudget) === status).map((i) => i.ref);
|
|
420
446
|
const next = [];
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
next.push(`${
|
|
447
|
+
const proposed = refsWith("planned");
|
|
448
|
+
if (proposed.length > 0)
|
|
449
|
+
next.push(`${proposed.join(", ")} ${are(proposed)} proposed: the navigator reviews the approach with your next ask, or with sidecar_review. Act on ${many(proposed, "it", "them")} only once agreed.`);
|
|
450
|
+
const agreed = refsWith("agreed");
|
|
451
|
+
if (agreed.length > 0)
|
|
452
|
+
next.push(`${agreed.join(", ")} ${are(agreed)} agreed by the user: act on ${many(agreed, "it", "them")}, then record a ready decision.`);
|
|
453
|
+
const decided = refsWith("user-decided");
|
|
454
|
+
if (decided.length > 0)
|
|
455
|
+
next.push(`${decided.join(", ")} ${are(decided)} settled as the user's final decision.`);
|
|
456
|
+
// Grouped by count: a user's answer may have granted one point more rounds than another.
|
|
457
|
+
const spentBy = Map.groupBy(points.filter((i) => itemStatus(i, reviewBudget) === "exhausted"), (i) => reviewCount(i, reviewBudget));
|
|
458
|
+
for (const [count, items] of spentBy) {
|
|
459
|
+
const spent = items.map((i) => i.ref);
|
|
460
|
+
next.push(`${spent.join(", ")} ${many(spent, "has", "have")} used ${many(spent, "its", "their")} ${count}; the navigator will not review this decision. Tell the user ${many(spent, "it is", "they are")} left for them, and record the user's answer with source=user.`);
|
|
430
461
|
}
|
|
431
462
|
return next.length > 0 ? { n, next: next.join(" ") } : { n };
|
|
432
463
|
});
|
|
@@ -455,12 +486,12 @@ export class SidecarServer {
|
|
|
455
486
|
const held = [...this.#cases];
|
|
456
487
|
if (held.length === 1) {
|
|
457
488
|
const details = await this.#details(held[0]);
|
|
458
|
-
const { unsettled: _, ...brief } = details;
|
|
489
|
+
const { unsettled: _, settled: __, ...brief } = details;
|
|
459
490
|
return { ...details, cases: details.attached ? [brief] : [] };
|
|
460
491
|
}
|
|
461
492
|
const cases = [];
|
|
462
493
|
for (const caseId of held) {
|
|
463
|
-
const { unsettled: _, ...brief } = await this.#details(caseId);
|
|
494
|
+
const { unsettled: _, settled: __, ...brief } = await this.#details(caseId);
|
|
464
495
|
if (brief.attached)
|
|
465
496
|
cases.push(brief);
|
|
466
497
|
}
|
|
@@ -472,6 +503,7 @@ export class SidecarServer {
|
|
|
472
503
|
...summary(caseId, state, state.owner?.token === this.#owner.token),
|
|
473
504
|
dashboard: this.#dashboardLink(caseId),
|
|
474
505
|
unsettled: this.#unsettled(state),
|
|
506
|
+
settled: this.#settled(state),
|
|
475
507
|
};
|
|
476
508
|
}
|
|
477
509
|
async list(input) {
|
|
@@ -518,14 +550,19 @@ export class SidecarServer {
|
|
|
518
550
|
return this.#mutex.run(async () => {
|
|
519
551
|
const caseId = await this.#target(input.case_id);
|
|
520
552
|
await this.#reportDriver(caseId);
|
|
521
|
-
const { left, askId } = await this.#owned(caseId, (s, append) => {
|
|
553
|
+
const { left, settled, done, askId } = await this.#owned(caseId, (s, append) => {
|
|
522
554
|
append({
|
|
523
555
|
author: "sidecar",
|
|
524
556
|
kind: "closed",
|
|
525
557
|
reason: input.reason ?? "closed by the driver",
|
|
526
558
|
});
|
|
527
559
|
append({ author: "sidecar", kind: "detached", token: this.#owner.token, reason: "closed" });
|
|
528
|
-
return {
|
|
560
|
+
return {
|
|
561
|
+
left: this.#unsettled(s),
|
|
562
|
+
settled: this.#settled(s),
|
|
563
|
+
done: complete(s.items),
|
|
564
|
+
askId: s.inFlight?.askId,
|
|
565
|
+
};
|
|
529
566
|
});
|
|
530
567
|
this.#cases.delete(caseId);
|
|
531
568
|
// Only the ask in flight at close: after a reopen, another one may be running.
|
|
@@ -535,10 +572,14 @@ export class SidecarServer {
|
|
|
535
572
|
? {
|
|
536
573
|
case_id: caseId,
|
|
537
574
|
state: "closed",
|
|
575
|
+
complete: done,
|
|
538
576
|
unsettled: left,
|
|
539
|
-
|
|
577
|
+
settled,
|
|
578
|
+
next: done
|
|
579
|
+
? "Tell the user which deferrals the navigator confirmed: they stay listed, not settled."
|
|
580
|
+
: "The case is incomplete. Tell the user which of the navigator's points were left unsettled, and why.",
|
|
540
581
|
}
|
|
541
|
-
: { case_id: caseId, state: "closed" };
|
|
582
|
+
: { case_id: caseId, state: "closed", complete: true, settled };
|
|
542
583
|
});
|
|
543
584
|
}
|
|
544
585
|
/** The driver session ended: release every case. A running turn continues; the next attach finds its result. */
|
|
@@ -654,6 +695,7 @@ function summary(caseId, s, attached) {
|
|
|
654
695
|
navigator: String(s.opened.navigator ?? ""),
|
|
655
696
|
created: s.opened.ts,
|
|
656
697
|
in_flight_ask: s.inFlight?.askId ?? null,
|
|
698
|
+
complete: complete(s.items),
|
|
657
699
|
attached,
|
|
658
700
|
};
|
|
659
701
|
}
|
|
@@ -696,23 +738,31 @@ function itemSummary(i, budget) {
|
|
|
696
738
|
ref: i.ref,
|
|
697
739
|
kind: i.kind,
|
|
698
740
|
status: itemStatus(i, budget),
|
|
741
|
+
stage: itemStage(i),
|
|
699
742
|
severity: i.severity ?? null,
|
|
700
743
|
point: i.point,
|
|
701
|
-
reviews_used: i
|
|
744
|
+
reviews_used: reviewsUsed(i),
|
|
745
|
+
...(i.decision && fromUser(i.decision) ? { decided_by: "user" } : {}),
|
|
702
746
|
};
|
|
703
747
|
}
|
|
704
748
|
function renderOpinion(e, state, budget) {
|
|
705
749
|
const askId = String(e.askId);
|
|
706
750
|
const isReview = state.asks.get(askId)?.event.review === true;
|
|
707
751
|
const flagIds = flagsOf(e).map((f) => f.id);
|
|
708
|
-
const targets = reviewTargetsOf(e);
|
|
752
|
+
const targets = [...reviewTargetsOf(e), ...agreementTargetsOf(e)];
|
|
709
753
|
// Each review with whether it applied: a review of a decision since superseded is history only.
|
|
710
|
-
const
|
|
754
|
+
const tagged = [
|
|
755
|
+
...reviewsOf(e).map((r) => ({ r, stage: "done" })),
|
|
756
|
+
...agreementsOf(e).map((r) => ({ r, stage: "agreement" })),
|
|
757
|
+
];
|
|
758
|
+
const reviews = tagged.map(({ r, stage }) => ({
|
|
711
759
|
ref: r.ref,
|
|
760
|
+
stage,
|
|
712
761
|
status: r.status,
|
|
713
762
|
body: r.body,
|
|
714
763
|
decision_n: r.decisionN,
|
|
715
|
-
applied: state.items.get(r.ref)?.reviews.find((h) => h.opinionN === e.n
|
|
764
|
+
applied: state.items.get(r.ref)?.reviews.find((h) => h.opinionN === e.n && h.stage === stage)
|
|
765
|
+
?.applied ?? false,
|
|
716
766
|
}));
|
|
717
767
|
// A replayed result may predate the driver's latest decision: only a review of that one asks for action.
|
|
718
768
|
const current = (r) => r.applied && state.items.get(r.ref)?.decision?.n === r.decision_n;
|
|
@@ -721,15 +771,21 @@ function renderOpinion(e, state, budget) {
|
|
|
721
771
|
for (const r of reviews.filter((r) => current(r) && r.status === "held")) {
|
|
722
772
|
next.push(`Tell the user now: the navigator holds its point on ${r.ref} against your decision; its reason is in reviews. The user may decide.`);
|
|
723
773
|
}
|
|
774
|
+
for (const r of reviews.filter((r) => current(r) && r.stage === "agreement" && r.status === "confirmed")) {
|
|
775
|
+
next.push(`The navigator agreed to your proposal on ${r.ref}: act on it once every point the action touches is agreed, then record a ready decision with ref=${r.ref}.`);
|
|
776
|
+
}
|
|
724
777
|
// A reopened point with its reviews spent cannot be settled by another decision: it escalates.
|
|
725
778
|
const now = (ref) => {
|
|
726
779
|
const item = state.items.get(ref);
|
|
727
780
|
return item ? itemStatus(item, budget) : undefined;
|
|
728
781
|
};
|
|
782
|
+
const used = (ref) => reviewCount(state.items.get(ref), budget);
|
|
729
783
|
for (const r of reviews.filter((r) => current(r) && r.status === "reopened")) {
|
|
730
784
|
next.push(now(r.ref) === "exhausted"
|
|
731
|
-
? `The navigator reopened ${r.ref}, and it has used its ${
|
|
732
|
-
:
|
|
785
|
+
? `The navigator reopened ${r.ref}, and it has used its ${used(r.ref)}: it is left for the user. Tell the user now, with both positions, and record the user's answer with source=user; do not decide it again yourself.`
|
|
786
|
+
: r.stage === "agreement"
|
|
787
|
+
? `The navigator reopened your proposal on ${r.ref}; what is missing is in reviews. Do not act on it yet: record a revised proposal with ref=${r.ref}, or leave it for the user.`
|
|
788
|
+
: `The navigator reopened ${r.ref}; what is missing is in reviews. Record a new decision with ref=${r.ref}, or leave it for the user.`);
|
|
733
789
|
}
|
|
734
790
|
// A newer decision may have been recorded during the turn: say what each point awaits now.
|
|
735
791
|
const stale = reviews.filter((r) => !current(r)).map((r) => r.ref);
|
|
@@ -757,7 +813,7 @@ function renderOpinion(e, state, budget) {
|
|
|
757
813
|
next.push(awaits(left, state, budget));
|
|
758
814
|
const waiting = awaitingReview(state.items, budget).map((i) => i.ref);
|
|
759
815
|
if (waiting.length > 0) {
|
|
760
|
-
next.push(`Awaiting the navigator
|
|
816
|
+
next.push(`Awaiting the navigator: ${waiting.join(", ")}. They ride along with your next ask, or call sidecar_review; act on a proposal only once agreed.`);
|
|
761
817
|
}
|
|
762
818
|
return {
|
|
763
819
|
status: "opinion",
|
|
@@ -771,7 +827,6 @@ function renderOpinion(e, state, budget) {
|
|
|
771
827
|
next: next.join(" "),
|
|
772
828
|
};
|
|
773
829
|
}
|
|
774
|
-
const reviewCount = (budget) => `${budget} ${budget === 1 ? "review" : "reviews"}`;
|
|
775
830
|
/** Where each point stands now, for a review that did not settle it. */
|
|
776
831
|
function awaits(refs, state, budget) {
|
|
777
832
|
return (refs
|
|
@@ -779,41 +834,39 @@ function awaits(refs, state, budget) {
|
|
|
779
834
|
const item = state.items.get(ref);
|
|
780
835
|
const status = item ? itemStatus(item, budget) : undefined;
|
|
781
836
|
if (status === "exhausted")
|
|
782
|
-
return `${ref} has used its ${reviewCount(budget)} and is left for the user: tell the user now`;
|
|
837
|
+
return `${ref} has used its ${reviewCount(item, budget)} and is left for the user: tell the user now`;
|
|
783
838
|
if (status === "addressed")
|
|
784
839
|
return `${ref} still awaits review`;
|
|
785
840
|
if (status === "planned")
|
|
786
|
-
return
|
|
787
|
-
|
|
788
|
-
|
|
841
|
+
return `${ref} is proposed and still awaits agreement`;
|
|
842
|
+
if (status === "agreed")
|
|
843
|
+
return `${ref} is agreed: act on it, then record a ready decision`;
|
|
789
844
|
return `${ref} is ${status ?? "unknown"}`;
|
|
790
845
|
})
|
|
791
846
|
.join("; ") + ".");
|
|
792
847
|
}
|
|
848
|
+
/** "2 reviews": what the item's current stage may use, a round the user's answer granted included. */
|
|
849
|
+
function reviewCount(item, budget) {
|
|
850
|
+
const n = reviewAllowance(item, budget);
|
|
851
|
+
return `${n} ${n === 1 ? "review" : "reviews"}`;
|
|
852
|
+
}
|
|
793
853
|
/**
|
|
794
854
|
* A review with nothing to do, and why, when the driver may not know: points left for the user,
|
|
795
|
-
* which no review settles, and
|
|
855
|
+
* which no review settles, and agreed points, which wait for the driver's action.
|
|
796
856
|
*/
|
|
797
|
-
function nothingToReview(left
|
|
857
|
+
function nothingToReview(left) {
|
|
798
858
|
const exhausted = left.filter((i) => i.status === "exhausted").map((i) => i.ref);
|
|
799
|
-
const
|
|
800
|
-
const reviewable = planned.filter((i) => i.reviews_used < budget).map((i) => i.ref);
|
|
801
|
-
const spent = planned.filter((i) => i.reviews_used >= budget).map((i) => i.ref);
|
|
859
|
+
const agreed = left.filter((i) => i.status === "agreed").map((i) => i.ref);
|
|
802
860
|
const are = (refs) => (refs.length > 1 ? "are" : "is");
|
|
803
861
|
const next = [
|
|
804
862
|
...(exhausted.length > 0
|
|
805
863
|
? [
|
|
806
|
-
`${exhausted.join(", ")} ${are(exhausted)} left for the user: no review can settle ${exhausted.length > 1 ? "them" : "it"}. Tell the user now.`,
|
|
807
|
-
]
|
|
808
|
-
: []),
|
|
809
|
-
...(reviewable.length > 0
|
|
810
|
-
? [
|
|
811
|
-
`${reviewable.join(", ")} ${are(reviewable)} planned: record a ready decision once the change exists, then review.`,
|
|
864
|
+
`${exhausted.join(", ")} ${are(exhausted)} left for the user: no review can settle ${exhausted.length > 1 ? "them" : "it"}. Tell the user now, and record the user's answer with source=user.`,
|
|
812
865
|
]
|
|
813
866
|
: []),
|
|
814
|
-
...(
|
|
867
|
+
...(agreed.length > 0
|
|
815
868
|
? [
|
|
816
|
-
`${
|
|
869
|
+
`${agreed.join(", ")} ${are(agreed)} agreed: act on ${agreed.length > 1 ? "them" : "it"}, record a ready decision, then review.`,
|
|
817
870
|
]
|
|
818
871
|
: []),
|
|
819
872
|
];
|
|
@@ -826,10 +879,8 @@ function nothingToReview(left, budget) {
|
|
|
826
879
|
/** Thrown inside the dispatch transaction when a review turn would have nothing to review. */
|
|
827
880
|
class NothingToReview extends Error {
|
|
828
881
|
unsettled;
|
|
829
|
-
|
|
830
|
-
constructor(unsettled, budget) {
|
|
882
|
+
constructor(unsettled) {
|
|
831
883
|
super("nothing awaits review");
|
|
832
884
|
this.unsettled = unsettled;
|
|
833
|
-
this.budget = budget;
|
|
834
885
|
}
|
|
835
886
|
}
|
package/dist/src/mcp/tools.js
CHANGED
|
@@ -22,16 +22,18 @@ When to use it
|
|
|
22
22
|
The loop
|
|
23
23
|
1. sidecar_open with a brief that stands alone. Share the dashboard link with the user once.
|
|
24
24
|
2. sidecar_ask one question at a time. Do not act on it until the outcome arrives.
|
|
25
|
-
3. Decide every point the result's next asks you to decide, with sidecar_record kind=decision: what you accept, reject or defer, and why. Never drop a point silently.
|
|
26
|
-
4.
|
|
27
|
-
5.
|
|
25
|
+
3. Decide every point the result's next asks you to decide, with sidecar_record kind=decision: what you accept, reject or defer, and why. Never drop a point silently. The navigator is a peer, not an authority. Check each point's evidence and premise. Accept when they hold; reject or narrow, with your reason, when they do not.
|
|
26
|
+
4. A point that needs an action (a change, a ticket, a document) gets a proposal first: state=planned. Act on it only once the navigator agrees, then record a ready decision. An action that touches several points waits until each is agreed; a changed proposal needs agreement again. A rejection or an explanation is ready at once.
|
|
27
|
+
5. The navigator reviews proposals and decisions with your next ask, or with sidecar_review. A point is settled only when the navigator confirms your ready decision. On reopened, decide again or leave the point for the user. Each stage of a point gets a limited number of reviews; past that, the point is left for the user: do not decide it again yourself.
|
|
28
|
+
6. Close the case with sidecar_close when the work is done; before that, call sidecar_review if decisions still await the navigator. When the same work continues later, a review round on the same PR included, sidecar_attach the case again, closed or not; a new problem gets a new case.
|
|
28
29
|
|
|
29
30
|
Tell the user
|
|
30
31
|
- On failed: "navigator unavailable: <outcome>, proceeding". Then continue without the opinion, and record your own conclusion as a note with ref=<ask id>.
|
|
31
32
|
- On held: the navigator stands by a point you rejected. Tell the user at once, with both positions, so they can intervene; do not argue it further.
|
|
32
33
|
- On a point left for the user: you and the navigator did not settle it within its reviews. Tell the user at once, with both positions, as for held.
|
|
34
|
+
- Record the user's own answer on such a point as a decision with source=user, and final=true only if the user says so. The navigator reviews each new answer once.
|
|
33
35
|
- The confirmed deferrals (they stay listed, not settled), and the points sidecar_close lists as unsettled.
|
|
34
|
-
- In your report, where the navigator disagreed with you and what you did about it. Report the case state accurately, for example "design agreed; implementation pending": do not say the navigator agrees while its points are open,
|
|
36
|
+
- In your report, where the navigator disagreed with you and what you did about it. Report the case state accurately, for example "design agreed; implementation pending": do not say the navigator agrees while its points are open, proposed, agreed but not acted on, or reopened.`;
|
|
35
37
|
const text = z.string().trim().min(1, "must be a non-empty string");
|
|
36
38
|
const upTo = (max) => text.max(max, `must be at most ${max} characters`);
|
|
37
39
|
const caseId = text
|
|
@@ -117,7 +119,7 @@ export function createMcpServer(server) {
|
|
|
117
119
|
},
|
|
118
120
|
}, (args) => reply(server.wait(defined(args))));
|
|
119
121
|
mcp.registerTool("sidecar_record", {
|
|
120
|
-
description: "Record a decision or a note in the case. Starts no turn. The navigator sees it with the next ask. A decision needs ref: a point the result's next names, or an answered ask. Each point an opinion raises has its own flag id, <ask id>.<n> (e.g. a1b2c3d4.1), and gets its own decision; an opinion that raises none is decided as one point, with ref=<ask id>. A review result needs decisions only on the points it reopens and on its new points. The opinion's limits are not points: weigh them when you rely on the opinion. A decision does not settle a point by itself: the navigator reviews a ready or deferred decision and confirms, reopens, or holds the point. Each point gets a limited number of reviews; past that, it is left for the user. A note may ref any point or ask.",
|
|
122
|
+
description: "Record a decision or a note in the case. Starts no turn. The navigator sees it with the next ask. A decision needs ref: a point the result's next names, or an answered ask. Each point an opinion raises has its own flag id, <ask id>.<n> (e.g. a1b2c3d4.1), and gets its own decision; an opinion that raises none is decided as one point, with ref=<ask id>. A review result needs decisions only on the points it reopens and on its new points. The opinion's limits are not points: weigh them when you rely on the opinion. A decision does not settle a point by itself: the navigator agrees to a planned decision, or reopens it, before you act; and it reviews a ready or deferred decision and confirms, reopens, or holds the point. Each stage of a point gets a limited number of reviews; past that, it is left for the user, whose answer you record with source=user. A note may ref any point or ask.",
|
|
121
123
|
inputSchema: {
|
|
122
124
|
kind: z.enum(["decision", "note"]),
|
|
123
125
|
body: upTo(RECORD_MAX).describe("For a decision: what you accept or reject, and why. When you disagree with the navigator, say so and give your reason."),
|
|
@@ -128,7 +130,15 @@ export function createMcpServer(server) {
|
|
|
128
130
|
state: z
|
|
129
131
|
.enum(DECISION_STATES)
|
|
130
132
|
.optional()
|
|
131
|
-
.describe("Decisions only. ready (default): the resolution exists — the change is in the workspace, or you reject or explain the point. planned: you accept
|
|
133
|
+
.describe("Decisions only. ready (default): the resolution exists — the change is in the workspace, or you reject or explain the point. planned: a proposal — you accept the point and say how you will resolve it, before you act; the navigator agrees to it or reopens it. Act once it is agreed, then record a ready decision on the same ref. deferred: the point moves out of this case, for later work or for the user; say why."),
|
|
134
|
+
source: z
|
|
135
|
+
.literal("user")
|
|
136
|
+
.optional()
|
|
137
|
+
.describe("Decisions only. user: the body records the user's own answer on the point, typically one left for the user. Each new answer gets one review from the navigator. Never set it for your own conclusion."),
|
|
138
|
+
final: z
|
|
139
|
+
.boolean()
|
|
140
|
+
.optional()
|
|
141
|
+
.describe("With source=user only, and only when the user says so: the user's answer ends the dispute without a review. On a planned decision it agrees to the proposal; on a ready one it settles the point."),
|
|
132
142
|
case_id: caseId,
|
|
133
143
|
},
|
|
134
144
|
}, (args) => reply(server.record(defined(args))));
|
package/dist/src/turns/prompt.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DEFAULTS } from "../config.js";
|
|
2
|
-
import { decisionState, itemStatus, unsettled } from "../cases/items.js";
|
|
2
|
+
import { decisionState, fromUser, itemStage, itemStatus, unsettled, } from "../cases/items.js";
|
|
3
3
|
const ROLE = `You are the navigator in a sidecar case. The driver, another coding agent, works on a task in this workspace and asks you for an independent opinion, one question at a time. You are read-only: you read and search; you never change anything.
|
|
4
4
|
|
|
5
5
|
How to work
|
|
6
6
|
- Check the driver's claim against the source yourself. Re-read every file:line the driver cites; do not trust its summary.
|
|
7
|
-
- Your value is
|
|
7
|
+
- Your value is a checked conclusion. Look for the case where the claim fails before you agree; agree when it holds. Agreement and disagreement both need reasons. Do not restate the driver's position.
|
|
8
8
|
- Answer the question that was asked. Put each point into its own entry of flags: the driver accepts or rejects each point on its own, and you review each decision.
|
|
9
9
|
- Separate what you read from what you infer, and mark inference as inference. An opinion that cites nothing will be discounted.
|
|
10
10
|
|
|
@@ -17,7 +17,11 @@ Reply with the JSON object the output schema requires:
|
|
|
17
17
|
- "confirmed": the decision settles your point — the fix is in the code (cite it), or the driver's reason holds.
|
|
18
18
|
- "reopened": it does not settle it; say what is still missing.
|
|
19
19
|
- "held": the driver rejected your point and you still stand by it. Say why, briefly; the user decides from here.
|
|
20
|
+
A proposal is how the driver plans to resolve your point, before it acts. Confirm it when the approach resolves your concern; reopen it and say what the approach misses. Check the approach: the action does not exist yet.
|
|
21
|
+
A decision shown with an agreed proposal is the action on it. Confirm it only when the action matches that proposal and resolves your point.
|
|
22
|
+
The user's answer is the user's own word on a point you and the driver did not settle. Check it as you check the driver's.
|
|
20
23
|
A decision marked "deferred" moves the point out of this case. Confirm it when that is reasonable — the point stays listed as deferred, not settled — or hold it when the point must be resolved here.
|
|
24
|
+
The driver is a peer. Weigh its reason on the merits: confirm when it holds, even if it rejects your point, and withdraw or narrow your point when its counter-argument holds. Hold only with evidence its reason does not answer.
|
|
21
25
|
A point or decision marked "…(truncated)" is shown in part. Confirm only what the shown text lets you check; otherwise reopen it and say what is missing.`;
|
|
22
26
|
/** Why a review turn ends without spawning: an earlier turn settled every point it was for. */
|
|
23
27
|
export const NOTHING_AWAITED = "nothing awaited review when the turn started";
|
|
@@ -259,8 +263,19 @@ function renderItem(item, text) {
|
|
|
259
263
|
: item.kind === "flag"
|
|
260
264
|
? `- [${item.ref}] your point${severity}: ${capped(item.point)}`
|
|
261
265
|
: `- [${item.ref}] your opinion${severity} on the ask "${capped(item.question ?? "")}": ${capped(item.point)}`;
|
|
262
|
-
const
|
|
263
|
-
|
|
266
|
+
const decision = item.decision;
|
|
267
|
+
const deferred = decision && decisionState(decision) === "deferred" ? " (deferred)" : "";
|
|
268
|
+
const user = decision !== undefined && fromUser(decision);
|
|
269
|
+
const label = itemStage(item) === "agreement"
|
|
270
|
+
? user
|
|
271
|
+
? "The user's answer, a proposal not acted on yet"
|
|
272
|
+
: "The driver's proposal, not acted on yet"
|
|
273
|
+
: `${user ? "The user's answer" : "The driver's decision"}${deferred}`;
|
|
274
|
+
// The action is checked against what was agreed, so the agreed proposal travels with it.
|
|
275
|
+
const agreed = itemStage(item) === "done" && item.agreement
|
|
276
|
+
? `\n The proposal ${item.agreement.by === "user" ? "the user agreed to as final" : "you agreed to"}: ${capped(String(item.agreement.decision.body))}`
|
|
277
|
+
: "";
|
|
278
|
+
return `${head}${agreed}\n ${label}: ${capped(String(decision?.body))}`;
|
|
264
279
|
}
|
|
265
280
|
/** The review section. Without `recalled`, every point is shown in full: the size a re-brief needs. */
|
|
266
281
|
function renderReview(items, recalled) {
|
package/dist/src/turns/runner.js
CHANGED
|
@@ -12,7 +12,7 @@ import { loadConfig } from "../config.js";
|
|
|
12
12
|
import { SERVER_VERSION_ENV } from "./dispatch.js";
|
|
13
13
|
import { testMs } from "./knobs.js";
|
|
14
14
|
import { buildPrompt, fitReview, NOTHING_AWAITED, NOTHING_TO_REVIEW, reviewRoom, } from "./prompt.js";
|
|
15
|
-
import { acceptReviews, awaitingReview } from "../cases/items.js";
|
|
15
|
+
import { acceptReviews, awaitingReview, itemStage } from "../cases/items.js";
|
|
16
16
|
import { fold } from "../cases/state.js";
|
|
17
17
|
import { defaultStoreOptions, Store } from "../cases/store.js";
|
|
18
18
|
// Executes one navigator turn and records its result. Started detached by the server, so it leads
|
|
@@ -71,7 +71,10 @@ const claim = await store.transact(caseId, (events, append) => {
|
|
|
71
71
|
// newer one recorded while the turn runs. Sized for a re-brief, so the targets fit if the resume
|
|
72
72
|
// turns into one. The room alone limits how many: a backlog is reviewed in as few turns as fit.
|
|
73
73
|
const review = fitReview(awaitingReview(state.items, config.reviewBudget), reviewRoom(state, ask, config.seedBound, git));
|
|
74
|
-
|
|
74
|
+
// One reply lists both kinds; each target's stage, fixed here, says which field its review lands in.
|
|
75
|
+
const targetOf = (i) => ({ ref: i.ref, decisionN: i.decision.n });
|
|
76
|
+
const reviewTargets = review.filter((i) => itemStage(i) === "done").map(targetOf);
|
|
77
|
+
const agreementTargets = review.filter((i) => itemStage(i) === "agreement").map(targetOf);
|
|
75
78
|
// A review turn whose points were all settled by an earlier turn has nothing to do: no spawn.
|
|
76
79
|
if (ask.event.review && review.length === 0) {
|
|
77
80
|
append({
|
|
@@ -96,13 +99,14 @@ const claim = await store.transact(caseId, (events, append) => {
|
|
|
96
99
|
hardDeadline,
|
|
97
100
|
watermark: state.watermark,
|
|
98
101
|
reviewTargets,
|
|
102
|
+
agreementTargets,
|
|
99
103
|
});
|
|
100
|
-
return { attemptId, hardDeadline, state, ask, review, reviewTargets, git };
|
|
104
|
+
return { attemptId, hardDeadline, state, ask, review, reviewTargets, agreementTargets, git };
|
|
101
105
|
});
|
|
102
106
|
if (!claim)
|
|
103
107
|
process.exit(0);
|
|
104
108
|
failpoint("runner.after-turn-started");
|
|
105
|
-
const { attemptId, hardDeadline, state, ask, review, reviewTargets, git } = claim;
|
|
109
|
+
const { attemptId, hardDeadline, state, ask, review, reviewTargets, agreementTargets, git } = claim;
|
|
106
110
|
const navigator = getNavigator(String(state.opened.navigator));
|
|
107
111
|
const opts = {
|
|
108
112
|
...(state.opened.model ? { model: String(state.opened.model) } : {}),
|
|
@@ -179,8 +183,10 @@ await store.transact(caseId, (events, append) => {
|
|
|
179
183
|
...rest,
|
|
180
184
|
flags: flags.map((flag, i) => ({ id: `${askId}.${i + 1}`, ...flag })),
|
|
181
185
|
reviews: acceptReviews(reviews, reviewTargets),
|
|
186
|
+
agreements: acceptReviews(reviews, agreementTargets),
|
|
182
187
|
// What the turn was shown: the review budget counts it, reviewed or not.
|
|
183
188
|
reviewTargets,
|
|
189
|
+
agreementTargets,
|
|
184
190
|
invocations,
|
|
185
191
|
});
|
|
186
192
|
}
|