@quolu/lattice 0.96.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-refusal-guidance.mjs +6 -18
- package/src/todo-cli.mjs +7 -16
- 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",
|
|
@@ -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>\`.`,
|
package/src/todo-cli.mjs
CHANGED
|
@@ -1054,22 +1054,13 @@ async function mutate({
|
|
|
1054
1054
|
return result;
|
|
1055
1055
|
}
|
|
1056
1056
|
|
|
1057
|
-
/**
|
|
1058
|
-
* a36: a reopened task stays in its last starter's `turn.own` (seat contract). When that is not
|
|
1059
|
-
* this seat, the result names the holder and the one command that moves the task here.
|
|
1060
|
-
*/
|
|
1057
|
+
/** retract-anyone: a reopened task is unstarted again; the redo records a start (from any seat). */
|
|
1061
1058
|
async function reopenTask({ repoRoot, env, planKey, taskId, payload }) {
|
|
1062
1059
|
const result = await mutate({ repoRoot, env, planKey, taskId, kind: 'reopen', payload, evidenceRef: null });
|
|
1063
|
-
const store = await readTodoStore({ repoRoot });
|
|
1064
|
-
const member = store.members.find(({ descriptor }) => descriptor.plan_key === result.plan_key);
|
|
1065
|
-
const holder = member?.journal.events
|
|
1066
|
-
.findLast((event) => event.kind === 'start' && event.task_id === result.task_id)?.actor?.agent ?? null;
|
|
1067
|
-
if (holder === resolveTodoActor(env).agent) return result;
|
|
1068
1060
|
const hinted = {
|
|
1069
|
-
...result,
|
|
1070
|
-
next_action: `${result.plan_key}/${result.task_id} is
|
|
1071
|
-
+ `
|
|
1072
|
-
+ ` 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}\`.`,
|
|
1073
1064
|
result_digest: '',
|
|
1074
1065
|
};
|
|
1075
1066
|
hinted.result_digest = todoSelfDigest(hinted, 'result_digest');
|
|
@@ -1228,7 +1219,8 @@ async function retireTask({ repoRoot, env, planKey, taskId, reason }) {
|
|
|
1228
1219
|
named.result_digest = todoSelfDigest(named, 'result_digest');
|
|
1229
1220
|
return named;
|
|
1230
1221
|
};
|
|
1231
|
-
|
|
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();
|
|
1232
1224
|
// Runtime binds an intake to the latest literal start and ignores later done/reopen, so the
|
|
1233
1225
|
// release targets that start (a reopened task keeps it; a retracted start left in-progress never).
|
|
1234
1226
|
const start = member.journal.events.findLast((event) => event.task_id === taskId && event.kind === 'start');
|
|
@@ -1574,9 +1566,8 @@ export async function rebindStart({ repoRoot, env, planKey, taskId, reason, acto
|
|
|
1574
1566
|
}
|
|
1575
1567
|
|
|
1576
1568
|
async function retractStart({ repoRoot, env, planKey, taskId, reason }) {
|
|
1577
|
-
const actor = resolveTodoActor(env);
|
|
1578
1569
|
const store = await readTodoStore({ repoRoot });
|
|
1579
|
-
const binding = resolveTodoStartRetractionBinding(store, { planKey, taskId
|
|
1570
|
+
const binding = resolveTodoStartRetractionBinding(store, { planKey, taskId });
|
|
1580
1571
|
return withStartRetractionGuard({
|
|
1581
1572
|
repoRoot,
|
|
1582
1573
|
planKey,
|
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'
|