pi-task-tracker 0.1.1 → 0.1.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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/index.ts +58 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -7,7 +7,7 @@ Task workflow tracking for the [pi coding agent](https://www.npmjs.com/package/@
7
7
  - **TODO.md tracking** — each prompt is recorded as a task entry in `TODO.md` and checked off when the agent settles.
8
8
  - **README.md maintenance** — the project structure section stays up to date with agent-created files.
9
9
  - **Per-task git auto-commit** — when a task completes, only the files the agent actually touched are staged and committed with the task as the message. Nothing else is swept in.
10
- - **`/rollback`** — pick any prior commit interactively and the working tree is restored to that point. Worktree-only, nothing is committed, fully reversible (`git diff` to review, commit when satisfied).
10
+ - **`/rollback`** — pick any prior commit interactively and the working tree is restored to that point **while the conversation rewinds to the turn that produced it** (one checkpoint for files *and* context). Worktree-only, nothing is committed, fully reversible (`git diff` to review, commit when satisfied). Old session branches are preserved — `/tree` can navigate back.
11
11
 
12
12
  ### What makes it different
13
13
 
@@ -26,7 +26,7 @@ Task workflow tracking for the [pi coding agent](https://www.npmjs.com/package/@
26
26
  → confirm → working tree restored to that commit
27
27
  ```
28
28
 
29
- Conservative by design: the index is untouched, the rollback itself is never auto-committed, and untracked files are out of scope (they were never committed, so their provenance is unknown).
29
+ Conservative by design: the index is untouched, the rollback itself is never auto-committed, and untracked files are out of scope (they were never committed, so their provenance is unknown). Conversation rewind reuses pi's session-tree navigation, so nothing is ever deleted from the session file.
30
30
 
31
31
  ## Configuration
32
32
 
@@ -60,7 +60,7 @@ Optional `taskTracker` key in `~/.pi/agent/settings.json` (all default to `true`
60
60
 
61
61
  ## 本简介(中文)
62
62
 
63
- `pi-task-tracker` 为 pi coding agent 提供任务级工作流跟踪:每次任务完成时,agent 实际改动的文件被自动提交到你的分支(提交信息即任务名),这些提交同时构成检查点;`/rollback` 可交互式地把工作区回滚到任意历史提交(仅工作区、不自动提交、可逆)。支持 hashline 编辑工具、bash/powershell 产物捕获、嵌套仓库归属最内层、自动排除 `.pi-subagents/` 会话数据。配置项见上方 `taskTracker`。
63
+ `pi-task-tracker` 为 pi coding agent 提供任务级工作流跟踪:每次任务完成时,agent 实际改动的文件被自动提交到你的分支(提交信息即任务名),这些提交同时构成检查点;`/rollback` 可交互式地把工作区回滚到任意历史提交,**同时把对话上下文回退到产生该提交的任务轮次**(文件与上下文同一检查点;仅工作区、不自动提交、可逆,旧会话分支保留可 /tree 回访)。支持 hashline 编辑工具、bash/powershell 产物捕获、嵌套仓库归属最内层、自动排除 `.pi-subagents/` 会话数据。配置项见上方 `taskTracker`。
64
64
 
65
65
  ## License
66
66
 
package/index.ts CHANGED
@@ -212,6 +212,20 @@ function normalizeReadme(readmePath: string, name: string): void {
212
212
  } catch {}
213
213
  }
214
214
 
215
+ // ---- Session helpers ----
216
+ // Flatten an AgentMessage's content to plain text (string or content blocks).
217
+ function messageText(m: { content?: unknown }): string {
218
+ const c = (m as { content?: unknown }).content;
219
+ if (typeof c === "string") return c;
220
+ if (Array.isArray(c)) {
221
+ return c
222
+ .filter((b) => b && typeof b === "object" && (b as { type?: string }).type === "text")
223
+ .map((b) => String((b as { text?: string }).text ?? ""))
224
+ .join(" ");
225
+ }
226
+ return "";
227
+ }
228
+
215
229
  // ---- Configuration ----
216
230
  // Optional `taskTracker` key in ~/.pi/agent/settings.json (env
217
231
  // PI_CODING_AGENT_DIR respected). All flags default to true.
@@ -555,7 +569,50 @@ export default function (pi: ExtensionAPI) {
555
569
  createdFiles.length = 0;
556
570
  editedFiles.length = 0;
557
571
  beforeStatus.clear();
558
- ctx.ui.notify(`Rolled back to ${target.sha} - worktree updated, nothing committed. Review with git diff, then commit when satisfied.`, "info");
572
+
573
+ // 6. rewind the conversation to the turn that produced this commit, so
574
+ // context and files land on the same checkpoint. The task commit's
575
+ // subject is the (normalized) user prompt, so match the last user
576
+ // message starting with it, then the end of that turn. Old entries stay
577
+ // in the session tree — /tree can navigate back at any time.
578
+ let conversationNote = "";
579
+ try {
580
+ const subject = git(["show", "-s", "--format=%s", target.sha], cwd);
581
+ if (subject && ctx.sessionManager) {
582
+ const norm = (t: string) => t.replace(/\s+/g, " ").trim();
583
+ const branch = ctx.sessionManager.getBranch();
584
+ let userIdx = -1;
585
+ for (let i = branch.length - 1; i >= 0; i--) {
586
+ const e = branch[i] as { type?: string; message?: { role?: string; content?: unknown } };
587
+ if (e.type !== "message" || e.message?.role !== "user") continue;
588
+ if (norm(messageText(e.message as { content?: unknown })).startsWith(norm(subject))) {
589
+ userIdx = i;
590
+ break;
591
+ }
592
+ }
593
+ if (userIdx !== -1) {
594
+ // end of that turn = last entry before the next user message
595
+ let end = userIdx;
596
+ for (let j = userIdx + 1; j < branch.length; j++) {
597
+ const e = branch[j] as { type?: string; message?: { role?: string } };
598
+ if (e.type === "message" && e.message?.role === "user") break;
599
+ end = j;
600
+ }
601
+ const targetId = branch[end].id;
602
+ const nav = ctx.navigateTree
603
+ ? await ctx.navigateTree(targetId, { label: `rollback → ${target.sha}` })
604
+ : { cancelled: false };
605
+ if (!nav.cancelled) {
606
+ conversationNote = " Conversation rewound to that point (/tree can navigate back).";
607
+ }
608
+ } else {
609
+ conversationNote = " (No matching conversation entry found - context unchanged.)";
610
+ }
611
+ }
612
+ } catch {
613
+ conversationNote = " (Conversation rewind failed - files were rolled back.)";
614
+ }
615
+ ctx.ui.notify(`Rolled back to ${target.sha} - worktree updated, nothing committed. Review with git diff, then commit when satisfied.${conversationNote}`, "info");
559
616
  },
560
617
  });
561
618
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-task-tracker",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Task workflow tracking for the pi coding agent: TODO/README maintenance, per-task git auto-commits as checkpoints, and an interactive /rollback. Hashline-aware, nested-repo aware, subagent-artifact-safe.",
5
5
  "keywords": [
6
6
  "pi-package",