@quolu/lattice 0.117.0 → 0.118.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/package.json +1 -1
- package/src/plan-backchain.mjs +10 -3
- package/src/plan-draft.mjs +8 -4
- package/src/plan-edit-advice.mjs +144 -0
- package/src/plan-revise.mjs +4 -0
- package/src/todo-cli.mjs +34 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quolu/lattice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.118.0",
|
|
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/plan-backchain.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
readTodoStore, TodoStoreError,
|
|
12
12
|
} from './todo-store.mjs';
|
|
13
13
|
import { gitSync } from './git-process.mjs';
|
|
14
|
+
import { findingHandoff, planEditAdvice } from './plan-edit-advice.mjs';
|
|
14
15
|
import { completeCreateInput, readAuthoringJsonFile } from './todo-authoring-input.mjs';
|
|
15
16
|
import {
|
|
16
17
|
explainPhaseTodoRevision, phaseTodoRevisionPlanVersion, validatePhaseTodoRevision,
|
|
@@ -635,7 +636,8 @@ export async function rebindCarriedWork({ repoRoot, planKey, env,
|
|
|
635
636
|
return rebound;
|
|
636
637
|
}
|
|
637
638
|
|
|
638
|
-
const draftOutput = (report) => (report === null ? {} : { draft: report.summary, draft_findings: report.findings
|
|
639
|
+
const draftOutput = async (report, repoRoot) => (report === null ? {} : { draft: report.summary, draft_findings: report.findings,
|
|
640
|
+
finding_handoff: await findingHandoff({ repoRoot, planKey: report.summary.plan_key, findings: report.findings }) });
|
|
639
641
|
|
|
640
642
|
export async function runPlanBackchain({ cwd, inputRef = null, draftRef = null, stdout, dryRun = false, env = process.env }) {
|
|
641
643
|
const repoRoot = gitRoot(cwd);
|
|
@@ -698,6 +700,9 @@ export async function runPlanBackchain({ cwd, inputRef = null, draftRef = null,
|
|
|
698
700
|
try { buildTodoPlan({ ...planSeed(amended, null), plan_version: chain.plan_version }); }
|
|
699
701
|
catch { fail('authoring_plan_invalid', '/authoring_ref'); }
|
|
700
702
|
}
|
|
703
|
+
// A finished chain revised through --input gets the same cut-off advisory; a draft already carries draft_findings + handoff.
|
|
704
|
+
const editAdvice = draftReport === null && revision !== null
|
|
705
|
+
? Object.fromEntries([['advice', await planEditAdvice({ repoRoot, before: member.plan, after: revision.desired_plan, states: member.tasks })]].filter(([, v]) => v !== null)) : {};
|
|
701
706
|
const unknownFeatureIds = chain.features.filter(({ provider: source }) => source.kind === 'unknown')
|
|
702
707
|
.map(({ feature_id: id }) => id).sort();
|
|
703
708
|
if (dryRun) {
|
|
@@ -711,7 +716,8 @@ export async function runPlanBackchain({ cwd, inputRef = null, draftRef = null,
|
|
|
711
716
|
: store === null ? 'create' : 'add',
|
|
712
717
|
task_migration: revision?.task_migration ?? null,
|
|
713
718
|
feature_chain_findings: featureChainFindings,
|
|
714
|
-
...draftOutput(draftReport),
|
|
719
|
+
...await draftOutput(draftReport, repoRoot),
|
|
720
|
+
...editAdvice,
|
|
715
721
|
result_digest: '',
|
|
716
722
|
};
|
|
717
723
|
checked.result_digest = todoSelfDigest(checked, 'result_digest');
|
|
@@ -769,7 +775,8 @@ export async function runPlanBackchain({ cwd, inputRef = null, draftRef = null,
|
|
|
769
775
|
chain_digest: effectiveChain.chain_digest, authoring_result: created,
|
|
770
776
|
rebound_task_ids: reboundTaskIds,
|
|
771
777
|
feature_chain_findings: featureChainFindings,
|
|
772
|
-
...draftOutput(draftReport),
|
|
778
|
+
...await draftOutput(draftReport, repoRoot),
|
|
779
|
+
...editAdvice,
|
|
773
780
|
operation: unchanged ? 'unchanged' : revision !== null ? 'revise'
|
|
774
781
|
: store === null ? 'create' : 'add',
|
|
775
782
|
journal_head_digest: finalMember.journal.events.at(-1).event_digest,
|
package/src/plan-draft.mjs
CHANGED
|
@@ -343,7 +343,7 @@ export async function compilePlanDraft({ repoRoot, draft, draftRef, member, stor
|
|
|
343
343
|
const pairs = (keys) => keys.map((key) => { const [from, to] = key.split('->'); return { from: from.split('/')[1], to: to.split('/')[1] }; });
|
|
344
344
|
return { chain, authoring, report: {
|
|
345
345
|
summary: {
|
|
346
|
-
mode: plan === null ? (store === null ? 'create' : 'add') : 'revise',
|
|
346
|
+
mode: plan === null ? (store === null ? 'create' : 'add') : 'revise', plan_key: planKey,
|
|
347
347
|
added_task_ids: [...tasks.keys()].filter((id) => !baseIds.has(id)),
|
|
348
348
|
retired_task_ids: [...retired].sort(),
|
|
349
349
|
edge_changes: {
|
|
@@ -392,10 +392,14 @@ async function draftFindings({ repoRoot, draft, chain, member, baseIds, scope, e
|
|
|
392
392
|
const byCapability = new Map();
|
|
393
393
|
for (const feature of chain.features.filter(inScope)) {
|
|
394
394
|
const key = `${feature.capability.trim()}\u0000${feature.acceptance.trim()}`; // same capability with another acceptance/scope is a different result
|
|
395
|
-
byCapability.set(key, [...(byCapability.get(key) ?? []), feature
|
|
395
|
+
byCapability.set(key, [...(byCapability.get(key) ?? []), feature]);
|
|
396
396
|
}
|
|
397
|
-
for (const [capability,
|
|
398
|
-
if (
|
|
397
|
+
for (const [capability, group] of byCapability) {
|
|
398
|
+
if (group.length > 1) {
|
|
399
|
+
found.push({ reason: 'duplicate_result', pointer: '/features', capability: capability.split('\u0000')[0],
|
|
400
|
+
feature_ids: group.map((f) => f.feature_id).sort(),
|
|
401
|
+
task_ids: group.filter((f) => f.provider.kind === 'task').map((f) => f.provider.task_id).sort() });
|
|
402
|
+
}
|
|
399
403
|
}
|
|
400
404
|
const canonicalRoot = await realpath(repoRoot);
|
|
401
405
|
for (const [index, entry] of (draft.observations ?? []).entries()) {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { readTodoChartMeta } from './todo-store.mjs';
|
|
2
|
+
|
|
3
|
+
// Advisory only (never a gate, never a message sent): what an edit cut off from its goals, and who to tell.
|
|
4
|
+
// Contract: docs/architecture/dfd-finding-handoff.md.
|
|
5
|
+
export const ADVICE_SCHEMA = 'lattice.plan_edit_advice.v1';
|
|
6
|
+
export const HANDOFF_SCHEMA = 'lattice.finding_handoff.v1';
|
|
7
|
+
// Missing or unreadable evidence alone is never a retirement candidate, so it is not handed off.
|
|
8
|
+
const HANDOFF_REASONS = new Set(['unused_output', 'duplicate_result', 'planned_provider_has_observation', 'completed_result_matches_planned']);
|
|
9
|
+
|
|
10
|
+
/** Prerequisite lists inside one plan: hard edges, joins (before waits for each after) and phase accepts. */
|
|
11
|
+
function prerequisites(plan) {
|
|
12
|
+
const into = new Map(plan.tasks.map(({ task_id: id }) => [id, new Set()]));
|
|
13
|
+
const wait = (to, from) => { if (into.has(to) && into.has(from)) into.get(to).add(from); };
|
|
14
|
+
const mine = (ref) => ref?.plan_key === plan.plan_key;
|
|
15
|
+
for (const { from, to } of plan.hard_dependencies ?? []) if (mine(from) && mine(to)) wait(to.task_id, from.task_id);
|
|
16
|
+
for (const { before, after } of plan.joins ?? []) {
|
|
17
|
+
if (mine(before)) for (const ref of after) if (mine(ref)) wait(before.task_id, ref.task_id);
|
|
18
|
+
}
|
|
19
|
+
for (const { from, to } of plan.phase_accept_dependencies ?? []) if (mine(from) && mine(to)) wait(to.task_id, from.task_id);
|
|
20
|
+
return into;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function served(into, goals) {
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
const stack = goals.filter((id) => into.has(id));
|
|
26
|
+
while (stack.length > 0) {
|
|
27
|
+
const id = stack.pop();
|
|
28
|
+
if (seen.has(id)) continue;
|
|
29
|
+
seen.add(id);
|
|
30
|
+
stack.push(...into.get(id));
|
|
31
|
+
}
|
|
32
|
+
return seen;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Tasks of `before` that served one of its goals (a goal = a task nothing waits for) and no longer serve a goal in `after`.
|
|
37
|
+
* Only the span the edit cut off is returned; new tasks and unrelated purposes are not judged.
|
|
38
|
+
*/
|
|
39
|
+
export function cutOffByEdit(before, after) {
|
|
40
|
+
const was = prerequisites(before);
|
|
41
|
+
const waited = new Set([...was.values()].flatMap((set) => [...set]));
|
|
42
|
+
const goals = [...was.keys()].filter((id) => !waited.has(id));
|
|
43
|
+
const now = served(prerequisites(after), goals);
|
|
44
|
+
const earlier = served(was, goals);
|
|
45
|
+
return after.tasks.map(({ task_id: id }) => id).filter((id) => earlier.has(id) && !now.has(id));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The advisory returned with an ordinary plan edit; null when nothing was cut off. */
|
|
49
|
+
export async function planEditAdvice({ repoRoot, before, after, states = [] }) {
|
|
50
|
+
const state = new Map(states.map((task) => [task.task_id, task.status]));
|
|
51
|
+
const findings = cutOffByEdit(before, after).filter((id) => state.get(id) !== 'retired').map((id) => ({
|
|
52
|
+
reason: 'unused_output', pointer: `/tasks/${id}`, task_id: id, task_state: state.get(id) ?? null,
|
|
53
|
+
candidate: 'retirement', cause: 'cut_off_by_edit' }));
|
|
54
|
+
if (findings.length === 0) return null;
|
|
55
|
+
return { schema: ADVICE_SCHEMA, advisory: true, plan_key: after.plan_key, findings,
|
|
56
|
+
handoff: await findingHandoff({ repoRoot, planKey: after.plan_key, findings }) };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const WHY = {
|
|
60
|
+
unused_output: (f) => f.cause === 'cut_off_by_edit'
|
|
61
|
+
? 'this edit left nothing waiting for its result, so no goal of the plan needs it any more'
|
|
62
|
+
: 'no goal result of the plan reaches its result',
|
|
63
|
+
planned_provider_has_observation: (f) => `its result was matched to the observation ${f.evidence_ref}`,
|
|
64
|
+
completed_result_matches_planned: (f) => `${f.completed_task} already completed a result with the identical capability and acceptance and recorded completion evidence (an evidence file or message alone does not prove equivalence)`,
|
|
65
|
+
};
|
|
66
|
+
const PROPOSE = (planKey) => ({
|
|
67
|
+
unused_output: (f) => `if it has no other purpose, retire it (lattice todo retire --plan ${planKey} --task ${f.task_id} --reason <text>); otherwise link a task that needs its result`,
|
|
68
|
+
duplicate_result: () => 'keep one provider of the result and retire or re-link the other',
|
|
69
|
+
completed_result_matches_planned: (f) => `compare the completion evidence of ${f.completed_task} with this task's scope (version, environment, behavior); if it already covers the result, retire this task`,
|
|
70
|
+
planned_provider_has_observation: () => 'compare that observation with the planned result (version, environment, behavior); if it already covers the result, retire the planned task',
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Who to tell and what to say. Recipient = the chart representative = K4 `readTodoChartMeta({repoRoot}).created_by`
|
|
75
|
+
* (K1 `charts list --json` `charts[].created_by`); unreadable or unrecorded stays an advisory with a manual lookup.
|
|
76
|
+
* Returns null when no finding is a candidate. Nothing is sent and nothing waits for an answer.
|
|
77
|
+
*/
|
|
78
|
+
export async function findingHandoff({ repoRoot, planKey, findings }) {
|
|
79
|
+
const eligible = findings.filter(({ reason }) => HANDOFF_REASONS.has(reason));
|
|
80
|
+
const items = eligible.flatMap((finding) => {
|
|
81
|
+
if (finding.reason === 'duplicate_result') {
|
|
82
|
+
// One item per provider task; results provided by an observation or an open question have no task to change.
|
|
83
|
+
const others = (tid) => finding.task_ids.filter((id) => id !== tid);
|
|
84
|
+
return (finding.task_ids ?? []).map((tid) => ({ task_id: tid, finding: finding.reason,
|
|
85
|
+
why: `${tid} provides the result "${finding.capability}" (${finding.feature_ids.join(', ')}), declared with the identical capability and acceptance${others(tid).length > 0 ? ` as ${others(tid).join(', ')}` : ' by another result'}`,
|
|
86
|
+
proposed_change: PROPOSE(planKey).duplicate_result() }));
|
|
87
|
+
}
|
|
88
|
+
return [{ task_id: finding.task_id ?? null, finding: finding.reason,
|
|
89
|
+
why: WHY[finding.reason](finding), proposed_change: PROPOSE(planKey)[finding.reason](finding),
|
|
90
|
+
...(finding.task_state === undefined ? {} : { task_state: finding.task_state }) }];
|
|
91
|
+
});
|
|
92
|
+
if (items.length === 0) return null;
|
|
93
|
+
const meta = await readTodoChartMeta({ repoRoot }).catch(() => null);
|
|
94
|
+
const createdBy = typeof meta?.created_by === 'string' && meta.created_by !== '' ? meta.created_by : null;
|
|
95
|
+
return {
|
|
96
|
+
schema: HANDOFF_SCHEMA, request: 'advisory', delivery: 'none',
|
|
97
|
+
recipient: {
|
|
98
|
+
role: 'chart_representative', created_by: createdBy,
|
|
99
|
+
source: 'readTodoChartMeta({repoRoot}).created_by; lattice charts list --json charts[].created_by',
|
|
100
|
+
lookup: createdBy === null
|
|
101
|
+
? 'created_by is not recorded here: read charts[].created_by of this chart in `lattice charts list --json`, or ask who created the chart' : null,
|
|
102
|
+
},
|
|
103
|
+
items,
|
|
104
|
+
ask: `Advisory, not a gate: tell ${createdBy ?? 'the chart representative'} the affected task, why it was flagged and the proposed change: `
|
|
105
|
+
+ items.map((item) => `${item.task_id ?? '(result)'}: ${item.why}; ${item.proposed_change}`).join(' | '),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* `todo done`: the tasks the completion makes unnecessary, from the completed task and the evidence recorded with it.
|
|
111
|
+
* With recorded evidence and a feature chain, a live task that
|
|
112
|
+
* provides a feature with the identical capability and acceptance as one the completed task provides. Scope differences keep
|
|
113
|
+
* results distinct; missing evidence never creates a candidate. Null when nothing is affected. The completion itself is untouched.
|
|
114
|
+
* `plan` and `states` are the committed completion version (what the Store returned from the write), so no chart read is added
|
|
115
|
+
* and a concurrent edit cannot make the advisory describe another version.
|
|
116
|
+
*/
|
|
117
|
+
export async function completionAdvice({ repoRoot, plan, states, taskId, planVersion, evidence }) {
|
|
118
|
+
const state = new Map(states.map((task) => [task.task_id, task.status]));
|
|
119
|
+
const live = (id) => id !== taskId && !['done', 'retired'].includes(state.get(id));
|
|
120
|
+
const findings = [];
|
|
121
|
+
const binding = evidence === null ? null
|
|
122
|
+
: await (await import('./plan-backchain.mjs')).readPlanBackchainBinding({ repoRoot, plan }).catch(() => null);
|
|
123
|
+
if (binding !== null) {
|
|
124
|
+
const features = new Map(binding.chain.features.map((f) => [f.feature_id, f]));
|
|
125
|
+
const doneTask = binding.chain.tasks.find((t) => t.task_id === taskId);
|
|
126
|
+
for (const id of doneTask?.provides_feature_ids ?? []) {
|
|
127
|
+
const done = features.get(id);
|
|
128
|
+
for (const other of binding.chain.tasks) {
|
|
129
|
+
if (!live(other.task_id)) continue;
|
|
130
|
+
for (const fid of other.provides_feature_ids) {
|
|
131
|
+
const twin = features.get(fid);
|
|
132
|
+
if (twin?.capability.trim() === done.capability.trim() && twin.acceptance.trim() === done.acceptance.trim()) {
|
|
133
|
+
findings.push({ reason: 'completed_result_matches_planned', pointer: `/tasks/${other.task_id}`, task_id: other.task_id,
|
|
134
|
+
task_state: state.get(other.task_id) ?? null, candidate: 'retirement', completed_task: taskId,
|
|
135
|
+
feature_id: fid, completed_feature_id: id, evidence });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (findings.length === 0) return null;
|
|
142
|
+
return { schema: ADVICE_SCHEMA, advisory: true, trigger: 'done', plan_key: plan.plan_key, plan_version: planVersion, completed_task: taskId, findings,
|
|
143
|
+
handoff: await findingHandoff({ repoRoot, planKey: plan.plan_key, findings }) };
|
|
144
|
+
}
|
package/src/plan-revise.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { planEditAdvice } from './plan-edit-advice.mjs';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
|
|
4
5
|
import { canonicalizeTodoArtifact, exactRecord, isTodoIdentifier, todoSelfDigest } from './todo-contracts.mjs';
|
|
@@ -413,6 +414,8 @@ export async function applyPlanRevision({
|
|
|
413
414
|
}
|
|
414
415
|
const declarations = dryRun || touches.length === 0 ? null
|
|
415
416
|
: await (await import('./todo-cli.mjs')).declareTouches({ repoRoot, planKey: revision.plan_key, touches });
|
|
417
|
+
const advice = unchanged ? null : await planEditAdvice({ repoRoot, before: member.plan,
|
|
418
|
+
after: revision.desired_plan, states: member.tasks });
|
|
416
419
|
const result = {
|
|
417
420
|
schema: unchanged ? 'lattice.plan_revise_unchanged.v1' : 'lattice.plan_revise_result.v1',
|
|
418
421
|
project_id: revision.project_id, plan_key: revision.plan_key,
|
|
@@ -420,6 +423,7 @@ export async function applyPlanRevision({
|
|
|
420
423
|
dry_run: dryRun, revision: unchanged ? null : revision, applied,
|
|
421
424
|
continuity, rebound_task_ids: reboundTaskIds,
|
|
422
425
|
...(featureChainFindings === null ? {} : { feature_chain_findings: featureChainFindings }),
|
|
426
|
+
...(advice === null ? {} : { advice }),
|
|
423
427
|
...(declarations === null ? {} : { declarations }),
|
|
424
428
|
result_digest: '',
|
|
425
429
|
};
|
package/src/todo-cli.mjs
CHANGED
|
@@ -922,6 +922,17 @@ async function mutate({
|
|
|
922
922
|
// 導出ビュー`phases`から読む。
|
|
923
923
|
const resolvedAdvisory = advisory ?? (kind === 'done' ? terminalAuditDoneAdvisory(plan, phases)
|
|
924
924
|
: kind === 'reopen' ? reopenAdvisory(plan, phases, event.task_id) : null);
|
|
925
|
+
// The completion advisory reads what this write committed (plan version + task states returned by the Store), so it adds
|
|
926
|
+
// no chart read and cannot describe another version. Evidence-free completion skips it; it never changes the completion.
|
|
927
|
+
const recordedMessage = kind === 'done' && payload === 'authored' && message !== DONE_WITHOUT_MESSAGE ? message : null;
|
|
928
|
+
const completionAdvice = recordedMessage === null && testResult === null ? null
|
|
929
|
+
: kind !== 'done' || payload !== 'authored' ? null
|
|
930
|
+
: await (await import('./plan-edit-advice.mjs')).completionAdvice({
|
|
931
|
+
repoRoot, plan, states: snapshot.tasks, taskId: event.task_id, planVersion: event.plan_version,
|
|
932
|
+
evidence: { event_digest: event.event_digest,
|
|
933
|
+
message: recordedMessage === null ? null : recordedMessage.slice(0, 400),
|
|
934
|
+
test_result: testResult === null ? null : String(testResult).slice(0, 400) },
|
|
935
|
+
}).catch(() => null);
|
|
925
936
|
const includesNoteContext = kind === 'start';
|
|
926
937
|
if (includesNoteContext && noteContext === null) {
|
|
927
938
|
throw new TypeError('start mutation requires note context');
|
|
@@ -941,6 +952,7 @@ async function mutate({
|
|
|
941
952
|
snapshot_digest: snapshot.snapshot_digest,
|
|
942
953
|
status: task.status,
|
|
943
954
|
advisory: resolvedAdvisory,
|
|
955
|
+
...(completionAdvice === null ? {} : { advice: completionAdvice }),
|
|
944
956
|
...(includesNoteContext ? {
|
|
945
957
|
design_memo: designMemoProjection(authoredTask),
|
|
946
958
|
done_condition: authoredTask.done_condition ?? null,
|
|
@@ -1783,7 +1795,8 @@ async function dependencyRevision({
|
|
|
1783
1795
|
schema: 'lattice.todo_dependency_revision_result.v1', project_id: store.project_id,
|
|
1784
1796
|
plan_key: planKey, operation, from, to, reason, actor: desired.actor,
|
|
1785
1797
|
plan_version: applied.plan_version, revision_digest: applied.revision.revision_digest,
|
|
1786
|
-
rebound_task_ids: applied.rebound_task_ids,
|
|
1798
|
+
rebound_task_ids: applied.rebound_task_ids, ...(applied.advice === undefined ? {} : { advice: applied.advice }),
|
|
1799
|
+
result_digest: '',
|
|
1787
1800
|
};
|
|
1788
1801
|
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
1789
1802
|
return result;
|
|
@@ -1848,7 +1861,8 @@ async function addTask({ repoRoot, env, planKey, flags }) {
|
|
|
1848
1861
|
schema: 'lattice.todo_task_add_result.v2', project_id: store.project_id, plan_key: planKey,
|
|
1849
1862
|
task_id: taskId, after, before, reason, actor: desired.actor, declaration,
|
|
1850
1863
|
plan_version: applied.plan_version, revision_digest: applied.revision?.revision_digest ?? null,
|
|
1851
|
-
rebound_task_ids: applied.rebound_task_ids,
|
|
1864
|
+
rebound_task_ids: applied.rebound_task_ids, ...(applied.advice === undefined ? {} : { advice: applied.advice }),
|
|
1865
|
+
result_digest: '',
|
|
1852
1866
|
};
|
|
1853
1867
|
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
1854
1868
|
return result;
|
|
@@ -2725,10 +2739,22 @@ async function revise({ repoRoot, env, planKey, inputRef }) {
|
|
|
2725
2739
|
if (revision.plan_key !== planKey) {
|
|
2726
2740
|
throw new TodoStoreError('REVISION_INVALID', 'requested_plan_mismatch');
|
|
2727
2741
|
}
|
|
2728
|
-
|
|
2742
|
+
const member = (await readTodoStore({ repoRoot }).catch(() => null))?.members.find(({ plan }) => plan.plan_key === planKey);
|
|
2743
|
+
return withEditAdvice({ repoRoot, member, desired: revision.desired_plan, receipt: await applyTodoRevision({
|
|
2729
2744
|
repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }), revision,
|
|
2730
2745
|
actor: resolveTodoActor(env), recordedAt: new Date().toISOString(),
|
|
2731
|
-
});
|
|
2746
|
+
}) });
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
/** The advisory of an ordinary plan edit (docs/architecture/dfd-finding-handoff.md) rides on the receipt; it never changes the write. */
|
|
2750
|
+
async function withEditAdvice({ repoRoot, member, desired, receipt }) {
|
|
2751
|
+
if (member === undefined || desired === undefined) return receipt;
|
|
2752
|
+
const { planEditAdvice } = await import('./plan-edit-advice.mjs');
|
|
2753
|
+
const advice = await planEditAdvice({ repoRoot, before: member.plan, after: desired, states: member.tasks }).catch(() => null);
|
|
2754
|
+
if (advice === null) return receipt;
|
|
2755
|
+
const next = { ...receipt, advice };
|
|
2756
|
+
if (typeof receipt.result_digest === 'string') next.result_digest = todoSelfDigest({ ...next, result_digest: '' }, 'result_digest');
|
|
2757
|
+
return next;
|
|
2732
2758
|
}
|
|
2733
2759
|
|
|
2734
2760
|
async function reviseSet({ repoRoot, env, inputRef }) {
|
|
@@ -2760,8 +2786,10 @@ async function revisePhase({ repoRoot, env, planKey, inputRef }) {
|
|
|
2760
2786
|
},
|
|
2761
2787
|
});
|
|
2762
2788
|
if (revision.plan_key !== planKey) throw new TodoStoreError('REVISION_INVALID', 'requested_plan_mismatch');
|
|
2763
|
-
|
|
2764
|
-
|
|
2789
|
+
const member = (await readTodoStore({ repoRoot }).catch(() => null))?.members.find(({ plan }) => plan.plan_key === planKey);
|
|
2790
|
+
return withEditAdvice({ repoRoot, member, desired: revision.desired_plan, receipt: await applyPhaseTodoRevision({
|
|
2791
|
+
repoRoot, writer: createTodoStoreWriter({ caller: 'g5-authoring' }),
|
|
2792
|
+
revision, actor: resolveTodoActor(env), recordedAt: new Date().toISOString() }) });
|
|
2765
2793
|
}
|
|
2766
2794
|
|
|
2767
2795
|
async function splitTodo({ repoRoot, env, planKey, inputRef }) {
|