@chatcode/chatcode-cli-test 1.0.47 → 3.0.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.
package/package.json CHANGED
@@ -1,126 +1,179 @@
1
1
  {
2
2
  "name": "@chatcode/chatcode-cli-test",
3
- "version": "1.0.47",
4
- "description": "ChatCode CLI command-line coding assistant.",
5
- "license": "SEE LICENSE IN LICENSE.md",
6
- "type": "module",
7
- "bin": {
8
- "chatcode-cli": "bin/cli.js",
9
- "cco": "bin/cli.js"
3
+ "description": "ChatCode CLI: TUI-first coding agent, Web launcher, profiles, and legacy DSH-compatible plugins",
4
+ "version": "3.0.1",
5
+ "publishConfig": {
6
+ "access": "public"
10
7
  },
11
- "packageManager": "bun@1.3.5",
12
8
  "repository": {
13
9
  "type": "git",
14
10
  "url": "http://gitlab.tianti.tg.unicom.local/kubernetesAMP/visualDesignPlatform/chatcode-cli.git"
15
11
  },
16
- "engines": {
17
- "node": ">=18.0.0"
18
- },
19
- "chatcodeNativePackageFormat": 1,
20
- "scripts": {
21
- "dev": "bun run ./scripts/dev-supervisor.mjs",
22
- "start": "bun run ./scripts/dev-supervisor.mjs",
23
- "version": "bun run ./scripts/dev-supervisor.mjs --version",
24
- "test": "bun test scripts/tests",
25
- "scan:public-surface": "bun run scripts/public-surface-scan.mjs --fail-on-match",
26
- "verify:public-surface": "bun run scripts/verify-public-surface-release.mjs",
27
- "build": "bun run scripts/build.mjs",
28
- "build:native": "bun run scripts/build.mjs --compile",
29
- "build:native:all": "bun run scripts/build.mjs --compile --all",
30
- "build:native:win": "bun run scripts/build.mjs --compile --targets=win32-x64",
31
- "build:native:pack": "node scripts/pack-native.mjs",
32
- "prepublishOnly": "bun run build"
12
+ "type": "module",
13
+ "bin": {
14
+ "chatcode-cli": "lib/bin.js",
15
+ "cco": "lib/bin.js",
16
+ "dsh": "lib/bin.js"
33
17
  },
34
18
  "files": [
35
- "bin/",
36
- "dist/cli.js",
37
- "dist/vendor/",
38
- "README.md"
19
+ "lib/*.js",
20
+ "lib/types/*.d.ts"
39
21
  ],
40
- "publishConfig": {
41
- "access": "public"
22
+ "dsh": {
23
+ "configTrees": [
24
+ {
25
+ "mount": "config/agent-presets",
26
+ "path": "../../packages/preset/agent-presets/presets",
27
+ "scanRoster": true
28
+ }
29
+ ]
30
+ },
31
+ "license": "MIT",
32
+ "dependencies": {
33
+ "@chatcode/cco-tui": "0.10.0-beta.5",
34
+ "@deepseek-harness-tui/dsh-tui": "npm:@chatcode/cco-tui@0.10.0-beta.5",
35
+ "commander": "^15.0.0",
36
+ "js-yaml": "^4.2.0",
37
+ "node-addon-require-builtin": "^0.1.6",
38
+ "@chatcode/cco-better-sidebar": "0.18.0-alpha.1",
39
+ "@chatcode/cco-builtin-browser": "0.1.21",
40
+ "@chatcode/cco-llm-chatcode-config": "0.1.1",
41
+ "@chatcode/cco-market": "1.45.1",
42
+ "dsh-better-sidebar": "npm:@chatcode/cco-better-sidebar@0.18.0-alpha.1",
43
+ "dsh-builtin-browser": "npm:@chatcode/cco-builtin-browser@0.1.21",
44
+ "dsh-llm-chatcode-config": "npm:@chatcode/cco-llm-chatcode-config@0.1.1",
45
+ "dshmarket": "npm:@chatcode/cco-market@1.45.1",
46
+ "dsh-chat-import": "npm:@chatcode/cco-chat-import@0.12.0",
47
+ "@chatcode/cco-chat-import": "0.12.0",
48
+ "@deepseek-ai/dsh-hmr": "^0.1.6-alpha.2",
49
+ "@deepseek-ai/cordis-plugin-loader": "^1.0.3",
50
+ "@deepseek-ai/cordis": "^4.0.2",
51
+ "@deepseek-ai/cordis-plugin-timer": "^1.1.4",
52
+ "@deepseek-ai/cordis-plugin-include": "^1.0.7",
53
+ "@deepseek-ai/dsh-agent-instructions": "^0.1.6-alpha.2",
54
+ "@deepseek-ai/dsh-acp-app": "^0.1.6-alpha.2",
55
+ "@deepseek-ai/dsh-app-boot": "^0.1.6-alpha.2",
56
+ "@deepseek-ai/dsh-client-ui-agent-preset": "^0.1.6-alpha.2",
57
+ "@deepseek-ai/dsh-cmdline": "^0.1.6-alpha.2",
58
+ "@deepseek-ai/cordis-plugin-group": "^1.0.2",
59
+ "@deepseek-ai/dsh-agent-tool-presentation": "^0.1.6-alpha.2",
60
+ "@deepseek-ai/dsh-client-ui-cordis": "^0.1.6-alpha.2",
61
+ "@deepseek-ai/dsh-base": "^0.1.6-alpha.2",
62
+ "@deepseek-ai/dsh-compaction-basic": "^0.1.6-alpha.2",
63
+ "@deepseek-ai/dsh-command-goal": "^0.1.6-alpha.2",
64
+ "@deepseek-ai/dsh-command-compact": "^0.1.6-alpha.2",
65
+ "@deepseek-ai/dsh-cordis-client-runner": "^0.1.6-alpha.2",
66
+ "@deepseek-ai/dsh-compaction-tool-result-pruner": "^0.1.6-alpha.2",
67
+ "@deepseek-ai/dsh-goal": "^0.1.6-alpha.2",
68
+ "@deepseek-ai/dsh-headless": "^0.1.6-alpha.2",
69
+ "@deepseek-ai/dsh-fs-local": "^0.1.6-alpha.2",
70
+ "@deepseek-ai/dsh-experimental-agent-team-web-profile": "^0.1.6-alpha.2",
71
+ "@deepseek-ai/dsh-jobs-local": "^0.1.6-alpha.2",
72
+ "@deepseek-ai/dsh-home-paths": "^0.1.6-alpha.2",
73
+ "@deepseek-ai/dsh-hooks-codex": "^0.1.6-alpha.2",
74
+ "@deepseek-ai/dsh-mcp-client": "^0.1.6-alpha.2",
75
+ "@deepseek-ai/dsh-pwsh-sandbox": "^0.1.6-alpha.2",
76
+ "@deepseek-ai/dsh-goal-round-driver": "^0.1.6-alpha.2",
77
+ "@deepseek-ai/dsh-launch-environment": "^0.1.6-alpha.2",
78
+ "@deepseek-ai/dsh-hooks-claude-code": "^0.1.6-alpha.2",
79
+ "@deepseek-ai/dsh-pwsh-local": "^0.1.6-alpha.2",
80
+ "@deepseek-ai/dsh-persona": "^0.1.6-alpha.2",
81
+ "@deepseek-ai/dsh-schedule": "^0.1.6-alpha.2",
82
+ "@deepseek-ai/dsh-sdk-minimal": "^0.1.6-alpha.2",
83
+ "@deepseek-ai/dsh-experimental-agent-team-profile": "^0.1.6-alpha.2",
84
+ "@deepseek-ai/dsh-session-projection": "^0.1.6-alpha.2",
85
+ "@deepseek-ai/dsh-system-prompt": "^0.1.6-alpha.2",
86
+ "@deepseek-ai/dsh-skill-filesystem": "^0.1.6-alpha.2",
87
+ "@deepseek-ai/dsh-session-reference": "^0.1.6-alpha.2",
88
+ "@deepseek-ai/dsh-terminal": "^0.1.6-alpha.2",
89
+ "@deepseek-ai/dsh-sdk-app": "^0.1.6-alpha.2",
90
+ "@deepseek-ai/dsh-tmux-context": "^0.1.6-alpha.2",
91
+ "@deepseek-ai/dsh-time-context": "^0.1.6-alpha.2",
92
+ "@deepseek-ai/dsh-terminal-bash": "^0.1.6-alpha.2",
93
+ "@deepseek-ai/dsh-tool-ask-user": "^0.1.6-alpha.2",
94
+ "@deepseek-ai/dsh-tool-bash": "^0.1.6-alpha.2",
95
+ "@deepseek-ai/dsh-token-meter": "^0.1.6-alpha.2",
96
+ "@deepseek-ai/dsh-tool-present": "^0.1.6-alpha.2",
97
+ "@deepseek-ai/dsh-tool-fs": "^0.1.6-alpha.2",
98
+ "@deepseek-ai/dsh-tool-fs-search": "^0.1.6-alpha.2",
99
+ "@deepseek-ai/dsh-tool-cordis": "^0.1.6-alpha.2",
100
+ "@deepseek-ai/dsh-skill": "^0.1.6-alpha.2",
101
+ "@deepseek-ai/dsh-tool-pwsh": "^0.1.6-alpha.2",
102
+ "@deepseek-ai/dsh-tool-pwsh-persistent": "^0.1.6-alpha.2",
103
+ "@deepseek-ai/dsh-tool-jobs": "^0.1.6-alpha.2",
104
+ "@deepseek-ai/dsh-tool-goal": "^0.1.6-alpha.2",
105
+ "@deepseek-ai/dsh-tool-skill": "^0.1.6-alpha.2",
106
+ "@deepseek-ai/dsh-tool-subagent": "^0.1.6-alpha.2",
107
+ "@deepseek-ai/dsh-tool-str-replace-editor": "^0.1.6-alpha.2",
108
+ "@deepseek-ai/dsh-tool-ralph": "^0.1.6-alpha.2",
109
+ "@deepseek-ai/dsh-tool-subagent-control": "^0.1.6-alpha.2",
110
+ "@deepseek-ai/dsh-tool-web": "^0.1.6-alpha.2",
111
+ "@deepseek-ai/dsh-tool-todo": "^0.1.6-alpha.2",
112
+ "@deepseek-ai/dsh-webhook": "^0.1.6-alpha.2",
113
+ "@deepseek-ai/dsh-web-app": "^0.1.6-alpha.2",
114
+ "@deepseek-ai/dsh-tool-workflow": "^0.1.6-alpha.2",
115
+ "@deepseek-ai/dsh-webhook-github": "^0.1.6-alpha.2",
116
+ "@deepseek-ai/schemastery": "^3.18.2",
117
+ "@deepseek-ai/dsh-mcp-resources": "^0.1.6-alpha.2",
118
+ "@deepseek-ai/dsh-http-proxy": "^0.1.6-alpha.2",
119
+ "@deepseek-ai/dsh-atomic-write": "^0.1.6-alpha.2",
120
+ "@deepseek-ai/dsh-plugin-manager": "^0.1.6-alpha.2",
121
+ "@deepseek-ai/dsh-tool-bash-persistent": "^0.1.6-alpha.2",
122
+ "@deepseek-ai/dsh-plan-mode": "^0.1.6-alpha.2",
123
+ "@deepseek-ai/dsh-workflow-ptc": "^0.1.6-alpha.2"
42
124
  },
43
125
  "devDependencies": {
44
- "@alcalzone/ansi-tokenize": "0.3.0",
45
- "@chatcode/chrome-mcp": "file:./shims/chatcode-chrome-mcp",
46
- "@chatcode/computer-use-input": "file:./shims/chatcode-computer-use-input",
47
- "@chatcode/computer-use-mcp": "file:./shims/chatcode-computer-use-mcp",
48
- "@chatcode/computer-use-swift": "file:./shims/chatcode-computer-use-swift",
49
- "@chatcode/mcpb": "file:./shims/chatcode-mcpb",
50
- "@chatcode/sandbox-runtime": "file:./shims/chatcode-sandbox-runtime",
51
- "@chatcode/sdk": "file:./shims/chatcode-sdk",
52
- "@commander-js/extra-typings": "14.0.0",
53
- "@growthbook/growthbook": "1.6.5",
54
- "@modelcontextprotocol/sdk": "1.29.0",
55
- "@opentelemetry/api": "1.9.1",
56
- "@opentelemetry/api-logs": "0.214.0",
57
- "@opentelemetry/core": "2.6.1",
58
- "@opentelemetry/resources": "2.6.1",
59
- "@opentelemetry/sdk-logs": "0.214.0",
60
- "@opentelemetry/sdk-metrics": "2.6.1",
61
- "@opentelemetry/sdk-trace-base": "2.6.1",
62
- "@opentelemetry/semantic-conventions": "1.40.0",
63
- "adm-zip": "0.5.16",
64
- "ajv": "8.18.0",
65
- "asciichart": "1.5.25",
66
- "auto-bind": "5.0.1",
67
- "axios": "1.14.0",
68
- "bidi-js": "1.0.3",
69
- "chalk": "5.6.2",
70
- "chokidar": "5.0.0",
71
- "cli-boxes": "4.0.1",
72
- "code-excerpt": "4.0.0",
73
- "color-diff-napi": "file:./shims/color-diff-napi",
74
- "diff": "8.0.4",
75
- "emoji-regex": "10.6.0",
76
- "env-paths": "4.0.0",
77
- "execa": "9.6.1",
78
- "fflate": "0.8.2",
79
- "figures": "6.1.0",
80
- "fuse.js": "7.1.0",
81
- "get-east-asian-width": "1.5.0",
82
- "highlight.js": "11.11.1",
83
- "https-proxy-agent": "8.0.0",
84
- "ignore": "7.0.5",
85
- "indent-string": "5.0.0",
86
- "ink": "6.8.0",
87
- "jsonc-parser": "3.3.1",
88
- "lodash-es": "4.17.23",
89
- "lru-cache": "11.2.7",
90
- "marked": "17.0.5",
91
- "modifiers-napi": "file:./shims/modifiers-napi",
92
- "p-map": "7.0.4",
93
- "picomatch": "4.0.4",
94
- "proper-lockfile": "4.1.2",
95
- "qrcode": "1.5.4",
96
- "react": "19.2.4",
97
- "react-reconciler": "0.33.0",
98
- "semver": "7.7.4",
99
- "shell-quote": "1.8.3",
100
- "signal-exit": "4.1.0",
101
- "stack-utils": "2.0.6",
102
- "strip-ansi": "7.2.0",
103
- "supports-hyperlinks": "4.4.0",
104
- "tree-kill": "1.2.2",
105
- "type-fest": "5.5.0",
106
- "undici": "7.24.6",
107
- "url-handler-napi": "file:./shims/url-handler-napi",
108
- "usehooks-ts": "3.1.1",
109
- "uuid": "^11.1.0",
110
- "vscode-jsonrpc": "8.2.1",
111
- "vscode-languageserver-protocol": "3.17.5",
112
- "vscode-languageserver-types": "3.17.5",
113
- "wrap-ansi": "10.0.0",
114
- "ws": "8.20.0",
115
- "xss": "1.0.15",
116
- "yaml": "2.8.3",
117
- "zod": "4.3.6"
126
+ "@agentclientprotocol/sdk": "1.4.0",
127
+ "@types/js-yaml": "^4.0.9",
128
+ "@types/ws": "8.18.1",
129
+ "execa": "^10.0.0",
130
+ "ws": "8.21.0",
131
+ "@deepseek-ai/dsh-acp": "^0.1.6-alpha.2",
132
+ "@deepseek-ai/dsh-agent": "^0.1.6-alpha.2",
133
+ "@deepseek-ai/dsh-attachment-local": "^0.1.6-alpha.2",
134
+ "@deepseek-ai/dsh-bash-local": "^0.1.6-alpha.2",
135
+ "@deepseek-ai/dsh-credentials-local": "^0.1.6-alpha.2",
136
+ "@deepseek-ai/dsh-experimental-agent-team": "^0.1.6-alpha.2",
137
+ "@deepseek-ai/dsh-agent-loop-testkit": "^0.1.6-alpha.2",
138
+ "@deepseek-ai/dsh-agent-loop": "^0.1.6-alpha.2",
139
+ "@deepseek-ai/dsh-fs-observation-policy": "^0.1.6-alpha.2",
140
+ "@deepseek-ai/dsh-host-frontend-static": "^0.1.6-alpha.2",
141
+ "@deepseek-ai/dsh-experimental-tool-agent-team": "^0.1.6-alpha.2",
142
+ "@deepseek-ai/dsh-deepseek-llm-api-extensions": "^0.1.6-alpha.2",
143
+ "@deepseek-ai/dsh-llm-deepseek": "^0.1.6-alpha.2",
144
+ "@deepseek-ai/dsh-host-webserver": "^0.1.6-alpha.2",
145
+ "@deepseek-ai/dsh-llm": "^0.1.6-alpha.2",
146
+ "@deepseek-ai/dsh-fs-sandbox": "^0.1.6-alpha.2",
147
+ "@deepseek-ai/dsh-llm-pi-ai": "^0.1.6-alpha.2",
148
+ "@deepseek-ai/dsh-llm-mock-server": "^0.1.6-alpha.2",
149
+ "@deepseek-ai/dsh-llm-replay": "^0.1.6-alpha.2",
150
+ "@deepseek-ai/dsh-plugin-package-inventory-deepseek": "^0.1.6-alpha.2",
151
+ "@deepseek-ai/dsh-loader-smoke": "^0.1.6-alpha.2",
152
+ "@deepseek-ai/dsh-experimental-ptc-runtime-python": "^0.1.6-alpha.2",
153
+ "@deepseek-ai/dsh-sandbox-policy": "^0.1.6-alpha.2",
154
+ "@deepseek-ai/dsh-sandbox-local": "^0.1.6-alpha.2",
155
+ "@deepseek-ai/dsh-session-log-deepseek": "^0.1.6-alpha.2",
156
+ "@deepseek-ai/dsh-session-checkpoint-policy": "^0.1.6-alpha.2",
157
+ "@deepseek-ai/dsh-session": "^0.1.6-alpha.2",
158
+ "@deepseek-ai/dsh-shell-env": "^0.1.6-alpha.2",
159
+ "@deepseek-ai/dsh-session-query": "^0.1.6-alpha.2",
160
+ "@deepseek-ai/dsh-subagent-fork-in-process": "^0.1.6-alpha.2",
161
+ "@deepseek-ai/dsh-settings-file": "^0.1.6-alpha.2",
162
+ "@deepseek-ai/dsh-subagent": "^0.1.6-alpha.2",
163
+ "@deepseek-ai/dsh-session-persistence-jsonl": "^0.1.6-alpha.2",
164
+ "@deepseek-ai/dsh-subprocess-local": "^0.1.6-alpha.2",
165
+ "@deepseek-ai/dsh-settings": "^0.1.6-alpha.2",
166
+ "@deepseek-ai/dsh-system-prompt": "^0.1.6-alpha.2",
167
+ "@deepseek-ai/dsh-tools": "^0.1.6-alpha.2",
168
+ "@deepseek-ai/dsh-subagent-spawn-in-process": "^0.1.6-alpha.2",
169
+ "@deepseek-ai/dsh-user-approval": "^0.1.6-alpha.2"
118
170
  },
119
- "optionalDependencies": {
120
- "@chatcode/chatcode-cli-test-darwin-arm64": "1.0.47",
121
- "@chatcode/chatcode-cli-test-darwin-x64": "1.0.47",
122
- "@chatcode/chatcode-cli-test-linux-x64": "1.0.47",
123
- "@chatcode/chatcode-cli-test-linux-arm64": "1.0.47",
124
- "@chatcode/chatcode-cli-test-win32-x64": "1.0.47"
171
+ "exports": {
172
+ "./profile-boot": {
173
+ "types": "./lib/types/profile-boot.d.ts",
174
+ "default": "./lib/profile-boot.js"
175
+ },
176
+ "./lib/*": "./lib/*",
177
+ "./package.json": "./package.json"
125
178
  }
126
- }
179
+ }
package/bin/cli.js DELETED
@@ -1,102 +0,0 @@
1
- #!/usr/bin/env node
2
- import { existsSync, readFileSync } from 'node:fs'
3
- import { createRequire } from 'node:module'
4
- import { dirname, join } from 'node:path'
5
- import { fileURLToPath } from 'node:url'
6
- import { runSupervised } from './generation-supervisor.js'
7
-
8
- const require = createRequire(import.meta.url)
9
- const here = dirname(fileURLToPath(import.meta.url))
10
- const root = join(here, '..')
11
- const args = process.argv.slice(2)
12
- const platformKey = `${process.platform}-${process.arch}`
13
- const executableName = process.platform === 'win32' ? 'chatcode-cli.exe' : 'chatcode-cli'
14
- const mainPackage = JSON.parse(
15
- readFileSync(join(root, 'package.json'), 'utf8'),
16
- )
17
- const mainPackageName = mainPackage.name
18
-
19
- function shouldUseNativeBinary() {
20
- if (process.env.CHATCODE_CLI_FORCE_NODE === '1') return false
21
- return (
22
- process.env.CHATCODE_CLI_USE_NATIVE === '1' ||
23
- process.env.CHATCODE_CLI_FORCE_NATIVE === '1'
24
- )
25
- }
26
-
27
- function resolveOptionalBinary() {
28
- if (process.env.CHATCODE_CLI_FORCE_NODE === '1') return null
29
- if (!shouldUseNativeBinary()) return null
30
-
31
- try {
32
- const packageName = `${mainPackageName}-${platformKey}`
33
- const executablePath = require.resolve(`${packageName}/${executableName}`)
34
- const nativePackage = JSON.parse(
35
- readFileSync(join(dirname(executablePath), 'package.json'), 'utf8'),
36
- )
37
- const versionMatches = nativePackage.version === mainPackage.version
38
- const formatMatches =
39
- nativePackage.chatcodeNativePackageFormat ===
40
- mainPackage.chatcodeNativePackageFormat
41
- if (!versionMatches || !formatMatches) {
42
- console.warn(
43
- `Ignoring ${packageName}@${nativePackage.version}: expected version ${mainPackage.version} and native package format ${mainPackage.chatcodeNativePackageFormat}. Using the bundled Node build instead.`,
44
- )
45
- return null
46
- }
47
- return executablePath
48
- } catch (_) {
49
- return null
50
- }
51
- }
52
-
53
- function resolveLocalBinary() {
54
- if (process.env.CHATCODE_CLI_FORCE_NODE === '1') return null
55
- if (!shouldUseNativeBinary()) return null
56
-
57
- const localBinary = join(root, 'dist', 'native', platformKey, executableName)
58
- return existsSync(localBinary) ? localBinary : null
59
- }
60
-
61
- function run(command, commandArgs) {
62
- const result = runSupervised(command, commandArgs)
63
-
64
- if (result.error) return result.error
65
- if (result.signal) {
66
- process.kill(process.pid, result.signal)
67
- process.exit(1)
68
- }
69
- process.exit(result.status ?? 1)
70
- }
71
-
72
- const nativeBinary = resolveLocalBinary() ?? resolveOptionalBinary()
73
- if (nativeBinary) {
74
- const error = run(nativeBinary, args)
75
- if (error && error.code !== 'ENOENT') {
76
- console.error(`Failed to run native ChatCode CLI binary: ${error.message}`)
77
- process.exit(1)
78
- }
79
- }
80
-
81
- const fallbackCli = join(root, 'dist', 'cli.js')
82
- if (!existsSync(fallbackCli)) {
83
- console.error(
84
- `ChatCode CLI is not installed correctly: missing ${fallbackCli}`,
85
- )
86
- process.exit(1)
87
- }
88
-
89
- const error = run(process.execPath, [
90
- '--max-old-space-size=4096',
91
- '--stack_size=4096',
92
- // The REPL only calls global.gc() after an idle rebuildable-cache release. This
93
- // lets V8 reclaim the now-unreachable graph promptly instead of waiting for
94
- // a future allocation to discover it.
95
- '--expose-gc',
96
- fallbackCli,
97
- ...args,
98
- ])
99
- if (error) {
100
- console.error(`Failed to run ChatCode CLI: ${error.message}`)
101
- process.exit(1)
102
- }
@@ -1,142 +0,0 @@
1
- import { spawnSync } from 'node:child_process'
2
- import { randomUUID } from 'node:crypto'
3
- import {
4
- existsSync,
5
- readFileSync,
6
- statSync,
7
- unlinkSync,
8
- } from 'node:fs'
9
- import { tmpdir } from 'node:os'
10
- import { isAbsolute, join, resolve } from 'node:path'
11
-
12
- export const PROCESS_GENERATION_ROTATE_EXIT_CODE = 75
13
- export const GENERATION_CONTROL_FILE_ENV =
14
- 'CHATCODE_CLI_GENERATION_CONTROL_FILE'
15
- export const GENERATION_CONTROL_TOKEN_ENV =
16
- 'CHATCODE_CLI_GENERATION_CONTROL_TOKEN'
17
- export const INTERNAL_RESUME_SESSION_ENV =
18
- 'CHATCODE_CLI_INTERNAL_RESUME_SESSION_ID'
19
- export const PROCESS_GENERATION_INDEX_ENV =
20
- 'CHATCODE_CLI_PROCESS_GENERATION_INDEX'
21
- export const GENERATION_SUPERVISOR_PID_ENV =
22
- 'CHATCODE_CLI_GENERATION_SUPERVISOR_PID'
23
-
24
- const UUID_PATTERN =
25
- /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
26
- const MAX_CONTROL_FILE_BYTES = 8 * 1024
27
-
28
- function removeControlFile(controlFile) {
29
- try {
30
- if (existsSync(controlFile)) unlinkSync(controlFile)
31
- } catch {
32
- // The file is private, contains no conversation content, and lives only
33
- // for this supervisor lifetime. Failure to remove it must not hide the
34
- // child process's real exit status.
35
- }
36
- }
37
-
38
- function readRotationRequest(controlFile, token) {
39
- try {
40
- const stat = statSync(controlFile)
41
- if (!stat.isFile() || stat.size <= 0 || stat.size > MAX_CONTROL_FILE_BYTES) {
42
- return null
43
- }
44
-
45
- const request = JSON.parse(readFileSync(controlFile, 'utf8'))
46
- if (
47
- request?.version !== 1 ||
48
- request.token !== token ||
49
- typeof request.sessionId !== 'string' ||
50
- !UUID_PATTERN.test(request.sessionId) ||
51
- typeof request.cwd !== 'string' ||
52
- request.cwd.length === 0
53
- ) {
54
- return null
55
- }
56
-
57
- const cwd = isAbsolute(request.cwd)
58
- ? resolve(request.cwd)
59
- : resolve(process.cwd(), request.cwd)
60
- if (!statSync(cwd).isDirectory()) return null
61
-
62
- return { sessionId: request.sessionId, cwd }
63
- } catch {
64
- return null
65
- }
66
- }
67
-
68
- /**
69
- * Run a ChatCode worker and replace it only after an authenticated, explicit
70
- * generation-rotation request. The supervisor itself holds no transcript or
71
- * UI graph, so replacing the worker returns JSC/V8, Yoga/WASM and native
72
- * allocator high-water pages to the operating system.
73
- */
74
- export function runSupervised(command, commandArgs) {
75
- // Mirror the worker opt-in gate. The supervisor must also fail closed so
76
- // exit code 75 cannot silently replace a desktop host's worker by default.
77
- const truthy = value => /^(1|true|yes|on)$/i.test(value?.trim() ?? '')
78
- const rotationEnabled = truthy(process.env.CHATCODE_CLI_ENABLE_PROCESS_GENERATION_ROTATION) &&
79
- !truthy(process.env.CHATCODE_CLI_DISABLE_PROCESS_GENERATION_ROTATION)
80
- const token = randomUUID()
81
- const controlFile = join(
82
- tmpdir(),
83
- `chatcode-cli-generation-${process.pid}-${randomUUID()}.json`,
84
- )
85
- let cwd = process.cwd()
86
- let resumeSessionId
87
- let generation = 0
88
-
89
- try {
90
- while (true) {
91
- removeControlFile(controlFile)
92
- const env = {
93
- ...process.env,
94
- [GENERATION_CONTROL_FILE_ENV]: controlFile,
95
- [GENERATION_CONTROL_TOKEN_ENV]: token,
96
- [PROCESS_GENERATION_INDEX_ENV]: String(generation),
97
- [GENERATION_SUPERVISOR_PID_ENV]: String(process.pid),
98
- }
99
- // Never trust an inherited internal-resume value. Only a request whose
100
- // one-time control token was validated above can populate this channel.
101
- delete env[INTERNAL_RESUME_SESSION_ENV]
102
- if (!rotationEnabled) {
103
- delete env[GENERATION_CONTROL_FILE_ENV]
104
- delete env[GENERATION_CONTROL_TOKEN_ENV]
105
- delete env[GENERATION_SUPERVISOR_PID_ENV]
106
- }
107
- if (resumeSessionId) {
108
- env[INTERNAL_RESUME_SESSION_ENV] = resumeSessionId
109
- }
110
-
111
- const result = spawnSync(command, commandArgs, {
112
- cwd,
113
- env,
114
- stdio: 'inherit',
115
- windowsHide: false,
116
- })
117
-
118
- if (
119
- !rotationEnabled ||
120
- result.error ||
121
- result.signal ||
122
- result.status !== PROCESS_GENERATION_ROTATE_EXIT_CODE
123
- ) {
124
- return result
125
- }
126
-
127
- const request = readRotationRequest(controlFile, token)
128
- if (!request) {
129
- console.error(
130
- 'ChatCode CLI rejected an invalid process-generation rotation request.',
131
- )
132
- return result
133
- }
134
-
135
- resumeSessionId = request.sessionId
136
- cwd = request.cwd
137
- generation += 1
138
- }
139
- } finally {
140
- removeControlFile(controlFile)
141
- }
142
- }