wherever-dev 0.17.0 → 0.17.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/dist/extension-lifecycle.d.ts +80 -0
- package/dist/extension-lifecycle.d.ts.map +1 -0
- package/dist/extension-lifecycle.js +155 -0
- package/dist/extension-lifecycle.js.map +1 -0
- package/dist/session-pool.d.ts +30 -2
- package/dist/session-pool.d.ts.map +1 -1
- package/dist/session-pool.js +57 -8
- package/dist/session-pool.js.map +1 -1
- package/package.json +1 -1
- package/public/_app/immutable/chunks/{C2Qht-9M.js → BRAYQ_mD.js} +2 -2
- package/public/_app/immutable/chunks/{C2Qht-9M.js.map → BRAYQ_mD.js.map} +1 -1
- package/public/_app/immutable/chunks/{tyMlRPpy.js → BhP7_nMn.js} +2 -2
- package/public/_app/immutable/chunks/{tyMlRPpy.js.map → BhP7_nMn.js.map} +1 -1
- package/public/_app/immutable/chunks/{BRpbyuah.js → Bio1jLTG.js} +2 -2
- package/public/_app/immutable/chunks/{BRpbyuah.js.map → Bio1jLTG.js.map} +1 -1
- package/public/_app/immutable/entry/{app.C-K4PQEc.js → app.D06PTvNp.js} +3 -3
- package/public/_app/immutable/entry/{app.C-K4PQEc.js.map → app.D06PTvNp.js.map} +1 -1
- package/public/_app/immutable/entry/start.DoiCihIa.js +2 -0
- package/public/_app/immutable/entry/start.DoiCihIa.js.map +1 -0
- package/public/_app/immutable/nodes/{0.DhT5vD6E.js → 0.05Mp-ARy.js} +2 -2
- package/public/_app/immutable/nodes/{0.DhT5vD6E.js.map → 0.05Mp-ARy.js.map} +1 -1
- package/public/_app/immutable/nodes/{1.Dg1qqEIS.js → 1.C_Y-Wpdd.js} +2 -2
- package/public/_app/immutable/nodes/{1.Dg1qqEIS.js.map → 1.C_Y-Wpdd.js.map} +1 -1
- package/public/_app/immutable/nodes/{2.gGFd8Q6p.js → 2.DmncGYOi.js} +2 -2
- package/public/_app/immutable/nodes/{2.gGFd8Q6p.js.map → 2.DmncGYOi.js.map} +1 -1
- package/public/_app/version.json +1 -1
- package/public/index.html +10 -10
- package/public/service-worker.js +1 -1
- package/public/_app/immutable/entry/start.CMyrB3xe.js +0 -2
- package/public/_app/immutable/entry/start.CMyrB3xe.js.map +0 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { AgentSession } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
/**
|
|
3
|
+
* The pi EXTENSION LIFECYCLE for server-created sessions.
|
|
4
|
+
*
|
|
5
|
+
* `createAgentSession()` only LOADS extensions. It does not start them: in the pi
|
|
6
|
+
* SDK it is `AgentSession.bindExtensions(...)` that emits `session_start` and then
|
|
7
|
+
* `resources_discover` (extension-contributed skills, prompts, themes). The pi CLI
|
|
8
|
+
* modes (interactive, print, rpc) all call it; a host that skips it leaves every
|
|
9
|
+
* extension that initialises on `session_start` dead. The pi-mcp-adapter was the
|
|
10
|
+
* visible victim ("MCP not initialized" on every `mcp(...)` call).
|
|
11
|
+
*
|
|
12
|
+
* Teardown has the same trap from the other side: `AgentSession.dispose()` does
|
|
13
|
+
* NOT emit `session_shutdown`. Only `AgentSessionRuntime.dispose()` does, through
|
|
14
|
+
* the internal (unexported) `emitSessionShutdownEvent`. Wherever owns bare
|
|
15
|
+
* AgentSessions, not runtimes, so without this module extensions never cleaned up
|
|
16
|
+
* (MCP connections, OAuth callback servers, timers) for the life of the process.
|
|
17
|
+
*
|
|
18
|
+
* The contract, used by every server-session path in session-pool.ts:
|
|
19
|
+
* - bind on create: `bindServerSessionExtensions()` right after
|
|
20
|
+
* `createAgentSession()`, before the session is tracked or handed to clients;
|
|
21
|
+
* - shut down before dispose: `shutdownAndDisposeAgentSession()` is the ONLY way
|
|
22
|
+
* a server session is disposed, so no call site can skip `session_shutdown`.
|
|
23
|
+
*/
|
|
24
|
+
/** Upper bound on extension `session_shutdown` handlers before we dispose anyway. */
|
|
25
|
+
export declare const EXTENSION_SHUTDOWN_TIMEOUT_MS = 5000;
|
|
26
|
+
/**
|
|
27
|
+
* After this long without `session_start` handlers finishing, log that the bind is
|
|
28
|
+
* stuck. It does NOT cancel the bind (a half-started extension set is worse than a
|
|
29
|
+
* slow one); it only makes a hang visible in the journal, where it otherwise
|
|
30
|
+
* shows up as a session that silently never opens.
|
|
31
|
+
*/
|
|
32
|
+
export declare const EXTENSION_BIND_WARN_AFTER_MS = 15000;
|
|
33
|
+
type ExtensionBindings = Parameters<AgentSession['bindExtensions']>[0];
|
|
34
|
+
/**
|
|
35
|
+
* The bindings a server-created session hands to `bindExtensions`. Chosen against
|
|
36
|
+
* `AgentSession.bindExtensions` / `_applyExtensionBindings` in the bundled SDK:
|
|
37
|
+
*
|
|
38
|
+
* - `uiContext`: left UNSET. The runner then uses its no-op UI context, so
|
|
39
|
+
* `ctx.hasUI` is false and extensions take their non-interactive path. The web
|
|
40
|
+
* UI has no channel for extension dialogs (select / confirm / input / custom
|
|
41
|
+
* components); a context that pretended otherwise would make a dialog hang or
|
|
42
|
+
* silently resolve to a default the human never chose.
|
|
43
|
+
* - `mode: 'print'`: the SDK's own headless default, and the only non-json mode
|
|
44
|
+
* the SDK documents as compatible with `hasUI === false` ("true in TUI and RPC
|
|
45
|
+
* modes"). Passing it explicitly records the decision instead of inheriting it.
|
|
46
|
+
* `rpc` would claim a dialog-capable client we do not have.
|
|
47
|
+
* - `onError`: logs every extension error (handler throws in session_start,
|
|
48
|
+
* session_shutdown, tool hooks...) to the journal. Setting any binding also
|
|
49
|
+
* makes `AgentSession.reload()` re-emit `session_start` on reload, which it
|
|
50
|
+
* skips for a session that was never bound.
|
|
51
|
+
* - `commandContextActions`: minimal and honest. Only `waitForIdle` acts (on this
|
|
52
|
+
* very AgentSession). The session-REPLACING actions (newSession, fork,
|
|
53
|
+
* switchSession) and navigateTree answer `{ cancelled: true }`: sessions here
|
|
54
|
+
* are owned by the pool, keyed by file, and swapped only through the web
|
|
55
|
+
* protocol, so an extension must not do it behind the UI's back. The SDK's
|
|
56
|
+
* unbound defaults would instead report `{ cancelled: false }` for work that
|
|
57
|
+
* never happened.
|
|
58
|
+
* - `reload` is REFUSED too (logged, resolves without reloading). Not because the
|
|
59
|
+
* session could not survive it, but because `AgentSession.reload()` calls pi-ai's
|
|
60
|
+
* `resetApiProviders()`, which is PROCESS-WIDE: in a multi-session server, one
|
|
61
|
+
* session's reload would drop the custom API providers every OTHER live
|
|
62
|
+
* session's extensions registered. Before bindings existed the SDK's reload
|
|
63
|
+
* handler was a no-op, so refusing keeps that behaviour until reload is designed
|
|
64
|
+
* as a server-level operation.
|
|
65
|
+
* - `shutdownHandler`: left unset. `ctx.shutdown()` from an extension must not
|
|
66
|
+
* stop the whole multi-session server.
|
|
67
|
+
* - `abortHandler`: left unset, so `ctx.abort()` aborts this session's turn (the
|
|
68
|
+
* SDK default).
|
|
69
|
+
*/
|
|
70
|
+
export declare function serverExtensionBindings(agentSession: AgentSession, label: string): ExtensionBindings;
|
|
71
|
+
/** Start the extensions of a freshly created server session (emits session_start + resources_discover). */
|
|
72
|
+
export declare function bindServerSessionExtensions(agentSession: AgentSession, label: string, warnAfterMs?: number): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Emit `session_shutdown` (reason `quit`) to the session's extensions, then
|
|
75
|
+
* dispose it. The shutdown is awaited but bounded by `timeoutMs`, so a hung
|
|
76
|
+
* extension cannot block idle eviction or server shutdown. Never rejects.
|
|
77
|
+
*/
|
|
78
|
+
export declare function shutdownAndDisposeAgentSession(agentSession: AgentSession, label: string, timeoutMs?: number): Promise<void>;
|
|
79
|
+
export {};
|
|
80
|
+
//# sourceMappingURL=extension-lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-lifecycle.d.ts","sourceRoot":"","sources":["../src/extension-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,iCAAiC,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,qFAAqF;AACrF,eAAO,MAAM,6BAA6B,OAAQ,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,QAAS,CAAC;AAEnD,KAAK,iBAAiB,GAAG,UAAU,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAWvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAmBpG;AAED,2GAA2G;AAC3G,wBAAsB,2BAA2B,CAC/C,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,WAAW,SAA+B,GACzC,OAAO,CAAC,IAAI,CAAC,CAcf;AAED;;;;GAIG;AACH,wBAAsB,8BAA8B,CAClD,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,SAAgC,GACxC,OAAO,CAAC,IAAI,CAAC,CAoCf"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pi EXTENSION LIFECYCLE for server-created sessions.
|
|
3
|
+
*
|
|
4
|
+
* `createAgentSession()` only LOADS extensions. It does not start them: in the pi
|
|
5
|
+
* SDK it is `AgentSession.bindExtensions(...)` that emits `session_start` and then
|
|
6
|
+
* `resources_discover` (extension-contributed skills, prompts, themes). The pi CLI
|
|
7
|
+
* modes (interactive, print, rpc) all call it; a host that skips it leaves every
|
|
8
|
+
* extension that initialises on `session_start` dead. The pi-mcp-adapter was the
|
|
9
|
+
* visible victim ("MCP not initialized" on every `mcp(...)` call).
|
|
10
|
+
*
|
|
11
|
+
* Teardown has the same trap from the other side: `AgentSession.dispose()` does
|
|
12
|
+
* NOT emit `session_shutdown`. Only `AgentSessionRuntime.dispose()` does, through
|
|
13
|
+
* the internal (unexported) `emitSessionShutdownEvent`. Wherever owns bare
|
|
14
|
+
* AgentSessions, not runtimes, so without this module extensions never cleaned up
|
|
15
|
+
* (MCP connections, OAuth callback servers, timers) for the life of the process.
|
|
16
|
+
*
|
|
17
|
+
* The contract, used by every server-session path in session-pool.ts:
|
|
18
|
+
* - bind on create: `bindServerSessionExtensions()` right after
|
|
19
|
+
* `createAgentSession()`, before the session is tracked or handed to clients;
|
|
20
|
+
* - shut down before dispose: `shutdownAndDisposeAgentSession()` is the ONLY way
|
|
21
|
+
* a server session is disposed, so no call site can skip `session_shutdown`.
|
|
22
|
+
*/
|
|
23
|
+
/** Upper bound on extension `session_shutdown` handlers before we dispose anyway. */
|
|
24
|
+
export const EXTENSION_SHUTDOWN_TIMEOUT_MS = 5_000;
|
|
25
|
+
/**
|
|
26
|
+
* After this long without `session_start` handlers finishing, log that the bind is
|
|
27
|
+
* stuck. It does NOT cancel the bind (a half-started extension set is worse than a
|
|
28
|
+
* slow one); it only makes a hang visible in the journal, where it otherwise
|
|
29
|
+
* shows up as a session that silently never opens.
|
|
30
|
+
*/
|
|
31
|
+
export const EXTENSION_BIND_WARN_AFTER_MS = 15_000;
|
|
32
|
+
function logExtensionError(label, err) {
|
|
33
|
+
// stderr is the wherever journal under systemd. Never swallowed: an extension
|
|
34
|
+
// that fails to start is otherwise invisible from the web UI.
|
|
35
|
+
console.error(`[wherever] extension error in ${label} (${err.extensionPath}, ${err.event}): ${err.error}` +
|
|
36
|
+
(err.stack ? `\n${err.stack}` : ''));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The bindings a server-created session hands to `bindExtensions`. Chosen against
|
|
40
|
+
* `AgentSession.bindExtensions` / `_applyExtensionBindings` in the bundled SDK:
|
|
41
|
+
*
|
|
42
|
+
* - `uiContext`: left UNSET. The runner then uses its no-op UI context, so
|
|
43
|
+
* `ctx.hasUI` is false and extensions take their non-interactive path. The web
|
|
44
|
+
* UI has no channel for extension dialogs (select / confirm / input / custom
|
|
45
|
+
* components); a context that pretended otherwise would make a dialog hang or
|
|
46
|
+
* silently resolve to a default the human never chose.
|
|
47
|
+
* - `mode: 'print'`: the SDK's own headless default, and the only non-json mode
|
|
48
|
+
* the SDK documents as compatible with `hasUI === false` ("true in TUI and RPC
|
|
49
|
+
* modes"). Passing it explicitly records the decision instead of inheriting it.
|
|
50
|
+
* `rpc` would claim a dialog-capable client we do not have.
|
|
51
|
+
* - `onError`: logs every extension error (handler throws in session_start,
|
|
52
|
+
* session_shutdown, tool hooks...) to the journal. Setting any binding also
|
|
53
|
+
* makes `AgentSession.reload()` re-emit `session_start` on reload, which it
|
|
54
|
+
* skips for a session that was never bound.
|
|
55
|
+
* - `commandContextActions`: minimal and honest. Only `waitForIdle` acts (on this
|
|
56
|
+
* very AgentSession). The session-REPLACING actions (newSession, fork,
|
|
57
|
+
* switchSession) and navigateTree answer `{ cancelled: true }`: sessions here
|
|
58
|
+
* are owned by the pool, keyed by file, and swapped only through the web
|
|
59
|
+
* protocol, so an extension must not do it behind the UI's back. The SDK's
|
|
60
|
+
* unbound defaults would instead report `{ cancelled: false }` for work that
|
|
61
|
+
* never happened.
|
|
62
|
+
* - `reload` is REFUSED too (logged, resolves without reloading). Not because the
|
|
63
|
+
* session could not survive it, but because `AgentSession.reload()` calls pi-ai's
|
|
64
|
+
* `resetApiProviders()`, which is PROCESS-WIDE: in a multi-session server, one
|
|
65
|
+
* session's reload would drop the custom API providers every OTHER live
|
|
66
|
+
* session's extensions registered. Before bindings existed the SDK's reload
|
|
67
|
+
* handler was a no-op, so refusing keeps that behaviour until reload is designed
|
|
68
|
+
* as a server-level operation.
|
|
69
|
+
* - `shutdownHandler`: left unset. `ctx.shutdown()` from an extension must not
|
|
70
|
+
* stop the whole multi-session server.
|
|
71
|
+
* - `abortHandler`: left unset, so `ctx.abort()` aborts this session's turn (the
|
|
72
|
+
* SDK default).
|
|
73
|
+
*/
|
|
74
|
+
export function serverExtensionBindings(agentSession, label) {
|
|
75
|
+
const refuse = (action) => async () => {
|
|
76
|
+
console.warn(`[wherever] extension asked to ${action} in ${label}; not supported for server sessions`);
|
|
77
|
+
return { cancelled: true };
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
mode: 'print',
|
|
81
|
+
onError: (err) => logExtensionError(label, err),
|
|
82
|
+
commandContextActions: {
|
|
83
|
+
waitForIdle: () => agentSession.waitForIdle(),
|
|
84
|
+
reload: async () => {
|
|
85
|
+
await refuse('reload (process-wide provider reset)')();
|
|
86
|
+
},
|
|
87
|
+
newSession: refuse('start a new session'),
|
|
88
|
+
fork: refuse('fork the session'),
|
|
89
|
+
navigateTree: refuse('navigate the session tree'),
|
|
90
|
+
switchSession: refuse('switch session'),
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** Start the extensions of a freshly created server session (emits session_start + resources_discover). */
|
|
95
|
+
export async function bindServerSessionExtensions(agentSession, label, warnAfterMs = EXTENSION_BIND_WARN_AFTER_MS) {
|
|
96
|
+
const started = Date.now();
|
|
97
|
+
const watchdog = setTimeout(() => {
|
|
98
|
+
console.error(`[wherever] extension session_start for ${label} still running after ${warnAfterMs}ms; the session cannot open until it finishes`);
|
|
99
|
+
}, warnAfterMs);
|
|
100
|
+
try {
|
|
101
|
+
await agentSession.bindExtensions(serverExtensionBindings(agentSession, label));
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
clearTimeout(watchdog);
|
|
105
|
+
const elapsed = Date.now() - started;
|
|
106
|
+
if (elapsed >= warnAfterMs)
|
|
107
|
+
console.error(`[wherever] extension session_start for ${label} finished after ${elapsed}ms`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Emit `session_shutdown` (reason `quit`) to the session's extensions, then
|
|
112
|
+
* dispose it. The shutdown is awaited but bounded by `timeoutMs`, so a hung
|
|
113
|
+
* extension cannot block idle eviction or server shutdown. Never rejects.
|
|
114
|
+
*/
|
|
115
|
+
export async function shutdownAndDisposeAgentSession(agentSession, label, timeoutMs = EXTENSION_SHUTDOWN_TIMEOUT_MS) {
|
|
116
|
+
// Stop any in-flight turn FIRST, synchronously. dispose() would abort it, but
|
|
117
|
+
// it runs only after the (up to timeoutMs) shutdown handlers; until then a live
|
|
118
|
+
// turn would keep streaming, running tools and appending to the transcript,
|
|
119
|
+
// which recreates a just-deleted session file or races a CLI that took over.
|
|
120
|
+
// This mirrors dispose()'s own first step and cannot hang.
|
|
121
|
+
try {
|
|
122
|
+
agentSession.agent.abort();
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
console.error(`[wherever] abort failed for ${label}:`, err);
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
// Read the runner NOW: `reload()` replaces it, and the live one is the one
|
|
129
|
+
// whose extensions hold resources.
|
|
130
|
+
const runner = agentSession.extensionRunner;
|
|
131
|
+
if (runner.hasHandlers('session_shutdown')) {
|
|
132
|
+
let timer;
|
|
133
|
+
const timedOut = await Promise.race([
|
|
134
|
+
runner.emit({ type: 'session_shutdown', reason: 'quit' }).then(() => false),
|
|
135
|
+
new Promise((resolve) => {
|
|
136
|
+
timer = setTimeout(() => resolve(true), timeoutMs);
|
|
137
|
+
}),
|
|
138
|
+
]).finally(() => clearTimeout(timer));
|
|
139
|
+
if (timedOut) {
|
|
140
|
+
console.error(`[wherever] extension session_shutdown for ${label} exceeded ${timeoutMs}ms; disposing anyway`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
// emit() already routes handler throws to onError; this is the runner itself failing.
|
|
146
|
+
console.error(`[wherever] session_shutdown failed for ${label}:`, err);
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
agentSession.dispose();
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
console.error(`[wherever] dispose failed for ${label}:`, err);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=extension-lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-lifecycle.js","sourceRoot":"","sources":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3E,mCAAmC;QACnC,MAAM,MAAM,GAAG,YAAY,CAAC,eAAe,CAAC;QAC5C,IAAI,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAC3C,IAAI,KAAgD,CAAC;YACrD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;gBAClC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC;gBAC3E,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,EAAE;oBAC/B,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC;gBACrD,CAAC,CAAC;aACH,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;YACtC,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,6CAA6C,KAAK,aAAa,SAAS,sBAAsB,CAAC,CAAC;YAChH,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,sFAAsF;QACtF,OAAO,CAAC,KAAK,CAAC,0CAA0C,KAAK,GAAG,EAAE,GAAG,CAAC,CAAC;IACzE,CAAC;IACD,IAAI,CAAC;QACH,YAAY,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,iCAAiC,KAAK,GAAG,EAAE,GAAG,CAAC,CAAC;IAChE,CAAC;AACH,CAAC"}
|
package/dist/session-pool.d.ts
CHANGED
|
@@ -307,6 +307,7 @@ export type RemoteRepoProbe = {
|
|
|
307
307
|
*/
|
|
308
308
|
export declare function detectRemoteRepo(rule: RemoteRepoRule, repoName: string): RemoteRepoProbe;
|
|
309
309
|
import { type ConversationModeSignal } from './conversation-mode-hint.js';
|
|
310
|
+
import type { InlineExtension } from '@earendil-works/pi-coding-agent';
|
|
310
311
|
import type { AgentSession, AgentSessionEvent } from '@earendil-works/pi-coding-agent';
|
|
311
312
|
import type { Model, Api } from '@earendil-works/pi-ai';
|
|
312
313
|
import type { SessionInfo, HistoryMessage, FolderWithSessions, ModelInfo, ContextUsageInfo, SkillCommand } from './session-types.js';
|
|
@@ -355,7 +356,21 @@ export declare class SessionPool {
|
|
|
355
356
|
/** How long an unanswered sudo prompt survives, if its session outlives it. */
|
|
356
357
|
private static readonly SUDO_PROMPT_TTL_MS;
|
|
357
358
|
onEvent?: (sessionFile: string, event: AgentSessionEvent) => void;
|
|
358
|
-
|
|
359
|
+
/**
|
|
360
|
+
* Extra inline extensions loaded into EVERY server-created session, after the
|
|
361
|
+
* built-in ones. Not used by the server itself; it is the seam tests use to
|
|
362
|
+
* observe the extension lifecycle (session_start / session_shutdown).
|
|
363
|
+
*/
|
|
364
|
+
private extraExtensionFactories;
|
|
365
|
+
/** Bound on extension `session_shutdown` before dispose (see extension-lifecycle.ts). */
|
|
366
|
+
private extensionShutdownTimeoutMs;
|
|
367
|
+
/** When a stuck `session_start` gets logged (see extension-lifecycle.ts). */
|
|
368
|
+
private extensionBindWarnAfterMs;
|
|
369
|
+
constructor(idleTimeoutMs?: number, options?: {
|
|
370
|
+
extraExtensionFactories?: InlineExtension[];
|
|
371
|
+
extensionShutdownTimeoutMs?: number;
|
|
372
|
+
extensionBindWarnAfterMs?: number;
|
|
373
|
+
});
|
|
359
374
|
initialize(): Promise<void>;
|
|
360
375
|
/** Resolve the on-disk sessions directory (agentDir/sessions). Session files
|
|
361
376
|
* always live here as <subdir>/*.jsonl, so deletion/operations on a session
|
|
@@ -611,7 +626,14 @@ export declare class SessionPool {
|
|
|
611
626
|
setCliContextUsage(sessionFileOrId: string, usage: ContextUsageInfo | null): void;
|
|
612
627
|
scheduleIdleCheck(sessionFileOrId: string): void;
|
|
613
628
|
cancelIdleCheck(sessionFileOrId: string): void;
|
|
614
|
-
|
|
629
|
+
/**
|
|
630
|
+
* Tear a session down. The pool entry is dropped SYNCHRONOUSLY (so nothing can
|
|
631
|
+
* reach a half-dead session), then a server session's extensions get their
|
|
632
|
+
* bounded `session_shutdown` before the agent is disposed. The returned promise
|
|
633
|
+
* settles when that is done and never rejects; callers that do not need to wait
|
|
634
|
+
* (idle eviction, the delete handler) may ignore it.
|
|
635
|
+
*/
|
|
636
|
+
destroySession(sessionFileOrId: string, reason: string): Promise<void>;
|
|
615
637
|
registerCliSession(rawSessionFile: string, cwd: string, modelStr: string, cliWs: WebSocket, isStreaming?: boolean): Promise<{
|
|
616
638
|
tracked: TrackedSession;
|
|
617
639
|
error?: string;
|
|
@@ -621,6 +643,12 @@ export declare class SessionPool {
|
|
|
621
643
|
unregisterCliSession(rawSessionFile: string): Promise<void>;
|
|
622
644
|
handleCliEvent(rawSessionFile: string, event: AgentSessionEvent): void;
|
|
623
645
|
disposeAll(): Promise<void>;
|
|
646
|
+
/**
|
|
647
|
+
* Bind a freshly created server session's extensions; if that throws, shut
|
|
648
|
+
* down and dispose the session so a failed create leaks nothing, then rethrow
|
|
649
|
+
* (the callers turn it into their `{ error }` result).
|
|
650
|
+
*/
|
|
651
|
+
private bindOrDispose;
|
|
624
652
|
private setupEventListeners;
|
|
625
653
|
private parseModelStr;
|
|
626
654
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-pool.d.ts","sourceRoot":"","sources":["../src/session-pool.ts"],"names":[],"mappings":"AAIA,OAAO,EAML,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;AAEjC,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAU/C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM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from 'node:crypto';
|
|
|
676
676
|
import { createAttachFileTool } from './attach-file-tool.js';
|
|
677
677
|
import { createSayTool } from './say-tool.js';
|
|
678
678
|
import { createConversationModeSignal } from './conversation-mode-hint.js';
|
|
679
|
+
import { bindServerSessionExtensions, shutdownAndDisposeAgentSession, EXTENSION_SHUTDOWN_TIMEOUT_MS, EXTENSION_BIND_WARN_AFTER_MS, } from './extension-lifecycle.js';
|
|
679
680
|
import { matchRemoteRepoRule } from './remote-candidates.js';
|
|
680
681
|
export class SessionPool {
|
|
681
682
|
sessions = new Map();
|
|
@@ -698,7 +699,20 @@ export class SessionPool {
|
|
|
698
699
|
/** How long an unanswered sudo prompt survives, if its session outlives it. */
|
|
699
700
|
static SUDO_PROMPT_TTL_MS = 30 * 60_000;
|
|
700
701
|
onEvent;
|
|
701
|
-
|
|
702
|
+
/**
|
|
703
|
+
* Extra inline extensions loaded into EVERY server-created session, after the
|
|
704
|
+
* built-in ones. Not used by the server itself; it is the seam tests use to
|
|
705
|
+
* observe the extension lifecycle (session_start / session_shutdown).
|
|
706
|
+
*/
|
|
707
|
+
extraExtensionFactories;
|
|
708
|
+
/** Bound on extension `session_shutdown` before dispose (see extension-lifecycle.ts). */
|
|
709
|
+
extensionShutdownTimeoutMs;
|
|
710
|
+
/** When a stuck `session_start` gets logged (see extension-lifecycle.ts). */
|
|
711
|
+
extensionBindWarnAfterMs;
|
|
712
|
+
constructor(idleTimeoutMs = 300_000, options = {}) {
|
|
713
|
+
this.extraExtensionFactories = options.extraExtensionFactories ?? [];
|
|
714
|
+
this.extensionShutdownTimeoutMs = options.extensionShutdownTimeoutMs ?? EXTENSION_SHUTDOWN_TIMEOUT_MS;
|
|
715
|
+
this.extensionBindWarnAfterMs = options.extensionBindWarnAfterMs ?? EXTENSION_BIND_WARN_AFTER_MS;
|
|
702
716
|
this.agentDir = getAgentDir();
|
|
703
717
|
this.authStorage = AuthStorage.create();
|
|
704
718
|
this.modelRegistry = ModelRegistry.create(this.authStorage);
|
|
@@ -971,7 +985,7 @@ export class SessionPool {
|
|
|
971
985
|
cwd: normalizedCwd,
|
|
972
986
|
agentDir: this.agentDir,
|
|
973
987
|
settingsManager,
|
|
974
|
-
extensionFactories: [conversationSignal.inlineExtension],
|
|
988
|
+
extensionFactories: [conversationSignal.inlineExtension, ...this.extraExtensionFactories],
|
|
975
989
|
});
|
|
976
990
|
await resourceLoader.reload();
|
|
977
991
|
const { session: agentSession } = await createAgentSession({
|
|
@@ -988,6 +1002,10 @@ export class SessionPool {
|
|
|
988
1002
|
// the tool call reaching the web UI, no bridge/marker needed.
|
|
989
1003
|
customTools: [createAttachFileTool(normalizedCwd), createSayTool()],
|
|
990
1004
|
});
|
|
1005
|
+
// Start the extensions BEFORE the session is tracked or reaches a client:
|
|
1006
|
+
// createAgentSession only loads them, bindExtensions emits session_start +
|
|
1007
|
+
// resources_discover (see extension-lifecycle.ts for the chosen bindings).
|
|
1008
|
+
await this.bindOrDispose(agentSession, resolvedFile);
|
|
991
1009
|
const modelLabel = agentSession.model ? `${agentSession.model.provider}:${agentSession.model.id}` : '';
|
|
992
1010
|
const tracked = {
|
|
993
1011
|
type: 'server',
|
|
@@ -1208,7 +1226,7 @@ export class SessionPool {
|
|
|
1208
1226
|
cwd: resolvedCwd,
|
|
1209
1227
|
agentDir: this.agentDir,
|
|
1210
1228
|
settingsManager,
|
|
1211
|
-
extensionFactories: [conversationSignal.inlineExtension],
|
|
1229
|
+
extensionFactories: [conversationSignal.inlineExtension, ...this.extraExtensionFactories],
|
|
1212
1230
|
});
|
|
1213
1231
|
await resourceLoader.reload();
|
|
1214
1232
|
const { session: agentSession } = await createAgentSession({
|
|
@@ -1223,6 +1241,8 @@ export class SessionPool {
|
|
|
1223
1241
|
// createAgentSession call for the rationale).
|
|
1224
1242
|
customTools: [createAttachFileTool(resolvedCwd), createSayTool()],
|
|
1225
1243
|
});
|
|
1244
|
+
// Start the extensions before tracking (see the other createAgentSession call).
|
|
1245
|
+
await this.bindOrDispose(agentSession, agentSession.sessionFile || resolvedCwd);
|
|
1226
1246
|
const sessionFile = normalizeSessionFile(agentSession.sessionFile || '');
|
|
1227
1247
|
const modelLabel = agentSession.model ? `${agentSession.model.provider}:${agentSession.model.id}` : '';
|
|
1228
1248
|
const tracked = {
|
|
@@ -1928,14 +1948,22 @@ export class SessionPool {
|
|
|
1928
1948
|
clearTimeout(tracked.idleTimer);
|
|
1929
1949
|
tracked.idleTimer = null;
|
|
1930
1950
|
}
|
|
1951
|
+
/**
|
|
1952
|
+
* Tear a session down. The pool entry is dropped SYNCHRONOUSLY (so nothing can
|
|
1953
|
+
* reach a half-dead session), then a server session's extensions get their
|
|
1954
|
+
* bounded `session_shutdown` before the agent is disposed. The returned promise
|
|
1955
|
+
* settles when that is done and never rejects; callers that do not need to wait
|
|
1956
|
+
* (idle eviction, the delete handler) may ignore it.
|
|
1957
|
+
*/
|
|
1931
1958
|
destroySession(sessionFileOrId, reason) {
|
|
1932
1959
|
const tracked = this.getSession(sessionFileOrId);
|
|
1933
1960
|
if (!tracked)
|
|
1934
|
-
return;
|
|
1961
|
+
return Promise.resolve();
|
|
1935
1962
|
this.cancelIdleCheck(tracked.sessionFile);
|
|
1963
|
+
let teardown = Promise.resolve();
|
|
1936
1964
|
if (tracked.type === 'server') {
|
|
1937
1965
|
tracked.eventUnsubscribe();
|
|
1938
|
-
tracked.agentSession.
|
|
1966
|
+
teardown = shutdownAndDisposeAgentSession(tracked.agentSession, `${tracked.sessionFile} (${reason})`, this.extensionShutdownTimeoutMs);
|
|
1939
1967
|
}
|
|
1940
1968
|
else {
|
|
1941
1969
|
try {
|
|
@@ -1951,6 +1979,7 @@ export class SessionPool {
|
|
|
1951
1979
|
if (p.sessionFileOrId === tracked.sessionFile)
|
|
1952
1980
|
this.pendingSudo.delete(id);
|
|
1953
1981
|
}
|
|
1982
|
+
return teardown;
|
|
1954
1983
|
}
|
|
1955
1984
|
async registerCliSession(rawSessionFile, cwd, modelStr, cliWs, isStreaming = false) {
|
|
1956
1985
|
// Canonicalize the CLI-reported path so it keys the same entry the server
|
|
@@ -1972,6 +2001,7 @@ export class SessionPool {
|
|
|
1972
2001
|
// (the tool-call flavour specifically) so the caller can warn accurately.
|
|
1973
2002
|
let interruptedTurn = false;
|
|
1974
2003
|
let interruptedToolCall = false;
|
|
2004
|
+
let serverTeardown = Promise.resolve();
|
|
1975
2005
|
if (existing) {
|
|
1976
2006
|
clients = existing.clients;
|
|
1977
2007
|
this.cancelIdleCheck(sessionFile);
|
|
@@ -1980,9 +2010,13 @@ export class SessionPool {
|
|
|
1980
2010
|
interruptedTurn = interruptedToolCall || existing.agentSession.isStreaming;
|
|
1981
2011
|
try {
|
|
1982
2012
|
existing.eventUnsubscribe();
|
|
1983
|
-
existing.agentSession.dispose();
|
|
1984
2013
|
}
|
|
1985
2014
|
catch (err) { }
|
|
2015
|
+
// Start the server agent's teardown NOW (its in-flight turn is aborted
|
|
2016
|
+
// synchronously, then session_shutdown, then dispose), but only AWAIT it after the CLI entry has replaced it in the pool, so
|
|
2017
|
+
// no message can reach the dying agent while its extensions shut down.
|
|
2018
|
+
// The CLI's pi process binds its own extensions; nothing to do for it.
|
|
2019
|
+
serverTeardown = shutdownAndDisposeAgentSession(existing.agentSession, `${sessionFile} (cli takeover)`, this.extensionShutdownTimeoutMs);
|
|
1986
2020
|
}
|
|
1987
2021
|
}
|
|
1988
2022
|
let sessionId = existing?.sessionId;
|
|
@@ -2038,6 +2072,7 @@ export class SessionPool {
|
|
|
2038
2072
|
this.cancelIdleCheck(sessionFile);
|
|
2039
2073
|
}
|
|
2040
2074
|
this.sessions.set(sessionFile, tracked);
|
|
2075
|
+
await serverTeardown;
|
|
2041
2076
|
return { tracked, interruptedTurn, interruptedToolCall };
|
|
2042
2077
|
}
|
|
2043
2078
|
async unregisterCliSession(rawSessionFile) {
|
|
@@ -2098,8 +2133,22 @@ export class SessionPool {
|
|
|
2098
2133
|
}
|
|
2099
2134
|
async disposeAll() {
|
|
2100
2135
|
const sessionIds = Array.from(this.sessions.keys());
|
|
2101
|
-
|
|
2102
|
-
|
|
2136
|
+
// In parallel: each teardown is bounded on its own, so shutdown takes at most
|
|
2137
|
+
// one extension-shutdown timeout, not one per session.
|
|
2138
|
+
await Promise.all(sessionIds.map((id) => this.destroySession(id, 'server shutdown')));
|
|
2139
|
+
}
|
|
2140
|
+
/**
|
|
2141
|
+
* Bind a freshly created server session's extensions; if that throws, shut
|
|
2142
|
+
* down and dispose the session so a failed create leaks nothing, then rethrow
|
|
2143
|
+
* (the callers turn it into their `{ error }` result).
|
|
2144
|
+
*/
|
|
2145
|
+
async bindOrDispose(agentSession, label) {
|
|
2146
|
+
try {
|
|
2147
|
+
await bindServerSessionExtensions(agentSession, label, this.extensionBindWarnAfterMs);
|
|
2148
|
+
}
|
|
2149
|
+
catch (err) {
|
|
2150
|
+
await shutdownAndDisposeAgentSession(agentSession, `${label} (bind failed)`, this.extensionShutdownTimeoutMs);
|
|
2151
|
+
throw err;
|
|
2103
2152
|
}
|
|
2104
2153
|
}
|
|
2105
2154
|
setupEventListeners(sessionFile, agentSession) {
|