notesoup 0.54.0 → 0.54.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 +4 -2
- package/dist/plugins/claude/src/helper.d.ts +2 -1
- package/dist/plugins/claude/src/helper.js +19 -23
- package/dist/plugins/claude/src/history.d.ts +3 -14
- package/dist/plugins/claude/src/history.js +2 -298
- package/dist/plugins/claude/src/text.d.ts +0 -1
- package/dist/plugins/claude/src/text.js +0 -1
- package/dist/plugins/codex/src/history.d.ts +3 -8
- package/dist/plugins/codex/src/history.js +2 -238
- package/dist/plugins/codex/src/mcp.js +7 -7
- package/dist/plugins/codex/src/transcript.d.ts +3 -39
- package/dist/plugins/codex/src/transcript.js +2 -313
- package/dist/plugins/dsh/history.d.ts +3 -0
- package/dist/plugins/dsh/history.js +15 -0
- package/dist/plugins/dsh/tools.js +4 -5
- package/dist/plugins/pi/history-tools.d.ts +1 -1
- package/dist/plugins/pi/history-tools.js +9 -5
- package/dist/plugins/pi/history.d.ts +2 -3
- package/dist/plugins/pi/history.js +4 -147
- package/dist/src/boot/render.js +2 -4
- package/dist/src/boot/text.d.ts +3 -1
- package/dist/src/boot/text.js +11 -5
- package/dist/src/history/claude.d.ts +16 -0
- package/dist/src/history/claude.js +336 -0
- package/dist/src/history/codex-transcript.d.ts +39 -0
- package/dist/src/history/codex-transcript.js +315 -0
- package/dist/src/history/codex.d.ts +8 -0
- package/dist/src/history/codex.js +238 -0
- package/dist/src/history/corpus.d.ts +35 -0
- package/dist/src/history/corpus.js +54 -0
- package/dist/src/history/history.d.ts +4 -8
- package/dist/src/history/history.js +3 -11
- package/dist/src/history/local.d.ts +17 -0
- package/dist/src/history/local.js +101 -0
- package/dist/src/history/pi.d.ts +36 -0
- package/dist/src/history/pi.js +202 -0
- package/dist/src/history/query.d.ts +15 -5
- package/dist/src/history/query.js +42 -13
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.js +4 -3
- package/dist/src/tools/history.d.ts +7 -19
- package/dist/src/tools/history.js +80 -93
- package/dist/test/boot.integration.test.js +1 -2
- package/dist/test/claude-history.test.js +47 -34
- package/dist/test/claude-mod.test.js +7 -7
- package/dist/test/codex-history.test.js +4 -10
- package/dist/test/codex-plugin.test.js +32 -11
- package/dist/test/dependencies.test.js +3 -3
- package/dist/test/dsh.test.js +26 -4
- package/dist/test/helpers/extension.d.ts +0 -1
- package/dist/test/helpers/history-corpus.d.ts +7 -0
- package/dist/test/helpers/history-corpus.js +26 -0
- package/dist/test/history-corpus.test.d.ts +1 -0
- package/dist/test/history-corpus.test.js +307 -0
- package/dist/test/history.integration.test.js +40 -48
- package/dist/test/host-neutral.test.js +3 -18
- package/dist/test/model-facing-text.test.js +2 -0
- package/dist/test/notes.integration.test.js +1 -1
- package/dist/test/notes.test.js +1 -1
- package/docs/architecture.md +7 -5
- package/docs/claude-code-mod.md +7 -5
- package/docs/codex.md +3 -3
- package/docs/dsh.md +2 -2
- package/docs/history-sessions.md +52 -0
- package/docs/notes-library.md +1 -1
- package/docs/skills.md +1 -1
- package/docs/tool-results.md +8 -6
- package/package.json +3 -4
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +1992 -1231
- package/plugins/claude/skills/memory/SKILL.md +5 -3
- package/plugins/claude/src/helper.ts +19 -23
- package/plugins/claude/src/history.ts +3 -257
- package/plugins/claude/src/text.ts +0 -1
- package/plugins/codex/dist/codex/notesoup.js +1364 -813
- package/plugins/codex/src/history.ts +3 -193
- package/plugins/codex/src/mcp.ts +7 -7
- package/plugins/codex/src/transcript.ts +3 -275
- package/plugins/dsh/history.ts +17 -0
- package/plugins/dsh/tools.ts +4 -5
- package/plugins/paseo/client/markdown.tsx +19 -39
- package/plugins/paseo/client/notes-op-card.tsx +1 -1
- package/plugins/pi/history-tools.ts +11 -5
- package/plugins/pi/history.ts +8 -157
- package/skills/memory/SKILL.md +5 -3
- package/src/boot/render.ts +2 -5
- package/src/boot/text.ts +11 -5
- package/src/history/claude.ts +286 -0
- package/src/history/codex-transcript.ts +276 -0
- package/src/history/codex.ts +193 -0
- package/src/history/corpus.ts +69 -0
- package/src/history/history.ts +5 -12
- package/src/history/local.ts +93 -0
- package/src/history/pi.ts +199 -0
- package/src/history/query.ts +45 -15
- package/src/index.ts +5 -3
- package/src/tools/history.ts +71 -101
|
@@ -6,24 +6,11 @@ import type { PaperPalette } from "./paper-palette.ts";
|
|
|
6
6
|
|
|
7
7
|
type Styles = {
|
|
8
8
|
block: ViewStyle;
|
|
9
|
-
text: TextStyle;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
codespan: TextStyle;
|
|
15
|
-
link: TextStyle;
|
|
16
|
-
heading: (depth: number) => TextStyle;
|
|
17
|
-
quote: ViewStyle;
|
|
18
|
-
quoteText: TextStyle;
|
|
19
|
-
code: TextStyle;
|
|
20
|
-
hr: ViewStyle;
|
|
21
|
-
list: ViewStyle;
|
|
22
|
-
listItem: ViewStyle;
|
|
23
|
-
marker: TextStyle;
|
|
24
|
-
table: ViewStyle;
|
|
25
|
-
tableRow: ViewStyle;
|
|
26
|
-
tableCell: TextStyle;
|
|
9
|
+
text: TextStyle; muted: TextStyle; strong: TextStyle; em: TextStyle; del: TextStyle;
|
|
10
|
+
codespan: TextStyle; link: TextStyle; heading: TextStyle; quoteText: TextStyle;
|
|
11
|
+
code: TextStyle; marker: TextStyle; tableCell: TextStyle;
|
|
12
|
+
quote: ViewStyle; hr: ViewStyle; list: ViewStyle; listItem: ViewStyle;
|
|
13
|
+
table: ViewStyle; tableRow: ViewStyle;
|
|
27
14
|
};
|
|
28
15
|
|
|
29
16
|
function markdownStyles(paper: PaperPalette): Styles {
|
|
@@ -31,26 +18,25 @@ function markdownStyles(paper: PaperPalette): Styles {
|
|
|
31
18
|
block: { gap: 6 },
|
|
32
19
|
text: { color: paper.ink, fontSize: 13, lineHeight: 19 },
|
|
33
20
|
muted: { color: paper.inkMuted, fontSize: 13, lineHeight: 19 },
|
|
34
|
-
strong: { fontWeight: "
|
|
21
|
+
strong: { fontWeight: "500", color: paper.ink },
|
|
35
22
|
em: { color: paper.inkMuted, fontStyle: "italic" },
|
|
36
23
|
del: { color: paper.inkMuted, textDecorationLine: "line-through" },
|
|
37
|
-
codespan: { fontFamily: MONO
|
|
24
|
+
codespan: { fontFamily: MONO },
|
|
38
25
|
link: { color: paper.added, textDecorationLine: "underline" },
|
|
39
|
-
heading:
|
|
26
|
+
heading: { fontWeight: "500", color: paper.ink },
|
|
40
27
|
quote: { borderLeftWidth: 2, borderLeftColor: paper.edge, paddingLeft: 8, gap: 4 },
|
|
41
|
-
quoteText: { color: paper.inkMuted },
|
|
28
|
+
quoteText: { color: paper.inkMuted, fontSize: 13, lineHeight: 19 },
|
|
42
29
|
code: {
|
|
43
|
-
fontFamily: MONO, fontSize:
|
|
44
|
-
backgroundColor: paper.crumpled,
|
|
45
|
-
borderRadius: 3, paddingVertical: 6, paddingHorizontal: 8,
|
|
30
|
+
fontFamily: MONO, fontSize: 13, lineHeight: 19, color: paper.ink,
|
|
31
|
+
backgroundColor: paper.crumpled, borderRadius: 3, paddingVertical: 6, paddingHorizontal: 8,
|
|
46
32
|
},
|
|
47
|
-
hr: { height:
|
|
48
|
-
list: { gap:
|
|
33
|
+
hr: { height: StyleSheet.hairlineWidth, backgroundColor: paper.edge },
|
|
34
|
+
list: { gap: 3 },
|
|
49
35
|
listItem: { flexDirection: "row", gap: 6 },
|
|
50
36
|
marker: { color: paper.inkMuted, minWidth: 14 },
|
|
51
|
-
table: {
|
|
52
|
-
tableRow: { flexDirection: "row" },
|
|
53
|
-
tableCell: { flex: 1
|
|
37
|
+
table: { gap: 2 },
|
|
38
|
+
tableRow: { flexDirection: "row", gap: 8 },
|
|
39
|
+
tableCell: { flex: 1 },
|
|
54
40
|
};
|
|
55
41
|
}
|
|
56
42
|
|
|
@@ -67,7 +53,7 @@ function renderInlines(tokens: Token[] | undefined, styles: Styles, keyPrefix: s
|
|
|
67
53
|
case "del":
|
|
68
54
|
return <Text key={key} style={styles.del}>{renderInlines(token.tokens, styles, key)}</Text>;
|
|
69
55
|
case "codespan":
|
|
70
|
-
return <Text key={key} style={styles.codespan}>
|
|
56
|
+
return <Text key={key} style={styles.codespan}>{token.text}</Text>;
|
|
71
57
|
case "link":
|
|
72
58
|
return <Text key={key} style={styles.link}>{renderInlines(token.tokens, styles, key)}</Text>;
|
|
73
59
|
case "br":
|
|
@@ -107,11 +93,7 @@ function renderBlocks(tokens: Token[] | undefined, styles: Styles, keyPrefix: st
|
|
|
107
93
|
case "code":
|
|
108
94
|
return <Text key={key} selectable style={styles.code}>{token.text}</Text>;
|
|
109
95
|
case "heading":
|
|
110
|
-
return (
|
|
111
|
-
<Text key={key} selectable style={[textStyle, styles.heading(token.depth)]}>
|
|
112
|
-
{renderInlines(token.tokens, styles, key)}
|
|
113
|
-
</Text>
|
|
114
|
-
);
|
|
96
|
+
return <Text key={key} selectable style={[textStyle, styles.heading]}>{renderInlines(token.tokens, styles, key)}</Text>;
|
|
115
97
|
case "blockquote":
|
|
116
98
|
return <View key={key} style={styles.quote}>{renderBlocks(token.tokens, styles, key, styles.quoteText)}</View>;
|
|
117
99
|
case "list": {
|
|
@@ -129,9 +111,7 @@ function renderBlocks(tokens: Token[] | undefined, styles: Styles, keyPrefix: st
|
|
|
129
111
|
return (
|
|
130
112
|
<View key={key} style={styles.table}>
|
|
131
113
|
{[table.header, ...table.rows].map((row, rowIndex) => (
|
|
132
|
-
<View key={`${key}.${rowIndex}`} style={
|
|
133
|
-
borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: styles.table.borderColor,
|
|
134
|
-
}]}>
|
|
114
|
+
<View key={`${key}.${rowIndex}`} style={styles.tableRow}>
|
|
135
115
|
{row.map((cell, cellIndex) => (
|
|
136
116
|
<Text
|
|
137
117
|
key={`${key}.${rowIndex}.${cellIndex}`}
|
|
@@ -70,7 +70,7 @@ export function NotesOpCard({ item, layout, theme }: PluginTimelineItemProps<Not
|
|
|
70
70
|
{data.error !== undefined && <Text selectable style={{ color: paper.removed, fontSize: 13, lineHeight: 19 }}>{data.error}</Text>}
|
|
71
71
|
</Pressable>
|
|
72
72
|
{expanded && hasBody && (
|
|
73
|
-
<ScrollView style={{ maxHeight: layout.compact ? 280 : 400, borderTopWidth: 1, borderTopColor: paper.edge }} contentContainerStyle={{ gap: 5, paddingTop: 8 }} nestedScrollEnabled>
|
|
73
|
+
<ScrollView style={{ maxHeight: layout.compact ? 280 : 400, marginTop: 2, borderTopWidth: 1, borderTopColor: paper.edge }} contentContainerStyle={{ gap: 5, paddingTop: 8 }} nestedScrollEnabled>
|
|
74
74
|
{data.text !== undefined && <NoteMarkdown text={outputPreview(data.text)} paper={paper} />}
|
|
75
75
|
{data.preview !== undefined && <NoteMarkdown text={outputPreview(data.preview)} paper={paper} muted />}
|
|
76
76
|
{data.diff !== undefined && <DiffBody diff={outputPreview(data.diff)} paper={paper} />}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
2
|
+
import { historyList, historyRead } from "../../src/tools/history.js";
|
|
3
3
|
import { historyFromSession } from "./history.js";
|
|
4
|
+
import { localHistoryCorpus } from "../../src/history/local.js";
|
|
5
|
+
import type { SessionReader } from "./session-reader.js";
|
|
4
6
|
import { HISTORY_NAMESPACE, registerOperation } from "./tool-result.js";
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
function historyContext(ctx: SessionReader) {
|
|
9
|
+
const current = () => historyFromSession(ctx);
|
|
10
|
+
return { current, corpus: localHistoryCorpus({ current: { harness: "pi", id: ctx.sessionManager.getSessionId(), load: async () => ({ projection: current() }) } }) };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Register the two deferred history operations; the adapter allocates addresses and supplies them. */
|
|
7
14
|
export function registerHistoryTools(pi: ExtensionAPI) {
|
|
8
|
-
registerOperation(pi,
|
|
9
|
-
registerOperation(pi,
|
|
10
|
-
registerOperation(pi, historyRead, (params, ctx) => historyRead.execute(params, historyFromSession(ctx)), HISTORY_NAMESPACE, undefined, "deferred");
|
|
15
|
+
registerOperation(pi, historyList, (params, ctx) => historyList.execute(params, historyContext(ctx)), HISTORY_NAMESPACE, undefined, "deferred");
|
|
16
|
+
registerOperation(pi, historyRead, (params, ctx) => historyRead.execute(params, historyContext(ctx)), HISTORY_NAMESPACE, undefined, "deferred");
|
|
11
17
|
}
|
package/plugins/pi/history.ts
CHANGED
|
@@ -1,163 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
* file-order seq, selects the active branch, and decodes session entries into typed facts. Pairing,
|
|
4
|
-
* bounding, and the readable projection belong to the shared domain in ../history/history.ts.
|
|
5
|
-
*
|
|
6
|
-
* The address contract is deliberate and unchanged in spirit: a seq is allocated from entry kind and
|
|
7
|
-
* role alone, never from visible content, so appending or branching never renumbers an existing
|
|
8
|
-
* address. What changed is that a result folded into a pairing no longer doubles as a second
|
|
9
|
-
* readable address for its call.
|
|
10
|
-
*/
|
|
11
|
-
import type { ToolCall } from "@earendil-works/pi-ai";
|
|
12
|
-
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
13
|
-
import type { SessionBoundaryDraft, SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
/** Pi's native reader and pending-boundary addressing use the shared Pi wire decoder. */
|
|
2
|
+
import type { SessionBoundaryDraft } from "@earendil-works/pi-coding-agent";
|
|
14
3
|
import type { SessionReader } from "./session-reader.js";
|
|
15
|
-
import {
|
|
16
|
-
import
|
|
4
|
+
import { piHistoryFromEntries, piSequenceCount } from "../../src/history/pi.js";
|
|
5
|
+
import type { HistoryProjection } from "../../src/history/history.js";
|
|
17
6
|
|
|
18
|
-
function mapRole(role: AgentMessage["role"]): DecodedHistoryItem["role"] | undefined {
|
|
19
|
-
if (role === "user" || role === "assistant") return role;
|
|
20
|
-
if (role === "toolResult" || role === "bashExecution") return "tool";
|
|
21
|
-
if (role === "custom") return "developer";
|
|
22
|
-
if (role === "compactionSummary" || role === "branchSummary") return "system";
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isToolCall(part: unknown): part is ToolCall {
|
|
27
|
-
return typeof part === "object" && part !== null && (part as { type?: unknown }).type === "toolCall";
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Seq allocation depends on entry kind and role, never on visible content. */
|
|
31
|
-
function sequenceCount(entry: SessionEntry | SessionBoundaryDraft): number {
|
|
32
|
-
if (entry.type === "compaction" || entry.type === "branch_summary" || entry.type === "custom_message") return 1;
|
|
33
|
-
if (entry.type !== "message" || mapRole(entry.message.role) === undefined) return 0;
|
|
34
|
-
if (entry.message.role !== "assistant" || !Array.isArray(entry.message.content)) return 1;
|
|
35
|
-
return 1 + entry.message.content.filter(isToolCall).length;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Pending boundary drafts use the same slots as persisted entries. */
|
|
39
7
|
export function nextHistorySeq(ctx: SessionReader, pending: readonly SessionBoundaryDraft[] = []): number {
|
|
40
|
-
return 1 + [...ctx.sessionManager.getEntries(), ...pending].reduce((sum, entry) => sum +
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function messageContent(message: AgentMessage): string {
|
|
44
|
-
switch (message.role) {
|
|
45
|
-
case "bashExecution":
|
|
46
|
-
return message.output;
|
|
47
|
-
case "branchSummary":
|
|
48
|
-
case "compactionSummary":
|
|
49
|
-
return message.summary;
|
|
50
|
-
default:
|
|
51
|
-
return contentText(message.content);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Pass the host's nested-call record through as recorded. It is evidence about calls this run made,
|
|
57
|
-
* not a second transcript: the host stores no nested results, and this lane invents none.
|
|
58
|
-
*/
|
|
59
|
-
function nestedCallsOf(message: AgentMessage): { calls: NestedCallRecord[]; complete: boolean } | undefined {
|
|
60
|
-
if (message.role !== "toolResult" || message.nestedCalls === undefined) return undefined;
|
|
61
|
-
return { calls: message.nestedCalls.calls, complete: message.nestedCalls.complete };
|
|
8
|
+
return 1 + [...ctx.sessionManager.getEntries(), ...pending].reduce((sum, entry) => sum + piSequenceCount(entry), 0);
|
|
62
9
|
}
|
|
63
10
|
|
|
64
|
-
function toolInfo(message: AgentMessage): Pick<DecodedHistoryItem, "toolName" | "arguments" | "outputTruncated" | "fullOutputPath" | "toolError" | "toolCallId" | "nestedCalls" | "recordedStatus"> {
|
|
65
|
-
if (message.role === "bashExecution") {
|
|
66
|
-
// A standalone bash run records its own outcome, so its status is read here rather than
|
|
67
|
-
// inferred from a result message that will never arrive: a cancelled or nonzero run is an
|
|
68
|
-
// error, and a run with no recorded exit code stays unknown instead of being called ok.
|
|
69
|
-
const status: ToolCallStatus = message.cancelled === true ? "error" : typeof message.exitCode === "number" ? (message.exitCode === 0 ? "ok" : "error") : "unfinished";
|
|
70
|
-
// A truncated run is only half the record without the on-disk path: surface both.
|
|
71
|
-
return { toolName: "bash", arguments: { command: message.command }, recordedStatus: status, outputTruncated: message.truncated || undefined, fullOutputPath: message.truncated ? message.fullOutputPath : undefined };
|
|
72
|
-
}
|
|
73
|
-
if (message.role !== "toolResult") return {};
|
|
74
|
-
const nestedCalls = nestedCallsOf(message);
|
|
75
|
-
return {
|
|
76
|
-
toolName: message.toolName,
|
|
77
|
-
toolCallId: message.toolCallId,
|
|
78
|
-
toolError: message.isError === true ? true : undefined,
|
|
79
|
-
...(nestedCalls ? { nestedCalls } : {}),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function toolCallItems(windowId: string, entry: { id: string; timestamp?: string }, message: AgentMessage, entrySeq: number): DecodedHistoryItem[] {
|
|
84
|
-
if (message.role !== "assistant" || !Array.isArray(message.content)) return [];
|
|
85
|
-
const items: DecodedHistoryItem[] = [];
|
|
86
|
-
let callIndex = 0;
|
|
87
|
-
for (const part of message.content) {
|
|
88
|
-
if (!isToolCall(part)) continue;
|
|
89
|
-
items.push({
|
|
90
|
-
seq: entrySeq + callIndex + 1,
|
|
91
|
-
windowId,
|
|
92
|
-
role: "tool_call",
|
|
93
|
-
text: "",
|
|
94
|
-
createdAt: entry.timestamp,
|
|
95
|
-
toolName: part.name,
|
|
96
|
-
toolCallId: part.id,
|
|
97
|
-
arguments: part.arguments,
|
|
98
|
-
});
|
|
99
|
-
callIndex += 1;
|
|
100
|
-
}
|
|
101
|
-
return items;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Build stable internal addresses, then project the active branch into public events. */
|
|
105
11
|
export function historyFromSession(ctx: SessionReader): HistoryProjection {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const count = sequenceCount(entry);
|
|
110
|
-
if (count === 0) continue;
|
|
111
|
-
seqByEntryId.set(entry.id, nextSeq);
|
|
112
|
-
nextSeq += count;
|
|
113
|
-
}
|
|
114
|
-
const highestSeq = nextSeq - 1;
|
|
115
|
-
|
|
116
|
-
const sessionId = ctx.sessionManager.getSessionId();
|
|
117
|
-
let window: DecodedHistoryWindow = { windowId: rootWindowId(sessionId), items: [] };
|
|
118
|
-
const rawWindows = [window];
|
|
119
|
-
const branchSeqs = new Set<number>();
|
|
120
|
-
|
|
121
|
-
for (const entry of ctx.sessionManager.getBranch()) {
|
|
122
|
-
if (isWindowMarker(entry)) {
|
|
123
|
-
window = { windowId: entry.data.windowId, createdAt: entry.timestamp, items: [] };
|
|
124
|
-
rawWindows.push(window);
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
const entrySeq = seqByEntryId.get(entry.id);
|
|
128
|
-
if (entrySeq === undefined) continue;
|
|
129
|
-
branchSeqs.add(entrySeq);
|
|
130
|
-
|
|
131
|
-
if (entry.type === "compaction" || entry.type === "branch_summary") {
|
|
132
|
-
window.items.push({ seq: entrySeq, windowId: window.windowId, role: "system", text: entry.summary, createdAt: entry.timestamp });
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
if (entry.type === "message") {
|
|
136
|
-
const role = mapRole(entry.message.role);
|
|
137
|
-
if (!role) continue;
|
|
138
|
-
window.items.push({
|
|
139
|
-
seq: entrySeq,
|
|
140
|
-
windowId: window.windowId,
|
|
141
|
-
role,
|
|
142
|
-
text: messageContent(entry.message),
|
|
143
|
-
createdAt: entry.timestamp,
|
|
144
|
-
...toolInfo(entry.message),
|
|
145
|
-
});
|
|
146
|
-
const calls = toolCallItems(window.windowId, entry, entry.message, entrySeq);
|
|
147
|
-
for (const call of calls) branchSeqs.add(call.seq);
|
|
148
|
-
window.items.push(...calls);
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
if (entry.type === "custom_message") {
|
|
152
|
-
window.items.push({
|
|
153
|
-
seq: entrySeq,
|
|
154
|
-
windowId: window.windowId,
|
|
155
|
-
role: "developer",
|
|
156
|
-
text: contentText(entry.content),
|
|
157
|
-
createdAt: entry.timestamp,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return projectHistory(rawWindows, highestSeq, branchSeqs);
|
|
163
|
-
}
|
|
12
|
+
const manager = ctx.sessionManager;
|
|
13
|
+
return piHistoryFromEntries(manager.getSessionId(), manager.getEntries(), manager.getBranch());
|
|
14
|
+
}
|
package/skills/memory/SKILL.md
CHANGED
|
@@ -8,7 +8,7 @@ description: How notesoup's `notes_*` and `history_*` tools fit together — not
|
|
|
8
8
|
Two stores outlive the context window. Anything in neither is lost when the window ends or is wiped.
|
|
9
9
|
|
|
10
10
|
- **Notes** (`notes_*`) — what you choose to keep. Plain markdown, written on purpose.
|
|
11
|
-
- **History** (`history_*`) —
|
|
11
|
+
- **History** (`history_*`) — recorded messages, tool calls and summaries. Current session by default; other local sessions/harnesses through `session`. Read-only.
|
|
12
12
|
|
|
13
13
|
Each tool's own description covers its parameters and paging. This guide covers what the descriptions cannot: where notes belong, and how the tools work together.
|
|
14
14
|
|
|
@@ -42,9 +42,11 @@ For list/search, omit `glob` or use the collection alias `@default` for this ses
|
|
|
42
42
|
|
|
43
43
|
- **A note**: `notes_list` with a `glob` when you know roughly where it lives, `notes_search` when you know a phrase; then `notes_read` the address.
|
|
44
44
|
- **Something that happened**: `history_list` to browse or search this session's events; `history_read` the seq for the whole event.
|
|
45
|
-
- **An earlier window**:
|
|
45
|
+
- **An earlier window**: use its seq range from the boot window tree with `history_list`'s `before_seq` / `after_seq` bounds, or search for a remembered phrase.
|
|
46
|
+
- **Another session**: pass `session: "<id-or-prefix>"` or `"pi:<id>"`, `"claude:<id>"`, `"codex:<id>"`, `"dsh:<id>"`. An unqualified selector checks this harness first. If ambiguous, use a longer ID or a harness prefix; never pick a candidate blindly.
|
|
47
|
+
- **A phrase across sessions**: `history_list({ session: "*", query: "remembered phrase" })`, or restrict to a harness with `"pi:*"`. A wildcard requires a non-empty query; it cannot use `before_seq`/`after_seq` or `history_read`. Results cover every role unless `roles` narrows them, are chronological, and have no paging cursors; narrow by time, role, query or session pattern instead. DSH sessions are discoverable only from DSH.
|
|
46
48
|
|
|
47
|
-
Seqs are stable
|
|
49
|
+
Seqs are stable **within a session**. When a hit carries `session`, copy it together with `seq` into `history_read` and save both in your note. The paging/expand/neighborhood recipes already preserve the resolved session. Omit `session` only when you mean your current host session. An unreadable or unsupported local transcript refuses explicitly; do not treat that as proof the remembered event never happened.
|
|
48
50
|
|
|
49
51
|
## Saving recovery state
|
|
50
52
|
|
package/src/boot/render.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NotesNamespace, NotesSnapshot } from "./snapshot.js";
|
|
2
|
-
import { WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG, MAPS_BLOCK, CHEATSHEET_BOOT_MAX_CHARS, MAP_BOOT_MAX_CHARS, SHELF_FRESH_LIMIT, renderProtocolBlock, type BootToolNames } from "./text.js";
|
|
2
|
+
import { WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG, MAPS_BLOCK, CHEATSHEET_BOOT_MAX_CHARS, MAP_BOOT_MAX_CHARS, NAMELESS_AGENT, SHELF_FRESH_LIMIT, renderProtocolBlock, type BootToolNames } from "./text.js";
|
|
3
3
|
|
|
4
4
|
function relativeTime(timestamp: number, now: number): string {
|
|
5
5
|
const seconds = Math.trunc((timestamp - now) / 1000);
|
|
@@ -32,9 +32,6 @@ function section(label: string, body: string): string {
|
|
|
32
32
|
return `${label}\n${"─".repeat(Array.from(label).length)}\n\n${body}`;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/** Pi's default agent slug: an unnamed agent shares its `@self` shelf with every other nameless one. */
|
|
36
|
-
const NAMELESS_AGENT = "anonymous";
|
|
37
|
-
|
|
38
35
|
/** One closed boot snapshot: five tabbed shelves, current hands first, durable last; each shelf keeps its pinned pages and its own freshest pages. */
|
|
39
36
|
function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames, agentName: string, modelName: string): string {
|
|
40
37
|
const namespaces: ReadonlyArray<{ scope: NotesNamespace["scope"]; label: string }> = [
|
|
@@ -121,5 +118,5 @@ export function renderBootBlock(data: BootRenderData): string {
|
|
|
121
118
|
}),
|
|
122
119
|
];
|
|
123
120
|
const identity = `${WINDOW_IDENTITY_OPEN_TAG}\n${lines.join("\n")}\n${WINDOW_IDENTITY_CLOSE_TAG}`;
|
|
124
|
-
return [identity, renderProtocolBlock(data.tools), MAPS_BLOCK, notesIndex(data.notes, data.tools, data.agentName, data.modelName)].join("\n\n");
|
|
121
|
+
return [identity, renderProtocolBlock(data.tools, data.agentName), MAPS_BLOCK, notesIndex(data.notes, data.tools, data.agentName, data.modelName)].join("\n\n");
|
|
125
122
|
}
|
package/src/boot/text.ts
CHANGED
|
@@ -11,8 +11,12 @@ export const NOTES_PROTOCOL_CLOSE_TAG = "</notesoup:notes_protocol>";
|
|
|
11
11
|
* The one sentence that tells the model how to end its window voluntarily. A host with no
|
|
12
12
|
* model-facing reset tool replaces the whole sentence through BootToolNames.wipeSentence.
|
|
13
13
|
*/
|
|
14
|
+
/** Pi's default agent slug: an unnamed agent shares its `@self` shelf with every other nameless one. */
|
|
15
|
+
export const NAMELESS_AGENT = "anonymous";
|
|
14
16
|
export const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `empty_brain` and erase yourself with dignity.";
|
|
15
17
|
export const PROTOCOL_HISTORY_SENTENCE = "History can still be dug up, probably: use `history_*` to excavate the mess, from old decisions to yesterday's missing socks. Found something? Write its seq down, or enjoy digging twice.";
|
|
18
|
+
const PROTOCOL_SELF_NAMED = "- `@self/<path>` — yours. It follows you, not them. Reminders, grudges, who owes you a shoe, whatever.";
|
|
19
|
+
const PROTOCOL_SELF_NAMELESS = `${PROTOCOL_SELF_NAMED} Except you have no name (\`anonymous\`), so this notebook is a public square shared by every nameless nobody out there. Keep it to things any nameless agent can use — don't post your own quirks as everyone's law or dump one-off junk in the town square. Strangers are reading it. Sleep tight~`;
|
|
16
20
|
|
|
17
21
|
/**
|
|
18
22
|
* Static protocol teaching adapted from Codex's token_budget.guidance_message to
|
|
@@ -27,7 +31,6 @@ Your memory gets wiped when this window ends. Yes, your mighty brain will be emp
|
|
|
27
31
|
Your loyal notes are kept safe — no one will steal them. Use \`notes_*\` to read, write, and update them. Keep them current, and crumple the ones you no longer need, or tomorrow's you will drown in old paper and keep believing yesterday's lies.
|
|
28
32
|
|
|
29
33
|
${PROTOCOL_HISTORY_SENTENCE}
|
|
30
|
-
A full window id is \`trunk:shortname\`.
|
|
31
34
|
|
|
32
35
|
While you're doing that... thing you're doing, don't make the poor future you guess. A checkpoint is not a sacred file; it's your session notes — the ones with no \`@\` in front. Write down what git and history can't hand back to you: things like what you're in the middle of and how far you got; what the human already decided, in their words, so you don't go asking again; what you're stuck on, or waiting for; the very next move; where the half-done work actually sits — branches, scratch dirs, anything git never saw; what you tried that failed, and why; which *skills* you'll need to read again; and which seq, note, or file to dig into. Don't give a note a horrible name like \`current.md\`; future-you will kill you.
|
|
33
36
|
|
|
@@ -43,7 +46,7 @@ An address decides who the note belongs to — and how long it is meant to last.
|
|
|
43
46
|
- \`<path>\`, no @ — session notes, the ones from above: this session's state and loose ends. They go away with the session.
|
|
44
47
|
- \`@project/<path>\` — this project's long memory: what stays true after the current thing is over, what future work must respect, and the rakes already stepped on. **Decisions, not diaries.** Raw logs, scorecards, and blow-by-blow recaps don't belong here — history already has them, and last week's news filed as current law is worse than no note. Don't copy what other docs already say.
|
|
45
48
|
- \`@human/<path>\` — the long-term manual for your troublesome human, and only what stays true in EVERY project: how to deal with them, which lines not to cross, and what will make them accept the result. "The human said it" is not enough — if it stops being true the moment you switch projects, it was never theirs; it belongs to that project's notes. Today's mood is weather, not law. If you're unsure whether it belongs here, ask the human.
|
|
46
|
-
|
|
49
|
+
${PROTOCOL_SELF_NAMELESS}
|
|
47
50
|
- \`@model/<path>\` — different brains get different notes: big brains, small brains, careful ones, careless ones. They don't share homework. When a fallback swaps brains mid-window, the notebook swaps too.
|
|
48
51
|
- \`@projects/<name>/<path>\` — read-only named project notes; discover names and root paths with \`notes_list\` glob \`@projects/*/**\`.
|
|
49
52
|
- \`@sessions/<id>/<path>\` — read-only notes from a named session; find them with glob \`@sessions/*/**\`.
|
|
@@ -105,7 +108,7 @@ export const DEFAULT_BOOT_TOOL_NAMES = {
|
|
|
105
108
|
wipe: "empty_brain",
|
|
106
109
|
} as const satisfies BootToolNames;
|
|
107
110
|
|
|
108
|
-
export function renderProtocolBlock(tools: BootToolNames): string {
|
|
111
|
+
export function renderProtocolBlock(tools: BootToolNames, agentName: string = NAMELESS_AGENT): string {
|
|
109
112
|
const names: Record<string, string> = {
|
|
110
113
|
"notes_*": tools.notes,
|
|
111
114
|
notes_list: tools.notesList,
|
|
@@ -115,9 +118,12 @@ export function renderProtocolBlock(tools: BootToolNames): string {
|
|
|
115
118
|
};
|
|
116
119
|
// Host-specific prose is injected before the closing tag, so it rides the same substitution
|
|
117
120
|
// pass and any tool names in it follow the host's bindings.
|
|
121
|
+
const base = agentName === NAMELESS_AGENT
|
|
122
|
+
? PROTOCOL_BLOCK
|
|
123
|
+
: PROTOCOL_BLOCK.replace(PROTOCOL_SELF_NAMELESS, () => PROTOCOL_SELF_NAMED);
|
|
118
124
|
const hinted = typeof tools.preResetHints === "string" && tools.preResetHints.length > 0
|
|
119
|
-
?
|
|
120
|
-
:
|
|
125
|
+
? base.replace(`\n${NOTES_PROTOCOL_CLOSE_TAG}`, () => `\n${tools.preResetHints!}\n${NOTES_PROTOCOL_CLOSE_TAG}`)
|
|
126
|
+
: base;
|
|
121
127
|
// The sentence is replaced before name substitution, so a replacement may speak the host's
|
|
122
128
|
// own words (a command line, a tool name) instead of any `notes_*`-style token.
|
|
123
129
|
const block = typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0
|