@hassangameryt/freeflow 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +3 -2
- package/.codex-plugin/plugin.json +5 -6
- package/.cursor-plugin/plugin.json +25 -0
- package/README.md +66 -56
- package/capabilities/cognitive-routing/SKILL.md +288 -130
- package/com.github.copilot/hooks/hooks.json +11 -0
- package/command-surface.json +0 -24
- package/gemini-extension.json +5 -0
- package/hooks/adapters/claude-session-start.mjs +16 -0
- package/hooks/adapters/codex-session-start.mjs +16 -0
- package/hooks/adapters/copilot-session-start.mjs +13 -0
- package/hooks/adapters/cursor-session-start.mjs +13 -0
- package/hooks/adapters/gemini-session-start.mjs +15 -0
- package/hooks/claude/hooks.json +18 -0
- package/hooks/codex/hooks.json +18 -0
- package/hooks/cursor/hooks.json +9 -0
- package/hooks/freeflow-runtime-context.mjs +3 -650
- package/hooks/hooks.json +4 -30
- package/hooks/shared/runtime-context.mjs +210 -0
- package/hooks/tests/check-host-adapters.test.mjs +82 -0
- package/hooks/tests/check-runtime-context-hook.sh +140 -320
- package/package.json +20 -4
- package/pi-extension/dist/cognitive-routing/commands.js +3 -3
- package/pi-extension/dist/cognitive-routing/config.js +16 -20
- package/pi-extension/dist/cognitive-routing/controller.js +478 -48
- package/pi-extension/dist/cognitive-routing/history.js +12 -0
- package/pi-extension/dist/cognitive-routing/host.js +74 -12
- package/pi-extension/dist/cognitive-routing/pi-routing-session.js +414 -0
- package/pi-extension/dist/cognitive-routing/pi-session-control.js +320 -0
- package/pi-extension/dist/cognitive-routing/tool.js +1 -0
- package/pi-extension/dist/cognitive-routing/types.js +1 -1
- package/pi-extension/dist/index.js +236 -219
- package/pi-extension/dist/runtime/runtime-context.js +126 -286
- package/pi-extension/dist/settings/settings-ui.js +52 -336
- package/pi-extension/src/cognitive-routing/commands.ts +15 -5
- package/pi-extension/src/cognitive-routing/config.ts +16 -20
- package/pi-extension/src/cognitive-routing/controller.ts +561 -51
- package/pi-extension/src/cognitive-routing/history.ts +12 -0
- package/pi-extension/src/cognitive-routing/host.ts +110 -16
- package/pi-extension/src/cognitive-routing/pi-routing-session.ts +538 -0
- package/pi-extension/src/cognitive-routing/pi-session-control.ts +444 -0
- package/pi-extension/src/cognitive-routing/tool.ts +1 -0
- package/pi-extension/src/cognitive-routing/types.ts +1 -1
- package/pi-extension/src/index.ts +249 -239
- package/pi-extension/src/runtime/runtime-context.ts +129 -305
- package/pi-extension/src/settings/settings-ui.ts +53 -371
- package/pi-extension/tests/cognitive-routing/commands.test.js +1 -1
- package/pi-extension/tests/cognitive-routing/controller.test.js +69 -40
- package/pi-extension/tests/cognitive-routing/extension-lifecycle.test.js +128 -57
- package/pi-extension/tests/cognitive-routing/pi-normal-lifecycle.test.js +434 -0
- package/pi-extension/tests/cognitive-routing/pi-session-control.test.js +174 -0
- package/pi-extension/tests/cognitive-routing/pi-session-history.test.js +91 -0
- package/pi-extension/tests/cognitive-routing/profile-resolution.test.js +47 -4
- package/pi-extension/tests/integration/mode-free-core.test.js +218 -0
- package/pi-extension/tests/integration/pi-extension.test.js +430 -2478
- package/pi-extension/tests/integration/prompt-architecture.test.js +124 -79
- package/pi-extension/tests/integration/unaffected-regressions.test.js +411 -0
- package/plugin.json +33 -0
- package/runtime/prompts/cognitive-routing.md +5 -4
- package/runtime/prompts/conversation-history.md +1 -1
- package/runtime/prompts/core.md +77 -6
- package/runtime/prompts/interaction-contract.md +6 -2
- package/skills/action-selection/SKILL.md +93 -44
- package/skills/action-selection/references/trajectory-stalls.md +71 -0
- package/skills/bypass/SKILL.md +109 -39
- package/skills/commit-work/SKILL.md +94 -55
- package/skills/commit-work/references/git-state-edges.md +94 -0
- package/skills/commit-work/references/simple-push.md +92 -0
- package/skills/commit-work/references/staging-decisions.md +79 -46
- package/skills/decision-gate/SKILL.md +80 -22
- package/skills/design-for-depth/SKILL.md +208 -43
- package/skills/design-for-depth/references/design-pressure-signals.md +108 -240
- package/skills/design-for-depth/references/interface-design-loop.md +77 -97
- package/skills/design-for-depth/references/module-and-dependency-design.md +147 -0
- package/skills/design-for-depth/references/software-design-philosophy.md +127 -173
- package/skills/design-for-depth/references/state-and-failure-boundaries.md +136 -0
- package/skills/diagnose-failure/SKILL.md +198 -52
- package/skills/diagnose-failure/references/diagnostic-loop-catalog.md +19 -5
- package/skills/diagnose-failure/references/flaky-and-performance-diagnosis.md +13 -5
- package/skills/discuss/SKILL.md +118 -76
- package/skills/discuss/references/discussion-continuity.md +84 -32
- package/skills/evaluate-skill/SKILL.md +166 -52
- package/skills/evaluate-skill/references/evaluation-definition-schema.md +2 -2
- package/skills/evaluate-skill/references/evaluation-design.md +56 -30
- package/skills/evaluate-skill/references/execution-and-evidence.md +1 -1
- package/skills/evaluate-skill/references/review-and-revision.md +62 -21
- package/skills/execute-work/SKILL.md +98 -59
- package/skills/execute-work/references/code-practices.md +4 -4
- package/skills/execute-work/references/execute-work-edges.md +42 -22
- package/skills/review-artifact/SKILL.md +132 -71
- package/skills/review-artifact/references/adjudicate-artifact-review.md +101 -0
- package/skills/review-artifact/references/independent-artifact-reviewer-contract.md +52 -41
- package/skills/review-work/SKILL.md +115 -72
- package/skills/review-work/references/adjudicate-work-review.md +97 -0
- package/skills/review-work/references/independent-work-reviewer-contract.md +40 -35
- package/skills/review-work/references/security-risk-lens.md +17 -15
- package/skills/setup-freeflow/SKILL.md +14 -17
- package/skills/setup-freeflow/references/activation-contract.md +24 -30
- package/skills/setup-freeflow/references/host-setup.md +6 -7
- package/skills/simplify-code/SKILL.md +97 -39
- package/skills/simplify-code/references/simplification-patterns.md +1 -1
- package/skills/tdd/SKILL.md +108 -41
- package/skills/tdd/references/test-design.md +1 -1
- package/skills/track-work/SKILL.md +133 -300
- package/skills/track-work/references/working-record-format.md +515 -0
- package/skills/track-work/scripts/lib/document.mjs +713 -0
- package/skills/track-work/scripts/lib/format.mjs +166 -0
- package/skills/track-work/scripts/lib/store.mjs +233 -0
- package/skills/track-work/scripts/lib/transitions.mjs +790 -0
- package/skills/track-work/scripts/lib/views.mjs +27 -430
- package/skills/track-work/scripts/working-record.mjs +292 -98
- package/skills/verify-work/SKILL.md +46 -20
- package/skills/verify-work/references/browser-runtime-evidence.md +1 -1
- package/skills/verify-work/references/integration-evidence.md +1 -7
- package/skills/verify-work/references/performance-evidence.md +1 -1
- package/skills/workflow/SKILL.md +110 -80
- package/skills/workflow/references/domain-skill-composition.md +24 -18
- package/skills/write-skill/SKILL.md +218 -62
- package/skills/write-skill/references/activation-boundaries.md +63 -21
- package/skills/write-skill/references/agent-first-instructions.md +61 -27
- package/skills/write-skill/references/progressive-disclosure.md +91 -41
- package/skills/write-skill/references/skill-dependency-graphs.md +190 -0
- package/runtime/prompts/skills.md +0 -65
- package/skills/mode-contract/SKILL.md +0 -104
- package/skills/track-work/scripts/lib/codec.mjs +0 -570
- package/skills/track-work/scripts/lib/commands.mjs +0 -568
- package/skills/track-work/scripts/lib/contract.mjs +0 -303
- package/skills/track-work/scripts/lib/model.mjs +0 -506
- package/skills/track-work/scripts/lib/operations.mjs +0 -965
- package/skills/track-work/scripts/lib/record-store.mjs +0 -264
- package/skills/track-work/scripts/lib/result.mjs +0 -37
- package/skills/track-work/scripts/lib/rewrites.mjs +0 -740
- package/skills/track-work/scripts/lib/schema.mjs +0 -277
- package/skills/track-work/scripts/lib/source-inventory.mjs +0 -162
- package/skills/track-work/scripts/lib/workspace.mjs +0 -134
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
import { fail } from "./model.mjs";
|
|
2
|
-
import { CHECKPOINT_RESULTS, CHECKPOINT_TYPES, DECISION_OPERATIONS, UPDATE_INPUT_KEYS } from "./contract.mjs";
|
|
3
|
-
|
|
4
|
-
const COMMON = `All existing-record mutations require --expected-sha from a confirmed view or prior confirmed result.
|
|
5
|
-
Semantic JSON is supplied with --input <json-file|->. Unknown fields and incompatible types fail before persistence.`;
|
|
6
|
-
|
|
7
|
-
const SCHEMAS = {
|
|
8
|
-
init: {
|
|
9
|
-
purpose: "Create a new ignored schema-v2 Working Record.",
|
|
10
|
-
input: `{
|
|
11
|
-
"taskName": "...",
|
|
12
|
-
"goal": "...",
|
|
13
|
-
"whatDefinesTask": "...",
|
|
14
|
-
"settled": "...",
|
|
15
|
-
"tentative": "...",
|
|
16
|
-
"open": "...",
|
|
17
|
-
"currentDirection": "...",
|
|
18
|
-
"boundaries": "...",
|
|
19
|
-
"route": "...",
|
|
20
|
-
"nextAction": "...",
|
|
21
|
-
"blockers": ["..."],
|
|
22
|
-
"upcomingCheckpoints": ["..."]
|
|
23
|
-
}`,
|
|
24
|
-
rules: [
|
|
25
|
-
"The CLI supplies --root and --name; JSON supplies optional task context.",
|
|
26
|
-
"Context fields are scalar strings; blockers and upcomingCheckpoints are arrays of strings.",
|
|
27
|
-
"Use the dedicated start path for an explicitly authorized Current Slice.",
|
|
28
|
-
],
|
|
29
|
-
},
|
|
30
|
-
update: {
|
|
31
|
-
purpose: "Apply one precise current-state or entity mutation without starting or settling a slice.",
|
|
32
|
-
examples: [
|
|
33
|
-
{
|
|
34
|
-
title: "Precise field edit",
|
|
35
|
-
input: `{
|
|
36
|
-
"edits": [
|
|
37
|
-
{
|
|
38
|
-
"target": "currentContext.currentDirection",
|
|
39
|
-
"replaceText": { "old": "old text", "new": "new text" }
|
|
40
|
-
}
|
|
41
|
-
]
|
|
42
|
-
}`,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
title: "Add proposal",
|
|
46
|
-
input: `{
|
|
47
|
-
"edits": [
|
|
48
|
-
{
|
|
49
|
-
"target": { "kind": "proposals" },
|
|
50
|
-
"addEntity": {
|
|
51
|
-
"title": "Implement the bounded result",
|
|
52
|
-
"type": "Delivery",
|
|
53
|
-
"intendedResult": "The accepted result",
|
|
54
|
-
"expectedEvidence": "Focused verification"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
]
|
|
58
|
-
}`,
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
title: "Add decision",
|
|
62
|
-
input: `{
|
|
63
|
-
"edits": [
|
|
64
|
-
{
|
|
65
|
-
"target": { "kind": "decisions" },
|
|
66
|
-
"addEntity": {
|
|
67
|
-
"title": "Keep one coherent slice",
|
|
68
|
-
"decision": "Keep related verification inside the same result",
|
|
69
|
-
"establishedBy": "User discussion"
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
]
|
|
73
|
-
}`,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
title: "Select pending checkpoint",
|
|
77
|
-
input: `{
|
|
78
|
-
"currentSlice": {
|
|
79
|
-
"selectedCheckpoints": ["Focused review"]
|
|
80
|
-
},
|
|
81
|
-
"upcomingCheckpoints": [
|
|
82
|
-
"Focused review — selected by User discussion — review before continuation"
|
|
83
|
-
]
|
|
84
|
-
}`,
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
title: "Resolve pending checkpoint — Add checkpoint History",
|
|
88
|
-
input: `{
|
|
89
|
-
"edits": [
|
|
90
|
-
{
|
|
91
|
-
"target": { "kind": "checkpoints" },
|
|
92
|
-
"addEntity": {
|
|
93
|
-
"title": "Focused review",
|
|
94
|
-
"type": "Independent review",
|
|
95
|
-
"selectedBy": "User explicitly selected the review",
|
|
96
|
-
"condition": "Review before continuation",
|
|
97
|
-
"result": "Completed",
|
|
98
|
-
"judgment": "Pass",
|
|
99
|
-
"evidence": "Focused regression suite",
|
|
100
|
-
"effect": "Continuation is allowed"
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
"target": "currentWork.upcomingCheckpoints",
|
|
105
|
-
"set": []
|
|
106
|
-
}
|
|
107
|
-
]
|
|
108
|
-
}`,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
title: "Add Note",
|
|
112
|
-
input: `{
|
|
113
|
-
"edits": [
|
|
114
|
-
{
|
|
115
|
-
"target": { "kind": "notes" },
|
|
116
|
-
"addEntity": {
|
|
117
|
-
"title": "Retained context",
|
|
118
|
-
"source": "User instruction",
|
|
119
|
-
"body": "Context worth preserving without active task effect."
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
]
|
|
123
|
-
}`,
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
title: "Reorder proposal",
|
|
127
|
-
input: `{
|
|
128
|
-
"edits": [
|
|
129
|
-
{
|
|
130
|
-
"target": { "kind": "proposal", "title": "First proposal" },
|
|
131
|
-
"moveAfter": "Second proposal"
|
|
132
|
-
}
|
|
133
|
-
]
|
|
134
|
-
}`,
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
title: "Supersede decision",
|
|
138
|
-
input: `{ "decision": { "operation": "supersede", "id": "D-001", "supersededBy": "D-002" } }`,
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
rules: [
|
|
142
|
-
"Choose one example form; do not combine edits with direct semantic fields.",
|
|
143
|
-
"Use one edit per affected field or entity; unspecified values are preserved.",
|
|
144
|
-
"For a direct context field target use a scalar set value or replaceText {old, new}; context fields are scalar strings.",
|
|
145
|
-
"For an entity target use {field: {old, new}}; list add/remove operations apply only to editable list fields.",
|
|
146
|
-
"replaceText accepts one exact semantic match after line-ending normalization; ambiguous or missing matches fail.",
|
|
147
|
-
`Decision operations are limited to: ${[...DECISION_OPERATIONS].join(", ")}. Decision state and supersession links are controlled by the atomic decision operation, not precise field edits.`,
|
|
148
|
-
`Checkpoint types: ${[...CHECKPOINT_TYPES].join(", ")}. Terminal results: ${[...CHECKPOINT_RESULTS].join(", ")}.`,
|
|
149
|
-
"Use the exact same title in selectedCheckpoints and checkpoint History so settlement can reconcile the boundary.",
|
|
150
|
-
"Selecting a checkpoint preserves its source and condition in upcomingCheckpoints; resolving it adds terminal History and removes its upcoming entry atomically.",
|
|
151
|
-
"Titles are non-empty single-line strings; checkpoint history requires type, selectedBy, condition, and result.",
|
|
152
|
-
`Accepted top-level update fields: ${[...UPDATE_INPUT_KEYS].join(", ")}.`,
|
|
153
|
-
"Whole-object or whole-collection replacement is not accepted; use explicit edits with a target and operation.",
|
|
154
|
-
"Batch related edits in one command for one atomic write.",
|
|
155
|
-
],
|
|
156
|
-
},
|
|
157
|
-
start: {
|
|
158
|
-
purpose: "Move one authorized proposal or direct result into Current Work.",
|
|
159
|
-
input:
|
|
160
|
-
'{ "proposalTitle": "...", "authoritySource": "...", "reasonAndScope": "...", "expectedEvidence": "...", "stopCondition": "..." }',
|
|
161
|
-
rules: ["The script assigns the S-NNN ID; the caller cannot supply one.", "There may be only one Current Slice."],
|
|
162
|
-
},
|
|
163
|
-
block: {
|
|
164
|
-
purpose: "Move the current In progress slice to Blocked.",
|
|
165
|
-
input:
|
|
166
|
-
'{ "sliceId": "S-NNN", "blocker": { "blocker": "...", "why": "...", "required": "..." }, "resumeWhen": "..." }',
|
|
167
|
-
rules: ["Record why continuation is unsafe and what resolution is required."],
|
|
168
|
-
},
|
|
169
|
-
resume: {
|
|
170
|
-
purpose: "Return the same currently Blocked slice to In progress.",
|
|
171
|
-
input: '{ "sliceId": "S-NNN", "resolutionSource": "..." }',
|
|
172
|
-
rules: ["Use reopen for historical slices."],
|
|
173
|
-
},
|
|
174
|
-
reopen: {
|
|
175
|
-
purpose: "Return a historical outcome to Current Work with the same ID.",
|
|
176
|
-
input:
|
|
177
|
-
'{ "sliceId": "S-NNN", "authoritySource": "...", "reopenReason": "...", "reasonAndScope": "...", "expectedEvidence": "...", "stopCondition": "..." }',
|
|
178
|
-
rules: ["Fresh active declarations are required; a full historical snapshot is never restored."],
|
|
179
|
-
},
|
|
180
|
-
close: {
|
|
181
|
-
purpose: "Compact and settle the current slice.",
|
|
182
|
-
input:
|
|
183
|
-
'{ "sliceId": "S-NNN", "finalState": "Completed", "outcome": "...", "evidence": ["..."], "reviewSummary": "...", "taskEffect": "..." }',
|
|
184
|
-
rules: [
|
|
185
|
-
"finalState must be Completed, Blocked, or Abandoned; Completed requires settled evidence, resolved checkpoints, and no pending boundaries.",
|
|
186
|
-
"Blocked requires deliberate park authority.",
|
|
187
|
-
"Abandoned requires authority, reason, residual effects, and evidence.",
|
|
188
|
-
],
|
|
189
|
-
},
|
|
190
|
-
unlock: {
|
|
191
|
-
purpose: "Remove one explicitly identified stale mutation lock without touching the record.",
|
|
192
|
-
input:
|
|
193
|
-
'{ "scope": "record", "authoritySource": "...", "lockPid": 999999, "lockCreatedAt": "2000-01-01T00:00:00.000Z" }',
|
|
194
|
-
rules: [
|
|
195
|
-
"The lock must be older than the stale threshold and owned by a dead process.",
|
|
196
|
-
"scope is record by default or init for the repository init lock.",
|
|
197
|
-
"The supplied PID, creation timestamp, and owner path must match the current lock exactly.",
|
|
198
|
-
"Live or changed locks are never removed.",
|
|
199
|
-
],
|
|
200
|
-
},
|
|
201
|
-
migrate: {
|
|
202
|
-
purpose: "Convert explicitly selected legacy or unsupported content to schema-v2 without semantic compression.",
|
|
203
|
-
input: `{
|
|
204
|
-
"authoritySource": "...",
|
|
205
|
-
"reason": "...",
|
|
206
|
-
"candidateText": "<complete schema-v2 record Markdown>",
|
|
207
|
-
"coverage": [
|
|
208
|
-
{
|
|
209
|
-
"unitId": "U-001",
|
|
210
|
-
"startByte": 0,
|
|
211
|
-
"endByte": 42,
|
|
212
|
-
"sourceSha256": "<exact source-unit hash>",
|
|
213
|
-
"kind": "content|blank",
|
|
214
|
-
"line": 1,
|
|
215
|
-
"disposition": "verbatim|represented|projection-only|formatting-normalized",
|
|
216
|
-
"targetPaths": ["currentContext.goal"]
|
|
217
|
-
}
|
|
218
|
-
]
|
|
219
|
-
}`,
|
|
220
|
-
rules: [
|
|
221
|
-
"Start with inspect and copy each sourceUnits unitId, byte boundary, hash, and kind into coverage.",
|
|
222
|
-
"Every exact source unit must appear once with matching boundaries, hash, and kind.",
|
|
223
|
-
"verbatim requires one exact, unconsumed candidate source unit; every other disposition requires existing targetPaths.",
|
|
224
|
-
"projection-only targets must belong to currentContext or currentWork.",
|
|
225
|
-
"Summarization, consolidation, and removal are rejected; use compress for semantic compaction.",
|
|
226
|
-
"Existing task and slice identities, state, and type cannot change during migration.",
|
|
227
|
-
],
|
|
228
|
-
},
|
|
229
|
-
compress: {
|
|
230
|
-
purpose: "Compact an explicitly scoped schema-v2 representation with recoverable source evidence.",
|
|
231
|
-
input: `{
|
|
232
|
-
"authoritySource": "...",
|
|
233
|
-
"reason": "...",
|
|
234
|
-
"preservation": "<semantic preservation declaration>",
|
|
235
|
-
"scope": ["history.slices"],
|
|
236
|
-
"candidateText": "<complete schema-v2 record Markdown>"
|
|
237
|
-
}`,
|
|
238
|
-
rules: [
|
|
239
|
-
"The candidate may change only paths inside scope.",
|
|
240
|
-
"Task state, IDs and ordering, Current Slice ownership and lifecycle, authority, blockers, pending boundaries, decision links, and strongest evidence are protected.",
|
|
241
|
-
"The source snapshot and operation manifest are created only on apply, never on dry run.",
|
|
242
|
-
],
|
|
243
|
-
},
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
function renderSchema(command) {
|
|
247
|
-
const names = command === "all" ? Object.keys(SCHEMAS) : [command];
|
|
248
|
-
for (const name of names)
|
|
249
|
-
if (!SCHEMAS[name]) fail("invalid-schema-command", `No input schema exists for command: ${name}`);
|
|
250
|
-
return [
|
|
251
|
-
"# Track Work command schema",
|
|
252
|
-
"",
|
|
253
|
-
`Command: ${command}`,
|
|
254
|
-
"",
|
|
255
|
-
COMMON,
|
|
256
|
-
"",
|
|
257
|
-
...names.flatMap((name) => {
|
|
258
|
-
const schema = SCHEMAS[name];
|
|
259
|
-
const examples = schema.examples ?? [{ title: "Input", input: schema.input }];
|
|
260
|
-
return [
|
|
261
|
-
`## ${name}`,
|
|
262
|
-
schema.purpose,
|
|
263
|
-
"",
|
|
264
|
-
...examples.flatMap(({ title, input }) =>
|
|
265
|
-
[title ? `### ${title}` : null, title ? "" : null, "```json", input, "```", ""].filter(Boolean),
|
|
266
|
-
),
|
|
267
|
-
"Rules:",
|
|
268
|
-
...schema.rules.map((rule) => `- ${rule}`),
|
|
269
|
-
"",
|
|
270
|
-
];
|
|
271
|
-
}),
|
|
272
|
-
].join("\n");
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export function renderCommandSchema(command = "all") {
|
|
276
|
-
return renderSchema(command);
|
|
277
|
-
}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { Buffer } from "node:buffer";
|
|
2
|
-
import { sha256 } from "./model.mjs";
|
|
3
|
-
|
|
4
|
-
export function sourceUnits(text) {
|
|
5
|
-
const chunks = text.split(/(?<=\n)/);
|
|
6
|
-
let offset = 0;
|
|
7
|
-
return chunks.map((chunk, index) => {
|
|
8
|
-
const startByte = offset;
|
|
9
|
-
offset += Buffer.byteLength(chunk, "utf8");
|
|
10
|
-
const content = chunk.endsWith("\n") ? chunk.slice(0, -1) : chunk;
|
|
11
|
-
return {
|
|
12
|
-
unitId: `U-${String(index + 1).padStart(3, "0")}`,
|
|
13
|
-
startByte,
|
|
14
|
-
endByte: offset,
|
|
15
|
-
sourceSha256: sha256(chunk),
|
|
16
|
-
kind: content.trim() ? "content" : "blank",
|
|
17
|
-
line: index + 1,
|
|
18
|
-
text: chunk,
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function publicSourceUnits(text) {
|
|
24
|
-
return sourceUnits(text).map(({ text: _text, ...unit }) => unit);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function sourceEntities(text) {
|
|
28
|
-
const entities = [];
|
|
29
|
-
let section = "";
|
|
30
|
-
let group = "";
|
|
31
|
-
for (const line of text.split(/\r\n?|\n/)) {
|
|
32
|
-
const match = /^(#{1,4})[ \t]+(.+?)\s*$/.exec(line);
|
|
33
|
-
if (!match) continue;
|
|
34
|
-
const level = match[1].length;
|
|
35
|
-
const title = match[2];
|
|
36
|
-
if (level === 2) {
|
|
37
|
-
section = title;
|
|
38
|
-
group = "";
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
if (level === 3) {
|
|
42
|
-
group = title;
|
|
43
|
-
if (section === "Proposed Slices") entities.push({ key: `proposal:${title}` });
|
|
44
|
-
else if (section === "Notes") entities.push({ key: `note:${title}` });
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (level !== 4 || section !== "History" || !["Decisions", "Checkpoints", "Slices"].includes(group)) continue;
|
|
48
|
-
const idMatch = /^([A-Z]-\d{3,})\s+—\s+(.+)$/.exec(title);
|
|
49
|
-
const kind = group === "Decisions" ? "decision" : group === "Checkpoints" ? "checkpoint" : "slice";
|
|
50
|
-
const identity = idMatch ? `${idMatch[1]}|${idMatch[2]}` : title;
|
|
51
|
-
entities.push({ key: `${kind}:${identity}` });
|
|
52
|
-
}
|
|
53
|
-
return entities;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function sourceUnitOwners(text) {
|
|
57
|
-
const owners = new Map();
|
|
58
|
-
const topSections = new Set(["Current Context", "Current Work", "Proposed Slices", "History", "Notes"]);
|
|
59
|
-
const contextHeadings = new Set([
|
|
60
|
-
"Goal",
|
|
61
|
-
"What defines this task",
|
|
62
|
-
"Settled",
|
|
63
|
-
"Tentative",
|
|
64
|
-
"Open",
|
|
65
|
-
"Current direction",
|
|
66
|
-
"Boundaries",
|
|
67
|
-
"Active Decisions",
|
|
68
|
-
]);
|
|
69
|
-
const workHeadings = new Set([
|
|
70
|
-
"Current route",
|
|
71
|
-
"Current Slice",
|
|
72
|
-
"Blockers",
|
|
73
|
-
"Upcoming checkpoints",
|
|
74
|
-
"Next useful action",
|
|
75
|
-
]);
|
|
76
|
-
const historyGroups = new Set(["Decisions", "Checkpoints", "Slices"]);
|
|
77
|
-
let section = "";
|
|
78
|
-
let group = "";
|
|
79
|
-
let owner = null;
|
|
80
|
-
for (const unit of sourceUnits(text)) {
|
|
81
|
-
const line = unit.text.endsWith("\n") ? unit.text.slice(0, -1) : unit.text;
|
|
82
|
-
const match = /^(#{1,4})[ \t]+(.+?)\s*$/.exec(line);
|
|
83
|
-
if (match) {
|
|
84
|
-
const level = match[1].length;
|
|
85
|
-
const title = match[2];
|
|
86
|
-
let recognized = false;
|
|
87
|
-
if (level === 1) {
|
|
88
|
-
owner = "taskName";
|
|
89
|
-
recognized = /^Working Record:\s+/.test(title);
|
|
90
|
-
} else if (level === 2) {
|
|
91
|
-
section = title;
|
|
92
|
-
group = "";
|
|
93
|
-
owner = section === "Current Context" ? "currentContext" : section === "Current Work" ? "currentWork" : null;
|
|
94
|
-
recognized = topSections.has(section);
|
|
95
|
-
} else if (level === 3) {
|
|
96
|
-
group = title;
|
|
97
|
-
if (section === "Current Context") {
|
|
98
|
-
owner = "currentContext";
|
|
99
|
-
recognized = contextHeadings.has(title);
|
|
100
|
-
} else if (section === "Current Work") {
|
|
101
|
-
owner = title === "Current Slice" ? "currentWork.currentSlice" : "currentWork";
|
|
102
|
-
recognized = workHeadings.has(title);
|
|
103
|
-
} else if (section === "Proposed Slices") {
|
|
104
|
-
owner = `proposals[title=${JSON.stringify(title)}]`;
|
|
105
|
-
recognized = true;
|
|
106
|
-
} else if (section === "Notes") {
|
|
107
|
-
owner = `notes[title=${JSON.stringify(title)}]`;
|
|
108
|
-
recognized = true;
|
|
109
|
-
} else if (section === "History") {
|
|
110
|
-
owner = `history.${title.toLowerCase()}`;
|
|
111
|
-
recognized = historyGroups.has(title);
|
|
112
|
-
}
|
|
113
|
-
} else if (level === 4 && section === "History" && historyGroups.has(group)) {
|
|
114
|
-
const idMatch = /^([A-Z]-\d{3,})\s+—\s+(.+)$/.exec(title);
|
|
115
|
-
if (group === "Decisions")
|
|
116
|
-
owner = `history.decisions[${idMatch ? `id=${JSON.stringify(idMatch[1])}` : `title=${JSON.stringify(title)}`}]`;
|
|
117
|
-
else if (group === "Slices")
|
|
118
|
-
owner = `history.slices[${idMatch ? `id=${JSON.stringify(idMatch[1])}` : `title=${JSON.stringify(title)}`}]`;
|
|
119
|
-
else
|
|
120
|
-
owner = `history.checkpoints[${idMatch ? `id=${JSON.stringify(idMatch[1])}` : `title=${JSON.stringify(title)}`}]`;
|
|
121
|
-
recognized = true;
|
|
122
|
-
}
|
|
123
|
-
owners.set(unit.unitId, { owner, structural: true, recognized, entityKey: entityKeyForOwner(owner) });
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
if (!section) {
|
|
127
|
-
if (/^State:\s*/.test(line)) owner = "taskState";
|
|
128
|
-
else if (/^Last updated:\s*/.test(line)) owner = "lastUpdated";
|
|
129
|
-
else if (/^Schema:\s*/.test(line)) owner = "schemaVersion";
|
|
130
|
-
else if (line.trim()) owner = null;
|
|
131
|
-
}
|
|
132
|
-
owners.set(unit.unitId, { owner, structural: false, recognized: false, entityKey: entityKeyForOwner(owner) });
|
|
133
|
-
}
|
|
134
|
-
return owners;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function entityKeyForOwner(owner) {
|
|
138
|
-
if (!owner) return null;
|
|
139
|
-
const match = /^(proposals|notes|history\.decisions|history\.checkpoints|history\.slices)\[(?:id|title)=(.+)\]$/.exec(
|
|
140
|
-
owner,
|
|
141
|
-
);
|
|
142
|
-
if (match) {
|
|
143
|
-
const kind =
|
|
144
|
-
match[1] === "history.decisions"
|
|
145
|
-
? "decision"
|
|
146
|
-
: match[1] === "history.checkpoints"
|
|
147
|
-
? "checkpoint"
|
|
148
|
-
: match[1] === "history.slices"
|
|
149
|
-
? "slice"
|
|
150
|
-
: match[1].slice(0, -1);
|
|
151
|
-
let identity = match[2];
|
|
152
|
-
if (identity.startsWith('"')) {
|
|
153
|
-
try {
|
|
154
|
-
identity = JSON.parse(identity);
|
|
155
|
-
} catch {
|
|
156
|
-
/* keep source identity */
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return `${kind}:${identity}`;
|
|
160
|
-
}
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
-
import { access, lstat, realpath } from "node:fs/promises";
|
|
3
|
-
import { promisify } from "node:util";
|
|
4
|
-
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
|
-
import { ensureString, fail } from "./model.mjs";
|
|
6
|
-
|
|
7
|
-
const execFile = promisify(execFileCallback);
|
|
8
|
-
|
|
9
|
-
export function pathInside(root, candidate) {
|
|
10
|
-
const rootPath = resolve(root);
|
|
11
|
-
const candidatePath = resolve(candidate);
|
|
12
|
-
const rel = relative(rootPath, candidatePath);
|
|
13
|
-
return rel === "" || (!rel.startsWith(`..${sep}`) && rel !== ".." && !isAbsolute(rel));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function assertNoSymlinkPath(path, stopAt) {
|
|
17
|
-
let current = resolve(path);
|
|
18
|
-
const boundary = resolve(stopAt);
|
|
19
|
-
while (pathInside(boundary, current)) {
|
|
20
|
-
try {
|
|
21
|
-
const entry = await lstat(current);
|
|
22
|
-
if (entry.isSymbolicLink()) fail("unsafe-symlink", `Mutable path contains a symlink: ${current}`);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
if (error?.code !== "ENOENT") throw error;
|
|
25
|
-
}
|
|
26
|
-
if (current === boundary) break;
|
|
27
|
-
const parent = dirname(current);
|
|
28
|
-
if (parent === current) break;
|
|
29
|
-
current = parent;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export async function exists(path) {
|
|
34
|
-
try {
|
|
35
|
-
await access(path);
|
|
36
|
-
return true;
|
|
37
|
-
} catch {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function gitInfo(root) {
|
|
43
|
-
try {
|
|
44
|
-
const result = await execFile("git", ["-C", root, "rev-parse", "--show-toplevel"], { maxBuffer: 1024 * 1024 });
|
|
45
|
-
const gitRoot = await realpath(result.stdout.trim());
|
|
46
|
-
return { available: true, root: gitRoot };
|
|
47
|
-
} catch {
|
|
48
|
-
return { available: false, root: null };
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export async function gitCommand(root, args) {
|
|
53
|
-
try {
|
|
54
|
-
const result = await execFile("git", ["-C", root, ...args], { maxBuffer: 1024 * 1024 });
|
|
55
|
-
return { ok: true, stdout: result.stdout, stderr: result.stderr };
|
|
56
|
-
} catch (error) {
|
|
57
|
-
return { ok: false, code: error.code, stdout: error.stdout ?? "", stderr: error.stderr ?? "" };
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export async function versionControlEvidence(root, path) {
|
|
62
|
-
const git = await gitInfo(root);
|
|
63
|
-
if (!git.available) return { available: false, ignored: null, tracked: null, gitRoot: null };
|
|
64
|
-
const rootReal = await realpath(root).catch(() => resolve(root));
|
|
65
|
-
const canonicalize = (candidate) => {
|
|
66
|
-
const fromRoot = relative(resolve(root), candidate);
|
|
67
|
-
return resolve(rootReal, fromRoot);
|
|
68
|
-
};
|
|
69
|
-
const relativePath = relative(git.root, canonicalize(path)).split(sep).join("/");
|
|
70
|
-
const ignored = await gitCommand(git.root, ["check-ignore", "--no-index", "-q", "--", relativePath]);
|
|
71
|
-
const parentPaths = [dirname(path), dirname(dirname(path))];
|
|
72
|
-
let ignoredParent = { ok: false };
|
|
73
|
-
if (!ignored.ok) {
|
|
74
|
-
for (const parentPath of parentPaths) {
|
|
75
|
-
const parentRelativePath = relative(git.root, canonicalize(parentPath)).split(sep).join("/");
|
|
76
|
-
ignoredParent = await gitCommand(git.root, ["check-ignore", "--no-index", "-q", "--", parentRelativePath]);
|
|
77
|
-
if (ignoredParent.ok) break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const tracked = await gitCommand(git.root, ["ls-files", "--error-unmatch", "--", relativePath]);
|
|
81
|
-
return {
|
|
82
|
-
available: true,
|
|
83
|
-
ignored: ignored.ok || ignoredParent.ok,
|
|
84
|
-
tracked: tracked.ok,
|
|
85
|
-
gitRoot: git.root,
|
|
86
|
-
relativePath,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function displayPath(root, path) {
|
|
91
|
-
const rel = relative(resolve(root), resolve(path));
|
|
92
|
-
return rel && !rel.startsWith(`..${sep}`) && rel !== ".." ? rel.split(sep).join("/") : path;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function taskRoot(root) {
|
|
96
|
-
return resolve(root, ".freeflow", "tasks");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function assertTaskRecordPath(root, recordPath) {
|
|
100
|
-
const tasks = taskRoot(root);
|
|
101
|
-
const resolved = resolve(recordPath);
|
|
102
|
-
if (!pathInside(tasks, resolved) || basename(resolved) !== "record.md")
|
|
103
|
-
fail("unsafe-path", `Record must be a record.md under ${displayPath(root, tasks)}`);
|
|
104
|
-
const taskDirectory = basename(dirname(resolved));
|
|
105
|
-
if (!/^task-\d{3}-[a-z0-9][a-z0-9-]*$/.test(taskDirectory))
|
|
106
|
-
fail("unsafe-path", `Invalid task directory: ${taskDirectory}`);
|
|
107
|
-
return resolved;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function resolveRecordPath(root, options, positionals = []) {
|
|
111
|
-
const supplied = options["--record"] ?? options["--task"] ?? positionals[0];
|
|
112
|
-
if (!supplied) fail("invalid-arguments", "A record path or task directory is required");
|
|
113
|
-
const candidate = isAbsolute(supplied) ? supplied : resolve(root, supplied);
|
|
114
|
-
const path = basename(candidate) === "record.md" ? candidate : join(candidate, "record.md");
|
|
115
|
-
return assertTaskRecordPath(root, path);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function nextTaskNumber(entries) {
|
|
119
|
-
const used = new Set();
|
|
120
|
-
for (const entry of entries) {
|
|
121
|
-
const match = /^task-(\d{3})-/.exec(entry.name);
|
|
122
|
-
if (entry.isDirectory() && match) used.add(Number(match[1]));
|
|
123
|
-
}
|
|
124
|
-
let number = 1;
|
|
125
|
-
while (used.has(number)) number += 1;
|
|
126
|
-
return number;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function safeShortName(value) {
|
|
130
|
-
const shortName = ensureString(value).trim();
|
|
131
|
-
if (!/^[a-z0-9][a-z0-9-]*$/.test(shortName))
|
|
132
|
-
fail("invalid-short-name", "Short name must contain lowercase letters, digits, and hyphens only");
|
|
133
|
-
return shortName;
|
|
134
|
-
}
|