@peakflo/agent-harness 0.0.0-stage → 0.2.1-rc.3
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 +38 -2
- package/dist/adapters/acp-adapter.d.ts +177 -0
- package/dist/adapters/acp-adapter.js +1732 -0
- package/dist/adapters/claude-code-adapter.d.ts +171 -0
- package/dist/adapters/claude-code-adapter.js +1918 -0
- package/dist/adapters/codex-adapter.d.ts +67 -0
- package/dist/adapters/codex-adapter.js +681 -0
- package/dist/adapters/codex-app-server-adapter.d.ts +105 -0
- package/dist/adapters/codex-app-server-adapter.js +1309 -0
- package/dist/adapters/coding-agent-adapter.d.ts +289 -0
- package/dist/adapters/coding-agent-adapter.js +31 -0
- package/dist/adapters/index.d.ts +17 -0
- package/dist/adapters/index.js +35 -0
- package/dist/adapters/model-gateway.d.ts +84 -0
- package/dist/adapters/model-gateway.js +270 -0
- package/dist/adapters/opencode-adapter.d.ts +403 -0
- package/dist/adapters/opencode-adapter.js +2710 -0
- package/dist/adapters/opencode-config.d.ts +41 -0
- package/dist/adapters/opencode-config.js +147 -0
- package/dist/adapters/opencode-server-policy.d.ts +82 -0
- package/dist/adapters/opencode-server-policy.js +148 -0
- package/dist/adapters/pi-adapter.d.ts +168 -0
- package/dist/adapters/pi-adapter.js +1468 -0
- package/dist/capabilities.d.ts +58 -0
- package/dist/capabilities.js +161 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +231 -0
- package/dist/contract.d.ts +273 -0
- package/dist/contract.js +357 -0
- package/dist/control-plane.d.ts +178 -0
- package/dist/control-plane.js +431 -0
- package/dist/credential-store.d.ts +110 -0
- package/dist/credential-store.js +181 -0
- package/dist/enrol/browser-enrol.d.ts +85 -0
- package/dist/enrol/browser-enrol.js +387 -0
- package/dist/github-command-guards.d.ts +20 -0
- package/dist/github-command-guards.js +330 -0
- package/dist/github-proxy-certificates.d.ts +25 -0
- package/dist/github-proxy-certificates.js +145 -0
- package/dist/github-proxy.d.ts +37 -0
- package/dist/github-proxy.js +476 -0
- package/dist/github-workspace.d.ts +55 -0
- package/dist/github-workspace.js +537 -0
- package/dist/harness.d.ts +333 -0
- package/dist/harness.js +1414 -0
- package/dist/health.d.ts +45 -0
- package/dist/health.js +116 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +123 -0
- package/dist/model-probe.d.ts +96 -0
- package/dist/model-probe.js +195 -0
- package/dist/options.d.ts +15 -0
- package/dist/options.js +212 -0
- package/dist/ports-default.d.ts +212 -0
- package/dist/ports-default.js +333 -0
- package/dist/ports.d.ts +436 -0
- package/dist/ports.js +27 -0
- package/dist/runtime/attachments.d.ts +92 -0
- package/dist/runtime/attachments.js +377 -0
- package/dist/runtime/child-stream-guards.d.ts +45 -0
- package/dist/runtime/child-stream-guards.js +111 -0
- package/dist/runtime/conversation.d.ts +87 -0
- package/dist/runtime/conversation.js +156 -0
- package/dist/runtime/lease-renewal.d.ts +169 -0
- package/dist/runtime/lease-renewal.js +433 -0
- package/dist/runtime/mcp-auth-proxy.d.ts +82 -0
- package/dist/runtime/mcp-auth-proxy.js +300 -0
- package/dist/runtime/permission-mode.d.ts +116 -0
- package/dist/runtime/permission-mode.js +146 -0
- package/dist/runtime/projection.d.ts +71 -0
- package/dist/runtime/projection.js +211 -0
- package/dist/runtime/session-runner.d.ts +520 -0
- package/dist/runtime/session-runner.js +2122 -0
- package/dist/shared/reasoning-effort.d.ts +11 -0
- package/dist/shared/reasoning-effort.js +20 -0
- package/dist/store/conversation-store.d.ts +100 -0
- package/dist/store/conversation-store.js +305 -0
- package/dist/store/sqlite-store.d.ts +120 -0
- package/dist/store/sqlite-store.js +346 -0
- package/dist/types.d.ts +952 -0
- package/dist/types.js +55 -0
- package/dist/version.d.ts +32 -0
- package/dist/version.js +77 -0
- package/package.json +53 -4
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code Adapter
|
|
3
|
+
*
|
|
4
|
+
* Implements CodingAgentAdapter for Claude Code using @anthropic-ai/claude-agent-sdk.
|
|
5
|
+
*
|
|
6
|
+
* Key differences from OpenCode:
|
|
7
|
+
* - Uses AsyncGenerator streaming API instead of HTTP client
|
|
8
|
+
* - File-based session persistence (~/.claude/sessions/)
|
|
9
|
+
* - Different message format (SDKMessage vs OpenCode messages)
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Extracted verbatim from 20x `src/main/adapters/claude-code-adapter.ts`.
|
|
13
|
+
* CHANGED: nothing. The only import it has is `./coding-agent-adapter`, which
|
|
14
|
+
* sits in the same directory here too. `@anthropic-ai/claude-agent-sdk` is an
|
|
15
|
+
* optional dependency (dynamically imported) and is declared ambiently in
|
|
16
|
+
* `./optional-agent-sdks.d.ts` so `tsc` succeeds when it is not installed.
|
|
17
|
+
* Source formatting (no semicolons) preserved.
|
|
18
|
+
*/
|
|
19
|
+
import type { CodingAgentAdapter, SessionConfig, SessionStatus, SessionMessage, MessagePart } from './coding-agent-adapter';
|
|
20
|
+
export declare enum ClaudeSystemSubtype {
|
|
21
|
+
INIT = "init",
|
|
22
|
+
TASK_STARTED = "task_started",
|
|
23
|
+
TASK_PROGRESS = "task_progress",
|
|
24
|
+
TASK_NOTIFICATION = "task_notification",
|
|
25
|
+
TASK_UPDATED = "task_updated",
|
|
26
|
+
/** Authoritative in-flight background-task list. Emitted by the CLI but NOT
|
|
27
|
+
* surfaced by SDK >= 0.3.x (absent from the SDKMessage union) — older bundled
|
|
28
|
+
* SDKs (e.g. 0.2.x) do pass it through, so it is handled defensively both as a
|
|
29
|
+
* status source and as a transcript-suppression case. */
|
|
30
|
+
BACKGROUND_TASKS_CHANGED = "background_tasks_changed",
|
|
31
|
+
STATUS = "status",
|
|
32
|
+
THINKING_TOKENS = "thinking_tokens"
|
|
33
|
+
}
|
|
34
|
+
export declare class ClaudeCodeAdapter implements CodingAgentAdapter {
|
|
35
|
+
private sessions;
|
|
36
|
+
private sdkLoading;
|
|
37
|
+
private claudeExecutablePath;
|
|
38
|
+
/**
|
|
39
|
+
* Callback set by agent-manager to trigger an immediate poll cycle
|
|
40
|
+
* when new stream data is buffered. Eliminates the up-to-2-second
|
|
41
|
+
* latency of the fixed-interval polling heartbeat.
|
|
42
|
+
*/
|
|
43
|
+
onDataAvailable?: (sessionId: string) => void;
|
|
44
|
+
constructor();
|
|
45
|
+
/**
|
|
46
|
+
* Find the Claude CLI executable path
|
|
47
|
+
*/
|
|
48
|
+
private findClaudeExecutable;
|
|
49
|
+
/**
|
|
50
|
+
* On Windows, .cmd wrapper files can't be spawned directly by the SDK
|
|
51
|
+
* (no shell: true). Resolve claude.cmd → the underlying cli.js path.
|
|
52
|
+
*/
|
|
53
|
+
private resolveWindowsCmdToJs;
|
|
54
|
+
/**
|
|
55
|
+
* Build environment variables for Claude process
|
|
56
|
+
* Removes CLAUDECODE to prevent nested session errors.
|
|
57
|
+
* When secrets are configured, sets SHELL to the secret-shell.sh wrapper
|
|
58
|
+
* so every bash command fetches secrets from the broker transparently.
|
|
59
|
+
*/
|
|
60
|
+
private buildClaudeEnvironment;
|
|
61
|
+
/**
|
|
62
|
+
* Build PreToolUse hooks for secret injection.
|
|
63
|
+
* Registers a hook that prepends `export KEY='value'` lines to each Bash command.
|
|
64
|
+
* The LLM never sees the modified command — only the original tool call and
|
|
65
|
+
* the output appear in conversation context.
|
|
66
|
+
*/
|
|
67
|
+
private buildSecretHooks;
|
|
68
|
+
private loadSDK;
|
|
69
|
+
private ensureSDKLoaded;
|
|
70
|
+
initialize(): Promise<void>;
|
|
71
|
+
createSession(config: SessionConfig): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Check if a session ID is valid for Claude Code (UUID format)
|
|
74
|
+
*/
|
|
75
|
+
private isValidClaudeSessionId;
|
|
76
|
+
/**
|
|
77
|
+
* Load conversation history from Claude session file
|
|
78
|
+
*/
|
|
79
|
+
/**
|
|
80
|
+
* Cleans the session file by removing messages with empty text blocks
|
|
81
|
+
* This prevents API errors when resuming sessions
|
|
82
|
+
*/
|
|
83
|
+
private cleanSessionFile;
|
|
84
|
+
/**
|
|
85
|
+
* Public, side-effect-free read of the persisted session history from the
|
|
86
|
+
* on-disk JSONL — no CLI/SDK spawn, no live session required. Used to backfill
|
|
87
|
+
* the durable transcript projection once. Returns [] if the file is missing.
|
|
88
|
+
*/
|
|
89
|
+
getPersistedMessages(sessionId: string, config: SessionConfig): Promise<SessionMessage[]>;
|
|
90
|
+
private loadSessionHistory;
|
|
91
|
+
resumeSession(sessionId: string, config: SessionConfig): Promise<SessionMessage[]>;
|
|
92
|
+
sendPrompt(sessionId: string, parts: MessagePart[], config: SessionConfig): Promise<void>;
|
|
93
|
+
getStatus(sessionId: string, _config: SessionConfig): Promise<SessionStatus>;
|
|
94
|
+
/**
|
|
95
|
+
* Exposes in-flight background subagents as "running tools" so agent-manager's
|
|
96
|
+
* delegation-aware watchdogs (which look for tool names like `task`/`agent`)
|
|
97
|
+
* stand down instead of aborting a coordinator that is waiting on children.
|
|
98
|
+
*/
|
|
99
|
+
getRunningTools(sessionId: string, _config: SessionConfig): Promise<Array<{
|
|
100
|
+
partId: string;
|
|
101
|
+
toolName: string;
|
|
102
|
+
startTime?: number;
|
|
103
|
+
input?: Record<string, unknown>;
|
|
104
|
+
}>>;
|
|
105
|
+
pollMessages(sessionId: string, _seenMessageIds: Set<string>, seenPartIds: Set<string>, partContentLengths: Map<string, string>, _config: SessionConfig): Promise<MessagePart[]>;
|
|
106
|
+
abortPrompt(sessionId: string, _config: SessionConfig): Promise<void>;
|
|
107
|
+
destroySession(sessionId: string, _config: SessionConfig): Promise<void>;
|
|
108
|
+
getAllMessages(sessionId: string, _config: SessionConfig): Promise<SessionMessage[]>;
|
|
109
|
+
respondToQuestion(sessionId: string, answers: Record<string, string>, config: SessionConfig): Promise<void>;
|
|
110
|
+
registerMcpServer(_serverName: string, _mcpConfig: {
|
|
111
|
+
type: 'local' | 'remote';
|
|
112
|
+
command?: string[];
|
|
113
|
+
args?: string[];
|
|
114
|
+
url?: string;
|
|
115
|
+
headers?: Record<string, string>;
|
|
116
|
+
environment?: Record<string, string>;
|
|
117
|
+
}, _workspaceDir?: string): Promise<void>;
|
|
118
|
+
checkHealth(): Promise<{
|
|
119
|
+
available: boolean;
|
|
120
|
+
reason?: string;
|
|
121
|
+
}>;
|
|
122
|
+
/**
|
|
123
|
+
* Safely logs a message by truncating large base64 content
|
|
124
|
+
*/
|
|
125
|
+
/**
|
|
126
|
+
* Lightweight message logger — only logs type/subtype to avoid blocking
|
|
127
|
+
* the event loop with expensive JSON serialization on every streaming chunk.
|
|
128
|
+
*/
|
|
129
|
+
private safeLogMessage;
|
|
130
|
+
/**
|
|
131
|
+
* Consumes the query stream in the background and buffers messages
|
|
132
|
+
*/
|
|
133
|
+
private consumeStream;
|
|
134
|
+
/**
|
|
135
|
+
* Maintains `session.backgroundTasks` from the SDK's task lifecycle messages.
|
|
136
|
+
*
|
|
137
|
+
* Note: the raw CLI also emits `background_tasks_changed` (which carries the
|
|
138
|
+
* authoritative in-flight list), but the SDK filters it out — it is not part of
|
|
139
|
+
* the `SDKMessage` union — so the set has to be rebuilt from task_started plus
|
|
140
|
+
* task_updated / task_notification.
|
|
141
|
+
*/
|
|
142
|
+
private trackBackgroundTask;
|
|
143
|
+
/**
|
|
144
|
+
* Drops background tasks that have outlived MAX_BACKGROUND_TASK_AGE_MS so a
|
|
145
|
+
* lost terminal notification can't keep the session BUSY (and un-reapable)
|
|
146
|
+
* indefinitely.
|
|
147
|
+
*/
|
|
148
|
+
private pruneStaleBackgroundTasks;
|
|
149
|
+
/**
|
|
150
|
+
* Marks the current turn idle once it has produced a `result` AND no
|
|
151
|
+
* background task is still running. The streaming-input prompt remains open
|
|
152
|
+
* for the full session lifetime. Until background work is complete,
|
|
153
|
+
* the session stays BUSY so agent-manager keeps polling instead of calling
|
|
154
|
+
* transitionToIdle (which flips the task to ready_for_review and eventually
|
|
155
|
+
* lets the inactivity reaper destroy the session out from under the subagents).
|
|
156
|
+
*/
|
|
157
|
+
private settleTurnIfComplete;
|
|
158
|
+
/**
|
|
159
|
+
* Extracts a unique message ID from SDKMessage
|
|
160
|
+
*/
|
|
161
|
+
private getMessageId;
|
|
162
|
+
/**
|
|
163
|
+
* Converts SDKMessage to MessagePart[] format
|
|
164
|
+
*/
|
|
165
|
+
private convertSDKMessageToParts;
|
|
166
|
+
/**
|
|
167
|
+
* Builds a human-readable title for a tool call from its input.
|
|
168
|
+
* Mirrors the titles that OpenCode/buildPartPayload produces.
|
|
169
|
+
*/
|
|
170
|
+
private buildToolTitle;
|
|
171
|
+
}
|