mtech-ai-local-runner 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -10,6 +10,14 @@ The package stores safe runner configuration locally and keeps OAuth refresh cre
|
|
|
10
10
|
|
|
11
11
|
Public npm installation requires no npm account or publishing OTP. Setup requires Gateway OAuth login, and local Claude Code must already be authenticated (`claude auth status`).
|
|
12
12
|
|
|
13
|
+
## 0.1.14: foreground administrator authentication wait
|
|
14
|
+
|
|
15
|
+
The manual Codex pilot waits for administrator authentication before starting
|
|
16
|
+
the 60-second profile inventory deadline. Cancelling the execution aborts its
|
|
17
|
+
owned pending query. Fixed error codes identify authentication and query failures
|
|
18
|
+
without exposing native stderr. This patch does not update a running daemon or
|
|
19
|
+
establish successful real-account Codex execution.
|
|
20
|
+
|
|
13
21
|
## 0.1.10: enforced PreToolUse hook
|
|
14
22
|
|
|
15
23
|
Earlier releases configured a hook command that the shell could not run, so Claude
|
|
@@ -153,4 +161,11 @@ into a completed job. Existing reconciliation rules still apply.
|
|
|
153
161
|
|
|
154
162
|
### Manual Codex pilot (0.1.11)
|
|
155
163
|
|
|
164
|
+
The foreground inventory separates human authentication wait from the bounded
|
|
165
|
+
query and evidence freshness. Its query deadline starts only after the fixed
|
|
166
|
+
root-identity check completes, not while the administrator prompt is waiting.
|
|
167
|
+
Cancellation revokes the pending query and rejects late results; authentication,
|
|
168
|
+
query timeout, command and validation failures use distinct safe codes. The
|
|
169
|
+
inventory must still be fresh at Codex spawn. No automatic retry is performed.
|
|
170
|
+
|
|
156
171
|
The reviewed manual Codex path preserves the existing CLI and ChatGPT login. It is separate from unattended daemon readiness. After the exact CLI/native reader and Gateway release are installed, an employee-authorized foreground pilot uses `mtec-ai-local-runner manual-codex --job-id=<approved Job UUID>`. It refuses a running daemon, unresolved recovery state, unknown release/account or a different Job. It does not stop services or alter personal settings. A direct administrator policy inventory occurs just before the approved execution; historical inventory is not continuous MDM monitoring. The Gateway OAuth client refuses refresh in this manual command. Actual vendor account startup may still refresh shared credentials and requires disclosure in the exact launch approval.
|
|
@@ -55,8 +55,8 @@ export async function runManualCodexJob(input, deps) {
|
|
|
55
55
|
inner.attachCleanup(cleanup);
|
|
56
56
|
return inner.prepare(ctx);
|
|
57
57
|
}, async inspect(plan) { if (!inner)
|
|
58
|
-
throw Error('MANUAL_PILOT_NOT_PREPARED'); return inner.inspect(plan); }, revoke() { inner?.revoke(); }, attachCleanup(fn) { if (cleanup)
|
|
59
|
-
throw Error('MANUAL_PILOT_DUPLICATE_CLEANUP'); cleanup = fn; }, async close() { await inner?.close(); } };
|
|
58
|
+
throw Error('MANUAL_PILOT_NOT_PREPARED'); return inner.inspect(plan); }, revoke() { controller?.cancel(); inner?.revoke(); }, attachCleanup(fn) { if (cleanup)
|
|
59
|
+
throw Error('MANUAL_PILOT_DUPLICATE_CLEANUP'); cleanup = fn; }, async close() { controller?.cancel(); await inner?.close(); } };
|
|
60
60
|
const plugin = new CodexPlugin({ probe, options: () => buildCodexExecJobOptions({ jobId: job.id, worktreePath: options.worktreePath, stateRoot: input.stateRoot, env: input.env, productionJob: () => lazy, processHost: deps?.processHost }) });
|
|
61
61
|
adapter = await plugin.create(options);
|
|
62
62
|
return adapter;
|
|
@@ -25,8 +25,10 @@ export function createManualPilotController(input, deps) {
|
|
|
25
25
|
const claim = structuredClone(input.claim), releases = structuredClone(deps?.releases ?? CODEX_EXEC_RELEASES), readLocal = deps?.readLocal, now = deps?.now ?? Date.now;
|
|
26
26
|
const account = path.resolve(input.codexHome ?? path.join(input.home, '.codex'));
|
|
27
27
|
let used = false, closed = false, manual, host;
|
|
28
|
-
const
|
|
29
|
-
|
|
28
|
+
const queryAbort = new AbortController();
|
|
29
|
+
const cancel = () => { closed = true; queryAbort.abort(); manual?.revoke(); };
|
|
30
|
+
const close = async () => { cancel(); await host?.close(); };
|
|
31
|
+
return Object.freeze({ close, cancel, async prepare() {
|
|
30
32
|
if (used || closed)
|
|
31
33
|
throw rejected();
|
|
32
34
|
used = true;
|
|
@@ -65,7 +67,7 @@ export function createManualPilotController(input, deps) {
|
|
|
65
67
|
if (closed)
|
|
66
68
|
throw rejected();
|
|
67
69
|
stage = 'codex_manual_inventory';
|
|
68
|
-
const inventory = await (deps?.collectInventory ?? createManualProfileQuery().collectOnce)();
|
|
70
|
+
const inventory = await (deps?.collectInventory ?? createManualProfileQuery().collectOnce)(queryAbort.signal);
|
|
69
71
|
if (closed)
|
|
70
72
|
throw rejected();
|
|
71
73
|
stage = 'codex_manual_policy_scope';
|
|
@@ -1,30 +1,175 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
|
-
import { promisify } from 'node:util';
|
|
3
2
|
import { createHash } from 'node:crypto';
|
|
4
3
|
import { emptyProfileInventoryXml } from './codex-native-observation.js';
|
|
4
|
+
import { executionError, executionFailure } from './execution-failure.js';
|
|
5
5
|
const rejected = () => Error('CODEX_MANUAL_PROFILE_QUERY_REJECTED');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const AUTHENTICATED = 'MTEC_PROFILE_AUTHENTICATED_V1';
|
|
7
|
+
const QUERY_TIMEOUT_MS = 60_000;
|
|
8
|
+
const failureMarkers = Object.freeze({
|
|
9
|
+
MTEC_PROFILE_AUTH_CANCELLED: 'CODEX_MANUAL_AUTH_CANCELLED',
|
|
10
|
+
MTEC_PROFILE_AUTH_REJECTED: 'CODEX_MANUAL_AUTH_REJECTED',
|
|
11
|
+
MTEC_PROFILE_QUERY_TIMEOUT: 'CODEX_MANUAL_QUERY_TIMEOUT',
|
|
12
|
+
MTEC_PROFILE_QUERY_FAILED: 'CODEX_MANUAL_QUERY_COMMAND_FAILED',
|
|
13
|
+
MTEC_PROFILE_NONROOT: 'CODEX_MANUAL_QUERY_NONROOT',
|
|
14
|
+
});
|
|
15
|
+
const failure = (code) => executionError(rejected(), 'codex_manual_inventory', code);
|
|
16
|
+
/** No Runner deadline while the employee is authenticating. The fixed first
|
|
17
|
+
* command acquires the grant; only then does the bounded read-only query start.
|
|
18
|
+
* No user commands, credential writes or persistent privileged process. */
|
|
19
|
+
export const MANUAL_PROFILES_ARGUMENTS = Object.freeze(['-e', `with timeout of 2147483647 seconds
|
|
20
|
+
try
|
|
21
|
+
set uid to do shell script "/usr/bin/id -u" with administrator privileges
|
|
22
|
+
on error messageText number errorNumber
|
|
23
|
+
if errorNumber is -128 then
|
|
24
|
+
log "MTEC_PROFILE_AUTH_CANCELLED"
|
|
25
|
+
else
|
|
26
|
+
log "MTEC_PROFILE_AUTH_REJECTED"
|
|
27
|
+
end if
|
|
28
|
+
error "Administrator authentication failed" number 10001
|
|
29
|
+
end try
|
|
30
|
+
if uid is not "0" then
|
|
31
|
+
log "MTEC_PROFILE_NONROOT"
|
|
32
|
+
error "Unexpected query identity" number 10002
|
|
33
|
+
end if
|
|
34
|
+
log "MTEC_PROFILE_AUTHENTICATED_V1"
|
|
35
|
+
try
|
|
36
|
+
with timeout of 60 seconds
|
|
37
|
+
set inventory to do shell script "/usr/bin/profiles list -all -output stdout-xml" with administrator privileges
|
|
38
|
+
end timeout
|
|
39
|
+
on error messageText number errorNumber
|
|
40
|
+
if errorNumber is -1712 then
|
|
41
|
+
log "MTEC_PROFILE_QUERY_TIMEOUT"
|
|
42
|
+
else
|
|
43
|
+
log "MTEC_PROFILE_QUERY_FAILED"
|
|
44
|
+
end if
|
|
45
|
+
error "Profile inventory failed" number 10003
|
|
46
|
+
end try
|
|
47
|
+
return uid & linefeed & inventory
|
|
48
|
+
end timeout`]);
|
|
49
|
+
/** Injectable process seam, never a task-provided command. Protocol markers are
|
|
50
|
+
* fixed by our script; raw native stderr is discarded rather than published. */
|
|
51
|
+
export function createManualProfileProcessRunner(start = execFile) {
|
|
52
|
+
return (binary, args, options) => new Promise((resolve, reject) => {
|
|
53
|
+
let pending = '', marked = false, reason, settled = false;
|
|
54
|
+
let child;
|
|
55
|
+
const finishError = (error) => { if (settled)
|
|
56
|
+
return; settled = true; reject(error); };
|
|
57
|
+
try {
|
|
58
|
+
child = start(binary, [...args], { encoding: 'utf8', timeout: 0, maxBuffer: 1_048_576, signal: options.signal, env: { PATH: '/usr/bin:/bin', LANG: 'C', LC_ALL: 'C' } }, (error, stdout, stderr) => {
|
|
59
|
+
if (settled)
|
|
60
|
+
return;
|
|
61
|
+
settled = true;
|
|
62
|
+
if (error) {
|
|
63
|
+
reject(reason ? failure(reason) : executionError(error, 'codex_manual_inventory', 'CODEX_MANUAL_QUERY_COMMAND_FAILED'));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (reason) {
|
|
67
|
+
reject(failure(reason));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (!marked) {
|
|
71
|
+
reject(failure('CODEX_MANUAL_QUERY_PROTOCOL_INVALID'));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const rest = String(stderr).split(/\r?\n/).filter(line => line !== AUTHENTICATED && line !== '').join('\n');
|
|
75
|
+
resolve({ stdout: String(stdout), stderr: rest });
|
|
76
|
+
});
|
|
77
|
+
child.stderr?.on('data', (chunk) => {
|
|
78
|
+
if (settled)
|
|
79
|
+
return;
|
|
80
|
+
pending += chunk.toString();
|
|
81
|
+
if (pending.length > 1_048_576) {
|
|
82
|
+
finishError(failure('CODEX_MANUAL_QUERY_OUTPUT_INVALID'));
|
|
83
|
+
child?.kill();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
let end;
|
|
87
|
+
while ((end = pending.indexOf('\n')) !== -1) {
|
|
88
|
+
const line = pending.slice(0, end).replace(/\r$/, '');
|
|
89
|
+
pending = pending.slice(end + 1);
|
|
90
|
+
if (Object.hasOwn(failureMarkers, line))
|
|
91
|
+
reason = failureMarkers[line];
|
|
92
|
+
if (line === AUTHENTICATED) {
|
|
93
|
+
if (marked) {
|
|
94
|
+
finishError(failure('CODEX_MANUAL_QUERY_PROTOCOL_INVALID'));
|
|
95
|
+
child?.kill();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
marked = true;
|
|
99
|
+
try {
|
|
100
|
+
options.onAuthenticated();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
finishError(failure('CODEX_MANUAL_QUERY_PROTOCOL_INVALID'));
|
|
104
|
+
child?.kill();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
finishError(executionError(error, 'codex_manual_inventory', 'CODEX_MANUAL_QUERY_COMMAND_FAILED'));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const nativeRun = createManualProfileProcessRunner();
|
|
117
|
+
/** Foreground-only, single-use, cancellable. Human authentication wait is not
|
|
118
|
+
* query age: evidence is stamped when the bounded inventory actually finishes. */
|
|
13
119
|
export function createManualProfileQuery(input) {
|
|
14
120
|
const run = input?.run ?? nativeRun, now = input?.now ?? Date.now;
|
|
15
121
|
let used = false;
|
|
16
|
-
return Object.freeze({ async collectOnce() {
|
|
122
|
+
return Object.freeze({ async collectOnce(signal) {
|
|
17
123
|
if (used)
|
|
18
|
-
throw
|
|
124
|
+
throw failure('CODEX_MANUAL_QUERY_REUSED');
|
|
19
125
|
used = true;
|
|
126
|
+
const controller = new AbortController();
|
|
127
|
+
let timer;
|
|
128
|
+
let firstFailure, authenticatedAt;
|
|
129
|
+
const abort = (code) => { firstFailure ??= failure(code); controller.abort(); };
|
|
130
|
+
const externalAbort = () => abort('CODEX_MANUAL_QUERY_ABORTED');
|
|
131
|
+
signal?.addEventListener('abort', externalAbort, { once: true });
|
|
20
132
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
throw
|
|
133
|
+
if (signal?.aborted) {
|
|
134
|
+
externalAbort();
|
|
135
|
+
throw firstFailure;
|
|
136
|
+
}
|
|
137
|
+
const startedAt = now();
|
|
138
|
+
if (!Number.isSafeInteger(startedAt) || startedAt < 0)
|
|
139
|
+
throw failure('CODEX_MANUAL_QUERY_PROTOCOL_INVALID');
|
|
140
|
+
// Reject independently of whether an injected/native runner settles on abort.
|
|
141
|
+
const cancelled = new Promise((_, reject) => { controller.signal.addEventListener('abort', () => reject(firstFailure), { once: true }); });
|
|
142
|
+
const operation = run('/usr/bin/osascript', MANUAL_PROFILES_ARGUMENTS, { signal: controller.signal, onAuthenticated() {
|
|
143
|
+
if (controller.signal.aborted || authenticatedAt !== undefined)
|
|
144
|
+
throw failure('CODEX_MANUAL_QUERY_PROTOCOL_INVALID');
|
|
145
|
+
authenticatedAt = now();
|
|
146
|
+
if (!Number.isSafeInteger(authenticatedAt) || authenticatedAt < startedAt)
|
|
147
|
+
throw failure('CODEX_MANUAL_QUERY_PROTOCOL_INVALID');
|
|
148
|
+
timer = setTimeout(() => abort('CODEX_MANUAL_QUERY_TIMEOUT'), QUERY_TIMEOUT_MS);
|
|
149
|
+
} });
|
|
150
|
+
const result = await Promise.race([operation, cancelled]), observedAt = now();
|
|
151
|
+
if (firstFailure)
|
|
152
|
+
throw firstFailure;
|
|
153
|
+
if (authenticatedAt === undefined || !Number.isSafeInteger(observedAt) || observedAt < authenticatedAt)
|
|
154
|
+
throw failure('CODEX_MANUAL_QUERY_PROTOCOL_INVALID');
|
|
155
|
+
if (observedAt - authenticatedAt > QUERY_TIMEOUT_MS)
|
|
156
|
+
throw failure('CODEX_MANUAL_QUERY_TIMEOUT');
|
|
157
|
+
if (typeof result.stdout !== 'string' || result.stderr !== '' || !result.stdout.includes('\n'))
|
|
158
|
+
throw failure('CODEX_MANUAL_QUERY_OUTPUT_INVALID');
|
|
159
|
+
if (!result.stdout.startsWith('0\n'))
|
|
160
|
+
throw failure('CODEX_MANUAL_QUERY_NONROOT');
|
|
161
|
+
if (!emptyProfileInventoryXml(result.stdout.slice(2)))
|
|
162
|
+
throw failure('CODEX_MANUAL_QUERY_OUTPUT_INVALID');
|
|
24
163
|
return Object.freeze({ version: 1, exit: 0, euid: 0, scope: 'machine_and_current_user', complete: true, empty: true, observedAt, inventoryFingerprint: createHash('sha256').update(result.stdout.slice(2)).digest('hex') });
|
|
25
164
|
}
|
|
26
|
-
catch {
|
|
27
|
-
|
|
165
|
+
catch (error) {
|
|
166
|
+
const diagnostic = executionFailure(error, 'codex_manual_inventory', 'CODEX_MANUAL_QUERY_COMMAND_FAILED');
|
|
167
|
+
throw firstFailure ?? executionError(error, 'codex_manual_inventory', diagnostic.code);
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
if (timer)
|
|
171
|
+
clearTimeout(timer);
|
|
172
|
+
signal?.removeEventListener('abort', externalAbort);
|
|
28
173
|
}
|
|
29
174
|
} });
|
|
30
175
|
}
|