@chatcode/chatcode-cli-test 1.0.47 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +41 -135
- package/README.zh.md +63 -0
- package/lib/bin.js +303 -0
- package/lib/chatcode-home-B93iESZd.js +48 -0
- package/lib/dump-config-WbxM4B3p.js +53 -0
- package/lib/home-migration-DLaSvmfn.js +307 -0
- package/lib/plugin-CMMvQgyR.js +31 -0
- package/lib/profile-boot-CCxnpvy7.js +331 -0
- package/lib/profile-boot.js +2 -0
- package/lib/types/args.d.ts +76 -0
- package/lib/types/bin.d.ts +15 -0
- package/lib/types/chatcode-home.d.ts +30 -0
- package/lib/types/dump-config.d.ts +18 -0
- package/lib/types/home-migration.d.ts +58 -0
- package/lib/types/plugin.d.ts +7 -0
- package/lib/types/process-shutdown.d.ts +20 -0
- package/lib/types/profile-boot.d.ts +94 -0
- package/lib/types/startup-diagnostics.d.ts +19 -0
- package/package.json +310 -112
- package/bin/cli.js +0 -102
- package/bin/generation-supervisor.js +0 -142
- package/dist/cli.js +0 -8793
- package/dist/vendor/ripgrep/COPYING +0 -3
- package/dist/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/dist/vendor/ripgrep/arm64-linux/rg +0 -0
- package/dist/vendor/ripgrep/arm64-win32/rg.exe +0 -0
- package/dist/vendor/ripgrep/x64-darwin/rg +0 -0
- package/dist/vendor/ripgrep/x64-linux/rg +0 -0
- package/dist/vendor/ripgrep/x64-win32/rg.exe +0 -0
|
@@ -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
|
-
}
|