wicked-crew 0.17.0 → 0.17.1
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 +27 -9
- package/dist/api/chat-jobs.d.ts +163 -0
- package/dist/api/chat-jobs.d.ts.map +1 -0
- package/dist/api/chat-jobs.js +767 -0
- package/dist/api/chat-jobs.js.map +1 -0
- package/dist/api/chat-proposals.d.ts +149 -3
- package/dist/api/chat-proposals.d.ts.map +1 -1
- package/dist/api/chat-proposals.js +831 -11
- package/dist/api/chat-proposals.js.map +1 -1
- package/dist/api/delivery-assurance.d.ts.map +1 -1
- package/dist/api/delivery-assurance.js +5 -2
- package/dist/api/delivery-assurance.js.map +1 -1
- package/dist/api/product.d.ts +79 -2
- package/dist/api/product.d.ts.map +1 -1
- package/dist/api/product.js +145 -66
- package/dist/api/product.js.map +1 -1
- package/dist/api/recording.d.ts +60 -3
- package/dist/api/recording.d.ts.map +1 -1
- package/dist/api/recording.js +51 -38
- package/dist/api/recording.js.map +1 -1
- package/dist/api/routes.d.ts +76 -7
- package/dist/api/routes.d.ts.map +1 -1
- package/dist/api/routes.js +697 -51
- package/dist/api/routes.js.map +1 -1
- package/dist/api/run-timing-index.d.ts +12 -1
- package/dist/api/run-timing-index.d.ts.map +1 -1
- package/dist/api/run-timing-index.js +35 -0
- package/dist/api/run-timing-index.js.map +1 -1
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +3 -1
- package/dist/api/server.js.map +1 -1
- package/dist/apps/exec/texts.d.ts +1 -1
- package/dist/core/adapter.d.ts +11 -1
- package/dist/core/adapter.d.ts.map +1 -1
- package/dist/core/adapter.js +29 -1
- package/dist/core/adapter.js.map +1 -1
- package/dist/core/builtin-catalog.d.ts.map +1 -1
- package/dist/core/builtin-catalog.js +2 -0
- package/dist/core/builtin-catalog.js.map +1 -1
- package/dist/core/deliver-text.d.ts +42 -6
- package/dist/core/deliver-text.d.ts.map +1 -1
- package/dist/core/deliver-text.js +204 -27
- package/dist/core/deliver-text.js.map +1 -1
- package/dist/core/deliver.d.ts.map +1 -1
- package/dist/core/deliver.js +28 -7
- package/dist/core/deliver.js.map +1 -1
- package/dist/core/qe-acceptance-setting.d.ts.map +1 -1
- package/dist/core/qe-acceptance-setting.js +6 -0
- package/dist/core/qe-acceptance-setting.js.map +1 -1
- package/dist/team/routes.d.ts +10 -0
- package/dist/team/routes.d.ts.map +1 -1
- package/dist/team/routes.js +27 -0
- package/dist/team/routes.js.map +1 -1
- package/dist/workflow-catalog/build-v2.d.ts +90 -0
- package/dist/workflow-catalog/build-v2.d.ts.map +1 -0
- package/dist/workflow-catalog/build-v2.js +527 -0
- package/dist/workflow-catalog/build-v2.js.map +1 -0
- package/dist/workflow-catalog/catalog-data-v2.d.ts +12 -0
- package/dist/workflow-catalog/catalog-data-v2.d.ts.map +1 -0
- package/dist/workflow-catalog/catalog-data-v2.js +2582 -0
- package/dist/workflow-catalog/catalog-data-v2.js.map +1 -0
- package/dist/workflow-catalog/seeds-v2.d.ts +91 -0
- package/dist/workflow-catalog/seeds-v2.d.ts.map +1 -0
- package/dist/workflow-catalog/seeds-v2.js +2 -0
- package/dist/workflow-catalog/seeds-v2.js.map +1 -0
- package/dist/workflow-catalog/shape.d.ts +97 -0
- package/dist/workflow-catalog/shape.d.ts.map +1 -0
- package/dist/workflow-catalog/shape.js +97 -0
- package/dist/workflow-catalog/shape.js.map +1 -0
- package/endpoint-manifest.json +33 -3
- package/package.json +23 -4
|
@@ -0,0 +1,767 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JOB PROPOSALS: the conversation's facts (DES-CATALOG-002 §2.4, §4.6).
|
|
3
|
+
*
|
|
4
|
+
* A job proposal is work in a chat: a v2 card (and option) whose resolved launch is a run, a compose or a demo. Every
|
|
5
|
+
* fact on it is crew's, computed here from crew's own resolution (`workflow-catalog/build-v2.ts`), never from a seat's
|
|
6
|
+
* words: the card and option, the repository and project from the chat's scope, the seats from the roster, the checks
|
|
7
|
+
* from the composed plan, the time, the sentence wicked says ("what Start runs"), its tokens and their swaps, at most two
|
|
8
|
+
* suggestions, the one question when something is missing, and the starting shape.
|
|
9
|
+
*
|
|
10
|
+
* A correction is a {@link ProposalRevision} merged by fixed rules ({@link mergeRevision}). The one rule that guards
|
|
11
|
+
* assurance is step 7: a result with fewer checks than its parent is never written from a seat's block — it becomes a
|
|
12
|
+
* question naming what is lost, whose lossy choice only a person's press applies (`confirmLoss`, person route only).
|
|
13
|
+
* A QE skip from a seat counts only when its reason appears, unquoted and not reported, in the person's own message
|
|
14
|
+
* that turn answers.
|
|
15
|
+
*/
|
|
16
|
+
import { createHash } from 'node:crypto';
|
|
17
|
+
import { CATALOG_V2_CARDS } from '../workflow-catalog/catalog-data-v2.js';
|
|
18
|
+
import { resolveOption } from '../workflow-catalog/build-v2.js';
|
|
19
|
+
import { DEPTH_LINES } from '../workflow-catalog/shape.js';
|
|
20
|
+
// ── words ──────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
21
|
+
/** How the sentence names each card and option ("I'll run this as **an upgrade** of …"): one entry per card. */
|
|
22
|
+
const NOUNS = {
|
|
23
|
+
'plan-it': { _: 'a plan' },
|
|
24
|
+
feature: { _: 'a feature' },
|
|
25
|
+
bug: { _: 'a bug fix' },
|
|
26
|
+
migrate: { move: 'a move', 'in-place': 'an in-place migration', upgrade: 'an upgrade' },
|
|
27
|
+
refactor: { refactor: 'a refactor', polish: 'a polish' },
|
|
28
|
+
release: { _: 'a release' },
|
|
29
|
+
'start-new': { cli: 'a new CLI', service: 'a new service', library: 'a new library', 'mcp-server': 'a new MCP server' },
|
|
30
|
+
'studio-plugin': { editor: 'an editor plugin', phase: 'a phase plugin' },
|
|
31
|
+
'plan-tests': { _: 'a test plan' },
|
|
32
|
+
'test-analysis': { _: 'a test analysis' },
|
|
33
|
+
'write-tests': { _: 'new tests' },
|
|
34
|
+
'suite-health': { flaky: 'a flaky-test cleanup', weak: 'a weak-test cleanup', snapshots: 'a snapshot cleanup', slow: 'a slow-test cleanup' },
|
|
35
|
+
incident: { _: 'an incident investigation' },
|
|
36
|
+
reconstruct: { _: 'a reconstruction of what happened' },
|
|
37
|
+
'analyze-codebase': { overview: 'an overview of how it works', domain: 'a domain map', docs: 'a docs-versus-code check' },
|
|
38
|
+
'map-requirements': { _: 'a requirements map' },
|
|
39
|
+
'review-change': { _: 'a review of the change' },
|
|
40
|
+
risk: { _: 'a risk analysis' },
|
|
41
|
+
security: { security: 'a security review', privacy: 'a privacy review', compliance: 'a compliance review' },
|
|
42
|
+
decide: { _: 'a decision record' },
|
|
43
|
+
document: { document: 'a document', presentation: 'a presentation', 'repo-docs': 'docs in the repo' },
|
|
44
|
+
'interactive-page': { _: 'an interactive page' },
|
|
45
|
+
'demo-video': { _: 'a demo video' },
|
|
46
|
+
communicate: { narrative: 'a narrative', 'meeting-prep': 'meeting prep', 'demo-script': 'a demo script', 'status-update': 'a status update', message: 'a message' },
|
|
47
|
+
backlog: { epics: 'epics', stories: 'stories', tasks: 'tasks' },
|
|
48
|
+
'operating-model': { _: 'roles and an operating model' },
|
|
49
|
+
'analyze-runs': { _: 'an analysis of your runs' },
|
|
50
|
+
'review-recent-work': { _: 'a review of recent work' },
|
|
51
|
+
propose: { rules: 'proposed rules', memories: 'proposed memories', knowledge: 'proposed knowledge' },
|
|
52
|
+
'evaluate-rules': { _: 'a rules evaluation' },
|
|
53
|
+
retro: { _: 'a retro' },
|
|
54
|
+
};
|
|
55
|
+
/** "an upgrade", or the card's title in lower case for a card the table does not name. */
|
|
56
|
+
export function nounOf(card, option) {
|
|
57
|
+
const n = NOUNS[card.id];
|
|
58
|
+
const hit = n?.[option ?? '_'] ?? n?.['_'];
|
|
59
|
+
if (hit !== undefined)
|
|
60
|
+
return hit;
|
|
61
|
+
const opt = card.variant?.options.find((o) => o.id === option);
|
|
62
|
+
return `${card.title.toLowerCase()}${opt !== undefined ? ` (${opt.title.toLowerCase()})` : ''}`;
|
|
63
|
+
}
|
|
64
|
+
const GATE_WORDS = {
|
|
65
|
+
'qe-acceptance': 'QE acceptance',
|
|
66
|
+
parity: 'a parity check',
|
|
67
|
+
'cited-findings': 'cited findings, each re-checked',
|
|
68
|
+
'fidelity-to-source': 'a check against its sources',
|
|
69
|
+
'proposal-only': 'your approval of everything it proposes',
|
|
70
|
+
'evidence-floor': 'the evidence floor',
|
|
71
|
+
'install-consent': 'your consent before it installs',
|
|
72
|
+
walkthrough: 'a walkthrough review',
|
|
73
|
+
pick: 'your pick',
|
|
74
|
+
'draft-floor': 'the draft floor',
|
|
75
|
+
'traces-to-requirements': 'a trace to each requirement',
|
|
76
|
+
review: 'a review on another seat',
|
|
77
|
+
};
|
|
78
|
+
const list = (xs) => xs.length <= 1 ? (xs[0] ?? '') : xs.length === 2 ? `${xs[0]} and ${xs[1]}` : `${xs.slice(0, -1).join(', ')} and ${xs[xs.length - 1]}`;
|
|
79
|
+
export const checksLabel = (gate) => (gate.length === 0 ? 'its own steps' : list(gate.map((g) => GATE_WORDS[g])));
|
|
80
|
+
const humanStep = (id) => {
|
|
81
|
+
const words = id.replace(/[-_]+/g, ' ').trim();
|
|
82
|
+
return words === '' ? id : `${words[0].toUpperCase()}${words.slice(1)}`;
|
|
83
|
+
};
|
|
84
|
+
/** Workflows whose launch picks its own seat (the run review's preparer, the default evals' Tool step): the proposal's
|
|
85
|
+
* seats are not what runs there, so they are neither shown as choosable nor sent (codex r2). */
|
|
86
|
+
export const SELF_SEATED = new Set(['review-recent-work', 'run-evals']);
|
|
87
|
+
export class JobRefusal extends Error {
|
|
88
|
+
code;
|
|
89
|
+
status;
|
|
90
|
+
constructor(code, message, status = 400) {
|
|
91
|
+
super(message);
|
|
92
|
+
this.code = code;
|
|
93
|
+
this.status = status;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** The kind a resolved option proposes as: a run, a compose or a demo is a job; a document is an artifact create. */
|
|
97
|
+
export function proposalKindOf(r) {
|
|
98
|
+
const k = r.resolved.launch.kind;
|
|
99
|
+
if (k === 'run' || k === 'compose' || k === 'demo')
|
|
100
|
+
return 'job';
|
|
101
|
+
if (k === 'document')
|
|
102
|
+
return 'create';
|
|
103
|
+
return r.resolved.status === 'coming_soon' ? 'job' : 'none';
|
|
104
|
+
}
|
|
105
|
+
/** The seats a card needs to check its own work (Q31: words name who builds; the reviewer and judge stay). */
|
|
106
|
+
export function seatsNeeded(r) {
|
|
107
|
+
return 1 + (r.resolved.seats.distinctEvaluator ? 1 : 0) + (r.resolved.seats.distinctJudge ? 1 : 0);
|
|
108
|
+
}
|
|
109
|
+
function seatsOf(facts, ctx, r) {
|
|
110
|
+
const can = new Set(ctx.roster.map((s) => s.key));
|
|
111
|
+
const name = (k) => ctx.roster.find((s) => s.key === k)?.name ?? k;
|
|
112
|
+
const ordered = [...new Set([facts.lead, ctx.chat.lead, ...ctx.chat.seats, ...ctx.roster.map((s) => s.key)].filter((k) => k !== null && can.has(k)))];
|
|
113
|
+
const keys = facts.seats !== null ? facts.seats.filter((k) => can.has(k)) : ordered;
|
|
114
|
+
const lead = facts.lead !== null && keys.includes(facts.lead) ? facts.lead : (keys[0] ?? null);
|
|
115
|
+
const rest = keys.filter((k) => k !== lead);
|
|
116
|
+
const others = rest.map(name);
|
|
117
|
+
const label = lead === null
|
|
118
|
+
? 'no seat that can work now'
|
|
119
|
+
: others.length === 0
|
|
120
|
+
? name(lead)
|
|
121
|
+
: facts.lead !== null && facts.seats === null
|
|
122
|
+
? `${name(lead)}, with ${list(others)} checking it`
|
|
123
|
+
: list([name(lead), ...others]);
|
|
124
|
+
return { seats: { lead, keys: lead === null ? [] : [lead, ...rest], label }, short: (lead === null ? 0 : 1 + rest.length) < seatsNeeded(r) };
|
|
125
|
+
}
|
|
126
|
+
function inputValueLabel(v) {
|
|
127
|
+
if (v.kind === 'requirements')
|
|
128
|
+
return `${v.refs.length} requirement${v.refs.length === 1 ? '' : 's'}`;
|
|
129
|
+
return v.value;
|
|
130
|
+
}
|
|
131
|
+
function needsOf(facts, ctx, r) {
|
|
132
|
+
const out = [];
|
|
133
|
+
for (const i of r.resolved.inputs) {
|
|
134
|
+
if (i.id === 'seats')
|
|
135
|
+
continue;
|
|
136
|
+
if (i.id === 'intent') {
|
|
137
|
+
out.push({ id: i.id, label: i.label, kind: i.kind, required: i.required, status: facts.words.trim() !== '' ? 'met' : 'missing', ...(facts.words.trim() !== '' ? { value: facts.words.trim().slice(0, 200) } : {}) });
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (i.id === 'repo') {
|
|
141
|
+
const hit = ctx.chat.repos.find((x) => x.id === facts.repoRef);
|
|
142
|
+
const choices = ctx.chat.repos.slice(0, 8).map((x) => ({ label: x.name, value: x.id }));
|
|
143
|
+
out.push({ id: i.id, label: i.label, kind: i.kind, required: i.required, status: hit !== undefined ? 'met' : 'missing', ...(hit !== undefined ? { value: hit.id } : {}), ...(choices.length > 0 ? { choices } : {}) });
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (i.id === 'project') {
|
|
147
|
+
out.push({ id: i.id, label: i.label, kind: i.kind, required: i.required, status: facts.projectId !== null ? 'met' : 'missing', ...(facts.projectId !== null ? { value: facts.projectId } : {}) });
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const v = facts.inputs[i.id];
|
|
151
|
+
out.push({ id: i.id, label: i.label, kind: i.kind, required: i.required, status: v !== undefined ? 'met' : 'missing', ...(v !== undefined ? { value: inputValueLabel(v).slice(0, 200) } : {}) });
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
/** The repository a job runs on: the one named, else the chat's only one. */
|
|
156
|
+
export function repoOf(facts, chat) {
|
|
157
|
+
if (facts.repoRef !== null)
|
|
158
|
+
return chat.repos.find((r) => r.id === facts.repoRef) ?? null;
|
|
159
|
+
return chat.repos.length === 1 ? chat.repos[0] : null;
|
|
160
|
+
}
|
|
161
|
+
/** The checks a resolution carries, the QE skip taken off. */
|
|
162
|
+
export function checksOf(r, skipQe) {
|
|
163
|
+
return r.resolved.gate.filter((g) => !(g === 'qe-acceptance' && skipQe !== null));
|
|
164
|
+
}
|
|
165
|
+
function sketchOf(r) {
|
|
166
|
+
const launch = r.resolved.launch.kind;
|
|
167
|
+
if (launch === 'compose')
|
|
168
|
+
return { steps: [{ label: 'Draft', asks: false }, { label: 'Review', asks: true }] };
|
|
169
|
+
const steps = r.steps.map((s) => {
|
|
170
|
+
const gate = s['gate'];
|
|
171
|
+
const asks = gate === 'consent_before' || (gate !== null && typeof gate === 'object' && (gate['human_confirm'] !== undefined || gate['human_confirm_if'] !== undefined));
|
|
172
|
+
return { label: humanStep(s.id), asks };
|
|
173
|
+
});
|
|
174
|
+
return { steps };
|
|
175
|
+
}
|
|
176
|
+
const minutesLabel = (m) => {
|
|
177
|
+
if (m === null)
|
|
178
|
+
return null;
|
|
179
|
+
const fmt = (x) => (x >= 60 ? `${Math.round((x / 60) * 10) / 10} h` : `${x} min`);
|
|
180
|
+
return `About ${fmt(m[0])}–${fmt(m[1])}`;
|
|
181
|
+
};
|
|
182
|
+
const STOPS = {
|
|
183
|
+
run: 'Asks you to approve the plan first.',
|
|
184
|
+
compose: 'Stops for you at the review.',
|
|
185
|
+
demo: 'Stops for you after the script and after the review.',
|
|
186
|
+
};
|
|
187
|
+
// ── the resolution ─────────────────────────────────────────────────────────────────────────────────────────────────
|
|
188
|
+
/** The option a card proposes when none is named (Q23 asks for the most used; the default stands in until usage is read). */
|
|
189
|
+
export function optionFor(card, option) {
|
|
190
|
+
if (option !== undefined)
|
|
191
|
+
return option;
|
|
192
|
+
return card.variant?.default ?? null;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Resolve a job proposal from its facts. Refuses (a {@link JobRefusal}) an unknown card or option and a hidden card
|
|
196
|
+
* reached by anything but its alias; everything else resolves, with what cannot run yet as `blocked` or the question.
|
|
197
|
+
*/
|
|
198
|
+
export function resolveJob(facts, ctx, opts = {}) {
|
|
199
|
+
const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
|
|
200
|
+
if (card === undefined)
|
|
201
|
+
throw new JobRefusal('card_unknown', `there is no job called “${facts.card.slice(0, 80)}”`);
|
|
202
|
+
if (card.hidden === true && opts.allowHidden !== true)
|
|
203
|
+
throw new JobRefusal('card_hidden', `${card.title} is reached only by its own command`);
|
|
204
|
+
const optionId = optionFor(card, facts.option);
|
|
205
|
+
const r = resolveOption(card.id, optionId, ctx.served);
|
|
206
|
+
if (r === null)
|
|
207
|
+
throw new JobRefusal('card_unknown', `${card.title} has no option “${String(optionId).slice(0, 80)}”`);
|
|
208
|
+
if (facts.depth !== null && card.depth !== true)
|
|
209
|
+
throw new JobRefusal('edits_invalid', `${card.title} takes no depth`);
|
|
210
|
+
// An Investigate card's depth is always one of three: the default is standard, shown and launched alike.
|
|
211
|
+
if (card.depth === true && facts.depth === null)
|
|
212
|
+
facts = { ...facts, depth: 'standard' };
|
|
213
|
+
const kind = proposalKindOf(r);
|
|
214
|
+
if (kind !== 'job')
|
|
215
|
+
throw new JobRefusal('not_a_job', `${card.title} makes a document: it is proposed as one`);
|
|
216
|
+
const notes = [...ctx.notes];
|
|
217
|
+
const repo = repoOf(facts, ctx.chat);
|
|
218
|
+
const { seats, short } = seatsOf(facts, ctx, r);
|
|
219
|
+
const needs = needsOf({ ...facts, repoRef: repo?.id ?? null }, ctx, r);
|
|
220
|
+
const qeOffHere = ctx.qeOff === true && facts.skipQe === null && r.resolved.gate.includes('qe-acceptance');
|
|
221
|
+
const gate = checksOf(r, facts.skipQe).filter((g) => !(qeOffHere && g === 'qe-acceptance'));
|
|
222
|
+
if (qeOffHere)
|
|
223
|
+
notes.push('QE acceptance is off on this daemon (Settings), so this job runs without it, labelled.');
|
|
224
|
+
const launch = r.resolved.launch.kind;
|
|
225
|
+
const shape = {
|
|
226
|
+
card: card.id,
|
|
227
|
+
option: r.option?.id ?? null,
|
|
228
|
+
depth: facts.depth,
|
|
229
|
+
by: facts.by,
|
|
230
|
+
source: facts.source,
|
|
231
|
+
...(facts.guess !== undefined ? { guess: facts.guess } : {}),
|
|
232
|
+
};
|
|
233
|
+
const optTitle = r.option?.title ?? null;
|
|
234
|
+
const label = `${card.title}${optTitle !== null ? ` · ${optTitle}` : ''}`;
|
|
235
|
+
const command = r.option?.command ?? card.command;
|
|
236
|
+
const blockedBy = [];
|
|
237
|
+
let coming;
|
|
238
|
+
if (r.resolved.status === 'coming_soon') {
|
|
239
|
+
coming = { release: card.release, note: r.resolved.statusNote ?? card.statusNote ?? null, nearest: card.nearest ?? null };
|
|
240
|
+
blockedBy.push(`${label} comes in ${card.release}`);
|
|
241
|
+
}
|
|
242
|
+
else if (r.resolved.status === 'unavailable') {
|
|
243
|
+
blockedBy.push(r.resolved.statusNote ?? `${label} can't start on this daemon`);
|
|
244
|
+
}
|
|
245
|
+
if (launch === 'compose' && briefOf(facts).length > 500)
|
|
246
|
+
blockedBy.push('A backlog takes a steer of at most 500 characters: say it shorter');
|
|
247
|
+
if (launch === 'demo' && demoShowOf({ words: facts.words, inputs: facts.inputs, details: facts.details }).length > 4000) {
|
|
248
|
+
blockedBy.push('What to show is over 4000 characters with your corrections: say it shorter');
|
|
249
|
+
}
|
|
250
|
+
// A self-seated workflow picks its own seat at launch: the roster's count is not its requirement (codex r3).
|
|
251
|
+
if (short && coming === undefined && !(r.workflow !== null && SELF_SEATED.has(r.workflow)))
|
|
252
|
+
blockedBy.push(`Needs ${seatsNeeded(r)} seats that can work now (one builds, the others check it); sign another seat in`);
|
|
253
|
+
// The one question: the first required need that is missing.
|
|
254
|
+
let question = null;
|
|
255
|
+
const missing = needs.find((n) => n.required && n.status === 'missing');
|
|
256
|
+
if (coming === undefined && missing !== undefined) {
|
|
257
|
+
if (missing.id === 'repo') {
|
|
258
|
+
question = {
|
|
259
|
+
kind: 'missing',
|
|
260
|
+
text: ctx.chat.repos.length === 0 ? 'Which repository? This chat has none in its scope: start a thread on one.' : 'Which repository?',
|
|
261
|
+
choices: ctx.chat.repos.slice(0, 4).map((x) => ({ label: x.name, edit: { repoRef: x.id } })),
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
else if (missing.kind === 'text' || missing.kind === 'url') {
|
|
265
|
+
question = { kind: 'missing', text: `${missing.label}?`, choices: [], input: { kind: 'text', label: missing.label, edit: `inputs.${missing.id}` } };
|
|
266
|
+
if (missing.id === 'intent')
|
|
267
|
+
question.input = { kind: 'text', label: missing.label, edit: 'inputs.intent' };
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
question = { kind: 'missing', text: `${missing.label}?`, choices: [] };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
// The sentence: one template per card (its noun), the facts as tokens.
|
|
274
|
+
const tokens = [];
|
|
275
|
+
const t = (tok) => {
|
|
276
|
+
tokens.push(tok);
|
|
277
|
+
return `{${tok.id}}`;
|
|
278
|
+
};
|
|
279
|
+
const visibleCards = CATALOG_V2_CARDS.filter((c) => c.hidden !== true && c.category === card.category && c.id !== card.id && c.release === '1.0');
|
|
280
|
+
const kindSwap = (card.variant?.options ?? [])
|
|
281
|
+
.filter((o) => o.id !== r.option?.id && o.status !== 'coming_soon')
|
|
282
|
+
.slice(0, 4)
|
|
283
|
+
.map((o) => swapChoice(nounOf(card, o.id), { option: o.id }, gate, card.id, o.id, ctx.served, facts.skipQe, seatProtections(r)));
|
|
284
|
+
const cardTok = t({
|
|
285
|
+
id: 'kind',
|
|
286
|
+
kind: card.variant !== undefined ? 'option' : 'card',
|
|
287
|
+
label: nounOf(card, r.option?.id ?? null),
|
|
288
|
+
swap: kindSwap.length > 0 ? { choices: kindSwap } : visibleCards.length > 0 ? { choices: visibleCards.slice(0, 4).map((c) => swapChoice(nounOf(c, optionFor(c, undefined)), { card: c.id }, gate, c.id, optionFor(c, undefined), ctx.served, facts.skipQe, seatProtections(r))) } : null,
|
|
289
|
+
});
|
|
290
|
+
const parts = [];
|
|
291
|
+
const delivers = r.resolved.delivers;
|
|
292
|
+
const repoTok = repo === null ? null : t({
|
|
293
|
+
id: 'repo',
|
|
294
|
+
kind: 'repo',
|
|
295
|
+
label: repo.name,
|
|
296
|
+
swap: ctx.chat.repos.length > 1 ? { choices: ctx.chat.repos.filter((x) => x.id !== repo.id).slice(0, 4).map((x) => ({ label: x.name, edit: { repoRef: x.id } })) } : null,
|
|
297
|
+
});
|
|
298
|
+
const selfSeated = r.workflow !== null && SELF_SEATED.has(r.workflow);
|
|
299
|
+
const seatsTok = t({
|
|
300
|
+
id: 'seats',
|
|
301
|
+
kind: 'seats',
|
|
302
|
+
label: selfSeated ? (r.workflow === 'run-evals' ? 'no seat (the evals compute every number)' : 'a seat the review picks itself') : seats.label,
|
|
303
|
+
swap: !selfSeated && ctx.roster.length > 1 ? { choices: ctx.roster.filter((s) => s.key !== seats.lead).slice(0, 4).map((s) => ({ label: `${s.name} leads`, edit: { lead: s.key } })) } : null,
|
|
304
|
+
});
|
|
305
|
+
const checksTok = t({ id: 'checks', kind: 'checks', label: checksLabel(gate), swap: null });
|
|
306
|
+
if (launch === 'compose') {
|
|
307
|
+
const projectTok = t({ id: 'project', kind: 'project', label: ctx.projectLabel, swap: null });
|
|
308
|
+
parts.push(`I'll draft ${cardTok} from the requirements you pick in ${projectTok}, checked by ${checksTok}.`);
|
|
309
|
+
}
|
|
310
|
+
else if (launch === 'demo') {
|
|
311
|
+
const url = facts.inputs['url'];
|
|
312
|
+
parts.push(`I'll record ${cardTok}${url !== undefined ? ` of ${inputValueLabel(url)}` : ''} with ${seatsTok}, checked by ${checksTok}.`);
|
|
313
|
+
}
|
|
314
|
+
else if (delivers === 'report' || delivers === 'answer' || delivers === 'proposals') {
|
|
315
|
+
parts.push(`I'll do this as ${cardTok}${repoTok !== null ? ` of ${repoTok}` : ''}, read-only, with ${seatsTok}, checked by ${checksTok}.`);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
parts.push(`I'll run this as ${cardTok}${repoTok !== null ? ` of ${repoTok}` : ''}, with ${seatsTok}, checked by ${checksTok}.`);
|
|
319
|
+
}
|
|
320
|
+
if (card.depth === true) {
|
|
321
|
+
const d = facts.depth ?? 'standard';
|
|
322
|
+
const depthTok = t({ id: 'depth', kind: 'depth', label: d, swap: { choices: ['quick', 'standard', 'deep'].filter((x) => x !== d).map((x) => ({ label: x, edit: { depth: x } })) } });
|
|
323
|
+
parts.push(`Depth: ${depthTok}.`);
|
|
324
|
+
}
|
|
325
|
+
if (facts.details.length > 0) {
|
|
326
|
+
const ds = facts.details.map((d, i) => t({ id: `detail-${i}`, kind: 'detail', label: d, swap: { choices: [{ label: 'Remove', edit: { detail: { remove: [d] } } }] } }));
|
|
327
|
+
parts.push(`Carrying: ${ds.join(', ')}.`);
|
|
328
|
+
}
|
|
329
|
+
if (facts.skipQe !== null)
|
|
330
|
+
parts.push(`Without QE acceptance (you said: “${facts.skipQe.reason}”), labelled on the job.`);
|
|
331
|
+
const time = minutesLabel(r.resolved.typicalMinutes);
|
|
332
|
+
const stops = launch === 'none' ? null : STOPS[launch];
|
|
333
|
+
if (coming === undefined)
|
|
334
|
+
parts.push(`${time !== null ? `${time}, and ` : ''}${launch === 'run' ? "I'll show you the plan before anything changes." : (stops ?? '')}`.trim());
|
|
335
|
+
const ask = coming !== undefined ? null : question !== null ? question.text : blockedBy.length > 0 ? null : 'Start?';
|
|
336
|
+
const comingText = coming !== undefined
|
|
337
|
+
? `${label} comes in ${card.release}.${coming.nearest !== null ? ` Today, the closest is ${nounOf(CATALOG_V2_CARDS.find((c) => c.id === coming.nearest.card) ?? card, coming.nearest.option)}.` : ''}`
|
|
338
|
+
: null;
|
|
339
|
+
const sentence = { text: comingText ?? parts.filter((p) => p !== '').join(' '), tokens: comingText !== null ? [] : tokens, notes, ask };
|
|
340
|
+
// At most two suggestions: another option that runs a different plan, and another repository in scope.
|
|
341
|
+
const suggestions = [];
|
|
342
|
+
if (coming !== undefined && coming.nearest !== null) {
|
|
343
|
+
const near = CATALOG_V2_CARDS.find((c) => c.id === coming.nearest.card);
|
|
344
|
+
if (near !== undefined)
|
|
345
|
+
suggestions.push({ label: `Do ${nounOf(near, coming.nearest.option)} instead`, edit: { card: near.id, ...(coming.nearest.option !== null ? { option: coming.nearest.option } : {}) } });
|
|
346
|
+
}
|
|
347
|
+
else if (question === null) {
|
|
348
|
+
const alt = (card.variant?.options ?? []).find((o) => o.id !== r.option?.id && o.status !== 'coming_soon' && JSON.stringify(o.launch) !== JSON.stringify(r.resolved.launch));
|
|
349
|
+
if (alt !== undefined) {
|
|
350
|
+
const c = swapChoice(nounOf(card, alt.id), { option: alt.id }, gate, card.id, alt.id, ctx.served, facts.skipQe, seatProtections(r));
|
|
351
|
+
suggestions.push({ label: `Make it ${c.label}`, edit: c.edit });
|
|
352
|
+
}
|
|
353
|
+
const other = ctx.chat.repos.find((x) => x.id !== repo?.id);
|
|
354
|
+
if (other !== undefined && r.resolved.inputs.some((i) => i.id === 'repo'))
|
|
355
|
+
suggestions.push({ label: `Use ${other.name}`, edit: { repoRef: other.id } });
|
|
356
|
+
}
|
|
357
|
+
const brief = briefOf(facts);
|
|
358
|
+
return {
|
|
359
|
+
pid: ctx.pid,
|
|
360
|
+
chatId: ctx.chatId,
|
|
361
|
+
turnId: ctx.turnId,
|
|
362
|
+
kind: 'job',
|
|
363
|
+
seat: ctx.seat,
|
|
364
|
+
what: { entry: card.id, title: card.title, label, outcome: card.outcome ?? null },
|
|
365
|
+
brief,
|
|
366
|
+
reason: facts.guess?.reason ?? null,
|
|
367
|
+
sources: [],
|
|
368
|
+
repos: repo !== null ? [repo.name] : [],
|
|
369
|
+
...(repo !== null ? { repoRefs: [repo.id] } : {}),
|
|
370
|
+
helpers: null,
|
|
371
|
+
time: { minutes: r.resolved.typicalMinutes, cost: r.resolved.cost, steps: r.steps.length > 0 ? r.steps.length : null, median: null, label: time ?? '' },
|
|
372
|
+
stops,
|
|
373
|
+
filedIn: { projectId: facts.projectId, label: ctx.projectLabel },
|
|
374
|
+
blocked: blockedBy[0] ?? (question !== null ? question.text : null),
|
|
375
|
+
shape,
|
|
376
|
+
catalogRev: ctx.served.rev,
|
|
377
|
+
resolution: r.resolved.resolution,
|
|
378
|
+
launch: launch === 'none' ? 'run' : launch,
|
|
379
|
+
command: command ?? null,
|
|
380
|
+
needs,
|
|
381
|
+
gate,
|
|
382
|
+
// A self-seated workflow has no membership of the proposal's choosing (codex r3).
|
|
383
|
+
seats: selfSeated ? { lead: null, keys: [], label: tokens.find((x) => x.id === 'seats')?.label ?? seats.label } : seats,
|
|
384
|
+
seatRules: seatProtections(r),
|
|
385
|
+
words: facts.words,
|
|
386
|
+
details: [...facts.details],
|
|
387
|
+
inputs: { ...facts.inputs },
|
|
388
|
+
skipQe: facts.skipQe,
|
|
389
|
+
...(coming !== undefined ? { coming } : {}),
|
|
390
|
+
sentence,
|
|
391
|
+
suggestions: suggestions.slice(0, 2),
|
|
392
|
+
question,
|
|
393
|
+
sketch: sketchOf(r),
|
|
394
|
+
revises: ctx.revises,
|
|
395
|
+
lineage: ctx.lineage ?? ctx.pid,
|
|
396
|
+
...(ctx.answers !== undefined ? { answers: ctx.answers } : {}),
|
|
397
|
+
...(ctx.request !== undefined ? { request: ctx.request } : {}),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/** A swap choice; one that drops a check names it in its own label and carries `confirmLoss` (pressing it is the
|
|
401
|
+
* person's act, §4.6 step 7). */
|
|
402
|
+
function swapChoice(label, edit, gate, card, option, served, skipQe, protections = []) {
|
|
403
|
+
const r = resolveOption(card, option, served);
|
|
404
|
+
if (r === null)
|
|
405
|
+
return { label, edit };
|
|
406
|
+
const lost = gate.filter((g) => !checksOf(r, skipQe).includes(g));
|
|
407
|
+
const lostSeats = protections.filter((k) => !seatProtections(r).includes(k));
|
|
408
|
+
if (lost.length === 0 && lostSeats.length === 0)
|
|
409
|
+
return { label, edit };
|
|
410
|
+
// Every loss the press confirms is named in its own label (codex r2).
|
|
411
|
+
return { label: `${label}, without ${list([...lost.map((g) => GATE_WORDS[g]), ...lostSeats.map((k) => SEAT_WORDS[k])])}`, edit: { ...edit, confirmLoss: [...lost, ...lostSeats] } };
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* The brief a launch runs on (§4.6 rule 6): the person's first words plus the current details, so removing a detail
|
|
415
|
+
* removes it from the brief. Crew's framing line and depth line are put first by the launch itself (shape.ts).
|
|
416
|
+
*/
|
|
417
|
+
export function briefOf(facts) {
|
|
418
|
+
const words = facts.words.trim();
|
|
419
|
+
if (facts.details.length === 0)
|
|
420
|
+
return words;
|
|
421
|
+
return `${words}\n\nAlso: ${facts.details.join('; ')}.`;
|
|
422
|
+
}
|
|
423
|
+
/** The facts a job proposal was resolved from (a revision starts from them: rule 1). */
|
|
424
|
+
export function factsOf(p) {
|
|
425
|
+
const shape = p.shape;
|
|
426
|
+
return {
|
|
427
|
+
card: shape.card,
|
|
428
|
+
option: shape.option,
|
|
429
|
+
depth: shape.depth,
|
|
430
|
+
words: p.words ?? p.brief ?? '',
|
|
431
|
+
details: [...(p.details ?? [])],
|
|
432
|
+
repoRef: p.repoRefs?.[0] ?? null,
|
|
433
|
+
projectId: p.filedIn.projectId,
|
|
434
|
+
lead: p.seats?.lead ?? null,
|
|
435
|
+
seats: p.seats !== undefined ? [...p.seats.keys] : null,
|
|
436
|
+
inputs: inputsOfProposal(p),
|
|
437
|
+
skipQe: p.skipQe ?? null,
|
|
438
|
+
by: shape.by,
|
|
439
|
+
source: shape.source,
|
|
440
|
+
...(shape.guess !== undefined ? { guess: shape.guess } : {}),
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
/** The input values a proposal holds (a revision carries them; Go launches with them). */
|
|
444
|
+
export function inputsOfProposal(p) {
|
|
445
|
+
return { ...(p.inputs ?? {}) };
|
|
446
|
+
}
|
|
447
|
+
const KNOWN_EDITS = new Set(['card', 'option', 'depth', 'repoRef', 'project', 'lead', 'addSeats', 'removeSeats', 'inputs', 'detail', 'skipQe', 'restoreQe', 'confirmLoss']);
|
|
448
|
+
export const SEAT_WORDS = {
|
|
449
|
+
distinctEvaluator: 'a reviewer who did not build it',
|
|
450
|
+
distinctJudge: 'a separate judge',
|
|
451
|
+
excludeChangeAuthors: "a reviewer who wrote none of the change",
|
|
452
|
+
notRunSeat: 'a reviewer who ran none of the work',
|
|
453
|
+
proposalOnly: 'your approval of everything it proposes',
|
|
454
|
+
};
|
|
455
|
+
export function seatProtections(r) {
|
|
456
|
+
if (r === null)
|
|
457
|
+
return [];
|
|
458
|
+
const s = r.resolved.seats;
|
|
459
|
+
return ['distinctEvaluator', 'distinctJudge', 'excludeChangeAuthors', 'notRunSeat', 'proposalOnly'].filter((k) => s[k]);
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Merge a revision into its parent by the rules of §4.6, in order. Pure over its inputs: the caller decides what a
|
|
463
|
+
* lost check does (a question, or, with the person's `confirmLoss`, the write).
|
|
464
|
+
*/
|
|
465
|
+
export function mergeRevision(parent, edits, ctx) {
|
|
466
|
+
const notes = [];
|
|
467
|
+
// 1. The parent whole; a field the revision does not name keeps its value.
|
|
468
|
+
const facts = factsOf(parent);
|
|
469
|
+
const before = JSON.stringify(facts);
|
|
470
|
+
for (const k of Object.keys(edits))
|
|
471
|
+
if (!KNOWN_EDITS.has(k))
|
|
472
|
+
notes.push(`Not changed: “${k.slice(0, 40)}” isn't something a job can change`);
|
|
473
|
+
// 2. A card change: the new card's default option and depth; what the new card takes is kept, the rest dropped.
|
|
474
|
+
if (edits.card !== undefined && edits.card !== facts.card) {
|
|
475
|
+
const target = CATALOG_V2_CARDS.find((c) => c.id === edits.card);
|
|
476
|
+
if (target === undefined || target.hidden === true) {
|
|
477
|
+
notes.push(`Not changed: there is no job called “${String(edits.card).slice(0, 60)}” to switch to`);
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
facts.card = target.id;
|
|
481
|
+
facts.option = target.variant?.default ?? null;
|
|
482
|
+
facts.depth = target.depth === true ? 'standard' : null;
|
|
483
|
+
// A QE skip was given for the old card: the new card's checks are its own, so it asks again (pi r1).
|
|
484
|
+
facts.skipQe = null;
|
|
485
|
+
const r = resolveOption(target.id, facts.option, ctx.served);
|
|
486
|
+
const takes = new Set((r?.resolved.inputs ?? []).map((i) => i.id));
|
|
487
|
+
if (!takes.has('repo') && facts.repoRef !== null) {
|
|
488
|
+
facts.repoRef = null;
|
|
489
|
+
notes.push(`${target.title} takes no repository: left out`);
|
|
490
|
+
}
|
|
491
|
+
for (const id of Object.keys(facts.inputs)) {
|
|
492
|
+
if (!takes.has(id)) {
|
|
493
|
+
delete facts.inputs[id];
|
|
494
|
+
notes.push(`${target.title} takes no ${id}: left out`);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
// 3. An option or depth change keeps everything else.
|
|
500
|
+
if (edits.option !== undefined) {
|
|
501
|
+
const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
|
|
502
|
+
// `null` on a card with variants is its default option, as the resolver reads it (codex r5).
|
|
503
|
+
if (edits.option !== null && card.variant?.options.some((o) => o.id === edits.option) !== true) {
|
|
504
|
+
notes.push(`Not changed: ${card.title} has no option “${String(edits.option).slice(0, 60)}”`);
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
facts.option = edits.option === null ? (card.variant?.default ?? null) : edits.option;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (edits.depth !== undefined) {
|
|
511
|
+
const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
|
|
512
|
+
if (edits.depth !== null && card.depth !== true)
|
|
513
|
+
notes.push(`Not changed: ${card.title} takes no depth`);
|
|
514
|
+
else
|
|
515
|
+
facts.depth = edits.depth;
|
|
516
|
+
}
|
|
517
|
+
if (edits.repoRef !== undefined) {
|
|
518
|
+
const hit = ctx.chat.repos.find((r) => r.id === edits.repoRef || r.name === edits.repoRef);
|
|
519
|
+
if (hit === undefined)
|
|
520
|
+
notes.push(`Not changed: ${String(edits.repoRef).slice(0, 80)} isn't in this chat's scope (start a thread on it)`);
|
|
521
|
+
else
|
|
522
|
+
facts.repoRef = hit.id;
|
|
523
|
+
}
|
|
524
|
+
if (edits.project !== undefined && edits.project !== facts.projectId)
|
|
525
|
+
notes.push("Not changed: the project is the chat's own");
|
|
526
|
+
// 4. Seats: the lead, added seats; removing the card's only distinct reviewer or judge is refused. A self-seated
|
|
527
|
+
// workflow picks its own seat: a seat edit there changes nothing (codex r2).
|
|
528
|
+
const card4 = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
|
|
529
|
+
const r4 = resolveOption(card4.id, optionFor(card4, facts.option), ctx.served);
|
|
530
|
+
if (r4?.workflow !== null && r4?.workflow !== undefined && SELF_SEATED.has(r4.workflow) && (edits.lead !== undefined || edits.addSeats !== undefined || edits.removeSeats !== undefined)) {
|
|
531
|
+
notes.push(`Not changed: ${card4.title} picks its own seat`);
|
|
532
|
+
edits = { ...edits };
|
|
533
|
+
delete edits.lead;
|
|
534
|
+
delete edits.addSeats;
|
|
535
|
+
delete edits.removeSeats;
|
|
536
|
+
}
|
|
537
|
+
const can = new Set(ctx.roster.map((s) => s.key));
|
|
538
|
+
const nameOf = (k) => ctx.roster.find((s) => s.key === k)?.name ?? k;
|
|
539
|
+
if (edits.lead !== undefined) {
|
|
540
|
+
if (!can.has(edits.lead))
|
|
541
|
+
notes.push(`Not changed: ${nameOf(edits.lead)} can't work now`);
|
|
542
|
+
else {
|
|
543
|
+
facts.lead = edits.lead;
|
|
544
|
+
if (facts.seats !== null && !facts.seats.includes(edits.lead))
|
|
545
|
+
facts.seats = [edits.lead, ...facts.seats];
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (edits.addSeats !== undefined) {
|
|
549
|
+
const add = edits.addSeats.filter((k) => can.has(k));
|
|
550
|
+
for (const k of edits.addSeats)
|
|
551
|
+
if (!can.has(k))
|
|
552
|
+
notes.push(`Not changed: ${nameOf(k)} can't work now`);
|
|
553
|
+
if (add.length > 0)
|
|
554
|
+
facts.seats = [...new Set([...(facts.seats ?? []), ...add])];
|
|
555
|
+
}
|
|
556
|
+
if (edits.removeSeats !== undefined && edits.removeSeats.length > 0) {
|
|
557
|
+
const r = resolveOption(facts.card, optionFor(CATALOG_V2_CARDS.find((c) => c.id === facts.card), facts.option), ctx.served);
|
|
558
|
+
const need = r === null ? 1 : seatsNeeded(r);
|
|
559
|
+
const current = facts.seats ?? [...new Set([facts.lead, ...ctx.chat.seats, ...ctx.roster.map((s) => s.key)].filter((k) => k !== null && can.has(k)))];
|
|
560
|
+
const kept = current.filter((k) => !edits.removeSeats.includes(k));
|
|
561
|
+
if (kept.length < need) {
|
|
562
|
+
notes.push(`Not changed: ${list(edits.removeSeats.map(nameOf))} ${edits.removeSeats.length === 1 ? 'stays' : 'stay'}; this job needs ${need} seats, so another seat checks the one that builds`);
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
facts.seats = kept;
|
|
566
|
+
if (facts.lead !== null && !kept.includes(facts.lead))
|
|
567
|
+
facts.lead = kept[0] ?? null;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
// 5. Inputs fill or replace the needs they name, each validated against the card's own input (its kind, non-blank).
|
|
571
|
+
if (edits.inputs !== undefined) {
|
|
572
|
+
const card5 = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
|
|
573
|
+
const defs5 = resolveOption(facts.card, optionFor(card5, facts.option), ctx.served)?.resolved.inputs ?? [];
|
|
574
|
+
for (const [id, v] of Object.entries(edits.inputs)) {
|
|
575
|
+
const def = defs5.find((d) => d.id === id);
|
|
576
|
+
const kindOk = def !== undefined && (def.kind === v.kind || (def.kind === 'text' && v.kind === 'text'));
|
|
577
|
+
if (!kindOk) {
|
|
578
|
+
notes.push(`Not changed: ${card5.title} takes no ${def === undefined ? '' : `${v.kind} `}${id.slice(0, 40)}`);
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
if ((v.kind === 'text' || v.kind === 'url') && v.value.trim() === '') {
|
|
582
|
+
notes.push(`Not changed: ${def.label} can't be blank`);
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
// The launch's own limits, checked here so Start never shows for a launch that would refuse (codex r3).
|
|
586
|
+
const LIMIT = { audience: 2000, show: 4000, url: 2048 };
|
|
587
|
+
if ((v.kind === 'text' || v.kind === 'url') && LIMIT[id] !== undefined && v.value.length > LIMIT[id]) {
|
|
588
|
+
notes.push(`Not changed: ${def.label} is over ${LIMIT[id]} characters`);
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
if (v.kind === 'requirements' && v.refs.length > 40) {
|
|
592
|
+
notes.push('Not changed: pick at most 40 requirements');
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
if (id === 'intent' && v.kind === 'text') {
|
|
596
|
+
facts.words = v.value.slice(0, 8000);
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
if ((v.kind === 'text' || v.kind === 'url') && (typeof v.value !== 'string' || v.value.length > 4000)) {
|
|
600
|
+
notes.push(`Not changed: ${id} is too long`);
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (v.kind === 'url') {
|
|
604
|
+
try {
|
|
605
|
+
const u = new URL(v.value);
|
|
606
|
+
if (u.protocol !== 'http:' && u.protocol !== 'https:')
|
|
607
|
+
throw new Error('scheme');
|
|
608
|
+
}
|
|
609
|
+
catch {
|
|
610
|
+
notes.push(`Not changed: ${v.value.slice(0, 80)} isn't an http(s) address`);
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
facts.inputs[id] = v;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
// 6. Details: facts carried from corrections; the brief is rebuilt from the first words plus these.
|
|
618
|
+
if (edits.detail !== undefined) {
|
|
619
|
+
for (const d of edits.detail.remove ?? [])
|
|
620
|
+
facts.details = facts.details.filter((x) => x !== d);
|
|
621
|
+
for (const d of edits.detail.add ?? []) {
|
|
622
|
+
const t = d.trim().slice(0, 200);
|
|
623
|
+
if (t !== '' && !facts.details.includes(t) && !facts.words.includes(t))
|
|
624
|
+
facts.details.push(t);
|
|
625
|
+
}
|
|
626
|
+
facts.details = facts.details.slice(0, 12);
|
|
627
|
+
}
|
|
628
|
+
if (edits.skipQe !== undefined)
|
|
629
|
+
facts.skipQe = { reason: edits.skipQe.reason.trim().slice(0, 600) };
|
|
630
|
+
if (edits.restoreQe === true)
|
|
631
|
+
facts.skipQe = null;
|
|
632
|
+
// 7. The checks compared with the parent's: what the result lacks is lost (the caller asks before writing it).
|
|
633
|
+
const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
|
|
634
|
+
const r = resolveOption(facts.card, optionFor(card, facts.option), ctx.served);
|
|
635
|
+
// A skip on a shape with no QE acceptance to skip is dropped (the engine refuses one there).
|
|
636
|
+
if (facts.skipQe !== null && r !== null && !r.resolved.gate.includes('qe-acceptance'))
|
|
637
|
+
facts.skipQe = null;
|
|
638
|
+
const after = r === null ? [] : checksOf(r, facts.skipQe);
|
|
639
|
+
// A loss the parent's own question is still asking about stays a loss until the person's press (codex r2).
|
|
640
|
+
const pending = parent.question?.kind === 'lost_check' ? (parent.question.lost ?? []) : [];
|
|
641
|
+
const lost = [...new Set([...(parent.gate ?? []), ...pending])].filter((g) => !after.includes(g));
|
|
642
|
+
const parentCard = parent.shape === undefined ? null : CATALOG_V2_CARDS.find((c) => c.id === parent.shape.card) ?? null;
|
|
643
|
+
// The parent's frozen seat rules (a catalog change since never erases one), else read from its card.
|
|
644
|
+
const before7 = parent.seatRules ?? (parentCard === null ? [] : seatProtections(resolveOption(parentCard.id, optionFor(parentCard, parent.shape.option), ctx.served)));
|
|
645
|
+
const after7 = seatProtections(r);
|
|
646
|
+
const pendingSeats = parent.question?.kind === 'lost_check' ? (parent.question.lostSeats ?? []) : [];
|
|
647
|
+
const lostSeats = [...new Set([...before7, ...pendingSeats])].filter((k) => !after7.includes(k));
|
|
648
|
+
return { facts, notes, lost, lostSeats, unchanged: JSON.stringify(facts) === before };
|
|
649
|
+
}
|
|
650
|
+
// ── the QE skip, bound to the person's own words (§2.4, §9.2 (ac)) ─────────────────────────────────────────────────
|
|
651
|
+
/** The text outside quotes and reported speech ("the PM said: …"): only that is the person's own ask. */
|
|
652
|
+
export function ownWords(message) {
|
|
653
|
+
// Quoted material in the chat's own formats: block quotes, code spans and fences; curly apostrophes read as straight.
|
|
654
|
+
let t = message
|
|
655
|
+
.replace(/(^|[\s(])\u2018[^\u2019]*\u2019(?![a-z])/giu, '$1 ')
|
|
656
|
+
.replace(/(?<=[a-z])\u2019(?=[a-z])/giu, "'")
|
|
657
|
+
.replace(/```[\s\S]*?```/gu, ' ')
|
|
658
|
+
.replace(/`[^`]*`/gu, ' ')
|
|
659
|
+
.split('\n')
|
|
660
|
+
.filter((line) => !/^\s*>/u.test(line))
|
|
661
|
+
.join('\n');
|
|
662
|
+
t = t.replace(/“[^”]*”|"[^"]*"|«[^»]*»|(^|[\s(])'[^']*'(?=$|[\s).,;:!?])/gu, (_m, lead) => `${lead ?? ''} `);
|
|
663
|
+
// Reported speech: whatever follows "X said:" / "they asked" / "told me to" is someone else's.
|
|
664
|
+
t = t.replace(/\b(said|says|asked|asks|told (me|us)( to)?|wrote|writes|wants (me|us) to|requested|requests|mentioned|suggested|according to|per)\b[\s\S]*$/iu, ' ');
|
|
665
|
+
return t;
|
|
666
|
+
}
|
|
667
|
+
const SKIP_ASK = /\b(skip(ping)?|drop(ping)?|without|no)\s+(the\s+)?qe(\s+acceptance)?\b/iu;
|
|
668
|
+
/** "No skipping QE…", "no need to skip…": a refusal phrased as a skip. */
|
|
669
|
+
const NO_SKIP = /\bno\s+(skipping|dropping|need\s+to)\b/iu;
|
|
670
|
+
/** A negation anywhere earlier in the same sentence makes the ask not one (conservative: ask the person instead). */
|
|
671
|
+
const NEGATED = /\b(don'?t|do not|never|not|no need to|shouldn'?t|mustn'?t|won'?t|can'?t|cannot)\b[^.!?\n]*$/iu;
|
|
672
|
+
/** Whether the person's own words (not quoted, not reported, not negated) ask to skip QE acceptance. */
|
|
673
|
+
export function personAskedSkip(message) {
|
|
674
|
+
if (message === null)
|
|
675
|
+
return false;
|
|
676
|
+
const own = ownWords(message);
|
|
677
|
+
const m = SKIP_ASK.exec(own);
|
|
678
|
+
return m !== null && !NEGATED.test(own.slice(0, m.index)) && !NO_SKIP.test(own);
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Whether a seat's QE skip is the person's own: their message that this turn answers asks for it in their own words
|
|
682
|
+
* (not quoted, not reported, not negated), and the reason appears there too, unquoted. A reason that is only "QE" is
|
|
683
|
+
* none.
|
|
684
|
+
*/
|
|
685
|
+
export function qeSkipBound(reason, message) {
|
|
686
|
+
if (message === null)
|
|
687
|
+
return false;
|
|
688
|
+
const own = ownWords(message);
|
|
689
|
+
const m = SKIP_ASK.exec(own);
|
|
690
|
+
if (m === null)
|
|
691
|
+
return false;
|
|
692
|
+
if (NEGATED.test(own.slice(0, m.index)) || NO_SKIP.test(own))
|
|
693
|
+
return false;
|
|
694
|
+
const r = reason.trim().toLowerCase().replace(/[.!?,;:]+$/u, '');
|
|
695
|
+
const bare = r.replace(/\b(qe|acceptance|skip|the|it|because|since)\b/gu, '').replace(/[^\p{L}\p{N}]+/gu, '');
|
|
696
|
+
if (r.length < 3 || bare.length < 3)
|
|
697
|
+
return false;
|
|
698
|
+
return own.toLowerCase().includes(r);
|
|
699
|
+
}
|
|
700
|
+
// ── ids ────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
701
|
+
/** A digest of a request body (a repeated `requestId` with another body is refused). */
|
|
702
|
+
export function requestDigest(body) {
|
|
703
|
+
return createHash('sha256').update(JSON.stringify(body)).digest('hex').slice(0, 24);
|
|
704
|
+
}
|
|
705
|
+
/** A person-made proposal's pid, derived from the person and their request id (a retry names the same one). */
|
|
706
|
+
export function personPid(chatId, actorId, requestId) {
|
|
707
|
+
const tag = createHash('sha256').update(`${actorId}\u0000${requestId}`, 'utf8').digest('hex').slice(0, 20);
|
|
708
|
+
return `${chatId}:p:${tag}`;
|
|
709
|
+
}
|
|
710
|
+
export const depthLine = (d) => DEPTH_LINES[d];
|
|
711
|
+
// ── what Go launches (DES-CATALOG-002 §4.6) ────────────────────────────────────────────────────────────────────────
|
|
712
|
+
/** A demo's brief: the person's first words, their show field and the corrections, together (one rendering for the
|
|
713
|
+
* check before Start and the launch). */
|
|
714
|
+
export function demoShowOf(p) {
|
|
715
|
+
const show = p.inputs?.['show'];
|
|
716
|
+
return [...new Set([p.words ?? '', show !== undefined && show.kind === 'text' ? show.value : '', ...(p.details ?? [])])].filter((x) => x.trim() !== '').join('\n');
|
|
717
|
+
}
|
|
718
|
+
/** The inputs a run launch carries in its brief (beside the intent, the repository and the project), as plain lines. */
|
|
719
|
+
export function inputLines(p) {
|
|
720
|
+
const out = [];
|
|
721
|
+
for (const [id, v] of Object.entries(p.inputs ?? {})) {
|
|
722
|
+
if (id === 'intent')
|
|
723
|
+
continue;
|
|
724
|
+
const label = p.needs?.find((n) => n.id === id)?.label ?? id;
|
|
725
|
+
if (v.kind === 'requirements')
|
|
726
|
+
out.push(`${label}: ${v.refs.map((r) => `${r.repoId} ${r.key}`).join(', ')}`);
|
|
727
|
+
else
|
|
728
|
+
out.push(`${label}: ${v.value}`);
|
|
729
|
+
}
|
|
730
|
+
return out;
|
|
731
|
+
}
|
|
732
|
+
/** The launch's `LaunchShape` from a proposal's frozen shape. */
|
|
733
|
+
export function launchShapeOfProposal(p) {
|
|
734
|
+
const shape = p.shape;
|
|
735
|
+
return {
|
|
736
|
+
card: shape.card,
|
|
737
|
+
option: shape.option,
|
|
738
|
+
depth: shape.depth,
|
|
739
|
+
by: shape.by === 'detected' ? 'detected' : 'person',
|
|
740
|
+
catalogRev: p.catalogRev,
|
|
741
|
+
...(shape.guess !== undefined ? { guess: { confidence: shape.guess.confidence, band: shape.guess.band, source: shape.guess.source, reason: shape.guess.reason, detectionRunId: null } } : {}),
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* The common launch fields of a job's Go, for every launch kind: the derived identity, the chat, the shape, the seats
|
|
746
|
+
* the person saw, the plan held, QE as shown (forced when the daemon's setting is off but the proposal promised it),
|
|
747
|
+
* and a reshape's lineage and envelope.
|
|
748
|
+
*/
|
|
749
|
+
export function jobLaunchCommon(p, d, o) {
|
|
750
|
+
const lead = p.seats?.lead ?? undefined;
|
|
751
|
+
const qeShown = (p.gate ?? []).includes('qe-acceptance');
|
|
752
|
+
const skip = p.skipQe ?? null;
|
|
753
|
+
return {
|
|
754
|
+
sessionId: d.runId,
|
|
755
|
+
chatId: d.chatId,
|
|
756
|
+
...(!o.selfSeated && lead !== undefined ? { primary: lead } : {}),
|
|
757
|
+
...(!o.selfSeated && o.clisJson !== undefined ? { clisJson: o.clisJson } : {}),
|
|
758
|
+
shape: launchShapeOfProposal(p),
|
|
759
|
+
// QE as the person saw it (codex r2): promised, it is forced (no setting or score drops it unseen); skipped, the
|
|
760
|
+
// person's own skip with their reason.
|
|
761
|
+
...(skip !== null ? { skipQeAcceptance: { reason: skip.reason } } : qeShown ? { forceQeAcceptance: true } : {}),
|
|
762
|
+
...(p.relaunch?.campaignId !== undefined ? { campaignId: p.relaunch.campaignId } : p.relaunch?.groupLabel !== undefined ? { groupLabel: p.relaunch.groupLabel } : {}),
|
|
763
|
+
...(p.reshapes !== undefined ? { retryOf: p.reshapes } : {}),
|
|
764
|
+
...(p.reducedAssurance === true ? { reducedAssurance: true } : {}),
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
//# sourceMappingURL=chat-jobs.js.map
|