@agent-plan/core 0.3.1 → 0.3.2

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/dist/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export * from "./handoff-reply.js";
24
24
  export * from "./mutation-reply.js";
25
25
  export * from "./recommend-reply.js";
26
26
  export * from "./feature-delete.js";
27
+ export * from "./task-move.js";
27
28
  export * from "./accepted-decision-guard.js";
28
29
  export * from "./project-context-migration.js";
29
30
  export * from "./project-context.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC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* from "./mutation-reply.js";
25
25
  export * from "./recommend-reply.js";
26
26
  export * from "./feature-delete.js";
27
+ export * from "./task-move.js";
27
28
  export * from "./accepted-decision-guard.js";
28
29
  export * from "./project-context-migration.js";
29
30
  export * from "./project-context.js";
package/dist/on-hold.d.ts CHANGED
@@ -29,9 +29,13 @@ export interface OnHoldTask {
29
29
  /** Why it was put on hold: the motivation of the status change that parked it. */
30
30
  reason: string;
31
31
  heldSince: string;
32
- /** Planner refs named in the reason, each checked against the plan. */
32
+ /** Planner refs the task is actually waiting on: refs named in the hold
33
+ * reason, plus its own dependsOn edges (by composite ref) — deduplicated,
34
+ * so a dependency already spelled out in the reason is not double-listed.
35
+ * Each is checked against the plan. */
33
36
  namedRefs: OnHoldRef[];
34
- /** True when the reason names at least one ref and every named ref is finished. */
37
+ /** True when there is at least one ref to wait on (named in the reason or
38
+ * a dependsOn edge) and every one of them is finished. */
35
39
  readyToResume: boolean;
36
40
  }
37
41
  /** Resolve every planner ref named in `text`, by number only (never by title). */
@@ -1 +1 @@
1
- {"version":3,"file":"on-hold.d.ts","sourceRoot":"","sources":["../src/on-hold.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAQ,MAAM,aAAa,CAAC;AAGxD;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,gBAAgB,aAA8C,CAAC;AAG5E,MAAM,WAAW,SAAS;IACxB,gFAAgF;IAChF,GAAG,EAAE,MAAM,CAAC;IACZ,8DAA8D;IAC9D,QAAQ,EAAE,OAAO,CAAC;IAClB,qDAAqD;IACrD,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,kFAAkF;IAClF,M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CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,kFAAkF;IAClF,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB;;;4CAGwC;IACxC,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB;+DAC2D;IAC3D,aAAa,EAAE,OAAO,CAAC;CACxB;AAgBD,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,UAAU,SAAK,GAAG,SAAS,EAAE,CA8B5G;AAoBD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,UAAU,EAAE,CAiCzG;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAKhE;AAID;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,KAAK,SAAI,GAAG,MAAM,CAiBvE"}
package/dist/on-hold.js CHANGED
@@ -55,6 +55,23 @@ export function refsNamedIn(text, phases, features, selfTaskId = "") {
55
55
  }
56
56
  return [...seen.values()];
57
57
  }
58
+ /** Resolve a task's dependsOn edges to composite refs, checked against the
59
+ * plan the same way refsNamedIn checks a ref found in text. A dependsOn id
60
+ * always resolves (dependencies are validated at creation — see
61
+ * PlanStore.addTaskDependency), but a defensive `found: false` covers a
62
+ * dangling edge from an older plan rather than throwing. */
63
+ function dependencyRefsFor(task, phases, features) {
64
+ return (task.dependsOn ?? []).map((dependencyId) => {
65
+ for (const phase of phases) {
66
+ const dependency = phase.tasks.find((candidate) => candidate.id === dependencyId);
67
+ if (dependency) {
68
+ const ref = `${formatPhaseRef(phase.number, featureNumberOfPhase(phase, features))}/T${pad(dependency.number)}`;
69
+ return { ref, found: true, finished: FINISHED.has(dependency.status) };
70
+ }
71
+ }
72
+ return { ref: dependencyId, found: false, finished: false };
73
+ });
74
+ }
58
75
  /**
59
76
  * Every on-hold task, ready-to-resume ones first. Pass `phaseIds` to limit
60
77
  * the list to the phases a caller is about to act on.
@@ -69,7 +86,17 @@ export function listOnHoldWork(features, phases, phaseIds) {
69
86
  if (!ON_HOLD_STATUSES.has(task.status))
70
87
  continue;
71
88
  const { reason, at } = holdEntry(task);
89
+ // A parked task waits on whatever its reason names AND whatever it
90
+ // depends on — merged by ref so a dependency already spelled out in
91
+ // the reason is not counted, or shown, twice.
72
92
  const namedRefs = refsNamedIn(reason, phases, features, task.id);
93
+ const seenRefs = new Set(namedRefs.map((named) => named.ref));
94
+ for (const dependencyRef of dependencyRefsFor(task, phases, features)) {
95
+ if (seenRefs.has(dependencyRef.ref))
96
+ continue;
97
+ seenRefs.add(dependencyRef.ref);
98
+ namedRefs.push(dependencyRef);
99
+ }
73
100
  items.push({
74
101
  taskId: task.id,
75
102
  ref: `${phaseRef}/T${pad(task.number)}`,
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Move one or more tasks to a different phase without recreating them.
3
+ *
4
+ * Before this, moving a task meant deleting it and creating a new one in
5
+ * the target phase — losing its id, statusLog, checklist ticks, accepted
6
+ * decisions, pause history, and every dependsOn edge pointing at it (see
7
+ * P108(F005): heca's P082(F003)/T468, T470, T471, T472, T513 are on hold
8
+ * until work in P094 lands, but belong in P094 as its closing steps, and
9
+ * recreating five ~4,000-character tasks loses all of that history). This
10
+ * module is the one place that moves a task: only `phaseId`, `statusLog`
11
+ * (one appended entry) and `updatedAt` change. Everything else — id,
12
+ * number, shortId, status, checklist, subtasks, acceptedDecisions,
13
+ * pauseSnapshot/pauseHistory, notes, description/descriptionRef and
14
+ * dependsOn — survives untouched because the task object is spread, never
15
+ * rebuilt field by field. Other tasks' dependsOn keep resolving because
16
+ * task ids never change; only the composite ref they'd print as changes.
17
+ *
18
+ * Reply size is deliberately independent of task size: a moved task's
19
+ * description can be tens of thousands of characters, and a caller moving
20
+ * five tasks already has that text — it must not pay to receive it again.
21
+ * buildTaskMoveReply (below) echoes only ref/id/shortId/title/status per
22
+ * task, never the task body.
23
+ *
24
+ * Both phase files change together or neither: this runs inside
25
+ * `store.runBatch` and mirrors the rollback-on-error shape the MCP/Pi
26
+ * `planner-task-switch` / `task_switch` tools already use for a two-phase
27
+ * write (pause a task in one phase, start one in another) — collect the
28
+ * exact task objects removed from each source phase, and if any later step
29
+ * throws, add them straight back rather than reconstructing the phase's
30
+ * task array (which could clobber a concurrent unrelated write to that
31
+ * file).
32
+ */
33
+ import type { PlanStore } from "./plan-store.js";
34
+ import type { MutationReply } from "./mutation-reply.js";
35
+ export type MoveTasksErrorCode = "NO_TASKS_GIVEN" | "TARGET_PHASE_NOT_FOUND" | "TASK_NOT_FOUND" | "SOURCE_EQUALS_TARGET" | "TARGET_PHASE_TERMINAL";
36
+ /** One moved task, named only by ref/identity — never its description,
37
+ * checklist, statusLog or any other field a caller already has. */
38
+ export interface TaskMoveSummary {
39
+ taskId: string;
40
+ shortId: string;
41
+ title: string;
42
+ status: string;
43
+ oldRef: string;
44
+ newRef: string;
45
+ }
46
+ export interface MoveTasksResult {
47
+ targetPhaseRef: string;
48
+ moves: TaskMoveSummary[];
49
+ /** Refs of source phases that had a pending handoff at the time of the
50
+ * move. A handoff is free prose and may name the moved task by ref; it
51
+ * is NOT rewritten here (see buildTaskMoveReply — the reply just flags
52
+ * it so a caller knows to check). */
53
+ sourcePhaseRefsWithHandoff: string[];
54
+ }
55
+ export type MoveTasksOutcome = {
56
+ ok: true;
57
+ result: MoveTasksResult;
58
+ } | {
59
+ ok: false;
60
+ errorCode: MoveTasksErrorCode;
61
+ error: string;
62
+ };
63
+ /**
64
+ * Move `taskIds` (task UUIDs, already resolved by the caller) into
65
+ * `targetPhaseId` (a phase UUID). Validates target-exists, source != target
66
+ * per task, and refuses a terminal target phase — a terminal phase is
67
+ * closed, and reopening it by dropping new work in is not this operation's
68
+ * job (accepted decision on P108(F005)/T443: no override flag; unlink or
69
+ * reopen the phase first). An in-progress task MAY move; the reply says so.
70
+ */
71
+ export declare function moveTasks(store: PlanStore, taskIds: string[], targetPhaseId: string, timestamp?: string): Promise<MoveTasksOutcome>;
72
+ /**
73
+ * The one reply planner-task-move / task_move return. Deliberately NOT
74
+ * built with buildMutationReply: that helper echoes one entity's changed
75
+ * field values, and the only value that changed here — phaseId — is not
76
+ * something a caller refers to directly. What a caller needs per task is
77
+ * its old ref, its new ref, and enough identity (id/shortId/title/status)
78
+ * to confirm it moved — never the description, checklist or statusLog it
79
+ * already has and did not ask to resend.
80
+ */
81
+ export declare function buildTaskMoveReply(result: MoveTasksResult, readBackCommand: string): MutationReply;
82
+ //# sourceMappingURL=task-move.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-move.d.ts","sourceRoot":"","sources":["../src/task-move.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,MAAM,kBAAkB,GAC1B,gBAAgB,GAChB,wBAAwB,GACxB,gBAAgB,GAChB,sBAAsB,GACtB,uBAAuB,CAAC;AAM5B;oEACoE;AACpE,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB;;;0CAGsC;IACtC,0BAA0B,EAAE,MAAM,EAAE,CAAC;CACtC;AAED,MAAM,MAAM,gBAAgB,GACxB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GACrC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,kBAAkB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAMhE;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,MAAM,EAAE,EACjB,aAAa,EAAE,MAAM,EACrB,SAAS,SAA2B,GACnC,OAAO,CAAC,gBAAgB,CAAC,CA4H3B;AAOD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,GAAG,aAAa,CAuBlG"}
@@ -0,0 +1,169 @@
1
+ import { createStatusLogEntryId, featureNumberOfPhase, formatPhaseRef, formatThreeDigitNumber } from "./naming.js";
2
+ /** Phase statuses a task cannot be moved into. Same terminal set as tasks
3
+ * (done/canceled/rejected) — a terminal phase is meant to stay closed. */
4
+ const TERMINAL_PHASE_STATUSES = new Set(["done", "canceled", "rejected"]);
5
+ function taskRef(task, phase, features) {
6
+ return `${formatPhaseRef(phase.number, featureNumberOfPhase(phase, features))}/T${formatThreeDigitNumber(task.number)}`;
7
+ }
8
+ /**
9
+ * Move `taskIds` (task UUIDs, already resolved by the caller) into
10
+ * `targetPhaseId` (a phase UUID). Validates target-exists, source != target
11
+ * per task, and refuses a terminal target phase — a terminal phase is
12
+ * closed, and reopening it by dropping new work in is not this operation's
13
+ * job (accepted decision on P108(F005)/T443: no override flag; unlink or
14
+ * reopen the phase first). An in-progress task MAY move; the reply says so.
15
+ */
16
+ export async function moveTasks(store, taskIds, targetPhaseId, timestamp = new Date().toISOString()) {
17
+ const uniqueTaskIds = [...new Set(taskIds)];
18
+ if (uniqueTaskIds.length === 0) {
19
+ return { ok: false, errorCode: "NO_TASKS_GIVEN", error: "No task ids given to move." };
20
+ }
21
+ return store.runBatch(async () => {
22
+ const [phases, featuresDoc] = await Promise.all([store.loadAllPhases(), store.loadFeatures()]);
23
+ const features = featuresDoc.features;
24
+ const targetPhase = phases.find((phase) => phase.id === targetPhaseId);
25
+ if (!targetPhase) {
26
+ return { ok: false, errorCode: "TARGET_PHASE_NOT_FOUND", error: `Target phase not found: ${targetPhaseId}` };
27
+ }
28
+ if (TERMINAL_PHASE_STATUSES.has(targetPhase.status)) {
29
+ const targetRef = formatPhaseRef(targetPhase.number, featureNumberOfPhase(targetPhase, features));
30
+ return {
31
+ ok: false,
32
+ errorCode: "TARGET_PHASE_TERMINAL",
33
+ error: `Target phase ${targetRef} is ${targetPhase.status}; cannot move tasks into a terminal phase.`,
34
+ };
35
+ }
36
+ const targetPhaseRef = formatPhaseRef(targetPhase.number, featureNumberOfPhase(targetPhase, features));
37
+ const allTasks = phases.flatMap((phase) => phase.tasks.map((task) => ({ phase, task })));
38
+ const located = [];
39
+ for (const taskId of uniqueTaskIds) {
40
+ const hit = allTasks.find((entry) => entry.task.id === taskId);
41
+ if (!hit)
42
+ return { ok: false, errorCode: "TASK_NOT_FOUND", error: `Task not found: ${taskId}` };
43
+ if (hit.phase.id === targetPhaseId) {
44
+ return {
45
+ ok: false,
46
+ errorCode: "SOURCE_EQUALS_TARGET",
47
+ error: `Task ${taskRef(hit.task, hit.phase, features)} is already in ${targetPhaseRef}.`,
48
+ };
49
+ }
50
+ located.push(hit);
51
+ }
52
+ // Group by source phase so a multi-source move removes each phase's
53
+ // tasks in one write, and rollback restores exactly what was removed.
54
+ const bySourcePhase = new Map();
55
+ for (const entry of located) {
56
+ const bucket = bySourcePhase.get(entry.phase.id) ?? { phase: entry.phase, tasks: [] };
57
+ bucket.tasks.push(entry.task);
58
+ bySourcePhase.set(entry.phase.id, bucket);
59
+ }
60
+ const writtenSourcePhaseIds = [];
61
+ const summaries = [];
62
+ const sourcePhaseRefsWithHandoff = [...bySourcePhase.values()]
63
+ .filter((bucket) => bucket.phase.handoff !== "")
64
+ .map((bucket) => formatPhaseRef(bucket.phase.number, featureNumberOfPhase(bucket.phase, features)));
65
+ try {
66
+ for (const [sourcePhaseId, bucket] of bySourcePhase) {
67
+ const idsToRemove = new Set(bucket.tasks.map((task) => task.id));
68
+ await store.updatePhase(sourcePhaseId, (phase) => {
69
+ phase.tasks = phase.tasks.filter((task) => !idsToRemove.has(task.id));
70
+ return phase;
71
+ });
72
+ writtenSourcePhaseIds.push(sourcePhaseId);
73
+ }
74
+ const movedTasks = located.map(({ phase: sourcePhase, task }) => {
75
+ const oldRef = taskRef(task, sourcePhase, features);
76
+ const newRef = `${targetPhaseRef}/T${formatThreeDigitNumber(task.number)}`;
77
+ summaries.push({ taskId: task.id, shortId: task.shortId, title: task.title, status: task.status, oldRef, newRef });
78
+ return {
79
+ ...task,
80
+ phaseId: targetPhaseId,
81
+ statusLog: [...task.statusLog, {
82
+ id: createStatusLogEntryId(),
83
+ date: timestamp,
84
+ fromStatus: task.status,
85
+ toStatus: task.status,
86
+ title: `moved ${oldRef} → ${newRef}`,
87
+ description: `Moved from ${oldRef} to ${newRef}; status unchanged.`,
88
+ }],
89
+ updatedAt: timestamp,
90
+ };
91
+ });
92
+ await store.updatePhase(targetPhaseId, (phase) => {
93
+ phase.tasks = [...phase.tasks, ...movedTasks];
94
+ return phase;
95
+ });
96
+ }
97
+ catch (error) {
98
+ // Roll back every source phase already written. Add the ORIGINAL task
99
+ // objects back rather than restoring a whole array snapshot, so a
100
+ // concurrent unrelated write to the same file (another task added or
101
+ // edited while this move was in flight) is not clobbered.
102
+ for (const sourcePhaseId of writtenSourcePhaseIds) {
103
+ const bucket = bySourcePhase.get(sourcePhaseId);
104
+ if (!bucket)
105
+ continue;
106
+ await store.updatePhase(sourcePhaseId, (phase) => {
107
+ phase.tasks = [...phase.tasks, ...bucket.tasks];
108
+ return phase;
109
+ }).catch(() => { });
110
+ }
111
+ throw error;
112
+ }
113
+ // Roll up derived status the same way every other task mutation does:
114
+ // a phase whose task count just changed may have crossed into or out of
115
+ // a terminal status (handoff archiving, phase/feature statusLog, resume
116
+ // refresh all live in syncTaskStatusRollup — callers must not reimplement
117
+ // them). Every touched phase gets it, not just the target.
118
+ for (const sourcePhaseId of writtenSourcePhaseIds) {
119
+ await store.syncTaskStatusRollup(sourcePhaseId);
120
+ }
121
+ await store.syncTaskStatusRollup(targetPhaseId);
122
+ await store.writeGenerated();
123
+ // Prove it happened: re-read from disk rather than trusting the
124
+ // in-memory write — same discipline as deleteFeatureCascade.
125
+ const persistedTarget = await store.loadPhase(targetPhaseId);
126
+ const persistedIds = new Set(persistedTarget.tasks.map((task) => task.id));
127
+ if (summaries.some((move) => !persistedIds.has(move.taskId))) {
128
+ return { ok: false, errorCode: "TASK_NOT_FOUND", error: `Task move did not persist to ${targetPhaseRef}.` };
129
+ }
130
+ return { ok: true, result: { targetPhaseRef, moves: summaries, sourcePhaseRefsWithHandoff } };
131
+ });
132
+ }
133
+ /** Cap on how many moved tasks a reply names individually. Moving one task
134
+ * or a handful (the documented case) always prints every ref; a very large
135
+ * batch degrades to a count rather than growing the reply without bound. */
136
+ const MAX_TASK_MOVE_REPLY_ITEMS = 20;
137
+ /**
138
+ * The one reply planner-task-move / task_move return. Deliberately NOT
139
+ * built with buildMutationReply: that helper echoes one entity's changed
140
+ * field values, and the only value that changed here — phaseId — is not
141
+ * something a caller refers to directly. What a caller needs per task is
142
+ * its old ref, its new ref, and enough identity (id/shortId/title/status)
143
+ * to confirm it moved — never the description, checklist or statusLog it
144
+ * already has and did not ask to resend.
145
+ */
146
+ export function buildTaskMoveReply(result, readBackCommand) {
147
+ const shown = result.moves.slice(0, MAX_TASK_MOVE_REPLY_ITEMS);
148
+ const omitted = result.moves.length - shown.length;
149
+ const lines = shown.map((move) => `${move.oldRef} → ${move.newRef} — ${move.title} [${move.status}]${move.shortId ? ` · ${move.shortId}` : ""}`);
150
+ const handoffNotice = result.sourcePhaseRefsWithHandoff.length > 0
151
+ ? [`⚠️ Pending handoff on ${result.sourcePhaseRefsWithHandoff.join(", ")} may reference the moved task(s) by ref; it is prose and was not rewritten — check it.`]
152
+ : [];
153
+ const text = [
154
+ `✅ Moved ${result.moves.length} task(s) to ${result.targetPhaseRef}:`,
155
+ ...lines,
156
+ ...(omitted > 0 ? [`(+${omitted} more)`] : []),
157
+ ...handoffNotice,
158
+ `Read back: ${readBackCommand}`,
159
+ ].join("\n");
160
+ const structured = {
161
+ moved: true,
162
+ targetPhaseRef: result.targetPhaseRef,
163
+ moves: shown.map((move) => ({ id: move.taskId, shortId: move.shortId, title: move.title, status: move.status, oldRef: move.oldRef, newRef: move.newRef })),
164
+ ...(omitted > 0 ? { omittedMoves: omitted } : {}),
165
+ ...(result.sourcePhaseRefsWithHandoff.length > 0 ? { sourcePhaseRefsWithHandoff: result.sourcePhaseRefsWithHandoff } : {}),
166
+ readBack: readBackCommand,
167
+ };
168
+ return { text, structured };
169
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-plan/core",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "private": false,
5
5
  "description": "Harness-agnostic core for Agent Plan: schemas, persistence, ordering, status rollups, and markdown rendering.",
6
6
  "license": "MIT",
package/planner-skill.md CHANGED
@@ -86,6 +86,7 @@ A decision has exactly one owner: the project when it is project-wide, a feature
86
86
  - A temporary task completion can emit `RESUME REQUIRED`. Resume the preserved source or deliberately switch again; do not silently abandon it.
87
87
  - Complete a task only after implementation and verification. Supply durable completion evidence, files touched, decisions, remaining or unverified work, and updated code references.
88
88
  - Status changes to `blocked`, `canceled`, `rejected`, `deferred`, `waiting`, or back to `planned` require a substantive motivation on agent surfaces.
89
+ - A task that belongs in a different phase is moved with `task_move` / `planner-task-move`, never recreated. Recreating loses the id, statusLog, checklist, accepted decisions, pause history, and every `dependsOn` edge pointing at it; moving keeps all of it and only the composite ref changes. Pass refs only — the move never needs the task's description.
89
90
 
90
91
  ## Mutation integrity and oversized descriptions
91
92
 
@@ -217,7 +218,7 @@ The MCP adapter publishes these tools:
217
218
  - Project: `planner-project-language`, `planner-project-discuss`, `planner-project-guidelines-show`, `planner-project-guidelines-update`, `planner-project-context-migrate`, `planner-accepted-decision-create`, `planner-accepted-decision-update`, `planner-accepted-decision-delete`, `planner-requirement-list`, `planner-requirement-create`, `planner-requirement-update`, `planner-requirement-delete`.
218
219
  - Features: `planner-feature-list`, `planner-feature-add`, `planner-feature-show`, `planner-feature-discuss`, `planner-feature-update`, `planner-feature-delete`.
219
220
  - Phases: `planner-phase-list`, `planner-phase-add`, `planner-phase-show`, `planner-phase-discuss`, `planner-phase-update`, `planner-phase-delete`.
220
- - Tasks: `planner-task-list`, `planner-task-add`, `planner-task-show`, `planner-task-discuss`, `planner-task-update`, `planner-task-dependency-add`, `planner-task-dependency-delete`, `planner-task-delete`, `planner-task-recommend`, `planner-task-deviation`, `planner-task-pause`, `planner-task-switch`, `planner-task-start`, `planner-task-reopen`, `planner-task-complete`, `planner-task-checklist-toggle`, `planner-task-checklist-add`, `planner-task-checklist-remove`.
221
+ - Tasks: `planner-task-list`, `planner-task-add`, `planner-task-show`, `planner-task-discuss`, `planner-task-update`, `planner-task-move`, `planner-task-dependency-add`, `planner-task-dependency-delete`, `planner-task-delete`, `planner-task-recommend`, `planner-task-deviation`, `planner-task-pause`, `planner-task-switch`, `planner-task-start`, `planner-task-reopen`, `planner-task-complete`, `planner-task-checklist-toggle`, `planner-task-checklist-add`, `planner-task-checklist-remove`.
221
222
  - Handoffs: `planner-handoff-list`, `planner-handoff-show`, `planner-handoff-prepare`, `planner-handoff-write`, `planner-handoff-verify`, `planner-handoff-clear`.
222
223
 
223
224
  ## Pi tool inventory
@@ -229,7 +230,7 @@ The Pi adapter registers these tools:
229
230
  - Plan: `plan_init`, `plan_get`, `description_freshness`, `plan_render`, `plan_repair`, `plan_cleanup_orphan_phases`, `plan_authorize_bypass`, `plan_clear_bypass`.
230
231
  - Features: `feature_list`, `feature_get`, `feature_create`, `feature_discuss`, `feature_update`, `feature_delete`.
231
232
  - Phases: `phase_list`, `phase_get`, `phase_create`, `phase_discuss`, `phase_update`, `phase_delete`, `decision_record` (deprecated, write-disabled compatibility redirect — see Accepted Decision ownership).
232
- - Tasks: `task_list`, `task_get`, `task_create`, `task_update`, `task_dependency_add`, `task_dependency_delete`, `task_delete`, `task_recommend`, `task_deviation`, `task_pause`, `task_switch`, `task_start`, `task_reopen`, `task_complete`, `task_checklist_toggle`, `task_checklist_add`, `task_checklist_remove`.
233
+ - Tasks: `task_list`, `task_get`, `task_create`, `task_update`, `task_move`, `task_dependency_add`, `task_dependency_delete`, `task_delete`, `task_recommend`, `task_deviation`, `task_pause`, `task_switch`, `task_start`, `task_reopen`, `task_complete`, `task_checklist_toggle`, `task_checklist_add`, `task_checklist_remove`.
233
234
  - Handoffs: `handoff_list`, `handoff_show`, `handoff_prepare`, `handoff_write`, `handoff_verify`, `handoff_clear`.
234
235
  - Dashboard and lifecycle: `planner-web`, `planner-load`, `planner-stop`.
235
236
  - Deprecated compatibility aliases: `plan_get_handoff`, `plan_write_handoff`, `plan_delete_handoff`. Prefer the entity-scoped handoff tools.