@digital-agora/friday 0.0.0-stage → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +296 -2
- package/bundles/friday-claude-0.1.0.zip +0 -0
- package/bundles/friday-opencode-0.1.0.zip +0 -0
- package/dist/adapters/adapter.js +6 -0
- package/dist/adapters/claude/guards.js +40 -0
- package/dist/adapters/claude/index.js +161 -0
- package/dist/adapters/claude/runtime.js +645 -0
- package/dist/adapters/claude/workflows.js +323 -0
- package/dist/adapters/drivers.js +300 -0
- package/dist/adapters/index.js +16 -0
- package/dist/adapters/opencode/index.js +232 -0
- package/dist/adapters/skill.js +327 -0
- package/dist/build.js +77 -0
- package/dist/cli.js +197 -0
- package/dist/frontmatter.js +16 -0
- package/dist/graph.js +218 -0
- package/dist/handoff.js +329 -0
- package/dist/install.js +137 -0
- package/dist/ir.js +177 -0
- package/dist/load.js +42 -0
- package/dist/paths.js +24 -0
- package/dist/prompts.js +230 -0
- package/dist/specialize.js +237 -0
- package/dist/step-schemas.js +444 -0
- package/dist/types.js +8 -0
- package/dist/validate.js +576 -0
- package/pack/conventions/changesets.yaml +20 -0
- package/pack/conventions/ci-workflows.yaml +16 -0
- package/pack/conventions/config-secrets.yaml +16 -0
- package/pack/conventions/data-classification.yaml +16 -0
- package/pack/conventions/decisions.yaml +13 -0
- package/pack/conventions/git.yaml +28 -0
- package/pack/conventions/hexagonal.yaml +31 -0
- package/pack/conventions/security-code.yaml +17 -0
- package/pack/conventions/testing.yaml +44 -0
- package/pack/conventions/typescript-node.yaml +16 -0
- package/pack/model-policy.yaml +80 -0
- package/pack/orchestrations/architecture-decision.yaml +52 -0
- package/pack/orchestrations/bugfix-tdd.yaml +67 -0
- package/pack/orchestrations/data-analysis.yaml +23 -0
- package/pack/orchestrations/discovery.yaml +214 -0
- package/pack/orchestrations/feature-delivery.yaml +129 -0
- package/pack/orchestrations/prompt-delivery.yaml +155 -0
- package/pack/orchestrations/prompt-discovery.yaml +201 -0
- package/pack/orchestrations/release.yaml +40 -0
- package/pack/pack.yaml +137 -0
- package/pack/personas/architect.yaml +18 -0
- package/pack/personas/backend-engineer.yaml +21 -0
- package/pack/personas/data-analyst-non-pii.yaml +14 -0
- package/pack/personas/data-analyst-pii.yaml +28 -0
- package/pack/personas/devops-engineer.yaml +19 -0
- package/pack/personas/frontend-engineer.yaml +18 -0
- package/pack/personas/git-steward.yaml +24 -0
- package/pack/personas/lead-developer.yaml +23 -0
- package/pack/personas/prompt-engineer.yaml +38 -0
- package/pack/personas/qa-engineer.yaml +24 -0
- package/pack/personas/security-steward.yaml +20 -0
- package/package.json +47 -4
- package/schemas/convention.schema.yaml +46 -0
- package/schemas/handoff.schema.yaml +303 -0
- package/schemas/model-policy.schema.yaml +33 -0
- package/schemas/orchestration.schema.yaml +224 -0
- package/schemas/pack.schema.yaml +168 -0
- package/schemas/persona.schema.yaml +41 -0
- package/schemas/specialization-patch.schema.yaml +39 -0
- package/schemas/specialization.schema.yaml +57 -0
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
// JavaScript runtime embedded at the top of every generated Claude Code workflow script.
|
|
2
|
+
// Rules of the host: plain JS, no Date.now / Math.random / argless new Date, no fs.
|
|
3
|
+
// Kept free of backticks and "${" so it can live in this TS template literal unescaped.
|
|
4
|
+
export const RUNTIME = String.raw `
|
|
5
|
+
const A = (typeof args === "object" && args) ? args : {};
|
|
6
|
+
const state = { testOwners: {}, foreign: [], outputs: {}, questions: [], assumptions: [], gaps: [], contradictions: [], dropped: [], deferred: [], halt: null, violations: [], done: [], seen: [], bootstrapped: false };
|
|
7
|
+
// With answersFile the full answers live in docs/friday/<workId>/answers.yaml and only their
|
|
8
|
+
// ids travel inline (answeredIds, resolvedIds), so args stop growing every round.
|
|
9
|
+
const ANSWERED = new Set((A.answers || []).map(function (a) { return a.id; }).concat(A.answeredIds || []));
|
|
10
|
+
const RESOLVED = new Set((A.gapResolutions || []).map(function (g) { return g.id; }).concat(A.resolvedIds || []));
|
|
11
|
+
const HANDOFF = A.handoff || null;
|
|
12
|
+
const HAS_PII = !!(HANDOFF && (HANDOFF.dataClassification || []).some(function (d) { return d.class === "pii"; }));
|
|
13
|
+
// Upstream question rounds: the driver passes round (1-based); extraRounds and scopeFrozen are
|
|
14
|
+
// the user's own choices once the limit is reached. Without maxRounds the loop is unbounded.
|
|
15
|
+
function count(v, min) { const n = parseInt(v, 10); return n >= min ? n : min; }
|
|
16
|
+
const ROUND = count(A.round, 1);
|
|
17
|
+
const ROUND_LIMIT = WORKFLOW.maxRounds ? WORKFLOW.maxRounds + count(A.extraRounds, 0) : null;
|
|
18
|
+
const FROZEN = A.scopeFrozen === true;
|
|
19
|
+
|
|
20
|
+
function halted() { return state.halt !== null; }
|
|
21
|
+
// The run's route trace (decision 45): why it went where it went, step by step, so the retro and
|
|
22
|
+
// the person reading the result can see each route without re-running it. No time fields: the
|
|
23
|
+
// script must stay deterministic.
|
|
24
|
+
state.trace = [];
|
|
25
|
+
function trace(step, item, round, route, reason) {
|
|
26
|
+
const t = { step: step, route: route };
|
|
27
|
+
if (item && item.id) t.item = item.id;
|
|
28
|
+
if (round !== null && round !== undefined) t.round = round;
|
|
29
|
+
if (reason) t.reason = reason;
|
|
30
|
+
state.trace.push(t);
|
|
31
|
+
}
|
|
32
|
+
function stop(h) {
|
|
33
|
+
if (state.halt) return;
|
|
34
|
+
state.halt = h;
|
|
35
|
+
trace(h.step || null, h.item ? { id: h.item } : null, null, h.status, h.reason || null);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function resolveRef(ref, item) {
|
|
39
|
+
let persona = ref.persona;
|
|
40
|
+
let kind = ref.taskKind;
|
|
41
|
+
if (persona === "{{stack}}") {
|
|
42
|
+
persona = item && STACKS[item.stack];
|
|
43
|
+
if (!persona) return { error: "no engineer for stack " + (item && item.stack) };
|
|
44
|
+
}
|
|
45
|
+
if (persona === "{{analyst}}") persona = ANALYSTS[HAS_PII ? "pii" : "non-pii"];
|
|
46
|
+
if (kind === "{{task.taskKind}}") {
|
|
47
|
+
kind = item && item.taskKind;
|
|
48
|
+
if ((ref.allowedTaskKinds || []).indexOf(kind) < 0) {
|
|
49
|
+
return { error: "task " + (item && item.id) + " has taskKind " + kind + ", allowed: " + (ref.allowedTaskKinds || []).join(", ") };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const agentType = (AGENTS[persona] || {})[kind];
|
|
53
|
+
if (!agentType) return { error: "no agent for " + persona + " / " + kind };
|
|
54
|
+
const policy = MODELS[kind];
|
|
55
|
+
return { persona: persona, kind: kind, agentType: agentType, model: ref.model || policy.model, effort: ref.effort || policy.effort };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// An answer that settles a contradiction lists the answers it replaces in supersedes.
|
|
59
|
+
const SUPERSEDED = new Set([].concat.apply([], (A.answers || []).map(function (a) { return a.supersedes || []; })));
|
|
60
|
+
|
|
61
|
+
function answersText() {
|
|
62
|
+
const qa = (A.answers || []).concat(state.autoAnswers || []).filter(function (a) { return !SUPERSEDED.has(a.id); });
|
|
63
|
+
if (!qa.length) return "(none yet)";
|
|
64
|
+
return qa.map(function (a) {
|
|
65
|
+
const sup = (a.supersedes || []).length ? "\n Replaces: " + a.supersedes.join(", ") : "";
|
|
66
|
+
const by = a.by === "close-out" ? " (close-out: recommended option)" : "";
|
|
67
|
+
const how = a.interpretation ? "\n Interpretation (the orchestrator's reading, not the user's words): " + a.interpretation : "";
|
|
68
|
+
return "- " + a.id + ": " + a.question + "\n Answer: " + a.answer + by + how + sup;
|
|
69
|
+
}).join("\n");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function gapsText() {
|
|
73
|
+
const g = A.gapResolutions || [];
|
|
74
|
+
if (!g.length) return "(none yet)";
|
|
75
|
+
return g.map(function (x) { return "- " + x.id + " [" + x.area + "] " + x.gap + "\n Resolution: " + x.resolution; }).join("\n");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function roundText() {
|
|
79
|
+
if (FROZEN) {
|
|
80
|
+
return "Round " + ROUND + ": the user froze the scope. Anything the answers above do not settle is out of scope for this work; report it only if a planned task cannot be written or tested without it.";
|
|
81
|
+
}
|
|
82
|
+
const of = ROUND_LIMIT ? " of " + ROUND_LIMIT : "";
|
|
83
|
+
const last = ROUND_LIMIT && ROUND >= ROUND_LIMIT ? " This is the last round: anything still open is shown to the user, who freezes the scope or allows more rounds." : "";
|
|
84
|
+
const later = ROUND > 1 ? " Ask only what the newest answers raise or still leave open; do not reopen what earlier rounds settled." : "";
|
|
85
|
+
return "Question round " + ROUND + of + "." + later + last;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Optional run inputs every step sees: the domain glossary and facts about the environment
|
|
89
|
+
// (registry access, emulators, tools) the orchestrator verified, so agents do not ask about them.
|
|
90
|
+
function factsText() {
|
|
91
|
+
const parts = [];
|
|
92
|
+
const g = A.glossary;
|
|
93
|
+
if (g && (Array.isArray(g) ? g.length : Object.keys(g).length)) {
|
|
94
|
+
const rows = Array.isArray(g) ? g.map(function (x) { return "- " + x.term + ": " + x.meaning; }) : Object.keys(g).map(function (k) { return "- " + k + ": " + g[k]; });
|
|
95
|
+
parts.push("Glossary (what these words mean in this domain; use them, do not ask what they mean):\n" + rows.join("\n"));
|
|
96
|
+
}
|
|
97
|
+
const e = A.environmentFacts;
|
|
98
|
+
if (e && (Array.isArray(e) ? e.length : Object.keys(e).length)) {
|
|
99
|
+
const rows = Array.isArray(e) ? e.map(function (x) { return "- " + x; }) : Object.keys(e).map(function (k) { return "- " + k + ": " + e[k]; });
|
|
100
|
+
parts.push("Environment facts (verified; not blockers, do not ask about them):\n" + rows.join("\n"));
|
|
101
|
+
}
|
|
102
|
+
return parts;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Slice-scoped prompts (args.sliceScoped): a task agent gets its task and the tasks it depends
|
|
106
|
+
// on, the decisions that touch its codebase (or name no place), the data classification, the
|
|
107
|
+
// command map and the standing policy; not the whole handoff. Smaller prompts, stable cache keys.
|
|
108
|
+
function sliceOf(item) {
|
|
109
|
+
const tasks = (HANDOFF.tasks || []).filter(function (t) { return t.id === item.id || (item.dependsOn || []).indexOf(t.id) >= 0; });
|
|
110
|
+
const decisions = (HANDOFF.decisions || []).filter(function (d) { return !d.where || String(d.where).indexOf(item.codebase) >= 0 || String(item.codebase).indexOf(d.where) >= 0; });
|
|
111
|
+
return { workId: HANDOFF.workId, scope: { summary: (HANDOFF.scope || {}).summary }, tasks: tasks, decisions: decisions, dataClassification: HANDOFF.dataClassification || [], commands: COMMANDS, deliveryPolicy: HANDOFF.deliveryPolicy || null };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function context(stepId, item) {
|
|
115
|
+
const parts = ["Workflow " + WORKFLOW.id + " (" + WORKFLOW.stream + "), step " + stepId + "."].concat(factsText());
|
|
116
|
+
if (WORKFLOW.stream === "upstream") {
|
|
117
|
+
parts.push("Work id: " + (A.workId || "(missing)"));
|
|
118
|
+
parts.push("Request:\n" + (A.request || "(missing)"));
|
|
119
|
+
if (A.answersFile) {
|
|
120
|
+
parts.push("Questions already answered and gaps already resolved by the user are in " + A.answersFile + " (answers, gapResolutions). Read it before you start; do not ask or report them again; where an answer lists supersedes, only it counts.");
|
|
121
|
+
if ((state.autoAnswers || []).length) parts.push("Answered in this run by the close-out rule:\n" + answersText());
|
|
122
|
+
} else {
|
|
123
|
+
parts.push("Questions already answered by the user (do not ask them again; build on the answers):\n" + answersText());
|
|
124
|
+
parts.push("Gaps already resolved by the user (do not report them again):\n" + gapsText());
|
|
125
|
+
}
|
|
126
|
+
parts.push(roundText());
|
|
127
|
+
if (state.deferred.length) {
|
|
128
|
+
parts.push("Deferred items (not blockers for this work): record each in scope.outOfScope as a follow-up work item, plan no task for it and do not ask about it:\n" + JSON.stringify(state.deferred));
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
// Task brief (decision 40): the prompt the prompt engineer wrote for this task, approved with the
|
|
132
|
+
// handoff; it comes first, and the handoff or its slice still follows as the source of truth.
|
|
133
|
+
const tb = HANDOFF && item && item.id && (HANDOFF.briefs || []).find(function (b) { return b.task === item.id; });
|
|
134
|
+
if (tb) parts.push("Task brief (approved with the handoff; the handoff below stays the source of truth):\n" + tb.text);
|
|
135
|
+
if (HANDOFF && A.sliceScoped && item && item.codebase) {
|
|
136
|
+
parts.push("Approved handoff, scoped to this task (the only source of truth; anything it does not settle is a blocker, not a guess):\n" + JSON.stringify(sliceOf(item)));
|
|
137
|
+
} else if (HANDOFF) {
|
|
138
|
+
parts.push("Approved handoff (the only source of truth; anything it does not settle is a blocker, not a guess):\n" + JSON.stringify(HANDOFF));
|
|
139
|
+
} else {
|
|
140
|
+
parts.push("Run arguments (anything they and the repository do not settle is a blocker, not a guess):\n" + JSON.stringify(A));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (HANDOFF && WORKFLOW.stream === "downstream") {
|
|
144
|
+
// After the preflight the install is done (decision 48); a breaking task's codebases are red
|
|
145
|
+
// until its closedBy tasks are done (decision 50).
|
|
146
|
+
if (state.bootstrapped) parts.push(BOOTSTRAPPED);
|
|
147
|
+
const br = openBreaks();
|
|
148
|
+
if (br.length) {
|
|
149
|
+
parts.push("Expected failures (tracked breaks, not foreign; do not fix them here):\n" + br.map(function (b) {
|
|
150
|
+
return "- " + b.codebases.join(", ") + " may fail typecheck or tests since task " + b.task + ", until " + b.until.join(", ") + " are done.";
|
|
151
|
+
}).join("\n"));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (HANDOFF && HANDOFF.deliveryPolicy) {
|
|
155
|
+
parts.push("Standing delivery policy (what delivery may settle itself; record each such decision in your summary, never product, copy or security-widening):\n" + JSON.stringify(HANDOFF.deliveryPolicy));
|
|
156
|
+
}
|
|
157
|
+
const earlier = Object.keys(state.outputs);
|
|
158
|
+
if (earlier.length) parts.push("Results of earlier steps:\n" + JSON.stringify(state.outputs));
|
|
159
|
+
if (item) parts.push("Current item:\n" + JSON.stringify(item));
|
|
160
|
+
return parts.join("\n\n");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Per-repo command map: level id -> commands, from args.commands or the handoff's commands.
|
|
164
|
+
// The pack's commands are only the default; an npm repo with test:architecture maps its own.
|
|
165
|
+
const COMMANDS = Object.assign({}, (HANDOFF && HANDOFF.commands) || {}, A.commands || {});
|
|
166
|
+
function levelCommands(id) {
|
|
167
|
+
const list = (COMMANDS[id] && COMMANDS[id].length) ? COMMANDS[id] : (LEVELS[id] || []);
|
|
168
|
+
return list.map(function (c) { return "\u0060" + c + "\u0060"; }).join(" ; ");
|
|
169
|
+
}
|
|
170
|
+
function withCommands(text) {
|
|
171
|
+
return text.replace(/@@commands:([a-z0-9-]+)@@/g, function (m, id) { return levelCommands(id); });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// The field descriptions of the schema an agent returns, as prompt text (the schema itself is shape only).
|
|
175
|
+
function guideFor(schema) {
|
|
176
|
+
const name = Object.keys(SCHEMAS).find(function (k) { return SCHEMAS[k] === schema; });
|
|
177
|
+
const g = name && FIELD_GUIDES[name];
|
|
178
|
+
return g ? "\n\n## What the fields of your result mean\n\n" + g : "";
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Mid-run answers: when a step stops for the user (needs-upstream or needs-input), the driver
|
|
182
|
+
// resumes the same run with args.midRunAnswers [{ step, item?, question, answer }]. They reach only
|
|
183
|
+
// the step that asked, so every step that finished before it keeps its prompt and replays from the
|
|
184
|
+
// cache: answering a question never restarts the workflow. The handoff argument is not changed on
|
|
185
|
+
// resume; the driver records the answers in the handoff file afterwards.
|
|
186
|
+
function midRunAnswersText(stepId, item) {
|
|
187
|
+
const own = (Array.isArray(A.midRunAnswers) ? A.midRunAnswers : []).filter(function (a) {
|
|
188
|
+
return a && a.step === stepId && (!a.item || (item && a.item === item.id));
|
|
189
|
+
});
|
|
190
|
+
if (!own.length) return "";
|
|
191
|
+
return "\n\n## Answers to the questions this step raised (from the user; settled, do not ask them again; ask only a question an answer newly creates)\n\n" +
|
|
192
|
+
own.map(function (a) { return "- Q: " + a.question + "\n A: " + a.answer + (a.interpretation ? "\n Interpretation: " + a.interpretation : ""); }).join("\n");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function call(stepId, ref, task, schema, item, phase) {
|
|
196
|
+
if (halted()) return null;
|
|
197
|
+
task = withCommands(task);
|
|
198
|
+
const r = resolveRef(ref, item);
|
|
199
|
+
if (r.error) { stop({ status: "failed", step: stepId, reason: r.error }); return null; }
|
|
200
|
+
const opts = { label: stepId + (item && item.id ? ":" + item.id : "") + " " + r.agentType, phase: phase, agentType: r.agentType, model: r.model, schema: schema };
|
|
201
|
+
if (r.effort) opts.effort = r.effort;
|
|
202
|
+
task = task + guideFor(schema) + midRunAnswersText(stepId, item);
|
|
203
|
+
let out = await agent(context(stepId, item) + "\n\n## Your task\n\n" + task, opts);
|
|
204
|
+
if (out === null || out === undefined) { stop({ status: "failed", step: stepId, reason: r.agentType + " returned no result" }); return null; }
|
|
205
|
+
if (out.status === "blocked" && HANDOFF) {
|
|
206
|
+
// Decider in delivery: the lead developer settles what the standing policy allows; the step
|
|
207
|
+
// runs once more with the decision. Product, copy and security-widening still stop the run.
|
|
208
|
+
const d = await decide(stepId, item, out, phase);
|
|
209
|
+
if (d && d.settled) {
|
|
210
|
+
const again = await agent(context(stepId, item) + "\n\n## Your task\n\n" + task + "\n\nDecision by the delivery decider (recorded, shown at the end): " + d.decision + " Why: " + (d.why || ""), opts);
|
|
211
|
+
if (again && again.status !== "blocked") return again;
|
|
212
|
+
if (again) out = again;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (out.status === "blocked") {
|
|
216
|
+
// With a handoff, a blocker goes back upstream; without one (release) it is reported as is.
|
|
217
|
+
if (HANDOFF) needsUpstream(stepId, item, (out.blocked && out.blocked.reason) || out.summary, (out.blocked && out.blocked.questions) || []);
|
|
218
|
+
else stop({ status: "blocked", step: stepId, item: item && item.id, reason: (out.blocked && out.blocked.reason) || out.summary, questions: (out.blocked && out.blocked.questions) || [] });
|
|
219
|
+
}
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// A downstream stop the people upstream answer: the same run resumes with the answers.
|
|
224
|
+
function needsUpstream(stepId, item, reason, questions, extra) {
|
|
225
|
+
stop(Object.assign({ status: "needs-upstream", step: stepId, item: item && item.id, reason: reason, questions: questions || [],
|
|
226
|
+
resume: "Resume this same run (resumeFromRunId) with args.midRunAnswers [{ step: " + JSON.stringify(stepId) + (item && item.id ? ", item: " + JSON.stringify(item.id) : "") + ", question, answer }] and the same other args; do not edit the handoff argument, or every finished step runs again." }, extra || {}));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Test file -> the task whose red step wrote it. Verify reads it to tell its own failures from
|
|
230
|
+
// another task's planned-red tests in the shared working tree.
|
|
231
|
+
function ownTests(item, files) { (files || []).forEach(function (f) { state.testOwners[f] = item && item.id; }); }
|
|
232
|
+
function ownersText(item) {
|
|
233
|
+
const others = Object.keys(state.testOwners).filter(function (f) { return state.testOwners[f] !== (item && item.id); });
|
|
234
|
+
if (!others.length) return "";
|
|
235
|
+
return "\n\nTest ownership (owned by other tasks; their failures are not this task's):\n" + others.map(function (f) { return "- " + f + ": " + state.testOwners[f]; }).join("\n");
|
|
236
|
+
}
|
|
237
|
+
// A foreign failure counts only when its owner is another known task; anything else is this task's.
|
|
238
|
+
function foreignOk(v, item) {
|
|
239
|
+
const ids = Object.keys(state.testOwners).map(function (f) { return state.testOwners[f]; });
|
|
240
|
+
return (v.foreignFailures || []).every(function (x) { return x.owner && x.owner !== (item && item.id) && ids.indexOf(x.owner) >= 0; });
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
state.decisions = [];
|
|
244
|
+
async function decide(stepId, item, out, phase) {
|
|
245
|
+
if (!DECIDER || !(HANDOFF.deliveryPolicy || A.decider)) return null;
|
|
246
|
+
const r = resolveRef(DECIDER, null);
|
|
247
|
+
if (r.error) return null;
|
|
248
|
+
const q = ((out.blocked && out.blocked.reason) || out.summary) + "\n" + JSON.stringify((out.blocked && out.blocked.questions) || []);
|
|
249
|
+
const d = await agent(context(stepId, item) + "\n\n## Your task\n\n" + DECIDE_BLOCKER + guideFor(SCHEMAS.DECISION) + "\n\nBlocked step " + stepId + (item && item.id ? " (" + item.id + ")" : "") + ":\n" + q,
|
|
250
|
+
{ label: "decide:" + stepId + (item && item.id ? ":" + item.id : "") + " " + r.agentType, phase: phase, agentType: r.agentType, model: r.model, schema: SCHEMAS.DECISION });
|
|
251
|
+
if (d) state.decisions.push({ step: stepId, item: item && item.id, settled: !!d.settled, kind: d.kind, decision: d.decision || null, why: d.why || null });
|
|
252
|
+
const never = ["product", "copy", "security-widening"];
|
|
253
|
+
return d && never.indexOf(d.kind) < 0 ? d : null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function key(stepId, item) { return item && item.id ? stepId + ":" + item.id : stepId; }
|
|
257
|
+
|
|
258
|
+
function collect(stepId, out) {
|
|
259
|
+
if (!out) return;
|
|
260
|
+
state.outputs[stepId] = { summary: out.summary, result: out.result || {} };
|
|
261
|
+
(out.questions || []).forEach(function (q) {
|
|
262
|
+
const id = q.id.indexOf(stepId + ".") === 0 ? q.id : stepId + "." + q.id;
|
|
263
|
+
if (!ANSWERED.has(id) && !ANSWERED.has(q.id)) state.questions.push(Object.assign({}, q, { id: id, step: stepId }));
|
|
264
|
+
});
|
|
265
|
+
(out.assumptions || []).forEach(function (a) {
|
|
266
|
+
const id = a.id.indexOf(stepId + ".") === 0 ? a.id : stepId + "." + a.id;
|
|
267
|
+
if (!ANSWERED.has(id) && !ANSWERED.has(a.id)) state.assumptions.push(Object.assign({}, a, { id: id, step: stepId }));
|
|
268
|
+
});
|
|
269
|
+
(out.gaps || []).forEach(function (g) {
|
|
270
|
+
if (!RESOLVED.has(g.id)) state.gaps.push(Object.assign({}, g, { step: stepId }));
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// A new guard test that already fails on the current repository, with no task or gap that
|
|
275
|
+
// settles it, is an open gap now rather than an upstream return during delivery.
|
|
276
|
+
function guardGaps(stepId, out) {
|
|
277
|
+
(((out && out.result) || {}).guardChecks || []).forEach(function (g) {
|
|
278
|
+
if (g.result !== "fail" || (g.addressedBy || []).length) return;
|
|
279
|
+
const id = "G-guard-" + String(g.test).toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
280
|
+
if (RESOLVED.has(id)) return;
|
|
281
|
+
state.gaps.push({ id: id, area: "testing", gap: "Guard test " + g.test + " already fails on the current repository: " + (g.findings || ""), why: "The task that adds it would be red from the start.", impact: "high", solutions: [{ option: "Add a task that fixes the existing violations first", tradeoff: "more work in this scope" }, { option: "Narrow the guard to new code", tradeoff: "existing violations stay" }], recommended: 0, changesBehaviour: true, step: stepId });
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Git step options: handoff.git, then args.git. Defaults keep the pack's behaviour (open a
|
|
286
|
+
// ready PR that links the handoff); an uncommitted handoff is never linked.
|
|
287
|
+
function gitText() {
|
|
288
|
+
const o = Object.assign({ pr: true, draft: false, linkHandoff: true }, (HANDOFF && HANDOFF.git) || {}, A.git || {});
|
|
289
|
+
const lines = ["Git options for this run (from the handoff and the run arguments; they override the steps above):"];
|
|
290
|
+
if (!o.pr) lines.push("- Do not open a pull request: commit and push the branch, return no prUrl.");
|
|
291
|
+
else lines.push("- Open the pull request" + (o.draft ? " as a draft." : " ready for review (not a draft)."));
|
|
292
|
+
if (o.pr && o.linkHandoff) lines.push("- Link the handoff only if docs/friday/<workId>/handoff.yaml is committed on the pushed branch (git ls-files, no local changes); otherwise name the work id without a link.");
|
|
293
|
+
if (o.pr && !o.linkHandoff) lines.push("- Do not link the handoff; name the work id only.");
|
|
294
|
+
return "\n\n" + lines.join("\n");
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// The retro runs after every finished run, halted or not, and never changes its status.
|
|
298
|
+
function retroFacts() {
|
|
299
|
+
return "\n\nRun facts:\n" + JSON.stringify({
|
|
300
|
+
halt: state.halt, round: ROUND, scopeFrozen: FROZEN,
|
|
301
|
+
reversedAnswers: (A.answers || []).filter(function (a) { return (a.supersedes || []).length; }),
|
|
302
|
+
autoAnswers: state.autoAnswers || [], dropped: state.dropped, deferred: state.deferred,
|
|
303
|
+
redRounds: state.red || [], pyramidViolations: state.violations, foreignFailures: state.foreign,
|
|
304
|
+
trace: state.trace, testChanges: state.testChanges,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
async function retro(ref, task) {
|
|
308
|
+
if (state.halt && (state.halt.status === "needs-input" || state.halt.status === "round-limit")) return null;
|
|
309
|
+
const r = resolveRef(ref, null);
|
|
310
|
+
if (r.error) return null;
|
|
311
|
+
const opts = { label: "retro " + r.agentType, phase: "retro", agentType: r.agentType, model: r.model, schema: SCHEMAS.RETRO };
|
|
312
|
+
if (r.effort) opts.effort = r.effort;
|
|
313
|
+
const out = await agent(context("retro", null) + "\n\n## Your task\n\n" + task + guideFor(SCHEMAS.RETRO) + retroFacts(), opts);
|
|
314
|
+
return out ? { path: out.retroPath, improvements: out.improvements || [] } : null;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function openCount() { return state.questions.length + state.assumptions.length + state.gaps.length + state.contradictions.length; }
|
|
318
|
+
|
|
319
|
+
function deferNonBlocking() {
|
|
320
|
+
if (!WORKFLOW.deferNonBlocking) return;
|
|
321
|
+
["questions", "assumptions", "gaps"].forEach(function (kind) {
|
|
322
|
+
state[kind] = state[kind].filter(function (x) {
|
|
323
|
+
if (x.blocking !== false) return true;
|
|
324
|
+
state.deferred.push({ id: x.id, step: x.step, item: x.question || x.assumption || x.gap });
|
|
325
|
+
return false;
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function openItemsText() {
|
|
331
|
+
const open = { questions: state.questions, assumptions: state.assumptions, gaps: state.gaps };
|
|
332
|
+
return "\n\nOpen items from the steps above (each id must end up in your output, in a mergedFrom, or in dropped):\n" + JSON.stringify(open);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// A consolidating gap analysis replaces this round's open items with its own list. Every earlier
|
|
336
|
+
// item must be accounted for (kept, merged or dropped with a reason); one it skips stays open.
|
|
337
|
+
function consolidate(stepId, out) {
|
|
338
|
+
if (!out) return;
|
|
339
|
+
state.outputs[stepId] = { summary: out.summary, result: out.result || {} };
|
|
340
|
+
const raw = { questions: state.questions, assumptions: state.assumptions, gaps: state.gaps };
|
|
341
|
+
const rawIds = new Set([].concat(raw.questions, raw.assumptions, raw.gaps).map(function (x) { return x.id; }));
|
|
342
|
+
const seen = new Set();
|
|
343
|
+
(out.dropped || []).forEach(function (d) {
|
|
344
|
+
if (!rawIds.has(d.id) || seen.has(d.id)) return;
|
|
345
|
+
seen.add(d.id);
|
|
346
|
+
state.dropped.push({ id: d.id, reason: d.reason, step: stepId });
|
|
347
|
+
});
|
|
348
|
+
// Question and assumption ids carry their step, as in collect(); gap ids do not.
|
|
349
|
+
function take(list, settled, prefix) {
|
|
350
|
+
const kept = [];
|
|
351
|
+
(list || []).forEach(function (x) {
|
|
352
|
+
const id = !prefix || rawIds.has(x.id) || x.id.indexOf(stepId + ".") === 0 ? x.id : stepId + "." + x.id;
|
|
353
|
+
(x.mergedFrom || []).forEach(function (m) { seen.add(m); });
|
|
354
|
+
seen.add(x.id); seen.add(id);
|
|
355
|
+
if (!settled.has(id) && !settled.has(x.id)) kept.push(Object.assign({}, x, { id: id, step: stepId }));
|
|
356
|
+
});
|
|
357
|
+
return kept;
|
|
358
|
+
}
|
|
359
|
+
const next = {
|
|
360
|
+
questions: take(out.questions, ANSWERED, true),
|
|
361
|
+
assumptions: take(out.assumptions, ANSWERED, true),
|
|
362
|
+
gaps: take(out.gaps, RESOLVED, false),
|
|
363
|
+
};
|
|
364
|
+
Object.keys(raw).forEach(function (k) {
|
|
365
|
+
raw[k].forEach(function (x) { if (!seen.has(x.id)) next[k].push(x); });
|
|
366
|
+
});
|
|
367
|
+
state.questions = next.questions; state.assumptions = next.assumptions; state.gaps = next.gaps;
|
|
368
|
+
(out.contradictions || []).forEach(function (c) {
|
|
369
|
+
if (!ANSWERED.has(c.id)) state.contradictions.push(Object.assign({}, c, { step: stepId }));
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Dedup across perspectives: one item per topic (the first keeps its id, the rest are listed
|
|
374
|
+
// in mergedFrom), and an item whose topic a recorded answer already covers is dropped with the
|
|
375
|
+
// reason, unless it says it contradicts that answer.
|
|
376
|
+
const ANSWERED_TOPICS = {};
|
|
377
|
+
(A.answers || []).forEach(function (a) { if (a.topic) ANSWERED_TOPICS[a.topic] = a.id; });
|
|
378
|
+
function dedupe() {
|
|
379
|
+
const byTopic = {};
|
|
380
|
+
function pass(list) {
|
|
381
|
+
const out = [];
|
|
382
|
+
list.forEach(function (x) {
|
|
383
|
+
if (!x.topic) { out.push(x); return; }
|
|
384
|
+
const t = x.topic;
|
|
385
|
+
if (ANSWERED_TOPICS[t] && !(x.contradicts || []).length) {
|
|
386
|
+
state.dropped.push({ id: x.id, reason: "topic " + t + " is settled by answer " + ANSWERED_TOPICS[t], step: x.step });
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
if (byTopic[t]) { byTopic[t].mergedFrom = (byTopic[t].mergedFrom || []).concat([x.id]); return; }
|
|
390
|
+
byTopic[t] = x; out.push(x);
|
|
391
|
+
});
|
|
392
|
+
return out;
|
|
393
|
+
}
|
|
394
|
+
state.questions = pass(state.questions); state.assumptions = pass(state.assumptions); state.gaps = pass(state.gaps);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Close-out (args.closeOut, the user's choice): only blockers or contradictions go to the user;
|
|
398
|
+
// the rest take the recommended option, recorded as answers marked by close-out.
|
|
399
|
+
const CLOSE_OUT = A.closeOut === true;
|
|
400
|
+
state.autoAnswers = [];
|
|
401
|
+
function closeOut() {
|
|
402
|
+
if (!CLOSE_OUT) return;
|
|
403
|
+
function keep(x) { return x.blocking !== false || (x.contradicts || []).length > 0; }
|
|
404
|
+
function auto(x, answer) { state.autoAnswers.push({ id: x.id, question: x.question || x.assumption || x.gap, answer: answer, by: "close-out" }); }
|
|
405
|
+
state.questions = state.questions.filter(function (x) {
|
|
406
|
+
if (keep(x)) return true;
|
|
407
|
+
auto(x, ((x.options || [])[x.recommended] || {}).label || "recommended option"); return false;
|
|
408
|
+
});
|
|
409
|
+
state.assumptions = state.assumptions.filter(function (x) { if (keep(x)) return true; auto(x, "Confirmed"); return false; });
|
|
410
|
+
state.gaps = state.gaps.filter(function (x) {
|
|
411
|
+
if (keep(x)) return true;
|
|
412
|
+
auto(x, ((x.solutions || [])[x.recommended] || {}).option || "recommended solution"); return false;
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Per-round cap (args.maxItemsPerRound or the workflow's): contradictions always show; then
|
|
417
|
+
// behaviour-changing items; the rest are held for the next round, listed in heldBack.
|
|
418
|
+
function cap() {
|
|
419
|
+
const max = count(A.maxItemsPerRound || WORKFLOW.maxItemsPerRound, 0);
|
|
420
|
+
if (!max) return [];
|
|
421
|
+
let room = max - state.contradictions.length;
|
|
422
|
+
if (room < 0) room = 0;
|
|
423
|
+
const held = [];
|
|
424
|
+
["questions", "assumptions", "gaps"].forEach(function (k) {
|
|
425
|
+
const first = state[k].filter(function (x) { return x.changesBehaviour !== false; });
|
|
426
|
+
const rest = state[k].filter(function (x) { return x.changesBehaviour === false; });
|
|
427
|
+
state[k] = first.concat(rest);
|
|
428
|
+
});
|
|
429
|
+
["questions", "assumptions", "gaps"].forEach(function (k) {
|
|
430
|
+
const shown = state[k].slice(0, room);
|
|
431
|
+
state[k].slice(room).forEach(function (x) { held.push({ id: x.id, step: x.step, item: x.question || x.assumption || x.gap }); });
|
|
432
|
+
room -= shown.length; state[k] = shown;
|
|
433
|
+
});
|
|
434
|
+
return held;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function needsInput(stepId) {
|
|
438
|
+
dedupe();
|
|
439
|
+
deferNonBlocking();
|
|
440
|
+
closeOut();
|
|
441
|
+
if (!FROZEN && openCount() === 0) return;
|
|
442
|
+
if (FROZEN) {
|
|
443
|
+
// The user froze the scope: what is still open is deferred, not asked, and the run goes on.
|
|
444
|
+
state.questions.concat(state.assumptions, state.gaps).forEach(function (x) {
|
|
445
|
+
state.deferred.push({ id: x.id, step: x.step, item: x.question || x.assumption || x.gap });
|
|
446
|
+
});
|
|
447
|
+
state.questions = []; state.assumptions = []; state.gaps = [];
|
|
448
|
+
// Contradictions are never deferred: no task can be built on two answers that conflict.
|
|
449
|
+
if (!state.contradictions.length) return;
|
|
450
|
+
}
|
|
451
|
+
const limit = !FROZEN && ROUND_LIMIT !== null && ROUND >= ROUND_LIMIT;
|
|
452
|
+
const heldBack = cap();
|
|
453
|
+
stop({
|
|
454
|
+
status: limit ? "round-limit" : "needs-input",
|
|
455
|
+
step: stepId,
|
|
456
|
+
round: ROUND,
|
|
457
|
+
roundLimit: ROUND_LIMIT,
|
|
458
|
+
workId: A.workId,
|
|
459
|
+
questions: state.questions,
|
|
460
|
+
assumptions: state.assumptions,
|
|
461
|
+
gaps: state.gaps,
|
|
462
|
+
contradictions: state.contradictions,
|
|
463
|
+
dropped: state.dropped,
|
|
464
|
+
heldBack: heldBack,
|
|
465
|
+
autoAnswers: state.autoAnswers,
|
|
466
|
+
outputs: state.outputs,
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Waves follow dependsOn (with order "dependsOn"). Tasks share one working tree, so two tasks
|
|
471
|
+
// with the same codebase never run in the same wave: the later one waits (decision 51).
|
|
472
|
+
function waves(items, order) {
|
|
473
|
+
const done = new Set();
|
|
474
|
+
const left = items.slice();
|
|
475
|
+
const out = [];
|
|
476
|
+
while (left.length) {
|
|
477
|
+
const ready = left.filter(function (t) {
|
|
478
|
+
if (order !== "dependsOn") return true;
|
|
479
|
+
return (t.dependsOn || []).every(function (d) { return done.has(d) || !items.some(function (i) { return i.id === d; }); });
|
|
480
|
+
});
|
|
481
|
+
if (!ready.length) { stop({ status: "failed", step: "foreach", reason: "dependency cycle between tasks: " + left.map(function (t) { return t.id; }).join(", ") }); return []; }
|
|
482
|
+
const codebases = new Set();
|
|
483
|
+
const wave = ready.filter(function (t) {
|
|
484
|
+
if (!t.codebase) return true;
|
|
485
|
+
if (codebases.has(t.codebase)) return false;
|
|
486
|
+
codebases.add(t.codebase);
|
|
487
|
+
return true;
|
|
488
|
+
});
|
|
489
|
+
wave.forEach(function (t) { done.add(t.id); left.splice(left.indexOf(t), 1); });
|
|
490
|
+
out.push(wave);
|
|
491
|
+
}
|
|
492
|
+
return out;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// Tasks started and finished green in this run; a breaking task leaves its codebases red from
|
|
496
|
+
// its start until its closedBy tasks are done (decision 50).
|
|
497
|
+
function markSeen(item) { if (item && item.id && state.seen.indexOf(item.id) < 0) state.seen.push(item.id); }
|
|
498
|
+
function markDone(item) { if (item && item.id && state.done.indexOf(item.id) < 0) state.done.push(item.id); }
|
|
499
|
+
function openBreaks() {
|
|
500
|
+
return ((HANDOFF && HANDOFF.tasks) || []).filter(function (t) {
|
|
501
|
+
return (t.breaks || []).length && state.seen.indexOf(t.id) >= 0;
|
|
502
|
+
}).map(function (t) {
|
|
503
|
+
return { task: t.id, codebases: t.breaks, until: (t.closedBy || []).filter(function (c) { return state.done.indexOf(c) < 0; }) };
|
|
504
|
+
}).filter(function (b) { return b.until.length > 0; });
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// Breakdown: every scope acceptance criterion maps to at least one task (decision 50). "AC1"
|
|
508
|
+
// covers "AC1: ..." but not "AC12: ..." (the same rule as friday handoff check).
|
|
509
|
+
function coversCriterion(entry, criterion) {
|
|
510
|
+
const e = String(entry).trim();
|
|
511
|
+
const c = String(criterion).trim();
|
|
512
|
+
if (!e) return false;
|
|
513
|
+
return c === e || (c.indexOf(e) === 0 && !/[A-Za-z0-9]/.test(c.charAt(e.length)));
|
|
514
|
+
}
|
|
515
|
+
function coverageGaps(stepId, out) {
|
|
516
|
+
if (!out || !out.result) return;
|
|
517
|
+
const acs = out.result.acceptance || [];
|
|
518
|
+
const tasks = out.result.tasks || [];
|
|
519
|
+
const add = function (g) {
|
|
520
|
+
if (!RESOLVED.has(g.id)) state.gaps.push(Object.assign({ area: "scope", impact: "high", topic: "acceptance-coverage", blocking: true, changesBehaviour: true, step: stepId }, g));
|
|
521
|
+
};
|
|
522
|
+
acs.forEach(function (ac, i) {
|
|
523
|
+
if (tasks.some(function (t) { return (t.covers || []).some(function (e) { return coversCriterion(e, ac); }); })) return;
|
|
524
|
+
const m = /^([A-Za-z]+[-_]?[0-9]+)/.exec(String(ac).trim());
|
|
525
|
+
add({
|
|
526
|
+
id: "G-coverage-" + (m ? m[1] : "ac" + (i + 1)),
|
|
527
|
+
gap: "Acceptance criterion not covered by any task: " + ac,
|
|
528
|
+
why: "Every scope acceptance criterion must map to at least one task (covers), or nobody builds and tests it.",
|
|
529
|
+
solutions: [
|
|
530
|
+
{ option: "Add it to the covers of the task that proves it", tradeoff: "None if that task really proves it." },
|
|
531
|
+
{ option: "Add a task for it", tradeoff: "More work, but the criterion has an owner." },
|
|
532
|
+
{ option: "Drop it from the scope", tradeoff: "The criterion is not delivered." },
|
|
533
|
+
],
|
|
534
|
+
recommended: 0,
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
tasks.forEach(function (t) {
|
|
538
|
+
(t.covers || []).forEach(function (e) {
|
|
539
|
+
if (acs.some(function (ac) { return coversCriterion(e, ac); })) return;
|
|
540
|
+
add({
|
|
541
|
+
id: "G-coverage-" + t.id + "-" + String(e).trim().replace(/[^A-Za-z0-9]+/g, "-").slice(0, 24),
|
|
542
|
+
gap: "Task " + t.id + " covers \"" + e + "\", which is no scope acceptance criterion.",
|
|
543
|
+
why: "covers must name a scope acceptance criterion by its id or the start of its text.",
|
|
544
|
+
solutions: [{ option: "Fix the reference", tradeoff: "None." }, { option: "Add the criterion to the scope", tradeoff: "The scope grows." }],
|
|
545
|
+
recommended: 0,
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function listFor(over) {
|
|
552
|
+
if (over === "handoff.tasks") return (HANDOFF && HANDOFF.tasks) || [];
|
|
553
|
+
if (over === "handoff.stacks") {
|
|
554
|
+
const by = {};
|
|
555
|
+
((HANDOFF && HANDOFF.tasks) || []).forEach(function (t) { (by[t.stack] = by[t.stack] || []).push(t.id); });
|
|
556
|
+
return Object.keys(by).map(function (s) { return { id: s, stack: s, tasks: by[s] }; });
|
|
557
|
+
}
|
|
558
|
+
const stepId = over.split(".")[0];
|
|
559
|
+
const o = state.outputs[stepId];
|
|
560
|
+
return (o && o.result && o.result.tasks) || [];
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// Test pyramid: commands a task loop ran that belong to integration (emulators, e2e).
|
|
564
|
+
// Mapped commands of the levels above the loop are forbidden too, whatever their script names.
|
|
565
|
+
const FORBIDDEN = FORBIDDEN_IN_LOOP.concat([].concat.apply([], Object.keys(COMMANDS).filter(function (id) {
|
|
566
|
+
return LOOP_LEVELS.indexOf(id) < 0;
|
|
567
|
+
}).map(function (id) { return COMMANDS[id] || []; })));
|
|
568
|
+
function violations(cmds) {
|
|
569
|
+
return (cmds || []).filter(function (c) {
|
|
570
|
+
return FORBIDDEN.some(function (f) { return String(c).indexOf(f) >= 0; });
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// Evidence before green (decision 44): an agent saying a suite passed is not evidence. Verify's
|
|
575
|
+
// green counts only when the commands it ran, each with its exit code, cover every level in scope:
|
|
576
|
+
// a level is covered by a command that matches one of its mapped commands, where <placeholder>
|
|
577
|
+
// stands for any text. Every exit code is 0, unless the failures are known to be another task's.
|
|
578
|
+
function commandPattern(c) {
|
|
579
|
+
return new RegExp(String(c).split(/<[^>]+>/).map(function (p) { return p.replace(/[.*+?^$()|[\]\\{}]/g, "\\$&"); }).join(".+?"));
|
|
580
|
+
}
|
|
581
|
+
function scopeCommands(id) { return (COMMANDS[id] && COMMANDS[id].length) ? COMMANDS[id] : (LEVELS[id] || []); }
|
|
582
|
+
function evidenceCommands(v) { return (Array.isArray(v && v.evidence) ? v.evidence : []).map(function (e) { return e && e.command; }).filter(Boolean); }
|
|
583
|
+
// The test pyramid (decision 47): a task's tests sit at the lowest level that proves each
|
|
584
|
+
// criterion, so verify needs evidence only for the levels the task's tests are at, plus the static
|
|
585
|
+
// checks at the bottom. A task proven only above the loop's scope (integration) needs the static
|
|
586
|
+
// checks here; integration runs the rest.
|
|
587
|
+
state.testLevels = {};
|
|
588
|
+
// Every decision on a test conflict, kept or changed, with its justification (decision 47).
|
|
589
|
+
state.testChanges = [];
|
|
590
|
+
function recordLevels(item, levels) {
|
|
591
|
+
const ids = Object.keys(LEVELS);
|
|
592
|
+
const ok = (levels || []).filter(function (l) { return ids.indexOf(l) >= 0; });
|
|
593
|
+
if (ok.length) state.testLevels[(item && item.id) || ""] = ok;
|
|
594
|
+
}
|
|
595
|
+
function requiredLevels(scope, item) {
|
|
596
|
+
const bottom = Object.keys(LEVELS)[0];
|
|
597
|
+
const own = state.testLevels[(item && item.id) || ""] || [(item && item.lowestLevel) || "unit"];
|
|
598
|
+
return scope.filter(function (id) { return id === bottom || own.indexOf(id) >= 0; });
|
|
599
|
+
}
|
|
600
|
+
function evidenceGaps(v, scope, item) {
|
|
601
|
+
const ev = Array.isArray(v && v.evidence) ? v.evidence : [];
|
|
602
|
+
const gaps = [];
|
|
603
|
+
requiredLevels(scope, item).forEach(function (id) {
|
|
604
|
+
const mapped = scopeCommands(id);
|
|
605
|
+
if (!mapped.length) return;
|
|
606
|
+
const res = mapped.map(commandPattern);
|
|
607
|
+
const ran = ev.some(function (e) { return res.some(function (re) { return re.test(String(e && e.command)); }); });
|
|
608
|
+
if (!ran) gaps.push("no evidence for level " + id + ": run " + mapped.join(" or ") + " and report it with its exit code");
|
|
609
|
+
});
|
|
610
|
+
const failed = ev.filter(function (e) { return !e || e.exitCode !== 0; });
|
|
611
|
+
const foreign = (v.foreignFailures || []).length > 0 && foreignOk(v, item);
|
|
612
|
+
if (failed.length && !foreign) gaps.push("non-zero exit code: " + failed.map(function (e) { return (e && e.command) + " -> " + (e && e.exitCode); }).join("; "));
|
|
613
|
+
return gaps;
|
|
614
|
+
}
|
|
615
|
+
// Integration is green only when every level in scope is reported and none failed.
|
|
616
|
+
function suiteGaps(r, scope) {
|
|
617
|
+
const suites = r.suites || [];
|
|
618
|
+
const gaps = scope.filter(function (id) { return !suites.some(function (x) { return x.level === id; }); }).map(function (id) { return "no suite reported for level " + id; });
|
|
619
|
+
suites.filter(function (x) { return x.result === "fail"; }).forEach(function (x) { gaps.push("suite " + x.level + " failed: " + x.command); });
|
|
620
|
+
return gaps;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function recordViolations(stepId, item, bad) {
|
|
624
|
+
bad.forEach(function (c) { state.violations.push({ step: stepId, item: item && item.id, command: c }); });
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// Follow-up ids are prefixed per round; dependsOn between follow-ups is renamed with them.
|
|
628
|
+
function renameFollowups(list, round) {
|
|
629
|
+
const map = {};
|
|
630
|
+
list.forEach(function (t, i) { map[t.id || String(i)] = "F" + round + "-" + (t.id || String(i)); });
|
|
631
|
+
return list.map(function (t, i) {
|
|
632
|
+
return Object.assign({}, t, {
|
|
633
|
+
id: map[t.id || String(i)],
|
|
634
|
+
dependsOn: (t.dependsOn || []).map(function (d) { return map[d] || d; }),
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// One integration item per stack that has tasks or follow-ups.
|
|
640
|
+
function integrationItems(followups) {
|
|
641
|
+
const by = {};
|
|
642
|
+
((HANDOFF && HANDOFF.tasks) || []).concat(followups).forEach(function (t) { (by[t.stack] = by[t.stack] || []).push(t.id); });
|
|
643
|
+
return Object.keys(by).map(function (s) { return { id: s, stack: s, tasks: by[s] }; });
|
|
644
|
+
}
|
|
645
|
+
`;
|