@wrongstack/core 0.6.6 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/{agent-bridge-BBXK_ppx.d.ts → agent-bridge-CrQpYjM7.d.ts} +1 -1
  2. package/dist/{compactor-C8NhpSt5.d.ts → compactor-CWV1u-IU.d.ts} +1 -1
  3. package/dist/{config-DfC6g6KV.d.ts → config-C34JRwl4.d.ts} +1 -1
  4. package/dist/{context-DN5v-uQX.d.ts → context-bmR0YgBm.d.ts} +74 -8
  5. package/dist/coordination/index.d.ts +11 -11
  6. package/dist/coordination/index.js +115 -39
  7. package/dist/coordination/index.js.map +1 -1
  8. package/dist/default-config-DvRSTELf.d.ts +20 -0
  9. package/dist/defaults/index.d.ts +20 -19
  10. package/dist/defaults/index.js +224 -64
  11. package/dist/defaults/index.js.map +1 -1
  12. package/dist/{events-CJqwQl8G.d.ts → events-CEKFTmIY.d.ts} +10 -1
  13. package/dist/execution/index.d.ts +27 -13
  14. package/dist/execution/index.js +153 -40
  15. package/dist/execution/index.js.map +1 -1
  16. package/dist/extension/index.d.ts +6 -6
  17. package/dist/extension/index.js +3 -1
  18. package/dist/extension/index.js.map +1 -1
  19. package/dist/{index-DcnXDPdY.d.ts → index-BJIFLGII.d.ts} +20 -5
  20. package/dist/{index-CXnWsGBp.d.ts → index-CZR0HjxM.d.ts} +14 -110
  21. package/dist/index.d.ts +27 -26
  22. package/dist/index.js +396 -180
  23. package/dist/index.js.map +1 -1
  24. package/dist/infrastructure/index.d.ts +6 -6
  25. package/dist/kernel/index.d.ts +9 -9
  26. package/dist/kernel/index.js +8 -4
  27. package/dist/kernel/index.js.map +1 -1
  28. package/dist/{mcp-servers-CevFHHM1.d.ts → mcp-servers-BRJicm5o.d.ts} +3 -3
  29. package/dist/models/index.d.ts +2 -2
  30. package/dist/{multi-agent-D5IbASk_.d.ts → multi-agent-Cm1wYSrw.d.ts} +9 -4
  31. package/dist/{agent-subagent-runner-DsSm9lKN.d.ts → multi-agent-coordinator-CCupVFqv.d.ts} +117 -4
  32. package/dist/observability/index.d.ts +2 -2
  33. package/dist/{path-resolver-CBx_q1HA.d.ts → path-resolver-CfT7e_HT.d.ts} +2 -2
  34. package/dist/{plan-templates-BEOllUJV.d.ts → plan-templates-Q78an-GJ.d.ts} +4 -4
  35. package/dist/{provider-runner-Byh5TcJs.d.ts → provider-runner-WDj28o7J.d.ts} +3 -3
  36. package/dist/{retry-policy-BZSIMxrJ.d.ts → retry-policy-Dpxp4SET.d.ts} +1 -1
  37. package/dist/sdd/index.d.ts +3 -3
  38. package/dist/{secret-scrubber-CT7wefiO.d.ts → secret-scrubber-C2YCYtkn.d.ts} +1 -1
  39. package/dist/{secret-scrubber-I0QHY_ob.d.ts → secret-scrubber-CowtdEF8.d.ts} +1 -1
  40. package/dist/security/index.d.ts +3 -3
  41. package/dist/{selector-DDb_mq9X.d.ts → selector-CP39HhCe.d.ts} +1 -1
  42. package/dist/{session-reader-B9nVkziM.d.ts → session-reader-Dwjn4WZR.d.ts} +1 -1
  43. package/dist/storage/index.d.ts +5 -5
  44. package/dist/storage/index.js +94 -11
  45. package/dist/storage/index.js.map +1 -1
  46. package/dist/{system-prompt-gL06H9P4.d.ts → system-prompt-CfgXqyv2.d.ts} +1 -1
  47. package/dist/{tool-executor-BF7QfYVE.d.ts → tool-executor-D5NFi_LV.d.ts} +5 -5
  48. package/dist/types/index.d.ts +16 -15
  49. package/dist/types/index.js +102 -23
  50. package/dist/types/index.js.map +1 -1
  51. package/dist/utils/index.d.ts +1 -1
  52. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { e as MetricsSink, M as MetricLabels, f as MetricsSnapshot, b as HealthRegistry, H as HealthCheck, A as AggregateHealth, T as Tracer, S as Span } from '../observability-BhnVLBLS.js';
2
- import { E as EventBus } from '../events-CJqwQl8G.js';
3
- import '../context-DN5v-uQX.js';
2
+ import { E as EventBus } from '../events-CEKFTmIY.js';
3
+ import '../context-bmR0YgBm.js';
4
4
 
5
5
  /**
6
6
  * In-memory metrics sink. Suitable for embedded use, tests, and /metrics
@@ -1,6 +1,6 @@
1
- import { E as EventBus } from './events-CJqwQl8G.js';
1
+ import { E as EventBus } from './events-CEKFTmIY.js';
2
2
  import { M as ModelsRegistry, b as ResolvedModel } from './models-registry-Y2xbog0E.js';
3
- import { a3 as TokenCounter, U as Usage, a4 as CacheStats } from './context-DN5v-uQX.js';
3
+ import { a6 as TokenCounter, U as Usage, a7 as CacheStats } from './context-bmR0YgBm.js';
4
4
  import { P as PathResolver } from './path-resolver-CPRj4bFY.js';
5
5
 
6
6
  /**
@@ -1,9 +1,9 @@
1
- import { E as EventBus } from './events-CJqwQl8G.js';
2
- import { p as SessionStore, o as SessionMetadata, r as SessionWriter, k as ResumedSession, S as SessionData, q as SessionSummary, b as ContentBlock, n as SessionEvent, a5 as TodoItem, a6 as ConversationState } from './context-DN5v-uQX.js';
3
- import { e as AttachmentStore, A as AddAttachmentInput, d as AttachmentRef, a as Attachment } from './session-reader-B9nVkziM.js';
1
+ import { E as EventBus } from './events-CEKFTmIY.js';
2
+ import { r as SessionStore, q as SessionMetadata, t as SessionWriter, m as ResumedSession, S as SessionData, s as SessionSummary, b as ContentBlock, p as SessionEvent, a8 as TodoItem, a9 as ConversationState } from './context-bmR0YgBm.js';
3
+ import { e as AttachmentStore, A as AddAttachmentInput, d as AttachmentRef, a as Attachment } from './session-reader-Dwjn4WZR.js';
4
4
  import { b as MemoryStore, a as MemoryScope } from './memory-CEXuo7sz.js';
5
5
  import { W as WstackPaths } from './wstack-paths-86YPFktR.js';
6
- import { c as ConfigStore, a as Config, b as ConfigLoader } from './config-DfC6g6KV.js';
6
+ import { c as ConfigStore, a as Config, b as ConfigLoader } from './config-C34JRwl4.js';
7
7
  import { S as SecretVault } from './secret-vault-DoISxaKO.js';
8
8
 
9
9
  interface SessionStoreOptions {
@@ -1,8 +1,8 @@
1
- import { E as EventBus } from './events-CJqwQl8G.js';
1
+ import { E as EventBus } from './events-CEKFTmIY.js';
2
2
  import { L as Logger } from './logger-BMQgxvdy.js';
3
3
  import { T as Tracer } from './observability-BhnVLBLS.js';
4
- import { g as Provider, R as Request, a2 as Context, j as Response } from './context-DN5v-uQX.js';
5
- import { R as RetryPolicy } from './retry-policy-BZSIMxrJ.js';
4
+ import { i as Provider, R as Request, a5 as Context, l as Response } from './context-bmR0YgBm.js';
5
+ import { R as RetryPolicy } from './retry-policy-Dpxp4SET.js';
6
6
 
7
7
  /**
8
8
  * Options passed to a ProviderRunner when calling the provider.
@@ -1,4 +1,4 @@
1
- import { j as Response, a2 as Context, h as ProviderError } from './context-DN5v-uQX.js';
1
+ import { l as Response, a5 as Context, j as ProviderError } from './context-bmR0YgBm.js';
2
2
 
3
3
  type RecoveryDecision = {
4
4
  /**
@@ -1,7 +1,7 @@
1
1
  import { h as Specification, S as SpecAnalysis, g as SpecValidationResult, l as TaskGraph, m as TaskNode, k as TaskFilter, p as TaskSort, o as TaskProgress, r as TaskType, n as TaskPriority, e as SpecStatus, f as SpecTemplate, b as SpecRequirement } from '../task-graph-D1YQbpxF.js';
2
- import { E as EventBus } from '../events-CJqwQl8G.js';
3
- import { D as DoneCondition } from '../multi-agent-D5IbASk_.js';
4
- import '../context-DN5v-uQX.js';
2
+ import { E as EventBus } from '../events-CEKFTmIY.js';
3
+ import { D as DoneCondition } from '../multi-agent-Cm1wYSrw.js';
4
+ import '../context-bmR0YgBm.js';
5
5
 
6
6
  declare class SpecParser {
7
7
  parse(content: string): Specification;
@@ -1,4 +1,4 @@
1
- import { v as Tool, a2 as Context, P as Permission } from './context-DN5v-uQX.js';
1
+ import { x as Tool, a5 as Context, P as Permission } from './context-bmR0YgBm.js';
2
2
 
3
3
  interface TrustPolicy {
4
4
  [toolNameOrPattern: string]: {
@@ -1,5 +1,5 @@
1
1
  import { S as SecretVault } from './secret-vault-DoISxaKO.js';
2
- import { S as SecretScrubber } from './secret-scrubber-CT7wefiO.js';
2
+ import { S as SecretScrubber } from './secret-scrubber-C2YCYtkn.js';
3
3
 
4
4
  interface SecretVaultOptions {
5
5
  /** Absolute path to the key file. Created with mode 0o600 if missing. */
@@ -1,7 +1,7 @@
1
- export { D as DefaultSecretScrubber, a as DefaultSecretVault, S as SecretVaultOptions, d as decryptConfigSecrets, e as encryptConfigSecrets, m as migratePlaintextSecrets, r as rewriteConfigEncrypted } from '../secret-scrubber-I0QHY_ob.js';
2
- import { v as Tool, a2 as Context } from '../context-DN5v-uQX.js';
1
+ export { D as DefaultSecretScrubber, a as DefaultSecretVault, S as SecretVaultOptions, d as decryptConfigSecrets, e as encryptConfigSecrets, m as migratePlaintextSecrets, r as rewriteConfigEncrypted } from '../secret-scrubber-CowtdEF8.js';
2
+ import { x as Tool, a5 as Context } from '../context-bmR0YgBm.js';
3
3
  import { I as InputReader } from '../input-reader-E-ffP2ee.js';
4
- import { a as PermissionPolicy, P as PermissionDecision } from '../secret-scrubber-CT7wefiO.js';
4
+ import { a as PermissionPolicy, P as PermissionDecision } from '../secret-scrubber-C2YCYtkn.js';
5
5
  import '../secret-vault-DoISxaKO.js';
6
6
 
7
7
  interface PermissionPolicyOptions {
@@ -1,4 +1,4 @@
1
- import { M as Message } from './context-DN5v-uQX.js';
1
+ import { M as Message } from './context-bmR0YgBm.js';
2
2
 
3
3
  /**
4
4
  * Result of LLM-driven message importance analysis.
@@ -1,4 +1,4 @@
1
- import { b as ContentBlock, n as SessionEvent, o as SessionMetadata, p as SessionStore } from './context-DN5v-uQX.js';
1
+ import { b as ContentBlock, p as SessionEvent, q as SessionMetadata, r as SessionStore } from './context-bmR0YgBm.js';
2
2
 
3
3
  type AttachmentKind = 'text' | 'image' | 'file';
4
4
  interface AttachmentMeta {
@@ -1,13 +1,13 @@
1
- export { A as AbandonedSession, a as AttachmentStoreOptions, C as ConfigLoaderOptions, b as ConfigMigration, c as ConfigMigrationError, d as ConfigSource, D as DEFAULT_CONFIG_MIGRATIONS, e as DefaultAttachmentStore, f as DefaultConfigLoader, g as DefaultConfigStore, h as DefaultMemoryStore, i as DefaultSessionStore, M as MemoryStoreOptions, j as MigrationContext, k as MigrationResult, P as PersistedQueueItem, l as PlanFile, m as PlanItem, n as PlanTemplate, Q as QueueStore, R as RecoveryLock, o as RecoveryLockOptions, S as SessionAnalyzer, p as SessionStoreOptions, T as TodosCheckpointFile, q as addPlanItem, r as attachPlanCheckpoint, s as attachTodosCheckpoint, t as clearPlan, u as deriveTodosFromPlanItem, v as emptyPlan, w as formatPlan, x as formatPlanTemplates, y as getPlanTemplate, z as listPlanTemplates, B as loadPlan, E as loadTodosCheckpoint, F as removePlanItem, G as runConfigMigrations, H as savePlan, I as saveTodosCheckpoint, J as setPlanItemStatus } from '../plan-templates-BEOllUJV.js';
2
- export { D as DefaultSessionReader } from '../session-reader-B9nVkziM.js';
1
+ export { A as AbandonedSession, a as AttachmentStoreOptions, C as ConfigLoaderOptions, b as ConfigMigration, c as ConfigMigrationError, d as ConfigSource, D as DEFAULT_CONFIG_MIGRATIONS, e as DefaultAttachmentStore, f as DefaultConfigLoader, g as DefaultConfigStore, h as DefaultMemoryStore, i as DefaultSessionStore, M as MemoryStoreOptions, j as MigrationContext, k as MigrationResult, P as PersistedQueueItem, l as PlanFile, m as PlanItem, n as PlanTemplate, Q as QueueStore, R as RecoveryLock, o as RecoveryLockOptions, S as SessionAnalyzer, p as SessionStoreOptions, T as TodosCheckpointFile, q as addPlanItem, r as attachPlanCheckpoint, s as attachTodosCheckpoint, t as clearPlan, u as deriveTodosFromPlanItem, v as emptyPlan, w as formatPlan, x as formatPlanTemplates, y as getPlanTemplate, z as listPlanTemplates, B as loadPlan, E as loadTodosCheckpoint, F as removePlanItem, G as runConfigMigrations, H as savePlan, I as saveTodosCheckpoint, J as setPlanItemStatus } from '../plan-templates-Q78an-GJ.js';
2
+ export { D as DefaultSessionReader } from '../session-reader-Dwjn4WZR.js';
3
3
  import { S as SessionRewinder, C as CheckpointInfo, a as RewindResultExtended } from '../session-rewinder-C9HnMkhP.js';
4
4
  export { D as DirectorStateCheckpoint, a as DirectorStateSnapshot, b as DirectorSubagentState, c as DirectorTaskState, l as loadDirectorState } from '../director-state-BmYi3DGA.js';
5
5
  export { G as GoalFile, J as JournalEntry, M as MAX_JOURNAL_ENTRIES, a as appendJournal, e as emptyGoal, f as formatGoal, g as goalFilePath, l as loadGoal, s as saveGoal, b as summarizeUsage } from '../goal-store-HHgaq5ue.js';
6
- import '../events-CJqwQl8G.js';
7
- import '../context-DN5v-uQX.js';
6
+ import '../events-CEKFTmIY.js';
7
+ import '../context-bmR0YgBm.js';
8
8
  import '../memory-CEXuo7sz.js';
9
9
  import '../wstack-paths-86YPFktR.js';
10
- import '../config-DfC6g6KV.js';
10
+ import '../config-C34JRwl4.js';
11
11
  import '../models-registry-Y2xbog0E.js';
12
12
  import '../secret-vault-DoISxaKO.js';
13
13
 
@@ -199,8 +199,16 @@ var DefaultSessionStore = class {
199
199
  }
200
200
  }
201
201
  async resume(id) {
202
- const data = await this.load(id);
203
202
  const file = path2.join(this.dir, `${id}.jsonl`);
203
+ try {
204
+ await fsp.access(file, fsp.constants.R_OK);
205
+ } catch {
206
+ throw new Error(
207
+ `Session "${id}" not found \u2014 the session file does not exist or was deleted.`,
208
+ { cause: new Error("ENOENT") }
209
+ );
210
+ }
211
+ const data = await this.load(id);
204
212
  let handle;
205
213
  try {
206
214
  handle = await fsp.open(file, "a", 384);
@@ -1145,6 +1153,20 @@ function safeParse(input, maxBytes = 5e6) {
1145
1153
  }
1146
1154
  }
1147
1155
 
1156
+ // src/types/default-config.ts
1157
+ var DEFAULT_TOOLS_CONFIG = Object.freeze({
1158
+ defaultExecutionStrategy: "smart",
1159
+ maxIterations: 100,
1160
+ iterationTimeoutMs: 3e5,
1161
+ sessionTimeoutMs: 18e5,
1162
+ perIterationOutputCapBytes: 1e5,
1163
+ autoExtendLimit: true
1164
+ });
1165
+ var DEFAULT_CONTEXT_CONFIG = Object.freeze({
1166
+ preserveK: 10,
1167
+ eliseThreshold: 2e3
1168
+ });
1169
+
1148
1170
  // src/storage/config-loader.ts
1149
1171
  var BEHAVIOR_DEFAULTS = {
1150
1172
  version: 1,
@@ -1154,16 +1176,16 @@ var BEHAVIOR_DEFAULTS = {
1154
1176
  softThreshold: 0.75,
1155
1177
  hardThreshold: 0.9,
1156
1178
  autoCompact: true,
1157
- preserveK: 10,
1158
- eliseThreshold: 2e3
1179
+ preserveK: DEFAULT_CONTEXT_CONFIG.preserveK,
1180
+ eliseThreshold: DEFAULT_CONTEXT_CONFIG.eliseThreshold
1159
1181
  },
1160
1182
  tools: {
1161
- defaultExecutionStrategy: "smart",
1162
- maxIterations: 100,
1163
- iterationTimeoutMs: 3e5,
1164
- sessionTimeoutMs: 18e5,
1165
- perIterationOutputCapBytes: 1e5,
1166
- autoExtendLimit: true
1183
+ defaultExecutionStrategy: DEFAULT_TOOLS_CONFIG.defaultExecutionStrategy,
1184
+ maxIterations: DEFAULT_TOOLS_CONFIG.maxIterations,
1185
+ iterationTimeoutMs: DEFAULT_TOOLS_CONFIG.iterationTimeoutMs,
1186
+ sessionTimeoutMs: DEFAULT_TOOLS_CONFIG.sessionTimeoutMs,
1187
+ perIterationOutputCapBytes: DEFAULT_TOOLS_CONFIG.perIterationOutputCapBytes,
1188
+ autoExtendLimit: DEFAULT_TOOLS_CONFIG.autoExtendLimit
1167
1189
  },
1168
1190
  log: { level: "info" },
1169
1191
  features: {
@@ -2513,7 +2535,7 @@ var DirectorStateCheckpoint = class {
2513
2535
  this.timer = null;
2514
2536
  }
2515
2537
  await this.persist();
2516
- if (this.rewriteRequested) {
2538
+ while (this.rewriteRequested) {
2517
2539
  this.rewriteRequested = false;
2518
2540
  await this.persist();
2519
2541
  }
@@ -2552,6 +2574,58 @@ var DirectorStateCheckpoint = class {
2552
2574
  }
2553
2575
  }
2554
2576
  };
2577
+
2578
+ // src/types/errors.ts
2579
+ var ERROR_CODES = {
2580
+ // File system
2581
+ FS_READ_FAILED: "FS_READ_FAILED",
2582
+ FS_ATOMIC_WRITE_FAILED: "FS_ATOMIC_WRITE_FAILED"};
2583
+ var WrongStackError = class extends Error {
2584
+ code;
2585
+ subsystem;
2586
+ severity;
2587
+ recoverable;
2588
+ context;
2589
+ constructor(opts) {
2590
+ super(opts.message, { cause: opts.cause });
2591
+ this.name = "WrongStackError";
2592
+ this.code = opts.code;
2593
+ this.subsystem = opts.subsystem;
2594
+ this.severity = opts.severity ?? "error";
2595
+ this.recoverable = opts.recoverable ?? false;
2596
+ this.context = opts.context;
2597
+ }
2598
+ /**
2599
+ * Render a one-line user-facing description.
2600
+ * Subclasses should override for domain-specific formatting.
2601
+ */
2602
+ describe() {
2603
+ const ctx = this.context ? ` ${formatContext(this.context)}` : "";
2604
+ return `${this.code}: ${this.message}${ctx}`;
2605
+ }
2606
+ };
2607
+ function formatContext(ctx) {
2608
+ const parts = Object.entries(ctx).filter(([, v]) => v !== void 0).slice(0, 3).map(([k, v]) => `${k}=${String(v)}`);
2609
+ return parts.length > 0 ? `[${parts.join(" ")}]` : "";
2610
+ }
2611
+ var FsError = class extends WrongStackError {
2612
+ path;
2613
+ constructor(opts) {
2614
+ super({
2615
+ message: opts.message,
2616
+ code: opts.code,
2617
+ subsystem: "fs",
2618
+ severity: "error",
2619
+ recoverable: opts.code !== ERROR_CODES.FS_READ_FAILED,
2620
+ context: { path: opts.path, ...opts.context },
2621
+ cause: opts.cause
2622
+ });
2623
+ this.name = "FsError";
2624
+ this.path = opts.path;
2625
+ }
2626
+ };
2627
+
2628
+ // src/storage/goal-store.ts
2555
2629
  var MAX_JOURNAL_ENTRIES = 500;
2556
2630
  function goalFilePath(projectRoot) {
2557
2631
  return path2.join(projectRoot, ".wrongstack", "goal.json");
@@ -2574,7 +2648,16 @@ async function loadGoal(filePath) {
2574
2648
  }
2575
2649
  }
2576
2650
  async function saveGoal(filePath, goal) {
2577
- await atomicWrite(filePath, JSON.stringify(goal, null, 2), { mode: 384 });
2651
+ try {
2652
+ await atomicWrite(filePath, JSON.stringify(goal, null, 2), { mode: 384 });
2653
+ } catch (err) {
2654
+ throw new FsError({
2655
+ message: err instanceof Error ? err.message : String(err),
2656
+ code: ERROR_CODES.FS_ATOMIC_WRITE_FAILED,
2657
+ path: filePath,
2658
+ cause: err
2659
+ });
2660
+ }
2578
2661
  }
2579
2662
  function emptyGoal(goal) {
2580
2663
  const now = (/* @__PURE__ */ new Date()).toISOString();