@code-yeongyu/senpi-codemode 2026.11.30 → 2026.12.1-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +81 -0
- package/README.md +8 -0
- package/package.json +5 -5
- package/src/bridge/reserved.ts +2 -0
- package/src/bridges/reserved-dispatch.ts +24 -1
- package/src/config/feature-settings.ts +10 -2
- package/src/extension/eval-cells-rpc.ts +17 -0
- package/src/extension/eval-notifier.ts +6 -2
- package/src/extension/runtime-factory.ts +3 -3
- package/src/index.ts +29 -1
- package/src/kernels/js/worker-core.js +2 -0
- package/src/kernels/js/worker-secret-fill.js +16 -0
- package/src/kernels/py/prelude.py +17 -1
- package/src/kernels/session-env.ts +3 -2
- package/src/tool/cell-reserved-dispatch.ts +3 -0
- package/src/tool/detached-cell-contract.ts +2 -0
- package/src/tool/detached-cell-manager.ts +31 -9
- package/src/tool/detached-notification-queue.ts +6 -1
- package/src/tool/managed-cell.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,86 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2026.12.1-2] - 2026-12-01
|
|
4
|
+
|
|
5
|
+
### Breaking Changes
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `eval_cells.stop_all` extension RPC: stops every detached cell and delivers each notice at the next turn instead of starting one ([#7867](https://github.com/code-yeongyu/senpi/pull/7867))
|
|
10
|
+
- The JavaScript kernel installs the `omowright/secret-resolver/v1` hook, backed by the reserved `__secret_fill__` bridge call, so omowright's `fillSecret` resolves references through the session's registered resolvers ([#7950](https://github.com/code-yeongyu/senpi/pull/7950))
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- `/stop all` and `stop_session` stop every detached eval cell (and the `agent()` fan-outs and workflow runs inside it) without waking the stopped session ([#7084](https://github.com/code-yeongyu/senpi/pull/7084))
|
|
17
|
+
|
|
18
|
+
### Removed
|
|
19
|
+
|
|
20
|
+
## [2026.12.1] - 2026-12-01
|
|
21
|
+
|
|
22
|
+
### Breaking Changes
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- Eval kernels (js, py, rb, jl) and their children never inherit the names listed in `<BRAND>_ENGINE_ONLY_ENV`, and while such a list is set the JS kernel always runs in its own process, whatever `isolation.js` or `SENPI_CODEMODE_JS_ISOLATION` says ([#7901](https://github.com/code-yeongyu/senpi/pull/7901))
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
### Removed
|
|
33
|
+
|
|
34
|
+
## [2026.11.30-5] - 2026-11-30
|
|
35
|
+
|
|
36
|
+
### Breaking Changes
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
|
|
44
|
+
### Removed
|
|
45
|
+
|
|
46
|
+
## [2026.11.30-4] - 2026-11-30
|
|
47
|
+
|
|
48
|
+
### Breaking Changes
|
|
49
|
+
|
|
50
|
+
### Added
|
|
51
|
+
|
|
52
|
+
### Changed
|
|
53
|
+
|
|
54
|
+
### Fixed
|
|
55
|
+
|
|
56
|
+
- An idle Python eval kernel no longer keeps exited children of dropped `Popen` handles as zombies ([#7347](https://github.com/code-yeongyu/senpi/pull/7347))
|
|
57
|
+
|
|
58
|
+
### Removed
|
|
59
|
+
|
|
60
|
+
## [2026.11.30-3] - 2026-11-30
|
|
61
|
+
|
|
62
|
+
### Breaking Changes
|
|
63
|
+
|
|
64
|
+
### Added
|
|
65
|
+
|
|
66
|
+
### Changed
|
|
67
|
+
|
|
68
|
+
### Fixed
|
|
69
|
+
|
|
70
|
+
### Removed
|
|
71
|
+
|
|
72
|
+
## [2026.11.30-2] - 2026-11-30
|
|
73
|
+
|
|
74
|
+
### Breaking Changes
|
|
75
|
+
|
|
76
|
+
### Added
|
|
77
|
+
|
|
78
|
+
### Changed
|
|
79
|
+
|
|
80
|
+
### Fixed
|
|
81
|
+
|
|
82
|
+
### Removed
|
|
83
|
+
|
|
3
84
|
## [2026.11.30] - 2026-11-30
|
|
4
85
|
|
|
5
86
|
### Breaking Changes
|
package/README.md
CHANGED
|
@@ -720,6 +720,14 @@ Session generations fence retired kernels and callbacks; each cell settles once
|
|
|
720
720
|
across completion, errors, cancellation, timeout, bridge failure, or a kernel
|
|
721
721
|
crash.
|
|
722
722
|
|
|
723
|
+
The JavaScript kernel installs a secret resolver hook on its realm under
|
|
724
|
+
`Symbol.for("omowright/secret-resolver/v1")`: `({ ref, origin }) => Promise<{ ok: true, value } | { ok: false, code }>`.
|
|
725
|
+
omowright's `page.fillSecret(selector, { ref })` calls it to type a secret into a sign-in field; the host resolves
|
|
726
|
+
the reference through `pi.registerSecretResolver` and scrubs the value from every later output of the session
|
|
727
|
+
(`[secret]`), so the model never reads it back. Code in the session's own JS kernel can call the hook with any
|
|
728
|
+
`origin`: the guarantee covers tool results, transcripts, stores and displays, not same-machine code reaching the
|
|
729
|
+
value. Values under 4 characters and image pixels are not scrubbed. Other kernels have no hook.
|
|
730
|
+
|
|
723
731
|
GPT models use the same JavaScript `eval` worker trust boundary as other JavaScript cells;
|
|
724
732
|
there is no separate execution runtime. `eval` is excluded from the nested tool
|
|
725
733
|
namespace to prevent recursive execution.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-yeongyu/senpi-codemode",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.12.1-2",
|
|
4
4
|
"description": "Source-only senpi extension package for codemode evaluation tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/parser": "8.0.4",
|
|
36
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.
|
|
37
|
-
"@earendil-works/pi-realm-registry": "npm:@code-yeongyu/senpi-realm-registry@2026.
|
|
36
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.12.1-2",
|
|
37
|
+
"@earendil-works/pi-realm-registry": "npm:@code-yeongyu/senpi-realm-registry@2026.12.1-2",
|
|
38
38
|
"quickjs-wasi": "3.6.2",
|
|
39
39
|
"typebox": "1.3.34"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@code-yeongyu/senpi": "2026.
|
|
42
|
+
"@code-yeongyu/senpi": "2026.12.1-2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@code-yeongyu/senpi": "2026.
|
|
45
|
+
"@code-yeongyu/senpi": "2026.12.1-2"
|
|
46
46
|
},
|
|
47
47
|
"keywords": [
|
|
48
48
|
"senpi",
|
package/src/bridge/reserved.ts
CHANGED
|
@@ -17,6 +17,8 @@ export const RESERVED_HANDLE_SEND_TOOL = "__handle_send__" as const;
|
|
|
17
17
|
export const RESERVED_HANDLE_CANCEL_TOOL = "__handle_cancel__" as const;
|
|
18
18
|
/** In-cell `packages.install(manager, requirements, {timeout?})`: the `%pip` / `%bun` / `%npm` installer as a call. */
|
|
19
19
|
export const RESERVED_PACKAGES_INSTALL_TOOL = "__packages_install__" as const;
|
|
20
|
+
/** The JS kernel's fill-by-reference hook (senpi#7945): resolves a secret reference for the browser library, never for the model. */
|
|
21
|
+
export const RESERVED_SECRET_FILL_TOOL = "__secret_fill__" as const;
|
|
20
22
|
/** Canonical oh-my-pi eval-timeout pause operation. */
|
|
21
23
|
export const TIMEOUT_PAUSE_OP = "timeout-pause" as const;
|
|
22
24
|
/** Canonical oh-my-pi eval-timeout resume operation. */
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { AgentToolResult, EvalHandleHost } from "@code-yeongyu/senpi";
|
|
1
|
+
import type { AgentToolResult, EvalHandleHost, SecretFillRequest, SecretFillResolution } from "@code-yeongyu/senpi";
|
|
2
2
|
import {
|
|
3
3
|
RESERVED_AGENT_TOOL,
|
|
4
4
|
RESERVED_OUTPUT_TOOL,
|
|
5
5
|
RESERVED_PACKAGES_INSTALL_TOOL,
|
|
6
6
|
RESERVED_SCHEMA_TOOL,
|
|
7
|
+
RESERVED_SECRET_FILL_TOOL,
|
|
7
8
|
} from "../bridge/reserved.ts";
|
|
8
9
|
import { type PackagesInstallEnvironments, runPackagesInstall } from "../environments/packages-install.ts";
|
|
9
10
|
import type { HandleRegistry } from "../handles/handle-registry.ts";
|
|
@@ -29,6 +30,8 @@ export interface ReservedDispatchContext {
|
|
|
29
30
|
readonly evalHandleHost?: EvalHandleHost;
|
|
30
31
|
/** The calling cell's session environments; `packages.install()` fails with environment_installer_unavailable without one. */
|
|
31
32
|
readonly environments?: PackagesInstallEnvironments;
|
|
33
|
+
/** The session's `ctx.resolveSecretForFill`; only the JS kernel's own route carries it, others answer `unavailable`. */
|
|
34
|
+
readonly resolveSecretForFill?: (request: SecretFillRequest, signal?: AbortSignal) => Promise<SecretFillResolution>;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
class SchemaUnavailableError extends Error {
|
|
@@ -45,6 +48,7 @@ export function isReservedToolName(toolName: string): boolean {
|
|
|
45
48
|
toolName === RESERVED_OUTPUT_TOOL ||
|
|
46
49
|
toolName === RESERVED_SCHEMA_TOOL ||
|
|
47
50
|
toolName === RESERVED_PACKAGES_INSTALL_TOOL ||
|
|
51
|
+
toolName === RESERVED_SECRET_FILL_TOOL ||
|
|
48
52
|
isHandleToolName(toolName)
|
|
49
53
|
);
|
|
50
54
|
}
|
|
@@ -78,6 +82,9 @@ export async function runReservedTool(toolName: string, context: ReservedDispatc
|
|
|
78
82
|
if (toolName === RESERVED_PACKAGES_INSTALL_TOOL) {
|
|
79
83
|
return await runPackagesInstall(context.args, context.environments ?? {}, context.signal);
|
|
80
84
|
}
|
|
85
|
+
if (toolName === RESERVED_SECRET_FILL_TOOL) {
|
|
86
|
+
return await runSecretFill(context.args, context.resolveSecretForFill, context.signal);
|
|
87
|
+
}
|
|
81
88
|
if (toolName === RESERVED_SCHEMA_TOOL) {
|
|
82
89
|
const listTools = context.listTools;
|
|
83
90
|
if (listTools === undefined) throw new SchemaUnavailableError();
|
|
@@ -85,3 +92,19 @@ export async function runReservedTool(toolName: string, context: ReservedDispatc
|
|
|
85
92
|
}
|
|
86
93
|
throw new Error(`runReservedTool received a non-reserved tool name: ${toolName}`);
|
|
87
94
|
}
|
|
95
|
+
|
|
96
|
+
function stringField(args: unknown, key: string): string {
|
|
97
|
+
const value: unknown = typeof args === "object" && args !== null ? Reflect.get(args, key) : undefined;
|
|
98
|
+
if (typeof value !== "string") throw new TypeError(`${RESERVED_SECRET_FILL_TOOL} needs a string ${key}`);
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function runSecretFill(
|
|
103
|
+
args: unknown,
|
|
104
|
+
resolve: ReservedDispatchContext["resolveSecretForFill"],
|
|
105
|
+
signal: AbortSignal | undefined,
|
|
106
|
+
): Promise<SecretFillResolution> {
|
|
107
|
+
const request = { ref: stringField(args, "ref"), origin: stringField(args, "origin") };
|
|
108
|
+
if (resolve === undefined) return { ok: false, code: "unavailable" };
|
|
109
|
+
return await resolve(request, signal);
|
|
110
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Static } from "typebox";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
+
import { engineOnlyEnvActive } from "@code-yeongyu/senpi";
|
|
3
4
|
import { runtimeNameOf } from "../kernels/js/runtime-name.ts";
|
|
4
5
|
|
|
5
6
|
type Environment = Readonly<Record<string, string | undefined>>;
|
|
@@ -63,13 +64,15 @@ export interface JsIsolationHost {
|
|
|
63
64
|
/** "bun" or "node" when the host's executable is that runtime; undefined for a compiled binary. */
|
|
64
65
|
readonly executable: "bun" | "node" | undefined;
|
|
65
66
|
readonly platform: NodeJS.Platform;
|
|
67
|
+
/** The engine withholds launch-listed names (`<BRAND>_ENGINE_ONLY_ENV`) from the children it starts. */
|
|
68
|
+
readonly engineOnlyEnv?: boolean;
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
export function currentJsIsolationHost(
|
|
69
72
|
execPath: string = process.execPath,
|
|
70
73
|
platform: NodeJS.Platform = process.platform,
|
|
71
74
|
): JsIsolationHost {
|
|
72
|
-
return { executable: runtimeNameOf(execPath), platform };
|
|
75
|
+
return { executable: runtimeNameOf(execPath), platform, engineOnlyEnv: engineOnlyEnvActive() };
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
/**
|
|
@@ -109,12 +112,17 @@ export function pickFeatureSettings(input: CodemodeFeatureSettings): CodemodeFea
|
|
|
109
112
|
};
|
|
110
113
|
}
|
|
111
114
|
|
|
112
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* The environment wins over the file, the file over the host default; an unknown value is ignored. An engine that
|
|
117
|
+
* withholds engine-only names always runs the kernel in its own process: a worker or inline kernel shares the engine's
|
|
118
|
+
* process, whose launch environment (`/proc/self/environ`) still holds those names whatever its `process.env` view says.
|
|
119
|
+
*/
|
|
113
120
|
export function resolveJsIsolation(
|
|
114
121
|
settings: CodemodeFeatureSettings,
|
|
115
122
|
env: Environment = process.env,
|
|
116
123
|
host: JsIsolationHost = currentJsIsolationHost(),
|
|
117
124
|
): JsIsolation {
|
|
125
|
+
if (host.engineOnlyEnv === true) return "process";
|
|
118
126
|
const fromEnv = env[JS_ISOLATION_ENVIRONMENT_FLAG];
|
|
119
127
|
if (fromEnv === "worker" || fromEnv === "process") return fromEnv;
|
|
120
128
|
return settings.isolation?.js ?? defaultJsIsolation(host);
|
|
@@ -22,6 +22,23 @@ export function registerEvalCellsRpc(
|
|
|
22
22
|
const cells = getCells();
|
|
23
23
|
return cells === undefined ? [] : listEvalCells(cells);
|
|
24
24
|
});
|
|
25
|
+
// The engine's `interrupt { background: "stop" }` (senpi#7862): every detached cell, its notice held for the next turn.
|
|
26
|
+
rpc?.handle?.("eval_cells.stop_all", async () => {
|
|
27
|
+
const outcomes = (await getCells()?.stopAllDetached("Stopped by a background stop")) ?? [];
|
|
28
|
+
const named = (cellId: string, summary: string | undefined) => ({
|
|
29
|
+
cellId,
|
|
30
|
+
...(summary === undefined ? {} : { summary }),
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
stopped: outcomes.filter((outcome) => !("error" in outcome)).map((o) => named(o.cellId, o.summary)),
|
|
34
|
+
failed: outcomes
|
|
35
|
+
.filter((outcome) => "error" in outcome)
|
|
36
|
+
.map((o) => ({
|
|
37
|
+
...named(o.cellId, o.summary),
|
|
38
|
+
reason: o.error instanceof Error ? o.error.message : String(o.error),
|
|
39
|
+
})),
|
|
40
|
+
};
|
|
41
|
+
});
|
|
25
42
|
for (const action of ["peek", "stop"] as const) {
|
|
26
43
|
rpc?.handle?.(`eval_cells.${action}`, async (data) => {
|
|
27
44
|
if (
|
|
@@ -17,7 +17,7 @@ export interface EvalNotifierDeps {
|
|
|
17
17
|
/** Deliver a model-visible notification without rendering synthetic user input. */
|
|
18
18
|
readonly sendMessage: (
|
|
19
19
|
message: { customType: string; content: EvalNotificationContent; display: boolean },
|
|
20
|
-
options: { triggerTurn: boolean; deliverAs: "steer" | "followUp" },
|
|
20
|
+
options: { triggerTurn: boolean; deliverAs: "steer" | "followUp" | "nextTurn" },
|
|
21
21
|
) => void;
|
|
22
22
|
readonly getContext: () => ExtensionContext | undefined;
|
|
23
23
|
readonly getMode: () => EvalNotifyMode;
|
|
@@ -49,13 +49,17 @@ export class EvalNotifier implements EvalDetachedCellNotifier {
|
|
|
49
49
|
const pending = cells.filter((cell) => !this.#notified.has(cell.cellId));
|
|
50
50
|
if (pending.length === 0) return;
|
|
51
51
|
for (const cell of pending) this.#notified.add(cell.cellId);
|
|
52
|
+
// Cells a client's background stop ended wait for the next turn; one still owed a wake wakes the batch.
|
|
53
|
+
const quiet = pending.every((cell) => cell.nextTurn === true);
|
|
52
54
|
this.#deps.sendMessage(
|
|
53
55
|
{
|
|
54
56
|
customType: EVAL_NOTIFICATION_CUSTOM_TYPE,
|
|
55
57
|
content: notificationContent(pending),
|
|
56
58
|
display: false,
|
|
57
59
|
},
|
|
58
|
-
|
|
60
|
+
quiet
|
|
61
|
+
? { triggerTurn: false, deliverAs: "nextTurn" }
|
|
62
|
+
: { triggerTurn: true, deliverAs: mode === "wake" ? "steer" : "followUp" },
|
|
59
63
|
);
|
|
60
64
|
}
|
|
61
65
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
activeKillGuardEnvironment,
|
|
3
|
-
|
|
3
|
+
agentChildEnvironmentOf,
|
|
4
4
|
type ExtensionContext,
|
|
5
5
|
readKillGuardSetting,
|
|
6
6
|
withBundledBunCommands,
|
|
@@ -100,8 +100,8 @@ export async function createRuntime(
|
|
|
100
100
|
const jsProcessIsolation = resolveJsIsolation(settings) === "process";
|
|
101
101
|
const artifacts = resolveSessionArtifactsDir(ctx.sessionManager.getSessionFile());
|
|
102
102
|
const activeTools = reachableToolNames(pi);
|
|
103
|
-
// Kernels and their children never see the RPC host's supervisor hand-off (senpi#5635).
|
|
104
|
-
const inheritedEnv = () =>
|
|
103
|
+
// Kernels and their children never see the RPC host's supervisor hand-off (senpi#5635) or an engine-only name.
|
|
104
|
+
const inheritedEnv = () => agentChildEnvironmentOf(process.env);
|
|
105
105
|
const writtenFiles = new WrittenFiles({
|
|
106
106
|
cwd: ctx.cwd,
|
|
107
107
|
artifactsDir: artifacts.dir,
|
package/src/index.ts
CHANGED
|
@@ -49,7 +49,13 @@ const SESSION_LIFECYCLE_EVENTS = ["session_start", "session_shutdown"] as const;
|
|
|
49
49
|
|
|
50
50
|
type SessionLifecycleEvent = (typeof SESSION_LIFECYCLE_EVENTS)[number];
|
|
51
51
|
|
|
52
|
-
type CodemodeEvent =
|
|
52
|
+
type CodemodeEvent =
|
|
53
|
+
| SessionLifecycleEvent
|
|
54
|
+
| "session_stop"
|
|
55
|
+
| "model_select"
|
|
56
|
+
| "turn_start"
|
|
57
|
+
| "tool_call_ready"
|
|
58
|
+
| "tool_execution_end";
|
|
53
59
|
|
|
54
60
|
export interface CodemodeExtensionAPI {
|
|
55
61
|
registerTool(tool: ReturnType<typeof createEvalTool>): void;
|
|
@@ -313,6 +319,28 @@ export default function senpiCodemode(pi: CodemodeExtensionAPI, options: SenpiCo
|
|
|
313
319
|
recovery.sessionEnded();
|
|
314
320
|
await dropRuntime();
|
|
315
321
|
});
|
|
322
|
+
// A full stop (oh-my-openagent#14390) ends every detached cell, so no background cell keeps spawning children or
|
|
323
|
+
// wakes the stopped session with its completion notice. The kernels stay: they hold state, not running work.
|
|
324
|
+
pi.on("session_stop", async () => {
|
|
325
|
+
const outcomes =
|
|
326
|
+
(await activeCells?.stopAllDetached("Session stopped; detached eval cell cancelled", { notice: "none" })) ??
|
|
327
|
+
[];
|
|
328
|
+
if (outcomes.length === 0) return undefined;
|
|
329
|
+
const item = ({ cellId, summary }: { cellId: string; summary?: string }) => ({
|
|
330
|
+
kind: "eval_cell",
|
|
331
|
+
id: cellId,
|
|
332
|
+
label: summary ?? cellId,
|
|
333
|
+
});
|
|
334
|
+
return {
|
|
335
|
+
stopped: outcomes.filter((outcome) => outcome.error === undefined).map(item),
|
|
336
|
+
failed: outcomes
|
|
337
|
+
.filter((outcome) => outcome.error !== undefined)
|
|
338
|
+
.map((outcome) => ({
|
|
339
|
+
...item(outcome),
|
|
340
|
+
reason: outcome.error instanceof Error ? outcome.error.message : String(outcome.error),
|
|
341
|
+
})),
|
|
342
|
+
};
|
|
343
|
+
});
|
|
316
344
|
pi.on("model_select", async (event, ctx) => {
|
|
317
345
|
activeContext = ctx;
|
|
318
346
|
const runtime = activeRuntime;
|
|
@@ -12,6 +12,7 @@ import { createRetireOffer } from "./retire-offer.js";
|
|
|
12
12
|
import { createWorkerMemory } from "./worker-memory.js";
|
|
13
13
|
import { JsWorkerRuntime } from "./worker-runtime.js";
|
|
14
14
|
import { installKernelWebView } from "./worker-webview.js";
|
|
15
|
+
import { installSecretResolverHook } from "./worker-secret-fill.js";
|
|
15
16
|
|
|
16
17
|
// Mirrors INTERRUPT_ACK_OP, CHILD_LIFECYCLE_OP, and MEMORY_COLLECTED_OP in src/bridge/reserved.ts (this worker file cannot import TypeScript).
|
|
17
18
|
const INTERRUPT_ACK_OP = "interrupt-ack";
|
|
@@ -198,6 +199,7 @@ export function createWorkerCore(transport, options) {
|
|
|
198
199
|
applySessionEnvironment(message.sessionEnv, message.removedEnv, message.inheritedSet);
|
|
199
200
|
installSessionCwd(options.cwd, options.cwdInstallOptions);
|
|
200
201
|
installKernelWebView(requestWebViewPort);
|
|
202
|
+
installSecretResolverHook(callTool);
|
|
201
203
|
installPackageResolver();
|
|
202
204
|
runtime = new JsWorkerRuntime({
|
|
203
205
|
cwd: options.cwd,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The JS kernel's end of fill by secret reference (senpi#7945). A browser library in the cell (omowright's
|
|
2
|
+
// fillSecret) finds the session's resolver on this realm under the symbol below and asks it for a reference with
|
|
3
|
+
// the origin the browser reports; the host resolves it, adds the value to the session scrub and answers. The value
|
|
4
|
+
// reaches only that library: every output of the session is scrubbed of it.
|
|
5
|
+
const SECRET_RESOLVER_HOOK = Symbol.for("omowright/secret-resolver/v1");
|
|
6
|
+
// Mirrors RESERVED_SECRET_FILL_TOOL in src/bridge/reserved.ts (this worker file cannot import TypeScript).
|
|
7
|
+
const RESERVED_SECRET_FILL_TOOL = "__secret_fill__";
|
|
8
|
+
|
|
9
|
+
export function installSecretResolverHook(callTool) {
|
|
10
|
+
Object.defineProperty(globalThis, SECRET_RESOLVER_HOOK, {
|
|
11
|
+
value: ({ ref, origin }) => callTool(RESERVED_SECRET_FILL_TOOL, { ref, origin }),
|
|
12
|
+
writable: false,
|
|
13
|
+
enumerable: false,
|
|
14
|
+
configurable: true,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -2480,6 +2480,17 @@ def _read_control(commands: queue.SimpleQueue[tuple[str, Any]]) -> None:
|
|
|
2480
2480
|
commands.put(("eof", None))
|
|
2481
2481
|
|
|
2482
2482
|
|
|
2483
|
+
# CPython collects a child whose Popen handle was dropped only when a later Popen starts, so a kernel that goes idle
|
|
2484
|
+
# keeps it as a zombie that pid-liveness checks still read as alive (senpi#7246). subprocess._cleanup waits only on
|
|
2485
|
+
# those dropped handles: a handle a cell still holds, and a child from os.fork, os.spawn* or pty.fork, keeps its exit
|
|
2486
|
+
# status for its owner. The main thread runs it between messages, never while a cell is executing.
|
|
2487
|
+
_DISCARDED_CHILD_REAP_SECONDS = 1.0
|
|
2488
|
+
|
|
2489
|
+
|
|
2490
|
+
def _reap_discarded_children() -> None:
|
|
2491
|
+
subprocess._cleanup()
|
|
2492
|
+
|
|
2493
|
+
|
|
2483
2494
|
def main() -> None:
|
|
2484
2495
|
emit_status("kernel-startup", force=True, stage="host-init")
|
|
2485
2496
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
|
@@ -2489,7 +2500,11 @@ def main() -> None:
|
|
|
2489
2500
|
threading.Thread(target=_read_control, args=(commands,), name="senpi-control-reader", daemon=True).start()
|
|
2490
2501
|
host_closed = False
|
|
2491
2502
|
while True:
|
|
2492
|
-
|
|
2503
|
+
try:
|
|
2504
|
+
kind, payload = commands.get(timeout=_DISCARDED_CHILD_REAP_SECONDS)
|
|
2505
|
+
except queue.Empty:
|
|
2506
|
+
_reap_discarded_children()
|
|
2507
|
+
continue
|
|
2493
2508
|
if kind == "eof":
|
|
2494
2509
|
break
|
|
2495
2510
|
if kind == "malformed":
|
|
@@ -2501,6 +2516,7 @@ def main() -> None:
|
|
|
2501
2516
|
break
|
|
2502
2517
|
except BaseException as exc: # noqa: BROAD_EXCEPT_OK — process boundary serializes malformed input and interrupts.
|
|
2503
2518
|
emit({"type": "init-failed", "error": bridge_error(exc)})
|
|
2519
|
+
_reap_discarded_children()
|
|
2504
2520
|
# Reaching here without a close frame means the host's pipe hit EOF: it is gone,
|
|
2505
2521
|
# so retire any subprocess the last cell left running before the interpreter exits.
|
|
2506
2522
|
if not host_closed:
|
|
@@ -23,7 +23,7 @@ export const SESSION_ENVIRONMENT_KEYS = [
|
|
|
23
23
|
/**
|
|
24
24
|
* The environment a kernel and its children inherit from the host: `process.env` without the RPC host's
|
|
25
25
|
* supervisor hand-off, plus the origin attribution (senpi#5635). Computed once by the extension through
|
|
26
|
-
* `
|
|
26
|
+
* `agentChildEnvironmentOf` at each spawn, so a restarted kernel sees the host env as it is then; kernels
|
|
27
27
|
* default to `process.env` when none is given.
|
|
28
28
|
*/
|
|
29
29
|
export type InheritedEnvironment = () => Readonly<Record<string, string | undefined>>;
|
|
@@ -36,7 +36,8 @@ export function inheritedEnvironmentDelta(
|
|
|
36
36
|
base: Readonly<Record<string, string | undefined>>,
|
|
37
37
|
inherited: Readonly<Record<string, string | undefined>>,
|
|
38
38
|
): { removedEnv: string[]; inheritedSet: Record<string, string> } {
|
|
39
|
-
|
|
39
|
+
// An `undefined` entry is a withheld name (an engine-only variable), removed like an absent one.
|
|
40
|
+
const removedEnv = Object.keys(base).filter((name) => inherited[name] === undefined);
|
|
40
41
|
const inheritedSet: Record<string, string> = {};
|
|
41
42
|
for (const [name, value] of Object.entries(inherited)) {
|
|
42
43
|
if (value !== undefined && base[name] !== value) inheritedSet[name] = value;
|
|
@@ -30,6 +30,9 @@ export function reservedDispatchContext(
|
|
|
30
30
|
...(runtime.handles === undefined ? {} : { handles: runtime.handles }),
|
|
31
31
|
...(host === undefined ? {} : { evalHandleHost: host }),
|
|
32
32
|
...(runtime.environments === undefined ? {} : { environments: runtime.environments }),
|
|
33
|
+
...(runtime.ctx.resolveSecretForFill === undefined
|
|
34
|
+
? {}
|
|
35
|
+
: { resolveSecretForFill: runtime.ctx.resolveSecretForFill }),
|
|
33
36
|
};
|
|
34
37
|
}
|
|
35
38
|
|
|
@@ -27,6 +27,8 @@ export interface EvalDetachedCellNotification {
|
|
|
27
27
|
readonly content: string;
|
|
28
28
|
/** Images the cell displayed, delivered with the notification the way a foreground result delivers them. */
|
|
29
29
|
readonly images?: readonly EvalImageContent[];
|
|
30
|
+
/** The cell was stopped by a client's background stop: its notice waits for the next turn instead of starting one. */
|
|
31
|
+
readonly nextTurn?: true;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export interface EvalDetachedCellNotifier {
|
|
@@ -235,6 +235,35 @@ export class EvalDetachedCellManager {
|
|
|
235
235
|
return this.#snapshot(live);
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Stop every detached cell at once, each through {@link stop}, and settle with each cell's outcome in start order.
|
|
240
|
+
* `notice` decides what a stopped cell's completion notice does: `next-turn` (a client's background stop) waits for
|
|
241
|
+
* the next turn instead of starting one, `wake` delivers it as usual, and `none` (a full session stop,
|
|
242
|
+
* oh-my-openagent#14390) queues none, so the stop never wakes the session it just stopped.
|
|
243
|
+
*/
|
|
244
|
+
async stopAllDetached(
|
|
245
|
+
reason: string,
|
|
246
|
+
{ notice = "next-turn" }: { readonly notice?: "next-turn" | "wake" | "none" } = {},
|
|
247
|
+
): Promise<readonly { readonly cellId: string; readonly summary?: string; readonly error?: unknown }[]> {
|
|
248
|
+
const cells = [...this.#detached.values()].sort((a, b) => a.startedAtMs - b.startedAtMs);
|
|
249
|
+
for (const cell of cells) {
|
|
250
|
+
if (notice === "next-turn") cell.noticeNextTurn = true;
|
|
251
|
+
if (notice === "none") cell.notificationQueued = true;
|
|
252
|
+
}
|
|
253
|
+
// Dequeue first: interrupting an active run can synchronously start its next waiter.
|
|
254
|
+
for (const cell of cells) if (cell.state === "queued") this.#cancelQueued(cell, reason);
|
|
255
|
+
const results = await Promise.allSettled(cells.map(async (cell) => await this.stop(cell.cellId, reason)));
|
|
256
|
+
if (cells.length === 0) this.#emitWakeSourceState([]);
|
|
257
|
+
return cells.map((cell, index) => {
|
|
258
|
+
const result = results[index];
|
|
259
|
+
return {
|
|
260
|
+
cellId: cell.cellId,
|
|
261
|
+
...(cell.input.summary ? { summary: cell.input.summary } : {}),
|
|
262
|
+
...(result?.status === "rejected" ? { error: result.reason } : {}),
|
|
263
|
+
};
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
238
267
|
peek(cellId: string): EvalDetachedCellSnapshot {
|
|
239
268
|
const live = this.#cells.get(cellId);
|
|
240
269
|
return live === undefined ? this.#terminal(cellId) : this.#snapshot(live);
|
|
@@ -266,15 +295,7 @@ export class EvalDetachedCellManager {
|
|
|
266
295
|
}
|
|
267
296
|
|
|
268
297
|
async dispose(): Promise<void> {
|
|
269
|
-
|
|
270
|
-
// Dequeue first: interrupting an active run can synchronously start its next waiter.
|
|
271
|
-
for (const cell of detached) {
|
|
272
|
-
if (cell.state === "queued") this.#cancelQueued(cell, "Session ended; detached eval cell cancelled");
|
|
273
|
-
}
|
|
274
|
-
await Promise.allSettled(
|
|
275
|
-
detached.map(async (cell) => await this.stop(cell.cellId, "Session ended; detached eval cell cancelled")),
|
|
276
|
-
);
|
|
277
|
-
if (detached.length === 0) this.#emitWakeSourceState([]);
|
|
298
|
+
await this.stopAllDetached("Session ended; detached eval cell cancelled", { notice: "wake" });
|
|
278
299
|
await this.#notificationQueue.flush();
|
|
279
300
|
this.#cells.clear();
|
|
280
301
|
this.#terminalSnapshots.clear();
|
|
@@ -316,6 +337,7 @@ export class EvalDetachedCellManager {
|
|
|
316
337
|
await cell.interruptOutcome?.promise;
|
|
317
338
|
return this.#snapshot(cell);
|
|
318
339
|
},
|
|
340
|
+
nextTurn: () => cell.noticeNextTurn,
|
|
319
341
|
...settling,
|
|
320
342
|
});
|
|
321
343
|
}
|
|
@@ -11,6 +11,8 @@ export interface PendingDetachedNotification {
|
|
|
11
11
|
readonly ready?: Promise<void>;
|
|
12
12
|
/** Called once the notification was handed to the notifier, or its delivery failed. */
|
|
13
13
|
readonly onDelivered?: () => void;
|
|
14
|
+
/** Deliver the notice at the next turn without starting one. */
|
|
15
|
+
readonly nextTurn?: () => boolean;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
type QueuedNotification = Omit<PendingDetachedNotification, "ready">;
|
|
@@ -76,7 +78,10 @@ export class DetachedNotificationQueue {
|
|
|
76
78
|
|
|
77
79
|
async #deliver(pending: readonly QueuedNotification[]): Promise<void> {
|
|
78
80
|
const notifications = await Promise.all(
|
|
79
|
-
pending.map(async (item) =>
|
|
81
|
+
pending.map(async (item) => {
|
|
82
|
+
const notification = buildDetachedCellNotification(await item.snapshot());
|
|
83
|
+
return item.nextTurn?.() === true ? { ...notification, nextTurn: true as const } : notification;
|
|
84
|
+
}),
|
|
80
85
|
);
|
|
81
86
|
this.#notifier?.notify(notifications);
|
|
82
87
|
}
|
package/src/tool/managed-cell.ts
CHANGED
|
@@ -25,6 +25,8 @@ export type ManagedCell = {
|
|
|
25
25
|
/** Holds the completion notification until the result the cell ended with has its written files. */
|
|
26
26
|
finalResult: Promise<void> | undefined;
|
|
27
27
|
notificationQueued: boolean;
|
|
28
|
+
/** Set by a client's background stop: the completion notice is delivered at the next turn, never starting one. */
|
|
29
|
+
noticeNextTurn: boolean;
|
|
28
30
|
readonly deadlines: CellDeadlines;
|
|
29
31
|
readonly hardLimitSeconds: number;
|
|
30
32
|
readonly runBudgetSeconds: number;
|
|
@@ -73,6 +75,7 @@ export function createManagedCell(init: ManagedCellInit): ManagedCell {
|
|
|
73
75
|
terminalResult: undefined,
|
|
74
76
|
finalResult: undefined,
|
|
75
77
|
notificationQueued: false,
|
|
78
|
+
noticeNextTurn: false,
|
|
76
79
|
deadlines,
|
|
77
80
|
hardLimitSeconds,
|
|
78
81
|
runBudgetSeconds,
|