opencode-swarm 7.132.2 → 7.134.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 (122) hide show
  1. package/README.md +4 -1
  2. package/dist/agents/agent-output-schema.d.ts +74 -0
  3. package/dist/agents/critic.d.ts +2 -1
  4. package/dist/agents/reviewer.d.ts +1 -1
  5. package/dist/background/completion-observer.d.ts +17 -5
  6. package/dist/background/pending-delegations.d.ts +315 -2
  7. package/dist/background/stage-b-gates.d.ts +2 -0
  8. package/dist/cli/{config-doctor-bp5spb79.js → config-doctor-t5r92674.js} +3 -3
  9. package/dist/cli/{core-wg3re04e.js → core-d6yd2jzv.js} +2 -2
  10. package/dist/cli/{curation-policy-7zp2m9gv.js → curation-policy-3smfn2a3.js} +7 -7
  11. package/dist/cli/{curator-drift-y1wm4atk.js → curator-drift-tsyyf4b4.js} +4 -4
  12. package/dist/cli/{curator-h067mrcc.js → curator-hva8f3nf.js} +31 -29
  13. package/dist/cli/{curator-llm-factory-605d08hf.js → curator-llm-factory-p3aqev12.js} +31 -29
  14. package/dist/cli/{dispatch-3mhgqj2x.js → dispatch-gxbeb2ps.js} +2 -2
  15. package/dist/cli/{evidence-summary-service-jfagmvrh.js → evidence-summary-service-mrzsjpg4.js} +12 -11
  16. package/dist/cli/{gate-evidence-cy2te3x8.js → gate-evidence-b5v1xvxp.js} +4 -4
  17. package/dist/cli/guardrail-explain-k8mcvk61.js +57 -0
  18. package/dist/cli/{guardrail-log-aa112fxv.js → guardrail-log-absma1rv.js} +5 -5
  19. package/dist/cli/{hive-promoter-nv0m5rzk.js → hive-promoter-jwd51gzk.js} +31 -29
  20. package/dist/cli/{index-g4mnf3p5.js → index-1j3682j8.js} +5 -5
  21. package/dist/cli/{index-6ccynjv3.js → index-2njes601.js} +8 -8
  22. package/dist/cli/{index-w9cb5zwh.js → index-2t1n9k7b.js} +4 -4
  23. package/dist/cli/{index-f6480ee6.js → index-3dtjhr26.js} +5259 -1759
  24. package/dist/cli/{index-2tn5h2zp.js → index-4p02dp92.js} +6 -6
  25. package/dist/cli/index-b4z7s917.js +80 -0
  26. package/dist/cli/{index-bvp2v7k1.js → index-b5ek2cge.js} +266 -19
  27. package/dist/cli/index-b8zgtz81.js +123 -0
  28. package/dist/cli/{index-3s9rfnqq.js → index-baawkm48.js} +12 -12
  29. package/dist/cli/{index-fgcmxjp7.js → index-c3e0ymrg.js} +1 -1
  30. package/dist/cli/{index-q27bajqb.js → index-cfkvc5q9.js} +3 -3
  31. package/dist/cli/{index-7mkpsw6g.js → index-dd7ttx8x.js} +1 -1
  32. package/dist/cli/{index-jgfcp9bh.js → index-dgxgvzab.js} +7 -7
  33. package/dist/cli/{index-8d3m0ge3.js → index-eedq2y40.js} +48 -34
  34. package/dist/cli/{index-630badhp.js → index-g87ty4wp.js} +149 -6
  35. package/dist/cli/{index-yvv1wt2h.js → index-hgh01f6h.js} +25 -3
  36. package/dist/cli/{index-9cf1yr67.js → index-j6ywarjp.js} +3 -3
  37. package/dist/cli/{index-mwkwyej1.js → index-jpkxjmfw.js} +5 -5
  38. package/dist/cli/{index-03zyn94g.js → index-k742ecbm.js} +178 -222
  39. package/dist/cli/{index-y5qp59rc.js → index-kapharv7.js} +10 -4
  40. package/dist/cli/{index-djwemsjn.js → index-m2s0gbzt.js} +2 -2
  41. package/dist/cli/{index-4ff0x4cg.js → index-p8hezdtz.js} +1 -1
  42. package/dist/cli/{index-k4tmx21m.js → index-rkyhv4p5.js} +2 -2
  43. package/dist/cli/{index-3x761jqv.js → index-wk1h5ec2.js} +1 -1
  44. package/dist/cli/{index-jj4earrh.js → index-xfejq1p9.js} +1 -1
  45. package/dist/cli/{index-rt5jgktq.js → index-y0kk3rtv.js} +2 -2
  46. package/dist/cli/index-y3v1404y.js +1625 -0
  47. package/dist/cli/index.js +35 -31
  48. package/dist/cli/{knowledge-escalator-j0nceas7.js → knowledge-escalator-mkdac2m7.js} +8 -8
  49. package/dist/cli/{knowledge-events-gpqc62jr.js → knowledge-events-jjc9qbe0.js} +6 -6
  50. package/dist/cli/{knowledge-link-4yd2z8ev.js → knowledge-link-nc4y2zkq.js} +5 -5
  51. package/dist/cli/{knowledge-store-ggxr3ww5.js → knowledge-store-9e0w1kxm.js} +6 -6
  52. package/dist/cli/{knowledge-validator-007smap6.js → knowledge-validator-h1nrn2pk.js} +9 -9
  53. package/dist/cli/pending-delegations-v9e40hfk.js +96 -0
  54. package/dist/cli/{pr-subscriptions-zqbmctwz.js → pr-subscriptions-ztq40hrt.js} +7 -7
  55. package/dist/cli/{scan-cursor-wz4bff7a.js → scan-cursor-mk3tq3sf.js} +7 -7
  56. package/dist/cli/{schema-023gwne7.js → schema-bjb0yzsq.js} +7 -3
  57. package/dist/cli/{scope-persistence-dm5bab50.js → scope-persistence-hz3zmmsv.js} +5 -5
  58. package/dist/cli/{skill-generator-rtsg1m7x.js → skill-generator-p1de0wkr.js} +10 -10
  59. package/dist/cli/worktree-collision-ownership-c4bdnjtx.js +221 -0
  60. package/dist/commands/command-dispatch.d.ts +7 -0
  61. package/dist/commands/index.d.ts +7 -0
  62. package/dist/commands/registry.d.ts +16 -0
  63. package/dist/commands/review.d.ts +21 -0
  64. package/dist/config/agent-names.d.ts +3 -3
  65. package/dist/config/evidence-schema.d.ts +47 -47
  66. package/dist/config/index.d.ts +2 -2
  67. package/dist/config/schema.d.ts +58 -6
  68. package/dist/consensus/contracts.d.ts +3 -3
  69. package/dist/evaluation/ephemeral-agent-dispatcher.d.ts +64 -0
  70. package/dist/evaluation/model-dispatcher.d.ts +11 -5
  71. package/dist/hooks/auto-review.d.ts +30 -65
  72. package/dist/hooks/delegation-gate/worktree-collision-ownership.d.ts +28 -0
  73. package/dist/hooks/delegation-gate/worktree-isolation.d.ts +63 -1
  74. package/dist/hooks/delegation-gate/worktree-merge-status.d.ts +14 -0
  75. package/dist/hooks/delegation-gate/worktree-ownership-tag.d.ts +19 -0
  76. package/dist/hooks/delegation-gate/worktree-provisioning-owner.d.ts +30 -0
  77. package/dist/hooks/delegation-gate.d.ts +15 -6
  78. package/dist/hooks/guardrails/tool-before.d.ts +8 -0
  79. package/dist/hooks/index.d.ts +1 -1
  80. package/dist/hooks/init-orphan-recovery.d.ts +17 -0
  81. package/dist/hooks/review-receipt-collector.d.ts +53 -10
  82. package/dist/hooks/review-receipt-scope.d.ts +74 -0
  83. package/dist/hooks/review-receipt.d.ts +104 -10
  84. package/dist/hooks/reviewer-scope-file-fingerprint.d.ts +21 -0
  85. package/dist/hooks/reviewer-scope-lifecycle.d.ts +19 -0
  86. package/dist/hooks/task-result-classifier.d.ts +6 -0
  87. package/dist/index.d.ts +2 -0
  88. package/dist/index.js +583 -524
  89. package/dist/memory/schema.d.ts +1 -1
  90. package/dist/review/contracts.d.ts +29 -0
  91. package/dist/review/diff-source.d.ts +134 -0
  92. package/dist/review/engine.d.ts +60 -0
  93. package/dist/review/evidence.d.ts +88 -0
  94. package/dist/review/finding-validator.d.ts +77 -0
  95. package/dist/review/phase-runner.d.ts +37 -0
  96. package/dist/review/runtime.d.ts +32 -0
  97. package/dist/scope/scope-binding.d.ts +9 -0
  98. package/dist/services/config-doctor.d.ts +12 -0
  99. package/dist/session/snapshot-writer.d.ts +2 -0
  100. package/dist/state.d.ts +222 -1
  101. package/dist/tools/dispatch-lanes.d.ts +3 -1
  102. package/dist/tools/epic-record-divergence.d.ts +5 -5
  103. package/dist/tools/lean-turbo-review.d.ts +4 -1
  104. package/dist/tools/lean-turbo-run-phase.d.ts +3 -1
  105. package/dist/tools/phase-complete/gates/final-review-gate.d.ts +18 -0
  106. package/dist/tools/phase-complete/gates/index.d.ts +1 -0
  107. package/dist/tools/phase-complete/gates/types.d.ts +10 -0
  108. package/dist/tools/phase-complete.d.ts +13 -1
  109. package/dist/tools/plugin-registration.d.ts +3 -1
  110. package/dist/tools/swarm-command.d.ts +4 -1
  111. package/dist/tools/tool-metadata.d.ts +22 -22
  112. package/dist/turbo/lean/integration.d.ts +18 -2
  113. package/dist/turbo/lean/reviewer.d.ts +19 -3
  114. package/dist/turbo/lean/runner.d.ts +1 -1
  115. package/dist/worktree/merge.d.ts +47 -1
  116. package/package.json +1 -1
  117. package/dist/cli/guardrail-explain-s7vzm6z7.js +0 -55
  118. package/dist/cli/index-y2pfmd0z.js +0 -259
  119. package/dist/cli/pending-delegations-37t4xecr.js +0 -34
  120. package/dist/cli/{index-9f71ye47.js → index-13xxjfhn.js} +3 -3
  121. package/dist/cli/{index-s80bsjkj.js → index-2ghkk9ve.js} +6 -6
  122. package/dist/cli/{index-76kvm9z5.js → index-5nybajn9.js} +3 -3
@@ -1,3 +1,5 @@
1
+ import type { ReviewModelDispatcher } from '../../review/contracts';
2
+ import { type ReviewAgentModelRegistry } from '../../review/runtime';
1
3
  import { type ModelOverride } from '../../utils/model-dispatch-fallback';
2
4
  import { type LaneEvidence, listLaneEvidence, readPhaseEvidence, type ValidationArtifact } from './evidence';
3
5
  /**
@@ -15,6 +17,20 @@ export interface LeanTurboPhaseCriticConfig {
15
17
  * Default: no timeout (critic is awaited indefinitely).
16
18
  */
17
19
  timeoutMs?: number;
20
+ /**
21
+ * Instance-local dispatcher bound to the active plugin client.
22
+ * New runtime call paths inject this instead of reading global client state.
23
+ */
24
+ dispatcher?: ReviewModelDispatcher;
25
+ /**
26
+ * Immutable agent-name registry captured by the plugin instance.
27
+ * Direct callers may omit this only when a single/default critic suffices.
28
+ */
29
+ generatedAgentNames?: readonly string[];
30
+ /** Exact active agent identity used to select this session's swarm. */
31
+ activeAgentName?: string;
32
+ /** Immutable plugin-instance model configuration for fallback ownership. */
33
+ agentModelRegistry?: ReviewAgentModelRegistry;
18
34
  }
19
35
  /**
20
36
  * Result of a phase critic dispatch.
@@ -43,7 +59,7 @@ interface ReviewerEvidence {
43
59
  * for the default swarm. Follows the same suffix-based resolution used by
44
60
  * `getCanonicalAgentRole` so that arbitrary swarm prefixes are handled correctly.
45
61
  */
46
- declare function resolveDefaultCriticAgent(generatedAgentNames: string[]): string;
62
+ declare function resolveDefaultCriticAgent(generatedAgentNames: readonly string[], activeAgentName?: string): string;
47
63
  /**
48
64
  * Reads the reviewer evidence from .swarm/evidence/{phase}/lean-turbo-reviewer.json.
49
65
  *
@@ -114,7 +130,7 @@ export declare const _internals: {
114
130
  compileCriticPackage: typeof compileCriticPackage;
115
131
  parseCriticVerdict: typeof parseCriticVerdict;
116
132
  writeCriticEvidence: typeof writeCriticEvidence;
117
- dispatchCriticAgent: (directory: string, pkg: CriticPackage, agentName: string, timeoutMs: number, parentSessionId?: string, model?: ModelOverride) => Promise<string>;
133
+ dispatchCriticAgent: (directory: string, pkg: CriticPackage, agentName: string, timeoutMs: number, parentSessionId?: string, model?: ModelOverride, dispatcher?: ReviewModelDispatcher) => Promise<string>;
118
134
  resolveDefaultCriticAgent: typeof resolveDefaultCriticAgent;
119
135
  readReviewerEvidence: typeof readReviewerEvidence;
120
136
  listLaneEvidence: typeof listLaneEvidence;
@@ -1,3 +1,5 @@
1
+ import { type ReviewModelDispatcher } from '../../review/contracts';
2
+ import { type ReviewAgentModelRegistry } from '../../review/runtime';
1
3
  import { type ModelOverride } from '../../utils/model-dispatch-fallback';
2
4
  import { type LaneEvidence, listLaneEvidence, readPhaseEvidence, type ValidationArtifact } from './evidence';
3
5
  import { readPersisted } from './state';
@@ -13,7 +15,7 @@ export interface LeanTurboPhaseReviewerConfig {
13
15
  reviewerAgent?: string;
14
16
  /**
15
17
  * Timeout in milliseconds for the reviewer dispatch.
16
- * Default: no timeout (reviewer is awaited indefinitely).
18
+ * Default: the shared bounded dispatcher timeout.
17
19
  */
18
20
  timeoutMs?: number;
19
21
  /**
@@ -22,6 +24,20 @@ export interface LeanTurboPhaseReviewerConfig {
22
24
  * Default: false.
23
25
  */
24
26
  requireDiffSummary?: boolean;
27
+ /**
28
+ * Instance-local dispatcher bound to the active plugin client.
29
+ * New runtime call paths inject this instead of reading global client state.
30
+ */
31
+ dispatcher?: ReviewModelDispatcher;
32
+ /**
33
+ * Immutable agent-name registry captured by the plugin instance.
34
+ * Direct callers may omit this only when a single/default reviewer suffices.
35
+ */
36
+ generatedAgentNames?: readonly string[];
37
+ /** Exact active agent identity used to select this session's swarm. */
38
+ activeAgentName?: string;
39
+ /** Immutable plugin-instance model configuration for fallback ownership. */
40
+ agentModelRegistry?: ReviewAgentModelRegistry;
25
41
  }
26
42
  /**
27
43
  * Result of a phase reviewer dispatch.
@@ -43,7 +59,7 @@ export interface PhaseReviewerResult {
43
59
  *
44
60
  * Exported for reuse by the auto-review hook (src/hooks/auto-review.ts).
45
61
  */
46
- export declare function resolveDefaultReviewerAgent(generatedAgentNames: string[]): string;
62
+ export declare function resolveDefaultReviewerAgent(generatedAgentNames: readonly string[], activeAgentName?: string): string;
47
63
  /**
48
64
  * Compiles a structured review package from lane and phase evidence.
49
65
  */
@@ -103,7 +119,7 @@ export declare const _internals: {
103
119
  compileReviewPackage: typeof compileReviewPackage;
104
120
  parseReviewerVerdict: typeof parseReviewerVerdict;
105
121
  writeReviewerEvidence: typeof writeReviewerEvidence;
106
- dispatchReviewerAgent: (directory: string, pkg: ReviewPackage, agentName: string, timeoutMs: number, parentSessionId?: string, model?: ModelOverride) => Promise<string>;
122
+ dispatchReviewerAgent: (directory: string, pkg: ReviewPackage, agentName: string, timeoutMs: number, parentSessionId?: string, model?: ModelOverride, dispatcher?: ReviewModelDispatcher) => Promise<string>;
107
123
  resolveDefaultReviewerAgent: typeof resolveDefaultReviewerAgent;
108
124
  listLaneEvidence: typeof listLaneEvidence;
109
125
  readPhaseEvidence: typeof readPhaseEvidence;
@@ -250,7 +250,7 @@ export declare class LeanTurboRunner {
250
250
  /** OpenCode SDK client. Pass null to stay fail-closed. Omit to allow test mock injection. */
251
251
  opencodeClient?: OpencodeClient | null;
252
252
  /** Pre-registered generated agent names */
253
- generatedAgentNames?: string[];
253
+ generatedAgentNames?: readonly string[];
254
254
  /** Lean-mode configuration. Falls back to hardcoded defaults if omitted. */
255
255
  leanConfig?: LeanTurboConfig;
256
256
  });
@@ -65,6 +65,10 @@ export interface DirtyMergeSuccess {
65
65
  strategy: string;
66
66
  autoCommitted: boolean;
67
67
  cleaned: boolean;
68
+ /** True when a resumed operation was already present on the target. */
69
+ reconciled?: boolean;
70
+ /** Durable identity for the Git operation, when settlement tracking is enabled. */
71
+ provenance?: MergeOperationProvenance;
68
72
  }
69
73
  export interface DirtyMergePartial {
70
74
  partial: true;
@@ -73,11 +77,45 @@ export interface DirtyMergePartial {
73
77
  cleaned: boolean;
74
78
  message: string;
75
79
  conflictFiles?: string[];
80
+ provenance?: MergeOperationProvenance;
76
81
  }
77
82
  export interface DirtyMergeFailure {
78
83
  failed: true;
79
84
  stage: string;
80
85
  message: string;
86
+ provenance?: MergeOperationProvenance;
87
+ }
88
+ /**
89
+ * Durable identity for a standard-worktree merge-back operation.
90
+ *
91
+ * `sourceHead` is captured after the lane's dirty state is auto-committed and
92
+ * `targetHeadBefore` immediately before the merge starts. The stable
93
+ * `operationId` is supplied by the durable background-delegation record.
94
+ */
95
+ export interface MergeOperationProvenance {
96
+ operationId: string;
97
+ sourceHead: string;
98
+ targetHeadBefore: string;
99
+ branchName: string;
100
+ strategy: MergeStrategy;
101
+ }
102
+ export type MergeReconciliationResult = {
103
+ landed: true;
104
+ method: 'ancestry' | 'cherry-pick-trailer';
105
+ } | {
106
+ landed: false;
107
+ error?: string;
108
+ };
109
+ export interface DirtyMergeOptions {
110
+ /** Stable identifier allocated before the merge-back begins. */
111
+ operationId?: string;
112
+ /** Previously persisted provenance when resuming a `settling` operation. */
113
+ resume?: MergeOperationProvenance;
114
+ /**
115
+ * Awaited after auto-commit and HEAD capture, but before the Git merge.
116
+ * A rejection fails closed without invoking the merge.
117
+ */
118
+ onBeforeMerge?: (provenance: MergeOperationProvenance) => Promise<void>;
81
119
  }
82
120
  export interface OrphanCleanupResult {
83
121
  removed: string[];
@@ -123,6 +161,14 @@ export declare function getMergeStrategy(config: {
123
161
  * @returns Discriminated union: success, conflict, or failure.
124
162
  */
125
163
  export declare function mergeLaneBranch(primaryDir: string, branchName: string, strategy: MergeStrategy): Promise<MergeSuccess | MergeConflict | MergeFailure>;
164
+ /**
165
+ * Detect whether a previously-started merge-back already landed on the target.
166
+ *
167
+ * Merge and rebase settlement uses ancestry. Cherry-pick settlement uses the
168
+ * exact provenance trailer emitted by Git's `cherry-pick -x`; patch identity or
169
+ * subject matching is intentionally insufficient.
170
+ */
171
+ export declare function reconcileLandedMerge(primaryDir: string, provenance: MergeOperationProvenance): Promise<MergeReconciliationResult>;
126
172
  /**
127
173
  * Cleans up a lane branch after a successful merge.
128
174
  *
@@ -168,7 +214,7 @@ export declare function handleMergeConflict(primaryDir: string, _branchName: str
168
214
  * @param strategy - Merge strategy to use.
169
215
  * @returns Discriminated union: success, partial, or failure.
170
216
  */
171
- export declare function attemptMergeBackFromDirty(worktreePath: string, branchName: string, primaryDir: string, strategy: MergeStrategy): Promise<DirtyMergeSuccess | DirtyMergePartial | DirtyMergeFailure>;
217
+ export declare function attemptMergeBackFromDirty(worktreePath: string, branchName: string, primaryDir: string, strategy: MergeStrategy, options?: DirtyMergeOptions): Promise<DirtyMergeSuccess | DirtyMergePartial | DirtyMergeFailure>;
172
218
  /**
173
219
  * Extracts the session ID from a swarm-lane branch name.
174
220
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-swarm",
3
- "version": "7.132.2",
3
+ "version": "7.134.0",
4
4
  "description": "Architect-centric agentic swarm plugin for OpenCode - hub-and-spoke orchestration with SME consultation, code generation, and QA review",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,55 +0,0 @@
1
- // @bun
2
- import {
3
- handleGuardrailExplain
4
- } from "./index-k4tmx21m.js";
5
- import"./index-f6480ee6.js";
6
- import"./index-yvv1wt2h.js";
7
- import"./index-630badhp.js";
8
- import"./index-03zyn94g.js";
9
- import"./index-4905hd2m.js";
10
- import"./index-134d35c1.js";
11
- import"./index-9f71ye47.js";
12
- import"./index-9cf1yr67.js";
13
- import"./index-mwkwyej1.js";
14
- import"./index-djwemsjn.js";
15
- import"./index-vxv732ex.js";
16
- import"./index-c8s9a3zh.js";
17
- import"./index-9ss2m4rs.js";
18
- import"./index-g4mnf3p5.js";
19
- import"./index-6ccynjv3.js";
20
- import"./index-rt5jgktq.js";
21
- import"./index-rtry5xyf.js";
22
- import"./index-3s9rfnqq.js";
23
- import"./index-jgfcp9bh.js";
24
- import"./index-ae75rja9.js";
25
- import"./index-q27bajqb.js";
26
- import"./index-jj4earrh.js";
27
- import"./index-k5jrywpr.js";
28
- import"./index-n832052r.js";
29
- import"./index-bvp2v7k1.js";
30
- import"./index-bk5tah7q.js";
31
- import"./index-8fwhhayc.js";
32
- import"./index-q1exe2b3.js";
33
- import"./index-4ff0x4cg.js";
34
- import"./index-2tn5h2zp.js";
35
- import"./index-1kz6da87.js";
36
- import"./index-w9cb5zwh.js";
37
- import"./index-4rhhvd1a.js";
38
- import"./index-y2pfmd0z.js";
39
- import"./index-s80bsjkj.js";
40
- import"./index-z6xqpmqg.js";
41
- import"./index-zjygnfay.js";
42
- import"./index-zgwm4ryv.js";
43
- import"./index-h3k62043.js";
44
- import"./index-3x761jqv.js";
45
- import"./index-7mkpsw6g.js";
46
- import"./index-fsrp8wp3.js";
47
- import"./index-76kvm9z5.js";
48
- import"./index-q2rrv0cy.js";
49
- import"./index-bpmtbmy9.js";
50
- import"./index-7g4c7s5r.js";
51
- import"./index-qe3v54nb.js";
52
- import"./index-a76rekgs.js";
53
- export {
54
- handleGuardrailExplain
55
- };
@@ -1,259 +0,0 @@
1
- // @bun
2
- import {
3
- validateSwarmPath
4
- } from "./index-s80bsjkj.js";
5
- import {
6
- init_logger,
7
- warn
8
- } from "./index-zgwm4ryv.js";
9
- import {
10
- withEvidenceLock
11
- } from "./index-76kvm9z5.js";
12
- import {
13
- exports_external,
14
- init_zod
15
- } from "./index-bpmtbmy9.js";
16
-
17
- // src/background/pending-delegations.ts
18
- init_zod();
19
- import { createHash } from "crypto";
20
- import * as fs from "fs";
21
- import * as path from "path";
22
- init_logger();
23
- var BACKGROUND_DELEGATIONS_FILE = "background-delegations.jsonl";
24
- var STORE_LOCK_AGENT = "background";
25
- var STORE_LOCK_TASK = "background-delegations";
26
- var ResultSchema = exports_external.object({
27
- text: exports_external.string().optional(),
28
- error: exports_external.string().optional(),
29
- chars: exports_external.number(),
30
- truncated: exports_external.boolean(),
31
- digest: exports_external.string(),
32
- outputRef: exports_external.string().optional(),
33
- outputPreviewChars: exports_external.number().optional(),
34
- outputDegraded: exports_external.boolean().optional(),
35
- outputArtifactError: exports_external.string().optional(),
36
- transcriptIncomplete: exports_external.boolean().optional(),
37
- messageCount: exports_external.number().optional()
38
- }).strict();
39
- var WorkspaceSchema = exports_external.object({
40
- directory: exports_external.string(),
41
- gitHead: exports_external.string().nullable(),
42
- dirtyHash: exports_external.string().nullable(),
43
- changedFiles: exports_external.array(exports_external.string()).nullable().optional(),
44
- prHeadSha: exports_external.string().nullable(),
45
- scope: exports_external.string().nullable()
46
- }).strict();
47
- var TaskChangeContextSchema = exports_external.object({
48
- declaredFiles: exports_external.array(exports_external.string()).nullable(),
49
- baseline: WorkspaceSchema
50
- }).strict();
51
- var PromptSchema = exports_external.object({
52
- text: exports_external.string(),
53
- chars: exports_external.number(),
54
- truncated: exports_external.boolean(),
55
- digest: exports_external.string()
56
- }).strict();
57
- var RecordSchema = exports_external.object({
58
- schemaVersion: exports_external.union([exports_external.literal(1), exports_external.literal(2)]),
59
- correlationId: exports_external.string().min(1),
60
- jobId: exports_external.string().nullable(),
61
- subagentSessionId: exports_external.string().min(1),
62
- parentSessionId: exports_external.string().min(1),
63
- callID: exports_external.string(),
64
- normalizedAgent: exports_external.string(),
65
- swarmPrefixedAgent: exports_external.string(),
66
- planTaskId: exports_external.string().nullable(),
67
- evidenceTaskId: exports_external.string().nullable(),
68
- status: exports_external.enum([
69
- "pending",
70
- "running",
71
- "ingestion_error",
72
- "completed",
73
- "error",
74
- "cancelled",
75
- "stale",
76
- "consumed"
77
- ]),
78
- createdAt: exports_external.number(),
79
- updatedAt: exports_external.number(),
80
- batchId: exports_external.string().optional(),
81
- laneId: exports_external.string().optional(),
82
- mode: exports_external.string().optional(),
83
- workflowLane: exports_external.string().optional(),
84
- ownedWorkflowLanes: exports_external.array(exports_external.string().min(1).max(120)).min(1).max(11).optional(),
85
- promptHash: exports_external.string().optional(),
86
- workspace: WorkspaceSchema.optional(),
87
- taskChangeContext: TaskChangeContextSchema.optional(),
88
- prompt: PromptSchema.optional(),
89
- generation: exports_external.number().optional(),
90
- result: ResultSchema.optional(),
91
- completedAt: exports_external.number().optional()
92
- }).strict();
93
- function storePath(directory) {
94
- return validateSwarmPath(directory, BACKGROUND_DELEGATIONS_FILE);
95
- }
96
- function ensureSwarmDir(directory) {
97
- fs.mkdirSync(path.resolve(directory, ".swarm"), { recursive: true });
98
- }
99
- function readDelegations(directory) {
100
- let raw;
101
- try {
102
- raw = fs.readFileSync(storePath(directory), "utf-8");
103
- } catch (err) {
104
- if (err.code === "ENOENT")
105
- return [];
106
- warn(`[background] readDelegations failed: ${err instanceof Error ? err.message : String(err)}`);
107
- return [];
108
- }
109
- const folded = new Map;
110
- for (const line of raw.split(`
111
- `)) {
112
- const trimmed = line.trim();
113
- if (trimmed.length === 0)
114
- continue;
115
- let parsedJson;
116
- try {
117
- parsedJson = JSON.parse(trimmed);
118
- } catch {
119
- continue;
120
- }
121
- const result = RecordSchema.safeParse(parsedJson);
122
- if (!result.success)
123
- continue;
124
- folded.set(result.data.correlationId, result.data);
125
- }
126
- return [...folded.values()];
127
- }
128
- function findByCorrelationId(directory, correlationId) {
129
- if (!correlationId)
130
- return null;
131
- for (const record of readDelegations(directory)) {
132
- if (record.correlationId === correlationId)
133
- return record;
134
- }
135
- return null;
136
- }
137
- function appendRecord(directory, record) {
138
- ensureSwarmDir(directory);
139
- fs.appendFileSync(storePath(directory), `${JSON.stringify(record)}
140
- `, "utf-8");
141
- }
142
- async function recordPendingDelegation(directory, input, options = {}) {
143
- const now = Date.now();
144
- const record = {
145
- schemaVersion: input.batchId ? 2 : 1,
146
- correlationId: input.correlationId,
147
- jobId: input.jobId,
148
- subagentSessionId: input.subagentSessionId,
149
- parentSessionId: input.parentSessionId,
150
- callID: input.callID,
151
- normalizedAgent: input.normalizedAgent,
152
- swarmPrefixedAgent: input.swarmPrefixedAgent,
153
- planTaskId: input.planTaskId,
154
- evidenceTaskId: input.evidenceTaskId,
155
- status: "pending",
156
- createdAt: now,
157
- updatedAt: now,
158
- ...input.batchId ? { batchId: input.batchId } : {},
159
- ...input.laneId ? { laneId: input.laneId } : {},
160
- ...input.mode ? { mode: input.mode } : {},
161
- ...input.workflowLane ? { workflowLane: input.workflowLane } : {},
162
- ...input.ownedWorkflowLanes?.length ? { ownedWorkflowLanes: [...input.ownedWorkflowLanes] } : {},
163
- ...input.promptHash ? { promptHash: input.promptHash } : {},
164
- ...input.workspace ? { workspace: input.workspace } : {},
165
- ...input.taskChangeContext ? { taskChangeContext: input.taskChangeContext } : {},
166
- ...input.prompt ? { prompt: input.prompt } : {},
167
- ...input.generation !== undefined ? { generation: input.generation } : {}
168
- };
169
- try {
170
- await withEvidenceLock(directory, BACKGROUND_DELEGATIONS_FILE, STORE_LOCK_AGENT, STORE_LOCK_TASK, async () => {
171
- if (options.staleTimeoutMs && options.staleTimeoutMs > 0) {
172
- sweepStaleLocked(directory, options.staleTimeoutMs, now);
173
- }
174
- appendRecord(directory, record);
175
- });
176
- return record;
177
- } catch (err) {
178
- warn(`[background] recordPendingDelegation failed: ${err instanceof Error ? err.message : String(err)}`);
179
- return null;
180
- }
181
- }
182
- function buildPromptSnapshot(text, maxChars) {
183
- const boundedMax = Math.max(0, Math.min(maxChars, 20000));
184
- const truncated = text.length > boundedMax;
185
- const bounded = truncated ? text.slice(0, boundedMax) : text;
186
- return {
187
- text: bounded,
188
- chars: text.length,
189
- truncated,
190
- digest: createHash("sha256").update(text).digest("hex")
191
- };
192
- }
193
- async function appendDelegationTransition(directory, correlationId, transition) {
194
- const now = Date.now();
195
- try {
196
- let next = null;
197
- await withEvidenceLock(directory, BACKGROUND_DELEGATIONS_FILE, STORE_LOCK_AGENT, STORE_LOCK_TASK, async () => {
198
- const current = findByCorrelationId(directory, correlationId);
199
- if (!current)
200
- return;
201
- if (isTerminal(current.status) && transition.status !== "consumed" && transition.status !== "ingestion_error") {
202
- next = current;
203
- return;
204
- }
205
- next = {
206
- ...current,
207
- schemaVersion: current.schemaVersion === 1 ? 2 : current.schemaVersion,
208
- status: transition.status,
209
- updatedAt: now,
210
- ...transition.completedAt !== undefined ? { completedAt: transition.completedAt } : transition.status === "completed" || transition.status === "error" ? { completedAt: now } : {},
211
- ...transition.result ? { result: transition.result } : {}
212
- };
213
- appendRecord(directory, next);
214
- });
215
- return next;
216
- } catch (err) {
217
- warn(`[background] appendDelegationTransition failed: ${err instanceof Error ? err.message : String(err)}`);
218
- return null;
219
- }
220
- }
221
- function findByBatchId(directory, batchId, opts) {
222
- if (!batchId)
223
- return [];
224
- return readDelegations(directory).filter((record) => record.batchId === batchId && (opts?.parentSessionId === undefined || record.parentSessionId === opts.parentSessionId));
225
- }
226
- function findOpenAsyncLaneBatches(directory) {
227
- return readDelegations(directory).filter((record) => record.batchId !== undefined && (record.status === "pending" || record.status === "running"));
228
- }
229
- function isTerminal(status) {
230
- return status === "completed" || status === "error" || status === "cancelled" || status === "stale" || status === "consumed";
231
- }
232
- function sweepStaleLocked(directory, timeoutMs, now) {
233
- let swept = 0;
234
- for (const record of readDelegations(directory)) {
235
- if (record.status !== "pending" && record.status !== "running" && record.status !== "ingestion_error")
236
- continue;
237
- if (now - record.updatedAt <= timeoutMs)
238
- continue;
239
- appendRecord(directory, {
240
- ...record,
241
- status: "stale",
242
- updatedAt: now
243
- });
244
- swept += 1;
245
- }
246
- return swept;
247
- }
248
- async function sweepStaleDelegations(directory, timeoutMs) {
249
- if (!timeoutMs || timeoutMs <= 0)
250
- return 0;
251
- try {
252
- return await withEvidenceLock(directory, BACKGROUND_DELEGATIONS_FILE, STORE_LOCK_AGENT, STORE_LOCK_TASK, async () => sweepStaleLocked(directory, timeoutMs, Date.now()));
253
- } catch (err) {
254
- warn(`[background] sweepStaleDelegations failed: ${err instanceof Error ? err.message : String(err)}`);
255
- return 0;
256
- }
257
- }
258
-
259
- export { BACKGROUND_DELEGATIONS_FILE, readDelegations, findByCorrelationId, recordPendingDelegation, buildPromptSnapshot, appendDelegationTransition, findByBatchId, findOpenAsyncLaneBatches, sweepStaleDelegations };
@@ -1,34 +0,0 @@
1
- // @bun
2
- import {
3
- BACKGROUND_DELEGATIONS_FILE,
4
- appendDelegationTransition,
5
- buildPromptSnapshot,
6
- findByBatchId,
7
- findByCorrelationId,
8
- findOpenAsyncLaneBatches,
9
- readDelegations,
10
- recordPendingDelegation,
11
- sweepStaleDelegations
12
- } from "./index-y2pfmd0z.js";
13
- import"./index-s80bsjkj.js";
14
- import"./index-z6xqpmqg.js";
15
- import"./index-zjygnfay.js";
16
- import"./index-zgwm4ryv.js";
17
- import"./index-fsrp8wp3.js";
18
- import"./index-76kvm9z5.js";
19
- import"./index-q2rrv0cy.js";
20
- import"./index-bpmtbmy9.js";
21
- import"./index-7g4c7s5r.js";
22
- import"./index-qe3v54nb.js";
23
- import"./index-a76rekgs.js";
24
- export {
25
- sweepStaleDelegations,
26
- recordPendingDelegation,
27
- readDelegations,
28
- findOpenAsyncLaneBatches,
29
- findByCorrelationId,
30
- findByBatchId,
31
- buildPromptSnapshot,
32
- appendDelegationTransition,
33
- BACKGROUND_DELEGATIONS_FILE
34
- };
@@ -2,12 +2,12 @@
2
2
  import {
3
3
  simpleGlobToRegex
4
4
  } from "./index-z6xqpmqg.js";
5
- import {
6
- warn
7
- } from "./index-zgwm4ryv.js";
8
5
  import {
9
6
  bunSpawnSync
10
7
  } from "./index-qe3v54nb.js";
8
+ import {
9
+ warn
10
+ } from "./index-zgwm4ryv.js";
11
11
  import {
12
12
  __export
13
13
  } from "./index-a76rekgs.js";
@@ -1,16 +1,16 @@
1
1
  // @bun
2
- import {
3
- SwarmError
4
- } from "./index-z6xqpmqg.js";
5
- import {
6
- warn
7
- } from "./index-zgwm4ryv.js";
8
2
  import {
9
3
  readCachedTextFile
10
4
  } from "./index-fsrp8wp3.js";
5
+ import {
6
+ SwarmError
7
+ } from "./index-z6xqpmqg.js";
11
8
  import {
12
9
  bunFile
13
10
  } from "./index-qe3v54nb.js";
11
+ import {
12
+ warn
13
+ } from "./index-zgwm4ryv.js";
14
14
 
15
15
  // src/hooks/utils.ts
16
16
  import * as fs from "fs";
@@ -1,10 +1,10 @@
1
1
  // @bun
2
- import {
3
- emit
4
- } from "./index-q2rrv0cy.js";
5
2
  import {
6
3
  require_proper_lockfile
7
4
  } from "./index-7g4c7s5r.js";
5
+ import {
6
+ emit
7
+ } from "./index-q2rrv0cy.js";
8
8
  import {
9
9
  __toESM
10
10
  } from "./index-a76rekgs.js";