opencode-swarm 6.16.1 → 6.17.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.
package/README.md CHANGED
@@ -429,6 +429,23 @@ Config file location: `~/.config/opencode/opencode-swarm.json` (global) or `.ope
429
429
  "evidence_auto_summaries": true,
430
430
  "decision_drift_detection": true
431
431
  }
432
+ },
433
+ "knowledge": {
434
+ "enabled": true,
435
+ "swarm_max_entries": 100,
436
+ "hive_max_entries": 1000,
437
+ "auto_promote_days": 30,
438
+ "max_inject_count": 5,
439
+ "dedup_threshold": 0.6,
440
+ "scope_filter": ["global"],
441
+ "hive_enabled": true,
442
+ "rejected_max_entries": 200,
443
+ "validation_enabled": true,
444
+ "evergreen_confidence": 0.8,
445
+ "evergreen_utility": 0.5,
446
+ "low_utility_threshold": 0.2,
447
+ "min_retrievals_for_utility": 3,
448
+ "schema_version": "v6.17"
432
449
  }
433
450
  }
434
451
  ```
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Handles /swarm dark-matter command.
3
+ * Detects hidden couplings (files that co-change without explicit import relationships).
4
+ */
5
+ export declare function handleDarkMatterCommand(directory: string, args: string[]): Promise<string>;
@@ -5,11 +5,13 @@ export { handleArchiveCommand } from './archive';
5
5
  export { handleBenchmarkCommand } from './benchmark';
6
6
  export { handleClarifyCommand } from './clarify';
7
7
  export { handleConfigCommand } from './config';
8
+ export { handleDarkMatterCommand } from './dark-matter';
8
9
  export { handleDiagnoseCommand } from './diagnose';
9
10
  export { handleDoctorCommand } from './doctor';
10
11
  export { handleEvidenceCommand } from './evidence';
11
12
  export { handleExportCommand } from './export';
12
13
  export { handleHistoryCommand } from './history';
14
+ export { handleKnowledgeQuarantineCommand, handleKnowledgeRestoreCommand, } from './knowledge';
13
15
  export { handlePlanCommand } from './plan';
14
16
  export { handlePreflightCommand } from './preflight';
15
17
  export { handleResetCommand } from './reset';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Handles /swarm knowledge quarantine <id> [reason] command.
3
+ * Moves a knowledge entry to quarantine with optional reason.
4
+ */
5
+ export declare function handleKnowledgeQuarantineCommand(directory: string, args: string[]): Promise<string>;
6
+ /**
7
+ * Handles /swarm knowledge restore <id> command.
8
+ * Restores a quarantined knowledge entry.
9
+ */
10
+ export declare function handleKnowledgeRestoreCommand(directory: string, args: string[]): Promise<string>;
@@ -202,8 +202,8 @@ export declare const RetrospectiveEvidenceSchema: z.ZodObject<{
202
202
  }>;
203
203
  scope: z.ZodEnum<{
204
204
  project: "project";
205
- session: "session";
206
205
  global: "global";
206
+ session: "session";
207
207
  }>;
208
208
  }, z.core.$strip>>>;
209
209
  approaches_tried: z.ZodDefault<z.ZodArray<z.ZodObject<{
@@ -570,8 +570,8 @@ export declare const EvidenceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
570
570
  }>;
571
571
  scope: z.ZodEnum<{
572
572
  project: "project";
573
- session: "session";
574
573
  global: "global";
574
+ session: "session";
575
575
  }>;
576
576
  }, z.core.$strip>>>;
577
577
  approaches_tried: z.ZodDefault<z.ZodArray<z.ZodObject<{
@@ -929,8 +929,8 @@ export declare const EvidenceBundleSchema: z.ZodObject<{
929
929
  }>;
930
930
  scope: z.ZodEnum<{
931
931
  project: "project";
932
- session: "session";
933
932
  global: "global";
933
+ session: "session";
934
934
  }>;
935
935
  }, z.core.$strip>>>;
936
936
  approaches_tried: z.ZodDefault<z.ZodArray<z.ZodObject<{
@@ -381,6 +381,24 @@ declare const AutomationConfigSchemaBase: z.ZodObject<{
381
381
  }, z.core.$strip>;
382
382
  export type AutomationConfig = z.infer<typeof AutomationConfigSchemaBase>;
383
383
  export declare const AutomationConfigSchema: z.ZodType<AutomationConfig>;
384
+ export declare const KnowledgeConfigSchema: z.ZodObject<{
385
+ enabled: z.ZodDefault<z.ZodBoolean>;
386
+ swarm_max_entries: z.ZodDefault<z.ZodNumber>;
387
+ hive_max_entries: z.ZodDefault<z.ZodNumber>;
388
+ auto_promote_days: z.ZodDefault<z.ZodNumber>;
389
+ max_inject_count: z.ZodDefault<z.ZodNumber>;
390
+ dedup_threshold: z.ZodDefault<z.ZodNumber>;
391
+ scope_filter: z.ZodDefault<z.ZodArray<z.ZodString>>;
392
+ hive_enabled: z.ZodDefault<z.ZodBoolean>;
393
+ rejected_max_entries: z.ZodDefault<z.ZodNumber>;
394
+ validation_enabled: z.ZodDefault<z.ZodBoolean>;
395
+ evergreen_confidence: z.ZodDefault<z.ZodNumber>;
396
+ evergreen_utility: z.ZodDefault<z.ZodNumber>;
397
+ low_utility_threshold: z.ZodDefault<z.ZodNumber>;
398
+ min_retrievals_for_utility: z.ZodDefault<z.ZodNumber>;
399
+ schema_version: z.ZodDefault<z.ZodNumber>;
400
+ }, z.core.$strip>;
401
+ export type KnowledgeConfig = z.infer<typeof KnowledgeConfigSchema>;
384
402
  export declare const PluginConfigSchema: z.ZodObject<{
385
403
  agents: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
386
404
  model: z.ZodOptional<z.ZodString>;
@@ -608,6 +626,23 @@ export declare const PluginConfigSchema: z.ZodObject<{
608
626
  decision_drift_detection: boolean;
609
627
  };
610
628
  }, unknown>>>;
629
+ knowledge: z.ZodOptional<z.ZodObject<{
630
+ enabled: z.ZodDefault<z.ZodBoolean>;
631
+ swarm_max_entries: z.ZodDefault<z.ZodNumber>;
632
+ hive_max_entries: z.ZodDefault<z.ZodNumber>;
633
+ auto_promote_days: z.ZodDefault<z.ZodNumber>;
634
+ max_inject_count: z.ZodDefault<z.ZodNumber>;
635
+ dedup_threshold: z.ZodDefault<z.ZodNumber>;
636
+ scope_filter: z.ZodDefault<z.ZodArray<z.ZodString>>;
637
+ hive_enabled: z.ZodDefault<z.ZodBoolean>;
638
+ rejected_max_entries: z.ZodDefault<z.ZodNumber>;
639
+ validation_enabled: z.ZodDefault<z.ZodBoolean>;
640
+ evergreen_confidence: z.ZodDefault<z.ZodNumber>;
641
+ evergreen_utility: z.ZodDefault<z.ZodNumber>;
642
+ low_utility_threshold: z.ZodDefault<z.ZodNumber>;
643
+ min_retrievals_for_utility: z.ZodDefault<z.ZodNumber>;
644
+ schema_version: z.ZodDefault<z.ZodNumber>;
645
+ }, z.core.$strip>>;
611
646
  tool_output: z.ZodOptional<z.ZodObject<{
612
647
  truncation_enabled: z.ZodDefault<z.ZodBoolean>;
613
648
  max_lines: z.ZodDefault<z.ZodNumber>;
@@ -23,7 +23,14 @@ interface MessageWithParts {
23
23
  * Creates the experimental.chat.messages.transform hook for delegation gating.
24
24
  * Inspects coder delegations and warns when tasks are oversized or batched.
25
25
  */
26
- export declare function createDelegationGateHook(config: PluginConfig): (input: Record<string, never>, output: {
27
- messages?: MessageWithParts[];
28
- }) => Promise<void>;
26
+ export declare function createDelegationGateHook(config: PluginConfig): {
27
+ messagesTransform: (input: Record<string, never>, output: {
28
+ messages?: MessageWithParts[];
29
+ }) => Promise<void>;
30
+ toolAfter: (input: {
31
+ tool: string;
32
+ sessionID: string;
33
+ callID: string;
34
+ }, output: unknown) => Promise<void>;
35
+ };
29
36
  export {};
@@ -0,0 +1,16 @@
1
+ /** Hive promoter hook for opencode-swarm v6.17 two-tier knowledge system. */
2
+ import type { KnowledgeConfig, SwarmKnowledgeEntry } from './knowledge-types.js';
3
+ /**
4
+ * Main promotion logic: checks swarm entries and promotes eligible ones to hive.
5
+ * Also updates existing hive entries with new project confirmations.
6
+ *
7
+ * @note The 'hive-fast-track' tag is treated as privileged — it bypasses the
8
+ * 3-phase confirmation requirement. It should only be set by authorized tooling
9
+ * (inferTags() never produces it automatically).
10
+ */
11
+ export declare function checkHivePromotions(swarmEntries: SwarmKnowledgeEntry[], config: KnowledgeConfig): Promise<void>;
12
+ /**
13
+ * Create a hook that promotes swarm entries to the hive.
14
+ * The hook fires unconditionally - the caller decides when to invoke it.
15
+ */
16
+ export declare function createHivePromoterHook(directory: string, config: KnowledgeConfig): (input: unknown, output: unknown) => Promise<void>;
@@ -0,0 +1,17 @@
1
+ /** Knowledge curator hook for opencode-swarm v6.17 two-tier knowledge system. */
2
+ import type { KnowledgeConfig } from './knowledge-types.js';
3
+ /**
4
+ * Curate and store swarm knowledge entries from lessons.
5
+ */
6
+ export declare function curateAndStoreSwarm(lessons: string[], projectName: string, phaseInfo: {
7
+ phase_number: number;
8
+ }, directory: string, config: KnowledgeConfig): Promise<void>;
9
+ /**
10
+ * Auto-promote swarm entries based on phase confirmations and age.
11
+ */
12
+ export declare function runAutoPromotion(directory: string, config: KnowledgeConfig): Promise<void>;
13
+ /**
14
+ * Create the knowledge curator hook.
15
+ * Watches for writes to .swarm/plan.md and extracts lessons from the retrospective section.
16
+ */
17
+ export declare function createKnowledgeCuratorHook(directory: string, config: KnowledgeConfig): (input: unknown, output: unknown) => Promise<void>;
@@ -0,0 +1,20 @@
1
+ /** Phase-Start Knowledge Injection Hook for opencode-swarm v6.17.
2
+ *
3
+ * Injects relevant knowledge (from both swarm + hive tiers) into the architect's
4
+ * context at phase start. Caches the injection text for re-injection after
5
+ * compaction. Skips for non-architect agents. Appends rejected-pattern warnings
6
+ * to prevent re-learning loops.
7
+ */
8
+ import type { KnowledgeConfig, MessageWithParts } from './knowledge-types.js';
9
+ /**
10
+ * Creates a knowledge injection hook that injects relevant knowledge into the
11
+ * architect's message context at phase start. Supports caching for re-injection
12
+ * after compaction.
13
+ *
14
+ * @param directory - The project directory containing .swarm/
15
+ * @param config - Knowledge system configuration
16
+ * @returns A hook function that injects knowledge into messages
17
+ */
18
+ export declare function createKnowledgeInjectorHook(directory: string, config: KnowledgeConfig): (input: Record<string, never>, output: {
19
+ messages?: MessageWithParts[];
20
+ }) => Promise<void>;
@@ -0,0 +1,10 @@
1
+ /** One-time migration from .swarm/context.md → .swarm/knowledge.jsonl for existing projects. */
2
+ import type { KnowledgeConfig } from './knowledge-types.js';
3
+ export interface MigrationResult {
4
+ migrated: boolean;
5
+ entriesMigrated: number;
6
+ entriesDropped: number;
7
+ entriesTotal: number;
8
+ skippedReason?: 'sentinel-exists' | 'no-context-file' | 'empty-context';
9
+ }
10
+ export declare function migrateContextToKnowledge(directory: string, config: KnowledgeConfig): Promise<MigrationResult>;
@@ -0,0 +1,18 @@
1
+ /** Read path for the opencode-swarm v6.17 two-tier knowledge system.
2
+ * Merges swarm + hive knowledge, deduplicates (hive wins), ranks by composite score,
3
+ * and provides utility tracking.
4
+ */
5
+ import type { KnowledgeConfig, KnowledgeEntryBase } from './knowledge-types.js';
6
+ export interface ProjectContext {
7
+ projectName: string;
8
+ currentPhase: string;
9
+ techStack?: string[];
10
+ recentErrors?: string[];
11
+ }
12
+ export interface RankedEntry extends KnowledgeEntryBase {
13
+ tier: 'swarm' | 'hive';
14
+ relevanceScore: number;
15
+ finalScore: number;
16
+ }
17
+ export declare function readMergedKnowledge(directory: string, config: KnowledgeConfig, context?: ProjectContext): Promise<RankedEntry[]>;
18
+ export declare function updateRetrievalOutcome(directory: string, phaseInfo: string, phaseSucceeded: boolean): Promise<void>;
@@ -0,0 +1,19 @@
1
+ /** Core storage layer for the opencode-swarm v6.17 two-tier knowledge system. */
2
+ import type { RejectedLesson } from './knowledge-types.js';
3
+ export declare function resolveSwarmKnowledgePath(directory: string): string;
4
+ export declare function resolveSwarmRejectedPath(directory: string): string;
5
+ export declare function resolveHiveKnowledgePath(): string;
6
+ export declare function resolveHiveRejectedPath(): string;
7
+ export declare function readKnowledge<T>(filePath: string): Promise<T[]>;
8
+ export declare function readRejectedLessons(directory: string): Promise<RejectedLesson[]>;
9
+ export declare function appendKnowledge<T>(filePath: string, entry: T): Promise<void>;
10
+ export declare function rewriteKnowledge<T>(filePath: string, entries: T[]): Promise<void>;
11
+ export declare function appendRejectedLesson(directory: string, lesson: RejectedLesson): Promise<void>;
12
+ export declare function normalize(text: string): string;
13
+ export declare function wordBigrams(text: string): Set<string>;
14
+ export declare function jaccardBigram(a: Set<string>, b: Set<string>): number;
15
+ export declare function findNearDuplicate<T extends {
16
+ lesson: string;
17
+ }>(candidate: string, entries: T[], threshold?: number): T | undefined;
18
+ export declare function computeConfidence(confirmedByCount: number, autoGenerated: boolean): number;
19
+ export declare function inferTags(lesson: string): string[];
@@ -0,0 +1,101 @@
1
+ /** Type definitions for the opencode-swarm v6.17 two-tier knowledge system. */
2
+ export type KnowledgeCategory = 'process' | 'architecture' | 'tooling' | 'security' | 'testing' | 'debugging' | 'performance' | 'integration' | 'other';
3
+ export interface PhaseConfirmationRecord {
4
+ phase_number: number;
5
+ confirmed_at: string;
6
+ project_name: string;
7
+ }
8
+ export interface ProjectConfirmationRecord {
9
+ project_name: string;
10
+ confirmed_at: string;
11
+ phase_number?: number;
12
+ }
13
+ export interface RetrievalOutcome {
14
+ applied_count: number;
15
+ succeeded_after_count: number;
16
+ failed_after_count: number;
17
+ last_applied_at?: string;
18
+ }
19
+ export interface KnowledgeEntryBase {
20
+ id: string;
21
+ tier: 'swarm' | 'hive';
22
+ lesson: string;
23
+ category: KnowledgeCategory;
24
+ tags: string[];
25
+ scope: string;
26
+ confidence: number;
27
+ status: 'candidate' | 'established' | 'promoted';
28
+ confirmed_by: PhaseConfirmationRecord[] | ProjectConfirmationRecord[];
29
+ retrieval_outcomes: RetrievalOutcome;
30
+ schema_version: number;
31
+ created_at: string;
32
+ updated_at: string;
33
+ hive_eligible?: boolean;
34
+ auto_generated?: boolean;
35
+ }
36
+ export interface SwarmKnowledgeEntry extends KnowledgeEntryBase {
37
+ tier: 'swarm';
38
+ confirmed_by: PhaseConfirmationRecord[];
39
+ project_name: string;
40
+ }
41
+ export interface HiveKnowledgeEntry extends KnowledgeEntryBase {
42
+ tier: 'hive';
43
+ confirmed_by: ProjectConfirmationRecord[];
44
+ source_project: string;
45
+ }
46
+ export interface RejectedLesson {
47
+ id: string;
48
+ lesson: string;
49
+ rejection_reason: string;
50
+ rejected_at: string;
51
+ rejection_layer: 1 | 2 | 3;
52
+ }
53
+ export interface KnowledgeConfig {
54
+ /** Enable or disable the entire knowledge system. Default: true */
55
+ enabled: boolean;
56
+ /** Maximum entries to keep in swarm knowledge.jsonl. Default: 100 */
57
+ swarm_max_entries: number;
58
+ /** Maximum entries to keep in hive shared-learnings.jsonl. Default: 200 */
59
+ hive_max_entries: number;
60
+ /** Days before auto-promotion to hive tier. Default: 90 */
61
+ auto_promote_days: number;
62
+ /** Maximum knowledge entries to inject per architect message. Default: 5 */
63
+ max_inject_count: number;
64
+ /** Jaccard bigram similarity threshold for deduplication. Default: 0.6 */
65
+ dedup_threshold: number;
66
+ /** Scope filters to apply when reading knowledge. Default: ['global'] */
67
+ scope_filter: string[];
68
+ /** Enable hive (cross-project) tier reads and writes. Default: true */
69
+ hive_enabled: boolean;
70
+ /** Maximum rejected lesson fingerprints to retain. Default: 20 */
71
+ rejected_max_entries: number;
72
+ /** Enable validation gate before storing lessons. Default: true */
73
+ validation_enabled: boolean;
74
+ /** Confidence threshold for marking an entry evergreen. Default: 0.9 */
75
+ evergreen_confidence: number;
76
+ /** Utility score threshold for marking an entry evergreen. Default: 0.8 */
77
+ evergreen_utility: number;
78
+ /** Utility score at or below which an entry is considered low-utility. Default: 0.3 */
79
+ low_utility_threshold: number;
80
+ /** Minimum retrieval count before utility scoring begins. Default: 3 */
81
+ min_retrievals_for_utility: number;
82
+ /** JSONL schema version. Default: 1 */
83
+ schema_version: number;
84
+ }
85
+ export interface MessageInfo {
86
+ role: string;
87
+ agent?: string;
88
+ sessionID?: string;
89
+ modelID?: string;
90
+ providerID?: string;
91
+ [key: string]: unknown;
92
+ }
93
+ export interface MessagePart {
94
+ type: string;
95
+ text?: string;
96
+ [key: string]: unknown;
97
+ }
98
+ export interface MessageWithParts {
99
+ info: MessageInfo;
100
+ parts: MessagePart[];
101
+ }
@@ -0,0 +1,28 @@
1
+ /** Three-layer validation gate for the opencode-swarm v6.17 knowledge system. */
2
+ import type { KnowledgeCategory, KnowledgeEntryBase } from './knowledge-types.js';
3
+ export interface ValidationResult {
4
+ valid: boolean;
5
+ layer: 1 | 2 | 3 | null;
6
+ reason: string | null;
7
+ severity: 'error' | 'warning' | null;
8
+ }
9
+ export declare const DANGEROUS_COMMAND_PATTERNS: RegExp[];
10
+ export declare const SECURITY_DEGRADING_PATTERNS: RegExp[];
11
+ export declare const INJECTION_PATTERNS: RegExp[];
12
+ export declare function validateLesson(candidate: string, existingLessons: string[], meta: {
13
+ category: KnowledgeCategory;
14
+ scope: string;
15
+ confidence: number;
16
+ }): ValidationResult;
17
+ export interface QuarantinedEntry extends KnowledgeEntryBase {
18
+ quarantine_reason: string;
19
+ quarantined_at: string;
20
+ reported_by: 'architect' | 'user' | 'auto';
21
+ }
22
+ export interface EntryHealthResult {
23
+ healthy: boolean;
24
+ concern?: string;
25
+ }
26
+ export declare function auditEntryHealth(entry: KnowledgeEntryBase): EntryHealthResult;
27
+ export declare function quarantineEntry(directory: string, entryId: string, reason: string, reportedBy: 'architect' | 'user' | 'auto'): Promise<void>;
28
+ export declare function restoreEntry(directory: string, entryId: string): Promise<void>;