contextos-mcp 0.4.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/LICENSE +21 -0
- package/README.md +260 -0
- package/bin/mcp.mjs +61 -0
- package/bin/swarm.mjs +45 -0
- package/dist/agents/aider.d.ts +12 -0
- package/dist/agents/aider.js +192 -0
- package/dist/agents/aider.js.map +1 -0
- package/dist/agents/claude-code.d.ts +9 -0
- package/dist/agents/claude-code.js +236 -0
- package/dist/agents/claude-code.js.map +1 -0
- package/dist/agents/codex.d.ts +14 -0
- package/dist/agents/codex.js +203 -0
- package/dist/agents/codex.js.map +1 -0
- package/dist/agents/direct-llm.d.ts +22 -0
- package/dist/agents/direct-llm.js +254 -0
- package/dist/agents/direct-llm.js.map +1 -0
- package/dist/agents/mock.d.ts +10 -0
- package/dist/agents/mock.js +170 -0
- package/dist/agents/mock.js.map +1 -0
- package/dist/agents/opencode.d.ts +23 -0
- package/dist/agents/opencode.js +631 -0
- package/dist/agents/opencode.js.map +1 -0
- package/dist/agents/provider.d.ts +11 -0
- package/dist/agents/provider.js +31 -0
- package/dist/agents/provider.js.map +1 -0
- package/dist/compression/compressor.d.ts +28 -0
- package/dist/compression/compressor.js +268 -0
- package/dist/compression/compressor.js.map +1 -0
- package/dist/config.d.ts +43 -0
- package/dist/config.js +172 -0
- package/dist/config.js.map +1 -0
- package/dist/contextos/loader.d.ts +46 -0
- package/dist/contextos/loader.js +120 -0
- package/dist/contextos/loader.js.map +1 -0
- package/dist/contextos/selector.d.ts +46 -0
- package/dist/contextos/selector.js +80 -0
- package/dist/contextos/selector.js.map +1 -0
- package/dist/core/action-dispatcher.d.ts +15 -0
- package/dist/core/action-dispatcher.js +28 -0
- package/dist/core/action-dispatcher.js.map +1 -0
- package/dist/core/action-schema.d.ts +72 -0
- package/dist/core/action-schema.js +86 -0
- package/dist/core/action-schema.js.map +1 -0
- package/dist/core/repl-interface.d.ts +48 -0
- package/dist/core/repl-interface.js +5 -0
- package/dist/core/repl-interface.js.map +1 -0
- package/dist/core/repl.d.ts +59 -0
- package/dist/core/repl.js +353 -0
- package/dist/core/repl.js.map +1 -0
- package/dist/core/rlm.d.ts +65 -0
- package/dist/core/rlm.js +564 -0
- package/dist/core/rlm.js.map +1 -0
- package/dist/core/runtime.py +470 -0
- package/dist/core/types.d.ts +265 -0
- package/dist/core/types.js +19 -0
- package/dist/core/types.js.map +1 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.js +75 -0
- package/dist/env.js.map +1 -0
- package/dist/hooks/runner.d.ts +43 -0
- package/dist/hooks/runner.js +173 -0
- package/dist/hooks/runner.js.map +1 -0
- package/dist/labs/cli.d.ts +15 -0
- package/dist/labs/cli.js +295 -0
- package/dist/labs/cli.js.map +1 -0
- package/dist/labs/episodic-memory.d.ts +132 -0
- package/dist/labs/episodic-memory.js +391 -0
- package/dist/labs/episodic-memory.js.map +1 -0
- package/dist/labs/interactive-swarm.d.ts +20 -0
- package/dist/labs/interactive-swarm.js +1173 -0
- package/dist/labs/interactive-swarm.js.map +1 -0
- package/dist/labs/interactive.d.ts +10 -0
- package/dist/labs/interactive.js +2099 -0
- package/dist/labs/interactive.js.map +1 -0
- package/dist/labs/ts-analyzer.d.ts +74 -0
- package/dist/labs/ts-analyzer.js +379 -0
- package/dist/labs/ts-analyzer.js.map +1 -0
- package/dist/labs/viewer.d.ts +12 -0
- package/dist/labs/viewer.js +1284 -0
- package/dist/labs/viewer.js.map +1 -0
- package/dist/main.d.ts +15 -0
- package/dist/main.js +247 -0
- package/dist/main.js.map +1 -0
- package/dist/mcp/server.d.ts +16 -0
- package/dist/mcp/server.js +192775 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/session.d.ts +117 -0
- package/dist/mcp/session.js +450 -0
- package/dist/mcp/session.js.map +1 -0
- package/dist/mcp/state.d.ts +42 -0
- package/dist/mcp/state.js +537 -0
- package/dist/mcp/state.js.map +1 -0
- package/dist/mcp/tools/contextos.d.ts +17 -0
- package/dist/mcp/tools/contextos.js +583 -0
- package/dist/mcp/tools/contextos.js.map +1 -0
- package/dist/mcp/tools.d.ts +15 -0
- package/dist/mcp/tools.js +393 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/orchestration/reviewer-gate.d.ts +43 -0
- package/dist/orchestration/reviewer-gate.js +280 -0
- package/dist/orchestration/reviewer-gate.js.map +1 -0
- package/dist/orchestration/reviewer-prompt.d.ts +18 -0
- package/dist/orchestration/reviewer-prompt.js +67 -0
- package/dist/orchestration/reviewer-prompt.js.map +1 -0
- package/dist/orchestration/verification-runner.d.ts +53 -0
- package/dist/orchestration/verification-runner.js +352 -0
- package/dist/orchestration/verification-runner.js.map +1 -0
- package/dist/plugins/adapter.d.ts +11 -0
- package/dist/plugins/adapter.js +11 -0
- package/dist/plugins/adapter.js.map +1 -0
- package/dist/plugins/core/archive.d.ts +9 -0
- package/dist/plugins/core/archive.js +128 -0
- package/dist/plugins/core/archive.js.map +1 -0
- package/dist/plugins/core/digest.d.ts +11 -0
- package/dist/plugins/core/digest.js +70 -0
- package/dist/plugins/core/digest.js.map +1 -0
- package/dist/plugins/core/grants.d.ts +22 -0
- package/dist/plugins/core/grants.js +90 -0
- package/dist/plugins/core/grants.js.map +1 -0
- package/dist/plugins/core/index.d.ts +10 -0
- package/dist/plugins/core/index.js +11 -0
- package/dist/plugins/core/index.js.map +1 -0
- package/dist/plugins/core/pinning.d.ts +15 -0
- package/dist/plugins/core/pinning.js +86 -0
- package/dist/plugins/core/pinning.js.map +1 -0
- package/dist/plugins/core/types.d.ts +105 -0
- package/dist/plugins/core/types.js +22 -0
- package/dist/plugins/core/types.js.map +1 -0
- package/dist/plugins/core/updater.d.ts +16 -0
- package/dist/plugins/core/updater.js +64 -0
- package/dist/plugins/core/updater.js.map +1 -0
- package/dist/plugins/loader.d.ts +65 -0
- package/dist/plugins/loader.js +110 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/prompts/orchestrator.d.ts +6 -0
- package/dist/prompts/orchestrator.js +114 -0
- package/dist/prompts/orchestrator.js.map +1 -0
- package/dist/routing/model-resolver.d.ts +27 -0
- package/dist/routing/model-resolver.js +265 -0
- package/dist/routing/model-resolver.js.map +1 -0
- package/dist/routing/model-router.d.ts +130 -0
- package/dist/routing/model-router.js +515 -0
- package/dist/routing/model-router.js.map +1 -0
- package/dist/runtime/attestations.cjs +260 -0
- package/dist/runtime/reviewer-pipeline.cjs +319 -0
- package/dist/runtime/sandbox.cjs +468 -0
- package/dist/runtime/state-machine.cjs +885 -0
- package/dist/runtime/thread-store.cjs +175 -0
- package/dist/runtime/transactional-git.cjs +315 -0
- package/dist/runtime/verification-pipeline.cjs +435 -0
- package/dist/sandbox/execution.d.ts +165 -0
- package/dist/sandbox/execution.js +497 -0
- package/dist/sandbox/execution.js.map +1 -0
- package/dist/security/file-policy.d.ts +22 -0
- package/dist/security/file-policy.js +53 -0
- package/dist/security/file-policy.js.map +1 -0
- package/dist/security/repository-boundary.d.ts +21 -0
- package/dist/security/repository-boundary.js +119 -0
- package/dist/security/repository-boundary.js.map +1 -0
- package/dist/security/secret-filter.d.ts +36 -0
- package/dist/security/secret-filter.js +149 -0
- package/dist/security/secret-filter.js.map +1 -0
- package/dist/swarm.d.ts +14 -0
- package/dist/swarm.js +624 -0
- package/dist/swarm.js.map +1 -0
- package/dist/threads/cache.d.ts +64 -0
- package/dist/threads/cache.js +241 -0
- package/dist/threads/cache.js.map +1 -0
- package/dist/threads/manager.d.ts +94 -0
- package/dist/threads/manager.js +914 -0
- package/dist/threads/manager.js.map +1 -0
- package/dist/ui/banner.d.ts +14 -0
- package/dist/ui/banner.js +42 -0
- package/dist/ui/banner.js.map +1 -0
- package/dist/ui/dashboard.d.ts +33 -0
- package/dist/ui/dashboard.js +135 -0
- package/dist/ui/dashboard.js.map +1 -0
- package/dist/ui/index.d.ts +11 -0
- package/dist/ui/index.js +12 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/log.d.ts +39 -0
- package/dist/ui/log.js +126 -0
- package/dist/ui/log.js.map +1 -0
- package/dist/ui/onboarding.d.ts +14 -0
- package/dist/ui/onboarding.js +755 -0
- package/dist/ui/onboarding.js.map +1 -0
- package/dist/ui/run-log.d.ts +50 -0
- package/dist/ui/run-log.js +60 -0
- package/dist/ui/run-log.js.map +1 -0
- package/dist/ui/spinner.d.ts +41 -0
- package/dist/ui/spinner.js +172 -0
- package/dist/ui/spinner.js.map +1 -0
- package/dist/ui/streaming-feed.d.ts +72 -0
- package/dist/ui/streaming-feed.js +386 -0
- package/dist/ui/streaming-feed.js.map +1 -0
- package/dist/ui/summary.d.ts +18 -0
- package/dist/ui/summary.js +113 -0
- package/dist/ui/summary.js.map +1 -0
- package/dist/ui/text-input.d.ts +19 -0
- package/dist/ui/text-input.js +266 -0
- package/dist/ui/text-input.js.map +1 -0
- package/dist/ui/theme.d.ts +63 -0
- package/dist/ui/theme.js +97 -0
- package/dist/ui/theme.js.map +1 -0
- package/dist/utils/command-exists.d.ts +11 -0
- package/dist/utils/command-exists.js +41 -0
- package/dist/utils/command-exists.js.map +1 -0
- package/dist/utils/process-security.d.ts +19 -0
- package/dist/utils/process-security.js +90 -0
- package/dist/utils/process-security.js.map +1 -0
- package/dist/utils/rolling-buffer.d.ts +16 -0
- package/dist/utils/rolling-buffer.js +30 -0
- package/dist/utils/rolling-buffer.js.map +1 -0
- package/dist/utils/safe-spawn.d.ts +13 -0
- package/dist/utils/safe-spawn.js +49 -0
- package/dist/utils/safe-spawn.js.map +1 -0
- package/dist/worktree/manager.d.ts +69 -0
- package/dist/worktree/manager.js +593 -0
- package/dist/worktree/manager.js.map +1 -0
- package/dist/worktree/merge.d.ts +58 -0
- package/dist/worktree/merge.js +389 -0
- package/dist/worktree/merge.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type definitions for swarm-code.
|
|
3
|
+
*/
|
|
4
|
+
/** Token usage reported by the agent (when available). */
|
|
5
|
+
export interface TokenUsage {
|
|
6
|
+
inputTokens: number;
|
|
7
|
+
outputTokens: number;
|
|
8
|
+
totalTokens: number;
|
|
9
|
+
}
|
|
10
|
+
export interface AgentResult {
|
|
11
|
+
success: boolean;
|
|
12
|
+
output: string;
|
|
13
|
+
filesChanged: string[];
|
|
14
|
+
diff: string;
|
|
15
|
+
durationMs: number;
|
|
16
|
+
error?: string;
|
|
17
|
+
/** Actual token usage from the agent (if reported). */
|
|
18
|
+
usage?: TokenUsage;
|
|
19
|
+
}
|
|
20
|
+
export interface AgentRunOptions {
|
|
21
|
+
task: string;
|
|
22
|
+
workDir: string;
|
|
23
|
+
model?: string;
|
|
24
|
+
files?: string[];
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
onOutput?: (chunk: string) => void;
|
|
27
|
+
}
|
|
28
|
+
export interface AgentProvider {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly isAvailable: () => Promise<boolean>;
|
|
31
|
+
run(options: AgentRunOptions): Promise<AgentResult>;
|
|
32
|
+
}
|
|
33
|
+
export type ThreadStatus = "pending" | "running" | "completed" | "failed" | "cancelled" | "verification_failed" | "interrupted" | "needs_recovery" | "requires_verification" | "requires_review" | "ready_for_merge";
|
|
34
|
+
export type ThreadProgressPhase = "queued" | "creating_worktree" | "agent_running" | "verifying" | "reviewing" | "capturing_diff" | "compressing" | "completed" | "failed" | "verification_failed" | "cancelled" | "retrying" | "interrupted" | "needs_recovery";
|
|
35
|
+
export interface WorktreeSessionMarker {
|
|
36
|
+
schemaVersion: 1;
|
|
37
|
+
sessionId: string;
|
|
38
|
+
repositoryFingerprint: string;
|
|
39
|
+
worktreePath: string;
|
|
40
|
+
branchName: string;
|
|
41
|
+
threadId: string;
|
|
42
|
+
ownerToken: string;
|
|
43
|
+
createdAt: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ThreadConfig {
|
|
46
|
+
id: string;
|
|
47
|
+
task: string;
|
|
48
|
+
context: string;
|
|
49
|
+
agent: {
|
|
50
|
+
backend: string;
|
|
51
|
+
model: string;
|
|
52
|
+
};
|
|
53
|
+
files?: string[];
|
|
54
|
+
focusFiles?: string[];
|
|
55
|
+
writeScope?: readonly string[];
|
|
56
|
+
writeScopeDeny?: readonly string[];
|
|
57
|
+
allowRepositoryWide?: boolean;
|
|
58
|
+
testCommand?: string;
|
|
59
|
+
verificationSpec?: VerificationSpec;
|
|
60
|
+
taskBrief?: TaskBrief;
|
|
61
|
+
sandboxMode?: "oci-required" | "oci-preferred" | "host-unsafe";
|
|
62
|
+
}
|
|
63
|
+
/** Structured specification for automated verification (Section 16.1). */
|
|
64
|
+
export interface VerificationSpec {
|
|
65
|
+
readonly schemaVersion?: number;
|
|
66
|
+
readonly executable: string;
|
|
67
|
+
readonly args: readonly string[];
|
|
68
|
+
readonly timeoutMs?: number;
|
|
69
|
+
readonly required?: boolean;
|
|
70
|
+
readonly network?: "deny" | "allow";
|
|
71
|
+
readonly allowedOutputPaths?: readonly string[];
|
|
72
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
73
|
+
readonly cwd?: string;
|
|
74
|
+
readonly trusted?: boolean;
|
|
75
|
+
readonly isLegacyString?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/** Immutable execution contract supplied to every subagent. */
|
|
78
|
+
export interface TaskBrief {
|
|
79
|
+
readonly taskId: string;
|
|
80
|
+
readonly baseSha: string;
|
|
81
|
+
readonly objective: string;
|
|
82
|
+
readonly writeScope: readonly string[];
|
|
83
|
+
readonly writeScopeDeny?: readonly string[];
|
|
84
|
+
readonly allowRepositoryWide?: boolean;
|
|
85
|
+
readonly focusFiles?: readonly string[];
|
|
86
|
+
readonly testCommand: string;
|
|
87
|
+
readonly verificationSpec?: VerificationSpec;
|
|
88
|
+
readonly expectedResult: string;
|
|
89
|
+
readonly maxAttempts: number;
|
|
90
|
+
readonly sandboxMode?: "oci-required" | "oci-preferred" | "host-unsafe";
|
|
91
|
+
}
|
|
92
|
+
export type VerificationVerdict = VerificationStatus | "CANCELLED";
|
|
93
|
+
export type ReviewVerdictValue = ReviewStatus;
|
|
94
|
+
export type ExecutionStatus = "QUEUED" | "PREPARING" | "RUNNING" | "SUCCEEDED" | "FAILED" | "TIMED_OUT" | "CANCELLED" | "INTERRUPTED";
|
|
95
|
+
export type VerificationStatus = "NOT_CONFIGURED" | "NOT_APPLICABLE" | "PENDING" | "RUNNING" | "PASS" | "FAIL" | "ERROR" | "TIMEOUT" | "UNAVAILABLE" | "MALFORMED" | "STALE";
|
|
96
|
+
export type ReviewStatus = "NOT_CONFIGURED" | "PENDING" | "RUNNING" | "PASS" | "FAIL" | "ERROR" | "TIMEOUT" | "UNAVAILABLE" | "MALFORMED" | "STALE";
|
|
97
|
+
export type MergeStatus = "NOT_READY" | "READY" | "MERGING" | "MERGED" | "BLOCKED" | "CONFLICT" | "STALE_BASE" | "ERROR";
|
|
98
|
+
export interface VerificationAttestation {
|
|
99
|
+
schemaVersion: 1;
|
|
100
|
+
status: VerificationStatus;
|
|
101
|
+
subject: {
|
|
102
|
+
repositoryFingerprint: string;
|
|
103
|
+
baseSha: string;
|
|
104
|
+
headSha: string;
|
|
105
|
+
diffSha256: string;
|
|
106
|
+
scopeSha256: string;
|
|
107
|
+
};
|
|
108
|
+
command?: {
|
|
109
|
+
executable: string;
|
|
110
|
+
args: string[];
|
|
111
|
+
cwd: string;
|
|
112
|
+
timeoutMs: number;
|
|
113
|
+
};
|
|
114
|
+
evidence?: {
|
|
115
|
+
exitCode: number | null;
|
|
116
|
+
signal: string | null;
|
|
117
|
+
outputSha256: string;
|
|
118
|
+
redactedPreview: string;
|
|
119
|
+
totalTests?: number;
|
|
120
|
+
passedTests?: number;
|
|
121
|
+
failedTests?: number;
|
|
122
|
+
};
|
|
123
|
+
runnerMode: "oci" | "host-unsafe";
|
|
124
|
+
startedAt?: number;
|
|
125
|
+
completedAt?: number;
|
|
126
|
+
reasonCode?: string;
|
|
127
|
+
}
|
|
128
|
+
export interface ReviewAttestation {
|
|
129
|
+
schemaVersion: 1;
|
|
130
|
+
status: ReviewStatus;
|
|
131
|
+
subject: {
|
|
132
|
+
repositoryFingerprint: string;
|
|
133
|
+
baseSha: string;
|
|
134
|
+
headSha: string;
|
|
135
|
+
diffSha256: string;
|
|
136
|
+
scopeSha256: string;
|
|
137
|
+
};
|
|
138
|
+
implementerExecutionId: string;
|
|
139
|
+
reviewerExecutionId: string;
|
|
140
|
+
provider: string;
|
|
141
|
+
model: string;
|
|
142
|
+
independenceLevel: "same_process" | "separate_process" | "isolated_container" | "external_evaluator";
|
|
143
|
+
rawOutputDigest: string;
|
|
144
|
+
staticFindings?: Array<{
|
|
145
|
+
ruleId: string;
|
|
146
|
+
severity: string;
|
|
147
|
+
message: string;
|
|
148
|
+
file?: string;
|
|
149
|
+
line?: number;
|
|
150
|
+
}>;
|
|
151
|
+
llmVerdict?: {
|
|
152
|
+
specCompliance: string;
|
|
153
|
+
codeQuality: string;
|
|
154
|
+
summary: string;
|
|
155
|
+
};
|
|
156
|
+
retries: number;
|
|
157
|
+
startedAt?: number;
|
|
158
|
+
completedAt?: number;
|
|
159
|
+
}
|
|
160
|
+
export interface ReviewVerdict {
|
|
161
|
+
readonly reviewerId: string;
|
|
162
|
+
readonly specCompliance: ReviewVerdictValue;
|
|
163
|
+
readonly codeQuality: ReviewVerdictValue;
|
|
164
|
+
readonly summary: string;
|
|
165
|
+
readonly reviewedAt: number;
|
|
166
|
+
}
|
|
167
|
+
export interface ThreadState {
|
|
168
|
+
id: string;
|
|
169
|
+
config: ThreadConfig;
|
|
170
|
+
status: ThreadStatus;
|
|
171
|
+
phase: ThreadProgressPhase;
|
|
172
|
+
worktreePath?: string;
|
|
173
|
+
branchName?: string;
|
|
174
|
+
result?: CompressedResult;
|
|
175
|
+
startedAt?: number;
|
|
176
|
+
completedAt?: number;
|
|
177
|
+
error?: string;
|
|
178
|
+
attempt: number;
|
|
179
|
+
maxAttempts: number;
|
|
180
|
+
estimatedCostUsd: number;
|
|
181
|
+
taskBrief?: TaskBrief;
|
|
182
|
+
verification?: VerificationVerdict;
|
|
183
|
+
review?: ReviewVerdict;
|
|
184
|
+
scopeViolation?: boolean;
|
|
185
|
+
revision?: number;
|
|
186
|
+
executionStatus?: ExecutionStatus;
|
|
187
|
+
verificationStatus?: VerificationStatus;
|
|
188
|
+
reviewStatus?: ReviewStatus;
|
|
189
|
+
mergeStatus?: MergeStatus;
|
|
190
|
+
verificationAttestation?: VerificationAttestation;
|
|
191
|
+
reviewAttestation?: ReviewAttestation;
|
|
192
|
+
}
|
|
193
|
+
export interface CompressedResult {
|
|
194
|
+
success: boolean;
|
|
195
|
+
summary: string;
|
|
196
|
+
filesChanged: string[];
|
|
197
|
+
diffStats: string;
|
|
198
|
+
durationMs: number;
|
|
199
|
+
estimatedCostUsd: number;
|
|
200
|
+
/** Actual token usage (when available from agent). */
|
|
201
|
+
usage?: TokenUsage;
|
|
202
|
+
/** Whether cost is based on real usage or estimates. */
|
|
203
|
+
costIsEstimate?: boolean;
|
|
204
|
+
}
|
|
205
|
+
export interface WorktreeInfo {
|
|
206
|
+
id: string;
|
|
207
|
+
path: string;
|
|
208
|
+
branch: string;
|
|
209
|
+
}
|
|
210
|
+
export interface MergeResult {
|
|
211
|
+
success: boolean;
|
|
212
|
+
branch: string;
|
|
213
|
+
conflicts: string[];
|
|
214
|
+
conflictDiff: string;
|
|
215
|
+
message: string;
|
|
216
|
+
}
|
|
217
|
+
export interface BudgetState {
|
|
218
|
+
totalSpentUsd: number;
|
|
219
|
+
totalReservedUsd?: number;
|
|
220
|
+
threadCosts: Map<string, number>;
|
|
221
|
+
sessionLimitUsd: number;
|
|
222
|
+
perThreadLimitUsd: number;
|
|
223
|
+
/** Total tokens consumed across all threads. */
|
|
224
|
+
totalTokens: {
|
|
225
|
+
input: number;
|
|
226
|
+
output: number;
|
|
227
|
+
};
|
|
228
|
+
/** Number of threads with actual (non-estimated) cost data. */
|
|
229
|
+
actualCostThreads: number;
|
|
230
|
+
/** Number of threads with estimated cost data. */
|
|
231
|
+
estimatedCostThreads: number;
|
|
232
|
+
}
|
|
233
|
+
/** Rough per-1M-token pricing for cost estimation. */
|
|
234
|
+
export declare const MODEL_PRICING: Record<string, {
|
|
235
|
+
input: number;
|
|
236
|
+
output: number;
|
|
237
|
+
}>;
|
|
238
|
+
export type { ModelSlots, SwarmConfig } from "../config.js";
|
|
239
|
+
export interface ThreadRequestMessage {
|
|
240
|
+
type: "thread_request";
|
|
241
|
+
id: string;
|
|
242
|
+
task: string;
|
|
243
|
+
context: string;
|
|
244
|
+
agent_backend: string;
|
|
245
|
+
model: string;
|
|
246
|
+
files: string[];
|
|
247
|
+
}
|
|
248
|
+
export interface ThreadResultMessage {
|
|
249
|
+
type: "thread_result";
|
|
250
|
+
id: string;
|
|
251
|
+
result: string;
|
|
252
|
+
success: boolean;
|
|
253
|
+
files_changed: string[];
|
|
254
|
+
duration_ms: number;
|
|
255
|
+
}
|
|
256
|
+
export interface MergeRequestMessage {
|
|
257
|
+
type: "merge_request";
|
|
258
|
+
id: string;
|
|
259
|
+
}
|
|
260
|
+
export interface MergeResultMessage {
|
|
261
|
+
type: "merge_result";
|
|
262
|
+
id: string;
|
|
263
|
+
result: string;
|
|
264
|
+
success: boolean;
|
|
265
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type definitions for swarm-code.
|
|
3
|
+
*/
|
|
4
|
+
/** Rough per-1M-token pricing for cost estimation. */
|
|
5
|
+
export const MODEL_PRICING = {
|
|
6
|
+
// Anthropic
|
|
7
|
+
"claude-sonnet-4-6": { input: 3, output: 15 },
|
|
8
|
+
"claude-opus-4-6": { input: 15, output: 75 },
|
|
9
|
+
"claude-haiku-4-5": { input: 0.8, output: 4 },
|
|
10
|
+
// OpenAI
|
|
11
|
+
"gpt-4o": { input: 2.5, output: 10 },
|
|
12
|
+
"gpt-4o-mini": { input: 0.15, output: 0.6 },
|
|
13
|
+
o3: { input: 10, output: 40 },
|
|
14
|
+
"o3-mini": { input: 1.1, output: 4.4 },
|
|
15
|
+
// Google
|
|
16
|
+
"gemini-2.5-pro": { input: 1.25, output: 10 },
|
|
17
|
+
"gemini-2.5-flash": { input: 0.15, output: 0.6 },
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgUH,sDAAsD;AACtD,MAAM,CAAC,MAAM,aAAa,GAAsD;IAC/E,YAAY;IACZ,mBAAmB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;IAC7C,iBAAiB,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IAC5C,kBAAkB,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE;IAC7C,SAAS;IACT,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE;IACpC,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE;IAC3C,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IAC7B,SAAS,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IACtC,SAAS;IACT,gBAAgB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;IAC7C,kBAAkB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE;CAChD,CAAC"}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load env vars into process.env.
|
|
3
|
+
* Must be imported BEFORE any module that reads env vars (e.g. pi-ai).
|
|
4
|
+
*
|
|
5
|
+
* Priority (highest wins):
|
|
6
|
+
* 1. Shell environment variables (already in process.env)
|
|
7
|
+
* 2. .env in package root
|
|
8
|
+
* 3. ~/.rlm/credentials — persistent keys saved by first-run setup
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load env vars into process.env.
|
|
3
|
+
* Must be imported BEFORE any module that reads env vars (e.g. pi-ai).
|
|
4
|
+
*
|
|
5
|
+
* Priority (highest wins):
|
|
6
|
+
* 1. Shell environment variables (already in process.env)
|
|
7
|
+
* 2. .env in package root
|
|
8
|
+
* 3. ~/.rlm/credentials — persistent keys saved by first-run setup
|
|
9
|
+
*/
|
|
10
|
+
import * as fs from "node:fs";
|
|
11
|
+
import * as os from "node:os";
|
|
12
|
+
import * as path from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
function parseEnvFile(filePath) {
|
|
15
|
+
const vars = new Map();
|
|
16
|
+
if (!fs.existsSync(filePath))
|
|
17
|
+
return vars;
|
|
18
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
19
|
+
for (const rawLine of content.split("\n")) {
|
|
20
|
+
let trimmed = rawLine.trim();
|
|
21
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
22
|
+
continue;
|
|
23
|
+
// Strip leading "export " (common in .env files)
|
|
24
|
+
if (trimmed.startsWith("export "))
|
|
25
|
+
trimmed = trimmed.slice(7);
|
|
26
|
+
const eqIndex = trimmed.indexOf("=");
|
|
27
|
+
if (eqIndex === -1)
|
|
28
|
+
continue;
|
|
29
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
30
|
+
let value = trimmed.slice(eqIndex + 1).trim();
|
|
31
|
+
// Strip matching surrounding quotes ("..." or '...')
|
|
32
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
33
|
+
value = value.slice(1, -1);
|
|
34
|
+
}
|
|
35
|
+
if (key)
|
|
36
|
+
vars.set(key, value);
|
|
37
|
+
}
|
|
38
|
+
return vars;
|
|
39
|
+
}
|
|
40
|
+
// Collect file-based vars: credentials first, .env overwrites
|
|
41
|
+
const fileVars = new Map();
|
|
42
|
+
// 1. Load persistent credentials (lowest priority file)
|
|
43
|
+
// Check both swarm and rlm credential locations
|
|
44
|
+
const credVars = parseEnvFile(path.join(os.homedir(), ".swarm", "credentials"));
|
|
45
|
+
const rlmCreds = parseEnvFile(path.join(os.homedir(), ".rlm", "credentials"));
|
|
46
|
+
for (const [k, v] of rlmCreds) {
|
|
47
|
+
if (!credVars.has(k))
|
|
48
|
+
credVars.set(k, v);
|
|
49
|
+
}
|
|
50
|
+
for (const [k, v] of credVars)
|
|
51
|
+
fileVars.set(k, v);
|
|
52
|
+
// 2. Load .env from package root (overwrites credentials)
|
|
53
|
+
const __dir = path.dirname(fileURLToPath(import.meta.url));
|
|
54
|
+
const dotenvVars = parseEnvFile(path.resolve(__dir, "..", ".env"));
|
|
55
|
+
for (const [k, v] of dotenvVars)
|
|
56
|
+
fileVars.set(k, v);
|
|
57
|
+
// 3. Apply: only set if NOT already in shell env (shell always wins)
|
|
58
|
+
for (const [key, value] of fileVars) {
|
|
59
|
+
if (!process.env[key]) {
|
|
60
|
+
process.env[key] = value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Alias: GOOGLE_API_KEY → GEMINI_API_KEY (pi-ai expects GEMINI_API_KEY)
|
|
64
|
+
// Remove GOOGLE_API_KEY after aliasing to avoid pi-ai "both set" warning
|
|
65
|
+
if (process.env.GOOGLE_API_KEY) {
|
|
66
|
+
if (!process.env.GEMINI_API_KEY) {
|
|
67
|
+
process.env.GEMINI_API_KEY = process.env.GOOGLE_API_KEY;
|
|
68
|
+
}
|
|
69
|
+
delete process.env.GOOGLE_API_KEY;
|
|
70
|
+
}
|
|
71
|
+
// Default model
|
|
72
|
+
if (!process.env.RLM_MODEL) {
|
|
73
|
+
process.env.RLM_MODEL = "claude-sonn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AAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC3D,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AACnE,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,UAAU;IAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEpD,qEAAqE;AACrE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,QAAQ,EAAE,CAAC;IACrC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC1B,CAAC;AACF,CAAC;AAED,wEAAwE;AACxE,yEAAyE;AACzE,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;IAChC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IACzD,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;AACnC,CAAC;AAED,gBAAgB;AAChB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;IAC5B,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,mBAAmB,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook runner — executes user-defined commands at lifecycle points.
|
|
3
|
+
*
|
|
4
|
+
* Hooks provide deterministic control flow (not LLM-decided).
|
|
5
|
+
* They run shell commands and surface only errors — success is silent.
|
|
6
|
+
*
|
|
7
|
+
* Lifecycle points:
|
|
8
|
+
* - post_thread: After a thread commits (before compression)
|
|
9
|
+
* - post_merge: After merge_threads() completes
|
|
10
|
+
* - post_session: When the session ends
|
|
11
|
+
*/
|
|
12
|
+
export interface HookConfig {
|
|
13
|
+
command: string;
|
|
14
|
+
on_failure: "warn" | "block";
|
|
15
|
+
}
|
|
16
|
+
export interface HooksConfig {
|
|
17
|
+
post_thread: HookConfig[];
|
|
18
|
+
post_merge: HookConfig[];
|
|
19
|
+
post_session: HookConfig[];
|
|
20
|
+
}
|
|
21
|
+
export interface HookResult {
|
|
22
|
+
success: boolean;
|
|
23
|
+
output: string;
|
|
24
|
+
command: string;
|
|
25
|
+
}
|
|
26
|
+
export interface LoadHooksOptions {
|
|
27
|
+
allow_hooks?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface RunHooksOptions {
|
|
30
|
+
allow_hooks?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Load hooks from .swarm/hooks.yaml or .agents/hooks.json.
|
|
34
|
+
* If hook files exist and allow_hooks is false (default), execution is blocked
|
|
35
|
+
* and a structured warning is emitted.
|
|
36
|
+
*/
|
|
37
|
+
export declare function loadHooks(projectDir: string, allowHooksOrOptions?: boolean | LoadHooksOptions): HooksConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Run hooks for a lifecycle point.
|
|
40
|
+
* Returns results for each hook. On "block" failure, throws.
|
|
41
|
+
* Success output is swallowed — only errors are surfaced.
|
|
42
|
+
*/
|
|
43
|
+
export declare function runHooks(hooks: HookConfig[], cwd: string, label: string, allowHooksOrOptions?: boolean | RunHooksOptions): HookResult[];
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook runner — executes user-defined commands at lifecycle points.
|
|
3
|
+
*
|
|
4
|
+
* Hooks provide deterministic control flow (not LLM-decided).
|
|
5
|
+
* They run shell commands and surface only errors — success is silent.
|
|
6
|
+
*
|
|
7
|
+
* Lifecycle points:
|
|
8
|
+
* - post_thread: After a thread commits (before compression)
|
|
9
|
+
* - post_merge: After merge_threads() completes
|
|
10
|
+
* - post_session: When the session ends
|
|
11
|
+
*/
|
|
12
|
+
import { execSync } from "node:child_process";
|
|
13
|
+
import * as fs from "node:fs";
|
|
14
|
+
import * as path from "node:path";
|
|
15
|
+
const DEFAULT_HOOKS = {
|
|
16
|
+
post_thread: [],
|
|
17
|
+
post_merge: [],
|
|
18
|
+
post_session: [],
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Load hooks from .swarm/hooks.yaml or .agents/hooks.json.
|
|
22
|
+
* If hook files exist and allow_hooks is false (default), execution is blocked
|
|
23
|
+
* and a structured warning is emitted.
|
|
24
|
+
*/
|
|
25
|
+
export function loadHooks(projectDir, allowHooksOrOptions = false) {
|
|
26
|
+
const allowHooks = typeof allowHooksOrOptions === "boolean" ? allowHooksOrOptions : Boolean(allowHooksOrOptions?.allow_hooks);
|
|
27
|
+
const swarmHooksFile = path.join(projectDir, ".swarm", "hooks.yaml");
|
|
28
|
+
const agentsHooksFile = path.join(projectDir, ".agents", "hooks.json");
|
|
29
|
+
const hasSwarmHooks = fs.existsSync(swarmHooksFile);
|
|
30
|
+
const hasAgentsHooks = fs.existsSync(agentsHooksFile);
|
|
31
|
+
if (!hasSwarmHooks && !hasAgentsHooks) {
|
|
32
|
+
return { ...DEFAULT_HOOKS };
|
|
33
|
+
}
|
|
34
|
+
if (!allowHooks) {
|
|
35
|
+
console.warn("[hooks] Hooks execution is disabled by default. Pass --allow-hooks or set allow_hooks: true in config to enable.");
|
|
36
|
+
return { ...DEFAULT_HOOKS };
|
|
37
|
+
}
|
|
38
|
+
const hooks = { post_thread: [], post_merge: [], post_session: [] };
|
|
39
|
+
if (hasSwarmHooks) {
|
|
40
|
+
try {
|
|
41
|
+
const raw = fs.readFileSync(swarmHooksFile, "utf-8");
|
|
42
|
+
const parsed = parseHooksYaml(raw);
|
|
43
|
+
hooks.post_thread.push(...parsed.post_thread);
|
|
44
|
+
hooks.post_merge.push(...parsed.post_merge);
|
|
45
|
+
hooks.post_session.push(...parsed.post_session);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// ignore malformed file
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (hasAgentsHooks) {
|
|
52
|
+
try {
|
|
53
|
+
const raw = fs.readFileSync(agentsHooksFile, "utf-8");
|
|
54
|
+
const parsed = parseHooksJson(raw);
|
|
55
|
+
hooks.post_thread.push(...parsed.post_thread);
|
|
56
|
+
hooks.post_merge.push(...parsed.post_merge);
|
|
57
|
+
hooks.post_session.push(...parsed.post_session);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// ignore malformed file
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return hooks;
|
|
64
|
+
}
|
|
65
|
+
function parseHooksJson(raw) {
|
|
66
|
+
const hooks = { post_thread: [], post_merge: [], post_session: [] };
|
|
67
|
+
try {
|
|
68
|
+
const parsed = JSON.parse(raw);
|
|
69
|
+
const target = parsed?.hooks && typeof parsed.hooks === "object" ? parsed.hooks : parsed;
|
|
70
|
+
const sections = ["post_thread", "post_merge", "post_session"];
|
|
71
|
+
for (const section of sections) {
|
|
72
|
+
const list = target[section];
|
|
73
|
+
if (!Array.isArray(list))
|
|
74
|
+
continue;
|
|
75
|
+
for (const item of list) {
|
|
76
|
+
if (typeof item === "string" && item.trim()) {
|
|
77
|
+
hooks[section].push({ command: item.trim(), on_failure: "warn" });
|
|
78
|
+
}
|
|
79
|
+
else if (item && typeof item === "object" && typeof item.command === "string") {
|
|
80
|
+
hooks[section].push({
|
|
81
|
+
command: item.command.trim(),
|
|
82
|
+
on_failure: item.on_failure === "block" ? "block" : "warn",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (Array.isArray(target)) {
|
|
88
|
+
for (const item of target) {
|
|
89
|
+
if (item && typeof item === "object" && typeof item.command === "string" && typeof item.event === "string") {
|
|
90
|
+
if (item.event === "post_thread" || item.event === "post_merge" || item.event === "post_session") {
|
|
91
|
+
hooks[item.event].push({
|
|
92
|
+
command: item.command.trim(),
|
|
93
|
+
on_failure: item.on_failure === "block" ? "block" : "warn",
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// return empty on invalid JSON
|
|
102
|
+
}
|
|
103
|
+
return hooks;
|
|
104
|
+
}
|
|
105
|
+
function parseHooksYaml(raw) {
|
|
106
|
+
const hooks = { post_thread: [], post_merge: [], post_session: [] };
|
|
107
|
+
let currentSection = null;
|
|
108
|
+
for (const line of raw.split("\n")) {
|
|
109
|
+
const trimmed = line.trim();
|
|
110
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
111
|
+
continue;
|
|
112
|
+
if (trimmed === "post_thread:" || trimmed === "post_merge:" || trimmed === "post_session:") {
|
|
113
|
+
currentSection = trimmed.replace(":", "");
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (currentSection && trimmed.startsWith("- command:")) {
|
|
117
|
+
let command = trimmed.replace("- command:", "").trim();
|
|
118
|
+
if ((command.startsWith('"') && command.endsWith('"')) || (command.startsWith("'") && command.endsWith("'"))) {
|
|
119
|
+
command = command.slice(1, -1);
|
|
120
|
+
}
|
|
121
|
+
if (command) {
|
|
122
|
+
hooks[currentSection].push({ command, on_failure: "warn" });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (currentSection && trimmed.startsWith("on_failure:")) {
|
|
126
|
+
const val = trimmed.replace("on_failure:", "").trim();
|
|
127
|
+
const last = hooks[currentSection][hooks[currentSection].length - 1];
|
|
128
|
+
if (last && (val === "warn" || val === "block")) {
|
|
129
|
+
last.on_failure = val;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return hooks;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Run hooks for a lifecycle point.
|
|
137
|
+
* Returns results for each hook. On "block" failure, throws.
|
|
138
|
+
* Success output is swallowed — only errors are surfaced.
|
|
139
|
+
*/
|
|
140
|
+
export function runHooks(hooks, cwd, label, allowHooksOrOptions = true) {
|
|
141
|
+
if (!hooks || hooks.length === 0) {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
const allowHooks = typeof allowHooksOrOptions === "boolean" ? allowHooksOrOptions : (allowHooksOrOptions?.allow_hooks ?? true);
|
|
145
|
+
if (!allowHooks) {
|
|
146
|
+
console.warn(`[hooks] Hooks execution is disabled. Skipping ${label} hooks.`);
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
const results = [];
|
|
150
|
+
for (const hook of hooks) {
|
|
151
|
+
try {
|
|
152
|
+
execSync(hook.command, {
|
|
153
|
+
cwd,
|
|
154
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
155
|
+
timeout: 60_000,
|
|
156
|
+
encoding: "utf-8",
|
|
157
|
+
});
|
|
158
|
+
// Success — silent (context-efficient per harness engineering best practice)
|
|
159
|
+
results.push({ success: true, output: "", command: hook.command });
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
const stderr = err.stderr || err.stdout || err.message || "unknown error";
|
|
163
|
+
// Only surface error output
|
|
164
|
+
const output = `[${label}] Hook failed: ${hook.command}\n${stderr}`.trim();
|
|
165
|
+
results.push({ success: false, output, command: hook.command });
|
|
166
|
+
if (hook.on_failure === "block") {
|
|
167
|
+
throw new Error(output);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return results;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/hooks/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAA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file large-file.txt "What are the main themes?"
|
|
7
|
+
* npx tsx src/cli.ts --url https://example.com/big.txt "Summarize this"
|
|
8
|
+
* cat data.txt | npx tsx src/cli.ts --stdin "Count the errors"
|
|
9
|
+
*
|
|
10
|
+
* Environment (pick one):
|
|
11
|
+
* ANTHROPIC_API_KEY — for Anthropic models
|
|
12
|
+
* OPENAI_API_KEY — for OpenAI models
|
|
13
|
+
* GEMINI_API_KEY — for Google models
|
|
14
|
+
*/
|
|
15
|
+
import "./env.js";
|