opencode-swarm-plugin 0.58.4 → 0.59.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.
package/dist/bin/swarm.js CHANGED
@@ -156,6 +156,7 @@ __export(exports_dist, {
156
156
  formatCSV: () => formatCSV,
157
157
  findSimilarDecisions: () => findSimilarDecisions,
158
158
  findRelatedMemories: () => findRelatedMemories,
159
+ findDecisionTraceByBead: () => findDecisionTraceByBead,
159
160
  findCellsByPartialId: () => findCellsByPartialId,
160
161
  failedDecompositions: () => failedDecompositions,
161
162
  extractEntitiesAndRelationships: () => extractEntitiesAndRelationships,
@@ -16688,6 +16689,10 @@ async function getDecisionTracesByEpic(db2, epicId) {
16688
16689
  const result = await db2.query(`SELECT * FROM decision_traces WHERE epic_id = ? ORDER BY timestamp ASC`, [epicId]);
16689
16690
  return result.rows;
16690
16691
  }
16692
+ async function findDecisionTraceByBead(db2, beadId) {
16693
+ const result = await db2.query(`SELECT * FROM decision_traces WHERE bead_id = ? ORDER BY timestamp DESC LIMIT 1`, [beadId]);
16694
+ return result.rows[0] ?? null;
16695
+ }
16691
16696
  async function getDecisionTracesByAgent(db2, agentName) {
16692
16697
  const result = await db2.query(`SELECT * FROM decision_traces WHERE agent_name = ? ORDER BY timestamp ASC`, [agentName]);
16693
16698
  return result.rows;
@@ -108131,6 +108136,7 @@ ${stack.split(`
108131
108136
  getAgent: () => getAgent2,
108132
108137
  getActiveReservations: () => getActiveReservations2,
108133
108138
  findSimilarDecisions: () => findSimilarDecisions,
108139
+ findDecisionTraceByBead: () => findDecisionTraceByBead,
108134
108140
  emitThreadActivity: () => emitThreadActivity,
108135
108141
  createEvent: () => createEvent,
108136
108142
  createEntityLink: () => createEntityLink,
@@ -116670,7 +116676,7 @@ __export(exports_dist2, {
116670
116676
  getDefaultLegacyPath: () => getDefaultLegacyPath2,
116671
116677
  getDefaultConfig: () => getDefaultConfig2,
116672
116678
  getDecisionsByMemoryPattern: () => getDecisionsByMemoryPattern2,
116673
- getDecisionTracesByType: () => getDecisionTracesByType2,
116679
+ getDecisionTracesByType: () => getDecisionTracesByType3,
116674
116680
  getDecisionTracesByEpic: () => getDecisionTracesByEpic2,
116675
116681
  getDecisionTracesByAgent: () => getDecisionTracesByAgent2,
116676
116682
  getDb: () => getDb2,
@@ -116693,6 +116699,7 @@ __export(exports_dist2, {
116693
116699
  formatCSV: () => formatCSV2,
116694
116700
  findSimilarDecisions: () => findSimilarDecisions2,
116695
116701
  findRelatedMemories: () => findRelatedMemories2,
116702
+ findDecisionTraceByBead: () => findDecisionTraceByBead2,
116696
116703
  findCellsByPartialId: () => findCellsByPartialId2,
116697
116704
  failedDecompositions: () => failedDecompositions2,
116698
116705
  extractEntitiesAndRelationships: () => extractEntitiesAndRelationships2,
@@ -133225,11 +133232,15 @@ async function getDecisionTracesByEpic2(db2, epicId) {
133225
133232
  const result = await db2.query(`SELECT * FROM decision_traces WHERE epic_id = ? ORDER BY timestamp ASC`, [epicId]);
133226
133233
  return result.rows;
133227
133234
  }
133235
+ async function findDecisionTraceByBead2(db2, beadId) {
133236
+ const result = await db2.query(`SELECT * FROM decision_traces WHERE bead_id = ? ORDER BY timestamp DESC LIMIT 1`, [beadId]);
133237
+ return result.rows[0] ?? null;
133238
+ }
133228
133239
  async function getDecisionTracesByAgent2(db2, agentName) {
133229
133240
  const result = await db2.query(`SELECT * FROM decision_traces WHERE agent_name = ? ORDER BY timestamp ASC`, [agentName]);
133230
133241
  return result.rows;
133231
133242
  }
133232
- async function getDecisionTracesByType2(db2, decisionType) {
133243
+ async function getDecisionTracesByType3(db2, decisionType) {
133233
133244
  const result = await db2.query(`SELECT * FROM decision_traces WHERE decision_type = ? ORDER BY timestamp ASC`, [decisionType]);
133234
133245
  return result.rows;
133235
133246
  }
@@ -224657,7 +224668,7 @@ ${stack.split(`
224657
224668
  getEvalStats: () => getEvalStats2,
224658
224669
  getEvalRecords: () => getEvalRecords2,
224659
224670
  getDecisionsByMemoryPattern: () => getDecisionsByMemoryPattern2,
224660
- getDecisionTracesByType: () => getDecisionTracesByType2,
224671
+ getDecisionTracesByType: () => getDecisionTracesByType3,
224661
224672
  getDecisionTracesByEpic: () => getDecisionTracesByEpic2,
224662
224673
  getDecisionTracesByAgent: () => getDecisionTracesByAgent2,
224663
224674
  getDatabasePath: () => getDatabasePath22,
@@ -224668,6 +224679,7 @@ ${stack.split(`
224668
224679
  getAgent: () => getAgent22,
224669
224680
  getActiveReservations: () => getActiveReservations22,
224670
224681
  findSimilarDecisions: () => findSimilarDecisions2,
224682
+ findDecisionTraceByBead: () => findDecisionTraceByBead2,
224671
224683
  emitThreadActivity: () => emitThreadActivity2,
224672
224684
  createEvent: () => createEvent2,
224673
224685
  createEntityLink: () => createEntityLink2,
@@ -273653,6 +273665,235 @@ Codebase context considered: ${args5.codebase_context.slice(0, 200)}...`;
273653
273665
  };
273654
273666
  });
273655
273667
 
273668
+ // src/decision-trace-integration.ts
273669
+ var exports_decision_trace_integration2 = {};
273670
+ __export(exports_decision_trace_integration2, {
273671
+ traceWorkerSpawn: () => traceWorkerSpawn2,
273672
+ traceStrategySelection: () => traceStrategySelection2,
273673
+ traceScopeChange: () => traceScopeChange2,
273674
+ traceReviewDecision: () => traceReviewDecision2,
273675
+ traceFileSelection: () => traceFileSelection2,
273676
+ linkOutcomeToDecisionTrace: () => linkOutcomeToDecisionTrace2,
273677
+ getEpicDecisionTraces: () => getEpicDecisionTraces2,
273678
+ getDecisionTracesByType: () => getDecisionTracesByType4,
273679
+ extractMemoryIds: () => extractMemoryIds2
273680
+ });
273681
+ async function getTraceDb2(projectPath) {
273682
+ const dbPath = getDatabasePath2(projectPath);
273683
+ return createLibSQLAdapter({ url: `file:${dbPath}` });
273684
+ }
273685
+ function extractMemoryIds2(precedentCited) {
273686
+ if (!precedentCited) {
273687
+ return [];
273688
+ }
273689
+ if (precedentCited.memoryIds && Array.isArray(precedentCited.memoryIds)) {
273690
+ return precedentCited.memoryIds;
273691
+ }
273692
+ if (precedentCited.memoryId) {
273693
+ return [precedentCited.memoryId];
273694
+ }
273695
+ return [];
273696
+ }
273697
+ async function traceStrategySelection2(input) {
273698
+ try {
273699
+ const db = await getTraceDb2(input.projectKey);
273700
+ const trace4 = await createDecisionTrace(db, {
273701
+ decision_type: "strategy_selection",
273702
+ epic_id: input.epicId,
273703
+ bead_id: input.beadId,
273704
+ agent_name: input.agentName,
273705
+ project_key: input.projectKey,
273706
+ decision: {
273707
+ strategy: input.strategy,
273708
+ confidence: input.confidence,
273709
+ task_preview: input.taskPreview
273710
+ },
273711
+ rationale: input.reasoning,
273712
+ inputs_gathered: input.inputsGathered,
273713
+ alternatives: input.alternatives,
273714
+ precedent_cited: input.precedentCited
273715
+ });
273716
+ const memoryIds = extractMemoryIds2(input.precedentCited);
273717
+ for (const memoryId of memoryIds) {
273718
+ await createEntityLink(db, {
273719
+ source_decision_id: trace4.id,
273720
+ target_entity_type: "memory",
273721
+ target_entity_id: memoryId,
273722
+ link_type: "cites_precedent",
273723
+ strength: input.precedentCited?.similarity ?? 1,
273724
+ context: "Cited as precedent for strategy selection"
273725
+ });
273726
+ }
273727
+ await db.close?.();
273728
+ return trace4.id;
273729
+ } catch (error56) {
273730
+ console.warn("[decision-trace] Failed to trace strategy_selection:", error56);
273731
+ return "";
273732
+ }
273733
+ }
273734
+ async function traceWorkerSpawn2(input) {
273735
+ try {
273736
+ const db = await getTraceDb2(input.projectKey);
273737
+ const trace4 = await createDecisionTrace(db, {
273738
+ decision_type: "worker_spawn",
273739
+ epic_id: input.epicId,
273740
+ bead_id: input.beadId,
273741
+ agent_name: input.agentName,
273742
+ project_key: input.projectKey,
273743
+ decision: {
273744
+ worker: input.workerName || "worker",
273745
+ subtask_title: input.subtaskTitle,
273746
+ files: input.files,
273747
+ model: input.model,
273748
+ spawn_order: input.spawnOrder,
273749
+ is_parallel: input.isParallel
273750
+ },
273751
+ rationale: input.rationale || `Spawning worker for: ${input.subtaskTitle}`
273752
+ });
273753
+ for (const file6 of input.files) {
273754
+ await createEntityLink(db, {
273755
+ source_decision_id: trace4.id,
273756
+ target_entity_type: "file",
273757
+ target_entity_id: file6,
273758
+ link_type: "assigns_file",
273759
+ strength: 1,
273760
+ context: `File assigned to worker ${input.workerName || "worker"}`
273761
+ });
273762
+ }
273763
+ await db.close?.();
273764
+ return trace4.id;
273765
+ } catch (error56) {
273766
+ console.warn("[decision-trace] Failed to trace worker_spawn:", error56);
273767
+ return "";
273768
+ }
273769
+ }
273770
+ async function traceReviewDecision2(input) {
273771
+ try {
273772
+ const db = await getTraceDb2(input.projectKey);
273773
+ const trace4 = await createDecisionTrace(db, {
273774
+ decision_type: "review_decision",
273775
+ epic_id: input.epicId,
273776
+ bead_id: input.beadId,
273777
+ agent_name: input.agentName,
273778
+ project_key: input.projectKey,
273779
+ decision: {
273780
+ status: input.status,
273781
+ worker_id: input.workerId,
273782
+ issues_count: input.issues?.length || 0,
273783
+ attempt_number: input.attemptNumber,
273784
+ remaining_attempts: input.remainingAttempts
273785
+ },
273786
+ rationale: input.rationale || input.summary || `Review ${input.status}`,
273787
+ inputs_gathered: input.issues ? [{ source: "code_review", issues: input.issues }] : undefined
273788
+ });
273789
+ await createEntityLink(db, {
273790
+ source_decision_id: trace4.id,
273791
+ target_entity_type: "agent",
273792
+ target_entity_id: input.workerId,
273793
+ link_type: "reviewed_work_by",
273794
+ strength: 1,
273795
+ context: `Review ${input.status} for ${input.workerId}`
273796
+ });
273797
+ await db.close?.();
273798
+ return trace4.id;
273799
+ } catch (error56) {
273800
+ console.warn("[decision-trace] Failed to trace review_decision:", error56);
273801
+ return "";
273802
+ }
273803
+ }
273804
+ async function traceFileSelection2(input) {
273805
+ try {
273806
+ const db = await getTraceDb2(input.projectKey);
273807
+ const trace4 = await createDecisionTrace(db, {
273808
+ decision_type: "file_selection",
273809
+ epic_id: input.epicId,
273810
+ bead_id: input.beadId,
273811
+ agent_name: input.agentName,
273812
+ project_key: input.projectKey,
273813
+ decision: {
273814
+ files_selected: input.filesSelected,
273815
+ files_owned: input.filesOwned,
273816
+ scope_expanded: input.scopeExpanded
273817
+ },
273818
+ rationale: input.rationale || `Selected ${input.filesSelected.length} files`
273819
+ });
273820
+ await db.close?.();
273821
+ return trace4.id;
273822
+ } catch (error56) {
273823
+ console.warn("[decision-trace] Failed to trace file_selection:", error56);
273824
+ return "";
273825
+ }
273826
+ }
273827
+ async function traceScopeChange2(input) {
273828
+ try {
273829
+ const db = await getTraceDb2(input.projectKey);
273830
+ const trace4 = await createDecisionTrace(db, {
273831
+ decision_type: "scope_change",
273832
+ epic_id: input.epicId,
273833
+ bead_id: input.beadId,
273834
+ agent_name: input.agentName,
273835
+ project_key: input.projectKey,
273836
+ decision: {
273837
+ files_added: input.filesAdded || [],
273838
+ files_removed: input.filesRemoved || [],
273839
+ coordinator_approved: input.coordinatorApproved
273840
+ },
273841
+ rationale: input.reason
273842
+ });
273843
+ await db.close?.();
273844
+ return trace4.id;
273845
+ } catch (error56) {
273846
+ console.warn("[decision-trace] Failed to trace scope_change:", error56);
273847
+ return "";
273848
+ }
273849
+ }
273850
+ async function getEpicDecisionTraces2(projectKey, epicId) {
273851
+ try {
273852
+ const { getDecisionTracesByEpic: getDecisionTracesByEpic3 } = await Promise.resolve().then(() => (init_dist(), exports_dist));
273853
+ const db = await getTraceDb2(projectKey);
273854
+ const traces = await getDecisionTracesByEpic3(db, epicId);
273855
+ await db.close?.();
273856
+ return traces;
273857
+ } catch (error56) {
273858
+ console.warn("[decision-trace] Failed to query epic traces:", error56);
273859
+ return [];
273860
+ }
273861
+ }
273862
+ async function getDecisionTracesByType4(projectKey, decisionType) {
273863
+ try {
273864
+ const { getDecisionTracesByType: queryByType } = await Promise.resolve().then(() => (init_dist(), exports_dist));
273865
+ const db = await getTraceDb2(projectKey);
273866
+ const traces = await queryByType(db, decisionType);
273867
+ await db.close?.();
273868
+ return traces;
273869
+ } catch (error56) {
273870
+ console.warn("[decision-trace] Failed to query traces by type:", error56);
273871
+ return [];
273872
+ }
273873
+ }
273874
+ async function linkOutcomeToDecisionTrace2(input) {
273875
+ try {
273876
+ const { findDecisionTraceByBead: findDecisionTraceByBead3, linkOutcomeToTrace: linkOutcomeToTrace3 } = await Promise.resolve().then(() => (init_dist(), exports_dist));
273877
+ const db = await getTraceDb2(input.projectKey);
273878
+ const trace4 = await findDecisionTraceByBead3(db, input.beadId);
273879
+ if (!trace4) {
273880
+ await db.close?.();
273881
+ return false;
273882
+ }
273883
+ await linkOutcomeToTrace3(db, trace4.id, input.outcomeEventId);
273884
+ await db.close?.();
273885
+ return true;
273886
+ } catch (error56) {
273887
+ console.warn("[decision-trace] Failed to link outcome to trace:", error56);
273888
+ return false;
273889
+ }
273890
+ }
273891
+ var init_decision_trace_integration2 = __esm(() => {
273892
+ init_dist();
273893
+ init_dist();
273894
+ init_dist();
273895
+ });
273896
+
273656
273897
  // src/learning.ts
273657
273898
  var exports_learning2 = {};
273658
273899
  __export(exports_learning2, {
@@ -324646,6 +324887,229 @@ echo "Project directory: $1"
324646
324887
  skills_init
324647
324888
  };
324648
324889
  });
324890
+ var exports_decision_trace_integration = {};
324891
+ __export4(exports_decision_trace_integration, {
324892
+ traceWorkerSpawn: () => traceWorkerSpawn,
324893
+ traceStrategySelection: () => traceStrategySelection,
324894
+ traceScopeChange: () => traceScopeChange,
324895
+ traceReviewDecision: () => traceReviewDecision,
324896
+ traceFileSelection: () => traceFileSelection,
324897
+ linkOutcomeToDecisionTrace: () => linkOutcomeToDecisionTrace,
324898
+ getEpicDecisionTraces: () => getEpicDecisionTraces,
324899
+ getDecisionTracesByType: () => getDecisionTracesByType2,
324900
+ extractMemoryIds: () => extractMemoryIds
324901
+ });
324902
+ async function getTraceDb(projectPath) {
324903
+ const dbPath = getDatabasePath2(projectPath);
324904
+ return createLibSQLAdapter({ url: `file:${dbPath}` });
324905
+ }
324906
+ function extractMemoryIds(precedentCited) {
324907
+ if (!precedentCited) {
324908
+ return [];
324909
+ }
324910
+ if (precedentCited.memoryIds && Array.isArray(precedentCited.memoryIds)) {
324911
+ return precedentCited.memoryIds;
324912
+ }
324913
+ if (precedentCited.memoryId) {
324914
+ return [precedentCited.memoryId];
324915
+ }
324916
+ return [];
324917
+ }
324918
+ async function traceStrategySelection(input) {
324919
+ try {
324920
+ const db = await getTraceDb(input.projectKey);
324921
+ const trace3 = await createDecisionTrace(db, {
324922
+ decision_type: "strategy_selection",
324923
+ epic_id: input.epicId,
324924
+ bead_id: input.beadId,
324925
+ agent_name: input.agentName,
324926
+ project_key: input.projectKey,
324927
+ decision: {
324928
+ strategy: input.strategy,
324929
+ confidence: input.confidence,
324930
+ task_preview: input.taskPreview
324931
+ },
324932
+ rationale: input.reasoning,
324933
+ inputs_gathered: input.inputsGathered,
324934
+ alternatives: input.alternatives,
324935
+ precedent_cited: input.precedentCited
324936
+ });
324937
+ const memoryIds = extractMemoryIds(input.precedentCited);
324938
+ for (const memoryId of memoryIds) {
324939
+ await createEntityLink(db, {
324940
+ source_decision_id: trace3.id,
324941
+ target_entity_type: "memory",
324942
+ target_entity_id: memoryId,
324943
+ link_type: "cites_precedent",
324944
+ strength: input.precedentCited?.similarity ?? 1,
324945
+ context: "Cited as precedent for strategy selection"
324946
+ });
324947
+ }
324948
+ await db.close?.();
324949
+ return trace3.id;
324950
+ } catch (error452) {
324951
+ console.warn("[decision-trace] Failed to trace strategy_selection:", error452);
324952
+ return "";
324953
+ }
324954
+ }
324955
+ async function traceWorkerSpawn(input) {
324956
+ try {
324957
+ const db = await getTraceDb(input.projectKey);
324958
+ const trace3 = await createDecisionTrace(db, {
324959
+ decision_type: "worker_spawn",
324960
+ epic_id: input.epicId,
324961
+ bead_id: input.beadId,
324962
+ agent_name: input.agentName,
324963
+ project_key: input.projectKey,
324964
+ decision: {
324965
+ worker: input.workerName || "worker",
324966
+ subtask_title: input.subtaskTitle,
324967
+ files: input.files,
324968
+ model: input.model,
324969
+ spawn_order: input.spawnOrder,
324970
+ is_parallel: input.isParallel
324971
+ },
324972
+ rationale: input.rationale || `Spawning worker for: ${input.subtaskTitle}`
324973
+ });
324974
+ for (const file22 of input.files) {
324975
+ await createEntityLink(db, {
324976
+ source_decision_id: trace3.id,
324977
+ target_entity_type: "file",
324978
+ target_entity_id: file22,
324979
+ link_type: "assigns_file",
324980
+ strength: 1,
324981
+ context: `File assigned to worker ${input.workerName || "worker"}`
324982
+ });
324983
+ }
324984
+ await db.close?.();
324985
+ return trace3.id;
324986
+ } catch (error452) {
324987
+ console.warn("[decision-trace] Failed to trace worker_spawn:", error452);
324988
+ return "";
324989
+ }
324990
+ }
324991
+ async function traceReviewDecision(input) {
324992
+ try {
324993
+ const db = await getTraceDb(input.projectKey);
324994
+ const trace3 = await createDecisionTrace(db, {
324995
+ decision_type: "review_decision",
324996
+ epic_id: input.epicId,
324997
+ bead_id: input.beadId,
324998
+ agent_name: input.agentName,
324999
+ project_key: input.projectKey,
325000
+ decision: {
325001
+ status: input.status,
325002
+ worker_id: input.workerId,
325003
+ issues_count: input.issues?.length || 0,
325004
+ attempt_number: input.attemptNumber,
325005
+ remaining_attempts: input.remainingAttempts
325006
+ },
325007
+ rationale: input.rationale || input.summary || `Review ${input.status}`,
325008
+ inputs_gathered: input.issues ? [{ source: "code_review", issues: input.issues }] : undefined
325009
+ });
325010
+ await createEntityLink(db, {
325011
+ source_decision_id: trace3.id,
325012
+ target_entity_type: "agent",
325013
+ target_entity_id: input.workerId,
325014
+ link_type: "reviewed_work_by",
325015
+ strength: 1,
325016
+ context: `Review ${input.status} for ${input.workerId}`
325017
+ });
325018
+ await db.close?.();
325019
+ return trace3.id;
325020
+ } catch (error452) {
325021
+ console.warn("[decision-trace] Failed to trace review_decision:", error452);
325022
+ return "";
325023
+ }
325024
+ }
325025
+ async function traceFileSelection(input) {
325026
+ try {
325027
+ const db = await getTraceDb(input.projectKey);
325028
+ const trace3 = await createDecisionTrace(db, {
325029
+ decision_type: "file_selection",
325030
+ epic_id: input.epicId,
325031
+ bead_id: input.beadId,
325032
+ agent_name: input.agentName,
325033
+ project_key: input.projectKey,
325034
+ decision: {
325035
+ files_selected: input.filesSelected,
325036
+ files_owned: input.filesOwned,
325037
+ scope_expanded: input.scopeExpanded
325038
+ },
325039
+ rationale: input.rationale || `Selected ${input.filesSelected.length} files`
325040
+ });
325041
+ await db.close?.();
325042
+ return trace3.id;
325043
+ } catch (error452) {
325044
+ console.warn("[decision-trace] Failed to trace file_selection:", error452);
325045
+ return "";
325046
+ }
325047
+ }
325048
+ async function traceScopeChange(input) {
325049
+ try {
325050
+ const db = await getTraceDb(input.projectKey);
325051
+ const trace3 = await createDecisionTrace(db, {
325052
+ decision_type: "scope_change",
325053
+ epic_id: input.epicId,
325054
+ bead_id: input.beadId,
325055
+ agent_name: input.agentName,
325056
+ project_key: input.projectKey,
325057
+ decision: {
325058
+ files_added: input.filesAdded || [],
325059
+ files_removed: input.filesRemoved || [],
325060
+ coordinator_approved: input.coordinatorApproved
325061
+ },
325062
+ rationale: input.reason
325063
+ });
325064
+ await db.close?.();
325065
+ return trace3.id;
325066
+ } catch (error452) {
325067
+ console.warn("[decision-trace] Failed to trace scope_change:", error452);
325068
+ return "";
325069
+ }
325070
+ }
325071
+ async function getEpicDecisionTraces(projectKey, epicId) {
325072
+ try {
325073
+ const { getDecisionTracesByEpic: getDecisionTracesByEpic2 } = await Promise.resolve().then(() => (init_dist(), exports_dist));
325074
+ const db = await getTraceDb(projectKey);
325075
+ const traces = await getDecisionTracesByEpic2(db, epicId);
325076
+ await db.close?.();
325077
+ return traces;
325078
+ } catch (error452) {
325079
+ console.warn("[decision-trace] Failed to query epic traces:", error452);
325080
+ return [];
325081
+ }
325082
+ }
325083
+ async function getDecisionTracesByType2(projectKey, decisionType) {
325084
+ try {
325085
+ const { getDecisionTracesByType: queryByType } = await Promise.resolve().then(() => (init_dist(), exports_dist));
325086
+ const db = await getTraceDb(projectKey);
325087
+ const traces = await queryByType(db, decisionType);
325088
+ await db.close?.();
325089
+ return traces;
325090
+ } catch (error452) {
325091
+ console.warn("[decision-trace] Failed to query traces by type:", error452);
325092
+ return [];
325093
+ }
325094
+ }
325095
+ async function linkOutcomeToDecisionTrace(input) {
325096
+ try {
325097
+ const { findDecisionTraceByBead: findDecisionTraceByBead2, linkOutcomeToTrace: linkOutcomeToTrace2 } = await Promise.resolve().then(() => (init_dist(), exports_dist));
325098
+ const db = await getTraceDb(input.projectKey);
325099
+ const trace3 = await findDecisionTraceByBead2(db, input.beadId);
325100
+ if (!trace3) {
325101
+ await db.close?.();
325102
+ return false;
325103
+ }
325104
+ await linkOutcomeToTrace2(db, trace3.id, input.outcomeEventId);
325105
+ await db.close?.();
325106
+ return true;
325107
+ } catch (error452) {
325108
+ console.warn("[decision-trace] Failed to link outcome to trace:", error452);
325109
+ return false;
325110
+ }
325111
+ }
325112
+ var init_decision_trace_integration = () => {};
324649
325113
  var exports_anti_patterns = {};
324650
325114
  __export4(exports_anti_patterns, {
324651
325115
  shouldInvertPattern: () => shouldInvertPattern,
@@ -325248,7 +325712,7 @@ class SemanticMemoryStorage {
325248
325712
  this.config = { ...getDefaultStorageConfig(), ...config22 };
325249
325713
  }
325250
325714
  async checkLowUsageAlert() {
325251
- const TEN_MINUTES = 10 * 60 * 1000;
325715
+ const TEN_MINUTES = 600000;
325252
325716
  const now3 = Date.now();
325253
325717
  const sessionDuration = now3 - sessionStats.sessionStart;
325254
325718
  const timeSinceLastAlert = now3 - sessionStats.lastAlertCheck;
@@ -325867,8 +326331,8 @@ var init_Utils2 = __esm4(() => {
325867
326331
  return new SingleShotGen4(this.self);
325868
326332
  }
325869
326333
  };
325870
- MUL_HI2 = 1481765933 >>> 0;
325871
- MUL_LO2 = 1284865837 >>> 0;
326334
+ MUL_HI2 = 1481765933;
326335
+ MUL_LO2 = 1284865837;
325872
326336
  YieldWrapTypeId2 = /* @__PURE__ */ Symbol.for("effect/Utils/YieldWrap");
325873
326337
  YieldWrap2 = class YieldWrap3 {
325874
326338
  #value;
@@ -330682,11 +331146,11 @@ var init_runtimeFlags2 = __esm4(() => {
330682
331146
  init_Function2();
330683
331147
  init_differ2();
330684
331148
  init_runtimeFlagsPatch2();
330685
- Interruption3 = 1 << 0;
330686
- OpSupervision3 = 1 << 1;
330687
- RuntimeMetrics3 = 1 << 2;
330688
- WindDown3 = 1 << 4;
330689
- CooperativeYielding3 = 1 << 5;
331149
+ Interruption3 = 1;
331150
+ OpSupervision3 = 2;
331151
+ RuntimeMetrics3 = 4;
331152
+ WindDown3 = 16;
331153
+ CooperativeYielding3 = 32;
330690
331154
  disable22 = /* @__PURE__ */ dual2(2, (self, flag) => self & ~flag);
330691
331155
  enable22 = /* @__PURE__ */ dual2(2, (self, flag) => self | flag);
330692
331156
  isEnabled5 = /* @__PURE__ */ dual2(2, (self, flag) => (self & flag) !== 0);
@@ -332399,7 +332863,7 @@ var init_core32 = __esm4(() => {
332399
332863
  zipRight18 = /* @__PURE__ */ dual2(2, (self, that) => flatMap72(self, () => that));
332400
332864
  zipWith24 = /* @__PURE__ */ dual2(3, (self, that, f) => flatMap72(self, (a) => map112(that, (b) => f(a, b))));
332401
332865
  never22 = /* @__PURE__ */ asyncInterrupt2(() => {
332402
- const interval = setInterval(() => {}, 2 ** 31 - 1);
332866
+ const interval = setInterval(() => {}, 2147483647);
332403
332867
  return sync23(() => clearInterval(interval));
332404
332868
  });
332405
332869
  interruptAsFiber2 = /* @__PURE__ */ dual2(2, (self, fiberId22) => flatMap72(self.interruptAsFork(fiberId22), () => self.await));
@@ -333088,7 +333552,7 @@ var init_clock2 = __esm4(() => {
333088
333552
  init_core32();
333089
333553
  ClockTypeId3 = /* @__PURE__ */ Symbol.for(ClockSymbolKey2);
333090
333554
  clockTag2 = /* @__PURE__ */ GenericTag2("effect/Clock");
333091
- MAX_TIMER_MILLIS2 = 2 ** 31 - 1;
333555
+ MAX_TIMER_MILLIS2 = 2147483647;
333092
333556
  globalClockScheduler2 = {
333093
333557
  unsafeSchedule(task, duration32) {
333094
333558
  const millis22 = toMillis2(duration32);
@@ -337156,7 +337620,7 @@ var init_iterator2 = __esm4(() => {
337156
337620
  init_Option2();
337157
337621
  Direction3 = {
337158
337622
  Forward: 0,
337159
- Backward: 1 << 0
337623
+ Backward: 1
337160
337624
  };
337161
337625
  });
337162
337626
  var RedBlackTreeSymbolKey2 = "effect/RedBlackTree";
@@ -344262,8 +344726,8 @@ var init_TestLive2 = () => {};
344262
344726
  var warning2;
344263
344727
  var suspendedWarning2;
344264
344728
  var init_TestClock2 = __esm4(() => {
344265
- warning2 = "Warning: A test is using time, but is not advancing " + "the test clock, which may result in the test hanging. Use TestClock.adjust to " + "manually advance the time.";
344266
- suspendedWarning2 = "Warning: A test is advancing the test clock, " + "but a fiber is not suspending, which may result in the test hanging. Use " + "TestAspect.diagnose to identity the fiber that is not suspending.";
344729
+ warning2 = "Warning: A test is using time, but is not advancing the test clock, which may result in the test hanging. Use TestClock.adjust to manually advance the time.";
344730
+ suspendedWarning2 = "Warning: A test is advancing the test clock, but a fiber is not suspending, which may result in the test hanging. Use TestAspect.diagnose to identity the fiber that is not suspending.";
344267
344731
  });
344268
344732
  var init_TestConfig2 = () => {};
344269
344733
  var init_TestSized2 = () => {};
@@ -345358,7 +345822,7 @@ function formatFileHistoryWarnings(histories) {
345358
345822
  }
345359
345823
  let result = lines.join(`
345360
345824
  `);
345361
- const maxChars = 300 * 4;
345825
+ const maxChars = 1200;
345362
345826
  if (result.length > maxChars) {
345363
345827
  result = result.slice(0, maxChars - 3) + "...";
345364
345828
  }
@@ -345369,7 +345833,7 @@ var CACHE_TTL_MS;
345369
345833
  var init_swarm_insights = __esm4(() => {
345370
345834
  init_memory_tools();
345371
345835
  insightsCache = new Map;
345372
- CACHE_TTL_MS = 5 * 60 * 1000;
345836
+ CACHE_TTL_MS = 300000;
345373
345837
  });
345374
345838
  var exports_model_selection = {};
345375
345839
  __export4(exports_model_selection, {
@@ -349274,80 +349738,7 @@ async function getStartCommit(projectPath) {
349274
349738
  init_dist7();
349275
349739
  init_zod3();
349276
349740
  init_eval_capture2();
349277
- async function getTraceDb(projectPath) {
349278
- const dbPath = getDatabasePath2(projectPath);
349279
- return createLibSQLAdapter({ url: `file:${dbPath}` });
349280
- }
349281
- async function traceWorkerSpawn(input) {
349282
- try {
349283
- const db = await getTraceDb(input.projectKey);
349284
- const trace3 = await createDecisionTrace(db, {
349285
- decision_type: "worker_spawn",
349286
- epic_id: input.epicId,
349287
- bead_id: input.beadId,
349288
- agent_name: input.agentName,
349289
- project_key: input.projectKey,
349290
- decision: {
349291
- worker: input.workerName || "worker",
349292
- subtask_title: input.subtaskTitle,
349293
- files: input.files,
349294
- model: input.model,
349295
- spawn_order: input.spawnOrder,
349296
- is_parallel: input.isParallel
349297
- },
349298
- rationale: input.rationale || `Spawning worker for: ${input.subtaskTitle}`
349299
- });
349300
- for (const file22 of input.files) {
349301
- await createEntityLink(db, {
349302
- source_decision_id: trace3.id,
349303
- target_entity_type: "file",
349304
- target_entity_id: file22,
349305
- link_type: "assigns_file",
349306
- strength: 1,
349307
- context: `File assigned to worker ${input.workerName || "worker"}`
349308
- });
349309
- }
349310
- await db.close?.();
349311
- return trace3.id;
349312
- } catch (error452) {
349313
- console.warn("[decision-trace] Failed to trace worker_spawn:", error452);
349314
- return "";
349315
- }
349316
- }
349317
- async function traceReviewDecision(input) {
349318
- try {
349319
- const db = await getTraceDb(input.projectKey);
349320
- const trace3 = await createDecisionTrace(db, {
349321
- decision_type: "review_decision",
349322
- epic_id: input.epicId,
349323
- bead_id: input.beadId,
349324
- agent_name: input.agentName,
349325
- project_key: input.projectKey,
349326
- decision: {
349327
- status: input.status,
349328
- worker_id: input.workerId,
349329
- issues_count: input.issues?.length || 0,
349330
- attempt_number: input.attemptNumber,
349331
- remaining_attempts: input.remainingAttempts
349332
- },
349333
- rationale: input.rationale || input.summary || `Review ${input.status}`,
349334
- inputs_gathered: input.issues ? [{ source: "code_review", issues: input.issues }] : undefined
349335
- });
349336
- await createEntityLink(db, {
349337
- source_decision_id: trace3.id,
349338
- target_entity_type: "agent",
349339
- target_entity_id: input.workerId,
349340
- link_type: "reviewed_work_by",
349341
- strength: 1,
349342
- context: `Review ${input.status} for ${input.workerId}`
349343
- });
349344
- await db.close?.();
349345
- return trace3.id;
349346
- } catch (error452) {
349347
- console.warn("[decision-trace] Failed to trace review_decision:", error452);
349348
- return "";
349349
- }
349350
- }
349741
+ init_decision_trace_integration();
349351
349742
  var ReviewIssueSchema = exports_external5.object({
349352
349743
  file: exports_external5.string(),
349353
349744
  line: exports_external5.number().optional(),
@@ -350602,6 +350993,7 @@ This will be recorded as a negative learning signal.`;
350602
350993
  }
350603
350994
  const completionDurationMs = Date.now() - args3.start_time;
350604
350995
  const eventEpicId = cell.parent_id || (args3.bead_id.includes(".") ? args3.bead_id.split(".")[0] : args3.bead_id);
350996
+ let outcomeEventId;
350605
350997
  try {
350606
350998
  const event = createEvent("subtask_outcome", {
350607
350999
  project_key: args3.project_key,
@@ -350616,10 +351008,23 @@ This will be recorded as a negative learning signal.`;
350616
351008
  scope_violation: contractValidation ? !contractValidation.valid : undefined,
350617
351009
  violation_files: contractValidation?.violations
350618
351010
  });
350619
- await appendEvent(event, args3.project_key);
351011
+ const savedEvent = await appendEvent(event, args3.project_key);
351012
+ outcomeEventId = savedEvent.id;
350620
351013
  } catch (error452) {
350621
351014
  console.warn("[swarm_complete] Failed to emit SubtaskOutcomeEvent:", error452);
350622
351015
  }
351016
+ if (outcomeEventId) {
351017
+ try {
351018
+ const { linkOutcomeToDecisionTrace: linkOutcomeToDecisionTrace2 } = await Promise.resolve().then(() => (init_decision_trace_integration(), exports_decision_trace_integration));
351019
+ await linkOutcomeToDecisionTrace2({
351020
+ projectKey: args3.project_key,
351021
+ beadId: args3.bead_id,
351022
+ outcomeEventId
351023
+ });
351024
+ } catch (error452) {
351025
+ console.warn("[swarm_complete] Failed to link outcome to decision trace:", error452);
351026
+ }
351027
+ }
350623
351028
  try {
350624
351029
  const workerCompletedEvent = createEvent("worker_completed", {
350625
351030
  project_key: args3.project_key,
@@ -351579,6 +351984,7 @@ ${skillBody}`, "utf-8");
351579
351984
  });
351580
351985
  init_eval_capture2();
351581
351986
  init_memory_tools();
351987
+ init_decision_trace_integration();
351582
351988
  var DECOMPOSITION_PROMPT = `You are decomposing a task into parallelizable subtasks for a swarm of agents.
351583
351989
 
351584
351990
  ## Task
@@ -359983,136 +360389,7 @@ init_dist11();
359983
360389
  init_zod5();
359984
360390
  init_swarm_strategies2();
359985
360391
  init_eval_capture3();
359986
-
359987
- // src/decision-trace-integration.ts
359988
- init_dist();
359989
- init_dist();
359990
- init_dist();
359991
- async function getTraceDb2(projectPath) {
359992
- const dbPath = getDatabasePath2(projectPath);
359993
- return createLibSQLAdapter({ url: `file:${dbPath}` });
359994
- }
359995
- function extractMemoryIds(precedentCited) {
359996
- if (!precedentCited) {
359997
- return [];
359998
- }
359999
- if (precedentCited.memoryIds && Array.isArray(precedentCited.memoryIds)) {
360000
- return precedentCited.memoryIds;
360001
- }
360002
- if (precedentCited.memoryId) {
360003
- return [precedentCited.memoryId];
360004
- }
360005
- return [];
360006
- }
360007
- async function traceStrategySelection(input) {
360008
- try {
360009
- const db = await getTraceDb2(input.projectKey);
360010
- const trace4 = await createDecisionTrace(db, {
360011
- decision_type: "strategy_selection",
360012
- epic_id: input.epicId,
360013
- bead_id: input.beadId,
360014
- agent_name: input.agentName,
360015
- project_key: input.projectKey,
360016
- decision: {
360017
- strategy: input.strategy,
360018
- confidence: input.confidence,
360019
- task_preview: input.taskPreview
360020
- },
360021
- rationale: input.reasoning,
360022
- inputs_gathered: input.inputsGathered,
360023
- alternatives: input.alternatives,
360024
- precedent_cited: input.precedentCited
360025
- });
360026
- const memoryIds = extractMemoryIds(input.precedentCited);
360027
- for (const memoryId of memoryIds) {
360028
- await createEntityLink(db, {
360029
- source_decision_id: trace4.id,
360030
- target_entity_type: "memory",
360031
- target_entity_id: memoryId,
360032
- link_type: "cites_precedent",
360033
- strength: input.precedentCited?.similarity ?? 1,
360034
- context: "Cited as precedent for strategy selection"
360035
- });
360036
- }
360037
- await db.close?.();
360038
- return trace4.id;
360039
- } catch (error56) {
360040
- console.warn("[decision-trace] Failed to trace strategy_selection:", error56);
360041
- return "";
360042
- }
360043
- }
360044
- async function traceWorkerSpawn2(input) {
360045
- try {
360046
- const db = await getTraceDb2(input.projectKey);
360047
- const trace4 = await createDecisionTrace(db, {
360048
- decision_type: "worker_spawn",
360049
- epic_id: input.epicId,
360050
- bead_id: input.beadId,
360051
- agent_name: input.agentName,
360052
- project_key: input.projectKey,
360053
- decision: {
360054
- worker: input.workerName || "worker",
360055
- subtask_title: input.subtaskTitle,
360056
- files: input.files,
360057
- model: input.model,
360058
- spawn_order: input.spawnOrder,
360059
- is_parallel: input.isParallel
360060
- },
360061
- rationale: input.rationale || `Spawning worker for: ${input.subtaskTitle}`
360062
- });
360063
- for (const file6 of input.files) {
360064
- await createEntityLink(db, {
360065
- source_decision_id: trace4.id,
360066
- target_entity_type: "file",
360067
- target_entity_id: file6,
360068
- link_type: "assigns_file",
360069
- strength: 1,
360070
- context: `File assigned to worker ${input.workerName || "worker"}`
360071
- });
360072
- }
360073
- await db.close?.();
360074
- return trace4.id;
360075
- } catch (error56) {
360076
- console.warn("[decision-trace] Failed to trace worker_spawn:", error56);
360077
- return "";
360078
- }
360079
- }
360080
- async function traceReviewDecision2(input) {
360081
- try {
360082
- const db = await getTraceDb2(input.projectKey);
360083
- const trace4 = await createDecisionTrace(db, {
360084
- decision_type: "review_decision",
360085
- epic_id: input.epicId,
360086
- bead_id: input.beadId,
360087
- agent_name: input.agentName,
360088
- project_key: input.projectKey,
360089
- decision: {
360090
- status: input.status,
360091
- worker_id: input.workerId,
360092
- issues_count: input.issues?.length || 0,
360093
- attempt_number: input.attemptNumber,
360094
- remaining_attempts: input.remainingAttempts
360095
- },
360096
- rationale: input.rationale || input.summary || `Review ${input.status}`,
360097
- inputs_gathered: input.issues ? [{ source: "code_review", issues: input.issues }] : undefined
360098
- });
360099
- await createEntityLink(db, {
360100
- source_decision_id: trace4.id,
360101
- target_entity_type: "agent",
360102
- target_entity_id: input.workerId,
360103
- link_type: "reviewed_work_by",
360104
- strength: 1,
360105
- context: `Review ${input.status} for ${input.workerId}`
360106
- });
360107
- await db.close?.();
360108
- return trace4.id;
360109
- } catch (error56) {
360110
- console.warn("[decision-trace] Failed to trace review_decision:", error56);
360111
- return "";
360112
- }
360113
- }
360114
-
360115
- // src/swarm-decompose.ts
360392
+ init_decision_trace_integration2();
360116
360393
  var DECOMPOSITION_PROMPT2 = `You are decomposing a task into parallelizable subtasks for a swarm of agents.
360117
360394
 
360118
360395
  ## Task
@@ -360627,7 +360904,7 @@ var swarm_delegate_planning = tool3({
360627
360904
  cassResultInfo = { queried: false, reason: "disabled" };
360628
360905
  }
360629
360906
  try {
360630
- await traceStrategySelection({
360907
+ await traceStrategySelection2({
360631
360908
  projectKey: args5.context?.includes("/") ? args5.context.split(" ")[0] : process.cwd(),
360632
360909
  agentName: "coordinator",
360633
360910
  epicId: undefined,
@@ -362695,6 +362972,7 @@ init_dist11();
362695
362972
  init_zod5();
362696
362973
  init_dist();
362697
362974
  init_eval_capture3();
362975
+ init_decision_trace_integration2();
362698
362976
  var ReviewIssueSchema2 = exports_external7.object({
362699
362977
  file: exports_external7.string(),
362700
362978
  line: exports_external7.number().optional(),
@@ -363955,6 +364233,7 @@ This will be recorded as a negative learning signal.`;
363955
364233
  }
363956
364234
  const completionDurationMs = Date.now() - args5.start_time;
363957
364235
  const eventEpicId = cell.parent_id || (args5.bead_id.includes(".") ? args5.bead_id.split(".")[0] : args5.bead_id);
364236
+ let outcomeEventId;
363958
364237
  try {
363959
364238
  const event = createEvent("subtask_outcome", {
363960
364239
  project_key: args5.project_key,
@@ -363969,10 +364248,23 @@ This will be recorded as a negative learning signal.`;
363969
364248
  scope_violation: contractValidation ? !contractValidation.valid : undefined,
363970
364249
  violation_files: contractValidation?.violations
363971
364250
  });
363972
- await appendEvent(event, args5.project_key);
364251
+ const savedEvent = await appendEvent(event, args5.project_key);
364252
+ outcomeEventId = savedEvent.id;
363973
364253
  } catch (error56) {
363974
364254
  console.warn("[swarm_complete] Failed to emit SubtaskOutcomeEvent:", error56);
363975
364255
  }
364256
+ if (outcomeEventId) {
364257
+ try {
364258
+ const { linkOutcomeToDecisionTrace: linkOutcomeToDecisionTrace3 } = await Promise.resolve().then(() => (init_decision_trace_integration2(), exports_decision_trace_integration2));
364259
+ await linkOutcomeToDecisionTrace3({
364260
+ projectKey: args5.project_key,
364261
+ beadId: args5.bead_id,
364262
+ outcomeEventId
364263
+ });
364264
+ } catch (error56) {
364265
+ console.warn("[swarm_complete] Failed to link outcome to decision trace:", error56);
364266
+ }
364267
+ }
363976
364268
  try {
363977
364269
  const workerCompletedEvent = createEvent("worker_completed", {
363978
364270
  project_key: args5.project_key,
@@ -364950,6 +365242,7 @@ var orchestrateTools = {
364950
365242
  // src/swarm-prompts.ts
364951
365243
  init_eval_capture3();
364952
365244
  init_memory_tools2();
365245
+ init_decision_trace_integration2();
364953
365246
  var STRATEGY_DECOMPOSITION_PROMPT3 = `You are decomposing a task into parallelizable subtasks for a swarm of agents.
364954
365247
 
364955
365248
  ## Task