notesoup 0.51.8 → 0.52.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -10
- package/dist/plugins/claude/src/history.js +3 -7
- package/dist/plugins/pi/notes/tools.d.ts +1 -1
- package/dist/plugins/pi/notes/tools.js +27 -7
- package/dist/plugins/pi/render.d.ts +40 -0
- package/dist/plugins/pi/render.js +168 -0
- package/dist/plugins/pi/runtime.js +3 -0
- package/dist/plugins/pi/tool-result.d.ts +5 -2
- package/dist/plugins/pi/tool-result.js +4 -1
- package/dist/src/dream/git.d.ts +2 -3
- package/dist/src/dream/git.js +3 -8
- package/dist/src/dream/lock.d.ts +10 -27
- package/dist/src/dream/lock.js +16 -79
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/identity.d.ts +2 -0
- package/dist/src/notes/identity.js +3 -1
- package/dist/src/notes/store.d.ts +2 -0
- package/dist/src/notes/store.js +40 -4
- package/dist/src/tools/dream.d.ts +113 -0
- package/dist/src/tools/dream.js +112 -0
- package/dist/src/tools/notes.d.ts +15 -1
- package/dist/src/tools/notes.js +4 -4
- package/dist/test/claude-history.test.js +18 -2
- package/dist/test/claude-mod.test.js +115 -30
- package/dist/test/dependencies.test.js +3 -6
- package/dist/test/dream-skill.test.js +2 -3
- package/dist/test/dream-tools.test.js +67 -0
- package/dist/test/pi-render.test.js +89 -0
- package/docs/claude-code-mod.md +1 -1
- package/docs/notes-library.md +1 -1
- package/docs/skills.md +12 -15
- package/package.json +151 -149
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +30 -22
- package/plugins/claude/hooks/register.ts +52 -33
- package/plugins/claude/src/history.ts +3 -6
- package/plugins/pi/notes/tools.ts +26 -8
- package/plugins/pi/render.ts +165 -0
- package/plugins/pi/runtime.ts +3 -0
- package/plugins/pi/tool-result.ts +9 -1
- package/src/dream/git.ts +3 -8
- package/src/dream/lock.ts +18 -66
- package/src/notes/errors.ts +1 -1
- package/src/notes/identity.ts +4 -1
- package/src/notes/store.ts +37 -4
- package/src/tools/dream.ts +112 -0
- package/src/tools/notes.ts +4 -4
- package/dist/plugins/pi/dream/cli.d.ts +0 -10
- package/dist/plugins/pi/dream/cli.js +0 -173
- package/dist/plugins/pi/dream/runner.d.ts +0 -27
- package/dist/plugins/pi/dream/runner.js +0 -91
- package/dist/plugins/pi/dream/settings.d.ts +0 -7
- package/dist/plugins/pi/dream/settings.js +0 -17
- package/dist/src/dream/doctor.d.ts +0 -2
- package/dist/src/dream/doctor.js +0 -161
- package/dist/src/dream/gates.d.ts +0 -10
- package/dist/src/dream/gates.js +0 -26
- package/dist/src/dream/jail.d.ts +0 -11
- package/dist/src/dream/jail.js +0 -71
- package/dist/src/dream/report.d.ts +0 -7
- package/dist/src/dream/report.js +0 -34
- package/dist/src/dream/result.d.ts +0 -9
- package/dist/src/dream/settings.d.ts +0 -9
- package/dist/src/dream/settings.js +0 -16
- package/dist/test/doctor.test.js +0 -37
- package/dist/test/dream.test.d.ts +0 -1
- package/dist/test/dream.test.js +0 -150
- package/plugins/pi/dream/cli.ts +0 -118
- package/plugins/pi/dream/runner.ts +0 -92
- package/plugins/pi/dream/settings.ts +0 -17
- package/src/dream/doctor.ts +0 -118
- package/src/dream/gates.ts +0 -26
- package/src/dream/jail.ts +0 -62
- package/src/dream/report.ts +0 -32
- package/src/dream/result.ts +0 -2
- package/src/dream/settings.ts +0 -19
- /package/dist/{src/dream/result.js → test/dream-tools.test.d.ts} +0 -0
- /package/dist/test/{doctor.test.d.ts → pi-render.test.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,151 +1,153 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
2
|
+
"name": "notesoup",
|
|
3
|
+
"version": "0.52.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/src/index.js",
|
|
6
|
+
"types": "./dist/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/src/index.d.ts",
|
|
10
|
+
"import": "./dist/src/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./notes": {
|
|
13
|
+
"types": "./dist/src/notes/index.d.ts",
|
|
14
|
+
"import": "./dist/src/notes/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json",
|
|
17
|
+
"./dsh": {
|
|
18
|
+
"types": "./dist/plugins/dsh/index.d.ts",
|
|
19
|
+
"import": "./dist/plugins/dsh/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./dsh/engine": {
|
|
22
|
+
"types": "./dist/plugins/dsh/engine.d.ts",
|
|
23
|
+
"import": "./dist/plugins/dsh/engine.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"description": "Host-neutral notes, history and context-window core, with plugins for Pi, Claude Code and the DeepSeek Harness.",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"pi-package",
|
|
30
|
+
"pi-extension",
|
|
31
|
+
"agent-memory",
|
|
32
|
+
"notes"
|
|
33
|
+
],
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/astrosheep-zero/notesoup.git"
|
|
37
|
+
},
|
|
38
|
+
"pi": {
|
|
39
|
+
"extensions": [
|
|
40
|
+
"./plugins/pi/index.ts"
|
|
41
|
+
],
|
|
42
|
+
"skills": [
|
|
43
|
+
"./skills"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"src",
|
|
48
|
+
"plugins",
|
|
49
|
+
"dist",
|
|
50
|
+
"docs",
|
|
51
|
+
"LICENSE",
|
|
52
|
+
"README.md",
|
|
53
|
+
"playbook.md",
|
|
54
|
+
"skills",
|
|
55
|
+
"!plugins/claude/types",
|
|
56
|
+
"!plugins/claude/tsconfig.json",
|
|
57
|
+
"cordis.patch.yml"
|
|
58
|
+
],
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && node scripts/build-extension.mjs",
|
|
61
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p plugins/claude/tsconfig.json",
|
|
62
|
+
"test": "npm run build && node --test --test-concurrency=4 $(ls dist/test/*.test.js | grep -v dist/test/claude-validation.test.js) && node --test dist/test/claude-validation.test.js",
|
|
63
|
+
"prepublishOnly": "npm run typecheck",
|
|
64
|
+
"prepack": "npm run build"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"@earendil-works/pi-agent-core": "*",
|
|
68
|
+
"@earendil-works/pi-ai": "*",
|
|
69
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
70
|
+
"@earendil-works/pi-tui": "*",
|
|
71
|
+
"typebox": "*",
|
|
72
|
+
"@deepseek-ai/cordis": "*",
|
|
73
|
+
"@deepseek-ai/cordis-plugin-loader": "*",
|
|
74
|
+
"@deepseek-ai/dsh-agent": "*",
|
|
75
|
+
"@deepseek-ai/dsh-compaction": "*",
|
|
76
|
+
"@deepseek-ai/dsh-commands": "*",
|
|
77
|
+
"@deepseek-ai/dsh-llm": "*",
|
|
78
|
+
"@deepseek-ai/dsh-session": "*",
|
|
79
|
+
"@deepseek-ai/dsh-session-query": "*",
|
|
80
|
+
"@deepseek-ai/dsh-system-prompt": "*",
|
|
81
|
+
"@deepseek-ai/dsh-token-meter": "*",
|
|
82
|
+
"@deepseek-ai/dsh-tools": "*"
|
|
83
|
+
},
|
|
84
|
+
"peerDependenciesMeta": {
|
|
85
|
+
"@earendil-works/pi-agent-core": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
88
|
+
"@earendil-works/pi-ai": {
|
|
89
|
+
"optional": true
|
|
90
|
+
},
|
|
91
|
+
"@earendil-works/pi-coding-agent": {
|
|
92
|
+
"optional": true
|
|
93
|
+
},
|
|
94
|
+
"@earendil-works/pi-tui": {
|
|
95
|
+
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"typebox": {
|
|
98
|
+
"optional": true
|
|
99
|
+
},
|
|
100
|
+
"@deepseek-ai/cordis": {
|
|
101
|
+
"optional": true
|
|
102
|
+
},
|
|
103
|
+
"@deepseek-ai/cordis-plugin-loader": {
|
|
104
|
+
"optional": true
|
|
105
|
+
},
|
|
106
|
+
"@deepseek-ai/dsh-agent": {
|
|
107
|
+
"optional": true
|
|
108
|
+
},
|
|
109
|
+
"@deepseek-ai/dsh-compaction": {
|
|
110
|
+
"optional": true
|
|
111
|
+
},
|
|
112
|
+
"@deepseek-ai/dsh-commands": {
|
|
113
|
+
"optional": true
|
|
114
|
+
},
|
|
115
|
+
"@deepseek-ai/dsh-llm": {
|
|
116
|
+
"optional": true
|
|
117
|
+
},
|
|
118
|
+
"@deepseek-ai/dsh-session": {
|
|
119
|
+
"optional": true
|
|
120
|
+
},
|
|
121
|
+
"@deepseek-ai/dsh-session-query": {
|
|
122
|
+
"optional": true
|
|
123
|
+
},
|
|
124
|
+
"@deepseek-ai/dsh-system-prompt": {
|
|
125
|
+
"optional": true
|
|
126
|
+
},
|
|
127
|
+
"@deepseek-ai/dsh-token-meter": {
|
|
128
|
+
"optional": true
|
|
129
|
+
},
|
|
130
|
+
"@deepseek-ai/dsh-tools": {
|
|
131
|
+
"optional": true
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
"devDependencies": {
|
|
135
|
+
"@deepseek-ai/dsh": "0.2.1-alpha.2",
|
|
136
|
+
"@earendil-works/pi-agent-core": "^1.0.0",
|
|
137
|
+
"@earendil-works/pi-ai": "^1.0.0",
|
|
138
|
+
"@earendil-works/pi-coding-agent": "^1.0.0",
|
|
139
|
+
"@earendil-works/pi-tui": "1.0.0",
|
|
140
|
+
"@types/node": "^22.19.19",
|
|
141
|
+
"esbuild": "^0.28.2",
|
|
142
|
+
"typebox": "1.3.27",
|
|
143
|
+
"typescript": "^5.9.3"
|
|
144
|
+
},
|
|
145
|
+
"publishConfig": {
|
|
146
|
+
"access": "public"
|
|
147
|
+
},
|
|
148
|
+
"dsh": {
|
|
149
|
+
"bundle": {
|
|
150
|
+
"patch": "./cordis.patch.yml"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
151
153
|
}
|
|
@@ -7975,7 +7975,7 @@ function isFilesystemError(error) {
|
|
|
7975
7975
|
|
|
7976
7976
|
// src/notes/store.ts
|
|
7977
7977
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
7978
|
-
import { mkdir, readdir as readdir2, readFile, realpath, rename, rm, writeFile } from "node:fs/promises";
|
|
7978
|
+
import { mkdir, readdir as readdir2, readFile, realpath, rename, rm, unlink, writeFile } from "node:fs/promises";
|
|
7979
7979
|
import { dirname as dirname2, join as join3, resolve as resolve3 } from "node:path";
|
|
7980
7980
|
|
|
7981
7981
|
// src/text-match.ts
|
|
@@ -8146,8 +8146,9 @@ function snapshotNotesIdentity(value) {
|
|
|
8146
8146
|
if (!SLUG_PATTERN.test(projectKey2)) throw new TypeError("notes context projectKey must be a canonical lowercase slug");
|
|
8147
8147
|
if (!SLUG_PATTERN.test(agent)) throw new TypeError("notes context agent must be a canonical lowercase slug");
|
|
8148
8148
|
if (!SLUG_PATTERN.test(model)) throw new TypeError("notes context model must be a canonical lowercase slug");
|
|
8149
|
+
if (value.dreaming !== void 0 && !SLUG_PATTERN.test(value.dreaming)) throw new TypeError("notes context dreaming must be a canonical lowercase slug");
|
|
8149
8150
|
const home = resolve(homeValue);
|
|
8150
|
-
return Object.freeze({ home, sessionId, projectKey: projectKey2, agent, model });
|
|
8151
|
+
return Object.freeze({ home, sessionId, projectKey: projectKey2, agent, model, ...value.dreaming === void 0 ? {} : { dreaming: value.dreaming } });
|
|
8151
8152
|
}
|
|
8152
8153
|
|
|
8153
8154
|
// src/notes/constants.ts
|
|
@@ -8510,6 +8511,7 @@ function frontmatterOf(meta) {
|
|
|
8510
8511
|
}
|
|
8511
8512
|
function assertWritableHome(scope, who, identity2) {
|
|
8512
8513
|
if (who === void 0) return;
|
|
8514
|
+
if (identity2.dreaming !== void 0 && (scope === "session" || scope === "project" && who === identity2.dreaming)) return;
|
|
8513
8515
|
if (scope === "session") throw new NoteError("invalid_scope", `@sessions/${who}/ is read-only; use a bare path to write to this session.`);
|
|
8514
8516
|
if (scope === "project") throw new NoteError("invalid_scope", `@projects/${who}/ is read-only; use @project/ to write to your own project.`);
|
|
8515
8517
|
const current = scope === "agent" ? identity2.agent : identity2.model;
|
|
@@ -8517,6 +8519,11 @@ function assertWritableHome(scope, who, identity2) {
|
|
|
8517
8519
|
const home = scope === "agent" ? `@agents/${who}/` : `@models/${who}/`;
|
|
8518
8520
|
throw new NoteError("invalid_scope", `${home} is someone else's home; you can write to this session, @project/, @human/, @self/, or @model/.`);
|
|
8519
8521
|
}
|
|
8522
|
+
function assertDreamSessionNote(scope, who, identity2, raw, address) {
|
|
8523
|
+
if (scope !== "session" || who === void 0 || identity2.dreaming === void 0) return;
|
|
8524
|
+
if (raw !== void 0 && parseNote(raw).meta.project === identity2.dreaming) return;
|
|
8525
|
+
throw new NoteError("invalid_scope", raw === void 0 ? `${address}: a dream edits other sessions' existing notes, it doesn't create new ones there.` : `${address} belongs to another project, not the one being dreamed over (${identity2.dreaming}).`);
|
|
8526
|
+
}
|
|
8520
8527
|
function createNotesStore(input) {
|
|
8521
8528
|
const identity2 = snapshotNotesIdentity(input);
|
|
8522
8529
|
async function write(address, content, options = {}) {
|
|
@@ -8531,6 +8538,7 @@ function createNotesStore(input) {
|
|
|
8531
8538
|
const now = writeStamp();
|
|
8532
8539
|
const cleanBody = stripLeadingFrontmatter(content);
|
|
8533
8540
|
const existingRaw = await readFileIfExists(path);
|
|
8541
|
+
assertDreamSessionNote(scope, destination.who, identity2, existingRaw, address);
|
|
8534
8542
|
const existing = existingRaw === void 0 ? void 0 : parseNote(existingRaw, now).meta;
|
|
8535
8543
|
const outcome = existing === void 0 ? "created" : existing.crumpledAt === void 0 ? "overwrote" : "uncrumpled";
|
|
8536
8544
|
const meta = existing ?? {
|
|
@@ -8561,7 +8569,7 @@ function createNotesStore(input) {
|
|
|
8561
8569
|
if (raw === void 0) return void 0;
|
|
8562
8570
|
const now = Date.now();
|
|
8563
8571
|
const parsed = parseNote(raw, now);
|
|
8564
|
-
if ((scope === "project" || scope === "session") && destination.who !== void 0) return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope };
|
|
8572
|
+
if (identity2.dreaming !== void 0 || (scope === "project" || scope === "session") && destination.who !== void 0) return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope };
|
|
8565
8573
|
const meta = { ...parsed.meta, scope, lastAccessed: now, accessCount: (typeof parsed.meta.accessCount === "number" ? parsed.meta.accessCount : 0) + 1 };
|
|
8566
8574
|
await atomicWrite(path, serializeNote(meta, parsed.body));
|
|
8567
8575
|
return { meta, body: parsed.body, resolvedScope: scope };
|
|
@@ -8586,6 +8594,8 @@ function createNotesStore(input) {
|
|
|
8586
8594
|
const raw = await readFileIfExists(fromPath);
|
|
8587
8595
|
if (raw === void 0) throw new NoteError("not_found", `No note at ${noteIdentity(identity2, address).address}.`);
|
|
8588
8596
|
const targetRaw = differentPaths ? await readFileIfExists(path) : void 0;
|
|
8597
|
+
assertDreamSessionNote(from.scope, from.who, identity2, raw, address);
|
|
8598
|
+
if (differentPaths) assertDreamSessionNote(scope, destination.who, identity2, targetRaw, stableOptions.renameTo);
|
|
8589
8599
|
const sourceReal = targetRaw === void 0 ? void 0 : await realpath(fromPath);
|
|
8590
8600
|
const sameFile = sourceReal !== void 0 && sourceReal === await realpath(path);
|
|
8591
8601
|
const moved = differentPaths && !sameFile;
|
|
@@ -8642,6 +8652,21 @@ function createNotesStore(input) {
|
|
|
8642
8652
|
const { meta, replacedCrumpledTarget } = await update(fromAddress, void 0, { renameTo: toAddress });
|
|
8643
8653
|
return { meta, replacedCrumpledTarget };
|
|
8644
8654
|
}
|
|
8655
|
+
async function forget(address) {
|
|
8656
|
+
if (identity2.dreaming === void 0) throw new NoteError("invalid_scope", "Only a dream can delete notes; begin one first.");
|
|
8657
|
+
const target = assertAddress(address);
|
|
8658
|
+
assertWritableHome(target.scope, target.who, identity2);
|
|
8659
|
+
const path = physicalPath(target.scope, target.path, identity2, target.who);
|
|
8660
|
+
return withPathQueue(path, async () => {
|
|
8661
|
+
const raw = await readFileIfExists(path);
|
|
8662
|
+
if (raw === void 0) throw new NoteError("not_found", `No note at ${noteIdentity(identity2, address).address}.`);
|
|
8663
|
+
assertDreamSessionNote(target.scope, target.who, identity2, raw, address);
|
|
8664
|
+
const { meta } = parseNote(raw);
|
|
8665
|
+
if (meta.crumpledAt === void 0) throw new NoteError("not_crumpled", `${noteIdentity(identity2, address).address} isn't crumpled; crumple it before deleting.`);
|
|
8666
|
+
await unlink(path);
|
|
8667
|
+
return { ...meta, scope: target.scope };
|
|
8668
|
+
});
|
|
8669
|
+
}
|
|
8645
8670
|
async function* scan(options, status) {
|
|
8646
8671
|
const glob = assertGlobPattern(options.glob);
|
|
8647
8672
|
const pattern = glob === "@default" ? void 0 : glob;
|
|
@@ -8723,7 +8748,7 @@ function createNotesStore(input) {
|
|
|
8723
8748
|
function searchWithStatus(queries, options = {}) {
|
|
8724
8749
|
return searchRows(queries, options, { homesUnavailable: [] });
|
|
8725
8750
|
}
|
|
8726
|
-
return { write, read, update, rename: rename2, list, search, listWithStatus, searchWithStatus };
|
|
8751
|
+
return { write, read, update, rename: rename2, forget, list, search, listWithStatus, searchWithStatus };
|
|
8727
8752
|
}
|
|
8728
8753
|
|
|
8729
8754
|
// src/tools/output.ts
|
|
@@ -9640,22 +9665,6 @@ var historyRead = {
|
|
|
9640
9665
|
// plugins/claude/src/history.ts
|
|
9641
9666
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
9642
9667
|
import { isDeepStrictEqual } from "node:util";
|
|
9643
|
-
var METADATA = /* @__PURE__ */ new Set([
|
|
9644
|
-
"queue-operation",
|
|
9645
|
-
"last-prompt",
|
|
9646
|
-
"atis-latch",
|
|
9647
|
-
"mode",
|
|
9648
|
-
"permission-mode",
|
|
9649
|
-
"file-history-snapshot",
|
|
9650
|
-
"cost-state",
|
|
9651
|
-
"summary",
|
|
9652
|
-
"custom-title",
|
|
9653
|
-
"agent-name",
|
|
9654
|
-
"agent-color",
|
|
9655
|
-
"tag",
|
|
9656
|
-
"session-title",
|
|
9657
|
-
"progress"
|
|
9658
|
-
]);
|
|
9659
9668
|
var MESSAGE_TYPES = /* @__PURE__ */ new Set(["user", "assistant", "system", "attachment"]);
|
|
9660
9669
|
var NON_TEXT_BLOCKS = /* @__PURE__ */ new Set(["thinking", "redacted_thinking", "image", "document", "audio", "video", "server_tool_use", "web_search_tool_result", "tool_reference"]);
|
|
9661
9670
|
function object(value) {
|
|
@@ -9752,8 +9761,7 @@ function claudeHistoryFromJsonl(text, source) {
|
|
|
9752
9761
|
const nodes = /* @__PURE__ */ new Map();
|
|
9753
9762
|
let nextSeq = 1;
|
|
9754
9763
|
for (const row of rowsOf(text)) {
|
|
9755
|
-
if (
|
|
9756
|
-
if (!MESSAGE_TYPES.has(row.type)) throw new Error(`unsupported Claude transcript record type: ${row.type}`);
|
|
9764
|
+
if (!MESSAGE_TYPES.has(row.type)) continue;
|
|
9757
9765
|
const uuid = requiredString(row.uuid, "uuid");
|
|
9758
9766
|
parent(row);
|
|
9759
9767
|
if (row.sessionId !== source.sessionId) throw new Error("Claude transcript belongs to a different session");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EngineInterface, On, ProcessRunResult, ToolCallResult, ToolSpec } from "claude-code"
|
|
1
|
+
import type { EngineInterface, On, ProcessRunResult, ToolCallInput, ToolCallResult, ToolSpec } from "claude-code"
|
|
2
2
|
|
|
3
3
|
const PREFIX = "mcp__notesoup__"
|
|
4
4
|
const HELPER = `${import.meta.dir}/../dist/claude/helper.js`
|
|
@@ -22,7 +22,7 @@ type ResetState = {
|
|
|
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
|
|
25
|
-
limits?: ClaudeLimits; warnedWindow?: number; texts?: SharedTexts; settingsFailureLogged: boolean
|
|
25
|
+
limits?: ClaudeLimits; warnedWindow?: number; warningPending?: number; texts?: SharedTexts; settingsFailureLogged: boolean
|
|
26
26
|
}
|
|
27
27
|
const HEADLESS = "No brain when headless"
|
|
28
28
|
const COMPACT_DISABLED = "Brain can't be emptied with DISABLE_COMPACT"
|
|
@@ -104,12 +104,9 @@ async function compactDisabled($: Engine): Promise<boolean> {
|
|
|
104
104
|
// The same presence convention as the helper's flag parsing: "off"/"no" mean not disabled.
|
|
105
105
|
return text !== "" && text !== "0" && text !== "false" && text !== "no" && text !== "off"
|
|
106
106
|
}
|
|
107
|
-
/** Presence-style
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
try { value = await $.env.get("NOTESOUP_DISABLED") } catch { return false }
|
|
111
|
-
if (value === undefined) return false
|
|
112
|
-
const text = value.trim().toLowerCase()
|
|
107
|
+
/** Presence-style env switch; the same convention as DISABLE_COMPACT. The loader requires literal env names. */
|
|
108
|
+
function envFlag(value: string | undefined): boolean {
|
|
109
|
+
const text = value?.trim().toLowerCase() ?? ""
|
|
113
110
|
return text !== "" && text !== "0" && text !== "false" && text !== "no" && text !== "off"
|
|
114
111
|
}
|
|
115
112
|
async function readSettings($: Engine, state: ResetState): Promise<unknown> {
|
|
@@ -267,7 +264,7 @@ function forgetSession(state: ResetState) {
|
|
|
267
264
|
state.continuationWindow = undefined
|
|
268
265
|
state.limitsAttempts = state.limitsWindow = 0
|
|
269
266
|
state.settingsFailureLogged = state.limitsFailureLogged = false
|
|
270
|
-
state.warnedWindow = undefined
|
|
267
|
+
state.warnedWindow = state.warningPending = undefined
|
|
271
268
|
}
|
|
272
269
|
async function modelOf($: Engine): Promise<string> {
|
|
273
270
|
// session.model() is the documented main-loop model API. Match the notes library's slug.
|
|
@@ -319,6 +316,7 @@ export function register(on: On) {
|
|
|
319
316
|
const manualSignal: { wake?: () => void } = {}
|
|
320
317
|
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 }
|
|
321
318
|
const registered = new Set<string>()
|
|
319
|
+
let keepMemory = false
|
|
322
320
|
// Classic SessionStart precedes typed session.start and startup appends. Keep this binding
|
|
323
321
|
// across forgetSession; re-key it only against the actual session id, never a guessed path.
|
|
324
322
|
on("classic.SessionStart", async ($, e, next) => {
|
|
@@ -339,12 +337,13 @@ export function register(on: On) {
|
|
|
339
337
|
})
|
|
340
338
|
on("session.start", async ($, e, next) => {
|
|
341
339
|
forgetSession(state)
|
|
342
|
-
state.disabled = await
|
|
340
|
+
state.disabled = envFlag(await $.env.get("NOTESOUP_DISABLED").catch(() => undefined))
|
|
343
341
|
if (state.disabled) {
|
|
344
342
|
registered.clear()
|
|
345
343
|
log($, NOTESOUP_DISABLED)
|
|
346
344
|
return next(e)
|
|
347
345
|
}
|
|
346
|
+
keepMemory = envFlag(await $.env.get("NOTESOUP_KEEP_MEMORY").catch(() => undefined))
|
|
348
347
|
await refreshIdentity($, state)
|
|
349
348
|
state.headless = !e.isInteractive
|
|
350
349
|
if (state.headless) log($, HEADLESS)
|
|
@@ -371,19 +370,13 @@ export function register(on: On) {
|
|
|
371
370
|
})
|
|
372
371
|
on("tool.call", async ($, e, next) => {
|
|
373
372
|
if (state.disabled) return next(e)
|
|
374
|
-
|
|
375
|
-
const
|
|
376
|
-
if (
|
|
377
|
-
|
|
378
|
-
const name = tool.slice(PREFIX.length)
|
|
379
|
-
if (name.startsWith("history_") && agentId !== undefined) return errorResult("history is unavailable for subagents; main-session history is not their transcript")
|
|
380
|
-
const result = await run($, { op: "tool", tool: name, params, identity, history: state.history })
|
|
381
|
-
if (!result.ok) return errorResult(result.error)
|
|
382
|
-
// The outcome already decided success or refusal; Claude requires isError: true on errors and no discriminator on success.
|
|
383
|
-
const outcome = toolResultOf(result.result)
|
|
384
|
-
if (!outcome) return errorResult("helper returned an invalid tool result")
|
|
385
|
-
return outcome.ok ? { result: outcome.text } : { result: outcome.text, isError: true }
|
|
373
|
+
const generation = state.generation
|
|
374
|
+
const result = registered.has(e.tool) ? await callNotesTool($, state, e) : await next(e)
|
|
375
|
+
if (e.agentId !== undefined || result.deny !== undefined || generation !== state.generation) return result
|
|
376
|
+
return withWarning($, state, (warning) => warning === undefined ? result : { ...result, context: [...(result.context ?? []), warning] })
|
|
386
377
|
})
|
|
378
|
+
on("prompt.submit", ($, e, next) => withWarning($, state, (warning) =>
|
|
379
|
+
next(warning === undefined ? e : { ...e, context: [...(e.context ?? []), warning] })))
|
|
387
380
|
on("turn.start", async ($, e, next) => {
|
|
388
381
|
// The documented turn.start is main-loop only. Guard tagged host events too:
|
|
389
382
|
// only a main-agent turn.complete clears this latch.
|
|
@@ -465,6 +458,9 @@ export function register(on: On) {
|
|
|
465
458
|
}
|
|
466
459
|
return { messages: built.messages }
|
|
467
460
|
})
|
|
461
|
+
// notesoup replaces Claude's summarization and auto-memory guidance; memory can be kept on request.
|
|
462
|
+
on("prompt.section", { name: "context_management" }, ($, e, next) => state.disabled ? next(e) : { text: null })
|
|
463
|
+
on("prompt.section", { name: "memory" }, ($, e, next) => state.disabled || keepMemory ? next(e) : { text: null })
|
|
468
464
|
on("prompt.context", async ($, e, next) => {
|
|
469
465
|
if (state.disabled) return next(e)
|
|
470
466
|
const result = await next(e)
|
|
@@ -485,18 +481,27 @@ export function register(on: On) {
|
|
|
485
481
|
}
|
|
486
482
|
blocks = [...blocks, { name: "notesoup:boot", text: boot.ok ? String(boot.result) : `# notesoup\nYour notes didn't load this time (${boot.error}). Try \`${PREFIX}notes_list\`; if it fails too, tell the human.` }]
|
|
487
483
|
}
|
|
488
|
-
|
|
489
|
-
return { ...result, blocks: warning === undefined ? blocks : [...blocks, warning] }
|
|
484
|
+
return { ...result, blocks }
|
|
490
485
|
})
|
|
491
486
|
|
|
492
487
|
}
|
|
493
488
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
if (
|
|
489
|
+
async function callNotesTool($: Engine, state: ResetState, e: ToolCallInput): Promise<ToolCallResult> {
|
|
490
|
+
const identity = await refreshIdentity($, state)
|
|
491
|
+
if (!identity) return errorResult("session changed during identity lookup")
|
|
492
|
+
const { tool, tool_use_id: _toolUseId, agentId, ...params } = e
|
|
493
|
+
const name = tool.slice(PREFIX.length)
|
|
494
|
+
if (name.startsWith("history_") && agentId !== undefined) return errorResult("history is unavailable for subagents; main-session history is not their transcript")
|
|
495
|
+
const result = await run($, { op: "tool", tool: name, params, identity, history: state.history })
|
|
496
|
+
if (!result.ok) return errorResult(result.error)
|
|
497
|
+
const outcome = toolResultOf(result.result)
|
|
498
|
+
if (!outcome) return errorResult("helper returned an invalid tool result")
|
|
499
|
+
return outcome.ok ? { result: outcome.text } : { result: outcome.text, isError: true }
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** Read the warning without consuming this window's delivery. */
|
|
503
|
+
async function warningText($: Engine, state: ResetState): Promise<string | undefined> {
|
|
504
|
+
if (state.disabled || state.headless || state.compactDisabled || !state.identity || state.warnedWindow === state.window || state.warningPending === state.window) return undefined
|
|
500
505
|
const generation = state.generation
|
|
501
506
|
const usage = await contextUsage($, state)
|
|
502
507
|
if (generation !== state.generation || usage === undefined) return undefined
|
|
@@ -505,9 +510,23 @@ async function warningBlock($: Engine, state: ResetState): Promise<{ name: strin
|
|
|
505
510
|
const measured = measuredValue(limits, usage)
|
|
506
511
|
if (measured === undefined || measured < limits.warn) return undefined
|
|
507
512
|
const texts = await loadTexts($, state)
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
513
|
+
return generation === state.generation ? texts?.warning : undefined
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** Reserve across next(), but consume only context the chain actually accepted. */
|
|
517
|
+
async function withWarning<T extends { context?: readonly string[]; drop?: string; deny?: string }>($: Engine, state: ResetState, deliver: (warning?: string) => T | Promise<T>): Promise<T> {
|
|
518
|
+
if (state.disabled || state.headless || state.compactDisabled || !await refreshIdentity($, state)) return deliver()
|
|
519
|
+
const generation = state.generation, window = state.window
|
|
520
|
+
const warning = await warningText($, state)
|
|
521
|
+
if (warning === undefined || generation !== state.generation || window !== state.window || state.warnedWindow === window || state.warningPending === window) return deliver()
|
|
522
|
+
state.warningPending = window
|
|
523
|
+
try {
|
|
524
|
+
const result = await deliver(warning)
|
|
525
|
+
if (generation === state.generation && window === state.window && result.drop === undefined && result.deny === undefined && result.context?.includes(warning)) state.warnedWindow = window
|
|
526
|
+
return result
|
|
527
|
+
} finally {
|
|
528
|
+
if (generation === state.generation && state.warningPending === window) state.warningPending = undefined
|
|
529
|
+
}
|
|
511
530
|
}
|
|
512
531
|
|
|
513
532
|
/** The boot's identity line; `context_window` is the pre-rename tag still in old transcripts. */
|
|
@@ -7,10 +7,6 @@ type Row = Record<string, unknown>;
|
|
|
7
7
|
type Version = { row: Row; ancestorUuid?: string; ancestor?: Version; ordinal?: number };
|
|
8
8
|
type Node = { first: Version; latest: Version; items: DecodedHistoryItem[] };
|
|
9
9
|
export type ClaudeHistorySource = { sessionId: string; transcriptPath: string; headUuid?: string };
|
|
10
|
-
const METADATA = new Set([
|
|
11
|
-
"queue-operation", "last-prompt", "atis-latch", "mode", "permission-mode", "file-history-snapshot", "cost-state",
|
|
12
|
-
"summary", "custom-title", "agent-name", "agent-color", "tag", "session-title", "progress",
|
|
13
|
-
]);
|
|
14
10
|
const MESSAGE_TYPES = new Set(["user", "assistant", "system", "attachment"]);
|
|
15
11
|
const NON_TEXT_BLOCKS = new Set(["thinking", "redacted_thinking", "image", "document", "audio", "video", "server_tool_use", "web_search_tool_result", "tool_reference"]);
|
|
16
12
|
function object(value: unknown): value is Row { return typeof value === "object" && value !== null && !Array.isArray(value); }
|
|
@@ -119,8 +115,9 @@ export function claudeHistoryFromJsonl(text: string, source: Omit<ClaudeHistoryS
|
|
|
119
115
|
const nodes = new Map<string, Node>();
|
|
120
116
|
let nextSeq = 1;
|
|
121
117
|
for (const row of rowsOf(text)) {
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
// Ignore non-message records, including future metadata. A skipped UUID that
|
|
119
|
+
// the selected branch actually requires still fails ancestry resolution below.
|
|
120
|
+
if (!MESSAGE_TYPES.has(row.type as string)) continue;
|
|
124
121
|
const uuid = requiredString(row.uuid, "uuid");
|
|
125
122
|
parent(row);
|
|
126
123
|
if (row.sessionId !== source.sessionId) throw new Error("Claude transcript belongs to a different session");
|