opencode-swarm 7.62.1 → 7.64.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/.opencode/skills/swarm-pr-review/SKILL.md +124 -0
- package/README.md +57 -0
- package/dist/agents/architect.d.ts +1 -1
- package/dist/agents/explorer.d.ts +1 -1
- package/dist/agents/reviewer-directive-compliance.d.ts +43 -0
- package/dist/cli/index.js +3418 -1029
- package/dist/config/constants.d.ts +2 -0
- package/dist/config/evidence-schema.d.ts +44 -44
- package/dist/config/schema.d.ts +201 -0
- package/dist/hooks/delegate-ack-collector.d.ts +51 -0
- package/dist/hooks/delegate-directive-injection.d.ts +33 -0
- package/dist/hooks/knowledge-application.d.ts +4 -3
- package/dist/hooks/knowledge-curator.d.ts +73 -1
- package/dist/hooks/knowledge-escalator.d.ts +50 -0
- package/dist/hooks/knowledge-events.d.ts +63 -3
- package/dist/hooks/knowledge-injector.d.ts +69 -1
- package/dist/hooks/knowledge-types.d.ts +41 -1
- package/dist/hooks/knowledge-validator.d.ts +43 -0
- package/dist/hooks/micro-reflector.d.ts +91 -0
- package/dist/hooks/phase-complete-directive-gate.d.ts +44 -0
- package/dist/hooks/phase-directives.d.ts +29 -0
- package/dist/hooks/reviewer-verdict-parser.d.ts +64 -0
- package/dist/hooks/search-knowledge.d.ts +33 -0
- package/dist/index.js +8600 -3951
- package/dist/memory/schema.d.ts +2 -2
- package/dist/services/directive-predicate-runner.d.ts +72 -0
- package/dist/services/external-skill-store.d.ts +96 -0
- package/dist/services/external-skill-validator.d.ts +160 -0
- package/dist/services/knowledge-diagnostics.d.ts +19 -0
- package/dist/services/skill-improver.d.ts +11 -0
- package/dist/services/status-service.d.ts +3 -0
- package/dist/services/synonym-map.d.ts +136 -0
- package/dist/services/trajectory-cluster.d.ts +49 -0
- package/dist/services/unactionable-hardening.d.ts +47 -0
- package/dist/tools/external-skill-delete.d.ts +16 -0
- package/dist/tools/external-skill-discover.d.ts +21 -0
- package/dist/tools/external-skill-inspect.d.ts +15 -0
- package/dist/tools/external-skill-list.d.ts +15 -0
- package/dist/tools/external-skill-promote.d.ts +20 -0
- package/dist/tools/external-skill-reject.d.ts +15 -0
- package/dist/tools/external-skill-revoke.d.ts +17 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/manifest.d.ts +7 -0
- package/dist/tools/phase-complete.d.ts +10 -0
- package/dist/tools/tool-metadata.d.ts +28 -0
- package/package.json +1 -1
package/dist/config/schema.d.ts
CHANGED
|
@@ -497,6 +497,7 @@ export declare const KnowledgeConfigSchema: z.ZodObject<{
|
|
|
497
497
|
hive_max_entries: z.ZodDefault<z.ZodNumber>;
|
|
498
498
|
auto_promote_days: z.ZodDefault<z.ZodNumber>;
|
|
499
499
|
max_inject_count: z.ZodDefault<z.ZodNumber>;
|
|
500
|
+
delegate_max_inject_count: z.ZodDefault<z.ZodNumber>;
|
|
500
501
|
inject_char_budget: z.ZodDefault<z.ZodNumber>;
|
|
501
502
|
context_budget_threshold: z.ZodOptional<z.ZodNumber>;
|
|
502
503
|
max_lesson_display_chars: z.ZodDefault<z.ZodNumber>;
|
|
@@ -520,6 +521,13 @@ export declare const KnowledgeConfigSchema: z.ZodObject<{
|
|
|
520
521
|
default_max_phases: z.ZodDefault<z.ZodNumber>;
|
|
521
522
|
todo_max_phases: z.ZodDefault<z.ZodNumber>;
|
|
522
523
|
sweep_enabled: z.ZodDefault<z.ZodBoolean>;
|
|
524
|
+
retrieval: z.ZodOptional<z.ZodObject<{
|
|
525
|
+
mmr_lambda: z.ZodDefault<z.ZodNumber>;
|
|
526
|
+
cold_start_bonus: z.ZodDefault<z.ZodNumber>;
|
|
527
|
+
cold_start_max_age_phases: z.ZodDefault<z.ZodNumber>;
|
|
528
|
+
synonym_min_cooccurrence: z.ZodDefault<z.ZodNumber>;
|
|
529
|
+
synonym_map_max_pairs: z.ZodDefault<z.ZodNumber>;
|
|
530
|
+
}, z.core.$strip>>;
|
|
523
531
|
}, z.core.$strip>;
|
|
524
532
|
export type KnowledgeConfig = z.infer<typeof KnowledgeConfigSchema>;
|
|
525
533
|
export declare const MemoryConfigSchema: z.ZodObject<{
|
|
@@ -954,6 +962,163 @@ export declare const TurboConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
954
962
|
}, z.core.$strip>;
|
|
955
963
|
}, z.core.$strip>], "strategy">;
|
|
956
964
|
export type TurboConfig = z.infer<typeof TurboConfigSchema>;
|
|
965
|
+
/** Where an external skill candidate was discovered. */
|
|
966
|
+
export declare const ExternalSkillCandidateSourceTypeSchema: z.ZodEnum<{
|
|
967
|
+
github: "github";
|
|
968
|
+
url: "url";
|
|
969
|
+
collection: "collection";
|
|
970
|
+
manual_import: "manual_import";
|
|
971
|
+
}>;
|
|
972
|
+
export type ExternalSkillCandidateSourceType = z.infer<typeof ExternalSkillCandidateSourceTypeSchema>;
|
|
973
|
+
/** Evaluation verdict for an external skill candidate. */
|
|
974
|
+
export declare const ExternalSkillCandidateEvaluationVerdictSchema: z.ZodEnum<{
|
|
975
|
+
pending: "pending";
|
|
976
|
+
in_review: "in_review";
|
|
977
|
+
quarantined: "quarantined";
|
|
978
|
+
passed: "passed";
|
|
979
|
+
rejected: "rejected";
|
|
980
|
+
promoted: "promoted";
|
|
981
|
+
revoked: "revoked";
|
|
982
|
+
}>;
|
|
983
|
+
export type ExternalSkillCandidateEvaluationVerdict = z.infer<typeof ExternalSkillCandidateEvaluationVerdictSchema>;
|
|
984
|
+
/** A single discovery source that feeds candidates into the quarantine store. */
|
|
985
|
+
export declare const DiscoverySourceSchema: z.ZodObject<{
|
|
986
|
+
type: z.ZodEnum<{
|
|
987
|
+
github: "github";
|
|
988
|
+
url: "url";
|
|
989
|
+
collection: "collection";
|
|
990
|
+
manual_import: "manual_import";
|
|
991
|
+
}>;
|
|
992
|
+
location: z.ZodString;
|
|
993
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
994
|
+
trust_level: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
995
|
+
low: "low";
|
|
996
|
+
medium: "medium";
|
|
997
|
+
high: "high";
|
|
998
|
+
}>>>;
|
|
999
|
+
}, z.core.$strip>;
|
|
1000
|
+
export type DiscoverySource = z.infer<typeof DiscoverySourceSchema>;
|
|
1001
|
+
/**
|
|
1002
|
+
* A quarantined or evaluated external skill candidate awaiting promotion.
|
|
1003
|
+
* Stored in `.swarm/external-skills/` with content-addressable naming.
|
|
1004
|
+
*/
|
|
1005
|
+
export declare const ExternalSkillCandidateSchema: z.ZodObject<{
|
|
1006
|
+
id: z.ZodString;
|
|
1007
|
+
source_url: z.ZodString;
|
|
1008
|
+
source_type: z.ZodEnum<{
|
|
1009
|
+
github: "github";
|
|
1010
|
+
url: "url";
|
|
1011
|
+
collection: "collection";
|
|
1012
|
+
manual_import: "manual_import";
|
|
1013
|
+
}>;
|
|
1014
|
+
publisher: z.ZodString;
|
|
1015
|
+
sha256: z.ZodString;
|
|
1016
|
+
fetched_at: z.ZodString;
|
|
1017
|
+
skill_name: z.ZodOptional<z.ZodString>;
|
|
1018
|
+
skill_description: z.ZodOptional<z.ZodString>;
|
|
1019
|
+
skill_body: z.ZodString;
|
|
1020
|
+
risk_flags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
1021
|
+
evaluation_verdict: z.ZodDefault<z.ZodEnum<{
|
|
1022
|
+
pending: "pending";
|
|
1023
|
+
in_review: "in_review";
|
|
1024
|
+
quarantined: "quarantined";
|
|
1025
|
+
passed: "passed";
|
|
1026
|
+
rejected: "rejected";
|
|
1027
|
+
promoted: "promoted";
|
|
1028
|
+
revoked: "revoked";
|
|
1029
|
+
}>>;
|
|
1030
|
+
evaluation_history: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
1031
|
+
verdict: z.ZodEnum<{
|
|
1032
|
+
pending: "pending";
|
|
1033
|
+
in_review: "in_review";
|
|
1034
|
+
quarantined: "quarantined";
|
|
1035
|
+
passed: "passed";
|
|
1036
|
+
rejected: "rejected";
|
|
1037
|
+
promoted: "promoted";
|
|
1038
|
+
revoked: "revoked";
|
|
1039
|
+
}>;
|
|
1040
|
+
timestamp: z.ZodString;
|
|
1041
|
+
actor: z.ZodString;
|
|
1042
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
1043
|
+
candidate_id: z.ZodOptional<z.ZodString>;
|
|
1044
|
+
original_verdict: z.ZodOptional<z.ZodEnum<{
|
|
1045
|
+
pending: "pending";
|
|
1046
|
+
in_review: "in_review";
|
|
1047
|
+
quarantined: "quarantined";
|
|
1048
|
+
passed: "passed";
|
|
1049
|
+
rejected: "rejected";
|
|
1050
|
+
promoted: "promoted";
|
|
1051
|
+
revoked: "revoked";
|
|
1052
|
+
}>>;
|
|
1053
|
+
gate_results: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1054
|
+
gate: z.ZodString;
|
|
1055
|
+
verdict: z.ZodString;
|
|
1056
|
+
}, z.core.$strip>>>;
|
|
1057
|
+
risk_assessment: z.ZodOptional<z.ZodObject<{
|
|
1058
|
+
total_flags: z.ZodNumber;
|
|
1059
|
+
findings: z.ZodArray<z.ZodObject<{
|
|
1060
|
+
severity: z.ZodEnum<{
|
|
1061
|
+
error: "error";
|
|
1062
|
+
warning: "warning";
|
|
1063
|
+
}>;
|
|
1064
|
+
category: z.ZodString;
|
|
1065
|
+
}, z.core.$strip>>;
|
|
1066
|
+
}, z.core.$strip>>;
|
|
1067
|
+
risk_flags_count: z.ZodOptional<z.ZodNumber>;
|
|
1068
|
+
provenance_snapshot: z.ZodOptional<z.ZodObject<{
|
|
1069
|
+
sha256: z.ZodString;
|
|
1070
|
+
source_url: z.ZodString;
|
|
1071
|
+
publisher: z.ZodString;
|
|
1072
|
+
fetched_at: z.ZodOptional<z.ZodString>;
|
|
1073
|
+
}, z.core.$strip>>;
|
|
1074
|
+
target_path: z.ZodOptional<z.ZodString>;
|
|
1075
|
+
promoted_content_hash: z.ZodOptional<z.ZodString>;
|
|
1076
|
+
original_evaluation: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1077
|
+
}, z.core.$strip>>>;
|
|
1078
|
+
}, z.core.$strip>;
|
|
1079
|
+
export type ExternalSkillCandidate = z.infer<typeof ExternalSkillCandidateSchema>;
|
|
1080
|
+
/** Top-level configuration block for the external skills subsystem. */
|
|
1081
|
+
export declare const ExternalSkillsConfigSchema: z.ZodObject<{
|
|
1082
|
+
curation_enabled: z.ZodDefault<z.ZodBoolean>;
|
|
1083
|
+
max_candidates: z.ZodDefault<z.ZodNumber>;
|
|
1084
|
+
max_bytes_per_candidate: z.ZodDefault<z.ZodNumber>;
|
|
1085
|
+
eviction_policy: z.ZodDefault<z.ZodEnum<{
|
|
1086
|
+
fifo: "fifo";
|
|
1087
|
+
}>>;
|
|
1088
|
+
ttl_days: z.ZodDefault<z.ZodNumber>;
|
|
1089
|
+
evaluation_enabled: z.ZodDefault<z.ZodBoolean>;
|
|
1090
|
+
sources: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
1091
|
+
type: z.ZodEnum<{
|
|
1092
|
+
github: "github";
|
|
1093
|
+
url: "url";
|
|
1094
|
+
collection: "collection";
|
|
1095
|
+
manual_import: "manual_import";
|
|
1096
|
+
}>;
|
|
1097
|
+
location: z.ZodString;
|
|
1098
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
1099
|
+
trust_level: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
1100
|
+
low: "low";
|
|
1101
|
+
medium: "medium";
|
|
1102
|
+
high: "high";
|
|
1103
|
+
}>>>;
|
|
1104
|
+
}, z.core.$strip>>>;
|
|
1105
|
+
max_candidates_per_discovery: z.ZodDefault<z.ZodNumber>;
|
|
1106
|
+
max_concurrent_fetches: z.ZodDefault<z.ZodNumber>;
|
|
1107
|
+
fetch_timeout_ms: z.ZodDefault<z.ZodNumber>;
|
|
1108
|
+
}, z.core.$strip>;
|
|
1109
|
+
export type ExternalSkillsConfig = z.infer<typeof ExternalSkillsConfigSchema>;
|
|
1110
|
+
/** Default external skills configuration (all subsystems disabled). */
|
|
1111
|
+
export declare const DEFAULT_EXTERNAL_SKILLS_CONFIG: ExternalSkillsConfig;
|
|
1112
|
+
/**
|
|
1113
|
+
* Resolve the external_skills config section, merging user-provided values
|
|
1114
|
+
* over defaults. Returns the default (all-disabled) config when
|
|
1115
|
+
* `external_skills` is absent or undefined, ensuring callers never need
|
|
1116
|
+
* null checks.
|
|
1117
|
+
*
|
|
1118
|
+
* Invalid source configs produce warnings via the logger but do NOT block
|
|
1119
|
+
* plugin load (AGENTS.md #1 — fail-open, bounded init).
|
|
1120
|
+
*/
|
|
1121
|
+
export declare function resolveExternalSkillsConfig(input: unknown): ExternalSkillsConfig;
|
|
957
1122
|
export declare const PluginConfigSchema: z.ZodObject<{
|
|
958
1123
|
agents: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
959
1124
|
model: z.ZodOptional<z.ZodString>;
|
|
@@ -1264,6 +1429,7 @@ export declare const PluginConfigSchema: z.ZodObject<{
|
|
|
1264
1429
|
hive_max_entries: z.ZodDefault<z.ZodNumber>;
|
|
1265
1430
|
auto_promote_days: z.ZodDefault<z.ZodNumber>;
|
|
1266
1431
|
max_inject_count: z.ZodDefault<z.ZodNumber>;
|
|
1432
|
+
delegate_max_inject_count: z.ZodDefault<z.ZodNumber>;
|
|
1267
1433
|
inject_char_budget: z.ZodDefault<z.ZodNumber>;
|
|
1268
1434
|
context_budget_threshold: z.ZodOptional<z.ZodNumber>;
|
|
1269
1435
|
max_lesson_display_chars: z.ZodDefault<z.ZodNumber>;
|
|
@@ -1287,6 +1453,13 @@ export declare const PluginConfigSchema: z.ZodObject<{
|
|
|
1287
1453
|
default_max_phases: z.ZodDefault<z.ZodNumber>;
|
|
1288
1454
|
todo_max_phases: z.ZodDefault<z.ZodNumber>;
|
|
1289
1455
|
sweep_enabled: z.ZodDefault<z.ZodBoolean>;
|
|
1456
|
+
retrieval: z.ZodOptional<z.ZodObject<{
|
|
1457
|
+
mmr_lambda: z.ZodDefault<z.ZodNumber>;
|
|
1458
|
+
cold_start_bonus: z.ZodDefault<z.ZodNumber>;
|
|
1459
|
+
cold_start_max_age_phases: z.ZodDefault<z.ZodNumber>;
|
|
1460
|
+
synonym_min_cooccurrence: z.ZodDefault<z.ZodNumber>;
|
|
1461
|
+
synonym_map_max_pairs: z.ZodDefault<z.ZodNumber>;
|
|
1462
|
+
}, z.core.$strip>>;
|
|
1290
1463
|
}, z.core.$strip>>;
|
|
1291
1464
|
memory: z.ZodOptional<z.ZodObject<{
|
|
1292
1465
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -1607,6 +1780,34 @@ export declare const PluginConfigSchema: z.ZodObject<{
|
|
|
1607
1780
|
every_minutes: z.ZodDefault<z.ZodNumber>;
|
|
1608
1781
|
}, z.core.$strip>>;
|
|
1609
1782
|
}, z.core.$strip>>>;
|
|
1783
|
+
external_skills: z.ZodOptional<z.ZodObject<{
|
|
1784
|
+
curation_enabled: z.ZodDefault<z.ZodBoolean>;
|
|
1785
|
+
max_candidates: z.ZodDefault<z.ZodNumber>;
|
|
1786
|
+
max_bytes_per_candidate: z.ZodDefault<z.ZodNumber>;
|
|
1787
|
+
eviction_policy: z.ZodDefault<z.ZodEnum<{
|
|
1788
|
+
fifo: "fifo";
|
|
1789
|
+
}>>;
|
|
1790
|
+
ttl_days: z.ZodDefault<z.ZodNumber>;
|
|
1791
|
+
evaluation_enabled: z.ZodDefault<z.ZodBoolean>;
|
|
1792
|
+
sources: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
1793
|
+
type: z.ZodEnum<{
|
|
1794
|
+
github: "github";
|
|
1795
|
+
url: "url";
|
|
1796
|
+
collection: "collection";
|
|
1797
|
+
manual_import: "manual_import";
|
|
1798
|
+
}>;
|
|
1799
|
+
location: z.ZodString;
|
|
1800
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
1801
|
+
trust_level: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
1802
|
+
low: "low";
|
|
1803
|
+
medium: "medium";
|
|
1804
|
+
high: "high";
|
|
1805
|
+
}>>>;
|
|
1806
|
+
}, z.core.$strip>>>;
|
|
1807
|
+
max_candidates_per_discovery: z.ZodDefault<z.ZodNumber>;
|
|
1808
|
+
max_concurrent_fetches: z.ZodDefault<z.ZodNumber>;
|
|
1809
|
+
fetch_timeout_ms: z.ZodDefault<z.ZodNumber>;
|
|
1810
|
+
}, z.core.$strip>>;
|
|
1610
1811
|
}, z.core.$strip>;
|
|
1611
1812
|
export type PluginConfig = z.infer<typeof PluginConfigSchema>;
|
|
1612
1813
|
export type { AgentName, PipelineAgentName, QAAgentName, } from './constants';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegate ack collection (Swarm Learning System, Change 1 / Task 1.5).
|
|
3
|
+
*
|
|
4
|
+
* A `tool.execute.after` hook on the `Task` tool. After a delegated subagent
|
|
5
|
+
* returns, this reconciles the directives that were shown to it (recovered by
|
|
6
|
+
* parsing the `<delegate_knowledge_directives>` block out of the delegation
|
|
7
|
+
* prompt) against the ack markers in the subagent's transcript:
|
|
8
|
+
*
|
|
9
|
+
* - For every ack whose ID was actually shown, emit a receipt event of the
|
|
10
|
+
* matching type (applied / ignored / violated / n_a). Acks for IDs that were
|
|
11
|
+
* never shown are DROPPED (anti-spoofing).
|
|
12
|
+
* - For every CRITICAL directive that was shown but never acknowledged, emit a
|
|
13
|
+
* `violated` event with reason `unacknowledged` and append an audit line to
|
|
14
|
+
* `.swarm/unacknowledged-criticals.jsonl`.
|
|
15
|
+
*
|
|
16
|
+
* Stateless by design: it re-parses the prompt rather than relying on
|
|
17
|
+
* cross-hook mutable state, so it is safe under parallel delegations. Fail-open:
|
|
18
|
+
* never throws, never blocks.
|
|
19
|
+
*/
|
|
20
|
+
export interface DelegateAckInput {
|
|
21
|
+
tool: unknown;
|
|
22
|
+
agent?: unknown;
|
|
23
|
+
sessionID?: unknown;
|
|
24
|
+
args?: unknown;
|
|
25
|
+
}
|
|
26
|
+
export interface DelegateAckOutput {
|
|
27
|
+
output?: unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface CollectDelegateAcksResult {
|
|
30
|
+
emitted: Array<{
|
|
31
|
+
id: string;
|
|
32
|
+
type: string;
|
|
33
|
+
}>;
|
|
34
|
+
unacknowledgedCriticals: string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Core reconciliation used by both the runtime hook and tests. Returns a summary
|
|
38
|
+
* of what was emitted. Never throws.
|
|
39
|
+
*/
|
|
40
|
+
export declare function collectDelegateAcks(params: {
|
|
41
|
+
directory: string;
|
|
42
|
+
prompt: string;
|
|
43
|
+
transcript: string;
|
|
44
|
+
agent: string;
|
|
45
|
+
sessionId?: string;
|
|
46
|
+
taskId?: string;
|
|
47
|
+
}): Promise<CollectDelegateAcksResult>;
|
|
48
|
+
/**
|
|
49
|
+
* `tool.execute.after` adapter. Reconciles delegate acks for a completed Task.
|
|
50
|
+
*/
|
|
51
|
+
export declare function collectDelegateAcksAfter(directory: string, input: DelegateAckInput, output: DelegateAckOutput): Promise<void>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Architect-side delegate directive injection (Swarm Learning System, Change 1 /
|
|
3
|
+
* Task 1.4).
|
|
4
|
+
*
|
|
5
|
+
* When the architect delegates via the `Task` tool, this `tool.execute.before`
|
|
6
|
+
* hook prepends the role-scoped `<delegate_knowledge_directives>` block to the
|
|
7
|
+
* subagent's prompt so the delegate sees the directives (and the ack contract)
|
|
8
|
+
* from its very first message. It mirrors the existing skill-injection pattern
|
|
9
|
+
* in src/index.ts, which already mutates `input.args.prompt`.
|
|
10
|
+
*
|
|
11
|
+
* This is ADVISORY (prompt enrichment): it must never throw or block a
|
|
12
|
+
* delegation. A retrieval failure simply leaves the prompt unchanged.
|
|
13
|
+
*
|
|
14
|
+
* NOTE on plan deviation: the implementation plan listed `src/agents/architect.ts`
|
|
15
|
+
* as the "delegation prompt builder". The architect is prompt-driven — real
|
|
16
|
+
* delegations are constructed by the model at runtime via the Task tool, so the
|
|
17
|
+
* code-accurate interception point is this hook, not the architect prompt
|
|
18
|
+
* template. The architect's own `<swarm_knowledge_directives>` injection is
|
|
19
|
+
* untouched.
|
|
20
|
+
*/
|
|
21
|
+
import type { KnowledgeConfig } from './knowledge-types.js';
|
|
22
|
+
export interface DelegateInjectionInput {
|
|
23
|
+
tool: unknown;
|
|
24
|
+
agent?: unknown;
|
|
25
|
+
sessionID?: unknown;
|
|
26
|
+
args?: unknown;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Prepend the per-delegate directive block to a Task delegation's prompt.
|
|
30
|
+
* Returns the number of directives injected (0 when nothing was injected),
|
|
31
|
+
* primarily for test assertions. Never throws.
|
|
32
|
+
*/
|
|
33
|
+
export declare function injectDelegateDirectivesBefore(directory: string, input: DelegateInjectionInput, config: KnowledgeConfig): Promise<number>;
|
|
@@ -8,15 +8,16 @@
|
|
|
8
8
|
import type { KnowledgeApplicationResult } from './knowledge-types.js';
|
|
9
9
|
export declare function resolveApplicationLogPath(directory: string): string;
|
|
10
10
|
/**
|
|
11
|
-
* Parse explicit knowledge-acknowledgment markers from architect text.
|
|
11
|
+
* Parse explicit knowledge-acknowledgment markers from architect/delegate text.
|
|
12
12
|
* Recognised forms (case-insensitive, line-anchored or inline):
|
|
13
13
|
* KNOWLEDGE_APPLIED: <id>
|
|
14
14
|
* KNOWLEDGE_IGNORED: <id> reason=<reason>
|
|
15
15
|
* KNOWLEDGE_VIOLATED: <id> reason=<reason>
|
|
16
|
+
* KNOWLEDGE_N_A: <id> reason=<reason> (delegate contract, Change 1)
|
|
16
17
|
*/
|
|
17
18
|
export interface ParsedAcknowledgment {
|
|
18
19
|
id: string;
|
|
19
|
-
result: 'applied' | 'ignored' | 'violated';
|
|
20
|
+
result: 'applied' | 'ignored' | 'violated' | 'n_a';
|
|
20
21
|
reason?: string;
|
|
21
22
|
}
|
|
22
23
|
export declare function parseAcknowledgments(text: string): ParsedAcknowledgment[];
|
|
@@ -38,7 +39,7 @@ export declare function recordKnowledgeShown(directory: string, ids: string[], c
|
|
|
38
39
|
export declare function recordAcknowledgment(directory: string, ack: ParsedAcknowledgment, ctx: RecordContext): Promise<void>;
|
|
39
40
|
/** Build the dedup key. Exported so test code and the runtime integration
|
|
40
41
|
* share the exact format. */
|
|
41
|
-
export declare function buildAckDedupKey(sessionId: string, id: string, result: KnowledgeApplicationResult, now?: Date): string;
|
|
42
|
+
export declare function buildAckDedupKey(sessionId: string, id: string, result: KnowledgeApplicationResult | 'n_a', now?: Date): string;
|
|
42
43
|
/** Acknowledgment recording with dedup. Returns whether a record was actually
|
|
43
44
|
* written (false on dedup hit). dedupSet should be swarmState.knowledgeAckDedup
|
|
44
45
|
* in production; tests can pass a fresh Set. */
|
|
@@ -1,10 +1,68 @@
|
|
|
1
1
|
/** Knowledge curator hook for opencode-swarm v6.17 two-tier knowledge system. */
|
|
2
|
-
import type {
|
|
2
|
+
import type { CuratorLLMDelegate } from './curator.js';
|
|
3
|
+
import type { ActionableDirectiveFields, KnowledgeConfig, SwarmKnowledgeEntry } from './knowledge-types.js';
|
|
4
|
+
import { type InsightCandidate } from './micro-reflector.js';
|
|
5
|
+
declare const seenRetroSections: Map<string, {
|
|
6
|
+
value: string;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Bound seenRetroSections to MAX_TRACKED_RETRO_SECTIONS entries, evicting the
|
|
11
|
+
* oldest-timestamp entries first. Called after every insert so the map can never
|
|
12
|
+
* exceed the cap regardless of how many distinct sessions appear within the
|
|
13
|
+
* 24-hour prune window.
|
|
14
|
+
*/
|
|
15
|
+
declare function capSeenRetroSections(): void;
|
|
16
|
+
/** Record a seen-section hash and enforce the size cap in one step. */
|
|
17
|
+
declare function recordSeenRetroSection(key: string, value: string, timestamp: number): void;
|
|
3
18
|
/**
|
|
4
19
|
* Check if the input is a write operation targeting an evidence file.
|
|
5
20
|
* Exported for testing purposes only.
|
|
6
21
|
*/
|
|
7
22
|
export declare function isWriteToEvidenceFile(input: unknown): boolean;
|
|
23
|
+
/** Build the v3-schema enrichment prompt for a single prose lesson. */
|
|
24
|
+
export declare function buildV3EnrichmentPrompt(lesson: string, category: string, tags: string[]): string;
|
|
25
|
+
/**
|
|
26
|
+
* Parse + validate an enrichment response. Returns the sanitized fields when
|
|
27
|
+
* the output is shape-valid AND actionable, otherwise the list of missing
|
|
28
|
+
* requirements (for the RETRY follow-up). Untrusted-input hardened: only
|
|
29
|
+
* allowlisted fields are copied, then shape-validated by
|
|
30
|
+
* validateActionableFields (length caps, name patterns, injection checks).
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseV3EnrichmentResponse(text: string): {
|
|
33
|
+
fields: ActionableDirectiveFields;
|
|
34
|
+
} | {
|
|
35
|
+
missing: string[];
|
|
36
|
+
};
|
|
37
|
+
export interface EnrichmentQuotaOptions {
|
|
38
|
+
maxCalls: number;
|
|
39
|
+
window: 'utc' | 'local';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Enrich one prose lesson with v3 actionability fields via the curator LLM.
|
|
43
|
+
* One retry on schema failure (with a RETRY message naming the missing
|
|
44
|
+
* fields). Quota-gated per call via skill-improver-quota. Returns null when
|
|
45
|
+
* enrichment is unavailable (quota exhausted) or fails twice — the caller
|
|
46
|
+
* quarantines the entry. Never throws.
|
|
47
|
+
*/
|
|
48
|
+
export declare function enrichLessonToV3(params: {
|
|
49
|
+
directory: string;
|
|
50
|
+
llmDelegate: CuratorLLMDelegate;
|
|
51
|
+
lesson: string;
|
|
52
|
+
category: string;
|
|
53
|
+
tags: string[];
|
|
54
|
+
quota?: EnrichmentQuotaOptions;
|
|
55
|
+
}): Promise<ActionableDirectiveFields | null>;
|
|
56
|
+
/** Max insight candidates folded into the store per phase boundary. */
|
|
57
|
+
export declare const MESO_INSIGHT_BATCH_LIMIT = 20;
|
|
58
|
+
/**
|
|
59
|
+
* Atomically consume up to `batchLimit` insight candidates from
|
|
60
|
+
* `.swarm/insight-candidates.jsonl`, writing back the unconsumed tail under the
|
|
61
|
+
* same lock so concurrent micro-reflection appends are never lost. Fail-open.
|
|
62
|
+
*/
|
|
63
|
+
export declare function consumeInsightCandidates(directory: string, batchLimit?: number): Promise<InsightCandidate[]>;
|
|
64
|
+
/** Build a SwarmKnowledgeEntry from an already-v3-actionable insight candidate. */
|
|
65
|
+
export declare function insightCandidateToEntry(cand: InsightCandidate, projectName: string, phaseNumber: number, config: KnowledgeConfig): SwarmKnowledgeEntry;
|
|
8
66
|
/**
|
|
9
67
|
* Curate and store swarm knowledge entries from lessons.
|
|
10
68
|
* @returns Promise resolving to an object with counts of stored, skipped, and rejected lessons.
|
|
@@ -13,10 +71,19 @@ export declare function curateAndStoreSwarm(lessons: string[], projectName: stri
|
|
|
13
71
|
phase_number: number;
|
|
14
72
|
}, directory: string, config: KnowledgeConfig, options?: {
|
|
15
73
|
skipAutoPromotion?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Change 4 (Task 4.2): LLM delegate used to enrich plain-prose lessons
|
|
76
|
+
* with v3 actionability fields before the Layer-5 gate. When absent,
|
|
77
|
+
* non-actionable lessons go straight to the unactionable queue.
|
|
78
|
+
*/
|
|
79
|
+
llmDelegate?: CuratorLLMDelegate;
|
|
80
|
+
/** Quota knobs for enrichment calls (defaults: 10/day, utc window). */
|
|
81
|
+
enrichmentQuota?: EnrichmentQuotaOptions;
|
|
16
82
|
}): Promise<{
|
|
17
83
|
stored: number;
|
|
18
84
|
skipped: number;
|
|
19
85
|
rejected: number;
|
|
86
|
+
quarantined: number;
|
|
20
87
|
}>;
|
|
21
88
|
/**
|
|
22
89
|
* Auto-promote swarm entries based on phase confirmations and age.
|
|
@@ -32,4 +99,9 @@ export declare const _internals: {
|
|
|
32
99
|
curateAndStoreSwarm: typeof curateAndStoreSwarm;
|
|
33
100
|
runAutoPromotion: typeof runAutoPromotion;
|
|
34
101
|
createKnowledgeCuratorHook: typeof createKnowledgeCuratorHook;
|
|
102
|
+
seenRetroSections: typeof seenRetroSections;
|
|
103
|
+
recordSeenRetroSection: typeof recordSeenRetroSection;
|
|
104
|
+
capSeenRetroSections: typeof capSeenRetroSections;
|
|
105
|
+
MAX_TRACKED_RETRO_SECTIONS: number;
|
|
35
106
|
};
|
|
107
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repeat-mistake escalator (Swarm Learning System, Change 3 / Task 3.2).
|
|
3
|
+
*
|
|
4
|
+
* When the same directive is violated >= {@link ESCALATION_THRESHOLD} times
|
|
5
|
+
* within {@link ESCALATION_WINDOW_DAYS} days (across sessions), it is
|
|
6
|
+
* auto-promoted to `directive_priority:'critical'` + `enforcement_mode:'enforce'`,
|
|
7
|
+
* its `escalation_history` gets a `repeat_violation` record, and an `escalation`
|
|
8
|
+
* event is emitted. Idempotent: an entry already at critical/enforce is never
|
|
9
|
+
* re-escalated, even on subsequent violations.
|
|
10
|
+
*
|
|
11
|
+
* Persistence goes through `rewriteKnowledge` (never a raw JSONL write). Fail-open:
|
|
12
|
+
* any error leaves the entry untouched and returns `escalated:false`.
|
|
13
|
+
*/
|
|
14
|
+
import type { DirectivePriority } from './knowledge-types.js';
|
|
15
|
+
export declare const ESCALATION_WINDOW_DAYS = 30;
|
|
16
|
+
export declare const ESCALATION_THRESHOLD = 2;
|
|
17
|
+
export interface EscalationResult {
|
|
18
|
+
escalated: boolean;
|
|
19
|
+
entryId: string;
|
|
20
|
+
from?: DirectivePriority;
|
|
21
|
+
to?: DirectivePriority;
|
|
22
|
+
violationsInWindow?: number;
|
|
23
|
+
/** True when the entry was already critical/enforce (no-op, idempotent). */
|
|
24
|
+
alreadyEscalated?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Evaluate and (if warranted) apply a repeat-violation escalation to a single
|
|
28
|
+
* entry. Call AFTER the triggering `violated` event has been persisted.
|
|
29
|
+
*/
|
|
30
|
+
export declare function maybeEscalateOnViolation(directory: string, entryId: string, now?: Date): Promise<EscalationResult>;
|
|
31
|
+
export interface RecentEscalation {
|
|
32
|
+
entry_id: string;
|
|
33
|
+
from: string;
|
|
34
|
+
to: string;
|
|
35
|
+
reason: string;
|
|
36
|
+
at: string;
|
|
37
|
+
}
|
|
38
|
+
export declare const ESCALATION_DISPLAY_WINDOW_DAYS = 7;
|
|
39
|
+
/**
|
|
40
|
+
* Read escalation events from the last `windowDays` days, newest first. Used by
|
|
41
|
+
* the architect briefing and `/swarm status`. Fail-open: returns [] on error.
|
|
42
|
+
*/
|
|
43
|
+
export declare function readRecentEscalations(directory: string, windowDays?: number, now?: Date): Promise<RecentEscalation[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Render the architect-briefing "Recently Escalated" subsection. Returns null
|
|
46
|
+
* when there is nothing to show (no empty header).
|
|
47
|
+
*/
|
|
48
|
+
export declare function buildEscalationBriefing(escalations: RecentEscalation[], windowDays?: number): string | null;
|
|
49
|
+
/** Run the escalator for several entry IDs (deduped). Never throws. */
|
|
50
|
+
export declare function escalateViolatedEntries(directory: string, entryIds: string[], now?: Date): Promise<EscalationResult[]>;
|
|
@@ -29,7 +29,11 @@ export declare const KNOWLEDGE_EVENT_SCHEMA_VERSION = 1;
|
|
|
29
29
|
*/
|
|
30
30
|
export declare const MAX_EVENT_LOG_ENTRIES = 5000;
|
|
31
31
|
/** Retrieval modes that surface knowledge to an agent. */
|
|
32
|
-
export type RetrievalEventMode = 'manual' | 'auto_injection' | 'coder_context' | 'review_context' | 'curator'
|
|
32
|
+
export type RetrievalEventMode = 'manual' | 'auto_injection' | 'coder_context' | 'review_context' | 'curator'
|
|
33
|
+
/** Per-delegate directive injection (Change 1): a delegated subagent
|
|
34
|
+
* (coder/reviewer/test_engineer/sme/docs/designer/critic/curator) was shown
|
|
35
|
+
* the subset of directives scoped to its role + expected tools. */
|
|
36
|
+
| 'delegate_inject';
|
|
33
37
|
/** A retrieval: a query returned a ranked set of knowledge entries. */
|
|
34
38
|
export interface RetrievedEvent {
|
|
35
39
|
type: 'retrieved';
|
|
@@ -52,7 +56,13 @@ export interface RetrievedEvent {
|
|
|
52
56
|
}
|
|
53
57
|
/** A receipt: an agent explicitly considered a specific knowledge entry. */
|
|
54
58
|
export interface ReceiptEvent {
|
|
55
|
-
type: 'acknowledged' | 'applied' | 'ignored' | 'contradicted' | 'violated'
|
|
59
|
+
type: 'acknowledged' | 'applied' | 'ignored' | 'contradicted' | 'violated'
|
|
60
|
+
/** Delegate decided a shown directive did not apply to its task (Change 1).
|
|
61
|
+
* Recorded for auditability; never penalizes the entry's outcome signal. */
|
|
62
|
+
| 'n_a'
|
|
63
|
+
/** Architect explicitly accepted an unresolved critical violation at
|
|
64
|
+
* phase_complete (Change 2, Task 2.4). Audit-only; never affects rollups. */
|
|
65
|
+
| 'override';
|
|
56
66
|
schema_version?: number;
|
|
57
67
|
event_id: string;
|
|
58
68
|
trace_id: string;
|
|
@@ -63,6 +73,19 @@ export interface ReceiptEvent {
|
|
|
63
73
|
task_id?: string;
|
|
64
74
|
agent: string;
|
|
65
75
|
reason?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Origin discriminator (Change 2). Distinguishes reviewer-issued verdicts
|
|
78
|
+
* (`'reviewer'`) from delegate self-acks (`'delegate'`) without changing the
|
|
79
|
+
* `type`, so existing counter rollups (which switch on `type`) stay intact.
|
|
80
|
+
* A reviewer VERIFIED maps to type:'applied' with source:'reviewer'.
|
|
81
|
+
*/
|
|
82
|
+
source?: 'delegate' | 'reviewer' | string;
|
|
83
|
+
/** Result of executing a directive's verification_predicate (Change 2). */
|
|
84
|
+
predicate_check?: {
|
|
85
|
+
predicate: string;
|
|
86
|
+
result: 'pass' | 'fail' | 'error';
|
|
87
|
+
detail: string;
|
|
88
|
+
};
|
|
66
89
|
evidence?: {
|
|
67
90
|
files?: string[];
|
|
68
91
|
commands?: string[];
|
|
@@ -96,7 +119,19 @@ export interface ArchivedEvent {
|
|
|
96
119
|
evidence?: string;
|
|
97
120
|
previous_status?: string;
|
|
98
121
|
}
|
|
99
|
-
|
|
122
|
+
/** An escalation: a directive was auto-promoted by the repeat-mistake escalator. */
|
|
123
|
+
export interface EscalationEvent {
|
|
124
|
+
type: 'escalation';
|
|
125
|
+
schema_version?: number;
|
|
126
|
+
event_id: string;
|
|
127
|
+
timestamp: string;
|
|
128
|
+
entry_id: string;
|
|
129
|
+
from: string;
|
|
130
|
+
to: string;
|
|
131
|
+
reason: string;
|
|
132
|
+
enforcement_mode?: string;
|
|
133
|
+
}
|
|
134
|
+
export type KnowledgeEvent = RetrievedEvent | ReceiptEvent | OutcomeEvent | ArchivedEvent | EscalationEvent;
|
|
100
135
|
export type KnowledgeEventType = KnowledgeEvent['type'];
|
|
101
136
|
/**
|
|
102
137
|
* Event shape accepted by {@link appendKnowledgeEvent} / {@link recordKnowledgeEvent}.
|
|
@@ -154,6 +189,9 @@ export interface CounterRollup {
|
|
|
154
189
|
ignored_count: number;
|
|
155
190
|
violated_count: number;
|
|
156
191
|
contradicted_count: number;
|
|
192
|
+
/** Count of explicit not-applicable decisions (Change 1). Auditable, neutral:
|
|
193
|
+
* never contributes to the outcome ranking signal. */
|
|
194
|
+
n_a_count: number;
|
|
157
195
|
succeeded_after_shown_count: number;
|
|
158
196
|
failed_after_shown_count: number;
|
|
159
197
|
/**
|
|
@@ -164,7 +202,15 @@ export interface CounterRollup {
|
|
|
164
202
|
partial_after_shown_count: number;
|
|
165
203
|
last_applied_at?: string;
|
|
166
204
|
last_acknowledged_at?: string;
|
|
205
|
+
/**
|
|
206
|
+
* The most recent violation timestamps for this entry (ISO 8601, newest
|
|
207
|
+
* first, capped at the last {@link MAX_VIOLATION_TIMESTAMPS}). Feeds the
|
|
208
|
+
* repeat-mistake escalator (Change 3).
|
|
209
|
+
*/
|
|
210
|
+
violation_timestamps: string[];
|
|
167
211
|
}
|
|
212
|
+
/** Cap on retained per-entry violation timestamps. */
|
|
213
|
+
export declare const MAX_VIOLATION_TIMESTAMPS = 10;
|
|
168
214
|
/**
|
|
169
215
|
* Recompute per-entry counters deterministically from the immutable event log,
|
|
170
216
|
* optionally folding in legacy `knowledge-application.jsonl` records.
|
|
@@ -189,6 +235,20 @@ export interface CounterRollup {
|
|
|
189
235
|
* @param legacyRecords Optional legacy application records (any order).
|
|
190
236
|
*/
|
|
191
237
|
export declare function recomputeCounters(events: KnowledgeEvent[], legacyRecords?: KnowledgeApplicationRecord[]): Map<string, CounterRollup>;
|
|
238
|
+
/**
|
|
239
|
+
* Count how many of the given violation timestamps fall within `windowDays` of
|
|
240
|
+
* `now` (inclusive). Pure helper — deterministic given its inputs. Malformed
|
|
241
|
+
* timestamps are ignored.
|
|
242
|
+
*/
|
|
243
|
+
export declare function countViolationsInWindow(timestamps: string[], windowDays: number, now?: Date): number;
|
|
244
|
+
/**
|
|
245
|
+
* Async convenience: count an entry's violations within a day-window. Counts
|
|
246
|
+
* directly from the event log + legacy application records so the result is
|
|
247
|
+
* INDEPENDENT of the {@link MAX_VIOLATION_TIMESTAMPS} display cap (the rollup's
|
|
248
|
+
* `violation_timestamps` keeps only the newest 10 and would undercount an entry
|
|
249
|
+
* with more in-window violations). Fail-open: returns 0 on error.
|
|
250
|
+
*/
|
|
251
|
+
export declare function countEntryViolationsInWindow(directory: string, entryId: string, windowDays: number, now?: Date): Promise<number>;
|
|
192
252
|
/**
|
|
193
253
|
* Fail-open rollup reader for hot paths. Search and promotion use this instead
|
|
194
254
|
* of stale persisted counters so `knowledge_receipt` feedback affects ranking
|