notesoup 0.51.4 → 0.51.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +6 -0
  2. package/dist/plugins/pi/dream/cli.js +1 -1
  3. package/dist/plugins/pi/extension.js +4 -0
  4. package/dist/plugins/pi/notes/adapter.js +2 -2
  5. package/dist/plugins/pi/reset/artifacts.d.ts +3 -1
  6. package/dist/plugins/pi/reset/artifacts.js +3 -1
  7. package/dist/plugins/pi/runtime.js +2 -2
  8. package/dist/src/boot/text.js +1 -1
  9. package/dist/test/agent-loop.test.js +12 -12
  10. package/dist/test/boot.integration.test.js +1 -1
  11. package/dist/test/claude-mod.test.js +34 -3
  12. package/dist/test/dependencies.test.js +27 -0
  13. package/dist/test/helpers/extension.js +6 -6
  14. package/dist/test/notes.integration.test.js +2 -2
  15. package/dist/test/notes.test.js +16 -16
  16. package/dist/test/reset-lifecycle.test.js +4 -4
  17. package/docs/claude-code-mod.md +1 -1
  18. package/docs/skills.md +1 -1
  19. package/package.json +1 -1
  20. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  21. package/plugins/claude/dist/claude/helper.js +1 -1
  22. package/plugins/claude/hooks/register.ts +26 -4
  23. package/plugins/paseo/client/brain-empty-card.tsx +30 -0
  24. package/plugins/paseo/client/brain-empty-transformer.ts +43 -0
  25. package/plugins/paseo/client/notes-op-card.tsx +18 -48
  26. package/plugins/paseo/client/paper-card.tsx +36 -0
  27. package/plugins/paseo/client/sticky-card.tsx +6 -20
  28. package/plugins/paseo/index.client.tsx +5 -0
  29. package/plugins/paseo/shared/brain-empty.ts +12 -0
  30. package/plugins/paseo/test/brain-empty.test.ts +51 -0
  31. package/plugins/pi/dream/cli.ts +1 -1
  32. package/plugins/pi/extension.ts +3 -0
  33. package/plugins/pi/notes/adapter.ts +2 -2
  34. package/plugins/pi/reset/artifacts.ts +4 -1
  35. package/plugins/pi/runtime.ts +2 -2
  36. package/src/boot/text.ts +1 -1
  37. package/plugins/paseo/package-lock.json +0 -4018
@@ -18,7 +18,7 @@ type ClaudeLimits = {
18
18
  native: number; reset: number; warn: number; resetMargin: number; warningRunway: number
19
19
  }
20
20
  type ResetState = {
21
- identity?: Identity; history?: HistorySource; historyWindowHead?: string; generation: number; window: number; turnRunning: boolean; resetting: boolean
21
+ identity?: Identity; history?: HistorySource; historyWindowHead?: string; generation: number; window: number; disabled: boolean; turnRunning: boolean; resetting: boolean
22
22
  manualPending: boolean; headless: boolean; usageFailureLogged: boolean; preparedBoot?: string; retainedBoot?: string
23
23
  continuation?: string; continuationWindow?: number
24
24
  compactDisabled: boolean; limitsFailureLogged: boolean; limitsAttempts: number; limitsWindow: number
@@ -26,6 +26,7 @@ type ResetState = {
26
26
  }
27
27
  const HEADLESS = "No brain when headless"
28
28
  const COMPACT_DISABLED = "Brain can't be emptied with DISABLE_COMPACT"
29
+ const NOTESOUP_DISABLED = "Notesoup is off with NOTESOUP_DISABLED"
29
30
  const THRESHOLDS_UNAVAILABLE = "Brain size unknown · no automatic emptying"
30
31
  const SETTINGS_UNAVAILABLE = "Notesoup settings unreadable · using the default flush margins"
31
32
  /** Bounded retries: a transient helper failure must not disable thresholds for a whole window. */
@@ -103,6 +104,14 @@ async function compactDisabled($: Engine): Promise<boolean> {
103
104
  // The same presence convention as the helper's flag parsing: "off"/"no" mean not disabled.
104
105
  return text !== "" && text !== "0" && text !== "false" && text !== "no" && text !== "off"
105
106
  }
107
+ /** Presence-style kill switch for the whole mod; the same convention as DISABLE_COMPACT. */
108
+ async function notesoupDisabled($: Engine): Promise<boolean> {
109
+ let value: string | undefined
110
+ try { value = await $.env.get("NOTESOUP_DISABLED") } catch { return false }
111
+ if (value === undefined) return false
112
+ const text = value.trim().toLowerCase()
113
+ return text !== "" && text !== "0" && text !== "false" && text !== "no" && text !== "off"
114
+ }
106
115
  async function readSettings($: Engine, state: ResetState): Promise<unknown> {
107
116
  try { return await $.settings.read() } catch {
108
117
  // A silent fallback would hide a broken settings read behind default margins.
@@ -279,7 +288,7 @@ async function refreshIdentity($: Engine, state: ResetState): Promise<Identity |
279
288
  await syncHistoryWindow($, state)
280
289
  return state.identity
281
290
  }
282
- const home = await $.env.get("PI_NOTES_HOME") ?? `${await $.env.get("HOME") ?? await $.env.get("USERPROFILE") ?? ""}/.agents/notes`
291
+ const home = await $.env.get("NOTESOUP_HOME") ?? `${await $.env.get("HOME") ?? await $.env.get("USERPROFILE") ?? ""}/.agents/notes`
283
292
  if (generation !== state.generation) return undefined
284
293
  forgetSession(state)
285
294
  state.identity = { home, sessionId, cwd, agent: "claude", model }
@@ -308,7 +317,7 @@ async function syncHistoryWindow($: Engine, state: ResetState) {
308
317
 
309
318
  export function register(on: On) {
310
319
  const manualSignal: { wake?: () => void } = {}
311
- const state: ResetState = { generation: 0, window: 0, turnRunning: false, resetting: false, manualPending: false, headless: false, usageFailureLogged: false, compactDisabled: false, limitsFailureLogged: false, limitsAttempts: 0, limitsWindow: 0, settingsFailureLogged: false }
320
+ const state: ResetState = { generation: 0, window: 0, disabled: false, turnRunning: false, resetting: false, manualPending: false, headless: false, usageFailureLogged: false, compactDisabled: false, limitsFailureLogged: false, limitsAttempts: 0, limitsWindow: 0, settingsFailureLogged: false }
312
321
  const registered = new Set<string>()
313
322
  // Classic SessionStart precedes typed session.start and startup appends. Keep this binding
314
323
  // across forgetSession; re-key it only against the actual session id, never a guessed path.
@@ -330,6 +339,12 @@ export function register(on: On) {
330
339
  })
331
340
  on("session.start", async ($, e, next) => {
332
341
  forgetSession(state)
342
+ state.disabled = await notesoupDisabled($)
343
+ if (state.disabled) {
344
+ registered.clear()
345
+ log($, NOTESOUP_DISABLED)
346
+ return next(e)
347
+ }
333
348
  await refreshIdentity($, state)
334
349
  state.headless = !e.isInteractive
335
350
  if (state.headless) log($, HEADLESS)
@@ -355,6 +370,7 @@ export function register(on: On) {
355
370
  return next(e)
356
371
  })
357
372
  on("tool.call", async ($, e, next) => {
373
+ if (state.disabled) return next(e)
358
374
  if (!registered.has(e.tool)) return next(e)
359
375
  const identity = await refreshIdentity($, state)
360
376
  if (!identity) return errorResult("session changed during identity lookup")
@@ -371,6 +387,7 @@ export function register(on: On) {
371
387
  on("turn.start", async ($, e, next) => {
372
388
  // The documented turn.start is main-loop only. Guard tagged host events too:
373
389
  // only a main-agent turn.complete clears this latch.
390
+ if (state.disabled) return next(e)
374
391
  if ("agentId" in e && e.agentId !== undefined) return next(e)
375
392
  if (!await refreshIdentity($, state)) return next(e)
376
393
  state.turnRunning = true
@@ -379,6 +396,7 @@ export function register(on: On) {
379
396
  on("turn.complete", async ($, e, next) => {
380
397
  const result = await next(e)
381
398
  if (e.agentId !== undefined) return result
399
+ if (state.disabled) return result
382
400
  if (!await refreshIdentity($, state)) return result
383
401
  state.turnRunning = false
384
402
  await maybeReset($, state, true)
@@ -386,10 +404,11 @@ export function register(on: On) {
386
404
  })
387
405
  on("session.measure", async ($, e, next) => {
388
406
  const result = await next(e)
389
- if (await refreshIdentity($, state)) await maybeReset($, state, false)
407
+ if (!state.disabled && await refreshIdentity($, state)) await maybeReset($, state, false)
390
408
  return result
391
409
  })
392
410
  on("command.run", async ($, e, next) => {
411
+ if (state.disabled) return next(e)
393
412
  if (e.command !== "empty" && e.command !== "fresh-window") return next(e)
394
413
  if (!await refreshIdentity($, state)) return { text: "🥣 Different brain now · try /fresh-window again" }
395
414
  if (state.headless) return { text: `🥣 ${HEADLESS}` }
@@ -406,6 +425,8 @@ export function register(on: On) {
406
425
  return { text: "🥣 Brain being emptied" }
407
426
  })
408
427
  on("session.compact", async ($, e, next) => {
428
+ // Disabled means fully transparent: native compaction runs exactly as if the mod were absent.
429
+ if (state.disabled) return next(e)
409
430
  if (e.agentId !== undefined) return next(e)
410
431
  const identity = await refreshIdentity($, state)
411
432
  const generation = state.generation
@@ -445,6 +466,7 @@ export function register(on: On) {
445
466
  return { messages: built.messages }
446
467
  })
447
468
  on("prompt.context", async ($, e, next) => {
469
+ if (state.disabled) return next(e)
448
470
  const result = await next(e)
449
471
  const identity = await refreshIdentity($, state)
450
472
  const generation = state.generation
@@ -0,0 +1,30 @@
1
+ import type { PluginTimelineItemProps } from "@getpaseo/plugin/client";
2
+ import { Text, View } from "react-native";
3
+ import type { BrainEmpty } from "../shared/brain-empty.ts";
4
+ import { PAPER } from "./paper-card.tsx";
5
+
6
+ function label(data: BrainEmpty): string {
7
+ if (data.status === "running") return "EMPTYING BRAIN …";
8
+ if (data.error !== undefined) return "BRAIN REFUSED TO EMPTY";
9
+ if (data.outcome === "rollover_already_pending") return "BRAIN ALREADY BEING EMPTIED";
10
+ return "✂ BRAIN EMPTIED";
11
+ }
12
+
13
+ export function BrainEmptyDivider({ item }: PluginTimelineItemProps<BrainEmpty>) {
14
+ const data = item.data;
15
+ const refused = data.error !== undefined || data.status === "failed";
16
+ const color = refused ? PAPER.removed : PAPER.inkMuted;
17
+ const line = { flex: 1, height: 1, backgroundColor: color, opacity: 0.6 };
18
+ return (
19
+ <View style={{ paddingVertical: 6, gap: 3 }}>
20
+ <View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
21
+ <View style={line} />
22
+ <Text style={{ color, fontSize: 11, letterSpacing: 1 }}>{label(data)}</Text>
23
+ <View style={line} />
24
+ </View>
25
+ {data.error !== undefined && (
26
+ <Text selectable style={{ color: PAPER.removed, fontSize: 12, textAlign: "center" }}>{data.error}</Text>
27
+ )}
28
+ </View>
29
+ );
30
+ }
@@ -0,0 +1,43 @@
1
+ import type { PluginClientContext } from "@getpaseo/plugin/client";
2
+ import { BRAIN_EMPTY_KIND, BRAIN_EMPTY_TOOL, type BrainEmpty } from "../shared/brain-empty.ts";
3
+
4
+ type Transformer = Extract<Parameters<PluginClientContext["addTimelineTransformer"]>[0], { query: { itemType: "tool_call" } }>;
5
+ type Source = Parameters<Transformer["transform"]>[0];
6
+ type ToolCallItem = Extract<Source["item"], { type: "tool_call" }>;
7
+
8
+ function isRecord(value: unknown): value is Record<string, unknown> {
9
+ return typeof value === "object" && value !== null;
10
+ }
11
+
12
+ /** empty_brain answers in a plain JSON text block; there is no structured payload. */
13
+ function resultJson(output: unknown): Record<string, unknown> | undefined {
14
+ if (!isRecord(output) || !Array.isArray(output.content)) return undefined;
15
+ const part = output.content.filter(isRecord).find((block) => block.type === "text" && typeof block.text === "string");
16
+ if (!part) return undefined;
17
+ try {
18
+ const parsed: unknown = JSON.parse(part.text as string);
19
+ return isRecord(parsed) ? parsed : undefined;
20
+ } catch {
21
+ return undefined;
22
+ }
23
+ }
24
+
25
+ function brainEmptyData(item: ToolCallItem): BrainEmpty | undefined {
26
+ if (item.detail.type !== "unknown") return undefined;
27
+ if (item.status === "running") return { status: "running" };
28
+ const wire = resultJson(item.detail.output);
29
+ if (wire && typeof wire.error === "string") return { status: item.status === "failed" ? "failed" : "completed", error: wire.error };
30
+ if (item.status === "failed") return { status: "failed", error: wire === undefined ? "failed" : undefined };
31
+ if (wire && typeof wire.status === "string") return { status: "completed", outcome: wire.status };
32
+ return { status: "completed" };
33
+ }
34
+
35
+ export const brainEmptyTransformer = {
36
+ id: "brain-empty-source",
37
+ query: { itemType: "tool_call" },
38
+ transform: ({ item }: Pick<Source, "item">) => {
39
+ if (item.type !== "tool_call" || item.name !== BRAIN_EMPTY_TOOL) return undefined;
40
+ const data = brainEmptyData(item);
41
+ return data === undefined ? undefined : { items: [{ type: "plugin" as const, kind: BRAIN_EMPTY_KIND, version: 1, data }] };
42
+ },
43
+ } satisfies Transformer;
@@ -3,22 +3,12 @@ import { Icon } from "@getpaseo/plugin/client/react-native";
3
3
  import { useState } from "react";
4
4
  import { Pressable, ScrollView, Text, View } from "react-native";
5
5
  import type { NotesOp } from "../shared/notes-op.ts";
6
+ import { PAPER, PaperCard } from "./paper-card.tsx";
6
7
 
7
8
  const OP_LABEL: Record<NotesOp["op"], string> = { read: "READ NOTE", write: "WROTE NOTE", update: "UPDATED NOTE" };
8
9
  const OP_LABEL_RUNNING: Record<NotesOp["op"], string> = { read: "READING NOTE", write: "WRITING NOTE", update: "UPDATING NOTE" };
9
10
  const CHANGE_LABEL: Record<string, string> = { body: "edited", metadata: "metadata", moved: "renamed", none: "unchanged" };
10
11
 
11
- /** Paper palette: pale note paper, readable regardless of the host theme. */
12
- const PAPER = {
13
- background: "#f7f2df",
14
- border: "#d9cdaa",
15
- tape: "#d8c98f",
16
- ink: "#33301f",
17
- inkMuted: "#867c63",
18
- added: "#357a44",
19
- removed: "#b0493e",
20
- };
21
-
22
12
  function DiffBody({ diff }: { diff: string }) {
23
13
  return (
24
14
  <View style={{ gap: 2 }}>
@@ -46,37 +36,12 @@ export function NotesOpCard({ item, layout }: PluginTimelineItemProps<NotesOp>)
46
36
  const showEllipsis = data.truncated && data.diff === undefined;
47
37
  const hasBody = Boolean(data.text || data.preview || data.diff || footnotes.length);
48
38
  return (
49
- <View style={{ paddingTop: 6 }}>
50
- <View style={{
51
- alignSelf: "flex-start", width: 84, height: 14, marginLeft: 28, marginBottom: -9, zIndex: 1,
52
- backgroundColor: PAPER.tape, opacity: 0.9, borderRadius: 2,
53
- transform: [{ rotate: "-2deg" }],
54
- }} />
55
- <View style={{
56
- padding: layout.compact ? 10 : 12,
57
- gap: 5,
58
- minWidth: 0,
59
- borderRadius: 4,
60
- borderWidth: 1,
61
- borderColor: PAPER.border,
62
- backgroundColor: PAPER.background,
63
- }}>
39
+ <PaperCard compact={layout.compact}>
40
+ <View style={{ gap: 5, paddingRight: hasBody && !expanded ? 34 : 0 }}>
64
41
  <View style={{ gap: 3 }}>
65
- <View style={{ flexDirection: "row", alignItems: "center", justifyContent: "space-between", gap: 8 }}>
66
- <Text style={{ color: PAPER.inkMuted, fontSize: 11, letterSpacing: 0.5 }}>
67
- {title}{data.status === "running" ? " …" : ""}
68
- </Text>
69
- {hasBody && !expanded && <Pressable
70
- accessibilityRole="button"
71
- accessibilityLabel={`${expanded ? "收起" : "展开"} ${data.address}`}
72
- aria-expanded={expanded}
73
- onPress={() => setExpanded(value => !value)}
74
- hitSlop={6}
75
- style={({ pressed }) => ({ padding: 5, opacity: pressed ? 0.6 : 1 })}
76
- >
77
- <Icon name={expanded ? "ChevronUp" : "ChevronDown"} size={18} color={PAPER.inkMuted} />
78
- </Pressable>}
79
- </View>
42
+ <Text style={{ color: PAPER.inkMuted, fontSize: 11, letterSpacing: 0.5 }}>
43
+ {title}{data.status === "running" ? " …" : ""}
44
+ </Text>
80
45
  <Text style={{ color: PAPER.ink, fontSize: 13, flexShrink: 1 }}>
81
46
  {data.address}
82
47
  {state !== undefined && <Text style={{ color: PAPER.inkMuted, fontSize: 12, fontWeight: "400" }}>{" "}{state}</Text>}
@@ -93,17 +58,22 @@ export function NotesOpCard({ item, layout }: PluginTimelineItemProps<NotesOp>)
93
58
  {data.diff !== undefined && <DiffBody diff={data.diff} />}
94
59
  {footnotes.length > 0 && <Text style={{ color: PAPER.inkMuted, fontSize: 11 }}>{footnotes.join(" · ")}</Text>}
95
60
  </ScrollView>}
96
- {hasBody && expanded && <Pressable
61
+ {hasBody && <Pressable
97
62
  accessibilityRole="button"
98
- accessibilityLabel={`收起 ${data.address}`}
99
- aria-expanded={true}
100
- onPress={() => setExpanded(false)}
63
+ accessibilityLabel={`${expanded ? "收起" : "展开"} ${data.address}`}
64
+ aria-expanded={expanded}
65
+ onPress={() => setExpanded(value => !value)}
101
66
  hitSlop={6}
102
- style={({ pressed }) => ({ alignSelf: "flex-end", paddingHorizontal: 5, paddingVertical: 1, opacity: pressed ? 0.6 : 1 })}
67
+ style={({ pressed }) => ({
68
+ ...(expanded
69
+ ? { alignSelf: "flex-end" as const, marginTop: -3, marginBottom: -4 }
70
+ : { position: "absolute" as const, right: 0, bottom: 0 }),
71
+ paddingHorizontal: 5, opacity: pressed ? 0.6 : 1,
72
+ })}
103
73
  >
104
- <Icon name="ChevronUp" size={18} color={PAPER.inkMuted} />
74
+ <Icon name={expanded ? "ChevronUp" : "ChevronDown"} size={18} color={PAPER.inkMuted} />
105
75
  </Pressable>}
106
76
  </View>
107
- </View>
77
+ </PaperCard>
108
78
  );
109
79
  }
@@ -0,0 +1,36 @@
1
+ import type { ReactNode } from "react";
2
+ import { View } from "react-native";
3
+
4
+ /** Shared paper palette, independent of the host theme. */
5
+ export const PAPER = {
6
+ background: "#f7f2df",
7
+ border: "#d9cdaa",
8
+ tape: "#d8c98f",
9
+ ink: "#33301f",
10
+ inkMuted: "#867c63",
11
+ added: "#357a44",
12
+ removed: "#b0493e",
13
+ };
14
+
15
+ export function PaperCard({ compact, children }: { compact: boolean; children: ReactNode }) {
16
+ return (
17
+ <View style={{ paddingTop: 6 }}>
18
+ <View style={{
19
+ alignSelf: "flex-start", width: 84, height: 14, marginLeft: 28, marginBottom: -9, zIndex: 1,
20
+ backgroundColor: PAPER.tape, opacity: 0.9, borderRadius: 2,
21
+ transform: [{ rotate: "-2deg" }],
22
+ }} />
23
+ <View style={{
24
+ padding: compact ? 10 : 12,
25
+ gap: 5,
26
+ minWidth: 0,
27
+ borderRadius: 4,
28
+ borderWidth: 1,
29
+ borderColor: PAPER.border,
30
+ backgroundColor: PAPER.background,
31
+ }}>
32
+ {children}
33
+ </View>
34
+ </View>
35
+ );
36
+ }
@@ -1,28 +1,14 @@
1
1
  import type { PluginTimelineItemProps } from "@getpaseo/plugin/client";
2
- import { Text, View } from "react-native";
2
+ import { Text } from "react-native";
3
3
  import type { LastWord } from "../shared/last-word.ts";
4
+ import { PAPER, PaperCard } from "./paper-card.tsx";
4
5
 
5
6
  export function StickyCard({ item, layout }: PluginTimelineItemProps<LastWord>) {
6
7
  const text = item.data.text.replace(/^\*You peel a sticky note off your forehead\.\*\n/, "");
7
8
  return (
8
- <View style={{ paddingTop: 6 }}>
9
- <View style={{
10
- alignSelf: "flex-start", width: 84, height: 14, marginLeft: 28, marginBottom: -9, zIndex: 1,
11
- backgroundColor: "#d8c98f", opacity: 0.9, borderRadius: 2,
12
- transform: [{ rotate: "-2deg" }],
13
- }} />
14
- <View style={{
15
- padding: layout.compact ? 10 : 12,
16
- gap: 5,
17
- minWidth: 0,
18
- borderRadius: 4,
19
- borderWidth: 1,
20
- borderColor: "#d9cdaa",
21
- backgroundColor: "#f7f2df",
22
- }}>
23
- <Text style={{ color: "#867c63", fontSize: 11, letterSpacing: 0.5 }}>LAST WORD</Text>
24
- <Text selectable style={{ color: "#33301f", fontSize: 13, lineHeight: 19, flexShrink: 1 }}>{text}</Text>
25
- </View>
26
- </View>
9
+ <PaperCard compact={layout.compact}>
10
+ <Text style={{ color: PAPER.inkMuted, fontSize: 11, letterSpacing: 0.5 }}>LAST WORD</Text>
11
+ <Text selectable style={{ color: PAPER.ink, fontSize: 13, lineHeight: 19, flexShrink: 1 }}>{text}</Text>
12
+ </PaperCard>
27
13
  );
28
14
  }
@@ -3,15 +3,20 @@ import { sourceRowTransformer } from "./client/source-row.ts";
3
3
  import { notesOpTransformer } from "./client/notes-op-transformer.ts";
4
4
  import { StickyCard } from "./client/sticky-card.tsx";
5
5
  import { NotesOpCard } from "./client/notes-op-card.tsx";
6
+ import { BrainEmptyDivider } from "./client/brain-empty-card.tsx";
7
+ import { brainEmptyTransformer } from "./client/brain-empty-transformer.ts";
6
8
  import { CARD_KIND, lastWordSchema } from "./shared/last-word.ts";
7
9
  import { NOTES_OP_KIND, notesOpSchema } from "./shared/notes-op.ts";
10
+ import { BRAIN_EMPTY_KIND, brainEmptySchema } from "./shared/brain-empty.ts";
8
11
 
9
12
  export default function contribute(client: PluginClientContext) {
10
13
  const removals = [
11
14
  client.addTimelineRenderer({ kind: CARD_KIND, version: 1, schema: lastWordSchema, Component: StickyCard }),
12
15
  client.addTimelineRenderer({ kind: NOTES_OP_KIND, version: 1, schema: notesOpSchema, Component: NotesOpCard }),
16
+ client.addTimelineRenderer({ kind: BRAIN_EMPTY_KIND, version: 1, schema: brainEmptySchema, Component: BrainEmptyDivider }),
13
17
  client.addTimelineTransformer(sourceRowTransformer),
14
18
  client.addTimelineTransformer(notesOpTransformer),
19
+ client.addTimelineTransformer(brainEmptyTransformer),
15
20
  ];
16
21
  return () => { for (const remove of removals) remove(); };
17
22
  }
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+
3
+ export const BRAIN_EMPTY_KIND = "brain-empty";
4
+ export const BRAIN_EMPTY_TOOL = "empty_brain";
5
+
6
+ export const brainEmptySchema = z.object({
7
+ status: z.enum(["running", "completed", "failed"]),
8
+ // completed: rollover_requested | rollover_already_pending
9
+ outcome: z.string().optional(),
10
+ error: z.string().optional(),
11
+ });
12
+ export type BrainEmpty = z.infer<typeof brainEmptySchema>;
@@ -0,0 +1,51 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { brainEmptyTransformer } from "../client/brain-empty-transformer.ts";
4
+ import { brainEmptySchema } from "../shared/brain-empty.ts";
5
+
6
+ function toolCall(overrides: Record<string, unknown>) {
7
+ return {
8
+ type: "tool_call" as const,
9
+ callId: "call-1",
10
+ name: "empty_brain",
11
+ status: "completed" as const,
12
+ error: null,
13
+ detail: { type: "unknown" as const, input: {}, output: {} },
14
+ ...overrides,
15
+ };
16
+ }
17
+
18
+ const transform = (overrides: Record<string, unknown>) => brainEmptyTransformer.transform({ item: toolCall(overrides) as never });
19
+ const jsonOut = (value: unknown) => ({ type: "unknown", input: {}, output: { content: [{ type: "text", text: JSON.stringify(value) }] } });
20
+
21
+ test("a successful call is a completed divider with the rollover outcome", () => {
22
+ const result = transform({ detail: jsonOut({ status: "rollover_requested" }) });
23
+ assert.deepEqual(brainEmptySchema.parse(result!.items[0]!.data), { status: "completed", outcome: "rollover_requested" });
24
+ });
25
+
26
+ test("an in-flight call shows as running from the call alone", () => {
27
+ const result = transform({ status: "running", detail: { type: "unknown", input: { last_word: "bye" }, output: null } });
28
+ assert.deepEqual(brainEmptySchema.parse(result!.items[0]!.data), { status: "running" });
29
+ });
30
+
31
+ test("a refused call surfaces the refusal text", () => {
32
+ const result = transform({ detail: jsonOut({ error: "last_word is 263 characters; the sticky note holds 250." }) });
33
+ const data = brainEmptySchema.parse(result!.items[0]!.data);
34
+ assert.equal(data.error, "last_word is 263 characters; the sticky note holds 250.");
35
+ assert.equal(data.outcome, undefined);
36
+ });
37
+
38
+ test("already-pending is an outcome, not an error", () => {
39
+ const result = transform({ detail: jsonOut({ status: "rollover_already_pending" }) });
40
+ assert.deepEqual(brainEmptySchema.parse(result!.items[0]!.data), { status: "completed", outcome: "rollover_already_pending" });
41
+ });
42
+
43
+ test("a failed transport call without a payload still fails", () => {
44
+ const result = transform({ status: "failed", error: { message: "boom" }, detail: { type: "unknown", input: {}, output: null } });
45
+ assert.deepEqual(brainEmptySchema.parse(result!.items[0]!.data), { status: "failed", error: "failed" });
46
+ });
47
+
48
+ test("other tools and non-tool items stay untouched", () => {
49
+ assert.equal(brainEmptyTransformer.transform({ item: toolCall({ name: "notes_read" }) as never }), undefined);
50
+ assert.equal(brainEmptyTransformer.transform({ item: { type: "user_message", text: "hi" } as never }), undefined);
51
+ });
@@ -64,7 +64,7 @@ export async function main(argv = process.argv.slice(2), deps: DreamDependencies
64
64
  : a["min-sessions"] !== undefined && minSessions === undefined ? "--min-sessions needs a positive whole number"
65
65
  : undefined;
66
66
  if (badArg) { console.error(`dream: ${badArg}`); return 1; }
67
- const home = resolve(homeArg ?? notesRoot()); process.env.PI_NOTES_HOME = home; mkdirSync(home, { recursive: true });
67
+ const home = resolve(homeArg ?? notesRoot()); process.env.NOTESOUP_HOME = home; mkdirSync(home, { recursive: true });
68
68
  const lockPath = join(home, ".dream.lock"); const stampPath = lastRunPath(lockPath);
69
69
  const time = timeGate(stampPath, minHours ?? 24); console.log(time.reason); if (!a.force && !time.ok) return 0;
70
70
  const since = existsSync(stampPath) ? statSync(stampPath).mtimeMs : 0;
@@ -1,9 +1,12 @@
1
1
  import { VERSION, type ExtensionAPI, type ExtensionFactory, type SettingsManager } from "@earendil-works/pi-coding-agent";
2
+ import { presenceFlag } from "../../src/budget/parse.js";
2
3
  import { registerHistoryTools } from "./history-tools.js";
3
4
  import { registerNotesTools } from "./notes/tools.js";
4
5
  import { registerContext } from "./runtime.js";
5
6
 
6
7
  function registerNotesoup(pi: ExtensionAPI, settingsManager?: SettingsManager): void {
8
+ // Presence-style kill switch for the whole extension, same convention as the DISABLE_* flags.
9
+ if (presenceFlag(process.env.NOTESOUP_DISABLED)) return;
7
10
  const [major, minor] = VERSION.split(".").map(Number);
8
11
  if (!(major > 0 || (major === 0 && minor >= 87))) {
9
12
  throw new Error(`notesoup requires Pi >= 0.87.0; running ${VERSION}. Upgrade Pi and restart the process; /reload only reloads extensions.`);
@@ -5,13 +5,13 @@ import { projectKey, slugify, type NotesIdentity } from "../../../src/notes/inde
5
5
 
6
6
  /** Pi's default notes root; environment access stays on the host side of the library boundary. */
7
7
  export function notesRoot(): string {
8
- const override = process.env.PI_NOTES_HOME;
8
+ const override = process.env.NOTESOUP_HOME;
9
9
  return override && override.length > 0 ? resolve(override) : join(homedir(), ".agents", "notes");
10
10
  }
11
11
 
12
12
  /** Translate the current Pi runtime into a fresh, explicit identity snapshot. */
13
13
  export function agentSlug(): string {
14
- return slugify(process.env.PI_NOTES_AGENT ?? "anonymous");
14
+ return slugify(process.env.NOTESOUP_AGENT ?? "anonymous");
15
15
  }
16
16
 
17
17
  /** Pi's active model identity is resolved live so a mid-session switch retargets @model. */
@@ -18,8 +18,11 @@ export function isCarriedInputEntry(entry: SessionEntry): boolean {
18
18
  return entry.type === "custom_message" && entry.customType === CARRIED_INPUT_TYPE && entry.display === true;
19
19
  }
20
20
 
21
+ /** Advertised size: the description quotes this softer limit so sloppy character counts still fit. */
22
+ export const LAST_WORD_ADVERTISED_CHARS = 250;
23
+
21
24
  /** A sticky note, not a letter: over this, empty_brain refuses instead of truncating. */
22
- export const MAX_LAST_WORD_CHARS = 250;
25
+ export const MAX_LAST_WORD_CHARS = 300;
23
26
 
24
27
  /** How the next window finds the note. */
25
28
  export const LAST_WORD_PREFIX = "*You peel a sticky note off your forehead.*\n";
@@ -6,7 +6,7 @@ import { registerBudget } from "./budget.js";
6
6
  import { output } from "./tool-result.js";
7
7
  import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, isWindowMarker, markerResetOrigin, projectRootWindow, projectWindow, rootWindowId, type WindowMarker } from "./window.js";
8
8
  import { registerResetLifecycle } from "./reset/lifecycle.js";
9
- import { buildResetDrafts, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
9
+ import { buildResetDrafts, LAST_WORD_ADVERTISED_CHARS, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
10
10
  import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
11
11
  import { commandWarningContent } from "./text.js";
12
12
  import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "./boot.js";
@@ -204,7 +204,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
204
204
  name: "empty_brain",
205
205
  label: "Empty Brain",
206
206
  description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to stick a tiny note on your forehead for after the wipe.",
207
- parameters: Type.Object({ last_word: Type.Optional(Type.String({ description: `A tiny sticky note, at most ${MAX_LAST_WORD_CHARS} characters. After the wipe it is slapped on your forehead; longer notes are refused.` })) }, { additionalProperties: false }),
207
+ parameters: Type.Object({ last_word: Type.Optional(Type.String({ description: `A tiny sticky note, at most ${LAST_WORD_ADVERTISED_CHARS} characters. After the wipe it is slapped on your forehead; longer notes are refused.` })) }, { additionalProperties: false }),
208
208
  async execute(_id, params, _signal, _update, ctx) {
209
209
  if (!enabled) return output({ error: "notesoup is off, so memory can't be cleared; the user can turn it on with `/notesoup on`." });
210
210
  const lastWord = sanitizeLastWord(params.last_word);
package/src/boot/text.ts CHANGED
@@ -40,7 +40,7 @@ An address decides who the note belongs to — and how long it is meant to last.
40
40
 
41
41
  - \`<path>\`, no @ — session notes, the ones from above: this session's state and loose ends. They go away with the session.
42
42
  - \`@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.** Commit hashes, test counts, dates, the story of how you got here: git and history already have them, and last week's news filed as current law is worse than no note. Don't copy what other docs already say.
43
- - \`@human/<path>\` — the long-term manual for your troublesome human: how to deal with them, which lines not to cross, and what will make them accept the result. If it only applies to one project or situation, say so — or don't write it here at all. Today's mood is weather, not law. If you're unsure whether it belongs here, ask the human.
43
+ - \`@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.
44
44
  - \`@self/<path>\` — yours. It follows you, not them. Reminders, grudges, who owes you a shoe, whatever. Got a name? Private. No name? Then it gets passed around every nameless nobody out there. Strangers. Reading your grudges. Sleep tight~
45
45
  - \`@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.
46
46
  - \`@projects/<name>/<path>\` — read-only named project notes; discover names and root paths with \`notes_list\` glob \`@projects/*/**\`.