@namzu/cli 22.0.1 → 24.0.0
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/CHANGELOG.md +97 -0
- package/README.md +12 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +17 -10
- package/dist/cli.js.map +1 -1
- package/dist/commands/resident-flags.d.ts +19 -0
- package/dist/commands/resident-flags.d.ts.map +1 -0
- package/dist/commands/resident-flags.js +153 -0
- package/dist/commands/resident-flags.js.map +1 -0
- package/dist/commands/resident.d.ts +20 -0
- package/dist/commands/resident.d.ts.map +1 -0
- package/dist/commands/resident.js +380 -0
- package/dist/commands/resident.js.map +1 -0
- package/dist/commands/upgrade-progress.d.ts +10 -0
- package/dist/commands/upgrade-progress.d.ts.map +1 -0
- package/dist/commands/upgrade-progress.js +54 -0
- package/dist/commands/upgrade-progress.js.map +1 -0
- package/dist/commands/upgrade.d.ts +2 -0
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +79 -40
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/doctor/checks/chain.d.ts +2 -0
- package/dist/doctor/checks/chain.d.ts.map +1 -1
- package/dist/doctor/checks/chain.js +1 -0
- package/dist/doctor/checks/chain.js.map +1 -1
- package/dist/integrations/npm-invocation.d.ts +10 -0
- package/dist/integrations/npm-invocation.d.ts.map +1 -0
- package/dist/integrations/npm-invocation.js +23 -0
- package/dist/integrations/npm-invocation.js.map +1 -0
- package/dist/integrations/providers/credential-store.d.ts +8 -7
- package/dist/integrations/providers/credential-store.d.ts.map +1 -1
- package/dist/integrations/providers/credential-store.js +44 -17
- package/dist/integrations/providers/credential-store.js.map +1 -1
- package/dist/integrations/providers/discover.d.ts.map +1 -1
- package/dist/integrations/providers/discover.js +7 -2
- package/dist/integrations/providers/discover.js.map +1 -1
- package/dist/integrations/providers/harness-credentials.d.ts +2 -2
- package/dist/integrations/providers/harness-credentials.d.ts.map +1 -1
- package/dist/integrations/providers/harness-credentials.js +13 -8
- package/dist/integrations/providers/harness-credentials.js.map +1 -1
- package/dist/integrations/providers/model-reasoning.d.ts.map +1 -1
- package/dist/integrations/providers/model-reasoning.js +5 -0
- package/dist/integrations/providers/model-reasoning.js.map +1 -1
- package/dist/integrations/providers/setup.d.ts.map +1 -1
- package/dist/integrations/providers/setup.js +52 -5
- package/dist/integrations/providers/setup.js.map +1 -1
- package/dist/integrations/resident/foreground.d.ts +19 -0
- package/dist/integrations/resident/foreground.d.ts.map +1 -0
- package/dist/integrations/resident/foreground.js +95 -0
- package/dist/integrations/resident/foreground.js.map +1 -0
- package/dist/integrations/resident/lifecycle-errors.d.ts +9 -0
- package/dist/integrations/resident/lifecycle-errors.d.ts.map +1 -0
- package/dist/integrations/resident/lifecycle-errors.js +15 -0
- package/dist/integrations/resident/lifecycle-errors.js.map +1 -0
- package/dist/integrations/resident/owned-runner.d.ts +17 -0
- package/dist/integrations/resident/owned-runner.d.ts.map +1 -0
- package/dist/integrations/resident/owned-runner.js +91 -0
- package/dist/integrations/resident/owned-runner.js.map +1 -0
- package/dist/integrations/resident/runner-control.d.ts +47 -0
- package/dist/integrations/resident/runner-control.d.ts.map +1 -0
- package/dist/integrations/resident/runner-control.js +238 -0
- package/dist/integrations/resident/runner-control.js.map +1 -0
- package/dist/integrations/resident/runner-launch.d.ts +47 -0
- package/dist/integrations/resident/runner-launch.d.ts.map +1 -0
- package/dist/integrations/resident/runner-launch.js +140 -0
- package/dist/integrations/resident/runner-launch.js.map +1 -0
- package/dist/integrations/resident/runner-store.d.ts +44 -0
- package/dist/integrations/resident/runner-store.d.ts.map +1 -0
- package/dist/integrations/resident/runner-store.js +283 -0
- package/dist/integrations/resident/runner-store.js.map +1 -0
- package/dist/integrations/resident/runner-worker.d.ts +2 -0
- package/dist/integrations/resident/runner-worker.d.ts.map +1 -0
- package/dist/integrations/resident/runner-worker.js +143 -0
- package/dist/integrations/resident/runner-worker.js.map +1 -0
- package/dist/integrations/resident/session-step.d.ts +24 -0
- package/dist/integrations/resident/session-step.d.ts.map +1 -0
- package/dist/integrations/resident/session-step.js +366 -0
- package/dist/integrations/resident/session-step.js.map +1 -0
- package/dist/integrations/resident/storage.d.ts +17 -0
- package/dist/integrations/resident/storage.d.ts.map +1 -0
- package/dist/integrations/resident/storage.js +139 -0
- package/dist/integrations/resident/storage.js.map +1 -0
- package/dist/integrations/state/private-directory.d.ts +4 -2
- package/dist/integrations/state/private-directory.d.ts.map +1 -1
- package/dist/integrations/state/private-directory.js +6 -4
- package/dist/integrations/state/private-directory.js.map +1 -1
- package/dist/integrations/subagents/runtime.d.ts +3 -1
- package/dist/integrations/subagents/runtime.d.ts.map +1 -1
- package/dist/integrations/subagents/runtime.js +56 -12
- package/dist/integrations/subagents/runtime.js.map +1 -1
- package/dist/integrations/web/exa-search.d.ts +4 -0
- package/dist/integrations/web/exa-search.d.ts.map +1 -0
- package/dist/integrations/web/exa-search.js +154 -0
- package/dist/integrations/web/exa-search.js.map +1 -0
- package/dist/integrations/web/search.d.ts +1 -1
- package/dist/integrations/web/search.d.ts.map +1 -1
- package/dist/integrations/web/search.js +27 -34
- package/dist/integrations/web/search.js.map +1 -1
- package/dist/tui/AgentExplorer.d.ts.map +1 -1
- package/dist/tui/AgentExplorer.js +10 -4
- package/dist/tui/AgentExplorer.js.map +1 -1
- package/dist/tui/App.js +1 -1
- package/dist/tui/App.js.map +1 -1
- package/dist/tui/ComposerFrame.d.ts +2 -2
- package/dist/tui/ComposerFrame.d.ts.map +1 -1
- package/dist/tui/ComposerFrame.js +3 -83
- package/dist/tui/ComposerFrame.js.map +1 -1
- package/dist/tui/LiveActivity.d.ts +1 -1
- package/dist/tui/LiveActivity.d.ts.map +1 -1
- package/dist/tui/LiveActivity.js +23 -8
- package/dist/tui/LiveActivity.js.map +1 -1
- package/dist/tui/agent.d.ts +10 -1
- package/dist/tui/agent.d.ts.map +1 -1
- package/dist/tui/agent.js +109 -24
- package/dist/tui/agent.js.map +1 -1
- package/dist/tui/exit-summary.d.ts +1 -1
- package/dist/tui/exit-summary.d.ts.map +1 -1
- package/dist/tui/exit-summary.js +17 -5
- package/dist/tui/exit-summary.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { randomBytes, randomUUID } from 'node:crypto';
|
|
2
|
+
import { lstatSync, readFileSync, readdirSync } from 'node:fs';
|
|
3
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
4
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
5
|
+
import { ResidentConflictError, isEntityId } from '@namzu/sdk';
|
|
6
|
+
import { publishPrivateJsonIfAbsent } from '../state/immutable-json.js';
|
|
7
|
+
import { ensurePrivateStateDirectory } from '../state/private-directory.js';
|
|
8
|
+
const UUID = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/u;
|
|
9
|
+
const REVISION_NAME = /^([1-9][0-9]{0,15})\.json$/u;
|
|
10
|
+
const FIELDS = [
|
|
11
|
+
'version',
|
|
12
|
+
'revision',
|
|
13
|
+
'instanceId',
|
|
14
|
+
'tenantId',
|
|
15
|
+
'projectId',
|
|
16
|
+
'agentKey',
|
|
17
|
+
'cwd',
|
|
18
|
+
'mode',
|
|
19
|
+
'phase',
|
|
20
|
+
'reservedAt',
|
|
21
|
+
'maxSteps',
|
|
22
|
+
'pauseGeneration',
|
|
23
|
+
'pid',
|
|
24
|
+
'port',
|
|
25
|
+
'token',
|
|
26
|
+
'endedAt',
|
|
27
|
+
'outcome',
|
|
28
|
+
];
|
|
29
|
+
function integer(value, minimum) {
|
|
30
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= minimum;
|
|
31
|
+
}
|
|
32
|
+
function canonicalPath(value) {
|
|
33
|
+
return !value.includes('\0') && isAbsolute(value) && resolve(value) === value;
|
|
34
|
+
}
|
|
35
|
+
function location(resident) {
|
|
36
|
+
if (!isEntityId(resident.tenantId, 'tenant') ||
|
|
37
|
+
!isEntityId(resident.projectId, 'project') ||
|
|
38
|
+
!/^[a-z0-9][a-z0-9_-]{0,63}$/u.test(resident.agentKey) ||
|
|
39
|
+
!canonicalPath(resident.root) ||
|
|
40
|
+
!canonicalPath(resident.cwd)) {
|
|
41
|
+
throw new Error('Invalid resident scope for runner ownership.');
|
|
42
|
+
}
|
|
43
|
+
const base = join(resident.root, 'projects', resident.projectId, 'cli', 'residents', resident.agentKey);
|
|
44
|
+
if (resident.artifactsRoot !== join(base, 'attempts')) {
|
|
45
|
+
throw new Error('Resident runner path does not match its bound project and agent.');
|
|
46
|
+
}
|
|
47
|
+
return { base, runner: join(base, 'runner'), revisions: join(base, 'runner', 'revisions') };
|
|
48
|
+
}
|
|
49
|
+
function realDirectory(path) {
|
|
50
|
+
try {
|
|
51
|
+
const entry = lstatSync(path);
|
|
52
|
+
if (!entry.isDirectory() || entry.isSymbolicLink()) {
|
|
53
|
+
throw new Error(`Resident runner state requires a real directory: ${path}`);
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error.code === 'ENOENT')
|
|
59
|
+
return false;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function revisions(resident) {
|
|
64
|
+
const paths = location(resident);
|
|
65
|
+
let current = resident.root;
|
|
66
|
+
if (!realDirectory(current))
|
|
67
|
+
return [];
|
|
68
|
+
for (const segment of [
|
|
69
|
+
'projects',
|
|
70
|
+
resident.projectId,
|
|
71
|
+
'cli',
|
|
72
|
+
'residents',
|
|
73
|
+
resident.agentKey,
|
|
74
|
+
'runner',
|
|
75
|
+
'revisions',
|
|
76
|
+
]) {
|
|
77
|
+
current = join(current, segment);
|
|
78
|
+
if (!realDirectory(current))
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
const numbers = [];
|
|
82
|
+
for (const entry of readdirSync(paths.revisions, { withFileTypes: true })) {
|
|
83
|
+
// Publication scratch names never establish ownership, even after a crash.
|
|
84
|
+
if (/^[1-9][0-9]{0,15}\.json\.candidate\.[0-9a-f-]+$/u.test(entry.name))
|
|
85
|
+
continue;
|
|
86
|
+
const match = REVISION_NAME.exec(entry.name);
|
|
87
|
+
const revision = match ? Number(match[1]) : Number.NaN;
|
|
88
|
+
if (!integer(revision, 1) || !entry.isFile() || entry.isSymbolicLink()) {
|
|
89
|
+
throw new Error(`Invalid resident runner revision entry: ${join(paths.revisions, entry.name)}`);
|
|
90
|
+
}
|
|
91
|
+
numbers.push(revision);
|
|
92
|
+
}
|
|
93
|
+
return numbers.sort((left, right) => right - left);
|
|
94
|
+
}
|
|
95
|
+
function checked(resident, raw, revision) {
|
|
96
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
97
|
+
throw new Error('Resident runner record must be an object.');
|
|
98
|
+
}
|
|
99
|
+
const value = raw;
|
|
100
|
+
if (Object.keys(value).length !== FIELDS.length || FIELDS.some((field) => !(field in value))) {
|
|
101
|
+
throw new Error('Resident runner record has missing or unsupported fields.');
|
|
102
|
+
}
|
|
103
|
+
if (value.version !== 1 ||
|
|
104
|
+
value.revision !== revision ||
|
|
105
|
+
!integer(value.revision, 1) ||
|
|
106
|
+
typeof value.instanceId !== 'string' ||
|
|
107
|
+
!UUID.test(value.instanceId) ||
|
|
108
|
+
value.tenantId !== resident.tenantId ||
|
|
109
|
+
value.projectId !== resident.projectId ||
|
|
110
|
+
value.agentKey !== resident.agentKey ||
|
|
111
|
+
value.cwd !== resident.cwd ||
|
|
112
|
+
(value.mode !== 'foreground' && value.mode !== 'background') ||
|
|
113
|
+
!['reserved', 'running', 'stopped', 'released'].includes(String(value.phase)) ||
|
|
114
|
+
!integer(value.reservedAt, 0) ||
|
|
115
|
+
!integer(value.maxSteps, 1) ||
|
|
116
|
+
!integer(value.pauseGeneration, 0) ||
|
|
117
|
+
(value.pid !== null && !integer(value.pid, 1)) ||
|
|
118
|
+
(value.port !== null && (!integer(value.port, 1) || value.port > 65_535)) ||
|
|
119
|
+
typeof value.token !== 'string' ||
|
|
120
|
+
!/^[0-9a-f]{64}$/u.test(value.token)) {
|
|
121
|
+
throw new Error('Resident runner version, revision, scope or ownership metadata is invalid.');
|
|
122
|
+
}
|
|
123
|
+
const terminal = value.phase === 'stopped' || value.phase === 'released';
|
|
124
|
+
if ((terminal
|
|
125
|
+
? !integer(value.endedAt, 0) ||
|
|
126
|
+
typeof value.outcome !== 'string' ||
|
|
127
|
+
!value.outcome.trim() ||
|
|
128
|
+
value.outcome.length > 8_000
|
|
129
|
+
: value.endedAt !== null || value.outcome !== null) ||
|
|
130
|
+
(value.phase === 'reserved' && (value.pid !== null || value.port !== null)) ||
|
|
131
|
+
(value.phase === 'running' && value.pid === null) ||
|
|
132
|
+
(value.pid === null && value.port !== null) ||
|
|
133
|
+
(value.mode === 'background' && value.pid !== null && value.port === null)) {
|
|
134
|
+
throw new Error('Resident runner phase and process metadata disagree.');
|
|
135
|
+
}
|
|
136
|
+
return Object.freeze(value);
|
|
137
|
+
}
|
|
138
|
+
function readRevision(resident, revision) {
|
|
139
|
+
const path = join(location(resident).revisions, `${revision}.json`);
|
|
140
|
+
try {
|
|
141
|
+
const entry = lstatSync(path);
|
|
142
|
+
if (!entry.isFile() || entry.isSymbolicLink() || entry.size > 64 * 1024) {
|
|
143
|
+
throw new Error('expected a bounded regular file without a symbolic link');
|
|
144
|
+
}
|
|
145
|
+
return checked(resident, JSON.parse(readFileSync(path, 'utf8')), revision);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
// JSON.parse diagnostics can quote private record bytes, including the
|
|
149
|
+
// control token. Keep filesystem/schema details, never parser excerpts.
|
|
150
|
+
const detail = error instanceof SyntaxError
|
|
151
|
+
? 'invalid JSON'
|
|
152
|
+
: error instanceof Error
|
|
153
|
+
? error.message
|
|
154
|
+
: 'unknown read failure';
|
|
155
|
+
throw new Error(`Cannot read resident runner revision ${path}: ${detail}. Refusing ownership recovery from damaged state.`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** An absent runner is a read-only result, never an instruction to initialize it. */
|
|
159
|
+
export function readRunner(resident) {
|
|
160
|
+
const head = revisions(resident)[0];
|
|
161
|
+
return head === undefined ? null : readRevision(resident, head);
|
|
162
|
+
}
|
|
163
|
+
/** The original runner's final evidence remains visible after a successor starts. */
|
|
164
|
+
export function readRunnerInstance(resident, instanceId) {
|
|
165
|
+
if (!UUID.test(instanceId))
|
|
166
|
+
throw new Error('Invalid resident runner instance ID.');
|
|
167
|
+
for (const revision of revisions(resident)) {
|
|
168
|
+
const record = readRevision(resident, revision);
|
|
169
|
+
if (record.instanceId === instanceId)
|
|
170
|
+
return record;
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
function publish(resident, expected, propose) {
|
|
175
|
+
const current = readRunner(resident);
|
|
176
|
+
if (!isDeepStrictEqual(current, expected))
|
|
177
|
+
throw new ResidentConflictError();
|
|
178
|
+
const next = (current?.revision ?? 0) + 1;
|
|
179
|
+
if (!integer(next, 1))
|
|
180
|
+
throw new Error('Resident runner revision overflow.');
|
|
181
|
+
const record = checked(resident, propose(next), next);
|
|
182
|
+
const paths = location(resident);
|
|
183
|
+
if (!realDirectory(paths.base))
|
|
184
|
+
throw new Error('Resident binding directory is missing.');
|
|
185
|
+
const runner = ensurePrivateStateDirectory(paths.base, 'runner');
|
|
186
|
+
const directory = ensurePrivateStateDirectory(runner, 'revisions');
|
|
187
|
+
publishPrivateJsonIfAbsent(join(directory, `${next}.json`), record);
|
|
188
|
+
// The helper reports EEXIST by preserving the winner. Equality proves whose
|
|
189
|
+
// complete proposal was published; never retry a stale operation on that owner.
|
|
190
|
+
if (!isDeepStrictEqual(readRevision(resident, next), record))
|
|
191
|
+
throw new ResidentConflictError();
|
|
192
|
+
return record;
|
|
193
|
+
}
|
|
194
|
+
/** Reserve one explicitly authorized invocation; an occupied owner is never stolen. */
|
|
195
|
+
export function reserveRunner(resident, options) {
|
|
196
|
+
if ((options.mode !== 'foreground' && options.mode !== 'background') ||
|
|
197
|
+
!integer(options.maxSteps, 1) ||
|
|
198
|
+
!integer(options.pauseGeneration, 0)) {
|
|
199
|
+
throw new Error('Invalid resident runner invocation limits or mode.');
|
|
200
|
+
}
|
|
201
|
+
const current = readRunner(resident);
|
|
202
|
+
if (current && current.phase !== 'stopped' && current.phase !== 'released') {
|
|
203
|
+
throw new ResidentConflictError();
|
|
204
|
+
}
|
|
205
|
+
return publish(resident, current, (revision) => ({
|
|
206
|
+
version: 1,
|
|
207
|
+
revision,
|
|
208
|
+
instanceId: randomUUID(),
|
|
209
|
+
tenantId: resident.tenantId,
|
|
210
|
+
projectId: resident.projectId,
|
|
211
|
+
agentKey: resident.agentKey,
|
|
212
|
+
cwd: resident.cwd,
|
|
213
|
+
mode: options.mode,
|
|
214
|
+
phase: 'reserved',
|
|
215
|
+
reservedAt: Date.now(),
|
|
216
|
+
maxSteps: options.maxSteps,
|
|
217
|
+
pauseGeneration: options.pauseGeneration,
|
|
218
|
+
pid: null,
|
|
219
|
+
port: null,
|
|
220
|
+
token: randomBytes(32).toString('hex'),
|
|
221
|
+
endedAt: null,
|
|
222
|
+
outcome: null,
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
export function attachRunning(resident, expected, process) {
|
|
226
|
+
if (expected.phase !== 'reserved')
|
|
227
|
+
throw new ResidentConflictError();
|
|
228
|
+
return publish(resident, expected, (revision) => ({
|
|
229
|
+
...expected,
|
|
230
|
+
revision,
|
|
231
|
+
phase: 'running',
|
|
232
|
+
pid: process.pid,
|
|
233
|
+
port: process.port,
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
/** Publish only after the executor and its controls have drained. */
|
|
237
|
+
export function finishRunner(resident, expected, outcome) {
|
|
238
|
+
if (expected.phase !== 'reserved' && expected.phase !== 'running') {
|
|
239
|
+
throw new ResidentConflictError();
|
|
240
|
+
}
|
|
241
|
+
return publish(resident, expected, (revision) => ({
|
|
242
|
+
...expected,
|
|
243
|
+
revision,
|
|
244
|
+
phase: 'stopped',
|
|
245
|
+
endedAt: Date.now(),
|
|
246
|
+
outcome,
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
/** Explicit operator recovery of an exact owner; this is never proof of drainage. */
|
|
250
|
+
export function releaseRunner(resident, expected) {
|
|
251
|
+
if (expected.phase !== 'reserved' && expected.phase !== 'running') {
|
|
252
|
+
throw new ResidentConflictError();
|
|
253
|
+
}
|
|
254
|
+
return publish(resident, expected, (revision) => ({
|
|
255
|
+
...expected,
|
|
256
|
+
revision,
|
|
257
|
+
phase: 'released',
|
|
258
|
+
endedAt: Date.now(),
|
|
259
|
+
outcome: 'Operator explicitly released this owner after inspecting stopped executors.',
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
/** Status reports retain ownership evidence without disclosing the control nonce. */
|
|
263
|
+
export function publicRunner(record) {
|
|
264
|
+
return {
|
|
265
|
+
version: record.version,
|
|
266
|
+
revision: record.revision,
|
|
267
|
+
instanceId: record.instanceId,
|
|
268
|
+
tenantId: record.tenantId,
|
|
269
|
+
projectId: record.projectId,
|
|
270
|
+
agentKey: record.agentKey,
|
|
271
|
+
cwd: record.cwd,
|
|
272
|
+
mode: record.mode,
|
|
273
|
+
phase: record.phase,
|
|
274
|
+
reservedAt: record.reservedAt,
|
|
275
|
+
maxSteps: record.maxSteps,
|
|
276
|
+
pauseGeneration: record.pauseGeneration,
|
|
277
|
+
pid: record.pid,
|
|
278
|
+
port: record.port,
|
|
279
|
+
endedAt: record.endedAt,
|
|
280
|
+
outcome: record.outcome,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=runner-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-store.js","sourceRoot":"","sources":["../../../src/integrations/resident/runner-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,SAAS,E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E,MAAM,CAAC,OAAO;QACvB,OAAO,EAAE,MAAM,CAAC,OAAO;KACvB,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-worker.d.ts","sourceRoot":"","sources":["../../../src/integrations/resident/runner-worker.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { realpath } from 'node:fs/promises';
|
|
2
|
+
import { openSessions } from '../sessions/store.js';
|
|
3
|
+
import { runOwnedResident } from './owned-runner.js';
|
|
4
|
+
import { finishRunner, readRunner } from './runner-store.js';
|
|
5
|
+
import { createResidentSessionStep } from './session-step.js';
|
|
6
|
+
import { lookupResident } from './storage.js';
|
|
7
|
+
// Internal child entrypoint. Launch parameters arrive only through the parent's
|
|
8
|
+
// IPC channel; credentials and resolved configuration are never copied to disk.
|
|
9
|
+
async function main() {
|
|
10
|
+
if (!process.send)
|
|
11
|
+
throw new Error('Resident workers must be started through namzu resident start.');
|
|
12
|
+
const controller = new AbortController();
|
|
13
|
+
let handedOff = false;
|
|
14
|
+
const stop = () => controller.abort(new Error('Resident worker interrupted before or during execution.'));
|
|
15
|
+
const disconnected = () => {
|
|
16
|
+
if (!handedOff)
|
|
17
|
+
stop();
|
|
18
|
+
};
|
|
19
|
+
process.on('disconnect', disconnected);
|
|
20
|
+
process.once('SIGINT', stop);
|
|
21
|
+
process.once('SIGTERM', stop);
|
|
22
|
+
let resident = null;
|
|
23
|
+
let owner = null;
|
|
24
|
+
let lifecycleStarted = false;
|
|
25
|
+
try {
|
|
26
|
+
const launch = await new Promise((resolve, reject) => {
|
|
27
|
+
const timer = setTimeout(() => reject(new Error('Resident startup parameters did not arrive.')), 15_000);
|
|
28
|
+
process.once('message', (message) => {
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
if (!message ||
|
|
31
|
+
typeof message !== 'object' ||
|
|
32
|
+
message.version !== 1) {
|
|
33
|
+
reject(new Error('Invalid resident worker launch.'));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
resolve(message);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
controller.signal.throwIfAborted();
|
|
40
|
+
resident = await lookupResident(launch.cwd, launch.agentKey);
|
|
41
|
+
if (!resident || resident.cwd !== launch.cwd || (await realpath(launch.cwd)) !== launch.cwd)
|
|
42
|
+
throw new Error('Resident execution directory changed before worker startup.');
|
|
43
|
+
const candidate = readRunner(resident);
|
|
44
|
+
if (candidate?.instanceId !== launch.instanceId || candidate.phase !== 'reserved')
|
|
45
|
+
throw new Error('Resident worker does not own this startup reservation.');
|
|
46
|
+
owner = candidate;
|
|
47
|
+
const sessions = await openSessions(resident.cwd);
|
|
48
|
+
if (sessions.projectId !== resident.projectId || sessions.tenantId !== resident.tenantId)
|
|
49
|
+
throw new Error('Resident project or tenant changed before worker startup.');
|
|
50
|
+
const ctx = {
|
|
51
|
+
config: launch.config,
|
|
52
|
+
formatter: { name: 'json', print() { }, info() { }, error() { } },
|
|
53
|
+
};
|
|
54
|
+
const step = createResidentSessionStep({
|
|
55
|
+
ctx,
|
|
56
|
+
cwd: resident.cwd,
|
|
57
|
+
sessions,
|
|
58
|
+
flags: launch.flags,
|
|
59
|
+
toolLoading: launch.toolLoading,
|
|
60
|
+
contextProfile: launch.contextProfile,
|
|
61
|
+
artifactsRoot: resident.artifactsRoot,
|
|
62
|
+
});
|
|
63
|
+
lifecycleStarted = true;
|
|
64
|
+
const result = await runOwnedResident({
|
|
65
|
+
resident,
|
|
66
|
+
owner,
|
|
67
|
+
step,
|
|
68
|
+
signal: controller.signal,
|
|
69
|
+
keepAlive: true,
|
|
70
|
+
maxIdleMs: launch.maxIdleMs,
|
|
71
|
+
ready: async (ready, signal) => {
|
|
72
|
+
await new Promise((resolve, reject) => {
|
|
73
|
+
const cleanup = () => {
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
process.removeListener('message', go);
|
|
76
|
+
signal.removeEventListener('abort', aborted);
|
|
77
|
+
};
|
|
78
|
+
const aborted = () => {
|
|
79
|
+
cleanup();
|
|
80
|
+
reject(signal.reason);
|
|
81
|
+
};
|
|
82
|
+
const go = (message) => {
|
|
83
|
+
if (message &&
|
|
84
|
+
typeof message === 'object' &&
|
|
85
|
+
message.kind === 'go' &&
|
|
86
|
+
message.instanceId === ready.instanceId) {
|
|
87
|
+
handedOff = true;
|
|
88
|
+
cleanup();
|
|
89
|
+
resolve();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const timer = setTimeout(() => {
|
|
93
|
+
cleanup();
|
|
94
|
+
reject(new Error('Resident startup handoff timed out.'));
|
|
95
|
+
}, 15_000);
|
|
96
|
+
process.on('message', go);
|
|
97
|
+
signal.addEventListener('abort', aborted, { once: true });
|
|
98
|
+
if (signal.aborted) {
|
|
99
|
+
aborted();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
process.send?.({ kind: 'ready', instanceId: ready.instanceId }, (error) => {
|
|
103
|
+
if (error) {
|
|
104
|
+
cleanup();
|
|
105
|
+
reject(error);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
return ['unresolved', 'contended'].includes(result.status)
|
|
112
|
+
? 1
|
|
113
|
+
: result.status === 'cancelled'
|
|
114
|
+
? 130
|
|
115
|
+
: 0;
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
if (!lifecycleStarted && resident && owner?.phase === 'reserved') {
|
|
119
|
+
try {
|
|
120
|
+
finishRunner(resident, owner, 'startup_failed');
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
/* A successor is never released by this worker. */
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (process.connected)
|
|
127
|
+
await new Promise((resolve) => {
|
|
128
|
+
process.send?.({
|
|
129
|
+
kind: 'error',
|
|
130
|
+
instanceId: owner?.instanceId,
|
|
131
|
+
message: error instanceof Error ? error.message : String(error),
|
|
132
|
+
}, () => resolve());
|
|
133
|
+
});
|
|
134
|
+
return 1;
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
process.removeListener('disconnect', disconnected);
|
|
138
|
+
process.removeListener('SIGINT', stop);
|
|
139
|
+
process.removeListener('SIGTERM', stop);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
void main().then((code) => process.exit(code), () => process.exit(1));
|
|
143
|
+
//# sourceMappingURL=runner-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-worker.js","sourceRoot":"","sources":["../../../src/integrations/resident/runner-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,gFAAgF;AAChF,gFAAgF;AAChF,KAAK,UAAU,IAAI;IAClB,IAAI,CAAC,OAAO,CAAC,IAAI;QAChB,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAA;IAClF,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;IACxC,IAAI,SAAS,GAAG,KAAK,CAAA;IACrB,MAAM,IAAI,GAAG,GAAG,EAAE,CACjB,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC,CAAA;IACvF,MAAM,YAAY,GAAG,GAAG,EAAE;QACzB,IAAI,CAAC,SAAS;YAAE,IAAI,EAAE,CAAA;IACvB,CAAC,CAAA;IACD,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;IACtC,OAAO,CAA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I,CAAC,CAAA;IACxC,CAAC;AACF,CAAC;AAED,KAAK,IAAI,EAAE,CAAC,IAAI,CACf,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAC5B,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CACrB,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ResidentContextualStep } from '@namzu/sdk';
|
|
2
|
+
import { type RunFlags } from '../../commands/run-flags.js';
|
|
3
|
+
import type { CommandContext } from '../../commands/types.js';
|
|
4
|
+
import type { CliSessions } from '../sessions/store.js';
|
|
5
|
+
export interface ResidentSessionStepOptions {
|
|
6
|
+
/** Already resolved through the CLI project trust boundary. */
|
|
7
|
+
readonly ctx: CommandContext;
|
|
8
|
+
readonly cwd: string;
|
|
9
|
+
readonly sessions: CliSessions;
|
|
10
|
+
readonly flags: RunFlags;
|
|
11
|
+
/** Defer optional tool schemas per step; authority and instructions remain unchanged. */
|
|
12
|
+
readonly toolLoading?: 'eager' | 'deferred';
|
|
13
|
+
/** Resident policy with layered snapshots by default; interactive preserves the earlier prompt. */
|
|
14
|
+
readonly contextProfile?: 'resident' | 'interactive';
|
|
15
|
+
/** Private, host-owned directory for per-claim receipts. */
|
|
16
|
+
readonly artifactsRoot: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* One admitted pursuit uses the normal CLI session and SDK answer-review loop.
|
|
20
|
+
* There is no provider construction before admission, conversation substitution,
|
|
21
|
+
* checkpoint replay, or host-side model retry. An error keeps the SDK claim held.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createResidentSessionStep(options: ResidentSessionStepOptions): ResidentContextualStep;
|
|
24
|
+
//# sourceMappingURL=session-step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-step.d.ts","sourceRoot":"","sources":["../../../src/integrations/resident/session-step.ts"],"names":[],"mappings":"AAIA,OAAO,EAGN,KAAK,sBAAsB,EAQ3B,MAAM,YAAY,CAAA;AAEnB,OAAO,EACN,KAAK,QAAQ,EAKb,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAO7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAuBvD,MAAM,WAAW,0BAA0B;IAC1C,+DAA+D;IAC/D,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAA;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAA;IAC9B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAA;IACxB,yFAAyF;IACzF,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,UAAU,CAAA;IAC3C,mGAAmG;IACnG,QAAQ,CAAC,cAAc,CAAC,EAAE,UAAU,GAAG,aAAa,CAAA;IACpD,4DAA4D;IAC5D,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;CAC9B;AAuGD;;;;GAIG;AACH,wBAAgB,yBAAyB,CACxC,OAAO,EAAE,0BAA0B,GACjC,sBAAsB,CAwPxB"}
|