linkshell-cli 0.5.42 → 0.6.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 (135) hide show
  1. package/dist/cli/src/commands/host.d.ts +30 -0
  2. package/dist/cli/src/commands/host.js +278 -0
  3. package/dist/cli/src/commands/host.js.map +1 -0
  4. package/dist/cli/src/commands/pair.d.ts +1 -0
  5. package/dist/cli/src/commands/pair.js +51 -0
  6. package/dist/cli/src/commands/pair.js.map +1 -0
  7. package/dist/cli/src/index.js +69 -0
  8. package/dist/cli/src/index.js.map +1 -1
  9. package/dist/cli/src/utils/daemon.d.ts +1 -1
  10. package/dist/cli/src/utils/daemon.js +3 -2
  11. package/dist/cli/src/utils/daemon.js.map +1 -1
  12. package/dist/cli/tsconfig.tsbuildinfo +1 -1
  13. package/dist/host/src/drivers/acp/connection.d.ts +61 -0
  14. package/dist/host/src/drivers/acp/connection.js +121 -0
  15. package/dist/host/src/drivers/acp/connection.js.map +1 -0
  16. package/dist/host/src/drivers/acp/driver.d.ts +110 -0
  17. package/dist/host/src/drivers/acp/driver.js +438 -0
  18. package/dist/host/src/drivers/acp/driver.js.map +1 -0
  19. package/dist/host/src/drivers/acp/mapper.d.ts +49 -0
  20. package/dist/host/src/drivers/acp/mapper.js +411 -0
  21. package/dist/host/src/drivers/acp/mapper.js.map +1 -0
  22. package/dist/host/src/drivers/auth.d.ts +7 -0
  23. package/dist/host/src/drivers/auth.js +57 -0
  24. package/dist/host/src/drivers/auth.js.map +1 -0
  25. package/dist/host/src/drivers/claude/driver.d.ts +76 -0
  26. package/dist/host/src/drivers/claude/driver.js +331 -0
  27. package/dist/host/src/drivers/claude/driver.js.map +1 -0
  28. package/dist/host/src/drivers/claude/transcript.d.ts +335 -0
  29. package/dist/host/src/drivers/claude/transcript.js +516 -0
  30. package/dist/host/src/drivers/claude/transcript.js.map +1 -0
  31. package/dist/host/src/drivers/codex/app-server.d.ts +36 -0
  32. package/dist/host/src/drivers/codex/app-server.js +144 -0
  33. package/dist/host/src/drivers/codex/app-server.js.map +1 -0
  34. package/dist/host/src/drivers/codex/driver.d.ts +89 -0
  35. package/dist/host/src/drivers/codex/driver.js +452 -0
  36. package/dist/host/src/drivers/codex/driver.js.map +1 -0
  37. package/dist/host/src/drivers/codex/mapper.d.ts +61 -0
  38. package/dist/host/src/drivers/codex/mapper.js +623 -0
  39. package/dist/host/src/drivers/codex/mapper.js.map +1 -0
  40. package/dist/host/src/drivers/codex/settings.d.ts +51 -0
  41. package/dist/host/src/drivers/codex/settings.js +107 -0
  42. package/dist/host/src/drivers/codex/settings.js.map +1 -0
  43. package/dist/host/src/drivers/images.d.ts +11 -0
  44. package/dist/host/src/drivers/images.js +34 -0
  45. package/dist/host/src/drivers/images.js.map +1 -0
  46. package/dist/host/src/drivers/nesting.d.ts +6 -0
  47. package/dist/host/src/drivers/nesting.js +25 -0
  48. package/dist/host/src/drivers/nesting.js.map +1 -0
  49. package/dist/host/src/drivers/registry.d.ts +21 -0
  50. package/dist/host/src/drivers/registry.js +30 -0
  51. package/dist/host/src/drivers/registry.js.map +1 -0
  52. package/dist/host/src/drivers/types.d.ts +105 -0
  53. package/dist/host/src/drivers/types.js +2 -0
  54. package/dist/host/src/drivers/types.js.map +1 -0
  55. package/dist/host/src/fs.d.ts +69 -0
  56. package/dist/host/src/fs.js +198 -0
  57. package/dist/host/src/fs.js.map +1 -0
  58. package/dist/host/src/gateway.d.ts +55 -0
  59. package/dist/host/src/gateway.js +263 -0
  60. package/dist/host/src/gateway.js.map +1 -0
  61. package/dist/host/src/host.d.ts +51 -0
  62. package/dist/host/src/host.js +133 -0
  63. package/dist/host/src/host.js.map +1 -0
  64. package/dist/host/src/hub.d.ts +89 -0
  65. package/dist/host/src/hub.js +592 -0
  66. package/dist/host/src/hub.js.map +1 -0
  67. package/dist/host/src/index.d.ts +10 -0
  68. package/dist/host/src/index.js +10 -0
  69. package/dist/host/src/index.js.map +1 -0
  70. package/dist/host/src/ports.d.ts +24 -0
  71. package/dist/host/src/ports.js +201 -0
  72. package/dist/host/src/ports.js.map +1 -0
  73. package/dist/host/src/rpc/client.d.ts +9 -0
  74. package/dist/host/src/rpc/client.js +42 -0
  75. package/dist/host/src/rpc/client.js.map +1 -0
  76. package/dist/host/src/rpc/server.d.ts +52 -0
  77. package/dist/host/src/rpc/server.js +293 -0
  78. package/dist/host/src/rpc/server.js.map +1 -0
  79. package/dist/host/src/screen.d.ts +30 -0
  80. package/dist/host/src/screen.js +230 -0
  81. package/dist/host/src/screen.js.map +1 -0
  82. package/dist/host/src/shell-env.d.ts +8 -0
  83. package/dist/host/src/shell-env.js +39 -0
  84. package/dist/host/src/shell-env.js.map +1 -0
  85. package/dist/host/src/store.d.ts +75 -0
  86. package/dist/host/src/store.js +265 -0
  87. package/dist/host/src/store.js.map +1 -0
  88. package/dist/host/src/terminals.d.ts +55 -0
  89. package/dist/host/src/terminals.js +367 -0
  90. package/dist/host/src/terminals.js.map +1 -0
  91. package/dist/shared-protocol/src/index.d.ts +3345 -3345
  92. package/dist/wire/src/crypto.d.ts +65 -0
  93. package/dist/wire/src/crypto.js +253 -0
  94. package/dist/wire/src/crypto.js.map +1 -0
  95. package/dist/wire/src/index.d.ts +8 -0
  96. package/dist/wire/src/index.js +9 -0
  97. package/dist/wire/src/index.js.map +1 -0
  98. package/dist/wire/src/model.d.ts +704 -0
  99. package/dist/wire/src/model.js +163 -0
  100. package/dist/wire/src/model.js.map +1 -0
  101. package/dist/wire/src/peer.d.ts +42 -0
  102. package/dist/wire/src/peer.js +143 -0
  103. package/dist/wire/src/peer.js.map +1 -0
  104. package/dist/wire/src/relay-client.d.ts +82 -0
  105. package/dist/wire/src/relay-client.js +259 -0
  106. package/dist/wire/src/relay-client.js.map +1 -0
  107. package/dist/wire/src/relay.d.ts +481 -0
  108. package/dist/wire/src/relay.js +129 -0
  109. package/dist/wire/src/relay.js.map +1 -0
  110. package/dist/wire/src/rpc.d.ts +4170 -0
  111. package/dist/wire/src/rpc.js +332 -0
  112. package/dist/wire/src/rpc.js.map +1 -0
  113. package/dist/wire/src/shell.d.ts +2 -0
  114. package/dist/wire/src/shell.js +62 -0
  115. package/dist/wire/src/shell.js.map +1 -0
  116. package/dist/wire/src/updates.d.ts +3325 -0
  117. package/dist/wire/src/updates.js +210 -0
  118. package/dist/wire/src/updates.js.map +1 -0
  119. package/package.json +8 -3
  120. package/src/commands/host.ts +297 -0
  121. package/src/commands/pair.ts +52 -0
  122. package/src/index.ts +74 -0
  123. package/src/utils/daemon.ts +4 -3
  124. package/dist/cli/src/commands/hook.d.ts +0 -6
  125. package/dist/cli/src/commands/hook.js +0 -120
  126. package/dist/cli/src/commands/hook.js.map +0 -1
  127. package/dist/cli/src/runtime/acp/agent-workspace-git.d.ts +0 -63
  128. package/dist/cli/src/runtime/acp/agent-workspace-git.js +0 -297
  129. package/dist/cli/src/runtime/acp/agent-workspace-git.js.map +0 -1
  130. package/dist/cli/src/runtime/acp-relay.d.ts +0 -23
  131. package/dist/cli/src/runtime/acp-relay.js +0 -73
  132. package/dist/cli/src/runtime/acp-relay.js.map +0 -1
  133. package/dist/cli/src/runtime/hook-permission-server.d.ts +0 -36
  134. package/dist/cli/src/runtime/hook-permission-server.js +0 -147
  135. package/dist/cli/src/runtime/hook-permission-server.js.map +0 -1
@@ -0,0 +1,61 @@
1
+ import { type RpcId } from "@linkshell/wire";
2
+ /** The subset of ACP `initialize` results LinkShell reads. */
3
+ export interface AcpAgentCapabilities {
4
+ loadSession?: boolean;
5
+ promptCapabilities?: {
6
+ image?: boolean;
7
+ audio?: boolean;
8
+ embeddedContext?: boolean;
9
+ };
10
+ sessionCapabilities?: {
11
+ list?: unknown;
12
+ resume?: unknown;
13
+ close?: unknown;
14
+ fork?: unknown;
15
+ delete?: unknown;
16
+ };
17
+ _meta?: Record<string, unknown>;
18
+ }
19
+ export interface AcpInitializeResult {
20
+ protocolVersion?: number;
21
+ agentCapabilities?: AcpAgentCapabilities;
22
+ agentInfo?: {
23
+ name?: string;
24
+ version?: string;
25
+ };
26
+ authMethods?: {
27
+ id: string;
28
+ name?: string;
29
+ }[];
30
+ _meta?: Record<string, unknown>;
31
+ }
32
+ export interface AcpConnectionOptions {
33
+ command: string;
34
+ args: string[];
35
+ env?: NodeJS.ProcessEnv;
36
+ cwd?: string;
37
+ clientVersion: string;
38
+ onUpdate: (sessionId: string, update: unknown) => void;
39
+ /** Agent → client requests (session/request_permission, …). */
40
+ onRequest: (method: string, params: unknown, id: RpcId) => unknown;
41
+ onExit: (reason: string) => void;
42
+ }
43
+ /**
44
+ * One ACP agent subprocess: JSON-RPC 2.0 over newline-delimited stdio.
45
+ * A single process serves every session of that agent.
46
+ */
47
+ export declare class AcpConnection {
48
+ private readonly options;
49
+ private child?;
50
+ private peer?;
51
+ private stopping;
52
+ private stderrTail;
53
+ initializeResult: AcpInitializeResult;
54
+ constructor(options: AcpConnectionOptions);
55
+ get capabilities(): AcpAgentCapabilities;
56
+ get alive(): boolean;
57
+ start(): Promise<AcpInitializeResult>;
58
+ request<T>(method: string, params: unknown, timeoutMs?: number): Promise<T>;
59
+ notify(method: string, params: unknown): void;
60
+ stop(): Promise<void>;
61
+ }
@@ -0,0 +1,121 @@
1
+ import { spawn } from "node:child_process";
2
+ import { RpcPeer } from "@linkshell/wire";
3
+ /**
4
+ * One ACP agent subprocess: JSON-RPC 2.0 over newline-delimited stdio.
5
+ * A single process serves every session of that agent.
6
+ */
7
+ export class AcpConnection {
8
+ options;
9
+ child;
10
+ peer;
11
+ stopping = false;
12
+ stderrTail = "";
13
+ initializeResult = {};
14
+ constructor(options) {
15
+ this.options = options;
16
+ }
17
+ get capabilities() {
18
+ return this.initializeResult.agentCapabilities ?? {};
19
+ }
20
+ get alive() {
21
+ return Boolean(this.child && this.child.exitCode === null && !this.peer?.isClosed);
22
+ }
23
+ async start() {
24
+ this.stopping = false;
25
+ const child = spawn(this.options.command, this.options.args, {
26
+ env: this.options.env,
27
+ cwd: this.options.cwd,
28
+ stdio: ["pipe", "pipe", "pipe"],
29
+ });
30
+ this.child = child;
31
+ const peer = new RpcPeer({
32
+ send: (text) => {
33
+ if (child.stdin?.writable)
34
+ child.stdin.write(`${text}\n`);
35
+ },
36
+ onNotification: (method, params) => {
37
+ if (method !== "session/update")
38
+ return;
39
+ const payload = params;
40
+ if (typeof payload?.sessionId === "string")
41
+ this.options.onUpdate(payload.sessionId, payload.update);
42
+ },
43
+ onRequest: (method, params, id) => this.options.onRequest(method, params, id),
44
+ requestTimeoutMs: 0,
45
+ });
46
+ this.peer = peer;
47
+ // stdout chunks can split a JSON line; only hand complete lines to the peer.
48
+ let pending = "";
49
+ child.stdout?.on("data", (chunk) => {
50
+ pending += chunk.toString("utf8");
51
+ const end = pending.lastIndexOf("\n");
52
+ if (end < 0)
53
+ return;
54
+ const complete = pending.slice(0, end);
55
+ pending = pending.slice(end + 1);
56
+ peer.receive(complete);
57
+ });
58
+ child.stderr?.on("data", (chunk) => {
59
+ this.stderrTail = (this.stderrTail + chunk.toString("utf8")).slice(-4000);
60
+ });
61
+ const exited = new Promise((_, reject) => {
62
+ child.once("exit", (code, signal) => {
63
+ const reason = `${this.options.command} exited (${signal ?? code})${this.stderrTail ? `: ${this.stderrTail.trim().split("\n").slice(-3).join(" | ")}` : ""}`;
64
+ peer.close(reason);
65
+ if (!this.stopping)
66
+ this.options.onExit(reason);
67
+ reject(new Error(reason));
68
+ });
69
+ child.once("error", (error) => {
70
+ peer.close(error.message);
71
+ reject(error);
72
+ });
73
+ });
74
+ exited.catch(() => { });
75
+ this.initializeResult = await Promise.race([
76
+ peer.request("initialize", {
77
+ protocolVersion: 1,
78
+ // LinkShell doesn't serve files or terminals to the agent: agents use their own tools.
79
+ clientCapabilities: {
80
+ fs: { readTextFile: false, writeTextFile: false },
81
+ terminal: false,
82
+ // Ask adapters that support it (Claude's) to stream sub-agents' own
83
+ // messages and tool calls, each stamped with the spawning call.
84
+ _meta: { "subagent-transcript": true },
85
+ },
86
+ clientInfo: { name: "linkshell", title: "LinkShell", version: this.options.clientVersion },
87
+ }, 30_000),
88
+ exited,
89
+ ]);
90
+ return this.initializeResult;
91
+ }
92
+ request(method, params, timeoutMs = 60_000) {
93
+ if (!this.peer)
94
+ return Promise.reject(new Error("agent is not running"));
95
+ return this.peer.request(method, params, timeoutMs);
96
+ }
97
+ notify(method, params) {
98
+ this.peer?.notify(method, params);
99
+ }
100
+ async stop() {
101
+ this.stopping = true;
102
+ const child = this.child;
103
+ this.child = undefined;
104
+ this.peer?.close("stopping");
105
+ if (!child || child.exitCode !== null)
106
+ return;
107
+ child.stdin?.end();
108
+ child.kill("SIGTERM");
109
+ await new Promise((resolve) => {
110
+ const timer = setTimeout(() => {
111
+ child.kill("SIGKILL");
112
+ resolve();
113
+ }, 3000);
114
+ child.once("exit", () => {
115
+ clearTimeout(timer);
116
+ resolve();
117
+ });
118
+ });
119
+ }
120
+ }
121
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../../../../host/src/drivers/acp/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAc,MAAM,iBAAiB,CAAC;AAoCtD;;;GAGG;AACH,MAAM,OAAO,aAAa;IAOK;IANrB,KAAK,CAAgB;IACrB,IAAI,CAAW;IACf,QAAQ,GAAG,KAAK,CAAC;IACjB,UAAU,GAAG,EAAE,CAAC;IACxB,gBAAgB,GAAwB,EAAE,CAAC;IAE3C,YAA6B,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IAE9D,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,IAAI,EAAE,CAAC;IACvD,CAAC;IAED,IAAI,KAAK;QACP,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,CAAC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C;QACzE,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAI,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAe;QACpC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAC7B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI;YAAE,OAAO;QAC9C,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC;QACnB,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YAClC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC5B,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACtB,OAAO,EAAE,CAAC;YACZ,CAAC,EAAE,IAAI,CAAC,CAAC;YACT,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE;gBACtB,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,110 @@
1
+ import { type AgentAuth, type AgentCapabilities, type AgentTier, type ContentBlock, type SessionUpdate } from "@linkshell/wire";
2
+ import type { AgentDriver, AttachContext, DiscoveredSession, DriverHost, DriverStatus, HistoryItem } from "../types.js";
3
+ import { AcpConnection } from "./connection.js";
4
+ import { AcpItemTracker, type SourcedConfigOption } from "./mapper.js";
5
+ export interface AcpAgentSpec {
6
+ id: string;
7
+ label: string;
8
+ tier: AgentTier;
9
+ /** How to start the agent as an ACP server. */
10
+ command: string;
11
+ args: string[];
12
+ /** Detects the install; defaults to `<command> --version`. */
13
+ version?: {
14
+ command: string;
15
+ args: string[];
16
+ };
17
+ env?: Record<string, string>;
18
+ authStatus?: (env: NodeJS.ProcessEnv) => Promise<AgentAuth>;
19
+ /**
20
+ * Start the agent process with the host so its existing sessions show up
21
+ * (needs ACP session/list). Otherwise it starts on first use.
22
+ */
23
+ discover?: boolean;
24
+ }
25
+ interface PendingPrompt {
26
+ content: ContentBlock[];
27
+ clientMessageId: string;
28
+ }
29
+ export interface AcpSessionState {
30
+ cwd: string;
31
+ loaded: boolean;
32
+ tracker: AcpItemTracker;
33
+ config: SourcedConfigOption[];
34
+ /** Set while a session/load replays history. */
35
+ replaying?: SessionUpdate[];
36
+ turnActive: boolean;
37
+ /** session/prompt requests in flight; with steering, a turn spans several. */
38
+ inflight: number;
39
+ queue: PendingPrompt[];
40
+ permissions: Map<string, (outcome: unknown) => void>;
41
+ }
42
+ /** Turns agent failures into something a person can act on. */
43
+ export declare function describeAgentError(label: string, message: string): {
44
+ message: string;
45
+ hint?: string;
46
+ };
47
+ /**
48
+ * A generic Agent Client Protocol driver: one agent subprocess serving every
49
+ * session. Tier "remote" by default — LinkShell drives the agent, the desktop
50
+ * uses LinkShell's own UI. Subclasses add desktop handoff.
51
+ */
52
+ export declare class AcpDriver implements AgentDriver {
53
+ protected readonly spec: AcpAgentSpec;
54
+ protected readonly options: {
55
+ env?: NodeJS.ProcessEnv;
56
+ hostVersion: string;
57
+ };
58
+ readonly id: string;
59
+ readonly label: string;
60
+ readonly tier: AgentTier;
61
+ capabilities: AgentCapabilities;
62
+ protected host?: DriverHost;
63
+ protected connection?: AcpConnection;
64
+ protected current: DriverStatus;
65
+ protected readonly sessions: Map<string, AcpSessionState>;
66
+ private restartTimer?;
67
+ private restartDelay;
68
+ private stopped;
69
+ private nextPermissionId;
70
+ constructor(spec: AcpAgentSpec, options: {
71
+ env?: NodeJS.ProcessEnv;
72
+ hostVersion: string;
73
+ });
74
+ status(): DriverStatus;
75
+ protected get env(): NodeJS.ProcessEnv;
76
+ authStatus(): Promise<AgentAuth>;
77
+ start(host: DriverHost): Promise<DriverStatus>;
78
+ stop(): Promise<void>;
79
+ listSessions(limit: number): Promise<DiscoveredSession[]>;
80
+ createSession(options: {
81
+ cwd: string;
82
+ model?: string;
83
+ }): Promise<DiscoveredSession>;
84
+ attach(nativeId: string, context: AttachContext): Promise<HistoryItem[]>;
85
+ detach(nativeId: string): Promise<void>;
86
+ prompt(nativeId: string, content: ContentBlock[], clientMessageId: string): Promise<"started" | "steered" | "queued">;
87
+ cancel(nativeId: string): Promise<void>;
88
+ respondPermission(nativeId: string, requestId: string, optionId: string): Promise<void>;
89
+ setConfig(nativeId: string, optionId: string, value: string): Promise<void>;
90
+ protected detectVersion(): Promise<string | undefined>;
91
+ private booting?;
92
+ /** Starts the agent process once; concurrent callers share the attempt. */
93
+ protected ensureStarted(): Promise<void>;
94
+ protected boot(): Promise<void>;
95
+ private scheduleRestart;
96
+ private onExit;
97
+ protected stateFor(nativeId: string, cwd: string): AcpSessionState;
98
+ protected emitConfig(nativeId: string, state: AcpSessionState): void;
99
+ /** Feeds an update through the item tracker and on to the host. */
100
+ protected emit(nativeId: string, update: SessionUpdate): void;
101
+ protected closeMessage(nativeId: string): void;
102
+ protected onUpdate(sessionId: string, raw: unknown): void;
103
+ private onRequest;
104
+ private cancelPermissions;
105
+ private echoUserMessage;
106
+ protected startTurn(nativeId: string, state: AcpSessionState, content: ContentBlock[], clientMessageId: string): void;
107
+ private sendPrompt;
108
+ protected rpc<T = unknown>(method: string, params: unknown, timeoutMs?: number): Promise<T>;
109
+ }
110
+ export {};