@quolu/lattice 0.106.0 → 0.108.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.
- package/README.ja.md +7 -10
- package/README.md +4 -4
- package/bin/lattice.mjs +3 -0
- package/package.json +1 -1
- package/src/chart-cli.mjs +23 -11
- package/src/cli-help.mjs +10 -16
- package/src/cli-refusal-guidance.mjs +7 -15
- package/src/runtime-front-end.mjs +20 -8
- package/src/schedulability-compiler-v2.mjs +10 -4
- package/src/sensor-cli.mjs +23 -0
- package/src/todo-audit-pending.mjs +3 -5
- package/src/todo-authoring-input.mjs +1 -1
- package/src/todo-cli.mjs +129 -496
- package/src/todo-contracts.mjs +6 -2
- package/src/todo-independence-authoritative-observation.mjs +32 -5
- package/src/todo-independence-contracts.mjs +1 -0
- package/src/todo-independence.mjs +4 -1
- package/src/todo-note-store.mjs +3 -3
- package/src/todo-readiness.mjs +0 -1
- package/src/todo-status.mjs +0 -1
- package/src/todo-store.mjs +7 -3
package/src/todo-cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createTodoReadiness, listTodoConnections, retireStateConflict, validateProspectiveEvent } from './todo-readiness.mjs';
|
|
2
2
|
import { cliCommandKind } from './cli-command-kind.mjs';
|
|
3
3
|
import { cliFailureClass } from './cli-failure-class.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { FLAG_PLACEHOLDER, publicRefusalCode, withRefusalGuidance } from './cli-refusal-guidance.mjs';
|
|
5
5
|
import { readTaskBackchainContext } from './plan-backchain.mjs';
|
|
6
6
|
import { auditPendingNextCommands, phaseAuditRequired } from './todo-audit-pending.mjs';
|
|
7
7
|
import { gitSync } from './git-process.mjs';
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
isAuthoringPathToken,
|
|
17
17
|
matchFlagCommand,
|
|
18
18
|
parseFlagMap,
|
|
19
|
-
parseAuthoringJson,
|
|
20
19
|
readAuthoringJsonFile,
|
|
21
20
|
repairAuthoringArtifact,
|
|
22
21
|
resolveAuthoringInputPath,
|
|
@@ -30,7 +29,6 @@ import {
|
|
|
30
29
|
TODO_TEST_RESULT_CONTRACT_ID,
|
|
31
30
|
canonicalizeTodoArtifact,
|
|
32
31
|
digestTodoArtifact,
|
|
33
|
-
exactRecord,
|
|
34
32
|
explainTodoDesignMemo,
|
|
35
33
|
isTodoDigest,
|
|
36
34
|
isTodoDesignMemo,
|
|
@@ -38,7 +36,6 @@ import {
|
|
|
38
36
|
isTodoRef,
|
|
39
37
|
isTodoTestResult,
|
|
40
38
|
todoSelfDigest,
|
|
41
|
-
validateEvidenceDescriptor,
|
|
42
39
|
} from './todo-contracts.mjs';
|
|
43
40
|
import {
|
|
44
41
|
adoptTodoDashboardActivity,
|
|
@@ -71,8 +68,6 @@ import {
|
|
|
71
68
|
createTodoStoreWriter,
|
|
72
69
|
TodoStoreError,
|
|
73
70
|
isPhaselessTodoPlanSchema,
|
|
74
|
-
findUnverifiedTodoEvidence,
|
|
75
|
-
isTodoEvidenceUncommitted,
|
|
76
71
|
isUninitializedTodoStore,
|
|
77
72
|
projectTodoCrossPlanDependencies,
|
|
78
73
|
TERMINAL_AUDIT_PHASE_ID,
|
|
@@ -92,6 +87,7 @@ import {
|
|
|
92
87
|
writeTodoWitnessSet,
|
|
93
88
|
readTodoStoreDisplaySource,
|
|
94
89
|
readTodoStoreForDisplay,
|
|
90
|
+
readTodoChartMeta,
|
|
95
91
|
readTodoStoreStable,
|
|
96
92
|
rebuildTodoSnapshot,
|
|
97
93
|
writeTodoIndependenceArtifact,
|
|
@@ -212,8 +208,8 @@ import { repairTodoStoreWorktreeEol } from './todo-store-worktree-eol.mjs';
|
|
|
212
208
|
const CLI_ERROR_SCHEMA = 'lattice.cli_error.v2';
|
|
213
209
|
const DEFAULT_GANTT_SCOPE = 'live';
|
|
214
210
|
const MAX_NOTE_INPUT_BYTES = 16_384;
|
|
215
|
-
/**
|
|
216
|
-
const
|
|
211
|
+
/** `todo done` without --message records this text. */
|
|
212
|
+
const DONE_WITHOUT_MESSAGE = '証拠の指定なしで完了した。\n';
|
|
217
213
|
|
|
218
214
|
/**
|
|
219
215
|
* `revise` / `revise-set` / `revise-phase` / `migrate`が配布する名前付き入力契約のJSON
|
|
@@ -279,16 +275,6 @@ function guidanceContext(argv, env = {}) {
|
|
|
279
275
|
};
|
|
280
276
|
}
|
|
281
277
|
|
|
282
|
-
/** Enforced plans, so a refusal's done hint names the change their done gate needs; none when the store is unreadable. */
|
|
283
|
-
async function enforcedPlanKeys(cwd) {
|
|
284
|
-
try {
|
|
285
|
-
const { members } = await readTodoStore({ repoRoot: resolveRepoRoot(cwd) });
|
|
286
|
-
return members.filter((member) => member.coordination?.mode === 'enforced').map(({ descriptor }) => descriptor.plan_key);
|
|
287
|
-
} catch {
|
|
288
|
-
return [];
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
278
|
/**
|
|
293
279
|
* An error that reached here is, by definition, one none of the typed
|
|
294
280
|
* TodoStoreError/TypeError branches recognized — the one case where the
|
|
@@ -315,7 +301,7 @@ function internalFailure(stderr, error) {
|
|
|
315
301
|
const TODO_COMMAND_NAMES = Object.freeze([
|
|
316
302
|
'status', 'show', 'note', 'bindings', 'display', 'independence', 'structure', 'seam-profile', 'seam-proposal',
|
|
317
303
|
'verify', 'repair-eol', 'snapshot', 'gantt', 'dashboard', 'phase', 'migrate', 'start', 'block',
|
|
318
|
-
'unblock', 'retire', 'done', 'reopen', '
|
|
304
|
+
'unblock', 'retire', 'done', 'reopen', 'split', 'revise', 'revise-phase', 'revise-set',
|
|
319
305
|
'retract', 'dependency', 'predecessor', 'connect', 'add', 'notice', 'wait', 'blockers', 'compact',
|
|
320
306
|
]);
|
|
321
307
|
|
|
@@ -372,11 +358,9 @@ const TODO_FLAG_SPECS = Object.freeze({
|
|
|
372
358
|
split: Object.freeze({ known: ['plan', 'input'], required: ['plan', 'input'] }),
|
|
373
359
|
note: NOTE_FLAG_SPEC,
|
|
374
360
|
// a28: the rest of the writes, and the reads whose --json is optional (their output is JSON either way).
|
|
375
|
-
'phase accept': Object.freeze({ known: ['plan', 'phase', 'evidence', 'message'
|
|
376
|
-
'phase reject': Object.freeze({ known: ['plan', 'phase', 'evidence', 'message', 'reason'
|
|
361
|
+
'phase accept': Object.freeze({ known: ['plan', 'phase', 'evidence', 'message'], required: ['plan', 'phase'] }),
|
|
362
|
+
'phase reject': Object.freeze({ known: ['plan', 'phase', 'evidence', 'message', 'reason'], required: ['plan', 'phase'] }),
|
|
377
363
|
'phase reopen': Object.freeze({ known: ['plan', 'phase', 'reason', 'override-reason'], required: ['plan', 'phase', 'reason'] }),
|
|
378
|
-
'evidence promote': Object.freeze({ known: ['plan', 'task', 'evidence'], required: ['plan', 'task', 'evidence'] }),
|
|
379
|
-
'evidence anchor': Object.freeze({ known: ['json'], required: [], booleans: ['json'] }),
|
|
380
364
|
'independence compile': Object.freeze({ known: ['plan', 'input'], required: ['plan', 'input'] }),
|
|
381
365
|
'independence mode': Object.freeze({ known: ['plan', 'set', 'reason'], required: ['plan', 'set', 'reason'] }),
|
|
382
366
|
'independence witness scaffold': Object.freeze({ known: ['plan', 'input'], required: ['plan', 'input'] }),
|
|
@@ -402,9 +386,8 @@ const TODO_SUBCOMMANDS = Object.freeze({
|
|
|
402
386
|
predecessor: { names: ['add', 'remove'], example: 'add' },
|
|
403
387
|
connect: { names: ['condition', 'priority'], example: 'priority' },
|
|
404
388
|
phase: { names: ['status', 'review', 'accept', 'reject', 'reopen', 'close-unaudited', 'baseline'], example: 'review' },
|
|
405
|
-
evidence: { names: ['promote'], example: 'promote' },
|
|
406
389
|
});
|
|
407
|
-
const GROUP_COMMANDS = ['dependency', 'predecessor', 'connect', 'phase', '
|
|
390
|
+
const GROUP_COMMANDS = ['dependency', 'predecessor', 'connect', 'phase', 'independence', 'note', 'structure'];
|
|
408
391
|
const IDENTIFIER_FLAGS = ['plan', 'task', 'phase', 'from-plan', 'from-task', 'to-plan', 'to-task'];
|
|
409
392
|
// The shared table is FLAG_PLACEHOLDER (cli-refusal-guidance, a27).
|
|
410
393
|
const placeholder = (name) => FLAG_PLACEHOLDER[name] ?? `<${name}>`;
|
|
@@ -523,23 +506,13 @@ function explainArgumentRefusal(argv) {
|
|
|
523
506
|
}
|
|
524
507
|
}
|
|
525
508
|
if (argv[0] === 'phase' && ['accept', 'reject'].includes(argv[1])) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
next_action: `Add --evidence <file> (or --message <text>, or --input <decision file>): \`${repairedCommand(head, { ...spec, required: [...spec.required, 'evidence', ...(argv[1] === 'reject' ? ['reason'] : [])] }, flags)}\`.` };
|
|
530
|
-
}
|
|
531
|
-
if (given.length > 1) {
|
|
532
|
-
const [keep, drop] = given;
|
|
533
|
-
return { pointer: `--${drop}`, rule: 'flags_exclusive',
|
|
534
|
-
next_action: `Pass one of --evidence, --message or --input: \`${repairedCommand(head, spec, { ...flags, ...Object.fromEntries(given.filter((name) => name !== keep).map((name) => [name, undefined])) })}\`.` };
|
|
509
|
+
if (flags.evidence !== undefined && flags.message !== undefined) {
|
|
510
|
+
return { pointer: '--evidence', rule: 'flags_exclusive',
|
|
511
|
+
next_action: `Pass --message <text> alone: \`${repairedCommand(head, spec, { ...flags, evidence: undefined })}\`.` };
|
|
535
512
|
}
|
|
536
|
-
if (argv[1] === 'reject' &&
|
|
513
|
+
if (argv[1] === 'reject' && !(typeof flags.reason === 'string' && flags.reason.length > 0)) {
|
|
537
514
|
return { pointer: '--reason', rule: 'flag_missing',
|
|
538
|
-
next_action: `A reject
|
|
539
|
-
}
|
|
540
|
-
if (given[0] === 'input' && flags.reason !== undefined) {
|
|
541
|
-
return { pointer: '--reason', rule: 'flag_unknown',
|
|
542
|
-
next_action: `With --input the reason is inside the decision file; drop --reason: \`${repairedCommand(head, spec, { ...flags, reason: undefined })}\`.` };
|
|
515
|
+
next_action: `A reject needs --reason <text>: \`${repairedCommand(head, { ...spec, required: [...spec.required, 'reason'] }, flags)}\`.` };
|
|
543
516
|
}
|
|
544
517
|
}
|
|
545
518
|
for (const name of ['input', 'evidence']) {
|
|
@@ -588,7 +561,6 @@ function supportsAtomicStoreCommit(argv) {
|
|
|
588
561
|
if (command === 'migrate') return !argv.includes('--dry-run') && !argv.includes('--schema');
|
|
589
562
|
if (['revise', 'split', 'revise-set', 'revise-phase', 'start', 'retract', 'block',
|
|
590
563
|
'unblock', 'retire', 'done', 'reopen', 'add'].includes(command)) return true;
|
|
591
|
-
if (command === 'evidence') return argv[1] === 'promote';
|
|
592
564
|
if (command === 'phase') return argv[1] !== 'status';
|
|
593
565
|
return false;
|
|
594
566
|
}
|
|
@@ -748,130 +720,22 @@ async function readRevisionInput(repoRoot, inputRef, {
|
|
|
748
720
|
return revision;
|
|
749
721
|
}
|
|
750
722
|
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
+ ' "media_type": "text/markdown", "anchor_digest": null }',
|
|
757
|
-
note: '証拠ファイル本体ではなく、コミット済みblobを指すJSON記述子を渡す。'
|
|
758
|
-
+ '対象ファイルをcommitした後、git_blob_oidは `git rev-parse HEAD:<path>`、'
|
|
759
|
-
+ 'content_digestはblob bytesのsha256(hex)で得る。refsから到達可能なblobだけが検証を通る',
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
function evidenceIdFor(planKey, taskId) {
|
|
763
|
-
const compact = `ev-${planKey}-${taskId}`.replace(/[^0-9A-Za-z._-]/gu, '-').slice(0, 128);
|
|
764
|
-
return isTodoIdentifier(compact) ? compact : 'evidence';
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
function mediaTypeFor(ref) {
|
|
768
|
-
if (ref.endsWith('.md')) return 'text/markdown';
|
|
769
|
-
if (ref.endsWith('.json')) return 'application/json';
|
|
770
|
-
return 'text/plain';
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
function looksLikeEvidenceDescriptor(value) {
|
|
774
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
// evidence-ref: every evidence blob Lattice writes is anchored here so gc keeps it. The Store's reachability walk
|
|
778
|
-
// excludes refs/lattice/evidence/* (seam refs still count), so an anchored blob still reads `uncommitted` until a commit reaches it.
|
|
779
|
-
const EVIDENCE_REF_PREFIX = 'refs/lattice/evidence/';
|
|
780
|
-
|
|
781
|
-
function anchorEvidenceBlob(repoRoot, oid) {
|
|
782
|
-
gitSync(['update-ref', `${EVIDENCE_REF_PREFIX}${oid}`, oid], { cwd: repoRoot, stdio: ['ignore', 'ignore', 'pipe'] });
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
function evidenceAnchored(repoRoot, oid) {
|
|
786
|
-
try {
|
|
787
|
-
gitSync(['show-ref', '--verify', '--quiet', `${EVIDENCE_REF_PREFIX}${oid}`], { cwd: repoRoot, stdio: 'ignore' });
|
|
788
|
-
return true;
|
|
789
|
-
} catch {
|
|
790
|
-
return false;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
function writeEvidenceBlob(repoRoot, bytes, blobPath, write = true) {
|
|
795
|
-
// worktree pathから作る証拠は`git add`と同じclean filterを通す。生のCRLF bytesを
|
|
796
|
-
// そのままhashすると、commit先はLFへ正規化される一方、descriptorはdangling blobを
|
|
797
|
-
// 指すため、commit後もhard検証を通せない。
|
|
798
|
-
const oid = gitSync(['hash-object', ...(write ? ['-w'] : []), `--path=${blobPath}`, '--stdin'], {
|
|
799
|
-
cwd: repoRoot, input: bytes, encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'],
|
|
800
|
-
}).trim();
|
|
801
|
-
let storedBytes;
|
|
802
|
-
try {
|
|
803
|
-
storedBytes = gitSync(['cat-file', 'blob', oid], { cwd: repoRoot, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
804
|
-
} catch (error) {
|
|
805
|
-
// a23: a comparison-only hash writes nothing; content never stored has no digest to compare.
|
|
806
|
-
if (!write) return { git_blob_oid: oid, content_digest: null };
|
|
807
|
-
throw error;
|
|
808
|
-
}
|
|
809
|
-
// Anchored before the event is appended: no recorded evidence without an anchor. A failed append leaves one ref
|
|
810
|
-
// keeping one blob alive (bounded, harmless).
|
|
811
|
-
if (write) anchorEvidenceBlob(repoRoot, oid);
|
|
812
|
-
return {
|
|
813
|
-
git_blob_oid: oid,
|
|
814
|
-
content_digest: createHash('sha256').update(storedBytes).digest('hex'),
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
async function resolveDoneEvidence({
|
|
819
|
-
repoRoot, evidenceRef, evidenceMessage, planKey, taskId, write = true, inlineFlag = null,
|
|
820
|
-
}) {
|
|
821
|
-
if (typeof evidenceMessage === 'string') {
|
|
822
|
-
const bytes = Buffer.from(evidenceMessage, 'utf8');
|
|
823
|
-
const sourceDigest = createHash('sha256').update(bytes).digest('hex');
|
|
824
|
-
const evidencePath = `.lattice/todo/evidence/${planKey}/${taskId}/${sourceDigest}.md`;
|
|
825
|
-
const descriptor = {
|
|
826
|
-
evidence_id: evidenceIdFor(planKey, taskId),
|
|
827
|
-
repo_id: 'self',
|
|
828
|
-
path: evidencePath,
|
|
829
|
-
...writeEvidenceBlob(repoRoot, bytes, evidencePath, write),
|
|
830
|
-
media_type: 'text/markdown',
|
|
831
|
-
anchor_digest: null,
|
|
832
|
-
};
|
|
833
|
-
if (write && (!validateEvidenceDescriptor(descriptor) || !isTodoRef(descriptor.path))) {
|
|
834
|
-
throw new TodoStoreError('INVALID_EVIDENCE', 'authored_evidence_descriptor_invalid');
|
|
835
|
-
}
|
|
836
|
-
return descriptor;
|
|
837
|
-
}
|
|
723
|
+
/**
|
|
724
|
+
* One-version alias: `--evidence <file>` stands for `--message <text>` with the file's text. No blob is written
|
|
725
|
+
* and no descriptor is built; the text is the record.
|
|
726
|
+
*/
|
|
727
|
+
async function readEvidenceText(repoRoot, evidenceRef, { inlineFlag = '--message' } = {}) {
|
|
838
728
|
const located = await resolveAuthoringInputPath(repoRoot, evidenceRef, { inlineFlag });
|
|
839
729
|
const bytes = await readFile(located.absolute);
|
|
840
|
-
|
|
841
|
-
try { text = new TextDecoder('utf-8', { fatal: true }).decode(bytes); }
|
|
730
|
+
try { return new TextDecoder('utf-8', { fatal: true }).decode(bytes); }
|
|
842
731
|
catch { throw new TodoStoreError('INVALID_EVIDENCE', 'evidence_input_invalid_utf8'); }
|
|
843
|
-
let parsed = null;
|
|
844
|
-
try {
|
|
845
|
-
parsed = parseAuthoringJson(text, { invalidCode: 'INVALID_JSON' });
|
|
846
|
-
} catch (error) {
|
|
847
|
-
if (error instanceof TodoStoreError && error.code !== 'INVALID_JSON') throw error;
|
|
848
|
-
}
|
|
849
|
-
if (looksLikeEvidenceDescriptor(parsed)) {
|
|
850
|
-
if (!validateEvidenceDescriptor(parsed)) {
|
|
851
|
-
throw new TodoStoreError('INVALID_EVIDENCE', 'schema_invalid', undefined, {
|
|
852
|
-
expected: EVIDENCE_DESCRIPTOR_EXPECTED,
|
|
853
|
-
});
|
|
854
|
-
}
|
|
855
|
-
return parsed;
|
|
856
|
-
}
|
|
857
|
-
const descriptor = {
|
|
858
|
-
evidence_id: evidenceIdFor(planKey, taskId),
|
|
859
|
-
repo_id: 'self',
|
|
860
|
-
path: located.inputRef,
|
|
861
|
-
...writeEvidenceBlob(repoRoot, bytes, located.inputRef, write),
|
|
862
|
-
media_type: mediaTypeFor(located.inputRef),
|
|
863
|
-
anchor_digest: null,
|
|
864
|
-
};
|
|
865
|
-
if (write && !validateEvidenceDescriptor(descriptor)) {
|
|
866
|
-
throw new TodoStoreError('INVALID_EVIDENCE', 'authored_evidence_descriptor_invalid');
|
|
867
|
-
}
|
|
868
|
-
return descriptor;
|
|
869
732
|
}
|
|
870
733
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
734
|
+
/** The alias says which flag replaces it, after the command succeeded. */
|
|
735
|
+
function retiredEvidenceFlag(stderr, command, result) {
|
|
736
|
+
stderr.write(`${JSON.stringify({ schema: 'lattice.todo_command_retired.v1', command: `${command} --evidence`,
|
|
737
|
+
still_works_until: 'the next minor version', use: `lattice ${command} --message <text>` })}\n`);
|
|
738
|
+
return result;
|
|
875
739
|
}
|
|
876
740
|
|
|
877
741
|
async function readJsonInput(repoRoot, inputRef, { validate, invalidCode, expected = null }) {
|
|
@@ -938,19 +802,16 @@ async function readStructureSetDraft(repoRoot, inputRef) {
|
|
|
938
802
|
*/
|
|
939
803
|
function auditGateGuidance(planKey, phaseId, auditRequired = false) {
|
|
940
804
|
const target = `--plan ${planKey} --phase ${phaseId}`;
|
|
941
|
-
const audit = `lattice todo phase review ${target} --reason <text> → accept ${target} --
|
|
942
|
-
// ADR 0200 gate 5: an enforced plan's heavy phase refuses close-unaudited, so only the audit is offered
|
|
943
|
-
|
|
944
|
-
if (auditRequired) return `全ToDoがdone。このplanはenforcedでheavyの段階なので監査する: ${audit}(fileを置けないなら --message <text>)`;
|
|
805
|
+
const audit = `lattice todo phase review ${target} --reason <text> → accept ${target} [--message <text>]`;
|
|
806
|
+
// ADR 0200 gate 5: an enforced plan's heavy phase refuses close-unaudited, so only the audit is offered.
|
|
807
|
+
if (auditRequired) return `全ToDoがdone。このplanはenforcedでheavyの段階なので監査する: ${audit}`;
|
|
945
808
|
return `全ToDoがdone。監査せず閉じるなら: lattice todo phase close-unaudited ${target} --reason <text>`
|
|
946
809
|
+ `(監査するなら ${audit})`;
|
|
947
810
|
}
|
|
948
811
|
|
|
949
812
|
/** a36: reviewing and rejected phases say their next command too (the same lines as audit_pending). */
|
|
950
813
|
function auditDecisionGuidance(plan, phase) {
|
|
951
|
-
const
|
|
952
|
-
?.required_evidence_slots.length ?? 1;
|
|
953
|
-
const [first, second] = auditPendingNextCommands(plan.plan_key, phase.phase_id, phase.status, slots);
|
|
814
|
+
const [first, second] = auditPendingNextCommands(plan.plan_key, phase.phase_id, phase.status);
|
|
954
815
|
return phase.status === 'reviewing'
|
|
955
816
|
? `監査中(review済み)。受け入れるなら: ${first}(通らないなら: ${second})`
|
|
956
817
|
: `監査が通らなかった。やり直すなら: ${first}`;
|
|
@@ -1014,7 +875,7 @@ function externalValidator(external) {
|
|
|
1014
875
|
}
|
|
1015
876
|
|
|
1016
877
|
async function mutate({
|
|
1017
|
-
repoRoot, env, planKey, taskId, kind, payload,
|
|
878
|
+
repoRoot, env, planKey, taskId, kind, payload, message = null,
|
|
1018
879
|
advisory = null, noteContext = null, structureContext = null, featureContext = null,
|
|
1019
880
|
testResultRef = null, actor: carriedActor = null, externalTasks = null,
|
|
1020
881
|
}) {
|
|
@@ -1023,31 +884,11 @@ async function mutate({
|
|
|
1023
884
|
const external = externalTasks ?? (kind === 'start' || (kind === 'done' && payload === 'authored')
|
|
1024
885
|
? (await readTodoExternalTasks(await readTodoStore({ repoRoot }), env)).external_tasks : []);
|
|
1025
886
|
const validator = externalValidator(external);
|
|
1026
|
-
const evidence = evidenceRef === null && evidenceMessage === null
|
|
1027
|
-
? null
|
|
1028
|
-
: await resolveDoneEvidence({
|
|
1029
|
-
repoRoot, evidenceRef, evidenceMessage, planKey, taskId,
|
|
1030
|
-
// Only an authored done takes --message as the inline alternative to --evidence.
|
|
1031
|
-
inlineFlag: kind === 'done' && payload === 'authored' ? '--message' : null,
|
|
1032
|
-
});
|
|
1033
887
|
const testResult = testResultRef === null ? null : await readTestResultInput(repoRoot, testResultRef);
|
|
1034
|
-
const materializedEvidence = typeof evidenceMessage === 'string'
|
|
1035
|
-
? {
|
|
1036
|
-
ref: evidence.path,
|
|
1037
|
-
bytes: gitSync(['cat-file', 'blob', evidence.git_blob_oid], {
|
|
1038
|
-
cwd: repoRoot, stdio: ['ignore', 'pipe', 'ignore'],
|
|
1039
|
-
}),
|
|
1040
|
-
}
|
|
1041
|
-
: null;
|
|
1042
888
|
let eventPayload = payload;
|
|
1043
889
|
if (kind === 'done' && payload === 'authored') {
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
if (kind === 'done' && payload === 'evidence_promotion') {
|
|
1047
|
-
// imported/authored の由来はlock内のcanonical stateから解決する。
|
|
1048
|
-
// CLI側で固定するとauthored doneの証拠を再束縛できず、path更新後の
|
|
1049
|
-
// evidence_unverifiedを修復する公開経路が無くなる。
|
|
1050
|
-
eventPayload = { done_mode: 'evidence_promotion', evidence };
|
|
890
|
+
// The store canonicalizes only the legacy {evidence} input, so the CLI sends the recorded shape itself.
|
|
891
|
+
eventPayload = { done_mode: 'authored', imported: false, message, ...(testResult === null ? {} : { test_result: testResult }) };
|
|
1051
892
|
}
|
|
1052
893
|
const { event, snapshot, plan, phases } = await appendTodoEvent({
|
|
1053
894
|
validateProspectiveEvent: validator,
|
|
@@ -1055,7 +896,6 @@ async function mutate({
|
|
|
1055
896
|
writer: createTodoStoreWriter({ caller: 'g5-authoring' }),
|
|
1056
897
|
planKey,
|
|
1057
898
|
event: { kind, task_id: taskId, actor, payload: eventPayload },
|
|
1058
|
-
materializedEvidence,
|
|
1059
899
|
});
|
|
1060
900
|
const task = snapshot.tasks.find(({ task_id: current }) => current === event.task_id);
|
|
1061
901
|
const authoredTask = plan.tasks.find(({ task_id: current }) => current === event.task_id);
|
|
@@ -1109,7 +949,7 @@ function withBlockGuidance(result) {
|
|
|
1109
949
|
|
|
1110
950
|
/** retract-anyone: a reopened task is unstarted again; the redo records a start (from any seat). */
|
|
1111
951
|
async function reopenTask({ repoRoot, env, planKey, taskId, payload }) {
|
|
1112
|
-
const result = await mutate({ repoRoot, env, planKey, taskId, kind: 'reopen', payload
|
|
952
|
+
const result = await mutate({ repoRoot, env, planKey, taskId, kind: 'reopen', payload });
|
|
1113
953
|
const hinted = {
|
|
1114
954
|
...result,
|
|
1115
955
|
next_action: `${result.plan_key}/${result.task_id} is unstarted again; redo it with`
|
|
@@ -1188,38 +1028,21 @@ async function mutateUnlessUnchanged(options) {
|
|
|
1188
1028
|
/** a23: block/retire drop a --reason that differs from the recorded one. */
|
|
1189
1029
|
const reasonDropped = (reason) => async (recorded) => (recorded?.payload?.reason === reason ? [] : ['--reason']);
|
|
1190
1030
|
|
|
1191
|
-
/** The
|
|
1192
|
-
async function
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
// The message is the record; it names the resolved file so nothing given is lost.
|
|
1197
|
-
const file = await resolveDoneEvidence({
|
|
1198
|
-
repoRoot, evidenceRef: flags.evidence, evidenceMessage: null, planKey: flags.plan, taskId: flags.task,
|
|
1199
|
-
write, inlineFlag: '--message',
|
|
1200
|
-
});
|
|
1201
|
-
return { evidenceRef: null, evidenceMessage: `${flags.message}\n\nevidence: ${file.repo_id}:${file.path}`
|
|
1202
|
-
+ ` (git blob ${file.git_blob_oid}, sha256 ${file.content_digest})\n` };
|
|
1203
|
-
}
|
|
1204
|
-
if (hasEvidence) return { evidenceRef: flags.evidence, evidenceMessage: null };
|
|
1205
|
-
return { evidenceRef: null, evidenceMessage: hasMessage ? flags.message : DONE_WITHOUT_EVIDENCE_MESSAGE };
|
|
1031
|
+
/** The text a `todo done` records: --message, else the text of the one-version `--evidence <file>` alias, else the default. */
|
|
1032
|
+
async function doneMessage({ repoRoot, flags }) {
|
|
1033
|
+
if (typeof flags.message === 'string' && flags.message.length > 0) return flags.message;
|
|
1034
|
+
if (isAuthoringPathToken(flags.evidence)) return readEvidenceText(repoRoot, flags.evidence);
|
|
1035
|
+
return DONE_WITHOUT_MESSAGE;
|
|
1206
1036
|
}
|
|
1207
1037
|
|
|
1208
|
-
/**
|
|
1209
|
-
* a23: the content flags of a repeated done that the recorded done does not hold. Compared by git blob,
|
|
1210
|
-
* hashed without writing; a file that cannot be read counts as differing.
|
|
1211
|
-
*/
|
|
1038
|
+
/** a23: the content flags of a repeated done that the recorded done does not hold. */
|
|
1212
1039
|
async function doneDropped({ repoRoot, flags, recorded }) {
|
|
1213
|
-
const
|
|
1214
|
-
const sameEvidence = async () => {
|
|
1215
|
-
const evidence = await resolveDoneEvidence({ repoRoot, ...await doneEvidenceInput({ repoRoot, flags, write: false }),
|
|
1216
|
-
planKey: flags.plan, taskId: flags.task, write: false });
|
|
1217
|
-
return evidence.git_blob_oid === recorded?.payload?.evidence?.git_blob_oid;
|
|
1218
|
-
};
|
|
1040
|
+
const sameMessage = async () => (await doneMessage({ repoRoot, flags })) === recorded?.payload?.message;
|
|
1219
1041
|
const sameTestResult = async () => (await readTestResultInput(repoRoot, flags['test-result'])) === recorded?.payload?.test_result;
|
|
1220
1042
|
const differs = async (same) => { try { return !(await same()); } catch { return true; } };
|
|
1043
|
+
const given = ['message', 'evidence'].filter((name) => flags[name] !== undefined).map((name) => `--${name}`);
|
|
1221
1044
|
return [
|
|
1222
|
-
...(given
|
|
1045
|
+
...(given.length > 0 && await differs(sameMessage) ? given : []),
|
|
1223
1046
|
...(flags['test-result'] !== undefined && await differs(sameTestResult) ? ['--test-result'] : []),
|
|
1224
1047
|
];
|
|
1225
1048
|
}
|
|
@@ -1250,7 +1073,7 @@ async function retireTask({ repoRoot, env, planKey, taskId, reason }) {
|
|
|
1250
1073
|
const state = member?.tasks.find(({ task_id: current }) => current === taskId);
|
|
1251
1074
|
if (state === undefined) {
|
|
1252
1075
|
// 未知のplan/taskはStoreの既存の拒否をそのまま通す。
|
|
1253
|
-
return mutate({ repoRoot, env, planKey, taskId, kind: 'retire', payload: { reason }
|
|
1076
|
+
return mutate({ repoRoot, env, planKey, taskId, kind: 'retire', payload: { reason } });
|
|
1254
1077
|
}
|
|
1255
1078
|
if (state.status === 'retired') {
|
|
1256
1079
|
return unchangedTransition(store, { env, planKey, taskId, kind: 'retire', dropped: reasonDropped(reason) });
|
|
@@ -1260,7 +1083,7 @@ async function retireTask({ repoRoot, env, planKey, taskId, reason }) {
|
|
|
1260
1083
|
let result;
|
|
1261
1084
|
try {
|
|
1262
1085
|
result = await mutate({ repoRoot, env, planKey, taskId, kind: 'retire',
|
|
1263
|
-
payload: { reason, prior_status: state.status }
|
|
1086
|
+
payload: { reason, prior_status: state.status } });
|
|
1264
1087
|
} catch (error) {
|
|
1265
1088
|
throw retireStateConflict(error, { planKey, taskId, priorStatus: state.status });
|
|
1266
1089
|
}
|
|
@@ -1525,7 +1348,7 @@ async function startTask({
|
|
|
1525
1348
|
const advisory = await startAdvisory({
|
|
1526
1349
|
repoRoot, store, projection, planKey, taskId: resolvedTaskId,
|
|
1527
1350
|
});
|
|
1528
|
-
if (member.coordination?.mode === 'enforced') {
|
|
1351
|
+
if (member.coordination?.mode === 'enforced' && !(await noCodeTask({ repoRoot, member, taskId: resolvedTaskId }))) {
|
|
1529
1352
|
enforcedStartGate({ advisory, planKey, taskId: resolvedTaskId, overrideReason });
|
|
1530
1353
|
}
|
|
1531
1354
|
const structureContext = await startStructureContext({
|
|
@@ -1543,7 +1366,7 @@ async function startTask({
|
|
|
1543
1366
|
{ code: 'LATTICE_START_BACKCHAIN_UNUSABLE' });
|
|
1544
1367
|
}
|
|
1545
1368
|
return mutate({ repoRoot, env, planKey, taskId: resolvedTaskId, kind: 'start',
|
|
1546
|
-
payload: { override_reason: overrideReason },
|
|
1369
|
+
payload: { override_reason: overrideReason }, advisory, noteContext,
|
|
1547
1370
|
structureContext, featureContext, externalTasks: store.external_tasks ?? [] });
|
|
1548
1371
|
}
|
|
1549
1372
|
|
|
@@ -1567,6 +1390,16 @@ function headResolves(repoRoot) {
|
|
|
1567
1390
|
const declareCommand = (planKey, taskId) => `lattice todo independence witness declare --plan ${planKey} --task ${taskId}`
|
|
1568
1391
|
+ ' --owns <path>[,<path>...] [--reads <path>,...] [--writes <path>,...]';
|
|
1569
1392
|
|
|
1393
|
+
/**
|
|
1394
|
+
* g3: a task in a lane the host marked `no_code_lanes` (`chart set --no-code-lane`) touches no code, so gates 1–3 do not apply:
|
|
1395
|
+
* it counts as declared with an empty boundary and can neither conflict nor go stale. Lattice names no lane itself.
|
|
1396
|
+
* An unreadable chart meta means no lane is marked (the gates apply).
|
|
1397
|
+
*/
|
|
1398
|
+
async function noCodeTask({ repoRoot, member, taskId }) {
|
|
1399
|
+
const lane = member.plan.tasks.find(({ task_id: id }) => id === taskId)?.lane;
|
|
1400
|
+
return (await readTodoChartMeta({ repoRoot }).catch(() => null))?.no_code_lanes?.includes(lane) ?? false;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1570
1403
|
/** ADR 0200 gates 1–3: an enforced plan does not start undeclared, stale or conflicting work. Reads the advisory only. */
|
|
1571
1404
|
function enforcedStartGate({ advisory, planKey, taskId, overrideReason }) {
|
|
1572
1405
|
const unknown = (kind) => advisory.self_unknowns.some((entry) => entry.kind === kind);
|
|
@@ -1587,24 +1420,6 @@ function enforcedStartGate({ advisory, planKey, taskId, overrideReason }) {
|
|
|
1587
1420
|
}
|
|
1588
1421
|
}
|
|
1589
1422
|
|
|
1590
|
-
/** ADR 0200 gate 4: done on an enforced plan names the change: evidence, an http(s) URL, or a commit in HEAD. */
|
|
1591
|
-
async function enforcedDoneGate({ repoRoot, planKey, flags }) {
|
|
1592
|
-
const member = (await readTodoStore({ repoRoot })).members.find(({ descriptor }) => descriptor.plan_key === planKey);
|
|
1593
|
-
if (member?.coordination?.mode !== 'enforced' || flags.evidence !== undefined) return;
|
|
1594
|
-
const message = typeof flags.message === 'string' ? flags.message : '';
|
|
1595
|
-
if (/https?:\/\/\S+/u.test(message)) return;
|
|
1596
|
-
for (const token of message.match(/\b[0-9a-f]{7,40}\b/gu) ?? []) {
|
|
1597
|
-
try {
|
|
1598
|
-
gitSync(['merge-base', '--is-ancestor', token, 'HEAD'], { cwd: repoRoot, stdio: 'ignore' });
|
|
1599
|
-
return;
|
|
1600
|
-
} catch { /* not a commit in HEAD; try the next token */ }
|
|
1601
|
-
}
|
|
1602
|
-
throw new TodoStoreError('TODO_TRANSITION_REFUSED', 'enforced_done_reference_missing', undefined, {
|
|
1603
|
-
plan_key: planKey, task_id: flags.task,
|
|
1604
|
-
next_action: `Name the adopted change: \`lattice todo done --plan ${planKey} --task ${flags.task} --message ${ENFORCED_DONE_MESSAGE}\` (a sha must be in HEAD).`,
|
|
1605
|
-
});
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
1423
|
// plan改訂でcarryされたin-progress ToDoの再束縛入口(ADR 0191)。task状態・開始時刻は
|
|
1609
1424
|
// 変えず、現plan_version・現actorのstart束縛だけをjournalへ積む。runtime intakeは
|
|
1610
1425
|
// literal startだけを束縛に使いcarryを推定しないため、改訂を跨いだ進行中工程の
|
|
@@ -1643,7 +1458,7 @@ export async function rebindStart({ repoRoot, env, planKey, taskId, reason, acto
|
|
|
1643
1458
|
}
|
|
1644
1459
|
return mutate({
|
|
1645
1460
|
repoRoot, env, planKey, taskId, kind: 'start',
|
|
1646
|
-
payload: { start_mode: 'rebind', reason },
|
|
1461
|
+
payload: { start_mode: 'rebind', reason }, noteContext, actor,
|
|
1647
1462
|
});
|
|
1648
1463
|
}
|
|
1649
1464
|
|
|
@@ -1679,85 +1494,22 @@ async function retractStart({ repoRoot, env, planKey, taskId, reason }) {
|
|
|
1679
1494
|
action: () => mutate({
|
|
1680
1495
|
repoRoot, env, planKey, taskId: binding.task_id, kind: 'start_retracted',
|
|
1681
1496
|
payload: { reason, target_start_digest: binding.activation_event_digest },
|
|
1682
|
-
evidenceRef: null,
|
|
1683
1497
|
}),
|
|
1684
1498
|
});
|
|
1685
1499
|
}
|
|
1686
1500
|
|
|
1687
|
-
function validatePhaseDecisionInput(value, outcome) {
|
|
1688
|
-
const keys = outcome === 'accept'
|
|
1689
|
-
? ['schema', 'review_event_digest', 'decision_evidence', 'evidence_slots', 'input_digest']
|
|
1690
|
-
: ['schema', 'review_event_digest', 'reason', 'decision_evidence', 'input_digest'];
|
|
1691
|
-
return exactRecord(value, keys) && value.schema === `lattice.phase_${outcome}_input.v1`
|
|
1692
|
-
&& isTodoDigest(value.review_event_digest) && validateEvidenceDescriptor(value.decision_evidence)
|
|
1693
|
-
&& (outcome === 'accept'
|
|
1694
|
-
? Array.isArray(value.evidence_slots) && value.evidence_slots.length > 0
|
|
1695
|
-
&& value.evidence_slots.every((entry) => exactRecord(entry, ['slot_id', 'evidence'])
|
|
1696
|
-
&& isTodoIdentifier(entry.slot_id) && validateEvidenceDescriptor(entry.evidence))
|
|
1697
|
-
&& value.evidence_slots.every((entry, index) => index === 0
|
|
1698
|
-
|| value.evidence_slots[index - 1].slot_id < entry.slot_id)
|
|
1699
|
-
: typeof value.reason === 'string' && value.reason.length > 0)
|
|
1700
|
-
&& isTodoDigest(value.input_digest) && value.input_digest === todoSelfDigest(value, 'input_digest');
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
|
-
// `--input`の形が合わないとき、期待形をerrorへ同梱する(ADR 0130)。自己digestは入口が補うので
|
|
1704
|
-
// 空でよい(ADR 0181)。証拠記述子を手で作らせないために、ふつうは`--evidence`を案内する。
|
|
1705
|
-
const PHASE_DECISION_EXPECTED = Object.freeze({
|
|
1706
|
-
accept: '{ "schema": "lattice.phase_accept_input.v1", "review_event_digest": "<phase reviewのevent_digest>",'
|
|
1707
|
-
+ ' "decision_evidence": <evidence記述子>, "evidence_slots": [{ "slot_id": "<必須slot>", "evidence": <evidence記述子> }],'
|
|
1708
|
-
+ ' "input_digest": "" }',
|
|
1709
|
-
reject: '{ "schema": "lattice.phase_reject_input.v1", "review_event_digest": "<phase reviewのevent_digest>",'
|
|
1710
|
-
+ ' "reason": "<text>", "decision_evidence": <evidence記述子>, "input_digest": "" }',
|
|
1711
|
-
note: 'input_digestは入口が計算する。証拠fileがcommit済みなら、`--evidence <file>`で'
|
|
1712
|
-
+ 'review_event_digest・記述子・必須slotを機械が埋める。fileを置けないなら`--message <text>`でも同じく埋まる'
|
|
1713
|
-
+ '(commitまではuncommitted)。evidence記述子の形はEVIDENCE_DESCRIPTOR_EXPECTEDを見る。',
|
|
1714
|
-
});
|
|
1715
|
-
|
|
1716
|
-
async function phaseDecision({ repoRoot, env, planKey, phaseId, outcome, inputRef }) {
|
|
1717
|
-
let input;
|
|
1718
|
-
try {
|
|
1719
|
-
input = await readRevisionInput(repoRoot, inputRef, {
|
|
1720
|
-
validate: (value) => validatePhaseDecisionInput(value, outcome),
|
|
1721
|
-
invalidCode: 'PHASE_DECISION_INVALID', invalidReason: 'phase_decision_schema_or_digest_invalid',
|
|
1722
|
-
// phase decision入力はrevision契約と別形状。既定のrevision explainを誤って当てない。
|
|
1723
|
-
explain: null,
|
|
1724
|
-
});
|
|
1725
|
-
} catch (error) {
|
|
1726
|
-
if (error instanceof TodoStoreError && error.code === 'PHASE_DECISION_INVALID') {
|
|
1727
|
-
throw new TodoStoreError('PHASE_DECISION_INVALID', 'phase_decision_schema_or_digest_invalid', undefined, {
|
|
1728
|
-
expected: PHASE_DECISION_EXPECTED[outcome], note: PHASE_DECISION_EXPECTED.note,
|
|
1729
|
-
evidence_descriptor: EVIDENCE_DESCRIPTOR_EXPECTED,
|
|
1730
|
-
next_action: `lattice todo phase ${outcome} --plan ${planKey} --phase ${phaseId}`
|
|
1731
|
-
+ (outcome === 'reject' ? ' --reason <text>' : '') + ' --evidence <repo内の監査file>',
|
|
1732
|
-
});
|
|
1733
|
-
}
|
|
1734
|
-
throw error;
|
|
1735
|
-
}
|
|
1736
|
-
const payload = outcome === 'accept'
|
|
1737
|
-
? { review_event_digest: input.review_event_digest, decision_evidence: input.decision_evidence,
|
|
1738
|
-
evidence_slots: input.evidence_slots }
|
|
1739
|
-
: { review_event_digest: input.review_event_digest, reason: input.reason,
|
|
1740
|
-
decision_evidence: input.decision_evidence };
|
|
1741
|
-
return phaseMutation({ repoRoot, env, planKey, phaseId, kind: `phase_${outcome}`, payload });
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1744
1501
|
/**
|
|
1745
|
-
*
|
|
1746
|
-
*
|
|
1747
|
-
* fileから作る。必須slotが1つならその証拠で埋める。複数slotへ1つの証拠を流用すると
|
|
1748
|
-
* 「各slotを別々に確かめた」ことを偽るので、その場合は`--input`で明示させる。
|
|
1502
|
+
* `phase accept|reject`: the decision binds to the current review and records an optional --message.
|
|
1503
|
+
* No evidence is asked for; the phase closes on the decision alone.
|
|
1749
1504
|
*/
|
|
1750
|
-
async function
|
|
1751
|
-
repoRoot, env, planKey, phaseId, outcome, evidenceRef = null, evidenceMessage = null, reason,
|
|
1752
|
-
}) {
|
|
1505
|
+
async function phaseDecision({ repoRoot, env, planKey, phaseId, outcome, message = null, reason = null }) {
|
|
1753
1506
|
const store = await readTodoStore({ repoRoot });
|
|
1754
1507
|
const member = store.members.find(({ plan }) => plan.plan_key === planKey);
|
|
1755
1508
|
if (member === undefined) {
|
|
1756
1509
|
throw new TodoStoreError('PHASE_DECISION_INVALID', 'plan_not_active', undefined, { plan_key: planKey });
|
|
1757
1510
|
}
|
|
1758
1511
|
const state = member.phases.find(({ phase_id: current }) => current === phaseId);
|
|
1759
|
-
|
|
1760
|
-
if (state === undefined || definition === undefined) {
|
|
1512
|
+
if (state === undefined) {
|
|
1761
1513
|
throw new TodoStoreError('PHASE_DECISION_INVALID', 'phase_not_found', undefined, {
|
|
1762
1514
|
plan_key: planKey, phase_id: phaseId,
|
|
1763
1515
|
phases: todoPhaseDefinitions(member.plan).map(({ phase_id: id }) => id),
|
|
@@ -1769,30 +1521,14 @@ async function phaseDecisionFromEvidence({
|
|
|
1769
1521
|
next_action: `lattice todo phase review --plan ${planKey} --phase ${phaseId} --reason <text>`,
|
|
1770
1522
|
});
|
|
1771
1523
|
}
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
});
|
|
1778
|
-
}
|
|
1779
|
-
// A --message becomes message evidence exactly as in `todo done`: no file inside the Store root is needed.
|
|
1780
|
-
const evidence = await resolveDoneEvidence({
|
|
1781
|
-
repoRoot, evidenceRef, evidenceMessage, planKey, taskId: `${phaseId}-${outcome}`,
|
|
1782
|
-
});
|
|
1783
|
-
const payload = outcome === 'accept'
|
|
1784
|
-
? { review_event_digest: state.review_event_digest, decision_evidence: evidence,
|
|
1785
|
-
evidence_slots: definition.required_evidence_slots.map((slotId) => ({ slot_id: slotId, evidence })) }
|
|
1786
|
-
: { review_event_digest: state.review_event_digest, reason, decision_evidence: evidence };
|
|
1524
|
+
const payload = {
|
|
1525
|
+
review_event_digest: state.review_event_digest,
|
|
1526
|
+
...(outcome === 'reject' ? { reason } : {}),
|
|
1527
|
+
...(message === null ? {} : { message }),
|
|
1528
|
+
};
|
|
1787
1529
|
return phaseMutation({ repoRoot, env, planKey, phaseId, kind: `phase_${outcome}`, payload });
|
|
1788
1530
|
}
|
|
1789
1531
|
|
|
1790
|
-
/** A phase decision's evidence: committed, uncommitted (no ref reaches it yet, e.g. `--message` on a root with no commit) or null. */
|
|
1791
|
-
function decisionEvidenceState(repoRoot, store, evidence) {
|
|
1792
|
-
if (evidence === null || evidence === undefined) return null;
|
|
1793
|
-
return isTodoEvidenceUncommitted({ repoRoot, store, evidence }) ? 'uncommitted' : 'committed';
|
|
1794
|
-
}
|
|
1795
|
-
|
|
1796
1532
|
async function phaseMutation({ repoRoot, env, planKey, phaseId, kind, payload }) {
|
|
1797
1533
|
if (kind === 'phase_close_unaudited') {
|
|
1798
1534
|
// ADR 0200 gate 5: an enforced plan keeps the audit its author required for a heavy phase.
|
|
@@ -1802,9 +1538,8 @@ async function phaseMutation({ repoRoot, env, planKey, phaseId, kind, payload })
|
|
|
1802
1538
|
if (phaseAuditRequired(member, phase?.gate_policy)) {
|
|
1803
1539
|
throw new TodoStoreError('TODO_TRANSITION_REFUSED', 'enforced_heavy_phase_unaudited', undefined, {
|
|
1804
1540
|
plan_key: planKey, phase_id: phaseId,
|
|
1805
|
-
next_action: `Audit it: \`lattice todo phase review --plan ${planKey} --phase ${phaseId} --reason <text>\` then \`lattice todo phase accept --plan ${planKey} --phase ${phaseId}
|
|
1806
|
-
+
|
|
1807
|
-
+ ' or revise the phase to a non-heavy gate_policy with `lattice plan revise` (recorded).',
|
|
1541
|
+
next_action: `Audit it: \`lattice todo phase review --plan ${planKey} --phase ${phaseId} --reason <text>\` then \`lattice todo phase accept --plan ${planKey} --phase ${phaseId}\``
|
|
1542
|
+
+ ' (a --message <text> is optional); or revise the phase to a non-heavy gate_policy with `lattice plan revise` (recorded).',
|
|
1808
1543
|
});
|
|
1809
1544
|
}
|
|
1810
1545
|
}
|
|
@@ -1823,8 +1558,6 @@ async function phaseMutation({ repoRoot, env, planKey, phaseId, kind, payload })
|
|
|
1823
1558
|
kind: event.kind, sequence: event.sequence, event_digest: event.event_digest,
|
|
1824
1559
|
journal_head_digest: event.event_digest, snapshot_digest: snapshot.snapshot_digest,
|
|
1825
1560
|
status: phase.status,
|
|
1826
|
-
decision_evidence_state: phase.decision_evidence === null || phase.decision_evidence === undefined ? null
|
|
1827
|
-
: decisionEvidenceState(repoRoot, await readTodoStore({ repoRoot }), phase.decision_evidence),
|
|
1828
1561
|
result_digest: '',
|
|
1829
1562
|
};
|
|
1830
1563
|
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
@@ -2348,7 +2081,6 @@ async function phaseStatus({ repoRoot, planKey }) {
|
|
|
2348
2081
|
// v4/v5の実Phaseがgate_readyになった場合も同じ理由で同じ案内が要る。
|
|
2349
2082
|
const phases = member.phases.map((phase) => ({
|
|
2350
2083
|
...phase,
|
|
2351
|
-
decision_evidence_state: decisionEvidenceState(repoRoot, store, phase.decision_evidence),
|
|
2352
2084
|
acceptance_stale: phaseAcceptanceStale(member.plan, member.journal.events, phase, member.tasks),
|
|
2353
2085
|
guidance: phaseAcceptanceStale(member.plan, member.journal.events, phase, member.tasks)
|
|
2354
2086
|
? staleAcceptanceGuidance(member.plan.plan_key, phase.phase_id)
|
|
@@ -2559,8 +2291,8 @@ function extractionFreshnessViolations(repoRoot, extraction) {
|
|
|
2559
2291
|
// rev-listの出力はobject数に比例して伸びる(本repo実測で既定maxBuffer 1MiB超過済み)。
|
|
2560
2292
|
// 隣のgit showと同様にmaxBufferを明示しないと、ENOBUFSが握られて
|
|
2561
2293
|
// source_reachability_unreadableへ誤変換される。
|
|
2562
|
-
//
|
|
2563
|
-
reachable = new Set(gitSync(['rev-list', '--objects',
|
|
2294
|
+
// Blobs anchored by 0.105 and earlier live under refs/lattice/evidence/*; they are not a reachable source.
|
|
2295
|
+
reachable = new Set(gitSync(['rev-list', '--objects', '--exclude=refs/lattice/evidence/*', '--all'], {
|
|
2564
2296
|
cwd: repoRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], maxBuffer: 134_217_728,
|
|
2565
2297
|
}).split('\n').filter(Boolean).map((line) => line.split(' ')[0]));
|
|
2566
2298
|
} catch {
|
|
@@ -3492,7 +3224,7 @@ async function recordStructureRealization({ repoRoot, planKey, taskId, realizati
|
|
|
3492
3224
|
previous_realization_digest: appended.previous_realization_digest,
|
|
3493
3225
|
history_length: appended.history_length,
|
|
3494
3226
|
effective: taskProjection,
|
|
3495
|
-
next_action: `lattice todo done --plan ${planKey} --task ${taskId} --
|
|
3227
|
+
next_action: `lattice todo done --plan ${planKey} --task ${taskId} --message <text>`,
|
|
3496
3228
|
result_digest: '',
|
|
3497
3229
|
};
|
|
3498
3230
|
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
@@ -3750,25 +3482,7 @@ async function independenceCompile({ repoRoot, planKey, inputRef }) {
|
|
|
3750
3482
|
{ task_ids: absentFromPlan },
|
|
3751
3483
|
);
|
|
3752
3484
|
}
|
|
3753
|
-
|
|
3754
|
-
.filter((task) => task.plan_key === planKey)
|
|
3755
|
-
.map((task) => task.task_id);
|
|
3756
|
-
const declared = new Set(declaredIds);
|
|
3757
|
-
const missingReady = readyIds.filter((taskId) => !declared.has(taskId)).sort();
|
|
3758
|
-
if (missingReady.length > 0) {
|
|
3759
|
-
throw new TodoStoreError(
|
|
3760
|
-
'INDEPENDENCE_READY_UNDECLARED',
|
|
3761
|
-
'ready_tasks_missing_from_witness',
|
|
3762
|
-
undefined,
|
|
3763
|
-
{
|
|
3764
|
-
plan_key: planKey,
|
|
3765
|
-
missing_task_ids: missingReady,
|
|
3766
|
-
// a35: compiling the same set again cannot add them; the template keeps what is declared.
|
|
3767
|
-
next_action: `Declare ${missingReady.join(', ')} in the witness set. ${witnessRoute(planKey)}`
|
|
3768
|
-
+ ' The template keeps the declarations already recorded, so only the new tasks need filling.',
|
|
3769
|
-
},
|
|
3770
|
-
);
|
|
3771
|
-
}
|
|
3485
|
+
// g4: a ready task nobody declared is `witness_missing` for itself only (projectIndependenceFrontier), so it no longer stops the compile.
|
|
3772
3486
|
const observation = await collectTodoIndependenceAuthoritativeObservation({ repoRoot, witnessSet });
|
|
3773
3487
|
const baseSha = observation.head_sha;
|
|
3774
3488
|
const store = storeForReady;
|
|
@@ -3860,6 +3574,33 @@ async function independenceWitnessMigrate({ repoRoot, planKey }) {
|
|
|
3860
3574
|
return result;
|
|
3861
3575
|
}
|
|
3862
3576
|
|
|
3577
|
+
/**
|
|
3578
|
+
* g4: the independence artifact is keyed to the plan version, so a revision (todo add, predecessor, plan revise ...) leaves the
|
|
3579
|
+
* new version without a record and an enforced plan refuses every start. After a revision, move the recorded declarations to the
|
|
3580
|
+
* new version and recompile over them: unchanged tasks keep their verdicts, a new undeclared task is `witness_missing` for itself
|
|
3581
|
+
* only. Best effort: the revision is already recorded, so a failure is one warning with the way out, never an error.
|
|
3582
|
+
*/
|
|
3583
|
+
export async function carryIndependenceAfterRevision({ cwd }) {
|
|
3584
|
+
let planKey = null;
|
|
3585
|
+
try {
|
|
3586
|
+
const repoRoot = resolveRepoRoot(cwd);
|
|
3587
|
+
const store = await readTodoStore({ repoRoot });
|
|
3588
|
+
for (const member of store.members) {
|
|
3589
|
+
planKey = member.plan.plan_key;
|
|
3590
|
+
if (!['witness', 'enforced'].includes(member.coordination?.mode) || !headResolves(repoRoot)) continue;
|
|
3591
|
+
const artifact = await readTodoIndependenceArtifact({ repoRoot, store, planKey });
|
|
3592
|
+
if (artifact !== null && !isTodoIndependenceLegacyMarker(artifact)) continue;
|
|
3593
|
+
if (await readTodoWitnessSet({ repoRoot, planKey }) === null) continue;
|
|
3594
|
+
if (Array.isArray(member.revision?.task_migration)) await independenceWitnessMigrate({ repoRoot, planKey });
|
|
3595
|
+
await independenceCompile({ repoRoot, planKey, inputRef: todoWitnessRef(planKey) });
|
|
3596
|
+
}
|
|
3597
|
+
} catch (error) {
|
|
3598
|
+
process.emitWarning(`independence record not carried to the new plan version${planKey === null ? '' : ` of ${planKey}`}`
|
|
3599
|
+
+ ` (${error?.detail?.reason ?? error?.message ?? error}): declare a task again, or run \`lattice todo independence witness migrate --plan <key>\``
|
|
3600
|
+
+ ' and then compile', { code: 'LATTICE_INDEPENDENCE_NOT_CARRIED' });
|
|
3601
|
+
}
|
|
3602
|
+
}
|
|
3603
|
+
|
|
3863
3604
|
async function independence({ repoRoot, requestedPlanKey }) {
|
|
3864
3605
|
const store = await readTodoStore({ repoRoot });
|
|
3865
3606
|
if (requestedPlanKey !== null
|
|
@@ -4188,7 +3929,7 @@ function declaredStartHint(store, member, state) {
|
|
|
4188
3929
|
|
|
4189
3930
|
/**
|
|
4190
3931
|
* a40: one task's witness row, declared by its member. Rows nobody declared stay out (an empty row
|
|
4191
|
-
* would claim "touches nothing"); compile runs
|
|
3932
|
+
* would claim "touches nothing"); compile runs on the declared rows (g4), `waiting_for` names the ready tasks still undeclared.
|
|
4192
3933
|
*/
|
|
4193
3934
|
async function witnessDeclare({ repoRoot, env, planKey, flags }) {
|
|
4194
3935
|
const store = await readTodoStoreForReadiness({ repoRoot, env });
|
|
@@ -4223,7 +3964,7 @@ async function witnessDeclare({ repoRoot, env, planKey, flags }) {
|
|
|
4223
3964
|
.map(({ task_id: id }) => id).sort();
|
|
4224
3965
|
// declare-without-git: a Store root with no commit cannot be observed, so the row is recorded and not compiled.
|
|
4225
3966
|
const observable = headResolves(repoRoot);
|
|
4226
|
-
const compile =
|
|
3967
|
+
const compile = observable
|
|
4227
3968
|
? await independenceCompile({ repoRoot, planKey, inputRef: scaffolded.witness_ref }) : null;
|
|
4228
3969
|
const result = {
|
|
4229
3970
|
schema: 'lattice.todo_witness_declare_result.v1', project_id: member.plan.project_id, plan_key: planKey,
|
|
@@ -4950,7 +4691,6 @@ function writesTodoStore(argv) {
|
|
|
4950
4691
|
case 'structure': return ['compile', 'realize', 'finalize'].includes(second)
|
|
4951
4692
|
|| (second === 'input' && !argv.includes('--dry-run'));
|
|
4952
4693
|
case 'seam-proposal': return ['compile', 'apply', 'land'].includes(second);
|
|
4953
|
-
case 'evidence': return second === 'promote';
|
|
4954
4694
|
case 'dependency': return ['connect', 'disconnect'].includes(second);
|
|
4955
4695
|
case 'predecessor': return ['add', 'remove'].includes(second);
|
|
4956
4696
|
case 'connect': return second === 'condition' && ['add', 'remove', 'resolve'].includes(argv[2]);
|
|
@@ -4962,6 +4702,13 @@ function writesTodoStore(argv) {
|
|
|
4962
4702
|
}
|
|
4963
4703
|
}
|
|
4964
4704
|
|
|
4705
|
+
/** g4: the todo commands that write a new plan version (the plan revise command carries on its own in bin/lattice.mjs). */
|
|
4706
|
+
function revisesPlan(argv) {
|
|
4707
|
+
return ['add', 'revise', 'revise-phase', 'revise-set', 'split', 'dependency', 'predecessor'].includes(argv[0])
|
|
4708
|
+
&& !(argv[0] === 'dependency' && !['connect', 'disconnect'].includes(argv[1]))
|
|
4709
|
+
&& !(argv[0] === 'predecessor' && !['add', 'remove'].includes(argv[1]));
|
|
4710
|
+
}
|
|
4711
|
+
|
|
4965
4712
|
/** notice-impl: the writes that can make a task startable carry `notices` ([startable notices](dfd-done-notice.md)). */
|
|
4966
4713
|
function releasesTasks(argv) {
|
|
4967
4714
|
const [command, second] = argv;
|
|
@@ -5212,78 +4959,6 @@ async function ensureActiveProjectDashboard({ repoRoot, env, stderr, strict = fa
|
|
|
5212
4959
|
}
|
|
5213
4960
|
}
|
|
5214
4961
|
|
|
5215
|
-
/** evidence-ref: an uncommitted item says whether gc is kept off it, and how to protect it if not. */
|
|
5216
|
-
function uncommittedEvidenceItem(repoRoot, store, evidence) {
|
|
5217
|
-
const anchored = evidenceAnchored(evidenceRepoRoot(repoRoot, store, evidence), evidence.git_blob_oid);
|
|
5218
|
-
return { repo_id: evidence.repo_id, path: evidence.path, anchored,
|
|
5219
|
-
next_action: anchored
|
|
5220
|
-
? `Commit ${evidence.path} (repository ${evidence.repo_id}), then rerun \`lattice todo verify --json\`.`
|
|
5221
|
-
: 'Anchor it so gc keeps it: `lattice todo evidence anchor --json`; commit it to make it committed.' };
|
|
5222
|
-
}
|
|
5223
|
-
|
|
5224
|
-
function evidenceRepoRoot(repoRoot, store, evidence) {
|
|
5225
|
-
const ref = store.manifest.repositories.find(({ repo_id: id }) => id === evidence.repo_id)?.path ?? '.';
|
|
5226
|
-
return path.resolve(repoRoot, ref);
|
|
5227
|
-
}
|
|
5228
|
-
|
|
5229
|
-
/** The evidence descriptors a Store records: task evidence, phase decision evidence and accepted slot evidence. */
|
|
5230
|
-
function recordedEvidence(store) {
|
|
5231
|
-
const entries = [];
|
|
5232
|
-
for (const member of store.members) {
|
|
5233
|
-
const planKey = member.plan.plan_key;
|
|
5234
|
-
for (const task of member.tasks) {
|
|
5235
|
-
if (validateEvidenceDescriptor(task.evidence)) entries.push({ plan_key: planKey, task_id: task.task_id, evidence: task.evidence });
|
|
5236
|
-
}
|
|
5237
|
-
for (const event of member.journal.events) {
|
|
5238
|
-
if (!['phase_accept', 'phase_reject'].includes(event.kind)) continue;
|
|
5239
|
-
for (const evidence of [event.payload.decision_evidence, ...(event.payload.evidence_slots ?? []).map((slot) => slot.evidence)]) {
|
|
5240
|
-
if (validateEvidenceDescriptor(evidence)) entries.push({ plan_key: planKey, phase_id: event.phase_id, evidence });
|
|
5241
|
-
}
|
|
5242
|
-
}
|
|
5243
|
-
}
|
|
5244
|
-
return entries;
|
|
5245
|
-
}
|
|
5246
|
-
|
|
5247
|
-
/**
|
|
5248
|
-
* `todo evidence anchor` (evidence-ref): anchor evidence recorded before writes anchored it. Idempotent; run once per
|
|
5249
|
-
* existing chart. Evidence gc already pruned cannot come back and is listed as `missing`.
|
|
5250
|
-
*/
|
|
5251
|
-
async function evidenceAnchor({ repoRoot }) {
|
|
5252
|
-
// No Store yet: nothing recorded, so nothing to anchor. Answer like `todo status` does, not as a broken store.
|
|
5253
|
-
if (await isUninitializedTodoStore({ repoRoot })) {
|
|
5254
|
-
const result = { schema: 'lattice.todo_evidence_anchor_uninitialized.v1', anchored: [], already: 0, missing: [],
|
|
5255
|
-
next_actions: ['lattice plan create --template --json', 'lattice plan create --input <file>'], result_digest: '' };
|
|
5256
|
-
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
5257
|
-
return result;
|
|
5258
|
-
}
|
|
5259
|
-
const store = await readTodoStore({ repoRoot });
|
|
5260
|
-
const anchored = [];
|
|
5261
|
-
const missing = [];
|
|
5262
|
-
const seen = new Set();
|
|
5263
|
-
let already = 0;
|
|
5264
|
-
for (const { evidence, ...owner } of recordedEvidence(store)) {
|
|
5265
|
-
const repo = evidenceRepoRoot(repoRoot, store, evidence);
|
|
5266
|
-
const key = `${repo}\0${evidence.git_blob_oid}`;
|
|
5267
|
-
if (seen.has(key)) continue;
|
|
5268
|
-
seen.add(key);
|
|
5269
|
-
const item = { ...owner, git_blob_oid: evidence.git_blob_oid };
|
|
5270
|
-
if (isTodoEvidenceUncommitted({ repoRoot, store, evidence })) {
|
|
5271
|
-
if (evidenceAnchored(repo, evidence.git_blob_oid)) already += 1;
|
|
5272
|
-
else { anchorEvidenceBlob(repo, evidence.git_blob_oid); anchored.push(item); }
|
|
5273
|
-
continue;
|
|
5274
|
-
}
|
|
5275
|
-
try {
|
|
5276
|
-
gitSync(['cat-file', '-e', evidence.git_blob_oid], { cwd: repo, stdio: 'ignore' });
|
|
5277
|
-
} catch {
|
|
5278
|
-
missing.push(item);
|
|
5279
|
-
}
|
|
5280
|
-
}
|
|
5281
|
-
const result = { schema: 'lattice.todo_evidence_anchor_result.v1', project_id: store.project_id,
|
|
5282
|
-
anchored, already, missing, result_digest: '' };
|
|
5283
|
-
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
5284
|
-
return result;
|
|
5285
|
-
}
|
|
5286
|
-
|
|
5287
4962
|
async function verify({ repoRoot, requestedPlanKey }) {
|
|
5288
4963
|
// k4: the full history checks (hash chain, canonical bytes, whole-snapshot comparison) run only here, on request.
|
|
5289
4964
|
const store = await readTodoStore({ repoRoot, verifyHistory: true });
|
|
@@ -5293,26 +4968,8 @@ async function verify({ repoRoot, requestedPlanKey }) {
|
|
|
5293
4968
|
await readTodoNoteEvents({ repoRoot, planKey: member.plan.plan_key });
|
|
5294
4969
|
}
|
|
5295
4970
|
const verifiedSourceInventories = new Map();
|
|
5296
|
-
const uncommittedEvidence = [];
|
|
5297
4971
|
for (const member of members) {
|
|
5298
4972
|
const planKey = member.descriptor.plan_key;
|
|
5299
|
-
// a12: evidence waiting for a commit is an item; missing or changed evidence still refuses.
|
|
5300
|
-
const unverifiedTasks = findUnverifiedTodoEvidence({ repoRoot, store, member });
|
|
5301
|
-
const pending = unverifiedTasks.filter((task) => isTodoEvidenceUncommitted({ repoRoot, store, evidence: task.evidence }));
|
|
5302
|
-
for (const { task_id: taskId, evidence } of pending) {
|
|
5303
|
-
uncommittedEvidence.push({ plan_key: planKey, task_id: taskId, ...uncommittedEvidenceItem(repoRoot, store, evidence) });
|
|
5304
|
-
}
|
|
5305
|
-
for (const { phase_id: phaseId, decision_evidence: evidence } of member.phases) {
|
|
5306
|
-
if (decisionEvidenceState(repoRoot, store, evidence) !== 'uncommitted') continue;
|
|
5307
|
-
uncommittedEvidence.push({ plan_key: planKey, phase_id: phaseId, ...uncommittedEvidenceItem(repoRoot, store, evidence) });
|
|
5308
|
-
}
|
|
5309
|
-
const unverified = unverifiedTasks.find((task) => !pending.includes(task));
|
|
5310
|
-
if (unverified !== undefined) {
|
|
5311
|
-
throw new TodoStoreError('STORE_INCONSISTENT', 'evidence_unverified', 'evidence_unverified', {
|
|
5312
|
-
plan_key: member.descriptor.plan_key,
|
|
5313
|
-
task_id: unverified.task_id,
|
|
5314
|
-
});
|
|
5315
|
-
}
|
|
5316
4973
|
if (member.revision !== null) {
|
|
5317
4974
|
switch (member.revision.schema) {
|
|
5318
4975
|
case 'lattice.todo_revision.v1':
|
|
@@ -5391,7 +5048,8 @@ async function verify({ repoRoot, requestedPlanKey }) {
|
|
|
5391
5048
|
requested_plan_key: requestedPlanKey,
|
|
5392
5049
|
verified_members: verifiedMembers,
|
|
5393
5050
|
snapshot_stale: verifiedMembers.some((member) => member.snapshot_stale),
|
|
5394
|
-
|
|
5051
|
+
// shortcut: constant [] so v4 readers keep working; drop the key with the next verify schema bump.
|
|
5052
|
+
uncommitted_evidence: [],
|
|
5395
5053
|
result_digest: '',
|
|
5396
5054
|
};
|
|
5397
5055
|
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
@@ -5399,15 +5057,12 @@ async function verify({ repoRoot, requestedPlanKey }) {
|
|
|
5399
5057
|
}
|
|
5400
5058
|
|
|
5401
5059
|
// `todo verify`の人間向け1行。--jsonと同じresultから導く(verifyは不整合を例外で拒否するので、
|
|
5402
|
-
// ここへ届くのは検証が通った結果だけ。注意が要るのはsnapshot
|
|
5060
|
+
// ここへ届くのは検証が通った結果だけ。注意が要るのはsnapshot古さだけ)。
|
|
5403
5061
|
function verifyVerdictLine(result) {
|
|
5404
5062
|
const members = result.verified_members.map((member) => `${member.plan_key} ${member.reconciliation_state}${
|
|
5405
5063
|
member.reconciliation_state === 'reconciled' ? '' : ', nothing to do'}`);
|
|
5406
5064
|
const notes = [];
|
|
5407
5065
|
if (result.snapshot_stale) notes.push('snapshot stale');
|
|
5408
|
-
if (result.uncommitted_evidence.length > 0) {
|
|
5409
|
-
notes.push(`${result.uncommitted_evidence.length} uncommitted evidence (commit it, then rerun)`);
|
|
5410
|
-
}
|
|
5411
5066
|
const count = result.verified_members.length;
|
|
5412
5067
|
return `todo verify: ${notes.length === 0 ? 'ok' : 'attention'}, ${count} plan${count === 1 ? '' : 's'} verified`
|
|
5413
5068
|
+ `${notes.map((note) => `, ${note}`).join('')} (${members.join('; ')})`;
|
|
@@ -5822,30 +5477,19 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
5822
5477
|
kind: 'phase_review', payload: { reason: flags.reason } });
|
|
5823
5478
|
} else if (argv[0] === 'phase' && ['accept', 'reject'].includes(argv[1])) {
|
|
5824
5479
|
const outcome = argv[1];
|
|
5825
|
-
const flags = matchFlagCommand(argv, ['phase', outcome], {
|
|
5826
|
-
known: ['plan', 'phase', 'input', 'evidence', 'message', 'reason'], required: ['plan', 'phase'],
|
|
5827
|
-
});
|
|
5480
|
+
const flags = matchFlagCommand(argv, ['phase', outcome], TODO_FLAG_SPECS[`phase ${outcome}`]);
|
|
5828
5481
|
const reasonFits = outcome === 'accept' ? flags?.reason === undefined
|
|
5829
5482
|
: typeof flags?.reason === 'string' && flags.reason.length > 0;
|
|
5830
|
-
const
|
|
5831
|
-
|
|
5832
|
-
&& flags.
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
repoRoot, env, planKey: flags.plan, phaseId: flags.phase,
|
|
5841
|
-
outcome, evidenceRef: flags.evidence, reason: flags.reason ?? null,
|
|
5842
|
-
});
|
|
5843
|
-
} else if (base && flags.input === undefined && flags.evidence === undefined
|
|
5844
|
-
&& typeof flags.message === 'string' && flags.message.length > 0 && reasonFits) {
|
|
5845
|
-
action = (repoRoot) => phaseDecisionFromEvidence({
|
|
5846
|
-
repoRoot, env, planKey: flags.plan, phaseId: flags.phase,
|
|
5847
|
-
outcome, evidenceMessage: flags.message, reason: flags.reason ?? null,
|
|
5848
|
-
});
|
|
5483
|
+
const textFits = flags !== null && (flags.message === undefined || flags.evidence === undefined)
|
|
5484
|
+
&& (flags.message === undefined || (typeof flags.message === 'string' && flags.message.length > 0))
|
|
5485
|
+
&& (flags.evidence === undefined || isAuthoringPathToken(flags.evidence));
|
|
5486
|
+
if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.phase) && reasonFits && textFits) {
|
|
5487
|
+
action = async (repoRoot) => {
|
|
5488
|
+
const message = flags.evidence === undefined ? flags.message ?? null : await readEvidenceText(repoRoot, flags.evidence);
|
|
5489
|
+
const result = await phaseDecision({ repoRoot, env, planKey: flags.plan, phaseId: flags.phase,
|
|
5490
|
+
outcome, message, reason: flags.reason ?? null });
|
|
5491
|
+
return flags.evidence === undefined ? result : retiredEvidenceFlag(stderr, `todo phase ${outcome}`, result);
|
|
5492
|
+
};
|
|
5849
5493
|
}
|
|
5850
5494
|
} else if (argv[0] === 'phase' && argv[1] === 'reopen' && phaseReopenFlags(argv) !== null) {
|
|
5851
5495
|
const flags = phaseReopenFlags(argv);
|
|
@@ -5880,19 +5524,19 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
5880
5524
|
}
|
|
5881
5525
|
} else if (argv[0] === 'done') {
|
|
5882
5526
|
const flags = matchFlagCommand(argv, ['done'], DONE_FLAG_SPEC);
|
|
5883
|
-
// u03 A58: both, one or neither of --evidence/--message is accepted.
|
|
5884
5527
|
if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)
|
|
5528
|
+
&& (flags.message === undefined || flags.evidence === undefined)
|
|
5885
5529
|
&& (flags.evidence === undefined || isAuthoringPathToken(flags.evidence))
|
|
5886
5530
|
&& (flags['test-result'] === undefined || isAuthoringPathToken(flags['test-result']))) {
|
|
5887
5531
|
action = (repoRoot) => mutateUnlessUnchanged({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
|
|
5888
5532
|
kind: 'done', dropped: (recorded) => doneDropped({ repoRoot, flags, recorded }),
|
|
5889
5533
|
action: async () => {
|
|
5890
|
-
await
|
|
5891
|
-
return mutate({
|
|
5534
|
+
const result = await mutate({
|
|
5892
5535
|
repoRoot, env, planKey: flags.plan, taskId: flags.task, kind: 'done', payload: 'authored',
|
|
5893
|
-
|
|
5536
|
+
message: await doneMessage({ repoRoot, flags }),
|
|
5894
5537
|
testResultRef: flags['test-result'] ?? null,
|
|
5895
5538
|
});
|
|
5539
|
+
return flags.evidence === undefined ? result : retiredEvidenceFlag(stderr, 'todo done', result);
|
|
5896
5540
|
} });
|
|
5897
5541
|
}
|
|
5898
5542
|
}
|
|
@@ -5909,7 +5553,7 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
5909
5553
|
action = (repoRoot) => mutateUnlessUnchanged({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
|
|
5910
5554
|
kind: 'block', dropped: reasonDropped(flags.reason), action: async () => withBlockGuidance(await mutate({
|
|
5911
5555
|
repoRoot, env, planKey: flags.plan, taskId: flags.task,
|
|
5912
|
-
kind: 'block', payload: { reason: flags.reason },
|
|
5556
|
+
kind: 'block', payload: { reason: flags.reason },
|
|
5913
5557
|
})) });
|
|
5914
5558
|
}
|
|
5915
5559
|
} else if (argv[0] === 'add') {
|
|
@@ -5931,21 +5575,9 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
5931
5575
|
action = (repoRoot) => mutateUnlessUnchanged({ repoRoot, env, planKey: flags.plan, taskId: flags.task,
|
|
5932
5576
|
kind: 'unblock', action: () => mutate({
|
|
5933
5577
|
repoRoot, env, planKey: flags.plan, taskId: flags.task,
|
|
5934
|
-
kind: 'unblock', payload: {},
|
|
5578
|
+
kind: 'unblock', payload: {},
|
|
5935
5579
|
}) });
|
|
5936
5580
|
}
|
|
5937
|
-
} else if (argv[0] === 'evidence' && argv[1] === 'anchor'
|
|
5938
|
-
&& matchFlagCommand(argv, ['evidence', 'anchor'], TODO_FLAG_SPECS['evidence anchor']) !== null) {
|
|
5939
|
-
action = (repoRoot) => evidenceAnchor({ repoRoot });
|
|
5940
|
-
} else if (argv[0] === 'evidence' && argv[1] === 'promote') {
|
|
5941
|
-
const flags = matchFlagCommand(argv, ['evidence', 'promote'], TODO_FLAG_SPECS['evidence promote']);
|
|
5942
|
-
if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)
|
|
5943
|
-
&& isAuthoringPathToken(flags.evidence)) {
|
|
5944
|
-
action = (repoRoot) => mutate({
|
|
5945
|
-
repoRoot, env, planKey: flags.plan, taskId: flags.task,
|
|
5946
|
-
kind: 'done', payload: 'evidence_promotion', evidenceRef: flags.evidence,
|
|
5947
|
-
});
|
|
5948
|
-
}
|
|
5949
5581
|
} else if (argv[0] === 'reopen') {
|
|
5950
5582
|
const flags = matchFlagCommand(argv, ['reopen'], TODO_FLAG_SPECS.reopen);
|
|
5951
5583
|
if (flags !== null && isTodoIdentifier(flags.plan) && isTodoIdentifier(flags.task)
|
|
@@ -6003,11 +5635,12 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
6003
5635
|
: await action(repoRoot);
|
|
6004
5636
|
const result = releasesTasks(argv) ? await withNotices(repoRoot, written, before, env) : written;
|
|
6005
5637
|
if (result !== null) stdout.write(`${plainVerify ? verifyVerdictLine(result) : JSON.stringify(result)}\n`);
|
|
5638
|
+
if (!atomicCommit && revisesPlan(argv)) await carryIndependenceAfterRevision({ cwd });
|
|
6006
5639
|
return 0;
|
|
6007
5640
|
} catch (error) {
|
|
6008
5641
|
if (error instanceof TodoStoreError || (typeof error?.code === 'string'
|
|
6009
5642
|
&& error.detail !== null && typeof error.detail === 'object')) {
|
|
6010
|
-
return typedFailure(stderr, error,
|
|
5643
|
+
return typedFailure(stderr, error, guidanceContext(argv, env));
|
|
6011
5644
|
}
|
|
6012
5645
|
// 漏れた`fetch failed`もTypeErrorで届く。呼び出し側の契約違反と答えず、内部故障として観測口へ渡す。
|
|
6013
5646
|
if (error instanceof TypeError && cliFailureClass(error) !== 'transport') {
|