@quolu/lattice 0.85.0 → 0.85.2
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 +31 -16
- 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/package.json +1 -1
- package/src/cli-help.mjs +21 -14
- package/src/cli-refusal-guidance.mjs +54 -2
- package/src/hooks-cli.mjs +4 -1
- package/src/plan-backchain.mjs +48 -8
- package/src/plan-scope-review.mjs +3 -2
- package/src/project-cli.mjs +103 -12
- package/src/runtime-cli.mjs +4 -1
- package/src/sensor-cli.mjs +8 -2
- package/src/sensor-diff.mjs +8 -0
- package/src/setup-cli.mjs +6 -2
- package/src/todo-authoring-input.mjs +14 -6
- package/src/todo-cli.mjs +284 -136
- package/src/todo-readiness.mjs +13 -3
package/bin/lattice.mjs
CHANGED
|
@@ -97,17 +97,6 @@ if (help !== null) {
|
|
|
97
97
|
} catch (error) {
|
|
98
98
|
process.exitCode = projectCliFailure(process.stderr, error);
|
|
99
99
|
}
|
|
100
|
-
} else if (args.length === 7 && args[0] === 'plan' && args[1] === 'scope-review'
|
|
101
|
-
&& args[2] === '--plan-input' && args[4] === '--review' && args[6] === '--json') {
|
|
102
|
-
const { runPlanScopeReview } = await import('../src/plan-scope-review.mjs');
|
|
103
|
-
const { projectCliFailure } = await import('../src/project-cli.mjs');
|
|
104
|
-
try {
|
|
105
|
-
process.exitCode = await runPlanScopeReview({
|
|
106
|
-
cwd: process.cwd(), planInputRef: args[3], reviewRef: args[5], stdout: process.stdout,
|
|
107
|
-
});
|
|
108
|
-
} catch (error) {
|
|
109
|
-
process.exitCode = projectCliFailure(process.stderr, error);
|
|
110
|
-
}
|
|
111
100
|
} else if (args.length === 4 && args[0] === 'plan' && args[1] === 'scope-review'
|
|
112
101
|
&& args[2] === '--schema' && args[3] === '--json') {
|
|
113
102
|
const { runPlanScopeReviewSchema } = await import('../src/plan-scope-review.mjs');
|
|
@@ -117,6 +106,25 @@ if (help !== null) {
|
|
|
117
106
|
} catch (error) {
|
|
118
107
|
process.exitCode = projectCliFailure(process.stderr, error);
|
|
119
108
|
}
|
|
109
|
+
} else if (args[0] === 'plan' && args[1] === 'scope-review') {
|
|
110
|
+
// 引数違反も欄と直し方をtypedに返す(a22)。素の`plan scope-review`をusage文1行で落とさない。
|
|
111
|
+
const { matchFlagCommand } = await import('../src/todo-authoring-input.mjs');
|
|
112
|
+
const spec = { known: ['plan-input', 'review', 'json'], required: ['plan-input', 'review'], booleans: ['json'] };
|
|
113
|
+
const flags = matchFlagCommand(args, ['plan', 'scope-review'], spec);
|
|
114
|
+
if (flags === null || flags.json !== true) {
|
|
115
|
+
const { planArgumentFailure } = await import('../src/project-cli.mjs');
|
|
116
|
+
process.exitCode = planArgumentFailure(process.stderr, args, spec);
|
|
117
|
+
} else {
|
|
118
|
+
const { runPlanScopeReview } = await import('../src/plan-scope-review.mjs');
|
|
119
|
+
const { projectCliFailure } = await import('../src/project-cli.mjs');
|
|
120
|
+
try {
|
|
121
|
+
process.exitCode = await runPlanScopeReview({
|
|
122
|
+
cwd: process.cwd(), planInputRef: flags['plan-input'], reviewRef: flags.review, stdout: process.stdout,
|
|
123
|
+
});
|
|
124
|
+
} catch (error) {
|
|
125
|
+
process.exitCode = projectCliFailure(process.stderr, error, { command: 'scope-review', flags });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
120
128
|
} else if (args.length === 4 && args[0] === 'plan' && args[1] === 'revise'
|
|
121
129
|
&& args[2] === '--schema' && args[3] === '--json') {
|
|
122
130
|
const { planReviseSchema } = await import('../src/plan-revise.mjs');
|
|
@@ -276,12 +284,19 @@ function observeInternalFailure(error, commandKind) {
|
|
|
276
284
|
}).catch(() => {});
|
|
277
285
|
}
|
|
278
286
|
|
|
279
|
-
// These
|
|
287
|
+
// These commands only ever print JSON, so a missing --json is implied (a20, a24). Plan writes are
|
|
288
|
+
// (revise, backchain) implied only once --input carries a value, so a missing --input is still named as such.
|
|
280
289
|
function withImpliedJson(argv) {
|
|
281
|
-
if (argv.includes('--json') || argv.
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
290
|
+
if (argv.includes('--json') || argv.includes('--help') || argv.includes('-h')) return argv;
|
|
291
|
+
const [command, sub] = argv;
|
|
292
|
+
const bare = !argv.some((word) => word.startsWith('-'));
|
|
293
|
+
const input = argv.indexOf('--input');
|
|
294
|
+
const implied = (bare && argv.length === 1 && (command === 'status' || command === 'session-context'))
|
|
295
|
+
|| (bare && argv.length === 3 && command === 'plan' && sub === 'show')
|
|
296
|
+
|| (bare && command === 'sensor' && (sub === 'init' || sub === 'sync') && argv.length <= 3)
|
|
297
|
+
|| (command === 'sensor' && sub === 'diff')
|
|
298
|
+
|| (command === 'plan' && (sub === 'revise' || sub === 'backchain')
|
|
299
|
+
&& input > 1 && typeof argv[input + 1] === 'string' && !argv[input + 1].startsWith('-'));
|
|
285
300
|
return implied ? [...argv, '--json'] : argv;
|
|
286
301
|
}
|
|
287
302
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
3
|
"$id": "https://github.com/kitepon/Lattice/blob/main/docs/schemas/lattice.plan_create_input.v4.schema.json",
|
|
4
4
|
"title": "lattice.plan_create_input.v4",
|
|
5
|
-
"description": "Canonical initial authoring input for a phase-audited plan. Every task
|
|
5
|
+
"description": "Canonical initial authoring input for a phase-audited plan. Every task carries a design memo; an omitted, null or blank one is recorded as `NO_PLAN`. After the complete plan is written, run `lattice plan scope-review --plan-input <file> --review <scope-review.json> --json` (the review input: `lattice plan scope-review --schema --json`) and confirm that every task preserves an owner-supplied work specification without adding a product purpose. actor, recorded_at, input_digest and tasks[].design_memo may be omitted: the machine fills the seat actor, the current time and NO_PLAN, recomputes input_digest and sorts every list into canonical order.",
|
|
6
6
|
"$comment": "Runtime validation additionally enforces canonical JSON+LF bytes, sorted identifiers and edges, unique ids, combined task/phase acyclicity, byte bounds, non-empty design_memo (omitted, null or blank becomes NO_PLAN), and input_digest (recomputed). tasks, hard_dependencies, joins, phases and phase_accept_dependencies are sorted into canonical order and exact duplicates dropped before validation.",
|
|
7
7
|
"type": "object",
|
|
8
8
|
"additionalProperties": false,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
3
|
"$id": "https://github.com/kitepon/Lattice/blob/main/docs/schemas/lattice.plan_create_input.v5.schema.json",
|
|
4
4
|
"title": "lattice.plan_create_input.v5",
|
|
5
|
-
"description": "Canonical initial authoring input for a phase-audited plan. Every task
|
|
5
|
+
"description": "Canonical initial authoring input for a phase-audited plan. Every task carries a design memo; an omitted, null or blank one is recorded as `NO_PLAN`. After the complete plan is written, run `lattice plan scope-review --plan-input <file> --review <scope-review.json> --json` (the review input: `lattice plan scope-review --schema --json`) and confirm that every task preserves an owner-supplied work specification without adding a product purpose. v5 adds the per-task authored `done_condition`: plain text (or null when the author states none) that Lattice records and shows but never evaluates, never assigns and never records as done. Builds lattice.todo_plan.v8. The author writes intent: ids, titles, phases and edges (see `lattice plan create --template --json`). Every key whose value is constant or null may be omitted and the machine fills it: schema (this version), project_id (the store's project id; with no store yet, the repository directory name as a lower-case identifier; a different value is refused as project_id_mismatch), plan_version (v1; `lattice plan revise` uses the active plan's), actor (the seat actor), recorded_at (the current time; an ISO-8601 date-time with an explicit zone is normalised to UTC milliseconds), input_digest (recomputed), tasks[].design_memo (NO_PLAN), tasks[].lane (main), tasks[].narrative_ref, narrative_anchor, compile_binding, parent_task_id and done_condition (null), phases[].gate_policy (heavy), phases[].predecessor_phase_ids ([]), phases[].required_evidence_slots ([\"acceptance\"]), hard_dependencies, joins and phase_accept_dependencies ([]), and project_id/plan_key of an edge reference (this input's own). Every list is sorted into canonical order. A refusal lists every problem at once in detail.problems. Edge direction: from is the prerequisite; to starts after from is done.",
|
|
6
6
|
"$comment": "Runtime validation additionally enforces canonical JSON+LF bytes, sorted identifiers and edges, unique ids, combined task/phase acyclicity, byte bounds, non-empty design_memo (omitted, null or blank becomes NO_PLAN), and input_digest (recomputed). v5 additionally accepts hard_dependencies, joins, each joins[].after, phase_accept_dependencies, phases, phases[].predecessor_phase_ids and phases[].required_evidence_slots in any order or with exact duplicates: they are sorted into canonical order and de-duplicated before validation. tasks are sorted by task_id. Entries with the same key but different content are still refused.",
|
|
7
7
|
"type": "object",
|
|
8
8
|
"additionalProperties": false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quolu/lattice",
|
|
3
|
-
"version": "0.85.
|
|
3
|
+
"version": "0.85.2",
|
|
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
|
@@ -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,11 +31,14 @@ 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
35
|
revise --schema --json
|
|
36
|
-
backchain --input <file> [--dry-run] --json
|
|
36
|
+
backchain --input <file> [--dry-run] [--json]
|
|
37
37
|
# 各工程の必要・提供機能を照合し、初回又は既存storeへのplan登録まで行う
|
|
38
38
|
show <plan_key> --json # task・依存辺・phase・状態をplan本体から1コマンドで投影する
|
|
39
|
+
scope-review --plan-input <file> --review <scope-review.json> --json
|
|
40
|
+
# 書き終えたplanの全taskが持ち主の作業仕様の内にあるかを、登録前に検査する
|
|
41
|
+
scope-review --schema --json # review入力のJSON Schemaを返す
|
|
39
42
|
compile --request <request.json>
|
|
40
43
|
compile --schema --json # lattice.run_request.v1 の JSON Schema を出す
|
|
41
44
|
verify --request <request.json> --plan <plan.json>
|
|
@@ -122,6 +125,8 @@ Write commands:
|
|
|
122
125
|
dependency connect --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>
|
|
123
126
|
dependency disconnect --from-plan <key> --from-task <id> --to-plan <key> --to-task <id> --reason <text>
|
|
124
127
|
# 開発中に発見した依存を明示接続する。同一plan内の辺はplan本体を軽い改訂で書き換え(plan_versionが変わる)、plan跨ぎは台帳に積む。依存の自動推定は行わない
|
|
128
|
+
independence mode --plan <key> --set <witness|conversation> --reason <text>
|
|
129
|
+
# このplanの調整方式(witness検証で並列するか、会話で調整するか)を記録する
|
|
125
130
|
independence compile --plan <key> --input <file> # witness setとsensorから並列可否を記録する
|
|
126
131
|
independence witness migrate --plan <key> # revision後の宣言をtask migrationで写す
|
|
127
132
|
independence witness scaffold --plan <key> --input <draft> # 下書きとfresh観測から宣言を書き出す
|
|
@@ -175,8 +180,8 @@ ${TODO_INDEPENDENCE_WORKFLOW.join('\n')}
|
|
|
175
180
|
todo startのadvisoryとtodo independenceの投影が、その状況と次の一歩を返す。
|
|
176
181
|
競合の同時起動は助言のまま。並列既定はstatusのdispatch_frontierとnext_actionが案内する。
|
|
177
182
|
`,
|
|
178
|
-
sensor: `Usage: lattice sensor <init|sync> [path] --json
|
|
179
|
-
lattice sensor diff <rootA> <rootB> [options] --json
|
|
183
|
+
sensor: `Usage: lattice sensor <init|sync> [path] [--json]
|
|
184
|
+
lattice sensor diff <rootA> <rootB> [options] [--json]
|
|
180
185
|
|
|
181
186
|
diff options:
|
|
182
187
|
--subtree-a <rel> # A側をこの部分木だけに絞り、prefixを剥がしてから突き合わせる
|
|
@@ -232,13 +237,13 @@ Windows製品hookとGrok製品hookは未対応として返し、MCPは独立し
|
|
|
232
237
|
|
|
233
238
|
const SUBCOMMAND_USAGE = Object.freeze({
|
|
234
239
|
'setup status': 'setup status [--host <claude|codex|grok|cursor|all>] [--json]',
|
|
235
|
-
status: 'status --json',
|
|
236
|
-
'session-context': 'session-context --json',
|
|
240
|
+
status: 'status [--json]',
|
|
241
|
+
'session-context': 'session-context [--json]',
|
|
237
242
|
'plan create': 'plan create --input <file> [--serialization-reviewed] | --schema --json | --schema-version <1|2|3|4|5> --json | --template --json',
|
|
238
243
|
'plan show': 'plan show <plan_key> --json',
|
|
239
244
|
'plan scope-review': 'plan scope-review --plan-input <plan-create-or-extraction.json> --review <scope-review.json> --json | --schema --json',
|
|
240
|
-
'plan backchain': 'plan backchain --input <file> [--dry-run] --json | --schema --json',
|
|
241
|
-
'plan revise': 'plan revise --input <file> [--dry-run] --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',
|
|
242
247
|
'plan compile': 'plan compile --request <request.json> | --schema --json',
|
|
243
248
|
'plan verify': 'plan verify --request <request.json> --plan <plan.json>',
|
|
244
249
|
'run start': 'run start --request <request.json> --executor <adapter>'
|
|
@@ -274,7 +279,9 @@ const SUBCOMMAND_USAGE = Object.freeze({
|
|
|
274
279
|
'todo note': 'todo note --plan <key> [--task <id>] (--message <text>|--input <file>) | list --plan <key> [--task <id>] --json',
|
|
275
280
|
'todo note list': 'todo note list --plan <key> [--task <id>] --json',
|
|
276
281
|
'todo bindings': 'todo bindings [--plan <key>] [--json]',
|
|
277
|
-
'todo independence': 'todo independence [--plan <key>] [--json] |
|
|
282
|
+
'todo independence': 'todo independence [--plan <key>] [--json] | mode --plan <key> --set <witness|conversation> --reason <text>'
|
|
283
|
+
+ ' | compile --plan <key> --input <file> | witness migrate --plan <key> | witness scaffold --plan <key> --input <draft>',
|
|
284
|
+
'todo independence mode': 'todo independence mode --plan <key> --set <witness|conversation> --reason <text>',
|
|
278
285
|
'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',
|
|
279
286
|
'todo seam-profile': 'todo seam-profile --plan <key> --file <path> [--json]',
|
|
280
287
|
'todo seam-proposal': 'todo seam-proposal [--plan <key>] [--json] | compile --plan <key>',
|
|
@@ -316,10 +323,10 @@ const SUBCOMMAND_USAGE = Object.freeze({
|
|
|
316
323
|
'todo revise-phase': 'todo revise-phase --plan <key> --input <file> | --schema --json',
|
|
317
324
|
'todo revise-set': 'todo revise-set --input <file> | --schema --json',
|
|
318
325
|
'todo migrate': 'todo migrate --input <extraction.json> [--serialization-reviewed] [--json] | --input <extraction.json> --dry-run --json [--serialization-reviewed] | --schema --json',
|
|
319
|
-
'sensor init': 'sensor init [path] --json',
|
|
320
|
-
'sensor sync': 'sensor sync [path] --json',
|
|
326
|
+
'sensor init': 'sensor init [path] [--json]',
|
|
327
|
+
'sensor sync': 'sensor sync [path] [--json]',
|
|
321
328
|
'sensor diff': 'sensor diff <rootA> <rootB> [--subtree-a <rel>] [--subtree-b <rel>]'
|
|
322
|
-
+ ' [--map-a <from>=<to>] [--map-b <from>=<to>] [--limit <n>] --json',
|
|
329
|
+
+ ' [--map-a <from>=<to>] [--map-b <from>=<to>] [--limit <n>] [--json]',
|
|
323
330
|
'runtime-errors snapshot': 'runtime-errors snapshot [--after-cursor <n>] [--limit <n>] --json',
|
|
324
331
|
'runtime-errors ack': 'runtime-errors ack <cursor> --json',
|
|
325
332
|
'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));
|
|
@@ -49,6 +55,16 @@ const dependencyCycle = {
|
|
|
49
55
|
return `${edgeName(detail)} would close a cycle${path === null ? '' : ` (${path})`}: leave it out, or disconnect one edge of that path with \`lattice todo dependency disconnect\`.`;
|
|
50
56
|
},
|
|
51
57
|
};
|
|
58
|
+
// a23: dependency refusals name the edge or the task and a command that lists valid ones.
|
|
59
|
+
const depFlag = (ctx, name) => ctx.flags?.[name] ?? `<${name}>`;
|
|
60
|
+
const depRef = (detail) => (record(detail.ref) ? detail.ref : detail);
|
|
61
|
+
const missingSide = (ref, ctx) => (ctx.flags?.['to-plan'] === ref.plan_key
|
|
62
|
+
&& (ref.task_id === undefined || ctx.flags?.['to-task'] === ref.task_id) ? 'to' : 'from');
|
|
63
|
+
const dependencyExists = {
|
|
64
|
+
pointer: '--to-task',
|
|
65
|
+
repair: (detail) => `${edgeName(detail)} already exists, so there is nothing to add;`
|
|
66
|
+
+ ` see \`lattice plan show ${record(detail.to) ? detail.to.plan_key : '<plan>'} --json\`.`,
|
|
67
|
+
};
|
|
52
68
|
|
|
53
69
|
/** The flag that carried the unreadable input: the one whose value is the refused path. */
|
|
54
70
|
function inputFlag(detail, ctx) {
|
|
@@ -99,6 +115,18 @@ const revisionDigest = (what) => ({
|
|
|
99
115
|
// rule -> { pointer?: string | (detail, ctx) => string, repair: (detail, ctx, pointer) => string }
|
|
100
116
|
const REGISTRY = {
|
|
101
117
|
unsorted: { repair: movedAfter },
|
|
118
|
+
duplicate: {
|
|
119
|
+
repair: (detail, ctx, pointer) => `${q(detail.actual)} appears more than once (${pointer}); give each entry its own id or remove the extra one.`,
|
|
120
|
+
},
|
|
121
|
+
dependency_cycle_in_input: {
|
|
122
|
+
repair: (detail) => `Tasks ${strings(detail.cycle).join(' -> ')} form a cycle: remove one of those edges from /hard_dependencies (or /joins), then rerun.`,
|
|
123
|
+
},
|
|
124
|
+
authoring_ref_invalid: {
|
|
125
|
+
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)}\`.`,
|
|
126
|
+
},
|
|
127
|
+
git_toplevel_unresolved: {
|
|
128
|
+
repair: () => 'cd into the project repository, or run `git init` there first',
|
|
129
|
+
},
|
|
102
130
|
unsorted_or_duplicate_collection: {
|
|
103
131
|
repair: (detail, ctx, pointer) => `${movedAfter(detail, ctx, pointer)} Remove the entry if ${q(detail.actual)} appears twice.`,
|
|
104
132
|
},
|
|
@@ -157,7 +185,7 @@ const REGISTRY = {
|
|
|
157
185
|
repair: (detail, ctx) => `Only a blocked task can be unblocked; check its status with \`${showTask(detail, ctx)}\`.`,
|
|
158
186
|
},
|
|
159
187
|
reopen_has_started_successor: {
|
|
160
|
-
repair: (detail, ctx) => `A successor of ${taskOf(detail, ctx)} has already started:
|
|
188
|
+
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>\`.`,
|
|
161
189
|
},
|
|
162
190
|
requested_plan_mismatch: {
|
|
163
191
|
pointer: '--plan',
|
|
@@ -201,6 +229,22 @@ const REGISTRY = {
|
|
|
201
229
|
},
|
|
202
230
|
dependency_cycle: dependencyCycle,
|
|
203
231
|
cross_plan_dependency_cycle: dependencyCycle,
|
|
232
|
+
dependency_already_in_plan: dependencyExists,
|
|
233
|
+
cross_plan_dependency_duplicate: dependencyExists,
|
|
234
|
+
dependency_self_reference: {
|
|
235
|
+
pointer: '--to-task',
|
|
236
|
+
repair: (detail, ctx) => `--from-task and --to-task name the same task ${depFlag(ctx, 'to-plan')}/${depFlag(ctx, 'to-task')}; a task cannot depend on itself:`
|
|
237
|
+
+ ` set --from-task to the task it waits on (see \`lattice plan show ${depFlag(ctx, 'to-plan')} --json\`).`,
|
|
238
|
+
},
|
|
239
|
+
dependency_task_not_found: {
|
|
240
|
+
pointer: (detail, ctx) => `--${missingSide(depRef(detail), ctx)}-task`,
|
|
241
|
+
repair: (detail) => `No task ${q(depRef(detail).task_id ?? '')} in plan ${depRef(detail).plan_key}:`
|
|
242
|
+
+ ` run \`lattice plan show ${depRef(detail).plan_key} --json\` to list its task ids.`,
|
|
243
|
+
},
|
|
244
|
+
dependency_plan_not_found: {
|
|
245
|
+
pointer: (detail, ctx) => `--${missingSide(depRef(detail), ctx)}-plan`,
|
|
246
|
+
repair: (detail) => `${q(depRef(detail).plan_key ?? '')} is not an active plan: run \`lattice todo status --json\` to list the active plan keys.`,
|
|
247
|
+
},
|
|
204
248
|
join_self_edge: {
|
|
205
249
|
pointer: '/joins',
|
|
206
250
|
repair: () => 'Remove the join whose `after` lists its own id, then rerun.',
|
|
@@ -272,7 +316,7 @@ const REGISTRY = {
|
|
|
272
316
|
},
|
|
273
317
|
|
|
274
318
|
flag_missing: {
|
|
275
|
-
repair: (detail, ctx, pointer) => `Add ${pointer}${detail.expected?.type === 'boolean' ? '' :
|
|
319
|
+
repair: (detail, ctx, pointer) => `Add ${pointer}${detail.expected?.type === 'boolean' ? '' : ` ${placeholderFor(pointer)}`} to \`${run(ctx)}\`.`,
|
|
276
320
|
},
|
|
277
321
|
flag_takes_no_value: {
|
|
278
322
|
repair: (detail, ctx, pointer) => `${pointer} is a switch: pass it without a value to \`${run(ctx)}\`.`,
|
|
@@ -364,6 +408,14 @@ function registeredPointer(entry, detail, ctx) {
|
|
|
364
408
|
* A concrete existing next_action wins; a placeholder token (^[a-z_]+$) is replaced by the registered repair.
|
|
365
409
|
* context = { family: 'todo' | 'plan', command, plan, task, flags } (all optional).
|
|
366
410
|
*/
|
|
411
|
+
// a27: a reason that only means "the value you typed names nothing" gets an input code, not
|
|
412
|
+
// STORE_INCONSISTENT (which says the store itself is broken). The one mapping for every error writer.
|
|
413
|
+
const INPUT_REFUSAL_CODES = Object.freeze({ plan_not_active: 'PLAN_NOT_FOUND' });
|
|
414
|
+
export function publicRefusalCode(code, reason) {
|
|
415
|
+
return code === 'STORE_INCONSISTENT' && Object.hasOwn(INPUT_REFUSAL_CODES, reason)
|
|
416
|
+
? INPUT_REFUSAL_CODES[reason] : code;
|
|
417
|
+
}
|
|
418
|
+
|
|
367
419
|
export function withRefusalGuidance({ code, message, detail }, context = {}) {
|
|
368
420
|
const base = record(detail) ? detail : {};
|
|
369
421
|
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() });
|
|
@@ -58,8 +58,9 @@ async function readJsonWithinRepo(repoRoot, inputRef) {
|
|
|
58
58
|
}
|
|
59
59
|
let stats;
|
|
60
60
|
try { stats = await lstat(absolute); } catch {
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
// a27: 無いfileは原因(input_missing)と解いた場所(repo_root)を言う。どのflagかはCLIの文脈が名指す。
|
|
62
|
+
throw new TodoStoreError('INPUT_UNREADABLE', 'input_missing', undefined,
|
|
63
|
+
{ input_ref: inputRef, repo_root: canonicalRoot });
|
|
63
64
|
}
|
|
64
65
|
if (!stats.isFile() || stats.isSymbolicLink() || stats.size > MAX_INPUT_BYTES
|
|
65
66
|
|| await realpath(absolute) !== absolute) {
|
package/src/project-cli.mjs
CHANGED
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
computeTodoDispatchShapeForPlan,
|
|
44
44
|
} from './todo-dispatch-shape.mjs';
|
|
45
45
|
import { completeCreateInput, explainFlagCommand, readAuthoringJsonFile, resolveTodoActor } from './todo-authoring-input.mjs';
|
|
46
|
-
import { withRefusalGuidance } from './cli-refusal-guidance.mjs';
|
|
46
|
+
import { publicRefusalCode, withRefusalGuidance } from './cli-refusal-guidance.mjs';
|
|
47
47
|
|
|
48
48
|
const STORE_REF = '.lattice/todo';
|
|
49
49
|
const MANIFEST_REF = `${STORE_REF}/manifest.json`;
|
|
@@ -227,7 +227,8 @@ function invalidStatus({ cliVersion, repoRoot, reason, nextAction = null }) {
|
|
|
227
227
|
store: { ref: STORE_REF, absolute_path: repoRoot === null ? null : path.join(repoRoot, STORE_REF) },
|
|
228
228
|
active_plans: [], active_runs: [], can_create_plan: false,
|
|
229
229
|
next_action: nextAction ?? {
|
|
230
|
-
|
|
230
|
+
// a27: repoの外では、もう一度失敗するgit statusでなく、repoを作るgit initを示す。
|
|
231
|
+
command: repoRoot === null ? 'git init' : 'lattice todo verify', reason,
|
|
231
232
|
},
|
|
232
233
|
});
|
|
233
234
|
}
|
|
@@ -317,14 +318,15 @@ async function resolveProjectState({ cwd, cliVersion, diagnoseStructureArtifacts
|
|
|
317
318
|
// ready frontierが在る間はADR 0063の並列開始コマンドが勝つ
|
|
318
319
|
// ——ここを監査で上書きするとdispatchが再直列化する。監査待ちはtodo statusの
|
|
319
320
|
// audit_pending欄に常在するので、順位を下げても消えない。
|
|
320
|
-
//
|
|
321
|
-
//
|
|
322
|
-
// (`todo phase status`の結果には既に両分岐のguidanceが載っている)。
|
|
321
|
+
// gate_ready(全taskが終わり監査も未着手)は軽い出口close-unauditedを1行で示す(a22)。
|
|
322
|
+
// 監査を始めた後(reviewing/rejected)は読み取り専用の`todo phase status`が両分岐を示す。
|
|
323
323
|
: todo.structure_finalization_pending.length > 0
|
|
324
324
|
? { command: todo.structure_finalization_pending[0].next_commands[0],
|
|
325
325
|
reason: 'structure_finalization_pending' }
|
|
326
326
|
: todo.audit_pending.length > 0
|
|
327
|
-
? { command:
|
|
327
|
+
? { command: todo.audit_pending[0].phase_status === 'gate_ready'
|
|
328
|
+
? `lattice todo phase close-unaudited --plan ${todo.audit_pending[0].plan_key} --phase ${todo.audit_pending[0].phase_id} --reason <text>`
|
|
329
|
+
: `lattice todo phase status --plan ${todo.audit_pending[0].plan_key}`,
|
|
328
330
|
reason: 'audit_pending' }
|
|
329
331
|
: { command: 'lattice todo status', reason: 'no_ready_task' };
|
|
330
332
|
const result = statusResult({
|
|
@@ -469,6 +471,9 @@ const isPlainRecord = (value) => value !== null && typeof value === 'object' &&
|
|
|
469
471
|
const typeOf = (value) => (value === null ? 'null' : Array.isArray(value) ? 'array' : typeof value);
|
|
470
472
|
|
|
471
473
|
/** keyの過不足を`missing_keys`/`unexpected_keys`で名指す。recordでなければ全keyが足りない。 */
|
|
474
|
+
// a27: 機械が整列するので、隣と等しいidは重複である。順序の違反と言わない。
|
|
475
|
+
const orderViolation = (previous, current) => (previous === current ? 'duplicate' : 'unsorted');
|
|
476
|
+
|
|
472
477
|
function keyShapeViolation(pointer, value, keys) {
|
|
473
478
|
const actual = isPlainRecord(value) ? Object.keys(value).sort() : null;
|
|
474
479
|
return {
|
|
@@ -512,7 +517,7 @@ function describePlanShapeViolation(value, { phaseInput }) {
|
|
|
512
517
|
}
|
|
513
518
|
const previous = value.tasks[index - 1]?.task_id;
|
|
514
519
|
if (index > 0 && isTodoIdentifier(previous) && isTodoIdentifier(task.task_id) && !(previous < task.task_id)) {
|
|
515
|
-
problems.push({ violation_kind:
|
|
520
|
+
problems.push({ violation_kind: orderViolation(previous, task.task_id), pointer: `/tasks/${index}/task_id`,
|
|
516
521
|
expected: { greater_than: previous, order: 'ascending_unique' }, actual: task.task_id });
|
|
517
522
|
}
|
|
518
523
|
}
|
|
@@ -550,7 +555,8 @@ function describePlanShapeViolation(value, { phaseInput }) {
|
|
|
550
555
|
}
|
|
551
556
|
const unsorted = list.findIndex((entry, i) => i > 0 && !(list[i - 1] < entry));
|
|
552
557
|
if (unsorted > 0) {
|
|
553
|
-
problems.push({ violation_kind:
|
|
558
|
+
problems.push({ violation_kind: orderViolation(list[unsorted - 1], list[unsorted]),
|
|
559
|
+
pointer: `/phases/${index}/${field}/${unsorted}`,
|
|
554
560
|
expected: { greater_than: list[unsorted - 1], order: 'ascending_unique' },
|
|
555
561
|
actual: list[unsorted] });
|
|
556
562
|
}
|
|
@@ -558,7 +564,7 @@ function describePlanShapeViolation(value, { phaseInput }) {
|
|
|
558
564
|
const previous = value.phases[index - 1]?.phase_id;
|
|
559
565
|
if (index > 0 && isTodoIdentifier(previous) && isTodoIdentifier(phase.phase_id)
|
|
560
566
|
&& !(previous < phase.phase_id)) {
|
|
561
|
-
problems.push({ violation_kind:
|
|
567
|
+
problems.push({ violation_kind: orderViolation(previous, phase.phase_id), pointer: `/phases/${index}/phase_id`,
|
|
562
568
|
expected: { greater_than: previous, order: 'ascending_unique' }, actual: phase.phase_id });
|
|
563
569
|
}
|
|
564
570
|
}
|
|
@@ -694,6 +700,75 @@ function describeCreateInputViolations(value) {
|
|
|
694
700
|
return found;
|
|
695
701
|
}
|
|
696
702
|
|
|
703
|
+
/** 辺の端が同じplanのtaskか。plan_key/project_idは補完済み(completeCreateInput)。 */
|
|
704
|
+
function ownRef(value, ref) {
|
|
705
|
+
return isPlainRecord(ref) && ref.plan_key === value.plan_key && ref.project_id === value.project_id;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* a27: 同じplanのtaskだけで、無いtaskを指す辺と循環を、名指しで返す。plan跨ぎの辺はStoreが判定する。
|
|
710
|
+
* 循環は依存辺(from→to)とjoin(after→before)の有向graphで、最初に見つけた1つを`cycle`に載せる。
|
|
711
|
+
*/
|
|
712
|
+
function describeCreateGraphViolations(value) {
|
|
713
|
+
const ids = new Set(value.tasks.map(({ task_id: id }) => id));
|
|
714
|
+
const known = [...ids].sort();
|
|
715
|
+
const problems = [];
|
|
716
|
+
const edges = [];
|
|
717
|
+
const endpoint = (ref, pointer) => {
|
|
718
|
+
if (!ownRef(value, ref)) return null;
|
|
719
|
+
if (ids.has(ref.task_id)) return ref.task_id;
|
|
720
|
+
problems.push({ violation_kind: 'unknown_reference', pointer: `${pointer}/task_id`,
|
|
721
|
+
expected: { one_of: known }, actual: ref.task_id });
|
|
722
|
+
return null;
|
|
723
|
+
};
|
|
724
|
+
for (const [index, edge] of (Array.isArray(value.hard_dependencies) ? value.hard_dependencies : []).entries()) {
|
|
725
|
+
const from = endpoint(edge?.from, `/hard_dependencies/${index}/from`);
|
|
726
|
+
const to = endpoint(edge?.to, `/hard_dependencies/${index}/to`);
|
|
727
|
+
if (from !== null && to !== null) edges.push([from, to]);
|
|
728
|
+
}
|
|
729
|
+
for (const [index, join] of (Array.isArray(value.joins) ? value.joins : []).entries()) {
|
|
730
|
+
const before = endpoint(join?.before, `/joins/${index}/before`);
|
|
731
|
+
for (const [at, ref] of (Array.isArray(join?.after) ? join.after : []).entries()) {
|
|
732
|
+
const after = endpoint(ref, `/joins/${index}/after/${at}`);
|
|
733
|
+
if (after !== null && before !== null) edges.push([after, before]);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
const cycle = findCycle(known, edges);
|
|
737
|
+
if (cycle !== null) {
|
|
738
|
+
problems.push({ violation_kind: 'dependency_cycle_in_input', pointer: '/hard_dependencies',
|
|
739
|
+
expected: { acyclic: true }, actual: { cycle }, cycle });
|
|
740
|
+
}
|
|
741
|
+
return problems;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/** 有向graphの循環を1つ、閉じた路(先頭と末尾が同じ)で返す。無ければnull。 */
|
|
745
|
+
function findCycle(nodes, edges) {
|
|
746
|
+
const next = new Map(nodes.map((node) => [node, []]));
|
|
747
|
+
for (const [from, to] of edges) next.get(from).push(to);
|
|
748
|
+
const state = new Map();
|
|
749
|
+
const stack = [];
|
|
750
|
+
const visit = (node) => {
|
|
751
|
+
state.set(node, 'open');
|
|
752
|
+
stack.push(node);
|
|
753
|
+
for (const target of next.get(node)) {
|
|
754
|
+
if (state.get(target) === 'open') return [...stack.slice(stack.indexOf(target)), target];
|
|
755
|
+
if (!state.has(target)) {
|
|
756
|
+
const found = visit(target);
|
|
757
|
+
if (found !== null) return found;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
stack.pop();
|
|
761
|
+
state.set(node, 'closed');
|
|
762
|
+
return null;
|
|
763
|
+
};
|
|
764
|
+
for (const node of nodes) {
|
|
765
|
+
if (state.has(node)) continue;
|
|
766
|
+
const found = visit(node);
|
|
767
|
+
if (found !== null) return found;
|
|
768
|
+
}
|
|
769
|
+
return null;
|
|
770
|
+
}
|
|
771
|
+
|
|
697
772
|
export function validatePlanCreateInput(input) {
|
|
698
773
|
const found = describeCreateInputViolations(input);
|
|
699
774
|
const problems = found.map(({ violation }) => violation);
|
|
@@ -750,6 +825,15 @@ export async function runPlanCreate({
|
|
|
750
825
|
}
|
|
751
826
|
const input = completeCreateInput(given, { env, now: new Date(), projectId, planVersion: 'v1' });
|
|
752
827
|
validatePlanCreateInput(input);
|
|
828
|
+
// a27: 同じplanの中の無いtaskを指す辺と循環は、入力の誤りとして作業を名指して返す。
|
|
829
|
+
// createだけで見る(revise・dependency connectは自分の辺を名指す拒否を持つ)。Storeの検査は最後の砦のまま。
|
|
830
|
+
const graphProblems = describeCreateGraphViolations(input);
|
|
831
|
+
if (graphProblems.length > 0) {
|
|
832
|
+
throw new TodoStoreError('INPUT_INVALID', 'plan_create_schema_invalid', undefined, {
|
|
833
|
+
...graphProblems[0], problems: graphProblems,
|
|
834
|
+
next_action: 'correct_the_reported_pointer_then_rerun_plan_create',
|
|
835
|
+
});
|
|
836
|
+
}
|
|
753
837
|
// dispatch_shapeは結果へ載せる観測であり、直列度では初期化を拒まない(ADR 0180)。
|
|
754
838
|
const dispatchShape = computeTodoDispatchShapeForPlan({
|
|
755
839
|
projectId: input.project_id,
|
|
@@ -778,7 +862,13 @@ export async function runPlanCreate({
|
|
|
778
862
|
const store = manifest === null
|
|
779
863
|
? await initializeAuthoredTodoStore({ ...options,
|
|
780
864
|
projectId: input.project_id, repositories: [{ repo_id: 'self', path: '.' }] })
|
|
781
|
-
: await appendAuthoredTodoPlan(options)
|
|
865
|
+
: await appendAuthoredTodoPlan(options).catch((error) => {
|
|
866
|
+
// a27: Storeの拒否はkeyを持たないので、断りの文が名指せるようにここで添える。
|
|
867
|
+
if (error?.detail?.reason !== 'plan_key_already_exists') throw error;
|
|
868
|
+
throw new TodoStoreError(error.code, 'plan_key_already_exists', undefined, {
|
|
869
|
+
...error.detail, plan_key: input.plan_key,
|
|
870
|
+
});
|
|
871
|
+
});
|
|
782
872
|
const member = store.members.find(({ plan }) => plan.plan_key === input.plan_key);
|
|
783
873
|
const result = {
|
|
784
874
|
schema: CREATE_RESULT_SCHEMA, project_id: store.project_id,
|
|
@@ -876,7 +966,8 @@ export async function runPlanShow({ cwd, planKey, stdout }) {
|
|
|
876
966
|
// 未知のplan_keyを「store不整合」と同じ扱いにするのはこのCLI全体の既定であり、
|
|
877
967
|
// ここだけ別codeへ逸れると呼び出し側の分岐が増える。
|
|
878
968
|
throw new TodoStoreError('STORE_INCONSISTENT', 'plan_not_active', undefined, {
|
|
879
|
-
plan_key: planKey,
|
|
969
|
+
plan_key: planKey, pointer: '<plan_key>',
|
|
970
|
+
next_action: `'${planKey}' is not an active plan: run \`lattice todo status --json\` to list the active plan keys, then rerun \`lattice plan show <plan_key> --json\` with one of them.`,
|
|
880
971
|
});
|
|
881
972
|
}
|
|
882
973
|
const { plan, tasks, phases } = member;
|
|
@@ -981,7 +1072,7 @@ export function projectStatusFailure({ cwd, stdout, cliVersion, error }) {
|
|
|
981
1072
|
}
|
|
982
1073
|
|
|
983
1074
|
export function projectCliFailure(stderr, error, context = {}) {
|
|
984
|
-
const code = error?.code ?? 'INTERNAL_FAILURE';
|
|
1075
|
+
const code = publicRefusalCode(error?.code ?? 'INTERNAL_FAILURE', error?.detail?.reason);
|
|
985
1076
|
const message = error?.message ?? 'project command failed';
|
|
986
1077
|
const payload = {
|
|
987
1078
|
schema: 'lattice.cli_error.v2', code, message,
|
package/src/runtime-cli.mjs
CHANGED
|
@@ -230,7 +230,10 @@ class CliContractError extends Error {
|
|
|
230
230
|
|
|
231
231
|
function usageFailure(stderr, args) {
|
|
232
232
|
const received = args.length === 0 ? '(none)' : args.join(' ');
|
|
233
|
-
|
|
233
|
+
// Typed like every other refusal, with a next step (a29); the message keeps the old wording.
|
|
234
|
+
stderr.write(`${JSON.stringify({ schema: CLI_ERROR_SCHEMA, code: 'USAGE',
|
|
235
|
+
message: `unsupported command or arguments: ${received}`,
|
|
236
|
+
detail: { arguments: args, next_action: 'lattice --help' } })}\n`);
|
|
234
237
|
return 2;
|
|
235
238
|
}
|
|
236
239
|
|