@wrongstack/core 0.87.0 → 0.89.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.
Files changed (49) hide show
  1. package/dist/{agent-bridge-C9P_HPez.d.ts → agent-bridge-B8F2ORwg.d.ts} +1 -1
  2. package/dist/{agent-subagent-runner-2Aq0jOSj.d.ts → agent-subagent-runner-CQaLFNnA.d.ts} +3 -2
  3. package/dist/coordination/index.d.ts +7 -7
  4. package/dist/coordination/index.js +183 -56
  5. package/dist/coordination/index.js.map +1 -1
  6. package/dist/{default-config-DEXI4jsl.d.ts → default-config-CXsDvOmP.d.ts} +3 -1
  7. package/dist/defaults/index.d.ts +10 -10
  8. package/dist/defaults/index.js +268 -68
  9. package/dist/defaults/index.js.map +1 -1
  10. package/dist/{events-DnRqXaZ3.d.ts → events-DzyLtja6.d.ts} +6 -0
  11. package/dist/execution/index.d.ts +5 -5
  12. package/dist/execution/index.js +56 -19
  13. package/dist/execution/index.js.map +1 -1
  14. package/dist/extension/index.d.ts +2 -2
  15. package/dist/{index-BNOLadHw.d.ts → index-Ca_lOmKl.d.ts} +2 -2
  16. package/dist/{index-N0_c4bHQ.d.ts → index-Dx-CnrDN.d.ts} +3 -1
  17. package/dist/index.d.ts +24 -21
  18. package/dist/index.js +448 -179
  19. package/dist/index.js.map +1 -1
  20. package/dist/infrastructure/index.d.ts +2 -2
  21. package/dist/infrastructure/index.js +12 -3
  22. package/dist/infrastructure/index.js.map +1 -1
  23. package/dist/kernel/index.d.ts +3 -3
  24. package/dist/kernel/index.js +17 -0
  25. package/dist/kernel/index.js.map +1 -1
  26. package/dist/models/index.js.map +1 -1
  27. package/dist/{multi-agent-coordinator-DllpCVkF.d.ts → multi-agent-coordinator-Da9nd8Ic.d.ts} +1 -1
  28. package/dist/{null-fleet-bus-BY0AN-sr.d.ts → null-fleet-bus-CHJOXv3t.d.ts} +11 -5
  29. package/dist/observability/index.d.ts +1 -1
  30. package/dist/{parallel-eternal-engine-D402RASp.d.ts → parallel-eternal-engine-DyMCj2Pw.d.ts} +4 -3
  31. package/dist/{path-resolver-UPFTsDyD.d.ts → path-resolver-TjBlRKyH.d.ts} +1 -1
  32. package/dist/{plan-templates-DRvPgkfZ.d.ts → plan-templates-D9UhwoGh.d.ts} +1 -1
  33. package/dist/{provider-runner-COAJM8tC.d.ts → provider-runner-BEPWwkxH.d.ts} +1 -1
  34. package/dist/sdd/index.d.ts +3 -3
  35. package/dist/sdd/index.js +89 -19
  36. package/dist/sdd/index.js.map +1 -1
  37. package/dist/security/index.js +18 -2
  38. package/dist/security/index.js.map +1 -1
  39. package/dist/skills/index.js.map +1 -1
  40. package/dist/storage/index.d.ts +4 -4
  41. package/dist/storage/index.js +149 -90
  42. package/dist/storage/index.js.map +1 -1
  43. package/dist/types/index.d.ts +10 -10
  44. package/dist/types/index.js +44 -7
  45. package/dist/types/index.js.map +1 -1
  46. package/dist/utils/index.d.ts +6 -1
  47. package/dist/utils/index.js +51 -3
  48. package/dist/utils/index.js.map +1 -1
  49. package/package.json +1 -1
package/dist/sdd/index.js CHANGED
@@ -17,7 +17,8 @@ var __export = (target, all) => {
17
17
  var atomic_write_exports = {};
18
18
  __export(atomic_write_exports, {
19
19
  atomicWrite: () => atomicWrite,
20
- ensureDir: () => ensureDir
20
+ ensureDir: () => ensureDir,
21
+ withFileLock: () => withFileLock
21
22
  });
22
23
  async function atomicWrite(targetPath, content, opts = {}) {
23
24
  const dir = path.dirname(targetPath);
@@ -60,6 +61,49 @@ async function atomicWrite(targetPath, content, opts = {}) {
60
61
  async function ensureDir(dir) {
61
62
  await fs.mkdir(dir, { recursive: true });
62
63
  }
64
+ async function withFileLock(targetPath, fn, opts = {}) {
65
+ const dir = path.dirname(targetPath);
66
+ await fs.mkdir(dir, { recursive: true });
67
+ const lockPath = path.join(dir, `.${path.basename(targetPath)}.lock`);
68
+ const timeoutMs = opts.timeoutMs ?? 5e3;
69
+ const staleMs = opts.staleMs ?? 3e4;
70
+ const started = Date.now();
71
+ let handle;
72
+ for (; ; ) {
73
+ try {
74
+ handle = await fs.open(lockPath, "wx");
75
+ await handle.writeFile(`${process.pid}:${Date.now()}`);
76
+ break;
77
+ } catch (err) {
78
+ if (err.code !== "EEXIST") throw err;
79
+ try {
80
+ const stat2 = await fs.stat(lockPath);
81
+ if (Date.now() - stat2.mtimeMs > staleMs) {
82
+ await fs.unlink(lockPath);
83
+ continue;
84
+ }
85
+ } catch {
86
+ continue;
87
+ }
88
+ if (Date.now() - started >= timeoutMs) {
89
+ throw new Error(`Timed out waiting for file lock: ${targetPath}`);
90
+ }
91
+ await new Promise((resolve) => setTimeout(resolve, 25));
92
+ }
93
+ }
94
+ try {
95
+ return await fn();
96
+ } finally {
97
+ try {
98
+ await handle?.close();
99
+ } catch {
100
+ }
101
+ try {
102
+ await fs.unlink(lockPath);
103
+ } catch {
104
+ }
105
+ }
106
+ }
63
107
  async function renameWithRetry(from, to) {
64
108
  if (process.platform !== "win32") {
65
109
  await fs.rename(from, to);
@@ -2591,6 +2635,7 @@ var SddTaskDecomposer = class {
2591
2635
  };
2592
2636
 
2593
2637
  // src/coordination/subagent-budget.ts
2638
+ var TIMEOUT_PREEMPT_FRACTION = 0.85;
2594
2639
  var BudgetExceededError = class extends Error {
2595
2640
  kind;
2596
2641
  limit;
@@ -6110,15 +6155,38 @@ var DefaultMultiAgentCoordinator = class _DefaultMultiAgentCoordinator extends E
6110
6155
  }
6111
6156
  const start = Date.now();
6112
6157
  let timer = null;
6158
+ let preemptedForLimit = null;
6113
6159
  const timeoutPromise = new Promise((_, reject) => {
6114
6160
  const armFor = (ms) => {
6115
6161
  if (timer) clearTimeout(timer);
6116
6162
  timer = setTimeout(onTick, Math.max(0, ms));
6117
6163
  };
6118
6164
  const scheduleNext = () => {
6119
- const wallRemaining = initialTimeoutMs === void 0 ? Number.POSITIVE_INFINITY : (budget.limits.timeoutMs ?? initialTimeoutMs) - (Date.now() - start);
6165
+ const wallLimit = budget.limits.timeoutMs ?? initialTimeoutMs;
6166
+ const wallRemaining = initialTimeoutMs === void 0 ? Number.POSITIVE_INFINITY : wallLimit - (Date.now() - start);
6120
6167
  const idleRemaining = idleLimitMs === void 0 ? Number.POSITIVE_INFINITY : (budget.limits.idleTimeoutMs ?? idleLimitMs) - budget.idleMs();
6121
- armFor(Math.max(25, Math.min(wallRemaining, idleRemaining)));
6168
+ const preemptRemaining = initialTimeoutMs === void 0 || preemptedForLimit === wallLimit ? Number.POSITIVE_INFINITY : wallLimit * TIMEOUT_PREEMPT_FRACTION - (Date.now() - start);
6169
+ armFor(Math.max(25, Math.min(wallRemaining, idleRemaining, preemptRemaining)));
6170
+ };
6171
+ const negotiateTimeout = async (used, limit) => {
6172
+ const handler = budget.onThreshold;
6173
+ if (!handler) return "stop";
6174
+ const result = handler({
6175
+ kind: "timeout",
6176
+ used,
6177
+ limit,
6178
+ requestDecision: () => new Promise((resolveDecision) => {
6179
+ budget._events?.emit("budget.threshold_reached", {
6180
+ kind: "timeout",
6181
+ used,
6182
+ limit,
6183
+ timeoutMs: 6e4,
6184
+ extend: (extra) => resolveDecision({ extend: extra }),
6185
+ deny: () => resolveDecision("stop")
6186
+ });
6187
+ })
6188
+ });
6189
+ return typeof result === "string" ? result : await result;
6122
6190
  };
6123
6191
  const onTick = async () => {
6124
6192
  const elapsed = Date.now() - start;
@@ -6131,6 +6199,21 @@ var DefaultMultiAgentCoordinator = class _DefaultMultiAgentCoordinator extends E
6131
6199
  reject(new BudgetExceededError("timeout", idleLimit ?? 0, budget.idleMs()));
6132
6200
  return;
6133
6201
  }
6202
+ if (wallLimit !== void 0 && !wallExceeded && budget.onThreshold && preemptedForLimit !== wallLimit && elapsed >= wallLimit * TIMEOUT_PREEMPT_FRACTION) {
6203
+ try {
6204
+ const decision = await negotiateTimeout(elapsed, wallLimit);
6205
+ if (typeof decision !== "string" && decision.extend.timeoutMs !== void 0) {
6206
+ budget.limits.timeoutMs = decision.extend.timeoutMs;
6207
+ preemptedForLimit = null;
6208
+ } else {
6209
+ preemptedForLimit = wallLimit;
6210
+ }
6211
+ } catch {
6212
+ preemptedForLimit = wallLimit;
6213
+ }
6214
+ scheduleNext();
6215
+ return;
6216
+ }
6134
6217
  if (!wallExceeded) {
6135
6218
  scheduleNext();
6136
6219
  return;
@@ -6142,28 +6225,15 @@ var DefaultMultiAgentCoordinator = class _DefaultMultiAgentCoordinator extends E
6142
6225
  return;
6143
6226
  }
6144
6227
  try {
6145
- const result = budget.onThreshold({
6146
- kind: "timeout",
6147
- used: elapsed,
6148
- limit,
6149
- requestDecision: () => new Promise((resolveDecision) => {
6150
- budget._events?.emit("budget.threshold_reached", {
6151
- kind: "timeout",
6152
- used: elapsed,
6153
- limit,
6154
- timeoutMs: 6e4,
6155
- extend: (extra) => resolveDecision({ extend: extra }),
6156
- deny: () => resolveDecision("stop")
6157
- });
6158
- })
6159
- });
6160
- const decision = typeof result === "string" ? result : await result;
6228
+ const decision = await negotiateTimeout(elapsed, limit);
6161
6229
  if (decision === "continue" || decision === "throw" || decision === "stop") {
6230
+ preemptedForLimit = null;
6162
6231
  armFor(Math.max(1e3, limit));
6163
6232
  return;
6164
6233
  }
6165
6234
  if (decision.extend.timeoutMs !== void 0) {
6166
6235
  budget.limits.timeoutMs = decision.extend.timeoutMs;
6236
+ preemptedForLimit = null;
6167
6237
  scheduleNext();
6168
6238
  return;
6169
6239
  }