opencode-swarm-plugin 0.22.0 → 0.23.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/.turbo/turbo-build.log +9 -0
- package/CHANGELOG.md +20 -0
- package/README.md +109 -429
- package/dist/agent-mail.d.ts +480 -0
- package/dist/agent-mail.d.ts.map +1 -0
- package/dist/anti-patterns.d.ts +257 -0
- package/dist/anti-patterns.d.ts.map +1 -0
- package/dist/beads.d.ts +377 -0
- package/dist/beads.d.ts.map +1 -0
- package/dist/eval-capture.d.ts +206 -0
- package/dist/eval-capture.d.ts.map +1 -0
- package/dist/index.d.ts +1299 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +498 -4246
- package/dist/learning.d.ts +670 -0
- package/dist/learning.d.ts.map +1 -0
- package/dist/mandate-promotion.d.ts +93 -0
- package/dist/mandate-promotion.d.ts.map +1 -0
- package/dist/mandate-storage.d.ts +209 -0
- package/dist/mandate-storage.d.ts.map +1 -0
- package/dist/mandates.d.ts +230 -0
- package/dist/mandates.d.ts.map +1 -0
- package/dist/output-guardrails.d.ts +125 -0
- package/dist/output-guardrails.d.ts.map +1 -0
- package/dist/pattern-maturity.d.ts +246 -0
- package/dist/pattern-maturity.d.ts.map +1 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +493 -4241
- package/dist/rate-limiter.d.ts +218 -0
- package/dist/rate-limiter.d.ts.map +1 -0
- package/dist/repo-crawl.d.ts +146 -0
- package/dist/repo-crawl.d.ts.map +1 -0
- package/dist/schemas/bead.d.ts +255 -0
- package/dist/schemas/bead.d.ts.map +1 -0
- package/dist/schemas/evaluation.d.ts +161 -0
- package/dist/schemas/evaluation.d.ts.map +1 -0
- package/dist/schemas/index.d.ts +34 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/mandate.d.ts +336 -0
- package/dist/schemas/mandate.d.ts.map +1 -0
- package/dist/schemas/swarm-context.d.ts +131 -0
- package/dist/schemas/swarm-context.d.ts.map +1 -0
- package/dist/schemas/task.d.ts +188 -0
- package/dist/schemas/task.d.ts.map +1 -0
- package/dist/skills.d.ts +471 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/storage.d.ts +260 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/structured.d.ts +196 -0
- package/dist/structured.d.ts.map +1 -0
- package/dist/swarm-decompose.d.ts +201 -0
- package/dist/swarm-decompose.d.ts.map +1 -0
- package/dist/swarm-mail.d.ts +240 -0
- package/dist/swarm-mail.d.ts.map +1 -0
- package/dist/swarm-orchestrate.d.ts +708 -0
- package/dist/swarm-orchestrate.d.ts.map +1 -0
- package/dist/swarm-prompts.d.ts +292 -0
- package/dist/swarm-prompts.d.ts.map +1 -0
- package/dist/swarm-strategies.d.ts +100 -0
- package/dist/swarm-strategies.d.ts.map +1 -0
- package/dist/swarm.d.ts +455 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/tool-availability.d.ts +91 -0
- package/dist/tool-availability.d.ts.map +1 -0
- package/docs/planning/ADR-001-monorepo-structure.md +171 -0
- package/docs/planning/ADR-002-package-extraction.md +393 -0
- package/docs/planning/ADR-003-performance-improvements.md +451 -0
- package/docs/planning/ADR-004-message-queue-features.md +187 -0
- package/docs/planning/ADR-005-devtools-observability.md +202 -0
- package/docs/planning/ROADMAP.md +368 -0
- package/package.json +13 -24
- package/src/agent-mail.ts +1 -1
- package/src/beads.ts +1 -2
- package/src/index.ts +2 -2
- package/src/learning.integration.test.ts +66 -11
- package/src/mandate-storage.test.ts +3 -3
- package/src/storage.ts +78 -10
- package/src/swarm-mail.ts +3 -3
- package/src/swarm-orchestrate.ts +7 -7
- package/src/tool-availability.ts +1 -1
- package/tsconfig.json +1 -1
- package/.beads/.local_version +0 -1
- package/.beads/README.md +0 -81
- package/.beads/analysis/skill-architecture-meta-skills.md +0 -1562
- package/.beads/config.yaml +0 -62
- package/.beads/issues.jsonl +0 -2197
- package/.beads/metadata.json +0 -4
- package/.gitattributes +0 -3
- package/.github/workflows/ci.yml +0 -30
- package/.github/workflows/opencode.yml +0 -31
- package/.opencode/skills/tdd/SKILL.md +0 -182
- package/INTEGRATION_EXAMPLE.md +0 -66
- package/VERIFICATION_QUALITY_PATTERNS.md +0 -565
- package/bun.lock +0 -286
- package/dist/pglite.data +0 -0
- package/dist/pglite.wasm +0 -0
- package/src/streams/agent-mail.test.ts +0 -777
- package/src/streams/agent-mail.ts +0 -535
- package/src/streams/debug.test.ts +0 -500
- package/src/streams/debug.ts +0 -727
- package/src/streams/effect/ask.integration.test.ts +0 -314
- package/src/streams/effect/ask.ts +0 -202
- package/src/streams/effect/cursor.integration.test.ts +0 -418
- package/src/streams/effect/cursor.ts +0 -288
- package/src/streams/effect/deferred.test.ts +0 -357
- package/src/streams/effect/deferred.ts +0 -445
- package/src/streams/effect/index.ts +0 -17
- package/src/streams/effect/layers.ts +0 -73
- package/src/streams/effect/lock.test.ts +0 -385
- package/src/streams/effect/lock.ts +0 -399
- package/src/streams/effect/mailbox.test.ts +0 -260
- package/src/streams/effect/mailbox.ts +0 -318
- package/src/streams/events.test.ts +0 -924
- package/src/streams/events.ts +0 -329
- package/src/streams/index.test.ts +0 -229
- package/src/streams/index.ts +0 -578
- package/src/streams/migrations.test.ts +0 -359
- package/src/streams/migrations.ts +0 -362
- package/src/streams/projections.test.ts +0 -611
- package/src/streams/projections.ts +0 -504
- package/src/streams/store.integration.test.ts +0 -658
- package/src/streams/store.ts +0 -1075
- package/src/streams/swarm-mail.ts +0 -552
- package/test-bug-fixes.ts +0 -86
- package/vitest.integration.config.ts +0 -19
- package/vitest.integration.setup.ts +0 -48
- package/workflow-integration-analysis.md +0 -876
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mandate Promotion Engine
|
|
3
|
+
*
|
|
4
|
+
* Handles state transitions for mandate entries based on vote scores:
|
|
5
|
+
* - candidate → established: net_votes >= 2
|
|
6
|
+
* - established → mandate: net_votes >= 5 AND vote_ratio >= 0.7
|
|
7
|
+
* - any → rejected: net_votes <= -3
|
|
8
|
+
*
|
|
9
|
+
* Integrates with pattern-maturity.ts decay calculations and state machine patterns.
|
|
10
|
+
*/
|
|
11
|
+
import type { MandateDecayConfig, MandateEntry, MandateScore, MandateStatus } from "./schemas/mandate";
|
|
12
|
+
/**
|
|
13
|
+
* Result of a promotion evaluation
|
|
14
|
+
*/
|
|
15
|
+
export interface PromotionResult {
|
|
16
|
+
/** The mandate entry ID */
|
|
17
|
+
mandate_id: string;
|
|
18
|
+
/** Status before evaluation */
|
|
19
|
+
previous_status: MandateStatus;
|
|
20
|
+
/** Status after evaluation */
|
|
21
|
+
new_status: MandateStatus;
|
|
22
|
+
/** Calculated score */
|
|
23
|
+
score: MandateScore;
|
|
24
|
+
/** Whether status changed */
|
|
25
|
+
promoted: boolean;
|
|
26
|
+
/** Human-readable reason for the transition (or lack thereof) */
|
|
27
|
+
reason: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Determine new status based on score and current status
|
|
31
|
+
*
|
|
32
|
+
* State machine:
|
|
33
|
+
* - candidate → established: net_votes >= establishedNetVotesThreshold (2)
|
|
34
|
+
* - established → mandate: net_votes >= mandateNetVotesThreshold (5) AND vote_ratio >= mandateVoteRatioThreshold (0.7)
|
|
35
|
+
* - any → rejected: net_votes <= rejectedNetVotesThreshold (-3)
|
|
36
|
+
* - mandate stays mandate (no demotion)
|
|
37
|
+
* - rejected stays rejected (permanent)
|
|
38
|
+
*
|
|
39
|
+
* @param score - Calculated mandate score with decayed votes
|
|
40
|
+
* @param currentStatus - Current status of the mandate entry
|
|
41
|
+
* @param config - Threshold configuration
|
|
42
|
+
* @returns New status after applying transition rules
|
|
43
|
+
*/
|
|
44
|
+
export declare function shouldPromote(score: MandateScore, currentStatus: MandateStatus, config?: MandateDecayConfig): MandateStatus;
|
|
45
|
+
/**
|
|
46
|
+
* Evaluate promotion for a mandate entry
|
|
47
|
+
*
|
|
48
|
+
* Main entry point for promotion logic. Calculates new status and provides
|
|
49
|
+
* detailed reasoning for the decision.
|
|
50
|
+
*
|
|
51
|
+
* @param entry - The mandate entry to evaluate
|
|
52
|
+
* @param score - Calculated score with decayed votes
|
|
53
|
+
* @param config - Threshold configuration (optional)
|
|
54
|
+
* @returns Promotion result with status change and reasoning
|
|
55
|
+
*/
|
|
56
|
+
export declare function evaluatePromotion(entry: MandateEntry, score: MandateScore, config?: MandateDecayConfig): PromotionResult;
|
|
57
|
+
/**
|
|
58
|
+
* Format promotion result for logging or display
|
|
59
|
+
*
|
|
60
|
+
* @param result - Promotion result
|
|
61
|
+
* @returns Formatted string
|
|
62
|
+
*/
|
|
63
|
+
export declare function formatPromotionResult(result: PromotionResult): string;
|
|
64
|
+
/**
|
|
65
|
+
* Batch evaluate promotions for multiple entries
|
|
66
|
+
*
|
|
67
|
+
* Useful for periodic recalculation of all mandate statuses.
|
|
68
|
+
*
|
|
69
|
+
* @param entries - Map of mandate IDs to entries
|
|
70
|
+
* @param scores - Map of mandate IDs to scores
|
|
71
|
+
* @param config - Threshold configuration (optional)
|
|
72
|
+
* @returns Array of promotion results
|
|
73
|
+
*/
|
|
74
|
+
export declare function evaluateBatchPromotions(entries: Map<string, MandateEntry>, scores: Map<string, MandateScore>, config?: MandateDecayConfig): PromotionResult[];
|
|
75
|
+
/**
|
|
76
|
+
* Get entries that changed status (promoted or demoted)
|
|
77
|
+
*
|
|
78
|
+
* Useful for filtering batch results to only show changes.
|
|
79
|
+
*
|
|
80
|
+
* @param results - Promotion results
|
|
81
|
+
* @returns Only the results where status changed
|
|
82
|
+
*/
|
|
83
|
+
export declare function getStatusChanges(results: PromotionResult[]): PromotionResult[];
|
|
84
|
+
/**
|
|
85
|
+
* Group promotion results by status transition
|
|
86
|
+
*
|
|
87
|
+
* Useful for analytics and reporting.
|
|
88
|
+
*
|
|
89
|
+
* @param results - Promotion results
|
|
90
|
+
* @returns Map of transition keys (e.g., "candidate→established") to results
|
|
91
|
+
*/
|
|
92
|
+
export declare function groupByTransition(results: PromotionResult[]): Map<string, PromotionResult[]>;
|
|
93
|
+
//# sourceMappingURL=mandate-promotion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandate-promotion.d.ts","sourceRoot":"","sources":["../src/mandate-promotion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,aAAa,EACd,MAAM,mBAAmB,CAAC;AAM3B;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,eAAe,EAAE,aAAa,CAAC;IAC/B,8BAA8B;IAC9B,UAAU,EAAE,aAAa,CAAC;IAC1B,uBAAuB;IACvB,KAAK,EAAE,YAAY,CAAC;IACpB,6BAA6B;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;CAChB;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,YAAY,EACnB,aAAa,EAAE,aAAa,EAC5B,MAAM,GAAE,kBAAiD,GACxD,aAAa,CAmCf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,YAAY,EACnB,MAAM,GAAE,kBAAiD,GACxD,eAAe,CAkCjB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAMrE;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAClC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EACjC,MAAM,GAAE,kBAAiD,GACxD,eAAe,EAAE,CAenB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,eAAe,EAAE,GACzB,eAAe,EAAE,CAEnB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,eAAe,EAAE,GACzB,GAAG,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC,CAiBhC"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mandate Storage Module - Persistent storage for agent voting system
|
|
3
|
+
*
|
|
4
|
+
* Provides unified storage interface for mandate entries and votes:
|
|
5
|
+
* - semantic-memory (default) - Persistent with semantic search
|
|
6
|
+
* - in-memory - For testing and ephemeral sessions
|
|
7
|
+
*
|
|
8
|
+
* Collections:
|
|
9
|
+
* - `swarm-mandates` - Mandate entry storage
|
|
10
|
+
* - `swarm-votes` - Vote storage
|
|
11
|
+
*
|
|
12
|
+
* Score calculation uses 90-day half-life decay matching learning.ts patterns.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Use default semantic-memory storage
|
|
17
|
+
* const storage = createMandateStorage();
|
|
18
|
+
*
|
|
19
|
+
* // Or in-memory for testing
|
|
20
|
+
* const storage = createMandateStorage({ backend: "memory" });
|
|
21
|
+
*
|
|
22
|
+
* // Store a mandate
|
|
23
|
+
* await storage.store({
|
|
24
|
+
* id: "mandate-123",
|
|
25
|
+
* content: "Always use Effect for async operations",
|
|
26
|
+
* content_type: "tip",
|
|
27
|
+
* author_agent: "BlueLake",
|
|
28
|
+
* created_at: new Date().toISOString(),
|
|
29
|
+
* status: "candidate",
|
|
30
|
+
* tags: ["async", "effect"]
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Cast a vote
|
|
34
|
+
* await storage.vote({
|
|
35
|
+
* id: "vote-456",
|
|
36
|
+
* mandate_id: "mandate-123",
|
|
37
|
+
* agent_name: "BlueLake",
|
|
38
|
+
* vote_type: "upvote",
|
|
39
|
+
* timestamp: new Date().toISOString(),
|
|
40
|
+
* weight: 1.0
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Calculate score with decay
|
|
44
|
+
* const score = await storage.calculateScore("mandate-123");
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
import type { MandateEntry, Vote, MandateScore, MandateStatus, MandateContentType, MandateDecayConfig, ScoreCalculationResult } from "./schemas/mandate";
|
|
48
|
+
/**
|
|
49
|
+
* Reset the cached command (for testing)
|
|
50
|
+
*/
|
|
51
|
+
export declare function resetCommandCache(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Storage backend type
|
|
54
|
+
*/
|
|
55
|
+
export type MandateStorageBackend = "semantic-memory" | "memory";
|
|
56
|
+
/**
|
|
57
|
+
* Collection names for semantic-memory
|
|
58
|
+
*/
|
|
59
|
+
export interface MandateStorageCollections {
|
|
60
|
+
mandates: string;
|
|
61
|
+
votes: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Storage configuration
|
|
65
|
+
*/
|
|
66
|
+
export interface MandateStorageConfig {
|
|
67
|
+
/** Backend to use (default: "semantic-memory") */
|
|
68
|
+
backend: MandateStorageBackend;
|
|
69
|
+
/** Collection names for semantic-memory backend */
|
|
70
|
+
collections: MandateStorageCollections;
|
|
71
|
+
/** Decay configuration */
|
|
72
|
+
decay: MandateDecayConfig;
|
|
73
|
+
/** Whether to use semantic search for queries (default: true) */
|
|
74
|
+
useSemanticSearch: boolean;
|
|
75
|
+
}
|
|
76
|
+
export declare const DEFAULT_MANDATE_STORAGE_CONFIG: MandateStorageConfig;
|
|
77
|
+
/**
|
|
78
|
+
* Unified storage interface for mandate data
|
|
79
|
+
*/
|
|
80
|
+
export interface MandateStorage {
|
|
81
|
+
store(entry: MandateEntry): Promise<void>;
|
|
82
|
+
get(id: string): Promise<MandateEntry | null>;
|
|
83
|
+
find(query: string, limit?: number): Promise<MandateEntry[]>;
|
|
84
|
+
list(filter?: {
|
|
85
|
+
status?: MandateStatus;
|
|
86
|
+
content_type?: MandateContentType;
|
|
87
|
+
}): Promise<MandateEntry[]>;
|
|
88
|
+
update(id: string, updates: Partial<MandateEntry>): Promise<void>;
|
|
89
|
+
vote(vote: Vote): Promise<void>;
|
|
90
|
+
getVotes(mandateId: string): Promise<Vote[]>;
|
|
91
|
+
hasVoted(mandateId: string, agentName: string): Promise<boolean>;
|
|
92
|
+
calculateScore(mandateId: string): Promise<MandateScore>;
|
|
93
|
+
close(): Promise<void>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Semantic-memory backed mandate storage
|
|
97
|
+
*
|
|
98
|
+
* Uses the semantic-memory CLI for persistence with semantic search.
|
|
99
|
+
* Data survives across sessions and can be searched by meaning.
|
|
100
|
+
*/
|
|
101
|
+
export declare class SemanticMemoryMandateStorage implements MandateStorage {
|
|
102
|
+
private config;
|
|
103
|
+
constructor(config?: Partial<MandateStorageConfig>);
|
|
104
|
+
private storeInternal;
|
|
105
|
+
private findInternal;
|
|
106
|
+
private listInternal;
|
|
107
|
+
store(entry: MandateEntry): Promise<void>;
|
|
108
|
+
get(id: string): Promise<MandateEntry | null>;
|
|
109
|
+
find(query: string, limit?: number): Promise<MandateEntry[]>;
|
|
110
|
+
list(filter?: {
|
|
111
|
+
status?: MandateStatus;
|
|
112
|
+
content_type?: MandateContentType;
|
|
113
|
+
}): Promise<MandateEntry[]>;
|
|
114
|
+
update(id: string, updates: Partial<MandateEntry>): Promise<void>;
|
|
115
|
+
vote(vote: Vote): Promise<void>;
|
|
116
|
+
getVotes(mandateId: string): Promise<Vote[]>;
|
|
117
|
+
hasVoted(mandateId: string, agentName: string): Promise<boolean>;
|
|
118
|
+
calculateScore(mandateId: string): Promise<MandateScore>;
|
|
119
|
+
close(): Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* In-memory mandate storage
|
|
123
|
+
*
|
|
124
|
+
* Useful for testing and ephemeral sessions.
|
|
125
|
+
*/
|
|
126
|
+
export declare class InMemoryMandateStorage implements MandateStorage {
|
|
127
|
+
private entries;
|
|
128
|
+
private votes;
|
|
129
|
+
private config;
|
|
130
|
+
constructor(config?: Partial<MandateStorageConfig>);
|
|
131
|
+
store(entry: MandateEntry): Promise<void>;
|
|
132
|
+
get(id: string): Promise<MandateEntry | null>;
|
|
133
|
+
find(query: string, limit?: number): Promise<MandateEntry[]>;
|
|
134
|
+
list(filter?: {
|
|
135
|
+
status?: MandateStatus;
|
|
136
|
+
content_type?: MandateContentType;
|
|
137
|
+
}): Promise<MandateEntry[]>;
|
|
138
|
+
update(id: string, updates: Partial<MandateEntry>): Promise<void>;
|
|
139
|
+
vote(vote: Vote): Promise<void>;
|
|
140
|
+
getVotes(mandateId: string): Promise<Vote[]>;
|
|
141
|
+
hasVoted(mandateId: string, agentName: string): Promise<boolean>;
|
|
142
|
+
calculateScore(mandateId: string): Promise<MandateScore>;
|
|
143
|
+
close(): Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Create a mandate storage instance
|
|
147
|
+
*
|
|
148
|
+
* @param config - Storage configuration (default: semantic-memory)
|
|
149
|
+
* @returns Configured storage instance
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* // Default semantic-memory storage
|
|
154
|
+
* const storage = createMandateStorage();
|
|
155
|
+
*
|
|
156
|
+
* // In-memory for testing
|
|
157
|
+
* const storage = createMandateStorage({ backend: "memory" });
|
|
158
|
+
*
|
|
159
|
+
* // Custom collections
|
|
160
|
+
* const storage = createMandateStorage({
|
|
161
|
+
* backend: "semantic-memory",
|
|
162
|
+
* collections: {
|
|
163
|
+
* mandates: "my-mandates",
|
|
164
|
+
* votes: "my-votes",
|
|
165
|
+
* },
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function createMandateStorage(config?: Partial<MandateStorageConfig>): MandateStorage;
|
|
170
|
+
/**
|
|
171
|
+
* Update mandate status based on calculated score
|
|
172
|
+
*
|
|
173
|
+
* Applies thresholds from decay config to determine status transitions:
|
|
174
|
+
* - mandate: net_votes >= 5 AND vote_ratio >= 0.7
|
|
175
|
+
* - established: net_votes >= 2
|
|
176
|
+
* - rejected: net_votes <= -3
|
|
177
|
+
* - candidate: otherwise
|
|
178
|
+
*
|
|
179
|
+
* @param mandateId - Mandate ID
|
|
180
|
+
* @param storage - Storage instance
|
|
181
|
+
* @returns Score calculation result with status update
|
|
182
|
+
*/
|
|
183
|
+
export declare function updateMandateStatus(mandateId: string, storage: MandateStorage): Promise<ScoreCalculationResult>;
|
|
184
|
+
/**
|
|
185
|
+
* Batch update all mandate statuses
|
|
186
|
+
*
|
|
187
|
+
* Useful for periodic recalculation of scores/status across all mandates.
|
|
188
|
+
*
|
|
189
|
+
* @param storage - Storage instance
|
|
190
|
+
* @returns Array of score calculation results
|
|
191
|
+
*/
|
|
192
|
+
export declare function updateAllMandateStatuses(storage: MandateStorage): Promise<ScoreCalculationResult[]>;
|
|
193
|
+
/**
|
|
194
|
+
* Get or create the global mandate storage instance
|
|
195
|
+
*
|
|
196
|
+
* Uses semantic-memory by default.
|
|
197
|
+
*/
|
|
198
|
+
export declare function getMandateStorage(): MandateStorage;
|
|
199
|
+
/**
|
|
200
|
+
* Set the global mandate storage instance
|
|
201
|
+
*
|
|
202
|
+
* Useful for testing or custom configurations.
|
|
203
|
+
*/
|
|
204
|
+
export declare function setMandateStorage(storage: MandateStorage): void;
|
|
205
|
+
/**
|
|
206
|
+
* Reset the global mandate storage instance
|
|
207
|
+
*/
|
|
208
|
+
export declare function resetMandateStorage(): Promise<void>;
|
|
209
|
+
//# sourceMappingURL=mandate-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandate-storage.d.ts","sourceRoot":"","sources":["../src/mandate-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,K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;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,GAAE,OAAO,CAAC,oBAAoB,CAAM,GACzC,cAAc,CAahB;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,sBAAsB,CAAC,CAwCjC;AAED;;;;;;;GAOG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAUnC;AAQD;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAKlD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAE/D;AAED;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAKzD"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
export declare class MandateError extends Error {
|
|
2
|
+
readonly operation: string;
|
|
3
|
+
readonly details?: unknown | undefined;
|
|
4
|
+
constructor(message: string, operation: string, details?: unknown | undefined);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Submit a new mandate entry
|
|
8
|
+
*
|
|
9
|
+
* Creates a new entry in the mandate system for voting.
|
|
10
|
+
* Entries start in "candidate" status and can be promoted based on votes.
|
|
11
|
+
*/
|
|
12
|
+
export declare const mandate_file: {
|
|
13
|
+
description: string;
|
|
14
|
+
args: {
|
|
15
|
+
content: import("zod").ZodString;
|
|
16
|
+
content_type: import("zod").ZodEnum<{
|
|
17
|
+
idea: "idea";
|
|
18
|
+
tip: "tip";
|
|
19
|
+
lore: "lore";
|
|
20
|
+
snippet: "snippet";
|
|
21
|
+
feature_request: "feature_request";
|
|
22
|
+
}>;
|
|
23
|
+
tags: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
24
|
+
metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
|
|
25
|
+
};
|
|
26
|
+
execute(args: {
|
|
27
|
+
content: string;
|
|
28
|
+
content_type: "idea" | "tip" | "lore" | "snippet" | "feature_request";
|
|
29
|
+
tags?: string[] | undefined;
|
|
30
|
+
metadata?: Record<string, unknown> | undefined;
|
|
31
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Cast a vote on an existing mandate
|
|
35
|
+
*
|
|
36
|
+
* Each agent can vote once per mandate. Duplicate votes are rejected.
|
|
37
|
+
* Votes influence mandate status through consensus scoring.
|
|
38
|
+
*/
|
|
39
|
+
export declare const mandate_vote: {
|
|
40
|
+
description: string;
|
|
41
|
+
args: {
|
|
42
|
+
mandate_id: import("zod").ZodString;
|
|
43
|
+
vote_type: import("zod").ZodEnum<{
|
|
44
|
+
upvote: "upvote";
|
|
45
|
+
downvote: "downvote";
|
|
46
|
+
}>;
|
|
47
|
+
agent_name: import("zod").ZodString;
|
|
48
|
+
};
|
|
49
|
+
execute(args: {
|
|
50
|
+
mandate_id: string;
|
|
51
|
+
vote_type: "upvote" | "downvote";
|
|
52
|
+
agent_name: string;
|
|
53
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Search for relevant mandates using semantic search
|
|
57
|
+
*
|
|
58
|
+
* Queries the mandate system by meaning, not just keywords.
|
|
59
|
+
* Useful for finding past decisions or patterns related to a topic.
|
|
60
|
+
*/
|
|
61
|
+
export declare const mandate_query: {
|
|
62
|
+
description: string;
|
|
63
|
+
args: {
|
|
64
|
+
query: import("zod").ZodString;
|
|
65
|
+
limit: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
66
|
+
status: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
67
|
+
candidate: "candidate";
|
|
68
|
+
established: "established";
|
|
69
|
+
mandate: "mandate";
|
|
70
|
+
rejected: "rejected";
|
|
71
|
+
}>>;
|
|
72
|
+
content_type: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
73
|
+
idea: "idea";
|
|
74
|
+
tip: "tip";
|
|
75
|
+
lore: "lore";
|
|
76
|
+
snippet: "snippet";
|
|
77
|
+
feature_request: "feature_request";
|
|
78
|
+
}>>;
|
|
79
|
+
};
|
|
80
|
+
execute(args: {
|
|
81
|
+
query: string;
|
|
82
|
+
limit?: number | undefined;
|
|
83
|
+
status?: "candidate" | "established" | "mandate" | "rejected" | undefined;
|
|
84
|
+
content_type?: "idea" | "tip" | "lore" | "snippet" | "feature_request" | undefined;
|
|
85
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* List mandates with optional filters
|
|
89
|
+
*
|
|
90
|
+
* Retrieves mandates by status, content type, or both.
|
|
91
|
+
* Does not use semantic search - returns all matching mandates.
|
|
92
|
+
*/
|
|
93
|
+
export declare const mandate_list: {
|
|
94
|
+
description: string;
|
|
95
|
+
args: {
|
|
96
|
+
status: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
97
|
+
candidate: "candidate";
|
|
98
|
+
established: "established";
|
|
99
|
+
mandate: "mandate";
|
|
100
|
+
rejected: "rejected";
|
|
101
|
+
}>>;
|
|
102
|
+
content_type: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
103
|
+
idea: "idea";
|
|
104
|
+
tip: "tip";
|
|
105
|
+
lore: "lore";
|
|
106
|
+
snippet: "snippet";
|
|
107
|
+
feature_request: "feature_request";
|
|
108
|
+
}>>;
|
|
109
|
+
limit: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
110
|
+
};
|
|
111
|
+
execute(args: {
|
|
112
|
+
status?: "candidate" | "established" | "mandate" | "rejected" | undefined;
|
|
113
|
+
content_type?: "idea" | "tip" | "lore" | "snippet" | "feature_request" | undefined;
|
|
114
|
+
limit?: number | undefined;
|
|
115
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Get voting statistics for a mandate or overall system
|
|
119
|
+
*
|
|
120
|
+
* If mandate_id is provided, returns detailed stats for that mandate.
|
|
121
|
+
* Otherwise, returns aggregate stats across all mandates.
|
|
122
|
+
*/
|
|
123
|
+
export declare const mandate_stats: {
|
|
124
|
+
description: string;
|
|
125
|
+
args: {
|
|
126
|
+
mandate_id: import("zod").ZodOptional<import("zod").ZodString>;
|
|
127
|
+
};
|
|
128
|
+
execute(args: {
|
|
129
|
+
mandate_id?: string | undefined;
|
|
130
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
131
|
+
};
|
|
132
|
+
export declare const mandateTools: {
|
|
133
|
+
mandate_file: {
|
|
134
|
+
description: string;
|
|
135
|
+
args: {
|
|
136
|
+
content: import("zod").ZodString;
|
|
137
|
+
content_type: import("zod").ZodEnum<{
|
|
138
|
+
idea: "idea";
|
|
139
|
+
tip: "tip";
|
|
140
|
+
lore: "lore";
|
|
141
|
+
snippet: "snippet";
|
|
142
|
+
feature_request: "feature_request";
|
|
143
|
+
}>;
|
|
144
|
+
tags: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
145
|
+
metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
|
|
146
|
+
};
|
|
147
|
+
execute(args: {
|
|
148
|
+
content: string;
|
|
149
|
+
content_type: "idea" | "tip" | "lore" | "snippet" | "feature_request";
|
|
150
|
+
tags?: string[] | undefined;
|
|
151
|
+
metadata?: Record<string, unknown> | undefined;
|
|
152
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
153
|
+
};
|
|
154
|
+
mandate_vote: {
|
|
155
|
+
description: string;
|
|
156
|
+
args: {
|
|
157
|
+
mandate_id: import("zod").ZodString;
|
|
158
|
+
vote_type: import("zod").ZodEnum<{
|
|
159
|
+
upvote: "upvote";
|
|
160
|
+
downvote: "downvote";
|
|
161
|
+
}>;
|
|
162
|
+
agent_name: import("zod").ZodString;
|
|
163
|
+
};
|
|
164
|
+
execute(args: {
|
|
165
|
+
mandate_id: string;
|
|
166
|
+
vote_type: "upvote" | "downvote";
|
|
167
|
+
agent_name: string;
|
|
168
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
169
|
+
};
|
|
170
|
+
mandate_query: {
|
|
171
|
+
description: string;
|
|
172
|
+
args: {
|
|
173
|
+
query: import("zod").ZodString;
|
|
174
|
+
limit: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
175
|
+
status: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
176
|
+
candidate: "candidate";
|
|
177
|
+
established: "established";
|
|
178
|
+
mandate: "mandate";
|
|
179
|
+
rejected: "rejected";
|
|
180
|
+
}>>;
|
|
181
|
+
content_type: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
182
|
+
idea: "idea";
|
|
183
|
+
tip: "tip";
|
|
184
|
+
lore: "lore";
|
|
185
|
+
snippet: "snippet";
|
|
186
|
+
feature_request: "feature_request";
|
|
187
|
+
}>>;
|
|
188
|
+
};
|
|
189
|
+
execute(args: {
|
|
190
|
+
query: string;
|
|
191
|
+
limit?: number | undefined;
|
|
192
|
+
status?: "candidate" | "established" | "mandate" | "rejected" | undefined;
|
|
193
|
+
content_type?: "idea" | "tip" | "lore" | "snippet" | "feature_request" | undefined;
|
|
194
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
195
|
+
};
|
|
196
|
+
mandate_list: {
|
|
197
|
+
description: string;
|
|
198
|
+
args: {
|
|
199
|
+
status: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
200
|
+
candidate: "candidate";
|
|
201
|
+
established: "established";
|
|
202
|
+
mandate: "mandate";
|
|
203
|
+
rejected: "rejected";
|
|
204
|
+
}>>;
|
|
205
|
+
content_type: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
206
|
+
idea: "idea";
|
|
207
|
+
tip: "tip";
|
|
208
|
+
lore: "lore";
|
|
209
|
+
snippet: "snippet";
|
|
210
|
+
feature_request: "feature_request";
|
|
211
|
+
}>>;
|
|
212
|
+
limit: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
213
|
+
};
|
|
214
|
+
execute(args: {
|
|
215
|
+
status?: "candidate" | "established" | "mandate" | "rejected" | undefined;
|
|
216
|
+
content_type?: "idea" | "tip" | "lore" | "snippet" | "feature_request" | undefined;
|
|
217
|
+
limit?: number | undefined;
|
|
218
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
219
|
+
};
|
|
220
|
+
mandate_stats: {
|
|
221
|
+
description: string;
|
|
222
|
+
args: {
|
|
223
|
+
mandate_id: import("zod").ZodOptional<import("zod").ZodString>;
|
|
224
|
+
};
|
|
225
|
+
execute(args: {
|
|
226
|
+
mandate_id?: string | undefined;
|
|
227
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
//# sourceMappingURL=mandates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandates.d.ts","sourceRoot":"","sources":["../src/mandates.ts"],"names":[],"mappings":"AAuCA,qBAAa,YAAa,SAAQ,KAAK;aAGnB,SAAS,EAAE,MAAM;aACjB,OAAO,CAAC,EAAE,OAAO;gBAFjC,OAAO,EAAE,MAAM,EACC,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,OAAO,YAAA;CAKpC;AAgCD;;;;;GAKG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;CA6DvB,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;CA6FvB,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;CAkFxB,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;CA8EvB,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;;;;;CA+FxB,CAAC;AAMH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAMxB,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output Guardrails for MCP Tool Response Truncation
|
|
3
|
+
*
|
|
4
|
+
* Prevents MCP tools from blowing out context with massive responses.
|
|
5
|
+
* Provides smart truncation that preserves JSON, code blocks, and markdown structure.
|
|
6
|
+
*
|
|
7
|
+
* @module output-guardrails
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { guardrailOutput, DEFAULT_GUARDRAIL_CONFIG } from "./output-guardrails"
|
|
12
|
+
*
|
|
13
|
+
* const result = guardrailOutput("context7_get-library-docs", hugeOutput)
|
|
14
|
+
* if (result.truncated) {
|
|
15
|
+
* console.log(`Truncated ${result.originalLength - result.truncatedLength} chars`)
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Guardrail configuration for tool output limits
|
|
21
|
+
*
|
|
22
|
+
* Controls per-tool character limits and skip rules.
|
|
23
|
+
*/
|
|
24
|
+
export interface GuardrailConfig {
|
|
25
|
+
/**
|
|
26
|
+
* Default max characters for tool output
|
|
27
|
+
* Default: 32000 chars (~8000 tokens at 4 chars/token)
|
|
28
|
+
*/
|
|
29
|
+
defaultMaxChars: number;
|
|
30
|
+
/**
|
|
31
|
+
* Per-tool character limit overrides
|
|
32
|
+
*
|
|
33
|
+
* Higher limits for code/doc tools that commonly return large outputs.
|
|
34
|
+
*/
|
|
35
|
+
toolLimits: Record<string, number>;
|
|
36
|
+
/**
|
|
37
|
+
* Tools that should never be truncated
|
|
38
|
+
*
|
|
39
|
+
* Internal coordination tools (beads_*, swarmmail_*, structured_*)
|
|
40
|
+
* should always return complete output.
|
|
41
|
+
*/
|
|
42
|
+
skipTools: string[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Result of guardrail output processing
|
|
46
|
+
*/
|
|
47
|
+
export interface GuardrailResult {
|
|
48
|
+
/** Processed output (truncated if needed) */
|
|
49
|
+
output: string;
|
|
50
|
+
/** Whether truncation occurred */
|
|
51
|
+
truncated: boolean;
|
|
52
|
+
/** Original output length in characters */
|
|
53
|
+
originalLength: number;
|
|
54
|
+
/** Final output length in characters */
|
|
55
|
+
truncatedLength: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Metrics for guardrail analytics
|
|
59
|
+
*
|
|
60
|
+
* Used to track truncation patterns and adjust limits.
|
|
61
|
+
*/
|
|
62
|
+
export interface GuardrailMetrics {
|
|
63
|
+
/** Tool that produced the output */
|
|
64
|
+
toolName: string;
|
|
65
|
+
/** Original output length */
|
|
66
|
+
originalLength: number;
|
|
67
|
+
/** Truncated output length */
|
|
68
|
+
truncatedLength: number;
|
|
69
|
+
/** Timestamp of truncation */
|
|
70
|
+
timestamp: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Default guardrail configuration
|
|
74
|
+
*
|
|
75
|
+
* - defaultMaxChars: 32000 (~8000 tokens)
|
|
76
|
+
* - Higher limits for code/doc tools (64000)
|
|
77
|
+
* - Skip internal coordination tools
|
|
78
|
+
*/
|
|
79
|
+
export declare const DEFAULT_GUARDRAIL_CONFIG: GuardrailConfig;
|
|
80
|
+
/**
|
|
81
|
+
* Smart truncation preserving structure boundaries
|
|
82
|
+
*
|
|
83
|
+
* Truncates text while preserving:
|
|
84
|
+
* - JSON structure (finds matching braces, doesn't cut mid-object)
|
|
85
|
+
* - Code blocks (preserves ``` boundaries)
|
|
86
|
+
* - Markdown headers (cuts at ## boundaries when possible)
|
|
87
|
+
*
|
|
88
|
+
* @param text - Text to truncate
|
|
89
|
+
* @param maxChars - Maximum character count
|
|
90
|
+
* @returns Truncated text with "[TRUNCATED - X chars removed]" suffix
|
|
91
|
+
*/
|
|
92
|
+
export declare function truncateWithBoundaries(text: string, maxChars: number): string;
|
|
93
|
+
/**
|
|
94
|
+
* Apply guardrails to tool output
|
|
95
|
+
*
|
|
96
|
+
* Main entry point for guardrail processing:
|
|
97
|
+
* 1. Check if tool is in skipTools → return unchanged
|
|
98
|
+
* 2. Check if output.length > getToolLimit(toolName) → truncate
|
|
99
|
+
* 3. Return { output, truncated, originalLength, truncatedLength }
|
|
100
|
+
*
|
|
101
|
+
* @param toolName - Name of the tool that produced the output
|
|
102
|
+
* @param output - Tool output to process
|
|
103
|
+
* @param config - Optional guardrail configuration (defaults to DEFAULT_GUARDRAIL_CONFIG)
|
|
104
|
+
* @returns Guardrail result with truncated output and metadata
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const result = guardrailOutput("context7_get-library-docs", hugeOutput)
|
|
109
|
+
* console.log(result.output) // Truncated or original
|
|
110
|
+
* console.log(result.truncated) // true if truncated
|
|
111
|
+
* console.log(`${result.originalLength} → ${result.truncatedLength} chars`)
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function guardrailOutput(toolName: string, output: string, config?: GuardrailConfig): GuardrailResult;
|
|
115
|
+
/**
|
|
116
|
+
* Create a guardrail metrics entry
|
|
117
|
+
*
|
|
118
|
+
* Used for analytics and learning about truncation patterns.
|
|
119
|
+
*
|
|
120
|
+
* @param result - Guardrail result from guardrailOutput
|
|
121
|
+
* @param toolName - Name of the tool
|
|
122
|
+
* @returns Metrics entry
|
|
123
|
+
*/
|
|
124
|
+
export declare function createMetrics(result: GuardrailResult, toolName: string): GuardrailMetrics;
|
|
125
|
+
//# sourceMappingURL=output-guardrails.d.ts.map
|
|
@@ -0,0 +1 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