@mjasnikovs/pi-task 0.28.2 → 0.28.3
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.
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { OwnedRequirement } from './requirements.js';
|
|
2
|
+
/** A freeze whose scope is a CATEGORY of files, with the paths it carves out. */
|
|
3
|
+
export interface CategoryFreeze {
|
|
4
|
+
/** The freeze line, verbatim. */
|
|
5
|
+
constraint: string;
|
|
6
|
+
/** The paths the category exempts — everything else is frozen. */
|
|
7
|
+
exempt: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* One unsatisfiable pair, keyed by the REQUIREMENT rather than by the path.
|
|
11
|
+
*
|
|
12
|
+
* Grouping matters for the resolution's size. mx5 run 18's TASK_0023 carries
|
|
13
|
+
* two owned build-contract clauses that between them name three frozen paths;
|
|
14
|
+
* per-path findings would demand three separate ownership grants (and the same
|
|
15
|
+
* pair twice over, because that spec states its freeze in CONSTRAINTS and again
|
|
16
|
+
* in ACCEPTANCE). Per requirement, the rewrite is told which files that one
|
|
17
|
+
* obligation names and grants only what it needs — which is what keeps
|
|
18
|
+
* `inv-no-spec-inflation` satisfiable at all.
|
|
19
|
+
*/
|
|
20
|
+
export interface OwnedFreezeConflict {
|
|
21
|
+
/** The owned requirement line, verbatim. */
|
|
22
|
+
requirement: string;
|
|
23
|
+
/** The files it names that this freeze covers. */
|
|
24
|
+
paths: string[];
|
|
25
|
+
/** The category freeze line, verbatim. */
|
|
26
|
+
constraint: string;
|
|
27
|
+
/** The paths that freeze exempts (the resolution has to widen this, or
|
|
28
|
+
* move the requirement to a task whose scope already includes the file). */
|
|
29
|
+
exempt: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Backtick-quoted path-shaped tokens in a text, INCLUDING the ones embedded in
|
|
33
|
+
* a backticked command (`bun run --watch src/server/index.ts` is one backtick
|
|
34
|
+
* span; the path inside it is what the requirement is about). Route literals
|
|
35
|
+
* (`/api`) and bare directories survive this filter — the caller decides what
|
|
36
|
+
* to do with them; `findOwnedFreezeConflicts` keeps only files.
|
|
37
|
+
*/
|
|
38
|
+
export declare function pathTokensIn(text: string): string[];
|
|
39
|
+
/**
|
|
40
|
+
* Every CATEGORY freeze in the spec: a modification ban (or its passive/only-
|
|
41
|
+
* form equivalent) scoped to a class of files rather than to named paths. A
|
|
42
|
+
* freeze that only names paths is `frozen-conflict.ts`'s job, not this one.
|
|
43
|
+
*/
|
|
44
|
+
export declare function findCategoryFreezes(spec: string | null | undefined): CategoryFreeze[];
|
|
45
|
+
/**
|
|
46
|
+
* The spec lines carrying an AUTHORITATIVE owned requirement: the machine-
|
|
47
|
+
* stamped ones, plus — when the run's ledger is supplied — any line carrying an
|
|
48
|
+
* owned quote verbatim (compose folding the quote in itself leaves no stamp).
|
|
49
|
+
*/
|
|
50
|
+
export declare function ownedRequirementLines(spec: string | null | undefined, owned?: OwnedRequirement[]): string[];
|
|
51
|
+
export interface OwnedFreezeOptions {
|
|
52
|
+
/** The run's owned-requirement ledger, so belt-folded (unstamped) quotes
|
|
53
|
+
* count too. Omitted → stamped lines only. */
|
|
54
|
+
owned?: OwnedRequirement[];
|
|
55
|
+
/**
|
|
56
|
+
* Is this repo-relative token an existing SOURCE file of the tree the spec
|
|
57
|
+
* will run against? Supplied by the caller (compose knows its cwd; the
|
|
58
|
+
* measured implementation is "tracked by git" — see `trackedSourceOracle`).
|
|
59
|
+
*
|
|
60
|
+
* Two false-positive classes die here, both observed at STEP 0 on the real
|
|
61
|
+
* TASK_0023 spec: route literals and build outputs (`/api`, `dist/`,
|
|
62
|
+
* `dist/app.css` — named by the very clause that is the true positive, but
|
|
63
|
+
* not files anyone can edit), and files a task is about to CREATE, which a
|
|
64
|
+
* freeze on the existing tree does not block. Omitted → every path-shaped
|
|
65
|
+
* token counts (the broad reading, reported alongside at STEP 0).
|
|
66
|
+
*/
|
|
67
|
+
isSource?: (p: string) => boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Every unsatisfiable pair in the composed spec: an AUTHORITATIVE owned
|
|
71
|
+
* requirement naming a file that a CATEGORY freeze in the same spec forbids
|
|
72
|
+
* touching. Deterministic, pure text (plus the caller's existence oracle).
|
|
73
|
+
* Empty when the spec froze no category or carries no owned requirement — the
|
|
74
|
+
* ordinary single-`/task` case degrades to a no-op.
|
|
75
|
+
*/
|
|
76
|
+
export declare function findOwnedFreezeConflicts(spec: string | null | undefined, opts?: OwnedFreezeOptions): OwnedFreezeConflict[];
|
|
77
|
+
/**
|
|
78
|
+
* The measured `isSource` oracle: a token counts only when git tracks it in
|
|
79
|
+
* `cwd`. Tracked ⇒ it exists, it is not a build output, and it is not ignored —
|
|
80
|
+
* exactly the "source file" the category freezes talk about. `git` missing or
|
|
81
|
+
* the tree not a repo ⇒ every token counts (the broad reading), so the detector
|
|
82
|
+
* degrades toward firing rather than toward silent blindness.
|
|
83
|
+
*/
|
|
84
|
+
export declare function trackedSourceOracle(lsFiles: (p: string) => {
|
|
85
|
+
stdout: string;
|
|
86
|
+
exitCode: number;
|
|
87
|
+
}): (p: string) => boolean;
|
|
88
|
+
/**
|
|
89
|
+
* The forced critique-rewrite defect text, in the shape the existing four
|
|
90
|
+
* families use: MANDATORY, self-contained, naming the exact resolutions. Prose
|
|
91
|
+
* surrender and silently dropping the requirement are called out as
|
|
92
|
+
* non-resolutions because narrowing the clause is precisely what run 16 did and
|
|
93
|
+
* freezing its file is precisely what run 18 did.
|
|
94
|
+
*/
|
|
95
|
+
export declare function ownedFreezeConflictProbeText(conflicts: OwnedFreezeConflict[]): string;
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* owned-freeze-conflict — the FIFTH unsatisfiable-pair family (nexttask 7):
|
|
3
|
+
* an AUTHORITATIVE owned requirement whose file falls inside a CATEGORY freeze
|
|
4
|
+
* written by the same spec.
|
|
5
|
+
*
|
|
6
|
+
* WHY frozen-conflict.ts does not see it (mx5 run 18, TASK_0023). The owned
|
|
7
|
+
* channel worked: `.pi-tasks/requirements-owned.md` carried the design clause
|
|
8
|
+
* "**Server:** `bun run --watch src/server/index.ts` — serves `/api` + static
|
|
9
|
+
* `dist/`." and the composed spec carried it verbatim under CONSTRAINTS, marked
|
|
10
|
+
* AUTHORITATIVE. The same CONSTRAINTS block then said "Do not modify
|
|
11
|
+
* `docker-compose.dev.yml`, …, or any source files outside of `package.json`",
|
|
12
|
+
* and the spec's ACCEPTANCE/VERIFY converted the behavioural half of the clause
|
|
13
|
+
* ("serves `/api` + static `dist/`") into a string-match on `package.json`. The
|
|
14
|
+
* only file that could implement it — `src/server/index.ts` — was frozen. The
|
|
15
|
+
* requirement was structurally unsatisfiable inside its owning task, VERIFY
|
|
16
|
+
* PASSed honestly, and the app shipped with no static route.
|
|
17
|
+
*
|
|
18
|
+
* The existing detector misses this shape twice over (both visible in its own
|
|
19
|
+
* header): its freeze side needs a NAMED path (`pathNamedIn`), and run 18's
|
|
20
|
+
* freeze names a CATEGORY ("any source files outside of `package.json`"); its
|
|
21
|
+
* statement side must match one of four measured phrasing families, and a plain
|
|
22
|
+
* behavioural claim matches none of them.
|
|
23
|
+
*
|
|
24
|
+
* HIGH-PRECISION BY CONSTRUCTION — the statement side needs no NLP:
|
|
25
|
+
* - owned requirement lines are MACHINE-MARKED. `appendOwnedConstraints`
|
|
26
|
+
* stamps every one it appends with "owned requirement from the source
|
|
27
|
+
* design (AUTHORITATIVE; …)"; when compose folded the quote in by itself
|
|
28
|
+
* the marker is absent, so the caller may also pass the run's ledger
|
|
29
|
+
* entries and the quote is matched verbatim against the spec text.
|
|
30
|
+
* - the requirement names its path literally, so the intersection is lexical.
|
|
31
|
+
* - category freezes are a small closed lexical set ("any source files
|
|
32
|
+
* outside of X", "any files other than X", "only X may be modified",
|
|
33
|
+
* "no files outside X").
|
|
34
|
+
*
|
|
35
|
+
* ── STATUS: NOT WIRED. The critique seam FAILED its A/B, 2026-08-04. ─────────
|
|
36
|
+
*
|
|
37
|
+
* The detector is precise — 1 finding over 58 real composed specs, and it is the
|
|
38
|
+
* true positive (scripts/owned-freeze-conflict-fp-suite.ts, PASS; STEP 0 in
|
|
39
|
+
* scripts/owned-vs-freeze-baserate.ts). What failed is the LEVER built on it,
|
|
40
|
+
* for two independent reasons, both measured:
|
|
41
|
+
*
|
|
42
|
+
* 1. THE SEAM IS BLIND IN PRODUCTION. `appendOwnedConstraints` — the BRACES that
|
|
43
|
+
* stamp the machine-marked owned bullet this detector keys on — runs AFTER
|
|
44
|
+
* `critiqueWithFallback`, inside the `critique` step (phases.ts). When
|
|
45
|
+
* critique runs, the stamped line does not exist yet; compose's own folding
|
|
46
|
+
* is a PARAPHRASE ("The server watch command must match the contract exactly:
|
|
47
|
+
* `…` — serves `/api` + static `dist/`"), so neither the stamp nor the
|
|
48
|
+
* verbatim quote is there to match. Live: 0/40 compose drafts carried a
|
|
49
|
+
* detectable pair while 11/40 carried the clause semantically. A critique-
|
|
50
|
+
* time probe cannot see the shape it was designed for.
|
|
51
|
+
* 2. THE REWRITE RESOLVES IT BY DELETING THE REQUIREMENT. Forced through the
|
|
52
|
+
* controlled critique seam on run 18's real TASK_0023 draft (n=20/arm):
|
|
53
|
+
* pair-present 8/20 → 0/20, but the resolution was scoped ownership in only
|
|
54
|
+
* 9/20 — the other 11/20 removed the AUTHORITATIVE clause outright and
|
|
55
|
+
* rationalised it ("this references an existing file; no edits are required
|
|
56
|
+
* or permitted"), with 0 of the 11 reassigning it to the task that owns the
|
|
57
|
+
* file. VERIFY behaviour-observation was 6/20 in BOTH arms: the delivered
|
|
58
|
+
* spec still verifies the requirement by grepping `package.json`.
|
|
59
|
+
*
|
|
60
|
+
* Removal of the pair is not satisfaction of the requirement — the same lesson
|
|
61
|
+
* as the run-16 lever's delivery metric, one level down. Anything built here
|
|
62
|
+
* next has to act AFTER the braces, where the pair actually exists, and cannot
|
|
63
|
+
* be a model rewrite: the braces are the last spec-producing step.
|
|
64
|
+
*
|
|
65
|
+
* It is a pure text function so the base rate, the FP suite and the live A/B all
|
|
66
|
+
* measure the same object.
|
|
67
|
+
*/
|
|
68
|
+
import { PROHIBITION_RE } from './prohibition-probe.js';
|
|
69
|
+
import { pathNamedIn } from './frozen-path-guard.js';
|
|
70
|
+
/**
|
|
71
|
+
* The machine stamp `appendOwnedConstraints` writes on every owned requirement
|
|
72
|
+
* it appends to CONSTRAINTS. Matching the stamp — not the prose — is what keeps
|
|
73
|
+
* the statement side free of NLP.
|
|
74
|
+
*/
|
|
75
|
+
const OWNED_MARKER_RE = /owned\s+requirement\s+from\s+the\s+source\s+design/i;
|
|
76
|
+
/**
|
|
77
|
+
* Modification verbs, shared by the active and passive freeze families. Scoped
|
|
78
|
+
* to modification exactly as `PROHIBITION_RE` is: a "do not CREATE any files
|
|
79
|
+
* other than X" line is a creation ban and freezes no existing file, so it must
|
|
80
|
+
* never be read as a category freeze (mx5 run 18 TASK_0009 ships that line).
|
|
81
|
+
*/
|
|
82
|
+
const MOD_VERB = 'modif|touch|edit|chang|alter|rewrit|overwrit';
|
|
83
|
+
/**
|
|
84
|
+
* A category noun phrase with an exception: "any source files outside of X",
|
|
85
|
+
* "any existing file other than X", "no files except X". `\w+` slots absorb the
|
|
86
|
+
* qualifiers seen in the corpora (source/existing/other), bounded so the phrase
|
|
87
|
+
* cannot span a whole paragraph.
|
|
88
|
+
*/
|
|
89
|
+
const CATEGORY_NOUN = String.raw `(?:any|no)\s+(?:\w+\s+){0,3}?files?\b`;
|
|
90
|
+
const EXCEPT_KEYWORD = String.raw `(?:outside(?:\s+of)?|other\s+than|except(?:\s+for)?|besides|apart\s+from|beyond)`;
|
|
91
|
+
/**
|
|
92
|
+
* Active family: a modification ban whose object is the category phrase. The
|
|
93
|
+
* tempered gap forbids crossing a creation/addition verb, so the compound line
|
|
94
|
+
* "Do not create any files other than `X` and do not modify `Y`" — where the
|
|
95
|
+
* category belongs to the CREATE half — cannot be mis-read as a category freeze.
|
|
96
|
+
*/
|
|
97
|
+
const ACTIVE_CATEGORY_RE = new RegExp(String.raw `\b(?:do\s+not|do\s+NOT|don'?t|must\s+not|never)\s+(?:${MOD_VERB})\w*\b`
|
|
98
|
+
+ String.raw `(?:(?!\b(?:creat|add|introduc|generat)\w*\b)[\s\S]){0,200}?`
|
|
99
|
+
+ String.raw `\b${CATEGORY_NOUN}[^\n]{0,40}?\b${EXCEPT_KEYWORD}\b`, 'i');
|
|
100
|
+
/**
|
|
101
|
+
* Passive family: "No files other than `package.json` are modified." — run 18's
|
|
102
|
+
* ACCEPTANCE line, identical in force to the CONSTRAINTS freeze above it.
|
|
103
|
+
*/
|
|
104
|
+
const PASSIVE_CATEGORY_RE = new RegExp(String.raw `\b${CATEGORY_NOUN}[^\n]{0,40}?\b${EXCEPT_KEYWORD}\b`
|
|
105
|
+
+ String.raw `[^\n]{0,120}?\b(?:are|is|may|must|should|can|will)\s+(?:be\s+|been\s+)?(?:${MOD_VERB})\w*`, 'i');
|
|
106
|
+
/**
|
|
107
|
+
* A SCOPED-OWNERSHIP grant — "You MAY edit `X` ONLY to …/ONLY as far as …" —
|
|
108
|
+
* which is the resolution this detector demands. Whatever else the spec says,
|
|
109
|
+
* the paths named on such a line are editable, so they can never be the frozen
|
|
110
|
+
* side of a pair. Without this the rewrite that grants ownership on a NEW line
|
|
111
|
+
* while leaving the category freeze in place would re-fire forever.
|
|
112
|
+
*/
|
|
113
|
+
const SCOPED_GRANT_RE = new RegExp(String.raw `\b(?:may|can|are\s+allowed\s+to|is\s+allowed\s+to)\s+(?:${MOD_VERB})\w*\b[^\n]{0,80}?\bonly\b`, 'i');
|
|
114
|
+
/** "Only `X` may be modified" / "Only `X` is edited". */
|
|
115
|
+
const ONLY_CATEGORY_RE = new RegExp(String.raw `\bonly\b[^\n]{0,60}?\b(?:may|must|should|can|will|is|are)\s+(?:be\s+)?(?:${MOD_VERB})\w*`, 'i');
|
|
116
|
+
/**
|
|
117
|
+
* Backtick-quoted path-shaped tokens in a text, INCLUDING the ones embedded in
|
|
118
|
+
* a backticked command (`bun run --watch src/server/index.ts` is one backtick
|
|
119
|
+
* span; the path inside it is what the requirement is about). Route literals
|
|
120
|
+
* (`/api`) and bare directories survive this filter — the caller decides what
|
|
121
|
+
* to do with them; `findOwnedFreezeConflicts` keeps only files.
|
|
122
|
+
*/
|
|
123
|
+
export function pathTokensIn(text) {
|
|
124
|
+
return tokensWithOrigin(text).map(t => t.path);
|
|
125
|
+
}
|
|
126
|
+
function tokensWithOrigin(text) {
|
|
127
|
+
const out = [];
|
|
128
|
+
const seen = new Set();
|
|
129
|
+
for (const m of text.matchAll(/`([^`]+)`/g)) {
|
|
130
|
+
const span = m[1];
|
|
131
|
+
const fromCommand = /\s/.test(span.trim());
|
|
132
|
+
for (const raw of span.split(/[\s,;()"']+/)) {
|
|
133
|
+
const token = raw.trim().replace(/[.,;:]+$/, '');
|
|
134
|
+
if (token.length === 0 || !/^[\w.@~/-]+$/.test(token))
|
|
135
|
+
continue;
|
|
136
|
+
if (!(token.includes('/') || /\.[A-Za-z0-9]+$/.test(token) || token.startsWith('.'))) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
// A leading `/` is a route literal or an absolute path — never a
|
|
140
|
+
// repo-relative source file, and `/api` is named by the very clause
|
|
141
|
+
// that is the true positive, so this one is not hypothetical.
|
|
142
|
+
if (token.startsWith('/'))
|
|
143
|
+
continue;
|
|
144
|
+
const n = token.replace(/^\.\//, '').replace(/\/+$/, '');
|
|
145
|
+
if (n.length === 0 || seen.has(n))
|
|
146
|
+
continue;
|
|
147
|
+
seen.add(n);
|
|
148
|
+
out.push({ path: n, fromCommand });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Does the requirement claim anything about the files it names BEYOND quoting a
|
|
155
|
+
* command that mentions them?
|
|
156
|
+
*
|
|
157
|
+
* This is what separates the two build-contract clauses of mx5 run 18's
|
|
158
|
+
* TASK_0023, which are otherwise the same shape:
|
|
159
|
+
*
|
|
160
|
+
* "**Client CSS:** `bunx @tailwindcss/cli -i src/client/index.css -o dist/app.css`"
|
|
161
|
+
* "**Server:** `bun run --watch src/server/index.ts` — serves `/api` + static `dist/`."
|
|
162
|
+
*
|
|
163
|
+
* The first is satisfied by putting that command in `package.json`; nothing
|
|
164
|
+
* about `src/client/index.css` has to change, so the freeze does not make it
|
|
165
|
+
* impossible. The second attaches a BEHAVIOURAL claim to the quoted file, and
|
|
166
|
+
* that claim can only be satisfied inside the file. Prose outside the backtick
|
|
167
|
+
* spans — minus the label, the anchor tag and the machine marker — is the
|
|
168
|
+
* signal; two words of it are enough.
|
|
169
|
+
*/
|
|
170
|
+
function hasClaimOutsideCommand(requirement) {
|
|
171
|
+
const prose = requirement
|
|
172
|
+
.replace(/`[^`]*`/g, ' ')
|
|
173
|
+
.replace(/—\s*owned\s+requirement\s+from\s+the\s+source\s+design[\s\S]*$/i, ' ')
|
|
174
|
+
.replace(/\[[^\]]*\]/g, ' ')
|
|
175
|
+
.replace(/\*\*[^*]*\*\*/g, ' ')
|
|
176
|
+
.replace(/^[\s\-"']+/, ' ');
|
|
177
|
+
const words = prose.match(/\b[A-Za-z][A-Za-z-]{1,}\b/g) ?? [];
|
|
178
|
+
return words.length >= 2;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The clause the exception keyword governs: from the keyword to the first
|
|
182
|
+
* clause break (an em dash, a semicolon, or a sentence end). Everything else on
|
|
183
|
+
* the line — notably the "— all engine modules (`document.ts`, …) must remain
|
|
184
|
+
* untouched" tail of gofer-pixel's freeze — is NOT an exemption.
|
|
185
|
+
*/
|
|
186
|
+
function exemptClause(line) {
|
|
187
|
+
const m = new RegExp(String.raw `\b${EXCEPT_KEYWORD}\b`, 'i').exec(line);
|
|
188
|
+
if (!m)
|
|
189
|
+
return null;
|
|
190
|
+
const rest = line.slice(m.index + m[0].length);
|
|
191
|
+
const brk = /\s+[—–]\s+|;|\.\s+[A-Z]|\.$/.exec(rest);
|
|
192
|
+
return brk ? rest.slice(0, brk.index) : rest;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Every CATEGORY freeze in the spec: a modification ban (or its passive/only-
|
|
196
|
+
* form equivalent) scoped to a class of files rather than to named paths. A
|
|
197
|
+
* freeze that only names paths is `frozen-conflict.ts`'s job, not this one.
|
|
198
|
+
*/
|
|
199
|
+
export function findCategoryFreezes(spec) {
|
|
200
|
+
if (!spec)
|
|
201
|
+
return [];
|
|
202
|
+
const out = [];
|
|
203
|
+
const seen = new Set();
|
|
204
|
+
for (const raw of spec.split('\n')) {
|
|
205
|
+
const line = raw.trim();
|
|
206
|
+
if (line.length === 0 || seen.has(line))
|
|
207
|
+
continue;
|
|
208
|
+
const isCategory = ACTIVE_CATEGORY_RE.test(line)
|
|
209
|
+
|| PASSIVE_CATEGORY_RE.test(line)
|
|
210
|
+
|| (ONLY_CATEGORY_RE.test(line) && PROHIBITION_RE.test(line) === false);
|
|
211
|
+
if (!isCategory || SCOPED_GRANT_RE.test(line))
|
|
212
|
+
continue;
|
|
213
|
+
const clause = ONLY_CATEGORY_RE.test(line) && exemptClause(line) === null ? line : exemptClause(line);
|
|
214
|
+
seen.add(line);
|
|
215
|
+
out.push({ constraint: line, exempt: clause === null ? [] : pathTokensIn(clause) });
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
const basename = (p) => p.slice(p.lastIndexOf('/') + 1);
|
|
220
|
+
/**
|
|
221
|
+
* Is `p` inside the freeze — i.e. NOT one of the exempted paths, a file under
|
|
222
|
+
* an exempted directory, or the same file spelled shorter?
|
|
223
|
+
*
|
|
224
|
+
* The last clause is load-bearing. gofer-pixel TASK_0011 exempts
|
|
225
|
+
* `src/components/Canvas.tsx` while its owned requirement quotes the design's
|
|
226
|
+
* table cell, which says just `Canvas.tsx` — the same file, and the spec is
|
|
227
|
+
* correctly formed. A bare basename is matched against the exempted paths'
|
|
228
|
+
* basenames; a path WITH a directory must match exactly or by prefix, so
|
|
229
|
+
* `src/a/config.ts` never counts as exempted by `src/b/config.ts`.
|
|
230
|
+
*/
|
|
231
|
+
function insideFreeze(p, exempt) {
|
|
232
|
+
return !exempt.some(e => e === p
|
|
233
|
+
|| p.startsWith(`${e}/`)
|
|
234
|
+
|| pathNamedIn(p, e)
|
|
235
|
+
|| (!p.includes('/') && basename(e) === p));
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* The spec lines carrying an AUTHORITATIVE owned requirement: the machine-
|
|
239
|
+
* stamped ones, plus — when the run's ledger is supplied — any line carrying an
|
|
240
|
+
* owned quote verbatim (compose folding the quote in itself leaves no stamp).
|
|
241
|
+
*/
|
|
242
|
+
export function ownedRequirementLines(spec, owned = []) {
|
|
243
|
+
if (!spec)
|
|
244
|
+
return [];
|
|
245
|
+
const quotes = owned.map(o => o.quote.trim()).filter(q => q.length > 0);
|
|
246
|
+
const out = [];
|
|
247
|
+
const seen = new Set();
|
|
248
|
+
for (const raw of spec.split('\n')) {
|
|
249
|
+
const line = raw.trim();
|
|
250
|
+
if (line.length === 0 || seen.has(line))
|
|
251
|
+
continue;
|
|
252
|
+
if (!OWNED_MARKER_RE.test(line) && !quotes.some(q => line.includes(q)))
|
|
253
|
+
continue;
|
|
254
|
+
seen.add(line);
|
|
255
|
+
out.push(line);
|
|
256
|
+
}
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Every unsatisfiable pair in the composed spec: an AUTHORITATIVE owned
|
|
261
|
+
* requirement naming a file that a CATEGORY freeze in the same spec forbids
|
|
262
|
+
* touching. Deterministic, pure text (plus the caller's existence oracle).
|
|
263
|
+
* Empty when the spec froze no category or carries no owned requirement — the
|
|
264
|
+
* ordinary single-`/task` case degrades to a no-op.
|
|
265
|
+
*/
|
|
266
|
+
export function findOwnedFreezeConflicts(spec, opts = {}) {
|
|
267
|
+
if (!spec)
|
|
268
|
+
return [];
|
|
269
|
+
const freezes = findCategoryFreezes(spec);
|
|
270
|
+
if (freezes.length === 0)
|
|
271
|
+
return [];
|
|
272
|
+
// Scoped ownership granted ANYWHERE in the spec settles the file, even when
|
|
273
|
+
// the grant is a line the rewrite added next to an untouched category
|
|
274
|
+
// freeze — otherwise a correctly resolved spec re-fires forever.
|
|
275
|
+
const granted = spec
|
|
276
|
+
.split('\n')
|
|
277
|
+
.filter(l => SCOPED_GRANT_RE.test(l))
|
|
278
|
+
.flatMap(l => pathTokensIn(l));
|
|
279
|
+
const out = [];
|
|
280
|
+
for (const requirement of ownedRequirementLines(spec, opts.owned)) {
|
|
281
|
+
// An owned requirement that is itself prohibition-shaped restates the
|
|
282
|
+
// freeze side; it can never be the thing the freeze makes impossible.
|
|
283
|
+
if (PROHIBITION_RE.test(requirement))
|
|
284
|
+
continue;
|
|
285
|
+
const claim = hasClaimOutsideCommand(requirement);
|
|
286
|
+
const named = tokensWithOrigin(requirement)
|
|
287
|
+
.filter(t => claim || !t.fromCommand)
|
|
288
|
+
.map(t => t.path)
|
|
289
|
+
.filter(p => !opts.isSource || opts.isSource(p));
|
|
290
|
+
if (named.length === 0)
|
|
291
|
+
continue;
|
|
292
|
+
// One finding per requirement: the FIRST freeze that covers any of its
|
|
293
|
+
// files. A spec that restates the same freeze under ACCEPTANCE (run 18
|
|
294
|
+
// does) must not double the rewrite's work.
|
|
295
|
+
for (const f of freezes) {
|
|
296
|
+
const paths = named.filter(p => insideFreeze(p, [...f.exempt, ...granted]));
|
|
297
|
+
if (paths.length === 0)
|
|
298
|
+
continue;
|
|
299
|
+
out.push({ requirement, paths, constraint: f.constraint, exempt: f.exempt });
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return out;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* The measured `isSource` oracle: a token counts only when git tracks it in
|
|
307
|
+
* `cwd`. Tracked ⇒ it exists, it is not a build output, and it is not ignored —
|
|
308
|
+
* exactly the "source file" the category freezes talk about. `git` missing or
|
|
309
|
+
* the tree not a repo ⇒ every token counts (the broad reading), so the detector
|
|
310
|
+
* degrades toward firing rather than toward silent blindness.
|
|
311
|
+
*/
|
|
312
|
+
export function trackedSourceOracle(lsFiles) {
|
|
313
|
+
const cache = new Map();
|
|
314
|
+
return p => {
|
|
315
|
+
const hit = cache.get(p);
|
|
316
|
+
if (hit !== undefined)
|
|
317
|
+
return hit;
|
|
318
|
+
const r = lsFiles(p);
|
|
319
|
+
const ok = r.exitCode !== 0 ? true : r.stdout.trim().length > 0;
|
|
320
|
+
cache.set(p, ok);
|
|
321
|
+
return ok;
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* The forced critique-rewrite defect text, in the shape the existing four
|
|
326
|
+
* families use: MANDATORY, self-contained, naming the exact resolutions. Prose
|
|
327
|
+
* surrender and silently dropping the requirement are called out as
|
|
328
|
+
* non-resolutions because narrowing the clause is precisely what run 16 did and
|
|
329
|
+
* freezing its file is precisely what run 18 did.
|
|
330
|
+
*/
|
|
331
|
+
export function ownedFreezeConflictProbeText(conflicts) {
|
|
332
|
+
const items = conflicts.map(c => `- the spec carries the AUTHORITATIVE owned requirement `
|
|
333
|
+
+ `"${c.requirement.slice(0, 200)}", which names ${c.paths.map(p => `\`${p}\``).join(', ')} — `
|
|
334
|
+
+ `and the spec FREEZES ${c.paths.length > 1 ? 'those files' : 'that file'} with a CATEGORY freeze `
|
|
335
|
+
+ `("${c.constraint.slice(0, 160)}"`
|
|
336
|
+
+ (c.exempt.length > 0 ?
|
|
337
|
+
`, which exempts only ${c.exempt.map(e => `\`${e}\``).join(', ')}`
|
|
338
|
+
: '')
|
|
339
|
+
+ ')');
|
|
340
|
+
return [
|
|
341
|
+
'UNSATISFIABLE-CONSTRAINT FINDING (deterministic; MUST be resolved, it overrides a CLEAN triage):',
|
|
342
|
+
...items,
|
|
343
|
+
'An owned requirement is AUTHORITATIVE: it comes from the source design and this task',
|
|
344
|
+
'owns it. A category freeze that covers the only file which could satisfy it makes the',
|
|
345
|
+
'requirement structurally impossible INSIDE THIS TASK, and the task will still pass its',
|
|
346
|
+
'own VERIFY — because VERIFY can then only assert strings in the files it is allowed to',
|
|
347
|
+
'touch. Narrowing the requirement to what the unfrozen files can express, or dropping it,',
|
|
348
|
+
'is NOT a resolution.',
|
|
349
|
+
'REWRITE the spec to resolve it in exactly ONE of these two ways:',
|
|
350
|
+
' (a) SCOPED OWNERSHIP — widen the category freeze for that file only:',
|
|
351
|
+
' "You MAY edit `<path>` ONLY as far as the owned requirement requires; any other',
|
|
352
|
+
' change to `<path>` is forbidden." Then make ACCEPTANCE state the requirement\'s',
|
|
353
|
+
' BEHAVIOUR and make VERIFY exercise that behaviour, not the presence of a string.',
|
|
354
|
+
' (b) REASSIGN — state that the owned requirement is not satisfiable in this task and',
|
|
355
|
+
" belongs to the task that owns `<path>`, and remove it from this spec's",
|
|
356
|
+
' CONSTRAINTS/ACCEPTANCE so it is not falsely claimed as met here.',
|
|
357
|
+
'Never ship both the category freeze and the owned requirement it makes impossible.'
|
|
358
|
+
].join('\n');
|
|
359
|
+
}
|
package/dist/task/phases.d.ts
CHANGED
|
@@ -132,7 +132,18 @@ export interface PhaseAutoAnswerDeps {
|
|
|
132
132
|
export declare function phaseAutoAnswer(deps: PhaseDeps, refined: string, research: string, question: string, autoDeps?: PhaseAutoAnswerDeps): Promise<AutoAnswer>;
|
|
133
133
|
export declare function phaseGrill(deps: PhaseDeps, ctx: ExtensionCommandContext, widgetState: WidgetState, refined: string, research: string): Promise<string>;
|
|
134
134
|
export declare function phaseCompose(deps: PhaseDeps, refined: string, research: string, qa: string): Promise<string>;
|
|
135
|
-
export declare function phaseCritique(deps: PhaseDeps, spec: string, refined: string, qa: string, planContext?: string, research?: string
|
|
135
|
+
export declare function phaseCritique(deps: PhaseDeps, spec: string, refined: string, qa: string, planContext?: string, research?: string,
|
|
136
|
+
/**
|
|
137
|
+
* An additional deterministic defect block, forced into the rewrite exactly
|
|
138
|
+
* like the probes below and overriding a CLEAN triage the same way.
|
|
139
|
+
*
|
|
140
|
+
* This is the A/B seam for a probe that is not wired yet: the discipline
|
|
141
|
+
* here is "wire only on PASS" (memory/prompt4-spec-urls-failed.md), so a
|
|
142
|
+
* candidate probe has to be measurable through the SHIPPED critique path
|
|
143
|
+
* rather than through a hand-copied replica of it, or the two arms differ by
|
|
144
|
+
* more than the probe. Undefined in production.
|
|
145
|
+
*/
|
|
146
|
+
extraDefects?: string | null): Promise<string>;
|
|
136
147
|
export declare function critiqueWithFallback(d: PhaseDeps, p: PhaseContext): Promise<string>;
|
|
137
148
|
export declare const PHASES: PhaseConfig[];
|
|
138
149
|
export declare function postCommitPhase(phase: PhaseConfig, deps: PhaseDeps, pc: PhaseContext, out: string): Promise<void>;
|
package/dist/task/phases.js
CHANGED
|
@@ -1269,7 +1269,18 @@ export async function phaseCompose(deps, refined, research, qa) {
|
|
|
1269
1269
|
return { ok: true, value: stripped };
|
|
1270
1270
|
}, problem => new Error(`compose_invalid: ${problem}`));
|
|
1271
1271
|
}
|
|
1272
|
-
export async function phaseCritique(deps, spec, refined, qa, planContext, research
|
|
1272
|
+
export async function phaseCritique(deps, spec, refined, qa, planContext, research,
|
|
1273
|
+
/**
|
|
1274
|
+
* An additional deterministic defect block, forced into the rewrite exactly
|
|
1275
|
+
* like the probes below and overriding a CLEAN triage the same way.
|
|
1276
|
+
*
|
|
1277
|
+
* This is the A/B seam for a probe that is not wired yet: the discipline
|
|
1278
|
+
* here is "wire only on PASS" (memory/prompt4-spec-urls-failed.md), so a
|
|
1279
|
+
* candidate probe has to be measurable through the SHIPPED critique path
|
|
1280
|
+
* rather than through a hand-copied replica of it, or the two arms differ by
|
|
1281
|
+
* more than the probe. Undefined in production.
|
|
1282
|
+
*/
|
|
1283
|
+
extraDefects) {
|
|
1273
1284
|
// Fast triage before the expensive full rewrite. The rewrite regenerates
|
|
1274
1285
|
// the entire spec from scratch and is the costliest tail of the pipeline
|
|
1275
1286
|
// (observed up to ~240s). Most compose drafts are already good, so we first
|
|
@@ -1392,7 +1403,8 @@ export async function phaseCritique(deps, spec, refined, qa, planContext, resear
|
|
|
1392
1403
|
&& absenceProbe === null
|
|
1393
1404
|
&& frozenProbe === null
|
|
1394
1405
|
&& grepOnlyProbe === null
|
|
1395
|
-
&& scriptProbe === null
|
|
1406
|
+
&& scriptProbe === null
|
|
1407
|
+
&& (extraDefects ?? null) === null) {
|
|
1396
1408
|
return spec;
|
|
1397
1409
|
}
|
|
1398
1410
|
}
|
|
@@ -1411,6 +1423,7 @@ export async function phaseCritique(deps, spec, refined, qa, planContext, resear
|
|
|
1411
1423
|
frozenProbe,
|
|
1412
1424
|
grepOnlyProbe,
|
|
1413
1425
|
scriptProbe,
|
|
1426
|
+
extraDefects ?? null,
|
|
1414
1427
|
triageDefects
|
|
1415
1428
|
]
|
|
1416
1429
|
.filter(Boolean)
|
|
@@ -11,6 +11,29 @@ export interface GrepOnlyVerifyFinding {
|
|
|
11
11
|
* source (doc/config-only tasks).
|
|
12
12
|
*/
|
|
13
13
|
export declare function findGrepOnlyVerify(spec: string): GrepOnlyVerifyFinding[];
|
|
14
|
+
/** One VERIFY command, classified by what it can observe. */
|
|
15
|
+
export interface VerifyCommandClass {
|
|
16
|
+
/** The command line, verbatim. */
|
|
17
|
+
raw: string;
|
|
18
|
+
/** Every pipeline segment is a STATIC head (grep/test/tsc/…) — it inspects
|
|
19
|
+
* files and can never observe the deliverable's behaviour. */
|
|
20
|
+
staticOnly: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The command observes RUNTIME behaviour: an HTTP request, a port probe, a
|
|
23
|
+
* process it starts and watches. This is the distinction nexttask 7's M3
|
|
24
|
+
* turns on — mx5 run 18's TASK_0023 VERIFY is all `node -e "…package.json…"`,
|
|
25
|
+
* which EXECUTES node yet can only assert that a string is present in a
|
|
26
|
+
* config file, and the behavioural half of the owned requirement ("serves
|
|
27
|
+
* `/api` + static `dist/`") is exactly what it cannot see.
|
|
28
|
+
*/
|
|
29
|
+
observesBehaviour: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Classify each command of a spec's VERIFY block. Shares `segmentHead` with the
|
|
33
|
+
* grep-theater detector, so "static" means one thing across the two measures.
|
|
34
|
+
* Empty when the spec has no runnable VERIFY block.
|
|
35
|
+
*/
|
|
36
|
+
export declare function classifyVerifyCommands(spec: string): VerifyCommandClass[];
|
|
14
37
|
/**
|
|
15
38
|
* Retry hint when the critique rewrite KEPT the grep-theater block it was told
|
|
16
39
|
* to fix (live A/B: 1/5 rewrites ignored the injected defect). Prepended to the
|
|
@@ -148,6 +148,28 @@ export function findGrepOnlyVerify(spec) {
|
|
|
148
148
|
}
|
|
149
149
|
return [...inspected.entries()].map(([target, lines]) => ({ target, lines }));
|
|
150
150
|
}
|
|
151
|
+
const BEHAVIOUR_RE = /\bcurl\b|\bwget\b|\bhttpie?\b|https?:\/\/|\bnc\s+-z\b|\bss\s+-|\blsof\b|127\.0\.0\.1|localhost|\bplaywright\b|\bfetch\(/i;
|
|
152
|
+
/**
|
|
153
|
+
* Classify each command of a spec's VERIFY block. Shares `segmentHead` with the
|
|
154
|
+
* grep-theater detector, so "static" means one thing across the two measures.
|
|
155
|
+
* Empty when the spec has no runnable VERIFY block.
|
|
156
|
+
*/
|
|
157
|
+
export function classifyVerifyCommands(spec) {
|
|
158
|
+
const cmds = parseVerifyBlock(spec);
|
|
159
|
+
if (!cmds)
|
|
160
|
+
return [];
|
|
161
|
+
return cmds.map(({ raw }) => {
|
|
162
|
+
let staticOnly = true;
|
|
163
|
+
for (const segment of raw.split(/&&|\|\||;|\|/)) {
|
|
164
|
+
const s = segmentHead(segment);
|
|
165
|
+
if (s === null)
|
|
166
|
+
continue;
|
|
167
|
+
if (!STATIC_HEADS.has(s.head))
|
|
168
|
+
staticOnly = false;
|
|
169
|
+
}
|
|
170
|
+
return { raw, staticOnly, observesBehaviour: BEHAVIOUR_RE.test(raw) };
|
|
171
|
+
});
|
|
172
|
+
}
|
|
151
173
|
/**
|
|
152
174
|
* Retry hint when the critique rewrite KEPT the grep-theater block it was told
|
|
153
175
|
* to fix (live A/B: 1/5 rewrites ignored the injected defect). Prepended to the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mjasnikovs/pi-task",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.3",
|
|
4
4
|
"description": "Deterministic task planning and spec-orchestration for local models — crash-safe /task pipelines with verify/enforce gates, a real-time remote web view, and web/docs/fetch/worker subagent tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|