@peakflo/agent-harness 0.0.0-stage → 0.2.2-rc.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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +68 -2
  3. package/dist/adapters/acp-adapter.d.ts +177 -0
  4. package/dist/adapters/acp-adapter.js +1732 -0
  5. package/dist/adapters/claude-code-adapter.d.ts +171 -0
  6. package/dist/adapters/claude-code-adapter.js +1918 -0
  7. package/dist/adapters/codex-adapter.d.ts +67 -0
  8. package/dist/adapters/codex-adapter.js +681 -0
  9. package/dist/adapters/codex-app-server-adapter.d.ts +105 -0
  10. package/dist/adapters/codex-app-server-adapter.js +1309 -0
  11. package/dist/adapters/coding-agent-adapter.d.ts +289 -0
  12. package/dist/adapters/coding-agent-adapter.js +31 -0
  13. package/dist/adapters/index.d.ts +17 -0
  14. package/dist/adapters/index.js +35 -0
  15. package/dist/adapters/model-gateway.d.ts +84 -0
  16. package/dist/adapters/model-gateway.js +270 -0
  17. package/dist/adapters/opencode-adapter.d.ts +403 -0
  18. package/dist/adapters/opencode-adapter.js +2710 -0
  19. package/dist/adapters/opencode-config.d.ts +41 -0
  20. package/dist/adapters/opencode-config.js +147 -0
  21. package/dist/adapters/opencode-server-policy.d.ts +82 -0
  22. package/dist/adapters/opencode-server-policy.js +148 -0
  23. package/dist/adapters/pi-adapter.d.ts +168 -0
  24. package/dist/adapters/pi-adapter.js +1468 -0
  25. package/dist/capabilities.d.ts +58 -0
  26. package/dist/capabilities.js +161 -0
  27. package/dist/cli.d.ts +2 -0
  28. package/dist/cli.js +231 -0
  29. package/dist/contract.d.ts +273 -0
  30. package/dist/contract.js +357 -0
  31. package/dist/control-plane.d.ts +178 -0
  32. package/dist/control-plane.js +431 -0
  33. package/dist/credential-store.d.ts +110 -0
  34. package/dist/credential-store.js +181 -0
  35. package/dist/enrol/browser-enrol.d.ts +85 -0
  36. package/dist/enrol/browser-enrol.js +387 -0
  37. package/dist/github-command-guards.d.ts +20 -0
  38. package/dist/github-command-guards.js +330 -0
  39. package/dist/github-proxy-certificates.d.ts +25 -0
  40. package/dist/github-proxy-certificates.js +145 -0
  41. package/dist/github-proxy.d.ts +37 -0
  42. package/dist/github-proxy.js +476 -0
  43. package/dist/github-workspace.d.ts +55 -0
  44. package/dist/github-workspace.js +537 -0
  45. package/dist/harness.d.ts +333 -0
  46. package/dist/harness.js +1414 -0
  47. package/dist/health.d.ts +45 -0
  48. package/dist/health.js +116 -0
  49. package/dist/index.d.ts +53 -0
  50. package/dist/index.js +123 -0
  51. package/dist/model-probe.d.ts +96 -0
  52. package/dist/model-probe.js +195 -0
  53. package/dist/options.d.ts +15 -0
  54. package/dist/options.js +212 -0
  55. package/dist/ports-default.d.ts +212 -0
  56. package/dist/ports-default.js +333 -0
  57. package/dist/ports.d.ts +436 -0
  58. package/dist/ports.js +27 -0
  59. package/dist/runtime/attachments.d.ts +92 -0
  60. package/dist/runtime/attachments.js +377 -0
  61. package/dist/runtime/child-stream-guards.d.ts +45 -0
  62. package/dist/runtime/child-stream-guards.js +111 -0
  63. package/dist/runtime/conversation.d.ts +87 -0
  64. package/dist/runtime/conversation.js +156 -0
  65. package/dist/runtime/lease-renewal.d.ts +169 -0
  66. package/dist/runtime/lease-renewal.js +433 -0
  67. package/dist/runtime/mcp-auth-proxy.d.ts +82 -0
  68. package/dist/runtime/mcp-auth-proxy.js +300 -0
  69. package/dist/runtime/permission-mode.d.ts +116 -0
  70. package/dist/runtime/permission-mode.js +146 -0
  71. package/dist/runtime/projection.d.ts +71 -0
  72. package/dist/runtime/projection.js +211 -0
  73. package/dist/runtime/session-runner.d.ts +520 -0
  74. package/dist/runtime/session-runner.js +2122 -0
  75. package/dist/shared/reasoning-effort.d.ts +11 -0
  76. package/dist/shared/reasoning-effort.js +20 -0
  77. package/dist/store/conversation-store.d.ts +100 -0
  78. package/dist/store/conversation-store.js +305 -0
  79. package/dist/store/sqlite-store.d.ts +120 -0
  80. package/dist/store/sqlite-store.js +346 -0
  81. package/dist/types.d.ts +952 -0
  82. package/dist/types.js +55 -0
  83. package/dist/version.d.ts +32 -0
  84. package/dist/version.js +77 -0
  85. 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
+ }