@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/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
|
}
|
|
@@ -470,6 +471,9 @@ const isPlainRecord = (value) => value !== null && typeof value === 'object' &&
|
|
|
470
471
|
const typeOf = (value) => (value === null ? 'null' : Array.isArray(value) ? 'array' : typeof value);
|
|
471
472
|
|
|
472
473
|
/** keyの過不足を`missing_keys`/`unexpected_keys`で名指す。recordでなければ全keyが足りない。 */
|
|
474
|
+
// a27: 機械が整列するので、隣と等しいidは重複である。順序の違反と言わない。
|
|
475
|
+
const orderViolation = (previous, current) => (previous === current ? 'duplicate' : 'unsorted');
|
|
476
|
+
|
|
473
477
|
function keyShapeViolation(pointer, value, keys) {
|
|
474
478
|
const actual = isPlainRecord(value) ? Object.keys(value).sort() : null;
|
|
475
479
|
return {
|
|
@@ -513,7 +517,7 @@ function describePlanShapeViolation(value, { phaseInput }) {
|
|
|
513
517
|
}
|
|
514
518
|
const previous = value.tasks[index - 1]?.task_id;
|
|
515
519
|
if (index > 0 && isTodoIdentifier(previous) && isTodoIdentifier(task.task_id) && !(previous < task.task_id)) {
|
|
516
|
-
problems.push({ violation_kind:
|
|
520
|
+
problems.push({ violation_kind: orderViolation(previous, task.task_id), pointer: `/tasks/${index}/task_id`,
|
|
517
521
|
expected: { greater_than: previous, order: 'ascending_unique' }, actual: task.task_id });
|
|
518
522
|
}
|
|
519
523
|
}
|
|
@@ -551,7 +555,8 @@ function describePlanShapeViolation(value, { phaseInput }) {
|
|
|
551
555
|
}
|
|
552
556
|
const unsorted = list.findIndex((entry, i) => i > 0 && !(list[i - 1] < entry));
|
|
553
557
|
if (unsorted > 0) {
|
|
554
|
-
problems.push({ violation_kind:
|
|
558
|
+
problems.push({ violation_kind: orderViolation(list[unsorted - 1], list[unsorted]),
|
|
559
|
+
pointer: `/phases/${index}/${field}/${unsorted}`,
|
|
555
560
|
expected: { greater_than: list[unsorted - 1], order: 'ascending_unique' },
|
|
556
561
|
actual: list[unsorted] });
|
|
557
562
|
}
|
|
@@ -559,7 +564,7 @@ function describePlanShapeViolation(value, { phaseInput }) {
|
|
|
559
564
|
const previous = value.phases[index - 1]?.phase_id;
|
|
560
565
|
if (index > 0 && isTodoIdentifier(previous) && isTodoIdentifier(phase.phase_id)
|
|
561
566
|
&& !(previous < phase.phase_id)) {
|
|
562
|
-
problems.push({ violation_kind:
|
|
567
|
+
problems.push({ violation_kind: orderViolation(previous, phase.phase_id), pointer: `/phases/${index}/phase_id`,
|
|
563
568
|
expected: { greater_than: previous, order: 'ascending_unique' }, actual: phase.phase_id });
|
|
564
569
|
}
|
|
565
570
|
}
|
|
@@ -695,6 +700,75 @@ function describeCreateInputViolations(value) {
|
|
|
695
700
|
return found;
|
|
696
701
|
}
|
|
697
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
|
+
|
|
698
772
|
export function validatePlanCreateInput(input) {
|
|
699
773
|
const found = describeCreateInputViolations(input);
|
|
700
774
|
const problems = found.map(({ violation }) => violation);
|
|
@@ -751,6 +825,15 @@ export async function runPlanCreate({
|
|
|
751
825
|
}
|
|
752
826
|
const input = completeCreateInput(given, { env, now: new Date(), projectId, planVersion: 'v1' });
|
|
753
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
|
+
}
|
|
754
837
|
// dispatch_shapeは結果へ載せる観測であり、直列度では初期化を拒まない(ADR 0180)。
|
|
755
838
|
const dispatchShape = computeTodoDispatchShapeForPlan({
|
|
756
839
|
projectId: input.project_id,
|
|
@@ -779,7 +862,13 @@ export async function runPlanCreate({
|
|
|
779
862
|
const store = manifest === null
|
|
780
863
|
? await initializeAuthoredTodoStore({ ...options,
|
|
781
864
|
projectId: input.project_id, repositories: [{ repo_id: 'self', path: '.' }] })
|
|
782
|
-
: 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
|
+
});
|
|
783
872
|
const member = store.members.find(({ plan }) => plan.plan_key === input.plan_key);
|
|
784
873
|
const result = {
|
|
785
874
|
schema: CREATE_RESULT_SCHEMA, project_id: store.project_id,
|
|
@@ -877,7 +966,8 @@ export async function runPlanShow({ cwd, planKey, stdout }) {
|
|
|
877
966
|
// 未知のplan_keyを「store不整合」と同じ扱いにするのはこのCLI全体の既定であり、
|
|
878
967
|
// ここだけ別codeへ逸れると呼び出し側の分岐が増える。
|
|
879
968
|
throw new TodoStoreError('STORE_INCONSISTENT', 'plan_not_active', undefined, {
|
|
880
|
-
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.`,
|
|
881
971
|
});
|
|
882
972
|
}
|
|
883
973
|
const { plan, tasks, phases } = member;
|
|
@@ -982,7 +1072,7 @@ export function projectStatusFailure({ cwd, stdout, cliVersion, error }) {
|
|
|
982
1072
|
}
|
|
983
1073
|
|
|
984
1074
|
export function projectCliFailure(stderr, error, context = {}) {
|
|
985
|
-
const code = error?.code ?? 'INTERNAL_FAILURE';
|
|
1075
|
+
const code = publicRefusalCode(error?.code ?? 'INTERNAL_FAILURE', error?.detail?.reason);
|
|
986
1076
|
const message = error?.message ?? 'project command failed';
|
|
987
1077
|
const payload = {
|
|
988
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
|
|
package/src/seat-identity.mjs
CHANGED
|
@@ -16,8 +16,16 @@ export function resolveSeatIdentity(env = process.env) {
|
|
|
16
16
|
return Object.freeze({ seat_id, state_dir });
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* session-context の top-level へ混ぜる欄。未設定なら空(欄を出さない)。
|
|
21
|
+
* 設定したのに不正な値は、断らずに無名へ落とし、捨てた値と規則を名指す(打ち間違いに気づかせる、a33)。
|
|
22
|
+
*/
|
|
20
23
|
export function seatIdentityFields(env = process.env) {
|
|
21
24
|
const { seat_id } = resolveSeatIdentity(env);
|
|
22
|
-
|
|
25
|
+
if (seat_id !== null) return { seat_id };
|
|
26
|
+
const raw = env.LATTICE_SEAT_ID;
|
|
27
|
+
// An empty value is the usual way to clear the variable, so it stays silent.
|
|
28
|
+
if (typeof raw !== 'string' || raw === '') return {};
|
|
29
|
+
return { seat_id_ignored: { value: raw.slice(0, 80),
|
|
30
|
+
rule: 'LATTICE_SEAT_ID must be 1-64 of letters, digits, ".", "_", "-", starting with a letter or digit; this seat runs anonymous' } };
|
|
23
31
|
}
|
package/src/sensor-cli.mjs
CHANGED
|
@@ -11,10 +11,10 @@ function writeJson(stream, value) {
|
|
|
11
11
|
stream.write(`${JSON.stringify(value)}\n`);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const USAGE = 'usage: lattice sensor <init|sync> [path] --json'
|
|
14
|
+
const USAGE = 'usage: lattice sensor <init|sync> [path] [--json]'
|
|
15
15
|
+ ' | lattice sensor diff <rootA> <rootB>'
|
|
16
16
|
+ ' [--subtree-a <rel>] [--subtree-b <rel>] [--map-a <from>=<to>] [--map-b <from>=<to>]'
|
|
17
|
-
+ ' [--limit <n>] --json';
|
|
17
|
+
+ ' [--limit <n>] [--json]';
|
|
18
18
|
|
|
19
19
|
function usage(stderr) {
|
|
20
20
|
writeJson(stderr, { schema: 'lattice.cli_error.v2', code: 'USAGE', message: USAGE });
|
|
@@ -100,6 +100,12 @@ export async function runSensorCli({ argv, stdout, stderr }) {
|
|
|
100
100
|
const request = parse(argv);
|
|
101
101
|
if (!request) return usage(stderr);
|
|
102
102
|
if (request.command === 'diff') return runDiff(request.diff, stdout, stderr);
|
|
103
|
+
if (!existsSync(request.path)) {
|
|
104
|
+
writeJson(stderr, { schema: 'lattice.cli_error.v2', code: 'LATTICE_SENSOR_PATH_MISSING',
|
|
105
|
+
message: `no such project path: ${request.path}`,
|
|
106
|
+
detail: { path: request.path, next_action: `lattice sensor ${request.command}` } });
|
|
107
|
+
return 1;
|
|
108
|
+
}
|
|
103
109
|
try {
|
|
104
110
|
const result = await execute(request.command, request.path);
|
|
105
111
|
if (result.code !== 0 || result.signal || result.overflow) {
|
package/src/sensor-diff.mjs
CHANGED
|
@@ -546,6 +546,14 @@ export function compareSensorIndexes(request) {
|
|
|
546
546
|
const sideB = withReadSnapshot(handleB, () => loadSide(
|
|
547
547
|
handleB, makePathNormalizer(request.b.subtree ?? '', request.b.mappings ?? []), 'b',
|
|
548
548
|
));
|
|
549
|
+
// A subtree that matches no indexed file is a typo, not an empty side: say so instead of "ok".
|
|
550
|
+
for (const [side, loaded, subtree] of [['a', sideA, request.a.subtree], ['b', sideB, request.b.subtree]]) {
|
|
551
|
+
if (subtree && loaded.counts.files === 0 && loaded.excluded.files_outside_subtree > 0) {
|
|
552
|
+
throw new SensorDiffError('LATTICE_SENSOR_DIFF_SUBTREE_EMPTY',
|
|
553
|
+
`--subtree-${side} ${subtree} matches no indexed file`,
|
|
554
|
+
{ side, subtree, next_action: `check the path; omit --subtree-${side} to compare the whole index` });
|
|
555
|
+
}
|
|
556
|
+
}
|
|
549
557
|
const comparability = assessComparability(sideA, sideB);
|
|
550
558
|
|
|
551
559
|
const nodes = diffNodes(sideA, sideB);
|
package/src/setup-cli.mjs
CHANGED
|
@@ -118,6 +118,8 @@ export async function runSetupCli({ argv, stdout, env = process.env, platform =
|
|
|
118
118
|
const state = !hosts.length || features.some((feature) => feature.state === 'failed') ? 'failed'
|
|
119
119
|
: features.every((feature) => feature.state === 'verified') ? 'ready' : 'partial';
|
|
120
120
|
stdout.write(`${JSON.stringify({ schema: 'lattice.setup_result.v1', operation: statusOnly ? 'status' : 'setup',
|
|
121
|
-
platform, state, ...(hosts.length ? {} : { code: 'HOST_NOT_PRESENT'
|
|
121
|
+
platform, state, ...(hosts.length ? {} : { code: 'HOST_NOT_PRESENT',
|
|
122
|
+
message: 'このHOMEにはAIの設定フォルダがありません',
|
|
123
|
+
next_action: 'lattice setup --host <claude|codex|grok|cursor>' }), hosts: results })}\n`);
|
|
122
124
|
return state === 'ready' ? 0 : 1;
|
|
123
125
|
}
|