@pruddiman/hem 0.0.1-beta-5671db0
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/dist/agents/arbiter-agent.d.ts +72 -0
- package/dist/agents/arbiter-agent.js +149 -0
- package/dist/agents/architecture-agent.d.ts +148 -0
- package/dist/agents/architecture-agent.js +459 -0
- package/dist/agents/base-agent.d.ts +44 -0
- package/dist/agents/base-agent.js +57 -0
- package/dist/agents/crossref-agent.d.ts +140 -0
- package/dist/agents/crossref-agent.js +560 -0
- package/dist/agents/crossref-arbiter-agent.d.ts +72 -0
- package/dist/agents/crossref-arbiter-agent.js +147 -0
- package/dist/agents/documentation-agent.d.ts +55 -0
- package/dist/agents/documentation-agent.js +159 -0
- package/dist/agents/exploration-agent.d.ts +58 -0
- package/dist/agents/exploration-agent.js +102 -0
- package/dist/agents/grouping-agent.d.ts +167 -0
- package/dist/agents/grouping-agent.js +557 -0
- package/dist/agents/index-agent.d.ts +86 -0
- package/dist/agents/index-agent.js +360 -0
- package/dist/agents/organization-agent.d.ts +144 -0
- package/dist/agents/organization-agent.js +607 -0
- package/dist/auth.d.ts +372 -0
- package/dist/auth.js +1072 -0
- package/dist/broadcast-mcp.d.ts +21 -0
- package/dist/broadcast-mcp.js +59 -0
- package/dist/changelog.d.ts +85 -0
- package/dist/changelog.js +223 -0
- package/dist/decision-queue.d.ts +173 -0
- package/dist/decision-queue.js +265 -0
- package/dist/diff-scope.d.ts +24 -0
- package/dist/diff-scope.js +28 -0
- package/dist/discovery.d.ts +54 -0
- package/dist/discovery.js +405 -0
- package/dist/grouping.d.ts +37 -0
- package/dist/grouping.js +343 -0
- package/dist/helpers/format.d.ts +5 -0
- package/dist/helpers/format.js +13 -0
- package/dist/helpers/index.d.ts +11 -0
- package/dist/helpers/index.js +11 -0
- package/dist/helpers/parsing.d.ts +52 -0
- package/dist/helpers/parsing.js +128 -0
- package/dist/helpers/paths.d.ts +41 -0
- package/dist/helpers/paths.js +67 -0
- package/dist/helpers/strings.d.ts +45 -0
- package/dist/helpers/strings.js +97 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.js +1087 -0
- package/dist/merge-utils.d.ts +22 -0
- package/dist/merge-utils.js +34 -0
- package/dist/orchestrator.d.ts +194 -0
- package/dist/orchestrator.js +1169 -0
- package/dist/output.d.ts +106 -0
- package/dist/output.js +243 -0
- package/dist/progress.d.ts +228 -0
- package/dist/progress.js +644 -0
- package/dist/providers/copilot.d.ts +247 -0
- package/dist/providers/copilot.js +598 -0
- package/dist/providers/index.d.ts +15 -0
- package/dist/providers/index.js +12 -0
- package/dist/providers/opencode.d.ts +156 -0
- package/dist/providers/opencode.js +416 -0
- package/dist/providers/types.d.ts +156 -0
- package/dist/providers/types.js +16 -0
- package/dist/resources.d.ts +76 -0
- package/dist/resources.js +151 -0
- package/dist/search-index.d.ts +71 -0
- package/dist/search-index.js +187 -0
- package/dist/search-mcp.d.ts +25 -0
- package/dist/search-mcp.js +100 -0
- package/dist/server-utils.d.ts +56 -0
- package/dist/server-utils.js +135 -0
- package/dist/session.d.ts +227 -0
- package/dist/session.js +370 -0
- package/dist/types.d.ts +272 -0
- package/dist/types.js +5 -0
- package/dist/worktree.d.ts +82 -0
- package/dist/worktree.js +187 -0
- package/package.json +45 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub Copilot provider implementation for Hem.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the @github/copilot-sdk CopilotClient behind the {@link Provider}
|
|
5
|
+
* interface. Provides full feature parity with OpenCodeProvider:
|
|
6
|
+
* - MCP server registration (hem-broadcast) per session
|
|
7
|
+
* - Per-agent permission profiles (mapped from agent name to Copilot SDK permissions)
|
|
8
|
+
* - Broadcast tool interception via `onPreToolUse` hook → normalized SSE events
|
|
9
|
+
* - Terminable SSE event stream via central emitter pattern
|
|
10
|
+
* - Verbose logging throughout
|
|
11
|
+
*
|
|
12
|
+
* Aligns with Dispatch's ProviderInstance pattern:
|
|
13
|
+
* - `createSession()` — creates a Copilot session with full MCP + permission config
|
|
14
|
+
* - `prompt(sessionId, text, { agent })` — sets agent context, sends prompt, waits for idle
|
|
15
|
+
* - `cleanup()` — destroys all sessions, terminates SSE generators, stops the client
|
|
16
|
+
*
|
|
17
|
+
* Authentication options (checked in order by the SDK):
|
|
18
|
+
* 1. COPILOT_GITHUB_TOKEN / GH_TOKEN / GITHUB_TOKEN env vars
|
|
19
|
+
* 2. Logged-in Copilot CLI user (default — no token needed)
|
|
20
|
+
*/
|
|
21
|
+
import type { Provider, ProviderConfig } from "./types.js";
|
|
22
|
+
/** Permission request kind from the Copilot SDK. */
|
|
23
|
+
type PermissionKind = "shell" | "write" | "mcp" | "read" | "url" | "custom-tool";
|
|
24
|
+
/** Minimal permission request shape. */
|
|
25
|
+
interface PermissionRequest {
|
|
26
|
+
kind: PermissionKind;
|
|
27
|
+
command?: string;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
/** Minimal permission result returned to the SDK. */
|
|
31
|
+
interface PermissionResult {
|
|
32
|
+
kind: "approved" | "denied-by-rules";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Minimal interface for a Copilot session, matching the subset of
|
|
36
|
+
* `CopilotSession` from `@github/copilot-sdk` used by the provider.
|
|
37
|
+
*/
|
|
38
|
+
export interface CopilotSessionLike {
|
|
39
|
+
sessionId: string;
|
|
40
|
+
send(options: {
|
|
41
|
+
prompt: string;
|
|
42
|
+
}): Promise<string>;
|
|
43
|
+
abort(): Promise<void>;
|
|
44
|
+
destroy(): Promise<void>;
|
|
45
|
+
getMessages(): Promise<Array<{
|
|
46
|
+
type: string;
|
|
47
|
+
data?: {
|
|
48
|
+
content?: string;
|
|
49
|
+
};
|
|
50
|
+
}>>;
|
|
51
|
+
on(eventType: string, handler: (...args: unknown[]) => void): () => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Minimal interface for a Copilot client, matching the subset of
|
|
55
|
+
* `CopilotClient` from `@github/copilot-sdk` used by the provider.
|
|
56
|
+
*/
|
|
57
|
+
export interface CopilotClientLike {
|
|
58
|
+
createSession(config?: {
|
|
59
|
+
model?: string;
|
|
60
|
+
workingDirectory?: string;
|
|
61
|
+
onPermissionRequest?: (request: PermissionRequest, ctx: {
|
|
62
|
+
sessionId: string;
|
|
63
|
+
}) => PermissionResult | Promise<PermissionResult>;
|
|
64
|
+
mcpServers?: Record<string, {
|
|
65
|
+
type?: string;
|
|
66
|
+
command?: string;
|
|
67
|
+
args?: string[];
|
|
68
|
+
tools?: string[];
|
|
69
|
+
}>;
|
|
70
|
+
hooks?: {
|
|
71
|
+
onPreToolUse?: (input: {
|
|
72
|
+
toolName: string;
|
|
73
|
+
toolArgs: unknown;
|
|
74
|
+
}, ctx: {
|
|
75
|
+
sessionId: string;
|
|
76
|
+
}) => Promise<{
|
|
77
|
+
permissionDecision?: string;
|
|
78
|
+
} | void> | void;
|
|
79
|
+
};
|
|
80
|
+
}): Promise<CopilotSessionLike>;
|
|
81
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
82
|
+
on(eventType: string, handler: (...args: unknown[]) => void): () => void;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Factory function type for creating a CopilotClient instance.
|
|
86
|
+
* Accepts an optional GitHub token (used when an env-var token is found).
|
|
87
|
+
* Returns an object with a client and stop method.
|
|
88
|
+
* Overridable in tests.
|
|
89
|
+
*/
|
|
90
|
+
export type CreateCopilotClientFn = (token?: string) => Promise<{
|
|
91
|
+
client: CopilotClientLike;
|
|
92
|
+
stop: () => Promise<void>;
|
|
93
|
+
}>;
|
|
94
|
+
/**
|
|
95
|
+
* Provider implementation backed by the GitHub Copilot SDK.
|
|
96
|
+
*
|
|
97
|
+
* Provides full feature parity with OpenCodeProvider:
|
|
98
|
+
* - MCP server: hem-broadcast registered on every session
|
|
99
|
+
* - Per-agent permissions: mapped from agent name via onPermissionRequest
|
|
100
|
+
* - Broadcast relay: onPreToolUse hook emits normalized message.part.updated events
|
|
101
|
+
* - SSE events: central emitter with terminable generators
|
|
102
|
+
* - Verbose logging throughout
|
|
103
|
+
*
|
|
104
|
+
* When no token is found in environment variables the SDK uses the
|
|
105
|
+
* Copilot CLI's own auth state (set up via `gh auth login`).
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const provider = await CopilotProvider.create(config);
|
|
110
|
+
* const sessionId = await provider.createSession();
|
|
111
|
+
* const result = await provider.prompt(sessionId, "Explain this code", { agent: "hem-doc" });
|
|
112
|
+
* await provider.cleanup();
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare class CopilotProvider implements Provider {
|
|
116
|
+
private _config;
|
|
117
|
+
private _client;
|
|
118
|
+
private _stopFn;
|
|
119
|
+
private _factory;
|
|
120
|
+
private _sessions;
|
|
121
|
+
private _sessionMeta;
|
|
122
|
+
private _modelValue;
|
|
123
|
+
private _modelDetected;
|
|
124
|
+
private _eventHandlers;
|
|
125
|
+
private _sseCleanupHandlers;
|
|
126
|
+
/** Low-level session operations (implementing Provider interface). */
|
|
127
|
+
readonly session: Provider["session"];
|
|
128
|
+
/** SSE event subscription (implementing Provider interface). */
|
|
129
|
+
readonly event: Provider["event"];
|
|
130
|
+
/**
|
|
131
|
+
* Creates a new Copilot provider.
|
|
132
|
+
*
|
|
133
|
+
* @param config - Provider configuration (model, destination, permissions).
|
|
134
|
+
* @param factory - Optional client factory override for testing.
|
|
135
|
+
*/
|
|
136
|
+
constructor(config: ProviderConfig, factory?: CreateCopilotClientFn);
|
|
137
|
+
get name(): string;
|
|
138
|
+
get model(): string | undefined;
|
|
139
|
+
get config(): ProviderConfig;
|
|
140
|
+
/**
|
|
141
|
+
* Creates and initializes a CopilotProvider.
|
|
142
|
+
* Mirrors Dispatch's `boot()` pattern — callers receive a ready-to-use
|
|
143
|
+
* provider without calling `initialize()` separately.
|
|
144
|
+
*/
|
|
145
|
+
static create(config: ProviderConfig, factory?: CreateCopilotClientFn): Promise<CopilotProvider>;
|
|
146
|
+
/** Fan out an SSE event to all active subscribers. */
|
|
147
|
+
private _emit;
|
|
148
|
+
/**
|
|
149
|
+
* Build a Copilot SDK permission handler that enforces the OpenCode-equivalent
|
|
150
|
+
* permission profile for the given agent context.
|
|
151
|
+
*
|
|
152
|
+
* Defaults to approve-all when `agentContext.name` is not yet set (i.e., before
|
|
153
|
+
* the first `prompt()` call). In practice, all tool calls arrive after the
|
|
154
|
+
* prompt, so the agent name is always set before any permission request.
|
|
155
|
+
*/
|
|
156
|
+
private _buildPermissionHandler;
|
|
157
|
+
/**
|
|
158
|
+
* Build the full session config for a new Copilot session.
|
|
159
|
+
*
|
|
160
|
+
* Includes:
|
|
161
|
+
* - MCP server: hem-broadcast (mirrors OpenCodeProvider's MCP config)
|
|
162
|
+
* - onPermissionRequest: agent-aware permission handler
|
|
163
|
+
* - hooks.onPreToolUse: intercepts broadcast tool calls → emits normalized SSE
|
|
164
|
+
* - workingDirectory: scoped to destination path
|
|
165
|
+
*/
|
|
166
|
+
private _buildSessionConfig;
|
|
167
|
+
/**
|
|
168
|
+
* Starts the Copilot client.
|
|
169
|
+
*
|
|
170
|
+
* Checks `COPILOT_GITHUB_TOKEN`, `GH_TOKEN`, and `GITHUB_TOKEN` environment
|
|
171
|
+
* variables and passes the token to the SDK when found. When no token is
|
|
172
|
+
* present the SDK uses the Copilot CLI's own auth state.
|
|
173
|
+
*
|
|
174
|
+
* Registers the client-level `session.created` listener once (used by agents
|
|
175
|
+
* that monitor child session creation via the SSE event stream).
|
|
176
|
+
*
|
|
177
|
+
* Idempotent — subsequent calls are no-ops if already initialized.
|
|
178
|
+
*
|
|
179
|
+
* @throws {Error} If the Copilot client fails to start.
|
|
180
|
+
*/
|
|
181
|
+
initialize(): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Create a new Copilot session with MCP server and permission configuration.
|
|
184
|
+
*
|
|
185
|
+
* Each session is created with:
|
|
186
|
+
* - hem-broadcast MCP server (matches OpenCodeProvider's MCP config)
|
|
187
|
+
* - A permission handler that enforces agent-specific rules once the agent
|
|
188
|
+
* name is set via `prompt()` or `session.promptAsync()`
|
|
189
|
+
* - An `onPreToolUse` hook for broadcast interception
|
|
190
|
+
* - SSE event listeners for session.idle and session.error
|
|
191
|
+
*
|
|
192
|
+
* @returns The session ID.
|
|
193
|
+
* @throws {Error} If the provider is not initialized.
|
|
194
|
+
*/
|
|
195
|
+
createSession(): Promise<string>;
|
|
196
|
+
/**
|
|
197
|
+
* Send a prompt to a Copilot session and wait for the response.
|
|
198
|
+
*
|
|
199
|
+
* Sets the agent context from `options.agent` so the permission handler
|
|
200
|
+
* enforces the correct per-agent policy for all subsequent tool calls.
|
|
201
|
+
*
|
|
202
|
+
* Flow:
|
|
203
|
+
* 1. Set agent context (for permission enforcement)
|
|
204
|
+
* 2. `session.send()` — fires the prompt
|
|
205
|
+
* 3. Wait for `session.idle` or `session.error` event
|
|
206
|
+
* 4. `session.getMessages()` — fetch the completed response
|
|
207
|
+
* 5. Return the last `assistant.message` content, or null
|
|
208
|
+
*
|
|
209
|
+
* @param sessionId - The session ID returned by `createSession()`.
|
|
210
|
+
* @param text - The prompt text.
|
|
211
|
+
* @param options - Optional: `agent` sets the permission profile for this session.
|
|
212
|
+
*/
|
|
213
|
+
prompt(sessionId: string, text: string, options?: {
|
|
214
|
+
agent?: string;
|
|
215
|
+
}): Promise<string | null>;
|
|
216
|
+
/**
|
|
217
|
+
* Shuts down the Copilot client and releases all resources.
|
|
218
|
+
*
|
|
219
|
+
* 1. Terminates all active SSE generators (unblocks pending iterators).
|
|
220
|
+
* 2. Destroys all active sessions.
|
|
221
|
+
* 3. Stops the Copilot client.
|
|
222
|
+
*
|
|
223
|
+
* After cleanup, the provider instance must not be reused.
|
|
224
|
+
* No-op if the provider was never initialized or already shut down.
|
|
225
|
+
*/
|
|
226
|
+
cleanup(): Promise<void>;
|
|
227
|
+
/**
|
|
228
|
+
* Alias for `cleanup()` — kept for backward compatibility with callers
|
|
229
|
+
* that use the old `shutdown()` name.
|
|
230
|
+
*/
|
|
231
|
+
shutdown(): Promise<void>;
|
|
232
|
+
/**
|
|
233
|
+
* Discovers a GitHub token from well-known environment variables.
|
|
234
|
+
*
|
|
235
|
+
* Returns `undefined` when no token is set — the SDK will then use the
|
|
236
|
+
* Copilot CLI's own auth state instead.
|
|
237
|
+
*
|
|
238
|
+
* @internal
|
|
239
|
+
*/
|
|
240
|
+
static _findToken(): string | undefined;
|
|
241
|
+
/**
|
|
242
|
+
* Returns the name of the env var that provided the token, for logging.
|
|
243
|
+
* @internal
|
|
244
|
+
*/
|
|
245
|
+
static _findTokenSource(): string;
|
|
246
|
+
}
|
|
247
|
+
export {};
|