opencode-swarm 7.154.0 → 7.154.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.
Files changed (75) hide show
  1. package/dist/background/completion-observer.d.ts +10 -1
  2. package/dist/background/pending-delegations.d.ts +47 -0
  3. package/dist/background/pr-subscriptions.d.ts +7 -0
  4. package/dist/cli/coder-settlement-xqs49g07.js +54 -0
  5. package/dist/cli/{config-doctor-8p9y543t.js → config-doctor-69eebk90.js} +2 -2
  6. package/dist/cli/{core-1h6x6k59.js → core-dyp14hcb.js} +2 -2
  7. package/dist/cli/{curation-policy-9r902jw4.js → curation-policy-jm9jsxtt.js} +6 -6
  8. package/dist/cli/curator-drift-h57z6tm3.js +1 -1
  9. package/dist/cli/{curator-yj00z1qz.js → curator-he8n9z9n.js} +35 -33
  10. package/dist/cli/{curator-llm-factory-ypwf3a90.js → curator-llm-factory-5tq9c4v5.js} +35 -33
  11. package/dist/cli/{evidence-summary-service-npq04240.js → evidence-summary-service-05s5y8d6.js} +13 -13
  12. package/dist/cli/{gate-evidence-4b6t0ycn.js → gate-evidence-3ptr9af3.js} +7 -7
  13. package/dist/cli/guardrail-explain-tebk344k.js +67 -0
  14. package/dist/cli/{guardrail-log-eyecsekk.js → guardrail-log-x3gz3x17.js} +5 -5
  15. package/dist/cli/{guardrail-reset-269jdwhd.js → guardrail-reset-716pdyf5.js} +35 -33
  16. package/dist/cli/{hive-promoter-5936am48.js → hive-promoter-nvwpj2t9.js} +35 -33
  17. package/dist/cli/{index-10zvxqra.js → index-07n87ctw.js} +1 -1
  18. package/dist/cli/{index-yve4e8fx.js → index-14bz2t7b.js} +1 -1
  19. package/dist/cli/{index-nkr634n6.js → index-2w6vy9a9.js} +1 -1
  20. package/dist/cli/{index-6yc06dx9.js → index-399e8aze.js} +1 -1
  21. package/dist/cli/{index-garsang6.js → index-4xqa0sgz.js} +1 -1
  22. package/dist/cli/{index-tnm9bb8b.js → index-57t97rtr.js} +1 -1
  23. package/dist/cli/{index-s70tmqn3.js → index-6qwp46k0.js} +5 -5
  24. package/dist/cli/{index-68w5jxv5.js → index-6rcx6vr6.js} +4 -4
  25. package/dist/cli/{index-wfxg3s7n.js → index-6rns7b2m.js} +96 -23
  26. package/dist/cli/{index-3mhgv8d6.js → index-7tw116n6.js} +2 -2
  27. package/dist/cli/{index-wpstzk85.js → index-8v69hfpt.js} +4 -4
  28. package/dist/cli/index-9avdncr2.js +875 -0
  29. package/dist/cli/{index-1tdsddab.js → index-bxvkn0ye.js} +2281 -2919
  30. package/dist/cli/index-ddszzne4.js +42 -0
  31. package/dist/cli/{index-4y7g04py.js → index-dm9tc6qb.js} +7 -7
  32. package/dist/cli/{index-4g00jhbs.js → index-dsqat5pg.js} +3 -3
  33. package/dist/cli/{index-snnps1vm.js → index-f6qmar4k.js} +5 -5
  34. package/dist/cli/{index-y64jrbch.js → index-fv9ddfta.js} +2 -2
  35. package/dist/cli/{index-ttqnhxxq.js → index-h1g8w4v0.js} +2 -2
  36. package/dist/cli/{index-s0a4ewkb.js → index-j6q3k628.js} +2 -2
  37. package/dist/cli/{index-c809a69b.js → index-kemxyzc0.js} +1 -1
  38. package/dist/cli/{index-pcj7jk4t.js → index-mnxtkt8s.js} +4 -4
  39. package/dist/cli/{index-hk4wa0v1.js → index-n0gqre56.js} +6 -6
  40. package/dist/cli/{index-7jnh1sgb.js → index-nh4axsxc.js} +228 -2
  41. package/dist/cli/{index-2mbs5q26.js → index-p7ey2w90.js} +7 -7
  42. package/dist/cli/{index-48m4841x.js → index-pj2nycpg.js} +1 -1
  43. package/dist/cli/{index-3db7xza0.js → index-r0dactw2.js} +1 -1
  44. package/dist/cli/{index-2kzxkx50.js → index-v2ryvr8k.js} +37 -35
  45. package/dist/cli/{index-mddgkqg9.js → index-v9585wjc.js} +2 -2
  46. package/dist/cli/{index-dwh02jmv.js → index-vhhdj49x.js} +10 -10
  47. package/dist/cli/{index-vtdwkfbv.js → index-xagq35tf.js} +1 -1
  48. package/dist/cli/{index-c6dfyzdh.js → index-xdy28ngt.js} +1 -1
  49. package/dist/cli/{index-3hdnfmhp.js → index-xq2v52tt.js} +2 -2
  50. package/dist/cli/{index-qcz4xprd.js → index-xt6jx41g.js} +4 -4
  51. package/dist/cli/{index-p4y7jefb.js → index-ynvw5kxc.js} +2 -2
  52. package/dist/cli/index.js +35 -33
  53. package/dist/cli/{knowledge-escalator-bxpzeth0.js → knowledge-escalator-s0tye368.js} +12 -12
  54. package/dist/cli/{knowledge-events-jxdpg2hj.js → knowledge-events-eyy9yf6b.js} +10 -10
  55. package/dist/cli/{knowledge-link-nwxykjya.js → knowledge-link-rb11f06y.js} +5 -5
  56. package/dist/cli/{knowledge-store-336hyzs8.js → knowledge-store-zjq5mz2d.js} +6 -6
  57. package/dist/cli/{knowledge-validator-9wkvnsv0.js → knowledge-validator-yw5qqqpd.js} +8 -8
  58. package/dist/cli/{pending-delegations-0fmj1qy6.js → pending-delegations-rdzjq3nw.js} +16 -3
  59. package/dist/cli/{pr-subscriptions-1ndwgtbw.js → pr-subscriptions-2f5fne6z.js} +4 -4
  60. package/dist/cli/{runner-06dvm53x.js → runner-yaqrj388.js} +6 -6
  61. package/dist/cli/{scan-cursor-3xxqtxwx.js → scan-cursor-8f0s883y.js} +7 -7
  62. package/dist/cli/{schema-jdx83m4m.js → schema-2xw94dh3.js} +1 -1
  63. package/dist/cli/{scope-persistence-wgxn2kba.js → scope-persistence-tap2q94x.js} +9 -9
  64. package/dist/cli/{skill-generator-vmxsc2fm.js → skill-generator-2xbfryqb.js} +14 -14
  65. package/dist/cli/{telemetry-q2km2zrz.js → telemetry-r8e8zey7.js} +1 -1
  66. package/dist/cli/{worktree-collision-ownership-gsay5210.js → worktree-collision-ownership-5gwey8ms.js} +10 -9
  67. package/dist/cli/{worktree-isolation-peb4bkg3.js → worktree-isolation-xsy14t5a.js} +35 -33
  68. package/dist/evaluation/contracts.d.ts +4 -4
  69. package/dist/evaluation/gate-ground-truth.d.ts +1 -1
  70. package/dist/index.js +523 -523
  71. package/dist/telemetry.d.ts +1 -0
  72. package/dist/utils/canonical-root.d.ts +2 -0
  73. package/dist/workflow/coder-settlement.d.ts +14 -0
  74. package/package.json +1 -1
  75. package/dist/cli/guardrail-explain-dyxbhrdj.js +0 -65
@@ -0,0 +1,42 @@
1
+ // @bun
2
+ // src/utils/canonical-root.ts
3
+ import * as fsSync from "fs";
4
+ import * as path from "path";
5
+ var SESSION_KEY_SEPARATOR = String.fromCharCode(0);
6
+ var canonicalRootMemo = new Map;
7
+ var MAX_CANONICAL_ROOT_CACHE = 128;
8
+ function resolveCanonicalRootKey(directory) {
9
+ let resolved = path.resolve(directory);
10
+ try {
11
+ resolved = fsSync.realpathSync(resolved);
12
+ } catch {}
13
+ const key = process.platform === "win32" ? resolved.toLowerCase() : resolved;
14
+ return key;
15
+ }
16
+ function canonicalRootKey(directory) {
17
+ const memoized = canonicalRootMemo.get(directory);
18
+ if (memoized !== undefined)
19
+ return memoized;
20
+ const key = resolveCanonicalRootKey(directory);
21
+ if (!canonicalRootMemo.has(directory)) {
22
+ while (canonicalRootMemo.size >= MAX_CANONICAL_ROOT_CACHE) {
23
+ const oldest = canonicalRootMemo.keys().next().value;
24
+ if (oldest === undefined)
25
+ break;
26
+ canonicalRootMemo.delete(oldest);
27
+ }
28
+ }
29
+ canonicalRootMemo.set(directory, key);
30
+ return key;
31
+ }
32
+ function canonicalRootKeyFresh(directory) {
33
+ return resolveCanonicalRootKey(directory);
34
+ }
35
+ function compositeSessionKey(directory, sessionId) {
36
+ return `${canonicalRootKey(directory)}${SESSION_KEY_SEPARATOR}${sessionId}`;
37
+ }
38
+ function sessionKeySuffix(sessionId) {
39
+ return `${SESSION_KEY_SEPARATOR}${sessionId}`;
40
+ }
41
+
42
+ export { canonicalRootKeyFresh, compositeSessionKey, sessionKeySuffix };
@@ -6,7 +6,12 @@ import {
6
6
  PluginConfigSchema,
7
7
  init_schema,
8
8
  resolveExternalSkillsConfig
9
- } from "./index-tnm9bb8b.js";
9
+ } from "./index-57t97rtr.js";
10
+ import {
11
+ MAX_MERGE_DEPTH,
12
+ deepMerge,
13
+ init_merge
14
+ } from "./index-zjygnfay.js";
10
15
  import {
11
16
  GIT_BINARY_ENV_VAR,
12
17
  init_git_executable
@@ -15,11 +20,6 @@ import {
15
20
  advisoryWarn,
16
21
  init_warning_buffer
17
22
  } from "./index-4rhhvd1a.js";
18
- import {
19
- MAX_MERGE_DEPTH,
20
- deepMerge,
21
- init_merge
22
- } from "./index-zjygnfay.js";
23
23
  import {
24
24
  exports_external,
25
25
  init_zod
@@ -788,4 +788,4 @@ var PlanSchema = exports_external.object({
788
788
  execution_profile: ExecutionProfileSchema.optional()
789
789
  });
790
790
 
791
- export { loadPluginConfig, loadPluginConfigWithMeta, getSafeDefaultConfigLoadResult, loadPluginConfigWithMetaAsync, loadAgentPrompt, exports_loader, init_loader, ExecutionProfileSchema, TaskStatusSchema, TaskSizeSchema, PhaseStatusSchema, MigrationStatusSchema, TaskSchema, PhaseSchema, PlanSchema };
791
+ export { ExecutionProfileSchema, TaskStatusSchema, TaskSizeSchema, PhaseStatusSchema, MigrationStatusSchema, TaskSchema, PhaseSchema, PlanSchema, loadPluginConfig, loadPluginConfigWithMeta, getSafeDefaultConfigLoadResult, loadPluginConfigWithMetaAsync, loadAgentPrompt, exports_loader, init_loader };
@@ -4,14 +4,14 @@ import {
4
4
  PlanSchema,
5
5
  TaskStatusSchema,
6
6
  init_loader
7
- } from "./index-4y7g04py.js";
7
+ } from "./index-dm9tc6qb.js";
8
8
  import {
9
9
  assertProjectRoot,
10
10
  withEvidenceLock
11
- } from "./index-vtdwkfbv.js";
11
+ } from "./index-xagq35tf.js";
12
12
  import {
13
13
  emit
14
- } from "./index-ttqnhxxq.js";
14
+ } from "./index-h1g8w4v0.js";
15
15
  import {
16
16
  criticalWarn,
17
17
  init_logger,
@@ -6,12 +6,12 @@ import {
6
6
  resolveSwarmKnowledgePath,
7
7
  transactKnowledge,
8
8
  wordBigrams
9
- } from "./index-hk4wa0v1.js";
9
+ } from "./index-n0gqre56.js";
10
10
  import {
11
11
  queryHistoricalOutcomes,
12
12
  readKnowledgeEvents,
13
13
  recordKnowledgeEvent
14
- } from "./index-2mbs5q26.js";
14
+ } from "./index-p7ey2w90.js";
15
15
  import {
16
16
  init_knowledge_types,
17
17
  isActiveStatus
@@ -224,11 +224,11 @@ async function maybeQuarantineOnContradiction(directory, entryId, threshold, win
224
224
  alreadyInactive: true
225
225
  };
226
226
  }
227
- const { quarantineEntry } = await import("./knowledge-validator-9wkvnsv0.js");
227
+ const { quarantineEntry } = await import("./knowledge-validator-yw5qqqpd.js");
228
228
  let policyConfig;
229
229
  try {
230
- const { KnowledgeConfigSchema } = await import("./schema-jdx83m4m.js");
231
- const { loadPluginConfigWithMeta } = await import("./index-pcj7jk4t.js");
230
+ const { KnowledgeConfigSchema } = await import("./schema-2xw94dh3.js");
231
+ const { loadPluginConfigWithMeta } = await import("./index-mnxtkt8s.js");
232
232
  const { config: loadedConfig } = loadPluginConfigWithMeta(directory);
233
233
  policyConfig = KnowledgeConfigSchema.parse(loadedConfig.knowledge ?? {});
234
234
  } catch {
@@ -9,11 +9,11 @@ import {
9
9
  } from "./index-y8552snf.js";
10
10
  import {
11
11
  atomicWriteFile
12
- } from "./index-s0a4ewkb.js";
12
+ } from "./index-j6q3k628.js";
13
13
  import {
14
14
  assertProjectRoot,
15
15
  withEvidenceLock
16
- } from "./index-vtdwkfbv.js";
16
+ } from "./index-xagq35tf.js";
17
17
  import {
18
18
  exports_external,
19
19
  init_zod
@@ -452,7 +452,7 @@ var CATALOG_SOURCE = [
452
452
  category: "prm",
453
453
  severity: "error",
454
454
  privacyClass: "pseudonymous",
455
- producer: "src/telemetry.ts:1117",
455
+ producer: "src/telemetry.ts:1118",
456
456
  consumers: NO_CONSUMERS,
457
457
  futureOwnerIssue: ISSUE_SINK,
458
458
  retentionOwnerIssue: ISSUE_SINK,
@@ -738,7 +738,7 @@ var CATALOG_SOURCE = [
738
738
  category: "lifecycle",
739
739
  severity: "notice",
740
740
  privacyClass: "operational",
741
- producer: "src/telemetry.ts:1101",
741
+ producer: "src/telemetry.ts:1102",
742
742
  consumers: NO_CONSUMERS,
743
743
  futureOwnerIssue: ISSUE_SINK,
744
744
  retentionOwnerIssue: ISSUE_SINK,
@@ -1,10 +1,10 @@
1
1
  // @bun
2
2
  import {
3
3
  atomicWriteFileAnyRoot
4
- } from "./index-c809a69b.js";
4
+ } from "./index-kemxyzc0.js";
5
5
  import {
6
6
  withEvidenceLock
7
- } from "./index-vtdwkfbv.js";
7
+ } from "./index-xagq35tf.js";
8
8
 
9
9
  // src/evidence/task-file.ts
10
10
  import * as path from "path";
@@ -123,7 +123,7 @@ var SWARM_TEMP_GRAMMARS = [
123
123
  "src/tools/spec-write.ts:98",
124
124
  "src/sdd/effective-spec.ts:1149",
125
125
  "src/background/lane-output-store.ts:353",
126
- "src/background/pending-delegations.ts:1053",
126
+ "src/background/pending-delegations.ts:1070",
127
127
  "src/background/delegation-health.ts:390",
128
128
  "src/tools/submit-phase-council-verdicts.ts:458",
129
129
  "src/summaries/store.ts:46 (pre-#2035)"
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  _internals,
4
4
  resolveWorktreeIsolationConfig
5
- } from "./index-p4y7jefb.js";
5
+ } from "./index-ynvw5kxc.js";
6
6
  import {
7
7
  ApprovalEvidenceSchema,
8
8
  BaseEvidenceSchema,
@@ -42,7 +42,7 @@ import {
42
42
  loadPluginConfig,
43
43
  loadPluginConfigWithMeta,
44
44
  loadPluginConfigWithMetaAsync
45
- } from "./index-4y7g04py.js";
45
+ } from "./index-dm9tc6qb.js";
46
46
  import {
47
47
  AUTO_REVIEW_V8_BURN_IN_DECISION,
48
48
  AgentOverrideConfigSchema,
@@ -64,7 +64,7 @@ import {
64
64
  TurboConfigSchema,
65
65
  WorktreeIsolationConfigSchema,
66
66
  resolveAutoReviewConfig
67
- } from "./index-tnm9bb8b.js";
67
+ } from "./index-57t97rtr.js";
68
68
  import {
69
69
  ALL_AGENT_NAMES,
70
70
  ALL_SUBAGENT_NAMES,
@@ -75,9 +75,9 @@ import {
75
75
  isQAAgent,
76
76
  isSubagent
77
77
  } from "./index-myt57pht.js";
78
+ import"./index-zjygnfay.js";
78
79
  import"./index-9e6fdz2h.js";
79
80
  import"./index-4rhhvd1a.js";
80
- import"./index-zjygnfay.js";
81
81
  import"./index-bk5tah7q.js";
82
82
  import"./index-bpmtbmy9.js";
83
83
  import"./index-zgwm4ryv.js";
@@ -6,10 +6,10 @@ import {
6
6
  } from "./index-ae75rja9.js";
7
7
  import {
8
8
  resolveKnowledgeStoreDir
9
- } from "./index-3db7xza0.js";
9
+ } from "./index-r0dactw2.js";
10
10
  import {
11
11
  atomicWriteFile
12
- } from "./index-s0a4ewkb.js";
12
+ } from "./index-j6q3k628.js";
13
13
  import {
14
14
  init_knowledge_types,
15
15
  isActiveStatus
@@ -713,7 +713,7 @@ async function applyConfidenceFloorAction(directory, touched, options) {
713
713
  const {
714
714
  readAuthoritativeKnowledgeCounterRollups,
715
715
  effectiveRetrievalOutcomes
716
- } = await import("./knowledge-events-jxdpg2hj.js");
716
+ } = await import("./knowledge-events-eyy9yf6b.js");
717
717
  const rollups = await readAuthoritativeKnowledgeCounterRollups(directory);
718
718
  const flagIds = new Set;
719
719
  for (const e of atFloor) {
@@ -780,11 +780,11 @@ async function applyConfidenceFloorAction(directory, touched, options) {
780
780
  });
781
781
  }
782
782
  if (action === "quarantine" && toQuarantine.length > 0) {
783
- const { quarantineEntry } = await import("./knowledge-validator-9wkvnsv0.js");
784
- const { KnowledgeConfigSchema } = await import("./schema-jdx83m4m.js");
783
+ const { quarantineEntry } = await import("./knowledge-validator-yw5qqqpd.js");
784
+ const { KnowledgeConfigSchema } = await import("./schema-2xw94dh3.js");
785
785
  let config;
786
786
  try {
787
- const { loadPluginConfigWithMeta } = await import("./index-pcj7jk4t.js");
787
+ const { loadPluginConfigWithMeta } = await import("./index-mnxtkt8s.js");
788
788
  const { config: loadedConfig } = loadPluginConfigWithMeta(directory);
789
789
  config = KnowledgeConfigSchema.parse(loadedConfig.knowledge ?? {});
790
790
  } catch {
@@ -1,4 +1,7 @@
1
1
  // @bun
2
+ import {
3
+ canonicalRootKeyFresh
4
+ } from "./index-ddszzne4.js";
2
5
  import {
3
6
  validateSwarmPath
4
7
  } from "./index-4cgee5vh.js";
@@ -8,7 +11,7 @@ import {
8
11
  import {
9
12
  EvidenceLockTimeoutError,
10
13
  withEvidenceLock
11
- } from "./index-vtdwkfbv.js";
14
+ } from "./index-xagq35tf.js";
12
15
  import {
13
16
  exports_external,
14
17
  init_zod
@@ -17,6 +20,9 @@ import {
17
20
  init_logger,
18
21
  warn
19
22
  } from "./index-zgwm4ryv.js";
23
+ import {
24
+ __require
25
+ } from "./index-a76rekgs.js";
20
26
 
21
27
  // src/background/pending-delegations.ts
22
28
  init_zod();
@@ -387,6 +393,7 @@ var MAX_LIVE_BACKGROUND_FALLBACKS = 256;
387
393
  var MAX_LIVE_BACKGROUND_CODER_RESERVATIONS = 256;
388
394
  var MAX_BACKGROUND_OBSERVED_FILES = 5000;
389
395
  var MAX_BACKGROUND_ADVISORY_CHARS = 4000;
396
+ var LEGACY_CODER_SETTLEMENT_PENDING_ADVISORY_MARKER = "legacy coder settlement transfer is pending";
390
397
  var MAX_BACKGROUND_DELEGATION_GENERATION = 1e6;
391
398
  var MAX_RECOVERY_FALLBACK_BYTES = 1024 * 1024;
392
399
  var DELEGATION_COMPACTION_LOW_WATER_BYTES = 256 * 1024;
@@ -674,6 +681,11 @@ var RecordSchema = exports_external.object({
674
681
  terminalResult: TerminalResultSchema.optional(),
675
682
  coderSettlement: CoderSettlementSchema.optional(),
676
683
  advisoryInbox: AdvisoryInboxSchema.optional(),
684
+ legacyCoderSettlementTransfer: exports_external.object({
685
+ taskId: exports_external.string().min(1).max(256),
686
+ transitionId: exports_external.string().min(1).max(256),
687
+ updatedAt: exports_external.number().nonnegative()
688
+ }).strict().optional(),
677
689
  ingestion: DelegationIngestionSchema.optional(),
678
690
  result: ResultSchema.optional(),
679
691
  completedAt: exports_external.number().optional()
@@ -1132,6 +1144,8 @@ function isCheckpointLiveRecord(record) {
1132
1144
  return true;
1133
1145
  if (record.advisoryInbox?.state === "pending")
1134
1146
  return true;
1147
+ if (record.legacyCoderSettlementTransfer)
1148
+ return true;
1135
1149
  const settlement = record.coderSettlement;
1136
1150
  if (settlement && settlement.state !== "settled")
1137
1151
  return true;
@@ -1986,6 +2000,99 @@ async function updateCoderSettlement(directory, correlationId, input) {
1986
2000
  return null;
1987
2001
  }
1988
2002
  }
2003
+ var MAX_LEGACY_CODER_SETTLEMENT_RECONCILERS = 32;
2004
+ var RETRYABLE_LEGACY_SETTLEMENT_ERROR_CODES = new Set([
2005
+ "CODER_SETTLEMENT_LOCKED",
2006
+ "EACCES",
2007
+ "EBUSY",
2008
+ "EIO",
2009
+ "EPERM",
2010
+ "ETIMEDOUT"
2011
+ ]);
2012
+ var legacyCoderSettlementReconcilers = new Map;
2013
+ var legacyCoderSettlementReconcilerOrder = [];
2014
+ function registerLegacyCoderSettlementReconciler(directory, reconciler) {
2015
+ const key = canonicalRootKeyFresh(directory);
2016
+ if (legacyCoderSettlementReconcilers.has(key)) {
2017
+ const existingIndex = legacyCoderSettlementReconcilerOrder.indexOf(key);
2018
+ if (existingIndex >= 0) {
2019
+ legacyCoderSettlementReconcilerOrder.splice(existingIndex, 1);
2020
+ }
2021
+ legacyCoderSettlementReconcilerOrder.push(key);
2022
+ legacyCoderSettlementReconcilers.set(key, reconciler);
2023
+ return;
2024
+ }
2025
+ if (legacyCoderSettlementReconcilerOrder.length >= MAX_LEGACY_CODER_SETTLEMENT_RECONCILERS) {
2026
+ const evicted = legacyCoderSettlementReconcilerOrder.shift();
2027
+ if (evicted)
2028
+ legacyCoderSettlementReconcilers.delete(evicted);
2029
+ }
2030
+ legacyCoderSettlementReconcilerOrder.push(key);
2031
+ legacyCoderSettlementReconcilers.set(key, reconciler);
2032
+ }
2033
+ function getLegacyCoderSettlementReconciler(directory) {
2034
+ return legacyCoderSettlementReconcilers.get(canonicalRootKeyFresh(directory));
2035
+ }
2036
+ var _internals = {
2037
+ getLegacyCoderSettlementReconciler,
2038
+ getLegacyCoderSettlementReconcilerOrder: () => [
2039
+ ...legacyCoderSettlementReconcilerOrder
2040
+ ],
2041
+ resetLegacyCoderSettlementReconcilers: () => {
2042
+ legacyCoderSettlementReconcilers.clear();
2043
+ legacyCoderSettlementReconcilerOrder.length = 0;
2044
+ }
2045
+ };
2046
+ async function markLegacyCoderSettlementTransferPending(directory, correlationId, transfer) {
2047
+ return updateLegacyCoderSettlementTransfer(directory, correlationId, transfer);
2048
+ }
2049
+ async function clearLegacyCoderSettlementTransferPending(directory, correlationId) {
2050
+ return updateLegacyCoderSettlementTransfer(directory, correlationId, null);
2051
+ }
2052
+ async function updateLegacyCoderSettlementTransfer(directory, correlationId, transfer) {
2053
+ if (!correlationId)
2054
+ return null;
2055
+ let result = null;
2056
+ try {
2057
+ await withEvidenceLock(directory, BACKGROUND_DELEGATIONS_FILE, STORE_LOCK_AGENT, STORE_LOCK_TASK, async () => {
2058
+ const records = loadRecordsForWrite(directory);
2059
+ if (records === null)
2060
+ return;
2061
+ const current = findRecordForWrite(records, correlationId);
2062
+ if (!current)
2063
+ return;
2064
+ if (transfer && (current.status === "consumed" || current.legacyCoderSettlementTransfer && (current.legacyCoderSettlementTransfer.taskId !== transfer.taskId || current.legacyCoderSettlementTransfer.transitionId !== transfer.transitionId))) {
2065
+ result = current;
2066
+ return;
2067
+ }
2068
+ const updatedAt = Date.now();
2069
+ const next = transfer ? {
2070
+ ...current,
2071
+ schemaVersion: 3,
2072
+ legacyCoderSettlementTransfer: {
2073
+ ...transfer,
2074
+ updatedAt
2075
+ },
2076
+ updatedAt
2077
+ } : (() => {
2078
+ const { legacyCoderSettlementTransfer: _pending, ...rest } = current;
2079
+ return {
2080
+ ...rest,
2081
+ schemaVersion: 3,
2082
+ updatedAt
2083
+ };
2084
+ })();
2085
+ if (!RecordSchema.safeParse(next).success)
2086
+ return;
2087
+ appendRecord(directory, next);
2088
+ maybeCompactDelegationsLocked(directory);
2089
+ result = next;
2090
+ });
2091
+ } catch (error) {
2092
+ warn(`[background] legacy coder settlement transfer marker update failed: ${error instanceof Error ? error.message : String(error)}`);
2093
+ }
2094
+ return result;
2095
+ }
1989
2096
  async function claimDelegationIngestion(directory, correlationId, options) {
1990
2097
  if (!correlationId || !options.claimantId)
1991
2098
  return null;
@@ -2129,6 +2236,50 @@ async function putPendingBackgroundAdvisory(directory, correlationId, input) {
2129
2236
  return null;
2130
2237
  }
2131
2238
  }
2239
+ async function replacePendingBackgroundAdvisory(directory, correlationId, input) {
2240
+ const createdAt = input.createdAt ?? Date.now();
2241
+ const parsed = AdvisoryInboxSchema.safeParse({
2242
+ eventId: input.eventId,
2243
+ parentSessionId: input.parentSessionId,
2244
+ state: "pending",
2245
+ message: input.message,
2246
+ createdAt
2247
+ });
2248
+ if (!correlationId || !parsed.success)
2249
+ return null;
2250
+ let result = null;
2251
+ try {
2252
+ await withEvidenceLock(directory, BACKGROUND_DELEGATIONS_FILE, STORE_LOCK_AGENT, STORE_LOCK_TASK, async () => {
2253
+ const records = loadRecordsForWrite(directory);
2254
+ if (records === null)
2255
+ return;
2256
+ const current = findRecordForWrite(records, correlationId);
2257
+ const existing = current?.advisoryInbox;
2258
+ if (!current?.terminalResult || current.terminalResult.eventId !== parsed.data.eventId || current.parentSessionId !== parsed.data.parentSessionId || !existing || !existing.message.includes(LEGACY_CODER_SETTLEMENT_PENDING_ADVISORY_MARKER) || parsed.data.message.includes(LEGACY_CODER_SETTLEMENT_PENDING_ADVISORY_MARKER)) {
2259
+ if (existing && existing.eventId === parsed.data.eventId && existing.parentSessionId === parsed.data.parentSessionId && existing.message === parsed.data.message) {
2260
+ result = { advisory: existing };
2261
+ }
2262
+ return;
2263
+ }
2264
+ const next = {
2265
+ ...current,
2266
+ schemaVersion: 3,
2267
+ advisoryInbox: parsed.data,
2268
+ updatedAt: createdAt
2269
+ };
2270
+ appendRecord(directory, next);
2271
+ maybeCompactDelegationsLocked(directory);
2272
+ result = {
2273
+ advisory: parsed.data,
2274
+ replacedMessage: existing.message
2275
+ };
2276
+ });
2277
+ return result;
2278
+ } catch (err) {
2279
+ warn(`[background] replacePendingBackgroundAdvisory failed: ${err instanceof Error ? err.message : String(err)}`);
2280
+ return null;
2281
+ }
2282
+ }
2132
2283
  async function preparePendingBackgroundAdvisories(directory, parentSessionId, options) {
2133
2284
  if (!parentSessionId || !options.preparationId)
2134
2285
  return [];
@@ -2940,6 +3091,74 @@ async function releaseBackgroundCoderReservation(directory, input) {
2940
3091
  }
2941
3092
  var DEFAULT_MAINTENANCE_LOCK_TIMEOUT_MS = 5000;
2942
3093
  var DEFAULT_MAINTENANCE_BATCH = 256;
3094
+ async function reconcileLegacyCoderSettlements(directory, maxRecords, onReconciled, onAdvisoryReplaced) {
3095
+ const reconciler = onReconciled ?? getLegacyCoderSettlementReconciler(directory);
3096
+ const candidates = readDelegations(directory).filter((record) => record.normalizedAgent === "coder" && Boolean(record.legacyCoderSettlementTransfer) && Boolean(record.terminalResult)).slice(0, maxRecords);
3097
+ if (candidates.length === 0)
3098
+ return 0;
3099
+ const { transferCoderSettlementToBackground } = await import("./coder-settlement-xqs49g07.js");
3100
+ let transferred = 0;
3101
+ for (const record of candidates) {
3102
+ try {
3103
+ const outcome = await transferCoderSettlementToBackground({
3104
+ directory,
3105
+ taskId: record.legacyCoderSettlementTransfer.taskId,
3106
+ transitionId: record.legacyCoderSettlementTransfer.transitionId
3107
+ });
3108
+ if ((outcome === "transferred" || outcome === "already-terminal" || outcome === "missing") && reconciler) {
3109
+ if (await reconciler(record)) {
3110
+ await clearLegacyCoderSettlementTransferPending(directory, record.correlationId);
3111
+ }
3112
+ }
3113
+ if (outcome === "transferred")
3114
+ transferred += 1;
3115
+ } catch (error) {
3116
+ const code = legacySettlementErrorCode(error);
3117
+ if (!RETRYABLE_LEGACY_SETTLEMENT_ERROR_CODES.has(code ?? "")) {
3118
+ const advisory = record.advisoryInbox;
3119
+ const manualMessage = `[BACKGROUND COMPLETION ${record.terminalResult?.eventId ?? record.correlationId}] coder task ${record.evidenceTaskId ?? record.planTaskId ?? "unknown"} legacy coder settlement requires manual recovery; run /swarm recover for this task (or /swarm reset-session).`;
3120
+ let advisoryRecorded = false;
3121
+ if (advisory?.state === "pending") {
3122
+ const replaced = await replacePendingBackgroundAdvisory(directory, record.correlationId, {
3123
+ eventId: advisory.eventId,
3124
+ parentSessionId: advisory.parentSessionId,
3125
+ message: manualMessage
3126
+ });
3127
+ advisoryRecorded = replaced !== null;
3128
+ if (replaced) {
3129
+ try {
3130
+ await onAdvisoryReplaced?.(record, replaced);
3131
+ } catch (callbackError) {
3132
+ warn(`[background] legacy coder settlement advisory replacement notification failed for ${record.correlationId}: ${callbackError instanceof Error ? callbackError.message : String(callbackError)}`);
3133
+ }
3134
+ }
3135
+ } else if (record.terminalResult) {
3136
+ const stored = await putPendingBackgroundAdvisory(directory, record.correlationId, {
3137
+ eventId: record.terminalResult.eventId,
3138
+ parentSessionId: record.parentSessionId,
3139
+ message: manualMessage
3140
+ });
3141
+ advisoryRecorded = stored !== null;
3142
+ }
3143
+ if (advisoryRecorded) {
3144
+ await clearLegacyCoderSettlementTransferPending(directory, record.correlationId);
3145
+ }
3146
+ warn(`[background] legacy coder settlement reconciliation requires manual recovery for ${record.correlationId}: ${code ?? "unknown transfer failure"}`);
3147
+ continue;
3148
+ }
3149
+ warn(`[background] legacy coder settlement reconciliation deferred for ${record.correlationId}: ${error instanceof Error ? error.message : String(error)}`);
3150
+ }
3151
+ }
3152
+ return transferred;
3153
+ }
3154
+ function legacySettlementErrorCode(error) {
3155
+ if (error && typeof error === "object" && "code" in error && typeof error.code === "string") {
3156
+ return error.code ?? null;
3157
+ }
3158
+ const detail = error instanceof Error ? error.message : String(error);
3159
+ const match = /^([A-Z][A-Z0-9_]*)(?::|$)/.exec(detail.trim());
3160
+ return match?.[1] ?? null;
3161
+ }
2943
3162
  async function maintainBackgroundDelegations(directory, options = {}) {
2944
3163
  const now = options.now ?? Date.now();
2945
3164
  const staleTimeoutMs = options.staleTimeoutMs ?? DEFAULT_STALE_DELEGATION_TIMEOUT_MS;
@@ -3221,10 +3440,17 @@ async function maintainBackgroundDelegations(directory, options = {}) {
3221
3440
  });
3222
3441
  return emitObservation("failure", error instanceof Error ? error.message : String(error));
3223
3442
  }
3443
+ if (!options.skipLegacyCoderSettlementReconciliation) {
3444
+ try {
3445
+ await reconcileLegacyCoderSettlements(directory, maxRecords, options.onLegacyCoderSettlementReconciled ?? getLegacyCoderSettlementReconciler(directory), options.onLegacyCoderSettlementAdvisoryReplaced);
3446
+ } catch (error) {
3447
+ warn(`[background] legacy coder settlement reconciliation pass failed: ${error instanceof Error ? error.message : String(error)}`);
3448
+ }
3449
+ }
3224
3450
  if (result.status === "failure") {
3225
3451
  return emitObservation("failure", result.reason);
3226
3452
  }
3227
3453
  return emitObservation("ok");
3228
3454
  }
3229
3455
 
3230
- export { MAX_RECOVERY_LEDGER_BYTES, readDelegationHealthArtifact, collectDelegationLedgerHealth, MAX_PR_REVIEW_COLLECTION_RECEIPT_ITEM_IDS, BACKGROUND_DELEGATIONS_FILE, BACKGROUND_DELEGATION_FALLBACK_DIR, BACKGROUND_CODER_RESERVATIONS_FILE, BACKGROUND_DELEGATIONS_CHECKPOINT_FILE, BACKGROUND_DELEGATIONS_MANIFEST_FILE, MAX_LIVE_BACKGROUND_FALLBACKS, MAX_LIVE_BACKGROUND_CODER_RESERVATIONS, MAX_BACKGROUND_OBSERVED_FILES, MAX_BACKGROUND_ADVISORY_CHARS, DELEGATION_COMPACTION_LOW_WATER_BYTES, DELEGATION_COMPACTION_HIGH_WATER_BYTES, MAX_CHECKPOINT_BYTES, MAX_CHECKPOINT_RECORDS, TOMBSTONE_MIN_AGE_MS, BACKGROUND_INGESTION_LEASE_MS, BACKGROUND_CODER_RESERVATION_LEASE_MS, BACKGROUND_CODER_RESERVATION_LEASE_MAX_MS, BACKGROUND_CODER_RESERVATION_LEASE_MIN_MS, DEFAULT_STALE_DELEGATION_TIMEOUT_MS, DEFAULT_SWEEPABLE_DELEGATION_STATUSES, _checkpointInternals, isUnsettledWorktreeOwner, compactBackgroundDelegations, readDelegations, scanDelegationsForRecovery, findByCorrelationId, recordPendingDelegationDetailed, recordPendingDelegation, buildPromptSnapshot, appendDelegationTransition, buildBackgroundCompletionEventId, claimTerminalResult, claimCoderSettlement, normalizeBackgroundObservedFiles, updateCoderSettlement, claimDelegationIngestion, recordDelegationIngestionResult, putPendingBackgroundAdvisory, preparePendingBackgroundAdvisories, acknowledgeObservedBackgroundAdvisories, releasePreparedBackgroundAdvisories, findByBatchId, findOpenAsyncLaneBatches, sweepStaleDelegations, readDelegationFallback, listDelegationFallbacks, scanDelegationFallbacksForRecovery, writeDelegationFallback, removeDelegationFallback, findDelegationForCompletion, promoteDelegationFallback, buildBackgroundCoderReservationId, scanBackgroundCoderReservationsForAdmission, reserveBackgroundCoderSlot, bindBackgroundCoderReservation, releaseBackgroundCoderReservation, maintainBackgroundDelegations };
3456
+ export { MAX_RECOVERY_LEDGER_BYTES, readDelegationHealthArtifact, collectDelegationLedgerHealth, MAX_PR_REVIEW_COLLECTION_RECEIPT_ITEM_IDS, BACKGROUND_DELEGATIONS_FILE, BACKGROUND_DELEGATION_FALLBACK_DIR, BACKGROUND_CODER_RESERVATIONS_FILE, BACKGROUND_DELEGATIONS_CHECKPOINT_FILE, BACKGROUND_DELEGATIONS_MANIFEST_FILE, MAX_LIVE_BACKGROUND_FALLBACKS, MAX_LIVE_BACKGROUND_CODER_RESERVATIONS, MAX_BACKGROUND_OBSERVED_FILES, MAX_BACKGROUND_ADVISORY_CHARS, LEGACY_CODER_SETTLEMENT_PENDING_ADVISORY_MARKER, DELEGATION_COMPACTION_LOW_WATER_BYTES, DELEGATION_COMPACTION_HIGH_WATER_BYTES, MAX_CHECKPOINT_BYTES, MAX_CHECKPOINT_RECORDS, TOMBSTONE_MIN_AGE_MS, BACKGROUND_INGESTION_LEASE_MS, BACKGROUND_CODER_RESERVATION_LEASE_MS, BACKGROUND_CODER_RESERVATION_LEASE_MAX_MS, BACKGROUND_CODER_RESERVATION_LEASE_MIN_MS, DEFAULT_STALE_DELEGATION_TIMEOUT_MS, DEFAULT_SWEEPABLE_DELEGATION_STATUSES, _checkpointInternals, isUnsettledWorktreeOwner, compactBackgroundDelegations, readDelegations, scanDelegationsForRecovery, findByCorrelationId, recordPendingDelegationDetailed, recordPendingDelegation, buildPromptSnapshot, appendDelegationTransition, buildBackgroundCompletionEventId, claimTerminalResult, claimCoderSettlement, normalizeBackgroundObservedFiles, updateCoderSettlement, registerLegacyCoderSettlementReconciler, _internals, markLegacyCoderSettlementTransferPending, clearLegacyCoderSettlementTransferPending, claimDelegationIngestion, recordDelegationIngestionResult, putPendingBackgroundAdvisory, replacePendingBackgroundAdvisory, preparePendingBackgroundAdvisories, acknowledgeObservedBackgroundAdvisories, releasePreparedBackgroundAdvisories, findByBatchId, findOpenAsyncLaneBatches, sweepStaleDelegations, readDelegationFallback, listDelegationFallbacks, scanDelegationFallbacksForRecovery, writeDelegationFallback, removeDelegationFallback, findDelegationForCompletion, promoteDelegationFallback, buildBackgroundCoderReservationId, scanBackgroundCoderReservationsForAdmission, reserveBackgroundCoderSlot, bindBackgroundCoderReservation, releaseBackgroundCoderReservation, maintainBackgroundDelegations };
@@ -4,26 +4,26 @@ import {
4
4
  } from "./index-4cgee5vh.js";
5
5
  import {
6
6
  loadPluginConfigWithMeta
7
- } from "./index-4y7g04py.js";
7
+ } from "./index-dm9tc6qb.js";
8
8
  import {
9
9
  KnowledgeConfigSchema,
10
10
  init_schema
11
- } from "./index-tnm9bb8b.js";
11
+ } from "./index-57t97rtr.js";
12
12
  import {
13
13
  resolveHiveEventsPath
14
14
  } from "./index-ae75rja9.js";
15
15
  import {
16
16
  resolveKnowledgeStoreDir
17
- } from "./index-3db7xza0.js";
17
+ } from "./index-r0dactw2.js";
18
18
  import {
19
19
  atomicWriteFile
20
- } from "./index-s0a4ewkb.js";
20
+ } from "./index-j6q3k628.js";
21
21
  import {
22
22
  assertProjectRoot
23
- } from "./index-vtdwkfbv.js";
23
+ } from "./index-xagq35tf.js";
24
24
  import {
25
25
  emit
26
- } from "./index-ttqnhxxq.js";
26
+ } from "./index-h1g8w4v0.js";
27
27
  import {
28
28
  require_proper_lockfile
29
29
  } from "./index-7g4c7s5r.js";
@@ -2793,7 +2793,7 @@ async function applyKnowledgeVerdictFeedback(directory, options) {
2793
2793
  }
2794
2794
  let bumps = 0;
2795
2795
  if (deltas.length > 0) {
2796
- const { bumpKnowledgeConfidenceBatch } = await import("./knowledge-store-336hyzs8.js");
2796
+ const { bumpKnowledgeConfidenceBatch } = await import("./knowledge-store-zjq5mz2d.js");
2797
2797
  bumps = await bumpKnowledgeConfidenceBatch(directory, deltas, options?.floorOptions);
2798
2798
  }
2799
2799
  return {
@@ -4,7 +4,7 @@ import {
4
4
  readShellAuditTail,
5
5
  redactPath,
6
6
  redactShellCommand
7
- } from "./index-3hdnfmhp.js";
7
+ } from "./index-xq2v52tt.js";
8
8
 
9
9
  // src/services/guardrail-log-service.ts
10
10
  var BLOCK_TYPES = new Set([
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  atomicWriteFile
4
- } from "./index-s0a4ewkb.js";
4
+ } from "./index-j6q3k628.js";
5
5
  import {
6
6
  init_logger,
7
7
  warn