@quolu/lattice 0.95.0 → 0.97.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/cli-help.mjs +2 -0
- package/src/cli-refusal-guidance.mjs +6 -18
- package/src/todo-blockers.mjs +29 -0
- package/src/todo-cli.mjs +33 -22
- package/src/todo-contracts.mjs +3 -1
- package/src/todo-readiness.mjs +5 -1
- package/src/todo-store-view.mjs +10 -0
- package/src/todo-store.mjs +56 -55
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quolu/lattice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.97.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/cli-help.mjs
CHANGED
|
@@ -89,6 +89,7 @@ Read commands:
|
|
|
89
89
|
note list --plan <key> [--task <id>] --json # note全履歴の診断面(通常read/startでは不要)
|
|
90
90
|
notice list [--lane <lane>] [--include-acked] [--json] # 着手できるようになった工程の知らせ(既定は未ackだけ。lane省略で全lane)
|
|
91
91
|
nudge [--json] # 前の工程が終わっているのに未着手の工程を担当ごとに返し、発火(着手)と、動けない時の止め(todo block)を促す(読むだけ)
|
|
92
|
+
blockers [--json] # 止めのある工程を全部返す(題・担当・理由の全文・止めた時刻と者・外すコマンド。読むだけ。外すのは誰でも todo unblock)
|
|
92
93
|
bindings [--plan <key>] [--json] # compile_binding付きTaskをTODO identityつきで投影する
|
|
93
94
|
display read [--json] # host表示用の工程表読取(lattice.todo_display_read_result.v1)。不整合でも断らずstateで返す
|
|
94
95
|
display source [--json] # 安い変更検知(lattice.todo_store_display_source.v1)。変わった時だけreadする
|
|
@@ -308,6 +309,7 @@ const SUBCOMMAND_USAGE = Object.freeze({
|
|
|
308
309
|
'todo notice list': 'todo notice list [--lane <lane>] [--include-acked] [--json] # lattice.todo_notice_list_result.v1',
|
|
309
310
|
'todo notice ack': 'todo notice ack --lane <lane> --notice <id>[,<id>...] [--json] # lattice.todo_notice_ack_result.v1 {acked, already, closed}',
|
|
310
311
|
'todo nudge': 'todo nudge [--json] # lattice.todo_nudge_result.v1 {lanes: [{lane, tasks: [{fire_actions, stop_action, prompt}]}]}',
|
|
312
|
+
'todo blockers': 'todo blockers [--json] # lattice.todo_blockers_result.v1 {blockers: [{plan_key, task_id, title, lane, reason, blocked_at, blocked_by, unblock_action}]}',
|
|
311
313
|
'todo wait': 'todo wait --plan <key> --task <id> [--reason <text>] | --cancel [--json] # lattice.todo_wait_result.v1 {state: waiting|startable_now|not_pending|cancelled}',
|
|
312
314
|
'todo bindings': 'todo bindings [--plan <key>] [--json]',
|
|
313
315
|
'todo display': 'todo display read [--json] | source [--json] # host表示用の読取。不整合でも断らずstateで返す',
|
|
@@ -97,16 +97,6 @@ const dependencyExists = {
|
|
|
97
97
|
};
|
|
98
98
|
|
|
99
99
|
/** The flag that carried the unreadable input: the one whose value is the refused path. */
|
|
100
|
-
const OPENED_BY_TEXT = Object.freeze({
|
|
101
|
-
reopen: ' because it was reopened', historical_import: ' from a historical import',
|
|
102
|
-
start: ' from a start',
|
|
103
|
-
});
|
|
104
|
-
/** a35: why an in-progress task is open, as a clause ('' when the store did not say). */
|
|
105
|
-
function openedByText(detail) {
|
|
106
|
-
return Object.hasOwn(OPENED_BY_TEXT, detail.opened_by ?? '') ? OPENED_BY_TEXT[detail.opened_by]
|
|
107
|
-
: detail.opened_by === null ? ' with no start recorded in this plan version' : '';
|
|
108
|
-
}
|
|
109
|
-
|
|
110
100
|
function inputFlag(detail, ctx) {
|
|
111
101
|
const flags = record(ctx.flags) ? ctx.flags : {};
|
|
112
102
|
const byValue = Object.keys(flags).find((name) => flags[name] === detail.input_ref);
|
|
@@ -235,10 +225,8 @@ const REGISTRY = {
|
|
|
235
225
|
const on = `--plan ${planOf(detail, ctx)} --task ${taskOf(detail, ctx)}`;
|
|
236
226
|
const done = doneCommand(planOf(detail, ctx), taskOf(detail, ctx), ctx);
|
|
237
227
|
return `Only a done task can be reopened; ${planOf(detail, ctx)}/${taskOf(detail, ctx)} is ${detail.status ?? 'not done'}. ` + ({
|
|
238
|
-
//
|
|
239
|
-
'in-progress':
|
|
240
|
-
? `It is still open: finish it with \`${done}\`, or undo the start with \`lattice todo retract ${on} --reason <text>\`.`
|
|
241
|
-
: `It is still open${openedByText(detail)}: finish it with \`${done}\`.`,
|
|
228
|
+
// retract-anyone: any seat may return an in-progress task to unstarted.
|
|
229
|
+
'in-progress': `It is still open: finish it with \`${done}\`, or return it to unstarted with \`lattice todo retract ${on} --reason <text>\`.`,
|
|
242
230
|
pending: `It has not started: run \`lattice todo start ${on}\`.`,
|
|
243
231
|
blocked: `It is blocked: resume it with \`lattice todo unblock ${on}\`.`,
|
|
244
232
|
retired: `Retire is permanent, so it stays closed; see \`${showTask(detail, ctx)}\`.`,
|
|
@@ -268,10 +256,10 @@ const REGISTRY = {
|
|
|
268
256
|
},
|
|
269
257
|
},
|
|
270
258
|
authored_start_binding_missing: {
|
|
271
|
-
//
|
|
272
|
-
repair: (detail, ctx) => `retract
|
|
273
|
-
+
|
|
274
|
-
+ `
|
|
259
|
+
// retract-anyone: retract targets the event that last made the task in-progress (start, reopen or carrying revision).
|
|
260
|
+
repair: (detail, ctx) => `retract targets the event that last put ${planOf(detail, ctx)}/${taskOf(detail, ctx)} in progress`
|
|
261
|
+
+ ` and found none in this plan version; see \`${showTask(detail, ctx)}\`, or finish it with`
|
|
262
|
+
+ ` \`${doneCommand(planOf(detail, ctx), taskOf(detail, ctx), ctx)}\`.`,
|
|
275
263
|
},
|
|
276
264
|
reopen_has_started_successor: {
|
|
277
265
|
repair: (detail, ctx) => `A successor of ${taskOf(detail, ctx)} has already started: to reopen it anyway run \`lattice todo reopen --plan ${planOf(detail, ctx)} --task ${taskOf(detail, ctx)} --reason <text> --override-reason <text>\`.`,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Blockers (blockers-list, docs/architecture/dfd-blockers.md): every blocked task in the chart with its full reason,
|
|
2
|
+
// who stopped it and when, and the command to lift it. Read-only; `todo unblock` stays open to any seat.
|
|
3
|
+
|
|
4
|
+
/** Blocked tasks of every member, sorted by plan_key then task_id. */
|
|
5
|
+
export function projectTodoBlockers(store) {
|
|
6
|
+
const blockers = [];
|
|
7
|
+
for (const member of store.members) {
|
|
8
|
+
const planKey = member.plan.plan_key;
|
|
9
|
+
const lastBlock = new Map();
|
|
10
|
+
for (const event of member.journal.events) if (event.kind === 'block') lastBlock.set(event.task_id, event);
|
|
11
|
+
for (const state of member.tasks) {
|
|
12
|
+
if (state.status !== 'blocked') continue;
|
|
13
|
+
const task = member.plan.tasks.find(({ task_id: id }) => id === state.task_id);
|
|
14
|
+
const event = lastBlock.get(state.task_id);
|
|
15
|
+
blockers.push({
|
|
16
|
+
plan_key: planKey,
|
|
17
|
+
task_id: state.task_id,
|
|
18
|
+
title: task?.title ?? null,
|
|
19
|
+
lane: task?.lane ?? null,
|
|
20
|
+
reason: state.blocked_reason,
|
|
21
|
+
blocked_at: event?.recorded_at ?? null,
|
|
22
|
+
blocked_by: event?.actor ?? null,
|
|
23
|
+
unblock_action: `lattice todo unblock --plan ${planKey} --task ${state.task_id}`,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const key = ({ plan_key: plan, task_id: task }) => `${plan}\u0000${task}`;
|
|
28
|
+
return blockers.sort((left, right) => (key(left) < key(right) ? -1 : 1));
|
|
29
|
+
}
|
package/src/todo-cli.mjs
CHANGED
|
@@ -170,6 +170,7 @@ import {
|
|
|
170
170
|
import { compileSeamProposalArtifact, declaredConcernSymbols } from './seam-proposal.mjs';
|
|
171
171
|
import { collectSensorEvidence } from './sensor-adapter.mjs';
|
|
172
172
|
import { newTodoNotices, projectTodoNotices, waitInEffect } from './todo-notices.mjs';
|
|
173
|
+
import { projectTodoBlockers } from './todo-blockers.mjs';
|
|
173
174
|
import { projectTodoNudges } from './todo-nudges.mjs';
|
|
174
175
|
import {
|
|
175
176
|
ackTodoNotices, cancelTodoNoticeWait, readAllTodoNoticeAcks, readAllTodoNoticeWaits, readTodoNoticeAcks, writeTodoNoticeWait,
|
|
@@ -308,7 +309,7 @@ const TODO_COMMAND_NAMES = Object.freeze([
|
|
|
308
309
|
'status', 'show', 'note', 'bindings', 'display', 'independence', 'structure', 'seam-profile', 'seam-proposal',
|
|
309
310
|
'verify', 'repair-eol', 'snapshot', 'gantt', 'dashboard', 'phase', 'migrate', 'start', 'block',
|
|
310
311
|
'unblock', 'retire', 'done', 'reopen', 'evidence', 'split', 'revise', 'revise-phase', 'revise-set',
|
|
311
|
-
'retract', 'dependency', 'add', 'notice', 'wait', 'nudge',
|
|
312
|
+
'retract', 'dependency', 'add', 'notice', 'wait', 'nudge', 'blockers',
|
|
312
313
|
]);
|
|
313
314
|
|
|
314
315
|
function typedArgumentFailure(stderr, code, message, detail, context = {}) {
|
|
@@ -371,6 +372,7 @@ const TODO_FLAG_SPECS = Object.freeze({
|
|
|
371
372
|
'notice list': Object.freeze({ known: ['lane', 'include-acked', 'json'], required: [], booleans: ['include-acked', 'json'] }),
|
|
372
373
|
'notice ack': Object.freeze({ known: ['lane', 'notice', 'json'], required: ['lane', 'notice'], booleans: ['json'] }),
|
|
373
374
|
nudge: Object.freeze({ known: ['json'], required: [], booleans: ['json'] }),
|
|
375
|
+
blockers: Object.freeze({ known: ['json'], required: [], booleans: ['json'] }),
|
|
374
376
|
wait: Object.freeze({ known: ['plan', 'task', 'reason', 'cancel', 'json'], required: ['plan', 'task'], booleans: ['cancel', 'json'] }),
|
|
375
377
|
'note list': Object.freeze({ known: ['plan', 'task', 'json'], required: ['plan'], booleans: ['json'] }),
|
|
376
378
|
'phase status': Object.freeze({ known: ['plan', 'json'], required: ['plan'], booleans: ['json'] }),
|
|
@@ -1052,22 +1054,13 @@ async function mutate({
|
|
|
1052
1054
|
return result;
|
|
1053
1055
|
}
|
|
1054
1056
|
|
|
1055
|
-
/**
|
|
1056
|
-
* a36: a reopened task stays in its last starter's `turn.own` (seat contract). When that is not
|
|
1057
|
-
* this seat, the result names the holder and the one command that moves the task here.
|
|
1058
|
-
*/
|
|
1057
|
+
/** retract-anyone: a reopened task is unstarted again; the redo records a start (from any seat). */
|
|
1059
1058
|
async function reopenTask({ repoRoot, env, planKey, taskId, payload }) {
|
|
1060
1059
|
const result = await mutate({ repoRoot, env, planKey, taskId, kind: 'reopen', payload, evidenceRef: null });
|
|
1061
|
-
const store = await readTodoStore({ repoRoot });
|
|
1062
|
-
const member = store.members.find(({ descriptor }) => descriptor.plan_key === result.plan_key);
|
|
1063
|
-
const holder = member?.journal.events
|
|
1064
|
-
.findLast((event) => event.kind === 'start' && event.task_id === result.task_id)?.actor?.agent ?? null;
|
|
1065
|
-
if (holder === resolveTodoActor(env).agent) return result;
|
|
1066
1060
|
const hinted = {
|
|
1067
|
-
...result,
|
|
1068
|
-
next_action: `${result.plan_key}/${result.task_id} is
|
|
1069
|
-
+ `
|
|
1070
|
-
+ ` to work on it from this seat run \`lattice todo start --plan ${result.plan_key} --task ${result.task_id} --rebind --reason <text>\`.`,
|
|
1061
|
+
...result,
|
|
1062
|
+
next_action: `${result.plan_key}/${result.task_id} is unstarted again; redo it with`
|
|
1063
|
+
+ ` \`lattice todo start --plan ${result.plan_key} --task ${result.task_id}\`.`,
|
|
1071
1064
|
result_digest: '',
|
|
1072
1065
|
};
|
|
1073
1066
|
hinted.result_digest = todoSelfDigest(hinted, 'result_digest');
|
|
@@ -1226,7 +1219,8 @@ async function retireTask({ repoRoot, env, planKey, taskId, reason }) {
|
|
|
1226
1219
|
named.result_digest = todoSelfDigest(named, 'result_digest');
|
|
1227
1220
|
return named;
|
|
1228
1221
|
};
|
|
1229
|
-
|
|
1222
|
+
// retract-anyone: a reopened task is pending yet may still hold the intake of its earlier start.
|
|
1223
|
+
if (!['in-progress', 'pending'].includes(state.status)) return append();
|
|
1230
1224
|
// Runtime binds an intake to the latest literal start and ignores later done/reopen, so the
|
|
1231
1225
|
// release targets that start (a reopened task keeps it; a retracted start left in-progress never).
|
|
1232
1226
|
const start = member.journal.events.findLast((event) => event.task_id === taskId && event.kind === 'start');
|
|
@@ -1572,9 +1566,8 @@ export async function rebindStart({ repoRoot, env, planKey, taskId, reason, acto
|
|
|
1572
1566
|
}
|
|
1573
1567
|
|
|
1574
1568
|
async function retractStart({ repoRoot, env, planKey, taskId, reason }) {
|
|
1575
|
-
const actor = resolveTodoActor(env);
|
|
1576
1569
|
const store = await readTodoStore({ repoRoot });
|
|
1577
|
-
const binding = resolveTodoStartRetractionBinding(store, { planKey, taskId
|
|
1570
|
+
const binding = resolveTodoStartRetractionBinding(store, { planKey, taskId });
|
|
1578
1571
|
return withStartRetractionGuard({
|
|
1579
1572
|
repoRoot,
|
|
1580
1573
|
planKey,
|
|
@@ -4677,15 +4670,31 @@ async function declaredWitnessRows(repoRoot, store) {
|
|
|
4677
4670
|
* no Store yet answers an empty list, since the BellTeam run walks every chart directory.
|
|
4678
4671
|
*/
|
|
4679
4672
|
async function nudgeList({ repoRoot }) {
|
|
4680
|
-
|
|
4681
|
-
|
|
4673
|
+
const store = await readTodoStoreOrNull(repoRoot);
|
|
4674
|
+
const result = {
|
|
4675
|
+
schema: 'lattice.todo_nudge_result.v1', project_id: store?.project_id ?? null,
|
|
4676
|
+
lanes: store === null ? [] : projectTodoNudges(store, { declared: await declaredWitnessRows(repoRoot, store) }),
|
|
4677
|
+
result_digest: '',
|
|
4678
|
+
};
|
|
4679
|
+
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
4680
|
+
return result;
|
|
4681
|
+
}
|
|
4682
|
+
|
|
4683
|
+
/** The Store, or null where none exists yet (the BellTeam reads walk every chart directory). */
|
|
4684
|
+
async function readTodoStoreOrNull(repoRoot) {
|
|
4685
|
+
try { return await readTodoStore({ repoRoot }); }
|
|
4682
4686
|
catch (error) {
|
|
4683
4687
|
if (error?.code !== 'STORE_UNINITIALIZED') throw error;
|
|
4684
|
-
|
|
4688
|
+
return null;
|
|
4685
4689
|
}
|
|
4690
|
+
}
|
|
4691
|
+
|
|
4692
|
+
/** `todo blockers` (blockers-list, dfd-blockers.md): every blocked task with its full reason and unblock command. */
|
|
4693
|
+
async function blockerList({ repoRoot }) {
|
|
4694
|
+
const store = await readTodoStoreOrNull(repoRoot);
|
|
4686
4695
|
const result = {
|
|
4687
|
-
schema: 'lattice.
|
|
4688
|
-
|
|
4696
|
+
schema: 'lattice.todo_blockers_result.v1', project_id: store?.project_id ?? null,
|
|
4697
|
+
blockers: store === null ? [] : projectTodoBlockers(store),
|
|
4689
4698
|
result_digest: '',
|
|
4690
4699
|
};
|
|
4691
4700
|
result.result_digest = todoSelfDigest(result, 'result_digest');
|
|
@@ -5255,6 +5264,8 @@ export async function runTodoCli({ argv, cwd, stdout, stderr, env = process.env,
|
|
|
5255
5264
|
}
|
|
5256
5265
|
} else if (argv[0] === 'nudge' && matchFlagCommand(argv, ['nudge'], TODO_FLAG_SPECS.nudge) !== null) {
|
|
5257
5266
|
action = (repoRoot) => nudgeList({ repoRoot });
|
|
5267
|
+
} else if (argv[0] === 'blockers' && matchFlagCommand(argv, ['blockers'], TODO_FLAG_SPECS.blockers) !== null) {
|
|
5268
|
+
action = (repoRoot) => blockerList({ repoRoot });
|
|
5258
5269
|
} else if (argv[0] === 'wait' && matchFlagCommand(argv, ['wait'], TODO_FLAG_SPECS.wait) !== null) {
|
|
5259
5270
|
const flags = matchFlagCommand(argv, ['wait'], TODO_FLAG_SPECS.wait);
|
|
5260
5271
|
const reasonOk = flags.reason === undefined
|
package/src/todo-contracts.mjs
CHANGED
|
@@ -628,7 +628,9 @@ function validPayload(event) {
|
|
|
628
628
|
&& typeof payload.imported === 'boolean'
|
|
629
629
|
&& isTodoDigest(payload.target_done_digest) && evidence(payload.evidence);
|
|
630
630
|
}
|
|
631
|
-
|
|
631
|
+
// retract-anyone (B1): new reopens carry to_status 'pending' (unstarted); legacy ones (no key) reopened in-progress.
|
|
632
|
+
if (event.kind === 'reopen') return (exactRecord(payload, ['reason', 'target_done_digest', 'override_reason'])
|
|
633
|
+
|| (exactRecord(payload, ['reason', 'target_done_digest', 'override_reason', 'to_status']) && payload.to_status === 'pending'))
|
|
632
634
|
&& nullableText(payload.reason) && payload.reason !== null && isTodoDigest(payload.target_done_digest)
|
|
633
635
|
&& nullableText(payload.override_reason);
|
|
634
636
|
if (event.kind === 'phase_review') return exactRecord(payload, ['reason'])
|
package/src/todo-readiness.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
isFinishedTodoTaskState,
|
|
4
4
|
isPhaseTodoPlanSchema,
|
|
5
5
|
projectTodoCrossPlanDependencies,
|
|
6
|
+
stepTodoReopenedPending,
|
|
6
7
|
} from './todo-store-view.mjs';
|
|
7
8
|
import { TodoStoreError, todoPhaseDefinitions } from './todo-store.mjs';
|
|
8
9
|
|
|
@@ -26,6 +27,8 @@ export function createTodoReadiness(store) {
|
|
|
26
27
|
const { plan } = member;
|
|
27
28
|
const states = new Map(member.tasks.map((state) => [state.task_id, state]));
|
|
28
29
|
const phaseStates = new Map((member.phases ?? []).map((phase) => [phase.phase_id, phase.status]));
|
|
30
|
+
// retract-anyone (B2): the same reopened set replay uses; such a start skips only the own-phase check.
|
|
31
|
+
const reopened = (member.journal?.events ?? []).reduce(stepTodoReopenedPending, new Set());
|
|
29
32
|
for (const phase of member.phases ?? []) {
|
|
30
33
|
phases.set(phaseKey({ ...plan, ...phase }), { plan_key: plan.plan_key, phase_id: phase.phase_id, status: phase.status });
|
|
31
34
|
}
|
|
@@ -40,6 +43,7 @@ export function createTodoReadiness(store) {
|
|
|
40
43
|
plan_key: plan.plan_key,
|
|
41
44
|
phase_id: isPhaseTodoPlanSchema(plan.schema) ? task.phase_id : null,
|
|
42
45
|
phase_status: phaseStates.get(task.phase_id),
|
|
46
|
+
reopened: reopened.has(task.task_id),
|
|
43
47
|
});
|
|
44
48
|
incoming.set(key, new Set());
|
|
45
49
|
outgoing.set(key, new Set());
|
|
@@ -115,7 +119,7 @@ export function createTodoReadiness(store) {
|
|
|
115
119
|
|
|
116
120
|
function ownPhaseReady(key) {
|
|
117
121
|
const node = nodes.get(key);
|
|
118
|
-
return node?.schema !== 'lattice.todo_plan.v4' || node.phase_status === 'active';
|
|
122
|
+
return node?.schema !== 'lattice.todo_plan.v4' || node.phase_status === 'active' || node.reopened === true;
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
/** a28: the successors that already left pending, sorted, so a refusal can name them. */
|
package/src/todo-store-view.mjs
CHANGED
|
@@ -23,6 +23,16 @@ export function isFinishedTodoTaskState(state) {
|
|
|
23
23
|
return state?.status === 'done' || state?.status === 'retired';
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* retract-anyone (B2): one rule, used by Store replay and Plan readiness, for tasks reopened to unstarted and not
|
|
28
|
+
* started or retired since. Shortcut: the set lives in one plan version's journal; upgrade when a v4 revision must keep it.
|
|
29
|
+
*/
|
|
30
|
+
export function stepTodoReopenedPending(ids, event) {
|
|
31
|
+
if (event.kind === 'reopen' && event.payload?.to_status === 'pending') ids.add(event.task_id);
|
|
32
|
+
else if (event.kind === 'start' || event.kind === 'retire') ids.delete(event.task_id);
|
|
33
|
+
return ids;
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
export function isDecoupledPhaseTodoPlanSchema(schema) {
|
|
27
37
|
return ['lattice.todo_plan.v5', 'lattice.todo_plan.v7', 'lattice.todo_plan.v8'].includes(schema);
|
|
28
38
|
}
|
package/src/todo-store.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
projectTodoCrossPlanDependencies,
|
|
6
6
|
normalizeCheckoutEol,
|
|
7
7
|
isFinishedTodoTaskState,
|
|
8
|
+
stepTodoReopenedPending,
|
|
8
9
|
} from './todo-store-view.mjs';
|
|
9
10
|
export {
|
|
10
11
|
isDecoupledPhaseTodoPlanSchema,
|
|
@@ -547,12 +548,36 @@ function localSuccessors(plan, taskId) {
|
|
|
547
548
|
return plan.tasks.map(({ task_id }) => task_id).filter((candidate) => localPredecessors(plan, candidate).includes(taskId));
|
|
548
549
|
}
|
|
549
550
|
|
|
551
|
+
const CARRY_STATE_POLICIES = ['carry', 'carry_reconciled_metadata', 'acquire_phase'];
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* retract-anyone (A3, Ludmila 2026-11-12): the digest of the event that last made the task in-progress, or null.
|
|
555
|
+
* One rule for replay and resolveTodoStartRetractionBinding. A revision genesis carrying the task open binds it.
|
|
556
|
+
*/
|
|
557
|
+
function stepStartBinding(binding, event, taskId) {
|
|
558
|
+
if (event.kind === 'plan_genesis') {
|
|
559
|
+
return (event.state_migration ?? []).some((migration) => CARRY_STATE_POLICIES.includes(migration.state_policy)
|
|
560
|
+
&& migration.to_task_id === taskId && ['in-progress', 'blocked'].includes(migration.state?.status))
|
|
561
|
+
? event.event_digest : binding;
|
|
562
|
+
}
|
|
563
|
+
if (event.task_id !== taskId) return binding;
|
|
564
|
+
if (event.kind === 'start' || (event.kind === 'reopen' && event.payload.to_status === undefined)) return event.event_digest;
|
|
565
|
+
if (['done', 'retire', 'start_retracted', 'reopen'].includes(event.kind)) return null;
|
|
566
|
+
return binding;
|
|
567
|
+
}
|
|
568
|
+
|
|
550
569
|
function replay(plan, events, { verifyEvidence, verifyImportSource } = {}) {
|
|
551
570
|
const states = new Map(plan.tasks.map(({ task_id }) => [task_id, taskState(task_id)]));
|
|
552
571
|
const phaseStates = new Map(phasesOf(plan).map(({ phase_id }) => [phase_id, emptyPhaseState(phase_id)]));
|
|
553
572
|
const doneDigest = new Map();
|
|
554
573
|
const completion = new Map();
|
|
555
574
|
const authoredStartBindings = new Map();
|
|
575
|
+
// retract-anyone (B2): tasks reopened to unstarted; their start skips only the v4 own-phase check.
|
|
576
|
+
const reopenedPending = new Set();
|
|
577
|
+
const bind = (event, taskId = event.task_id) => {
|
|
578
|
+
const next = stepStartBinding(authoredStartBindings.get(taskId) ?? null, event, taskId);
|
|
579
|
+
if (next === null) authoredStartBindings.delete(taskId); else authoredStartBindings.set(taskId, next);
|
|
580
|
+
};
|
|
556
581
|
// hard証拠検証は即時でなくreplay完了後、まだ現在状態を支えている記述子だけへ行う。
|
|
557
582
|
// reopen・再doneで差し替えられた古いdoneが指すblobは一度もcommitされないままGCで消え得るし、
|
|
558
583
|
// 履歴の完全性はevent_digest鎖が既に持つ。即時検証だと消えたblobを指す過去eventが
|
|
@@ -586,7 +611,7 @@ function replay(plan, events, { verifyEvidence, verifyImportSource } = {}) {
|
|
|
586
611
|
for (const migration of event.state_migration) {
|
|
587
612
|
// acquire_phaseもcarry系(状態を完全に持ち越す)。ADR 0147裁定4のPhase獲得はdoneを
|
|
588
613
|
// 保つことが目的であり、ここで除外するとreplayが状態を復元しない。
|
|
589
|
-
if (!
|
|
614
|
+
if (!CARRY_STATE_POLICIES.includes(migration.state_policy)) continue;
|
|
590
615
|
const state = states.get(migration.to_task_id);
|
|
591
616
|
Object.assign(state, structuredClone(migration.state), { evidence_unverified: false });
|
|
592
617
|
if (state.evidence !== null) {
|
|
@@ -617,6 +642,7 @@ function replay(plan, events, { verifyEvidence, verifyImportSource } = {}) {
|
|
|
617
642
|
}
|
|
618
643
|
}
|
|
619
644
|
}
|
|
645
|
+
for (const taskId of states.keys()) bind(event, taskId);
|
|
620
646
|
}
|
|
621
647
|
continue;
|
|
622
648
|
}
|
|
@@ -719,9 +745,7 @@ function replay(plan, events, { verifyEvidence, verifyImportSource } = {}) {
|
|
|
719
745
|
if (state.status !== 'in-progress') {
|
|
720
746
|
fail('STORE_INCONSISTENT', 'invalid_rebind_start_transition');
|
|
721
747
|
}
|
|
722
|
-
|
|
723
|
-
actor: structuredClone(event.actor), event_digest: event.event_digest,
|
|
724
|
-
});
|
|
748
|
+
bind(event);
|
|
725
749
|
continue;
|
|
726
750
|
}
|
|
727
751
|
if (event.payload.start_mode === 'historical_import') {
|
|
@@ -740,7 +764,8 @@ function replay(plan, events, { verifyEvidence, verifyImportSource } = {}) {
|
|
|
740
764
|
state.evidence = event.payload.evidence;
|
|
741
765
|
state.imported = true;
|
|
742
766
|
} else {
|
|
743
|
-
|
|
767
|
+
// B2: a task reopened to unstarted is redone inside its (possibly decided) phase, as the old reopen allowed.
|
|
768
|
+
const phaseStatus = plan.schema === 'lattice.todo_plan.v4' && !reopenedPending.has(event.task_id)
|
|
744
769
|
? derivedPhaseStatus(plan, states, phaseStates,
|
|
745
770
|
plan.tasks.find(({ task_id }) => task_id === event.task_id).phase_id) : 'active';
|
|
746
771
|
if (state.status !== 'pending' || phaseStatus !== 'active'
|
|
@@ -748,31 +773,26 @@ function replay(plan, events, { verifyEvidence, verifyImportSource } = {}) {
|
|
|
748
773
|
fail('STORE_INCONSISTENT', 'invalid_start_transition');
|
|
749
774
|
}
|
|
750
775
|
state.status = 'in-progress'; state.started_at = event.recorded_at;
|
|
751
|
-
authoredStartBindings.set(event.task_id, {
|
|
752
|
-
actor: structuredClone(event.actor), event_digest: event.event_digest,
|
|
753
|
-
});
|
|
754
776
|
}
|
|
777
|
+
bind(event);
|
|
778
|
+
stepTodoReopenedPending(reopenedPending, event);
|
|
755
779
|
} else if (event.kind === 'start_retracted') {
|
|
780
|
+
// A1-A3: any seat retracts; the target must be the event that last made the task in-progress.
|
|
756
781
|
const binding = authoredStartBindings.get(event.task_id);
|
|
757
|
-
const sameActor = binding !== undefined
|
|
758
|
-
&& binding.actor.host === event.actor.host
|
|
759
|
-
&& binding.actor.session === event.actor.session
|
|
760
|
-
&& binding.actor.agent === event.actor.agent;
|
|
761
782
|
if (state.status !== 'in-progress') {
|
|
762
783
|
fail('START_RETRACTION_INVALID', 'start_retraction_requires_in_progress', {
|
|
763
784
|
task_id: event.task_id, status: state.status,
|
|
764
785
|
});
|
|
765
786
|
}
|
|
766
|
-
if (binding === undefined || binding
|
|
787
|
+
if (binding === undefined || binding !== event.payload.target_start_digest) {
|
|
767
788
|
fail('START_RETRACTION_INVALID', 'authored_start_binding_missing', {
|
|
768
789
|
task_id: event.task_id,
|
|
769
790
|
});
|
|
770
791
|
}
|
|
771
|
-
if (!sameActor) {
|
|
772
|
-
fail('START_RETRACTION_INVALID', 'start_actor_mismatch', { task_id: event.task_id });
|
|
773
|
-
}
|
|
774
792
|
Object.assign(state, taskState(event.task_id));
|
|
775
|
-
|
|
793
|
+
// A2: a retracted historical_import start no longer holds its import source.
|
|
794
|
+
pendingVerifications.delete(`task:${event.task_id}`);
|
|
795
|
+
bind(event);
|
|
776
796
|
} else if (event.kind === 'block') {
|
|
777
797
|
if (state.status !== 'in-progress') fail('STORE_INCONSISTENT', 'invalid_block_transition');
|
|
778
798
|
state.status = 'blocked'; state.blocked_reason = event.payload.reason;
|
|
@@ -794,7 +814,8 @@ function replay(plan, events, { verifyEvidence, verifyImportSource } = {}) {
|
|
|
794
814
|
// done_at and imported survive a retire from done so the finished mark stays (isFinishedTodoTaskState).
|
|
795
815
|
state.evidence = null; state.test_result = null; state.imported = wasDone ? state.imported : false;
|
|
796
816
|
state.evidence_unverified = false;
|
|
797
|
-
|
|
817
|
+
bind(event);
|
|
818
|
+
stepTodoReopenedPending(reopenedPending, event);
|
|
798
819
|
if (wasDone) {
|
|
799
820
|
completion.delete(event.task_id);
|
|
800
821
|
pendingVerifications.delete(`task:${event.task_id}`);
|
|
@@ -854,7 +875,7 @@ function replay(plan, events, { verifyEvidence, verifyImportSource } = {}) {
|
|
|
854
875
|
completion.set(event.task_id, { mode: 'evidence_promotion', completed_at: current.completed_at });
|
|
855
876
|
}
|
|
856
877
|
doneDigest.set(event.task_id, event.event_digest);
|
|
857
|
-
|
|
878
|
+
bind(event);
|
|
858
879
|
} else if (event.kind === 'reopen') {
|
|
859
880
|
if (state.status !== 'done' || doneDigest.get(event.task_id) !== event.payload.target_done_digest) {
|
|
860
881
|
fail('STORE_INCONSISTENT', 'invalid_reopen_binding');
|
|
@@ -863,32 +884,24 @@ function replay(plan, events, { verifyEvidence, verifyImportSource } = {}) {
|
|
|
863
884
|
// phase decision stays as recorded; Plan shows it as acceptance_stale (derived from the journal).
|
|
864
885
|
const startedSuccessor = localSuccessors(plan, event.task_id).some((id) => states.get(id).status !== 'pending');
|
|
865
886
|
if (startedSuccessor && event.payload.override_reason === null) fail('STORE_INCONSISTENT', 'reopen_has_started_successor');
|
|
866
|
-
|
|
887
|
+
if (event.payload.to_status === 'pending') {
|
|
888
|
+
// B3: back to unstarted; doneDigest stays stale until the next done (unreachable while not done).
|
|
889
|
+
Object.assign(state, taskState(event.task_id));
|
|
890
|
+
} else {
|
|
891
|
+
state.status = 'in-progress'; state.done_at = null; state.evidence = null; state.test_result = null;
|
|
892
|
+
}
|
|
867
893
|
completion.delete(event.task_id);
|
|
868
894
|
pendingVerifications.delete(`task:${event.task_id}`);
|
|
895
|
+
bind(event);
|
|
896
|
+
stepTodoReopenedPending(reopenedPending, event);
|
|
869
897
|
}
|
|
870
898
|
}
|
|
871
899
|
for (const verify of pendingVerifications.values()) verify();
|
|
872
900
|
return [...states.values()].sort((left, right) => left.task_id < right.task_id ? -1 : left.task_id > right.task_id ? 1 : 0);
|
|
873
901
|
}
|
|
874
902
|
|
|
875
|
-
/**
|
|
876
|
-
|
|
877
|
-
* 'historical_import', 'reopen', or null (no event here, e.g. carried by a revision).
|
|
878
|
-
* Only an authored start has something for `todo retract` to undo.
|
|
879
|
-
*/
|
|
880
|
-
function todoOpenedBy(member, taskId) {
|
|
881
|
-
let openedBy = null;
|
|
882
|
-
for (const event of member.journal.events) {
|
|
883
|
-
if (event.task_id !== taskId) continue;
|
|
884
|
-
if (event.kind === 'start') openedBy = event.payload.start_mode === 'historical_import' ? 'historical_import' : 'start';
|
|
885
|
-
else if (event.kind === 'reopen') openedBy = 'reopen';
|
|
886
|
-
}
|
|
887
|
-
return openedBy;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
/** 最新のauthored startだけを撤回対象として返す。readとappendの双方で同じbindingを検証する。 */
|
|
891
|
-
export function resolveTodoStartRetractionBinding(store, { planKey, taskId, actor }) {
|
|
903
|
+
/** retract-anyone (A3): the binding a retract targets, by the same rule replay uses; any seat may retract. */
|
|
904
|
+
export function resolveTodoStartRetractionBinding(store, { planKey, taskId }) {
|
|
892
905
|
const member = store.members.find(({ descriptor }) => descriptor.plan_key === planKey);
|
|
893
906
|
if (member === undefined) fail('STORE_INCONSISTENT', 'plan_not_active');
|
|
894
907
|
const canonicalTaskId = resolveCanonicalTaskId(member.plan, taskId);
|
|
@@ -899,21 +912,9 @@ export function resolveTodoStartRetractionBinding(store, { planKey, taskId, acto
|
|
|
899
912
|
task_id: canonicalTaskId, status: task.status,
|
|
900
913
|
});
|
|
901
914
|
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
if (event.kind === 'start' && event.payload.start_mode !== 'historical_import') binding = event;
|
|
906
|
-
else if (event.kind === 'done' || event.kind === 'start_retracted') binding = null;
|
|
907
|
-
}
|
|
908
|
-
if (binding === null) {
|
|
909
|
-
fail('START_RETRACTION_INVALID', 'authored_start_binding_missing', {
|
|
910
|
-
plan_key: planKey, task_id: canonicalTaskId, opened_by: todoOpenedBy(member, canonicalTaskId) });
|
|
911
|
-
}
|
|
912
|
-
if (binding.actor.host !== actor.host || binding.actor.session !== actor.session
|
|
913
|
-
|| binding.actor.agent !== actor.agent) {
|
|
914
|
-
fail('START_RETRACTION_INVALID', 'start_actor_mismatch', { task_id: canonicalTaskId });
|
|
915
|
-
}
|
|
916
|
-
return { task_id: canonicalTaskId, activation_event_digest: binding.event_digest };
|
|
915
|
+
const binding = member.journal.events.reduce((current, event) => stepStartBinding(current, event, canonicalTaskId), null);
|
|
916
|
+
if (binding === null) fail('START_RETRACTION_INVALID', 'authored_start_binding_missing', { plan_key: planKey, task_id: canonicalTaskId });
|
|
917
|
+
return { task_id: canonicalTaskId, activation_event_digest: binding };
|
|
917
918
|
}
|
|
918
919
|
|
|
919
920
|
function snapshotFor(plan, events, tasks) {
|
|
@@ -2289,14 +2290,14 @@ function resolveTargetedEvent(input, storeMember) {
|
|
|
2289
2290
|
const status = storeMember.tasks?.find(({ task_id: id }) => id === input.task_id)?.status;
|
|
2290
2291
|
if (status !== undefined && status !== 'done') {
|
|
2291
2292
|
fail('TODO_TRANSITION_REFUSED', 'invalid_reopen_transition', {
|
|
2292
|
-
cause: 'task_state', status, plan_key: storeMember.plan.plan_key, task_id: input.task_id
|
|
2293
|
-
...(status === 'in-progress' ? { opened_by: todoOpenedBy(storeMember, input.task_id) } : {}) });
|
|
2293
|
+
cause: 'task_state', status, plan_key: storeMember.plan.plan_key, task_id: input.task_id });
|
|
2294
2294
|
}
|
|
2295
2295
|
const targetDigest = resolveDoneBindingDigest(storeMember, input.task_id);
|
|
2296
2296
|
if (targetDigest === null) fail('STORE_INCONSISTENT', 'invalid_reopen_binding');
|
|
2297
2297
|
return {
|
|
2298
2298
|
...input,
|
|
2299
|
-
|
|
2299
|
+
// retract-anyone (B1): a reopened task is unstarted; the redo records a start.
|
|
2300
|
+
payload: { ...input.payload, target_done_digest: targetDigest, to_status: 'pending' },
|
|
2300
2301
|
};
|
|
2301
2302
|
}
|
|
2302
2303
|
if (input.kind === 'done'
|