@myagentroam/node 0.1.3 → 0.1.6
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/README.md +9 -1
- package/dist/capabilities.d.ts +2 -0
- package/dist/capabilities.js +15 -4
- package/dist/claude-agent-sdk.d.ts +4 -16
- package/dist/claude-agent-sdk.js +18 -79
- package/dist/claude-channel.js +0 -1
- package/dist/codex-app-server.d.ts +5 -0
- package/dist/codex-app-server.js +26 -5
- package/dist/config.d.ts +3 -0
- package/dist/config.js +18 -2
- package/dist/connector/node-connector-options.d.ts +26 -0
- package/dist/connector/node-connector-options.js +1 -0
- package/dist/connector/node-operation-router.d.ts +9 -0
- package/dist/connector/node-operation-router.js +22 -0
- package/dist/connector.d.ts +62 -356
- package/dist/connector.js +714 -6176
- package/dist/control-outbound-scheduler.d.ts +26 -0
- package/dist/control-outbound-scheduler.js +121 -0
- package/dist/database.d.ts +4 -0
- package/dist/database.js +15 -10
- package/dist/event-buffer.js +0 -1
- package/dist/fake-runner.js +0 -1
- package/dist/health.js +0 -1
- package/dist/main.js +6 -1
- package/dist/migrations/v001.js +0 -1
- package/dist/migrations/v002.js +0 -1
- package/dist/migrations/v003.d.ts +4 -0
- package/dist/migrations/v003.js +44 -0
- package/dist/native-jsonl-reader.d.ts +14 -0
- package/dist/native-jsonl-reader.js +97 -0
- package/dist/native-session-history.d.ts +41 -4
- package/dist/native-session-history.js +340 -159
- package/dist/opencode-runtime.d.ts +33 -0
- package/dist/opencode-runtime.js +80 -0
- package/dist/opencode-server.d.ts +47 -0
- package/dist/opencode-server.js +250 -0
- package/dist/operational.js +10 -3
- package/dist/process-tree.js +0 -1
- package/dist/runner/abstract-runner.d.ts +153 -0
- package/dist/runner/abstract-runner.js +154 -0
- package/dist/runner/claude/managed-run-controller.d.ts +52 -0
- package/dist/runner/claude/managed-run-controller.js +326 -0
- package/dist/runner/claude-code-runner.d.ts +70 -0
- package/dist/runner/claude-code-runner.js +286 -0
- package/dist/runner/codex/conversation-parser.d.ts +59 -0
- package/dist/runner/codex/conversation-parser.js +816 -0
- package/dist/runner/codex/managed-run-controller.d.ts +80 -0
- package/dist/runner/codex/managed-run-controller.js +388 -0
- package/dist/runner/codex-runner.d.ts +85 -0
- package/dist/runner/codex-runner.js +365 -0
- package/dist/runner/fake-test-runner.d.ts +26 -0
- package/dist/runner/fake-test-runner.js +47 -0
- package/dist/runner/opencode/conversation-parser.d.ts +27 -0
- package/dist/runner/opencode/conversation-parser.js +217 -0
- package/dist/runner/opencode/managed-run-controller.d.ts +76 -0
- package/dist/runner/opencode/managed-run-controller.js +451 -0
- package/dist/runner/opencode-runner.d.ts +60 -0
- package/dist/runner/opencode-runner.js +330 -0
- package/dist/runner/runner-registry.d.ts +19 -0
- package/dist/runner/runner-registry.js +75 -0
- package/dist/runner-command-engine.js +0 -1
- package/dist/runner-profiles.d.ts +4 -0
- package/dist/runner-profiles.js +76 -3
- package/dist/runner-usage.d.ts +2 -2
- package/dist/runner-usage.js +3 -6
- package/dist/runtime-state.js +26 -14
- package/dist/service/attachment-domain-state.d.ts +5 -0
- package/dist/service/attachment-domain-state.js +5 -0
- package/dist/service/conversation-history-service.d.ts +34 -0
- package/dist/service/conversation-history-service.js +158 -0
- package/dist/service/external-session-resume-service.d.ts +32 -0
- package/dist/service/external-session-resume-service.js +98 -0
- package/dist/service/fake-managed-run-service.d.ts +29 -0
- package/dist/service/fake-managed-run-service.js +62 -0
- package/dist/service/managed-runner-session-service.d.ts +12 -0
- package/dist/service/managed-runner-session-service.js +35 -0
- package/dist/service/native-session-projection-service.d.ts +51 -0
- package/dist/service/native-session-projection-service.js +271 -0
- package/dist/service/native-session-watch-service.d.ts +37 -0
- package/dist/service/native-session-watch-service.js +150 -0
- package/dist/service/node-connection-lifecycle-service.d.ts +37 -0
- package/dist/service/node-connection-lifecycle-service.js +85 -0
- package/dist/service/node-control-channel.d.ts +32 -0
- package/dist/service/node-control-channel.js +85 -0
- package/dist/service/node-control-message-service.d.ts +28 -0
- package/dist/service/node-control-message-service.js +104 -0
- package/dist/service/node-request-service.d.ts +14 -0
- package/dist/service/node-request-service.js +50 -0
- package/dist/service/node-run-event-bridge.d.ts +40 -0
- package/dist/service/node-run-event-bridge.js +83 -0
- package/dist/service/node-terminal-channel.d.ts +29 -0
- package/dist/service/node-terminal-channel.js +182 -0
- package/dist/service/node-upgrade-coordinator.d.ts +29 -0
- package/dist/service/node-upgrade-coordinator.js +137 -0
- package/dist/service/node-workspace-coordinator.d.ts +32 -0
- package/dist/service/node-workspace-coordinator.js +80 -0
- package/dist/service/run-attachment-service.d.ts +37 -0
- package/dist/service/run-attachment-service.js +160 -0
- package/dist/service/run-domain-state.d.ts +4 -0
- package/dist/service/run-domain-state.js +4 -0
- package/dist/service/run-event-service.d.ts +31 -0
- package/dist/service/run-event-service.js +102 -0
- package/dist/service/run-workbench-service.d.ts +27 -0
- package/dist/service/run-workbench-service.js +113 -0
- package/dist/service/runner-channel-message-service.d.ts +13 -0
- package/dist/service/runner-channel-message-service.js +20 -0
- package/dist/service/runner-interaction-service.d.ts +40 -0
- package/dist/service/runner-interaction-service.js +246 -0
- package/dist/service/runner-service.d.ts +44 -0
- package/dist/service/runner-service.js +68 -0
- package/dist/service/session-catalog-service.d.ts +45 -0
- package/dist/service/session-catalog-service.js +224 -0
- package/dist/service/session-command-service.d.ts +23 -0
- package/dist/service/session-command-service.js +69 -0
- package/dist/service/session-context-service.d.ts +34 -0
- package/dist/service/session-context-service.js +87 -0
- package/dist/service/session-domain-state.d.ts +8 -0
- package/dist/service/session-domain-state.js +8 -0
- package/dist/service/session-identity-service.d.ts +24 -0
- package/dist/service/session-identity-service.js +86 -0
- package/dist/service/session-lifecycle-service.d.ts +31 -0
- package/dist/service/session-lifecycle-service.js +242 -0
- package/dist/service/session-message-service.d.ts +33 -0
- package/dist/service/session-message-service.js +157 -0
- package/dist/service/session-presentation-service.d.ts +33 -0
- package/dist/service/session-presentation-service.js +36 -0
- package/dist/service/session-query-service.d.ts +31 -0
- package/dist/service/session-query-service.js +77 -0
- package/dist/service/terminal-relay-state.d.ts +6 -0
- package/dist/service/terminal-relay-state.js +3 -0
- package/dist/service/terminal-service.d.ts +12 -0
- package/dist/service/terminal-service.js +52 -0
- package/dist/service/workbench-event-service.d.ts +21 -0
- package/dist/service/workbench-event-service.js +53 -0
- package/dist/service/workbench-manifest-service.d.ts +89 -0
- package/dist/service/workbench-manifest-service.js +70 -0
- package/dist/service/workspace-change-service.d.ts +9 -0
- package/dist/service/workspace-change-service.js +86 -0
- package/dist/service/workspace-content-search-service.d.ts +14 -0
- package/dist/service/workspace-content-search-service.js +477 -0
- package/dist/service/workspace-domain-state.d.ts +75 -0
- package/dist/service/workspace-domain-state.js +40 -0
- package/dist/service/workspace-file-service.d.ts +17 -0
- package/dist/service/workspace-file-service.js +109 -0
- package/dist/service/workspace-queue-workbench-service.d.ts +55 -0
- package/dist/service/workspace-queue-workbench-service.js +226 -0
- package/dist/service/workspace-service.d.ts +15 -0
- package/dist/service/workspace-service.js +67 -0
- package/dist/service/workspace-session-service.d.ts +23 -0
- package/dist/service/workspace-session-service.js +139 -0
- package/dist/service/workspace-upload-service.d.ts +37 -0
- package/dist/service/workspace-upload-service.js +240 -0
- package/dist/service/workspace-watch-service.d.ts +18 -0
- package/dist/service/workspace-watch-service.js +120 -0
- package/dist/service/workspace-workbench-service.d.ts +47 -0
- package/dist/service/workspace-workbench-service.js +223 -0
- package/dist/service.js +2 -3
- package/dist/storage.js +0 -1
- package/dist/supervisor.d.ts +1 -0
- package/dist/supervisor.js +154 -0
- package/dist/terminal.d.ts +1 -0
- package/dist/terminal.js +1 -2
- package/dist/util/node-operation-parsers.d.ts +92 -0
- package/dist/util/node-operation-parsers.js +382 -0
- package/dist/util/runner-native-session-parsers.d.ts +72 -0
- package/dist/util/runner-native-session-parsers.js +381 -0
- package/dist/util/secret-environment.d.ts +1 -0
- package/dist/util/secret-environment.js +25 -0
- package/dist/workspace.d.ts +62 -2
- package/dist/workspace.js +539 -57
- package/package.json +3 -2
- package/dist/capabilities.js.map +0 -1
- package/dist/claude-agent-sdk.js.map +0 -1
- package/dist/claude-channel.js.map +0 -1
- package/dist/codex-app-server.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/connector.js.map +0 -1
- package/dist/database.js.map +0 -1
- package/dist/event-buffer.js.map +0 -1
- package/dist/fake-runner.js.map +0 -1
- package/dist/health.js.map +0 -1
- package/dist/main.js.map +0 -1
- package/dist/migrations/v001.js.map +0 -1
- package/dist/migrations/v002.js.map +0 -1
- package/dist/native-session-history.js.map +0 -1
- package/dist/operational.js.map +0 -1
- package/dist/process-tree.js.map +0 -1
- package/dist/runner-command-engine.js.map +0 -1
- package/dist/runner-profiles.js.map +0 -1
- package/dist/runner-usage.js.map +0 -1
- package/dist/runtime-state.js.map +0 -1
- package/dist/service.js.map +0 -1
- package/dist/storage.js.map +0 -1
- package/dist/terminal.js.map +0 -1
- package/dist/workspace.js.map +0 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
MyAgentRoam Node runtime CLI for Linux and Windows.
|
|
4
4
|
|
|
5
5
|
For third-party deployment, registration, Runner prerequisites, and automatic startup, see the
|
|
6
|
-
public **Node deployment and connection guide** at `/docs/
|
|
6
|
+
public **Node deployment and connection guide** at `/docs/deployment/node-installation` in your MyAgentRoam
|
|
7
7
|
Server Web Console. The same guide is also linked from **Settings → Node registration**.
|
|
8
8
|
|
|
9
9
|
## Requirements
|
|
@@ -31,4 +31,12 @@ npm install --global @myagentroam/node@latest
|
|
|
31
31
|
mar-node run --config /path/to/mar-node.json
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
Managed deployments should run the stable supervisor entrypoint instead:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
mar-node supervise --config /path/to/mar-node.json
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The supervisor only installs an exact version requested by an authenticated Server operation. It never follows the npm `latest` tag automatically.
|
|
41
|
+
|
|
34
42
|
The package contains only the executable and its runtime dependencies. It never includes Node configuration, credentials, SQLite data, workspaces, or Runner credentials.
|
package/dist/capabilities.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ export declare function unavailableCapabilities(): NodeCapabilities;
|
|
|
3
3
|
export declare function detectCapabilities(commands?: {
|
|
4
4
|
readonly codex?: string;
|
|
5
5
|
readonly claudeCode?: string;
|
|
6
|
+
readonly openCode?: string;
|
|
6
7
|
}): NodeCapabilities;
|
|
7
8
|
export declare function detectCapabilitiesAsync(commands?: {
|
|
8
9
|
readonly codex?: string;
|
|
9
10
|
readonly claudeCode?: string;
|
|
11
|
+
readonly openCode?: string;
|
|
10
12
|
}): Promise<NodeCapabilities>;
|
package/dist/capabilities.js
CHANGED
|
@@ -2,6 +2,7 @@ import { release, version } from 'node:os';
|
|
|
2
2
|
import nodePackage from '../package.json' with { type: 'json' };
|
|
3
3
|
import { probeClaudeCode, probeClaudeCodeAsync } from './claude-agent-sdk.js';
|
|
4
4
|
import { probeCodex, probeCodexAsync } from './codex-app-server.js';
|
|
5
|
+
import { probeOpenCode, probeOpenCodeAsync } from './opencode-runtime.js';
|
|
5
6
|
const nodeAppVersion = typeof nodePackage.version === 'string' ? nodePackage.version : 'unknown';
|
|
6
7
|
function reportedPlatform() {
|
|
7
8
|
return process.platform === 'win32' ? 'windows' : 'linux';
|
|
@@ -20,7 +21,8 @@ export function unavailableCapabilities() {
|
|
|
20
21
|
osVersion: version()
|
|
21
22
|
},
|
|
22
23
|
codex: { available: false },
|
|
23
|
-
claudeCode: { available: false }
|
|
24
|
+
claudeCode: { available: false },
|
|
25
|
+
openCode: { available: false }
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
28
|
export function detectCapabilities(commands = {}) {
|
|
@@ -29,6 +31,7 @@ export function detectCapabilities(commands = {}) {
|
|
|
29
31
|
}
|
|
30
32
|
const codex = probeCodex(commands.codex);
|
|
31
33
|
const claudeCode = probeClaudeCode(commands.claudeCode);
|
|
34
|
+
const openCode = probeOpenCode(commands.openCode);
|
|
32
35
|
return {
|
|
33
36
|
platform: reportedPlatform(),
|
|
34
37
|
architecture: process.arch,
|
|
@@ -45,6 +48,10 @@ export function detectCapabilities(commands = {}) {
|
|
|
45
48
|
claudeCode: {
|
|
46
49
|
available: claudeCode.available && claudeCode.compatible,
|
|
47
50
|
...(claudeCode.version === undefined ? {} : { version: claudeCode.version })
|
|
51
|
+
},
|
|
52
|
+
openCode: {
|
|
53
|
+
available: openCode.available && openCode.compatible,
|
|
54
|
+
...(openCode.version === undefined ? {} : { version: openCode.version })
|
|
48
55
|
}
|
|
49
56
|
};
|
|
50
57
|
}
|
|
@@ -52,9 +59,10 @@ export async function detectCapabilitiesAsync(commands = {}) {
|
|
|
52
59
|
if (process.platform !== 'win32' && process.platform !== 'linux') {
|
|
53
60
|
throw new Error('NODE_PLATFORM_UNSUPPORTED');
|
|
54
61
|
}
|
|
55
|
-
const [codex, claudeCode] = await Promise.all([
|
|
62
|
+
const [codex, claudeCode, openCode] = await Promise.all([
|
|
56
63
|
probeCodexAsync(commands.codex),
|
|
57
|
-
probeClaudeCodeAsync(commands.claudeCode)
|
|
64
|
+
probeClaudeCodeAsync(commands.claudeCode),
|
|
65
|
+
probeOpenCodeAsync(commands.openCode)
|
|
58
66
|
]);
|
|
59
67
|
return {
|
|
60
68
|
platform: reportedPlatform(),
|
|
@@ -72,7 +80,10 @@ export async function detectCapabilitiesAsync(commands = {}) {
|
|
|
72
80
|
claudeCode: {
|
|
73
81
|
available: claudeCode.available && claudeCode.compatible,
|
|
74
82
|
...(claudeCode.version === undefined ? {} : { version: claudeCode.version })
|
|
83
|
+
},
|
|
84
|
+
openCode: {
|
|
85
|
+
available: openCode.available && openCode.compatible,
|
|
86
|
+
...(openCode.version === undefined ? {} : { version: openCode.version })
|
|
75
87
|
}
|
|
76
88
|
};
|
|
77
89
|
}
|
|
78
|
-
//# sourceMappingURL=capabilities.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CanUseTool, type Options, type PermissionResult, type Query, type SDKMessage, type SDKSessionInfo, type SDKUserMessage, type SessionMessage } from '@anthropic-ai/claude-agent-sdk';
|
|
1
|
+
import { forkSession, type CanUseTool, type Options, type PermissionResult, type Query, type SDKMessage, type SDKSessionInfo, type SDKUserMessage, type SessionMessage } from '@anthropic-ai/claude-agent-sdk';
|
|
2
2
|
export interface ClaudeCodeProbe {
|
|
3
3
|
readonly available: boolean;
|
|
4
4
|
readonly compatible: boolean;
|
|
@@ -21,6 +21,7 @@ export interface ClaudeQueryInput {
|
|
|
21
21
|
readonly onPermission: CanUseTool;
|
|
22
22
|
readonly onMessage: (message: SDKMessage) => void;
|
|
23
23
|
readonly onChannelReply?: (content: string) => void;
|
|
24
|
+
readonly environment?: Readonly<Record<string, string>>;
|
|
24
25
|
}
|
|
25
26
|
/** Image blocks accepted by the Claude Agent SDK message input. */
|
|
26
27
|
export interface ClaudeImageAttachment {
|
|
@@ -31,20 +32,11 @@ export interface ClaudeRunHandle {
|
|
|
31
32
|
readonly completed: Promise<void>;
|
|
32
33
|
interrupt(): Promise<void>;
|
|
33
34
|
cancel(): void;
|
|
34
|
-
getContextUsage(): Promise<ClaudeContextUsage>;
|
|
35
35
|
}
|
|
36
36
|
/** A live, SDK-owned session accepts input only after the SDK consumes it. */
|
|
37
37
|
export interface ClaudeChannelRunHandle extends ClaudeRunHandle {
|
|
38
38
|
deliver(content: string): Promise<void>;
|
|
39
39
|
}
|
|
40
|
-
/** Normalized public portion of the official SDK context usage response. */
|
|
41
|
-
export interface ClaudeContextUsage {
|
|
42
|
-
readonly model: string;
|
|
43
|
-
readonly usedTokens: number;
|
|
44
|
-
readonly maxTokens: number;
|
|
45
|
-
readonly rawMaxTokens: number;
|
|
46
|
-
readonly percentage: number;
|
|
47
|
-
}
|
|
48
40
|
/** The small injectable surface prevents tests from depending on authentication. */
|
|
49
41
|
export interface ClaudeSdkBindings {
|
|
50
42
|
readonly query: (input: {
|
|
@@ -61,6 +53,7 @@ export interface ClaudeSdkBindings {
|
|
|
61
53
|
readonly getSessionMessages: (sessionId: string, options: {
|
|
62
54
|
readonly dir?: string;
|
|
63
55
|
}) => Promise<SessionMessage[]>;
|
|
56
|
+
readonly forkSession?: typeof forkSession;
|
|
64
57
|
}
|
|
65
58
|
/**
|
|
66
59
|
* Adapter for the supported Agent SDK APIs only. It neither parses nor writes
|
|
@@ -78,13 +71,8 @@ export declare class ClaudeAgentSdkAdapter {
|
|
|
78
71
|
private startWithPrompt;
|
|
79
72
|
listSessions(cwd: string): Promise<SDKSessionInfo[]>;
|
|
80
73
|
readSession(sessionId: string, cwd: string): Promise<SessionMessage[]>;
|
|
74
|
+
forkSession(sessionId: string, cwd: string, upToMessageId: string, title: string): Promise<string>;
|
|
81
75
|
sessionInfo(sessionId: string, cwd: string): Promise<SDKSessionInfo | undefined>;
|
|
82
|
-
/**
|
|
83
|
-
* Reads context occupancy through the SDK's control channel. The input
|
|
84
|
-
* iterable deliberately never yields a user message, so this does not add
|
|
85
|
-
* `/context` or any synthetic text to the native conversation.
|
|
86
|
-
*/
|
|
87
|
-
readContextUsage(sessionId: string, cwd: string): Promise<ClaudeContextUsage>;
|
|
88
76
|
/**
|
|
89
77
|
* The SDK publishes the authoritative, session-specific command list in its
|
|
90
78
|
* first system/init record. Keep the input stream empty and stop as soon as
|
package/dist/claude-agent-sdk.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { createSdkMcpServer, getSessionInfo, getSessionMessages, listSessions, query } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
+
import { createSdkMcpServer, forkSession, getSessionInfo, getSessionMessages, listSessions, query } from '@anthropic-ai/claude-agent-sdk';
|
|
3
3
|
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { minimalRunnerEnvironment, platformCliInvocation, runRunnerProbe } from './operational.js';
|
|
@@ -49,7 +49,14 @@ export class ClaudeAgentSdkAdapter {
|
|
|
49
49
|
prompt,
|
|
50
50
|
options: {
|
|
51
51
|
cwd: input.cwd,
|
|
52
|
-
|
|
52
|
+
// Claude SDK defaults CLAUDE_CODE_ENTRYPOINT to sdk-ts. Keep the
|
|
53
|
+
// transcript discoverable by the same VS Code session filters used by
|
|
54
|
+
// the external Claude Code extension.
|
|
55
|
+
env: {
|
|
56
|
+
...minimalRunnerEnvironment(),
|
|
57
|
+
...input.environment,
|
|
58
|
+
CLAUDE_CODE_ENTRYPOINT: 'claude-vscode'
|
|
59
|
+
},
|
|
53
60
|
...(input.resumeSessionId === undefined ? {} : { resume: input.resumeSessionId }),
|
|
54
61
|
...(input.model === undefined || input.model === null ? {} : { model: input.model }),
|
|
55
62
|
...(isClaudeEffort(input.effort) ? { effort: input.effort } : {}),
|
|
@@ -68,9 +75,6 @@ export class ClaudeAgentSdkAdapter {
|
|
|
68
75
|
async interrupt() {
|
|
69
76
|
await stream.interrupt();
|
|
70
77
|
},
|
|
71
|
-
async getContextUsage() {
|
|
72
|
-
return normalizeContextUsage(await stream.getContextUsage());
|
|
73
|
-
},
|
|
74
78
|
cancel() {
|
|
75
79
|
abortController.abort();
|
|
76
80
|
stream.close();
|
|
@@ -86,59 +90,17 @@ export class ClaudeAgentSdkAdapter {
|
|
|
86
90
|
readSession(sessionId, cwd) {
|
|
87
91
|
return this.sdk.getSessionMessages(sessionId, { dir: cwd });
|
|
88
92
|
}
|
|
93
|
+
async forkSession(sessionId, cwd, upToMessageId, title) {
|
|
94
|
+
const result = await (this.sdk.forkSession ?? forkSession)(sessionId, {
|
|
95
|
+
dir: cwd,
|
|
96
|
+
upToMessageId,
|
|
97
|
+
title
|
|
98
|
+
});
|
|
99
|
+
return result.sessionId;
|
|
100
|
+
}
|
|
89
101
|
sessionInfo(sessionId, cwd) {
|
|
90
102
|
return this.sdk.getSessionInfo(sessionId, { dir: cwd });
|
|
91
103
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Reads context occupancy through the SDK's control channel. The input
|
|
94
|
-
* iterable deliberately never yields a user message, so this does not add
|
|
95
|
-
* `/context` or any synthetic text to the native conversation.
|
|
96
|
-
*/
|
|
97
|
-
async readContextUsage(sessionId, cwd) {
|
|
98
|
-
const abortController = new AbortController();
|
|
99
|
-
// 冷启动 Claude CLI 可能需要数秒加载本地 skills;3 秒会在控制响应
|
|
100
|
-
// 到达前主动中止,导致历史会话看似没有上下文。
|
|
101
|
-
const timeout = setTimeout(() => abortController.abort(), 15_000);
|
|
102
|
-
const emptyInput = {
|
|
103
|
-
async *[Symbol.asyncIterator]() {
|
|
104
|
-
await new Promise(() => undefined);
|
|
105
|
-
yield* [];
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
const stream = this.sdk.query({
|
|
109
|
-
prompt: emptyInput,
|
|
110
|
-
options: {
|
|
111
|
-
cwd,
|
|
112
|
-
env: minimalRunnerEnvironment(),
|
|
113
|
-
resume: sessionId,
|
|
114
|
-
abortController
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
// Claude 的控制请求由 Query 的事件循环驱动。即使不发送用户输入,
|
|
118
|
-
// 也必须消费该流,initialize/get_context_usage 才能收到 CLI 响应。
|
|
119
|
-
// 这个 drain 只读取 SDK 事件,emptyInput 永远不会产生一个 Turn。
|
|
120
|
-
const drain = (async () => {
|
|
121
|
-
try {
|
|
122
|
-
for await (const message of stream) {
|
|
123
|
-
void message;
|
|
124
|
-
// Context probe has no presentation events to project.
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
// Closing this short-lived control query aborts its read loop normally.
|
|
129
|
-
}
|
|
130
|
-
})();
|
|
131
|
-
try {
|
|
132
|
-
await stream.initializationResult();
|
|
133
|
-
return normalizeContextUsage(await stream.getContextUsage());
|
|
134
|
-
}
|
|
135
|
-
finally {
|
|
136
|
-
clearTimeout(timeout);
|
|
137
|
-
abortController.abort();
|
|
138
|
-
stream.close();
|
|
139
|
-
await drain;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
104
|
/**
|
|
143
105
|
* The SDK publishes the authoritative, session-specific command list in its
|
|
144
106
|
* first system/init record. Keep the input stream empty and stop as soon as
|
|
@@ -175,28 +137,6 @@ export class ClaudeAgentSdkAdapter {
|
|
|
175
137
|
}
|
|
176
138
|
}
|
|
177
139
|
}
|
|
178
|
-
function normalizeContextUsage(value) {
|
|
179
|
-
if (!Number.isFinite(value.totalTokens) ||
|
|
180
|
-
!Number.isInteger(value.totalTokens) ||
|
|
181
|
-
!Number.isFinite(value.maxTokens) ||
|
|
182
|
-
!Number.isInteger(value.maxTokens) ||
|
|
183
|
-
!Number.isFinite(value.rawMaxTokens) ||
|
|
184
|
-
!Number.isInteger(value.rawMaxTokens) ||
|
|
185
|
-
!Number.isFinite(value.percentage) ||
|
|
186
|
-
value.totalTokens < 0 ||
|
|
187
|
-
value.maxTokens <= 0 ||
|
|
188
|
-
value.rawMaxTokens <= 0 ||
|
|
189
|
-
typeof value.model !== 'string' ||
|
|
190
|
-
value.model.length === 0)
|
|
191
|
-
throw new Error('CLAUDE_CONTEXT_USAGE_INVALID');
|
|
192
|
-
return {
|
|
193
|
-
model: value.model,
|
|
194
|
-
usedTokens: value.totalTokens,
|
|
195
|
-
maxTokens: value.maxTokens,
|
|
196
|
-
rawMaxTokens: value.rawMaxTokens,
|
|
197
|
-
percentage: value.percentage
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
140
|
function isClaudeEffort(value) {
|
|
201
141
|
return (value === 'low' ||
|
|
202
142
|
value === 'medium' ||
|
|
@@ -216,7 +156,7 @@ function claudePermissionMode(access) {
|
|
|
216
156
|
function channelMcpServer(input) {
|
|
217
157
|
return createSdkMcpServer({
|
|
218
158
|
name: 'myagentroam',
|
|
219
|
-
version: '0.1.
|
|
159
|
+
version: '0.1.4',
|
|
220
160
|
instructions: 'Use the myagentroam_channel_reply tool only to send a concise reply to the Admin Channel.',
|
|
221
161
|
alwaysLoad: true,
|
|
222
162
|
tools: [
|
|
@@ -372,4 +312,3 @@ export async function probeClaudeCodeAsync(command = 'claude') {
|
|
|
372
312
|
export function denyPermission(message = 'USER_DECISION_REJECTED') {
|
|
373
313
|
return { behavior: 'deny', message };
|
|
374
314
|
}
|
|
375
|
-
//# sourceMappingURL=claude-agent-sdk.js.map
|
package/dist/claude-channel.js
CHANGED
|
@@ -40,6 +40,7 @@ export interface CodexAppServerOptions {
|
|
|
40
40
|
readonly socketPath?: string;
|
|
41
41
|
readonly spawnProcess?: (command: string, args: readonly string[], options: {
|
|
42
42
|
readonly cwd?: string;
|
|
43
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
43
44
|
}) => ChildProcessWithoutNullStreams;
|
|
44
45
|
}
|
|
45
46
|
export interface CodexRunConfiguration {
|
|
@@ -70,7 +71,10 @@ export declare class CodexAppServerClient {
|
|
|
70
71
|
private nextId;
|
|
71
72
|
private readonly pending;
|
|
72
73
|
private readonly notifications;
|
|
74
|
+
private environment;
|
|
73
75
|
constructor(options?: CodexAppServerOptions);
|
|
76
|
+
configureEnvironment(environment: Readonly<Record<string, string>>): void;
|
|
77
|
+
clearEnvironment(): void;
|
|
74
78
|
start(): Promise<void>;
|
|
75
79
|
stop(): void;
|
|
76
80
|
onNotification(listener: (notification: JsonRpcNotification) => void): () => void;
|
|
@@ -81,6 +85,7 @@ export declare class CodexAppServerClient {
|
|
|
81
85
|
listThreads(): Promise<unknown>;
|
|
82
86
|
listCollaborationModes(): Promise<unknown>;
|
|
83
87
|
readThread(threadId: string, includeTurns?: boolean): Promise<unknown>;
|
|
88
|
+
forkThread(threadId: string, cwd: string, lastTurnId: string, configuration?: CodexRunConfiguration): Promise<unknown>;
|
|
84
89
|
setThreadName(threadId: string, name: string): Promise<unknown>;
|
|
85
90
|
resumeThread(threadId: string, cwd: string, configuration?: CodexRunConfiguration): Promise<unknown>;
|
|
86
91
|
startTurn(threadId: string, text: string, cwd: string, configuration?: CodexRunConfiguration, attachments?: readonly Extract<CodexComposerInput, {
|
package/dist/codex-app-server.js
CHANGED
|
@@ -49,9 +49,20 @@ export class CodexAppServerClient {
|
|
|
49
49
|
nextId = 1;
|
|
50
50
|
pending = new Map();
|
|
51
51
|
notifications = new Set();
|
|
52
|
+
environment = {};
|
|
52
53
|
constructor(options = {}) {
|
|
53
54
|
this.options = options;
|
|
54
55
|
}
|
|
56
|
+
configureEnvironment(environment) {
|
|
57
|
+
if (this.child !== undefined)
|
|
58
|
+
throw new Error('CODEX_APP_SERVER_ALREADY_STARTED');
|
|
59
|
+
this.environment = { ...environment };
|
|
60
|
+
}
|
|
61
|
+
clearEnvironment() {
|
|
62
|
+
if (this.child !== undefined)
|
|
63
|
+
throw new Error('CODEX_APP_SERVER_ALREADY_STARTED');
|
|
64
|
+
this.environment = {};
|
|
65
|
+
}
|
|
55
66
|
async start() {
|
|
56
67
|
if (this.child !== undefined)
|
|
57
68
|
return;
|
|
@@ -66,7 +77,8 @@ export class CodexAppServerClient {
|
|
|
66
77
|
];
|
|
67
78
|
const spawnProcess = this.options.spawnProcess ?? defaultSpawn;
|
|
68
79
|
let child = spawnProcess(command, args, {
|
|
69
|
-
...(this.options.cwd === undefined ? {} : { cwd: this.options.cwd })
|
|
80
|
+
...(this.options.cwd === undefined ? {} : { cwd: this.options.cwd }),
|
|
81
|
+
env: { ...minimalRunnerEnvironment(), ...this.environment }
|
|
70
82
|
});
|
|
71
83
|
this.child = child;
|
|
72
84
|
let socket;
|
|
@@ -84,7 +96,8 @@ export class CodexAppServerClient {
|
|
|
84
96
|
await unlink(this.socketPath);
|
|
85
97
|
this.socketPath = undefined;
|
|
86
98
|
child = spawnProcess(command, baseArgs, {
|
|
87
|
-
...(this.options.cwd === undefined ? {} : { cwd: this.options.cwd })
|
|
99
|
+
...(this.options.cwd === undefined ? {} : { cwd: this.options.cwd }),
|
|
100
|
+
env: { ...minimalRunnerEnvironment(), ...this.environment }
|
|
88
101
|
});
|
|
89
102
|
this.child = child;
|
|
90
103
|
}
|
|
@@ -98,7 +111,7 @@ export class CodexAppServerClient {
|
|
|
98
111
|
this.failAll(new Error('CODEX_APP_SERVER_EXITED'));
|
|
99
112
|
});
|
|
100
113
|
await this.request('initialize', {
|
|
101
|
-
clientInfo: { name: '
|
|
114
|
+
clientInfo: { name: 'codex_vscode', title: 'MyAgentRoam', version: '0.1.4' },
|
|
102
115
|
capabilities: { experimentalApi: true }
|
|
103
116
|
});
|
|
104
117
|
this.notify('initialized', {});
|
|
@@ -160,6 +173,14 @@ export class CodexAppServerClient {
|
|
|
160
173
|
readThread(threadId, includeTurns = true) {
|
|
161
174
|
return this.request('thread/read', { threadId, includeTurns });
|
|
162
175
|
}
|
|
176
|
+
forkThread(threadId, cwd, lastTurnId, configuration = {}) {
|
|
177
|
+
return this.request('thread/fork', {
|
|
178
|
+
threadId,
|
|
179
|
+
lastTurnId,
|
|
180
|
+
cwd,
|
|
181
|
+
...codexThreadConfiguration(cwd, configuration)
|
|
182
|
+
});
|
|
183
|
+
}
|
|
163
184
|
setThreadName(threadId, name) {
|
|
164
185
|
return this.request('thread/name/set', { threadId, name });
|
|
165
186
|
}
|
|
@@ -340,7 +361,8 @@ function defaultSpawn(command, args, options) {
|
|
|
340
361
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
341
362
|
shell: false,
|
|
342
363
|
windowsHide: true,
|
|
343
|
-
...(options.cwd === undefined ? {} : { cwd: options.cwd })
|
|
364
|
+
...(options.cwd === undefined ? {} : { cwd: options.cwd }),
|
|
365
|
+
...(options.env === undefined ? {} : { env: options.env })
|
|
344
366
|
});
|
|
345
367
|
}
|
|
346
368
|
function stdioTransport(child) {
|
|
@@ -376,4 +398,3 @@ function connectUnix(socketPath, timeoutMs) {
|
|
|
376
398
|
attempt();
|
|
377
399
|
});
|
|
378
400
|
}
|
|
379
|
-
//# sourceMappingURL=codex-app-server.js.map
|
package/dist/config.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export interface NodeConfig {
|
|
|
7
7
|
readonly nodeId?: string;
|
|
8
8
|
readonly credential?: string;
|
|
9
9
|
readonly registrationToken?: string;
|
|
10
|
+
readonly upgrade?: {
|
|
11
|
+
readonly registryUrl?: string;
|
|
12
|
+
};
|
|
10
13
|
}
|
|
11
14
|
export declare function nodeConfigPath(): string;
|
|
12
15
|
export declare function loadNodeConfig(path?: string): Promise<NodeConfig>;
|
package/dist/config.js
CHANGED
|
@@ -21,6 +21,14 @@ export async function loadNodeConfig(path = nodeConfigPath()) {
|
|
|
21
21
|
const credential = optionalString('credential');
|
|
22
22
|
const registrationToken = optionalString('registrationToken');
|
|
23
23
|
const databasePath = optionalString('databasePath');
|
|
24
|
+
const upgradeInput = input['upgrade'];
|
|
25
|
+
if (upgradeInput !== undefined &&
|
|
26
|
+
(upgradeInput === null ||
|
|
27
|
+
typeof upgradeInput !== 'object' ||
|
|
28
|
+
Array.isArray(upgradeInput) ||
|
|
29
|
+
('registryUrl' in upgradeInput &&
|
|
30
|
+
typeof upgradeInput['registryUrl'] !== 'string')))
|
|
31
|
+
throw new Error('NODE_CONFIG_INVALID');
|
|
24
32
|
const allowedRoots = Array.isArray(input['allowedRoots'])
|
|
25
33
|
? input['allowedRoots']
|
|
26
34
|
: defaultAllowedRoots();
|
|
@@ -30,7 +38,16 @@ export async function loadNodeConfig(path = nodeConfigPath()) {
|
|
|
30
38
|
...(nodeId === undefined ? {} : { nodeId }),
|
|
31
39
|
...(credential === undefined ? {} : { credential }),
|
|
32
40
|
...(registrationToken === undefined ? {} : { registrationToken }),
|
|
33
|
-
...(databasePath === undefined ? {} : { databasePath })
|
|
41
|
+
...(databasePath === undefined ? {} : { databasePath }),
|
|
42
|
+
...(upgradeInput === undefined
|
|
43
|
+
? {}
|
|
44
|
+
: {
|
|
45
|
+
upgrade: {
|
|
46
|
+
...(upgradeInput['registryUrl'] === undefined
|
|
47
|
+
? {}
|
|
48
|
+
: { registryUrl: upgradeInput['registryUrl'] })
|
|
49
|
+
}
|
|
50
|
+
})
|
|
34
51
|
};
|
|
35
52
|
}
|
|
36
53
|
/** Uses the Node service account's scope when no Workspace roots are configured. */
|
|
@@ -48,4 +65,3 @@ export async function saveNodeConfig(config, path = nodeConfigPath()) {
|
|
|
48
65
|
await chmod(path, 0o600);
|
|
49
66
|
}
|
|
50
67
|
}
|
|
51
|
-
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { NodeCapabilities } from '@myagentroam/protocol';
|
|
2
|
+
import type { ClaudeAgentSdkAdapter } from '../claude-agent-sdk.js';
|
|
3
|
+
import type { CodexAppServerClient } from '../codex-app-server.js';
|
|
4
|
+
import type { NodeConfig } from '../config.js';
|
|
5
|
+
import type { NodeDatabase } from '../database.js';
|
|
6
|
+
import type { FakeRunner, FakeRunnerStep } from '../fake-runner.js';
|
|
7
|
+
import type { RunnerUsageReader } from '../runner-usage.js';
|
|
8
|
+
import type { TerminalManager } from '../terminal.js';
|
|
9
|
+
import type { OpenCodeServerClient } from '../opencode-server.js';
|
|
10
|
+
export interface NodeConnectorOptions {
|
|
11
|
+
readonly configPath?: string;
|
|
12
|
+
readonly config?: NodeConfig;
|
|
13
|
+
readonly capabilities?: NodeCapabilities;
|
|
14
|
+
readonly capabilityDetector?: () => NodeCapabilities | Promise<NodeCapabilities>;
|
|
15
|
+
readonly reconnect?: boolean;
|
|
16
|
+
readonly fakeRunner?: FakeRunner;
|
|
17
|
+
readonly fakeScript?: (input: unknown, runId: string) => readonly FakeRunnerStep[];
|
|
18
|
+
readonly codexClient?: CodexAppServerClient;
|
|
19
|
+
readonly claudeClient?: ClaudeAgentSdkAdapter;
|
|
20
|
+
readonly openCodeClient?: OpenCodeServerClient;
|
|
21
|
+
readonly database?: NodeDatabase;
|
|
22
|
+
readonly claudeApprovalTimeoutMs?: number;
|
|
23
|
+
readonly terminalManager?: TerminalManager;
|
|
24
|
+
readonly runnerUsageReader?: RunnerUsageReader;
|
|
25
|
+
readonly upgradeReady?: () => void;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type NodeOperationHandler = (data: unknown) => Promise<unknown> | unknown;
|
|
2
|
+
/** Exact allow-list dispatcher for protocol-defined Node operations. */
|
|
3
|
+
export declare class NodeOperationRouter {
|
|
4
|
+
private readonly handlers;
|
|
5
|
+
register(operation: string, handler: NodeOperationHandler): void;
|
|
6
|
+
registerAll(handlers: Readonly<Record<string, NodeOperationHandler>>): void;
|
|
7
|
+
has(operation: string): boolean;
|
|
8
|
+
execute(operation: string, data: unknown): Promise<unknown>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Exact allow-list dispatcher for protocol-defined Node operations. */
|
|
2
|
+
export class NodeOperationRouter {
|
|
3
|
+
handlers = new Map();
|
|
4
|
+
register(operation, handler) {
|
|
5
|
+
if (this.handlers.has(operation))
|
|
6
|
+
throw new Error(`NODE_OPERATION_ALREADY_REGISTERED:${operation}`);
|
|
7
|
+
this.handlers.set(operation, handler);
|
|
8
|
+
}
|
|
9
|
+
registerAll(handlers) {
|
|
10
|
+
for (const [operation, handler] of Object.entries(handlers))
|
|
11
|
+
this.register(operation, handler);
|
|
12
|
+
}
|
|
13
|
+
has(operation) {
|
|
14
|
+
return this.handlers.has(operation);
|
|
15
|
+
}
|
|
16
|
+
execute(operation, data) {
|
|
17
|
+
const handler = this.handlers.get(operation);
|
|
18
|
+
if (handler === undefined)
|
|
19
|
+
return Promise.reject(new Error('OPERATION_UNSUPPORTED'));
|
|
20
|
+
return Promise.resolve(handler(data));
|
|
21
|
+
}
|
|
22
|
+
}
|