@wrongstack/core 0.5.0 → 0.5.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/dist/{agent-bridge-BkjOkSkD.d.ts → agent-bridge-EiUFe3if.d.ts} +1 -1
- package/dist/{compactor-CTHjZAwf.d.ts → compactor-BP4xhKVi.d.ts} +1 -1
- package/dist/{config-DO2eCKgq.d.ts → config-BOD_HQBw.d.ts} +1 -1
- package/dist/{context-P207fTpo.d.ts → context-PH4DvBZV.d.ts} +49 -1
- package/dist/coordination/index.d.ts +9 -9
- package/dist/coordination/index.js +93 -2
- package/dist/coordination/index.js.map +1 -1
- package/dist/defaults/index.d.ts +18 -18
- package/dist/defaults/index.js +93 -2
- package/dist/defaults/index.js.map +1 -1
- package/dist/director-state-CVzkjKRZ.d.ts +539 -0
- package/dist/{events-DYAbU84e.d.ts → events-oxn-Wkub.d.ts} +18 -1
- package/dist/execution/index.d.ts +11 -11
- package/dist/extension/index.d.ts +6 -6
- package/dist/{index-BHL8QDCL.d.ts → index-CcbWbcpy.d.ts} +5 -5
- package/dist/{index-BNzUUDVR.d.ts → index-a12jc7-r.d.ts} +5 -5
- package/dist/index.d.ts +27 -25
- package/dist/index.js +266 -23
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/index.d.ts +6 -6
- package/dist/kernel/index.d.ts +9 -9
- package/dist/kernel/index.js.map +1 -1
- package/dist/{mcp-servers-CLkhKdnF.d.ts → mcp-servers-uPmBxZ1B.d.ts} +3 -3
- package/dist/models/index.d.ts +2 -2
- package/dist/{multi-agent-B1Nn9eC0.d.ts → multi-agent-D6S4Z7H8.d.ts} +2 -2
- package/dist/observability/index.d.ts +2 -2
- package/dist/{path-resolver-mPccVA0l.d.ts → path-resolver-CprD5DhS.d.ts} +2 -2
- package/dist/{provider-runner-D7lHu07L.d.ts → provider-runner-DGisz_lG.d.ts} +3 -3
- package/dist/{retry-policy-CnYVKGPv.d.ts → retry-policy-DUJ8-Qc_.d.ts} +1 -1
- package/dist/sdd/index.d.ts +3 -3
- package/dist/{secret-scrubber-Buo9zLGs.d.ts → secret-scrubber-CB11A2P7.d.ts} +1 -1
- package/dist/{secret-scrubber-BSgec8CU.d.ts → secret-scrubber-EqFa0SyI.d.ts} +1 -1
- package/dist/security/index.d.ts +3 -3
- package/dist/{selector-B-CGOshv.d.ts → selector-yqyxt-Ii.d.ts} +1 -1
- package/dist/{session-reader-DmOEmSkq.d.ts → session-reader-1tOyoY1s.d.ts} +1 -1
- package/dist/session-rewinder-C9HnMkhP.d.ts +23 -0
- package/dist/storage/index.d.ts +21 -534
- package/dist/storage/index.js +246 -3
- package/dist/storage/index.js.map +1 -1
- package/dist/{system-prompt-CzY1zrbC.d.ts → system-prompt-BJlzKGO6.d.ts} +1 -1
- package/dist/{tool-executor-CYe5cp5U.d.ts → tool-executor-B6kRcWeF.d.ts} +4 -4
- package/dist/types/index.d.ts +16 -15
- package/dist/utils/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/storage/index.js
CHANGED
|
@@ -186,7 +186,7 @@ var DefaultSessionStore = class {
|
|
|
186
186
|
);
|
|
187
187
|
}
|
|
188
188
|
try {
|
|
189
|
-
return new FileSessionWriter(id, handle, startedAt, meta, { dir: this.dir, filePath: file });
|
|
189
|
+
return new FileSessionWriter(id, handle, startedAt, meta, this.events, { dir: this.dir, filePath: file });
|
|
190
190
|
} catch (err) {
|
|
191
191
|
await handle.close().catch(() => {
|
|
192
192
|
});
|
|
@@ -214,6 +214,7 @@ var DefaultSessionStore = class {
|
|
|
214
214
|
model: data.metadata.model,
|
|
215
215
|
provider: data.metadata.provider
|
|
216
216
|
},
|
|
217
|
+
this.events,
|
|
217
218
|
{ resumed: true, dir: this.dir, filePath: file }
|
|
218
219
|
);
|
|
219
220
|
return { writer, data };
|
|
@@ -377,11 +378,12 @@ var DefaultSessionStore = class {
|
|
|
377
378
|
}
|
|
378
379
|
};
|
|
379
380
|
var FileSessionWriter = class {
|
|
380
|
-
constructor(id, handle, startedAt, meta, opts = {}) {
|
|
381
|
+
constructor(id, handle, startedAt, meta, events, opts = {}) {
|
|
381
382
|
this.id = id;
|
|
382
383
|
this.handle = handle;
|
|
383
384
|
this.startedAt = startedAt;
|
|
384
385
|
this.meta = meta;
|
|
386
|
+
this.events = events;
|
|
385
387
|
this.resumed = opts.resumed ?? false;
|
|
386
388
|
this.manifestFile = opts.dir ? path2.join(opts.dir, `${id}.summary.json`) : "";
|
|
387
389
|
this.filePath = opts.filePath ?? "";
|
|
@@ -398,6 +400,7 @@ var FileSessionWriter = class {
|
|
|
398
400
|
handle;
|
|
399
401
|
startedAt;
|
|
400
402
|
meta;
|
|
403
|
+
events;
|
|
401
404
|
closed = false;
|
|
402
405
|
closing = false;
|
|
403
406
|
manifestFile;
|
|
@@ -415,6 +418,13 @@ var FileSessionWriter = class {
|
|
|
415
418
|
resumed;
|
|
416
419
|
appendFailCount = 0;
|
|
417
420
|
lastAppendWarnAt = 0;
|
|
421
|
+
// Rewind support: track pending file changes and prompt index
|
|
422
|
+
promptIndex = 0;
|
|
423
|
+
pendingFileSnapshots = [];
|
|
424
|
+
// Register a pending file change. Call recordFileChange() from tools.
|
|
425
|
+
recordFileChange(input) {
|
|
426
|
+
this.pendingFileSnapshots.push(input);
|
|
427
|
+
}
|
|
418
428
|
async writeSessionStartLazy() {
|
|
419
429
|
const record = `${JSON.stringify({
|
|
420
430
|
type: this.resumed ? "session_resumed" : "session_start",
|
|
@@ -490,6 +500,87 @@ var FileSessionWriter = class {
|
|
|
490
500
|
} catch {
|
|
491
501
|
}
|
|
492
502
|
}
|
|
503
|
+
async writeCheckpoint(promptIndex, promptPreview) {
|
|
504
|
+
const fileCount = this.pendingFileSnapshots.length;
|
|
505
|
+
if (fileCount > 0) {
|
|
506
|
+
await this.writeFileSnapshot(promptIndex, [...this.pendingFileSnapshots]);
|
|
507
|
+
this.pendingFileSnapshots = [];
|
|
508
|
+
}
|
|
509
|
+
this.promptIndex = promptIndex + 1;
|
|
510
|
+
await this.append({
|
|
511
|
+
type: "checkpoint",
|
|
512
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
513
|
+
promptIndex,
|
|
514
|
+
promptPreview
|
|
515
|
+
});
|
|
516
|
+
this.events?.emit("checkpoint.written", {
|
|
517
|
+
promptIndex,
|
|
518
|
+
promptPreview,
|
|
519
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
520
|
+
fileCount
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
async writeFileSnapshot(promptIndex, files) {
|
|
524
|
+
await this.append({
|
|
525
|
+
type: "file_snapshot",
|
|
526
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
527
|
+
promptIndex,
|
|
528
|
+
files
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
async truncateToCheckpoint(targetPromptIndex) {
|
|
532
|
+
if (!this.filePath) return 0;
|
|
533
|
+
const raw = await fsp.readFile(this.filePath, "utf8");
|
|
534
|
+
const lines = raw.split("\n");
|
|
535
|
+
const kept = [];
|
|
536
|
+
let removedCount = 0;
|
|
537
|
+
let targetCheckpointLine = -1;
|
|
538
|
+
let afterTarget = false;
|
|
539
|
+
for (let i = 0; i < lines.length; i++) {
|
|
540
|
+
const line = lines[i];
|
|
541
|
+
if (!line.trim()) continue;
|
|
542
|
+
let event;
|
|
543
|
+
try {
|
|
544
|
+
event = JSON.parse(line);
|
|
545
|
+
} catch {
|
|
546
|
+
kept.push(line);
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
if (event.type === "checkpoint") {
|
|
550
|
+
if (event.promptIndex === targetPromptIndex) {
|
|
551
|
+
targetCheckpointLine = kept.length;
|
|
552
|
+
afterTarget = true;
|
|
553
|
+
} else if (event.promptIndex > targetPromptIndex) {
|
|
554
|
+
afterTarget = true;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
if (event.promptIndex !== void 0 && event.promptIndex > targetPromptIndex) {
|
|
558
|
+
removedCount++;
|
|
559
|
+
} else if (event.promptIndex === void 0) {
|
|
560
|
+
if (!afterTarget || targetCheckpointLine === -1) {
|
|
561
|
+
kept.push(line);
|
|
562
|
+
} else {
|
|
563
|
+
removedCount++;
|
|
564
|
+
}
|
|
565
|
+
} else {
|
|
566
|
+
kept.push(line);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
const truncated = kept.join("\n");
|
|
570
|
+
await fsp.writeFile(this.filePath, truncated + "\n", "utf8");
|
|
571
|
+
await this.append({
|
|
572
|
+
type: "rewound",
|
|
573
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
574
|
+
toPromptIndex: targetPromptIndex,
|
|
575
|
+
revertedFiles: []
|
|
576
|
+
});
|
|
577
|
+
this.events?.emit("session.rewound", {
|
|
578
|
+
toPromptIndex: targetPromptIndex,
|
|
579
|
+
revertedFiles: [],
|
|
580
|
+
removedEvents: removedCount
|
|
581
|
+
});
|
|
582
|
+
return removedCount;
|
|
583
|
+
}
|
|
493
584
|
};
|
|
494
585
|
function userInputTitle(content) {
|
|
495
586
|
if (typeof content === "string") return content.slice(0, 60);
|
|
@@ -1765,6 +1856,158 @@ var SessionAnalyzer = class {
|
|
|
1765
1856
|
return last - first;
|
|
1766
1857
|
}
|
|
1767
1858
|
};
|
|
1859
|
+
var DefaultSessionRewinder = class {
|
|
1860
|
+
constructor(sessionsDir) {
|
|
1861
|
+
this.sessionsDir = sessionsDir;
|
|
1862
|
+
}
|
|
1863
|
+
sessionsDir;
|
|
1864
|
+
async listCheckpoints(sessionId) {
|
|
1865
|
+
const file = path2.join(this.sessionsDir, `${sessionId}.jsonl`);
|
|
1866
|
+
const raw = await fsp.readFile(file, "utf8");
|
|
1867
|
+
const events = parseEvents(raw);
|
|
1868
|
+
const fileCountMap = /* @__PURE__ */ new Map();
|
|
1869
|
+
for (const event of events) {
|
|
1870
|
+
if (event.type === "file_snapshot") {
|
|
1871
|
+
const e = event;
|
|
1872
|
+
fileCountMap.set(e.promptIndex, (fileCountMap.get(e.promptIndex) ?? 0) + e.files.length);
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
const checkpoints = [];
|
|
1876
|
+
for (const event of events) {
|
|
1877
|
+
if (event.type === "checkpoint") {
|
|
1878
|
+
const e = event;
|
|
1879
|
+
checkpoints.push({
|
|
1880
|
+
promptIndex: e.promptIndex,
|
|
1881
|
+
promptPreview: e.promptPreview,
|
|
1882
|
+
ts: e.ts,
|
|
1883
|
+
fileCount: fileCountMap.get(e.promptIndex) ?? 0
|
|
1884
|
+
});
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
return checkpoints;
|
|
1888
|
+
}
|
|
1889
|
+
async rewindToCheckpoint(sessionId, checkpointIndex) {
|
|
1890
|
+
const file = path2.join(this.sessionsDir, `${sessionId}.jsonl`);
|
|
1891
|
+
const raw = await fsp.readFile(file, "utf8");
|
|
1892
|
+
const events = parseEvents(raw);
|
|
1893
|
+
let targetIdx = -1;
|
|
1894
|
+
for (let i = 0; i < events.length; i++) {
|
|
1895
|
+
const event = events[i];
|
|
1896
|
+
if (event.type === "checkpoint") {
|
|
1897
|
+
const checkpointEvent = event;
|
|
1898
|
+
if (checkpointEvent.promptIndex === checkpointIndex) {
|
|
1899
|
+
targetIdx = i;
|
|
1900
|
+
break;
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
if (targetIdx === -1) {
|
|
1905
|
+
throw new Error(`Checkpoint ${checkpointIndex} not found`);
|
|
1906
|
+
}
|
|
1907
|
+
const snapshotsToRevert = [];
|
|
1908
|
+
for (let i = targetIdx + 1; i < events.length; i++) {
|
|
1909
|
+
const event = events[i];
|
|
1910
|
+
if (event.type === "checkpoint") {
|
|
1911
|
+
break;
|
|
1912
|
+
}
|
|
1913
|
+
if (event.type === "file_snapshot") {
|
|
1914
|
+
const snapshotEvent = event;
|
|
1915
|
+
if (snapshotEvent.promptIndex >= checkpointIndex) {
|
|
1916
|
+
snapshotsToRevert.push({ promptIndex: snapshotEvent.promptIndex, files: snapshotEvent.files });
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
const result = await revertSnapshots(snapshotsToRevert);
|
|
1921
|
+
const removedEvents = events.length - targetIdx - 1;
|
|
1922
|
+
return { ...result, toPromptIndex: checkpointIndex, removedEvents };
|
|
1923
|
+
}
|
|
1924
|
+
async rewindLastN(sessionId, n) {
|
|
1925
|
+
const file = path2.join(this.sessionsDir, `${sessionId}.jsonl`);
|
|
1926
|
+
const raw = await fsp.readFile(file, "utf8");
|
|
1927
|
+
const events = parseEvents(raw);
|
|
1928
|
+
const checkpoints = [];
|
|
1929
|
+
for (const event of events) {
|
|
1930
|
+
if (event.type === "checkpoint") {
|
|
1931
|
+
checkpoints.push({ promptIndex: event.promptIndex, ts: event.ts });
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
if (checkpoints.length === 0) {
|
|
1935
|
+
return { revertedFiles: [], errors: [], toPromptIndex: 0, removedEvents: 0 };
|
|
1936
|
+
}
|
|
1937
|
+
checkpoints.sort((a, b) => b.promptIndex - a.promptIndex);
|
|
1938
|
+
const targetIndex = checkpoints[n]?.promptIndex ?? 0;
|
|
1939
|
+
const snapshotsToRevert = [];
|
|
1940
|
+
let shouldRevert = false;
|
|
1941
|
+
for (const event of events) {
|
|
1942
|
+
if (event.type === "checkpoint" && event.promptIndex === targetIndex) {
|
|
1943
|
+
shouldRevert = true;
|
|
1944
|
+
continue;
|
|
1945
|
+
}
|
|
1946
|
+
if (shouldRevert && event.type === "file_snapshot") {
|
|
1947
|
+
snapshotsToRevert.push({ promptIndex: event.promptIndex, files: event.files });
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
const result = await revertSnapshots(snapshotsToRevert.reverse());
|
|
1951
|
+
return { ...result, toPromptIndex: targetIndex, removedEvents: snapshotsToRevert.length };
|
|
1952
|
+
}
|
|
1953
|
+
async rewindToStart(sessionId) {
|
|
1954
|
+
const file = path2.join(this.sessionsDir, `${sessionId}.jsonl`);
|
|
1955
|
+
const raw = await fsp.readFile(file, "utf8");
|
|
1956
|
+
const events = parseEvents(raw);
|
|
1957
|
+
const allSnapshots = [];
|
|
1958
|
+
for (const event of events) {
|
|
1959
|
+
if (event.type === "file_snapshot") {
|
|
1960
|
+
allSnapshots.push({ promptIndex: event.promptIndex, files: event.files });
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
if (allSnapshots.length === 0) {
|
|
1964
|
+
return { revertedFiles: [], errors: [], toPromptIndex: 0, removedEvents: 0 };
|
|
1965
|
+
}
|
|
1966
|
+
const result = await revertSnapshots(allSnapshots.reverse());
|
|
1967
|
+
return { ...result, toPromptIndex: 0, removedEvents: allSnapshots.length };
|
|
1968
|
+
}
|
|
1969
|
+
};
|
|
1970
|
+
function parseEvents(raw) {
|
|
1971
|
+
const lines = raw.split("\n").filter((l) => l.trim());
|
|
1972
|
+
const events = [];
|
|
1973
|
+
for (const line of lines) {
|
|
1974
|
+
try {
|
|
1975
|
+
const parsed = JSON.parse(line);
|
|
1976
|
+
if (parsed !== null && typeof parsed === "object" && typeof parsed.type === "string" && typeof parsed.ts === "string") {
|
|
1977
|
+
events.push(parsed);
|
|
1978
|
+
}
|
|
1979
|
+
} catch {
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
return events;
|
|
1983
|
+
}
|
|
1984
|
+
async function revertSnapshots(snapshots) {
|
|
1985
|
+
const revertedFiles = [];
|
|
1986
|
+
const errors = [];
|
|
1987
|
+
for (const snapshot of snapshots) {
|
|
1988
|
+
for (const file of snapshot.files) {
|
|
1989
|
+
try {
|
|
1990
|
+
if (file.action === "deleted") {
|
|
1991
|
+
if (file.before !== null) {
|
|
1992
|
+
await fsp.writeFile(file.path, file.before, { mode: 420 });
|
|
1993
|
+
revertedFiles.push(file.path);
|
|
1994
|
+
}
|
|
1995
|
+
} else if (file.action === "created") {
|
|
1996
|
+
await fsp.unlink(file.path);
|
|
1997
|
+
revertedFiles.push(file.path);
|
|
1998
|
+
} else if (file.action === "modified") {
|
|
1999
|
+
if (file.before !== null) {
|
|
2000
|
+
await fsp.writeFile(file.path, file.before, { mode: 420 });
|
|
2001
|
+
revertedFiles.push(file.path);
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
} catch (err) {
|
|
2005
|
+
errors.push(`${file.path}: ${err instanceof Error ? err.message : String(err)}`);
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
return { revertedFiles, errors };
|
|
2010
|
+
}
|
|
1768
2011
|
async function loadTodosCheckpoint(filePath) {
|
|
1769
2012
|
let raw;
|
|
1770
2013
|
try {
|
|
@@ -2047,6 +2290,6 @@ var DirectorStateCheckpoint = class {
|
|
|
2047
2290
|
}
|
|
2048
2291
|
};
|
|
2049
2292
|
|
|
2050
|
-
export { ConfigMigrationError, DEFAULT_CONFIG_MIGRATIONS, DefaultAttachmentStore, DefaultConfigLoader, DefaultConfigStore, DefaultMemoryStore, DefaultSessionReader, DefaultSessionStore, DirectorStateCheckpoint, QueueStore, RecoveryLock, SessionAnalyzer, addPlanItem, attachPlanCheckpoint, attachTodosCheckpoint, clearPlan, emptyPlan, formatPlan, loadDirectorState, loadPlan, loadTodosCheckpoint, removePlanItem, runConfigMigrations, savePlan, saveTodosCheckpoint, setPlanItemStatus };
|
|
2293
|
+
export { ConfigMigrationError, DEFAULT_CONFIG_MIGRATIONS, DefaultAttachmentStore, DefaultConfigLoader, DefaultConfigStore, DefaultMemoryStore, DefaultSessionReader, DefaultSessionRewinder, DefaultSessionStore, DirectorStateCheckpoint, QueueStore, RecoveryLock, SessionAnalyzer, addPlanItem, attachPlanCheckpoint, attachTodosCheckpoint, clearPlan, emptyPlan, formatPlan, loadDirectorState, loadPlan, loadTodosCheckpoint, removePlanItem, runConfigMigrations, savePlan, saveTodosCheckpoint, setPlanItemStatus };
|
|
2051
2294
|
//# sourceMappingURL=index.js.map
|
|
2052
2295
|
//# sourceMappingURL=index.js.map
|