pi-auto-save-to-markdown 0.8.0 → 0.8.1
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 +17 -10
- package/README.zh.md +13 -8
- package/index.ts +16 -7
- package/markdown.ts +86 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,7 +92,7 @@ changes never touch the filename, and manually renamed files are left alone.
|
|
|
92
92
|
---
|
|
93
93
|
title: "Fix login redirect loop"
|
|
94
94
|
agent: "pi"
|
|
95
|
-
format_version: "1.
|
|
95
|
+
format_version: "1.5"
|
|
96
96
|
session_id: "d0a4f541-976d-4d1b-8e1c-30a1f2b3c4d5"
|
|
97
97
|
session_key: "c2088d77"
|
|
98
98
|
branch_last_entry_id: "019be3a2-1f4d-7c8a-9b01-d23e45f6a7b8"
|
|
@@ -119,7 +119,7 @@ User <span style="font-size: 0.5em; color: var(--text-faint);">2026-08-29 13:05:
|
|
|
119
119
|
The login page redirects in a loop after the auth refactor...
|
|
120
120
|
|
|
121
121
|
> [!quote]- Editor Selection
|
|
122
|
-
>
|
|
122
|
+
> [[src/auth/middleware.ts|middleware.ts]] · **lines**: `14-22`
|
|
123
123
|
>
|
|
124
124
|
> export function middleware(request) { … }
|
|
125
125
|
|
|
@@ -158,14 +158,21 @@ editor's active selection, attached or referenced notes, loaded skills — are
|
|
|
158
158
|
re-rendered from their raw XML (which Obsidian cannot render and would show
|
|
159
159
|
as literal angle-bracket text) into generic callouts. No block is parsed
|
|
160
160
|
individually: the title is the tag name in words (`editor_selection` →
|
|
161
|
-
Editor Selection),
|
|
162
|
-
(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
161
|
+
Editor Selection), and the body opens with vault-shaped `path`/`location`
|
|
162
|
+
values as bare Obsidian wikilinks (the aliased filename speaks for itself —
|
|
163
|
+
no `path:` label), followed by the remaining attributes as
|
|
164
|
+
`**name**: value` items, then the content. Every callout is preset-collapsed
|
|
165
|
+
— user-provided blocks (selections, note attachments) as `> [!quote]-`, even
|
|
166
|
+
when they carry only attributes (the client emits note references as
|
|
167
|
+
self-closing tags carrying just a path), agent-side skill traces as a
|
|
168
|
+
`> [!note]- Skill · <name>` marker (the loaded skill's name rides the title,
|
|
169
|
+
so the collapsed marker still says which skill; the location follows in the
|
|
170
|
+
body, the content is dropped) — and consecutive blocks of
|
|
171
|
+
the same tag (nothing but whitespace between them) merge into one callout,
|
|
172
|
+
so a run of note references collapses into a single list. Unknown markup is
|
|
173
|
+
left verbatim, so XML pasted as content is never mangled — and the fallback
|
|
174
|
+
filename slug derives from the typed message with every known block
|
|
175
|
+
stripped.
|
|
169
176
|
|
|
170
177
|
Each message block opens with a setext level-1 info header (`User`,
|
|
171
178
|
`Assistant`) underlined with `===` — one level above the `##` headings AI
|
package/README.zh.md
CHANGED
|
@@ -66,7 +66,7 @@ PI_SAVE_CONVERSATION_DIR=notes/ai pi
|
|
|
66
66
|
---
|
|
67
67
|
title: "修复登录重定向死循环"
|
|
68
68
|
agent: "pi"
|
|
69
|
-
format_version: "1.
|
|
69
|
+
format_version: "1.5"
|
|
70
70
|
session_id: "d0a4f541-976d-4d1b-8e1c-30a1f2b3c4d5"
|
|
71
71
|
session_key: "c2088d77"
|
|
72
72
|
branch_last_entry_id: "019be3a2-1f4d-7c8a-9b01-d23e45f6a7b8"
|
|
@@ -93,7 +93,7 @@ User <span style="font-size: 0.5em; color: var(--text-faint);">2026-08-29 13:05:
|
|
|
93
93
|
auth 重构之后登录页一直重定向死循环……
|
|
94
94
|
|
|
95
95
|
> [!quote]- Editor Selection
|
|
96
|
-
>
|
|
96
|
+
> [[src/auth/middleware.ts|middleware.ts]] · **lines**: `14-22`
|
|
97
97
|
>
|
|
98
98
|
> export function middleware(request) { … }
|
|
99
99
|
|
|
@@ -128,12 +128,17 @@ Markdown 解析。
|
|
|
128
128
|
客户端或 agent 注入到用户消息中的提示块——编辑器当前选区、附加或引用的
|
|
129
129
|
笔记、加载的 skill——会从原始 XML(Obsidian 无法渲染,只会显示成裸露的
|
|
130
130
|
尖括号文本)重新渲染为通用 callout。不做任何逐块解析:标题取标记名的分词
|
|
131
|
-
(`editor_selection` → Editor Selection
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
(`editor_selection` → Editor Selection),正文以形似 vault 相对笔记路径的
|
|
132
|
+
`path`/`location` 值开头——直接渲染为不带标签的 Obsidian wikilink(别名
|
|
133
|
+
文件名自解释,`path:` 标签反而冗余),其余属性以 `**属性**: 值` 跟随,
|
|
134
|
+
最后是引用内容。所有 callout 一律预设折叠——用户提供的块(选区、笔记附件)
|
|
135
|
+
为 `> [!quote]-`(仅有属性的自闭合笔记引用同样折叠),agent 侧痕迹(skill)
|
|
136
|
+
为 `> [!note]- Skill · <名称>` 标记(加载的 skill 名称直接进标题,折叠状态
|
|
137
|
+
也能看到是哪个 skill;location 跟在正文,内容丢弃);连续的同标签块(中间
|
|
138
|
+
只有空白)合并进同一个 callout,一串笔记引用因此收拢为一份列表(skill 标记
|
|
139
|
+
不合并:各自标注各自的 skill)。未知标记原样保留,用户粘贴的
|
|
140
|
+
XML 内容绝不会被误改;回退文件名 slug 也从剥离全部已知块后的纯键入文本
|
|
141
|
+
推导。
|
|
137
142
|
|
|
138
143
|
每个消息块以 setext 一级信息头(`User`、`Assistant`,下一行以 `===` 下划)
|
|
139
144
|
开头——高于 AI 内容常见的 `##` 二级标题,解析时也能与内容中的 `#` 一级标题
|
package/index.ts
CHANGED
|
@@ -61,12 +61,21 @@
|
|
|
61
61
|
* Obsidian cannot render (unknown tags are not HTML; CDATA is XML), so
|
|
62
62
|
* every block in a known vocabulary is re-rendered generically (see
|
|
63
63
|
* markdown.ts) — no per-tag formatting: the callout title is the tag name
|
|
64
|
-
* in words,
|
|
65
|
-
* (
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
64
|
+
* in words, the body opens with vault-shaped path/location values as
|
|
65
|
+
* bare wikilinks (the aliased filename is self-explanatory — a `path:`
|
|
66
|
+
* label is noise) followed by the remaining attributes as
|
|
67
|
+
* "**name**: value" lines, then the content (the client's `]]>`
|
|
68
|
+
* split-escaping reversed). Every callout is preset-collapsed: visible
|
|
69
|
+
* blocks (selections, note references, attachments) as `> [!quote]-`,
|
|
70
|
+
* whether they carry content or only attributes (the client emits note
|
|
71
|
+
* references as self-closing tags whose whole payload is a path
|
|
72
|
+
* attribute), agent-side traces (skills) as a `> [!note]- Skill · <name>`
|
|
73
|
+
* marker — the loaded skill's name rides the title so the collapsed
|
|
74
|
+
* marker still says which skill, the location follows in the body, the
|
|
75
|
+
* content is dropped — and consecutive visible same-tag blocks (nothing
|
|
76
|
+
* but whitespace between them) merge into one callout, so a run of note
|
|
77
|
+
* references collapses into a single list (skill markers never merge:
|
|
78
|
+
* each names its own skill). Title
|
|
70
79
|
* derivation strips every known block — the typed message is the title.
|
|
71
80
|
* Unknown markup is left verbatim so XML pasted as content is never
|
|
72
81
|
* mangled.
|
|
@@ -216,7 +225,7 @@ const SAVE_STATE_SCHEMA = "1.2";
|
|
|
216
225
|
* the frontmatter and the document heading); additive frontmatter fields do
|
|
217
226
|
* NOT bump it — they are invisible to any within-major parser.
|
|
218
227
|
*/
|
|
219
|
-
const FORMAT_VERSION = "1.
|
|
228
|
+
const FORMAT_VERSION = "1.5";
|
|
220
229
|
|
|
221
230
|
/**
|
|
222
231
|
* Package version of this extension, read best-effort from the adjacent
|
package/markdown.ts
CHANGED
|
@@ -54,8 +54,11 @@ export function callout(type: string, title: string, body: string, fold = true):
|
|
|
54
54
|
* references (linked_note / linked_content — the client's attachment
|
|
55
55
|
* mechanism; a typed @-mention stays as plain text in the message, these
|
|
56
56
|
* are the machine copy).
|
|
57
|
-
* - Hidden: agent-side traces (loaded skills) — rendered as a
|
|
58
|
-
*
|
|
57
|
+
* - Hidden: agent-side traces (loaded skills) — rendered as a folded
|
|
58
|
+
* `> [!note]- Skill · <name>` marker with the name riding the title
|
|
59
|
+
* (which skill was loaded is the marker's whole meaning and must survive
|
|
60
|
+
* the collapsed view), the content dropped (a skill is re-loadable from
|
|
61
|
+
* its location).
|
|
59
62
|
*
|
|
60
63
|
* Unknown tags are left verbatim: this is both the safety boundary against
|
|
61
64
|
* mangling pasted XML and a soft failure mode for future client tags (they
|
|
@@ -151,60 +154,105 @@ function wikilinkOf(path: string): string {
|
|
|
151
154
|
return base && base !== path ? `[[${path}|${base}]]` : `[[${path}]]`;
|
|
152
155
|
}
|
|
153
156
|
|
|
157
|
+
/** Whether an attribute renders as a bare wikilink (a vault-shaped path/location). */
|
|
158
|
+
function isWikilinkAttr(p: { name: string; value: string }): boolean {
|
|
159
|
+
return (p.name === "path" || p.name === "location") && isVaultNotePath(p.value);
|
|
160
|
+
}
|
|
161
|
+
|
|
154
162
|
/**
|
|
155
|
-
*
|
|
156
|
-
* like vault-relative note
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
163
|
+
* Attribute pairs of one injected block as body items: a `path`/`location`
|
|
164
|
+
* value shaped like a vault-relative note path becomes a BARE wikilink —
|
|
165
|
+
* no `**name**:` prefix, because the aliased filename is self-explanatory
|
|
166
|
+
* (the file is user-provided material) and the label only adds noise — and
|
|
167
|
+
* sorts first, so the reference leads the line; every other attribute stays
|
|
168
|
+
* a labeled `**name**: value` item in source order.
|
|
160
169
|
*/
|
|
161
|
-
function
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
170
|
+
function attrItems(attrs: string): string[] {
|
|
171
|
+
const pairs = parseAttrs(attrs);
|
|
172
|
+
return [
|
|
173
|
+
...pairs.filter(isWikilinkAttr).map((p) => wikilinkOf(p.value)),
|
|
174
|
+
...pairs.filter((p) => !isWikilinkAttr(p)).map((p) => `**${p.name}**: ${inlineCode(p.value)}`),
|
|
175
|
+
];
|
|
165
176
|
}
|
|
166
177
|
|
|
167
178
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
179
|
+
* Hidden block as its own self-contained marker callout: the `name`
|
|
180
|
+
* attribute joins the title — WHICH skill was loaded is the marker's whole
|
|
181
|
+
* meaning, and a collapsed `Skill` alone would say nothing — while the
|
|
182
|
+
* remaining attributes (the location) form the body and the content is
|
|
183
|
+
* dropped (a skill is re-loadable from its location). A hidden block with
|
|
184
|
+
* no attributes at all carries no information and is removed.
|
|
185
|
+
*/
|
|
186
|
+
function hiddenCallout(tag: string, attrs: string): string {
|
|
187
|
+
const pairs = parseAttrs(attrs);
|
|
188
|
+
if (pairs.length === 0) return "";
|
|
189
|
+
const name = pairs.find((p) => p.name === "name")?.value;
|
|
190
|
+
const body = pairs
|
|
191
|
+
.filter((p) => p.name !== "name")
|
|
192
|
+
.map((p) => (isWikilinkAttr(p) ? wikilinkOf(p.value) : `**${p.name}**: ${inlineCode(p.value)}`))
|
|
193
|
+
.join(" · ");
|
|
194
|
+
return callout("note", name ? `${tagTitle(tag)} · ${name}` : tagTitle(tag), body);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* One VISIBLE injected block's rendered body (no callout wrapper; hidden
|
|
199
|
+
* blocks render through hiddenCallout): the attribute items, then (after a
|
|
200
|
+
* blank line) the content.
|
|
177
201
|
*
|
|
178
202
|
* linked_note is the one content concession: its whole payload IS a note
|
|
179
203
|
* reference, so content shaped like a vault note path renders as a wikilink
|
|
180
204
|
* too — the same mechanical shape test, no semantics.
|
|
181
205
|
*/
|
|
182
|
-
function
|
|
183
|
-
const attrLine =
|
|
184
|
-
.map((p) => `**${p.name}**: ${formatAttrValue(p.name, p.value)}`)
|
|
185
|
-
.join(" · ");
|
|
186
|
-
const title = tagTitle(tag);
|
|
187
|
-
if (HIDDEN_TAGS.has(tag)) return callout("note", title, attrLine, false);
|
|
206
|
+
function injectedBlockBody(tag: string, attrs: string, content: string): string {
|
|
207
|
+
const attrLine = attrItems(attrs).join(" · ");
|
|
188
208
|
const text = content ? unwrapCDATA(content).trim() : "";
|
|
189
209
|
const body = tag === "linked_note" && isVaultNotePath(text) ? wikilinkOf(text) : text;
|
|
190
|
-
return
|
|
191
|
-
"quote",
|
|
192
|
-
title,
|
|
193
|
-
attrLine ? (body ? `${attrLine}\n\n${body}` : attrLine) : body,
|
|
194
|
-
Boolean(body),
|
|
195
|
-
);
|
|
210
|
+
return attrLine ? (body ? `${attrLine}\n\n${body}` : attrLine) : body;
|
|
196
211
|
}
|
|
197
212
|
|
|
198
213
|
/**
|
|
199
214
|
* User message text for the saved body: every known injected block renders
|
|
200
|
-
* as a callout
|
|
215
|
+
* as a preset-collapsed callout — visible blocks as `> [!quote]-`, hidden
|
|
216
|
+
* blocks as a `> [!note]-` marker — and a RUN of visible same-tag blocks
|
|
217
|
+
* with nothing but whitespace between them merges into ONE callout (a user
|
|
218
|
+
* attaching five notes saves one Linked Content callout listing five
|
|
219
|
+
* wikilinks, not five callouts; hidden markers never merge — each names its
|
|
220
|
+
* own skill). Anything else stays verbatim.
|
|
201
221
|
*/
|
|
202
222
|
export function renderUserMessageText(text: string): string {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
223
|
+
const re = new RegExp(INJECTED_BLOCK_RE, "g");
|
|
224
|
+
let out = "";
|
|
225
|
+
let pos = 0;
|
|
226
|
+
let runTag: string | null = null;
|
|
227
|
+
const runBodies: string[] = [];
|
|
228
|
+
const flushRun = () => {
|
|
229
|
+
if (runTag === null) return;
|
|
230
|
+
out += callout("quote", tagTitle(runTag), runBodies.join("\n\n"));
|
|
231
|
+
runTag = null;
|
|
232
|
+
runBodies.length = 0;
|
|
233
|
+
};
|
|
234
|
+
let m: RegExpExecArray | null;
|
|
235
|
+
while ((m = re.exec(text)) !== null) {
|
|
236
|
+
const tag = m[1];
|
|
237
|
+
const gap = text.slice(pos, m.index);
|
|
238
|
+
const mergeable = runTag !== null && tag === runTag && gap.trim() === "";
|
|
239
|
+
if (!mergeable) {
|
|
240
|
+
// A different tag, real text between the blocks, or a hidden block
|
|
241
|
+
// (self-contained markers never merge) ends the run; the gap is
|
|
242
|
+
// emitted only then — inside a run it is whitespace.
|
|
243
|
+
flushRun();
|
|
244
|
+
out += gap;
|
|
245
|
+
}
|
|
246
|
+
if (HIDDEN_TAGS.has(tag)) {
|
|
247
|
+
out += hiddenCallout(tag, m[2]);
|
|
248
|
+
} else {
|
|
249
|
+
if (runTag === null) runTag = tag;
|
|
250
|
+
runBodies.push(injectedBlockBody(tag, m[2], m[3] ?? ""));
|
|
251
|
+
}
|
|
252
|
+
pos = re.lastIndex;
|
|
253
|
+
}
|
|
254
|
+
flushRun();
|
|
255
|
+
return out + text.slice(pos);
|
|
208
256
|
}
|
|
209
257
|
|
|
210
258
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-auto-save-to-markdown",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
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",
|