pi-auto-save-to-markdown 0.8.1 → 0.8.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/README.md CHANGED
@@ -28,6 +28,10 @@ pi install npm:pi-auto-save-to-markdown
28
28
  Automatic: after every settled agent turn (`agent_settled`), the current
29
29
  conversation branch is written to `<cwd>/<folder>/<title>-<key>-<time>.md`.
30
30
 
31
+ Sessions Pi does not persist (in-memory, `--no-session` — including the
32
+ ephemeral auxiliary agents host clients spawn next to the real conversation,
33
+ such as Claudian's title generation) are skipped by every automatic save; only
34
+ the explicit `/save-conversation` command archives such a session on demand.
31
35
  Manual: run `/save-conversation` to save the current branch immediately and
32
36
  report the file path.
33
37
 
package/README.zh.md CHANGED
@@ -21,6 +21,10 @@ pi install npm:pi-auto-save-to-markdown
21
21
 
22
22
  自动:每个 agent 轮次完全结束(`agent_settled`,含自动重试与压缩全部完成)后,当前对话分支写入 `<cwd>/<文件夹>/<标题>-<key>-<时间>.md`。
23
23
 
24
+ Pi 未持久化的会话(内存态、`--no-session`——包括宿主客户端在真实对话旁派生的临时辅助
25
+ agent,例如 Claudian 的标题生成)会被所有自动保存路径跳过;只有显式的
26
+ `/save-conversation` 命令才会按需归档此类会话。
27
+
24
28
  手动:运行 `/save-conversation` 立即保存当前分支并显示文件路径。
25
29
 
26
30
  批量:运行 `/save-conversation-all` 保存**当前项目的全部 session**——即项目的
package/index.ts CHANGED
@@ -9,6 +9,15 @@
9
9
  * - Trigger: `agent_settled` — fires once per user prompt, after the turn is
10
10
  * fully done (including automatic retries and compaction), so each save
11
11
  * captures a settled state of the conversation.
12
+ * - Skip rule: every automatic path (the `agent_settled` save and the batch
13
+ * command's live save) skips sessions Pi does not persist — no session
14
+ * file, i.e. an in-memory SessionManager (`--no-session`): those are
15
+ * ephemeral auxiliary agents host clients spawn next to the real
16
+ * conversation (Claudian's title generation, instruction refinement,
17
+ * inline edits) or one-shot `pi --no-session` runs, not project
18
+ * conversations, and archiving them would mint junk "User's request …"
19
+ * files. The manual /save-conversation command still saves such a session
20
+ * on explicit demand; the batch never sees them (no jsonl on disk).
12
21
  * - Location: a subfolder of the session's working directory (`ctx.cwd`, the
13
22
  * directory the session was started in), defaulting to `ai-conversations`.
14
23
  * Override with the PI_SAVE_CONVERSATION_DIR environment variable; set it to
@@ -1925,6 +1934,15 @@ export default function (pi: ExtensionAPI) {
1925
1934
 
1926
1935
  // 1. Automatic: save after every settled agent turn.
1927
1936
  pi.on("agent_settled", async (_event: AgentSettledEvent, ctx: ExtensionContext) => {
1937
+ // Non-persisted sessions (in-memory, `--no-session`) are ephemeral
1938
+ // auxiliary agents — see the skip rule in the header. The manual
1939
+ // /save-conversation command below is the explicit-demand escape hatch.
1940
+ if (!ctx.sessionManager.getSessionFile()) {
1941
+ debug(
1942
+ "agent_settled — session has no session file (in-memory / --no-session); skipping auto-save",
1943
+ );
1944
+ return;
1945
+ }
1928
1946
  debug("agent_settled — saving conversation");
1929
1947
  try {
1930
1948
  const live = liveContext(ctx);
@@ -2005,28 +2023,36 @@ export default function (pi: ExtensionAPI) {
2005
2023
 
2006
2024
  // The live session first, through the normal path: its in-memory tree may
2007
2025
  // be fresher than disk, and its state entry goes through pi.appendEntry.
2008
- try {
2009
- const r = await runSave(live);
2010
- count(r);
2011
- if (ctx.hasUI) {
2012
- const target = r.file ? relativeForUser(live, r.file) : "";
2013
- ctx.ui.notify(`${NOTIFY_TAG} ${r.message}${target ? ` → ${target}` : ""}`, "info");
2014
- if (r.recovered && r.file) {
2015
- ctx.ui.notify(`${NOTIFY_TAG} ${r.recovered} → ${target}`, "warning");
2026
+ // A non-persisted current session (in-memory / --no-session) is skipped —
2027
+ // see the skip rule in the header.
2028
+ if (!ctx.sessionManager.getSessionFile()) {
2029
+ debug(
2030
+ "/" + COMMAND_ALL + " — current session not persisted (in-memory / --no-session); skipped",
2031
+ );
2032
+ } else {
2033
+ try {
2034
+ const r = await runSave(live);
2035
+ count(r);
2036
+ if (ctx.hasUI) {
2037
+ const target = r.file ? relativeForUser(live, r.file) : "";
2038
+ ctx.ui.notify(`${NOTIFY_TAG} ${r.message}${target ? ` → ${target}` : ""}`, "info");
2039
+ if (r.recovered && r.file) {
2040
+ ctx.ui.notify(`${NOTIFY_TAG} ${r.recovered} → ${target}`, "warning");
2041
+ }
2042
+ if (r.switchedFrom && r.file) {
2043
+ ctx.ui.notify(
2044
+ `${NOTIFY_TAG} branch changed — new branch file ${target}; the earlier branch file ${r.switchedFrom} is kept`,
2045
+ "info",
2046
+ );
2047
+ }
2016
2048
  }
2017
- if (r.switchedFrom && r.file) {
2018
- ctx.ui.notify(
2019
- `${NOTIFY_TAG} branch changed — new branch file ${target}; the earlier branch file ${r.switchedFrom} is kept`,
2020
- "info",
2021
- );
2049
+ } catch (e) {
2050
+ failed.push("<current session>");
2051
+ debug("/" + COMMAND_ALL + " live save failed:", String(e));
2052
+ if (ctx.hasUI) {
2053
+ ctx.ui.notify(`${NOTIFY_TAG} save failed: ${String(e)}`, "error");
2022
2054
  }
2023
2055
  }
2024
- } catch (e) {
2025
- failed.push("<current session>");
2026
- debug("/" + COMMAND_ALL + " live save failed:", String(e));
2027
- if (ctx.hasUI) {
2028
- ctx.ui.notify(`${NOTIFY_TAG} save failed: ${String(e)}`, "error");
2029
- }
2030
2056
  }
2031
2057
 
2032
2058
  // The project's sessions directory — every session jsonl lives there.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-auto-save-to-markdown",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Pi extension that automatically saves each completed conversation turn as a markdown file with YAML frontmatter, one file per session-tree branch.",
5
5
  "type": "module",
6
6
  "license": "MIT",