notesoup 0.60.1 → 0.62.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/.agents/plugins/marketplace.json +15 -0
- package/README.md +14 -10
- package/dist/plugins/antigravity/src/cli.d.ts +1 -0
- package/dist/plugins/antigravity/src/cli.js +23 -0
- package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
- package/dist/plugins/antigravity/src/hooks.js +53 -0
- package/dist/plugins/antigravity/src/identity.d.ts +26 -0
- package/dist/plugins/antigravity/src/identity.js +129 -0
- package/dist/plugins/claude/src/helper.js +2 -1
- package/dist/plugins/codex/src/hooks.js +1 -0
- package/dist/plugins/codex/src/identity.d.ts +6 -1
- package/dist/plugins/codex/src/identity.js +13 -1
- package/dist/plugins/codex/src/mcp.d.ts +35 -7
- package/dist/plugins/codex/src/mcp.js +26 -88
- package/dist/plugins/codex/src/text.js +3 -3
- package/dist/plugins/dsh/tools.js +8 -4
- package/dist/plugins/mcp/operations.d.ts +15 -0
- package/dist/plugins/mcp/operations.js +43 -0
- package/dist/plugins/mcp/server.d.ts +14 -0
- package/dist/plugins/mcp/server.js +13 -0
- package/dist/plugins/pi/budget.d.ts +1 -1
- package/dist/plugins/pi/budget.js +3 -2
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -0
- package/dist/plugins/pi/history-tools.js +2 -1
- package/dist/plugins/pi/history.js +18 -1
- package/dist/plugins/pi/notes/tools.js +7 -3
- package/dist/plugins/pi/render.d.ts +7 -1
- package/dist/plugins/pi/render.js +2 -2
- package/dist/plugins/pi/reset/lifecycle.d.ts +1 -1
- package/dist/plugins/pi/reset/lifecycle.js +8 -9
- package/dist/plugins/pi/runtime.js +102 -61
- package/dist/plugins/pi/tool-result.js +7 -7
- package/dist/plugins/pi/window.d.ts +33 -3
- package/dist/plugins/pi/window.js +209 -9
- package/dist/src/boot/render.d.ts +5 -0
- package/dist/src/boot/render.js +60 -28
- package/dist/src/boot/text.d.ts +3 -3
- package/dist/src/boot/text.js +27 -26
- package/dist/src/budget/text.d.ts +2 -2
- package/dist/src/budget/text.js +13 -13
- package/dist/src/history/claude.d.ts +2 -0
- package/dist/src/history/claude.js +46 -0
- package/dist/src/history/codex-transcript.js +7 -5
- package/dist/src/history/codex.js +3 -0
- package/dist/src/history/corpus.d.ts +28 -1
- package/dist/src/history/corpus.js +40 -0
- package/dist/src/history/history.d.ts +37 -46
- package/dist/src/history/history.js +21 -40
- package/dist/src/history/local.js +67 -32
- package/dist/src/history/pi.d.ts +2 -1
- package/dist/src/history/pi.js +122 -48
- package/dist/src/history/prefilter.js +76 -19
- package/dist/src/history/query.d.ts +28 -49
- package/dist/src/history/query.js +83 -68
- package/dist/src/history/summary-cache.d.ts +8 -1
- package/dist/src/history/summary-cache.js +138 -12
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/notes/frontmatter.d.ts +4 -0
- package/dist/src/notes/frontmatter.js +15 -1
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/policy.d.ts +15 -1
- package/dist/src/notes/policy.js +47 -6
- package/dist/src/notes/store.d.ts +14 -0
- package/dist/src/notes/store.js +33 -12
- package/dist/src/text-match.d.ts +10 -1
- package/dist/src/text-match.js +42 -3
- package/dist/src/tools/dream.d.ts +22 -91
- package/dist/src/tools/dream.js +30 -27
- package/dist/src/tools/history.d.ts +33 -26
- package/dist/src/tools/history.js +257 -163
- package/dist/src/tools/notes.d.ts +58 -160
- package/dist/src/tools/notes.js +151 -99
- package/dist/src/tools/output.d.ts +2 -1
- package/dist/src/tools/output.js +2 -1
- package/dist/src/tools/result.d.ts +4 -7
- package/dist/src/tools/result.js +8 -9
- package/dist/src/tools/schema.d.ts +4 -1
- package/dist/src/tools/schema.js +25 -1
- package/dist/test/agent-loop.test.js +198 -16
- package/dist/test/antigravity-live.test.d.ts +1 -0
- package/dist/test/antigravity-live.test.js +142 -0
- package/dist/test/antigravity-plugin.test.d.ts +1 -0
- package/dist/test/antigravity-plugin.test.js +101 -0
- package/dist/test/boot.integration.test.js +133 -14
- package/dist/test/claude-history.test.js +14 -13
- package/dist/test/claude-mod.test.js +9 -6
- package/dist/test/codex-history.test.js +15 -3
- package/dist/test/codex-plugin.test.js +76 -38
- package/dist/test/dependencies.test.js +7 -3
- package/dist/test/dream-skill.test.js +3 -3
- package/dist/test/dream-tools.test.js +101 -56
- package/dist/test/dsh.test.js +34 -19
- package/dist/test/helpers/dependency-graph.js +2 -2
- package/dist/test/helpers/extension.d.ts +65 -2
- package/dist/test/helpers/extension.js +72 -3
- package/dist/test/history-corpus.test.js +79 -77
- package/dist/test/history-summary-cache.test.js +97 -9
- package/dist/test/history.integration.test.js +234 -168
- package/dist/test/host-neutral.test.js +69 -19
- package/dist/test/marker.test.js +1 -1
- package/dist/test/note-policy.test.js +189 -56
- package/dist/test/notes.integration.test.js +212 -94
- package/dist/test/notes.test.js +184 -113
- package/dist/test/pi-render.test.js +20 -12
- package/dist/test/project-namespace.test.js +3 -2
- package/dist/test/reset-lifecycle.test.js +2 -2
- package/docs/antigravity.md +44 -0
- package/docs/architecture.md +6 -4
- package/docs/claude-code-mod.md +2 -2
- package/docs/codex.md +36 -38
- package/docs/dsh.md +4 -4
- package/docs/history-sessions.md +28 -50
- package/docs/notes-library.md +6 -6
- package/docs/reset-lifecycle.md +1 -1
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +47 -28
- package/package.json +3 -2
- package/playbook.md +3 -3
- package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
- package/plugins/antigravity/hooks.json +7 -0
- package/plugins/antigravity/mcp_config.json +8 -0
- package/plugins/antigravity/plugin.json +6 -0
- package/plugins/antigravity/src/cli.ts +22 -0
- package/plugins/antigravity/src/hooks.ts +51 -0
- package/plugins/antigravity/src/identity.ts +127 -0
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +1129 -549
- package/plugins/claude/hooks/register.ts +2 -2
- package/plugins/claude/playbook.md +3 -3
- package/plugins/claude/skills/dream/SKILL.md +2 -2
- package/plugins/claude/skills/notesoup/SKILL.md +92 -0
- package/plugins/claude/src/helper.ts +2 -1
- package/plugins/codex/.codex-plugin/plugin.json +8 -0
- package/plugins/codex/.mcp.json +11 -0
- package/plugins/codex/README.md +5 -21
- package/plugins/codex/dist/codex/notesoup.js +18494 -17905
- package/plugins/codex/src/hooks.ts +1 -0
- package/plugins/codex/src/identity.ts +14 -1
- package/plugins/codex/src/mcp.ts +28 -98
- package/plugins/codex/src/text.ts +3 -3
- package/plugins/dsh/tools.ts +8 -4
- package/plugins/mcp/operations.ts +50 -0
- package/plugins/mcp/server.ts +23 -0
- package/plugins/paseo/README.md +5 -10
- package/plugins/paseo/client/brain-empty-card.tsx +3 -3
- package/plugins/paseo/client/markdown.tsx +50 -38
- package/plugins/paseo/client/notes-op-card.tsx +12 -9
- package/plugins/paseo/client/paper-card.tsx +6 -5
- package/plugins/paseo/client/paper-palette.ts +2 -9
- package/plugins/paseo/client/sticky-card.tsx +2 -2
- package/plugins/paseo/client/tool-result.ts +7 -14
- package/plugins/paseo/package-lock.json +3406 -0
- package/plugins/paseo/package.json +1 -0
- package/plugins/paseo/test/markdown-core.test.ts +73 -66
- package/plugins/pi/budget.ts +3 -3
- package/plugins/pi/entries.ts +1 -0
- package/plugins/pi/history-tools.ts +2 -1
- package/plugins/pi/history.ts +30 -1
- package/plugins/pi/notes/tools.ts +7 -3
- package/plugins/pi/render.ts +6 -6
- package/plugins/pi/reset/lifecycle.ts +9 -10
- package/plugins/pi/runtime.ts +96 -60
- package/plugins/pi/tool-result.ts +8 -8
- package/plugins/pi/window.ts +198 -9
- package/skills/dream/SKILL.md +2 -2
- package/skills/notesoup/SKILL.md +92 -0
- package/src/boot/render.ts +59 -25
- package/src/boot/text.ts +30 -27
- package/src/budget/text.ts +13 -13
- package/src/history/claude.ts +41 -0
- package/src/history/codex-transcript.ts +6 -4
- package/src/history/codex.ts +2 -0
- package/src/history/corpus.ts +51 -2
- package/src/history/history.ts +35 -44
- package/src/history/local.ts +67 -27
- package/src/history/pi.ts +113 -35
- package/src/history/prefilter.ts +73 -15
- package/src/history/query.ts +93 -73
- package/src/history/summary-cache.ts +142 -17
- package/src/index.ts +1 -1
- package/src/notes/frontmatter.ts +16 -1
- package/src/notes/index.ts +1 -1
- package/src/notes/policy.ts +45 -6
- package/src/notes/store.ts +30 -15
- package/src/text-match.ts +46 -4
- package/src/tools/dream.ts +29 -31
- package/src/tools/history.ts +249 -142
- package/src/tools/notes.ts +150 -112
- package/src/tools/output.ts +2 -1
- package/src/tools/result.ts +12 -11
- package/src/tools/schema.ts +24 -1
- package/plugins/claude/skills/memory/SKILL.md +0 -69
- package/plugins/codex/mcp.json +0 -10
- package/plugins/codex/plugin.json +0 -6
- package/plugins/paseo/client/markdown-core.tsx +0 -189
- package/plugins/paseo/client/typography.ts +0 -24
- package/skills/memory/SKILL.md +0 -69
package/dist/src/text-match.js
CHANGED
|
@@ -32,6 +32,45 @@ export function prefixFit(text, fits) {
|
|
|
32
32
|
}
|
|
33
33
|
return chars.slice(0, low).join("");
|
|
34
34
|
}
|
|
35
|
+
/** Compile literal Unicode case-insensitive patterns once per search operation. */
|
|
36
|
+
export function compileSearchQueries(queries) {
|
|
37
|
+
return queries.map((query) => new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "iu"));
|
|
38
|
+
}
|
|
39
|
+
/** Count Unicode code points in `text.slice(0, utf16End)` without allocating an array. */
|
|
40
|
+
export function codePointCount(text, utf16End = text.length) {
|
|
41
|
+
let count = utf16End;
|
|
42
|
+
for (let i = 0; i < utf16End - 1; i++) {
|
|
43
|
+
const code = text.charCodeAt(i);
|
|
44
|
+
if (code >= 0xd800 && code <= 0xdbff) {
|
|
45
|
+
const next = text.charCodeAt(i + 1);
|
|
46
|
+
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
47
|
+
count--;
|
|
48
|
+
i++;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return count;
|
|
53
|
+
}
|
|
54
|
+
/** Slice `[start, start + limit)` code points without splitting the entire string into an array. */
|
|
55
|
+
export function sliceCodePoints(text, start, limit) {
|
|
56
|
+
const len = text.length;
|
|
57
|
+
let utf16Start = 0;
|
|
58
|
+
let cp = 0;
|
|
59
|
+
while (cp < start && utf16Start < len) {
|
|
60
|
+
const code = text.charCodeAt(utf16Start);
|
|
61
|
+
utf16Start += code >= 0xd800 && code <= 0xdbff && utf16Start + 1 < len && text.charCodeAt(utf16Start + 1) >= 0xdc00 && text.charCodeAt(utf16Start + 1) <= 0xdfff ? 2 : 1;
|
|
62
|
+
cp++;
|
|
63
|
+
}
|
|
64
|
+
let utf16End = utf16Start;
|
|
65
|
+
let taken = 0;
|
|
66
|
+
while (taken < limit && utf16End < len) {
|
|
67
|
+
const code = text.charCodeAt(utf16End);
|
|
68
|
+
utf16End += code >= 0xd800 && code <= 0xdbff && utf16End + 1 < len && text.charCodeAt(utf16End + 1) >= 0xdc00 && text.charCodeAt(utf16End + 1) <= 0xdfff ? 2 : 1;
|
|
69
|
+
taken++;
|
|
70
|
+
}
|
|
71
|
+
const truncated = start > 0 || utf16End < len;
|
|
72
|
+
return { text: truncated ? text.slice(utf16Start, utf16End) : text, truncated };
|
|
73
|
+
}
|
|
35
74
|
/**
|
|
36
75
|
* Code-point offset of the earliest case-insensitive literal match, or -1 when
|
|
37
76
|
* none occurs. Match against the original text so Unicode casing cannot shift offsets.
|
|
@@ -39,12 +78,12 @@ export function prefixFit(text, fits) {
|
|
|
39
78
|
export function earliestMatchOffsetChars(text, queries) {
|
|
40
79
|
let earliest = -1;
|
|
41
80
|
for (const query of queries) {
|
|
42
|
-
const
|
|
43
|
-
const index =
|
|
81
|
+
const pattern = typeof query === "string" ? new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "iu") : query;
|
|
82
|
+
const index = pattern.exec(text)?.index ?? -1;
|
|
44
83
|
if (index < 0)
|
|
45
84
|
continue;
|
|
46
85
|
if (earliest < 0 || index < earliest)
|
|
47
86
|
earliest = index;
|
|
48
87
|
}
|
|
49
|
-
return earliest < 0 ? -1 :
|
|
88
|
+
return earliest < 0 ? -1 : codePointCount(text, earliest);
|
|
50
89
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Type, type Static } from "typebox";
|
|
2
|
-
import { type NotesIdentity } from "../notes/index.js";
|
|
2
|
+
import { noteIdentity, type NotesIdentity } from "../notes/index.js";
|
|
3
|
+
import { type ProjectReceipt } from "../notes/project-namespace.js";
|
|
3
4
|
import { type Outcome } from "../result.js";
|
|
5
|
+
import { type ListedFile, type Snapshot } from "./notes.js";
|
|
6
|
+
import { type NotesToolContext } from "./notes-context.js";
|
|
4
7
|
/** The one open dream per session; the host owns where it lives. */
|
|
5
8
|
type DreamOpening = {
|
|
6
9
|
project: string;
|
|
@@ -18,121 +21,49 @@ export declare function abandonDream(state: DreamState): void;
|
|
|
18
21
|
/** The identity a store uses while `state` holds an open dream. */
|
|
19
22
|
export declare function dreamingIdentity(identity: NotesIdentity, state: DreamState): NotesIdentity;
|
|
20
23
|
export declare const dreamBeginParameters: Type.TObject<{
|
|
21
|
-
|
|
24
|
+
cwd: Type.TOptional<Type.TString>;
|
|
22
25
|
}>;
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
project:
|
|
27
|
-
baseline:
|
|
28
|
-
|
|
29
|
-
last_accessed: Type.TString;
|
|
30
|
-
updated_at: Type.TString;
|
|
31
|
-
crumpled_at: Type.TOptional<Type.TString>;
|
|
32
|
-
warnings: Type.TArray<Type.TString>;
|
|
33
|
-
pinned: Type.TBoolean;
|
|
34
|
-
budget: Type.TInteger;
|
|
35
|
-
readonly: Type.TBoolean;
|
|
36
|
-
project_root: Type.TOptional<Type.TString>;
|
|
37
|
-
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
38
|
-
name: Type.TString;
|
|
39
|
-
path: Type.TString;
|
|
40
|
-
}>>>;
|
|
41
|
-
address: Type.TString;
|
|
42
|
-
project_key: Type.TOptional<Type.TString>;
|
|
43
|
-
}>>;
|
|
44
|
-
}>;
|
|
45
|
-
export type DreamBeginData = Static<typeof DreamBeginDataSchema>;
|
|
26
|
+
export type DreamBeginData = Snapshot<ListedFile & {
|
|
27
|
+
last_accessed: string;
|
|
28
|
+
}> & {
|
|
29
|
+
project: string;
|
|
30
|
+
baseline: string;
|
|
31
|
+
} & ProjectReceipt;
|
|
46
32
|
export declare const dreamBegin: {
|
|
47
33
|
readonly name: "dream_begin";
|
|
48
34
|
readonly label: "Dream begin";
|
|
49
|
-
readonly description: "
|
|
35
|
+
readonly description: "Open a project's notes and its session notes for consolidation after committing a Git baseline; unlocks writes until `dream_end`.";
|
|
50
36
|
readonly parameters: Type.TObject<{
|
|
51
|
-
|
|
37
|
+
cwd: Type.TOptional<Type.TString>;
|
|
52
38
|
}>;
|
|
53
|
-
readonly
|
|
54
|
-
more: Type.TInteger;
|
|
55
|
-
namespaces_unavailable: Type.TArray<Type.TString>;
|
|
56
|
-
project: Type.TString;
|
|
57
|
-
baseline: Type.TString;
|
|
58
|
-
files: Type.TArray<Type.TObject<{
|
|
59
|
-
last_accessed: Type.TString;
|
|
60
|
-
updated_at: Type.TString;
|
|
61
|
-
crumpled_at: Type.TOptional<Type.TString>;
|
|
62
|
-
warnings: Type.TArray<Type.TString>;
|
|
63
|
-
pinned: Type.TBoolean;
|
|
64
|
-
budget: Type.TInteger;
|
|
65
|
-
readonly: Type.TBoolean;
|
|
66
|
-
project_root: Type.TOptional<Type.TString>;
|
|
67
|
-
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
68
|
-
name: Type.TString;
|
|
69
|
-
path: Type.TString;
|
|
70
|
-
}>>>;
|
|
71
|
-
address: Type.TString;
|
|
72
|
-
project_key: Type.TOptional<Type.TString>;
|
|
73
|
-
}>>;
|
|
74
|
-
}>, Type.TObject<{
|
|
75
|
-
error: Type.TString;
|
|
76
|
-
code: Type.TString;
|
|
77
|
-
}>]>;
|
|
78
|
-
readonly execute: (params: Static<typeof dreamBeginParameters>, identity: NotesIdentity, state: DreamState) => Promise<Outcome<DreamBeginData>>;
|
|
39
|
+
readonly execute: (params: Static<typeof dreamBeginParameters>, context: NotesToolContext, state: DreamState) => Promise<Outcome<DreamBeginData>>;
|
|
79
40
|
readonly render: (result: Outcome<DreamBeginData>) => string;
|
|
80
41
|
};
|
|
81
42
|
export declare const dreamForgetParameters: Type.TObject<{
|
|
82
43
|
address: Type.TString;
|
|
83
44
|
}>;
|
|
84
|
-
export
|
|
85
|
-
project_root: Type.TOptional<Type.TString>;
|
|
86
|
-
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
87
|
-
name: Type.TString;
|
|
88
|
-
path: Type.TString;
|
|
89
|
-
}>>>;
|
|
90
|
-
address: Type.TString;
|
|
91
|
-
project_key: Type.TOptional<Type.TString>;
|
|
92
|
-
}>;
|
|
93
|
-
export type DreamForgetData = Static<typeof DreamForgetDataSchema>;
|
|
45
|
+
export type DreamForgetData = ReturnType<typeof noteIdentity>;
|
|
94
46
|
export declare const dreamForget: {
|
|
95
47
|
readonly name: "dream_forget";
|
|
96
48
|
readonly label: "Dream forget";
|
|
97
|
-
readonly description: "
|
|
49
|
+
readonly description: "Permanently delete a crumpled note in the open dream.";
|
|
98
50
|
readonly parameters: Type.TObject<{
|
|
99
51
|
address: Type.TString;
|
|
100
52
|
}>;
|
|
101
|
-
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
102
|
-
project_root: Type.TOptional<Type.TString>;
|
|
103
|
-
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
104
|
-
name: Type.TString;
|
|
105
|
-
path: Type.TString;
|
|
106
|
-
}>>>;
|
|
107
|
-
address: Type.TString;
|
|
108
|
-
project_key: Type.TOptional<Type.TString>;
|
|
109
|
-
}>, Type.TObject<{
|
|
110
|
-
error: Type.TString;
|
|
111
|
-
code: Type.TString;
|
|
112
|
-
}>]>;
|
|
113
53
|
readonly execute: (params: Static<typeof dreamForgetParameters>, identity: NotesIdentity, state: DreamState) => Promise<Outcome<DreamForgetData>>;
|
|
114
54
|
readonly render: (result: Outcome<DreamForgetData>) => string;
|
|
115
55
|
};
|
|
116
56
|
export declare const dreamEndParameters: Type.TObject<{}>;
|
|
117
|
-
export
|
|
118
|
-
project:
|
|
119
|
-
commit
|
|
120
|
-
audit_error
|
|
121
|
-
}
|
|
122
|
-
export type DreamEndData = Static<typeof DreamEndDataSchema>;
|
|
57
|
+
export type DreamEndData = {
|
|
58
|
+
project: string;
|
|
59
|
+
commit?: string;
|
|
60
|
+
audit_error?: string;
|
|
61
|
+
};
|
|
123
62
|
export declare const dreamEnd: {
|
|
124
63
|
readonly name: "dream_end";
|
|
125
64
|
readonly label: "Dream end";
|
|
126
|
-
readonly description: "
|
|
65
|
+
readonly description: "Commit dream changes to the notes Git repo and close the open dream.";
|
|
127
66
|
readonly parameters: Type.TObject<{}>;
|
|
128
|
-
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
129
|
-
project: Type.TString;
|
|
130
|
-
commit: Type.TOptional<Type.TString>;
|
|
131
|
-
audit_error: Type.TOptional<Type.TString>;
|
|
132
|
-
}>, Type.TObject<{
|
|
133
|
-
error: Type.TString;
|
|
134
|
-
code: Type.TString;
|
|
135
|
-
}>]>;
|
|
136
67
|
readonly execute: (_params: Static<typeof dreamEndParameters>, identity: NotesIdentity, state: DreamState) => Promise<Outcome<DreamEndData>>;
|
|
137
68
|
readonly render: (result: Outcome<DreamEndData>) => string;
|
|
138
69
|
};
|
package/dist/src/tools/dream.js
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { Type } from "typebox";
|
|
4
4
|
import { localIso } from "../notes/frontmatter.js";
|
|
5
|
-
import { createNotesStore, noteIdentity } from "../notes/index.js";
|
|
6
|
-
import {
|
|
5
|
+
import { compareNoteRows, createNotesStore, noteIdentity } from "../notes/index.js";
|
|
6
|
+
import { projectReceipt } from "../notes/project-namespace.js";
|
|
7
7
|
import { gitCommit } from "../dream/git.js";
|
|
8
8
|
import { trySqliteLock } from "../sqlite-lock.js";
|
|
9
9
|
import { failure, success } from "../result.js";
|
|
10
|
-
import { renderOutcome
|
|
11
|
-
import { failureOf, listedFile,
|
|
10
|
+
import { renderOutcome } from "./result.js";
|
|
11
|
+
import { failureOf, listedFile, renderListData, snapshot } from "./notes.js";
|
|
12
|
+
import { notesIdentityForCall } from "./notes-context.js";
|
|
12
13
|
function currentOpening(state, opening) {
|
|
13
14
|
return state.pending === opening && state.generation === opening.generation;
|
|
14
15
|
}
|
|
@@ -43,29 +44,31 @@ export function dreamingIdentity(identity, state) {
|
|
|
43
44
|
}
|
|
44
45
|
const NOT_DREAMING = "No dream is open; call dream_begin first.";
|
|
45
46
|
export const dreamBeginParameters = Type.Object({
|
|
46
|
-
|
|
47
|
-
}, { additionalProperties: false });
|
|
48
|
-
export const DreamBeginDataSchema = Type.Object({
|
|
49
|
-
project: Type.String(), baseline: Type.String(),
|
|
50
|
-
files: Type.Array(Type.Object({ ...ListedFileSchema.properties, last_accessed: Type.String() }, { additionalProperties: false })),
|
|
51
|
-
...SnapshotSchema,
|
|
47
|
+
cwd: Type.Optional(Type.String({ minLength: 1, description: "Treat this directory's project as current." })),
|
|
52
48
|
}, { additionalProperties: false });
|
|
53
49
|
function renderBeginData(data) {
|
|
54
|
-
|
|
50
|
+
const header = `dreaming over ${data.project} (baseline ${data.baseline}${data.project_root === undefined ? "" : `, project_root ${data.project_root}`})`;
|
|
51
|
+
const siblings = data.project_siblings === undefined ? "" : `\n Same-basename projects: ${data.project_siblings.map(sibling => `${sibling.name} (${sibling.path})`).join(", ")}`;
|
|
52
|
+
return `${header}${siblings}\n${renderListData(data, undefined, { omitNamedProjectContext: true })}`;
|
|
55
53
|
}
|
|
56
54
|
export const dreamBegin = {
|
|
57
55
|
name: "dream_begin", label: "Dream begin",
|
|
58
|
-
description: "
|
|
59
|
-
parameters: dreamBeginParameters,
|
|
60
|
-
async execute(params,
|
|
56
|
+
description: "Open a project's notes and its session notes for consolidation after committing a Git baseline; unlocks writes until `dream_end`.",
|
|
57
|
+
parameters: dreamBeginParameters,
|
|
58
|
+
async execute(params, context, state) {
|
|
61
59
|
if (state.project !== undefined || state.pending !== undefined) {
|
|
62
60
|
const project = state.project ?? state.pending?.project;
|
|
63
61
|
return failure("already_dreaming", `Already dreaming over ${project}; call dream_end before opening another project.`);
|
|
64
62
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
let identity;
|
|
64
|
+
try {
|
|
65
|
+
identity = notesIdentityForCall(context, params.cwd);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
return failureOf(error);
|
|
68
69
|
}
|
|
70
|
+
const project = identity.projectKey;
|
|
71
|
+
const receipt = projectReceipt(identity.home, project);
|
|
69
72
|
const release = trySqliteLock(join(identity.home, ".dream.lock.sqlite"), 0);
|
|
70
73
|
if (!release)
|
|
71
74
|
return failure("already_dreaming", "Another dream is open in this notes home.");
|
|
@@ -85,8 +88,10 @@ export const dreamBegin = {
|
|
|
85
88
|
unavailable.push(...result.status.namespacesUnavailable);
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
|
-
rows.sort(
|
|
89
|
-
const listed = snapshot(rows.map(row => ({ ...listedFile(row, identity), last_accessed: localIso(row.meta.lastAccessed) })), undefined, { namespacesUnavailable: unavailable },
|
|
91
|
+
rows.sort(compareNoteRows);
|
|
92
|
+
const listed = snapshot(rows.map(row => ({ ...listedFile(row, identity), last_accessed: localIso(row.meta.lastAccessed) })), undefined, { namespacesUnavailable: unavailable },
|
|
93
|
+
// Reserve the header before committing; Git object IDs are at most 64 hex digits.
|
|
94
|
+
(data) => renderBeginData({ ...data, project, baseline: "0".repeat(64), ...receipt }));
|
|
90
95
|
if (!listed.ok) {
|
|
91
96
|
releaseOpening(state, opening);
|
|
92
97
|
return listed;
|
|
@@ -103,7 +108,7 @@ export const dreamBegin = {
|
|
|
103
108
|
state.project = opening.project;
|
|
104
109
|
state.release = opening.release;
|
|
105
110
|
delete state.pending;
|
|
106
|
-
return success({ project, baseline: baseline.commit, ...listed.data });
|
|
111
|
+
return success({ project, baseline: baseline.commit, ...receipt, ...listed.data });
|
|
107
112
|
}
|
|
108
113
|
catch (error) {
|
|
109
114
|
if (!currentOpening(state, opening))
|
|
@@ -114,12 +119,11 @@ export const dreamBegin = {
|
|
|
114
119
|
},
|
|
115
120
|
render: (result) => renderOutcome(result, renderBeginData),
|
|
116
121
|
};
|
|
117
|
-
export const dreamForgetParameters = Type.Object({ address: Type.String({ description: "
|
|
118
|
-
export const DreamForgetDataSchema = Type.Object({ ...NoteIdentitySchema }, { additionalProperties: false });
|
|
122
|
+
export const dreamForgetParameters = Type.Object({ address: Type.String({ description: "Address of the crumpled note to delete." }) }, { additionalProperties: false });
|
|
119
123
|
export const dreamForget = {
|
|
120
124
|
name: "dream_forget", label: "Dream forget",
|
|
121
|
-
description: "
|
|
122
|
-
parameters: dreamForgetParameters,
|
|
125
|
+
description: "Permanently delete a crumpled note in the open dream.",
|
|
126
|
+
parameters: dreamForgetParameters,
|
|
123
127
|
async execute(params, identity, state) {
|
|
124
128
|
if (state.project === undefined)
|
|
125
129
|
return failure("not_dreaming", NOT_DREAMING);
|
|
@@ -135,11 +139,10 @@ export const dreamForget = {
|
|
|
135
139
|
render: (result) => renderOutcome(result, data => `forgot ${data.address}`),
|
|
136
140
|
};
|
|
137
141
|
export const dreamEndParameters = Type.Object({}, { additionalProperties: false });
|
|
138
|
-
export const DreamEndDataSchema = Type.Object({ project: Type.String(), commit: Type.Optional(Type.String()), audit_error: Type.Optional(Type.String()) }, { additionalProperties: false });
|
|
139
142
|
export const dreamEnd = {
|
|
140
143
|
name: "dream_end", label: "Dream end",
|
|
141
|
-
description: "
|
|
142
|
-
parameters: dreamEndParameters,
|
|
144
|
+
description: "Commit dream changes to the notes Git repo and close the open dream.",
|
|
145
|
+
parameters: dreamEndParameters,
|
|
143
146
|
async execute(_params, identity, state) {
|
|
144
147
|
const project = state.project;
|
|
145
148
|
if (project === undefined)
|
|
@@ -1,41 +1,48 @@
|
|
|
1
|
-
/** Host-neutral history operations:
|
|
1
|
+
/** Host-neutral history operations: bounded plain-text output. */
|
|
2
2
|
import { Type, type Static } from "typebox";
|
|
3
|
-
import { type Operation } from "./result.js";
|
|
3
|
+
import { type TextWindow, type Operation } from "./result.js";
|
|
4
4
|
import { type HistoryPage } from "../history/query.js";
|
|
5
5
|
import { type HistoryContext } from "../history/corpus.js";
|
|
6
|
+
import { type HistoryRole, type NestedCallSummary, type ToolSummary } from "../history/history.js";
|
|
6
7
|
/** One read: identity, tool summary and a flat document slice. */
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
session
|
|
20
|
-
|
|
21
|
-
seq: Type.TInteger;
|
|
22
|
-
role: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>;
|
|
23
|
-
created_at: Type.TUnion<[Type.TString, Type.TNull]>;
|
|
24
|
-
}>;
|
|
25
|
-
type HistoryReadData = Static<typeof HistoryReadDataSchema>;
|
|
8
|
+
type HistoryReadData = ToolSummary & TextWindow & {
|
|
9
|
+
session?: string;
|
|
10
|
+
notice?: string;
|
|
11
|
+
seq: number;
|
|
12
|
+
role: HistoryRole;
|
|
13
|
+
created_at: string | null;
|
|
14
|
+
nested_calls?: NestedCallSummary;
|
|
15
|
+
};
|
|
16
|
+
type TimelinePage = HistoryPage & {
|
|
17
|
+
paging: Omit<Static<typeof historyListParameters>, "after" | "before">;
|
|
18
|
+
};
|
|
19
|
+
type SearchPage = HistoryPage & {
|
|
20
|
+
session?: string;
|
|
21
|
+
};
|
|
26
22
|
/** Pure host decoration, measured during selection and applied unchanged by the caller at delivery. */
|
|
27
23
|
export type HistoryTextWrapper = (text: string) => string;
|
|
28
24
|
export declare const historyListParameters: Type.TObject<{
|
|
29
25
|
session: Type.TOptional<Type.TString>;
|
|
30
|
-
roles: Type.TOptional<Type.TArray<Type.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
roles: Type.TOptional<Type.TArray<Type.TUnsafe<"user" | "assistant" | "tool" | "context">>>;
|
|
27
|
+
after: Type.TOptional<Type.TInteger>;
|
|
28
|
+
before: Type.TOptional<Type.TInteger>;
|
|
29
|
+
since: Type.TOptional<Type.TString>;
|
|
30
|
+
until: Type.TOptional<Type.TString>;
|
|
31
|
+
limit: Type.TOptional<Type.TInteger>;
|
|
32
|
+
max_chars_per_item: Type.TOptional<Type.TInteger>;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const historyList: Operation<typeof historyListParameters, TimelinePage | SearchPage, [HistoryContext, HistoryTextWrapper?]>;
|
|
35
|
+
export declare const historySearchParameters: Type.TObject<{
|
|
36
|
+
session: Type.TOptional<Type.TString>;
|
|
37
|
+
query: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>;
|
|
38
|
+
since: Type.TOptional<Type.TString>;
|
|
39
|
+
until: Type.TOptional<Type.TString>;
|
|
40
|
+
roles: Type.TOptional<Type.TArray<Type.TUnsafe<"user" | "assistant" | "tool" | "context">>>;
|
|
34
41
|
context: Type.TOptional<Type.TInteger>;
|
|
35
42
|
limit: Type.TOptional<Type.TInteger>;
|
|
36
43
|
max_chars_per_item: Type.TOptional<Type.TInteger>;
|
|
37
44
|
}>;
|
|
38
|
-
export declare const
|
|
45
|
+
export declare const historySearch: Operation<typeof historySearchParameters, SearchPage, [HistoryContext, HistoryTextWrapper?]>;
|
|
39
46
|
export declare const historyReadParameters: Type.TObject<{
|
|
40
47
|
offset_chars: Type.TOptional<Type.TInteger>;
|
|
41
48
|
max_chars: Type.TOptional<Type.TInteger>;
|