@kraki/tentacle 0.1.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/dist/adapters/base.d.ts +107 -0
- package/dist/adapters/base.js +32 -0
- package/dist/adapters/base.js.map +1 -0
- package/dist/adapters/copilot.d.ts +57 -0
- package/dist/adapters/copilot.js +489 -0
- package/dist/adapters/copilot.js.map +1 -0
- package/dist/adapters/index.d.ts +5 -0
- package/dist/adapters/index.js +4 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/banner-data.json +1 -0
- package/dist/banner.d.ts +7 -0
- package/dist/banner.js +187 -0
- package/dist/banner.js.map +1 -0
- package/dist/checks.d.ts +26 -0
- package/dist/checks.js +74 -0
- package/dist/checks.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.js +306 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +38 -0
- package/dist/config.js +113 -0
- package/dist/config.js.map +1 -0
- package/dist/daemon-worker.d.ts +21 -0
- package/dist/daemon-worker.js +127 -0
- package/dist/daemon-worker.js.map +1 -0
- package/dist/daemon.d.ts +24 -0
- package/dist/daemon.js +163 -0
- package/dist/daemon.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/key-manager.d.ts +28 -0
- package/dist/key-manager.js +61 -0
- package/dist/key-manager.js.map +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +30 -0
- package/dist/logger.js.map +1 -0
- package/dist/pair.d.ts +32 -0
- package/dist/pair.js +131 -0
- package/dist/pair.js.map +1 -0
- package/dist/parse-permission.d.ts +25 -0
- package/dist/parse-permission.js +67 -0
- package/dist/parse-permission.js.map +1 -0
- package/dist/relay-client.d.ts +90 -0
- package/dist/relay-client.js +525 -0
- package/dist/relay-client.js.map +1 -0
- package/dist/session-manager.d.ts +85 -0
- package/dist/session-manager.js +218 -0
- package/dist/session-manager.js.map +1 -0
- package/dist/setup.d.ts +13 -0
- package/dist/setup.js +234 -0
- package/dist/setup.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kraki Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for coding agent adapters.
|
|
3
|
+
*
|
|
4
|
+
* Each concrete adapter (Copilot, Claude Code, Codex, etc.) wraps
|
|
5
|
+
* an agent's SDK and normalises its events into Kraki protocol types.
|
|
6
|
+
*
|
|
7
|
+
* The tentacle runtime sets the `on*` callbacks before calling `start()`.
|
|
8
|
+
* The adapter fires them as the agent produces events.
|
|
9
|
+
*/
|
|
10
|
+
import type { ToolArgs } from '@kraki/protocol';
|
|
11
|
+
import type { SessionContext } from '../session-manager.js';
|
|
12
|
+
export interface SessionCreatedEvent {
|
|
13
|
+
sessionId: string;
|
|
14
|
+
agent: string;
|
|
15
|
+
model?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface MessageEvent {
|
|
18
|
+
content: string;
|
|
19
|
+
}
|
|
20
|
+
export interface MessageDeltaEvent {
|
|
21
|
+
content: string;
|
|
22
|
+
}
|
|
23
|
+
export interface PermissionRequestEvent {
|
|
24
|
+
id: string;
|
|
25
|
+
toolArgs: ToolArgs;
|
|
26
|
+
description: string;
|
|
27
|
+
}
|
|
28
|
+
export interface QuestionRequestEvent {
|
|
29
|
+
id: string;
|
|
30
|
+
question: string;
|
|
31
|
+
choices?: string[];
|
|
32
|
+
allowFreeform: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface ToolStartEvent {
|
|
35
|
+
toolName: string;
|
|
36
|
+
args: Record<string, unknown>;
|
|
37
|
+
toolCallId?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ToolCompleteEvent {
|
|
40
|
+
toolName: string;
|
|
41
|
+
result: string;
|
|
42
|
+
toolCallId?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface SessionEndedEvent {
|
|
45
|
+
reason: string;
|
|
46
|
+
}
|
|
47
|
+
export interface ErrorEvent {
|
|
48
|
+
message: string;
|
|
49
|
+
}
|
|
50
|
+
export interface CreateSessionConfig {
|
|
51
|
+
/** Agent-specific model identifier (e.g. "claude-opus-4.6-1m") */
|
|
52
|
+
model?: string;
|
|
53
|
+
/** Working directory for the session */
|
|
54
|
+
cwd?: string;
|
|
55
|
+
/** Caller-supplied session ID (adapter may ignore) */
|
|
56
|
+
sessionId?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface SessionInfo {
|
|
59
|
+
id: string;
|
|
60
|
+
state: 'active' | 'idle' | 'ended';
|
|
61
|
+
model?: string;
|
|
62
|
+
cwd?: string;
|
|
63
|
+
summary?: string;
|
|
64
|
+
}
|
|
65
|
+
export type PermissionDecision = 'approve' | 'deny' | 'always_allow';
|
|
66
|
+
export declare abstract class AgentAdapter {
|
|
67
|
+
onSessionCreated: ((event: SessionCreatedEvent) => void) | null;
|
|
68
|
+
onMessage: ((sessionId: string, event: MessageEvent) => void) | null;
|
|
69
|
+
onMessageDelta: ((sessionId: string, event: MessageDeltaEvent) => void) | null;
|
|
70
|
+
onPermissionRequest: ((sessionId: string, event: PermissionRequestEvent) => void) | null;
|
|
71
|
+
/** Called when a permission is auto-resolved (e.g. by "Always Allow" for same tool kind) */
|
|
72
|
+
onPermissionAutoResolved: ((sessionId: string, permissionId: string) => void) | null;
|
|
73
|
+
onQuestionRequest: ((sessionId: string, event: QuestionRequestEvent) => void) | null;
|
|
74
|
+
onToolStart: ((sessionId: string, event: ToolStartEvent) => void) | null;
|
|
75
|
+
onToolComplete: ((sessionId: string, event: ToolCompleteEvent) => void) | null;
|
|
76
|
+
onIdle: ((sessionId: string) => void) | null;
|
|
77
|
+
onError: ((sessionId: string, event: ErrorEvent) => void) | null;
|
|
78
|
+
onSessionEnded: ((sessionId: string, event: SessionEndedEvent) => void) | null;
|
|
79
|
+
/** Start the adapter (e.g. spawn CLI server). */
|
|
80
|
+
abstract start(): Promise<void>;
|
|
81
|
+
/** Stop the adapter and release all resources. */
|
|
82
|
+
abstract stop(): Promise<void>;
|
|
83
|
+
/** Create a new agent session. */
|
|
84
|
+
abstract createSession(config: CreateSessionConfig): Promise<{
|
|
85
|
+
sessionId: string;
|
|
86
|
+
}>;
|
|
87
|
+
/** Resume a previously created session with recovery context. */
|
|
88
|
+
abstract resumeSession(sessionId: string, context?: SessionContext): Promise<{
|
|
89
|
+
sessionId: string;
|
|
90
|
+
}>;
|
|
91
|
+
/** Send a user message to a session. */
|
|
92
|
+
abstract sendMessage(sessionId: string, text: string, attachments?: string[]): Promise<void>;
|
|
93
|
+
/** Respond to a pending permission request. */
|
|
94
|
+
abstract respondToPermission(sessionId: string, permissionId: string, decision: PermissionDecision): Promise<void>;
|
|
95
|
+
/** Respond to a pending agent question. */
|
|
96
|
+
abstract respondToQuestion(sessionId: string, questionId: string, answer: string, wasFreeform: boolean): Promise<void>;
|
|
97
|
+
/** Kill / disconnect a session. */
|
|
98
|
+
abstract killSession(sessionId: string): Promise<void>;
|
|
99
|
+
/** Abort the current turn (session stays alive). Override in concrete adapters. */
|
|
100
|
+
abortSession(_sessionId: string): Promise<void>;
|
|
101
|
+
/** List known sessions. */
|
|
102
|
+
abstract listSessions(): Promise<SessionInfo[]>;
|
|
103
|
+
/** List available models. Override in concrete adapters. */
|
|
104
|
+
listModels(): Promise<string[]>;
|
|
105
|
+
/** Set permission mode for a session. Override in concrete adapters. */
|
|
106
|
+
setSessionMode(_sessionId: string, _mode: 'ask' | 'auto'): void;
|
|
107
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for coding agent adapters.
|
|
3
|
+
*
|
|
4
|
+
* Each concrete adapter (Copilot, Claude Code, Codex, etc.) wraps
|
|
5
|
+
* an agent's SDK and normalises its events into Kraki protocol types.
|
|
6
|
+
*
|
|
7
|
+
* The tentacle runtime sets the `on*` callbacks before calling `start()`.
|
|
8
|
+
* The adapter fires them as the agent produces events.
|
|
9
|
+
*/
|
|
10
|
+
// ── The adapter interface ───────────────────────────────
|
|
11
|
+
export class AgentAdapter {
|
|
12
|
+
// --- Callbacks (set by the tentacle runtime) ---
|
|
13
|
+
onSessionCreated = null;
|
|
14
|
+
onMessage = null;
|
|
15
|
+
onMessageDelta = null;
|
|
16
|
+
onPermissionRequest = null;
|
|
17
|
+
/** Called when a permission is auto-resolved (e.g. by "Always Allow" for same tool kind) */
|
|
18
|
+
onPermissionAutoResolved = null;
|
|
19
|
+
onQuestionRequest = null;
|
|
20
|
+
onToolStart = null;
|
|
21
|
+
onToolComplete = null;
|
|
22
|
+
onIdle = null;
|
|
23
|
+
onError = null;
|
|
24
|
+
onSessionEnded = null;
|
|
25
|
+
/** Abort the current turn (session stays alive). Override in concrete adapters. */
|
|
26
|
+
async abortSession(_sessionId) { }
|
|
27
|
+
/** List available models. Override in concrete adapters. */
|
|
28
|
+
async listModels() { return []; }
|
|
29
|
+
/** Set permission mode for a session. Override in concrete adapters. */
|
|
30
|
+
setSessionMode(_sessionId, _mode) { }
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/adapters/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA+EH,2DAA2D;AAE3D,MAAM,OAAgB,YAAY;IAChC,kDAAkD;IAElD,gBAAgB,GAAkD,IAAI,CAAC;IACvE,SAAS,GAA8D,IAAI,CAAC;IAC5E,cAAc,GAAmE,IAAI,CAAC;IACtF,mBAAmB,GAAwE,IAAI,CAAC;IAChG,4FAA4F;IAC5F,wBAAwB,GAA+D,IAAI,CAAC;IAC5F,iBAAiB,GAAsE,IAAI,CAAC;IAC5F,WAAW,GAAgE,IAAI,CAAC;IAChF,cAAc,GAAmE,IAAI,CAAC;IACtF,MAAM,GAAyC,IAAI,CAAC;IACpD,OAAO,GAA4D,IAAI,CAAC;IACxE,cAAc,GAAmE,IAAI,CAAC;IAuCtF,mFAAmF;IACnF,KAAK,CAAC,YAAY,CAAC,UAAkB,IAA0C,CAAC;IAKhF,4DAA4D;IAC5D,KAAK,CAAC,UAAU,KAAwB,OAAO,EAAE,CAAC,CAAC,CAAC;IAEpD,wEAAwE;IACxE,cAAc,CAAC,UAAkB,EAAE,KAAqB,IAAiC,CAAC;CAC3F"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copilot SDK adapter for Kraki.
|
|
3
|
+
*
|
|
4
|
+
* Wraps `@github/copilot-sdk` and normalises Copilot CLI events
|
|
5
|
+
* into the abstract `AgentAdapter` callback interface.
|
|
6
|
+
*
|
|
7
|
+
* Key responsibilities:
|
|
8
|
+
* - Manage the CopilotClient lifecycle (start/stop the CLI server)
|
|
9
|
+
* - Create/resume/kill sessions via the SDK
|
|
10
|
+
* - Wire SDK streaming events → `on*` callbacks
|
|
11
|
+
* - Implement the permission-request / question blocking pattern:
|
|
12
|
+
* the SDK handler returns a Promise that resolves when the
|
|
13
|
+
* remote user approves/denies/answers via the tentacle runtime.
|
|
14
|
+
*/
|
|
15
|
+
import { AgentAdapter, type CreateSessionConfig, type SessionInfo, type PermissionDecision } from './base.js';
|
|
16
|
+
export declare function patchCopilotSdkSessionImport(currentUrl?: string): boolean;
|
|
17
|
+
export declare function resolveCopilotSdkSessionPath(currentUrl?: string): string | null;
|
|
18
|
+
export declare function installCopilotSdkImportCompatibility(currentUrl?: string): 'hook' | 'patch' | null;
|
|
19
|
+
export declare class CopilotAdapter extends AgentAdapter {
|
|
20
|
+
private client;
|
|
21
|
+
private sessions;
|
|
22
|
+
private cliPath;
|
|
23
|
+
/** Per-session auto-approve sets (populated by "Always Allow" clicks) */
|
|
24
|
+
private sessionAllowSets;
|
|
25
|
+
/** Session permission mode: 'ask' (default) or 'auto' */
|
|
26
|
+
private sessionModes;
|
|
27
|
+
constructor(options?: {
|
|
28
|
+
cliPath?: string;
|
|
29
|
+
});
|
|
30
|
+
start(): Promise<void>;
|
|
31
|
+
stop(): Promise<void>;
|
|
32
|
+
createSession(config: CreateSessionConfig): Promise<{
|
|
33
|
+
sessionId: string;
|
|
34
|
+
}>;
|
|
35
|
+
resumeSession(sessionId: string): Promise<{
|
|
36
|
+
sessionId: string;
|
|
37
|
+
}>;
|
|
38
|
+
sendMessage(sessionId: string, text: string, attachments?: string[]): Promise<void>;
|
|
39
|
+
respondToPermission(sessionId: string, permissionId: string, decision: PermissionDecision): Promise<void>;
|
|
40
|
+
respondToQuestion(sessionId: string, questionId: string, answer: string, wasFreeform: boolean): Promise<void>;
|
|
41
|
+
killSession(sessionId: string): Promise<void>;
|
|
42
|
+
abortSession(sessionId: string): Promise<void>;
|
|
43
|
+
listSessions(): Promise<SessionInfo[]>;
|
|
44
|
+
listModels(): Promise<string[]>;
|
|
45
|
+
/** Set permission mode for a session ('ask' or 'auto') */
|
|
46
|
+
setSessionMode(sessionId: string, mode: 'ask' | 'auto'): void;
|
|
47
|
+
/** Clean up session-scoped permission state */
|
|
48
|
+
private cleanupSessionPermissions;
|
|
49
|
+
private makeResumeConfig;
|
|
50
|
+
private resumeTrackedSession;
|
|
51
|
+
private handleUnavailableSession;
|
|
52
|
+
private wireEvents;
|
|
53
|
+
private makePermissionHandler;
|
|
54
|
+
private makeQuestionHandler;
|
|
55
|
+
private ensureClient;
|
|
56
|
+
private getSession;
|
|
57
|
+
}
|