@wrongstack/core 0.5.7 → 0.6.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/dist/{agent-bridge-BKNiE1VH.d.ts → agent-bridge-DaCvA_uK.d.ts} +1 -1
- package/dist/coordination/index.d.ts +5 -5
- package/dist/coordination/index.js +218 -78
- package/dist/coordination/index.js.map +1 -1
- package/dist/defaults/index.d.ts +10 -9
- package/dist/defaults/index.js +1127 -180
- package/dist/defaults/index.js.map +1 -1
- package/dist/{events-DPQKFX7W.d.ts → events-CzkeaVVl.d.ts} +8 -2
- package/dist/execution/index.d.ts +281 -5
- package/dist/execution/index.js +785 -3
- package/dist/execution/index.js.map +1 -1
- package/dist/extension/index.d.ts +2 -2
- package/dist/extension/index.js +2 -1
- package/dist/extension/index.js.map +1 -1
- package/dist/goal-store-DVCfj7Ff.d.ts +95 -0
- package/dist/{index-j2WyAyML.d.ts → index-BkKLQjea.d.ts} +34 -2
- package/dist/{index-Bf9Bpkdc.d.ts → index-i9rPR53g.d.ts} +11 -4
- package/dist/index.d.ts +51 -16
- package/dist/index.js +1506 -247
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/index.d.ts +2 -2
- package/dist/kernel/index.d.ts +2 -2
- package/dist/kernel/index.js.map +1 -1
- package/dist/models/index.js +2 -3
- package/dist/models/index.js.map +1 -1
- package/dist/{multi-agent-Cpp7FXUl.d.ts → multi-agent-MfI6dmv-.d.ts} +30 -5
- package/dist/observability/index.d.ts +1 -1
- package/dist/{path-resolver--g_hKJ7V.d.ts → path-resolver-CWINz5XR.d.ts} +1 -1
- package/dist/{plan-templates-Bveo2W8n.d.ts → plan-templates-Bne1pB4d.d.ts} +6 -5
- package/dist/{provider-runner-hl4Il3xS.d.ts → provider-runner-CZYIzeBp.d.ts} +1 -1
- package/dist/sdd/index.d.ts +5 -3
- package/dist/sdd/index.js +102 -68
- package/dist/sdd/index.js.map +1 -1
- package/dist/security/index.js +82 -82
- package/dist/security/index.js.map +1 -1
- package/dist/skills/index.js +102 -38
- package/dist/skills/index.js.map +1 -1
- package/dist/storage/index.d.ts +3 -2
- package/dist/storage/index.js +134 -22
- package/dist/storage/index.js.map +1 -1
- package/dist/{tool-executor-DbAFkHdP.d.ts → tool-executor-40Q6shR-.d.ts} +1 -1
- package/dist/types/index.d.ts +7 -7
- package/dist/types/index.js +116 -103
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +5 -1
package/dist/storage/index.js
CHANGED
|
@@ -210,19 +210,25 @@ var DefaultSessionStore = class {
|
|
|
210
210
|
{ cause: err }
|
|
211
211
|
);
|
|
212
212
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
handle,
|
|
216
|
-
(/* @__PURE__ */ new Date()).toISOString(),
|
|
217
|
-
{
|
|
213
|
+
try {
|
|
214
|
+
const writer = new FileSessionWriter(
|
|
218
215
|
id,
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
216
|
+
handle,
|
|
217
|
+
(/* @__PURE__ */ new Date()).toISOString(),
|
|
218
|
+
{
|
|
219
|
+
id,
|
|
220
|
+
model: data.metadata.model,
|
|
221
|
+
provider: data.metadata.provider
|
|
222
|
+
},
|
|
223
|
+
this.events,
|
|
224
|
+
{ resumed: true, dir: this.dir, filePath: file }
|
|
225
|
+
);
|
|
226
|
+
return { writer, data };
|
|
227
|
+
} catch (err) {
|
|
228
|
+
await handle.close().catch(() => {
|
|
229
|
+
});
|
|
230
|
+
throw err;
|
|
231
|
+
}
|
|
226
232
|
}
|
|
227
233
|
async load(id) {
|
|
228
234
|
const file = path2.join(this.dir, `${id}.jsonl`);
|
|
@@ -268,7 +274,7 @@ var DefaultSessionStore = class {
|
|
|
268
274
|
const full = path2.join(this.dir, `${id}.jsonl`);
|
|
269
275
|
const stat3 = await fsp.stat(full);
|
|
270
276
|
const summary = await this.summarize(id, stat3.mtime.toISOString());
|
|
271
|
-
await
|
|
277
|
+
await atomicWrite(manifest, JSON.stringify(summary), { mode: 384 }).catch((err) => {
|
|
272
278
|
console.warn(
|
|
273
279
|
`[session-store] Failed to write manifest for "${id}":`,
|
|
274
280
|
err instanceof Error ? err.message : String(err)
|
|
@@ -496,7 +502,7 @@ var FileSessionWriter = class {
|
|
|
496
502
|
this.closed = true;
|
|
497
503
|
if (this.manifestFile) {
|
|
498
504
|
try {
|
|
499
|
-
await
|
|
505
|
+
await atomicWrite(this.manifestFile, JSON.stringify(this.summary), { mode: 384 });
|
|
500
506
|
} catch {
|
|
501
507
|
}
|
|
502
508
|
}
|
|
@@ -663,7 +669,9 @@ var DefaultAttachmentStore = class {
|
|
|
663
669
|
if (this.spoolDir && bytes >= this.spoolThreshold) {
|
|
664
670
|
await fsp.mkdir(this.spoolDir, { recursive: true });
|
|
665
671
|
spooledPath = path2.join(this.spoolDir, `${id}.bin`);
|
|
666
|
-
await
|
|
672
|
+
await atomicWrite(spooledPath, input.data, {
|
|
673
|
+
encoding: input.kind === "image" ? "base64" : "utf8"
|
|
674
|
+
});
|
|
667
675
|
data = void 0;
|
|
668
676
|
}
|
|
669
677
|
const att = {
|
|
@@ -774,12 +782,13 @@ var DefaultMemoryStore = class {
|
|
|
774
782
|
* issue order. Different scopes still proceed in parallel.
|
|
775
783
|
*
|
|
776
784
|
* The chain tracks only the last pending write. If a write fails, its
|
|
777
|
-
* error is caught and swallowed
|
|
778
|
-
*
|
|
779
|
-
*
|
|
780
|
-
* backup whose worst case is losing a memory consolidation pass.
|
|
785
|
+
* error is caught and swallowed so the chain stays alive for subsequent
|
|
786
|
+
* calls. The error is stored in `writeErrors` so callers can learn about
|
|
787
|
+
* it on the next read operation.
|
|
781
788
|
*/
|
|
782
789
|
writeChain = /* @__PURE__ */ new Map();
|
|
790
|
+
/** Last write error per scope — surfaced as warnings on the next readAll(). */
|
|
791
|
+
writeErrors = /* @__PURE__ */ new Map();
|
|
783
792
|
constructor(opts) {
|
|
784
793
|
this.files = {
|
|
785
794
|
"project-agents": opts.paths.inProjectAgentsFile,
|
|
@@ -789,10 +798,16 @@ var DefaultMemoryStore = class {
|
|
|
789
798
|
}
|
|
790
799
|
async runSerialized(scope, work) {
|
|
791
800
|
const prior = this.writeChain.get(scope) ?? Promise.resolve();
|
|
801
|
+
prior.catch((err) => {
|
|
802
|
+
this.writeErrors.set(scope, err);
|
|
803
|
+
});
|
|
792
804
|
const next = prior.catch(() => void 0).then(work);
|
|
793
805
|
this.writeChain.set(scope, next);
|
|
794
806
|
try {
|
|
795
807
|
return await next;
|
|
808
|
+
} catch (err) {
|
|
809
|
+
this.writeErrors.set(scope, err);
|
|
810
|
+
throw err;
|
|
796
811
|
} finally {
|
|
797
812
|
if (this.writeChain.get(scope) === next) {
|
|
798
813
|
this.writeChain.delete(scope);
|
|
@@ -802,6 +817,10 @@ var DefaultMemoryStore = class {
|
|
|
802
817
|
async readAll() {
|
|
803
818
|
const parts = [];
|
|
804
819
|
for (const scope of ["project-agents", "project-memory", "user-memory"]) {
|
|
820
|
+
const writeErr = this.writeErrors.get(scope);
|
|
821
|
+
if (writeErr) {
|
|
822
|
+
parts.push(`> \u26A0\uFE0F Memory write error (${labelOf(scope)}): ${writeErr.message}`);
|
|
823
|
+
}
|
|
805
824
|
const body = await this.read(scope);
|
|
806
825
|
if (body.trim()) parts.push(`## ${labelOf(scope)}
|
|
807
826
|
|
|
@@ -2009,7 +2028,7 @@ async function revertSnapshots(snapshots) {
|
|
|
2009
2028
|
try {
|
|
2010
2029
|
if (file.action === "deleted") {
|
|
2011
2030
|
if (file.before !== null) {
|
|
2012
|
-
await
|
|
2031
|
+
await atomicWrite(file.path, file.before, { mode: 420 });
|
|
2013
2032
|
revertedFiles.push(file.path);
|
|
2014
2033
|
}
|
|
2015
2034
|
} else if (file.action === "created") {
|
|
@@ -2017,7 +2036,7 @@ async function revertSnapshots(snapshots) {
|
|
|
2017
2036
|
revertedFiles.push(file.path);
|
|
2018
2037
|
} else if (file.action === "modified") {
|
|
2019
2038
|
if (file.before !== null) {
|
|
2020
|
-
await
|
|
2039
|
+
await atomicWrite(file.path, file.before, { mode: 420 });
|
|
2021
2040
|
revertedFiles.push(file.path);
|
|
2022
2041
|
}
|
|
2023
2042
|
}
|
|
@@ -2508,7 +2527,100 @@ var DirectorStateCheckpoint = class {
|
|
|
2508
2527
|
}
|
|
2509
2528
|
}
|
|
2510
2529
|
};
|
|
2530
|
+
var MAX_JOURNAL_ENTRIES = 500;
|
|
2531
|
+
function goalFilePath(projectRoot) {
|
|
2532
|
+
return path2.join(projectRoot, ".wrongstack", "goal.json");
|
|
2533
|
+
}
|
|
2534
|
+
async function loadGoal(filePath) {
|
|
2535
|
+
let raw;
|
|
2536
|
+
try {
|
|
2537
|
+
raw = await fsp.readFile(filePath, "utf8");
|
|
2538
|
+
} catch {
|
|
2539
|
+
return null;
|
|
2540
|
+
}
|
|
2541
|
+
try {
|
|
2542
|
+
const parsed = JSON.parse(raw);
|
|
2543
|
+
if (parsed?.version !== 1 || typeof parsed.goal !== "string" || !Array.isArray(parsed.journal)) {
|
|
2544
|
+
return null;
|
|
2545
|
+
}
|
|
2546
|
+
return parsed;
|
|
2547
|
+
} catch {
|
|
2548
|
+
return null;
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
async function saveGoal(filePath, goal) {
|
|
2552
|
+
await atomicWrite(filePath, JSON.stringify(goal, null, 2), { mode: 384 });
|
|
2553
|
+
}
|
|
2554
|
+
function emptyGoal(goal) {
|
|
2555
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2556
|
+
return {
|
|
2557
|
+
version: 1,
|
|
2558
|
+
goal,
|
|
2559
|
+
setAt: now,
|
|
2560
|
+
lastActivityAt: now,
|
|
2561
|
+
iterations: 0,
|
|
2562
|
+
engineState: "idle",
|
|
2563
|
+
goalState: "active",
|
|
2564
|
+
todoAttempts: {},
|
|
2565
|
+
journal: []
|
|
2566
|
+
};
|
|
2567
|
+
}
|
|
2568
|
+
function appendJournal(goal, entry) {
|
|
2569
|
+
const iteration = goal.iterations + 1;
|
|
2570
|
+
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
2571
|
+
const full = { ...entry, iteration, at };
|
|
2572
|
+
const journal = [...goal.journal, full];
|
|
2573
|
+
const trimmed = journal.length > MAX_JOURNAL_ENTRIES ? journal.slice(journal.length - MAX_JOURNAL_ENTRIES) : journal;
|
|
2574
|
+
return {
|
|
2575
|
+
...goal,
|
|
2576
|
+
iterations: iteration,
|
|
2577
|
+
lastActivityAt: at,
|
|
2578
|
+
journal: trimmed
|
|
2579
|
+
};
|
|
2580
|
+
}
|
|
2581
|
+
function summarizeUsage(goal) {
|
|
2582
|
+
let totalCostUsd = 0;
|
|
2583
|
+
let totalInputTokens = 0;
|
|
2584
|
+
let totalOutputTokens = 0;
|
|
2585
|
+
let iterationsWithUsage = 0;
|
|
2586
|
+
for (const e of goal.journal) {
|
|
2587
|
+
if (typeof e.costUsd === "number") totalCostUsd += e.costUsd;
|
|
2588
|
+
if (e.tokens) {
|
|
2589
|
+
totalInputTokens += e.tokens.input;
|
|
2590
|
+
totalOutputTokens += e.tokens.output;
|
|
2591
|
+
}
|
|
2592
|
+
if (typeof e.costUsd === "number" || e.tokens) iterationsWithUsage++;
|
|
2593
|
+
}
|
|
2594
|
+
return { totalCostUsd, totalInputTokens, totalOutputTokens, iterationsWithUsage };
|
|
2595
|
+
}
|
|
2596
|
+
function formatGoal(goal, journalLimit = 10) {
|
|
2597
|
+
const lines = [];
|
|
2598
|
+
lines.push(`Goal: ${goal.goal}`);
|
|
2599
|
+
lines.push(`Set: ${goal.setAt}`);
|
|
2600
|
+
lines.push(`Last activity: ${goal.lastActivityAt}`);
|
|
2601
|
+
lines.push(`Iterations: ${goal.iterations}`);
|
|
2602
|
+
lines.push(`Mission: ${goal.goalState ?? "active"}`);
|
|
2603
|
+
lines.push(`Engine: ${goal.engineState}`);
|
|
2604
|
+
const usage = summarizeUsage(goal);
|
|
2605
|
+
if (usage.iterationsWithUsage > 0) {
|
|
2606
|
+
lines.push(
|
|
2607
|
+
`Spent: $${usage.totalCostUsd.toFixed(4)} (in ${usage.totalInputTokens} / out ${usage.totalOutputTokens} tokens across ${usage.iterationsWithUsage} iterations)`
|
|
2608
|
+
);
|
|
2609
|
+
}
|
|
2610
|
+
if (goal.journal.length > 0) {
|
|
2611
|
+
lines.push("");
|
|
2612
|
+
lines.push(`Recent journal (last ${Math.min(journalLimit, goal.journal.length)}):`);
|
|
2613
|
+
const tail = goal.journal.slice(-journalLimit);
|
|
2614
|
+
for (const e of tail) {
|
|
2615
|
+
const mark = e.status === "success" ? "\u2713" : e.status === "failure" ? "\u2717" : e.status === "aborted" ? "\u2298" : "\xB7";
|
|
2616
|
+
const note = e.note ? ` \u2014 ${e.note}` : "";
|
|
2617
|
+
const cost = typeof e.costUsd === "number" ? ` ($${e.costUsd.toFixed(4)})` : "";
|
|
2618
|
+
lines.push(` #${e.iteration} ${mark} [${e.source}] ${e.task}${cost}${note}`);
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
return lines.join("\n");
|
|
2622
|
+
}
|
|
2511
2623
|
|
|
2512
|
-
export { ConfigMigrationError, DEFAULT_CONFIG_MIGRATIONS, DefaultAttachmentStore, DefaultConfigLoader, DefaultConfigStore, DefaultMemoryStore, DefaultSessionReader, DefaultSessionRewinder, DefaultSessionStore, DirectorStateCheckpoint, QueueStore, RecoveryLock, SessionAnalyzer, addPlanItem, attachPlanCheckpoint, attachTodosCheckpoint, clearPlan, deriveTodosFromPlanItem, emptyPlan, formatPlan, formatPlanTemplates, getPlanTemplate, listPlanTemplates, loadDirectorState, loadPlan, loadTodosCheckpoint, removePlanItem, runConfigMigrations, savePlan, saveTodosCheckpoint, setPlanItemStatus };
|
|
2624
|
+
export { ConfigMigrationError, DEFAULT_CONFIG_MIGRATIONS, DefaultAttachmentStore, DefaultConfigLoader, DefaultConfigStore, DefaultMemoryStore, DefaultSessionReader, DefaultSessionRewinder, DefaultSessionStore, DirectorStateCheckpoint, MAX_JOURNAL_ENTRIES, QueueStore, RecoveryLock, SessionAnalyzer, addPlanItem, appendJournal, attachPlanCheckpoint, attachTodosCheckpoint, clearPlan, deriveTodosFromPlanItem, emptyGoal, emptyPlan, formatGoal, formatPlan, formatPlanTemplates, getPlanTemplate, goalFilePath, listPlanTemplates, loadDirectorState, loadGoal, loadPlan, loadTodosCheckpoint, removePlanItem, runConfigMigrations, saveGoal, savePlan, saveTodosCheckpoint, setPlanItemStatus, summarizeUsage };
|
|
2513
2625
|
//# sourceMappingURL=index.js.map
|
|
2514
2626
|
//# sourceMappingURL=index.js.map
|