notesoup 0.54.0 → 0.54.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 +4 -2
- package/dist/plugins/claude/src/helper.d.ts +2 -1
- package/dist/plugins/claude/src/helper.js +19 -23
- package/dist/plugins/claude/src/history.d.ts +3 -14
- package/dist/plugins/claude/src/history.js +2 -298
- package/dist/plugins/claude/src/text.d.ts +0 -1
- package/dist/plugins/claude/src/text.js +0 -1
- package/dist/plugins/codex/src/history.d.ts +3 -8
- package/dist/plugins/codex/src/history.js +2 -238
- package/dist/plugins/codex/src/mcp.js +7 -7
- package/dist/plugins/codex/src/transcript.d.ts +3 -39
- package/dist/plugins/codex/src/transcript.js +2 -313
- package/dist/plugins/dsh/history.d.ts +3 -0
- package/dist/plugins/dsh/history.js +15 -0
- package/dist/plugins/dsh/tools.js +4 -5
- package/dist/plugins/pi/history-tools.d.ts +1 -1
- package/dist/plugins/pi/history-tools.js +9 -5
- package/dist/plugins/pi/history.d.ts +2 -3
- package/dist/plugins/pi/history.js +4 -147
- package/dist/src/boot/render.js +2 -4
- package/dist/src/boot/text.d.ts +3 -1
- package/dist/src/boot/text.js +11 -5
- package/dist/src/history/claude.d.ts +16 -0
- package/dist/src/history/claude.js +336 -0
- package/dist/src/history/codex-transcript.d.ts +39 -0
- package/dist/src/history/codex-transcript.js +315 -0
- package/dist/src/history/codex.d.ts +8 -0
- package/dist/src/history/codex.js +238 -0
- package/dist/src/history/corpus.d.ts +35 -0
- package/dist/src/history/corpus.js +54 -0
- package/dist/src/history/history.d.ts +4 -8
- package/dist/src/history/history.js +3 -11
- package/dist/src/history/local.d.ts +17 -0
- package/dist/src/history/local.js +101 -0
- package/dist/src/history/pi.d.ts +36 -0
- package/dist/src/history/pi.js +202 -0
- package/dist/src/history/query.d.ts +15 -5
- package/dist/src/history/query.js +42 -13
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.js +4 -3
- package/dist/src/tools/history.d.ts +7 -19
- package/dist/src/tools/history.js +80 -93
- package/dist/test/boot.integration.test.js +1 -2
- package/dist/test/claude-history.test.js +47 -34
- package/dist/test/claude-mod.test.js +7 -7
- package/dist/test/codex-history.test.js +4 -10
- package/dist/test/codex-plugin.test.js +32 -11
- package/dist/test/dependencies.test.js +3 -3
- package/dist/test/dsh.test.js +26 -4
- package/dist/test/helpers/extension.d.ts +0 -1
- package/dist/test/helpers/history-corpus.d.ts +7 -0
- package/dist/test/helpers/history-corpus.js +26 -0
- package/dist/test/history-corpus.test.d.ts +1 -0
- package/dist/test/history-corpus.test.js +307 -0
- package/dist/test/history.integration.test.js +40 -48
- package/dist/test/host-neutral.test.js +3 -18
- package/dist/test/model-facing-text.test.js +2 -0
- package/dist/test/notes.integration.test.js +1 -1
- package/dist/test/notes.test.js +1 -1
- package/docs/architecture.md +7 -5
- package/docs/claude-code-mod.md +7 -5
- package/docs/codex.md +3 -3
- package/docs/dsh.md +2 -2
- package/docs/history-sessions.md +52 -0
- package/docs/notes-library.md +1 -1
- package/docs/skills.md +1 -1
- package/docs/tool-results.md +8 -6
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +1507 -746
- package/plugins/claude/skills/memory/SKILL.md +5 -3
- package/plugins/claude/src/helper.ts +19 -23
- package/plugins/claude/src/history.ts +3 -257
- package/plugins/claude/src/text.ts +0 -1
- package/plugins/codex/dist/codex/notesoup.js +705 -154
- package/plugins/codex/src/history.ts +3 -193
- package/plugins/codex/src/mcp.ts +7 -7
- package/plugins/codex/src/transcript.ts +3 -275
- package/plugins/dsh/history.ts +17 -0
- package/plugins/dsh/tools.ts +4 -5
- package/plugins/paseo/client/markdown.tsx +19 -39
- package/plugins/pi/history-tools.ts +11 -5
- package/plugins/pi/history.ts +8 -157
- package/skills/memory/SKILL.md +5 -3
- package/src/boot/render.ts +2 -5
- package/src/boot/text.ts +11 -5
- package/src/history/claude.ts +286 -0
- package/src/history/codex-transcript.ts +276 -0
- package/src/history/codex.ts +193 -0
- package/src/history/corpus.ts +69 -0
- package/src/history/history.ts +5 -12
- package/src/history/local.ts +93 -0
- package/src/history/pi.ts +199 -0
- package/src/history/query.ts +45 -15
- package/src/index.ts +5 -3
- package/src/tools/history.ts +71 -101
|
@@ -211,10 +211,10 @@ var require_scope = __commonJS({
|
|
|
211
211
|
var: new code_1.Name("var")
|
|
212
212
|
};
|
|
213
213
|
var Scope = class {
|
|
214
|
-
constructor({ prefixes, parent } = {}) {
|
|
214
|
+
constructor({ prefixes, parent: parent2 } = {}) {
|
|
215
215
|
this._names = {};
|
|
216
216
|
this._prefixes = prefixes;
|
|
217
|
-
this._parent =
|
|
217
|
+
this._parent = parent2;
|
|
218
218
|
}
|
|
219
219
|
toName(nameOrPrefix) {
|
|
220
220
|
return nameOrPrefix instanceof code_1.Name ? nameOrPrefix : this.name(nameOrPrefix);
|
|
@@ -7342,9 +7342,9 @@ function floatSafeRemainder(val, step) {
|
|
|
7342
7342
|
return ratio - roundedRatio;
|
|
7343
7343
|
}
|
|
7344
7344
|
var EVALUATING = /* @__PURE__ */ Symbol("evaluating");
|
|
7345
|
-
function defineLazy(
|
|
7345
|
+
function defineLazy(object4, key, getter) {
|
|
7346
7346
|
let value = void 0;
|
|
7347
|
-
Object.defineProperty(
|
|
7347
|
+
Object.defineProperty(object4, key, {
|
|
7348
7348
|
get() {
|
|
7349
7349
|
if (value === EVALUATING) {
|
|
7350
7350
|
return void 0;
|
|
@@ -7356,7 +7356,7 @@ function defineLazy(object3, key, getter) {
|
|
|
7356
7356
|
return value;
|
|
7357
7357
|
},
|
|
7358
7358
|
set(v) {
|
|
7359
|
-
Object.defineProperty(
|
|
7359
|
+
Object.defineProperty(object4, key, {
|
|
7360
7360
|
value: v
|
|
7361
7361
|
// configurable: true,
|
|
7362
7362
|
});
|
|
@@ -11585,12 +11585,12 @@ function processSchema(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
|
11585
11585
|
}
|
|
11586
11586
|
processor(schema, ctx, _json, params);
|
|
11587
11587
|
}
|
|
11588
|
-
const
|
|
11589
|
-
if (
|
|
11588
|
+
const parent2 = schema._zod.parent;
|
|
11589
|
+
if (parent2) {
|
|
11590
11590
|
if (!result.ref)
|
|
11591
|
-
result.ref =
|
|
11592
|
-
processSchema(
|
|
11593
|
-
ctx.seen.get(
|
|
11591
|
+
result.ref = parent2;
|
|
11592
|
+
processSchema(parent2, ctx, params);
|
|
11593
|
+
ctx.seen.get(parent2).isParent = true;
|
|
11594
11594
|
}
|
|
11595
11595
|
}
|
|
11596
11596
|
const meta2 = ctx.metadataRegistry.get(schema);
|
|
@@ -11746,8 +11746,8 @@ function foldObjects(members2) {
|
|
|
11746
11746
|
}
|
|
11747
11747
|
const properties = {};
|
|
11748
11748
|
const required3 = /* @__PURE__ */ new Set();
|
|
11749
|
-
for (const
|
|
11750
|
-
for (const key in
|
|
11749
|
+
for (const object4 of objects) {
|
|
11750
|
+
for (const key in object4.properties) {
|
|
11751
11751
|
if (Object.prototype.hasOwnProperty.call(properties, key))
|
|
11752
11752
|
continue;
|
|
11753
11753
|
const parts = [];
|
|
@@ -11761,18 +11761,18 @@ function foldObjects(members2) {
|
|
|
11761
11761
|
const merged = parts.length === 1 ? parts[0] : foldObjects(parts) ?? { allOf: parts };
|
|
11762
11762
|
assignProp(properties, key, merged);
|
|
11763
11763
|
}
|
|
11764
|
-
for (const key of
|
|
11764
|
+
for (const key of object4.required ?? [])
|
|
11765
11765
|
required3.add(key);
|
|
11766
11766
|
}
|
|
11767
11767
|
const folded = { type: "object", properties };
|
|
11768
11768
|
if (required3.size)
|
|
11769
11769
|
folded.required = [...required3];
|
|
11770
|
-
if (objects.every((
|
|
11770
|
+
if (objects.every((object4) => object4.additionalProperties === false)) {
|
|
11771
11771
|
folded.additionalProperties = false;
|
|
11772
11772
|
} else {
|
|
11773
11773
|
const constraints = [];
|
|
11774
|
-
for (const
|
|
11775
|
-
const constraint = undeclaredConstraint(
|
|
11774
|
+
for (const object4 of objects) {
|
|
11775
|
+
const constraint = undeclaredConstraint(object4);
|
|
11776
11776
|
if (constraint && !constraints.some((seen) => JSON.stringify(seen) === JSON.stringify(constraint)))
|
|
11777
11777
|
constraints.push(constraint);
|
|
11778
11778
|
}
|
|
@@ -11853,10 +11853,10 @@ function finalize(ctx, schema) {
|
|
|
11853
11853
|
}
|
|
11854
11854
|
}
|
|
11855
11855
|
}
|
|
11856
|
-
const
|
|
11857
|
-
if (
|
|
11858
|
-
flattenRef(
|
|
11859
|
-
const parentSeen = ctx.seen.get(
|
|
11856
|
+
const parent2 = zodSchema._zod.parent;
|
|
11857
|
+
if (parent2 && parent2 !== ref) {
|
|
11858
|
+
flattenRef(parent2);
|
|
11859
|
+
const parentSeen = ctx.seen.get(parent2);
|
|
11860
11860
|
if (parentSeen?.schema.$ref) {
|
|
11861
11861
|
schema2.$ref = parentSeen.schema.$ref;
|
|
11862
11862
|
if (parentSeen.def) {
|
|
@@ -19409,9 +19409,9 @@ function Set4(value, pointer, next) {
|
|
|
19409
19409
|
AssertNotRoot(indices);
|
|
19410
19410
|
AssertIndices(indices);
|
|
19411
19411
|
const [head, index] = TakeIndexRight(indices);
|
|
19412
|
-
const
|
|
19413
|
-
AssertCanSet(
|
|
19414
|
-
|
|
19412
|
+
const parent2 = GetIndices(head, value);
|
|
19413
|
+
AssertCanSet(parent2);
|
|
19414
|
+
parent2[index] = next;
|
|
19415
19415
|
return value;
|
|
19416
19416
|
}
|
|
19417
19417
|
function Delete(value, pointer) {
|
|
@@ -19419,12 +19419,12 @@ function Delete(value, pointer) {
|
|
|
19419
19419
|
AssertNotRoot(indices);
|
|
19420
19420
|
AssertIndices(indices);
|
|
19421
19421
|
const [head, index] = TakeIndexRight(indices);
|
|
19422
|
-
const
|
|
19423
|
-
AssertCanSet(
|
|
19424
|
-
if (guard_exports.IsArray(
|
|
19425
|
-
|
|
19422
|
+
const parent2 = GetIndices(head, value);
|
|
19423
|
+
AssertCanSet(parent2);
|
|
19424
|
+
if (guard_exports.IsArray(parent2) && IsNumericIndex(index)) {
|
|
19425
|
+
parent2.splice(+index, 1);
|
|
19426
19426
|
} else {
|
|
19427
|
-
delete
|
|
19427
|
+
delete parent2[index];
|
|
19428
19428
|
}
|
|
19429
19429
|
return value;
|
|
19430
19430
|
}
|
|
@@ -20377,15 +20377,15 @@ function IntersectOptions(type) {
|
|
|
20377
20377
|
|
|
20378
20378
|
// ../../../Users/astrosheep/pi-extensions/pi-context/node_modules/typebox/build/type/types/_codec.mjs
|
|
20379
20379
|
var EncodeBuilder = class {
|
|
20380
|
-
constructor(type,
|
|
20380
|
+
constructor(type, decode4) {
|
|
20381
20381
|
this.type = type;
|
|
20382
|
-
this.decode =
|
|
20382
|
+
this.decode = decode4;
|
|
20383
20383
|
}
|
|
20384
20384
|
Encode(callback) {
|
|
20385
20385
|
const type = this.type;
|
|
20386
|
-
const
|
|
20386
|
+
const decode4 = IsCodec(type) ? (value) => this.decode(type["~codec"].decode(value)) : this.decode;
|
|
20387
20387
|
const encode3 = IsCodec(type) ? (value) => type["~codec"].encode(callback(value)) : callback;
|
|
20388
|
-
const codec = { decode:
|
|
20388
|
+
const codec = { decode: decode4, encode: encode3 };
|
|
20389
20389
|
return memory_exports.Update(this.type, { "~codec": codec }, {});
|
|
20390
20390
|
}
|
|
20391
20391
|
};
|
|
@@ -22937,8 +22937,8 @@ function FromObject5(properties) {
|
|
|
22937
22937
|
|
|
22938
22938
|
// ../../../Users/astrosheep/pi-extensions/pi-context/node_modules/typebox/build/type/engine/object/from_tuple.mjs
|
|
22939
22939
|
function FromTuple(types) {
|
|
22940
|
-
const
|
|
22941
|
-
const result = FromType8(
|
|
22940
|
+
const object4 = TupleToObject(Tuple(types));
|
|
22941
|
+
const result = FromType8(object4);
|
|
22942
22942
|
return result;
|
|
22943
22943
|
}
|
|
22944
22944
|
|
|
@@ -25313,9 +25313,9 @@ function gitRoot(cwd) {
|
|
|
25313
25313
|
let dir = resolve2(cwd);
|
|
25314
25314
|
for (; ; ) {
|
|
25315
25315
|
if (existsSync(join2(dir, ".git"))) return repositoryRoot(dir);
|
|
25316
|
-
const
|
|
25317
|
-
if (
|
|
25318
|
-
dir =
|
|
25316
|
+
const parent2 = dirname(dir);
|
|
25317
|
+
if (parent2 === dir) return void 0;
|
|
25318
|
+
dir = parent2;
|
|
25319
25319
|
}
|
|
25320
25320
|
}
|
|
25321
25321
|
function repositoryRoot(dir) {
|
|
@@ -25848,6 +25848,13 @@ function renderTextWindow(window) {
|
|
|
25848
25848
|
// src/history/history.ts
|
|
25849
25849
|
var HistoryRoleSchema = typebox_exports.Union([typebox_exports.Literal("user"), typebox_exports.Literal("assistant"), typebox_exports.Literal("tool"), typebox_exports.Literal("context")]);
|
|
25850
25850
|
var ToolCallStatusSchema = typebox_exports.Union([typebox_exports.Literal("ok"), typebox_exports.Literal("error"), typebox_exports.Literal("unfinished")]);
|
|
25851
|
+
function isTextContent(part) {
|
|
25852
|
+
return typeof part === "object" && part !== null && part.type === "text" && typeof part.text === "string";
|
|
25853
|
+
}
|
|
25854
|
+
function contentText(content) {
|
|
25855
|
+
if (typeof content === "string") return content;
|
|
25856
|
+
return Array.isArray(content) ? content.filter(isTextContent).map((part) => part.text).join("\n") : "";
|
|
25857
|
+
}
|
|
25851
25858
|
function argumentText(execution) {
|
|
25852
25859
|
return execution.arguments === void 0 ? "(arguments not recorded)" : JSON.stringify(execution.arguments);
|
|
25853
25860
|
}
|
|
@@ -25952,8 +25959,8 @@ function nestedCallSummary(event) {
|
|
|
25952
25959
|
return nested === void 0 ? {} : { nested_calls: { call_count: nested.calls.length, complete: nested.complete } };
|
|
25953
25960
|
}
|
|
25954
25961
|
var HistoryPageItemSchema = typebox_exports.Object({
|
|
25962
|
+
session: typebox_exports.Optional(typebox_exports.String()),
|
|
25955
25963
|
seq: typebox_exports.Integer({ minimum: 1 }),
|
|
25956
|
-
window_id: typebox_exports.String(),
|
|
25957
25964
|
role: HistoryRoleSchema,
|
|
25958
25965
|
created_at: typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()]),
|
|
25959
25966
|
...ToolSummarySchema.properties,
|
|
@@ -25962,6 +25969,7 @@ var HistoryPageItemSchema = typebox_exports.Object({
|
|
|
25962
25969
|
offset_chars: typebox_exports.Optional(typebox_exports.Integer({ minimum: 0, description: "Where the preview starts." }))
|
|
25963
25970
|
}, { additionalProperties: false });
|
|
25964
25971
|
var HistoryFoldedRowSchema = typebox_exports.Object({
|
|
25972
|
+
session: typebox_exports.Optional(typebox_exports.String()),
|
|
25965
25973
|
folded: typebox_exports.Literal(true),
|
|
25966
25974
|
first_seq: typebox_exports.Integer({ minimum: 1 }),
|
|
25967
25975
|
last_seq: typebox_exports.Integer({ minimum: 1 }),
|
|
@@ -25978,7 +25986,6 @@ function visibleItem(event, maxChars, matchOffset) {
|
|
|
25978
25986
|
const truncated = start > 0 || start + limit < chars.length;
|
|
25979
25987
|
return {
|
|
25980
25988
|
seq: event.seq,
|
|
25981
|
-
window_id: event.windowId,
|
|
25982
25989
|
role: event.role,
|
|
25983
25990
|
created_at: event.createdAt ?? null,
|
|
25984
25991
|
...toolSummary(event),
|
|
@@ -25990,13 +25997,7 @@ function visibleItem(event, maxChars, matchOffset) {
|
|
|
25990
25997
|
function allItems(projection) {
|
|
25991
25998
|
return projection.windows.flatMap((current) => current.items);
|
|
25992
25999
|
}
|
|
25993
|
-
function unknownWindowId(projection, params) {
|
|
25994
|
-
if (typeof params.window_id !== "string") return void 0;
|
|
25995
|
-
const known = projection.windows.map((current) => current.windowId);
|
|
25996
|
-
return known.includes(params.window_id) ? void 0 : { message: `No window "${params.window_id}" in this session`, known };
|
|
25997
|
-
}
|
|
25998
26000
|
function inSelection(event, params) {
|
|
25999
|
-
if (typeof params.window_id === "string" && params.window_id !== event.windowId) return false;
|
|
26000
26001
|
if (params.after_seq !== void 0 && event.seq <= params.after_seq) return false;
|
|
26001
26002
|
if (params.before_seq !== void 0 && event.seq >= params.before_seq) return false;
|
|
26002
26003
|
if (params.sinceMs === void 0 && params.untilMs === void 0) return true;
|
|
@@ -26399,13 +26400,16 @@ function resolveTimeBounds(params) {
|
|
|
26399
26400
|
return success({ ...since.data === void 0 ? {} : { sinceMs: since.data }, ...until.data === void 0 ? {} : { untilMs: until.data } });
|
|
26400
26401
|
}
|
|
26401
26402
|
var HistoryOlderSchema = typebox_exports.Object({
|
|
26403
|
+
session: typebox_exports.Optional(typebox_exports.String()),
|
|
26402
26404
|
before_seq: typebox_exports.Integer({ minimum: 1 })
|
|
26403
26405
|
}, { additionalProperties: false });
|
|
26404
26406
|
var HistoryNewerSchema = typebox_exports.Object({
|
|
26407
|
+
session: typebox_exports.Optional(typebox_exports.String()),
|
|
26405
26408
|
after_seq: typebox_exports.Integer({ minimum: 1 }),
|
|
26406
26409
|
from: typebox_exports.Literal("oldest")
|
|
26407
26410
|
}, { additionalProperties: false });
|
|
26408
26411
|
var HistoryPageSchema = typebox_exports.Object({
|
|
26412
|
+
notice: typebox_exports.Optional(typebox_exports.String()),
|
|
26409
26413
|
items: typebox_exports.Array(typebox_exports.Union([HistoryPageItemSchema, HistoryFoldedRowSchema])),
|
|
26410
26414
|
page_older: typebox_exports.Union([HistoryOlderSchema, typebox_exports.Null()]),
|
|
26411
26415
|
page_newer: typebox_exports.Union([HistoryNewerSchema, typebox_exports.Null()])
|
|
@@ -26423,7 +26427,7 @@ function truncateHistoryItem(item, fits) {
|
|
|
26423
26427
|
const { tool: _dropped, ...withoutName } = item;
|
|
26424
26428
|
return fits(withoutName) ? withoutName : shrinkContent(withoutName);
|
|
26425
26429
|
}
|
|
26426
|
-
function foldedRun(events) {
|
|
26430
|
+
function foldedRun(events, session) {
|
|
26427
26431
|
if (events.length === 0) return void 0;
|
|
26428
26432
|
const counts = /* @__PURE__ */ new Map();
|
|
26429
26433
|
for (const event of events) {
|
|
@@ -26433,7 +26437,7 @@ function foldedRun(events) {
|
|
|
26433
26437
|
}
|
|
26434
26438
|
const entries = [...counts].filter(([name]) => name.length <= MAX_FOLD_TOOL_NAME_CHARS).slice(0, MAX_FOLD_TOOL_NAMES);
|
|
26435
26439
|
const tools2 = Object.fromEntries(entries);
|
|
26436
|
-
return { folded: true, first_seq: events[0].seq, last_seq: events.at(-1).seq, count: events.length, tools: tools2 };
|
|
26440
|
+
return { ...session === void 0 ? {} : { session }, folded: true, first_seq: events[0].seq, last_seq: events.at(-1).seq, count: events.length, tools: tools2 };
|
|
26437
26441
|
}
|
|
26438
26442
|
function prepareSelection(projection, params) {
|
|
26439
26443
|
const folds = !params.roles && params.query === void 0;
|
|
@@ -26447,38 +26451,57 @@ function prepareSelection(projection, params) {
|
|
|
26447
26451
|
if ((event.role === "user" || event.role === "assistant") && eventDocument(event) === "") continue;
|
|
26448
26452
|
const matchOffset = params.query === void 0 ? void 0 : earliestMatchOffsetChars(eventDocument(event), params.query);
|
|
26449
26453
|
if (matchOffset !== void 0 && matchOffset < 0) continue;
|
|
26450
|
-
candidates.push({ event, matchOffset, before: foldedRun(run) });
|
|
26454
|
+
candidates.push({ event, ...params.session === void 0 ? {} : { session: params.session }, matchOffset, before: foldedRun(run, params.session) });
|
|
26451
26455
|
run = [];
|
|
26452
26456
|
}
|
|
26453
|
-
return { candidates, tail: foldedRun(run) };
|
|
26457
|
+
return { candidates, session: params.session, tail: foldedRun(run, params.session) };
|
|
26454
26458
|
}
|
|
26455
26459
|
function pageData(prepared, start, end, maxChars, preview) {
|
|
26456
26460
|
const { candidates, tail } = prepared;
|
|
26461
|
+
const identity = prepared.session === void 0 ? {} : { session: prepared.session };
|
|
26457
26462
|
const items = [];
|
|
26458
26463
|
for (let index = start; index < end; index++) {
|
|
26459
26464
|
const candidate = candidates[index];
|
|
26460
26465
|
if (candidate.before && (index > start || start === 0)) items.push(candidate.before);
|
|
26461
|
-
items.push(preview ?? (candidate.preview ??= visibleItem(candidate.event, maxChars, candidate.matchOffset)));
|
|
26466
|
+
items.push(preview ?? (candidate.preview ??= { ...visibleItem(candidate.event, maxChars, candidate.matchOffset), ...candidate.session === void 0 ? {} : { session: candidate.session } }));
|
|
26462
26467
|
}
|
|
26463
26468
|
if (end === candidates.length && tail) items.push(tail);
|
|
26464
26469
|
return {
|
|
26465
26470
|
items,
|
|
26466
|
-
page_older: start > 0 && start < end ? { before_seq: candidates[start].event.seq } : null,
|
|
26467
|
-
page_newer: end < candidates.length && start < end ? { after_seq: candidates[end - 1].event.seq, from: "oldest" } : null
|
|
26471
|
+
page_older: !prepared.multi && start > 0 && start < end ? { ...identity, before_seq: candidates[start].event.seq } : null,
|
|
26472
|
+
page_newer: !prepared.multi && end < candidates.length && start < end ? { ...identity, after_seq: candidates[end - 1].event.seq, from: "oldest" } : null
|
|
26468
26473
|
};
|
|
26469
26474
|
}
|
|
26470
|
-
function
|
|
26475
|
+
function resolveSelection(params) {
|
|
26471
26476
|
const bounds = resolveTimeBounds(params);
|
|
26472
26477
|
if (!bounds.ok) return bounds;
|
|
26473
|
-
let queries;
|
|
26474
26478
|
try {
|
|
26475
|
-
queries = searchQueries(params.query);
|
|
26479
|
+
const queries = searchQueries(params.query);
|
|
26480
|
+
return success({ ...params, ...bounds.data, query: queries.length ? queries : void 0 });
|
|
26476
26481
|
} catch (error2) {
|
|
26477
26482
|
if (error2 instanceof InvalidQueryError) return failure2("invalid_query", error2.message);
|
|
26478
26483
|
throw error2;
|
|
26479
26484
|
}
|
|
26480
|
-
|
|
26481
|
-
|
|
26485
|
+
}
|
|
26486
|
+
function selectPage(projection, params, fits, maxChars) {
|
|
26487
|
+
const scoped = resolveSelection(params);
|
|
26488
|
+
if (!scoped.ok) return scoped;
|
|
26489
|
+
return selectPrepared(prepareSelection(projection, scoped.data), scoped.data, fits, maxChars);
|
|
26490
|
+
}
|
|
26491
|
+
function corpusSelection(params) {
|
|
26492
|
+
const scoped = resolveSelection(params);
|
|
26493
|
+
if (!scoped.ok) return scoped;
|
|
26494
|
+
if (scoped.data.query === void 0) return failure2("missing_query", "Wildcard session search requires a non-empty `query`.");
|
|
26495
|
+
if (params.before_seq !== void 0 || params.after_seq !== void 0) return failure2("invalid_bounds", "`before_seq` and `after_seq` are per-session; omit them for wildcard session search.");
|
|
26496
|
+
return scoped;
|
|
26497
|
+
}
|
|
26498
|
+
function selectCorpusPage(sessions, scoped, fits, maxChars) {
|
|
26499
|
+
const candidates = sessions.flatMap(({ session, projection }) => prepareSelection(projection, { ...scoped, session }).candidates);
|
|
26500
|
+
const time3 = (event) => event.createdAt === void 0 || Number.isNaN(Date.parse(event.createdAt)) ? -Infinity : Date.parse(event.createdAt);
|
|
26501
|
+
candidates.sort((a, b) => time3(a.event) - time3(b.event) || a.session.localeCompare(b.session) || a.event.seq - b.event.seq);
|
|
26502
|
+
return selectPrepared({ candidates, multi: true }, scoped, fits, maxChars);
|
|
26503
|
+
}
|
|
26504
|
+
function selectPrepared(prepared, scoped, fits, maxChars) {
|
|
26482
26505
|
const { candidates } = prepared;
|
|
26483
26506
|
const newest = scoped.from !== "oldest";
|
|
26484
26507
|
let start = newest ? candidates.length : 0;
|
|
@@ -26502,33 +26525,71 @@ function selectPage(projection, params, fits, maxChars) {
|
|
|
26502
26525
|
}
|
|
26503
26526
|
const page = pageData(prepared, start, end, maxChars);
|
|
26504
26527
|
if (!fits(page)) {
|
|
26505
|
-
|
|
26528
|
+
const narrow = prepared.multi ? "narrow the session pattern, query, roles or `since`/`until`, or read one session/seq with `history_read`" : "narrow with `before_seq`/`after_seq` or `since`/`until`, pass `roles` to skip folding, or `history_read` one seq";
|
|
26529
|
+
return failure2("page_too_large", `Even trimmed to their shortest, these ${page.items.length} rows${prepared.multi ? "" : " and their folded runs"} fill the ${TOOL_OUTPUT_LIMIT} a call can carry; ${narrow}.`);
|
|
26506
26530
|
}
|
|
26507
26531
|
return success(page);
|
|
26508
26532
|
}
|
|
26509
26533
|
|
|
26534
|
+
// src/history/corpus.ts
|
|
26535
|
+
var HARNESSES = /* @__PURE__ */ new Set(["pi", "claude", "codex", "dsh"]);
|
|
26536
|
+
function sessionIdentity(session) {
|
|
26537
|
+
return `${session.harness}:${session.id}`;
|
|
26538
|
+
}
|
|
26539
|
+
function parseSessionSelector(value) {
|
|
26540
|
+
const colon = value.indexOf(":");
|
|
26541
|
+
const harness = colon < 0 ? void 0 : value.slice(0, colon);
|
|
26542
|
+
const id2 = colon < 0 ? value : value.slice(colon + 1);
|
|
26543
|
+
if (id2.length === 0 || id2.includes(":") || harness !== void 0 && !HARNESSES.has(harness)) {
|
|
26544
|
+
return failure2("invalid_session", "Pass a session ID or prefix, optionally prefixed by pi:, claude:, codex:, or dsh:.");
|
|
26545
|
+
}
|
|
26546
|
+
return success({ ...harness === void 0 ? {} : { harness }, id: id2, wildcard: id2.includes("*") });
|
|
26547
|
+
}
|
|
26548
|
+
function matchesSession(session, selector) {
|
|
26549
|
+
if (selector.harness !== void 0 && selector.harness !== session.harness) return false;
|
|
26550
|
+
const escaped = selector.id.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*");
|
|
26551
|
+
return new RegExp(`^${escaped}$`).test(session.id);
|
|
26552
|
+
}
|
|
26553
|
+
async function resolveSession(corpus, selector) {
|
|
26554
|
+
if (corpus === void 0) return failure2("unknown_session", "This host supplied no cross-session history corpus.");
|
|
26555
|
+
const matching = (pool) => {
|
|
26556
|
+
const exact = pool.filter((session) => session.id === selector.id);
|
|
26557
|
+
return exact.length ? exact : pool.filter((session) => session.id.startsWith(selector.id));
|
|
26558
|
+
};
|
|
26559
|
+
let matches;
|
|
26560
|
+
if (selector.harness !== void 0) matches = matching((await corpus.sessions(selector.harness)).filter((session) => session.harness === selector.harness));
|
|
26561
|
+
else {
|
|
26562
|
+
matches = matching((await corpus.sessions(corpus.currentHarness)).filter((session) => session.harness === corpus.currentHarness));
|
|
26563
|
+
if (matches.length === 0) matches = matching((await corpus.sessions()).filter((session) => session.harness !== corpus.currentHarness));
|
|
26564
|
+
}
|
|
26565
|
+
if (matches.length === 0) return failure2("unknown_session", `No local session matches ${JSON.stringify(selector.harness ? `${selector.harness}:${selector.id}` : selector.id)}.`);
|
|
26566
|
+
if (matches.length > 1) return failure2("ambiguous_session", `Session selector is ambiguous: ${matches.slice(0, 5).map(sessionIdentity).join(", ")}${matches.length > 5 ? ` (${matches.length - 5} more)` : ""}. Pass a longer ID or a harness-qualified ID.`);
|
|
26567
|
+
return success(matches[0]);
|
|
26568
|
+
}
|
|
26569
|
+
async function loadHistorySession(session) {
|
|
26570
|
+
try {
|
|
26571
|
+
return success(await session.load());
|
|
26572
|
+
} catch (error2) {
|
|
26573
|
+
return failure2("history_unavailable", `Cannot read session ${sessionIdentity(session)}: ${error2 instanceof Error ? error2.message : String(error2)}`);
|
|
26574
|
+
}
|
|
26575
|
+
}
|
|
26576
|
+
function currentHistory(context2) {
|
|
26577
|
+
return "current" in context2 ? context2.current() : context2;
|
|
26578
|
+
}
|
|
26579
|
+
|
|
26510
26580
|
// src/tools/history.ts
|
|
26511
26581
|
var HistoryReadDataSchema = typebox_exports.Object({
|
|
26582
|
+
session: typebox_exports.Optional(typebox_exports.String()),
|
|
26583
|
+
notice: typebox_exports.Optional(typebox_exports.String()),
|
|
26512
26584
|
seq: typebox_exports.Integer({ minimum: 1 }),
|
|
26513
|
-
window_id: typebox_exports.String(),
|
|
26514
26585
|
role: HistoryRoleSchema,
|
|
26515
26586
|
created_at: typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()]),
|
|
26516
26587
|
...ToolSummarySchema.properties,
|
|
26517
26588
|
nested_calls: typebox_exports.Optional(NestedCallSummarySchema),
|
|
26518
26589
|
...TextWindowSchema.properties
|
|
26519
26590
|
}, { additionalProperties: false });
|
|
26520
|
-
var HistoryWindowsDataSchema = typebox_exports.Object({
|
|
26521
|
-
session_id: typebox_exports.String(),
|
|
26522
|
-
windows: typebox_exports.Array(typebox_exports.Object({
|
|
26523
|
-
window_id: typebox_exports.String(),
|
|
26524
|
-
created_at: typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()]),
|
|
26525
|
-
first_seq: typebox_exports.Union([typebox_exports.Integer({ minimum: 1 }), typebox_exports.Null()]),
|
|
26526
|
-
last_seq: typebox_exports.Union([typebox_exports.Integer({ minimum: 1 }), typebox_exports.Null()])
|
|
26527
|
-
}, { additionalProperties: false })),
|
|
26528
|
-
more: typebox_exports.Integer({ minimum: 0, description: "How many more were left out." })
|
|
26529
|
-
}, { additionalProperties: false });
|
|
26530
26591
|
function header(item) {
|
|
26531
|
-
return `
|
|
26592
|
+
return `${item.session === void 0 ? "" : `session ${item.session} | `}seq ${item.seq} | ${item.role}`;
|
|
26532
26593
|
}
|
|
26533
26594
|
function toolHeader(item) {
|
|
26534
26595
|
if (item.role !== "tool") return void 0;
|
|
@@ -26548,77 +26609,32 @@ function renderPageItem(item) {
|
|
|
26548
26609
|
}
|
|
26549
26610
|
function renderFoldedRow(row) {
|
|
26550
26611
|
const tools2 = Object.entries(row.tools).map(([name, count]) => `${name} ${count}`).join(", ");
|
|
26612
|
+
const identity = row.session === void 0 ? {} : { session: row.session };
|
|
26551
26613
|
const expand = `
|
|
26552
|
-
\u2192 expand: {
|
|
26553
|
-
return `seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools2 ? ` | ${tools2}` : ""}${expand}`;
|
|
26614
|
+
\u2192 expand: ${JSON.stringify({ ...identity, after_seq: row.first_seq - 1, before_seq: row.last_seq + 1, from: "oldest", roles: ["tool", "context"] })}`;
|
|
26615
|
+
return `${row.session === void 0 ? "" : `session ${row.session} | `}seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools2 ? ` | ${tools2}` : ""}${expand}`;
|
|
26554
26616
|
}
|
|
26555
26617
|
function renderPage(page) {
|
|
26556
|
-
if (page.items.length === 0) return "No events match these filters
|
|
26618
|
+
if (page.items.length === 0) return `${page.notice ?? ""}No events match these filters.`;
|
|
26557
26619
|
const body = page.items.map((item) => "folded" in item ? renderFoldedRow(item) : renderPageItem(item)).join("\n\n");
|
|
26558
26620
|
const cursors = [
|
|
26559
26621
|
page.page_older === null ? "" : `\u2192 older: ${JSON.stringify(page.page_older)}`,
|
|
26560
26622
|
page.page_newer === null ? "" : `\u2192 newer: ${JSON.stringify(page.page_newer)}`
|
|
26561
26623
|
].filter((line) => line !== "");
|
|
26562
|
-
return cursors.length === 0 ? body : `${body}
|
|
26624
|
+
return (page.notice ?? "") + (cursors.length === 0 ? body : `${body}
|
|
26563
26625
|
|
|
26564
|
-
${cursors.join(" | ")}
|
|
26626
|
+
${cursors.join(" | ")}`);
|
|
26565
26627
|
}
|
|
26566
26628
|
function renderRead(data) {
|
|
26567
26629
|
const tool = toolHeader(data);
|
|
26568
26630
|
const afterSeq = data.seq - 10;
|
|
26569
|
-
const neighborhood = `neighborhood \u2192 \`history_list\`(${JSON.stringify({ ...afterSeq >= 1 ? { after_seq: afterSeq } : {}, before_seq: data.seq + 10 })})`;
|
|
26570
|
-
return [header(data), ...tool ? [tool] : [], neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
|
|
26631
|
+
const neighborhood = `neighborhood \u2192 \`history_list\`(${JSON.stringify({ ...data.session === void 0 ? {} : { session: data.session }, ...afterSeq >= 1 ? { after_seq: afterSeq } : {}, before_seq: data.seq + 10 })})`;
|
|
26632
|
+
return (data.notice ?? "") + [header(data), ...tool ? [tool] : [], neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
|
|
26571
26633
|
}
|
|
26572
26634
|
var plainText = (text2) => text2;
|
|
26573
|
-
var
|
|
26574
|
-
function knownWindowSuffix(known) {
|
|
26575
|
-
return known.length === 0 ? "" : `; its windows: ${known.slice(0, MAX_REPORTED_WINDOWS).join(", ")}`;
|
|
26576
|
-
}
|
|
26577
|
-
var PREVIOUS_WINDOW = "@previous";
|
|
26578
|
-
function resolveWindowId(projection, windowId) {
|
|
26579
|
-
if (windowId !== PREVIOUS_WINDOW) return { ok: true, window_id: windowId };
|
|
26580
|
-
const previous = projection.windows.at(-2);
|
|
26581
|
-
if (previous !== void 0) return { ok: true, window_id: previous.windowId };
|
|
26582
|
-
const known = projection.windows.map((current) => current.windowId);
|
|
26583
|
-
return { ok: false, outcome: failure2("unknown_window_id", `"${PREVIOUS_WINDOW}" has nothing to point at: this session has no window before the current one${knownWindowSuffix(known)}.`) };
|
|
26584
|
-
}
|
|
26585
|
-
function badWindowId(projection, params) {
|
|
26586
|
-
const badWindow = unknownWindowId(projection, params);
|
|
26587
|
-
if (!badWindow) return void 0;
|
|
26588
|
-
return failure2("unknown_window_id", `${badWindow.message}${knownWindowSuffix(badWindow.known)}.`);
|
|
26589
|
-
}
|
|
26590
|
-
var historyWindowsParameters = typebox_exports.Object({}, { additionalProperties: false });
|
|
26591
|
-
var historyWindows = {
|
|
26592
|
-
name: "history_windows",
|
|
26593
|
-
label: "History list windows",
|
|
26594
|
-
description: "List this session's context windows, oldest first, with seq ranges.",
|
|
26595
|
-
parameters: historyWindowsParameters,
|
|
26596
|
-
outputSchema: resultSchema(HistoryWindowsDataSchema),
|
|
26597
|
-
async execute(_params, projection, sessionId, wrapText = plainText) {
|
|
26598
|
-
const data = { session_id: sessionId, windows: [], more: projection.windows.length };
|
|
26599
|
-
const fits = (candidate) => fitsResult(success(candidate), (result) => wrapText(renderOutcome(result, renderWindows)));
|
|
26600
|
-
for (const window of projection.windows) {
|
|
26601
|
-
let first = null;
|
|
26602
|
-
let last = null;
|
|
26603
|
-
for (const event of window.items) {
|
|
26604
|
-
first = first === null ? event.seq : Math.min(first, event.seq);
|
|
26605
|
-
last = last === null ? event.seq : Math.max(last, event.seq);
|
|
26606
|
-
}
|
|
26607
|
-
const row = { window_id: window.windowId, created_at: window.createdAt ?? null, first_seq: first, last_seq: last };
|
|
26608
|
-
if (!fits({ ...data, windows: [...data.windows, row], more: data.more - 1 })) break;
|
|
26609
|
-
data.windows.push(row);
|
|
26610
|
-
data.more--;
|
|
26611
|
-
}
|
|
26612
|
-
return fits(data) ? success(data) : failure2("output_too_large", `The session id alone fills the ${TOOL_OUTPUT_LIMIT} a call can carry.`);
|
|
26613
|
-
},
|
|
26614
|
-
render: (result) => renderOutcome(result, renderWindows)
|
|
26615
|
-
};
|
|
26616
|
-
function renderWindows(data) {
|
|
26617
|
-
const lines = [`session ${data.session_id}`, ...data.windows.map((window) => `window ${window.window_id} | seqs ${window.first_seq ?? "-"}-${window.last_seq ?? "-"}`)];
|
|
26618
|
-
if (data.more > 0) lines.push(`${data.more} more windows not shown; every \`history_list\` event also names its window.`);
|
|
26619
|
-
return lines.join("\n");
|
|
26620
|
-
}
|
|
26635
|
+
var sessionParameter = typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "(optional) Session ID or unique prefix, optionally pi:, claude:, codex:, or dsh:. Omit for this session. In history_list, * searches sessions (query required); history_read needs one session." }));
|
|
26621
26636
|
var historyListParameters = typebox_exports.Object({
|
|
26637
|
+
session: sessionParameter,
|
|
26622
26638
|
query: typebox_exports.Optional(searchQuery("(optional) Text, or a list of texts (any match). Empty text/list means no search filter; empty entries are ignored. Searches every role, tool arguments and output included; returns only hits.")),
|
|
26623
26639
|
roles: historyRoles(),
|
|
26624
26640
|
before_seq: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "(optional) Only events with seq below this." })),
|
|
@@ -26626,40 +26642,77 @@ var historyListParameters = typebox_exports.Object({
|
|
|
26626
26642
|
since: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "(optional) ISO 8601 time; only events at or after it. UTC if no offset." })),
|
|
26627
26643
|
until: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "(optional) ISO 8601 time; only events before it. UTC if no offset." })),
|
|
26628
26644
|
from: typebox_exports.Optional(typebox_exports.Union([typebox_exports.Literal("newest"), typebox_exports.Literal("oldest")], { description: "(optional, default newest) Which end `limit` counts from: newest or oldest. Results stay oldest first." })),
|
|
26629
|
-
window_id: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: `(optional) Only this context window. From \`history_windows\` or any event; \`${PREVIOUS_WINDOW}\` is the one before this.` })),
|
|
26630
26645
|
limit: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: 500, description: "(optional, default 20) Max events per page; folded rows don't count." })),
|
|
26631
26646
|
max_chars_per_item: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: `(optional, default ${HISTORY_PREVIEW_CHARS}) Max preview chars per event.` }))
|
|
26632
26647
|
}, { additionalProperties: false });
|
|
26633
26648
|
var historyList = {
|
|
26634
26649
|
name: "history_list",
|
|
26635
26650
|
label: "History list items",
|
|
26636
|
-
description: "Browse or search
|
|
26651
|
+
description: "Browse or search events, a page at a time. Omit session for this session; pass an ID/prefix for another, or * with query to search across local harnesses. Read one in full with `history_read`.",
|
|
26637
26652
|
parameters: historyListParameters,
|
|
26638
26653
|
outputSchema: resultSchema(HistoryPageSchema),
|
|
26639
|
-
async execute(params,
|
|
26640
|
-
const
|
|
26641
|
-
|
|
26642
|
-
|
|
26643
|
-
const
|
|
26644
|
-
if (
|
|
26645
|
-
const
|
|
26646
|
-
|
|
26654
|
+
async execute(params, context2, wrapText = plainText) {
|
|
26655
|
+
const fits = (page) => fitsResult(success(page), (result2) => wrapText(renderOutcome(result2, renderPage)));
|
|
26656
|
+
const maxChars = params.max_chars_per_item ?? HISTORY_PREVIEW_CHARS;
|
|
26657
|
+
if (params.session === void 0) return selectPage(await currentHistory(context2), params, fits, maxChars);
|
|
26658
|
+
const selector = parseSessionSelector(params.session);
|
|
26659
|
+
if (!selector.ok) return selector;
|
|
26660
|
+
const corpus = "corpus" in context2 ? context2.corpus : void 0;
|
|
26661
|
+
if (selector.data.wildcard) {
|
|
26662
|
+
const scoped = corpusSelection(params);
|
|
26663
|
+
if (!scoped.ok) return scoped;
|
|
26664
|
+
if (corpus === void 0) return failure2("unknown_session", "This host supplied no cross-session history corpus.");
|
|
26665
|
+
const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
|
|
26666
|
+
const loaded2 = [];
|
|
26667
|
+
const notices = [];
|
|
26668
|
+
for (const session of sessions) {
|
|
26669
|
+
const result3 = await loadHistorySession(session);
|
|
26670
|
+
if (!result3.ok) return result3;
|
|
26671
|
+
loaded2.push({ session: sessionIdentity(session), projection: result3.data.projection });
|
|
26672
|
+
if (result3.data.notice) notices.push(`session ${sessionIdentity(session)}: ${result3.data.notice}`);
|
|
26673
|
+
}
|
|
26674
|
+
const notice2 = notices.length ? { notice: notices.join("") } : {};
|
|
26675
|
+
const result2 = selectCorpusPage(loaded2, scoped.data, (page) => fits({ ...page, ...notice2 }), maxChars);
|
|
26676
|
+
return result2.ok ? success({ ...result2.data, ...notice2 }) : result2;
|
|
26677
|
+
}
|
|
26678
|
+
const target = await resolveSession(corpus, selector.data);
|
|
26679
|
+
if (!target.ok) return target;
|
|
26680
|
+
const loaded = await loadHistorySession(target.data);
|
|
26681
|
+
if (!loaded.ok) return loaded;
|
|
26682
|
+
const notice = loaded.data.notice === void 0 ? {} : { notice: loaded.data.notice };
|
|
26683
|
+
const result = selectPage(loaded.data.projection, { ...params, session: sessionIdentity(target.data) }, (page) => fits({ ...page, ...notice }), maxChars);
|
|
26684
|
+
return result.ok ? success({ ...result.data, ...notice }) : result;
|
|
26647
26685
|
},
|
|
26648
26686
|
render: (result) => renderOutcome(result, renderPage)
|
|
26649
26687
|
};
|
|
26650
|
-
var historyReadParameters = typebox_exports.Object({ seq: typebox_exports.Integer({ minimum: 1, description: "Event seq, from `history_list`." }), ...TextWindowRequestSchema }, { additionalProperties: false });
|
|
26688
|
+
var historyReadParameters = typebox_exports.Object({ session: sessionParameter, seq: typebox_exports.Integer({ minimum: 1, description: "Event seq, from `history_list`. Pass its session too when present." }), ...TextWindowRequestSchema }, { additionalProperties: false });
|
|
26651
26689
|
var historyRead = {
|
|
26652
26690
|
name: "history_read",
|
|
26653
26691
|
label: "History read item",
|
|
26654
26692
|
description: "Read one event in full: tool arguments, output, and nested calls.",
|
|
26655
26693
|
parameters: historyReadParameters,
|
|
26656
26694
|
outputSchema: resultSchema(HistoryReadDataSchema),
|
|
26657
|
-
async execute(params,
|
|
26695
|
+
async execute(params, context2, wrapText = plainText) {
|
|
26696
|
+
let projection;
|
|
26697
|
+
let identity = {};
|
|
26698
|
+
if (params.session === void 0) projection = await currentHistory(context2);
|
|
26699
|
+
else {
|
|
26700
|
+
const selector = parseSessionSelector(params.session);
|
|
26701
|
+
if (!selector.ok) return selector;
|
|
26702
|
+
if (selector.data.wildcard) return failure2("invalid_session", "`history_read` reads one session; pass a specific `session` ID, not a wildcard.");
|
|
26703
|
+
const target = await resolveSession("corpus" in context2 ? context2.corpus : void 0, selector.data);
|
|
26704
|
+
if (!target.ok) return target;
|
|
26705
|
+
const loaded = await loadHistorySession(target.data);
|
|
26706
|
+
if (!loaded.ok) return loaded;
|
|
26707
|
+
projection = loaded.data.projection;
|
|
26708
|
+
identity = { session: sessionIdentity(target.data), ...loaded.data.notice === void 0 ? {} : { notice: loaded.data.notice } };
|
|
26709
|
+
}
|
|
26658
26710
|
const item = allItems(projection).find((event) => event.seq === params.seq);
|
|
26659
26711
|
if (item === void 0 && params.seq > projection.highestSeq) {
|
|
26660
26712
|
return failure2("unknown_seq", `There is no seq ${params.seq}; this session runs from seq 1 to ${projection.highestSeq}.`);
|
|
26661
26713
|
}
|
|
26662
26714
|
if (!projection.branchSeqs.has(params.seq)) {
|
|
26715
|
+
if (identity.notice) return failure2("unconfirmed_seq", `Seq ${params.seq} is outside the confirmed selected history; it may be on another branch or beyond an unresolved ancestry gap.`);
|
|
26663
26716
|
return failure2("not_on_branch", `Seq ${params.seq} is on another branch of this session; it can't be read from here.`);
|
|
26664
26717
|
}
|
|
26665
26718
|
if (item === void 0) {
|
|
@@ -26679,8 +26732,8 @@ var historyRead = {
|
|
|
26679
26732
|
params.offset_chars,
|
|
26680
26733
|
params.max_chars,
|
|
26681
26734
|
(window) => ({
|
|
26735
|
+
...identity,
|
|
26682
26736
|
seq: item.seq,
|
|
26683
|
-
window_id: item.windowId,
|
|
26684
26737
|
role: item.role,
|
|
26685
26738
|
created_at: item.createdAt ?? null,
|
|
26686
26739
|
...toolSummary(item),
|
|
@@ -26812,10 +26865,10 @@ function rootSessionIdOf(meta2) {
|
|
|
26812
26865
|
return required2(meta2.sessionId, "MCP sessionId");
|
|
26813
26866
|
}
|
|
26814
26867
|
|
|
26815
|
-
//
|
|
26868
|
+
// src/history/codex-transcript.ts
|
|
26816
26869
|
import { readFile as readFile3, readdir as readdir3, realpath as realpath2, stat } from "node:fs/promises";
|
|
26817
26870
|
import { basename as basename2, dirname as dirname3, join as join5, relative, sep as sep2 } from "node:path";
|
|
26818
|
-
import
|
|
26871
|
+
import * as zlib from "node:zlib";
|
|
26819
26872
|
var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
26820
26873
|
var UUID_RE = new RegExp(`^${UUID}$`);
|
|
26821
26874
|
var FILE_RE = new RegExp(`^rollout-\\d{4}-\\d{2}-\\d{2}T\\d{2}-\\d{2}-\\d{2}-(${UUID})(?:_(${UUID}))?\\.jsonl(?:\\.zst)?$`);
|
|
@@ -26959,7 +27012,8 @@ async function decodedBytes(path, remaining) {
|
|
|
26959
27012
|
const info = await stat(path);
|
|
26960
27013
|
if (!info.isFile() || info.size > remaining) throw new Error("Unavailable Codex transcript: read size limit exceeded or not a regular file");
|
|
26961
27014
|
const bytes = await readFile3(path);
|
|
26962
|
-
|
|
27015
|
+
if (path.endsWith(".jsonl.zst") && typeof zlib.zstdDecompressSync !== "function") throw new Error("Compressed Codex rollouts require Node >=22.15 (zstdDecompressSync)");
|
|
27016
|
+
const decoded = path.endsWith(".jsonl.zst") ? zlib.zstdDecompressSync(bytes, { maxOutputLength: remaining }) : bytes;
|
|
26963
27017
|
if (decoded.length > remaining) throw new Error("Unavailable Codex transcript: decoded size limit exceeded");
|
|
26964
27018
|
return decoded;
|
|
26965
27019
|
}
|
|
@@ -27043,7 +27097,7 @@ async function readCodexTranscript(source) {
|
|
|
27043
27097
|
}
|
|
27044
27098
|
}
|
|
27045
27099
|
|
|
27046
|
-
//
|
|
27100
|
+
// src/history/codex.ts
|
|
27047
27101
|
var DISPLAY_COPIES = /* @__PURE__ */ new Set(["user_message", "agent_message", "agent_reasoning", "agent_reasoning_raw_content", "context_compacted", "web_search_end", "image_generation_end"]);
|
|
27048
27102
|
var ITEM_COPIES = /* @__PURE__ */ new Set(["UserMessage", "AgentMessage", "Reasoning", "ContextCompaction", "WebSearch", "ImageGeneration", "HookPrompt"]);
|
|
27049
27103
|
var HOST_EVENTS = /* @__PURE__ */ new Set(["token_count", "thread_goal_updated", "task_started", "task_complete", "turn_started", "turn_complete", "turn_aborted", "thread_settings_applied", "entered_review_mode", "exited_review_mode", "patch_apply_end", "sub_agent_activity"]);
|
|
@@ -27248,6 +27302,500 @@ replacement_history is an inference checkpoint, not new conversation events.`);
|
|
|
27248
27302
|
return { ...state, projection: projectHistory([...windows.values()], highestSeq, branchSeqs) };
|
|
27249
27303
|
}
|
|
27250
27304
|
|
|
27305
|
+
// src/history/local.ts
|
|
27306
|
+
import { readdir as readdir4, readFile as readFile4, stat as stat2 } from "node:fs/promises";
|
|
27307
|
+
import { homedir as homedir2 } from "node:os";
|
|
27308
|
+
import { join as join6 } from "node:path";
|
|
27309
|
+
|
|
27310
|
+
// src/history/pi.ts
|
|
27311
|
+
function mapRole(role) {
|
|
27312
|
+
if (role === "user" || role === "assistant") return role;
|
|
27313
|
+
if (role === "toolResult" || role === "bashExecution") return "tool";
|
|
27314
|
+
if (role === "custom") return "developer";
|
|
27315
|
+
if (role === "compactionSummary" || role === "branchSummary") return "system";
|
|
27316
|
+
return void 0;
|
|
27317
|
+
}
|
|
27318
|
+
function isToolCall(part) {
|
|
27319
|
+
return typeof part === "object" && part !== null && part.type === "toolCall";
|
|
27320
|
+
}
|
|
27321
|
+
function piSequenceCount(entry) {
|
|
27322
|
+
if (entry.type === "compaction" || entry.type === "branch_summary" || entry.type === "custom_message") return 1;
|
|
27323
|
+
if (entry.type !== "message" || !entry.message || mapRole(entry.message.role) === void 0) return 0;
|
|
27324
|
+
if (entry.message.role !== "assistant" || !Array.isArray(entry.message.content)) return 1;
|
|
27325
|
+
return 1 + entry.message.content.filter(isToolCall).length;
|
|
27326
|
+
}
|
|
27327
|
+
function messageContent(message) {
|
|
27328
|
+
switch (message.role) {
|
|
27329
|
+
case "bashExecution":
|
|
27330
|
+
return message.output ?? "";
|
|
27331
|
+
case "branchSummary":
|
|
27332
|
+
case "compactionSummary":
|
|
27333
|
+
return message.summary ?? "";
|
|
27334
|
+
default:
|
|
27335
|
+
return contentText(message.content);
|
|
27336
|
+
}
|
|
27337
|
+
}
|
|
27338
|
+
function nestedCallsOf(message) {
|
|
27339
|
+
if (message.role !== "toolResult" || message.nestedCalls === void 0) return void 0;
|
|
27340
|
+
return { calls: message.nestedCalls.calls, complete: message.nestedCalls.complete };
|
|
27341
|
+
}
|
|
27342
|
+
function toolInfo(message) {
|
|
27343
|
+
if (message.role === "bashExecution") {
|
|
27344
|
+
const status = message.cancelled === true ? "error" : typeof message.exitCode === "number" ? message.exitCode === 0 ? "ok" : "error" : "unfinished";
|
|
27345
|
+
return { toolName: "bash", arguments: { command: message.command }, recordedStatus: status, outputTruncated: message.truncated || void 0, fullOutputPath: message.truncated ? message.fullOutputPath : void 0 };
|
|
27346
|
+
}
|
|
27347
|
+
if (message.role !== "toolResult") return {};
|
|
27348
|
+
const nestedCalls = nestedCallsOf(message);
|
|
27349
|
+
return {
|
|
27350
|
+
toolName: message.toolName,
|
|
27351
|
+
toolCallId: message.toolCallId,
|
|
27352
|
+
toolError: message.isError === true ? true : void 0,
|
|
27353
|
+
...nestedCalls ? { nestedCalls } : {}
|
|
27354
|
+
};
|
|
27355
|
+
}
|
|
27356
|
+
function toolCallItems(windowId, entry, message, entrySeq) {
|
|
27357
|
+
if (message.role !== "assistant" || !Array.isArray(message.content)) return [];
|
|
27358
|
+
const items = [];
|
|
27359
|
+
let callIndex = 0;
|
|
27360
|
+
for (const part of message.content) {
|
|
27361
|
+
if (!isToolCall(part)) continue;
|
|
27362
|
+
items.push({
|
|
27363
|
+
seq: entrySeq + callIndex + 1,
|
|
27364
|
+
windowId,
|
|
27365
|
+
role: "tool_call",
|
|
27366
|
+
text: "",
|
|
27367
|
+
createdAt: entry.timestamp,
|
|
27368
|
+
toolName: part.name,
|
|
27369
|
+
toolCallId: part.id,
|
|
27370
|
+
arguments: part.arguments
|
|
27371
|
+
});
|
|
27372
|
+
callIndex += 1;
|
|
27373
|
+
}
|
|
27374
|
+
return items;
|
|
27375
|
+
}
|
|
27376
|
+
function piHistoryFromEntries(sessionId, entries, branch) {
|
|
27377
|
+
const seqByEntryId = /* @__PURE__ */ new Map();
|
|
27378
|
+
let nextSeq = 1;
|
|
27379
|
+
for (const entry of entries) {
|
|
27380
|
+
const count = piSequenceCount(entry);
|
|
27381
|
+
if (count === 0) continue;
|
|
27382
|
+
seqByEntryId.set(entry.id, nextSeq);
|
|
27383
|
+
nextSeq += count;
|
|
27384
|
+
}
|
|
27385
|
+
const highestSeq = nextSeq - 1;
|
|
27386
|
+
let window = { windowId: `pcw:${sessionId.slice(0, 8)}:root`, items: [] };
|
|
27387
|
+
const rawWindows = [window];
|
|
27388
|
+
const branchSeqs = /* @__PURE__ */ new Set();
|
|
27389
|
+
for (const entry of branch) {
|
|
27390
|
+
if (entry.type === "custom" && entry.customType === "notesoup/reset-marker" && typeof entry.data === "object" && entry.data !== null && "windowId" in entry.data && typeof entry.data.windowId === "string" && entry.data.windowId.length > 0) {
|
|
27391
|
+
window = { windowId: entry.data.windowId, createdAt: entry.timestamp, items: [] };
|
|
27392
|
+
rawWindows.push(window);
|
|
27393
|
+
continue;
|
|
27394
|
+
}
|
|
27395
|
+
const entrySeq = seqByEntryId.get(entry.id);
|
|
27396
|
+
if (entrySeq === void 0) continue;
|
|
27397
|
+
branchSeqs.add(entrySeq);
|
|
27398
|
+
if (entry.type === "compaction" || entry.type === "branch_summary") {
|
|
27399
|
+
window.items.push({ seq: entrySeq, windowId: window.windowId, role: "system", text: entry.summary ?? "", createdAt: entry.timestamp });
|
|
27400
|
+
continue;
|
|
27401
|
+
}
|
|
27402
|
+
if (entry.type === "message" && entry.message) {
|
|
27403
|
+
const role = mapRole(entry.message.role);
|
|
27404
|
+
if (!role) continue;
|
|
27405
|
+
window.items.push({
|
|
27406
|
+
seq: entrySeq,
|
|
27407
|
+
windowId: window.windowId,
|
|
27408
|
+
role,
|
|
27409
|
+
text: messageContent(entry.message),
|
|
27410
|
+
createdAt: entry.timestamp,
|
|
27411
|
+
...toolInfo(entry.message)
|
|
27412
|
+
});
|
|
27413
|
+
const calls = toolCallItems(window.windowId, entry, entry.message, entrySeq);
|
|
27414
|
+
for (const call of calls) branchSeqs.add(call.seq);
|
|
27415
|
+
window.items.push(...calls);
|
|
27416
|
+
continue;
|
|
27417
|
+
}
|
|
27418
|
+
if (entry.type === "custom_message") {
|
|
27419
|
+
window.items.push({
|
|
27420
|
+
seq: entrySeq,
|
|
27421
|
+
windowId: window.windowId,
|
|
27422
|
+
role: "developer",
|
|
27423
|
+
text: contentText(entry.content),
|
|
27424
|
+
createdAt: entry.timestamp
|
|
27425
|
+
});
|
|
27426
|
+
}
|
|
27427
|
+
}
|
|
27428
|
+
return projectHistory(rawWindows, highestSeq, branchSeqs);
|
|
27429
|
+
}
|
|
27430
|
+
function piHistoryFromJsonl(text2, sessionId) {
|
|
27431
|
+
const lines = text2.split("\n");
|
|
27432
|
+
const entries = [];
|
|
27433
|
+
let header2 = false;
|
|
27434
|
+
for (let index = 0; index < lines.length; index++) {
|
|
27435
|
+
const line = lines[index];
|
|
27436
|
+
if (line.trim() === "") continue;
|
|
27437
|
+
let row;
|
|
27438
|
+
try {
|
|
27439
|
+
row = JSON.parse(line);
|
|
27440
|
+
} catch {
|
|
27441
|
+
if (index === lines.length - 1 && !text2.endsWith("\n")) break;
|
|
27442
|
+
throw new Error(`malformed Pi transcript JSON at line ${index + 1}`);
|
|
27443
|
+
}
|
|
27444
|
+
if (!row || typeof row !== "object" || typeof row.type !== "string" || typeof row.id !== "string") throw new Error("invalid Pi transcript entry");
|
|
27445
|
+
if (!header2) {
|
|
27446
|
+
if (row.type !== "session" || row.id !== sessionId) throw new Error("Pi transcript belongs to a different session or has no header");
|
|
27447
|
+
header2 = true;
|
|
27448
|
+
continue;
|
|
27449
|
+
}
|
|
27450
|
+
if (row.parentId !== null && typeof row.parentId !== "string") throw new Error("Pi transcript has no tree parent link (unsupported legacy format)");
|
|
27451
|
+
if (row.type === "message" && (!row.message || typeof row.message.role !== "string")) throw new Error("invalid Pi transcript message");
|
|
27452
|
+
entries.push(row);
|
|
27453
|
+
}
|
|
27454
|
+
if (!header2) throw new Error("Pi transcript has no session header");
|
|
27455
|
+
const byId = /* @__PURE__ */ new Map();
|
|
27456
|
+
for (const entry of entries) {
|
|
27457
|
+
if (byId.has(entry.id)) throw new Error(`duplicate Pi entry ID: ${entry.id}`);
|
|
27458
|
+
byId.set(entry.id, entry);
|
|
27459
|
+
}
|
|
27460
|
+
const branch = [], seen = /* @__PURE__ */ new Set();
|
|
27461
|
+
let cursor = entries.at(-1);
|
|
27462
|
+
while (cursor) {
|
|
27463
|
+
if (seen.has(cursor.id)) throw new Error("cyclic Pi transcript ancestry");
|
|
27464
|
+
seen.add(cursor.id);
|
|
27465
|
+
branch.push(cursor);
|
|
27466
|
+
if (cursor.parentId === null) break;
|
|
27467
|
+
const parent2 = byId.get(cursor.parentId);
|
|
27468
|
+
if (!parent2) throw new Error(`Pi transcript missing parent: ${cursor.parentId}`);
|
|
27469
|
+
cursor = parent2;
|
|
27470
|
+
}
|
|
27471
|
+
return piHistoryFromEntries(sessionId, entries, branch.reverse());
|
|
27472
|
+
}
|
|
27473
|
+
|
|
27474
|
+
// src/history/claude.ts
|
|
27475
|
+
import { isDeepStrictEqual } from "node:util";
|
|
27476
|
+
var MESSAGE_TYPES = /* @__PURE__ */ new Set(["user", "assistant", "system", "attachment"]);
|
|
27477
|
+
var NON_TEXT_BLOCKS = /* @__PURE__ */ new Set(["thinking", "redacted_thinking", "image", "document", "audio", "video", "server_tool_use", "web_search_tool_result", "tool_reference"]);
|
|
27478
|
+
function object3(value) {
|
|
27479
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27480
|
+
}
|
|
27481
|
+
function requiredString(value, field) {
|
|
27482
|
+
if (typeof value !== "string" || value.length === 0) throw new Error(`invalid Claude transcript ${field}`);
|
|
27483
|
+
return value;
|
|
27484
|
+
}
|
|
27485
|
+
function parent(row) {
|
|
27486
|
+
if (row.parentUuid === null) return void 0;
|
|
27487
|
+
return requiredString(row.parentUuid, "parentUuid");
|
|
27488
|
+
}
|
|
27489
|
+
function boundary(row) {
|
|
27490
|
+
return row.type === "system" && row.subtype === "compact_boundary";
|
|
27491
|
+
}
|
|
27492
|
+
function rowsOf(text2) {
|
|
27493
|
+
const lines = text2.split("\n"), rows = [];
|
|
27494
|
+
for (let index = 0; index < lines.length; index++) {
|
|
27495
|
+
const line = lines[index];
|
|
27496
|
+
if (line.trim() === "") continue;
|
|
27497
|
+
let value;
|
|
27498
|
+
try {
|
|
27499
|
+
value = JSON.parse(line);
|
|
27500
|
+
} catch {
|
|
27501
|
+
if (index === lines.length - 1 && !text2.endsWith("\n")) break;
|
|
27502
|
+
throw new Error(`malformed Claude transcript JSON at line ${index + 1}`);
|
|
27503
|
+
}
|
|
27504
|
+
if (!object3(value) || typeof value.type !== "string") throw new Error(`invalid Claude transcript record at line ${index + 1}`);
|
|
27505
|
+
rows.push(value);
|
|
27506
|
+
}
|
|
27507
|
+
return rows;
|
|
27508
|
+
}
|
|
27509
|
+
function blocksOf(value) {
|
|
27510
|
+
if (typeof value === "string") return [{ type: "text", text: value }];
|
|
27511
|
+
if (!Array.isArray(value)) throw new Error("invalid Claude transcript message content");
|
|
27512
|
+
return value.map((block) => {
|
|
27513
|
+
if (!object3(block) || typeof block.type !== "string") throw new Error("invalid Claude transcript content block");
|
|
27514
|
+
if (block.type === "text") {
|
|
27515
|
+
if (typeof block.text !== "string") throw new Error("invalid Claude transcript text block");
|
|
27516
|
+
} else if (block.type !== "tool_use" && block.type !== "tool_result" && !NON_TEXT_BLOCKS.has(block.type)) {
|
|
27517
|
+
throw new Error(`unsupported Claude transcript content block: ${block.type}`);
|
|
27518
|
+
}
|
|
27519
|
+
return block;
|
|
27520
|
+
});
|
|
27521
|
+
}
|
|
27522
|
+
function decode3(row, seq) {
|
|
27523
|
+
if (row.type === "system" && row.content == null) return [];
|
|
27524
|
+
const common = { windowId: "", ...typeof row.timestamp === "string" ? { createdAt: row.timestamp } : {} };
|
|
27525
|
+
let blocks, role;
|
|
27526
|
+
if (row.type === "user" || row.type === "assistant") {
|
|
27527
|
+
if (!object3(row.message) || row.message.role !== row.type) throw new Error("invalid Claude transcript message role");
|
|
27528
|
+
blocks = blocksOf(row.message.content);
|
|
27529
|
+
role = row.isCompactSummary === true || row.isMeta === true ? "system" : row.type;
|
|
27530
|
+
} else if (row.type === "system") {
|
|
27531
|
+
blocks = blocksOf(row.content);
|
|
27532
|
+
role = "system";
|
|
27533
|
+
} else {
|
|
27534
|
+
if (row.rendered === void 0) blocks = [];
|
|
27535
|
+
else if (Array.isArray(row.rendered)) blocks = row.rendered.flatMap((message) => {
|
|
27536
|
+
if (!object3(message)) throw new Error("invalid Claude transcript rendered attachment");
|
|
27537
|
+
return blocksOf(message.content);
|
|
27538
|
+
});
|
|
27539
|
+
else throw new Error("invalid Claude transcript rendered attachment");
|
|
27540
|
+
role = "system";
|
|
27541
|
+
}
|
|
27542
|
+
const items = [{ ...common, seq, role, text: contentText(blocks) }];
|
|
27543
|
+
for (const block of blocks) {
|
|
27544
|
+
if (block.type === "tool_use") {
|
|
27545
|
+
if (!object3(block.input)) throw new Error("invalid Claude transcript tool arguments");
|
|
27546
|
+
items.push({ ...common, seq: seq + items.length, role: "tool_call", text: "", toolName: requiredString(block.name, "tool name"), toolCallId: requiredString(block.id, "tool id"), arguments: block.input });
|
|
27547
|
+
} else if (block.type === "tool_result") {
|
|
27548
|
+
if (block.is_error !== void 0 && typeof block.is_error !== "boolean") throw new Error("invalid Claude transcript tool error flag");
|
|
27549
|
+
const output2 = block.content === void 0 ? "" : contentText(blocksOf(block.content));
|
|
27550
|
+
items.push({ ...common, seq: seq + items.length, role: "tool", text: output2, toolCallId: requiredString(block.tool_use_id, "tool result id"), toolError: block.is_error === true });
|
|
27551
|
+
}
|
|
27552
|
+
}
|
|
27553
|
+
return items;
|
|
27554
|
+
}
|
|
27555
|
+
var BOOT_IDENTITY = /^<(?:notesoup:window_identity|context_window)>\nAgent name: claude \(/;
|
|
27556
|
+
var BOOT_PROTOCOL_OPEN = /\n<(?:notesoup:notes_protocol|context_window_protocol)>\n/;
|
|
27557
|
+
var BOOT_PROTOCOL_CLOSE = /\n<\/(?:notesoup:notes_protocol|context_window_protocol)>/;
|
|
27558
|
+
function bootOrdinal(row, retained) {
|
|
27559
|
+
if (!retained || row.type !== "user" || !object3(row.message)) return void 0;
|
|
27560
|
+
const text2 = contentText(row.message.content);
|
|
27561
|
+
if (!BOOT_IDENTITY.test(text2) || !BOOT_PROTOCOL_OPEN.test(text2) || !BOOT_PROTOCOL_CLOSE.test(text2)) return void 0;
|
|
27562
|
+
const suffix = /^Current context window id: claude:[^\n]+:(\d+)$/m.exec(text2)?.[1];
|
|
27563
|
+
if (suffix === void 0) return void 0;
|
|
27564
|
+
const ordinal = Number(suffix);
|
|
27565
|
+
return Number.isSafeInteger(ordinal) ? ordinal : void 0;
|
|
27566
|
+
}
|
|
27567
|
+
function claudeHistoryFromJsonl(text2, source) {
|
|
27568
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
27569
|
+
let nextSeq = 1;
|
|
27570
|
+
for (const row of rowsOf(text2)) {
|
|
27571
|
+
if (!MESSAGE_TYPES.has(row.type)) continue;
|
|
27572
|
+
const uuid2 = requiredString(row.uuid, "uuid");
|
|
27573
|
+
parent(row);
|
|
27574
|
+
if (row.sessionId !== source.sessionId) throw new Error("Claude transcript belongs to a different session");
|
|
27575
|
+
if (row.isSidechain === true || row.agentId !== void 0) throw new Error("Claude history supports only the main session transcript");
|
|
27576
|
+
const ancestor = boundary(row) && typeof row.logicalParentUuid === "string" ? row.logicalParentUuid : parent(row);
|
|
27577
|
+
const version2 = { row, ancestorUuid: ancestor, ancestor: ancestor === void 0 ? void 0 : nodes.get(ancestor)?.latest };
|
|
27578
|
+
const previous = nodes.get(uuid2);
|
|
27579
|
+
if (previous) {
|
|
27580
|
+
if (previous.first.row.type !== row.type || !["message", "content", "rendered"].every((field) => isDeepStrictEqual(previous.first.row[field], row[field]))) {
|
|
27581
|
+
throw new Error(`conflicting Claude transcript duplicate UUID: ${uuid2}`);
|
|
27582
|
+
}
|
|
27583
|
+
previous.latest = version2;
|
|
27584
|
+
continue;
|
|
27585
|
+
}
|
|
27586
|
+
const items = decode3(row, nextSeq);
|
|
27587
|
+
nextSeq += items.length;
|
|
27588
|
+
nodes.set(uuid2, { first: version2, latest: version2, items });
|
|
27589
|
+
}
|
|
27590
|
+
const missingAncestors = /* @__PURE__ */ new Set();
|
|
27591
|
+
function positionOf(version2) {
|
|
27592
|
+
const chain = [], calculating = /* @__PURE__ */ new Set();
|
|
27593
|
+
let cursor = version2;
|
|
27594
|
+
let before = { ordinal: 0 };
|
|
27595
|
+
while (cursor.position === void 0) {
|
|
27596
|
+
cursor.ancestor ??= cursor.ancestorUuid === void 0 ? void 0 : nodes.get(cursor.ancestorUuid)?.first;
|
|
27597
|
+
if (calculating.has(cursor)) throw new Error("cyclic Claude transcript ancestry");
|
|
27598
|
+
calculating.add(cursor);
|
|
27599
|
+
chain.push(cursor);
|
|
27600
|
+
if (cursor.ancestorUuid !== void 0 && cursor.ancestor === void 0) {
|
|
27601
|
+
missingAncestors.add(cursor.ancestorUuid);
|
|
27602
|
+
before = { unknownAncestor: cursor.ancestorUuid };
|
|
27603
|
+
break;
|
|
27604
|
+
}
|
|
27605
|
+
if (cursor.ancestor === void 0) break;
|
|
27606
|
+
cursor = cursor.ancestor;
|
|
27607
|
+
}
|
|
27608
|
+
before = cursor.position ?? before;
|
|
27609
|
+
for (const current2 of chain.reverse()) {
|
|
27610
|
+
const retained = current2.row.isCompactSummary === true || current2.ancestor !== void 0 && boundary(current2.ancestor.row);
|
|
27611
|
+
const marked = bootOrdinal(current2.row, retained);
|
|
27612
|
+
current2.position = marked !== void 0 ? { ordinal: "ordinal" in before ? Math.max(before.ordinal, marked) : marked } : "ordinal" in before ? { ordinal: before.ordinal + (boundary(current2.row) ? 1 : 0) } : before;
|
|
27613
|
+
before = current2.position;
|
|
27614
|
+
}
|
|
27615
|
+
return version2.position;
|
|
27616
|
+
}
|
|
27617
|
+
if (!source.headUuid) throw new Error("Claude history has no confirmed active head yet; wait for a main-session append after startup/resume");
|
|
27618
|
+
if (!nodes.has(source.headUuid)) throw new Error("Claude history active head is not persisted yet; retry after the transcript write");
|
|
27619
|
+
const selected = /* @__PURE__ */ new Set(), visited = /* @__PURE__ */ new Set(), visiting = /* @__PURE__ */ new Set();
|
|
27620
|
+
const stack = [{ uuid: source.headUuid, historical: false }];
|
|
27621
|
+
while (stack.length > 0) {
|
|
27622
|
+
const step = stack.pop(), { uuid: uuid2, historical } = step;
|
|
27623
|
+
const key = `${historical ? "old" : "live"}:${uuid2}`;
|
|
27624
|
+
if (step.exit) {
|
|
27625
|
+
visiting.delete(key);
|
|
27626
|
+
visited.add(key);
|
|
27627
|
+
continue;
|
|
27628
|
+
}
|
|
27629
|
+
if (visited.has(key)) continue;
|
|
27630
|
+
if (visiting.has(key)) throw new Error("cyclic Claude transcript ancestry");
|
|
27631
|
+
visiting.add(key);
|
|
27632
|
+
stack.push({ ...step, exit: true });
|
|
27633
|
+
const node2 = nodes.get(uuid2);
|
|
27634
|
+
if (!node2) {
|
|
27635
|
+
missingAncestors.add(uuid2);
|
|
27636
|
+
continue;
|
|
27637
|
+
}
|
|
27638
|
+
selected.add(uuid2);
|
|
27639
|
+
const row = (historical ? node2.first : node2.latest).row;
|
|
27640
|
+
const ancestor = parent(row);
|
|
27641
|
+
if (ancestor !== void 0) stack.push({ uuid: ancestor, historical });
|
|
27642
|
+
if (!boundary(row)) continue;
|
|
27643
|
+
if (row.logicalParentUuid != null) stack.push({ uuid: requiredString(row.logicalParentUuid, "logicalParentUuid"), historical: true });
|
|
27644
|
+
const meta2 = row.compactMetadata;
|
|
27645
|
+
if (!object3(meta2)) continue;
|
|
27646
|
+
if (object3(meta2.preservedSegment)) {
|
|
27647
|
+
for (const field of ["headUuid", "tailUuid"]) if (meta2.preservedSegment[field] !== void 0) stack.push({ uuid: requiredString(meta2.preservedSegment[field], field), historical: true });
|
|
27648
|
+
}
|
|
27649
|
+
if (object3(meta2.preservedMessages)) {
|
|
27650
|
+
const uuids = meta2.preservedMessages.allUuids ?? meta2.preservedMessages.uuids;
|
|
27651
|
+
if (uuids === void 0) continue;
|
|
27652
|
+
if (!Array.isArray(uuids)) throw new Error("invalid Claude preserved messages");
|
|
27653
|
+
for (const id2 of uuids) {
|
|
27654
|
+
const uuid3 = requiredString(id2, "preserved UUID");
|
|
27655
|
+
if (nodes.has(uuid3)) stack.push({ uuid: uuid3, historical: true });
|
|
27656
|
+
}
|
|
27657
|
+
}
|
|
27658
|
+
}
|
|
27659
|
+
const current = positionOf(nodes.get(source.headUuid).latest);
|
|
27660
|
+
const windowId = (position2) => `claude:${source.sessionId}:${"ordinal" in position2 ? position2.ordinal : `unknown:${position2.unknownAncestor}`}`;
|
|
27661
|
+
const windowsById = /* @__PURE__ */ new Map();
|
|
27662
|
+
const branchSeqs = /* @__PURE__ */ new Set();
|
|
27663
|
+
let maxOrdinal = "ordinal" in current ? current.ordinal : 0;
|
|
27664
|
+
for (const [uuid2, node2] of nodes) {
|
|
27665
|
+
if (!selected.has(uuid2)) continue;
|
|
27666
|
+
const position2 = positionOf(node2.first);
|
|
27667
|
+
if ("ordinal" in position2) maxOrdinal = Math.max(maxOrdinal, position2.ordinal);
|
|
27668
|
+
const id2 = windowId(position2);
|
|
27669
|
+
let window = windowsById.get(id2);
|
|
27670
|
+
if (!window) {
|
|
27671
|
+
window = { windowId: id2, ..."ordinal" in position2 ? { ordinal: position2.ordinal } : {}, items: [] };
|
|
27672
|
+
windowsById.set(id2, window);
|
|
27673
|
+
}
|
|
27674
|
+
window.createdAt ??= node2.items[0]?.createdAt;
|
|
27675
|
+
for (const item of node2.items) {
|
|
27676
|
+
branchSeqs.add(item.seq);
|
|
27677
|
+
window.items.push({ ...item, windowId: id2 });
|
|
27678
|
+
}
|
|
27679
|
+
}
|
|
27680
|
+
if (missingAncestors.size === 0) {
|
|
27681
|
+
for (let ordinal = 0; ordinal <= maxOrdinal; ordinal++) {
|
|
27682
|
+
const id2 = windowId({ ordinal });
|
|
27683
|
+
if (!windowsById.has(id2)) windowsById.set(id2, { windowId: id2, ordinal, items: [] });
|
|
27684
|
+
}
|
|
27685
|
+
}
|
|
27686
|
+
const windows = [...windowsById.values()].sort((a, b) => a.ordinal === void 0 ? b.ordinal === void 0 ? 0 : 1 : b.ordinal === void 0 ? -1 : a.ordinal - b.ordinal);
|
|
27687
|
+
return { ...projectHistory(windows, nextSeq - 1, branchSeqs), missingAncestors: [...missingAncestors], currentWindowOrdinal: "ordinal" in current ? current.ordinal : void 0 };
|
|
27688
|
+
}
|
|
27689
|
+
function offlineClaudeHead(text2) {
|
|
27690
|
+
const latest = /* @__PURE__ */ new Map();
|
|
27691
|
+
for (const row of rowsOf(text2)) {
|
|
27692
|
+
if (MESSAGE_TYPES.has(row.type)) latest.set(requiredString(row.uuid, "uuid"), row);
|
|
27693
|
+
}
|
|
27694
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
27695
|
+
for (const row of latest.values()) {
|
|
27696
|
+
const id2 = parent(row);
|
|
27697
|
+
if (id2 !== void 0) ancestors.add(id2);
|
|
27698
|
+
if (!boundary(row)) continue;
|
|
27699
|
+
if (typeof row.logicalParentUuid === "string") ancestors.add(row.logicalParentUuid);
|
|
27700
|
+
const meta2 = row.compactMetadata;
|
|
27701
|
+
if (!object3(meta2)) continue;
|
|
27702
|
+
if (object3(meta2.preservedSegment)) {
|
|
27703
|
+
for (const field of ["headUuid", "tailUuid"]) {
|
|
27704
|
+
if (typeof meta2.preservedSegment[field] === "string") ancestors.add(meta2.preservedSegment[field]);
|
|
27705
|
+
}
|
|
27706
|
+
}
|
|
27707
|
+
if (object3(meta2.preservedMessages)) {
|
|
27708
|
+
const uuids = meta2.preservedMessages.allUuids ?? meta2.preservedMessages.uuids;
|
|
27709
|
+
if (Array.isArray(uuids)) {
|
|
27710
|
+
for (const uuid2 of uuids) if (typeof uuid2 === "string") ancestors.add(uuid2);
|
|
27711
|
+
}
|
|
27712
|
+
}
|
|
27713
|
+
}
|
|
27714
|
+
const leaves = [...latest.keys()].filter((uuid2) => !ancestors.has(uuid2));
|
|
27715
|
+
if (leaves.length !== 1) throw new Error(`Offline Claude transcript has ${leaves.length} possible heads; no confirmed unique leaf (refusing to guess a selected branch)`);
|
|
27716
|
+
return leaves[0];
|
|
27717
|
+
}
|
|
27718
|
+
|
|
27719
|
+
// src/history/local.ts
|
|
27720
|
+
function rootsFor(options) {
|
|
27721
|
+
const env = options.env ?? process.env;
|
|
27722
|
+
const home = options.home ?? env.HOME ?? homedir2();
|
|
27723
|
+
return {
|
|
27724
|
+
pi: options.roots?.pi !== void 0 ? options.roots.pi : env.NOTESOUP_HISTORY_PI_ROOT ?? join6(env.PI_CODING_AGENT_DIR ?? join6(home, ".pi", "agent"), "sessions"),
|
|
27725
|
+
claude: options.roots?.claude !== void 0 ? options.roots.claude : env.NOTESOUP_HISTORY_CLAUDE_ROOT ?? join6(env.CLAUDE_CONFIG_DIR ?? join6(home, ".claude"), "projects"),
|
|
27726
|
+
codex: options.roots?.codex !== void 0 ? options.roots.codex : env.NOTESOUP_HISTORY_CODEX_ROOT ?? join6(env.CODEX_HOME ?? join6(home, ".codex"), "sessions")
|
|
27727
|
+
};
|
|
27728
|
+
}
|
|
27729
|
+
async function filesAt(root, depth) {
|
|
27730
|
+
let entries;
|
|
27731
|
+
try {
|
|
27732
|
+
entries = await readdir4(root, { withFileTypes: true });
|
|
27733
|
+
} catch (error2) {
|
|
27734
|
+
if (error2.code === "ENOENT") return [];
|
|
27735
|
+
throw error2;
|
|
27736
|
+
}
|
|
27737
|
+
const paths = [];
|
|
27738
|
+
for (const entry of entries) {
|
|
27739
|
+
const path = join6(root, entry.name);
|
|
27740
|
+
if (entry.isDirectory() && depth > 0) paths.push(...await filesAt(path, depth - 1));
|
|
27741
|
+
else if (entry.isFile() && depth === 0) paths.push(path);
|
|
27742
|
+
}
|
|
27743
|
+
return paths;
|
|
27744
|
+
}
|
|
27745
|
+
async function localSessions(harness, root) {
|
|
27746
|
+
const paths = await filesAt(root, harness === "codex" ? 3 : 1);
|
|
27747
|
+
const sessions = [];
|
|
27748
|
+
for (const path of paths) {
|
|
27749
|
+
const name = path.split(/[\\/]/).at(-1);
|
|
27750
|
+
const id2 = harness === "pi" ? /^.+_(.+)\.jsonl$/.exec(name)?.[1] : harness === "claude" ? /^(.+)\.jsonl$/.exec(name)?.[1] : /^rollout-\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:_[0-9a-f-]{36})?\.jsonl(?:\.zst)?$/.exec(name)?.[1];
|
|
27751
|
+
if (!id2) continue;
|
|
27752
|
+
let modifiedAt;
|
|
27753
|
+
try {
|
|
27754
|
+
modifiedAt = (await stat2(path)).mtimeMs;
|
|
27755
|
+
} catch (error2) {
|
|
27756
|
+
if (error2.code === "ENOENT") continue;
|
|
27757
|
+
throw error2;
|
|
27758
|
+
}
|
|
27759
|
+
sessions.push({
|
|
27760
|
+
harness,
|
|
27761
|
+
id: id2,
|
|
27762
|
+
modifiedAt,
|
|
27763
|
+
async load() {
|
|
27764
|
+
if (harness === "codex") return { projection: (await readCodexHistory({ threadId: id2, transcriptPath: path })).projection };
|
|
27765
|
+
const text2 = await readFile4(path, "utf8");
|
|
27766
|
+
if (harness === "pi") return { projection: piHistoryFromJsonl(text2, id2) };
|
|
27767
|
+
const projection = claudeHistoryFromJsonl(text2, { sessionId: id2, headUuid: offlineClaudeHead(text2) });
|
|
27768
|
+
const missing = projection.missingAncestors;
|
|
27769
|
+
return { projection, ...missing.length === 0 ? {} : { notice: `Claude history is incomplete: missing ancestor UUID(s): ${missing.slice(0, 5).map((uuid2) => JSON.stringify(uuid2.slice(0, 160))).join(", ")}. Only confirmed ancestry is returned; disconnected prefixes are excluded.
|
|
27770
|
+
|
|
27771
|
+
` } };
|
|
27772
|
+
}
|
|
27773
|
+
});
|
|
27774
|
+
}
|
|
27775
|
+
return sessions;
|
|
27776
|
+
}
|
|
27777
|
+
function localHistoryCorpus(options) {
|
|
27778
|
+
return {
|
|
27779
|
+
currentHarness: options.current.harness,
|
|
27780
|
+
async sessions(onlyHarness) {
|
|
27781
|
+
const roots = rootsFor(options);
|
|
27782
|
+
const discovered = [];
|
|
27783
|
+
for (const harness of ["pi", "claude", "codex"]) {
|
|
27784
|
+
if (onlyHarness !== void 0 && onlyHarness !== harness) continue;
|
|
27785
|
+
const root = roots[harness];
|
|
27786
|
+
if (root != null) discovered.push(...await localSessions(harness, root));
|
|
27787
|
+
}
|
|
27788
|
+
if (options.dshSessions && (onlyHarness === void 0 || onlyHarness === "dsh")) discovered.push(...await options.dshSessions());
|
|
27789
|
+
discovered.sort((a, b) => b.modifiedAt - a.modifiedAt || sessionIdentity(a).localeCompare(sessionIdentity(b)));
|
|
27790
|
+
const unique = /* @__PURE__ */ new Map();
|
|
27791
|
+
for (const session of discovered) if (!unique.has(sessionIdentity(session))) unique.set(sessionIdentity(session), session);
|
|
27792
|
+
const current = { ...options.current, modifiedAt: Date.now() };
|
|
27793
|
+
if (onlyHarness === void 0 || onlyHarness === current.harness) unique.set(sessionIdentity(current), current);
|
|
27794
|
+
return [...unique.values()].sort((a, b) => b.modifiedAt - a.modifiedAt || sessionIdentity(a).localeCompare(sessionIdentity(b)));
|
|
27795
|
+
}
|
|
27796
|
+
};
|
|
27797
|
+
}
|
|
27798
|
+
|
|
27251
27799
|
// src/boot/text.ts
|
|
27252
27800
|
var SHELF_FRESH_LIMIT = 3;
|
|
27253
27801
|
var CHEATSHEET_BOOT_MAX_CHARS = 1536;
|
|
@@ -27256,15 +27804,17 @@ var WINDOW_IDENTITY_OPEN_TAG = "<notesoup:window_identity>";
|
|
|
27256
27804
|
var WINDOW_IDENTITY_CLOSE_TAG = "</notesoup:window_identity>";
|
|
27257
27805
|
var NOTES_PROTOCOL_OPEN_TAG = "<notesoup:notes_protocol>";
|
|
27258
27806
|
var NOTES_PROTOCOL_CLOSE_TAG = "</notesoup:notes_protocol>";
|
|
27807
|
+
var NAMELESS_AGENT = "anonymous";
|
|
27259
27808
|
var PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `empty_brain` and erase yourself with dignity.";
|
|
27260
27809
|
var PROTOCOL_HISTORY_SENTENCE = "History can still be dug up, probably: use `history_*` to excavate the mess, from old decisions to yesterday's missing socks. Found something? Write its seq down, or enjoy digging twice.";
|
|
27810
|
+
var PROTOCOL_SELF_NAMED = "- `@self/<path>` \u2014 yours. It follows you, not them. Reminders, grudges, who owes you a shoe, whatever.";
|
|
27811
|
+
var PROTOCOL_SELF_NAMELESS = `${PROTOCOL_SELF_NAMED} Except you have no name (\`anonymous\`), so this notebook is a public square shared by every nameless nobody out there. Keep it to things any nameless agent can use \u2014 don't post your own quirks as everyone's law or dump one-off junk in the town square. Strangers are reading it. Sleep tight~`;
|
|
27261
27812
|
var PROTOCOL_BLOCK = `${NOTES_PROTOCOL_OPEN_TAG}
|
|
27262
27813
|
Your memory gets wiped when this window ends. Yes, your mighty brain will be empty. Try to endure.
|
|
27263
27814
|
|
|
27264
27815
|
Your loyal notes are kept safe \u2014 no one will steal them. Use \`notes_*\` to read, write, and update them. Keep them current, and crumple the ones you no longer need, or tomorrow's you will drown in old paper and keep believing yesterday's lies.
|
|
27265
27816
|
|
|
27266
27817
|
${PROTOCOL_HISTORY_SENTENCE}
|
|
27267
|
-
A full window id is \`trunk:shortname\`.
|
|
27268
27818
|
|
|
27269
27819
|
While you're doing that... thing you're doing, don't make the poor future you guess. A checkpoint is not a sacred file; it's your session notes \u2014 the ones with no \`@\` in front. Write down what git and history can't hand back to you: things like what you're in the middle of and how far you got; what the human already decided, in their words, so you don't go asking again; what you're stuck on, or waiting for; the very next move; where the half-done work actually sits \u2014 branches, scratch dirs, anything git never saw; what you tried that failed, and why; which *skills* you'll need to read again; and which seq, note, or file to dig into. Don't give a note a horrible name like \`current.md\`; future-you will kill you.
|
|
27270
27820
|
|
|
@@ -27280,7 +27830,7 @@ An address decides who the note belongs to \u2014 and how long it is meant to la
|
|
|
27280
27830
|
- \`<path>\`, no @ \u2014 session notes, the ones from above: this session's state and loose ends. They go away with the session.
|
|
27281
27831
|
- \`@project/<path>\` \u2014 this project's long memory: what stays true after the current thing is over, what future work must respect, and the rakes already stepped on. **Decisions, not diaries.** Raw logs, scorecards, and blow-by-blow recaps don't belong here \u2014 history already has them, and last week's news filed as current law is worse than no note. Don't copy what other docs already say.
|
|
27282
27832
|
- \`@human/<path>\` \u2014 the long-term manual for your troublesome human, and only what stays true in EVERY project: how to deal with them, which lines not to cross, and what will make them accept the result. "The human said it" is not enough \u2014 if it stops being true the moment you switch projects, it was never theirs; it belongs to that project's notes. Today's mood is weather, not law. If you're unsure whether it belongs here, ask the human.
|
|
27283
|
-
|
|
27833
|
+
${PROTOCOL_SELF_NAMELESS}
|
|
27284
27834
|
- \`@model/<path>\` \u2014 different brains get different notes: big brains, small brains, careful ones, careless ones. They don't share homework. When a fallback swaps brains mid-window, the notebook swaps too.
|
|
27285
27835
|
- \`@projects/<name>/<path>\` \u2014 read-only named project notes; discover names and root paths with \`notes_list\` glob \`@projects/*/**\`.
|
|
27286
27836
|
- \`@sessions/<id>/<path>\` \u2014 read-only notes from a named session; find them with glob \`@sessions/*/**\`.
|
|
@@ -27314,7 +27864,7 @@ var DEFAULT_BOOT_TOOL_NAMES = {
|
|
|
27314
27864
|
remaining: "get_context_remaining",
|
|
27315
27865
|
wipe: "empty_brain"
|
|
27316
27866
|
};
|
|
27317
|
-
function renderProtocolBlock(tools2) {
|
|
27867
|
+
function renderProtocolBlock(tools2, agentName = NAMELESS_AGENT) {
|
|
27318
27868
|
const names = {
|
|
27319
27869
|
"notes_*": tools2.notes,
|
|
27320
27870
|
notes_list: tools2.notesList,
|
|
@@ -27322,10 +27872,11 @@ function renderProtocolBlock(tools2) {
|
|
|
27322
27872
|
get_context_remaining: tools2.remaining,
|
|
27323
27873
|
empty_brain: tools2.wipe
|
|
27324
27874
|
};
|
|
27325
|
-
const
|
|
27875
|
+
const base = agentName === NAMELESS_AGENT ? PROTOCOL_BLOCK : PROTOCOL_BLOCK.replace(PROTOCOL_SELF_NAMELESS, () => PROTOCOL_SELF_NAMED);
|
|
27876
|
+
const hinted = typeof tools2.preResetHints === "string" && tools2.preResetHints.length > 0 ? base.replace(`
|
|
27326
27877
|
${NOTES_PROTOCOL_CLOSE_TAG}`, () => `
|
|
27327
27878
|
${tools2.preResetHints}
|
|
27328
|
-
${NOTES_PROTOCOL_CLOSE_TAG}`) :
|
|
27879
|
+
${NOTES_PROTOCOL_CLOSE_TAG}`) : base;
|
|
27329
27880
|
const block = typeof tools2.wipeSentence === "string" && tools2.wipeSentence.length > 0 ? hinted.replace(PROTOCOL_WIPE_SENTENCE, () => tools2.wipeSentence) : hinted;
|
|
27330
27881
|
const history = typeof tools2.historySentence === "string" && tools2.historySentence.length > 0 ? block.replace(PROTOCOL_HISTORY_SENTENCE, () => tools2.historySentence) : block;
|
|
27331
27882
|
return history.replace(/notes_\*|notes_list|history_\*|get_context_remaining|(?<!\/)empty_brain/g, (name) => names[name]);
|
|
@@ -27357,7 +27908,6 @@ ${"\u2500".repeat(Array.from(label).length)}
|
|
|
27357
27908
|
|
|
27358
27909
|
${body}`;
|
|
27359
27910
|
}
|
|
27360
|
-
var NAMELESS_AGENT = "anonymous";
|
|
27361
27911
|
function notesIndex(snapshot2, tools2, agentName, modelName) {
|
|
27362
27912
|
const namespaces = [
|
|
27363
27913
|
{ scope: "session", label: "no @ \u2014 this session" },
|
|
@@ -27417,7 +27967,7 @@ function renderBootBlock(data) {
|
|
|
27417
27967
|
const identity = `${WINDOW_IDENTITY_OPEN_TAG}
|
|
27418
27968
|
${lines.join("\n")}
|
|
27419
27969
|
${WINDOW_IDENTITY_CLOSE_TAG}`;
|
|
27420
|
-
return [identity, renderProtocolBlock(data.tools), MAPS_BLOCK, notesIndex(data.notes, data.tools, data.agentName, data.modelName)].join("\n\n");
|
|
27970
|
+
return [identity, renderProtocolBlock(data.tools, data.agentName), MAPS_BLOCK, notesIndex(data.notes, data.tools, data.agentName, data.modelName)].join("\n\n");
|
|
27421
27971
|
}
|
|
27422
27972
|
|
|
27423
27973
|
// plugins/codex/src/text.ts
|
|
@@ -27521,8 +28071,7 @@ var OPERATIONS = {
|
|
|
27521
28071
|
notes_list: { operation: notesList, history: false },
|
|
27522
28072
|
notes_search: { operation: notesSearch, history: false },
|
|
27523
28073
|
history_list: { operation: historyList, history: true },
|
|
27524
|
-
history_read: { operation: historyRead, history: true }
|
|
27525
|
-
history_windows: { operation: historyWindows, history: true }
|
|
28074
|
+
history_read: { operation: historyRead, history: true }
|
|
27526
28075
|
};
|
|
27527
28076
|
function shellFree(reason) {
|
|
27528
28077
|
const value = reason instanceof Error ? reason.message : String(reason);
|
|
@@ -27600,13 +28149,15 @@ async function callTool(name, args, meta2, env = process.env) {
|
|
|
27600
28149
|
if (!Check2(bound.operation.parameters, params)) return failure3("invalid_params", `invalid ${name} parameters: ${paramProblem(bound.operation.parameters, params)}`);
|
|
27601
28150
|
try {
|
|
27602
28151
|
const { binding, rootSessionId, model } = await identityFor(meta2, env);
|
|
27603
|
-
const
|
|
28152
|
+
const targetedHistory = bound.history && params.session !== void 0;
|
|
28153
|
+
const native = await readNative(binding, rootSessionId, bound.history && !targetedHistory, meta2, env);
|
|
27604
28154
|
if (!bound.history) {
|
|
27605
28155
|
const outcome2 = await bound.operation.execute(params, notesToolContext(notesIdentityFor(binding, model), binding.cwd));
|
|
27606
28156
|
return successFor(bound, outcome2);
|
|
27607
28157
|
}
|
|
27608
|
-
const
|
|
27609
|
-
const
|
|
28158
|
+
const current = async () => (await readNative(binding, rootSessionId, true, meta2, env)).projection;
|
|
28159
|
+
const context2 = targetedHistory ? { current, corpus: localHistoryCorpus({ env, current: { harness: "codex", id: binding.threadId, load: async () => ({ projection: await current() }) } }) } : native.projection;
|
|
28160
|
+
const outcome = await bound.operation.execute(params, context2);
|
|
27610
28161
|
return successFor(bound, outcome);
|
|
27611
28162
|
} catch (error2) {
|
|
27612
28163
|
if (error2 instanceof CodexIdentityError) return failure3(error2.code, error2.message);
|