notesoup 0.51.9 → 0.52.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -10
- package/dist/plugins/claude/src/history.js +9 -12
- package/dist/plugins/pi/notes/tools.d.ts +1 -1
- package/dist/plugins/pi/notes/tools.js +26 -7
- package/dist/plugins/pi/tool-result.d.ts +3 -2
- package/dist/plugins/pi/tool-result.js +3 -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/history/query.js +2 -1
- 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/history.js +1 -1
- package/dist/src/tools/notes.d.ts +15 -1
- package/dist/src/tools/notes.js +4 -4
- package/dist/test/claude-history.test.js +49 -2
- package/dist/test/claude-mod.test.js +136 -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/docs/claude-code-mod.md +2 -2
- package/docs/notes-library.md +1 -1
- package/docs/skills.md +12 -15
- package/package.json +2 -5
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +36 -29
- package/plugins/claude/hooks/register.ts +71 -47
- package/plugins/claude/src/history.ts +9 -11
- package/plugins/pi/notes/tools.ts +25 -8
- package/plugins/pi/tool-result.ts +4 -1
- package/src/dream/git.ts +3 -8
- package/src/dream/lock.ts +18 -66
- package/src/history/query.ts +2 -1
- 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/history.ts +1 -1
- 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.d.ts +0 -1
- 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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** Dream operations: open one project's notes for consolidation, delete crumpled notes, close. */
|
|
2
|
+
import { Type, type Static } from "typebox";
|
|
3
|
+
import { type NotesIdentity } from "../notes/index.js";
|
|
4
|
+
import { type DreamLock } from "../dream/lock.js";
|
|
5
|
+
import { type Outcome } from "./result.js";
|
|
6
|
+
/** The one open dream per session; the host owns where it lives. */
|
|
7
|
+
export type DreamState = {
|
|
8
|
+
project?: string;
|
|
9
|
+
lock?: DreamLock;
|
|
10
|
+
};
|
|
11
|
+
/** Drop an open dream without an end commit, e.g. when its session shuts down. */
|
|
12
|
+
export declare function abandonDream(state: DreamState): void;
|
|
13
|
+
/** The identity a store uses while `state` holds an open dream. */
|
|
14
|
+
export declare function dreamingIdentity(identity: NotesIdentity, state: DreamState): NotesIdentity;
|
|
15
|
+
export declare const dreamBeginParameters: Type.TObject<{
|
|
16
|
+
project: Type.TOptional<Type.TString>;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const DreamBeginDataSchema: Type.TObject<{
|
|
19
|
+
more: Type.TInteger;
|
|
20
|
+
homes_unavailable: Type.TArray<Type.TString>;
|
|
21
|
+
files: Type.TArray<Type.TObject<{
|
|
22
|
+
updated_at: Type.TString;
|
|
23
|
+
crumpled_at: Type.TOptional<Type.TString>;
|
|
24
|
+
project_root: Type.TOptional<Type.TString>;
|
|
25
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
26
|
+
name: Type.TString;
|
|
27
|
+
path: Type.TString;
|
|
28
|
+
}>>>;
|
|
29
|
+
address: Type.TString;
|
|
30
|
+
project_key: Type.TOptional<Type.TString>;
|
|
31
|
+
}>>;
|
|
32
|
+
project: Type.TString;
|
|
33
|
+
baseline: Type.TString;
|
|
34
|
+
}>;
|
|
35
|
+
export type DreamBeginData = Static<typeof DreamBeginDataSchema>;
|
|
36
|
+
export declare const dreamBegin: {
|
|
37
|
+
readonly name: "dream_begin";
|
|
38
|
+
readonly label: "Dream begin";
|
|
39
|
+
readonly description: "Dream: open one project's notes for consolidation, one project at a time. Lists its @projects/<name>/ notes and every session note born in it, crumpled ones included. Until dream_end, notes_write/notes_update can edit those addresses and reads leave no access stamp. Takes the project's dream lock and commits a Git baseline of the notes home.";
|
|
40
|
+
readonly parameters: Type.TObject<{
|
|
41
|
+
project: Type.TOptional<Type.TString>;
|
|
42
|
+
}>;
|
|
43
|
+
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
44
|
+
more: Type.TInteger;
|
|
45
|
+
homes_unavailable: Type.TArray<Type.TString>;
|
|
46
|
+
files: Type.TArray<Type.TObject<{
|
|
47
|
+
updated_at: Type.TString;
|
|
48
|
+
crumpled_at: Type.TOptional<Type.TString>;
|
|
49
|
+
project_root: Type.TOptional<Type.TString>;
|
|
50
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
51
|
+
name: Type.TString;
|
|
52
|
+
path: Type.TString;
|
|
53
|
+
}>>>;
|
|
54
|
+
address: Type.TString;
|
|
55
|
+
project_key: Type.TOptional<Type.TString>;
|
|
56
|
+
}>>;
|
|
57
|
+
project: Type.TString;
|
|
58
|
+
baseline: Type.TString;
|
|
59
|
+
}>, Type.TObject<{
|
|
60
|
+
error: Type.TString;
|
|
61
|
+
code: Type.TString;
|
|
62
|
+
}>]>;
|
|
63
|
+
readonly execute: (params: Static<typeof dreamBeginParameters>, identity: NotesIdentity, state: DreamState) => Promise<Outcome<DreamBeginData>>;
|
|
64
|
+
readonly render: (result: Outcome<DreamBeginData>) => string;
|
|
65
|
+
};
|
|
66
|
+
export declare const dreamForgetParameters: Type.TObject<{
|
|
67
|
+
address: Type.TString;
|
|
68
|
+
}>;
|
|
69
|
+
export declare const DreamForgetDataSchema: Type.TObject<{
|
|
70
|
+
address: Type.TString;
|
|
71
|
+
project_key: Type.TOptional<Type.TString>;
|
|
72
|
+
}>;
|
|
73
|
+
export type DreamForgetData = Static<typeof DreamForgetDataSchema>;
|
|
74
|
+
export declare const dreamForget: {
|
|
75
|
+
readonly name: "dream_forget";
|
|
76
|
+
readonly label: "Dream forget";
|
|
77
|
+
readonly description: "Dream: permanently delete one crumpled note in the project being dreamed over, or in @human/, @self/, @model/. Crumple it first; live notes refuse.";
|
|
78
|
+
readonly parameters: Type.TObject<{
|
|
79
|
+
address: Type.TString;
|
|
80
|
+
}>;
|
|
81
|
+
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
82
|
+
address: Type.TString;
|
|
83
|
+
project_key: Type.TOptional<Type.TString>;
|
|
84
|
+
}>, Type.TObject<{
|
|
85
|
+
error: Type.TString;
|
|
86
|
+
code: Type.TString;
|
|
87
|
+
}>]>;
|
|
88
|
+
readonly execute: (params: Static<typeof dreamForgetParameters>, identity: NotesIdentity, state: DreamState) => Promise<Outcome<DreamForgetData>>;
|
|
89
|
+
readonly render: (result: Outcome<DreamForgetData>) => string;
|
|
90
|
+
};
|
|
91
|
+
export declare const dreamEndParameters: Type.TObject<{}>;
|
|
92
|
+
export declare const DreamEndDataSchema: Type.TObject<{
|
|
93
|
+
project: Type.TString;
|
|
94
|
+
commit: Type.TOptional<Type.TString>;
|
|
95
|
+
audit_error: Type.TOptional<Type.TString>;
|
|
96
|
+
}>;
|
|
97
|
+
export type DreamEndData = Static<typeof DreamEndDataSchema>;
|
|
98
|
+
export declare const dreamEnd: {
|
|
99
|
+
readonly name: "dream_end";
|
|
100
|
+
readonly label: "Dream end";
|
|
101
|
+
readonly description: "Dream: close the open dream. Commits the dream's changes to the notes home's Git and releases the lock; the project's notes are read-only again and reads stamp access again.";
|
|
102
|
+
readonly parameters: Type.TObject<{}>;
|
|
103
|
+
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
104
|
+
project: Type.TString;
|
|
105
|
+
commit: Type.TOptional<Type.TString>;
|
|
106
|
+
audit_error: Type.TOptional<Type.TString>;
|
|
107
|
+
}>, Type.TObject<{
|
|
108
|
+
error: Type.TString;
|
|
109
|
+
code: Type.TString;
|
|
110
|
+
}>]>;
|
|
111
|
+
readonly execute: (_params: Static<typeof dreamEndParameters>, identity: NotesIdentity, state: DreamState) => Promise<Outcome<DreamEndData>>;
|
|
112
|
+
readonly render: (result: Outcome<DreamEndData>) => string;
|
|
113
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/** Dream operations: open one project's notes for consolidation, delete crumpled notes, close. */
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { createNotesStore, noteIdentity } from "../notes/index.js";
|
|
4
|
+
import { projectHomes } from "../notes/project-home.js";
|
|
5
|
+
import { gitCommit } from "../dream/git.js";
|
|
6
|
+
import { acquireDreamLock, dreamLockPath, releaseDreamLock } from "../dream/lock.js";
|
|
7
|
+
import { failure, renderOutcome, resultSchema, success } from "./result.js";
|
|
8
|
+
import { failureOf, listedFile, NotesListDataSchema, renderListData, snapshot } from "./notes.js";
|
|
9
|
+
/** Drop an open dream without an end commit, e.g. when its session shuts down. */
|
|
10
|
+
export function abandonDream(state) {
|
|
11
|
+
if (state.lock)
|
|
12
|
+
releaseDreamLock(state.lock);
|
|
13
|
+
delete state.project;
|
|
14
|
+
delete state.lock;
|
|
15
|
+
}
|
|
16
|
+
/** The identity a store uses while `state` holds an open dream. */
|
|
17
|
+
export function dreamingIdentity(identity, state) {
|
|
18
|
+
return state.project === undefined ? identity : { ...identity, dreaming: state.project };
|
|
19
|
+
}
|
|
20
|
+
const NOT_DREAMING = "No dream is open; call dream_begin first.";
|
|
21
|
+
export const dreamBeginParameters = Type.Object({
|
|
22
|
+
project: Type.Optional(Type.String({ description: "(optional, default this project) Project name, as in @projects/<name>/." })),
|
|
23
|
+
}, { additionalProperties: false });
|
|
24
|
+
export const DreamBeginDataSchema = Type.Object({ project: Type.String(), baseline: Type.String(), ...NotesListDataSchema.properties }, { additionalProperties: false });
|
|
25
|
+
function renderBeginData(data) {
|
|
26
|
+
return `dreaming over ${data.project} (baseline ${data.baseline})\n${renderListData(data)}`;
|
|
27
|
+
}
|
|
28
|
+
export const dreamBegin = {
|
|
29
|
+
name: "dream_begin", label: "Dream begin",
|
|
30
|
+
description: "Dream: open one project's notes for consolidation, one project at a time. Lists its @projects/<name>/ notes and every session note born in it, crumpled ones included. Until dream_end, notes_write/notes_update can edit those addresses and reads leave no access stamp. Takes the project's dream lock and commits a Git baseline of the notes home.",
|
|
31
|
+
parameters: dreamBeginParameters, outputSchema: resultSchema(DreamBeginDataSchema),
|
|
32
|
+
async execute(params, identity, state) {
|
|
33
|
+
if (state.project !== undefined)
|
|
34
|
+
return failure("already_dreaming", `Already dreaming over ${state.project}; call dream_end before opening another project.`);
|
|
35
|
+
const project = params.project ?? identity.projectKey;
|
|
36
|
+
if (project !== identity.projectKey && !projectHomes(identity.home).some(home => home.name === project)) {
|
|
37
|
+
return failure("not_found", `No project named ${JSON.stringify(project)}; notes_list with glob @projects/*/** shows the names.`);
|
|
38
|
+
}
|
|
39
|
+
const lock = acquireDreamLock(dreamLockPath(identity.home, project));
|
|
40
|
+
if (!lock)
|
|
41
|
+
return failure("already_dreaming", `Another dream holds ${dreamLockPath(identity.home, project)}. If none is running, delete that file by hand.`);
|
|
42
|
+
try {
|
|
43
|
+
const store = createNotesStore({ ...identity, dreaming: project });
|
|
44
|
+
const rows = [];
|
|
45
|
+
const unavailable = [];
|
|
46
|
+
for (const crumpled of [false, true]) {
|
|
47
|
+
for (const glob of [`@projects/${project}/**`, "@sessions/*/**"]) {
|
|
48
|
+
const result = await store.listWithStatus({ glob, crumpled });
|
|
49
|
+
rows.push(...result.rows.filter(row => row.scope === "project" || row.meta.project === project));
|
|
50
|
+
unavailable.push(...result.status.homesUnavailable);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address));
|
|
54
|
+
const listed = snapshot(rows.map(row => listedFile(row, identity)), undefined, { homesUnavailable: unavailable }, renderListData);
|
|
55
|
+
if (!listed.ok) {
|
|
56
|
+
releaseDreamLock(lock);
|
|
57
|
+
return listed;
|
|
58
|
+
}
|
|
59
|
+
const baseline = gitCommit(identity.home, `dream baseline ${project}`);
|
|
60
|
+
if (!baseline.ok) {
|
|
61
|
+
releaseDreamLock(lock);
|
|
62
|
+
return failure("audit_failed", `Couldn't commit the Git baseline, so nothing could be rolled back; no dream was opened: ${baseline.error}`);
|
|
63
|
+
}
|
|
64
|
+
Object.assign(state, { project, lock });
|
|
65
|
+
return success({ project, baseline: baseline.commit, ...listed.data });
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
releaseDreamLock(lock);
|
|
69
|
+
return failureOf(error);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
render: (result) => renderOutcome(result, renderBeginData),
|
|
73
|
+
};
|
|
74
|
+
export const dreamForgetParameters = Type.Object({ address: Type.String() }, { additionalProperties: false });
|
|
75
|
+
export const DreamForgetDataSchema = Type.Object({ address: Type.String(), project_key: Type.Optional(Type.String()) }, { additionalProperties: false });
|
|
76
|
+
export const dreamForget = {
|
|
77
|
+
name: "dream_forget", label: "Dream forget",
|
|
78
|
+
description: "Dream: permanently delete one crumpled note in the project being dreamed over, or in @human/, @self/, @model/. Crumple it first; live notes refuse.",
|
|
79
|
+
parameters: dreamForgetParameters, outputSchema: resultSchema(DreamForgetDataSchema),
|
|
80
|
+
async execute(params, identity, state) {
|
|
81
|
+
if (state.project === undefined)
|
|
82
|
+
return failure("not_dreaming", NOT_DREAMING);
|
|
83
|
+
try {
|
|
84
|
+
const dreaming = dreamingIdentity(identity, state);
|
|
85
|
+
await createNotesStore(dreaming).forget(params.address);
|
|
86
|
+
return success(noteIdentity(dreaming, params.address));
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return failureOf(error);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
render: (result) => renderOutcome(result, data => `forgot ${data.address}`),
|
|
93
|
+
};
|
|
94
|
+
export const dreamEndParameters = Type.Object({}, { additionalProperties: false });
|
|
95
|
+
export const DreamEndDataSchema = Type.Object({ project: Type.String(), commit: Type.Optional(Type.String()), audit_error: Type.Optional(Type.String()) }, { additionalProperties: false });
|
|
96
|
+
export const dreamEnd = {
|
|
97
|
+
name: "dream_end", label: "Dream end",
|
|
98
|
+
description: "Dream: close the open dream. Commits the dream's changes to the notes home's Git and releases the lock; the project's notes are read-only again and reads stamp access again.",
|
|
99
|
+
parameters: dreamEndParameters, outputSchema: resultSchema(DreamEndDataSchema),
|
|
100
|
+
async execute(_params, identity, state) {
|
|
101
|
+
const project = state.project;
|
|
102
|
+
if (project === undefined)
|
|
103
|
+
return failure("not_dreaming", NOT_DREAMING);
|
|
104
|
+
// The dream closes even when the audit commit fails; the uncommitted changes stay in the work tree.
|
|
105
|
+
const audit = gitCommit(identity.home, `dream ${project}`);
|
|
106
|
+
abandonDream(state);
|
|
107
|
+
return success(audit.ok ? { project, commit: audit.commit } : { project, audit_error: audit.error });
|
|
108
|
+
},
|
|
109
|
+
render: (result) => renderOutcome(result, data => data.commit !== undefined
|
|
110
|
+
? `woke from ${data.project} (commit ${data.commit})`
|
|
111
|
+
: `woke from ${data.project}; the Git commit failed, changes are uncommitted: ${data.audit_error}`),
|
|
112
|
+
};
|
|
@@ -68,7 +68,7 @@ function renderRead(data) {
|
|
|
68
68
|
const tool = toolHeader(data);
|
|
69
69
|
const afterSeq = data.seq - 10;
|
|
70
70
|
const neighborhood = `neighborhood → \`history_list\`(${JSON.stringify({ ...(afterSeq >= 1 ? { after_seq: afterSeq } : {}), before_seq: data.seq + 10 })})`;
|
|
71
|
-
return [header(data), ...(tool ? [tool] : []), neighborhood, "", renderTextWindow(data)].join("\n");
|
|
71
|
+
return [header(data), ...(tool ? [tool] : []), neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
|
|
72
72
|
}
|
|
73
73
|
/* ------------------------------------------------------------------ shared bounding */
|
|
74
74
|
/** Include rendering and cursors in the budget, not just row contents. */
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { NotesIdentity } from "../notes/identity.js";
|
|
2
2
|
import { Type, type Static } from "typebox";
|
|
3
|
-
import { type NoteChange } from "../notes/index.js";
|
|
3
|
+
import { type NoteChange, type NoteQueryStatus, type NoteRow } from "../notes/index.js";
|
|
4
4
|
import { type Outcome } from "./result.js";
|
|
5
|
+
/**
|
|
6
|
+
* Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
|
|
7
|
+
* Convert expected refusals; unexpected errors propagate unchanged.
|
|
8
|
+
*/
|
|
9
|
+
export declare function failureOf(error: unknown): Outcome<never>;
|
|
5
10
|
export declare const NoteMetadataSchema: Type.TObject<{
|
|
6
11
|
origin: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>;
|
|
7
12
|
created_at: Type.TString;
|
|
@@ -83,6 +88,14 @@ export declare const NotesSearchDataSchema: Type.TObject<{
|
|
|
83
88
|
}>>;
|
|
84
89
|
}>;
|
|
85
90
|
export type NotesSearchData = Static<typeof NotesSearchDataSchema>;
|
|
91
|
+
type Snapshot<T> = Omit<NotesListData, "files"> & {
|
|
92
|
+
files: T[];
|
|
93
|
+
};
|
|
94
|
+
/** Keep identities intact. Only search previews may shrink to make the first row fit. */
|
|
95
|
+
export declare function snapshot<T extends {
|
|
96
|
+
address: string;
|
|
97
|
+
}>(rows: T[], limit: number | undefined, status: NoteQueryStatus, renderData: (data: Snapshot<T>) => string, shrink?: (item: T, fits: (candidate: T) => boolean) => T): Outcome<Snapshot<T>>;
|
|
98
|
+
export declare function listedFile(row: Pick<NoteRow, "address" | "meta">, identity: NotesIdentity): NotesListData["files"][number];
|
|
86
99
|
export declare const notesWriteParameters: Type.TObject<{
|
|
87
100
|
address: Type.TString;
|
|
88
101
|
content: Type.TString;
|
|
@@ -197,6 +210,7 @@ export declare const notesListParameters: Type.TObject<{
|
|
|
197
210
|
limit: Type.TOptional<Type.TInteger>;
|
|
198
211
|
crumpled: Type.TOptional<Type.TBoolean>;
|
|
199
212
|
}>;
|
|
213
|
+
export declare function renderListData(data: NotesListData): string;
|
|
200
214
|
export declare const notesList: {
|
|
201
215
|
readonly name: "notes_list";
|
|
202
216
|
readonly label: "Notes list";
|
package/dist/src/tools/notes.js
CHANGED
|
@@ -19,7 +19,7 @@ const ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@pr
|
|
|
19
19
|
* Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
|
|
20
20
|
* Convert expected refusals; unexpected errors propagate unchanged.
|
|
21
21
|
*/
|
|
22
|
-
function failureOf(error) {
|
|
22
|
+
export function failureOf(error) {
|
|
23
23
|
if (error instanceof NoteError)
|
|
24
24
|
return failure(error.code, error.message);
|
|
25
25
|
// Address, glob, and query guards raise declared types; nothing else is converted.
|
|
@@ -150,7 +150,7 @@ export const NotesSearchDataSchema = Type.Object({
|
|
|
150
150
|
...SnapshotSchema,
|
|
151
151
|
}, { additionalProperties: false });
|
|
152
152
|
/** Keep identities intact. Only search previews may shrink to make the first row fit. */
|
|
153
|
-
function snapshot(rows, limit, status, renderData, shrink) {
|
|
153
|
+
export function snapshot(rows, limit, status, renderData, shrink) {
|
|
154
154
|
const files = [];
|
|
155
155
|
const data = (selected) => ({ files: selected, more: rows.length - selected.length, homes_unavailable: status.homesUnavailable });
|
|
156
156
|
const render = (outcome) => renderOutcome(outcome, renderData);
|
|
@@ -172,7 +172,7 @@ function snapshot(rows, limit, status, renderData, shrink) {
|
|
|
172
172
|
const outcome = success(data(files));
|
|
173
173
|
return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable homes is itself over ${TOOL_OUTPUT_LIMIT}; narrow \`glob\` to fewer homes.`);
|
|
174
174
|
}
|
|
175
|
-
function listedFile(row, identity) {
|
|
175
|
+
export function listedFile(row, identity) {
|
|
176
176
|
return { ...noteIdentity(identity, row.address), updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
|
|
177
177
|
}
|
|
178
178
|
export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN }, { additionalProperties: false });
|
|
@@ -275,7 +275,7 @@ export const notesRead = {
|
|
|
275
275
|
render: (result) => renderOutcome(result, renderReadData),
|
|
276
276
|
};
|
|
277
277
|
export const notesListParameters = Type.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
|
|
278
|
-
function renderListData(data) {
|
|
278
|
+
export function renderListData(data) {
|
|
279
279
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
280
280
|
for (const file of data.files) {
|
|
281
281
|
lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at}${file.crumpled_at === undefined ? "" : ` | crumpled ${file.crumpled_at}`}`);
|
|
@@ -52,6 +52,44 @@ test("Claude append and result arrival preserve call addresses and use the share
|
|
|
52
52
|
assert.ok(search.ok);
|
|
53
53
|
assert.deepEqual(search.data.items.map((item) => "seq" in item ? item.seq : -1), [3]);
|
|
54
54
|
});
|
|
55
|
+
test("Claude dialogue paging skips tool/thinking envelopes without losing array text or changing addresses", async () => {
|
|
56
|
+
const rows = [row("u", null, "user", [{ type: "text", text: "human question" }]),
|
|
57
|
+
assistant("reply", "u", [{ type: "text", text: "assistant answer" }]),
|
|
58
|
+
assistant("thinking", "reply", [{ type: "thinking", thinking: "private thought" }]),
|
|
59
|
+
assistant("call", "thinking", [call("one")]), row("result", "call", "user", [result("one", "tool output")]),
|
|
60
|
+
row("last", "result", "user", [{ type: "text", text: "human followup" }]),
|
|
61
|
+
compact("boundary", "last"), row("boot", "boundary", "user", bootText(1))];
|
|
62
|
+
const projection = project(rows, "boot");
|
|
63
|
+
assert.equal(projection.highestSeq, 10);
|
|
64
|
+
const listed = await historyList.execute({ window_id: "@previous", roles: ["user", "assistant"], limit: 3 }, projection);
|
|
65
|
+
assert.ok(listed.ok);
|
|
66
|
+
assert.deepEqual(listed.data.items.map((item) => "seq" in item ? [item.seq, item.content] : []), [[1, "human question"], [2, "assistant answer"], [8, "human followup"]]);
|
|
67
|
+
const read = await historyRead.execute({ seq: 2 }, projection);
|
|
68
|
+
assert.ok(read.ok);
|
|
69
|
+
assert.equal(read.data.text, "assistant answer");
|
|
70
|
+
const envelope = await historyRead.execute({ seq: 6 }, projection);
|
|
71
|
+
assert.ok(envelope.ok);
|
|
72
|
+
assert.equal(envelope.data.text, "", "a tool-result envelope has no dialogue text to invent");
|
|
73
|
+
assert.match(historyRead.render(envelope), /No visible text recorded/);
|
|
74
|
+
const tool = await historyRead.execute({ seq: 5 }, projection);
|
|
75
|
+
assert.ok(tool.ok);
|
|
76
|
+
assert.match(tool.data.text, /tool output/);
|
|
77
|
+
assert.doesNotMatch(historyList.render(listed), /private thought|tool output/);
|
|
78
|
+
});
|
|
79
|
+
test("Claude file-history deltas do not become events or change history addresses", () => {
|
|
80
|
+
const rows = [user("u", null, "hello"), assistant("a", "u", [{ type: "text", text: "reply" }])];
|
|
81
|
+
const delta = { type: "file-history-delta", messageId: "u", snapshotMessageId: "u", trackingPath: "private-file.txt",
|
|
82
|
+
backup: { backupFileName: "private-backup", version: 1, backupTime: "2026-01-01T00:00:00Z", realParentDir: "/private" }, timestamp: "2026-01-01T00:00:00Z" };
|
|
83
|
+
const baseline = project(rows, "a");
|
|
84
|
+
assert.deepEqual(project([delta, rows[0], delta, rows[1], delta], "a"), baseline);
|
|
85
|
+
assert.equal(baseline.highestSeq, 2);
|
|
86
|
+
});
|
|
87
|
+
test("Claude skips unknown record types unless selected ancestry requires them", () => {
|
|
88
|
+
const u = user("u", null, "hello"), a = assistant("a", "u", [{ type: "text", text: "reply" }]);
|
|
89
|
+
const unknown = { type: "future-record", uuid: "future", parentUuid: "not-on-disk", content: "private metadata" };
|
|
90
|
+
assert.deepEqual(project([unknown, u, unknown, a, unknown], "a"), project([u, a], "a"));
|
|
91
|
+
assert.throws(() => project([u, unknown, { ...a, parentUuid: "future" }], "a"), /missing Claude transcript ancestor: future/);
|
|
92
|
+
});
|
|
55
93
|
test("Claude duplicate UUID records do not allocate again or move addresses on reload", () => {
|
|
56
94
|
const u = user("u", null, "hello"), a = assistant("a", "u", [call("one")]);
|
|
57
95
|
const original = project([u, a], "a");
|
|
@@ -93,6 +131,13 @@ test("a persisted boot yields its ordinal under both tag spellings", () => {
|
|
|
93
131
|
const partial = `<notesoup:window_identity>\nAgent name: claude (brain: claude)\n\nclaude:${sessionId}\n</notesoup:window_identity>\nCurrent context window id: claude:${sessionId}:3`;
|
|
94
132
|
assert.equal(allItems(project(rowsFor(partial), "after")).find((event) => event.text === "after reset")?.windowId, `claude:${sessionId}:1`, "an identity line without the protocol block is not a trusted boot");
|
|
95
133
|
});
|
|
134
|
+
test("Claude forked transcripts retain copied boot ordinals but use the new session's window ids", () => {
|
|
135
|
+
const rows = [user("u", null, "old request"), compact("boundary", "u"), row("boot", "boundary", "user", bootText(3)), user("after", "boot", "after fork")];
|
|
136
|
+
const forkId = "forked-session";
|
|
137
|
+
const projection = claudeHistoryFromJsonl(jsonl(rows.map((row) => ({ ...row, sessionId: forkId }))), { sessionId: forkId, headUuid: "after" });
|
|
138
|
+
assert.equal(allItems(projection).find((event) => event.text === "after fork")?.windowId, `claude:${forkId}:3`);
|
|
139
|
+
assert.ok(projection.windows.every((window) => window.windowId.startsWith(`claude:${forkId}:`)));
|
|
140
|
+
});
|
|
96
141
|
test("Claude native compaction and reset keep pre-reset history, preserved rewrites and matching boot windows", async () => {
|
|
97
142
|
const old = assistant("old", "u", [{ type: "text", text: "before first reset" }]);
|
|
98
143
|
const reset = row("boot", "boundary", "user", bootText(1));
|
|
@@ -154,7 +199,6 @@ test("Claude tolerates only the uncommitted JSONL tail, not malformed committed
|
|
|
154
199
|
assert.deepEqual(claudeHistoryFromJsonl(`${text}{\"type\":\"user\"`, { sessionId, headUuid: "u" }), project([user("u", null, "first")], "u"));
|
|
155
200
|
assert.equal(claudeHistoryFromJsonl(text.trimEnd(), { sessionId, headUuid: "u" }).highestSeq, 1);
|
|
156
201
|
assert.throws(() => claudeHistoryFromJsonl(`${text}{broken}\n`, { sessionId, headUuid: "u" }), /malformed.*line 2/);
|
|
157
|
-
assert.throws(() => project([user("u", null, "first"), { type: "new-message-schema", uuid: "unknown" }], "u"), /unsupported.*record type/);
|
|
158
202
|
assert.throws(() => project([row("u", null, "user", [{ type: "new-block-schema" }])], "u"), /unsupported.*content block/);
|
|
159
203
|
assert.throws(() => project([row("u", null, "user", { type: "text", text: "not an array" })], "u"), /message content/);
|
|
160
204
|
assert.throws(() => project([user("u", null, "first"), user("u", null, "conflict")], "u"), /conflicting.*duplicate UUID/);
|
|
@@ -165,7 +209,10 @@ test("Claude helper history tools reuse shared schemas, outcomes and text render
|
|
|
165
209
|
const root = mkdtempSync(join(tmpdir(), "claude-history-"));
|
|
166
210
|
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
167
211
|
const transcriptPath = join(root, "transcript.jsonl"), rows = [user("u", null, "remember this"), assistant("a", "u", [call("one")]), row("r", "a", "user", [result("one", "recorded output")])];
|
|
168
|
-
writeFileSync(transcriptPath, jsonl(rows
|
|
212
|
+
writeFileSync(transcriptPath, jsonl([...rows,
|
|
213
|
+
{ type: "file-history-delta", messageId: "r", snapshotMessageId: "u", trackingPath: "file.txt", backup: null, timestamp: "2026-01-01T00:00:00Z" },
|
|
214
|
+
{ type: "future-record", content: "private metadata" },
|
|
215
|
+
]));
|
|
169
216
|
const identity = { home: join(root, "notes"), sessionId, cwd: root, agent: "claude", model: "claude" };
|
|
170
217
|
const history = { sessionId, transcriptPath, headUuid: "r" };
|
|
171
218
|
const projection = await readClaudeHistory(history);
|
|
@@ -36,7 +36,13 @@ async function loadHookModule(t) {
|
|
|
36
36
|
t.after(() => rmSync(loaded, { recursive: true, force: true }));
|
|
37
37
|
const module = join(loaded, "register.mjs");
|
|
38
38
|
writeFileSync(module, transpiled.outputFiles[0].text);
|
|
39
|
-
|
|
39
|
+
const hooks = await import(pathToFileURL(module).href);
|
|
40
|
+
return { register: (on) => hooks.register((event, matcherOrHandler, handler) => {
|
|
41
|
+
if (typeof matcherOrHandler === "function")
|
|
42
|
+
on(event, matcherOrHandler);
|
|
43
|
+
else
|
|
44
|
+
on(event, ($, e, next) => Object.entries(matcherOrHandler).every(([key, value]) => e[key] === value) ? handler($, e, next) : next(e));
|
|
45
|
+
}) };
|
|
40
46
|
}
|
|
41
47
|
/** An engine that answers the hook by running the real helper against a throwaway notes home. */
|
|
42
48
|
function fakeEngine(home) {
|
|
@@ -301,6 +307,27 @@ test("Claude Mod appends boot once and reuses persisted blocks after re-registra
|
|
|
301
307
|
assert.equal(nextCalls, 2, "the upstream chain still runs exactly once per prompt");
|
|
302
308
|
assert.deepEqual(notifications, [], "successful boot never notifies");
|
|
303
309
|
});
|
|
310
|
+
test("Claude fork replaces a copied boot with the current identity without resetting the window ordinal", async (t) => {
|
|
311
|
+
const home = mkdtempSync(join(tmpdir(), "claude-fork-boot-"));
|
|
312
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
313
|
+
const { host } = fakeEngine(home);
|
|
314
|
+
const copied = "<notesoup:window_identity>\nAgent name: claude (brain: claude)\n\nclaude:parent-session\n</notesoup:window_identity>\n\n<notesoup:notes_protocol>\nParent protocol\n</notesoup:notes_protocol>\nCurrent context window id: claude:parent-session:3";
|
|
315
|
+
host.session.messages = async () => [{ role: "user", text: copied }];
|
|
316
|
+
const handlers = new Map();
|
|
317
|
+
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
318
|
+
const invoke = (name, event = {}, result = {}) => handlers.get(name)(host, event, async () => result);
|
|
319
|
+
await invoke("session.start", { cwd: home, isInteractive: true });
|
|
320
|
+
const upstream = { blocks: [{ name: "other", text: "keep me" }, { name: "notesoup:boot", text: copied }], sentinel: "kept" };
|
|
321
|
+
const current = await invoke("prompt.context", {}, upstream);
|
|
322
|
+
assert.equal(current.sentinel, "kept");
|
|
323
|
+
assert.deepEqual(current.blocks[0], upstream.blocks[0]);
|
|
324
|
+
assert.equal(current.blocks.length, 2, "replace the copied context block rather than adding another");
|
|
325
|
+
assert.match(current.blocks[1].text, /Current context window id: claude:hook-session:3/);
|
|
326
|
+
assert.doesNotMatch(current.blocks[1].text, /claude:parent-session/);
|
|
327
|
+
assert.deepEqual(await invoke("prompt.context", {}, current), current, "reuse the now-current block on reload");
|
|
328
|
+
const compacted = await invoke("session.compact", { trigger: "auto", messages: [] });
|
|
329
|
+
assert.match(compacted.messages[0].text, /Current context window id: claude:hook-session:4/);
|
|
330
|
+
});
|
|
304
331
|
test("Claude Mod with NOTESOUP_DISABLED registers nothing and passes every event through", async (t) => {
|
|
305
332
|
const home = mkdtempSync(join(tmpdir(), "claude-hook-disabled-"));
|
|
306
333
|
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
@@ -331,6 +358,43 @@ test("Claude Mod with NOTESOUP_DISABLED registers nothing and passes every event
|
|
|
331
358
|
const measured = await handlers.get("session.measure")(host, {}, async () => ({ marks: true }));
|
|
332
359
|
assert.deepEqual(measured, { marks: true }, "session.measure passes through without a reset");
|
|
333
360
|
assert.equal(helperCalls, 0, "the helper never runs while disabled");
|
|
361
|
+
const event = { text: "continue", context: ["upstream"] };
|
|
362
|
+
assert.equal(await handlers.get("prompt.submit")(host, event, async (e) => e), event);
|
|
363
|
+
const tool = { result: "upstream" };
|
|
364
|
+
assert.equal(await handlers.get("tool.call")(host, { tool: "Read" }, async () => tool), tool);
|
|
365
|
+
assert.equal(helperCalls, 0, "disabled warning routes are transparent too");
|
|
366
|
+
});
|
|
367
|
+
test("Claude Mod omits context_management always and memory unless kept; disabled passes through", async (t) => {
|
|
368
|
+
for (const mode of ["default", "keep", "disabled"]) {
|
|
369
|
+
await t.test(mode, async (t) => {
|
|
370
|
+
const home = mkdtempSync(join(tmpdir(), "claude-context-section-"));
|
|
371
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
372
|
+
const { host } = fakeEngine(home);
|
|
373
|
+
const readEnv = host.env.get;
|
|
374
|
+
host.env.get = async (name) => name === "NOTESOUP_KEEP_MEMORY" ? (mode === "keep" ? " YES " : undefined)
|
|
375
|
+
: name === "NOTESOUP_DISABLED" && mode === "disabled" ? "1" : readEnv(name);
|
|
376
|
+
const handlers = new Map(), sections = [];
|
|
377
|
+
(await loadHookModule(t)).register((event, handler) => event === "prompt.section" ? sections.push(handler) : handlers.set(event, handler));
|
|
378
|
+
await handlers.get("session.start")(host, { cwd: home, isInteractive: true }, async () => ({}));
|
|
379
|
+
for (const name of ["context_management", "memory"]) {
|
|
380
|
+
const event = { name, text: `engine ${name}` };
|
|
381
|
+
const upstream = { text: event.text };
|
|
382
|
+
let calls = 0;
|
|
383
|
+
const next = async (e) => { assert.equal(e, event); calls++; return upstream; };
|
|
384
|
+
// Chain the section hooks as the engine does; each matcher passes other names along.
|
|
385
|
+
const result = await sections.reduceRight((rest, handler) => (e) => handler(host, e, rest), next)(event);
|
|
386
|
+
const kept = mode === "disabled" || (mode === "keep" && name === "memory");
|
|
387
|
+
if (kept) {
|
|
388
|
+
assert.equal(result, upstream);
|
|
389
|
+
assert.equal(calls, 1);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
assert.deepEqual(result, { text: null });
|
|
393
|
+
assert.equal(calls, 0);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
}
|
|
334
398
|
});
|
|
335
399
|
test("Claude Mod boot failure preserves fallback with available, absent, or failing notifications", async (t) => {
|
|
336
400
|
for (const mode of ["available", "no ui", "no toast", "throws", "rejects"]) {
|
|
@@ -500,6 +564,8 @@ test("Claude Mod headless detection skips compaction and logs once", async (t) =
|
|
|
500
564
|
assert.equal(notifications.length, 1);
|
|
501
565
|
const boot = await handlers.get("prompt.context")(host, {}, async () => ({ blocks: [] }));
|
|
502
566
|
assert.match(boot.blocks[0].text, /Current context window id: claude:hook-session:0/);
|
|
567
|
+
const event = { text: "continue" };
|
|
568
|
+
assert.equal(await handlers.get("prompt.submit")(host, event, async (e) => e), event, "headless prompts never warn");
|
|
503
569
|
});
|
|
504
570
|
test("Claude Mod keeps its window numbering from a boot written before the tag rename", async (t) => {
|
|
505
571
|
const home = mkdtempSync(join(tmpdir(), "claude-legacy-boot-"));
|
|
@@ -602,33 +668,65 @@ test("Claude Mod manual reset uses one hidden close-out turn, then recovers its
|
|
|
602
668
|
assert.equal(prompts.length, 1, "a busy manual request reuses the current turn instead of submitting another");
|
|
603
669
|
assert.match(kept[0].text, /Current context window id: claude:hook-session:2/);
|
|
604
670
|
});
|
|
605
|
-
test("Claude Mod
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
const handlers = new Map();
|
|
610
|
-
(await loadHookModule(t)).register((event, handler) => handlers.set(event, handler));
|
|
611
|
-
const invoke = (name, e = {}) => handlers.get(name)(host, e, async () => ({}));
|
|
612
|
-
let tokens = 142_423;
|
|
671
|
+
test("Claude Mod delivers one warning per window through main tools or prompt submission, never boot", async (t) => {
|
|
672
|
+
const { host, invoke, context } = await retainedFixture(t);
|
|
673
|
+
const texts = await dispatch({ op: "texts" });
|
|
674
|
+
let tokens = CLAUDE_200K.warn - 1;
|
|
613
675
|
host.session.usage = async () => ({ context: { tokens, window: 200_000 } });
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
const
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const
|
|
621
|
-
assert.
|
|
622
|
-
assert.equal(
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
await
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
assert.deepEqual(
|
|
631
|
-
assert.equal(
|
|
676
|
+
const foreign = { result: "upstream result", context: ["upstream context"], ref: 1 };
|
|
677
|
+
const tool = (event = { tool: "Read" }, result = foreign) => invoke("tool.call", event, result);
|
|
678
|
+
const submit = () => invoke("prompt.submit", { text: "continue", context: ["earlier plugin"] }, {}, async (e) => e);
|
|
679
|
+
assert.equal(await tool(), foreign, "below the warn point the result passes through untouched");
|
|
680
|
+
tokens++;
|
|
681
|
+
assert.deepEqual((await context()).blocks, [], "prompt.context never delivers a warning, even above the runway");
|
|
682
|
+
const denied = { deny: "upstream refusal" };
|
|
683
|
+
assert.equal(await tool({ tool: "Read" }, denied), denied, "deny stays unchanged and does not consume the warning");
|
|
684
|
+
assert.equal(await invoke("tool.call", { tool: "Read", agentId: "child" }, foreign), foreign, "subagent results do not warn");
|
|
685
|
+
const own = await tool({ tool: "mcp__notesoup__notes_list" });
|
|
686
|
+
assert.equal(typeof own.result, "string", "a self-registered result still carries its original text");
|
|
687
|
+
assert.deepEqual(own.context, [texts.warning]);
|
|
688
|
+
assert.equal(await tool(), foreign, "another tool cannot warn twice in the same window");
|
|
689
|
+
assert.deepEqual((await submit()).context, ["earlier plugin"], "tool delivery also consumes the prompt route");
|
|
690
|
+
const reset = () => invoke("session.compact", { trigger: "auto", messages: [] });
|
|
691
|
+
await reset();
|
|
692
|
+
assert.deepEqual(await tool(), { ...foreign, context: [...foreign.context, texts.warning] }, "a new window can warn through a next() tool result");
|
|
693
|
+
assert.equal(await tool(), foreign);
|
|
694
|
+
await reset();
|
|
695
|
+
assert.deepEqual((await submit()).context, ["earlier plugin", texts.warning], "prompt submission preserves earlier context and warns once");
|
|
696
|
+
assert.deepEqual((await submit()).context, ["earlier plugin"]);
|
|
697
|
+
assert.equal(await tool(), foreign, "prompt delivery wins over the later tool route");
|
|
698
|
+
assert.deepEqual((await context()).blocks, [], "no notesoup:warning block is ever added to prompt context");
|
|
699
|
+
});
|
|
700
|
+
test("Claude Mod consumes a warning only after an accepted delivery and ignores stale generations", async (t) => {
|
|
701
|
+
const { host, invoke } = await retainedFixture(t);
|
|
702
|
+
const texts = await dispatch({ op: "texts" });
|
|
703
|
+
host.session.usage = async () => ({ context: { tokens: CLAUDE_200K.warn, window: 200_000 } });
|
|
704
|
+
const event = { text: "continue", context: ["upstream"] };
|
|
705
|
+
const drop = { drop: "another plugin refused" };
|
|
706
|
+
assert.equal(await invoke("prompt.submit", event, drop), drop);
|
|
707
|
+
await assert.rejects(invoke("prompt.submit", event, {}, async () => { throw new Error("submission failed"); }), /submission failed/);
|
|
708
|
+
assert.deepEqual(await invoke("prompt.submit", event, event), event, "a downstream context rewrite does not count as delivery");
|
|
709
|
+
let entered, release;
|
|
710
|
+
const ready = new Promise((resolve) => { entered = resolve; });
|
|
711
|
+
const held = new Promise((resolve) => { release = resolve; });
|
|
712
|
+
const pending = invoke("prompt.submit", event, {}, async (e) => {
|
|
713
|
+
assert.deepEqual(e.context, [...event.context, texts.warning]);
|
|
714
|
+
entered();
|
|
715
|
+
await held;
|
|
716
|
+
return e;
|
|
717
|
+
});
|
|
718
|
+
await ready;
|
|
719
|
+
const result = { result: "tool while prompt enters" };
|
|
720
|
+
assert.equal(await invoke("tool.call", { tool: "Read" }, result), result, "an in-flight accepted route reserves this window against duplicate tool delivery");
|
|
721
|
+
await invoke("session.end", { reason: "clear" });
|
|
722
|
+
host.session.id = async () => "next-session";
|
|
723
|
+
host.session.messages = async () => [];
|
|
724
|
+
await invoke("prompt.context", {}, { blocks: [] });
|
|
725
|
+
release();
|
|
726
|
+
await pending;
|
|
727
|
+
const delivered = await invoke("prompt.submit", event, {}, async (e) => e);
|
|
728
|
+
assert.deepEqual(delivered.context, [...event.context, texts.warning], "an old delivery cannot mark the new generation warned");
|
|
729
|
+
assert.equal(await invoke("prompt.submit", event, event), event, "only an accepted delivery consumes the new window");
|
|
632
730
|
});
|
|
633
731
|
test("Claude Mod moves the reset point to the hard window when auto-compact is off", async (t) => {
|
|
634
732
|
const home = mkdtempSync(join(tmpdir(), "claude-off-home-"));
|
|
@@ -677,6 +775,8 @@ test("Claude Mod stops the automatic reset and the manual command under DISABLE_
|
|
|
677
775
|
await invoke("session.measure");
|
|
678
776
|
assert.equal(compactions, 0, "the automatic reset is off and does not retry");
|
|
679
777
|
assert.equal(notifications.length, 1, "detection logs once, not per turn");
|
|
778
|
+
const upstream = { result: "upstream", context: ["other plugin"] };
|
|
779
|
+
assert.equal(await handlers.get("tool.call")(host, { tool: "Read" }, async () => upstream), upstream, "DISABLE_COMPACT also suppresses warnings");
|
|
680
780
|
});
|
|
681
781
|
test("Claude Mod skips the automatic reset when thresholds cannot be resolved", async (t) => {
|
|
682
782
|
const home = mkdtempSync(join(tmpdir(), "claude-nolimits-home-"));
|
|
@@ -829,7 +929,7 @@ test("Claude session.end gives /clear, /resume and /branch a fresh boot and iden
|
|
|
829
929
|
await t.test(action, async (t) => {
|
|
830
930
|
const { host, invoke, context } = await retainedFixture(t);
|
|
831
931
|
host.session.usage = async () => ({ context: { tokens: 142_424, window: 200_000 } });
|
|
832
|
-
assert.
|
|
932
|
+
assert.deepEqual((await invoke("prompt.submit", { text: "continue" }, {}, async (e) => e)).context, [CLAUDE_WARNING_PROMPT], "the old window has already warned");
|
|
833
933
|
await invoke("turn.start");
|
|
834
934
|
await invoke("command.run", { command: "empty" });
|
|
835
935
|
const ended = { sentinel: action };
|
|
@@ -842,7 +942,8 @@ test("Claude session.end gives /clear, /resume and /branch a fresh boot and iden
|
|
|
842
942
|
await invoke("turn.complete");
|
|
843
943
|
assert.equal(compactions, 0, "the old queued reset cannot spill into the new session");
|
|
844
944
|
const fresh = await context();
|
|
845
|
-
assert.deepEqual(fresh.blocks.map((block) => block.name), ["notesoup:boot"
|
|
945
|
+
assert.deepEqual(fresh.blocks.map((block) => block.name), ["notesoup:boot"]);
|
|
946
|
+
assert.deepEqual((await invoke("prompt.submit", { text: "continue" }, {}, async (e) => e)).context, [CLAUDE_WARNING_PROMPT], "the new session can warn again");
|
|
846
947
|
assert.match(fresh.blocks[0].text, new RegExp(`Current context window id: claude:after-${action}:0`));
|
|
847
948
|
assert.doesNotMatch(fresh.blocks[0].text, /claude:hook-session:/);
|
|
848
949
|
const requests = [];
|
|
@@ -941,7 +1042,12 @@ test("Claude identity uses the documented current model and cwd, with a safe mod
|
|
|
941
1042
|
host.session.cwd = async () => cwd;
|
|
942
1043
|
const seen = [];
|
|
943
1044
|
const run = host.process.run;
|
|
944
|
-
host.process.run = async (argv, init) => {
|
|
1045
|
+
host.process.run = async (argv, init) => {
|
|
1046
|
+
const request = JSON.parse(init.stdin);
|
|
1047
|
+
if (request.op === "tool")
|
|
1048
|
+
seen.push(request);
|
|
1049
|
+
return run(argv, init);
|
|
1050
|
+
};
|
|
945
1051
|
const write = (address, content) => invoke("tool.call", { tool: "mcp__notesoup__notes_write", tool_use_id: "model-call", address, content });
|
|
946
1052
|
assert.equal((await write("@model/model.md", "opus")).result, "created @model/model.md");
|
|
947
1053
|
assert.equal(seen.at(-1).identity.model, "claude-opus-4-6");
|