@quolu/lattice 0.85.1 → 0.85.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.
- package/bin/lattice.mjs +1 -1
- package/docs/schemas/lattice.plan_create_input.v4.schema.json +1 -1
- package/docs/schemas/lattice.plan_create_input.v5.schema.json +1 -1
- package/docs/schemas/lattice.plan_revise_input.v1.schema.json +1 -1
- package/docs/schemas/lattice.plan_scope_review.v1.schema.json +3 -3
- package/docs/schemas/lattice.todo_witness_draft.v2.schema.json +86 -0
- package/docs/schemas/lattice.todo_witness_set.v5.schema.json +400 -0
- package/package.json +3 -1
- package/src/cli-help.mjs +24 -15
- package/src/cli-refusal-guidance.mjs +48 -4
- package/src/hooks-cli.mjs +4 -1
- package/src/plan-backchain.mjs +48 -8
- package/src/plan-revise.mjs +43 -3
- package/src/plan-scope-review.mjs +40 -14
- package/src/project-cli.mjs +98 -8
- package/src/runtime-cli.mjs +4 -1
- package/src/seat-identity.mjs +10 -2
- package/src/sensor-cli.mjs +8 -2
- package/src/sensor-diff.mjs +8 -0
- package/src/setup-cli.mjs +3 -1
- package/src/todo-cli.mjs +225 -78
- package/src/todo-independence-guidance.mjs +3 -2
- package/src/todo-readiness.mjs +13 -3
- package/src/todo-store.mjs +6 -0
- package/src/witness-scaffold.mjs +58 -21
package/src/cli-help.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import { TODO_INDEPENDENCE_WORKFLOW } from './todo-independence-guidance.mjs';
|
|
|
3
3
|
const ROOT_HELP = `Usage: lattice <command> [options]
|
|
4
4
|
|
|
5
5
|
Commands:
|
|
6
|
-
status --json
|
|
7
|
-
session-context --json
|
|
6
|
+
status [--json] Discover the current project and next action
|
|
7
|
+
session-context [--json] Session開始時の現在地を1プロセスで返す(工程状態+並列可否)
|
|
8
8
|
plan <command> Create, compile, or verify plans
|
|
9
9
|
run <command> Start or observe compiled runs
|
|
10
10
|
event verify Verify a runtime event log
|
|
@@ -31,9 +31,11 @@ Commands:
|
|
|
31
31
|
create --schema-version <1|2|3|4|5> --json
|
|
32
32
|
create --template --json # 作者が書くkeyだけの最小のv5入力(そのままplan createが受理する)
|
|
33
33
|
backchain --schema --json # 最終成果から必要な機能を逆算する入力契約
|
|
34
|
-
revise --input <file> [--dry-run] --json
|
|
34
|
+
revise --input <file> [--dry-run] [--json]
|
|
35
|
+
# 改訂後の計画の全体を、plan createと同じ形で渡す(plan create --template --jsonから始められる)。
|
|
36
|
+
# 継続方針を自分で書くなら {"schema":"lattice.plan_revise_input.v1","desired":<計画>,"continuity":[...]}
|
|
35
37
|
revise --schema --json
|
|
36
|
-
backchain --input <file> [--dry-run] --json
|
|
38
|
+
backchain --input <file> [--dry-run] [--json]
|
|
37
39
|
# 各工程の必要・提供機能を照合し、初回又は既存storeへのplan登録まで行う
|
|
38
40
|
show <plan_key> --json # task・依存辺・phase・状態をplan本体から1コマンドで投影する
|
|
39
41
|
scope-review --plan-input <file> --review <scope-review.json> --json
|
|
@@ -128,7 +130,10 @@ Write commands:
|
|
|
128
130
|
independence mode --plan <key> --set <witness|conversation> --reason <text>
|
|
129
131
|
# このplanの調整方式(witness検証で並列するか、会話で調整するか)を記録する
|
|
130
132
|
independence compile --plan <key> --input <file> # witness setとsensorから並列可否を記録する
|
|
133
|
+
independence compile --schema --json # compileが読むwitness set(lattice.todo_witness_set.v5)のJSON Schema
|
|
131
134
|
independence witness migrate --plan <key> # revision後の宣言をtask migrationで写す
|
|
135
|
+
independence witness scaffold --template --plan <key> [--json] # 未完の工程を並べた下書きのひな形を出す
|
|
136
|
+
independence witness scaffold --schema --json # 下書き(lattice.todo_witness_draft.v2)のJSON Schema
|
|
132
137
|
independence witness scaffold --plan <key> --input <draft> # 下書きとfresh観測から宣言を書き出す
|
|
133
138
|
structure input --plan <key> --input <file> --dry-run --json
|
|
134
139
|
# plan identity・topology・unfinished task coverage・baseline祖先を無変更で検査する
|
|
@@ -180,8 +185,8 @@ ${TODO_INDEPENDENCE_WORKFLOW.join('\n')}
|
|
|
180
185
|
todo startのadvisoryとtodo independenceの投影が、その状況と次の一歩を返す。
|
|
181
186
|
競合の同時起動は助言のまま。並列既定はstatusのdispatch_frontierとnext_actionが案内する。
|
|
182
187
|
`,
|
|
183
|
-
sensor: `Usage: lattice sensor <init|sync> [path] --json
|
|
184
|
-
lattice sensor diff <rootA> <rootB> [options] --json
|
|
188
|
+
sensor: `Usage: lattice sensor <init|sync> [path] [--json]
|
|
189
|
+
lattice sensor diff <rootA> <rootB> [options] [--json]
|
|
185
190
|
|
|
186
191
|
diff options:
|
|
187
192
|
--subtree-a <rel> # A側をこの部分木だけに絞り、prefixを剥がしてから突き合わせる
|
|
@@ -237,13 +242,16 @@ Windows製品hookとGrok製品hookは未対応として返し、MCPは独立し
|
|
|
237
242
|
|
|
238
243
|
const SUBCOMMAND_USAGE = Object.freeze({
|
|
239
244
|
'setup status': 'setup status [--host <claude|codex|grok|cursor|all>] [--json]',
|
|
240
|
-
status: 'status --json',
|
|
241
|
-
'session-context': 'session-context --json',
|
|
245
|
+
status: 'status [--json]',
|
|
246
|
+
'session-context': 'session-context [--json]',
|
|
242
247
|
'plan create': 'plan create --input <file> [--serialization-reviewed] | --schema --json | --schema-version <1|2|3|4|5> --json | --template --json',
|
|
243
248
|
'plan show': 'plan show <plan_key> --json',
|
|
244
249
|
'plan scope-review': 'plan scope-review --plan-input <plan-create-or-extraction.json> --review <scope-review.json> --json | --schema --json',
|
|
245
|
-
'plan backchain': 'plan backchain --input <file> [--dry-run] --json | --schema --json',
|
|
246
|
-
'plan revise': 'plan revise --input <file> [--dry-run] --json | --schema --json'
|
|
250
|
+
'plan backchain': 'plan backchain --input <file> [--dry-run] [--json] | --schema --json',
|
|
251
|
+
'plan revise': 'plan revise --input <file> [--dry-run] [--json] | --schema --json\n\n'
|
|
252
|
+
+ '--input: the whole desired plan in the same shape as `plan create` (start from `plan create --template --json`),\n'
|
|
253
|
+
+ 'or {"schema":"lattice.plan_revise_input.v1","desired":<that plan>,"continuity":[{task_id, policy: carry|reset|retire, reason}]}.\n'
|
|
254
|
+
+ 'Without continuity the machine computes carry/reset/retire. A plan_key with no active plan is made with `plan create`.',
|
|
247
255
|
'plan compile': 'plan compile --request <request.json> | --schema --json',
|
|
248
256
|
'plan verify': 'plan verify --request <request.json> --plan <plan.json>',
|
|
249
257
|
'run start': 'run start --request <request.json> --executor <adapter>'
|
|
@@ -277,10 +285,11 @@ const SUBCOMMAND_USAGE = Object.freeze({
|
|
|
277
285
|
'todo status': 'todo status [--json]',
|
|
278
286
|
'todo show': 'todo show --plan <key> --task <id> --json',
|
|
279
287
|
'todo note': 'todo note --plan <key> [--task <id>] (--message <text>|--input <file>) | list --plan <key> [--task <id>] --json',
|
|
280
|
-
'todo note list': 'todo note list --plan <key> [--task <id>] --json',
|
|
288
|
+
'todo note list': 'todo note list --plan <key> [--task <id>] [--json]',
|
|
281
289
|
'todo bindings': 'todo bindings [--plan <key>] [--json]',
|
|
282
290
|
'todo independence': 'todo independence [--plan <key>] [--json] | mode --plan <key> --set <witness|conversation> --reason <text>'
|
|
283
|
-
+ ' | compile --plan <key> --input <file> |
|
|
291
|
+
+ ' | compile --plan <key> --input <file> | compile --schema --json | witness migrate --plan <key>'
|
|
292
|
+
+ ' | witness scaffold --template --plan <key> [--json] | witness scaffold --schema --json | witness scaffold --plan <key> --input <draft>',
|
|
284
293
|
'todo independence mode': 'todo independence mode --plan <key> --set <witness|conversation> --reason <text>',
|
|
285
294
|
'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',
|
|
286
295
|
'todo seam-profile': 'todo seam-profile --plan <key> --file <path> [--json]',
|
|
@@ -323,10 +332,10 @@ const SUBCOMMAND_USAGE = Object.freeze({
|
|
|
323
332
|
'todo revise-phase': 'todo revise-phase --plan <key> --input <file> | --schema --json',
|
|
324
333
|
'todo revise-set': 'todo revise-set --input <file> | --schema --json',
|
|
325
334
|
'todo migrate': 'todo migrate --input <extraction.json> [--serialization-reviewed] [--json] | --input <extraction.json> --dry-run --json [--serialization-reviewed] | --schema --json',
|
|
326
|
-
'sensor init': 'sensor init [path] --json',
|
|
327
|
-
'sensor sync': 'sensor sync [path] --json',
|
|
335
|
+
'sensor init': 'sensor init [path] [--json]',
|
|
336
|
+
'sensor sync': 'sensor sync [path] [--json]',
|
|
328
337
|
'sensor diff': 'sensor diff <rootA> <rootB> [--subtree-a <rel>] [--subtree-b <rel>]'
|
|
329
|
-
+ ' [--map-a <from>=<to>] [--map-b <from>=<to>] [--limit <n>] --json',
|
|
338
|
+
+ ' [--map-a <from>=<to>] [--map-b <from>=<to>] [--limit <n>] [--json]',
|
|
330
339
|
'runtime-errors snapshot': 'runtime-errors snapshot [--after-cursor <n>] [--limit <n>] --json',
|
|
331
340
|
'runtime-errors ack': 'runtime-errors ack <cursor> --json',
|
|
332
341
|
'runtime-errors diagnostics': 'runtime-errors diagnostics --json',
|
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
// Refusal sites keep their own keys; this fills the three keys the seat contract requires.
|
|
4
4
|
|
|
5
5
|
const PLACEHOLDER = /^[a-z_]+$/u;
|
|
6
|
+
// a27: one placeholder per flag for every missing-flag text (plan and todo alike).
|
|
7
|
+
export const FLAG_PLACEHOLDER = Object.freeze({
|
|
8
|
+
input: '<file>', 'plan-input': '<file>', review: '<file>', evidence: '<file>', 'test-result': '<file>',
|
|
9
|
+
request: '<file>', reason: '<text>', 'override-reason': '<text>', message: '<text>', plan: '<key>', task: '<id>',
|
|
10
|
+
});
|
|
11
|
+
const placeholderFor = (pointer) => FLAG_PLACEHOLDER[String(pointer).replace(/^--/u, '')] ?? '<value>';
|
|
6
12
|
const EXAMPLE_TIMESTAMP = '2026-11-08T12:00:00.000Z';
|
|
7
13
|
|
|
8
14
|
const q = (value) => (typeof value === 'string' ? `'${value}'` : JSON.stringify(value));
|
|
@@ -87,7 +93,12 @@ function keyDifference(detail, ctx, pointer) {
|
|
|
87
93
|
const parts = [];
|
|
88
94
|
if (missing.length > 0) parts.push(`add keys ${names(missing)}`);
|
|
89
95
|
if (extra.length > 0) parts.push(`remove keys ${names(extra)}`);
|
|
90
|
-
|
|
96
|
+
// a31: 計画の目的・最終成果・受入はplan createでなくbackchainのgoalが持つ(seat contract)。
|
|
97
|
+
const goalHint = ctx.family === 'plan' && ctx.command === 'create' && pointer === '/'
|
|
98
|
+
&& extra.some((key) => key === 'goal' || key === 'title')
|
|
99
|
+
? ' A plan is named by plan_key; its purpose, final outcome and acceptance go in `goal` of `lattice plan backchain` (see `lattice plan backchain --schema --json`).'
|
|
100
|
+
: '';
|
|
101
|
+
return `At ${pointer} ${parts.join(' and ') || `use exactly the keys ${names(expected)}`}.${goalHint}`;
|
|
91
102
|
}
|
|
92
103
|
|
|
93
104
|
function acceptedValues(detail) {
|
|
@@ -109,6 +120,18 @@ const revisionDigest = (what) => ({
|
|
|
109
120
|
// rule -> { pointer?: string | (detail, ctx) => string, repair: (detail, ctx, pointer) => string }
|
|
110
121
|
const REGISTRY = {
|
|
111
122
|
unsorted: { repair: movedAfter },
|
|
123
|
+
duplicate: {
|
|
124
|
+
repair: (detail, ctx, pointer) => `${q(detail.actual)} appears more than once (${pointer}); give each entry its own id or remove the extra one.`,
|
|
125
|
+
},
|
|
126
|
+
dependency_cycle_in_input: {
|
|
127
|
+
repair: (detail) => `Tasks ${strings(detail.cycle).join(' -> ')} form a cycle: remove one of those edges from /hard_dependencies (or /joins), then rerun.`,
|
|
128
|
+
},
|
|
129
|
+
authoring_ref_invalid: {
|
|
130
|
+
repair: (detail, ctx, pointer) => `Set ${pointer} to the repo path of the plan create input this chain describes (for example \`plan.json\`); it is ${q(detail.actual)}. See \`${schemaCommand(ctx)}\`.`,
|
|
131
|
+
},
|
|
132
|
+
git_toplevel_unresolved: {
|
|
133
|
+
repair: () => 'cd into the project repository, or run `git init` there first',
|
|
134
|
+
},
|
|
112
135
|
unsorted_or_duplicate_collection: {
|
|
113
136
|
repair: (detail, ctx, pointer) => `${movedAfter(detail, ctx, pointer)} Remove the entry if ${q(detail.actual)} appears twice.`,
|
|
114
137
|
},
|
|
@@ -166,8 +189,20 @@ const REGISTRY = {
|
|
|
166
189
|
invalid_unblock_transition: {
|
|
167
190
|
repair: (detail, ctx) => `Only a blocked task can be unblocked; check its status with \`${showTask(detail, ctx)}\`.`,
|
|
168
191
|
},
|
|
192
|
+
invalid_reopen_transition: {
|
|
193
|
+
// a32: only a done task can be reopened; say the state and the step that fits it.
|
|
194
|
+
repair: (detail, ctx) => {
|
|
195
|
+
const on = `--plan ${planOf(detail, ctx)} --task ${taskOf(detail, ctx)}`;
|
|
196
|
+
return `Only a done task can be reopened; ${planOf(detail, ctx)}/${taskOf(detail, ctx)} is ${detail.status ?? 'not done'}. ` + ({
|
|
197
|
+
'in-progress': `It is still open: finish it with \`lattice todo done ${on}\`, or undo the start with \`lattice todo retract ${on} --reason <text>\`.`,
|
|
198
|
+
pending: `It has not started: run \`lattice todo start ${on}\`.`,
|
|
199
|
+
blocked: `It is blocked: resume it with \`lattice todo unblock ${on}\`.`,
|
|
200
|
+
retired: `Retire is permanent, so it stays closed; see \`${showTask(detail, ctx)}\`.`,
|
|
201
|
+
}[detail.status] ?? `Check its state with \`${showTask(detail, ctx)}\`.`);
|
|
202
|
+
},
|
|
203
|
+
},
|
|
169
204
|
reopen_has_started_successor: {
|
|
170
|
-
repair: (detail, ctx) => `A successor of ${taskOf(detail, ctx)} has already started:
|
|
205
|
+
repair: (detail, ctx) => `A successor of ${taskOf(detail, ctx)} has already started: to reopen it anyway run \`lattice todo reopen --plan ${planOf(detail, ctx)} --task ${taskOf(detail, ctx)} --reason <text> --override-reason <text>\`.`,
|
|
171
206
|
},
|
|
172
207
|
requested_plan_mismatch: {
|
|
173
208
|
pointer: '--plan',
|
|
@@ -298,7 +333,7 @@ const REGISTRY = {
|
|
|
298
333
|
},
|
|
299
334
|
|
|
300
335
|
flag_missing: {
|
|
301
|
-
repair: (detail, ctx, pointer) => `Add ${pointer}${detail.expected?.type === 'boolean' ? '' :
|
|
336
|
+
repair: (detail, ctx, pointer) => `Add ${pointer}${detail.expected?.type === 'boolean' ? '' : ` ${placeholderFor(pointer)}`} to \`${run(ctx)}\`.`,
|
|
302
337
|
},
|
|
303
338
|
flag_takes_no_value: {
|
|
304
339
|
repair: (detail, ctx, pointer) => `${pointer} is a switch: pass it without a value to \`${run(ctx)}\`.`,
|
|
@@ -312,7 +347,8 @@ const REGISTRY = {
|
|
|
312
347
|
|
|
313
348
|
plan_revise_schema_invalid: {
|
|
314
349
|
pointer: '--input',
|
|
315
|
-
|
|
350
|
+
// a31: 包みの形を名指す。素のplan create入力も受けるので、まずそれを勧める。
|
|
351
|
+
repair: (detail, ctx) => `Pass the whole desired plan in the same shape as \`lattice plan create\` (start from \`lattice plan create --template --json\`), or wrap it as {"schema":${JSON.stringify(detail.expected)},"desired":<that plan>,"continuity":[...]} to state carry/reset/retire yourself; see \`${schemaCommand(ctx)}\`.`,
|
|
316
352
|
},
|
|
317
353
|
plan_revise_requires_source_revision: {
|
|
318
354
|
repair: (detail) => `This plan carries source revisions: use ${detail.next_action ?? '`lattice todo revise-phase --plan <plan> --input <file>`'}.`,
|
|
@@ -390,6 +426,14 @@ function registeredPointer(entry, detail, ctx) {
|
|
|
390
426
|
* A concrete existing next_action wins; a placeholder token (^[a-z_]+$) is replaced by the registered repair.
|
|
391
427
|
* context = { family: 'todo' | 'plan', command, plan, task, flags } (all optional).
|
|
392
428
|
*/
|
|
429
|
+
// a27: a reason that only means "the value you typed names nothing" gets an input code, not
|
|
430
|
+
// STORE_INCONSISTENT (which says the store itself is broken). The one mapping for every error writer.
|
|
431
|
+
const INPUT_REFUSAL_CODES = Object.freeze({ plan_not_active: 'PLAN_NOT_FOUND' });
|
|
432
|
+
export function publicRefusalCode(code, reason) {
|
|
433
|
+
return code === 'STORE_INCONSISTENT' && Object.hasOwn(INPUT_REFUSAL_CODES, reason)
|
|
434
|
+
? INPUT_REFUSAL_CODES[reason] : code;
|
|
435
|
+
}
|
|
436
|
+
|
|
393
437
|
export function withRefusalGuidance({ code, message, detail }, context = {}) {
|
|
394
438
|
const base = record(detail) ? detail : {};
|
|
395
439
|
const rule = base.rule ?? base.violation_kind ?? base.violation_reason ?? base.reason ?? message;
|
package/src/hooks-cli.mjs
CHANGED
|
@@ -1122,7 +1122,10 @@ export async function runHooksCli({
|
|
|
1122
1122
|
}) {
|
|
1123
1123
|
if (argv.length !== 3 || !['install', 'status', 'uninstall', 'emit'].includes(argv[0])
|
|
1124
1124
|
|| argv[1] !== '--host' || !HOSTS.has(argv[2])) {
|
|
1125
|
-
|
|
1125
|
+
const known = ['install', 'status', 'uninstall', 'emit'].includes(argv[0]);
|
|
1126
|
+
return failure(stdout, 'USAGE', HOST_USAGE, 2, known
|
|
1127
|
+
? { pointer: '--host', next_action: `lattice hooks ${argv[0]} --host <claude|codex|cursor>` }
|
|
1128
|
+
: { pointer: null, next_action: 'lattice hooks --help' });
|
|
1126
1129
|
}
|
|
1127
1130
|
const [command, , host] = argv;
|
|
1128
1131
|
if (platform === 'win32') {
|
package/src/plan-backchain.mjs
CHANGED
|
@@ -59,19 +59,58 @@ function registeredTasks(authoring) {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
const CHAIN_KEYS = Object.freeze([
|
|
63
|
+
'schema', 'authoring_ref', 'project_id', 'plan_key', 'plan_version',
|
|
64
|
+
'goal', 'features', 'tasks', 'chain_digest',
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* a27: 上位の形の違反をすべて、pointer付きで返す。`authoring_ref`はfileを読む前にここで見るので、
|
|
69
|
+
* 欠けた・壊れたrefが`--input`のpathの誤りに見えることはない。
|
|
70
|
+
*/
|
|
71
|
+
export function backchainShapeProblems(chain) {
|
|
72
|
+
if (chain === null || typeof chain !== 'object' || Array.isArray(chain)) {
|
|
73
|
+
return [{ violation_kind: 'type', pointer: '/', expected: { type: 'object' },
|
|
74
|
+
actual: { type: Array.isArray(chain) ? 'array' : chain === null ? 'null' : typeof chain } }];
|
|
75
|
+
}
|
|
76
|
+
const problems = [];
|
|
77
|
+
const allowed = [...CHAIN_KEYS, 'continuity'];
|
|
78
|
+
const actual = Object.keys(chain).sort();
|
|
79
|
+
const missing = CHAIN_KEYS.filter((key) => !actual.includes(key)).sort();
|
|
80
|
+
const unexpected = actual.filter((key) => !allowed.includes(key));
|
|
81
|
+
if (missing.length > 0 || unexpected.length > 0) {
|
|
82
|
+
problems.push({ violation_kind: 'unexpected_or_missing_keys', pointer: '/',
|
|
83
|
+
expected: { keys: [...CHAIN_KEYS].sort() }, actual: { keys: actual },
|
|
84
|
+
missing_keys: missing, unexpected_keys: unexpected });
|
|
85
|
+
}
|
|
86
|
+
if ('schema' in chain && chain.schema !== BACKCHAIN_SCHEMA) {
|
|
87
|
+
problems.push({ violation_kind: 'const_mismatch', pointer: '/schema',
|
|
88
|
+
expected: { one_of: [BACKCHAIN_SCHEMA] }, actual: chain.schema });
|
|
89
|
+
}
|
|
90
|
+
if (!isTodoRef(chain.authoring_ref)) {
|
|
91
|
+
problems.push({ violation_kind: 'authoring_ref_invalid', pointer: '/authoring_ref',
|
|
92
|
+
expected: { format: 'repo_relative_path_to_plan_create_input' }, actual: chain.authoring_ref ?? null });
|
|
93
|
+
}
|
|
94
|
+
for (const field of ['project_id', 'plan_key', 'plan_version']) {
|
|
95
|
+
if (field in chain && !isTodoIdentifier(chain[field])) {
|
|
96
|
+
problems.push({ violation_kind: 'identifier_invalid', pointer: `/${field}`,
|
|
97
|
+
expected: { format: 'todo_identifier' }, actual: chain[field] });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return problems;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function failOnShape(chain) {
|
|
104
|
+
const problems = backchainShapeProblems(chain);
|
|
105
|
+
if (problems.length > 0) fail('schema_invalid', problems[0].pointer, { ...problems[0], problems });
|
|
106
|
+
}
|
|
107
|
+
|
|
62
108
|
/**
|
|
63
109
|
* AIの機能分解を検査する。意味の正しさを推測せず、最終機能からの到達性と
|
|
64
110
|
* producer/consumer の契約が閉じていることだけを機械が保証する。
|
|
65
111
|
*/
|
|
66
112
|
export function validatePlanBackchain(chain, authoring) {
|
|
67
|
-
|
|
68
|
-
'schema', 'authoring_ref', 'project_id', 'plan_key', 'plan_version',
|
|
69
|
-
'goal', 'features', 'tasks', 'chain_digest',
|
|
70
|
-
];
|
|
71
|
-
if (!(exactRecord(chain, keys) || exactRecord(chain, [...keys, 'continuity']))
|
|
72
|
-
|| chain.schema !== BACKCHAIN_SCHEMA || !isTodoRef(chain.authoring_ref)
|
|
73
|
-
|| !isTodoIdentifier(chain.project_id) || !isTodoIdentifier(chain.plan_key)
|
|
74
|
-
|| !isTodoIdentifier(chain.plan_version)) fail('schema_invalid', '/');
|
|
113
|
+
failOnShape(chain);
|
|
75
114
|
if (chain.continuity !== undefined && (!Array.isArray(chain.continuity)
|
|
76
115
|
|| chain.continuity.length > 512
|
|
77
116
|
|| !chain.continuity.every((entry) => exactRecord(entry, ['task_id', 'policy', 'reason'])
|
|
@@ -590,6 +629,7 @@ export async function rebindCarriedWork({ repoRoot, planKey, env,
|
|
|
590
629
|
export async function runPlanBackchain({ cwd, inputRef, stdout, dryRun = false, env = process.env }) {
|
|
591
630
|
const repoRoot = gitRoot(cwd);
|
|
592
631
|
const chain = await readAuthoringJsonFile(repoRoot, inputRef, { invalidCode: 'PLAN_BACKCHAIN_INVALID' });
|
|
632
|
+
failOnShape(chain);
|
|
593
633
|
const authoring = completeCreateInput(await readAuthoringJsonFile(repoRoot, chain.authoring_ref, {
|
|
594
634
|
invalidCode: 'PLAN_BACKCHAIN_INVALID',
|
|
595
635
|
}), { env, now: new Date() });
|
package/src/plan-revise.mjs
CHANGED
|
@@ -174,6 +174,14 @@ export function resolvePlanRevision({ member, input, env = process.env, now = ne
|
|
|
174
174
|
fail('plan_revise_schema_invalid', '/', { expected: INPUT_SCHEMA });
|
|
175
175
|
}
|
|
176
176
|
if (input.schema !== INPUT_SCHEMA) fail('plan_revise_schema_invalid', '/', { expected: INPUT_SCHEMA });
|
|
177
|
+
// a31: 無いplanは補完の前に断る。補完は現行planの値を使うので、無いplanでは「欄を足せ」に化ける。
|
|
178
|
+
if (member === undefined) {
|
|
179
|
+
const planKey = typeof input.desired?.plan_key === 'string' ? input.desired.plan_key : null;
|
|
180
|
+
fail('plan_not_active', '/desired/plan_key', {
|
|
181
|
+
plan_key: planKey,
|
|
182
|
+
next_action: `No active plan ${planKey === null ? 'with that plan_key' : `'${planKey}'`}: make it as a new plan with \`lattice plan create --input <file>\` (the plan itself, without the revise wrapper); to revise an existing one, set plan_key to one listed by \`lattice todo status --json\`.`,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
177
185
|
// a17: 改訂は既存planの上で行うので、project_id・plan_versionは書かなければ現行planの値で埋まる。
|
|
178
186
|
const desired = completeCreateInput(input.desired, {
|
|
179
187
|
env, now, projectId: member?.plan.project_id, planVersion: member?.plan.plan_version,
|
|
@@ -192,7 +200,6 @@ export function resolvePlanRevision({ member, input, env = process.env, now = ne
|
|
|
192
200
|
actual: desired.schema, next_action: 'lattice plan create --schema-version 5 --json',
|
|
193
201
|
});
|
|
194
202
|
}
|
|
195
|
-
if (member === undefined) fail('plan_not_active', '/desired/plan_key');
|
|
196
203
|
if (member.plan.schema === 'lattice.todo_plan.v6'
|
|
197
204
|
|| member.journal.events[0].schema === 'lattice.todo_event.v2'
|
|
198
205
|
|| [...member.plan.tasks, ...desired.tasks].some((task) => task.narrative_anchor !== null)) {
|
|
@@ -310,12 +317,45 @@ export function desiredFromPlan(plan, { env = process.env, now = new Date() } =
|
|
|
310
317
|
* 公開→履歴note→作業中taskの結び直しまで行って、結果artifactを返す(印字はしない)。
|
|
311
318
|
* notes: 履歴noteへ足す plan scope の追加note([{task_id, body}])。公開後に改訂noteと同じ経路で追記する。
|
|
312
319
|
*/
|
|
320
|
+
/**
|
|
321
|
+
* a31: 作成・追加・改訂は同じ入力の形を持つ(seat contract)。`desired`で包まないplan create入力は
|
|
322
|
+
* そのまま望む全体として読み、継続方針は機械が算出する。包んだ形(continuity付き)もそのまま受ける。
|
|
323
|
+
*/
|
|
324
|
+
export function isBareCreateInput(input) {
|
|
325
|
+
return input !== null && typeof input === 'object' && !Array.isArray(input)
|
|
326
|
+
&& !('desired' in input) && Array.isArray(input.tasks)
|
|
327
|
+
&& (input.schema === undefined || /^lattice\.plan_create_input\.v[0-9]+$/u.test(input.schema));
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** 包まない入力の拒否は、包みの`/desired`を名指さない。 */
|
|
331
|
+
function unwrapPointers(error) {
|
|
332
|
+
const detail = error?.detail;
|
|
333
|
+
if (detail === null || typeof detail !== 'object') return error;
|
|
334
|
+
if (typeof detail.pointer === 'string' && detail.pointer.startsWith('/desired')) {
|
|
335
|
+
detail.pointer = detail.pointer.slice('/desired'.length) || '/';
|
|
336
|
+
}
|
|
337
|
+
if (typeof detail.next_action === 'string') {
|
|
338
|
+
detail.next_action = detail.next_action.replaceAll('/desired/', '/');
|
|
339
|
+
}
|
|
340
|
+
for (const problem of Array.isArray(detail.problems) ? detail.problems : []) {
|
|
341
|
+
if (typeof problem?.pointer === 'string' && problem.pointer.startsWith('/desired')) {
|
|
342
|
+
problem.pointer = problem.pointer.slice('/desired'.length) || '/';
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return error;
|
|
346
|
+
}
|
|
347
|
+
|
|
313
348
|
export async function applyPlanRevision({
|
|
314
|
-
repoRoot, input, env = process.env, dryRun = false, notes: extraNotes = [],
|
|
349
|
+
repoRoot, input: authored, env = process.env, dryRun = false, notes: extraNotes = [],
|
|
315
350
|
}) {
|
|
351
|
+
const bare = isBareCreateInput(authored);
|
|
352
|
+
const input = bare ? { schema: INPUT_SCHEMA, desired: authored } : authored;
|
|
316
353
|
const store = await readTodoStore({ repoRoot });
|
|
317
354
|
const member = store.members.find(({ plan }) => plan.plan_key === input?.desired?.plan_key);
|
|
318
|
-
|
|
355
|
+
let resolved;
|
|
356
|
+
try { resolved = resolvePlanRevision({ member, input, env, now: new Date() }); }
|
|
357
|
+
catch (error) { throw bare ? unwrapPointers(error) : error; }
|
|
358
|
+
const { desired, continuity } = resolved;
|
|
319
359
|
// 集合の並びは正準化済みなので、同じ内容の別の並びは「変更なし」になる。
|
|
320
360
|
const unchanged = continuity.every(({ policy }) => policy === 'carry')
|
|
321
361
|
&& canonicalizeTodoArtifact(planSeed(desired, null, member.plan))
|
|
@@ -14,7 +14,9 @@ import { TodoStoreError } from './todo-store.mjs';
|
|
|
14
14
|
|
|
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']);
|
|
19
|
+
const DEFAULT_PLAN_CREATE_SCHEMA = 'lattice.plan_create_input.v5';
|
|
18
20
|
const TODO_EXTRACTION_SCHEMAS = new Set([
|
|
19
21
|
'lattice.todo_extraction.v3',
|
|
20
22
|
'lattice.todo_extraction.v4',
|
|
@@ -58,8 +60,9 @@ async function readJsonWithinRepo(repoRoot, inputRef) {
|
|
|
58
60
|
}
|
|
59
61
|
let stats;
|
|
60
62
|
try { stats = await lstat(absolute); } catch {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
// a27: 無いfileは原因(input_missing)と解いた場所(repo_root)を言う。どのflagかはCLIの文脈が名指す。
|
|
64
|
+
throw new TodoStoreError('INPUT_UNREADABLE', 'input_missing', undefined,
|
|
65
|
+
{ input_ref: inputRef, repo_root: canonicalRoot });
|
|
63
66
|
}
|
|
64
67
|
if (!stats.isFile() || stats.isSymbolicLink() || stats.size > MAX_INPUT_BYTES
|
|
65
68
|
|| await realpath(absolute) !== absolute) {
|
|
@@ -75,18 +78,22 @@ async function readJsonWithinRepo(repoRoot, inputRef) {
|
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
function authoredPlan(value) {
|
|
78
|
-
const
|
|
81
|
+
const createInput = value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
82
|
+
&& (PLAN_CREATE_SCHEMAS.has(value.schema) || value.schema === undefined);
|
|
83
|
+
const digestField = createInput ? 'input_digest'
|
|
79
84
|
: TODO_EXTRACTION_SCHEMAS.has(value?.schema) ? 'extraction_digest' : null;
|
|
80
85
|
if (digestField === null) {
|
|
81
86
|
throw new TodoStoreError('PLAN_SCOPE_REVIEW_INVALID', 'authoring_schema_unsupported', undefined, {
|
|
82
|
-
pointer: '/schema', expected: [
|
|
87
|
+
pointer: '/schema', expected: [...PLAN_CREATE_SCHEMAS, ...TODO_EXTRACTION_SCHEMAS],
|
|
83
88
|
actual: typeof value?.schema === 'string' ? value.schema : null,
|
|
84
89
|
});
|
|
85
90
|
}
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
// a31: digestは機械が計算する。書かれていなければ本文から求め、書かれていて違えば期待値を返す。
|
|
92
|
+
const digest = todoSelfDigest(value, digestField);
|
|
93
|
+
if (value[digestField] !== undefined && value[digestField] !== '' && value[digestField] !== digest) {
|
|
88
94
|
throw new TodoStoreError('PLAN_SCOPE_REVIEW_INVALID', 'authoring_digest_mismatch', undefined, {
|
|
89
|
-
pointer: `/${digestField}`,
|
|
95
|
+
pointer: `/${digestField}`, expected: digest, actual: value[digestField],
|
|
96
|
+
next_action: `Omit ${digestField} (the machine computes it) or set it to "${digest}".`,
|
|
90
97
|
});
|
|
91
98
|
}
|
|
92
99
|
const selected = TODO_EXTRACTION_SCHEMAS.has(value.schema)
|
|
@@ -105,17 +112,33 @@ function authoredPlan(value) {
|
|
|
105
112
|
pointer: '/tasks',
|
|
106
113
|
});
|
|
107
114
|
}
|
|
108
|
-
return { schema: value.schema, digest
|
|
115
|
+
return { schema: value.schema ?? DEFAULT_PLAN_CREATE_SCHEMA, digest, taskIds };
|
|
109
116
|
}
|
|
110
117
|
|
|
111
118
|
function invalid(reason, pointer, detail = {}) {
|
|
112
119
|
throw new TodoStoreError('PLAN_SCOPE_REVIEW_INVALID', reason, undefined, { pointer, ...detail });
|
|
113
120
|
}
|
|
114
121
|
|
|
122
|
+
const REVIEW_KEYS = ['schema', 'authoring_digest', 'work_specs', 'task_assessments', 'verdict', 'review_digest'];
|
|
123
|
+
|
|
124
|
+
/** a31: 席は判断だけを書く。authoring_digestとreview_digestは省けば機械が埋める(書けば照合する)。 */
|
|
125
|
+
function completeReview(review, authored) {
|
|
126
|
+
if (review === null || typeof review !== 'object' || Array.isArray(review)) return review;
|
|
127
|
+
const filled = { ...review };
|
|
128
|
+
if (filled.authoring_digest === undefined || filled.authoring_digest === '') filled.authoring_digest = authored.digest;
|
|
129
|
+
if (filled.review_digest === undefined || filled.review_digest === '') {
|
|
130
|
+
filled.review_digest = todoSelfDigest(filled, 'review_digest');
|
|
131
|
+
}
|
|
132
|
+
return filled;
|
|
133
|
+
}
|
|
134
|
+
|
|
115
135
|
function validateReview(review, authored) {
|
|
116
|
-
if (!exactRecord(review,
|
|
117
|
-
'
|
|
118
|
-
|
|
136
|
+
if (!exactRecord(review, REVIEW_KEYS) || review.schema !== REVIEW_SCHEMA) {
|
|
137
|
+
invalid('review_schema_invalid', exactRecord(review, REVIEW_KEYS) ? '/schema' : '/', {
|
|
138
|
+
expected: { schema: REVIEW_SCHEMA, keys: [...REVIEW_KEYS].sort() },
|
|
139
|
+
actual: review !== null && typeof review === 'object' ? { keys: Object.keys(review).sort() } : null,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
119
142
|
if (!isTodoDigest(review.authoring_digest) || review.authoring_digest !== authored.digest) {
|
|
120
143
|
invalid('review_authoring_digest_mismatch', '/authoring_digest', {
|
|
121
144
|
expected: authored.digest, actual: review.authoring_digest ?? null,
|
|
@@ -123,7 +146,9 @@ function validateReview(review, authored) {
|
|
|
123
146
|
}
|
|
124
147
|
if (!isTodoDigest(review.review_digest)
|
|
125
148
|
|| review.review_digest !== todoSelfDigest(review, 'review_digest')) {
|
|
126
|
-
invalid('review_digest_mismatch', '/review_digest'
|
|
149
|
+
invalid('review_digest_mismatch', '/review_digest', {
|
|
150
|
+
expected: todoSelfDigest(review, 'review_digest'), actual: review.review_digest ?? null,
|
|
151
|
+
});
|
|
127
152
|
}
|
|
128
153
|
if (!Array.isArray(review.work_specs) || review.work_specs.length === 0
|
|
129
154
|
|| !review.work_specs.every((spec) => exactRecord(spec, [
|
|
@@ -169,8 +194,9 @@ function validateReview(review, authored) {
|
|
|
169
194
|
return { outOfScopeTaskIds, uncoveredWorkSpecIds };
|
|
170
195
|
}
|
|
171
196
|
|
|
172
|
-
export function evaluatePlanScopeReview(planInput,
|
|
197
|
+
export function evaluatePlanScopeReview(planInput, authoredReview) {
|
|
173
198
|
const authored = authoredPlan(planInput);
|
|
199
|
+
const review = completeReview(authoredReview, authored);
|
|
174
200
|
const findings = validateReview(review, authored);
|
|
175
201
|
const result = {
|
|
176
202
|
schema: RESULT_SCHEMA,
|