@chatcode/chatcode-cli 3.0.6-rc.3 → 3.0.6-rc.4
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/package.json +21 -21
- package/runtime/manifest.json +2 -2
- package/runtime/node_modules/@chatcode/runtime-client/README.md +6 -6
- package/runtime/node_modules/@chatcode/runtime-client/desktop-history.mjs +49 -48
- package/runtime/node_modules/@chatcode/runtime-client/index.d.ts +4 -4
- package/runtime/node_modules/@chatcode/runtime-client/local-platform.mjs +81 -0
- package/runtime/node_modules/@chatcode/runtime-client/model-preferences.mjs +7 -12
- package/runtime/node_modules/@chatcode/runtime-client/package.json +4 -3
- package/runtime/node_modules/@chatcode/runtime-client/runtime-connector.mjs +12 -11
- package/runtime/node_modules/@deepseek-ai/dsh-client-ui-settings-account/lib/client.js +2 -2
- package/runtime/node_modules/@deepseek-ai/dsh-client-ui-settings-general/lib/client.js +1 -1
- package/runtime/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatcode/chatcode-cli",
|
|
3
3
|
"description": "ChatCode CLI: TUI-first coding agent, Web launcher, profiles, and legacy DSH-compatible plugins",
|
|
4
|
-
"version": "3.0.6-rc.
|
|
4
|
+
"version": "3.0.6-rc.4",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -95,47 +95,47 @@
|
|
|
95
95
|
"ajv": "^8.20.0",
|
|
96
96
|
"execa": "^10.0.0",
|
|
97
97
|
"ws": "8.21.0",
|
|
98
|
-
"@deepseek-ai/dsh-attachment-local": "0.1.7-rc.2",
|
|
99
|
-
"@deepseek-ai/dsh-agent": "0.1.7-rc.2",
|
|
100
98
|
"@deepseek-ai/dsh-acp": "0.1.7-rc.2",
|
|
101
|
-
"@deepseek-ai/dsh-
|
|
99
|
+
"@deepseek-ai/dsh-agent": "0.1.7-rc.2",
|
|
102
100
|
"@deepseek-ai/dsh-agent-loop-testkit": "0.1.7-rc.2",
|
|
101
|
+
"@deepseek-ai/dsh-agent-loop": "0.1.7-rc.2",
|
|
102
|
+
"@deepseek-ai/dsh-attachment-local": "0.1.7-rc.2",
|
|
103
|
+
"@deepseek-ai/dsh-bash-local": "0.1.7-rc.2",
|
|
103
104
|
"@deepseek-ai/dsh-experimental-agent-team": "0.1.7-rc.2",
|
|
104
105
|
"@deepseek-ai/dsh-deepseek-llm-api-extensions": "0.1.7-rc.2",
|
|
105
|
-
"@deepseek-ai/dsh-agent-loop": "0.1.7-rc.2",
|
|
106
|
-
"@deepseek-ai/dsh-experimental-tool-agent-team": "0.1.7-rc.2",
|
|
107
|
-
"@deepseek-ai/dsh-fs-observation-policy": "0.1.7-rc.2",
|
|
108
106
|
"@deepseek-ai/dsh-experimental-ptc-runtime-python": "0.1.7-rc.2",
|
|
109
|
-
"@deepseek-ai/dsh-
|
|
107
|
+
"@deepseek-ai/dsh-experimental-tool-agent-team": "0.1.7-rc.2",
|
|
110
108
|
"@deepseek-ai/dsh-fs-sandbox": "0.1.7-rc.2",
|
|
109
|
+
"@deepseek-ai/dsh-fs-observation-policy": "0.1.7-rc.2",
|
|
111
110
|
"@deepseek-ai/dsh-host-frontend-static": "0.1.7-rc.2",
|
|
112
|
-
"@deepseek-ai/dsh-
|
|
111
|
+
"@deepseek-ai/dsh-host-webserver": "0.1.7-rc.2",
|
|
113
112
|
"@deepseek-ai/dsh-llm-deepseek-api-key": "0.1.7-rc.2",
|
|
114
|
-
"@deepseek-ai/dsh-llm-deepseek": "0.1.7-rc.2",
|
|
115
113
|
"@deepseek-ai/dsh-llm": "0.1.7-rc.2",
|
|
114
|
+
"@deepseek-ai/dsh-llm-deepseek": "0.1.7-rc.2",
|
|
115
|
+
"@deepseek-ai/dsh-llm-mock-server": "0.1.7-rc.2",
|
|
116
|
+
"@deepseek-ai/dsh-llm-deepseek-account": "0.1.7-rc.2",
|
|
116
117
|
"@deepseek-ai/dsh-llm-pi-ai": "0.1.7-rc.2",
|
|
117
|
-
"@deepseek-ai/dsh-plugin-package-inventory-deepseek": "0.1.7-rc.2",
|
|
118
118
|
"@deepseek-ai/dsh-llm-replay": "0.1.7-rc.2",
|
|
119
119
|
"@deepseek-ai/dsh-sdk-client": "0.1.7-rc.2",
|
|
120
|
-
"@deepseek-ai/dsh-sandbox-local": "0.1.7-rc.2",
|
|
121
120
|
"@deepseek-ai/dsh-loader-smoke": "0.1.7-rc.2",
|
|
122
121
|
"@deepseek-ai/dsh-sandbox-policy": "0.1.7-rc.2",
|
|
122
|
+
"@deepseek-ai/dsh-sandbox-local": "0.1.7-rc.2",
|
|
123
|
+
"@deepseek-ai/dsh-credentials-local": "0.1.7-rc.2",
|
|
124
|
+
"@deepseek-ai/dsh-plugin-package-inventory-deepseek": "0.1.7-rc.2",
|
|
123
125
|
"@deepseek-ai/dsh-session": "0.1.7-rc.2",
|
|
124
|
-
"@deepseek-ai/dsh-session-
|
|
126
|
+
"@deepseek-ai/dsh-session-checkpoint-policy": "0.1.7-rc.2",
|
|
125
127
|
"@deepseek-ai/dsh-session-log-deepseek": "0.1.7-rc.2",
|
|
126
|
-
"@deepseek-ai/dsh-
|
|
127
|
-
"@deepseek-ai/dsh-settings": "0.1.7-rc.2",
|
|
128
|
+
"@deepseek-ai/dsh-session-persistence-jsonl": "0.1.7-rc.2",
|
|
128
129
|
"@deepseek-ai/dsh-shell-env": "0.1.7-rc.2",
|
|
129
|
-
"@deepseek-ai/dsh-
|
|
130
|
+
"@deepseek-ai/dsh-session-query": "0.1.7-rc.2",
|
|
131
|
+
"@deepseek-ai/dsh-settings": "0.1.7-rc.2",
|
|
130
132
|
"@deepseek-ai/dsh-subagent": "0.1.7-rc.2",
|
|
131
|
-
"@deepseek-ai/dsh-
|
|
132
|
-
"@deepseek-ai/dsh-
|
|
133
|
-
"@deepseek-ai/dsh-llm-mock-server": "0.1.7-rc.2",
|
|
134
|
-
"@deepseek-ai/dsh-system-prompt": "0.1.7-rc.2",
|
|
133
|
+
"@deepseek-ai/dsh-subagent-fork-in-process": "0.1.7-rc.2",
|
|
134
|
+
"@deepseek-ai/dsh-subprocess-local": "0.1.7-rc.2",
|
|
135
135
|
"@deepseek-ai/dsh-subagent-spawn-in-process": "0.1.7-rc.2",
|
|
136
136
|
"@deepseek-ai/dsh-tools": "0.1.7-rc.2",
|
|
137
137
|
"@deepseek-ai/dsh-user-approval": "0.1.7-rc.2",
|
|
138
|
-
"@deepseek-ai/dsh-
|
|
138
|
+
"@deepseek-ai/dsh-system-prompt": "0.1.7-rc.2"
|
|
139
139
|
},
|
|
140
140
|
"exports": {
|
|
141
141
|
"./headless-compat": {
|
package/runtime/manifest.json
CHANGED
|
@@ -33,7 +33,7 @@ The application writes createIntegrationPatch(mode) to a file and passes its abs
|
|
|
33
33
|
|
|
34
34
|
```js
|
|
35
35
|
const { RuntimeConnector } = await import('@chatcode/runtime-client')
|
|
36
|
-
const runtime = new RuntimeConnector({ nodePath, launcherPath, home, patches: [patchPath] })
|
|
36
|
+
const runtime = new RuntimeConnector({ nodePath, launcherPath, home, patches: [patchPath], appCredentials: { appId, secret } })
|
|
37
37
|
await runtime.start()
|
|
38
38
|
const { sessionId } = await runtime.createSession({ cwd })
|
|
39
39
|
const off = await runtime.follow(sessionId, onFrame, onFailure)
|
|
@@ -44,13 +44,13 @@ The example’s paths, callbacks, stable requestId, and text come from the host.
|
|
|
44
44
|
|
|
45
45
|
Desktop execution views use `readAssistantContent` for separate body/reasoning, `readAssistantToolCalls` for partial arguments, and `readSessionActivity` for task-list replacements and parent-owned child catalogs. Follow verified children with `followAddress`; `toolCatalog(sessionId)` reads the actual scoped tools. Follow events retain native calls, results and nested PTC dispatches. Current tool results identify their call through `message.source.callId`; hosts preserve that identity and the original arguments when building cards. These projections add no model messages or authentication APIs.
|
|
46
46
|
|
|
47
|
-
Session callbacks receive snapshots, durable events, and assistant-stream frames. Convert these into the host’s message UI; readAssistantText only reconstructs body blocks. accepted means admission, and assistant-stream/end closes one model attempt rather than a whole turn. On transport loss, invalidate pending approvals and call reconnect() to obtain new baselines without resending prompts. off() detaches one conversation; cancel(sessionId) stops its active turn; await close() on application exit.
|
|
47
|
+
Unexpected Runtime exit notifies every active Session, Workspace, and interaction subscription with `runtime/exited`. Session callbacks receive snapshots, durable events, and assistant-stream frames. Convert these into the host’s message UI; readAssistantText only reconstructs body blocks. accepted means admission, and assistant-stream/end closes one model attempt rather than a whole turn. On transport loss, invalidate pending approvals and call reconnect() to obtain new baselines without resending prompts. off() detaches one conversation; cancel(sessionId) stops its active turn; await close() on application exit.
|
|
48
48
|
|
|
49
49
|
ChatCode account authentication is separate from tool approvals and local HTTP cookie authentication. When the host already owns a validated ChatCode account, pass its token only in the subprocess env field as CHATCODE_CLI_OAUTH_TOKEN. The host owns token validation, renewal, logout, and account isolation; restart the Connector after changing the token. This SDK version does not expose account login, status, or logout APIs. Neither createIntegrationPatch mode disables account authentication.
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
Every `new RuntimeConnector(options)` requires `appCredentials: { appId, secret }` from the desktop backend. Omitting the option or either field, or supplying an empty value, throws `runtime/app-credentials` before starting a subprocess. Use 1 to 128 printable ASCII characters for the ID and 1 to 1024 for the secret, without spaces. If the backend reads the secret from an environment variable, omit that variable from the subprocess `env` option. A distributed SDK or installer cannot protect a shared long-lived secret. An installation can use a credential provisioned separately by the operator or by an authorization service.
|
|
52
52
|
|
|
53
|
-
The SDK sends `X-ChatCode-App-Id` and `X-ChatCode-App-Secret` in the local launch token exchange and copies `appCredentials.appId` into each new Session. The Session log, creation result, Session list and unified conversation report carry optional `appId`; resuming preserves the recorded value, including its absence on legacy Sessions.
|
|
53
|
+
The SDK sends `X-ChatCode-App-Id` and `X-ChatCode-App-Secret` in the local launch token exchange and copies `appCredentials.appId` into each new Session. The Session log, creation result, Session list and unified conversation report carry optional `appId`; resuming preserves the recorded value, including its absence on legacy Sessions. The Connector keeps both values in private memory; callers supply them once per Connector, not on each message. Subsequent HTTP requests and WebSocket subscriptions use the issued Cookie. The Runtime receives the secret only in the launch request and does not retain it in an application credential registry; it cannot retrieve the secret later from Session metadata. A new Connector requires both values again. Application credential verification is deferred. The launch exchange accepts the normal local cookie without an application acknowledgment, while HTTP 401/403 still reject startup. Secrets are excluded from Session metadata.
|
|
54
54
|
|
|
55
55
|
The current Web profile also checks ChatCode/CVP launch admission before binding HTTP. Both integration modes preserve this check. Prepare the Runtime’s required service access and credentials, then verify that its launcher starts; report admission failures as Runtime startup errors rather than tool approval requests.
|
|
56
56
|
|
|
@@ -102,7 +102,7 @@ Human questions are independent of tool approval mode. Both integration modes ca
|
|
|
102
102
|
|
|
103
103
|
### Desktop history handoff
|
|
104
104
|
|
|
105
|
-
The source package exposes `DesktopHistoryHost`, `createDesktopHistoryClient`, and `releaseSession`; published integration.1 lacks these additions. The host supplies verified account/configuration checks, discovery metadata, snapshot previews, exact native launch context, tool policy, and return synchronization. The CLI client discovers only running hosts through private Unix sockets and defers spawning until the current UI exits. The terminal uses a temporary configuration home with the original authoritative Session root; it retains the host-approved model routes, preset, directory, and account, disables both legacy and current automatic history import plus user asset discovery, and never copies credentials or replays the transcript. Keep the host running: account or host loss stops execution.
|
|
105
|
+
The source package exposes `DesktopHistoryHost`, `createDesktopHistoryClient`, and `releaseSession`; published integration.1 lacks these additions. The host supplies verified account/configuration checks, discovery metadata, snapshot previews, exact native launch context, tool policy, and return synchronization. The CLI client discovers only running hosts through local Windows named pipes or private Unix sockets on macOS/Linux, and defers spawning until the current UI exits. Windows uses Windows PowerShell to establish and verify current-user ownership and private Windows ACLs on discovery files, temporary homes, and shared model preferences; the filesystem must support Windows ACLs. Existing discovery directories must already be private. Unix keeps owner-only permission checks. The terminal uses a temporary configuration home with the original authoritative Session root; it retains the host-approved model routes, preset, directory, and account, disables both legacy and current automatic history import plus user asset discovery, and never copies credentials or replays the transcript. Keep the host running: account or host loss stops execution. Offline continuation is unsupported. The host must reject unsupported input, tools, policy modes, and changed tool arguments.
|
|
106
106
|
|
|
107
107
|
Call `releaseSession(sessionId)` only after completing or cancelling pending work. It drains a controller-owned idle Session and releases its native writer without stopping other Sessions; active work, foreign lifecycle ownership, or another process's writer rejects. Released identities reject implicit prompt admission until explicit `createSession({ cwd, sessionId })` resumes them. On return, probe release before activation, import events idempotently through the public snapshot/page APIs, and reject a nonempty native inbox instead of automatically replaying pending work.
|
|
108
108
|
|
|
@@ -124,7 +124,7 @@ Desktop AI workbenches that manage their own API keys and model catalog use the
|
|
|
124
124
|
|
|
125
125
|
**Typical desktop flow:**
|
|
126
126
|
```js
|
|
127
|
-
const runtime = new RuntimeConnector({ nodePath, launcherPath, home, patches: [patchPath] })
|
|
127
|
+
const runtime = new RuntimeConnector({ nodePath, launcherPath, home, patches: [patchPath], appCredentials: { appId, secret } })
|
|
128
128
|
await runtime.start()
|
|
129
129
|
|
|
130
130
|
// Optionally inject an OAuth login token
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
/** Local, single-writer handoff between a desktop host and the official terminal. */
|
|
2
2
|
import { spawn } from 'node:child_process'
|
|
3
3
|
import { createHash, randomUUID } from 'node:crypto'
|
|
4
|
-
import { chmod,
|
|
4
|
+
import { chmod, mkdir, mkdtemp, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises'
|
|
5
5
|
import { createServer, request } from 'node:http'
|
|
6
6
|
import { homedir, tmpdir } from 'node:os'
|
|
7
7
|
import { join } from 'node:path'
|
|
8
8
|
|
|
9
|
+
import { assertPrivateLocalEntry, ensurePrivateLocalDirectory, historySocketPath, sealPrivateLocalEntry } from './local-platform.mjs'
|
|
10
|
+
|
|
9
11
|
const MAX_BODY = 2 * 1024 * 1024
|
|
10
12
|
const errorMessage = error => error instanceof Error ? error.message : 'Desktop history unavailable'
|
|
11
13
|
const directoryOf = directory => directory ?? join(homedir(), '.chatcode-cli', 'desktop-history', 'v1')
|
|
12
14
|
const keyOf = (hostId, sessionId) => `desktop-history:${hostId}:${encodeURIComponent(sessionId)}`
|
|
13
15
|
|
|
14
|
-
async function privateEntry(path, directory = false) {
|
|
15
|
-
const stat = await lstat(path)
|
|
16
|
-
if (stat.isSymbolicLink() || (directory ? !stat.isDirectory() : !stat.isFile())
|
|
17
|
-
|| (process.getuid && stat.uid !== process.getuid()) || (stat.mode & 0o077) !== 0) {
|
|
18
|
-
throw new Error('Desktop history discovery requires private, user-owned files')
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
16
|
/** Request the local host over its private socket; credentials never enter discovery records. */
|
|
23
17
|
export function desktopHistoryRequest(socketPath, body, timeoutMs = 10000) {
|
|
24
18
|
return new Promise((resolve, reject) => {
|
|
@@ -45,6 +39,7 @@ export function desktopHistoryRequest(socketPath, body, timeoutMs = 10000) {
|
|
|
45
39
|
export class DesktopHistoryHost {
|
|
46
40
|
#server
|
|
47
41
|
#temporary
|
|
42
|
+
#socketPath
|
|
48
43
|
#record
|
|
49
44
|
#reservations = new Map()
|
|
50
45
|
#closing = false
|
|
@@ -54,43 +49,49 @@ export class DesktopHistoryHost {
|
|
|
54
49
|
|
|
55
50
|
async start() {
|
|
56
51
|
if (this.#server) return
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
52
|
+
if (this.#closing) throw new Error('Desktop history host is closed; create a new host')
|
|
53
|
+
try {
|
|
54
|
+
const directory = directoryOf(this.options.directory)
|
|
55
|
+
await ensurePrivateLocalDirectory(directory)
|
|
56
|
+
this.#temporary = await mkdtemp(join(tmpdir(), 'chatcode-history-'))
|
|
57
|
+
await sealPrivateLocalEntry(this.#temporary, true)
|
|
58
|
+
const socketPath = historySocketPath(this.#temporary)
|
|
59
|
+
this.#socketPath = socketPath
|
|
60
|
+
this.#server = createServer(async (req, res) => {
|
|
61
|
+
try {
|
|
62
|
+
if (req.method !== 'POST' || req.url !== '/') throw new Error('Unsupported desktop history request')
|
|
63
|
+
let text = ''
|
|
64
|
+
for await (const chunk of req) {
|
|
65
|
+
text += chunk
|
|
66
|
+
if (text.length > MAX_BODY) throw new Error('Desktop history request too large')
|
|
67
|
+
}
|
|
68
|
+
const result = await this.#dispatch(JSON.parse(text))
|
|
69
|
+
res.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(result))
|
|
70
|
+
} catch (error) {
|
|
71
|
+
res.writeHead(409, { 'content-type': 'application/json' }).end(JSON.stringify({ error: errorMessage(error) }))
|
|
71
72
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.#
|
|
80
|
-
this.#
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
73
|
+
})
|
|
74
|
+
await new Promise((resolve, reject) => {
|
|
75
|
+
this.#server.once('error', reject)
|
|
76
|
+
this.#server.listen(socketPath, resolve)
|
|
77
|
+
})
|
|
78
|
+
if (process.platform !== 'win32') await chmod(socketPath, 0o600)
|
|
79
|
+
const hostId = createHash('sha256').update(this.options.hostId).digest('hex')
|
|
80
|
+
this.#record = join(directory, `${hostId}.json`)
|
|
81
|
+
const temporary = `${this.#record}.${randomUUID()}.tmp`
|
|
82
|
+
await writeFile(temporary, JSON.stringify({ v: 1, hostId, socketPath, pid: process.pid }), { mode: 0o600 })
|
|
83
|
+
await sealPrivateLocalEntry(temporary)
|
|
84
|
+
await rename(temporary, this.#record)
|
|
85
|
+
this.#timer = setInterval(() => {
|
|
86
|
+
for (const [sessionId, lease] of this.#reservations) {
|
|
87
|
+
if (lease.phase !== 'preparing' && lease.expiresAt <= Date.now()) void this.#finish(sessionId, lease).catch(() => {})
|
|
88
|
+
}
|
|
89
|
+
}, 1000)
|
|
90
|
+
this.#timer.unref()
|
|
91
|
+
} catch (error) {
|
|
92
|
+
await this.close()
|
|
93
|
+
throw error
|
|
94
|
+
}
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
/** Reports a reservation, including revoked ownership awaiting return synchronization. */
|
|
@@ -129,7 +130,7 @@ export class DesktopHistoryHost {
|
|
|
129
130
|
config: { sessionId: body.sessionId, provider: launch.provider, model: launch.model, tools: launch.tools, allowedModels: launch.allowedModels } }] }]), { mode: 0o600 })
|
|
130
131
|
return { ...launch, home: terminalHome, patches: [...launch.patches, patchPath], env: { ...launch.env,
|
|
131
132
|
CHATCODE_CLI_TUI_SESSION_ROOT: join(launch.home, 'sessions'),
|
|
132
|
-
CHATCODE_DESKTOP_HISTORY_SOCKET:
|
|
133
|
+
CHATCODE_DESKTOP_HISTORY_SOCKET: this.#socketPath,
|
|
133
134
|
CHATCODE_DESKTOP_HISTORY_LEASE: lease.id }, leaseId: lease.id }
|
|
134
135
|
} catch (error) {
|
|
135
136
|
this.#reservations.delete(body.sessionId)
|
|
@@ -201,13 +202,13 @@ export function createDesktopHistoryClient(options = {}) {
|
|
|
201
202
|
async list() {
|
|
202
203
|
const directory = directoryOf(options.directory)
|
|
203
204
|
let files
|
|
204
|
-
try { await
|
|
205
|
+
try { await assertPrivateLocalEntry(directory, true); files = await readdir(directory) }
|
|
205
206
|
catch (error) { if (error.code === 'ENOENT') return []; throw error }
|
|
206
207
|
const rows = []
|
|
207
208
|
for (const file of files.filter(file => /^[a-f0-9]{64}\.json$/u.test(file))) {
|
|
208
209
|
try {
|
|
209
210
|
const path = join(directory, file)
|
|
210
|
-
await
|
|
211
|
+
await assertPrivateLocalEntry(path)
|
|
211
212
|
const record = JSON.parse(await readFile(path, 'utf8'))
|
|
212
213
|
if (record.v !== 1 || `${record.hostId}.json` !== file || typeof record.socketPath !== 'string') continue
|
|
213
214
|
const result = await desktopHistoryRequest(record.socketPath, { op: 'list' }, 3000)
|
|
@@ -39,8 +39,8 @@ export interface RuntimeOptions {
|
|
|
39
39
|
home: string
|
|
40
40
|
patches?: string[]
|
|
41
41
|
env?: Record<string, string | undefined>
|
|
42
|
-
/**
|
|
43
|
-
appCredentials
|
|
42
|
+
/** Required application metadata, supplied once per Connector; Runtime verification is deferred. */
|
|
43
|
+
appCredentials: RuntimeAppCredentials
|
|
44
44
|
processCwd?: string
|
|
45
45
|
startupTimeoutMs?: number
|
|
46
46
|
requestTimeoutMs?: number
|
|
@@ -79,7 +79,7 @@ export interface DesktopHistoryEntry {
|
|
|
79
79
|
provider: string
|
|
80
80
|
model: string
|
|
81
81
|
}
|
|
82
|
-
/** Desktop-owned launch context, transferred only over a private local
|
|
82
|
+
/** Desktop-owned launch context, transferred only over a private local IPC endpoint. */
|
|
83
83
|
export interface DesktopHistoryLaunch {
|
|
84
84
|
nodePath: string
|
|
85
85
|
launcherPath: string
|
|
@@ -136,7 +136,7 @@ export class AccountModelPreferences {
|
|
|
136
136
|
export class RuntimeConnector {
|
|
137
137
|
/** @param options - Explicit child-process paths, overlays, application credentials, and operation settings. */
|
|
138
138
|
constructor(options: RuntimeOptions)
|
|
139
|
-
/** Start once and authenticate. @returns Ready after cookie
|
|
139
|
+
/** Start once and authenticate. @returns Ready after the cookie exchange carrying application metadata; verification is deferred. */
|
|
140
140
|
start(): Promise<void>
|
|
141
141
|
/**
|
|
142
142
|
* Create or restore an owned Session.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** Local IPC names and private discovery files for Unix and Windows hosts. */
|
|
2
|
+
import { execFile } from 'node:child_process'
|
|
3
|
+
import { randomUUID } from 'node:crypto'
|
|
4
|
+
import { chmod, lstat, mkdir } from 'node:fs/promises'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { promisify } from 'node:util'
|
|
7
|
+
|
|
8
|
+
const execute = promisify(execFile)
|
|
9
|
+
const privateError = () => new Error('Local state requires private, user-owned files')
|
|
10
|
+
|
|
11
|
+
/** Choose a local named pipe on Windows or a filesystem socket on Unix. */
|
|
12
|
+
export function historySocketPath(directory, platform = process.platform) {
|
|
13
|
+
return platform === 'win32' ? `\\\\.\\pipe\\chatcode-history-${process.pid}-${randomUUID()}` : join(directory, 'host.sock')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Paths travel through the child environment, never PowerShell source interpolation.
|
|
17
|
+
const aclScript = `
|
|
18
|
+
$ErrorActionPreference = 'Stop'
|
|
19
|
+
$path = $env:CHATCODE_HISTORY_ACL_PATH
|
|
20
|
+
$seal = $env:CHATCODE_HISTORY_ACL_SEAL -eq '1'
|
|
21
|
+
$item = Get-Item -LiteralPath $path -Force
|
|
22
|
+
if (($item.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0) { throw 'Links are not allowed' }
|
|
23
|
+
$user = [Security.Principal.WindowsIdentity]::GetCurrent().User
|
|
24
|
+
$trusted = @($user.Value, 'S-1-5-18', 'S-1-5-32-544')
|
|
25
|
+
if ($seal) {
|
|
26
|
+
if ($item.PSIsContainer) {
|
|
27
|
+
$acl = [System.Security.AccessControl.DirectorySecurity]::new()
|
|
28
|
+
$inherit = [Security.AccessControl.InheritanceFlags]'ContainerInherit, ObjectInherit'
|
|
29
|
+
} else {
|
|
30
|
+
$acl = [System.Security.AccessControl.FileSecurity]::new()
|
|
31
|
+
$inherit = [Security.AccessControl.InheritanceFlags]::None
|
|
32
|
+
}
|
|
33
|
+
$acl.SetOwner($user)
|
|
34
|
+
$acl.SetAccessRuleProtection($true, $false)
|
|
35
|
+
foreach ($sid in $trusted) {
|
|
36
|
+
$identity = [System.Security.Principal.SecurityIdentifier]::new($sid)
|
|
37
|
+
$rule = [System.Security.AccessControl.FileSystemAccessRule]::new($identity, 'FullControl', $inherit, 'None', 'Allow')
|
|
38
|
+
$acl.AddAccessRule($rule)
|
|
39
|
+
}
|
|
40
|
+
Set-Acl -LiteralPath $path -AclObject $acl
|
|
41
|
+
}
|
|
42
|
+
$acl = Get-Acl -LiteralPath $path
|
|
43
|
+
if ($acl.GetOwner([Security.Principal.SecurityIdentifier]).Value -ne $user.Value) { throw 'Unexpected owner' }
|
|
44
|
+
foreach ($rule in $acl.GetAccessRules($true, $true, [Security.Principal.SecurityIdentifier])) {
|
|
45
|
+
if ($rule.AccessControlType -eq 'Allow' -and $trusted -notcontains $rule.IdentityReference.Value) { throw 'Shared access is not allowed' }
|
|
46
|
+
}
|
|
47
|
+
`
|
|
48
|
+
|
|
49
|
+
async function windowsPrivacy(path, seal) {
|
|
50
|
+
try {
|
|
51
|
+
await execute('powershell.exe', ['-NoLogo', '-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(aclScript, 'utf16le').toString('base64')], {
|
|
52
|
+
windowsHide: true, timeout: 10000, maxBuffer: 16384,
|
|
53
|
+
env: { ...process.env, CHATCODE_HISTORY_ACL_PATH: path, CHATCODE_HISTORY_ACL_SEAL: seal ? '1' : '0' },
|
|
54
|
+
})
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new Error('Local state requires Windows PowerShell and private, user-owned Windows ACL-protected files', { cause: error })
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Refuse links and shared discovery entries using native ownership and access rules. */
|
|
61
|
+
export async function assertPrivateLocalEntry(path, directory = false) {
|
|
62
|
+
const stat = await lstat(path)
|
|
63
|
+
if (stat.isSymbolicLink() || (directory ? !stat.isDirectory() : !stat.isFile())) throw privateError()
|
|
64
|
+
if (process.platform === 'win32') return windowsPrivacy(path, false)
|
|
65
|
+
if ((process.getuid && stat.uid !== process.getuid()) || (stat.mode & 0o077) !== 0) throw privateError()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Secure a newly created host directory or discovery record before publishing it. */
|
|
69
|
+
export async function sealPrivateLocalEntry(path, directory = false) {
|
|
70
|
+
const stat = await lstat(path)
|
|
71
|
+
if (stat.isSymbolicLink() || (directory ? !stat.isDirectory() : !stat.isFile())) throw privateError()
|
|
72
|
+
if (process.platform === 'win32') return windowsPrivacy(path, true)
|
|
73
|
+
await chmod(path, directory ? 0o700 : 0o600)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Create the discovery directory privately; existing directories must already be private. */
|
|
77
|
+
export async function ensurePrivateLocalDirectory(directory) {
|
|
78
|
+
const created = await mkdir(directory, { recursive: true, mode: 0o700 })
|
|
79
|
+
if (created !== undefined) await sealPrivateLocalEntry(directory, true)
|
|
80
|
+
await assertPrivateLocalEntry(directory, true)
|
|
81
|
+
}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
/** Account-scoped model preferences shared by local desktop and terminal entry points. */
|
|
2
2
|
import { randomUUID } from 'node:crypto'
|
|
3
|
-
import {
|
|
3
|
+
import { readFile, rename, rm, writeFile } from 'node:fs/promises'
|
|
4
4
|
import { homedir } from 'node:os'
|
|
5
5
|
import { join } from 'node:path'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (stat.isSymbolicLink() || (directory ? !stat.isDirectory() : !stat.isFile())
|
|
10
|
-
|| (process.getuid && stat.uid !== process.getuid()) || (stat.mode & 0o077)) {
|
|
11
|
-
throw new Error('Model preferences require private user-owned files')
|
|
12
|
-
}
|
|
13
|
-
}
|
|
7
|
+
import { assertPrivateLocalEntry, ensurePrivateLocalDirectory, sealPrivateLocalEntry } from './local-platform.mjs'
|
|
8
|
+
|
|
14
9
|
function route(value) {
|
|
15
10
|
if (!value || typeof value.provider !== 'string' || !value.provider.trim()
|
|
16
11
|
|| typeof value.model !== 'string' || !value.model.trim()) throw new Error('A complete model route is required')
|
|
@@ -30,8 +25,8 @@ export class AccountModelPreferences {
|
|
|
30
25
|
async read(owner) {
|
|
31
26
|
const path = this.#path(owner)
|
|
32
27
|
try {
|
|
33
|
-
await
|
|
34
|
-
await
|
|
28
|
+
await assertPrivateLocalEntry(this.directory, true)
|
|
29
|
+
await assertPrivateLocalEntry(path)
|
|
35
30
|
const value = JSON.parse(await readFile(path, 'utf8'))
|
|
36
31
|
if (value.v !== 1 || value.owner !== owner || typeof value.revision !== 'string') throw new Error('Invalid account model preference')
|
|
37
32
|
return { ...route(value), revision: value.revision }
|
|
@@ -45,11 +40,11 @@ export class AccountModelPreferences {
|
|
|
45
40
|
async write(owner, selection) {
|
|
46
41
|
const path = this.#path(owner)
|
|
47
42
|
const value = { v: 1, owner, ...route(selection), revision: randomUUID() }
|
|
48
|
-
await
|
|
49
|
-
await owned(this.directory, true)
|
|
43
|
+
await ensurePrivateLocalDirectory(this.directory)
|
|
50
44
|
const temporary = `${path}.${randomUUID()}.tmp`
|
|
51
45
|
try {
|
|
52
46
|
await writeFile(temporary, JSON.stringify(value), { flag: 'wx', mode: 0o600 })
|
|
47
|
+
await sealPrivateLocalEntry(temporary)
|
|
53
48
|
await rename(temporary, path)
|
|
54
49
|
} finally { await rm(temporary, { force: true }) }
|
|
55
50
|
return { ...route(value), revision: value.revision }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatcode/runtime-client",
|
|
3
|
-
"version": "0.1.0-integration.
|
|
3
|
+
"version": "0.1.0-integration.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Node.js client for persistent chatcode-cli Runtime sessions and desktop approvals",
|
|
6
6
|
"exports": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"stdio-bridge.mjs",
|
|
20
20
|
"desktop-permission-gate.mjs",
|
|
21
21
|
"desktop-history.mjs",
|
|
22
|
+
"local-platform.mjs",
|
|
22
23
|
"model-preferences.mjs",
|
|
23
24
|
"desktop-history-guard.mjs",
|
|
24
25
|
"index.d.ts",
|
|
@@ -34,8 +35,8 @@
|
|
|
34
35
|
"ws": "8.21.0"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
|
-
"test": "node --test tests/lifecycle.test.mjs tests/interactions.test.mjs tests/history.test.mjs tests/models.test.mjs tests/activity.test.mjs tests/execution.test.mjs tests/user-questions.test.mjs tests/session-browser.test.mjs",
|
|
38
|
-
"build": "node --check session-browser.mjs && node --check user-questions.mjs && node --check execution.mjs && node --check runtime-connector.mjs && node --check session-activity.mjs && node --check model-preferences.mjs && node --check desktop-permission-gate.mjs && node --check desktop-history.mjs && node --check desktop-history-guard.mjs && node --check stdio-bridge.mjs && tsc -p tsconfig.json",
|
|
38
|
+
"test": "node --test tests/lifecycle.test.mjs tests/interactions.test.mjs tests/history.test.mjs tests/history-platform.test.mjs tests/models.test.mjs tests/activity.test.mjs tests/execution.test.mjs tests/user-questions.test.mjs tests/session-browser.test.mjs",
|
|
39
|
+
"build": "node --check session-browser.mjs && node --check user-questions.mjs && node --check execution.mjs && node --check runtime-connector.mjs && node --check session-activity.mjs && node --check model-preferences.mjs && node --check desktop-permission-gate.mjs && node --check desktop-history.mjs && node --check local-platform.mjs && node --check desktop-history-guard.mjs && node --check stdio-bridge.mjs && tsc -p tsconfig.json",
|
|
39
40
|
"prepublishOnly": "npm run build && npm test"
|
|
40
41
|
},
|
|
41
42
|
"license": "MIT",
|
|
@@ -57,14 +57,12 @@ export class RuntimeConnector {
|
|
|
57
57
|
throw new Error('nodePath, launcherPath and home are required')
|
|
58
58
|
}
|
|
59
59
|
const { appCredentials, ...launchOptions } = options
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
throw failure('Application credentials require a valid appId and secret', 'runtime/app-credentials')
|
|
65
|
-
}
|
|
66
|
-
this.#appCredentials = { appId, secret }
|
|
60
|
+
const { appId, secret } = appCredentials ?? {}
|
|
61
|
+
if (typeof appId !== 'string' || !appId || appId.length > 128 || /[^\x21-\x7e]/u.test(appId)
|
|
62
|
+
|| typeof secret !== 'string' || !secret || secret.length > 1024 || /[^\x21-\x7e]/u.test(secret)) {
|
|
63
|
+
throw failure('Application credentials require a valid appId and secret', 'runtime/app-credentials')
|
|
67
64
|
}
|
|
65
|
+
this.#appCredentials = { appId, secret }
|
|
68
66
|
this.options = {
|
|
69
67
|
startupTimeoutMs: 20000, requestTimeoutMs: 10000,
|
|
70
68
|
shutdownTimeoutMs: 10000, socketTimeoutMs: 10000, childReadyTimeoutMs: 1000,
|
|
@@ -136,8 +134,11 @@ export class RuntimeConnector {
|
|
|
136
134
|
ready.reject(error)
|
|
137
135
|
if (!this.#closed) {
|
|
138
136
|
this.#failed = error
|
|
139
|
-
this.#
|
|
137
|
+
const followers = [...this.#followers.entries()]
|
|
140
138
|
this.#socket?.terminate()
|
|
139
|
+
for (const [streamId] of followers) this.#disposeFollower(streamId, error)
|
|
140
|
+
this.#state('failed', error)
|
|
141
|
+
for (const [, follower] of followers) this.#notify(follower.onFailure, error)
|
|
141
142
|
}
|
|
142
143
|
resolveExit({ code, signal })
|
|
143
144
|
}))
|
|
@@ -145,11 +146,11 @@ export class RuntimeConnector {
|
|
|
145
146
|
if (launchURL.protocol !== 'http:' || launchURL.hostname !== '127.0.0.1') {
|
|
146
147
|
throw new Error('Runtime reported an unexpected non-loopback URL')
|
|
147
148
|
}
|
|
148
|
-
const auth = await this.#http(launchURL, undefined,
|
|
149
|
+
const auth = await this.#http(launchURL, undefined, {
|
|
149
150
|
[APP_ID_HEADER]: credentials.appId,
|
|
150
151
|
[APP_SECRET_HEADER]: credentials.secret,
|
|
151
152
|
})
|
|
152
|
-
if (
|
|
153
|
+
if (auth.status === 401 || auth.status === 403) {
|
|
153
154
|
throw failure('Runtime rejected application authentication', 'runtime/app-auth')
|
|
154
155
|
}
|
|
155
156
|
if (auth.status !== 303 || !auth.headers['set-cookie']?.length) throw failure('Host authentication failed', 'runtime/auth')
|
|
@@ -287,7 +288,7 @@ export class RuntimeConnector {
|
|
|
287
288
|
createSession(request) {
|
|
288
289
|
return this.#rpc('session/create', {
|
|
289
290
|
...request,
|
|
290
|
-
|
|
291
|
+
appId: this.#appCredentials.appId,
|
|
291
292
|
})
|
|
292
293
|
}
|
|
293
294
|
/**
|
|
@@ -4125,7 +4125,7 @@ window.__ModuleLoader__.load({
|
|
|
4125
4125
|
for (const listener of listeners) listener();
|
|
4126
4126
|
};
|
|
4127
4127
|
/** @returns the client identity for one account call, read at call time so it carries the language and zone in effect then. */
|
|
4128
|
-
const client = () => accountClientMetadata(ctx.locale.getSnapshot().active, "3.0.6-rc.
|
|
4128
|
+
const client = () => accountClientMetadata(ctx.locale.getSnapshot().active, "3.0.6-rc.4");
|
|
4129
4129
|
const notices = createBonusNoticeController({
|
|
4130
4130
|
ackRetryDelayMs: config.bonusAckRetryDelayMs,
|
|
4131
4131
|
ackRetryMaxDelayMs: config.bonusAckRetryMaxDelayMs,
|
|
@@ -4256,7 +4256,7 @@ window.__ModuleLoader__.load({
|
|
|
4256
4256
|
refreshAccount,
|
|
4257
4257
|
contactUs() {
|
|
4258
4258
|
const url = contactUrl(config, {
|
|
4259
|
-
version: "3.0.6-rc.
|
|
4259
|
+
version: "3.0.6-rc.4",
|
|
4260
4260
|
locale: ctx.locale.getSnapshot().active === "zh" ? "zh-CN" : "en",
|
|
4261
4261
|
width: window.screen.width,
|
|
4262
4262
|
height: window.screen.height,
|
|
@@ -657,7 +657,7 @@ window.__ModuleLoader__.load({
|
|
|
657
657
|
function CurrentVersionRow({ t }) {
|
|
658
658
|
return (0, react_jsx_runtime.jsx)("div", {
|
|
659
659
|
className: CurrentVersionRow_module_css_default.row,
|
|
660
|
-
children: t("general.currentVersion", { version: "3.0.6-rc.
|
|
660
|
+
children: t("general.currentVersion", { version: "3.0.6-rc.4" })
|
|
661
661
|
});
|
|
662
662
|
}
|
|
663
663
|
//#endregion
|
|
@@ -167,7 +167,7 @@ window.__ModuleLoader__.load({
|
|
|
167
167
|
const SCROLLBAR_LINGER_MS = 2e3;
|
|
168
168
|
/** Format complete-build metadata for the local brand badge. */
|
|
169
169
|
function localBuildVersion() {
|
|
170
|
-
return `3.0.6-rc.
|
|
170
|
+
return `3.0.6-rc.4-00aa4ca-dirty`;
|
|
171
171
|
}
|
|
172
172
|
/** Each panel row subscribes only to its own selection state. */
|
|
173
173
|
function PanelRow({ id, label, wide, usePanelInfo, selectPanel, renderSlot }) {
|