@quolu/lattice 0.109.0 → 0.110.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/package.json +1 -1
- package/src/cli-help.mjs +8 -0
- package/src/cli-refusal-guidance.mjs +3 -0
- package/src/function-split-verify.mjs +396 -0
- package/src/plan-backchain.mjs +18 -7
- package/src/plan-revise.mjs +14 -11
- package/src/project-cli.mjs +3 -0
- package/src/seam-apply.mjs +2 -2
- package/src/sensor-adapter.mjs +14 -7
- package/src/todo-cli.mjs +113 -10
- package/src/todo-contracts.mjs +56 -4
- package/src/todo-function-split.mjs +234 -0
- package/src/todo-gantt-html-independence.mjs +2 -2
- package/src/todo-gantt-html-shared.mjs +4 -1
- package/src/todo-gantt-html.mjs +4 -2
- package/src/todo-note-store.mjs +3 -2
- package/src/todo-revision.mjs +5 -5
- package/src/todo-split-labels.mjs +26 -0
- package/src/todo-split-start.mjs +100 -0
- package/src/todo-split-store.mjs +100 -0
- package/src/todo-store-view.mjs +3 -2
- package/src/todo-store.mjs +40 -25
- package/src/todo-version-compact.mjs +22 -13
- package/src/todo-version-memo.mjs +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quolu/lattice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.110.1",
|
|
4
4
|
"description": "Schedulability compiler for multi-agent development: observe real code boundaries, refactor the conflicting seam, recompile the plan for parallel execution",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Quo / クオ at kitepon.dev",
|
package/src/cli-help.mjs
CHANGED
|
@@ -191,6 +191,8 @@ Write commands:
|
|
|
191
191
|
seam-proposal compile --plan <key> # 並列可否記録と実sensorからseam提案を記録する
|
|
192
192
|
seam-proposal apply --plan <key> # 記録済み提案を隔離worktreeで適用し五条件で採否を決める
|
|
193
193
|
seam-proposal land --plan <key> --names <file> # 採用された変換を本ツリーへ着地させる
|
|
194
|
+
function-split verify --plan <key> --task <id> --commit <sha> [--base <sha>] --map <task>=<path#function>[,...] # 関数分割工程S: 作業者の切り出しを五条件で検査して記録する
|
|
195
|
+
function-split decline --plan <key> --task <id> --reason <text> # 分けない: Sを閉じ、先に着手した工程の後ろへ他をつなぐ
|
|
194
196
|
split --plan <key> --input <file> # in-progress ToDoを抽出群とpending残差へrevisionする
|
|
195
197
|
revise --plan <key> --input <file>
|
|
196
198
|
revise-phase --plan <key> --input <file>
|
|
@@ -364,6 +366,12 @@ const SUBCOMMAND_USAGE = Object.freeze({
|
|
|
364
366
|
'todo structure': 'todo structure --schema --json | [--plan <key>] --json | input --plan <key> --input <file> [--dry-run --json] | compile --plan <key> --input <file> | realize --plan <key> --task <id> (--planned|--realized <actual-structure.json>) [--commit <HEAD|sha>]... | realize --plan <key> --task <id> --input <full-realization.json> | finalize --plan <key> --json',
|
|
365
367
|
'todo seam-profile': 'todo seam-profile --plan <key> --file <path> [--json]',
|
|
366
368
|
'todo seam-proposal': 'todo seam-proposal [--plan <key>] [--json] | compile --plan <key>',
|
|
369
|
+
'todo function-split': [
|
|
370
|
+
'todo function-split verify --plan <key> --task <id> --commit <sha> [--base <sha>] --map <task>=<path#function>[,...]',
|
|
371
|
+
'todo function-split decline --plan <key> --task <id> --reason <text>',
|
|
372
|
+
].join('\n lattice '),
|
|
373
|
+
'todo function-split verify': 'todo function-split verify --plan <key> --task <id> --commit <sha> [--base <sha>] --map <task>=<path#function>[,...] # ADR 0205: behaviour, tests, fresh, overlap, parallel on the commit',
|
|
374
|
+
'todo function-split decline': 'todo function-split decline --plan <key> --task <id> --reason <text> # 分割しない(ADR 0205)',
|
|
367
375
|
'todo verify': 'todo verify [--plan <key>] [--json]',
|
|
368
376
|
'todo repair-eol': 'todo repair-eol --json',
|
|
369
377
|
'todo snapshot': 'todo snapshot --rebuild --plan <key>',
|
|
@@ -463,6 +463,9 @@ const REGISTRY = {
|
|
|
463
463
|
done_condition_schema_downgrade: {
|
|
464
464
|
repair: (detail) => `The desired plan schema ${q(detail.desired_schema)} drops done_condition from ${q(detail.predecessor_schema)}: build the desired plan with ${q(detail.predecessor_schema)}.`,
|
|
465
465
|
},
|
|
466
|
+
function_split_schema_downgrade: {
|
|
467
|
+
repair: (detail) => `The desired plan schema ${q(detail.desired_schema)} drops function_split from ${q(detail.predecessor_schema)}: build the desired plan with ${q(detail.predecessor_schema)}.`,
|
|
468
|
+
},
|
|
466
469
|
acquire_phase_requires_unassigned_predecessor: {
|
|
467
470
|
repair: (detail) => `Task ${migratedTask(detail)} already has a phase, so it cannot acquire one: migrate it with policy 'carry' or 'reset' instead.`,
|
|
468
471
|
},
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code graph's side of ADR 0205 §3-§4: check a worker's function-split commit, and size the cut before the worker decides.
|
|
3
|
+
*
|
|
4
|
+
* The cut itself is the worker's code change; this module only observes it. It never reads the plan or the journal (the
|
|
5
|
+
* overlap and parallel conditions are Plan/lifecycle's), and never writes the source repository: every observation runs
|
|
6
|
+
* in a disposable worktree of the commit with ONE fresh index, reused for the tests, the file nodes and Resolve.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { execFile, spawnSync } from 'node:child_process';
|
|
10
|
+
import { existsSync } from 'node:fs';
|
|
11
|
+
import { mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { promisify } from 'node:util';
|
|
15
|
+
|
|
16
|
+
import { runIsolatedTransform } from './isolation-runner.mjs';
|
|
17
|
+
import { computeSeamCostProfile } from './seam-cost.mjs';
|
|
18
|
+
import { buildOutputMounts, detectSeveredReferences } from './seam-apply.mjs';
|
|
19
|
+
import { compareExportSurface } from './seam-verification.mjs';
|
|
20
|
+
import { runSensorCli } from './sensor-cli.mjs';
|
|
21
|
+
import { resolveAnchors } from './sensor-resolve.mjs';
|
|
22
|
+
import { invokeSensorCli } from './sensor-runtime.mjs';
|
|
23
|
+
|
|
24
|
+
const execFileAsync = promisify(execFile);
|
|
25
|
+
const LIST_CAP = 64; // the splits record caps lists at 64 (ADR 0205 §2)
|
|
26
|
+
const DETAIL_CAP = 2048;
|
|
27
|
+
const JS_TS = /\.(?:mjs|cjs|js|jsx|ts|tsx|mts|cts)$/u;
|
|
28
|
+
const NODE_RUNNABLE = /\.(?:mjs|cjs|js)$/u;
|
|
29
|
+
const TEST_FILE = /(?:^|\/)(?:tests?|__tests__)\/|\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
30
|
+
const sink = { write() {} };
|
|
31
|
+
const compareText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
32
|
+
const cap = (list) => list.slice(0, LIST_CAP);
|
|
33
|
+
const clip = (text) => String(text).slice(0, DETAIL_CAP);
|
|
34
|
+
|
|
35
|
+
class InputError extends Error {
|
|
36
|
+
constructor(code, next_action, extra = {}) {
|
|
37
|
+
super(code);
|
|
38
|
+
this.error = { code, next_action, ...extra };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const git = async (repoRoot, args, options = {}) => (await execFileAsync('git', args, {
|
|
43
|
+
cwd: repoRoot, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, ...options,
|
|
44
|
+
})).stdout;
|
|
45
|
+
|
|
46
|
+
const safePath = (value) => typeof value === 'string' && value !== '' && !path.isAbsolute(value)
|
|
47
|
+
&& !value.split('/').includes('..');
|
|
48
|
+
const wellFormed = (entry) => safePath(entry?.path) && typeof entry?.symbol === 'string' && entry.symbol !== '';
|
|
49
|
+
|
|
50
|
+
function validate({ target, map, anchors }) {
|
|
51
|
+
if (!wellFormed(target)) throw new InputError('map_entry_malformed', 'target must be {path, symbol} (repo-relative path)');
|
|
52
|
+
const seen = new Set();
|
|
53
|
+
for (const entry of map) {
|
|
54
|
+
if (!wellFormed(entry) || typeof entry.task_id !== 'string' || entry.task_id === '' || seen.has(entry.task_id)) {
|
|
55
|
+
throw new InputError('map_entry_malformed', 'map takes one {task_id, path, symbol} per member, repo-relative paths');
|
|
56
|
+
}
|
|
57
|
+
seen.add(entry.task_id);
|
|
58
|
+
}
|
|
59
|
+
for (const entry of anchors) {
|
|
60
|
+
if (!wellFormed(entry) || typeof entry.task_id !== 'string') {
|
|
61
|
+
throw new InputError('map_entry_malformed', 'anchors take {task_id, path, symbol}');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A host's chart repository usually takes in main only, so the worker's cut is not there (ADR 0205 §4): fetch what is
|
|
68
|
+
* missing from `origin`, objects only (`--no-write-fetch-head`, no refspec: no ref moves). False when origin cannot give it.
|
|
69
|
+
*/
|
|
70
|
+
async function fetchFromOrigin(repoRoot, args) {
|
|
71
|
+
try {
|
|
72
|
+
await git(repoRoot, ['fetch', '--no-tags', '--no-recurse-submodules', '--no-write-fetch-head', ...args]);
|
|
73
|
+
return true;
|
|
74
|
+
} catch { return false; }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function revParse(repoRoot, ref, what) {
|
|
78
|
+
const parse = () => git(repoRoot, ['rev-parse', '--verify', `${ref}^{commit}`]).then((out) => out.trim(), () => null);
|
|
79
|
+
// only a full sha can be asked of origin; a branch name or abbreviation is the worker's to push.
|
|
80
|
+
const found = await parse() ?? (/^[0-9a-f]{40}$/iu.test(ref) && await fetchFromOrigin(repoRoot, ['origin', ref]) ? await parse() : null);
|
|
81
|
+
if (found === null) {
|
|
82
|
+
throw new InputError('commit_not_found', `${what} ${ref} is in neither this repository nor its origin: push the branch, then verify again`, { ref });
|
|
83
|
+
}
|
|
84
|
+
return found;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** merge-base(commit, HEAD); in a shallow clone, deepen and then unshallow until the two histories meet. */
|
|
88
|
+
async function mergeBaseWithHead(repoRoot, commitSha) {
|
|
89
|
+
const attempt = () => git(repoRoot, ['merge-base', commitSha, 'HEAD']).then((out) => out.trim(), () => null);
|
|
90
|
+
let found = await attempt();
|
|
91
|
+
if (found !== null || (await git(repoRoot, ['rev-parse', '--is-shallow-repository'])).trim() !== 'true') return found;
|
|
92
|
+
// shortcut: `HEAD` names origin's HEAD, which is the chart's branch on a host; deepen both sides, then everything.
|
|
93
|
+
for (const depth of ['--deepen=200', '--unshallow']) {
|
|
94
|
+
if (!await fetchFromOrigin(repoRoot, [depth, 'origin', commitSha, 'HEAD'])) break;
|
|
95
|
+
found = await attempt();
|
|
96
|
+
if (found !== null) return found;
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** `git diff --name-status`: [{status: A|M|D|..., path}]. No rename detection: a rename is a delete plus an add. */
|
|
102
|
+
async function changedFiles(repoRoot, base, commit) {
|
|
103
|
+
const fields = (await git(repoRoot, ['diff', '--name-status', '-z', '--no-renames', base, commit])).split('\0');
|
|
104
|
+
const changes = [];
|
|
105
|
+
for (let at = 0; at + 1 < fields.length; at += 2) changes.push({ status: fields[at][0], path: fields[at + 1] });
|
|
106
|
+
return changes;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const spanKey = (rows) => rows.map((row) => `${row.start_line}-${row.end_line}`).sort(compareText).join(',');
|
|
110
|
+
|
|
111
|
+
/** Runs `work` inside a disposable worktree of `ref` with one fresh index; `verifyCommands` may be filled by `work`. */
|
|
112
|
+
async function atRef({ repoRoot, ref, work, verifyCommands = [] }) {
|
|
113
|
+
const scratch = await mkdtemp(path.join(tmpdir(), 'lattice-split-index-'));
|
|
114
|
+
try {
|
|
115
|
+
return await runIsolatedTransform({
|
|
116
|
+
repoRoot, baseRef: ref, allowedPaths: [], verifyCommands,
|
|
117
|
+
transform: ({ worktreePath }) => work(worktreePath),
|
|
118
|
+
mounts: [
|
|
119
|
+
{ entry: 'node_modules', target: path.join(repoRoot, 'node_modules') },
|
|
120
|
+
{ entry: '.lattice/sensor', target: scratch },
|
|
121
|
+
...await buildOutputMounts(repoRoot),
|
|
122
|
+
],
|
|
123
|
+
verifierEnv: { LATTICE_DASHBOARD_AUTOSTART: '0' },
|
|
124
|
+
});
|
|
125
|
+
} finally {
|
|
126
|
+
await rm(scratch, { recursive: true, force: true });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function indexWorktree(worktreePath) {
|
|
131
|
+
if (await runSensorCli({ argv: ['init', worktreePath, '--json'], stdout: sink, stderr: sink }) !== 0) {
|
|
132
|
+
throw new Error('sensor_init_failed');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function fileNodes(worktreePath, file) {
|
|
137
|
+
const result = invokeSensorCli(
|
|
138
|
+
(command, args, options) => spawnSync(command, args, options),
|
|
139
|
+
['file-nodes', file, '--path', '.'],
|
|
140
|
+
{ cwd: worktreePath, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 },
|
|
141
|
+
);
|
|
142
|
+
if (result.status !== 0) return null;
|
|
143
|
+
try { return JSON.parse(result.stdout)?.nodes ?? null; } catch { return null; }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function affectedTests(worktreePath, files) {
|
|
147
|
+
const result = invokeSensorCli(
|
|
148
|
+
(command, args, options) => spawnSync(command, args, options),
|
|
149
|
+
['affected', ...files, '--path', '.', '--json'],
|
|
150
|
+
{ cwd: worktreePath, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 },
|
|
151
|
+
);
|
|
152
|
+
if (result.status !== 0) return null;
|
|
153
|
+
try { return JSON.parse(result.stdout)?.affectedTests ?? null; } catch { return null; }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Resolve rows of each requested `{path, symbol}`: Map key `path\0symbol` -> rows; plus the misses and ambiguous names. */
|
|
157
|
+
async function resolveAll(root, wanted) {
|
|
158
|
+
const unique = [...new Map(wanted.map(({ path: p, symbol }) => [`${p}\0${symbol}`, { path: p, symbol }])).values()];
|
|
159
|
+
const answer = await resolveAnchors({ root, anchors: unique });
|
|
160
|
+
const rows = new Map();
|
|
161
|
+
for (const row of answer.resolved) {
|
|
162
|
+
const key = `${row.path}\0${row.symbol}`;
|
|
163
|
+
rows.set(key, [...(rows.get(key) ?? []), row]);
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
rows,
|
|
167
|
+
unresolved: new Map(answer.unresolved.map((item) => [`${item.path}\0${item.symbol}`, item])),
|
|
168
|
+
ambiguous: new Map(answer.ambiguous.map((item) => [`${item.path}\0${item.symbol}`, item])),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const keyOf = ({ path: p, symbol }) => `${p}\0${symbol}`;
|
|
173
|
+
|
|
174
|
+
/** Why an entry is not usable: `{reason, nearest|candidates}` or null when it resolved to one definition. */
|
|
175
|
+
function missOf(resolved, entry) {
|
|
176
|
+
const key = keyOf(entry);
|
|
177
|
+
if (resolved.ambiguous.has(key)) return { reason: 'ambiguous', candidates: resolved.ambiguous.get(key).names };
|
|
178
|
+
if (!resolved.rows.has(key)) {
|
|
179
|
+
const miss = resolved.unresolved.get(key);
|
|
180
|
+
return { reason: 'not_found', nearest: (miss?.nearest ?? []).slice(0, 5) };
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The base side: ranges of the target and mapped entries before the cut, and the graph nodes of deleted non-JS files. */
|
|
186
|
+
async function observeBase({ repoRoot, base, target, map, deletedOther }) {
|
|
187
|
+
const seen = { rows: new Map(), deletedWithNodes: [] };
|
|
188
|
+
await atRef({
|
|
189
|
+
repoRoot, ref: base,
|
|
190
|
+
work: async (worktreePath) => {
|
|
191
|
+
await indexWorktree(worktreePath);
|
|
192
|
+
seen.rows = (await resolveAll(worktreePath, [target, ...map])).rows;
|
|
193
|
+
for (const file of deletedOther) {
|
|
194
|
+
if ((fileNodes(worktreePath, file) ?? []).length > 0) seen.deletedWithNodes.push(file);
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
return seen;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function textAt(repoRoot, ref, file) {
|
|
202
|
+
try { return await git(repoRoot, ['show', `${ref}:${file}`]); } catch { return ''; }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Verify a function-split commit (ADR 0205 §4, behaviour / tests / fresh; overlap and parallel are Plan/lifecycle's).
|
|
207
|
+
* → `{base, commit, target, behaviour, tests, fresh, ranges, anchors_unresolved, map}` or `{error: {code, next_action}}`.
|
|
208
|
+
*/
|
|
209
|
+
export async function verifyFunctionSplit({ repoRoot, commit, base, target, map = [], anchors = [] } = {}) {
|
|
210
|
+
try {
|
|
211
|
+
validate({ target, map, anchors });
|
|
212
|
+
const commitSha = await revParse(repoRoot, commit, 'commit');
|
|
213
|
+
const baseSha = base === undefined
|
|
214
|
+
? await mergeBaseWithHead(repoRoot, commitSha) ?? (() => {
|
|
215
|
+
throw new InputError('commit_not_found', 'commit shares no history with HEAD (origin has none either): pass --base', { ref: commit });
|
|
216
|
+
})()
|
|
217
|
+
: await revParse(repoRoot, base, 'base');
|
|
218
|
+
if (baseSha === commitSha) {
|
|
219
|
+
throw new InputError('empty_diff', 'the commit is already on HEAD or equals base: pass --base <main sha before the merge>');
|
|
220
|
+
}
|
|
221
|
+
const changes = await changedFiles(repoRoot, baseSha, commitSha);
|
|
222
|
+
if (changes.length === 0) throw new InputError('empty_diff', 'no file differs between base and commit: pass a different --base or commit');
|
|
223
|
+
if (!changes.some((change) => change.path === target.path)) {
|
|
224
|
+
throw new InputError('target_untouched', `the diff base..commit does not touch ${target.path}: the cut must change the target file`);
|
|
225
|
+
}
|
|
226
|
+
return await observe({ repoRoot, baseSha, commitSha, changes, target, map, anchors });
|
|
227
|
+
} catch (error) {
|
|
228
|
+
if (error instanceof InputError) return { error: error.error };
|
|
229
|
+
const errors = error instanceof AggregateError ? error.errors : [error];
|
|
230
|
+
const dirty = errors.find((item) => String(item?.message).startsWith('source repository must be clean'));
|
|
231
|
+
if (dirty) {
|
|
232
|
+
return { error: { code: 'source_dirty', next_action: 'commit or stash the changes in the repository, then verify again', detail: clip(dirty.message) } };
|
|
233
|
+
}
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function observe({ repoRoot, baseSha, commitSha, changes, target, map, anchors }) {
|
|
239
|
+
const alive = changes.filter(({ status }) => status !== 'D').map(({ path: p }) => p);
|
|
240
|
+
const deletedOther = changes.filter(({ status, path: p }) => status === 'D' && !JS_TS.test(p)).map(({ path: p }) => p);
|
|
241
|
+
const state = { failures: [], resolved: null, unobserved: null, tests: null };
|
|
242
|
+
|
|
243
|
+
let baseSeen = null;
|
|
244
|
+
try {
|
|
245
|
+
baseSeen = await observeBase({ repoRoot, base: baseSha, target, map, deletedOther });
|
|
246
|
+
} catch (error) {
|
|
247
|
+
if (String(error?.message).startsWith('source repository must be clean')) throw error;
|
|
248
|
+
// existed_at_base is recorded, not a condition (ADR 0205 §4): a failed base index leaves it null.
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const verifyCommands = [];
|
|
252
|
+
const work = async (worktreePath) => {
|
|
253
|
+
try {
|
|
254
|
+
await indexWorktree(worktreePath);
|
|
255
|
+
} catch (error) {
|
|
256
|
+
state.indexFailure = clip(error.message);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
// behaviour: export surface per JS/TS file, the graph for every other language.
|
|
260
|
+
for (const { status, path: file } of changes) {
|
|
261
|
+
if (JS_TS.test(file)) {
|
|
262
|
+
const before = status === 'A' ? '' : await textAt(repoRoot, baseSha, file);
|
|
263
|
+
const after = status === 'D' ? '' : await readFile(path.join(worktreePath, file), 'utf8');
|
|
264
|
+
const { missing } = compareExportSurface({ before, after });
|
|
265
|
+
if (missing.length > 0) state.failures.push(`export_surface_lost:${file}:${missing.join(',')}`);
|
|
266
|
+
} else if (status !== 'D' && (fileNodes(worktreePath, file) ?? []).length > 0) {
|
|
267
|
+
state.failures.push(`export_surface_unobserved:${file}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
for (const file of baseSeen?.deletedWithNodes ?? []) state.failures.push(`export_surface_unobserved:${file}`);
|
|
271
|
+
const others = {};
|
|
272
|
+
for (const file of alive) {
|
|
273
|
+
if (file !== target.path && JS_TS.test(file) && !TEST_FILE.test(file)) {
|
|
274
|
+
others[file] = await readFile(path.join(worktreePath, file), 'utf8');
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (alive.includes(target.path)) {
|
|
278
|
+
const severed = await detectSeveredReferences({ worktreePath, files: others, residualPath: target.path });
|
|
279
|
+
if (!severed.observed) state.failures.push('severed_observation_missing');
|
|
280
|
+
for (const { file, name } of severed.entries) state.failures.push(`severed_reference:${file}:${name}`);
|
|
281
|
+
}
|
|
282
|
+
state.resolved = await resolveAll(worktreePath, [target, ...map, ...anchors]);
|
|
283
|
+
// tests: the file-level affected tests of the changed files, the target and the mapped paths, on this index.
|
|
284
|
+
const roots = [...new Set([...alive, target.path, ...map.map(({ path: p }) => p)])]
|
|
285
|
+
.filter((file) => existsSync(path.join(worktreePath, file)));
|
|
286
|
+
const affected = affectedTests(worktreePath, roots);
|
|
287
|
+
if (affected === null) { state.testsFailure = 'affected_unavailable'; return; }
|
|
288
|
+
const runnable = affected.filter((file) => NODE_RUNNABLE.test(file)).sort(compareText);
|
|
289
|
+
state.tests = { runnable, skipped: affected.filter((file) => !NODE_RUNNABLE.test(file)).sort(compareText) };
|
|
290
|
+
for (const file of runnable) verifyCommands.push({ command: process.execPath, args: ['--test', file] });
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
let infra = null;
|
|
294
|
+
try {
|
|
295
|
+
await atRef({ repoRoot, ref: commitSha, work, verifyCommands });
|
|
296
|
+
state.testsPassed = true;
|
|
297
|
+
} catch (error) {
|
|
298
|
+
const errors = error instanceof AggregateError ? error.errors : [error];
|
|
299
|
+
const dirty = errors.find((item) => String(item?.message).startsWith('source repository must be clean'));
|
|
300
|
+
if (dirty) throw dirty;
|
|
301
|
+
const failed = errors.find((item) => String(item?.message).startsWith('verifier failed'));
|
|
302
|
+
if (failed) state.testsFailed = failed;
|
|
303
|
+
else infra = clip(errors.map((item) => item?.message).join(' | '));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return report({ baseSha, commitSha, target, map, anchors, baseSeen, state, verifyCommands, infra });
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function report({ baseSha, commitSha, target, map, anchors, baseSeen, state, verifyCommands, infra }) {
|
|
310
|
+
const cause = state.indexFailure ?? infra;
|
|
311
|
+
const resolved = state.resolved;
|
|
312
|
+
const ran = verifyCommands.map(({ args }) => args[1]);
|
|
313
|
+
const spans = (entry) => (resolved?.rows.get(keyOf(entry)) ?? []);
|
|
314
|
+
|
|
315
|
+
const behaviourFailures = cause ? [`worktree_failed:${cause}`] : state.failures;
|
|
316
|
+
const behaviour = { passed: behaviourFailures.length === 0, detail: behaviourFailures.length === 0 ? 'ok' : clip(behaviourFailures.join('; ')) };
|
|
317
|
+
|
|
318
|
+
let tests;
|
|
319
|
+
if (cause || state.testsFailure) {
|
|
320
|
+
tests = { passed: false, ran: [], not_run: [], skipped: [], detail: cause ? `worktree_failed:${cause}` : state.testsFailure };
|
|
321
|
+
} else if (state.tests.runnable.length === 0) {
|
|
322
|
+
tests = { passed: false, ran: [], not_run: [], skipped: cap(state.tests.skipped), detail: 'no_test_reaches_function' };
|
|
323
|
+
} else if (state.testsFailed) {
|
|
324
|
+
const stopped = String(state.testsFailed.message).match(/--test (\S+)/u)?.[1];
|
|
325
|
+
const at = ran.indexOf(stopped);
|
|
326
|
+
tests = {
|
|
327
|
+
passed: false, ran: cap(ran.slice(0, at + 1)), not_run: cap(ran.slice(at + 1)), skipped: cap(state.tests.skipped),
|
|
328
|
+
detail: clip(state.testsFailed.message),
|
|
329
|
+
};
|
|
330
|
+
} else {
|
|
331
|
+
tests = { passed: true, ran: cap(ran), not_run: [], skipped: cap(state.tests.skipped), detail: 'ok' };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const unresolved = [];
|
|
335
|
+
const anchorsUnresolved = [];
|
|
336
|
+
const ranges = [];
|
|
337
|
+
const mapOut = [];
|
|
338
|
+
if (resolved) {
|
|
339
|
+
for (const entry of map) {
|
|
340
|
+
const miss = missOf(resolved, entry);
|
|
341
|
+
if (miss) unresolved.push({ task_id: entry.task_id, path: entry.path, symbol: entry.symbol, ...miss });
|
|
342
|
+
const before = baseSeen?.rows.get(keyOf(entry));
|
|
343
|
+
mapOut.push({
|
|
344
|
+
...entry,
|
|
345
|
+
existed_at_base: baseSeen === null ? null : before !== undefined && spanKey(before) === spanKey(spans(entry)),
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
for (const entry of anchors) {
|
|
349
|
+
const miss = missOf(resolved, entry);
|
|
350
|
+
if (miss) anchorsUnresolved.push({ task_id: entry.task_id, path: entry.path, symbol: entry.symbol, ...miss });
|
|
351
|
+
}
|
|
352
|
+
for (const entry of [...map, ...anchors]) {
|
|
353
|
+
for (const row of spans(entry)) {
|
|
354
|
+
ranges.push({ task_id: entry.task_id, path: entry.path, symbol: entry.symbol, start_line: row.start_line, end_line: row.end_line });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
const targetRows = resolved ? spans(target) : [];
|
|
359
|
+
return {
|
|
360
|
+
base: baseSha,
|
|
361
|
+
commit: commitSha,
|
|
362
|
+
target: {
|
|
363
|
+
resolved: targetRows.length > 0,
|
|
364
|
+
start_line: targetRows.length > 0 ? Math.min(...targetRows.map((row) => row.start_line)) : null,
|
|
365
|
+
end_line: targetRows.length > 0 ? Math.max(...targetRows.map((row) => row.end_line)) : null,
|
|
366
|
+
},
|
|
367
|
+
behaviour,
|
|
368
|
+
tests,
|
|
369
|
+
fresh: resolved === null
|
|
370
|
+
? { passed: false, unresolved: [], detail: `worktree_failed:${cause ?? 'not_observed'}` }
|
|
371
|
+
: { passed: unresolved.length === 0, unresolved: cap(unresolved) },
|
|
372
|
+
// never capped: Plan/lifecycle's overlap check reads every row, and a lost row could turn an overlap into a pass.
|
|
373
|
+
ranges,
|
|
374
|
+
anchors_unresolved: anchorsUnresolved,
|
|
375
|
+
map: mapOut,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Size of the cut for `todo start S` (ADR 0205 §3): the seam-cost profile of the target function's file, every member
|
|
381
|
+
* owning F. Best effort: `{profile: null, reasons}` when the maintained index cannot answer. One owner key joins the member
|
|
382
|
+
* ids because they all own the same function; the profile's cross-task figures are therefore empty by construction.
|
|
383
|
+
*/
|
|
384
|
+
export async function cutCost({ repoRoot, target, memberTaskIds } = {}) {
|
|
385
|
+
if (!wellFormed(target) || !Array.isArray(memberTaskIds) || memberTaskIds.length === 0) {
|
|
386
|
+
return { profile: null, reasons: ['target_or_members_malformed'] };
|
|
387
|
+
}
|
|
388
|
+
let sourceText;
|
|
389
|
+
try { sourceText = await readFile(path.join(repoRoot, target.path), 'utf8'); } catch { return { profile: null, reasons: ['source_unreadable'] }; }
|
|
390
|
+
// the profile names nodes by their bare name; a qualified `Cls.method` is looked up by its last part.
|
|
391
|
+
const name = target.symbol.split('.').at(-1);
|
|
392
|
+
return computeSeamCostProfile({
|
|
393
|
+
repoRoot, sourcePath: target.path, sourceText,
|
|
394
|
+
ownedSymbolsByTask: { [[...memberTaskIds].sort(compareText).join('+')]: [name] },
|
|
395
|
+
});
|
|
396
|
+
}
|
package/src/plan-backchain.mjs
CHANGED
|
@@ -417,25 +417,36 @@ async function verifyExistingFeatureReferences(repoRoot, chain) {
|
|
|
417
417
|
}
|
|
418
418
|
|
|
419
419
|
const DONE_CONDITION_PLAN_SCHEMA = 'lattice.todo_plan.v8';
|
|
420
|
+
const SPLIT_PLAN_SCHEMA = 'lattice.todo_plan.v9';
|
|
420
421
|
|
|
421
422
|
/**
|
|
422
423
|
* authoring(create入力またはplan本体)から後継planの種を作る。
|
|
423
|
-
* 作る版: v5入力か先行planがv8ならv8
|
|
424
|
+
* 作る版: 先行planがv9、または splitMarks が分割を書くならv9(v8へ戻さない)。v5入力か先行planがv8ならv8、それ以外はv7。
|
|
424
425
|
* v8でdone_conditionを書いていないtask(v4入力)は、先行planの同じtaskの値を引き継ぐ
|
|
425
426
|
* (書き換えも消去もしていないので意味を変えない)。新規taskはnull。
|
|
427
|
+
* v9のfunction_splitは作成者が書けない(ADR 0205 §2): 先行planの同じtaskの値を引き継ぎ、
|
|
428
|
+
* splitMarks(Map task_id → 印 | null、`todo start` の分割だけが渡す)が上書きする。
|
|
426
429
|
*/
|
|
427
|
-
export function planSeed(authoring, predecessorPlanDigest, predecessorPlan = null) {
|
|
428
|
-
const
|
|
430
|
+
export function planSeed(authoring, predecessorPlanDigest, predecessorPlan = null, splitMarks = null) {
|
|
431
|
+
const marks = splitMarks ?? new Map();
|
|
432
|
+
const v9 = authoring.schema === SPLIT_PLAN_SCHEMA || predecessorPlan?.schema === SPLIT_PLAN_SCHEMA
|
|
433
|
+
|| [...marks.values()].some((mark) => mark !== null);
|
|
434
|
+
const v8 = v9 || authoring.schema === 'lattice.plan_create_input.v5'
|
|
429
435
|
|| authoring.schema === DONE_CONDITION_PLAN_SCHEMA
|
|
430
436
|
|| predecessorPlan?.schema === DONE_CONDITION_PLAN_SCHEMA;
|
|
431
|
-
const
|
|
432
|
-
? predecessorPlan.tasks.map((
|
|
437
|
+
const carried = (field) => new Map(['lattice.todo_plan.v8', SPLIT_PLAN_SCHEMA].includes(predecessorPlan?.schema)
|
|
438
|
+
? predecessorPlan.tasks.map((task) => [task.task_id, task[field] ?? null]) : []);
|
|
439
|
+
const inherited = carried('done_condition');
|
|
440
|
+
const split = carried('function_split');
|
|
433
441
|
return {
|
|
434
|
-
schema: v8 ? DONE_CONDITION_PLAN_SCHEMA : 'lattice.todo_plan.v7', project_id: authoring.project_id,
|
|
442
|
+
schema: v9 ? SPLIT_PLAN_SCHEMA : v8 ? DONE_CONDITION_PLAN_SCHEMA : 'lattice.todo_plan.v7', project_id: authoring.project_id,
|
|
435
443
|
plan_key: authoring.plan_key, predecessor_plan_digest: predecessorPlanDigest,
|
|
436
444
|
tasks: v8 ? authoring.tasks.map((task) => ({ ...task,
|
|
437
445
|
done_condition: Object.hasOwn(task, 'done_condition')
|
|
438
|
-
? task.done_condition : inherited.get(task.task_id) ?? null
|
|
446
|
+
? task.done_condition : inherited.get(task.task_id) ?? null,
|
|
447
|
+
...(v9 ? { function_split: marks.has(task.task_id) ? marks.get(task.task_id)
|
|
448
|
+
: Object.hasOwn(task, 'function_split') ? task.function_split : split.get(task.task_id) ?? null } : {}) }))
|
|
449
|
+
: authoring.tasks,
|
|
439
450
|
phases: authoring.phases,
|
|
440
451
|
hard_dependencies: authoring.hard_dependencies, joins: authoring.joins,
|
|
441
452
|
phase_accept_dependencies: authoring.phase_accept_dependencies,
|
package/src/plan-revise.mjs
CHANGED
|
@@ -19,6 +19,7 @@ import { phaseTodoRevisionPlanVersion, validatePhaseTodoRevision } from './todo-
|
|
|
19
19
|
export { validateBindingCarry } from './plan-binding-carry.mjs';
|
|
20
20
|
|
|
21
21
|
const INPUT_SCHEMA = 'lattice.plan_revise_input.v1';
|
|
22
|
+
const LIGHT_PLAN_SCHEMAS = ['lattice.todo_plan.v7', 'lattice.todo_plan.v8', 'lattice.todo_plan.v9'];
|
|
22
23
|
|
|
23
24
|
function fail(reason, pointer, detail = {}) {
|
|
24
25
|
throw new TodoStoreError('INPUT_INVALID', reason, undefined, { pointer, ...detail });
|
|
@@ -209,7 +210,7 @@ export function resolvePlanRevision({ member, input, env = process.env, now = ne
|
|
|
209
210
|
next_action: `lattice todo revise-phase --plan ${desired.plan_key} --input <phase-revision.json>`,
|
|
210
211
|
});
|
|
211
212
|
}
|
|
212
|
-
if (!
|
|
213
|
+
if (!LIGHT_PLAN_SCHEMAS.includes(member.plan.schema)) {
|
|
213
214
|
fail('predecessor_plan_schema_unsupported', '/desired/plan_key');
|
|
214
215
|
}
|
|
215
216
|
if (desired.project_id !== member.plan.project_id) {
|
|
@@ -231,7 +232,7 @@ export function compilePlanRevision({ member, input, env, now }) {
|
|
|
231
232
|
return compileLightRevision({ member, desired, continuity });
|
|
232
233
|
}
|
|
233
234
|
|
|
234
|
-
function compileLightRevision({ member, desired, continuity }) {
|
|
235
|
+
function compileLightRevision({ member, desired, continuity, splitMarks = null }) {
|
|
235
236
|
const taskMigration = continuity.map(({ task_id: id, policy }) => ({
|
|
236
237
|
from_task_id: id, to_task_id: policy === 'retire' ? 'removed' : id,
|
|
237
238
|
state_policy: policy === 'retire' ? 'removed'
|
|
@@ -241,7 +242,7 @@ function compileLightRevision({ member, desired, continuity }) {
|
|
|
241
242
|
journal_head_digest: member.journal.events.at(-1).event_digest,
|
|
242
243
|
plan_version: member.plan.plan_version,
|
|
243
244
|
};
|
|
244
|
-
const seed = planSeed(desired, predecessor.plan_digest, member.plan);
|
|
245
|
+
const seed = planSeed(desired, predecessor.plan_digest, member.plan, splitMarks);
|
|
245
246
|
const phaseMigration = compileLightPhaseMigration(member.plan, seed, taskMigration,
|
|
246
247
|
new Map(member.tasks.map(({ task_id: id, status }) => [id, status])));
|
|
247
248
|
const version = phaseTodoRevisionPlanVersion({
|
|
@@ -281,7 +282,7 @@ export async function planReviseSchema() {
|
|
|
281
282
|
* (v7/v8以外・源泉束縛・旧event・compile_binding付きtask)ならfalse。書く前の判定にだけ使う。
|
|
282
283
|
*/
|
|
283
284
|
export function lightRevisionExpresses(member) {
|
|
284
|
-
return
|
|
285
|
+
return LIGHT_PLAN_SCHEMAS.includes(member.plan.schema)
|
|
285
286
|
&& member.journal.events[0]?.schema !== 'lattice.todo_event.v2'
|
|
286
287
|
&& member.plan.tasks.every((task) => task.narrative_anchor === null && task.compile_binding === null);
|
|
287
288
|
}
|
|
@@ -297,18 +298,19 @@ export function desiredFromPlan(plan, { env = process.env, now = new Date() } =
|
|
|
297
298
|
next_action: `lattice todo revise-phase --plan ${plan.plan_key} --input <phase-revision.json>`,
|
|
298
299
|
});
|
|
299
300
|
}
|
|
300
|
-
if (!
|
|
301
|
+
if (!LIGHT_PLAN_SCHEMAS.includes(plan.schema)) {
|
|
301
302
|
fail('predecessor_plan_schema_unsupported', '/desired/plan_key');
|
|
302
303
|
}
|
|
303
304
|
const edge = ({ from, to }) => ({
|
|
304
305
|
from: { project_id: from.project_id, plan_key: from.plan_key, task_id: from.task_id },
|
|
305
306
|
to: { project_id: to.project_id, plan_key: to.plan_key, task_id: to.task_id } });
|
|
306
307
|
return {
|
|
307
|
-
schema: plan.schema === 'lattice.todo_plan.
|
|
308
|
-
? 'lattice.plan_create_input.
|
|
308
|
+
schema: plan.schema === 'lattice.todo_plan.v7'
|
|
309
|
+
? 'lattice.plan_create_input.v4' : 'lattice.plan_create_input.v5',
|
|
309
310
|
project_id: plan.project_id, plan_key: plan.plan_key, plan_version: plan.plan_version,
|
|
310
311
|
actor: resolveTodoActor(env), recorded_at: now.toISOString(),
|
|
311
|
-
|
|
312
|
+
// function_split is not authorable (ADR 0205 §2): planSeed carries it from the predecessor by task id.
|
|
313
|
+
tasks: plan.tasks.map(({ function_split: _split, ...task }) => task), phases: plan.phases,
|
|
312
314
|
hard_dependencies: plan.hard_dependencies.map(edge), joins: plan.joins,
|
|
313
315
|
phase_accept_dependencies: plan.phase_accept_dependencies,
|
|
314
316
|
};
|
|
@@ -348,7 +350,7 @@ function unwrapPointers(error) {
|
|
|
348
350
|
}
|
|
349
351
|
|
|
350
352
|
export async function applyPlanRevision({
|
|
351
|
-
repoRoot, input: authored, env = process.env, dryRun = false, notes: extraNotes = [],
|
|
353
|
+
repoRoot, input: authored, env = process.env, dryRun = false, notes: extraNotes = [], splitMarks = null,
|
|
352
354
|
}) {
|
|
353
355
|
const bare = isBareCreateInput(authored);
|
|
354
356
|
const wrapped = bare ? { schema: INPUT_SCHEMA, desired: authored } : authored;
|
|
@@ -367,17 +369,18 @@ export async function applyPlanRevision({
|
|
|
367
369
|
const { desired, continuity } = resolved;
|
|
368
370
|
// 集合の並びは正準化済みなので、同じ内容の別の並びは「変更なし」になる。
|
|
369
371
|
const unchanged = continuity.every(({ policy }) => policy === 'carry')
|
|
370
|
-
&& canonicalizeTodoArtifact(planSeed(desired, null, member.plan))
|
|
372
|
+
&& canonicalizeTodoArtifact(planSeed(desired, null, member.plan, splitMarks))
|
|
371
373
|
=== canonicalizeTodoArtifact(planSeed(member.plan, null));
|
|
372
374
|
const binding = await readPlanBackchainBinding({ repoRoot, plan: member.plan });
|
|
373
375
|
let revision;
|
|
374
376
|
let featureChainFindings = null;
|
|
377
|
+
if (binding !== null && splitMarks !== null) fail('plan_revise_split_unsupported', '/', { cause: 'backchain_bound' });
|
|
375
378
|
if (binding !== null && !unchanged) {
|
|
376
379
|
({ revision, findings: featureChainFindings } = await compileBackchainRevision({
|
|
377
380
|
repoRoot, member, authoring: desired,
|
|
378
381
|
chain: successorBackchain(binding.chain, desired, continuity) }));
|
|
379
382
|
} else {
|
|
380
|
-
revision = compileLightRevision({ member, desired, continuity });
|
|
383
|
+
revision = compileLightRevision({ member, desired, continuity, splitMarks });
|
|
381
384
|
if (!unchanged && !validatePhaseTodoRevision(revision)) fail('plan_revise_artifact_invalid', '/');
|
|
382
385
|
}
|
|
383
386
|
let applied = null;
|
package/src/project-cli.mjs
CHANGED
|
@@ -46,6 +46,7 @@ import {
|
|
|
46
46
|
} from './todo-dispatch-shape.mjs';
|
|
47
47
|
import { splitTouches } from './todo-declaration.mjs';
|
|
48
48
|
import { readTodoRelationSummary } from './todo-relation-store.mjs';
|
|
49
|
+
import { splitLabels } from './todo-split-labels.mjs';
|
|
49
50
|
import { completeCreateInput, explainFlagCommand, readAuthoringJsonFile, resolveTodoActor } from './todo-authoring-input.mjs';
|
|
50
51
|
import { publicRefusalCode, withRefusalGuidance } from './cli-refusal-guidance.mjs';
|
|
51
52
|
|
|
@@ -458,6 +459,8 @@ export async function runSessionContext({ cwd, stdout, cliVersion, env = process
|
|
|
458
459
|
// todoは`lattice todo status`のresultそのもの。新しい意味論を発明しない。
|
|
459
460
|
todo: state.todo,
|
|
460
461
|
independence,
|
|
462
|
+
// ADR 0205 §7: additive; `todo` above is the status projection and keeps its exact shape
|
|
463
|
+
...(state.store === null || splitLabels(state.store).length === 0 ? {} : { labels: splitLabels(state.store) }),
|
|
461
464
|
turn: projectTurn({
|
|
462
465
|
store: state.store, todo: state.todo, actor: resolveTodoActor(env),
|
|
463
466
|
// 名乗れないときの理由はstatusが既に持つ(invalidはnext_action.reason、未初期化はstate)。
|
package/src/seam-apply.mjs
CHANGED
|
@@ -72,7 +72,7 @@ async function deriveWithClosure({ cwd, deriveOnce }) {
|
|
|
72
72
|
const SYMBOL_LOOKUP_LIMIT = 500;
|
|
73
73
|
|
|
74
74
|
/** gitに載らないbuild成果物のうち、focused testが要るものを実在する時だけ張る。 */
|
|
75
|
-
async function buildOutputMounts(repoRoot) {
|
|
75
|
+
export async function buildOutputMounts(repoRoot) {
|
|
76
76
|
const { access } = await import('node:fs/promises');
|
|
77
77
|
const mounts = [];
|
|
78
78
|
for (const entry of ['sensor/dist']) {
|
|
@@ -173,7 +173,7 @@ async function runIn(worktreePath, command, args) {
|
|
|
173
173
|
* 網は受入の一点だけで、過程には触れない。不認定は拒否ではなく、理由を見て直せば
|
|
174
174
|
* 何度でも再提出できる。
|
|
175
175
|
*/
|
|
176
|
-
async function detectSeveredReferences({ worktreePath, files, residualPath }) {
|
|
176
|
+
export async function detectSeveredReferences({ worktreePath, files, residualPath }) {
|
|
177
177
|
const readFileNodes = (target) => {
|
|
178
178
|
const result = invokeSensorCli(
|
|
179
179
|
(command, args, options) => spawnSync(command, args, options),
|
package/src/sensor-adapter.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import { spawnSensorCli } from './sensor-runtime.mjs';
|
|
5
5
|
|
|
6
6
|
const OPERATIONS = new Set(['status', 'query', 'callers', 'callees', 'impact', 'affected']);
|
|
7
|
+
const SENSOR_QUERY_CONCURRENCY = 6;
|
|
7
8
|
const ANSI_ESCAPE = /\u001B\[[0-?]*[ -/]*[@-~]/g;
|
|
8
9
|
|
|
9
10
|
function stripAnsi(value) {
|
|
@@ -430,13 +431,19 @@ export async function collectSensorEvidence({
|
|
|
430
431
|
return { cwd, outcomes: [{ outcome: 'unresolved', reason: 'invalid_path_inspector' }] };
|
|
431
432
|
}
|
|
432
433
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
434
|
+
// Each affected query spawns one sensor process (250-400 ms); run a few at once.
|
|
435
|
+
// Workers claim the next index, so outcomes stay in query order and no outcome changes.
|
|
436
|
+
const outcomes = new Array(queries.length);
|
|
437
|
+
let next = 0;
|
|
438
|
+
const worker = async () => {
|
|
439
|
+
while (next < queries.length) {
|
|
440
|
+
const index = next++;
|
|
441
|
+
const query = queries[index];
|
|
442
|
+
outcomes[index] = !query || typeof query !== 'object'
|
|
443
|
+
? { outcome: 'unresolved', reason: 'invalid_query' }
|
|
444
|
+
: await collectOne({ cwd, query, execute, inspectAffectedPath });
|
|
438
445
|
}
|
|
439
|
-
|
|
440
|
-
}
|
|
446
|
+
};
|
|
447
|
+
await Promise.all(Array.from({ length: Math.min(SENSOR_QUERY_CONCURRENCY, queries.length) }, worker));
|
|
441
448
|
return { cwd, outcomes };
|
|
442
449
|
}
|