autodev-cli 1.4.192 → 1.4.193

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.
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ // ---------------------------------------------------------------------------
3
+ // grok leader KEEPALIVE client (Layer B, 1.4.193).
4
+ //
5
+ // A tiny leader-client that holds ONE session warm in the leader's memory forever
6
+ // so loop clients can attach-without-load across restarts (grok 1.0.41 evicts a
7
+ // session's in-memory context when its LAST client disconnects). Deliberately
8
+ // depends on ONLY node:fs + node:child_process — NO commander, NO provider graph —
9
+ // so the DETACHED process starts fast and can't fail to load a missing dep. Run via
10
+ // the minimal `keepaliveMain` entry, spawned detached by `ensureLeader`.
11
+ // ---------------------------------------------------------------------------
12
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || (function () {
29
+ var ownKeys = function(o) {
30
+ ownKeys = Object.getOwnPropertyNames || function (o) {
31
+ var ar = [];
32
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
+ return ar;
34
+ };
35
+ return ownKeys(o);
36
+ };
37
+ return function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
+ __setModuleDefault(result, mod);
42
+ return result;
43
+ };
44
+ })();
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.runKeepalive = runKeepalive;
47
+ const fs = __importStar(require("fs"));
48
+ const child_process = __importStar(require("child_process"));
49
+ /**
50
+ * Connect to the leader as a client, establish ONE session (session/load the seed
51
+ * id if given, else session/new), write the session id to `sidFile`, then HOLD the
52
+ * connection open indefinitely so the leader never evicts the in-memory context.
53
+ * Exits when the leader dies (its stdout closes) so it never lingers as an orphan.
54
+ * The returned promise never resolves (the caller keeps the process alive).
55
+ */
56
+ async function runKeepalive(opts) {
57
+ const { socket, cwd, sidFile, bin, seed } = opts;
58
+ const child = child_process.spawn(bin, ['agent', '--always-approve', '--leader', '--leader-socket', socket, 'stdio'], {
59
+ cwd, stdio: ['pipe', 'pipe', 'ignore'],
60
+ env: { ...process.env, TERM: process.env['TERM'] || 'xterm-256color' },
61
+ });
62
+ let buf = '';
63
+ let nextId = 1;
64
+ const pending = new Map();
65
+ child.stdout?.setEncoding('utf8');
66
+ child.stdout?.on('data', (chunk) => {
67
+ buf += chunk;
68
+ let nl;
69
+ while ((nl = buf.indexOf('\n')) >= 0) {
70
+ const line = buf.slice(0, nl).trim();
71
+ buf = buf.slice(nl + 1);
72
+ if (!line) {
73
+ continue;
74
+ }
75
+ let m;
76
+ try {
77
+ m = JSON.parse(line);
78
+ }
79
+ catch {
80
+ continue;
81
+ }
82
+ const id = m['id'];
83
+ if (typeof id === 'number' && (m['result'] !== undefined || m['error'] !== undefined) && pending.has(id)) {
84
+ const r = pending.get(id);
85
+ pending.delete(id);
86
+ r(m);
87
+ }
88
+ else if (m['method'] && id !== undefined) {
89
+ // agent→client request: auto-allow so nothing wedges.
90
+ const params = m['params'];
91
+ const optsArr = params?.options ?? [];
92
+ const allow = optsArr.find((o) => /allow|once|always/i.test(o.optionId || o.kind || '')) || optsArr[0];
93
+ try {
94
+ child.stdin?.write(JSON.stringify({ jsonrpc: '2.0', id, result: { outcome: { outcome: 'selected', optionId: allow?.optionId } } }) + '\n');
95
+ }
96
+ catch { /* ignore */ }
97
+ }
98
+ }
99
+ });
100
+ const req = (method, params) => new Promise((resolve) => {
101
+ const id = nextId++;
102
+ pending.set(id, resolve);
103
+ try {
104
+ child.stdin?.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n');
105
+ }
106
+ catch {
107
+ pending.delete(id);
108
+ resolve({ error: { message: 'write failed' } });
109
+ }
110
+ });
111
+ // When the leader (or this client) dies, exit so no orphan lingers.
112
+ child.on('exit', () => { process.exit(0); });
113
+ const bye = () => { try {
114
+ child.kill('SIGKILL');
115
+ }
116
+ catch { /* ignore */ } process.exit(0); };
117
+ process.on('SIGTERM', bye);
118
+ process.on('SIGINT', bye);
119
+ await req('initialize', { protocolVersion: 1, clientCapabilities: {} });
120
+ let sid = seed;
121
+ if (sid) {
122
+ const r = await req('session/load', { sessionId: sid, cwd, mcpServers: [] });
123
+ if (r.error) {
124
+ sid = undefined;
125
+ } // stale disk id → session/new
126
+ }
127
+ if (!sid) {
128
+ const sn = await req('session/new', { cwd, mcpServers: [] });
129
+ sid = sn.result?.sessionId;
130
+ }
131
+ if (!sid) {
132
+ process.exit(1);
133
+ }
134
+ try {
135
+ fs.writeFileSync(sidFile, sid, 'utf8');
136
+ }
137
+ catch { /* ignore */ }
138
+ // Hold the connection open forever — the whole point.
139
+ await new Promise(() => { });
140
+ }
141
+ //# sourceMappingURL=keepalive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keepalive.js","sourceRoot":"","sources":["../../../src/providers/grok/keepalive.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,mDAAmD;AACnD,EAAE;AACF,kFAAkF;AAClF,gFAAgF;AAChF,8EAA8E;AAC9E,mFAAmF;AACnF,oFAAoF;AACpF,yEAAyE;AACzE,8EAA8E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoB9E,oCAwDC;AA1ED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EAAE,EAAE,EAAE,CAAC,CAAC;IACxE,IAAI,GAAG,GAAuB,IAAI,CAAC;IACnC,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;QAC7E,IAAK,CAAyB,CAAC,KAAK,EAAE,CAAC;YAAC,GAAG,GAAG,SAAS,CAAC;QAAC,CAAC,CAAC,8BAA8B;IAC3F,CAAC;IACD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;QAC7D,GAAG,GAAI,EAAE,CAAC,MAA6C,EAAE,SAAS,CAAC;IACrE,CAAC;IACD,IAAI,CAAC,GAAG,EAAE,CAAC;QAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAAC,CAAC;IAC9B,IAAI,CAAC;QAAC,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;IACtE,sDAAsD;IACtD,MAAM,IAAI,OAAO,CAAO,GAAG,EAAE,GAAyD,CAAC,CAAC,CAAC;AAC3F,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Minimal entry for the DETACHED grok leader keepalive (Layer B). Parses argv by
4
+ // hand and calls runKeepalive — NO commander / CLI graph, so the background holder
5
+ // loads instantly and can't die on a missing dependency. Spawned by ensureLeader
6
+ // as `node <this> --socket … --cwd … --sid-file … --bin … [--seed …]`.
7
+ const keepalive_1 = require("./keepalive");
8
+ function arg(name) {
9
+ const i = process.argv.indexOf(name);
10
+ return i >= 0 && i + 1 < process.argv.length ? process.argv[i + 1] : undefined;
11
+ }
12
+ const socket = arg('--socket');
13
+ const cwd = arg('--cwd');
14
+ const sidFile = arg('--sid-file');
15
+ const bin = arg('--bin');
16
+ const seed = arg('--seed');
17
+ if (!socket || !cwd || !sidFile || !bin) {
18
+ process.stderr.write('grok keepalive: missing required arg (--socket/--cwd/--sid-file/--bin)\n');
19
+ process.exit(2);
20
+ }
21
+ void (0, keepalive_1.runKeepalive)({ socket, cwd, sidFile, bin, seed });
22
+ //# sourceMappingURL=keepaliveMain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keepaliveMain.js","sourceRoot":"","sources":["../../../src/providers/grok/keepaliveMain.ts"],"names":[],"mappings":";;AAAA,iFAAiF;AACjF,mFAAmF;AACnF,iFAAiF;AACjF,uEAAuE;AACvE,2CAA2C;AAE3C,SAAS,GAAG,CAAC,IAAY;IACvB,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACjF,CAAC;AAED,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC;AAC/B,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC;AACzB,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC;AAClC,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC;AACzB,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC3B,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;IACxC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,0EAA0E,CAAC,CAAC;IACjG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AACD,KAAK,IAAA,wBAAY,EAAC,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC"}
@@ -0,0 +1,66 @@
1
+ import type { ProviderId } from '../../providers';
2
+ export { runKeepalive } from './keepalive';
3
+ export type { RunKeepaliveOpts } from './keepalive';
4
+ /** Shape persisted to `.autodev/leader.json` (the app contract). `pid` is the
5
+ * LEADER daemon pid; `keepalivePid` the detached session-holder. Both are reaped
6
+ * by `autodev leader-stop <root>`. `sessionId` is the warm grok session. */
7
+ export interface LeaderInfo {
8
+ pid: number;
9
+ socket: string;
10
+ startedAt: string;
11
+ keepalivePid?: number;
12
+ sessionId?: string;
13
+ root?: string;
14
+ }
15
+ /** Env gate — leader mode is OPT-IN and DEFAULT OFF. Pure (env injectable). */
16
+ export declare function leaderModeEnabled(env?: NodeJS.ProcessEnv): boolean;
17
+ /** Per-agent AF_UNIX socket. Prefer `.autodev/grok-leader.sock`; fall back to a
18
+ * hashed path under tmp when the workspace path would blow the ~108-byte sun_path
19
+ * limit (a deterministic function of the root either way). */
20
+ export declare function leaderSocketPath(root: string): string;
21
+ export declare function leaderJsonPath(root: string): string;
22
+ export declare function leaderSidPath(root: string): string;
23
+ export declare function readLeaderInfo(root: string): LeaderInfo | null;
24
+ export declare function writeLeaderInfo(root: string, info: LeaderInfo): void;
25
+ export declare function removeLeaderInfo(root: string): void;
26
+ /** `process.kill(pid, 0)` liveness probe — true iff the pid exists (and is ours
27
+ * or EPERM, which still means alive). */
28
+ export declare function isPidAlive(pid: number | undefined): boolean;
29
+ /**
30
+ * PURE orphan-sweep decision. Given the persisted info and the observed liveness
31
+ * of its pieces, decide whether to reuse a still-live leader ('adopt'), reap a
32
+ * stale/dead one ('reap-stale'), or spawn fresh ('spawn'). Unit-tested.
33
+ */
34
+ export declare function decideLeaderAction(info: LeaderInfo | null, alive: {
35
+ leader: boolean;
36
+ keepalive: boolean;
37
+ socket: boolean;
38
+ }): 'spawn' | 'adopt' | 'reap-stale';
39
+ /** Is the persisted leader fully healthy right now (adoptable)? */
40
+ export declare function leaderHealthy(info: LeaderInfo | null): boolean;
41
+ /** Resolve the minimal keepalive entry (out/providers/grok/keepaliveMain.js) so a
42
+ * detached keepalive loads with NO commander/CLI graph. Overridable for odd
43
+ * packagings via AUTODEV_KEEPALIVE_ENTRY. */
44
+ export declare function keepaliveEntryPath(): string;
45
+ export interface EnsureLeaderOpts {
46
+ root: string;
47
+ bin: string;
48
+ providerId: ProviderId;
49
+ model?: string;
50
+ log: (msg: string) => void;
51
+ }
52
+ /**
53
+ * ORPHAN-SWEEP + ensure a live leader+keepalive for this root. Adopts a still-live
54
+ * one (no second leader), reaps a stale/dead one, else spawns both DETACHED so they
55
+ * survive the loop process exiting. Returns the LeaderInfo (with the warm session
56
+ * id) or null when the backend could not be established (caller falls back to the
57
+ * non-leader ACP path). Never throws.
58
+ */
59
+ export declare function ensureLeader(opts: EnsureLeaderOpts): Promise<LeaderInfo | null>;
60
+ /**
61
+ * `autodev leader-stop <root>` — kill the leader + keepalive pid-trees named in
62
+ * `.autodev/leader.json` and clean up the socket / sid / json. This is what the
63
+ * app calls on office stop / remove / quit. Best-effort; returns whether anything
64
+ * was reaped.
65
+ */
66
+ export declare function stopLeader(root: string, log: (msg: string) => void): boolean;
@@ -0,0 +1,390 @@
1
+ "use strict";
2
+ // ---------------------------------------------------------------------------
3
+ // grok LEADER daemon — "always open, reconnect-never-reload" (Layer B, 1.4.193).
4
+ //
5
+ // GOAL: the grok backend OUTLIVES loop/app restarts so a restarted loop
6
+ // RECONNECTS to the live in-memory session with NO `session/load` replay (the
7
+ // office-feed spam Layer A only quieted). GATED behind env AUTODEV_GROK_LEADER,
8
+ // DEFAULT OFF — when off, the existing non-leader ACP path (1.4.188/1.4.191) is
9
+ // used UNCHANGED.
10
+ //
11
+ // ARCHITECTURE (verified live on grok 1.0.41; see memory `grok-leader-always-open`
12
+ // + the 1.4.193 re-spike):
13
+ // • A per-agent grok LEADER daemon (`grok agent --always-approve leader
14
+ // --no-exit-on-disconnect --relay-on-demand --no-auto-update --leader-socket
15
+ // <per-agent .sock>`) is a shared backend that survives client disconnects.
16
+ // • CRITICAL grok-1.0.41 fact: the leader EVICTS a session's in-memory context
17
+ // when its LAST client disconnects (the session persists on disk, but a fresh
18
+ // client then gets "unknown session id" and must `session/load` = the replay).
19
+ // So a bare leader is NOT enough for attach-without-load across a loop restart.
20
+ // • Fix: a detached KEEPALIVE client holds the session warm in the leader's
21
+ // memory forever. Loop clients then attach as a SECOND concurrent client and
22
+ // `session/prompt {sessionId}` DIRECTLY — context intact, NO session/load —
23
+ // across any number of loop-process restarts (proven: codeword recalled,
24
+ // zero session/load).
25
+ // • The ONE `session/load` (cold recovery from disk) happens inside the
26
+ // keepalive at cold start when it is seeded with the persisted id; every
27
+ // subsequent loop restart is a warm attach. No live keepalive ⇒ degrade to
28
+ // Layer A (session/load), never data-loss.
29
+ //
30
+ // REAP BY PID (critical): `grok leader list/kill` CANNOT see a per-socket
31
+ // `--relay-on-demand` leader (verified: list→[], "No leader candidates found").
32
+ // So we track the leader + keepalive PIDs in `.autodev/leader.json` and reap the
33
+ // pid-trees ourselves. `autodev leader-stop <root>` (hidden) is what the app calls
34
+ // on office stop/remove/quit. The loop's own SIGINT/exit reaper kills ONLY the
35
+ // thin client (leader/keepalive are DETACHED, so they survive a loop restart).
36
+ // ---------------------------------------------------------------------------
37
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
38
+ if (k2 === undefined) k2 = k;
39
+ var desc = Object.getOwnPropertyDescriptor(m, k);
40
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
41
+ desc = { enumerable: true, get: function() { return m[k]; } };
42
+ }
43
+ Object.defineProperty(o, k2, desc);
44
+ }) : (function(o, m, k, k2) {
45
+ if (k2 === undefined) k2 = k;
46
+ o[k2] = m[k];
47
+ }));
48
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
49
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
50
+ }) : function(o, v) {
51
+ o["default"] = v;
52
+ });
53
+ var __importStar = (this && this.__importStar) || (function () {
54
+ var ownKeys = function(o) {
55
+ ownKeys = Object.getOwnPropertyNames || function (o) {
56
+ var ar = [];
57
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
58
+ return ar;
59
+ };
60
+ return ownKeys(o);
61
+ };
62
+ return function (mod) {
63
+ if (mod && mod.__esModule) return mod;
64
+ var result = {};
65
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
66
+ __setModuleDefault(result, mod);
67
+ return result;
68
+ };
69
+ })();
70
+ Object.defineProperty(exports, "__esModule", { value: true });
71
+ exports.runKeepalive = void 0;
72
+ exports.leaderModeEnabled = leaderModeEnabled;
73
+ exports.leaderSocketPath = leaderSocketPath;
74
+ exports.leaderJsonPath = leaderJsonPath;
75
+ exports.leaderSidPath = leaderSidPath;
76
+ exports.readLeaderInfo = readLeaderInfo;
77
+ exports.writeLeaderInfo = writeLeaderInfo;
78
+ exports.removeLeaderInfo = removeLeaderInfo;
79
+ exports.isPidAlive = isPidAlive;
80
+ exports.decideLeaderAction = decideLeaderAction;
81
+ exports.leaderHealthy = leaderHealthy;
82
+ exports.keepaliveEntryPath = keepaliveEntryPath;
83
+ exports.ensureLeader = ensureLeader;
84
+ exports.stopLeader = stopLeader;
85
+ const fs = __importStar(require("fs"));
86
+ const os = __importStar(require("os"));
87
+ const path = __importStar(require("path"));
88
+ const crypto = __importStar(require("crypto"));
89
+ const child_process = __importStar(require("child_process"));
90
+ const killProcessTree_1 = require("../../core/killProcessTree");
91
+ const sessionState_1 = require("../../sessionState");
92
+ // Re-export the keepalive runner + its options so existing importers keep working.
93
+ var keepalive_1 = require("./keepalive");
94
+ Object.defineProperty(exports, "runKeepalive", { enumerable: true, get: function () { return keepalive_1.runKeepalive; } });
95
+ /** Env gate — leader mode is OPT-IN and DEFAULT OFF. Pure (env injectable). */
96
+ function leaderModeEnabled(env = process.env) {
97
+ const raw = String(env['AUTODEV_GROK_LEADER'] ?? '').toLowerCase().trim();
98
+ return raw === '1' || raw === 'true' || raw === 'on' || raw === 'yes';
99
+ }
100
+ /** Per-agent AF_UNIX socket. Prefer `.autodev/grok-leader.sock`; fall back to a
101
+ * hashed path under tmp when the workspace path would blow the ~108-byte sun_path
102
+ * limit (a deterministic function of the root either way). */
103
+ function leaderSocketPath(root) {
104
+ const inAutodev = path.join(root, '.autodev', 'grok-leader.sock');
105
+ if (Buffer.byteLength(inAutodev) <= 100) {
106
+ return inAutodev;
107
+ }
108
+ const h = crypto.createHash('sha1').update(path.resolve(root)).digest('hex').slice(0, 16);
109
+ return path.join(os.tmpdir(), `autodev-grok-${h}.sock`);
110
+ }
111
+ function leaderJsonPath(root) { return path.join(root, '.autodev', 'leader.json'); }
112
+ function leaderSidPath(root) { return path.join(root, '.autodev', 'grok-leader.sid'); }
113
+ function readLeaderInfo(root) {
114
+ try {
115
+ const raw = fs.readFileSync(leaderJsonPath(root), 'utf8');
116
+ const info = JSON.parse(raw);
117
+ if (info && typeof info.pid === 'number' && typeof info.socket === 'string') {
118
+ return info;
119
+ }
120
+ }
121
+ catch { /* absent / malformed */ }
122
+ return null;
123
+ }
124
+ function writeLeaderInfo(root, info) {
125
+ try {
126
+ (0, sessionState_1.autodevDir)(root);
127
+ fs.writeFileSync(leaderJsonPath(root), JSON.stringify(info, null, 2), 'utf8');
128
+ }
129
+ catch { /* best effort */ }
130
+ }
131
+ function removeLeaderInfo(root) {
132
+ try {
133
+ fs.unlinkSync(leaderJsonPath(root));
134
+ }
135
+ catch { /* already gone */ }
136
+ }
137
+ /** `process.kill(pid, 0)` liveness probe — true iff the pid exists (and is ours
138
+ * or EPERM, which still means alive). */
139
+ function isPidAlive(pid) {
140
+ if (!pid || !Number.isInteger(pid) || pid <= 1) {
141
+ return false;
142
+ }
143
+ try {
144
+ process.kill(pid, 0);
145
+ return true;
146
+ }
147
+ catch (err) {
148
+ return err?.code === 'EPERM';
149
+ }
150
+ }
151
+ /**
152
+ * PURE orphan-sweep decision. Given the persisted info and the observed liveness
153
+ * of its pieces, decide whether to reuse a still-live leader ('adopt'), reap a
154
+ * stale/dead one ('reap-stale'), or spawn fresh ('spawn'). Unit-tested.
155
+ */
156
+ function decideLeaderAction(info, alive) {
157
+ if (!info) {
158
+ return 'spawn';
159
+ }
160
+ const keepaliveOk = info.keepalivePid ? alive.keepalive : true;
161
+ if (alive.leader && keepaliveOk && alive.socket) {
162
+ return 'adopt';
163
+ }
164
+ return 'reap-stale';
165
+ }
166
+ /** Is the persisted leader fully healthy right now (adoptable)? */
167
+ function leaderHealthy(info) {
168
+ if (!info) {
169
+ return false;
170
+ }
171
+ const alive = { leader: isPidAlive(info.pid), keepalive: isPidAlive(info.keepalivePid), socket: (() => { try {
172
+ return fs.existsSync(info.socket);
173
+ }
174
+ catch {
175
+ return false;
176
+ } })() };
177
+ return decideLeaderAction(info, alive) === 'adopt';
178
+ }
179
+ function readSidFile(sidFile) {
180
+ try {
181
+ const s = fs.readFileSync(sidFile, 'utf8').trim();
182
+ return s || null;
183
+ }
184
+ catch {
185
+ return null;
186
+ }
187
+ }
188
+ async function waitUntil(pred, ms, stepMs = 100) {
189
+ const end = Date.now() + ms;
190
+ while (Date.now() < end) {
191
+ if (pred()) {
192
+ return true;
193
+ }
194
+ await new Promise((r) => setTimeout(r, stepMs));
195
+ }
196
+ return pred();
197
+ }
198
+ function openLogFd(file) {
199
+ try {
200
+ return fs.openSync(file, 'a');
201
+ }
202
+ catch {
203
+ return 'ignore';
204
+ }
205
+ }
206
+ /** Resolve the minimal keepalive entry (out/providers/grok/keepaliveMain.js) so a
207
+ * detached keepalive loads with NO commander/CLI graph. Overridable for odd
208
+ * packagings via AUTODEV_KEEPALIVE_ENTRY. */
209
+ function keepaliveEntryPath() {
210
+ const override = process.env['AUTODEV_KEEPALIVE_ENTRY'];
211
+ if (override && fs.existsSync(override)) {
212
+ return override;
213
+ }
214
+ return path.join(__dirname, 'keepaliveMain.js');
215
+ }
216
+ /** Reap the leader + keepalive pid-trees named in `info` (best-effort). */
217
+ function reapLeaderProcs(info) {
218
+ if (info.keepalivePid) {
219
+ try {
220
+ (0, killProcessTree_1.killProcessTree)(info.keepalivePid);
221
+ }
222
+ catch { /* ignore */ }
223
+ }
224
+ if (info.pid) {
225
+ try {
226
+ (0, killProcessTree_1.killProcessTree)(info.pid);
227
+ }
228
+ catch { /* ignore */ }
229
+ }
230
+ }
231
+ /**
232
+ * ORPHAN-SWEEP + ensure a live leader+keepalive for this root. Adopts a still-live
233
+ * one (no second leader), reaps a stale/dead one, else spawns both DETACHED so they
234
+ * survive the loop process exiting. Returns the LeaderInfo (with the warm session
235
+ * id) or null when the backend could not be established (caller falls back to the
236
+ * non-leader ACP path). Never throws.
237
+ */
238
+ async function ensureLeader(opts) {
239
+ const { root, bin, providerId, model, log } = opts;
240
+ const existing = readLeaderInfo(root);
241
+ if (existing && leaderHealthy(existing)) {
242
+ log(`grok leader: adopting live backend (leader=${existing.pid} keepalive=${existing.keepalivePid ?? '?'} sid=${(existing.sessionId ?? '').slice(0, 8)}…)`);
243
+ return existing;
244
+ }
245
+ if (existing) {
246
+ log(`grok leader: reaping stale backend (leader=${existing.pid} keepalive=${existing.keepalivePid ?? '?'})`);
247
+ reapLeaderProcs(existing);
248
+ removeLeaderInfo(existing.root ?? root);
249
+ }
250
+ const socket = leaderSocketPath(root);
251
+ try {
252
+ fs.unlinkSync(socket);
253
+ }
254
+ catch { /* no stale socket */ }
255
+ (0, sessionState_1.autodevDir)(root);
256
+ // 1) Spawn the LEADER daemon, detached.
257
+ const leaderArgs = ['agent', '--always-approve', 'leader', '--no-exit-on-disconnect', '--relay-on-demand', '--no-auto-update', '--leader-socket', socket];
258
+ const leaderErrFd = openLogFd(path.join(root, '.autodev', 'grok-leader.err'));
259
+ let leaderChild;
260
+ try {
261
+ leaderChild = child_process.spawn(bin, leaderArgs, {
262
+ cwd: root, detached: true,
263
+ stdio: ['ignore', 'ignore', leaderErrFd],
264
+ env: { ...process.env, TERM: process.env['TERM'] || 'xterm-256color' },
265
+ });
266
+ }
267
+ catch (err) {
268
+ log(`grok leader: spawn failed (${err?.message ?? err})`);
269
+ return null;
270
+ }
271
+ leaderChild.unref();
272
+ const leaderPid = leaderChild.pid;
273
+ if (!leaderPid) {
274
+ log('grok leader: no pid after spawn');
275
+ return null;
276
+ }
277
+ const sockOk = await waitUntil(() => { try {
278
+ return fs.existsSync(socket);
279
+ }
280
+ catch {
281
+ return false;
282
+ } }, 15_000);
283
+ if (!sockOk) {
284
+ log('grok leader: socket never appeared — reaping');
285
+ try {
286
+ (0, killProcessTree_1.killProcessTree)(leaderPid);
287
+ }
288
+ catch { /* ignore */ }
289
+ return null;
290
+ }
291
+ // 2) Spawn the KEEPALIVE client, detached — it holds the session warm. Seed it
292
+ // with the persisted id so a cold start does its ONE session/load here.
293
+ const sidFile = leaderSidPath(root);
294
+ try {
295
+ fs.unlinkSync(sidFile);
296
+ }
297
+ catch { /* ignore */ }
298
+ const seed = (0, sessionState_1.getSessionId)(root, providerId) || undefined;
299
+ const kaArgs = [keepaliveEntryPath(), '--socket', socket, '--cwd', root, '--sid-file', sidFile, '--bin', bin];
300
+ if (seed) {
301
+ kaArgs.push('--seed', seed);
302
+ }
303
+ let kaChild;
304
+ try {
305
+ kaChild = child_process.spawn(process.execPath, kaArgs, {
306
+ cwd: root, detached: true, stdio: 'ignore',
307
+ // ELECTRON_RUN_AS_NODE so an Electron-bundled CLI runs the keepalive as pure
308
+ // node (no window) — the inverse of the app's ELECTRON_RUN_AS_NODE trap.
309
+ env: { ...process.env, ELECTRON_RUN_AS_NODE: '1', TERM: process.env['TERM'] || 'xterm-256color' },
310
+ });
311
+ }
312
+ catch (err) {
313
+ log(`grok leader: keepalive spawn failed (${err?.message ?? err})`);
314
+ try {
315
+ (0, killProcessTree_1.killProcessTree)(leaderPid);
316
+ }
317
+ catch { /* ignore */ }
318
+ return null;
319
+ }
320
+ kaChild.unref();
321
+ const keepalivePid = kaChild.pid;
322
+ const gotSid = await waitUntil(() => readSidFile(sidFile) !== null, 25_000);
323
+ const sessionId = readSidFile(sidFile) || undefined;
324
+ if (!keepalivePid || !gotSid || !sessionId) {
325
+ log('grok leader: keepalive failed to establish a session — reaping');
326
+ if (keepalivePid) {
327
+ try {
328
+ (0, killProcessTree_1.killProcessTree)(keepalivePid);
329
+ }
330
+ catch { /* ignore */ }
331
+ }
332
+ try {
333
+ (0, killProcessTree_1.killProcessTree)(leaderPid);
334
+ }
335
+ catch { /* ignore */ }
336
+ return null;
337
+ }
338
+ const info = { pid: leaderPid, socket, startedAt: new Date().toISOString(), keepalivePid, sessionId, root };
339
+ writeLeaderInfo(root, info);
340
+ try {
341
+ (0, sessionState_1.saveSessionId)(root, providerId, sessionId);
342
+ }
343
+ catch { /* ignore */ }
344
+ log(`grok leader: backend up (leader=${leaderPid} keepalive=${keepalivePid} sid=${sessionId.slice(0, 8)}…)`);
345
+ return info;
346
+ }
347
+ /**
348
+ * `autodev leader-stop <root>` — kill the leader + keepalive pid-trees named in
349
+ * `.autodev/leader.json` and clean up the socket / sid / json. This is what the
350
+ * app calls on office stop / remove / quit. Best-effort; returns whether anything
351
+ * was reaped.
352
+ */
353
+ function stopLeader(root, log) {
354
+ const info = readLeaderInfo(root);
355
+ let killed = false;
356
+ if (info) {
357
+ if (info.keepalivePid && isPidAlive(info.keepalivePid)) {
358
+ try {
359
+ (0, killProcessTree_1.killProcessTree)(info.keepalivePid);
360
+ killed = true;
361
+ }
362
+ catch { /* ignore */ }
363
+ }
364
+ if (info.pid && isPidAlive(info.pid)) {
365
+ try {
366
+ (0, killProcessTree_1.killProcessTree)(info.pid);
367
+ killed = true;
368
+ }
369
+ catch { /* ignore */ }
370
+ }
371
+ try {
372
+ if (info.socket) {
373
+ fs.unlinkSync(info.socket);
374
+ }
375
+ }
376
+ catch { /* ignore */ }
377
+ }
378
+ try {
379
+ fs.unlinkSync(leaderSocketPath(root));
380
+ }
381
+ catch { /* ignore */ }
382
+ try {
383
+ fs.unlinkSync(leaderSidPath(root));
384
+ }
385
+ catch { /* ignore */ }
386
+ removeLeaderInfo(root);
387
+ log(killed ? `leader-stop: reaped grok leader backend for ${root}` : `leader-stop: no live grok leader for ${root}`);
388
+ return killed;
389
+ }
390
+ //# sourceMappingURL=leader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leader.js","sourceRoot":"","sources":["../../../src/providers/grok/leader.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,iFAAiF;AACjF,EAAE;AACF,wEAAwE;AACxE,8EAA8E;AAC9E,gFAAgF;AAChF,gFAAgF;AAChF,kBAAkB;AAClB,EAAE;AACF,mFAAmF;AACnF,2BAA2B;AAC3B,0EAA0E;AAC1E,iFAAiF;AACjF,gFAAgF;AAChF,iFAAiF;AACjF,kFAAkF;AAClF,mFAAmF;AACnF,oFAAoF;AACpF,8EAA8E;AAC9E,iFAAiF;AACjF,gFAAgF;AAChF,6EAA6E;AAC7E,0BAA0B;AAC1B,0EAA0E;AAC1E,6EAA6E;AAC7E,+EAA+E;AAC/E,+CAA+C;AAC/C,EAAE;AACF,0EAA0E;AAC1E,gFAAgF;AAChF,iFAAiF;AACjF,mFAAmF;AACnF,+EAA+E;AAC/E,+EAA+E;AAC/E,8EAA8E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B9E,8CAGC;AAKD,4CAKC;AAED,wCAA2G;AAC3G,sCAA8G;AAE9G,wCAOC;AAED,0CAEC;AAED,4CAEC;AAID,gCAGC;AAOD,gDAQC;AAGD,sCAIC;AAmBD,gDAIC;AAuBD,oCAkEC;AAQD,gCAaC;AA7ND,uCAAyB;AACzB,uCAAyB;AACz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