notesoup 0.57.3 → 0.58.0
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 +15 -1
- package/dist/plugins/claude/src/helper.js +2 -11
- package/dist/plugins/claude/src/thresholds.js +5 -18
- package/dist/plugins/codex/src/mcp.js +3 -11
- package/dist/plugins/codex/src/state.d.ts +1 -1
- package/dist/plugins/codex/src/state.js +1 -1
- package/dist/plugins/dsh/tools.js +1 -1
- package/dist/plugins/pi/boot.d.ts +1 -1
- package/dist/plugins/pi/boot.js +2 -3
- package/dist/plugins/pi/budget.d.ts +1 -1
- package/dist/plugins/pi/budget.js +1 -1
- package/dist/plugins/pi/render.d.ts +1 -1
- package/dist/plugins/pi/render.js +20 -11
- package/dist/plugins/pi/runtime.js +6 -2
- package/dist/plugins/pi/tool-result.d.ts +2 -1
- package/dist/plugins/pi/window.js +24 -1
- package/dist/src/boot/render.d.ts +3 -4
- package/dist/src/boot/render.js +23 -21
- package/dist/src/boot/text.d.ts +2 -5
- package/dist/src/boot/text.js +12 -9
- package/dist/src/budget/text.d.ts +1 -1
- package/dist/src/budget/text.js +1 -1
- package/dist/src/history/corpus.d.ts +1 -1
- package/dist/src/history/corpus.js +1 -1
- package/dist/src/history/history.d.ts +2 -2
- package/dist/src/history/history.js +5 -8
- package/dist/src/history/query.d.ts +11 -3
- package/dist/src/history/query.js +7 -11
- package/dist/src/index.d.ts +4 -3
- package/dist/src/index.js +1 -1
- package/dist/src/notes/constants.d.ts +1 -1
- package/dist/src/notes/constants.js +1 -1
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.d.ts +2 -1
- package/dist/src/notes/frontmatter.js +3 -1
- package/dist/src/notes/index.d.ts +1 -0
- package/dist/src/notes/index.js +1 -0
- package/dist/src/notes/policy.d.ts +16 -0
- package/dist/src/notes/policy.js +43 -0
- package/dist/src/notes/store.d.ts +8 -3
- package/dist/src/notes/store.js +64 -20
- package/dist/src/result.d.ts +21 -0
- package/dist/src/result.js +18 -0
- package/dist/src/text-match.d.ts +8 -0
- package/dist/src/text-match.js +34 -0
- package/dist/src/tools/dream.d.ts +9 -1
- package/dist/src/tools/dream.js +2 -1
- package/dist/src/tools/history.js +14 -5
- package/dist/src/tools/notes.d.ts +75 -13
- package/dist/src/tools/notes.js +58 -19
- package/dist/src/tools/output.d.ts +1 -3
- package/dist/src/tools/output.js +1 -19
- package/dist/src/tools/result.d.ts +2 -20
- package/dist/src/tools/result.js +4 -18
- package/dist/src/tools/schema.d.ts +3 -7
- package/dist/src/tools/schema.js +10 -16
- package/dist/test/agent-loop.test.js +78 -6
- package/dist/test/boot.integration.test.js +30 -3
- package/dist/test/claude-mod.test.js +7 -6
- package/dist/test/codex-history.test.js +2 -2
- package/dist/test/codex-plugin.test.js +2 -0
- package/dist/test/dependencies.test.js +38 -3
- package/dist/test/dsh.test.js +1 -1
- package/dist/test/helpers/dependency-graph.js +12 -6
- package/dist/test/helpers/extension.d.ts +2 -1
- package/dist/test/history.integration.test.js +47 -1
- package/dist/test/host-neutral.test.js +4 -3
- package/dist/test/model-facing-text.test.js +20 -16
- package/dist/test/note-policy.test.d.ts +1 -0
- package/dist/test/note-policy.test.js +227 -0
- package/dist/test/notes-query-namespaces.test.js +7 -3
- package/dist/test/notes.integration.test.js +10 -10
- package/dist/test/notes.test.js +4 -4
- package/dist/test/pi-render.test.js +28 -1
- package/dist/test/project-namespace.test.js +1 -1
- package/docs/architecture.md +10 -7
- package/docs/dsh.md +1 -1
- package/docs/notes-library.md +20 -7
- package/docs/reset-lifecycle.md +2 -2
- package/docs/tool-results.md +3 -1
- package/package.json +12 -12
- package/playbook.md +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +528 -422
- package/plugins/claude/hooks/register.ts +1 -10
- package/plugins/claude/playbook.md +1 -1
- package/plugins/claude/skills/dream/SKILL.md +1 -1
- package/plugins/claude/skills/memory/SKILL.md +1 -1
- package/plugins/claude/src/helper.ts +2 -11
- package/plugins/claude/src/thresholds.ts +5 -15
- package/plugins/codex/dist/codex/notesoup.js +520 -403
- package/plugins/codex/src/mcp.ts +5 -12
- package/plugins/codex/src/state.ts +1 -1
- package/plugins/dsh/tools.ts +2 -1
- package/plugins/pi/boot.ts +3 -4
- package/plugins/pi/budget.ts +1 -1
- package/plugins/pi/render.ts +20 -8
- package/plugins/pi/runtime.ts +6 -2
- package/plugins/pi/tool-result.ts +2 -1
- package/plugins/pi/window.ts +20 -1
- package/skills/dream/SKILL.md +1 -1
- package/skills/memory/SKILL.md +1 -1
- package/src/boot/render.ts +24 -21
- package/src/boot/text.ts +12 -9
- package/src/budget/text.ts +1 -1
- package/src/history/corpus.ts +1 -1
- package/src/history/history.ts +5 -6
- package/src/history/query.ts +11 -14
- package/src/index.ts +5 -2
- package/src/notes/constants.ts +1 -1
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +4 -2
- package/src/notes/index.ts +1 -0
- package/src/notes/policy.ts +49 -0
- package/src/notes/store.ts +66 -26
- package/src/result.ts +26 -0
- package/src/text-match.ts +32 -0
- package/src/tools/dream.ts +2 -1
- package/src/tools/history.ts +15 -6
- package/src/tools/notes.ts +60 -20
- package/src/tools/output.ts +1 -17
- package/src/tools/result.ts +4 -26
- package/src/tools/schema.ts +11 -17
- package/dist/plugins/codex/src/history.d.ts +0 -3
- package/dist/plugins/codex/src/history.js +0 -2
- package/dist/plugins/codex/src/transcript.d.ts +0 -3
- package/dist/plugins/codex/src/transcript.js +0 -2
- package/plugins/codex/src/history.ts +0 -3
- package/plugins/codex/src/transcript.ts +0 -3
package/plugins/codex/src/mcp.ts
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { CallToolRequestSchema, ListToolsRequestSchema, type CallToolResult, type Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
-
import { Check
|
|
5
|
+
import { Check } from "typebox/value";
|
|
6
|
+
import { paramProblem } from "../../../src/tools/schema.js";
|
|
6
7
|
import type { TSchema } from "typebox";
|
|
7
8
|
import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../../../src/tools/notes.js";
|
|
8
9
|
import { historyList, historyRead } from "../../../src/tools/history.js";
|
|
9
|
-
import
|
|
10
|
+
import type { Outcome } from "../../../src/result.js";
|
|
11
|
+
import { wireResult, type Operation } from "../../../src/tools/result.js";
|
|
10
12
|
import { CodexIdentityError, notesIdentityFor, pluginDataRoot, readBinding, rootSessionIdOf, safeThreadId, turnModel, type ThreadBinding } from "./identity.js";
|
|
11
|
-
import { readCodexHistory } from "
|
|
13
|
+
import { readCodexHistory } from "../../../src/history/codex.js";
|
|
12
14
|
import { localHistoryCorpus } from "../../../src/history/local.js";
|
|
13
15
|
import { readStartState } from "./state.js";
|
|
14
16
|
import { notesToolContext } from "../../../src/tools/notes-context.js";
|
|
@@ -51,15 +53,6 @@ function successFor(bound: Bound, outcome: Outcome<unknown>): CallToolResult {
|
|
|
51
53
|
};
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
/** The first schema violation, named by parameter so the model can fix that one field. */
|
|
55
|
-
function paramProblem(schema: TSchema, params: unknown): string {
|
|
56
|
-
const first = Errors(schema, params).find((error) => error.keyword !== "boolean");
|
|
57
|
-
if (!first) return "unrecognized shape";
|
|
58
|
-
const extra = first.keyword === "additionalProperties" ? `: ${(first.params as { additionalProperties: string[] }).additionalProperties.join(", ")}` : "";
|
|
59
|
-
const field = first.instancePath.replace(/^\//, "").replaceAll("/", ".");
|
|
60
|
-
return `${field ? `${field} ` : ""}${first.message}${extra}`;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
56
|
type NativeFacts = { threadId: string; rootSessionId: string; currentWindowId?: string };
|
|
64
57
|
|
|
65
58
|
/** MCP metadata is the caller's claim; it must agree with the hook binding before any read. */
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { DEFAULT_BOOT_TOOL_NAMES } from "../../../src/boot/text.js";
|
|
3
3
|
import { renderBootBlock, type BootWindowTree } from "../../../src/boot/render.js";
|
|
4
4
|
import type { NotesSnapshot } from "../../../src/boot/snapshot.js";
|
|
5
|
-
import { readCodexTranscript, type CodexRecord, type CodexTranscriptSource, type CodexTranscriptState } from "
|
|
5
|
+
import { readCodexTranscript, type CodexRecord, type CodexTranscriptSource, type CodexTranscriptState } from "../../../src/history/codex-transcript.js";
|
|
6
6
|
import { CODEX_PRE_RESET_HINTS, CODEX_WIPE_SENTENCE } from "./text.js";
|
|
7
7
|
|
|
8
8
|
export type CodexSource = CodexTranscriptSource;
|
package/plugins/dsh/tools.ts
CHANGED
|
@@ -6,7 +6,8 @@ import type { Static, TSchema } from "typebox";
|
|
|
6
6
|
import { Check, Errors } from "typebox/value";
|
|
7
7
|
import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../../src/tools/notes.js";
|
|
8
8
|
import { historyList, historyRead } from "../../src/tools/history.js";
|
|
9
|
-
import { success
|
|
9
|
+
import { success } from "../../src/result.js";
|
|
10
|
+
import type { Operation } from "../../src/tools/result.js";
|
|
10
11
|
import { historyContext } from "./history.js";
|
|
11
12
|
import { notesCwd, notesIdentity } from "./window.js";
|
|
12
13
|
import { notesToolContext } from "../../src/tools/notes-context.js";
|
package/plugins/pi/boot.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { DEFAULT_BOOT_TOOL_NAMES } from "../../src/boot/text.js";
|
|
2
|
-
import { PI_PRE_RESET_HINTS } from "./text.js";
|
|
3
2
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
3
|
import { agentSlug, modelSlug, notesIdentityFromPi } from "./notes/adapter.js";
|
|
5
4
|
import { loadNotesSnapshot, unavailableNotesSnapshot, type NotesSnapshot } from "../../src/boot/snapshot.js";
|
|
6
5
|
import { isFilesystemError } from "../../src/notes/index.js";
|
|
7
6
|
import { BOOT_TYPE } from "./entries.js";
|
|
8
|
-
import {
|
|
7
|
+
import { renderBootContext } from "../../src/boot/render.js";
|
|
9
8
|
import { historyFromSession, nextHistorySeq } from "./history.js";
|
|
10
9
|
|
|
11
10
|
export type IncompleteNotesNotifier = (ctx: ExtensionContext, windowId: string, snapshot: NotesSnapshot) => void;
|
|
12
11
|
|
|
13
|
-
/** The
|
|
12
|
+
/** The hidden user boot: window identity and notes snapshot; teaching belongs to system sections. */
|
|
14
13
|
export type BootMessage = {
|
|
15
14
|
readonly customType: string;
|
|
16
15
|
readonly content: string;
|
|
@@ -65,7 +64,7 @@ export async function buildBootMessage(
|
|
|
65
64
|
if (isCurrent()) notifyIncompleteNotes?.(ctx, windowId, notes);
|
|
66
65
|
return {
|
|
67
66
|
customType: BOOT_TYPE,
|
|
68
|
-
content:
|
|
67
|
+
content: renderBootContext({ agentName, modelName, tree, notes, tools: DEFAULT_BOOT_TOOL_NAMES }),
|
|
69
68
|
display: false,
|
|
70
69
|
details: { windowId },
|
|
71
70
|
};
|
package/plugins/pi/budget.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_BOOT_TOOL_NAMES } from "../../src/boot/text.js";
|
|
2
2
|
import { remainingBudget, type ResolvedThresholds } from "../../src/budget/policy.js";
|
|
3
3
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
4
|
-
import { Type } from "
|
|
4
|
+
import { Type } from "typebox";
|
|
5
5
|
import { convertToLlm, defineTool, type ExtensionAPI, type ExtensionContext, type SessionBoundaryDraft, type SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { GUIDANCE_TYPE, WARNING_TYPE } from "./entries.js";
|
|
7
7
|
import { estimateContextTokens } from "./estimate.js";
|
package/plugins/pi/render.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/** Pi TUI renderers
|
|
1
|
+
/** Pi TUI renderers: compact slips with visible policy/warnings, expandable bodies. */
|
|
2
2
|
import { renderDiff, type AgentToolResult, type Theme } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import { Text, TruncatedText, truncateToWidth, visibleWidth, type Component } from "@earendil-works/pi-tui";
|
|
3
|
+
import { Container, Text, TruncatedText, truncateToWidth, visibleWidth, type Component } from "@earendil-works/pi-tui";
|
|
4
4
|
import type { Static } from "typebox";
|
|
5
|
+
import type { NotePolicy } from "../../src/notes/index.js";
|
|
5
6
|
import type { NotesReadData, NotesUpdateData, NotesWriteData } from "../../src/tools/notes.js";
|
|
6
7
|
import { notesReadParameters, notesUpdateParameters, notesWriteParameters } from "../../src/tools/notes.js";
|
|
7
8
|
|
|
@@ -61,6 +62,20 @@ function boundedLines(text: string, theme: Theme): string {
|
|
|
61
62
|
return `${lines.slice(0, EXPANDED_LINE_CAP).join("\n")}\n${theme.fg("dim", `… ${lines.length - EXPANDED_LINE_CAP} more lines`)}`;
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
/** Keep policy and warnings outside the clipped summary and expandable body, even when collapsed.
|
|
66
|
+
* Older persisted receipts may have neither; don't invent policy for those results.
|
|
67
|
+
*/
|
|
68
|
+
function noteResult(head: string, policy: Partial<NotePolicy> | undefined, warnings: string[] | undefined, expanded: boolean, body: string | undefined, theme: Theme): Component {
|
|
69
|
+
const result = new Container();
|
|
70
|
+
result.addChild(expanded ? new Text(head, 0, 0) : new TruncatedText(head, 0, 0));
|
|
71
|
+
if (policy?.pinned !== undefined && policy.budget !== undefined && policy.readonly !== undefined) {
|
|
72
|
+
result.addChild(new Text(theme.fg("dim", `pinned ${policy.pinned} | budget ${policy.budget} | readonly ${policy.readonly}`), 0, 0));
|
|
73
|
+
}
|
|
74
|
+
for (const warning of warnings ?? []) result.addChild(new Text(theme.fg("warning", warning), 0, 0));
|
|
75
|
+
if (expanded && body) result.addChild(new Text(`\n${body}`, 0, 0));
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
64
79
|
export type NotesWriteArgs = Static<typeof notesWriteParameters>;
|
|
65
80
|
export const notesWriteRenderers = {
|
|
66
81
|
renderCall: (args: NotesWriteArgs, theme: Theme): Component => callLine(theme, "notes_write", args.address),
|
|
@@ -71,8 +86,7 @@ export const notesWriteRenderers = {
|
|
|
71
86
|
const content = typeof context.args?.content === "string" ? context.args.content : "";
|
|
72
87
|
const qualifier = data.outcome === "created" ? "" : theme.fg("dim", ` · ${data.outcome}`);
|
|
73
88
|
const head = `wrote ${addressText(theme, data.address)}${qualifier}${theme.fg("dim", ` · ${Array.from(content).length} chars`)}`;
|
|
74
|
-
|
|
75
|
-
return new Text(`${head}\n\n${boundedLines(content, theme)}`, 0, 0);
|
|
89
|
+
return noteResult(head, data, data.warnings, options.expanded, options.expanded ? boundedLines(content, theme) : undefined, theme);
|
|
76
90
|
},
|
|
77
91
|
};
|
|
78
92
|
|
|
@@ -105,8 +119,7 @@ export const notesUpdateRenderers = {
|
|
|
105
119
|
const peek = firstAddedLine(diff);
|
|
106
120
|
if (peek !== undefined && peek !== "") head += theme.fg("dim", " · ") + theme.fg("toolDiffAdded", `+ ${peek}`);
|
|
107
121
|
}
|
|
108
|
-
|
|
109
|
-
return new Text(diff !== "" ? `${head}\n\n${renderDiff(diff)}` : head, 0, 0);
|
|
122
|
+
return noteResult(head, data, data.warnings, options.expanded, options.expanded && diff !== "" ? renderDiff(diff) : undefined, theme);
|
|
110
123
|
},
|
|
111
124
|
};
|
|
112
125
|
|
|
@@ -122,9 +135,8 @@ export const notesReadRenderers = {
|
|
|
122
135
|
let head = `read ${addressText(theme, data.address)}${theme.fg("dim", ` · ${data.total_chars} chars${truncated ? " · truncated" : ""}`)}`;
|
|
123
136
|
const peek = data.text.split("\n").find((line) => line.trim() !== "");
|
|
124
137
|
if (peek !== undefined) head += theme.fg("dim", ` — ${peek.trim()}`);
|
|
125
|
-
if (!options.expanded) return new TruncatedText(head, 0, 0);
|
|
126
138
|
const tail = truncated ? `\n${theme.fg("dim", `… continue at offset_chars=${data.next_offset_chars}`)}` : "";
|
|
127
|
-
return
|
|
139
|
+
return noteResult(head, data.metadata, data.warnings, options.expanded, options.expanded ? `${boundedLines(data.text, theme)}${tail}` : undefined, theme);
|
|
128
140
|
},
|
|
129
141
|
};
|
|
130
142
|
|
package/plugins/pi/runtime.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { resetBoundaryCommitted } from "./reset/committed.js";
|
|
3
|
-
import { getCurrentSystemMessage
|
|
3
|
+
import { getCurrentSystemMessage } from "@earendil-works/pi-ai";
|
|
4
|
+
import { Type } from "typebox";
|
|
4
5
|
import { VERSION, defineTool, type ExtensionAPI, type ExtensionCommandContext, type ExtensionContext, type SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
5
6
|
import { registerBudget } from "./budget.js";
|
|
6
7
|
import { DREAM_NAMESPACE, HISTORY_NAMESPACE, NOTES_NAMESPACE, output } from "./tool-result.js";
|
|
@@ -9,7 +10,9 @@ import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, i
|
|
|
9
10
|
import { registerResetLifecycle } from "./reset/lifecycle.js";
|
|
10
11
|
import { buildResetDrafts, LAST_WORD_ADVERTISED_CHARS, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
|
|
11
12
|
import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
|
|
12
|
-
import { commandWarningContent } from "./text.js";
|
|
13
|
+
import { commandWarningContent, PI_PRE_RESET_HINTS } from "./text.js";
|
|
14
|
+
import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, renderProtocolBlock } from "../../src/boot/text.js";
|
|
15
|
+
import { agentSlug } from "./notes/adapter.js";
|
|
13
16
|
import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "./boot.js";
|
|
14
17
|
import { maybeSendMarker } from "./marker.js";
|
|
15
18
|
import { nextHistorySeq } from "./history.js";
|
|
@@ -82,6 +85,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
82
85
|
};
|
|
83
86
|
pi.on("before_agent_start", (event, ctx) => {
|
|
84
87
|
event.systemPromptOptions.sections.notesoup_tools = notesoupTools;
|
|
88
|
+
event.systemPromptOptions.sections.notesoup_protocol = `${renderProtocolBlock({ ...DEFAULT_BOOT_TOOL_NAMES, preResetHints: PI_PRE_RESET_HINTS }, agentSlug())}\n\n${MAPS_BLOCK}`;
|
|
85
89
|
if (enabled) maybeSendMarker(pi, ctx);
|
|
86
90
|
});
|
|
87
91
|
pi.on("turn_start", (_event, ctx) => {
|
|
@@ -3,7 +3,8 @@ import { defineTool, type ExtensionAPI, type ExtensionToolContext, type ToolDefi
|
|
|
3
3
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
4
4
|
import type { JsonValue } from "@earendil-works/pi-ai";
|
|
5
5
|
import type { Static, TSchema } from "typebox";
|
|
6
|
-
import
|
|
6
|
+
import type { Outcome } from "../../src/result.js";
|
|
7
|
+
import { wireResult, type Operation, type Renderer } from "../../src/tools/result.js";
|
|
7
8
|
|
|
8
9
|
/** Pi's JSON envelope for reset and budget tools; details carry only log/UI metadata. */
|
|
9
10
|
export function output(value: unknown, details?: unknown, terminate = false) {
|
package/plugins/pi/window.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { estimateContextTokens } from "./estimate.js";
|
|
|
4
4
|
import { convertToLlm, type CustomEntry, type ExtensionContext, type SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import { BOOT_TYPE, RESET_MARKER_TYPE } from "./entries.js";
|
|
6
6
|
import type { ResetOrigin } from "../../src/budget/text.js";
|
|
7
|
+
import { NOTES_PROTOCOL_OPEN_TAG, NOTES_PROTOCOL_CLOSE_TAG, WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG } from "../../src/boot/text.js";
|
|
7
8
|
import type { SessionReader } from "./session-reader.js";
|
|
8
9
|
|
|
9
10
|
export type WindowMarkerData = { readonly windowId: string; readonly origin?: ResetOrigin };
|
|
@@ -99,6 +100,23 @@ export function isWindowBootEntry(entry: SessionEntry, windowId: string): boolea
|
|
|
99
100
|
return entry.type === "custom_message" && entry.customType === BOOT_TYPE && hasWindowId(entry.details, windowId);
|
|
100
101
|
}
|
|
101
102
|
|
|
103
|
+
/** Strip only the old boot's leading teaching blocks, never tags quoted inside its notes. */
|
|
104
|
+
function withoutBootTeaching(message: AgentMessage): AgentMessage {
|
|
105
|
+
if (message.role !== "custom" || typeof message.content !== "string" || !message.content.startsWith(`${WINDOW_IDENTITY_OPEN_TAG}\n`)) return message;
|
|
106
|
+
const identityEnd = message.content.indexOf(`\n${WINDOW_IDENTITY_CLOSE_TAG}\n\n`);
|
|
107
|
+
if (identityEnd < 0) return message;
|
|
108
|
+
const start = identityEnd + `\n${WINDOW_IDENTITY_CLOSE_TAG}\n\n`.length;
|
|
109
|
+
let rest = message.content.slice(start);
|
|
110
|
+
for (const [open, close] of [[NOTES_PROTOCOL_OPEN_TAG, NOTES_PROTOCOL_CLOSE_TAG], ["<notesoup:maps>", "</notesoup:maps>"]]) {
|
|
111
|
+
if (!rest.startsWith(`${open}\n`)) return message;
|
|
112
|
+
const end = rest.indexOf(`\n${close}\n\n`);
|
|
113
|
+
if (end < 0) return message;
|
|
114
|
+
rest = rest.slice(end + `\n${close}\n\n`.length);
|
|
115
|
+
}
|
|
116
|
+
if (!rest.startsWith("YOUR NOTES\n──────────\n")) return message;
|
|
117
|
+
return { ...message, content: message.content.slice(0, start) + rest };
|
|
118
|
+
}
|
|
119
|
+
|
|
102
120
|
/**
|
|
103
121
|
* The durable marker selects a boot message by identity, never by wall-clock time.
|
|
104
122
|
* The boot is the first conversation message of the window. Folding only its prefix
|
|
@@ -109,6 +127,7 @@ export function projectWindow(messages: AgentMessage[], windowId: string): Agent
|
|
|
109
127
|
if (cut < 0) throw new Error(`Missing boot for context window ${windowId}`);
|
|
110
128
|
const head = getCurrentSystemMessage(messages.slice(0, cut));
|
|
111
129
|
const suffix = messages.slice(cut);
|
|
130
|
+
suffix[0] = withoutBootTeaching(suffix[0]!);
|
|
112
131
|
return head ? [head, ...suffix] : suffix;
|
|
113
132
|
}
|
|
114
133
|
|
|
@@ -120,7 +139,7 @@ export function projectWindow(messages: AgentMessage[], windowId: string): Agent
|
|
|
120
139
|
export function projectRootWindow(messages: AgentMessage[], windowId: string): AgentMessage[] {
|
|
121
140
|
const matching = messages.filter((message) => isWindowBoot(message, windowId));
|
|
122
141
|
if (matching.length === 0) return messages;
|
|
123
|
-
const activeBoot = matching[matching.length - 1];
|
|
142
|
+
const activeBoot = withoutBootTeaching(matching[matching.length - 1]!);
|
|
124
143
|
const firstBoot = messages.findIndex((message) => isWindowBoot(message));
|
|
125
144
|
const withoutBoots = messages.filter((message) => !isWindowBoot(message));
|
|
126
145
|
return [...withoutBoots.slice(0, firstBoot), activeBoot, ...withoutBoots.slice(firstBoot)];
|
package/skills/dream/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: Review and consolidate durable notes using notesoup's shared dream
|
|
|
5
5
|
|
|
6
6
|
# Dream
|
|
7
7
|
|
|
8
|
-
Read `../../playbook.md` completely, resolving the path from this skill's directory. It is the shared guide to reviewing and organizing notes. Standing reminders belong in a separate `CHEATSHEET.md` (five lines); `MAP.md` holds only the note index. Both load every window when
|
|
8
|
+
Read `../../playbook.md` completely, resolving the path from this skill's directory. It is the shared guide to reviewing and organizing notes. Standing reminders belong in a separate `CHEATSHEET.md` (five lines); `MAP.md` holds only the note index. Both default to pinned and load every window when live unless explicitly unpinned. Every note defaults to a 2048-code-point advisory budget, adjustable per note; pinned bodies load whole with overflow warnings. Respect soft readonly locks; explicitly unlock with `readonly:false` before changing a locked note.
|
|
9
9
|
|
|
10
10
|
Dream in this agent's current session. Do not start another agent or model unless the human asks.
|
|
11
11
|
|
package/skills/memory/SKILL.md
CHANGED
|
@@ -32,7 +32,7 @@ Any other `@` prefix is refused. A path is relative and `/`-separated, with no e
|
|
|
32
32
|
|
|
33
33
|
`@` addresses are not file paths: never pass them to file tools like `read`, `write`, `edit`, or `bash`. That creates a stray directory instead of a note.
|
|
34
34
|
|
|
35
|
-
`CHEATSHEET.md` and `MAP.md` at
|
|
35
|
+
`CHEATSHEET.md` and `MAP.md` at each notebook's root are separate default-pinned pages you wake up with; absent or crumpled pages are skipped. Set `pinned`, `budget`, and `readonly` through `notes_write`/`notes_update` or frontmatter. Explicit `pinned:false` unpins even a default page. Each notebook allows five live pins; every page defaults to a 2048-code-point advisory budget, adjustable per note. Overflow warns but saves, and pinned bodies load whole. `readonly:true` is a soft lock, not security; explicitly set `readonly:false` to unlock, alone or alongside your changes. Keep standing reminders in `CHEATSHEET.md`, to five lines. `MAP.md` holds only the note index: each durable note's address and gist, for lookup. Update it whenever you add, move or crumple a durable note. Do not create empty pages.
|
|
36
36
|
|
|
37
37
|
Keep notes focused on what is true now; if a piece of past context still matters (such as why an approach was ruled out), keep only a brief summary rather than a blow-by-blow log. Crumple notes that are no longer true; a stale note is worse than none.
|
|
38
38
|
|
package/src/boot/render.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NotesNamespace, NotesSnapshot } from "./snapshot.js";
|
|
2
|
-
import {
|
|
2
|
+
import { effectiveNotePolicy, MAX_PINNED_NOTES, noteBudgetWarnings, pinnedPageOrder } from "../notes/policy.js";
|
|
3
|
+
import { WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG, MAPS_BLOCK, NAMELESS_AGENT, SHELF_FRESH_LIMIT, renderProtocolBlock, type BootToolNames } from "./text.js";
|
|
3
4
|
|
|
4
5
|
function relativeTime(timestamp: number, now: number): string {
|
|
5
6
|
const seconds = Math.trunc((timestamp - now) / 1000);
|
|
@@ -49,12 +50,11 @@ function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames, agentName: st
|
|
|
49
50
|
continue;
|
|
50
51
|
}
|
|
51
52
|
const rows = (snapshot.namespaces.get(namespace.scope) ?? []).filter((row) => row.meta.crumpledAt === undefined);
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
53
|
+
const pins = rows.filter(row => effectiveNotePolicy(row.meta, row.path).pinned)
|
|
54
|
+
.sort((a, b) => pinnedPageOrder(a.path) - pinnedPageOrder(b.path) || a.path.localeCompare(b.path));
|
|
55
|
+
const pinned = pins.slice(0, MAX_PINNED_NOTES);
|
|
56
56
|
const fresh = rows
|
|
57
|
-
.filter(
|
|
57
|
+
.filter(row => !effectiveNotePolicy(row.meta, row.path).pinned)
|
|
58
58
|
.slice(0, SHELF_FRESH_LIMIT)
|
|
59
59
|
.map((row) => {
|
|
60
60
|
const locator = `${row.address} · ${relativeTime(row.meta.updatedAt, snapshot.openedAt)}`;
|
|
@@ -62,7 +62,11 @@ function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames, agentName: st
|
|
|
62
62
|
return title === undefined ? ` ${locator}` : ` ${title}\n ${locator}`;
|
|
63
63
|
});
|
|
64
64
|
if (pinned.length === 0 && fresh.length === 0) continue;
|
|
65
|
-
const parts = pinned.map(
|
|
65
|
+
const parts = pinned.map(row => {
|
|
66
|
+
const warnings = noteBudgetWarnings(row.body, effectiveNotePolicy(row.meta, row.path));
|
|
67
|
+
return `${row.address}\n\n${indent([...warnings, row.body].join("\n"))}`;
|
|
68
|
+
});
|
|
69
|
+
if (pins.length > MAX_PINNED_NOTES) parts.push(indent(`Warning: only ${MAX_PINNED_NOTES} pinned notes per notebook are injected; omitted pins: ${pins.slice(MAX_PINNED_NOTES).map(row => row.address).join(", ")}. Unpin some notes or read the omitted pages with ${tools.notes}.`));
|
|
66
70
|
if (fresh.length > 0) parts.push(`recent\n\n${fresh.join("\n\n")}`);
|
|
67
71
|
shelves.push(section(namespace.label, parts.join("\n\n")));
|
|
68
72
|
}
|
|
@@ -72,13 +76,6 @@ function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames, agentName: st
|
|
|
72
76
|
: "YOUR NOTES\n──────────\n\nNone yet. A blank slate is a fine place to start — just don't finish there.";
|
|
73
77
|
}
|
|
74
78
|
|
|
75
|
-
/** Each pinned page is bounded; the cut names where the rest lives. */
|
|
76
|
-
function pinnedBodyForBoot(address: string, body: string, maxChars: number): string {
|
|
77
|
-
const chars = Array.from(body);
|
|
78
|
-
if (chars.length <= maxChars) return body;
|
|
79
|
-
return `${chars.slice(0, maxChars).join("")}\n[truncated at ${maxChars} chars; slim this page down, full body at \`${address}\`]`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
79
|
export type BootWindowTree = {
|
|
83
80
|
readonly trunk: string;
|
|
84
81
|
readonly windows: ReadonlyArray<{
|
|
@@ -97,11 +94,8 @@ export type BootRenderData = {
|
|
|
97
94
|
readonly tools: BootToolNames;
|
|
98
95
|
};
|
|
99
96
|
|
|
100
|
-
/**
|
|
101
|
-
|
|
102
|
-
* notes or call runtime UI APIs; acquisition belongs to loadNotesSnapshot and its caller.
|
|
103
|
-
*/
|
|
104
|
-
export function renderBootBlock(data: BootRenderData): string {
|
|
97
|
+
/** Render the window identity without reading notes or consulting the host. */
|
|
98
|
+
function renderIdentity(data: BootRenderData): string {
|
|
105
99
|
// Root, the window before this one, and this one: the block is rewritten every window, so an
|
|
106
100
|
// unbounded list would repeat the whole history once per window for no new information.
|
|
107
101
|
const shown = new Set([0, data.tree.windows.length - 2, data.tree.windows.length - 1]);
|
|
@@ -117,6 +111,15 @@ export function renderBootBlock(data: BootRenderData): string {
|
|
|
117
111
|
return `${window.isCurrent ? "└─" : "├─"} ${name}${range}${window.isCurrent ? " ← you are here" : ""}`;
|
|
118
112
|
}),
|
|
119
113
|
];
|
|
120
|
-
|
|
121
|
-
|
|
114
|
+
return `${WINDOW_IDENTITY_OPEN_TAG}\n${lines.join("\n")}\n${WINDOW_IDENTITY_CLOSE_TAG}`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Window data only: identity and the closed notes snapshot, never protocol teaching. */
|
|
118
|
+
export function renderBootContext(data: BootRenderData): string {
|
|
119
|
+
return [renderIdentity(data), notesIndex(data.notes, data.tools, data.agentName, data.modelName)].join("\n\n");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Full boot for hosts that keep protocol teaching alongside their window data. */
|
|
123
|
+
export function renderBootBlock(data: BootRenderData): string {
|
|
124
|
+
return [renderIdentity(data), renderProtocolBlock(data.tools, data.agentName), MAPS_BLOCK, notesIndex(data.notes, data.tools, data.agentName, data.modelName)].join("\n\n");
|
|
122
125
|
}
|
package/src/boot/text.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/** Each shelf shows this many of its own freshest pages beneath its pinned pages. */
|
|
2
2
|
export const SHELF_FRESH_LIMIT = 3;
|
|
3
|
-
/** Each pinned page has its own code-point cap; overflow keeps a lookup pointer. */
|
|
4
|
-
export const CHEATSHEET_BOOT_MAX_CHARS = 1536;
|
|
5
|
-
export const MAP_BOOT_MAX_CHARS = 4096;
|
|
6
3
|
export const WINDOW_IDENTITY_OPEN_TAG = "<notesoup:window_identity>";
|
|
7
4
|
export const WINDOW_IDENTITY_CLOSE_TAG = "</notesoup:window_identity>";
|
|
8
5
|
export const NOTES_PROTOCOL_OPEN_TAG = "<notesoup:notes_protocol>";
|
|
@@ -20,8 +17,8 @@ const PROTOCOL_SELF_NAMELESS = `${PROTOCOL_SELF_NAMED} Except you have no name (
|
|
|
20
17
|
|
|
21
18
|
/**
|
|
22
19
|
* Static protocol teaching adapted from Codex's token_budget.guidance_message to
|
|
23
|
-
* notesoup's tool names.
|
|
24
|
-
* it
|
|
20
|
+
* notesoup's tool names. Pi supplies it as a named system section; other hosts
|
|
21
|
+
* retain it in their persisted boot block. Neither path reads note content.
|
|
25
22
|
*
|
|
26
23
|
* The reported room reaches zero at the hard-reserve wipe line.
|
|
27
24
|
*/
|
|
@@ -59,12 +56,18 @@ Any other @ address is fake. End of discussion. @ addresses are not file paths:
|
|
|
59
56
|
${NOTES_PROTOCOL_CLOSE_TAG}`;
|
|
60
57
|
|
|
61
58
|
/**
|
|
62
|
-
*
|
|
59
|
+
* Default pinned pages and per-note policy are taught between the protocol and the notes index.
|
|
63
60
|
*/
|
|
64
61
|
export const MAPS_BLOCK = `<notesoup:maps>
|
|
65
|
-
Every notebook's root
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
Every notebook's root has two default pins: \`CHEATSHEET.md\` and \`MAP.md\`.
|
|
63
|
+
Pinned pages get jammed straight into your brain the moment you wake up. Whoever wakes up next
|
|
64
|
+
reads them, and next is you. So keep them short, and keep them true.
|
|
65
|
+
|
|
66
|
+
Set \`pinned\`, \`budget\`, and \`readonly\` with the note tools or frontmatter. Each notebook allows five
|
|
67
|
+
live pins, including the defaults; \`pinned:false\` unpins even a default page. Every page's budget
|
|
68
|
+
starts at 2048 Unicode code points; set a positive integer to change it. Going over warns but saves,
|
|
69
|
+
and pinned bodies arrive whole, not cut short. \`readonly:true\` is a soft lock, not security;
|
|
70
|
+
explicitly set \`readonly:false\` to unlock, on its own or with your changes.
|
|
68
71
|
|
|
69
72
|
- **\`CHEATSHEET.md\`** holds what you'll want next time — a rule, a warning, a grudge, a name,
|
|
70
73
|
a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat
|
package/src/budget/text.ts
CHANGED
|
@@ -33,7 +33,7 @@ export const WARNING_TIMING = "The reserve is nearly spent. The wipe lands at th
|
|
|
33
33
|
|
|
34
34
|
/** The shared handoff instructions, used for both budget and manual close-outs. */
|
|
35
35
|
export const WARNING_BODY =
|
|
36
|
-
"Stop the task. Write down what git and history can't give back:\n- where you are, and how far you got\n- what the human decided, in their words\n- what's blocked or waiting\n- the next move\n- where the half-done work sits\n- what failed, and why\n- which skills, seqs, notes, or files to reopen\n- anything else worth noting\nThen leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim CHEATSHEET.md and MAP.md; every new window loads
|
|
36
|
+
"Stop the task. Write down what git and history can't give back:\n- where you are, and how far you got\n- what the human decided, in their words\n- what's blocked or waiting\n- the next move\n- where the half-done work sits\n- what failed, and why\n- which skills, seqs, notes, or files to reopen\n- anything else worth noting\nThen leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim pinned pages (CHEATSHEET.md and MAP.md by default); every new window loads the pins. The next window gets whatever you leave, dead notes and dead sections alike.\nDon't call anything that might return a large output. One big read can spend the rest of the reserve before your notes are saved.";
|
|
37
37
|
|
|
38
38
|
export const WARNING_CALL = "Then call `empty_brain`. Nothing in between.";
|
|
39
39
|
|
package/src/history/corpus.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** A read-only history corpus: identity/discovery is separate from loading a projection. */
|
|
2
|
-
import { failure, success, type Outcome } from "../
|
|
2
|
+
import { failure, success, type Outcome } from "../result.js";
|
|
3
3
|
import type { HistoryEvent, HistoryProjection } from "./history.js";
|
|
4
4
|
import { sessionRepresentative } from "./query.js";
|
|
5
5
|
|
package/src/history/history.ts
CHANGED
|
@@ -274,10 +274,9 @@ export function inSelection(event: HistoryEvent, params: HistoryFilter): boolean
|
|
|
274
274
|
return !Number.isNaN(at) && (params.sinceMs === undefined || at >= params.sinceMs) && (params.untilMs === undefined || at < params.untilMs);
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
-
/**
|
|
278
|
-
export function filteredItems(projection: HistoryProjection, params: HistoryFilter
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
return items.sort((a, b) => a.seq - b.seq);
|
|
277
|
+
/** Ordered events inside the requested seq/time range and optional roles, before folding. */
|
|
278
|
+
export function filteredItems(projection: HistoryProjection, params: HistoryFilter): HistoryEvent[] {
|
|
279
|
+
return allItems(projection)
|
|
280
|
+
.filter((item) => inSelection(item, params) && (!params.roles || params.roles.includes(item.role)))
|
|
281
|
+
.sort((a, b) => a.seq - b.seq);
|
|
283
282
|
}
|
package/src/history/query.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/** Stable-anchor paging, folding and literal matching. The operation supplies the full-response budget check. */
|
|
2
2
|
import { Type, type Static } from "typebox";
|
|
3
|
-
import { failure, success, type Outcome } from "../
|
|
4
|
-
import { prefixFit,
|
|
5
|
-
import { earliestMatchOffsetChars } from "../text-match.js";
|
|
6
|
-
import { InvalidQueryError, searchQueries } from "../tools/schema.js";
|
|
3
|
+
import { failure, success, type Outcome } from "../result.js";
|
|
4
|
+
import { earliestMatchOffsetChars, InvalidQueryError, prefixFit, searchQueries } from "../text-match.js";
|
|
7
5
|
import { eventDocument, filteredItems, visibleItem, HistoryFoldedRowSchema, HistoryPageItemSchema, MAX_FOLD_TOOL_NAMES, MAX_FOLD_TOOL_NAME_CHARS, type HistoryEvent, type HistoryFilter, type HistoryFoldedRow, type HistoryPageItem, type HistoryProjection } from "./history.js";
|
|
8
6
|
|
|
9
7
|
type Candidate = { event: HistoryEvent; session?: string; matchOffset?: number; preview?: HistoryPageItem; before?: HistoryFoldedRow };
|
|
@@ -66,6 +64,8 @@ export const HistoryPageSchema = Type.Object({
|
|
|
66
64
|
|
|
67
65
|
/** One whole page payload, before it becomes an outcome. */
|
|
68
66
|
export type HistoryPage = Static<typeof HistoryPageSchema>;
|
|
67
|
+
/** A caller's budget rejected even the shortest page; tool limits and refusal copy belong to the caller. */
|
|
68
|
+
export type HistoryPageResult = Outcome<HistoryPage> | { ok: false; pageTooLarge: { count: number; multi: boolean } };
|
|
69
69
|
|
|
70
70
|
/** Shorten preview text first; omit an oversized tool name rather than invent a partial name. */
|
|
71
71
|
function truncateHistoryItem(item: HistoryPageItem, fits: (candidate: HistoryPageItem) => boolean): HistoryPageItem {
|
|
@@ -102,7 +102,7 @@ function prepareSelection(projection: HistoryProjection, params: HistorySelectio
|
|
|
102
102
|
const folds = !params.roles && params.query === undefined;
|
|
103
103
|
const candidates: Candidate[] = [];
|
|
104
104
|
let run: HistoryEvent[] = [];
|
|
105
|
-
for (const event of filteredItems(projection, params
|
|
105
|
+
for (const event of filteredItems(projection, params)) {
|
|
106
106
|
if (folds && (event.role === "tool" || event.role === "context")) {
|
|
107
107
|
run.push(event);
|
|
108
108
|
continue;
|
|
@@ -151,7 +151,7 @@ function resolveSelection(params: HistorySelection): Outcome<HistorySelection> {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
export function selectPage(projection: HistoryProjection, params: HistorySelection, fits: (page: HistoryPage) => boolean, maxChars: number):
|
|
154
|
+
export function selectPage(projection: HistoryProjection, params: HistorySelection, fits: (page: HistoryPage) => boolean, maxChars: number): HistoryPageResult {
|
|
155
155
|
const scoped = resolveSelection(params);
|
|
156
156
|
if (!scoped.ok) return scoped;
|
|
157
157
|
return selectPrepared(prepareSelection(projection, scoped.data), scoped.data, fits, maxChars);
|
|
@@ -165,7 +165,7 @@ export function corpusSelection(params: HistorySelection): Outcome<HistorySelect
|
|
|
165
165
|
|
|
166
166
|
/** One topic per session, after role/time filtering; empty dialogue envelopes are not visible. */
|
|
167
167
|
export function sessionRepresentative(projection: HistoryProjection, scoped: HistorySelection): HistoryEvent | undefined {
|
|
168
|
-
const events = filteredItems(projection, scoped
|
|
168
|
+
const events = filteredItems(projection, scoped).filter((event) =>
|
|
169
169
|
(event.role !== "user" && event.role !== "assistant") || eventDocument(event) !== "");
|
|
170
170
|
if (scoped.roles) return events.at(-1);
|
|
171
171
|
return events.find((event) => event.role === "user")
|
|
@@ -217,7 +217,7 @@ export class CorpusCollector {
|
|
|
217
217
|
/** Returns whether this session contributes an overview representative. */
|
|
218
218
|
add(session: string, projection: HistoryProjection): boolean {
|
|
219
219
|
if (this.scoped.query === undefined) return this.addRepresentative(session, sessionRepresentative(projection, this.scoped));
|
|
220
|
-
for (const event of filteredItems(projection, this.scoped
|
|
220
|
+
for (const event of filteredItems(projection, this.scoped)) {
|
|
221
221
|
const document = eventDocument(event);
|
|
222
222
|
if ((event.role === "user" || event.role === "assistant") && document === "") continue;
|
|
223
223
|
const matchOffset = earliestMatchOffsetChars(document, this.scoped.query as string[]);
|
|
@@ -226,12 +226,12 @@ export class CorpusCollector {
|
|
|
226
226
|
return true;
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
page(fits: (page: HistoryPage) => boolean, maxChars: number, unvisited = false):
|
|
229
|
+
page(fits: (page: HistoryPage) => boolean, maxChars: number, unvisited = false): HistoryPageResult {
|
|
230
230
|
return selectPrepared({ candidates: this.candidates, multi: true, discarded: this.discarded || unvisited, from: this.scoped.from }, this.scoped, fits, maxChars);
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
function selectPrepared(prepared: PreparedSelection, scoped: HistorySelection, fits: (page: HistoryPage) => boolean, maxChars: number):
|
|
234
|
+
function selectPrepared(prepared: PreparedSelection, scoped: HistorySelection, fits: (page: HistoryPage) => boolean, maxChars: number): HistoryPageResult {
|
|
235
235
|
const { candidates } = prepared;
|
|
236
236
|
// Grow a contiguous interval from the requested end; even a byte-limited newest page stays ascending.
|
|
237
237
|
const from = scoped.from ?? (scoped.after_seq !== undefined ? "oldest" : "newest");
|
|
@@ -256,9 +256,6 @@ function selectPrepared(prepared: PreparedSelection, scoped: HistorySelection, f
|
|
|
256
256
|
break;
|
|
257
257
|
}
|
|
258
258
|
const page = pageData(prepared, start, end, maxChars);
|
|
259
|
-
if (!fits(page)) {
|
|
260
|
-
const narrow = prepared.multi ? "narrow the session pattern, query, roles or `since`/`until`, or read one session/seq with `history_read`" : "narrow with `before_seq`/`after_seq` or `since`/`until`, pass `roles` to skip folding, or `history_read` one seq";
|
|
261
|
-
return failure("page_too_large", `Even trimmed to their shortest, these ${page.items.length} rows${prepared.multi ? "" : " and their folded runs"} fill the ${TOOL_OUTPUT_LIMIT} a call can carry; ${narrow}.`);
|
|
262
|
-
}
|
|
259
|
+
if (!fits(page)) return { ok: false, pageTooLarge: { count: page.items.length, multi: prepared.multi === true } };
|
|
263
260
|
return success(page);
|
|
264
261
|
}
|
package/src/index.ts
CHANGED
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
// Notes: the standalone filesystem library, addressed by an explicit identity.
|
|
16
|
-
export { createNotesStore, noteIdentity, projectKey, slugify, NoteError } from "./notes/index.js";
|
|
16
|
+
export { createNotesStore, effectiveNotePolicy, noteIdentity, projectKey, slugify, NoteError } from "./notes/index.js";
|
|
17
17
|
export type {
|
|
18
18
|
NoteEditResult,
|
|
19
19
|
NoteMatch,
|
|
20
20
|
NoteMeta,
|
|
21
|
+
NotePolicy,
|
|
22
|
+
NotePolicyFields,
|
|
21
23
|
NoteReadResult,
|
|
22
24
|
NoteRenameResult,
|
|
23
25
|
NoteRow,
|
|
@@ -46,7 +48,8 @@ export { historyList, historyRead } from "./tools/history.js";
|
|
|
46
48
|
export { projectHistory } from "./history/history.js";
|
|
47
49
|
export type { HistoryProjection } from "./history/history.js";
|
|
48
50
|
export type { HistoryContext, HistoryCorpus, HistoryHarness, HistorySession, HistorySessionData } from "./history/corpus.js";
|
|
49
|
-
export type {
|
|
51
|
+
export type { OperationError, Outcome } from "./result.js";
|
|
52
|
+
export type { Operation, Renderer, TextWindow } from "./tools/result.js";
|
|
50
53
|
|
|
51
54
|
// Budget: pure thresholds and the approved reset prose.
|
|
52
55
|
export { deriveThresholds, remainingBudget } from "./budget/policy.js";
|
package/src/notes/constants.ts
CHANGED
package/src/notes/errors.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type NoteErrorCode = "not_found" | "already_exists" | "ambiguous_edit" | "no_match" | "invalid_edit" | "nothing_to_do" | "not_crumpled" | "too_large" | "invalid_scope" | "invalid_origin" | "invalid_address" | "invalid_pattern" | "invalid_query" | "invalid_offset" | "invalid_cwd" | "io_error" | "internal_error";
|
|
1
|
+
export type NoteErrorCode = "invalid_policy" | "pin_limit" | "readonly" | "not_found" | "already_exists" | "ambiguous_edit" | "no_match" | "invalid_edit" | "nothing_to_do" | "not_crumpled" | "too_large" | "invalid_scope" | "invalid_origin" | "invalid_address" | "invalid_pattern" | "invalid_query" | "invalid_offset" | "invalid_cwd" | "io_error" | "internal_error";
|
|
2
2
|
|
|
3
3
|
/** Typed store refusal. Edit locations are exposed in camelCase. */
|
|
4
4
|
export class NoteError extends Error {
|
package/src/notes/frontmatter.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Scope } from "./paths.js";
|
|
2
|
+
import { validateNotePolicy, type NotePolicyFields } from "./policy.js";
|
|
2
3
|
|
|
3
4
|
export type Origin = "user" | "self" | "external";
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ export type Origin = "user" | "self" | "external";
|
|
|
7
8
|
* sleep-shift keys survive this layer untouched when present. `[key: string]: unknown` carries
|
|
8
9
|
* any frontmatter key this layer does not know, preserved verbatim across rewrites.
|
|
9
10
|
*/
|
|
10
|
-
export type NoteMeta = {
|
|
11
|
+
export type NoteMeta = NotePolicyFields & {
|
|
11
12
|
scope: Scope;
|
|
12
13
|
origin: Origin;
|
|
13
14
|
/** Present only while the note is in the wastebasket; serialized as an ISO timestamp. */
|
|
@@ -29,7 +30,7 @@ const SCOPES: readonly Scope[] = ["session", "project", "human", "agent", "model
|
|
|
29
30
|
const ORIGINS: readonly Origin[] = ["user", "self", "external"];
|
|
30
31
|
const TIMESTAMP_KEYS = ["createdAt", "updatedAt", "lastAccessed"] as const;
|
|
31
32
|
/** Emission order, exactly the Design's key list. */
|
|
32
|
-
const KNOWN_KEYS = ["origin", "crumpledAt", "createdAt", "updatedAt", "lastAccessed", "accessCount", "sourceWindow", "supersedes", "recurrenceCount", "recurrenceWindows"] as const;
|
|
33
|
+
const KNOWN_KEYS = ["pinned", "budget", "readonly", "origin", "crumpledAt", "createdAt", "updatedAt", "lastAccessed", "accessCount", "sourceWindow", "supersedes", "recurrenceCount", "recurrenceWindows"] as const;
|
|
33
34
|
|
|
34
35
|
const pad2 = (value: number) => String(value).padStart(2, "0");
|
|
35
36
|
|
|
@@ -122,6 +123,7 @@ function parseFrontmatter(raw: string): { fields: Record<string, unknown>; body:
|
|
|
122
123
|
*/
|
|
123
124
|
export function parseNote(raw: string, now = Date.now()): { meta: NoteMeta; body: string } {
|
|
124
125
|
const { fields, body } = parseFrontmatter(raw);
|
|
126
|
+
validateNotePolicy(fields);
|
|
125
127
|
const meta = { ...fields } as Record<string, unknown>;
|
|
126
128
|
// scope is a legacy on-disk field: store callers derive it from the file's notebook and
|
|
127
129
|
// overwrite it after parsing, so an absent or outdated value just falls back.
|
package/src/notes/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createNotesStore, noteIdentity } from "./store.js";
|
|
2
|
+
export { effectiveNotePolicy, type NotePolicy, type NotePolicyFields } from "./policy.js";
|
|
2
3
|
export { NoteError, type NoteErrorCode } from "./errors.js";
|
|
3
4
|
export { projectKey } from "./project-namespace.js";
|
|
4
5
|
export { slugify } from "./paths.js";
|