@sabaiway/agent-workflow-kit 19.4.0 → 20.0.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +17 -9
  3. package/SKILL.md +6 -6
  4. package/capability.json +1 -1
  5. package/migrations/1.1.0-communication-language.md +2 -4
  6. package/migrations/1.2.0-agent-attribution.md +1 -3
  7. package/migrations/5.0.0-kit-text-in-kit-files.md +30 -0
  8. package/migrations/README.md +2 -2
  9. package/package.json +1 -1
  10. package/references/advisor-writers.md +1 -1
  11. package/references/contracts.md +9 -11
  12. package/references/modes/bootstrap.md +2 -4
  13. package/references/modes/hook.md +1 -1
  14. package/references/modes/procedures.md +1 -1
  15. package/references/modes/recommendations.md +1 -1
  16. package/references/modes/rules.md +4 -3
  17. package/references/modes/upgrade.md +23 -49
  18. package/references/modes/velocity.md +1 -1
  19. package/references/reference-profile.json +0 -6
  20. package/references/rules/communication.md +22 -0
  21. package/references/rules/project-layout.md +2 -0
  22. package/references/rules/story-sessions.md +14 -0
  23. package/references/scripts/spec-schema.mjs +1 -3
  24. package/references/scripts/spec-schema.test.mjs +6 -6
  25. package/references/shared/composition-handoff.md +24 -59
  26. package/references/shared/deploy-tail.md +2 -2
  27. package/references/templates/AGENTS.md +0 -10
  28. package/references/templates/agent_rules.md +0 -33
  29. package/references/templates/specs/index.md +1 -1
  30. package/tools/cheap-agents-read.mjs +1 -1
  31. package/tools/delegation.mjs +5 -8
  32. package/tools/engine-source.mjs +13 -11
  33. package/tools/family-registry.mjs +4 -5
  34. package/tools/inject-methodology.mjs +153 -493
  35. package/tools/migration-blocks.mjs +0 -6
  36. package/tools/orchestration-readme.mjs +1 -1
  37. package/tools/profile-gap-screen.mjs +2 -6
  38. package/tools/profile-gaps.mjs +19 -100
  39. package/tools/project-rules/index.mjs +1 -2
  40. package/tools/project-rules/rules-ensure.mjs +37 -6
  41. package/tools/project-rules/rules-priors.mjs +1 -0
  42. package/tools/project-rules/themes.mjs +13 -5
  43. package/tools/script-priors.mjs +2 -0
  44. package/tools/transition/index.mjs +214 -0
  45. package/tools/upgrade-runlist.mjs +2 -17
  46. package/tools/velocity-profile.mjs +1 -1
  47. package/tools/lens-region.mjs +0 -281
  48. package/tools/project-rules/memory-map-row.mjs +0 -81
  49. package/tools/rules-insert.mjs +0 -203
  50. package/tools/rules-regions.mjs +0 -190
@@ -1,190 +0,0 @@
1
- import { fileURLToPath } from 'node:url';
2
-
3
- const LF = String.fromCharCode(10);
4
- const CR = String.fromCharCode(13);
5
- const CRLF = CR + LF;
6
- const BACKSLASH = String.fromCharCode(92);
7
- const FRONTMATTER_BOUNDARY = '---';
8
- const STRUCTURAL_HEADING_RE = /^#{2,3} /;
9
- const NUMBERED_HEADING_RE = /^### 2[.]([0-9]+)[.]/;
10
- const NUMBERED_HEADING_PREFIX = '### 2.';
11
- const MAX_LINES_RE = new RegExp('^maxLines:' + BACKSLASH + 's*([0-9]+)' + BACKSLASH + 's*$');
12
- const TEMPLATE_CANON = 'template';
13
- const HEADING_COUNT_DEFECT = 'heading-count';
14
- const HEADING_TWICE_REFUSAL = 'heading-twice';
15
- const ANCHOR_ABSENT_REFUSAL = 'anchor-absent';
16
- const CAP_REFUSAL = 'cap';
17
- const SINGLE_HEADING = 1;
18
- const NOT_FOUND = -1;
19
- const UTF8_LABEL = 'utf-8';
20
- const UTF8_ENCODING = 'utf8';
21
- const ROUND_TRIP_MESSAGE = 'the bytes read do not survive a UTF-8 round trip';
22
- const BOM_CHAR = String.fromCharCode(65279);
23
- const INSERT_PATH = fileURLToPath(new URL('./rules-insert.mjs', import.meta.url));
24
- const COMMAND_UNSAFE_RE = /[\u0000-\u001f\u007f`]/;
25
- const SHELL_PLAIN_RE = /^[A-Za-z0-9_./-]+$/;
26
- const SINGLE_QUOTE = "'";
27
- const QUOTE_ESCAPE = "'\\''";
28
-
29
- // Append the OUTGOING canon here in the same release that changes the template
30
- // §2.5 or §2.7 region — the fragment-or-prior reconcile depends on it.
31
- const COMMS_PRIOR_PRE_AD054 = `### 2.x. Communication (user-facing messages)
32
- Apply this as part of §2 before any user-facing summary:
33
- - **Deliver the artifact IN the message** — paste the prompt / diff / version / command inline; never "see §X / open the file / run it and you'll see" as a *substitute* for showing what was asked.
34
- - **Lead with the result**, then the details; show exactly what was asked — no deflection, no "almost done" when the ask was the finished thing.
35
- - **No condescension, no filler.** Own a miss plainly and fix it in the same message.
36
- - **Large artifact (≈>100 lines):** deliver a real summary or the key excerpt inline **and** link the file — never flood the reader with a 2000-line paste, never hide the answer behind a bare pointer.`;
37
- const COMMS_PRIOR_AD054 = `${COMMS_PRIOR_PRE_AD054}
38
- - **Live host/session facts are tool-composed only.** Any claim about the current host or session state (prompts fired, sandbox scope, whether a bypass was needed, network reachability, approval counts) must trace to **live tool output** from **this session**; a memory/handover snapshot is **context, never report facts**, and a claim with no live signal is **omitted or explicitly marked unverified** — never asserted from recollection.`;
39
- const COMMS_PRIOR_PLAIN_LANGUAGE = `### 2.x. Communication (user-facing messages)
40
- Apply this as part of §2 before any user-facing summary:
41
- - **Plain language.** User-facing narration is short, clear, plain words of the dialogue language; when the dialogue language is not English, transliterated English jargon is banned — an English term survives only as the NAME of a thing (a flag / command / file / test), glossed in plain words when helpful; plain English stays plain for English-dialogue users.
42
- - **Deliver the artifact IN the message** — paste the prompt / diff / version / command inline; never "see §X / open the file / run it and you'll see" as a *substitute* for showing what was asked.
43
- - **Lead with the result**, then the details; show exactly what was asked — no deflection, no "almost done" when the ask was the finished thing.
44
- - **No condescension, no filler.** Own a miss plainly and fix it in the same message.
45
- - **Large artifact (≈>100 lines):** deliver a real summary or the key excerpt inline **and** link the file — never flood the reader with a 2000-line paste, never hide the answer behind a bare pointer.
46
- - **Live host/session facts are tool-composed only.** Any claim about the current host or session state (prompts fired, sandbox scope, whether a bypass was needed, network reachability, approval counts) must trace to **live tool output** from **this session**; a memory/handover snapshot is **context, never report facts**, and a claim with no live signal is **omitted or explicitly marked unverified** — never asserted from recollection.`;
47
- const COMMS_PRIOR_STATE_BLOCK = `${COMMS_PRIOR_PLAIN_LANGUAGE}
48
- - **The closing state block answers three DIFFERENT questions.** Close a user-facing message with three labelled slots — *now* · *what I need from you* · *what's next*. The slot LABELS stay ENGLISH — an English label is what lets a state-block checker FIND the block and its slots at all; everything written INTO a slot is in the project's dialogue language; when that language is not English, the checker's English phrase sets do not judge those values. **Now** = the state at this instant: what is RUNNING, or what the work is stopped on. It is **never a report of finished work** — what you completed goes in the message BODY, above the block. **From you** = the real unblocker, named; a turn that is ENDING always has one. **Next** = what follows. A *now* slot that opens with what was completed buries the one fact the reader opened the message for, and the three slots collapse into one restatement.`;
49
- const COMMS_PRIOR_SKIP_FINDING = `${COMMS_PRIOR_STATE_BLOCK}
50
- - **A skip that contradicts the tree is a finding.** A tool-composed \`skipped-*\` line whose stated reason the observed tree disproves (a "no Node" skip beside deployed Node scripts) is raised as a FINDING in the report, never pasted as a neutral outcome — and a tool may not emit a skip whose reason it could itself disprove.`;
51
- const COMMS_PRIORS = [
52
- COMMS_PRIOR_PRE_AD054, COMMS_PRIOR_AD054, COMMS_PRIOR_PLAIN_LANGUAGE, COMMS_PRIOR_STATE_BLOCK, COMMS_PRIOR_SKIP_FINDING,
53
- ];
54
- const STORY_PRIOR_FIVE_SESSIONS = `### 2.x. Story sessions
55
- A story — one row of an epic's ledger, carried by one plan — runs as five sessions, each ending at its own review checkpoint: **spec** (the contract under \`docs/ai/specs/\`, drafted and reviewed on the \`plan-authoring\` recipe), **plan** (the ledger, same recipe), **tests** (one task per ledger row, red first), **code** (one task per row, to green), and **diff review, release and record** (the review of the staged tree on the \`plan-execution\` recipe, the release where the story ships one, then the changelog and handover entries and the plan's Phase: Cleanup). Tests and code never share a session, and a spec and its plan never share one either. A storyless plan runs the same five. **Exception — a split:** moving code and its existing cases into modules, with no new logic and no new case, is one session: a short spec (the Module list), the split, the diff review, the release, Cleanup.`;
56
- const STORY_PRIOR_ONE_TASK = `${STORY_PRIOR_FIVE_SESSIONS} Inside the tests and code sessions it is one task per session: each task runs as its own carrier session — one brief, one run, never one run for a whole wave — and the orchestrator's session briefs, checks, verifies and folds.`;
57
-
58
- export const RULES_REGIONS = Object.freeze([
59
- Object.freeze({
60
- id: 'communication',
61
- headingRe: /^### 2[.]([0-9]+)[.] Communication [(]user-facing messages[)]/,
62
- label: '### 2.x. Communication (user-facing messages)',
63
- canon: TEMPLATE_CANON,
64
- priors: COMMS_PRIORS,
65
- }),
66
- Object.freeze({
67
- id: 'story-sessions',
68
- headingRe: /^### 2[.]([0-9]+)[.] Story sessions/,
69
- label: '### 2.x. Story sessions',
70
- canon: TEMPLATE_CANON,
71
- priors: [STORY_PRIOR_FIVE_SESSIONS, STORY_PRIOR_ONE_TASK],
72
- }),
73
- Object.freeze({
74
- id: 'lens',
75
- headingRe: /^### 2[.]([0-9]+)[.] Planning, review & process-fidelity/,
76
- label: '### 2.x. Planning, review & process-fidelity invariants',
77
- canon: 'engine',
78
- priors: [],
79
- }),
80
- ]);
81
- const TEMPLATE_REGIONS = RULES_REGIONS.filter(({ canon }) => canon === TEMPLATE_CANON);
82
-
83
- const stripCr = (line) => (line.endsWith(CR) ? line.slice(0, -1) : line);
84
- const isBoundary = (line) => line === FRONTMATTER_BOUNDARY || STRUCTURAL_HEADING_RE.test(line);
85
- const lineCount = (text) => text.split(LF).length - (text.endsWith(LF) ? 1 : 0);
86
- const findHeadings = (lines, headingRe) => lines.flatMap((line, index) => {
87
- const match = stripCr(line).match(headingRe);
88
- return match ? [{ index, number: match[1] }] : [];
89
- });
90
- const regionEnd = (lines, start) => {
91
- const afterHeading = start + 1;
92
- const boundary = lines.slice(afterHeading).findIndex((line) => isBoundary(stripCr(line)));
93
- return boundary === NOT_FOUND ? lines.length : afterHeading + boundary;
94
- };
95
-
96
- export const extractRegionBy = (text, headingRe) => {
97
- const lines = String(text).split(LF);
98
- const headings = findHeadings(lines, headingRe);
99
- const count = headings.length;
100
- if (count === 0) return { found: false, count: 0 };
101
- const { index: start, number } = headings[0];
102
- const end = regionEnd(lines, start);
103
- const regionLines = lines.slice(start, end).map(stripCr);
104
- const bodyEnd = regionLines.findLastIndex((line) => line.trim() !== '') + 1;
105
- const body = regionLines.slice(0, bodyEnd).join(LF);
106
- return { found: true, count, start, end, number, body };
107
- };
108
-
109
- export const readTemplateSpan = (text, headingRe) => {
110
- const region = extractRegionBy(text, headingRe);
111
- if (region.count !== SINGLE_HEADING) return { defect: HEADING_COUNT_DEFECT };
112
- const span = String(text).split(LF).slice(region.start, region.end).map(stripCr).join(LF);
113
- return { span, number: region.number };
114
- };
115
-
116
- // A reader that will WRITE the whole document back must not decode leniently: readFileSync(path,
117
- // 'utf8') turns an invalid byte into U+FFFD, and the rewrite would carry that substitution into
118
- // bytes nobody asked to change. The guarantee the callers need is not "the decoder is strict" but
119
- // "re-encoding gives back the bytes we read" — so it is asserted, not reasoned about: any decoder
120
- // asymmetry (a substitution, a stripped byte-order mark) fails here rather than in the written file.
121
- // Bytes in, text out, or one throw the caller answers by its own name.
122
- export const decodeUtf8Strict = (bytes) => {
123
- const text = new TextDecoder(UTF8_LABEL, { fatal: true, ignoreBOM: true }).decode(bytes);
124
- if (!Buffer.from(text, UTF8_ENCODING).equals(bytes)) throw new Error(ROUND_TRIP_MESSAGE);
125
- return text;
126
- };
127
-
128
- // The decoded text KEEPS a leading byte-order mark, because the writer must give the bytes back
129
- // exactly; a structural reader must therefore look past it, or a file that declares maxLines reads
130
- // as one that declares none. Only judgement skips it — never the text any offset is computed over.
131
- export const frontmatterMaxLines = (text) => {
132
- const lines = String(text).split(LF).map(stripCr);
133
- const opening = lines[0]?.startsWith(BOM_CHAR) ? lines[0].slice(BOM_CHAR.length) : lines[0];
134
- if (opening !== FRONTMATTER_BOUNDARY) return null;
135
- for (const line of lines.slice(1)) {
136
- if (line === FRONTMATTER_BOUNDARY) return null;
137
- const match = line.match(MAX_LINES_RE);
138
- if (match) return Number(match[1]);
139
- }
140
- return null;
141
- };
142
-
143
- export const exceedsCap = (text, cap) => {
144
- const count = lineCount(text);
145
- const skipped = cap === null;
146
- return { over: !skipped && count > cap, count, skipped };
147
- };
148
-
149
- export const planInsert = ({ text, spans, cap }) => {
150
- const regions = TEMPLATE_REGIONS.map(({ id, headingRe }) => ({
151
- id,
152
- region: extractRegionBy(text, headingRe),
153
- }));
154
- const doubled = regions.find(({ region }) => region.count > SINGLE_HEADING);
155
- if (doubled) return { refusal: HEADING_TWICE_REFUSAL, region: doubled.id };
156
- const missing = regions.filter(({ region }) => !region.found);
157
- if (missing.length === 0) return { planned: [], text };
158
- const lines = text.split(LF);
159
- const headings = findHeadings(lines, NUMBERED_HEADING_RE);
160
- if (headings.length === 0) return { refusal: ANCHOR_ABSENT_REFUSAL };
161
- const insertAt = regionEnd(lines, headings.at(-1).index);
162
- const highestNumber = Math.max(...headings.map(({ number }) => Number(number)));
163
- const planned = missing.map(({ id }, index) => ({
164
- id,
165
- number: String(highestNumber + index + 1),
166
- insertAt,
167
- }));
168
- const newline = text.includes(CRLF) ? CRLF : LF;
169
- const offset = insertAt === lines.length
170
- ? text.length
171
- : lines.slice(0, insertAt).reduce((length, line) => length + line.length + LF.length, 0);
172
- const prefix = offset === text.length && !text.endsWith(LF) ? newline : '';
173
- const inserted = planned.map(({ id, number }) => {
174
- const bound = spans[id].span.replace(NUMBERED_HEADING_RE, NUMBERED_HEADING_PREFIX + number + '.');
175
- return bound.split(LF).map(stripCr).join(newline) + newline;
176
- }).join('');
177
- const resultText = text.slice(0, offset) + prefix + inserted + text.slice(offset);
178
- const decision = exceedsCap(resultText, cap);
179
- if (decision.over) return { refusal: CAP_REFUSAL, count: decision.count, cap };
180
- return { planned, text: resultText };
181
- };
182
-
183
- const shellWord = (path) => SHELL_PLAIN_RE.test(path)
184
- ? path
185
- : SINGLE_QUOTE + path.split(SINGLE_QUOTE).join(QUOTE_ESCAPE) + SINGLE_QUOTE;
186
-
187
- export const buildInsertPreview = (root, insertPath = INSERT_PATH) => {
188
- if ([root, insertPath].some((path) => COMMAND_UNSAFE_RE.test(path))) return '';
189
- return 'node ' + shellWord(insertPath) + ' --cwd ' + shellWord(root);
190
- };