@sabaiway/agent-workflow-kit 23.12.0 → 24.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.
- package/CHANGELOG.md +58 -0
- package/README.md +4 -4
- package/SKILL.md +1 -1
- package/bridges/codex-cli-bridge/SKILL.md +7 -2
- package/bridges/codex-cli-bridge/bin/codex-exec-jev.test.mjs +11 -6
- package/bridges/codex-cli-bridge/bin/codex-exec.sh +72 -33
- package/bridges/codex-cli-bridge/bin/codex-exec.test.mjs +111 -3
- package/bridges/codex-cli-bridge/bin/codex-fixtures-harness.test.mjs +16 -1
- package/bridges/codex-cli-bridge/bin/codex-model-posture.test.mjs +5 -3
- package/bridges/codex-cli-bridge/bin/codex-review.sh +1 -1
- package/bridges/codex-cli-bridge/capability.json +2 -2
- package/capability.json +1 -1
- package/package.json +1 -1
- package/references/advisor-writers.md +2 -0
- package/references/agents/author.md +21 -0
- package/references/agents/executor.md +12 -6
- package/references/contracts.md +4 -4
- package/references/hooks/gate-approve.mjs +7 -8
- package/references/hooks/stage-write-guard.mjs +314 -0
- package/references/modes/agents.md +6 -4
- package/references/modes/bootstrap.md +1 -1
- package/references/modes/flow-writer.md +10 -2
- package/references/modes/hook.md +4 -1
- package/references/modes/now.md +1 -1
- package/references/modes/procedures.md +49 -10
- package/references/modes/recipes.md +7 -7
- package/references/modes/recommendations.md +4 -3
- package/references/modes/robustness-brief.md +9 -8
- package/references/modes/set-recipe.md +1 -1
- package/references/modes/state-block-guard.md +4 -3
- package/references/modes/status.md +1 -1
- package/references/modes/upgrade.md +1 -1
- package/references/modes/worktrees.md +28 -5
- package/references/rules/story-sessions.md +2 -2
- package/references/scripts/archives/archive-caps.mjs +1 -1
- package/references/scripts/archives/archive-changelog.mjs +8 -8
- package/references/scripts/archives/archive-decisions.mjs +7 -7
- package/references/scripts/archives/archive-issues.mjs +5 -5
- package/references/scripts/archives/rotation-conservation.mjs +2 -1
- package/references/scripts/docs-size/check-docs-size.mjs +15 -15
- package/references/scripts/family.json +2 -0
- package/references/scripts/gates/kit-command-gates.mjs +7 -8
- package/references/scripts/gates/migrate-gates.mjs +10 -10
- package/references/scripts/git-hooks/install-git-hooks.mjs +13 -13
- package/references/scripts/run.mjs +1 -2
- package/references/scripts/shared/index.mjs +2 -0
- package/references/scripts/shared/locations.mjs +103 -0
- package/references/scripts/spec-schema/spec-schema.mjs +2 -1
- package/references/templates/orchestration.json +1 -1
- package/tools/ack-store.mjs +2 -1
- package/tools/apply-danger-check.mjs +20 -6
- package/tools/atomic-write.mjs +3 -2
- package/tools/attribution.mjs +2 -1
- package/tools/autonomy-config.mjs +2 -1
- package/tools/bridge-wiring.mjs +13 -11
- package/tools/carriers.mjs +54 -14
- package/tools/cheap-agents-read.mjs +28 -7
- package/tools/cheap-agents.mjs +15 -10
- package/tools/checker-gates-read.mjs +6 -5
- package/tools/commands.mjs +2 -2
- package/tools/coverage-declared/config.mjs +2 -1
- package/tools/coverage-producer.mjs +10 -9
- package/tools/delegation.mjs +7 -6
- package/tools/detect-backends.mjs +1 -1
- package/tools/dispatch-baseline.mjs +2 -1
- package/tools/distribution-files/scripts.mjs +4 -4
- package/tools/ensure-configs.mjs +2 -2
- package/tools/ensure-ops.mjs +24 -24
- package/tools/ensure-specs.mjs +7 -7
- package/tools/epic-shape-cli.mjs +2 -2
- package/tools/epic-shape-ledger.mjs +5 -5
- package/tools/epic-shape.mjs +5 -3
- package/tools/epic-store.mjs +2 -1
- package/tools/family-members.mjs +7 -5
- package/tools/family-registry.mjs +36 -30
- package/tools/feedback-record-cli.mjs +4 -5
- package/tools/flow-writer.mjs +26 -15
- package/tools/gate-hook.mjs +33 -28
- package/tools/gates-declaration.mjs +2 -1
- package/tools/gates-init.mjs +6 -5
- package/tools/git-hooks.mjs +64 -41
- package/tools/grounding.mjs +3 -2
- package/tools/hide-footprint.mjs +2 -1
- package/tools/hook-writer/index.mjs +147 -0
- package/tools/init-preflight.mjs +5 -4
- package/tools/init-project.mjs +12 -11
- package/tools/inject-methodology.mjs +3 -2
- package/tools/jev-guide.mjs +2 -2
- package/tools/known-footprint.mjs +27 -25
- package/tools/mcp-registration.mjs +6 -5
- package/tools/migration-blocks.mjs +2 -1
- package/tools/migration-notes.mjs +2 -2
- package/tools/node-evidence.mjs +4 -4
- package/tools/now-facts.mjs +5 -5
- package/tools/now-status.mjs +1 -5
- package/tools/orchestration-config.mjs +2 -1
- package/tools/orchestration-readme.mjs +7 -2
- package/tools/plan-approval/cli.mjs +45 -0
- package/tools/plan-approval/entries.mjs +109 -0
- package/tools/plan-approval/index.mjs +2 -0
- package/tools/plan-approval/record.mjs +198 -0
- package/tools/plan-files.mjs +6 -4
- package/tools/plan-shape-cli.mjs +10 -64
- package/tools/plan-shape-facts.mjs +240 -83
- package/tools/plan-shape.mjs +173 -160
- package/tools/plan-structure/cli.mjs +79 -0
- package/tools/plan-structure/index.mjs +67 -0
- package/tools/procedures.mjs +21 -17
- package/tools/profile-gaps.mjs +4 -6
- package/tools/project-rules/rules-priors.mjs +2 -0
- package/tools/project-rules/themes.mjs +6 -4
- package/tools/recipes.mjs +44 -29
- package/tools/recommendations.mjs +84 -33
- package/tools/reference-profile.mjs +2 -2
- package/tools/renderers.mjs +14 -8
- package/tools/repo-lex.mjs +84 -0
- package/tools/robustness-brief.mjs +14 -11
- package/tools/satellite-locator.mjs +3 -2
- package/tools/script-priors.mjs +3 -2
- package/tools/session-close-check.mjs +71 -15
- package/tools/set-flow.mjs +2 -2
- package/tools/set-recipe.mjs +17 -9
- package/tools/source-size/help.mjs +4 -4
- package/tools/source-size/layout.mjs +2 -1
- package/tools/source-size/piles.mjs +2 -2
- package/tools/source-size-config.mjs +3 -3
- package/tools/source-size-refusal.mjs +4 -3
- package/tools/source-size-report.mjs +41 -13
- package/tools/spec-check-cli.mjs +159 -21
- package/tools/spec-check-ops.mjs +74 -5
- package/tools/spec-check.mjs +54 -45
- package/tools/spec-coverage-cli.mjs +3 -2
- package/tools/stage-render/cli.mjs +231 -0
- package/tools/stage-render/index.mjs +340 -0
- package/tools/stage-render/stages.json +115 -0
- package/tools/stage-write-guard/cli.mjs +64 -0
- package/tools/stage-write-guard/index.mjs +56 -0
- package/tools/state-block-hook.mjs +38 -163
- package/tools/task-brief.mjs +8 -13
- package/tools/task-thread.mjs +3 -1
- package/tools/tier-guide-facts.mjs +23 -9
- package/tools/tier-preview.mjs +15 -19
- package/tools/transition/index.mjs +10 -9
- package/tools/uninstall.mjs +26 -12
- package/tools/vehicle-settings.mjs +2 -1
- package/tools/velocity-profile.mjs +5 -6
- package/tools/view-model.mjs +7 -4
- package/tools/worktree-prompt.mjs +7 -3
- package/tools/worktrees.mjs +235 -159
- package/tools/write-lanes.mjs +20 -14
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": 1,
|
|
3
|
+
"stages": {
|
|
4
|
+
"epic": {
|
|
5
|
+
"title": "Epic session",
|
|
6
|
+
"goal": "Write the epic file: its intent, value, non-goals, acceptance, specs and stories in order, at concept altitude.",
|
|
7
|
+
"steps": [{ "activity": "epic", "part": null, "from": 1, "to": 6 }],
|
|
8
|
+
"doNot": ["Write code.", "Write a test.", "Copy the tree.", "Run a trial suite.", "Name a mechanism or a file line in the epic."],
|
|
9
|
+
"output": "The epic file the shape check accepts, its review folded, and its queue row.",
|
|
10
|
+
"done": "The epic shape check accepts the file and the lens read is folded or carried to the maintainer.",
|
|
11
|
+
"next": ["epic", "design-consult", "spec-and-plan", "pause", "empty-queue"],
|
|
12
|
+
"slots": { "queue-row": "queue-row", "decisions": "decisions" }
|
|
13
|
+
},
|
|
14
|
+
"design-consult": {
|
|
15
|
+
"title": "Design consult session",
|
|
16
|
+
"goal": "Settle one design question with the council and Fable before any plan is written.",
|
|
17
|
+
"steps": [{ "activity": "epic", "part": "Design consult", "from": 1, "to": 4 }],
|
|
18
|
+
"doNot": ["Write code.", "Write a test.", "Copy the tree.", "Run a trial suite.", "Size the work by a prototype."],
|
|
19
|
+
"output": "The design record the epic's brief reads, each answer saved under the plans directory.",
|
|
20
|
+
"done": "Every member's fold is read back, and any fork left open is put to the maintainer.",
|
|
21
|
+
"next": ["design-consult", "epic", "spec-and-plan", "pause"],
|
|
22
|
+
"slots": { "queue-row": "queue-row", "decisions": "decisions" }
|
|
23
|
+
},
|
|
24
|
+
"spec-and-plan": {
|
|
25
|
+
"title": "Spec and plan session",
|
|
26
|
+
"goal": "Write every contract the story creates or revises and the plan's ledger beside them, through one review of at most two rounds.",
|
|
27
|
+
"steps": [{ "activity": "plan-authoring", "part": null, "from": 1, "to": 5 }],
|
|
28
|
+
"doNot": ["Write code.", "Write a test before the approval; a fold names its scenario instead.", "Copy the tree.", "Run a trial suite.", "Size a file in the plan."],
|
|
29
|
+
"output": "The contracts as drafts or revisions and the plan, folded with the review.",
|
|
30
|
+
"done": "The spec gate and the plan-shape gate accept, and the review is clean or its open findings are with the maintainer.",
|
|
31
|
+
"next": ["spec-and-plan", "waiting-on-approval", "pause"],
|
|
32
|
+
"slots": { "queue-row": "queue-row", "decisions": "decisions" }
|
|
33
|
+
},
|
|
34
|
+
"waiting-on-approval": {
|
|
35
|
+
"title": "Waiting on approval",
|
|
36
|
+
"goal": "Show the plan's essence and, on the maintainer's yes, record the approval.",
|
|
37
|
+
"steps": [{ "activity": "plan-authoring", "part": null, "from": 6, "to": 6 }],
|
|
38
|
+
"doNot": ["Write code.", "Write a test.", "Copy the tree.", "Run a trial suite.", "Record an approval the maintainer has not given in the chat."],
|
|
39
|
+
"output": "The essence file and, on the yes, the plan's approval record.",
|
|
40
|
+
"done": "The record check exits 0 for the plan, or the maintainer has asked for a change.",
|
|
41
|
+
"next": ["waiting-on-approval", "spec-and-plan", "tests", "split-edits", "pause"],
|
|
42
|
+
"slots": { "plan": "plan" }
|
|
43
|
+
},
|
|
44
|
+
"tests": {
|
|
45
|
+
"title": "Tests session",
|
|
46
|
+
"goal": "Write only the plan's tests, each failing for the reason its scenario or acceptance bullet states.",
|
|
47
|
+
"steps": [{ "activity": "plan-execution", "part": null, "from": 1, "to": 4 }],
|
|
48
|
+
"doNot": ["Write code.", "Write a prototype.", "Write a test that passes before its code exists."],
|
|
49
|
+
"output": "The plan's tests, staged, each red for its stated reason, and the session record.",
|
|
50
|
+
"done": "Every new test fails for its scenario's reason or on the absence of a name the plan adds.",
|
|
51
|
+
"next": ["tests", "code", "pause"],
|
|
52
|
+
"slots": { "plan": "plan" }
|
|
53
|
+
},
|
|
54
|
+
"code": {
|
|
55
|
+
"title": "Code session",
|
|
56
|
+
"goal": "Write the plan's code until its tests and run-gates --pre-review pass.",
|
|
57
|
+
"steps": [{ "activity": "plan-execution", "part": null, "from": 1, "to": 4 }],
|
|
58
|
+
"doNot": ["Change a test except back to what its scenario states.", "Write code no approved row or amendment entry covers.", "Commit."],
|
|
59
|
+
"output": "The code rows written and every contract revision copied into the store.",
|
|
60
|
+
"done": "The staged tests and run-gates --pre-review pass.",
|
|
61
|
+
"next": ["code", "diff-review", "pause"],
|
|
62
|
+
"slots": { "plan": "plan" }
|
|
63
|
+
},
|
|
64
|
+
"diff-review": {
|
|
65
|
+
"title": "Diff review session",
|
|
66
|
+
"goal": "Review the story's staged diff, run the final gates and the release where the story ships one, then commit and clean up.",
|
|
67
|
+
"steps": [{ "activity": "plan-execution", "part": null, "from": 5, "to": 8 }],
|
|
68
|
+
"doNot": ["Commit before the review is clean.", "Fold a finding without asking the member who raised it.", "Leave a committable output unstaged before the review."],
|
|
69
|
+
"output": "The reviewed commit, the release where one ships, and the plan's Phase: Cleanup done.",
|
|
70
|
+
"done": "The commit has landed and the Cleanup has run.",
|
|
71
|
+
"next": ["diff-review", "spec-and-plan", "epic", "pause", "empty-queue"],
|
|
72
|
+
"slots": { "plan": "plan" }
|
|
73
|
+
},
|
|
74
|
+
"split-modules": {
|
|
75
|
+
"title": "Split modules session",
|
|
76
|
+
"goal": "Write the split's module list as a plan with no code.",
|
|
77
|
+
"steps": [{ "activity": "plan-execution", "part": "Split", "from": 1, "to": 2 }],
|
|
78
|
+
"doNot": ["Write code.", "Write a test.", "Copy the tree.", "Run a trial suite.", "Move a file before the approval."],
|
|
79
|
+
"output": "The module list plan and, on the yes, its approval record.",
|
|
80
|
+
"done": "The plan's record check exits 0, or the maintainer has asked for a change.",
|
|
81
|
+
"next": ["split-modules", "waiting-on-approval", "split-edits", "pause"],
|
|
82
|
+
"slots": { "queue-row": "queue-row", "decisions": "decisions" }
|
|
83
|
+
},
|
|
84
|
+
"split-edits": {
|
|
85
|
+
"title": "Split edits session",
|
|
86
|
+
"goal": "Move the existing code and its cases into the modules the approved list names, then review, release and clean up.",
|
|
87
|
+
"steps": [{ "activity": "plan-execution", "part": "Split", "from": 3, "to": 4 }],
|
|
88
|
+
"doNot": ["Add new logic.", "Add a new case.", "Move a file the approved list does not name."],
|
|
89
|
+
"output": "The moved modules with their tests beside them, the reviewed commit and the Cleanup.",
|
|
90
|
+
"done": "The commit has landed and the Cleanup has run.",
|
|
91
|
+
"next": ["split-edits", "spec-and-plan", "epic", "pause", "empty-queue"],
|
|
92
|
+
"slots": { "plan": "plan" }
|
|
93
|
+
},
|
|
94
|
+
"pause": {
|
|
95
|
+
"title": "Paused session",
|
|
96
|
+
"goal": "The session waits: the work stops here until the maintainer names the next stage.",
|
|
97
|
+
"steps": [],
|
|
98
|
+
"doNot": ["Write code.", "Write a test.", "Start a stage the maintainer has not named."],
|
|
99
|
+
"output": "No change to the tree.",
|
|
100
|
+
"done": "The maintainer names the next stage.",
|
|
101
|
+
"next": ["epic", "design-consult", "spec-and-plan", "waiting-on-approval", "tests", "code", "diff-review", "split-modules", "split-edits", "pause", "empty-queue"],
|
|
102
|
+
"slots": {}
|
|
103
|
+
},
|
|
104
|
+
"empty-queue": {
|
|
105
|
+
"title": "Empty queue",
|
|
106
|
+
"goal": "The session waits: no work is open until the maintainer opens some.",
|
|
107
|
+
"steps": [],
|
|
108
|
+
"doNot": ["Write code.", "Write a test.", "Open work the maintainer has not asked for."],
|
|
109
|
+
"output": "No change to the tree.",
|
|
110
|
+
"done": "The maintainer opens new work.",
|
|
111
|
+
"next": ["epic", "design-consult", "spec-and-plan", "waiting-on-approval", "tests", "code", "diff-review", "split-modules", "split-edits", "pause", "empty-queue"],
|
|
112
|
+
"slots": {}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// stage-write-guard/cli.mjs — docs/ai/specs/kit/stage-write-guard.md
|
|
3
|
+
|
|
4
|
+
import { isDirectRun } from '../direct-run.mjs';
|
|
5
|
+
import { escapeForDisplay } from '../repo-lex.mjs';
|
|
6
|
+
import { writeStageGuard } from './index.mjs';
|
|
7
|
+
|
|
8
|
+
const EXIT_OK = 0;
|
|
9
|
+
const EXIT_PRECONDITION = 1;
|
|
10
|
+
const EXIT_USAGE = 2;
|
|
11
|
+
const APPLY_FLAG = '--apply';
|
|
12
|
+
const CWD_FLAG = '--cwd';
|
|
13
|
+
const FLAG_PREFIX = '-';
|
|
14
|
+
const LINE_ENDING = '\n';
|
|
15
|
+
|
|
16
|
+
const OUTCOME_LINES = Object.freeze({
|
|
17
|
+
usage: () => `usage: stage-write-guard [${APPLY_FLAG}] ${CWD_FLAG} <root>`,
|
|
18
|
+
unknownArgument: (arg) => `unknown argument: ${escapeForDisplay(arg)}`,
|
|
19
|
+
cwdNeedsDirectory: () => `${CWD_FLAG} needs a directory argument`,
|
|
20
|
+
cwdRequired: () => `${CWD_FLAG} <root> is required`,
|
|
21
|
+
report: (line) => escapeForDisplay(line),
|
|
22
|
+
refused: (message) => escapeForDisplay(message),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const usageError = (line) => Object.assign(new Error(line), { exitCode: EXIT_USAGE });
|
|
26
|
+
|
|
27
|
+
const parseArgs = (argv, parsed = { apply: false, cwd: undefined }) => {
|
|
28
|
+
if (argv.length === 0) {
|
|
29
|
+
if (parsed.cwd === undefined) throw usageError(OUTCOME_LINES.cwdRequired());
|
|
30
|
+
return parsed;
|
|
31
|
+
}
|
|
32
|
+
const [arg, ...tail] = argv;
|
|
33
|
+
if (arg === APPLY_FLAG) return parseArgs(tail, { ...parsed, apply: true });
|
|
34
|
+
if (arg !== CWD_FLAG) throw usageError(OUTCOME_LINES.unknownArgument(arg));
|
|
35
|
+
const [value, ...rest] = tail;
|
|
36
|
+
if (value === undefined || value.startsWith(FLAG_PREFIX)) throw usageError(OUTCOME_LINES.cwdNeedsDirectory());
|
|
37
|
+
return parseArgs(rest, { ...parsed, cwd: value });
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const writeLine = (write, line) => write(`${line}${LINE_ENDING}`);
|
|
41
|
+
|
|
42
|
+
const main = (argv, io) => {
|
|
43
|
+
try {
|
|
44
|
+
const { apply, cwd } = parseArgs(argv);
|
|
45
|
+
const { report } = writeStageGuard({ cwd, dryRun: !apply });
|
|
46
|
+
for (const line of report.split(LINE_ENDING)) writeLine(io.stdout, OUTCOME_LINES.report(line));
|
|
47
|
+
return EXIT_OK;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error?.exitCode === EXIT_USAGE) {
|
|
50
|
+
writeLine(io.stderr, error.message);
|
|
51
|
+
writeLine(io.stderr, OUTCOME_LINES.usage());
|
|
52
|
+
return EXIT_USAGE;
|
|
53
|
+
}
|
|
54
|
+
writeLine(io.stderr, OUTCOME_LINES.refused(error?.message ?? String(error)));
|
|
55
|
+
return EXIT_PRECONDITION;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (isDirectRun(import.meta.url)) {
|
|
60
|
+
process.exitCode = main(process.argv.slice(2), {
|
|
61
|
+
stdout: (text) => process.stdout.write(text),
|
|
62
|
+
stderr: (text) => process.stderr.write(text),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// stage-write-guard/index.mjs — docs/ai/specs/kit/stage-write-guard.md
|
|
2
|
+
|
|
3
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { STAGE_GUARD_HOOK } from '../../references/scripts/shared/index.mjs';
|
|
6
|
+
import { formatKitHookResult, writeKitHook } from '../hook-writer/index.mjs';
|
|
7
|
+
|
|
8
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const BUNDLED_STAGE_GUARD_PATH = resolve(HERE, '..', '..', 'references', 'hooks', basename(STAGE_GUARD_HOOK));
|
|
10
|
+
const PRE_TOOL_USE_EVENT = 'PreToolUse';
|
|
11
|
+
const COMMAND_HOOK_TYPE = 'command';
|
|
12
|
+
|
|
13
|
+
export const STAGE_GUARD_MATCHER = 'Write|Edit|MultiEdit|NotebookEdit';
|
|
14
|
+
export const STAGE_GUARD_HOOK_COMMAND = `node "$CLAUDE_PROJECT_DIR/${STAGE_GUARD_HOOK}"`;
|
|
15
|
+
|
|
16
|
+
export const buildStageGuardEntry = () => ({
|
|
17
|
+
matcher: STAGE_GUARD_MATCHER,
|
|
18
|
+
hooks: [{ type: COMMAND_HOOK_TYPE, command: STAGE_GUARD_HOOK_COMMAND }],
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const isJsonObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
22
|
+
const runsStageGuard = (hook) => isJsonObject(hook) && hook.type === COMMAND_HOOK_TYPE && hook.command === STAGE_GUARD_HOOK_COMMAND;
|
|
23
|
+
|
|
24
|
+
export const isStageGuardWired = (data) => {
|
|
25
|
+
const entries = isJsonObject(data) && isJsonObject(data.hooks) ? data.hooks[PRE_TOOL_USE_EVENT] : undefined;
|
|
26
|
+
if (!Array.isArray(entries)) return false;
|
|
27
|
+
return entries.some((entry) => isJsonObject(entry)
|
|
28
|
+
&& entry.matcher === STAGE_GUARD_MATCHER
|
|
29
|
+
&& Array.isArray(entry.hooks)
|
|
30
|
+
&& entry.hooks.some(runsStageGuard));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const STAGE_GUARD = Object.freeze({
|
|
34
|
+
fileRel: STAGE_GUARD_HOOK,
|
|
35
|
+
bundlePath: BUNDLED_STAGE_GUARD_PATH,
|
|
36
|
+
event: PRE_TOOL_USE_EVENT,
|
|
37
|
+
entry: Object.freeze(buildStageGuardEntry()),
|
|
38
|
+
isWired: isStageGuardWired,
|
|
39
|
+
refusesUnsafeModes: false,
|
|
40
|
+
lines: Object.freeze({
|
|
41
|
+
title: 'stage guard hook',
|
|
42
|
+
reload: 'the guard runs from the next file write',
|
|
43
|
+
merge: Object.freeze({
|
|
44
|
+
'no-hooks': `the hooks key with the ${PRE_TOOL_USE_EVENT} entry`,
|
|
45
|
+
'no-event': `the ${PRE_TOOL_USE_EVENT} key beside the existing hooks`,
|
|
46
|
+
append: `one element to the existing hooks.${PRE_TOOL_USE_EVENT} array`,
|
|
47
|
+
}),
|
|
48
|
+
trustPosture: 'trust posture: the guard reads the stage record and the orchestration config on each file write of the edit tools and prints one deny or nothing; it makes no network call, writes nothing and approves nothing.',
|
|
49
|
+
nothingToChange: 'nothing to change: the stage guard hook is placed, current and wired',
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const writeStageGuard = ({ cwd, dryRun = true } = {}, deps = {}) => {
|
|
54
|
+
const result = writeKitHook(STAGE_GUARD, { cwd, dryRun }, deps);
|
|
55
|
+
return { ...result, report: formatKitHookResult(STAGE_GUARD, result) };
|
|
56
|
+
};
|
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
// three cases of references/modes/state-block-guard.md: no `hooks` key, a `hooks` key without
|
|
6
6
|
// `Stop`, and a `hooks.Stop` array, which gains one element.
|
|
7
7
|
//
|
|
8
|
-
// The
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// settings write follow gate-hook's, with its error codes. What is the Stop hook's own:
|
|
8
|
+
// The place-then-wire flow runs on the kit's hook writer (hook-writer/index.mjs), which imports the
|
|
9
|
+
// hardened checks, the hook-file write and the unsafe-mode and stamp refusals from gate-hook.mjs,
|
|
10
|
+
// with its error codes. What is the Stop hook's own:
|
|
12
11
|
// • preview by default; `--apply` writes;
|
|
13
12
|
// • the runtime is created when absent, kept when byte-equal, replaced when it differs (the
|
|
14
13
|
// preview says so; the danger check prints the replaced bytes' digest);
|
|
@@ -21,42 +20,17 @@
|
|
|
21
20
|
// Exit codes: 0 done / preview; 1 precondition STOP; 2 usage. Dependency-free beyond the kit's
|
|
22
21
|
// own internal exports, Node >= 22. No side effects on import.
|
|
23
22
|
|
|
24
|
-
import { dirname,
|
|
23
|
+
import { dirname, resolve } from 'node:path';
|
|
25
24
|
import { fileURLToPath } from 'node:url';
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
SAFE_DEFAULT_MODES,
|
|
30
|
-
SETTINGS_FILE,
|
|
31
|
-
SETTINGS_LOCAL_FILE,
|
|
32
|
-
UNSAFE_BYPASS_MODE,
|
|
33
|
-
WORKFLOW_STAMP,
|
|
34
|
-
readSettingsFile,
|
|
35
|
-
resolveEffectiveMode,
|
|
36
|
-
} from './velocity-profile.mjs';
|
|
37
|
-
import {
|
|
38
|
-
GATE_HOOK_DIVERGED,
|
|
39
|
-
GATE_HOOK_STAMP,
|
|
40
|
-
GATE_HOOK_UNSAFE_MODE,
|
|
41
|
-
HOOKS_DIR,
|
|
42
|
-
assertDirSafe,
|
|
43
|
-
assertHooksShape,
|
|
44
|
-
assertSettingsWritable,
|
|
45
|
-
formatJson,
|
|
46
|
-
fsDeps,
|
|
47
|
-
makeGateHookError,
|
|
48
|
-
planTarget,
|
|
49
|
-
readBundledHook,
|
|
50
|
-
readStamp,
|
|
51
|
-
writeHookFile,
|
|
52
|
-
} from './gate-hook.mjs';
|
|
25
|
+
import { STOP_HOOK } from '../references/scripts/shared/index.mjs';
|
|
26
|
+
import { SETTINGS_FILE, SETTINGS_LOCAL_FILE } from './velocity-profile.mjs';
|
|
27
|
+
import { formatKitHookResult, mergeHookEntryInto, writeKitHook } from './hook-writer/index.mjs';
|
|
53
28
|
import { isDirectRun } from './direct-run.mjs';
|
|
54
|
-
import { fileLine } from './distribution-files/index.mjs';
|
|
55
29
|
|
|
56
30
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
57
31
|
|
|
58
32
|
export const STATE_BLOCK_HOOK_RUNTIME = 'state-block-guard.mjs';
|
|
59
|
-
export const STATE_BLOCK_HOOK_FILE_REL =
|
|
33
|
+
export const STATE_BLOCK_HOOK_FILE_REL = STOP_HOOK;
|
|
60
34
|
const BUNDLED_STATE_BLOCK_HOOK_PATH = resolve(HERE, '..', 'references', 'hooks', STATE_BLOCK_HOOK_RUNTIME);
|
|
61
35
|
// NO `--require-block` in the offered command. That flag turns on the absent-block report, and this
|
|
62
36
|
// kit does not mandate the three-part closing block — offering it to every project would hand them a
|
|
@@ -68,17 +42,13 @@ export const STOP_EVENT = 'Stop';
|
|
|
68
42
|
const EXIT_OK = 0;
|
|
69
43
|
const EXIT_PRECONDITION = 1;
|
|
70
44
|
const EXIT_USAGE = 2;
|
|
71
|
-
const UTF8 = 'utf8';
|
|
72
|
-
const LF = '\n';
|
|
73
|
-
|
|
74
|
-
const PLACEMENT_CREATE = 'create';
|
|
75
|
-
const PLACEMENT_KEEP = 'keep';
|
|
76
|
-
const PLACEMENT_REPLACE = 'replace';
|
|
77
|
-
const PLACEMENT_OF = Object.freeze({ place: PLACEMENT_CREATE, 'already-current': PLACEMENT_KEEP, diverged: PLACEMENT_REPLACE });
|
|
78
45
|
|
|
79
46
|
const MERGE_NO_HOOKS = 'no-hooks';
|
|
47
|
+
const MERGE_NO_EVENT = 'no-event';
|
|
80
48
|
const MERGE_NO_STOP = 'no-stop';
|
|
81
49
|
const MERGE_APPEND = 'append';
|
|
50
|
+
const STOP_CASE_OF = Object.freeze({ [MERGE_NO_EVENT]: MERGE_NO_STOP });
|
|
51
|
+
const KIT_CASE_OF = Object.freeze({ [MERGE_NO_STOP]: MERGE_NO_EVENT });
|
|
82
52
|
|
|
83
53
|
const USAGE = `usage: state-block-hook [--apply] [--cwd <dir>] [--help]
|
|
84
54
|
|
|
@@ -91,7 +61,6 @@ The entry is merged only while no ${STOP_EVENT} entry of either settings file ru
|
|
|
91
61
|
Never writes ${SETTINGS_LOCAL_FILE}; never commits.`;
|
|
92
62
|
|
|
93
63
|
const usageError = (message) => Object.assign(new Error(message), { exitCode: EXIT_USAGE });
|
|
94
|
-
const isJsonObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
95
64
|
|
|
96
65
|
// ── the Stop entry ────────────────────────────────────────────────────────────────────
|
|
97
66
|
|
|
@@ -112,137 +81,43 @@ export const isStopHookWired = (data) => {
|
|
|
112
81
|
: runsStateBlockGuard(entry)));
|
|
113
82
|
};
|
|
114
83
|
|
|
115
|
-
const mergeCaseOf = (data) => {
|
|
116
|
-
if (!isJsonObject(data) || data.hooks === undefined) return MERGE_NO_HOOKS;
|
|
117
|
-
return data.hooks[STOP_EVENT] === undefined ? MERGE_NO_STOP : MERGE_APPEND;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
84
|
// Append our ONE entry; every foreign hook, matcher and key is carried over untouched. Only called
|
|
121
85
|
// when the entry is absent (idempotence lives in the caller's plan, not in dedup-on-write).
|
|
122
|
-
export const mergeStopEntry = (base) =>
|
|
123
|
-
const root = isJsonObject(base) ? base : {};
|
|
124
|
-
const hooks = isJsonObject(root.hooks) ? root.hooks : {};
|
|
125
|
-
const entries = Array.isArray(hooks[STOP_EVENT]) ? hooks[STOP_EVENT] : [];
|
|
126
|
-
return { ...root, hooks: { ...hooks, [STOP_EVENT]: [...entries, buildStopHookEntry()] } };
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// ── the writer ────────────────────────────────────────────────────────────────────────
|
|
130
|
-
|
|
131
|
-
const preflight = (projectDir, deps) => {
|
|
132
|
-
const fs = fsDeps(deps);
|
|
133
|
-
const bundleContent = readBundledHook({ ...deps, bundlePath: deps.bundlePath ?? BUNDLED_STATE_BLOCK_HOOK_PATH });
|
|
134
|
-
const stamp = readStamp(join(projectDir, WORKFLOW_STAMP), fs);
|
|
135
|
-
assertDirSafe(join(projectDir, CLAUDE_DIR), CLAUDE_DIR, fs);
|
|
136
|
-
assertDirSafe(join(projectDir, HOOKS_DIR), HOOKS_DIR, fs);
|
|
137
|
-
const target = planTarget(join(projectDir, STATE_BLOCK_HOOK_FILE_REL), STATE_BLOCK_HOOK_FILE_REL, bundleContent, fs);
|
|
138
|
-
assertSettingsWritable(join(projectDir, SETTINGS_FILE), fs);
|
|
139
|
-
const projectSettings = readSettingsFile(join(projectDir, SETTINGS_FILE), { ...deps, cwd: projectDir });
|
|
140
|
-
const localSettings = readSettingsFile(join(projectDir, SETTINGS_LOCAL_FILE), { ...deps, cwd: projectDir });
|
|
141
|
-
const { bypassPermissionsPresent, unsafeModePresent } = resolveEffectiveMode(projectSettings.data, localSettings.data);
|
|
142
|
-
if (bypassPermissionsPresent) {
|
|
143
|
-
throw makeGateHookError(GATE_HOOK_UNSAFE_MODE, `${UNSAFE_BYPASS_MODE} appears in Claude settings - refusing to wire a hook beside it`);
|
|
144
|
-
}
|
|
145
|
-
if (unsafeModePresent) {
|
|
146
|
-
throw makeGateHookError(
|
|
147
|
-
GATE_HOOK_UNSAFE_MODE,
|
|
148
|
-
`an unsafe or unknown permissions.defaultMode is present in Claude settings - accepted modes: ${SAFE_DEFAULT_MODES.join(', ')}`,
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
assertHooksShape(projectSettings.data, SETTINGS_FILE, STOP_EVENT);
|
|
152
|
-
return {
|
|
153
|
-
projectDir,
|
|
154
|
-
bundleContent,
|
|
155
|
-
stamp,
|
|
156
|
-
stampOk: stamp === EXPECTED_WORKFLOW_VERSION,
|
|
157
|
-
placement: PLACEMENT_OF[target.action],
|
|
158
|
-
projectSettings,
|
|
159
|
-
localSettings,
|
|
160
|
-
wiredInProject: isStopHookWired(projectSettings.data),
|
|
161
|
-
wiredInLocal: isStopHookWired(localSettings.data),
|
|
162
|
-
mergeCase: mergeCaseOf(projectSettings.data),
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export const writeStateBlockHook = ({ cwd, dryRun = true } = {}, deps = {}) => {
|
|
167
|
-
const fs = fsDeps(deps);
|
|
168
|
-
const plan = preflight(resolve(cwd ?? deps.cwd ?? process.cwd()), deps);
|
|
169
|
-
const placePlanned = plan.placement !== PLACEMENT_KEEP;
|
|
170
|
-
const mergePlanned = !plan.wiredInProject && !plan.wiredInLocal;
|
|
171
|
-
const base = { placePlanned, mergePlanned, ...plan };
|
|
172
|
-
if (dryRun) return { wrote: false, dryRun: true, ...base };
|
|
173
|
-
|
|
174
|
-
if (!plan.stampOk) {
|
|
175
|
-
throw makeGateHookError(
|
|
176
|
-
GATE_HOOK_STAMP,
|
|
177
|
-
`not a deployed agent-workflow project at lineage ${EXPECTED_WORKFLOW_VERSION} (found ${plan.stamp ?? 'none'}) — run init/upgrade first`,
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
// Place FIRST, then wire — a wired-but-missing hook would error on every turn end.
|
|
181
|
-
const hookAbs = join(plan.projectDir, STATE_BLOCK_HOOK_FILE_REL);
|
|
182
|
-
if (plan.placement === PLACEMENT_CREATE) fs.mkdir(join(plan.projectDir, HOOKS_DIR), { recursive: true });
|
|
183
|
-
if (placePlanned) writeHookFile(hookAbs, STATE_BLOCK_HOOK_FILE_REL, plan.bundleContent, plan.placement === PLACEMENT_CREATE, fs);
|
|
184
|
-
if (mergePlanned) {
|
|
185
|
-
// Re-judge the placed file no-follow immediately BEFORE wiring: a runtime swapped, or turned
|
|
186
|
-
// into a link, between the placement and now must never be wired — zero settings mutation.
|
|
187
|
-
const placed = planTarget(hookAbs, STATE_BLOCK_HOOK_FILE_REL, plan.bundleContent, fs);
|
|
188
|
-
if (placed.action !== 'already-current') {
|
|
189
|
-
throw makeGateHookError(
|
|
190
|
-
GATE_HOOK_DIVERGED,
|
|
191
|
-
`${STATE_BLOCK_HOOK_FILE_REL} changed after placement — refusing to wire an unknown script as a ${STOP_EVENT} hook (no settings change made); re-run`,
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
fs.writeFile(
|
|
195
|
-
join(plan.projectDir, SETTINGS_FILE),
|
|
196
|
-
formatJson(mergeStopEntry(plan.projectSettings.data ?? {}), plan.projectSettings.eol ?? LF),
|
|
197
|
-
UTF8,
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
return { wrote: placePlanned || mergePlanned, dryRun: false, ...base };
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
// ── report ────────────────────────────────────────────────────────────────────────────
|
|
86
|
+
export const mergeStopEntry = (base) => mergeHookEntryInto(base, STOP_EVENT, buildStopHookEntry());
|
|
204
87
|
|
|
205
|
-
|
|
88
|
+
// ── the writer and its report ─────────────────────────────────────────────────────────
|
|
206
89
|
|
|
207
90
|
const TRUST_POSTURE_LINE =
|
|
208
91
|
'trust posture: the guard reads the closing assistant message of each turn and writes one warning line; it runs a Node process on every turn end, reads nothing else, makes no network call and approves nothing.';
|
|
209
92
|
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
:
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
93
|
+
const STATE_BLOCK_HOOK = Object.freeze({
|
|
94
|
+
fileRel: STATE_BLOCK_HOOK_FILE_REL,
|
|
95
|
+
bundlePath: BUNDLED_STATE_BLOCK_HOOK_PATH,
|
|
96
|
+
event: STOP_EVENT,
|
|
97
|
+
entry: buildStopHookEntry(),
|
|
98
|
+
isWired: isStopHookWired,
|
|
99
|
+
refusesUnsafeModes: true,
|
|
100
|
+
lines: Object.freeze({
|
|
101
|
+
title: 'state-block hook',
|
|
102
|
+
commandNote: `command: ${STATE_BLOCK_HOOK_COMMAND} (no --require-block; references/modes/state-block-guard.md says when to add it)`,
|
|
103
|
+
reload: 'the Stop hook runs from the next turn end',
|
|
104
|
+
merge: Object.freeze({
|
|
105
|
+
[MERGE_NO_HOOKS]: 'the hooks key with the Stop entry',
|
|
106
|
+
[MERGE_NO_EVENT]: 'the Stop key beside the existing hooks',
|
|
107
|
+
[MERGE_APPEND]: 'one element to the existing hooks.Stop array',
|
|
108
|
+
}),
|
|
109
|
+
bypassReason: 'refusing to wire a hook beside it',
|
|
110
|
+
trustPosture: TRUST_POSTURE_LINE,
|
|
111
|
+
nothingToChange: 'nothing to change: the state-block hook is placed, current and wired',
|
|
112
|
+
}),
|
|
219
113
|
});
|
|
220
114
|
|
|
221
|
-
const
|
|
222
|
-
if (result.wiredInProject) return ` - ${SETTINGS_FILE}: already wired`;
|
|
223
|
-
if (result.wiredInLocal) return ` - ${SETTINGS_FILE}: already wired via ${SETTINGS_LOCAL_FILE} — not duplicated`;
|
|
224
|
-
return ` - ${SETTINGS_FILE}: ${result.dryRun ? 'would add' : 'added'} ${MERGE_LINES[result.mergeCase]}`;
|
|
225
|
-
};
|
|
115
|
+
const withMergeCase = (result, caseOf) => ({ ...result, mergeCase: caseOf[result.mergeCase] ?? result.mergeCase });
|
|
226
116
|
|
|
227
|
-
export const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
? 'agent-workflow state-block hook — DRY RUN (no changes; re-run with --apply)'
|
|
232
|
-
: 'agent-workflow state-block hook — APPLY',
|
|
233
|
-
` - ${placementLine(result)}`,
|
|
234
|
-
formatSettingsLine(result),
|
|
235
|
-
` command: ${STATE_BLOCK_HOOK_COMMAND} (no --require-block; references/modes/state-block-guard.md says when to add it)`,
|
|
236
|
-
TRUST_POSTURE_LINE,
|
|
237
|
-
];
|
|
238
|
-
if (!result.stampOk) {
|
|
239
|
-
lines.push(`note: no current deployment stamp found (${result.stamp ?? 'none'}) — --apply will refuse until init/upgrade runs.`);
|
|
240
|
-
}
|
|
241
|
-
if (!result.dryRun && result.mergePlanned) {
|
|
242
|
-
lines.push('settings hot-reload: the Stop hook runs from the next turn end — no session restart needed.');
|
|
243
|
-
}
|
|
244
|
-
return lines.join(LF);
|
|
245
|
-
};
|
|
117
|
+
export const writeStateBlockHook = ({ cwd, dryRun = true } = {}, deps = {}) =>
|
|
118
|
+
withMergeCase(writeKitHook(STATE_BLOCK_HOOK, { cwd: cwd ?? deps.cwd ?? process.cwd(), dryRun }, deps), STOP_CASE_OF);
|
|
119
|
+
|
|
120
|
+
export const formatResult = (result) => formatKitHookResult(STATE_BLOCK_HOOK, withMergeCase(result, KIT_CASE_OF));
|
|
246
121
|
|
|
247
122
|
// ── CLI ───────────────────────────────────────────────────────────────────────────────
|
|
248
123
|
|
package/tools/task-brief.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { writeFileSync, realpathSync, constants as fsConstants } from 'node:fs';
|
|
3
3
|
import { dirname, isAbsolute, relative, resolve, sep, posix } from 'node:path';
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
5
|
+
import { PLANS } from '../references/scripts/shared/index.mjs';
|
|
5
6
|
import { readFileBytesNoFollow } from './fs-read-nofollow.mjs';
|
|
6
7
|
import { parseLedger, isSweep, PLAN_HEADINGS } from './plan-shape.mjs';
|
|
7
8
|
import { expandSweepPaths } from './plan-shape-facts.mjs';
|
|
@@ -13,6 +14,7 @@ import { claimedPaths } from './task-thread.mjs';
|
|
|
13
14
|
import { newestCheckpoint, verifyCheckpoint } from './checkpoint.mjs';
|
|
14
15
|
import { withRepository, readGit } from './checkpoint-core.mjs';
|
|
15
16
|
import { isDirectRun } from './direct-run.mjs';
|
|
17
|
+
import { escapeRegExp } from './repo-lex.mjs';
|
|
16
18
|
|
|
17
19
|
export const BRIEF_BINDING_INFO_STRING = 'aw-task-binding';
|
|
18
20
|
const ACCEPT = 0;
|
|
@@ -36,11 +38,10 @@ const FENCE_RE = /^(`{3,})(.*)$/;
|
|
|
36
38
|
const TITLE_RE = /^# Task: (\S.*)$/;
|
|
37
39
|
const HEADING_RE = /^#{1,2} /;
|
|
38
40
|
const STORY_PREFIX = 'Story:';
|
|
39
|
-
const HEADINGS = ['## Slice', '## Reads', '## Acceptance', '## Negative cases'
|
|
40
|
-
const SLICE_FIELDS = [
|
|
41
|
+
const HEADINGS = ['## Slice', '## Reads', '## Acceptance', '## Negative cases'];
|
|
42
|
+
const SLICE_FIELDS = [new RegExp(`^Plan: (${escapeRegExp(PLANS)}\\/[^/]+\\.md)$`), /^Row: (\S+)$/, /^Grouping: (.*)$/, /^Files:$/];
|
|
41
43
|
const PAIR_RE = /^- (\S(?:.*\S)?) :: (\S(?:.*\S)?)$/;
|
|
42
44
|
const BULLET_RE = /^- (\S.*)$/;
|
|
43
|
-
const INTEGER_RE = /^[1-9]\d*$/;
|
|
44
45
|
const TEST_RE = /(?:^|\/)[^/]+\.test(?:\.mjs$|\/[^/].*$)/;
|
|
45
46
|
const EXTENSION_RE = /\.[^/.]+$/;
|
|
46
47
|
const TEST_SUFFIX = '.test.mjs';
|
|
@@ -135,22 +136,16 @@ export const parseBrief = (text) => {
|
|
|
135
136
|
checkMembers(found, HEADINGS, 'heading');
|
|
136
137
|
if (HEADINGS.some((text, index) => found[index] !== text)) reject(NAMES.shape, `headings out of order: ${found.join(', ')}`);
|
|
137
138
|
const sections = HEADINGS.map((heading, index) => lines.slice(headings[index + ONE].index + ONE, headings[index + BASIC_ARGS]?.index ?? lines.length));
|
|
138
|
-
const [slice, reads, acceptance, negative
|
|
139
|
+
const [slice, reads, acceptance, negative] = sections;
|
|
139
140
|
const [[planPath], [rowId], [grouping]] = SLICE_FIELDS.map((pattern, index) => checkSliceField(pattern, slice[index], index));
|
|
140
141
|
const files = slice.slice(SLICE_FIELDS.length).map((line) => {
|
|
141
142
|
const [path, tag] = matchLine(PAIR_RE, line, 'a Files: line is not "- <path> :: <tag>"');
|
|
142
143
|
return { path, tag };
|
|
143
144
|
});
|
|
144
|
-
const budgets = budget.map((line) => {
|
|
145
|
-
const [path, count] = matchLine(PAIR_RE, line, 'a ## Budget line is not "- <path> :: <lines>"');
|
|
146
|
-
if (!INTEGER_RE.test(count) || !Number.isSafeInteger(Number(count))) reject(NAMES.shape, `a ## Budget count is not a positive integer: ${line}`);
|
|
147
|
-
return { path, maxLines: Number(count) };
|
|
148
|
-
});
|
|
149
145
|
if (files.length === START) reject(NAMES.shape, 'Files: lists no path');
|
|
150
|
-
checkMembers(budgets.map(({ path }) => path), [...new Set(files.map(({ path }) => path))], '## Budget path');
|
|
151
146
|
if (acceptance.length === START) reject(NAMES.shape, '## Acceptance lists no line');
|
|
152
147
|
if (negative.length === START) reject(NAMES.shape, '## Negative cases lists no line');
|
|
153
|
-
return { ok: true, title, storyLines, planPath, rowId, grouping, files,
|
|
148
|
+
return { ok: true, title, storyLines, planPath, rowId, grouping, files,
|
|
154
149
|
reads: reads.map((line) => matchLine(BULLET_RE, line, 'a ## Reads line is not a bullet')[START]),
|
|
155
150
|
acceptance: acceptance.map((line) => matchLine(PAIR_RE, line, 'an ## Acceptance line is not "- <command> :: <outcome>"')),
|
|
156
151
|
negative: negative.map((line) => matchLine(BULLET_RE, line, 'a ## Negative cases line is not a bullet')[START]),
|
|
@@ -177,12 +172,11 @@ const checkGrouping = (brief, row) => {
|
|
|
177
172
|
const expected = TAGS.filter((tag) => brief.files.some((file) => file.tag === tag)).join(GROUP_SEPARATOR);
|
|
178
173
|
if (brief.grouping !== expected) reject(NAMES.grouping, `Grouping: ${brief.grouping} differs from the Files tags ${expected}`);
|
|
179
174
|
const pins = brief.files.filter(({ tag }) => tag === PIN);
|
|
180
|
-
if (
|
|
175
|
+
if (posix.basename(row.path) === PIN_FILE) {
|
|
181
176
|
if (pins.length !== ONE || pins[START].path !== row.path) reject(NAMES.grouping, `a pin row tags only its own path ${row.path} pin`);
|
|
182
177
|
} else if (pins.length !== START) reject(NAMES.grouping, `the pin tag belongs to a ${PIN_FILE} row only`);
|
|
183
178
|
};
|
|
184
179
|
const checkRow = (context, brief, row) => {
|
|
185
|
-
if (!row?.valid) reject(NAMES.row, brief.rowId);
|
|
186
180
|
const files = brief.files.map((file) => {
|
|
187
181
|
const path = posix.normalize(file.path);
|
|
188
182
|
if (path !== file.path || path === CURRENT || path.startsWith(PARENT) || posix.isAbsolute(path)) reject(NAMES.row, file.path);
|
|
@@ -210,6 +204,7 @@ const readGrammar = (context, briefPath) => {
|
|
|
210
204
|
const plan = readInside(context, brief.planPath);
|
|
211
205
|
const ledger = parseLedger(plan.bytes.toString(UTF8));
|
|
212
206
|
const row = ledger.rows.find(({ id }) => id === brief.rowId);
|
|
207
|
+
if (!row?.valid) reject(NAMES.row, brief.rowId);
|
|
213
208
|
checkGrouping(brief, row);
|
|
214
209
|
checkRow(context, brief, row);
|
|
215
210
|
const goal = ledger.document.headings.find(({ text }) => text === PLAN_HEADINGS[START]);
|
package/tools/task-thread.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { PLANS } from '../references/scripts/shared/index.mjs';
|
|
1
2
|
import { hasPathOverlap } from './claim-relation.mjs';
|
|
3
|
+
import { escapeRegExp } from './repo-lex.mjs';
|
|
2
4
|
|
|
3
|
-
const TASK_BRIEF =
|
|
5
|
+
const TASK_BRIEF = new RegExp(`^${escapeRegExp(PLANS)}\\/TASK-[^/]+-T[1-9][0-9]*\\.md$`, 'u');
|
|
4
6
|
const INVALID_SEGMENTS = Object.freeze(['', '.', '..', '.git']);
|
|
5
7
|
const HEAD_BASELINE = Object.freeze({ kind: 'head', treeOid: null });
|
|
6
8
|
|