opencode-swarm 7.73.3 → 7.74.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/cli/index.js +478 -196
- package/dist/config/schema.d.ts +14 -0
- package/dist/hooks/knowledge-application.d.ts +1 -0
- package/dist/hooks/knowledge-curator.d.ts +7 -2
- package/dist/hooks/knowledge-events.d.ts +16 -9
- package/dist/hooks/knowledge-injector.d.ts +1 -1
- package/dist/hooks/knowledge-reader.d.ts +1 -0
- package/dist/hooks/knowledge-store.d.ts +3 -0
- package/dist/hooks/knowledge-types.d.ts +5 -0
- package/dist/hooks/knowledge-validator.d.ts +5 -6
- package/dist/hooks/micro-reflector.d.ts +2 -1
- package/dist/hooks/skill-scoring.d.ts +1 -1
- package/dist/hooks/skill-usage-log.d.ts +7 -2
- package/dist/index.js +715 -318
- package/dist/services/external-skill-validator.d.ts +3 -0
- package/dist/services/skill-generator.d.ts +5 -0
- package/dist/services/skill-improver-quota.d.ts +6 -4
- package/dist/services/skill-improver.d.ts +6 -2
- package/dist/services/unactionable-hardening.d.ts +2 -2
- package/package.json +1 -1
- package/dist/skills/index.d.ts +0 -30
package/dist/config/schema.d.ts
CHANGED
|
@@ -575,6 +575,13 @@ export declare const KnowledgeConfigSchema: z.ZodObject<{
|
|
|
575
575
|
synonym_min_cooccurrence: z.ZodDefault<z.ZodNumber>;
|
|
576
576
|
synonym_map_max_pairs: z.ZodDefault<z.ZodNumber>;
|
|
577
577
|
}, z.core.$strip>>;
|
|
578
|
+
enrichment: z.ZodDefault<z.ZodObject<{
|
|
579
|
+
max_calls_per_day: z.ZodDefault<z.ZodNumber>;
|
|
580
|
+
quota_window: z.ZodDefault<z.ZodEnum<{
|
|
581
|
+
utc: "utc";
|
|
582
|
+
local: "local";
|
|
583
|
+
}>>;
|
|
584
|
+
}, z.core.$strip>>;
|
|
578
585
|
}, z.core.$strip>;
|
|
579
586
|
export type KnowledgeConfig = z.infer<typeof KnowledgeConfigSchema>;
|
|
580
587
|
export declare const MemoryConfigSchema: z.ZodObject<{
|
|
@@ -1561,6 +1568,13 @@ export declare const PluginConfigSchema: z.ZodObject<{
|
|
|
1561
1568
|
synonym_min_cooccurrence: z.ZodDefault<z.ZodNumber>;
|
|
1562
1569
|
synonym_map_max_pairs: z.ZodDefault<z.ZodNumber>;
|
|
1563
1570
|
}, z.core.$strip>>;
|
|
1571
|
+
enrichment: z.ZodDefault<z.ZodObject<{
|
|
1572
|
+
max_calls_per_day: z.ZodDefault<z.ZodNumber>;
|
|
1573
|
+
quota_window: z.ZodDefault<z.ZodEnum<{
|
|
1574
|
+
utc: "utc";
|
|
1575
|
+
local: "local";
|
|
1576
|
+
}>>;
|
|
1577
|
+
}, z.core.$strip>>;
|
|
1564
1578
|
}, z.core.$strip>>;
|
|
1565
1579
|
memory: z.ZodOptional<z.ZodObject<{
|
|
1566
1580
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { KnowledgeApplicationResult } from './knowledge-types.js';
|
|
9
9
|
export declare function resolveApplicationLogPath(directory: string): string;
|
|
10
|
+
export declare const MAX_LEGACY_APPLICATION_LOG_ENTRIES = 5000;
|
|
10
11
|
/**
|
|
11
12
|
* Parse explicit knowledge-acknowledgment markers from architect/delegate text.
|
|
12
13
|
* Recognised forms (case-insensitive, line-anchored or inline):
|
|
@@ -41,7 +41,8 @@ export interface EnrichmentQuotaOptions {
|
|
|
41
41
|
/**
|
|
42
42
|
* Enrich one prose lesson with v3 actionability fields via the curator LLM.
|
|
43
43
|
* One retry on schema failure (with a RETRY message naming the missing
|
|
44
|
-
* fields). Quota-gated per call via
|
|
44
|
+
* fields). Quota-gated per call via the dedicated knowledge-enrichment quota.
|
|
45
|
+
* Returns null when
|
|
45
46
|
* enrichment is unavailable (quota exhausted) or fails twice — the caller
|
|
46
47
|
* quarantines the entry. Never throws.
|
|
47
48
|
*/
|
|
@@ -94,7 +95,11 @@ export declare function runAutoPromotion(directory: string, config: KnowledgeCon
|
|
|
94
95
|
* Create the knowledge curator hook.
|
|
95
96
|
* Watches for writes to .swarm/plan.md and extracts lessons from the retrospective section.
|
|
96
97
|
*/
|
|
97
|
-
export
|
|
98
|
+
export interface KnowledgeCuratorHookOptions {
|
|
99
|
+
llmDelegateFactory?: (sessionID: string) => CuratorLLMDelegate | undefined;
|
|
100
|
+
enrichmentQuota?: EnrichmentQuotaOptions;
|
|
101
|
+
}
|
|
102
|
+
export declare function createKnowledgeCuratorHook(directory: string, config: KnowledgeConfig, options?: KnowledgeCuratorHookOptions): (input: unknown, output: unknown) => Promise<void>;
|
|
98
103
|
export declare const _internals: {
|
|
99
104
|
isWriteToEvidenceFile: typeof isWriteToEvidenceFile;
|
|
100
105
|
curateAndStoreSwarm: typeof curateAndStoreSwarm;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Event-sourced knowledge lifecycle for opencode-swarm.
|
|
3
3
|
*
|
|
4
|
-
* `.swarm/knowledge-events.jsonl`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* `.swarm/knowledge-events.jsonl` records meaningful knowledge interactions
|
|
5
|
+
* (retrieval, receipt, outcome, archival). Recent lines stay in the event log;
|
|
6
|
+
* old lines are folded into `.swarm/knowledge-counter-baseline.json` when the
|
|
7
|
+
* log exceeds the cap. The event log plus baseline are the authoritative
|
|
8
|
+
* history for derived per-entry counters (`retrieval_outcomes.*`).
|
|
9
9
|
*
|
|
10
10
|
* Design contracts:
|
|
11
|
-
* - Append-
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* - Append-first, bounded retention. New events use OS-level atomic append; trim
|
|
12
|
+
* rewrites only after folding evicted counters into the baseline so aggregate
|
|
13
|
+
* counters survive log rotation.
|
|
14
14
|
* - Fail-open. Event recording is telemetry; it must never break tool or hook
|
|
15
15
|
* execution. Use {@link recordKnowledgeEvent} (swallows + warns) on hot paths;
|
|
16
16
|
* {@link appendKnowledgeEvent} throws and is intended for tests / callers that
|
|
@@ -113,6 +113,7 @@ export interface ArchivedEvent {
|
|
|
113
113
|
event_id: string;
|
|
114
114
|
timestamp: string;
|
|
115
115
|
entry_id: string;
|
|
116
|
+
tier?: 'swarm' | 'hive';
|
|
116
117
|
actor: string;
|
|
117
118
|
reason: string;
|
|
118
119
|
mode: 'archive' | 'quarantine' | 'purge';
|
|
@@ -147,6 +148,8 @@ export type KnowledgeEventInput = KnowledgeEvent extends infer T ? T extends Kno
|
|
|
147
148
|
export declare const RECEIPT_EVENT_TYPES: ReadonlySet<string>;
|
|
148
149
|
/** Returns `.swarm/knowledge-events.jsonl` for the given project directory. */
|
|
149
150
|
export declare function resolveKnowledgeEventsPath(directory: string): string;
|
|
151
|
+
/** Returns `.swarm/knowledge-counter-baseline.json` for folded event counters. */
|
|
152
|
+
export declare function resolveKnowledgeCounterBaselinePath(directory: string): string;
|
|
150
153
|
/** Returns `.swarm/knowledge-application.jsonl` for legacy v2 audit records. */
|
|
151
154
|
export declare function resolveLegacyApplicationLogPath(directory: string): string;
|
|
152
155
|
/** Generate a fresh trace id. One per retrieval; receipts reference it. */
|
|
@@ -211,6 +214,7 @@ export interface CounterRollup {
|
|
|
211
214
|
}
|
|
212
215
|
/** Cap on retained per-entry violation timestamps. */
|
|
213
216
|
export declare const MAX_VIOLATION_TIMESTAMPS = 10;
|
|
217
|
+
declare function readCounterBaseline(directory: string): Promise<Map<string, CounterRollup>>;
|
|
214
218
|
/**
|
|
215
219
|
* Recompute per-entry counters deterministically from the immutable event log,
|
|
216
220
|
* optionally folding in legacy `knowledge-application.jsonl` records.
|
|
@@ -234,7 +238,7 @@ export declare const MAX_VIOLATION_TIMESTAMPS = 10;
|
|
|
234
238
|
* @param events Events from {@link readKnowledgeEvents}.
|
|
235
239
|
* @param legacyRecords Optional legacy application records (any order).
|
|
236
240
|
*/
|
|
237
|
-
export declare function recomputeCounters(events: KnowledgeEvent[], legacyRecords?: KnowledgeApplicationRecord[]): Map<string, CounterRollup>;
|
|
241
|
+
export declare function recomputeCounters(events: KnowledgeEvent[], legacyRecords?: KnowledgeApplicationRecord[], baseline?: Map<string, CounterRollup>): Map<string, CounterRollup>;
|
|
238
242
|
/**
|
|
239
243
|
* Count how many of the given violation timestamps fall within `windowDays` of
|
|
240
244
|
* `now` (inclusive). Pure helper — deterministic given its inputs. Malformed
|
|
@@ -276,9 +280,11 @@ export declare function applyKnowledgeVerdictFeedback(directory: string, options
|
|
|
276
280
|
}>;
|
|
277
281
|
export declare const _internals: {
|
|
278
282
|
resolveKnowledgeEventsPath: typeof resolveKnowledgeEventsPath;
|
|
283
|
+
resolveKnowledgeCounterBaselinePath: typeof resolveKnowledgeCounterBaselinePath;
|
|
279
284
|
appendKnowledgeEvent: typeof appendKnowledgeEvent;
|
|
280
285
|
recordKnowledgeEvent: typeof recordKnowledgeEvent;
|
|
281
286
|
readKnowledgeEvents: typeof readKnowledgeEvents;
|
|
287
|
+
readCounterBaseline: typeof readCounterBaseline;
|
|
282
288
|
readLegacyApplicationRecords: typeof readLegacyApplicationRecords;
|
|
283
289
|
readKnowledgeCounterRollups: typeof readKnowledgeCounterRollups;
|
|
284
290
|
effectiveRetrievalOutcomes: typeof effectiveRetrievalOutcomes;
|
|
@@ -287,3 +293,4 @@ export declare const _internals: {
|
|
|
287
293
|
newTraceId: typeof newTraceId;
|
|
288
294
|
newEventId: typeof newEventId;
|
|
289
295
|
};
|
|
296
|
+
export {};
|
|
@@ -87,7 +87,7 @@ export declare function matchesDelegateScope(entry: Pick<RankedEntry, 'applies_t
|
|
|
87
87
|
* @param config - Knowledge system configuration
|
|
88
88
|
* @returns A hook function that injects knowledge into messages
|
|
89
89
|
*/
|
|
90
|
-
export declare function createKnowledgeInjectorHook(directory: string, config: KnowledgeConfig): (input: Record<string, never>, output: {
|
|
90
|
+
export declare function createKnowledgeInjectorHook(directory: string, config: KnowledgeConfig, modelLimitOverrides?: Record<string, number>): (input: Record<string, never>, output: {
|
|
91
91
|
messages?: MessageWithParts[];
|
|
92
92
|
}) => Promise<void>;
|
|
93
93
|
export declare const _internals: {
|
|
@@ -17,6 +17,7 @@ export interface RankedEntry extends KnowledgeEntryBase {
|
|
|
17
17
|
keywords: number;
|
|
18
18
|
};
|
|
19
19
|
finalScore: number;
|
|
20
|
+
coldStartBoost?: number;
|
|
20
21
|
}
|
|
21
22
|
declare function transactShownFile(shownFile: string, mutate: (data: Record<string, string[]>) => Record<string, string[]> | null): Promise<boolean>;
|
|
22
23
|
export declare function readMergedKnowledge(directory: string, config: KnowledgeConfig, context?: ProjectContext, opts?: {
|
|
@@ -26,6 +26,7 @@ export declare function transactFile<T>(filePath: string, read: (filePath: strin
|
|
|
26
26
|
export declare function transactKnowledge<T>(filePath: string, mutate: (entries: T[]) => T[] | null): Promise<boolean>;
|
|
27
27
|
export declare function appendKnowledgeWithCapEnforcement<T>(filePath: string, entry: T, maxEntries: number): Promise<boolean>;
|
|
28
28
|
export declare function enforceKnowledgeCap<T>(filePath: string, maxEntries: number): Promise<void>;
|
|
29
|
+
declare function selectKnowledgeCapSurvivors<T>(entries: T[], maxEntries: number): T[];
|
|
29
30
|
export interface SweepResult {
|
|
30
31
|
scanned: number;
|
|
31
32
|
aged: number;
|
|
@@ -87,6 +88,8 @@ export declare const _internals: {
|
|
|
87
88
|
findNearDuplicate: typeof findNearDuplicate;
|
|
88
89
|
computeConfidence: typeof computeConfidence;
|
|
89
90
|
computeOutcomeSignal: typeof computeOutcomeSignal;
|
|
91
|
+
selectKnowledgeCapSurvivors: typeof selectKnowledgeCapSurvivors;
|
|
90
92
|
inferTags: typeof inferTags;
|
|
91
93
|
bumpKnowledgeConfidenceBatch: typeof bumpKnowledgeConfidenceBatch;
|
|
92
94
|
};
|
|
95
|
+
export {};
|
|
@@ -212,6 +212,11 @@ export interface KnowledgeConfig {
|
|
|
212
212
|
synonym_min_cooccurrence?: number;
|
|
213
213
|
synonym_map_max_pairs?: number;
|
|
214
214
|
};
|
|
215
|
+
/** Dedicated quota for LLM enrichment of plain-prose lessons into v3 directives. */
|
|
216
|
+
enrichment: {
|
|
217
|
+
max_calls_per_day: number;
|
|
218
|
+
quota_window: 'utc' | 'local';
|
|
219
|
+
};
|
|
215
220
|
}
|
|
216
221
|
export interface MessageInfo {
|
|
217
222
|
role: string;
|
|
@@ -6,6 +6,8 @@ export interface ValidationResult {
|
|
|
6
6
|
reason: string | null;
|
|
7
7
|
severity: 'error' | 'warning' | null;
|
|
8
8
|
}
|
|
9
|
+
export declare const DANGEROUS_COMMAND_ERROR_PATTERNS: RegExp[];
|
|
10
|
+
export declare const DANGEROUS_COMMAND_WARNING_PATTERNS: RegExp[];
|
|
9
11
|
export declare const DANGEROUS_COMMAND_PATTERNS: RegExp[];
|
|
10
12
|
export declare const SECURITY_DEGRADING_PATTERNS: RegExp[];
|
|
11
13
|
export declare const INVISIBLE_FORMAT_CHARS: RegExp;
|
|
@@ -65,12 +67,9 @@ export interface UnactionableRecord extends KnowledgeEntryBase {
|
|
|
65
67
|
* queue (held out of the active store, pending hardening by the skill-improver).
|
|
66
68
|
* FIFO-capped at 200. Best-effort: throws only on lock failure for tests.
|
|
67
69
|
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* damage at 200 records of plain text, (b) the hardening loop's promotion path
|
|
72
|
-
* dedups at commit time against the active store, and (c) queue producers are
|
|
73
|
-
* themselves quota- or phase-bounded. Revisit if telemetry shows real evictions.
|
|
70
|
+
* Duplicate or near-duplicate prose lessons are deduped under the same lock used
|
|
71
|
+
* for the append/trim transaction. This keeps hook-first/phase_complete replay
|
|
72
|
+
* from filling the bounded queue with equivalent quarantines.
|
|
74
73
|
*/
|
|
75
74
|
export declare function appendUnactionable(directory: string, entry: KnowledgeEntryBase, reason: string): Promise<void>;
|
|
76
75
|
export interface QuarantinedEntry extends KnowledgeEntryBase {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Budget: the prompt is capped well under ~2k input chars and the model is
|
|
15
15
|
* asked for ≤512 output. Exactly one LLM call per qualifying return, gated by
|
|
16
|
-
* the
|
|
16
|
+
* the dedicated knowledge-enrichment quota. Fail-open: never throws, never
|
|
17
|
+
* blocks.
|
|
17
18
|
*/
|
|
18
19
|
import type { CuratorLLMDelegate } from './curator.js';
|
|
19
20
|
import type { EnrichmentQuotaOptions } from './knowledge-curator.js';
|
|
@@ -88,7 +88,7 @@ declare function computeRecencyScore(lastUsedTimestamp: string): number;
|
|
|
88
88
|
* @param skillPath - Repo-relative path to the skill file.
|
|
89
89
|
* @returns Context match score in [0, 1].
|
|
90
90
|
*/
|
|
91
|
-
declare function computeContextMatchScore(taskDescription: string, skillPath: string): number;
|
|
91
|
+
declare function computeContextMatchScore(taskDescription: string, skillPath: string, metadata?: SkillMetadata): number;
|
|
92
92
|
/**
|
|
93
93
|
* Compute a composite relevance score for a skill based on its usage history
|
|
94
94
|
* and keyword overlap with the task description.
|
|
@@ -85,7 +85,12 @@ export declare const _internals: {
|
|
|
85
85
|
applySkillUsageFeedback: typeof applySkillUsageFeedback;
|
|
86
86
|
parseGeneratedFromKnowledge: typeof parseGeneratedFromKnowledge;
|
|
87
87
|
computeComplianceByVersion: typeof computeComplianceByVersion;
|
|
88
|
+
normalizeComplianceVerdict: typeof normalizeComplianceVerdict;
|
|
89
|
+
readFeedbackAppliedEntryIds: typeof readFeedbackAppliedEntryIds;
|
|
90
|
+
appendFeedbackAppliedMarker: typeof appendFeedbackAppliedMarker;
|
|
88
91
|
};
|
|
92
|
+
declare function readFeedbackAppliedEntryIds(directory: string): Set<string>;
|
|
93
|
+
declare function appendFeedbackAppliedMarker(directory: string, processedEntryIds: string[]): void;
|
|
89
94
|
/**
|
|
90
95
|
* Validate and append a single skill-usage entry to the JSONL log.
|
|
91
96
|
*
|
|
@@ -162,9 +167,9 @@ declare function parseGeneratedFromKnowledge(content: string): string[];
|
|
|
162
167
|
* Read skill-usage entries, resolve source knowledge IDs for each skill,
|
|
163
168
|
* and apply confidence bumps/decays to the originating knowledge entries.
|
|
164
169
|
*
|
|
165
|
-
* For each unique skillPath with at least one compliance or
|
|
170
|
+
* For each unique skillPath with at least one compliance or violated entry:
|
|
166
171
|
* 1. Resolve source knowledge UUIDs from the skill's SKILL.md frontmatter.
|
|
167
|
-
* 2. Count compliant and
|
|
172
|
+
* 2. Count compliant and violated events for that skill.
|
|
168
173
|
* 3. Compute net delta: if compliant count > violation count → +0.05; else → -0.1.
|
|
169
174
|
* 4. Call `bumpKnowledgeConfidenceBatch` with the aggregated deltas.
|
|
170
175
|
*
|