@quolu/lattice 0.107.0 → 0.109.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.ja.md +1 -1
  2. package/README.md +2 -2
  3. package/bin/lattice.mjs +5 -2
  4. package/docs/schemas/lattice.plan_create_input.v6.schema.json +384 -0
  5. package/docs/schemas/lattice.plan_revise_input.v1.schema.json +3 -0
  6. package/docs/schemas/lattice.todo_witness_draft.v2.schema.json +14 -2
  7. package/docs/schemas/lattice.todo_witness_set.v6.schema.json +482 -0
  8. package/package.json +3 -1
  9. package/sensor/dist/bin/lattice-sensor.js +76 -0
  10. package/sensor/dist/graph/anchor-resolve.d.ts +90 -0
  11. package/sensor/dist/graph/anchor-resolve.d.ts.map +1 -0
  12. package/sensor/dist/graph/anchor-resolve.js +132 -0
  13. package/sensor/dist/graph/anchor-resolve.js.map +1 -0
  14. package/sensor/dist/graph/touched-symbols.d.ts +42 -0
  15. package/sensor/dist/graph/touched-symbols.d.ts.map +1 -0
  16. package/sensor/dist/graph/touched-symbols.js +80 -0
  17. package/sensor/dist/graph/touched-symbols.js.map +1 -0
  18. package/src/cli-help.mjs +21 -7
  19. package/src/plan-revise.mjs +12 -1
  20. package/src/plan-scope-review.mjs +1 -1
  21. package/src/project-cli.mjs +20 -3
  22. package/src/runtime-front-end.mjs +26 -9
  23. package/src/schedulability-compiler-v2.mjs +10 -4
  24. package/src/sensor-cli.mjs +82 -1
  25. package/src/sensor-resolve.mjs +116 -0
  26. package/src/sensor-touched.mjs +76 -0
  27. package/src/todo-authoring-input.mjs +1 -0
  28. package/src/todo-cli.mjs +233 -43
  29. package/src/todo-contracts.mjs +62 -0
  30. package/src/todo-declaration.mjs +165 -0
  31. package/src/todo-independence-authoritative-observation.mjs +45 -15
  32. package/src/todo-independence-contracts.mjs +18 -4
  33. package/src/todo-independence.mjs +8 -2
  34. package/src/todo-judgment.mjs +141 -0
  35. package/src/todo-relation-store.mjs +294 -0
  36. package/src/todo-store.mjs +8 -4
  37. package/src/witness-scaffold.mjs +23 -15
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ /**
3
+ * Anchor resolution — `{path, symbol}` → the line span(s) of that symbol in that file (ADR 0204 Resolve, a3).
4
+ *
5
+ * Deterministic, no AI. Unlike `lookupSymbolNodes` (a name typed by a human, anywhere in the project) this answers one
6
+ * question: "in THIS file, which definition does this written chain name?". Matching is exact on a boundary-aligned
7
+ * chain; a miss never degrades to a fuzzy hit, it answers the nearest names so the caller can correct the typo.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.resolveAnchors = resolveAnchors;
11
+ exports.lookupNames = lookupNames;
12
+ /** Kinds that are not a unit of change inside a file. */
13
+ const NOT_A_SYMBOL = new Set(['file', 'import', 'export', 'parameter']);
14
+ const NEAREST_LIMIT = 5;
15
+ const ELSEWHERE_LIMIT = 5;
16
+ const RELATED_LIMIT = 20;
17
+ /** Scope separators are `::` in the extractors and `.` in what people write; `/n` is Erlang arity. */
18
+ function chainOf(text) {
19
+ return text.split(/::|\./).filter((part) => part.length > 0);
20
+ }
21
+ const display = (node) => chainOf(node.qualifiedName || node.name).join('.');
22
+ /**
23
+ * Does the node's chain end with the written chain? Leading parts that the extractor does not keep in the name
24
+ * (Rust modules, Python packages live in the path) may instead match a path segment.
25
+ */
26
+ function nodeMatches(node, written, pathSegments) {
27
+ const own = chainOf(node.qualifiedName || node.name);
28
+ for (let tail = written.length; tail >= 1; tail--) {
29
+ const wantedTail = written.slice(written.length - tail);
30
+ if (wantedTail.length > own.length)
31
+ continue;
32
+ const ownTail = own.slice(own.length - tail);
33
+ if (!wantedTail.every((part, i) => part === ownTail[i]))
34
+ continue;
35
+ if (written.slice(0, written.length - tail).every((part) => pathSegments.has(part)))
36
+ return true;
37
+ }
38
+ return false;
39
+ }
40
+ function distance(a, b) {
41
+ const x = a.toLowerCase();
42
+ const y = b.toLowerCase();
43
+ let previous = Array.from({ length: y.length + 1 }, (_, i) => i);
44
+ for (let i = 1; i <= x.length; i++) {
45
+ const row = [i];
46
+ for (let j = 1; j <= y.length; j++) {
47
+ row[j] = Math.min(previous[j] + 1, row[j - 1] + 1, previous[j - 1] + (x[i - 1] === y[j - 1] ? 0 : 1));
48
+ }
49
+ previous = row;
50
+ }
51
+ return previous[y.length];
52
+ }
53
+ function span(path, symbol, node) {
54
+ return { path, symbol, qualified: display(node), kind: node.kind, startLine: node.startLine, endLine: node.endLine };
55
+ }
56
+ function relatedOf(host, node) {
57
+ const take = (rows) => rows.slice(0, RELATED_LIMIT).map(({ node: n }) => ({
58
+ path: n.filePath, symbol: display(n), kind: n.kind, startLine: n.startLine, endLine: n.endLine,
59
+ }));
60
+ const callers = host.getCallers?.(node.id, 1) ?? [];
61
+ const callees = host.getCallees?.(node.id, 1) ?? [];
62
+ return { callers: take(callers), callees: take(callees), truncated: callers.length > RELATED_LIMIT || callees.length > RELATED_LIMIT };
63
+ }
64
+ function nearestIn(nodes, written) {
65
+ const target = written.join('.');
66
+ return nodes
67
+ .map((node) => ({ node, score: distance(target, display(node)) }))
68
+ .sort((a, b) => a.score - b.score || a.node.startLine - b.node.startLine)
69
+ .slice(0, NEAREST_LIMIT)
70
+ .map(({ node }) => ({
71
+ symbol: display(node), qualified: display(node), kind: node.kind, startLine: node.startLine, endLine: node.endLine,
72
+ }));
73
+ }
74
+ function resolveAnchors(host, anchors, options = {}) {
75
+ const out = { resolved: [], unresolved: [], ambiguous: [] };
76
+ const fileCache = new Map();
77
+ for (const anchor of anchors) {
78
+ const path = anchor.path.replace(/^\.\//, '');
79
+ const written = chainOf(anchor.symbol.replace(/\/\d{1,3}$/, ''));
80
+ const miss = (reason, nearest = [], elsewhere = []) => out.unresolved.push({ path: anchor.path, symbol: anchor.symbol, reason, nearest, elsewhere });
81
+ if (path === '' || path.startsWith('/') || path.split('/').includes('..')) {
82
+ miss('path_invalid');
83
+ continue;
84
+ }
85
+ if (written.length === 0) {
86
+ miss('symbol_empty');
87
+ continue;
88
+ }
89
+ let all = fileCache.get(path);
90
+ if (all === undefined) {
91
+ all = host.getNodesInFile(path);
92
+ fileCache.set(path, all);
93
+ }
94
+ const symbols = all.filter((node) => !NOT_A_SYMBOL.has(node.kind));
95
+ const segments = new Set(path.split('/').flatMap((part) => [part, part.replace(/\.[^.]+$/, '')]));
96
+ const hits = symbols.filter((node) => nodeMatches(node, written, segments));
97
+ if (hits.length > 0) {
98
+ for (const node of hits) {
99
+ const resolved = span(path, anchor.symbol, node);
100
+ if (options.related === true)
101
+ resolved.related = relatedOf(host, node);
102
+ out.resolved.push(resolved);
103
+ }
104
+ const names = [...new Set(hits.map(display))];
105
+ if (names.length > 1)
106
+ out.ambiguous.push({ path, symbol: anchor.symbol, names });
107
+ continue;
108
+ }
109
+ const elsewhere = host.getNodesByName(written[written.length - 1])
110
+ .filter((node) => node.filePath !== path && !NOT_A_SYMBOL.has(node.kind))
111
+ .slice(0, ELSEWHERE_LIMIT)
112
+ .map((node) => ({ path: node.filePath, symbol: display(node), kind: node.kind, startLine: node.startLine, endLine: node.endLine }));
113
+ miss(all.length === 0 ? 'file_not_indexed' : 'symbol_not_found', nearestIn(symbols, written), elsewhere);
114
+ }
115
+ return out;
116
+ }
117
+ const NAME_DEFINITION_LIMIT = 5;
118
+ /** Seed fallback (2b): which graph symbols does a bare identifier name? Exact name only, never fuzzy. */
119
+ function lookupNames(host, names) {
120
+ return names.map((name) => {
121
+ const found = host.getNodesByName(name).filter((node) => !NOT_A_SYMBOL.has(node.kind));
122
+ const tooCommon = found.length > NAME_DEFINITION_LIMIT;
123
+ return {
124
+ name,
125
+ tooCommon,
126
+ definitions: tooCommon ? [] : found.map((node) => ({
127
+ path: node.filePath, symbol: display(node), kind: node.kind, startLine: node.startLine, endLine: node.endLine,
128
+ })),
129
+ };
130
+ });
131
+ }
132
+ //# sourceMappingURL=anchor-resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchor-resolve.js","sourceRoot":"","sources":["../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0 +1,42 @@
1
+ /**
2
+ * Touched — diff hunks → the symbols they changed (ADR 0204 Touched, a6). Deterministic, no AI.
3
+ *
4
+ * The caller hands the hunks of a commit range (`git diff -U0`) and the index of the range END; each hunk's new-side lines are
5
+ * mapped to the innermost indexed symbols they overlap. What no symbol can carry is never dropped: it comes back in
6
+ * `unattributed` with a reason, so "no symbol" is read as "file-level", never as "touched nothing".
7
+ */
8
+ import type { Node } from '../types';
9
+ export interface HunkInput {
10
+ old_start: number;
11
+ old_count: number;
12
+ new_start: number;
13
+ new_count: number;
14
+ }
15
+ export interface FileChangeInput {
16
+ path: string;
17
+ old_path: string | null;
18
+ status: 'modified' | 'added' | 'deleted' | 'renamed' | 'binary';
19
+ hunks: HunkInput[];
20
+ }
21
+ export interface TouchedSymbol {
22
+ path: string;
23
+ symbol: string;
24
+ kind: string;
25
+ start_line: number;
26
+ end_line: number;
27
+ }
28
+ export interface UnattributedChange {
29
+ path: string;
30
+ reason: 'file_not_indexed' | 'file_deleted' | 'binary' | 'renamed' | 'outside_any_symbol' | 'partly_outside_any_symbol' | 'deleted_outside_any_symbol';
31
+ old_range: [number, number] | null;
32
+ new_range: [number, number] | null;
33
+ }
34
+ export interface TouchedResult {
35
+ touched: TouchedSymbol[];
36
+ unattributed: UnattributedChange[];
37
+ }
38
+ export interface TouchedHost {
39
+ getNodesInFile(filePath: string): Node[];
40
+ }
41
+ export declare function touchedSymbols(host: TouchedHost, files: FileChangeInput[]): TouchedResult;
42
+ //# sourceMappingURL=touched-symbols.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"touched-symbols.d.ts","sourceRoot":"","sources":["../../src/graph/touched-symbols.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAIrC,MAAM,WAAW,SAAS;IAAG,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE;AACzG,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IAChE,KAAK,EAAE,SAAS,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EACF,kBAAkB,GAAG,cAAc,GAAG,QAAQ,GAAG,SAAS,GAC1D,oBAAoB,GAAG,2BAA2B,GAAG,4BAA4B,CAAC;IACtF,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,aAAa;IAAG,OAAO,EAAE,aAAa,EAAE,CAAC;IAAC,YAAY,EAAE,kBAAkB,EAAE,CAAA;CAAE;AAE/F,MAAM,WAAW,WAAW;IAAG,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,CAAA;CAAE;AAoBzE,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,aAAa,CAyCzF"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /**
3
+ * Touched — diff hunks → the symbols they changed (ADR 0204 Touched, a6). Deterministic, no AI.
4
+ *
5
+ * The caller hands the hunks of a commit range (`git diff -U0`) and the index of the range END; each hunk's new-side lines are
6
+ * mapped to the innermost indexed symbols they overlap. What no symbol can carry is never dropped: it comes back in
7
+ * `unattributed` with a reason, so "no symbol" is read as "file-level", never as "touched nothing".
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.touchedSymbols = touchedSymbols;
11
+ const NOT_A_SYMBOL = new Set(['file', 'import', 'export', 'parameter']);
12
+ const chainOf = (node) => (node.qualifiedName || node.name).split(/::|\./).filter((p) => p.length > 0);
13
+ const display = (node) => chainOf(node).join('.');
14
+ /** `a` holds `b`: range containment, and on equal ranges (a one-line class and its method) the longer chain is the inner one. */
15
+ function holds(a, b) {
16
+ if (a === b || b.startLine < a.startLine || b.endLine > a.endLine)
17
+ return false;
18
+ if (b.startLine > a.startLine || b.endLine < a.endLine)
19
+ return true;
20
+ const ca = chainOf(a);
21
+ const cb = chainOf(b);
22
+ return cb.length > ca.length && ca.every((part, i) => part === cb[i]);
23
+ }
24
+ function innermost(nodes) {
25
+ return nodes.filter((node) => !nodes.some((other) => holds(node, other)));
26
+ }
27
+ const rangeOf = (start, count) => (count > 0 ? [start, start + count - 1] : null);
28
+ function touchedSymbols(host, files) {
29
+ const touched = new Map();
30
+ const unattributed = [];
31
+ const note = (path, reason, old_range, new_range) => unattributed.push({ path, reason, old_range, new_range });
32
+ for (const file of files) {
33
+ if (file.status === 'binary') {
34
+ note(file.path, 'binary', null, null);
35
+ continue;
36
+ }
37
+ if (file.status === 'deleted') {
38
+ note(file.path, 'file_deleted', null, null);
39
+ continue;
40
+ }
41
+ if (file.status === 'renamed' && file.hunks.length === 0) {
42
+ note(file.path, 'renamed', null, null);
43
+ continue;
44
+ }
45
+ const all = host.getNodesInFile(file.path);
46
+ const nodes = all.filter((node) => !NOT_A_SYMBOL.has(node.kind));
47
+ for (const hunk of file.hunks) {
48
+ const oldRange = rangeOf(hunk.old_start, hunk.old_count);
49
+ const newRange = rangeOf(hunk.new_start, hunk.new_count);
50
+ if (all.length === 0) {
51
+ note(file.path, 'file_not_indexed', oldRange, newRange);
52
+ continue;
53
+ }
54
+ // A pure deletion sits between new lines `new_start` and `new_start + 1`; it is inside a symbol only when both belong to it.
55
+ const [first, last] = newRange ?? [hunk.new_start, hunk.new_start + 1];
56
+ const overlapping = nodes.filter((node) => (newRange === null
57
+ ? node.startLine <= first && node.endLine >= last
58
+ : node.startLine <= last && node.endLine >= first));
59
+ if (overlapping.length === 0) {
60
+ note(file.path, newRange === null ? 'deleted_outside_any_symbol' : 'outside_any_symbol', oldRange, newRange);
61
+ continue;
62
+ }
63
+ for (const node of innermost(overlapping)) {
64
+ touched.set(`${file.path}\0${display(node)}\0${node.startLine}\0${node.endLine}`, {
65
+ path: file.path, symbol: display(node), kind: node.kind, start_line: node.startLine, end_line: node.endLine,
66
+ });
67
+ }
68
+ // Lines of an added or changed block that no symbol holds (imports, top-level code next to a function): disclosed, not lost.
69
+ if (newRange !== null && file.status !== 'added') {
70
+ let line = first;
71
+ while (line <= last && overlapping.some((node) => node.startLine <= line && node.endLine >= line))
72
+ line++;
73
+ if (line <= last)
74
+ note(file.path, 'partly_outside_any_symbol', oldRange, newRange);
75
+ }
76
+ }
77
+ }
78
+ return { touched: [...touched.values()], unattributed };
79
+ }
80
+ //# sourceMappingURL=touched-symbols.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"touched-symbols.js","sourceRoot":"","sources":["../../src/graph/touched-symbols.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAqDH,wCAyCC;AA1FD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;AA+BxE,MAAM,OAAO,GAAG,CAAC,IAAU,EAAY,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACvH,MAAM,OAAO,GAA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,EAAE,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO;iBAC5G,CAAC,CAAC;YACL,CAAC;YACD,6HAA6H;YAC7H,IAAI,QAAQ,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;gBACjD,IAAI,IAAI,GAAG,KAAK,CAAC;gBACjB,OAAO,IAAI,IAAI,IAAI,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC;oBAAE,IAAI,EAAE,CAAC;gBAC1G,IAAI,IAAI,IAAI,IAAI;oBAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,2BAA2B,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACrF,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC;AAC1D,CAAC"}
package/src/cli-help.mjs CHANGED
@@ -34,7 +34,7 @@ Commands:
34
34
  create --input <file> [--serialization-reviewed]
35
35
  # 結果へdispatch_shapeを載せる。--serialization-reviewedは互換のため受理するだけで門ではない
36
36
  create --schema --json # 既定は最新版(v5)のJSON Schemaを返す
37
- create --schema-version <1|2|3|4|5> --json
37
+ create --schema-version <1|2|3|4|5|6> --json
38
38
  create --template --json # 作者が書くkeyだけの最小のv5入力(各taskの設計メモを書けばplan createが受理する)
39
39
  backchain --schema --json # 最終成果から必要な機能を逆算する入力契約
40
40
  revise [--plan <key>] --input <file> [--dry-run] [--json]
@@ -137,7 +137,8 @@ Write commands:
137
137
  # 1件を閉じる。planは書き直さず、他のtaskの状態とjournalはそのまま
138
138
  add --plan <key> --task <id> --title <text> [--phase <id>] [--lane <lane>] [--done-condition <text>]
139
139
  [--design-memo <text>] [--after <id>[,<id>...]] [--before <id>[,<id>...]] [--reason <text>]
140
- # 1件を足す(a39)。planの全体を書かずに軽量改訂で新plan_versionを作り、他のtaskはcarry
140
+ [--owns <path>[#<function>][,...]] [--reads <path>[#<function>][,...]]
141
+ # 1件を足す(a39)。planの全体を書かずに軽量改訂で新plan_versionを作り、他のtaskはcarry。--owns/--reads は変える・読む関数を path#関数 で一度だけ宣言する(解決できない名前は行を書かず、近い名前を結果に返す。足すこと自体は失敗しない)
141
142
  done --plan <key> --task <id> [--message <text>] [--test-result <markdown-file>]
142
143
  # taskを閉じる。--messageの文が閉じた記録になる(省略すると既定の文)。--evidence <file>は次のminorまでの別名で、fileの文を--messageとして読む。
143
144
  # 既にdoneなら何も足さずunchanged:trueで成功する(a12)
@@ -168,13 +169,13 @@ Write commands:
168
169
  # enforced = witness+未宣言・古い宣言・衝突・参照なしdone・heavy段階の監査なし閉じを止める(ADR 0200)
169
170
  # このplanの調整方式(witness検証で並列するか、会話で調整するか)を記録する
170
171
  independence compile --plan <key> --input <file> # witness setとsensorから並列可否を記録する
171
- independence compile --schema --json # compileが読むwitness set(lattice.todo_witness_set.v5)のJSON Schema
172
+ independence compile --schema --json # compileが読むwitness set(lattice.todo_witness_set.v5。read_anchorsを使う計画はv6: docs/schemas/lattice.todo_witness_set.v6.schema.json)のJSON Schema
172
173
  independence witness migrate --plan <key> # revision後の宣言をtask migrationで写す
173
174
  independence witness scaffold --template --plan <key> [--json] # 未完の工程を並べた下書きのひな形を出す
174
175
  independence witness scaffold --schema --json # 下書き(lattice.todo_witness_draft.v2)のJSON Schema
175
176
  independence witness scaffold --plan <key> --input <draft> # 下書きとfresh観測から宣言を書き出す
176
- independence witness declare --plan <key> --task <id> [--owns <path>[,<path>...]] [--reads ...] [--writes ...]
177
- # 1件のtaskの行だけを宣言する(a40)。readyが全部宣言済みならcompileまで行い、未宣言はwaiting_forに返す
177
+ independence witness declare --plan <key> --task <id> [--owns <path>[#<function>][,...]] [--reads <path>[#<function>][,...]] [--writes ...]
178
+ # 1件のtaskの行だけを宣言する(a40)。宣言済みの行でcompileまで行い、未宣言のreadyはwaiting_forに返す
178
179
  structure input --plan <key> --input <file> --dry-run --json
179
180
  # plan identity・topology・unfinished task coverage・baseline祖先を無変更で検査する
180
181
  structure input --plan <key> --input <file>
@@ -227,6 +228,17 @@ todo startのadvisoryとtodo independenceの投影が、その状況と次の一
227
228
  `,
228
229
  sensor: `Usage: lattice sensor <init|sync> [path] [--json]
229
230
  lattice sensor diff <rootA> <rootB> [options] [--json]
231
+ lattice sensor resolve <path#symbol>... [--path <root>] [--related] [--json]
232
+ lattice sensor touched <from> [<to>] [--path <root>] [--json]
233
+
234
+ resolve: path#symbolの関数の行範囲を、維持されている索引から引く(完全一致のみ)。symbolは区切りを.でつないだ
235
+ 入れ子の名前(Bar.baz)で、pathとsymbolは最初の#で分ける。外れたらunresolvedに同じファイルの近い名前
236
+ (nearest)と他ファイルの同名(elsewhere)を返し、終了コードは0。--relatedで直接の呼び出し元と先も添える。
237
+
238
+ touched: <from>..<to>(<to>の既定はHEAD)の差分のhunkを、変えた関数へ写す。touchedは{path, symbol, kind, start_line, end_line}、
239
+ 関数に入らない変更(import、トップ階層、消えた関数、改名、バイナリ、索引にない種類のファイル)はunattributedに
240
+ 理由つきで返し、ファイル単位の変更として扱う。<to>がHEADで作業木がcleanなら維持された索引を使い、そうでなければ
241
+ <to>の使い捨てworktreeで新しく索引する(未commitの状態は見ない)。
230
242
 
231
243
  diff options:
232
244
  --subtree-a <rel> # A側をこの部分木だけに絞り、prefixを剥がしてから突き合わせる
@@ -284,7 +296,7 @@ const SUBCOMMAND_USAGE = Object.freeze({
284
296
  'setup status': 'setup status [--host <claude|codex|grok|cursor|all>] [--json]',
285
297
  status: 'status [--json]',
286
298
  'session-context': 'session-context [--json]',
287
- 'plan create': 'plan create --input <file> [--serialization-reviewed] | --schema --json | --schema-version <1|2|3|4|5> --json | --template --json',
299
+ 'plan create': 'plan create --input <file> [--serialization-reviewed] | --schema --json | --schema-version <1|2|3|4|5|6> --json | --template --json',
288
300
  'plan show': 'plan show <plan_key> --json',
289
301
  'plan scope-review': 'plan scope-review --plan-input <plan-create-or-extraction.json> --review <scope-review.json> --json | --schema --json',
290
302
  'plan backchain': 'plan backchain --input <file> [--dry-run] [--json] | --schema --json',
@@ -347,7 +359,7 @@ const SUBCOMMAND_USAGE = Object.freeze({
347
359
  'todo independence': 'todo independence [--plan <key>] [--json] | mode --plan <key> --set <witness|conversation|enforced> --reason <text>'
348
360
  + ' | compile --plan <key> --input <file> | compile --schema --json | witness migrate --plan <key>'
349
361
  + ' | witness scaffold --template --plan <key> [--json] | witness scaffold --schema --json | witness scaffold --plan <key> --input <draft>'
350
- + ' | witness declare --plan <key> --task <id> [--owns <path>[,<path>...]] [--reads ...] [--writes ...]',
362
+ + ' | witness declare --plan <key> --task <id> [--owns <path>[#<function>][,...]] [--reads <path>[#<function>][,...]] [--writes ...]',
351
363
  'todo independence mode': 'todo independence mode --plan <key> --set <witness|conversation|enforced> --reason <text>',
352
364
  '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',
353
365
  'todo seam-profile': 'todo seam-profile --plan <key> --file <path> [--json]',
@@ -414,6 +426,8 @@ const SUBCOMMAND_USAGE = Object.freeze({
414
426
  'todo migrate': 'todo migrate --input <extraction.json> [--serialization-reviewed] [--json] | --input <extraction.json> --dry-run --json [--serialization-reviewed] | --schema --json',
415
427
  'sensor init': 'sensor init [path] [--json]',
416
428
  'sensor sync': 'sensor sync [path] [--json]',
429
+ 'sensor resolve': 'sensor resolve <path#symbol>... [--path <root>] [--related] [--json]',
430
+ 'sensor touched': 'sensor touched <from> [<to>] [--path <root>] [--json]',
417
431
  'sensor diff': 'sensor diff <rootA> <rootB> [--subtree-a <rel>] [--subtree-b <rel>]'
418
432
  + ' [--map-a <from>=<to>] [--map-b <from>=<to>] [--limit <n>] [--json]',
419
433
  'runtime-errors snapshot': 'runtime-errors snapshot [--after-cursor <n>] [--limit <n>] --json',
@@ -12,6 +12,7 @@ import {
12
12
  applyPhaseTodoRevision, buildTodoPlan, createTodoStoreWriter, readTodoStore, TodoStoreError,
13
13
  } from './todo-store.mjs';
14
14
  import { appendTodoNote } from './todo-note-store.mjs';
15
+ import { splitTouches } from './todo-declaration.mjs';
15
16
  import { planReviseNoteBody } from './todo-revision-note.mjs';
16
17
  import { phaseTodoRevisionPlanVersion, validatePhaseTodoRevision } from './todo-revision.mjs';
17
18
 
@@ -350,7 +351,14 @@ export async function applyPlanRevision({
350
351
  repoRoot, input: authored, env = process.env, dryRun = false, notes: extraNotes = [],
351
352
  }) {
352
353
  const bare = isBareCreateInput(authored);
353
- const input = bare ? { schema: INPUT_SCHEMA, desired: authored } : authored;
354
+ const wrapped = bare ? { schema: INPUT_SCHEMA, desired: authored } : authored;
355
+ let input = wrapped;
356
+ let touches;
357
+ try {
358
+ const split = splitTouches(wrapped?.desired, '/desired');
359
+ touches = split.touches;
360
+ if (split.input !== wrapped?.desired) input = { ...wrapped, desired: split.input };
361
+ } catch (error) { throw bare ? unwrapPointers(error) : error; }
354
362
  const store = await readTodoStore({ repoRoot });
355
363
  const member = store.members.find(({ plan }) => plan.plan_key === input?.desired?.plan_key);
356
364
  let resolved;
@@ -400,6 +408,8 @@ export async function applyPlanRevision({
400
408
  throw error;
401
409
  }
402
410
  }
411
+ const declarations = dryRun || touches.length === 0 ? null
412
+ : await (await import('./todo-cli.mjs')).declareTouches({ repoRoot, planKey: revision.plan_key, touches });
403
413
  const result = {
404
414
  schema: unchanged ? 'lattice.plan_revise_unchanged.v1' : 'lattice.plan_revise_result.v1',
405
415
  project_id: revision.project_id, plan_key: revision.plan_key,
@@ -407,6 +417,7 @@ export async function applyPlanRevision({
407
417
  dry_run: dryRun, revision: unchanged ? null : revision, applied,
408
418
  continuity, rebound_task_ids: reboundTaskIds,
409
419
  ...(featureChainFindings === null ? {} : { feature_chain_findings: featureChainFindings }),
420
+ ...(declarations === null ? {} : { declarations }),
410
421
  result_digest: '',
411
422
  };
412
423
  result.result_digest = todoSelfDigest(result, 'result_digest');
@@ -15,7 +15,7 @@ import { TodoStoreError } from './todo-store.mjs';
15
15
  const REVIEW_SCHEMA = 'lattice.plan_scope_review.v1';
16
16
  const RESULT_SCHEMA = 'lattice.plan_scope_review_result.v1';
17
17
  // a31: 席が書く既定(v5、template)も審査できる。schemaを省いた入力はv5として読む(plan createと同じ)。
18
- const PLAN_CREATE_SCHEMAS = new Set(['lattice.plan_create_input.v4', 'lattice.plan_create_input.v5']);
18
+ const PLAN_CREATE_SCHEMAS = new Set(['lattice.plan_create_input.v4', 'lattice.plan_create_input.v5', 'lattice.plan_create_input.v6']);
19
19
  const DEFAULT_PLAN_CREATE_SCHEMA = 'lattice.plan_create_input.v5';
20
20
  const TODO_EXTRACTION_SCHEMAS = new Set([
21
21
  'lattice.todo_extraction.v3',
@@ -44,6 +44,8 @@ import {
44
44
  import {
45
45
  computeTodoDispatchShapeForPlan,
46
46
  } from './todo-dispatch-shape.mjs';
47
+ import { splitTouches } from './todo-declaration.mjs';
48
+ import { readTodoRelationSummary } from './todo-relation-store.mjs';
47
49
  import { completeCreateInput, explainFlagCommand, readAuthoringJsonFile, resolveTodoActor } from './todo-authoring-input.mjs';
48
50
  import { publicRefusalCode, withRefusalGuidance } from './cli-refusal-guidance.mjs';
49
51
 
@@ -151,6 +153,15 @@ export function validateProjectStatus(value) {
151
153
  * store読みは呼び出し側が済ませている。ここが払うのはplanごとの小さな記録ファイルと、
152
154
  * 記録があるときだけのHEAD照合である。readyが無いplanは述べる対象が無いので載せない。
153
155
  */
156
+ /** a5c: the plan's function-level relation count from its one summary file (ADR 0204 §5), or null when it has none. */
157
+ async function relationSummaryOf(repoRoot, planKey) {
158
+ try {
159
+ const summary = await readTodoRelationSummary({ repoRoot, planKey });
160
+ return summary === null || summary.relation_count === 0 ? null
161
+ : { relation_count: summary.relation_count, unresolved_count: summary.unresolved_count, head_sha: summary.head_sha };
162
+ } catch (error) { return { unreadable: error?.detail?.reason ?? error?.code ?? 'relations_unreadable' }; }
163
+ }
164
+
154
165
  async function summarizeIndependence({ repoRoot, store, todo }) {
155
166
  const readyPlanKeys = [...new Set(todo.next_ready.map(({ plan_key: key }) => key))].sort();
156
167
  if (readyPlanKeys.length === 0) return [];
@@ -189,8 +200,10 @@ async function summarizeIndependence({ repoRoot, store, todo }) {
189
200
  currentBaseSha: currentBaseSha ?? PLACEHOLDER_SHA,
190
201
  changedPaths: null,
191
202
  });
203
+ const functionConflicts = await relationSummaryOf(repoRoot, planKey);
192
204
  summaries.push({
193
205
  plan_key: planKey,
206
+ ...(functionConflicts === null ? {} : { function_conflicts: functionConflicts }),
194
207
  coverage: projected.coverage,
195
208
  guidance: selectIndependenceGuidance({
196
209
  coverage: projected.coverage,
@@ -827,7 +840,8 @@ export async function runPlanCreate({
827
840
  next_action: `Omit project_id (the machine fills "${projectId}") or set it to "${projectId}".`,
828
841
  });
829
842
  }
830
- const input = completeCreateInput(given, { env, now: new Date(), projectId, planVersion: 'v1' });
843
+ const { input: authored, touches } = splitTouches(given);
844
+ const input = completeCreateInput(authored, { env, now: new Date(), projectId, planVersion: 'v1' });
831
845
  validatePlanCreateInput(input);
832
846
  // a27: 同じplanの中の無いtaskを指す辺と循環は、入力の誤りとして作業を名指して返す。
833
847
  // createだけで見る(revise・dependency connectは自分の辺を名指す拒否を持つ)。Storeの検査は最後の砦のまま。
@@ -876,6 +890,8 @@ export async function runPlanCreate({
876
890
  });
877
891
  });
878
892
  const member = store.members.find(({ plan }) => plan.plan_key === input.plan_key);
893
+ const declarations = touches.length === 0 ? null
894
+ : await (await import('./todo-cli.mjs')).declareTouches({ repoRoot, planKey: input.plan_key, touches });
879
895
  const result = {
880
896
  schema: CREATE_RESULT_SCHEMA, project_id: store.project_id,
881
897
  plan_key: member.plan.plan_key, plan_version: member.plan.plan_version,
@@ -891,6 +907,7 @@ export async function runPlanCreate({
891
907
  // ADR 0147裁定3: phase無し(v3)のplan createは拒否せず、終端監査が要ることを結果へ
892
908
  // 明示するに留める。phase入力(v4/v5)ならfalse——既存のPhase gateがそのまま重監査を担う。
893
909
  terminal_audit_required: isPhaselessTodoPlanSchema(member.plan.schema),
910
+ ...(declarations === null ? {} : { declarations }),
894
911
  result_digest: '',
895
912
  };
896
913
  result.result_digest = resultDigest(result);
@@ -908,8 +925,8 @@ export async function runPlanCreate({
908
925
  * 既に機械可読に持っている。壊さずに追加のkeyを足す理由が無いので足さない。
909
926
  */
910
927
  export async function runPlanCreateSchema({ stdout, version = 5 }) {
911
- if (![1, 2, 3, 4, 5].includes(version)) throw new TypeError('unsupported plan create schema version');
912
- const expected = version === 5 ? DONE_CONDITION_CREATE_INPUT_SCHEMA : version === 4 ? MEMO_PHASE_CREATE_INPUT_SCHEMA
928
+ if (![1, 2, 3, 4, 5, 6].includes(version)) throw new TypeError('unsupported plan create schema version');
929
+ const expected = version === 6 ? 'lattice.plan_create_input.v6' : version === 5 ? DONE_CONDITION_CREATE_INPUT_SCHEMA : version === 4 ? MEMO_PHASE_CREATE_INPUT_SCHEMA
913
930
  : version === 3 ? DECOUPLED_PHASE_CREATE_INPUT_SCHEMA
914
931
  : version === 2 ? PHASE_CREATE_INPUT_SCHEMA : CREATE_INPUT_SCHEMA;
915
932
  const schemaUrl = new URL(`../docs/schemas/lattice.plan_create_input.v${version}.schema.json`, import.meta.url);
@@ -434,10 +434,13 @@ export function evidenceFromCollectedOutcomes(options = {}) {
434
434
  * 入力shape違反はTypeErrorでfail closed。
435
435
  */
436
436
  export function compileRuntimePlanV1(options = {}) {
437
- if (!exactRecord(options, ['request', 'sensorEvidence', 'planRef', 'planEpoch', 'predecessorRefs'])) {
437
+ const { omitWavesOverLimit, refineResources, ...required } = options;
438
+ if (!exactRecord(required, ['request', 'sensorEvidence', 'planRef', 'planEpoch', 'predecessorRefs'])
439
+ || (omitWavesOverLimit !== undefined && typeof omitWavesOverLimit !== 'boolean')
440
+ || (refineResources !== undefined && typeof refineResources !== 'function')) {
438
441
  fail('compileRuntimePlanV1 optionsがexact shapeでない');
439
442
  }
440
- const { request, sensorEvidence, planRef, planEpoch, predecessorRefs } = options;
443
+ const { request, sensorEvidence, planRef, planEpoch, predecessorRefs } = required;
441
444
  if (!validateRunRequest(request)) fail('run_request.v1がcontractを満たさない');
442
445
  if (!identifier(planRef)) fail('planRefがidentifierではない');
443
446
  if (!Number.isSafeInteger(planEpoch) || planEpoch < 0) fail('planEpochが不正');
@@ -582,7 +585,7 @@ export function compileRuntimePlanV1(options = {}) {
582
585
  if (ambiguous.length > 0) return nonDispatchable('QUERY_DRIFT', { ambiguous_targets: ambiguous });
583
586
 
584
587
  // observation set resources。
585
- const resources = [];
588
+ let resources = [];
586
589
  for (const [key, group] of [...ownGroups.entries()].sort((left, right) => compareText(left[0], right[0]))) {
587
590
  const coveringQueryId = coveringByTarget.get(key);
588
591
  if (coveringQueryId === undefined) continue; // 未束縛ownsは既にunknownへ落ちている
@@ -793,6 +796,10 @@ export function compileRuntimePlanV1(options = {}) {
793
796
  });
794
797
  }
795
798
 
799
+ // ADR 0204 a5b: the caller may narrow a shared path resource to the task pairs that really overlap (function ranges).
800
+ // It only removes or splits resources and never adds a task to one; a pair it cannot compare stays in the resource.
801
+ if (refineResources !== undefined) resources = refineResources(resources);
802
+
796
803
  const observationSet = {
797
804
  schema_version: 'lattice.boundary_observation_set.v2',
798
805
  source: {
@@ -808,7 +815,7 @@ export function compileRuntimePlanV1(options = {}) {
808
815
  };
809
816
 
810
817
  const bundle = compileBoundaryObservationV2(observationSet);
811
- const compiled = compileSchedulabilityGraphV2(bundle.graph);
818
+ const compiled = compileSchedulabilityGraphV2(bundle.graph, omitWavesOverLimit === true ? { omitWavesOverLimit: true } : {});
812
819
 
813
820
  if (compiled.outcome === 'unsupported' && compiled.code === 'NODE_LIMIT_EXCEEDED') {
814
821
  return nonDispatchable('NODE_LIMIT_EXCEEDED', { todo_count: todoIds.length });
@@ -843,11 +850,13 @@ export function compileRuntimePlanV1(options = {}) {
843
850
  }
844
851
  if (compiled.outcome !== 'compiled') fail(`未知のcompiler outcome: ${compiled.outcome}`);
845
852
 
846
- // producer非依存の独立verifierと必ず一致すること(成功条件5)。
847
- const verified = verifySchedulabilityPlanV2(bundle.graph, compiled.plan);
848
- if (verified.outcome !== 'verified'
849
- || verified.minimum_feasible_waves !== compiled.plan.minimum_feasible_waves) {
850
- fail(`producerとverifierの結果が一致しない: ${JSON.stringify(verified)}`);
853
+ // producer非依存の独立verifierと必ず一致すること(成功条件5)。g5: wave planを省いた(plan: null)時は検証する対象が無い。
854
+ if (compiled.plan !== null) {
855
+ const verified = verifySchedulabilityPlanV2(bundle.graph, compiled.plan);
856
+ if (verified.outcome !== 'verified'
857
+ || verified.minimum_feasible_waves !== compiled.plan.minimum_feasible_waves) {
858
+ fail(`producerとverifierの結果が一致しない: ${JSON.stringify(verified)}`);
859
+ }
851
860
  }
852
861
 
853
862
  // boundary_manifest.v2をTODOごとに構成する。
@@ -890,6 +899,14 @@ export function compileRuntimePlanV1(options = {}) {
890
899
  manifests[todoId] = manifest;
891
900
  }
892
901
 
902
+ // g5: no wave plan (over the exact-search limit) means no runtime plan either: its claim is `exact_minimum`.
903
+ if (compiled.plan === null) {
904
+ return {
905
+ outcome: 'dispatchable', plan: null, manifests, schedule: null, pairwise_verdicts: compiled.pairwise_verdicts,
906
+ graph: bundle.graph, resources: bundle.resources, graph_digest: bundle.graph_digest,
907
+ };
908
+ }
909
+
893
910
  const plan = {
894
911
  schema: 'lattice.runtime_plan.v1',
895
912
  plan_ref: planRef,
@@ -48,14 +48,16 @@ function assertArray(value, label) {
48
48
  }
49
49
 
50
50
  function normalizeOptions(options) {
51
- if (!exactRecord(options, []) && !exactRecord(options, ['maxSearchStates'])) {
51
+ const keys = Object.keys(options).sort();
52
+ if (!exactRecord(options, keys) || !keys.every((key) => ['maxSearchStates', 'omitWavesOverLimit'].includes(key))
53
+ || (options.omitWavesOverLimit !== undefined && typeof options.omitWavesOverLimit !== 'boolean')) {
52
54
  fail('options shapeが不正');
53
55
  }
54
56
  const maxSearchStates = options.maxSearchStates ?? DEFAULT_MAX_SEARCH_STATES;
55
57
  if (!Number.isSafeInteger(maxSearchStates) || maxSearchStates < 0) {
56
58
  fail('maxSearchStatesがnon-negative safe integerではない');
57
59
  }
58
- return { maxSearchStates };
60
+ return { maxSearchStates, omitWavesOverLimit: options.omitWavesOverLimit === true };
59
61
  }
60
62
 
61
63
  function assertAcyclic(todos, precedences) {
@@ -270,14 +272,18 @@ function pairwiseVerdicts(graph) {
270
272
  */
271
273
  export function compileSchedulabilityGraphV2(normalizedGraph, options = {}) {
272
274
  const graph = normalizeGraph(normalizedGraph);
273
- const { maxSearchStates } = normalizeOptions(options);
275
+ const { maxSearchStates, omitWavesOverLimit } = normalizeOptions(options);
274
276
 
275
- if (graph.todos.length > MAX_TODOS) {
277
+ const overLimit = graph.todos.length > MAX_TODOS;
278
+ if (overLimit && !omitWavesOverLimit) {
276
279
  return { outcome: 'unsupported', code: 'NODE_LIMIT_EXCEEDED' };
277
280
  }
278
281
  if (graph.unknowns.length > 0) {
279
282
  return { outcome: 'unknown', code: 'BOUNDARY_UNKNOWN', unknowns: graph.unknowns };
280
283
  }
284
+ // g5: the exact minimum-wave search stops at MAX_TODOS. A caller that only needs the verdicts (independence) opts in to
285
+ // `plan: null` above it: the pairwise verdicts do not depend on the search, and no minimum is claimed.
286
+ if (overLimit) return { outcome: 'compiled', pairwise_verdicts: pairwiseVerdicts(graph), plan: null };
281
287
  if (maxSearchStates === 0) {
282
288
  return { outcome: 'unsupported', code: 'SEARCH_BUDGET_EXHAUSTED' };
283
289
  }