opencode-swarm-plugin 0.58.4 → 0.59.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.
@@ -201,4 +201,22 @@ export declare function getEpicDecisionTraces(projectKey: string, epicId: string
201
201
  * @returns Array of decision traces
202
202
  */
203
203
  export declare function getDecisionTracesByType(projectKey: string, decisionType: string): Promise<import("swarm-mail").DecisionTrace[]>;
204
+ /**
205
+ * Input for linking an outcome to a decision trace
206
+ */
207
+ export interface LinkOutcomeInput {
208
+ projectKey: string;
209
+ beadId: string;
210
+ outcomeEventId: number;
211
+ }
212
+ /**
213
+ * Link an outcome event to its decision trace and calculate quality score.
214
+ *
215
+ * Finds the most recent decision trace for the bead and links the outcome
216
+ * event to it, triggering quality score calculation.
217
+ *
218
+ * @param input - Outcome linking details
219
+ * @returns true if linked successfully, false if no trace found or error
220
+ */
221
+ export declare function linkOutcomeToDecisionTrace(input: LinkOutcomeInput): Promise<boolean>;
204
222
  //# sourceMappingURL=decision-trace-integration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decision-trace-integration.d.ts","sourceRoot":"","sources":["../src/decision-trace-integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AA6BH;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,cAAc,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GACvF,MAAM,EAAE,CAgBV;AAMD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAA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CAAC;IACf,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAMD;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,iDAYf;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,iDAYrB"}
1
+ {"version":3,"file":"decision-trace-integration.d.ts","sourceRoot":"","sources":["../src/decision-trace-integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AA6BH;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,cAAc,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GACvF,MAAM,EAAE,CAgBV;AAMD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,KAAK,CAAC;QACrB,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,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AgB,CACpC,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAMD;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,iDAYf;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,iDAYrB;AAMD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;GAQG;AACH,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,OAAO,CAAC,CAuBlB"}
package/dist/index.js CHANGED
@@ -22942,6 +22942,237 @@ Codebase context considered: ${args.codebase_context.slice(0, 200)}...`;
22942
22942
  };
22943
22943
  });
22944
22944
 
22945
+ // src/decision-trace-integration.ts
22946
+ var exports_decision_trace_integration = {};
22947
+ __export(exports_decision_trace_integration, {
22948
+ traceWorkerSpawn: () => traceWorkerSpawn,
22949
+ traceStrategySelection: () => traceStrategySelection,
22950
+ traceScopeChange: () => traceScopeChange,
22951
+ traceReviewDecision: () => traceReviewDecision,
22952
+ traceFileSelection: () => traceFileSelection,
22953
+ linkOutcomeToDecisionTrace: () => linkOutcomeToDecisionTrace,
22954
+ getEpicDecisionTraces: () => getEpicDecisionTraces,
22955
+ getDecisionTracesByType: () => getDecisionTracesByType,
22956
+ extractMemoryIds: () => extractMemoryIds
22957
+ });
22958
+ import {
22959
+ createDecisionTrace,
22960
+ createEntityLink
22961
+ } from "swarm-mail";
22962
+ import { createLibSQLAdapter } from "swarm-mail";
22963
+ import { getDatabasePath } from "swarm-mail";
22964
+ async function getTraceDb(projectPath) {
22965
+ const dbPath = getDatabasePath(projectPath);
22966
+ return createLibSQLAdapter({ url: `file:${dbPath}` });
22967
+ }
22968
+ function extractMemoryIds(precedentCited) {
22969
+ if (!precedentCited) {
22970
+ return [];
22971
+ }
22972
+ if (precedentCited.memoryIds && Array.isArray(precedentCited.memoryIds)) {
22973
+ return precedentCited.memoryIds;
22974
+ }
22975
+ if (precedentCited.memoryId) {
22976
+ return [precedentCited.memoryId];
22977
+ }
22978
+ return [];
22979
+ }
22980
+ async function traceStrategySelection(input) {
22981
+ try {
22982
+ const db = await getTraceDb(input.projectKey);
22983
+ const trace = await createDecisionTrace(db, {
22984
+ decision_type: "strategy_selection",
22985
+ epic_id: input.epicId,
22986
+ bead_id: input.beadId,
22987
+ agent_name: input.agentName,
22988
+ project_key: input.projectKey,
22989
+ decision: {
22990
+ strategy: input.strategy,
22991
+ confidence: input.confidence,
22992
+ task_preview: input.taskPreview
22993
+ },
22994
+ rationale: input.reasoning,
22995
+ inputs_gathered: input.inputsGathered,
22996
+ alternatives: input.alternatives,
22997
+ precedent_cited: input.precedentCited
22998
+ });
22999
+ const memoryIds = extractMemoryIds(input.precedentCited);
23000
+ for (const memoryId of memoryIds) {
23001
+ await createEntityLink(db, {
23002
+ source_decision_id: trace.id,
23003
+ target_entity_type: "memory",
23004
+ target_entity_id: memoryId,
23005
+ link_type: "cites_precedent",
23006
+ strength: input.precedentCited?.similarity ?? 1,
23007
+ context: "Cited as precedent for strategy selection"
23008
+ });
23009
+ }
23010
+ await db.close?.();
23011
+ return trace.id;
23012
+ } catch (error45) {
23013
+ console.warn("[decision-trace] Failed to trace strategy_selection:", error45);
23014
+ return "";
23015
+ }
23016
+ }
23017
+ async function traceWorkerSpawn(input) {
23018
+ try {
23019
+ const db = await getTraceDb(input.projectKey);
23020
+ const trace = await createDecisionTrace(db, {
23021
+ decision_type: "worker_spawn",
23022
+ epic_id: input.epicId,
23023
+ bead_id: input.beadId,
23024
+ agent_name: input.agentName,
23025
+ project_key: input.projectKey,
23026
+ decision: {
23027
+ worker: input.workerName || "worker",
23028
+ subtask_title: input.subtaskTitle,
23029
+ files: input.files,
23030
+ model: input.model,
23031
+ spawn_order: input.spawnOrder,
23032
+ is_parallel: input.isParallel
23033
+ },
23034
+ rationale: input.rationale || `Spawning worker for: ${input.subtaskTitle}`
23035
+ });
23036
+ for (const file2 of input.files) {
23037
+ await createEntityLink(db, {
23038
+ source_decision_id: trace.id,
23039
+ target_entity_type: "file",
23040
+ target_entity_id: file2,
23041
+ link_type: "assigns_file",
23042
+ strength: 1,
23043
+ context: `File assigned to worker ${input.workerName || "worker"}`
23044
+ });
23045
+ }
23046
+ await db.close?.();
23047
+ return trace.id;
23048
+ } catch (error45) {
23049
+ console.warn("[decision-trace] Failed to trace worker_spawn:", error45);
23050
+ return "";
23051
+ }
23052
+ }
23053
+ async function traceReviewDecision(input) {
23054
+ try {
23055
+ const db = await getTraceDb(input.projectKey);
23056
+ const trace = await createDecisionTrace(db, {
23057
+ decision_type: "review_decision",
23058
+ epic_id: input.epicId,
23059
+ bead_id: input.beadId,
23060
+ agent_name: input.agentName,
23061
+ project_key: input.projectKey,
23062
+ decision: {
23063
+ status: input.status,
23064
+ worker_id: input.workerId,
23065
+ issues_count: input.issues?.length || 0,
23066
+ attempt_number: input.attemptNumber,
23067
+ remaining_attempts: input.remainingAttempts
23068
+ },
23069
+ rationale: input.rationale || input.summary || `Review ${input.status}`,
23070
+ inputs_gathered: input.issues ? [{ source: "code_review", issues: input.issues }] : undefined
23071
+ });
23072
+ await createEntityLink(db, {
23073
+ source_decision_id: trace.id,
23074
+ target_entity_type: "agent",
23075
+ target_entity_id: input.workerId,
23076
+ link_type: "reviewed_work_by",
23077
+ strength: 1,
23078
+ context: `Review ${input.status} for ${input.workerId}`
23079
+ });
23080
+ await db.close?.();
23081
+ return trace.id;
23082
+ } catch (error45) {
23083
+ console.warn("[decision-trace] Failed to trace review_decision:", error45);
23084
+ return "";
23085
+ }
23086
+ }
23087
+ async function traceFileSelection(input) {
23088
+ try {
23089
+ const db = await getTraceDb(input.projectKey);
23090
+ const trace = await createDecisionTrace(db, {
23091
+ decision_type: "file_selection",
23092
+ epic_id: input.epicId,
23093
+ bead_id: input.beadId,
23094
+ agent_name: input.agentName,
23095
+ project_key: input.projectKey,
23096
+ decision: {
23097
+ files_selected: input.filesSelected,
23098
+ files_owned: input.filesOwned,
23099
+ scope_expanded: input.scopeExpanded
23100
+ },
23101
+ rationale: input.rationale || `Selected ${input.filesSelected.length} files`
23102
+ });
23103
+ await db.close?.();
23104
+ return trace.id;
23105
+ } catch (error45) {
23106
+ console.warn("[decision-trace] Failed to trace file_selection:", error45);
23107
+ return "";
23108
+ }
23109
+ }
23110
+ async function traceScopeChange(input) {
23111
+ try {
23112
+ const db = await getTraceDb(input.projectKey);
23113
+ const trace = await createDecisionTrace(db, {
23114
+ decision_type: "scope_change",
23115
+ epic_id: input.epicId,
23116
+ bead_id: input.beadId,
23117
+ agent_name: input.agentName,
23118
+ project_key: input.projectKey,
23119
+ decision: {
23120
+ files_added: input.filesAdded || [],
23121
+ files_removed: input.filesRemoved || [],
23122
+ coordinator_approved: input.coordinatorApproved
23123
+ },
23124
+ rationale: input.reason
23125
+ });
23126
+ await db.close?.();
23127
+ return trace.id;
23128
+ } catch (error45) {
23129
+ console.warn("[decision-trace] Failed to trace scope_change:", error45);
23130
+ return "";
23131
+ }
23132
+ }
23133
+ async function getEpicDecisionTraces(projectKey, epicId) {
23134
+ try {
23135
+ const { getDecisionTracesByEpic } = await import("swarm-mail");
23136
+ const db = await getTraceDb(projectKey);
23137
+ const traces = await getDecisionTracesByEpic(db, epicId);
23138
+ await db.close?.();
23139
+ return traces;
23140
+ } catch (error45) {
23141
+ console.warn("[decision-trace] Failed to query epic traces:", error45);
23142
+ return [];
23143
+ }
23144
+ }
23145
+ async function getDecisionTracesByType(projectKey, decisionType) {
23146
+ try {
23147
+ const { getDecisionTracesByType: queryByType } = await import("swarm-mail");
23148
+ const db = await getTraceDb(projectKey);
23149
+ const traces = await queryByType(db, decisionType);
23150
+ await db.close?.();
23151
+ return traces;
23152
+ } catch (error45) {
23153
+ console.warn("[decision-trace] Failed to query traces by type:", error45);
23154
+ return [];
23155
+ }
23156
+ }
23157
+ async function linkOutcomeToDecisionTrace(input) {
23158
+ try {
23159
+ const { findDecisionTraceByBead, linkOutcomeToTrace } = await import("swarm-mail");
23160
+ const db = await getTraceDb(input.projectKey);
23161
+ const trace = await findDecisionTraceByBead(db, input.beadId);
23162
+ if (!trace) {
23163
+ await db.close?.();
23164
+ return false;
23165
+ }
23166
+ await linkOutcomeToTrace(db, trace.id, input.outcomeEventId);
23167
+ await db.close?.();
23168
+ return true;
23169
+ } catch (error45) {
23170
+ console.warn("[decision-trace] Failed to link outcome to trace:", error45);
23171
+ return false;
23172
+ }
23173
+ }
23174
+ var init_decision_trace_integration = () => {};
23175
+
22945
23176
  // src/learning.ts
22946
23177
  var exports_learning = {};
22947
23178
  __export(exports_learning, {
@@ -62574,139 +62805,7 @@ init_dist();
62574
62805
  init_zod();
62575
62806
  init_swarm_strategies();
62576
62807
  init_eval_capture();
62577
-
62578
- // src/decision-trace-integration.ts
62579
- import {
62580
- createDecisionTrace,
62581
- createEntityLink
62582
- } from "swarm-mail";
62583
- import { createLibSQLAdapter } from "swarm-mail";
62584
- import { getDatabasePath } from "swarm-mail";
62585
- async function getTraceDb(projectPath) {
62586
- const dbPath = getDatabasePath(projectPath);
62587
- return createLibSQLAdapter({ url: `file:${dbPath}` });
62588
- }
62589
- function extractMemoryIds(precedentCited) {
62590
- if (!precedentCited) {
62591
- return [];
62592
- }
62593
- if (precedentCited.memoryIds && Array.isArray(precedentCited.memoryIds)) {
62594
- return precedentCited.memoryIds;
62595
- }
62596
- if (precedentCited.memoryId) {
62597
- return [precedentCited.memoryId];
62598
- }
62599
- return [];
62600
- }
62601
- async function traceStrategySelection(input) {
62602
- try {
62603
- const db = await getTraceDb(input.projectKey);
62604
- const trace = await createDecisionTrace(db, {
62605
- decision_type: "strategy_selection",
62606
- epic_id: input.epicId,
62607
- bead_id: input.beadId,
62608
- agent_name: input.agentName,
62609
- project_key: input.projectKey,
62610
- decision: {
62611
- strategy: input.strategy,
62612
- confidence: input.confidence,
62613
- task_preview: input.taskPreview
62614
- },
62615
- rationale: input.reasoning,
62616
- inputs_gathered: input.inputsGathered,
62617
- alternatives: input.alternatives,
62618
- precedent_cited: input.precedentCited
62619
- });
62620
- const memoryIds = extractMemoryIds(input.precedentCited);
62621
- for (const memoryId of memoryIds) {
62622
- await createEntityLink(db, {
62623
- source_decision_id: trace.id,
62624
- target_entity_type: "memory",
62625
- target_entity_id: memoryId,
62626
- link_type: "cites_precedent",
62627
- strength: input.precedentCited?.similarity ?? 1,
62628
- context: "Cited as precedent for strategy selection"
62629
- });
62630
- }
62631
- await db.close?.();
62632
- return trace.id;
62633
- } catch (error45) {
62634
- console.warn("[decision-trace] Failed to trace strategy_selection:", error45);
62635
- return "";
62636
- }
62637
- }
62638
- async function traceWorkerSpawn(input) {
62639
- try {
62640
- const db = await getTraceDb(input.projectKey);
62641
- const trace = await createDecisionTrace(db, {
62642
- decision_type: "worker_spawn",
62643
- epic_id: input.epicId,
62644
- bead_id: input.beadId,
62645
- agent_name: input.agentName,
62646
- project_key: input.projectKey,
62647
- decision: {
62648
- worker: input.workerName || "worker",
62649
- subtask_title: input.subtaskTitle,
62650
- files: input.files,
62651
- model: input.model,
62652
- spawn_order: input.spawnOrder,
62653
- is_parallel: input.isParallel
62654
- },
62655
- rationale: input.rationale || `Spawning worker for: ${input.subtaskTitle}`
62656
- });
62657
- for (const file2 of input.files) {
62658
- await createEntityLink(db, {
62659
- source_decision_id: trace.id,
62660
- target_entity_type: "file",
62661
- target_entity_id: file2,
62662
- link_type: "assigns_file",
62663
- strength: 1,
62664
- context: `File assigned to worker ${input.workerName || "worker"}`
62665
- });
62666
- }
62667
- await db.close?.();
62668
- return trace.id;
62669
- } catch (error45) {
62670
- console.warn("[decision-trace] Failed to trace worker_spawn:", error45);
62671
- return "";
62672
- }
62673
- }
62674
- async function traceReviewDecision(input) {
62675
- try {
62676
- const db = await getTraceDb(input.projectKey);
62677
- const trace = await createDecisionTrace(db, {
62678
- decision_type: "review_decision",
62679
- epic_id: input.epicId,
62680
- bead_id: input.beadId,
62681
- agent_name: input.agentName,
62682
- project_key: input.projectKey,
62683
- decision: {
62684
- status: input.status,
62685
- worker_id: input.workerId,
62686
- issues_count: input.issues?.length || 0,
62687
- attempt_number: input.attemptNumber,
62688
- remaining_attempts: input.remainingAttempts
62689
- },
62690
- rationale: input.rationale || input.summary || `Review ${input.status}`,
62691
- inputs_gathered: input.issues ? [{ source: "code_review", issues: input.issues }] : undefined
62692
- });
62693
- await createEntityLink(db, {
62694
- source_decision_id: trace.id,
62695
- target_entity_type: "agent",
62696
- target_entity_id: input.workerId,
62697
- link_type: "reviewed_work_by",
62698
- strength: 1,
62699
- context: `Review ${input.status} for ${input.workerId}`
62700
- });
62701
- await db.close?.();
62702
- return trace.id;
62703
- } catch (error45) {
62704
- console.warn("[decision-trace] Failed to trace review_decision:", error45);
62705
- return "";
62706
- }
62707
- }
62708
-
62709
- // src/swarm-decompose.ts
62808
+ init_decision_trace_integration();
62710
62809
  var DECOMPOSITION_PROMPT = `You are decomposing a task into parallelizable subtasks for a swarm of agents.
62711
62810
 
62712
62811
  ## Task
@@ -65316,6 +65415,7 @@ init_dist();
65316
65415
  init_zod();
65317
65416
  import { sendSwarmMessage as sendSwarmMessage2 } from "swarm-mail";
65318
65417
  init_eval_capture();
65418
+ init_decision_trace_integration();
65319
65419
  var ReviewIssueSchema = exports_external.object({
65320
65420
  file: exports_external.string(),
65321
65421
  line: exports_external.number().optional(),
@@ -66576,6 +66676,7 @@ This will be recorded as a negative learning signal.`;
66576
66676
  }
66577
66677
  const completionDurationMs = Date.now() - args.start_time;
66578
66678
  const eventEpicId = cell.parent_id || (args.bead_id.includes(".") ? args.bead_id.split(".")[0] : args.bead_id);
66679
+ let outcomeEventId;
66579
66680
  try {
66580
66681
  const event = createEvent3("subtask_outcome", {
66581
66682
  project_key: args.project_key,
@@ -66590,10 +66691,23 @@ This will be recorded as a negative learning signal.`;
66590
66691
  scope_violation: contractValidation ? !contractValidation.valid : undefined,
66591
66692
  violation_files: contractValidation?.violations
66592
66693
  });
66593
- await appendEvent2(event, args.project_key);
66694
+ const savedEvent = await appendEvent2(event, args.project_key);
66695
+ outcomeEventId = savedEvent.id;
66594
66696
  } catch (error45) {
66595
66697
  console.warn("[swarm_complete] Failed to emit SubtaskOutcomeEvent:", error45);
66596
66698
  }
66699
+ if (outcomeEventId) {
66700
+ try {
66701
+ const { linkOutcomeToDecisionTrace: linkOutcomeToDecisionTrace2 } = await Promise.resolve().then(() => (init_decision_trace_integration(), exports_decision_trace_integration));
66702
+ await linkOutcomeToDecisionTrace2({
66703
+ projectKey: args.project_key,
66704
+ beadId: args.bead_id,
66705
+ outcomeEventId
66706
+ });
66707
+ } catch (error45) {
66708
+ console.warn("[swarm_complete] Failed to link outcome to decision trace:", error45);
66709
+ }
66710
+ }
66597
66711
  try {
66598
66712
  const workerCompletedEvent = createEvent3("worker_completed", {
66599
66713
  project_key: args.project_key,
@@ -67571,6 +67685,7 @@ var orchestrateTools = {
67571
67685
  // src/swarm-prompts.ts
67572
67686
  init_eval_capture();
67573
67687
  init_memory_tools();
67688
+ init_decision_trace_integration();
67574
67689
  var STRATEGY_DECOMPOSITION_PROMPT2 = `You are decomposing a task into parallelizable subtasks for a swarm of agents.
67575
67690
 
67576
67691
  ## Task