@code-yeongyu/senpi-codemode 2026.11.3-1 → 2026.11.3-3

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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## [2026.11.3-3] - 2026-11-03
4
+
5
+ ### Breaking Changes
6
+
7
+ ### Added
8
+
9
+ ### Changed
10
+
11
+ ### Fixed
12
+
13
+ ### Removed
14
+
15
+ ## [2026.11.3-2] - 2026-11-03
16
+
17
+ ### Breaking Changes
18
+
19
+ ### Added
20
+
21
+ ### Changed
22
+
23
+ ### Fixed
24
+
25
+ ### Removed
26
+
3
27
  ## [2026.11.3-1] - 2026-11-03
4
28
 
5
29
  ### Breaking Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi-codemode",
3
- "version": "2026.11.3-1",
3
+ "version": "2026.11.3-3",
4
4
  "description": "Source-only senpi extension package for codemode evaluation tools",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -33,15 +33,15 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@babel/parser": "8.0.4",
36
- "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.3-1",
36
+ "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.3-3",
37
37
  "quickjs-wasi": "3.6.2",
38
38
  "typebox": "1.3.34"
39
39
  },
40
40
  "peerDependencies": {
41
- "@code-yeongyu/senpi": "2026.11.3-1"
41
+ "@code-yeongyu/senpi": "2026.11.3-3"
42
42
  },
43
43
  "devDependencies": {
44
- "@code-yeongyu/senpi": "2026.11.3-1"
44
+ "@code-yeongyu/senpi": "2026.11.3-3"
45
45
  },
46
46
  "keywords": [
47
47
  "senpi",
@@ -0,0 +1,100 @@
1
+ import { createHash } from "node:crypto";
2
+ import { join } from "node:path";
3
+ import {
4
+ type CodemodeSessionManager,
5
+ CodemodeSessionDisposedError,
6
+ type CreateCodemodeSessionManagerOptions,
7
+ createCodemodeSessionManager,
8
+ } from "./session-manager.ts";
9
+
10
+ /** One execution scope (the agent's `ExecutionScope`): an opaque id minted by the loop, and its root directory. */
11
+ export interface KernelScope {
12
+ readonly id: string;
13
+ readonly root: string;
14
+ }
15
+
16
+ /** What belongs to one scope and cannot be shared from the runtime's options: its handles and package environments. */
17
+ export type KernelScopeOwned = Pick<CreateCodemodeSessionManagerOptions, "handles" | "environments" | "sessionEnv">;
18
+
19
+ type CreateManager = (
20
+ options: CreateCodemodeSessionManagerOptions,
21
+ ) => CodemodeSessionManager | Promise<CodemodeSessionManager>;
22
+
23
+ /** The scope id is opaque, so its directory is a digest of it, never the id itself. */
24
+ function scopeDirectory(id: string): string {
25
+ return createHash("sha256").update(id).digest("hex").slice(0, 24);
26
+ }
27
+
28
+ function scopeOptions(
29
+ base: CreateCodemodeSessionManagerOptions,
30
+ scope: KernelScope,
31
+ owned: KernelScopeOwned,
32
+ ): CreateCodemodeSessionManagerOptions {
33
+ const directory = scopeDirectory(scope.id);
34
+ const inScope = (path: string): string => join(path, "scopes", directory);
35
+ return {
36
+ settings: base.settings,
37
+ availability: base.availability,
38
+ executeTool: base.executeTool,
39
+ complete: base.complete,
40
+ ...(base.listTools === undefined ? {} : { listTools: base.listTools }),
41
+ ...owned,
42
+ sessionId: scope.id,
43
+ ownerSessionId: scope.id,
44
+ cwd: scope.root === "" ? base.cwd : scope.root,
45
+ ...(base.artifactsDir === undefined ? {} : { artifactsDir: inScope(base.artifactsDir) }),
46
+ ...(base.localRoots === undefined
47
+ ? {}
48
+ : {
49
+ localRoots: Object.fromEntries(
50
+ Object.entries(base.localRoots).map(([name, root]) => [name, inScope(root)]),
51
+ ),
52
+ }),
53
+ };
54
+ }
55
+
56
+ /**
57
+ * Kernels per execution scope (brain/hand S16b): when one runtime serves several scopes, each gets its own
58
+ * session manager, so its kernels, globals, bridge, completion context, ledgers and `local://` root are its
59
+ * own. Releasing a scope closes exactly its kernels; the others keep running.
60
+ */
61
+ export class ScopedKernelManagers {
62
+ readonly #base: CreateCodemodeSessionManagerOptions;
63
+ readonly #create: CreateManager;
64
+ readonly #managers = new Map<string, Promise<CodemodeSessionManager>>();
65
+ #disposed = false;
66
+
67
+ constructor(base: CreateCodemodeSessionManagerOptions, create: CreateManager = createCodemodeSessionManager) {
68
+ this.#base = base;
69
+ this.#create = create;
70
+ }
71
+
72
+ forScope(scope: KernelScope, owned: KernelScopeOwned = {}): Promise<CodemodeSessionManager> {
73
+ if (this.#disposed) return Promise.reject(new CodemodeSessionDisposedError());
74
+ const existing = this.#managers.get(scope.id);
75
+ if (existing) return existing;
76
+ const created = Promise.resolve(this.#create(scopeOptions(this.#base, scope, owned)));
77
+ this.#managers.set(scope.id, created);
78
+ created.catch(() => {
79
+ if (this.#managers.get(scope.id) === created) this.#managers.delete(scope.id);
80
+ });
81
+ return created;
82
+ }
83
+
84
+ async releaseScope(id: string): Promise<void> {
85
+ const manager = this.#managers.get(id);
86
+ this.#managers.delete(id);
87
+ if (manager) await (await manager).dispose();
88
+ }
89
+
90
+ async dispose(): Promise<void> {
91
+ this.#disposed = true;
92
+ const managers = [...this.#managers.values()];
93
+ this.#managers.clear();
94
+ const failures: unknown[] = [];
95
+ for (const outcome of await Promise.allSettled(managers.map(async (pending) => (await pending).dispose()))) {
96
+ if (outcome.status === "rejected") failures.push(outcome.reason);
97
+ }
98
+ if (failures.length > 0) throw new AggregateError(failures, "Failed to dispose scoped codemode kernels");
99
+ }
100
+ }
@@ -15,6 +15,8 @@ export interface EvalPromptParts {
15
15
  readonly description: string;
16
16
  readonly promptSnippet: string;
17
17
  readonly promptGuidelines: readonly string[];
18
+ /** The pre-diet guidelines, rendered by presets that declare full shared sections (senpi#5665). */
19
+ readonly fullPromptGuidelines: readonly string[];
18
20
  }
19
21
 
20
22
  export interface EvalPromptOptions {
@@ -121,9 +123,33 @@ export function buildEvalPrompt(
121
123
  promptSnippet: "Run one incremental code cell in a persistent language kernel.",
122
124
  // Batching guidance lives in the per-style description above; the guideline keeps only what no schema states.
123
125
  promptGuidelines: ["Bracketed kernel memory notice in eval result names biggest globals -> drop unneeded ones."],
126
+ fullPromptGuidelines: [
127
+ style === "gpt" && context.monitor === true ? GPT_MONITOR_BATCHING_GUIDELINE : BATCHING_GUIDELINES[style],
128
+ "Use eval reset only when a language kernel must be wiped; reset is scoped to the selected language. A bracketed kernel memory notice in a result names the globals holding the most memory; drop the ones you no longer need.",
129
+ ],
124
130
  };
125
131
  }
126
132
 
133
+ /**
134
+ * System-prompt guideline per emphasis dialect. The default dialect carries
135
+ * maximum emphasis so unmapped models still batch through eval; the others are
136
+ * tuned to what steers that family reliably. The GPT line routes waits to the
137
+ * subscription when `monitor` is reachable, because a GPT model that reads
138
+ * "long cells detach" as the way to wait awaits a `--watch` inside a cell.
139
+ */
140
+ const GPT_MONITOR_BATCHING_GUIDELINE =
141
+ "Use eval to compose tool work in one cell; a wait or a long run starts through `tool.monitor` in that cell, so no cell sits on it and nothing polls.";
142
+
143
+ const BATCHING_GUIDELINES: Record<EvalEmphasisStyle, string> = {
144
+ default:
145
+ "Prefer eval when a step's calls are independent: one cell runs them together and keeps every failure in its result; edits and result-dependent calls go one at a time, each observed before the next.",
146
+ claude:
147
+ "Prefer eval for a step's independent calls: one cell runs them together and keeps every failure in its result.",
148
+ codex: "Route a step's independent calls through one eval cell and inspect every result; a direct tool call is right when one call is sufficient.",
149
+ gpt: "Use eval to batch a step's independent tool calls in one cell and inspect every result; long cells detach on their own and notify on completion, so do not poll.",
150
+ kimi: "Put a step's independent calls into one eval cell with parallel(thunks) and keep every failed item in the result.",
151
+ };
152
+
127
153
  function renderTemplate(template: string, context: Context): string {
128
154
  let index = 0;
129
155
  const [rendered, nextIndex] = renderUntil(template, context, index, []);
@@ -134,6 +134,7 @@ export function createEvalTool(options: CreateEvalToolOptions) {
134
134
  description: prompt.description,
135
135
  promptSnippet: prompt.promptSnippet,
136
136
  promptGuidelines: [...prompt.promptGuidelines],
137
+ fullPromptGuidelines: [...prompt.fullPromptGuidelines],
137
138
  parameters,
138
139
  executionMode: "sequential",
139
140
  prepareArguments: (args) => {