@code-yeongyu/senpi 2026.9.18-6 → 2026.9.19-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 +28 -0
- package/dist/bundle/chunks/{app-server-command-EKH7X2QJ.js → app-server-command-QBJ4GPN7.js} +1 -1
- package/dist/bundle/chunks/{bun-extension-importer-JIWSA22V.js → bun-extension-importer-JQZRPNJH.js} +3 -3
- package/dist/bundle/chunks/{chunk-T2RJVIR7.js → chunk-5E5TLB76.js} +1 -1
- package/dist/bundle/chunks/{chunk-TPILTBZO.js → chunk-EHSDTQ6I.js} +6 -6
- package/dist/bundle/chunks/{cli-main-JE55IOJ2.js → cli-main-MLJ2H637.js} +1 -1
- package/dist/bundle/chunks/{interactive-mode-CU6MCSCO.js → interactive-mode-7C75IXNF.js} +1 -1
- package/dist/bundle/chunks/{multi-session-host-X5OT4534.js → multi-session-host-2YCJKQOL.js} +1 -1
- package/dist/bundle/chunks/{package-manager-cli-LVLT5XXS.js → package-manager-cli-4ANSELYT.js} +1 -1
- package/dist/bundle/chunks/{rpc-mode-ULIOZ7JD.js → rpc-mode-OPFQIWFP.js} +1 -1
- package/dist/bundle/chunks/session-worker.js +7 -7
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/agent-session.d.ts +4 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +57 -33
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/bun-extension-importer.d.ts.map +1 -1
- package/dist/core/extensions/bun-extension-importer.js +31 -5
- package/dist/core/extensions/bun-extension-importer.js.map +1 -1
- package/dist/core/extensions/bun-extension-registry.d.ts +5 -0
- package/dist/core/extensions/bun-extension-registry.d.ts.map +1 -1
- package/dist/core/extensions/bun-extension-registry.js +13 -5
- package/dist/core/extensions/bun-extension-registry.js.map +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +24 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/venice.json +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-extension-importer.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/bun-extension-importer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bun-extension-importer.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/bun-extension-importer.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAYxE,iFAAiF;AACjF,wBAAgB,0BAA0B,CACzC,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAqHpE,MAAM,OAAO,MAAM,YAAY;QAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAalF,OAAO;EAQR"}
|
|
@@ -19,6 +19,10 @@ export { bunExtensionImporterStats } from "./bun-extension-registry.js";
|
|
|
19
19
|
export function createBunExtensionImporter(virtualModules) {
|
|
20
20
|
const sources = new Map();
|
|
21
21
|
const commonJs = new Set();
|
|
22
|
+
// Live `module` objects by id, registered while a CommonJS body runs: a require inside a
|
|
23
|
+
// cycle receives the partially built exports, as in Node, instead of an unset ESM default.
|
|
24
|
+
// A body that throws is evicted so a later require re-throws instead of seeing a half-built module.
|
|
25
|
+
const commonJsModules = new Map();
|
|
22
26
|
const nativeRequire = createRequire(import.meta.url);
|
|
23
27
|
let active = true;
|
|
24
28
|
const assertActive = () => {
|
|
@@ -43,9 +47,26 @@ export function createBunExtensionImporter(virtualModules) {
|
|
|
43
47
|
},
|
|
44
48
|
require(specifier, filename) {
|
|
45
49
|
const id = graph.resolve(specifier, filename);
|
|
50
|
+
const evaluating = commonJsModules.get(id);
|
|
51
|
+
if (evaluating !== undefined)
|
|
52
|
+
return evaluating.exports;
|
|
46
53
|
const result = nativeRequire(id);
|
|
47
54
|
return commonJs.has(id) ? result.default : result;
|
|
48
55
|
},
|
|
56
|
+
evaluateCommonJs(filename, body) {
|
|
57
|
+
assertActive();
|
|
58
|
+
const id = moduleId(filename);
|
|
59
|
+
const module = { exports: {} };
|
|
60
|
+
commonJsModules.set(id, module);
|
|
61
|
+
try {
|
|
62
|
+
body.call(module.exports, module.exports, module);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
commonJsModules.delete(id);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
return module.exports;
|
|
69
|
+
},
|
|
49
70
|
load(filename) {
|
|
50
71
|
assertActive();
|
|
51
72
|
const existing = sources.get(filename);
|
|
@@ -102,13 +123,17 @@ export function createBunExtensionImporter(virtualModules) {
|
|
|
102
123
|
for (const edit of edits.sort((a, b) => b.start - a.start)) {
|
|
103
124
|
contents = contents.slice(0, edit.start) + edit.text + contents.slice(edit.end);
|
|
104
125
|
}
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
126
|
+
// A shebang is only a shebang on the first line, so it goes before any prologue.
|
|
127
|
+
contents = contents.replace(/^#![^\n]*\n/, "");
|
|
128
|
+
// Runtime plugins load ESM, even for CommonJS source. Node's module
|
|
129
|
+
// function wrapper preserves synchronous export assignment and keeps
|
|
130
|
+
// `exports` and `module` reassignable bindings with `this` as the exports
|
|
131
|
+
// object, as dependencies such as whatwg-url and jsdom require.
|
|
132
|
+
if (!hasModuleSyntax && extension !== ".mjs" && extension !== ".mts") {
|
|
108
133
|
commonJs.add(moduleId(filename));
|
|
109
|
-
contents = `
|
|
134
|
+
contents = `export default ${name}.commonJs(function (exports, module) {\n${contents}\n});`;
|
|
110
135
|
}
|
|
111
|
-
contents = `import { metadata as ${name}Factory } from "${extensionNamespace}:runtime";\nconst ${name} = ${name}Factory(${JSON.stringify(registration.generation)}, ${JSON.stringify(filename)});\n${contents
|
|
136
|
+
contents = `import { metadata as ${name}Factory } from "${extensionNamespace}:runtime";\nconst ${name} = ${name}Factory(${JSON.stringify(registration.generation)}, ${JSON.stringify(filename)});\n${contents}`;
|
|
112
137
|
const prepared = { contents, loader: "js" };
|
|
113
138
|
sources.set(filename, prepared);
|
|
114
139
|
return prepared;
|
|
@@ -135,6 +160,7 @@ export function createBunExtensionImporter(virtualModules) {
|
|
|
135
160
|
registration.dispose();
|
|
136
161
|
sources.clear();
|
|
137
162
|
commonJs.clear();
|
|
163
|
+
commonJsModules.clear();
|
|
138
164
|
},
|
|
139
165
|
};
|
|
140
166
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-extension-importer.js","sourceRoot":"","sources":["../../../src/core/extensions/bun-extension-importer.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM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CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFileSync, realpathSync } from \"node:fs\";\nimport { createRequire, isBuiltin } from \"node:module\";\nimport { dirname, extname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { parse } from \"es-module-lexer/js\";\nimport { isCommonJsFile, rewriteCommonJsImport } from \"./bun-extension-commonjs.ts\";\nimport { ExtensionSourceError } from \"./bun-extension-error.ts\";\nimport {\n\tExtensionGenerationDisposedError,\n\textensionNamespace,\n\ttype ModuleSource,\n\tregisterExtensionGraph,\n} from \"./bun-extension-registry.ts\";\n\nexport { bunExtensionImporterStats } from \"./bun-extension-registry.ts\";\n\n// Keep the source/Node build independent of Bun's ambient type declarations.\ndeclare const Bun: {\n\tresolveSync(specifier: string, directory: string): string;\n\tTranspiler: new (options: {\n\t\treadonly loader: \"ts\" | \"tsx\" | \"jsx\";\n\t\treadonly target: \"bun\";\n\t\treadonly define: Readonly<Record<string, string>>;\n\t}) => { transformSync(source: string): string };\n};\n\n/** A generation owns only source bookkeeping; Bun owns evaluation and cycles. */\nexport function createBunExtensionImporter(\n\tvirtualModules: Readonly<Record<string, Readonly<Record<string, unknown>>>>,\n) {\n\tconst sources = new Map<string, ModuleSource>();\n\tconst commonJs = new Set<string>();\n\tconst nativeRequire = createRequire(import.meta.url);\n\tlet active = true;\n\tconst assertActive = () => {\n\t\tif (!active) throw new ExtensionGenerationDisposedError(registration.generation);\n\t};\n\tconst moduleId = (filename: string) =>\n\t\t`${extensionNamespace}:${registration.generation}/${encodeURIComponent(filename)}`;\n\tconst resolveTarget = (specifier: string, filename: string): { readonly id: string; readonly path?: string } => {\n\t\tassertActive();\n\t\tif (Object.hasOwn(virtualModules, specifier) || isBuiltin(specifier) || specifier.startsWith(\"bun:\"))\n\t\t\treturn { id: specifier };\n\t\tif (specifier.startsWith(`${extensionNamespace}:`)) return { id: specifier };\n\t\tconst path = specifier.startsWith(\"file:\") ? fileURLToPath(specifier) : specifier;\n\t\tconst resolved = realpathSync(Bun.resolveSync(path, dirname(filename)));\n\t\treturn { id: moduleId(resolved), path: resolved };\n\t};\n\tconst graph = {\n\t\tassertActive,\n\t\tresolve(specifier: string, filename: string): string {\n\t\t\treturn resolveTarget(specifier, filename).id;\n\t\t},\n\t\trequire(specifier: string, filename: string): unknown {\n\t\t\tconst id = graph.resolve(specifier, filename);\n\t\t\tconst result: { readonly default?: unknown } = nativeRequire(id);\n\t\t\treturn commonJs.has(id) ? result.default : result;\n\t\t},\n\t\tload(filename: string): ModuleSource {\n\t\t\tassertActive();\n\t\t\tconst existing = sources.get(filename);\n\t\t\tif (existing) return existing;\n\t\t\tconst source = readFileSync(filename, \"utf8\");\n\t\t\tlet name = \"__senpiExtensionMeta\";\n\t\t\twhile (source.includes(name)) name += \"_\";\n\t\t\tconst extension = extname(filename);\n\t\t\tconst transpiler = new Bun.Transpiler({\n\t\t\t\tloader: extension === \".tsx\" ? \"tsx\" : extension === \".jsx\" ? \"jsx\" : \"ts\",\n\t\t\t\ttarget: \"bun\",\n\t\t\t\tdefine: {\n\t\t\t\t\t\"import.meta\": name,\n\t\t\t\t\trequire: `${name}.require`,\n\t\t\t\t\t__filename: `${name}.path`,\n\t\t\t\t\t__dirname: `${name}.dir`,\n\t\t\t\t},\n\t\t\t});\n\t\t\tlet contents: string;\n\t\t\ttry {\n\t\t\t\tcontents = transpiler.transformSync(source);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof AggregateError) throw new ExtensionSourceError(filename, error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst [imports, , , hasModuleSyntax] = parse(contents, filename);\n\t\t\tconst edits: { readonly start: number; readonly end: number; readonly text: string }[] = [];\n\t\t\tlet commonJsImports = 0;\n\t\t\tfor (const edge of imports) {\n\t\t\t\tif (edge.d >= 0) {\n\t\t\t\t\t// Replace the keyword, not its argument: nested expressions, templates,\n\t\t\t\t\t// import attributes, and unavailable optional dependencies stay lazy.\n\t\t\t\t\tedits.push({ start: edge.ss, end: edge.d, text: `${name}.import` });\n\t\t\t\t} else if (edge.n !== undefined) {\n\t\t\t\t\tconst target = resolveTarget(edge.n, filename);\n\t\t\t\t\tif (target.path !== undefined && isCommonJsFile(target.path)) {\n\t\t\t\t\t\tconst clause = contents.slice(edge.ss + \"import\".length, edge.s - 1).replace(/\\bfrom\\s*$/, \"\");\n\t\t\t\t\t\tedits.push({\n\t\t\t\t\t\t\tstart: edge.ss,\n\t\t\t\t\t\t\tend: edge.se,\n\t\t\t\t\t\t\ttext: rewriteCommonJsImport(clause, target.id, `${name}Cjs${commonJsImports++}`),\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tedits.push({ start: edge.s - 1, end: edge.e + 1, text: JSON.stringify(target.id) });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const edit of edits.sort((a, b) => b.start - a.start)) {\n\t\t\t\tcontents = contents.slice(0, edit.start) + edit.text + contents.slice(edit.end);\n\t\t\t}\n\t\t\t// Runtime plugins load ESM, even for CommonJS source. A local module\n\t\t\t// wrapper preserves synchronous export assignment.\n\t\t\tif (!hasModuleSyntax) {\n\t\t\t\tcommonJs.add(moduleId(filename));\n\t\t\t\tcontents = `const module = { exports: {} }; const exports = module.exports;\\n${contents}\\nexport default module.exports;`;\n\t\t\t}\n\t\t\tcontents = `import { metadata as ${name}Factory } from \"${extensionNamespace}:runtime\";\\nconst ${name} = ${name}Factory(${JSON.stringify(registration.generation)}, ${JSON.stringify(filename)});\\n${contents.replace(/^#![^\\n]*\\n/, \"\")}`;\n\t\t\tconst prepared = { contents, loader: \"js\" } satisfies ModuleSource;\n\t\t\tsources.set(filename, prepared);\n\t\t\treturn prepared;\n\t\t},\n\t};\n\tconst registration = registerExtensionGraph(graph, virtualModules);\n\treturn {\n\t\tasync import(path: string, _options: { readonly default: true }): Promise<unknown> {\n\t\t\tassertActive();\n\t\t\tconst id = moduleId(realpathSync(resolve(path)));\n\t\t\tconst module: { readonly default?: unknown } = await import(id);\n\t\t\tconst factory = module.default;\n\t\t\tif (typeof factory !== \"function\") return factory;\n\t\t\t// This wrapper is not stored in Bun's permanent module registry. A\n\t\t\t// reachable old factory keeps its own computed-import graph alive.\n\t\t\treturn function (this: unknown, ...args: unknown[]) {\n\t\t\t\tgraph.assertActive();\n\t\t\t\treturn factory.apply(this, args);\n\t\t\t};\n\t\t},\n\t\tdispose() {\n\t\t\tactive = false;\n\t\t\tregistration.dispose();\n\t\t\tsources.clear();\n\t\t\tcommonJs.clear();\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bun-extension-importer.js","sourceRoot":"","sources":["../../../src/core/extensions/bun-extension-importer.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAGN,gCAAgC,EAChC,kBAAkB,EAElB,sBAAsB,GACtB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAYxE,iFAAiF;AACjF,MAAM,UAAU,0BAA0B,CACzC,cAA2E;IAE3E,MAAM,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;IAChD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,yFAAyF;IACzF,2FAA2F;IAC3F,oGAAoG;IACpG,MAA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ACjD,MAAM,MAAM,GAAmC,MAAM,MAAM,kCAAC,EAAE,EAAC,CAAC;YAChE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;YAC/B,IAAI,OAAO,OAAO,KAAK,UAAU;gBAAE,OAAO,OAAO,CAAC;YAClD,mEAAmE;YACnE,mEAAmE;YACnE,OAAO,UAAyB,GAAG,IAAe;gBACjD,KAAK,CAAC,YAAY,EAAE,CAAC;gBACrB,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAClC,CAAC,CAAC;QACH,CAAC;QACD,OAAO;YACN,MAAM,GAAG,KAAK,CAAC;YACf,YAAY,CAAC,OAAO,EAAE,CAAC;YACvB,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,eAAe,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFileSync, realpathSync } from \"node:fs\";\nimport { createRequire, isBuiltin } from \"node:module\";\nimport { dirname, extname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { parse } from \"es-module-lexer/js\";\nimport { isCommonJsFile, rewriteCommonJsImport } from \"./bun-extension-commonjs.ts\";\nimport { ExtensionSourceError } from \"./bun-extension-error.ts\";\nimport {\n\ttype CommonJsBody,\n\ttype CommonJsModule,\n\tExtensionGenerationDisposedError,\n\textensionNamespace,\n\ttype ModuleSource,\n\tregisterExtensionGraph,\n} from \"./bun-extension-registry.ts\";\n\nexport { bunExtensionImporterStats } from \"./bun-extension-registry.ts\";\n\n// Keep the source/Node build independent of Bun's ambient type declarations.\ndeclare const Bun: {\n\tresolveSync(specifier: string, directory: string): string;\n\tTranspiler: new (options: {\n\t\treadonly loader: \"ts\" | \"tsx\" | \"jsx\";\n\t\treadonly target: \"bun\";\n\t\treadonly define: Readonly<Record<string, string>>;\n\t}) => { transformSync(source: string): string };\n};\n\n/** A generation owns only source bookkeeping; Bun owns evaluation and cycles. */\nexport function createBunExtensionImporter(\n\tvirtualModules: Readonly<Record<string, Readonly<Record<string, unknown>>>>,\n) {\n\tconst sources = new Map<string, ModuleSource>();\n\tconst commonJs = new Set<string>();\n\t// Live `module` objects by id, registered while a CommonJS body runs: a require inside a\n\t// cycle receives the partially built exports, as in Node, instead of an unset ESM default.\n\t// A body that throws is evicted so a later require re-throws instead of seeing a half-built module.\n\tconst commonJsModules = new Map<string, CommonJsModule>();\n\tconst nativeRequire = createRequire(import.meta.url);\n\tlet active = true;\n\tconst assertActive = () => {\n\t\tif (!active) throw new ExtensionGenerationDisposedError(registration.generation);\n\t};\n\tconst moduleId = (filename: string) =>\n\t\t`${extensionNamespace}:${registration.generation}/${encodeURIComponent(filename)}`;\n\tconst resolveTarget = (specifier: string, filename: string): { readonly id: string; readonly path?: string } => {\n\t\tassertActive();\n\t\tif (Object.hasOwn(virtualModules, specifier) || isBuiltin(specifier) || specifier.startsWith(\"bun:\"))\n\t\t\treturn { id: specifier };\n\t\tif (specifier.startsWith(`${extensionNamespace}:`)) return { id: specifier };\n\t\tconst path = specifier.startsWith(\"file:\") ? fileURLToPath(specifier) : specifier;\n\t\tconst resolved = realpathSync(Bun.resolveSync(path, dirname(filename)));\n\t\treturn { id: moduleId(resolved), path: resolved };\n\t};\n\tconst graph = {\n\t\tassertActive,\n\t\tresolve(specifier: string, filename: string): string {\n\t\t\treturn resolveTarget(specifier, filename).id;\n\t\t},\n\t\trequire(specifier: string, filename: string): unknown {\n\t\t\tconst id = graph.resolve(specifier, filename);\n\t\t\tconst evaluating = commonJsModules.get(id);\n\t\t\tif (evaluating !== undefined) return evaluating.exports;\n\t\t\tconst result: { readonly default?: unknown } = nativeRequire(id);\n\t\t\treturn commonJs.has(id) ? result.default : result;\n\t\t},\n\t\tevaluateCommonJs(filename: string, body: CommonJsBody): unknown {\n\t\t\tassertActive();\n\t\t\tconst id = moduleId(filename);\n\t\t\tconst module: CommonJsModule = { exports: {} };\n\t\t\tcommonJsModules.set(id, module);\n\t\t\ttry {\n\t\t\t\tbody.call(module.exports, module.exports, module);\n\t\t\t} catch (error) {\n\t\t\t\tcommonJsModules.delete(id);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn module.exports;\n\t\t},\n\t\tload(filename: string): ModuleSource {\n\t\t\tassertActive();\n\t\t\tconst existing = sources.get(filename);\n\t\t\tif (existing) return existing;\n\t\t\tconst source = readFileSync(filename, \"utf8\");\n\t\t\tlet name = \"__senpiExtensionMeta\";\n\t\t\twhile (source.includes(name)) name += \"_\";\n\t\t\tconst extension = extname(filename);\n\t\t\tconst transpiler = new Bun.Transpiler({\n\t\t\t\tloader: extension === \".tsx\" ? \"tsx\" : extension === \".jsx\" ? \"jsx\" : \"ts\",\n\t\t\t\ttarget: \"bun\",\n\t\t\t\tdefine: {\n\t\t\t\t\t\"import.meta\": name,\n\t\t\t\t\trequire: `${name}.require`,\n\t\t\t\t\t__filename: `${name}.path`,\n\t\t\t\t\t__dirname: `${name}.dir`,\n\t\t\t\t},\n\t\t\t});\n\t\t\tlet contents: string;\n\t\t\ttry {\n\t\t\t\tcontents = transpiler.transformSync(source);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof AggregateError) throw new ExtensionSourceError(filename, error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst [imports, , , hasModuleSyntax] = parse(contents, filename);\n\t\t\tconst edits: { readonly start: number; readonly end: number; readonly text: string }[] = [];\n\t\t\tlet commonJsImports = 0;\n\t\t\tfor (const edge of imports) {\n\t\t\t\tif (edge.d >= 0) {\n\t\t\t\t\t// Replace the keyword, not its argument: nested expressions, templates,\n\t\t\t\t\t// import attributes, and unavailable optional dependencies stay lazy.\n\t\t\t\t\tedits.push({ start: edge.ss, end: edge.d, text: `${name}.import` });\n\t\t\t\t} else if (edge.n !== undefined) {\n\t\t\t\t\tconst target = resolveTarget(edge.n, filename);\n\t\t\t\t\tif (target.path !== undefined && isCommonJsFile(target.path)) {\n\t\t\t\t\t\tconst clause = contents.slice(edge.ss + \"import\".length, edge.s - 1).replace(/\\bfrom\\s*$/, \"\");\n\t\t\t\t\t\tedits.push({\n\t\t\t\t\t\t\tstart: edge.ss,\n\t\t\t\t\t\t\tend: edge.se,\n\t\t\t\t\t\t\ttext: rewriteCommonJsImport(clause, target.id, `${name}Cjs${commonJsImports++}`),\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tedits.push({ start: edge.s - 1, end: edge.e + 1, text: JSON.stringify(target.id) });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const edit of edits.sort((a, b) => b.start - a.start)) {\n\t\t\t\tcontents = contents.slice(0, edit.start) + edit.text + contents.slice(edit.end);\n\t\t\t}\n\t\t\t// A shebang is only a shebang on the first line, so it goes before any prologue.\n\t\t\tcontents = contents.replace(/^#![^\\n]*\\n/, \"\");\n\t\t\t// Runtime plugins load ESM, even for CommonJS source. Node's module\n\t\t\t// function wrapper preserves synchronous export assignment and keeps\n\t\t\t// `exports` and `module` reassignable bindings with `this` as the exports\n\t\t\t// object, as dependencies such as whatwg-url and jsdom require.\n\t\t\tif (!hasModuleSyntax && extension !== \".mjs\" && extension !== \".mts\") {\n\t\t\t\tcommonJs.add(moduleId(filename));\n\t\t\t\tcontents = `export default ${name}.commonJs(function (exports, module) {\\n${contents}\\n});`;\n\t\t\t}\n\t\t\tcontents = `import { metadata as ${name}Factory } from \"${extensionNamespace}:runtime\";\\nconst ${name} = ${name}Factory(${JSON.stringify(registration.generation)}, ${JSON.stringify(filename)});\\n${contents}`;\n\t\t\tconst prepared = { contents, loader: \"js\" } satisfies ModuleSource;\n\t\t\tsources.set(filename, prepared);\n\t\t\treturn prepared;\n\t\t},\n\t};\n\tconst registration = registerExtensionGraph(graph, virtualModules);\n\treturn {\n\t\tasync import(path: string, _options: { readonly default: true }): Promise<unknown> {\n\t\t\tassertActive();\n\t\t\tconst id = moduleId(realpathSync(resolve(path)));\n\t\t\tconst module: { readonly default?: unknown } = await import(id);\n\t\t\tconst factory = module.default;\n\t\t\tif (typeof factory !== \"function\") return factory;\n\t\t\t// This wrapper is not stored in Bun's permanent module registry. A\n\t\t\t// reachable old factory keeps its own computed-import graph alive.\n\t\t\treturn function (this: unknown, ...args: unknown[]) {\n\t\t\t\tgraph.assertActive();\n\t\t\t\treturn factory.apply(this, args);\n\t\t\t};\n\t\t},\n\t\tdispose() {\n\t\t\tactive = false;\n\t\t\tregistration.dispose();\n\t\t\tsources.clear();\n\t\t\tcommonJs.clear();\n\t\t\tcommonJsModules.clear();\n\t\t},\n\t};\n}\n"]}
|
|
@@ -6,10 +6,15 @@ export type Resolution = {
|
|
|
6
6
|
readonly path: string;
|
|
7
7
|
readonly namespace: string;
|
|
8
8
|
};
|
|
9
|
+
export type CommonJsModule = {
|
|
10
|
+
exports: unknown;
|
|
11
|
+
};
|
|
12
|
+
export type CommonJsBody = (this: unknown, exports: unknown, module: CommonJsModule) => void;
|
|
9
13
|
export interface ExtensionGraph {
|
|
10
14
|
resolve(specifier: string, filename: string): string;
|
|
11
15
|
load(filename: string): ModuleSource;
|
|
12
16
|
require(specifier: string, filename: string): unknown;
|
|
17
|
+
evaluateCommonJs(filename: string, body: CommonJsBody): unknown;
|
|
13
18
|
}
|
|
14
19
|
export declare const extensionNamespace = "senpi-extension";
|
|
15
20
|
export declare class ExtensionModuleIdError extends Error {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-extension-registry.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/bun-extension-registry.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAA;CAAE,CAAC;AAChF,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,C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AAC,IAAI,4BAA4B;IACzC,YAAY,EAAE,EAAE,MAAM,EAErB;CACD;AAED,qBAAa,gCAAiC,SAAQ,KAAK;IAC1D,QAAQ,CAAC,IAAI,sCAAsC;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,YAAY,UAAU,EAAE,MAAM,EAG7B;CACD;AAmFD,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,cAAc,EACrB,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;;;EAa3E;AAED,gFAAgF;AAChF,wBAAgB,yBAAyB;IAC/B,WAAW;IAAgE,OAAO;EAC3F"}
|
|
@@ -63,17 +63,25 @@ function graphFor(generation) {
|
|
|
63
63
|
// Module-registry exports must never close over a graph: Bun retains modules.
|
|
64
64
|
// Only the importer, returned factory wrappers, and live runtimes own graphs.
|
|
65
65
|
function metadata(generation, filename) {
|
|
66
|
+
const resolvePath = (specifier) => {
|
|
67
|
+
const id = graphFor(generation).resolve(specifier, filename);
|
|
68
|
+
return id.startsWith(`${extensionNamespace}:`) ? decodeURIComponent(id.slice(id.indexOf("/") + 1)) : undefined;
|
|
69
|
+
};
|
|
70
|
+
// CommonJS code calls `require.resolve` for sibling files (jsdom locates its XHR sync
|
|
71
|
+
// worker that way), so `require` is a function object carrying Node's resolver shape.
|
|
72
|
+
const require = Object.assign((specifier) => graphFor(generation).require(specifier, filename), {
|
|
73
|
+
resolve: (specifier) => resolvePath(specifier) ?? graphFor(generation).resolve(specifier, filename),
|
|
74
|
+
});
|
|
66
75
|
return {
|
|
67
76
|
url: pathToFileURL(filename).href,
|
|
68
77
|
path: filename,
|
|
69
78
|
dir: dirname(filename),
|
|
70
|
-
require
|
|
79
|
+
require,
|
|
80
|
+
commonJs: (body) => graphFor(generation).evaluateCommonJs(filename, body),
|
|
71
81
|
import: async (specifier, options) => import(__rewriteRelativeImportExtension(graphFor(generation).resolve(specifier, filename)), { ...options }),
|
|
72
82
|
resolve: (specifier) => {
|
|
73
|
-
const
|
|
74
|
-
return
|
|
75
|
-
? pathToFileURL(decodeURIComponent(id.slice(id.indexOf("/") + 1))).href
|
|
76
|
-
: id;
|
|
83
|
+
const path = resolvePath(specifier);
|
|
84
|
+
return path === undefined ? graphFor(generation).resolve(specifier, filename) : pathToFileURL(path).href;
|
|
77
85
|
},
|
|
78
86
|
};
|
|
79
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-extension-registry.js","sourceRoot":"","sources":["../../../src/core/extensions/bun-extension-registry.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AA2BvE,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AACpD,MAAM,iBAAiB,GAAG,SAAS,CAAC;AACpC,2FAA2F;AAC3F,+FAA+F;AAC/F,sEAAsE;AACtE,MAAM,iBAAiB,GAAG,wBAAwB,EAAE,CAAC;AAErD,SAAS,wBAAwB;IAChC,IAAI,CAAC;QACJ,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,+BAA+B,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3F,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC;AAED,4FAA4F;AAC5F,8FAA8F;AAC9F,8FAA8F;AAC9F,8DAA8D;AAC9D,SAAS,aAAa,CAAC,EAAU;IA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C1B,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;KACD,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,yBAAyB;IACxC,OAAO,EAAE,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC;AACpH,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { publishRuntimeMetadata } from \"./extension-runtime-module.ts\";\n\nexport type ModuleSource = { readonly contents: string; readonly loader: \"js\" };\nexport type Resolution = { readonly path: string; readonly namespace: string };\nexport interface ExtensionGraph {\n\tresolve(specifier: string, filename: string): string;\n\tload(filename: string): ModuleSource;\n\trequire(specifier: string, filename: string): unknown;\n}\ntype ModuleObject = { readonly exports: Readonly<Record<string, unknown>>; readonly loader: \"object\" };\ndeclare const Bun: {\n\tplugin(options: {\n\t\treadonly name: string;\n\t\treadonly setup: (builder: {\n\t\t\tmodule(name: string, load: () => ModuleObject): void;\n\t\t\tonResolve(\n\t\t\t\toptions: { readonly filter: RegExp; readonly namespace: string },\n\t\t\t\tresolve: (args: { readonly path: string }) => Resolution,\n\t\t\t): void;\n\t\t\tonLoad(\n\t\t\t\toptions: { readonly filter: RegExp; readonly namespace: string },\n\t\t\t\tload: (args: { readonly path: string }) => ModuleSource,\n\t\t\t): void;\n\t\t}) => void;\n\t}): void;\n};\n\nexport const extensionNamespace = \"senpi-extension\";\nconst RUNTIME_SPECIFIER = \"runtime\";\n// Inside a `bun build --compile` binary the shim has no on-disk path (import.meta.url is a\n// $bunfs URL), so the file route is only available when the file is really there; the compiled\n// binary keeps the virtual module, which it never had a problem with.\nconst runtimeModulePath = resolveRuntimeModulePath();\n\nfunction resolveRuntimeModulePath(): string | undefined {\n\ttry {\n\t\tconst candidate = fileURLToPath(new URL(\"./extension-runtime-module.js\", import.meta.url));\n\t\treturn existsSync(candidate) ? candidate : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n// An id is `<generation>/<encodeURIComponent(filename)>`. The encoded half never contains a\n// literal \"/\" (Windows separators arrive as %5C), so the FIRST slash is always the generation\n// separator — but only when one exists. A bare id with no slash used to slice to nonsense and\n// surface as `Cannot find package '<generation>'` (omo#8427).\nfunction splitModuleId(id: string): { readonly generation: string; readonly filename: string } | undefined {\n\tconst slash = id.indexOf(\"/\");\n\tif (slash <= 0 || slash === id.length - 1) return undefined;\n\treturn { generation: id.slice(0, slash), filename: decodeURIComponent(id.slice(slash + 1)) };\n}\nconst graphs = new Map<string, WeakRef<ExtensionGraph>>();\nconst collected = new FinalizationRegistry<string>((generation) => graphs.delete(generation));\nlet nextGeneration = 0;\nlet installed = false;\nlet pluginRegistrations = 0;\nconst registeredHosts = new Set<string>();\n\nexport class ExtensionModuleIdError extends Error {\n\treadonly name = \"ExtensionModuleIdError\";\n\tconstructor(id: string) {\n\t\tsuper(`Extension module id is not \"<generation>/<encoded filename>\": ${id}`);\n\t}\n}\n\nexport class ExtensionGenerationDisposedError extends Error {\n\treadonly name = \"ExtensionGenerationDisposedError\";\n\treadonly generation: string;\n\tconstructor(generation: string) {\n\t\tsuper(`Extension generation ${generation} has been disposed`);\n\t\tthis.generation = generation;\n\t}\n}\nfunction graphFor(generation: string): ExtensionGraph {\n\tconst graph = graphs.get(generation)?.deref();\n\tif (!graph) throw new ExtensionGenerationDisposedError(generation);\n\treturn graph;\n}\n\n// Module-registry exports must never close over a graph: Bun retains modules.\n// Only the importer, returned factory wrappers, and live runtimes own graphs.\nfunction metadata(generation: string, filename: string) {\n\treturn {\n\t\turl: pathToFileURL(filename).href,\n\t\tpath: filename,\n\t\tdir: dirname(filename),\n\t\trequire: (specifier: string) => graphFor(generation).require(specifier, filename),\n\t\timport: async (specifier: string, options?: ImportCallOptions) =>\n\t\t\timport(graphFor(generation).resolve(specifier, filename), { ...options }),\n\t\tresolve: (specifier: string) => {\n\t\t\tconst id = graphFor(generation).resolve(specifier, filename);\n\t\t\treturn id.startsWith(`${extensionNamespace}:`)\n\t\t\t\t? pathToFileURL(decodeURIComponent(id.slice(id.indexOf(\"/\") + 1))).href\n\t\t\t\t: id;\n\t\t},\n\t};\n}\n\n// A separate activation prevents permanent hooks from sharing a closure\n// environment with registerExtensionGraph's disposable graph reference.\nfunction installRegistry(virtualModules: Readonly<Record<string, Readonly<Record<string, unknown>>>>) {\n\tconst hosts = Object.entries(virtualModules).filter(([name]) => !registeredHosts.has(name));\n\tif (!installed || hosts.length > 0) {\n\t\tpluginRegistrations++;\n\t\tBun.plugin({\n\t\t\tname: extensionNamespace,\n\t\t\tsetup(builder) {\n\t\t\t\tfor (const [name, exports] of hosts) {\n\t\t\t\t\tbuilder.module(name, () => ({ exports, loader: \"object\" }));\n\t\t\t\t\tregisteredHosts.add(name);\n\t\t\t\t}\n\t\t\t\tif (installed) return;\n\t\t\t\t// \"runtime\" resolves to a real file, never a Bun.plugin virtual module. A\n\t\t\t\t// builder.module() registration is intermittently invisible to the resolver under\n\t\t\t\t// `bun test --parallel` on a loaded Windows shard: onResolve still fires and returns\n\t\t\t\t// the namespace, the registration is still listed, and Bun answers\n\t\t\t\t// `Cannot find package 'runtime'` anyway — generation 1 served 40 resolves and\n\t\t\t\t// refused the 41st in the same worker (omo#8427, run 35329245740). A file on disk\n\t\t\t\t// has no registration window to lose.\n\t\t\t\tpublishRuntimeMetadata(metadata);\n\t\t\t\tbuilder.module(`${extensionNamespace}:${RUNTIME_SPECIFIER}`, () => ({\n\t\t\t\t\texports: { metadata },\n\t\t\t\t\tloader: \"object\",\n\t\t\t\t}));\n\t\t\t\tbuilder.onResolve({ filter: /.*/, namespace: extensionNamespace }, ({ path }) => {\n\t\t\t\t\tif (path === RUNTIME_SPECIFIER)\n\t\t\t\t\t\treturn runtimeModulePath === undefined\n\t\t\t\t\t\t\t? { path, namespace: extensionNamespace }\n\t\t\t\t\t\t\t: { path: runtimeModulePath, namespace: \"file\" };\n\t\t\t\t\tconst parsed = splitModuleId(path);\n\t\t\t\t\tif (parsed === undefined) throw new ExtensionModuleIdError(path);\n\t\t\t\t\tgraphFor(parsed.generation);\n\t\t\t\t\treturn /\\.[cm]?[jt]sx?$/.test(parsed.filename)\n\t\t\t\t\t\t? { path, namespace: extensionNamespace }\n\t\t\t\t\t\t: { path: parsed.filename, namespace: \"file\" };\n\t\t\t\t});\n\t\t\t\tbuilder.onLoad({ filter: /.*/, namespace: extensionNamespace }, ({ path }) => {\n\t\t\t\t\tconst parsed = splitModuleId(path);\n\t\t\t\t\tif (parsed === undefined) throw new ExtensionModuleIdError(path);\n\t\t\t\t\treturn graphFor(parsed.generation).load(parsed.filename);\n\t\t\t\t});\n\t\t\t\tinstalled = true;\n\t\t\t},\n\t\t});\n\t}\n}\n\nexport function registerExtensionGraph(\n\tgraph: ExtensionGraph,\n\tvirtualModules: Readonly<Record<string, Readonly<Record<string, unknown>>>>,\n) {\n\tinstallRegistry(virtualModules);\n\tconst generation = String(nextGeneration++);\n\tgraphs.set(generation, new WeakRef(graph));\n\tcollected.register(graph, generation, graph);\n\treturn {\n\t\tgeneration,\n\t\tdispose() {\n\t\t\tgraphs.delete(generation);\n\t\t\tcollected.unregister(graph);\n\t\t},\n\t};\n}\n\n/** Internal lifecycle diagnostics, shared by regression and compiled probes. */\nexport function bunExtensionImporterStats() {\n\treturn { generations: [...graphs.values()].filter((entry) => entry.deref()).length, plugins: pluginRegistrations };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bun-extension-registry.js","sourceRoot":"","sources":["../../../src/core/extensions/bun-extension-registry.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,E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AC,CAAC;IAC7C,OAAO;QACN,UAAU;QACV,OAAO;YACN,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAC1B,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;KACD,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,yBAAyB;IACxC,OAAO,EAAE,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC;AACpH,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { publishRuntimeMetadata } from \"./extension-runtime-module.ts\";\n\nexport type ModuleSource = { readonly contents: string; readonly loader: \"js\" };\nexport type Resolution = { readonly path: string; readonly namespace: string };\nexport type CommonJsModule = { exports: unknown };\nexport type CommonJsBody = (this: unknown, exports: unknown, module: CommonJsModule) => void;\nexport interface ExtensionGraph {\n\tresolve(specifier: string, filename: string): string;\n\tload(filename: string): ModuleSource;\n\trequire(specifier: string, filename: string): unknown;\n\tevaluateCommonJs(filename: string, body: CommonJsBody): unknown;\n}\ntype ModuleObject = { readonly exports: Readonly<Record<string, unknown>>; readonly loader: \"object\" };\ndeclare const Bun: {\n\tplugin(options: {\n\t\treadonly name: string;\n\t\treadonly setup: (builder: {\n\t\t\tmodule(name: string, load: () => ModuleObject): void;\n\t\t\tonResolve(\n\t\t\t\toptions: { readonly filter: RegExp; readonly namespace: string },\n\t\t\t\tresolve: (args: { readonly path: string }) => Resolution,\n\t\t\t): void;\n\t\t\tonLoad(\n\t\t\t\toptions: { readonly filter: RegExp; readonly namespace: string },\n\t\t\t\tload: (args: { readonly path: string }) => ModuleSource,\n\t\t\t): void;\n\t\t}) => void;\n\t}): void;\n};\n\nexport const extensionNamespace = \"senpi-extension\";\nconst RUNTIME_SPECIFIER = \"runtime\";\n// Inside a `bun build --compile` binary the shim has no on-disk path (import.meta.url is a\n// $bunfs URL), so the file route is only available when the file is really there; the compiled\n// binary keeps the virtual module, which it never had a problem with.\nconst runtimeModulePath = resolveRuntimeModulePath();\n\nfunction resolveRuntimeModulePath(): string | undefined {\n\ttry {\n\t\tconst candidate = fileURLToPath(new URL(\"./extension-runtime-module.js\", import.meta.url));\n\t\treturn existsSync(candidate) ? candidate : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n// An id is `<generation>/<encodeURIComponent(filename)>`. The encoded half never contains a\n// literal \"/\" (Windows separators arrive as %5C), so the FIRST slash is always the generation\n// separator — but only when one exists. A bare id with no slash used to slice to nonsense and\n// surface as `Cannot find package '<generation>'` (omo#8427).\nfunction splitModuleId(id: string): { readonly generation: string; readonly filename: string } | undefined {\n\tconst slash = id.indexOf(\"/\");\n\tif (slash <= 0 || slash === id.length - 1) return undefined;\n\treturn { generation: id.slice(0, slash), filename: decodeURIComponent(id.slice(slash + 1)) };\n}\nconst graphs = new Map<string, WeakRef<ExtensionGraph>>();\nconst collected = new FinalizationRegistry<string>((generation) => graphs.delete(generation));\nlet nextGeneration = 0;\nlet installed = false;\nlet pluginRegistrations = 0;\nconst registeredHosts = new Set<string>();\n\nexport class ExtensionModuleIdError extends Error {\n\treadonly name = \"ExtensionModuleIdError\";\n\tconstructor(id: string) {\n\t\tsuper(`Extension module id is not \"<generation>/<encoded filename>\": ${id}`);\n\t}\n}\n\nexport class ExtensionGenerationDisposedError extends Error {\n\treadonly name = \"ExtensionGenerationDisposedError\";\n\treadonly generation: string;\n\tconstructor(generation: string) {\n\t\tsuper(`Extension generation ${generation} has been disposed`);\n\t\tthis.generation = generation;\n\t}\n}\nfunction graphFor(generation: string): ExtensionGraph {\n\tconst graph = graphs.get(generation)?.deref();\n\tif (!graph) throw new ExtensionGenerationDisposedError(generation);\n\treturn graph;\n}\n\n// Module-registry exports must never close over a graph: Bun retains modules.\n// Only the importer, returned factory wrappers, and live runtimes own graphs.\nfunction metadata(generation: string, filename: string) {\n\tconst resolvePath = (specifier: string) => {\n\t\tconst id = graphFor(generation).resolve(specifier, filename);\n\t\treturn id.startsWith(`${extensionNamespace}:`) ? decodeURIComponent(id.slice(id.indexOf(\"/\") + 1)) : undefined;\n\t};\n\t// CommonJS code calls `require.resolve` for sibling files (jsdom locates its XHR sync\n\t// worker that way), so `require` is a function object carrying Node's resolver shape.\n\tconst require = Object.assign((specifier: string) => graphFor(generation).require(specifier, filename), {\n\t\tresolve: (specifier: string) => resolvePath(specifier) ?? graphFor(generation).resolve(specifier, filename),\n\t});\n\treturn {\n\t\turl: pathToFileURL(filename).href,\n\t\tpath: filename,\n\t\tdir: dirname(filename),\n\t\trequire,\n\t\tcommonJs: (body: CommonJsBody) => graphFor(generation).evaluateCommonJs(filename, body),\n\t\timport: async (specifier: string, options?: ImportCallOptions) =>\n\t\t\timport(graphFor(generation).resolve(specifier, filename), { ...options }),\n\t\tresolve: (specifier: string) => {\n\t\t\tconst path = resolvePath(specifier);\n\t\t\treturn path === undefined ? graphFor(generation).resolve(specifier, filename) : pathToFileURL(path).href;\n\t\t},\n\t};\n}\n\n// A separate activation prevents permanent hooks from sharing a closure\n// environment with registerExtensionGraph's disposable graph reference.\nfunction installRegistry(virtualModules: Readonly<Record<string, Readonly<Record<string, unknown>>>>) {\n\tconst hosts = Object.entries(virtualModules).filter(([name]) => !registeredHosts.has(name));\n\tif (!installed || hosts.length > 0) {\n\t\tpluginRegistrations++;\n\t\tBun.plugin({\n\t\t\tname: extensionNamespace,\n\t\t\tsetup(builder) {\n\t\t\t\tfor (const [name, exports] of hosts) {\n\t\t\t\t\tbuilder.module(name, () => ({ exports, loader: \"object\" }));\n\t\t\t\t\tregisteredHosts.add(name);\n\t\t\t\t}\n\t\t\t\tif (installed) return;\n\t\t\t\t// \"runtime\" resolves to a real file, never a Bun.plugin virtual module. A\n\t\t\t\t// builder.module() registration is intermittently invisible to the resolver under\n\t\t\t\t// `bun test --parallel` on a loaded Windows shard: onResolve still fires and returns\n\t\t\t\t// the namespace, the registration is still listed, and Bun answers\n\t\t\t\t// `Cannot find package 'runtime'` anyway — generation 1 served 40 resolves and\n\t\t\t\t// refused the 41st in the same worker (omo#8427, run 35329245740). A file on disk\n\t\t\t\t// has no registration window to lose.\n\t\t\t\tpublishRuntimeMetadata(metadata);\n\t\t\t\tbuilder.module(`${extensionNamespace}:${RUNTIME_SPECIFIER}`, () => ({\n\t\t\t\t\texports: { metadata },\n\t\t\t\t\tloader: \"object\",\n\t\t\t\t}));\n\t\t\t\tbuilder.onResolve({ filter: /.*/, namespace: extensionNamespace }, ({ path }) => {\n\t\t\t\t\tif (path === RUNTIME_SPECIFIER)\n\t\t\t\t\t\treturn runtimeModulePath === undefined\n\t\t\t\t\t\t\t? { path, namespace: extensionNamespace }\n\t\t\t\t\t\t\t: { path: runtimeModulePath, namespace: \"file\" };\n\t\t\t\t\tconst parsed = splitModuleId(path);\n\t\t\t\t\tif (parsed === undefined) throw new ExtensionModuleIdError(path);\n\t\t\t\t\tgraphFor(parsed.generation);\n\t\t\t\t\treturn /\\.[cm]?[jt]sx?$/.test(parsed.filename)\n\t\t\t\t\t\t? { path, namespace: extensionNamespace }\n\t\t\t\t\t\t: { path: parsed.filename, namespace: \"file\" };\n\t\t\t\t});\n\t\t\t\tbuilder.onLoad({ filter: /.*/, namespace: extensionNamespace }, ({ path }) => {\n\t\t\t\t\tconst parsed = splitModuleId(path);\n\t\t\t\t\tif (parsed === undefined) throw new ExtensionModuleIdError(path);\n\t\t\t\t\treturn graphFor(parsed.generation).load(parsed.filename);\n\t\t\t\t});\n\t\t\t\tinstalled = true;\n\t\t\t},\n\t\t});\n\t}\n}\n\nexport function registerExtensionGraph(\n\tgraph: ExtensionGraph,\n\tvirtualModules: Readonly<Record<string, Readonly<Record<string, unknown>>>>,\n) {\n\tinstallRegistry(virtualModules);\n\tconst generation = String(nextGeneration++);\n\tgraphs.set(generation, new WeakRef(graph));\n\tcollected.register(graph, generation, graph);\n\treturn {\n\t\tgeneration,\n\t\tdispose() {\n\t\t\tgraphs.delete(generation);\n\t\t\tcollected.unregister(graph);\n\t\t},\n\t};\n}\n\n/** Internal lifecycle diagnostics, shared by regression and compiled probes. */\nexport function bunExtensionImporterStats() {\n\treturn { generations: [...graphs.values()].filter((entry) => entry.deref()).length, plugins: pluginRegistrations };\n}\n"]}
|
|
@@ -12,6 +12,30 @@
|
|
|
12
12
|
|
|
13
13
|
### Removed
|
|
14
14
|
|
|
15
|
+
## [2026.9.19-2] - 2026-09-19
|
|
16
|
+
|
|
17
|
+
### Breaking Changes
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
### Removed
|
|
26
|
+
|
|
27
|
+
## [2026.9.19] - 2026-09-19
|
|
28
|
+
|
|
29
|
+
### Breaking Changes
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
### Removed
|
|
38
|
+
|
|
15
39
|
## [2026.9.18-6] - 2026-09-18
|
|
16
40
|
|
|
17
41
|
### Breaking Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-yeongyu/senpi-codemode",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.19-2",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Source-only senpi extension package for codemode evaluation tools",
|
|
6
6
|
"type": "module",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/parser": "8.0.4",
|
|
34
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.
|
|
34
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.19-2",
|
|
35
35
|
"typebox": "1.3.27"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@code-yeongyu/senpi": "2026.9.
|
|
38
|
+
"@code-yeongyu/senpi": "2026.9.19-2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@code-yeongyu/senpi": "2026.9.
|
|
41
|
+
"@code-yeongyu/senpi": "2026.9.19-2"
|
|
42
42
|
},
|
|
43
43
|
"keywords": [
|
|
44
44
|
"senpi",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@earendil-works/pi-agent-core",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.19-2",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@earendil-works/chord": "0.85.1",
|
|
60
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.
|
|
61
|
-
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.9.
|
|
60
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.19-2",
|
|
61
|
+
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.9.19-2",
|
|
62
62
|
"diff": "9.0.0",
|
|
63
63
|
"ignore": "7.0.8",
|
|
64
64
|
"typebox": "1.3.27",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"schemaVersion":3,"generatedAt":"2026-09-
|
|
1
|
+
{"schemaVersion":3,"generatedAt":"2026-09-19T04:09:40.557Z","structureHash":"57db5c07086b14bc2c9c1819202d28d05e4b9790bf4e84884593fa709763eb7a","files":{"alibaba-token-plan.json":"3a9c1be76d47459371e9fa2feeffc31e7edbbfec65fa9cc41236988efc4cf6d9","amazon-bedrock.json":"d82a76308591b1777c351a22f1bd3e4f332a50464743dfc3610b250e265e531d","ant-ling.json":"4979fe79d99ed97382d7ce40170c6132e932e77906de1eb54464c042e7d63633","anthropic.json":"e9d883ee35d94dba963320b5496bd7dd368d226cbafcf134bfec66a0a24b3b7f","azure-openai-responses.json":"9d2137c68fbf7012872296a02a13a138f7d5246dc09f2ca79e34e6a875b11488","bai.json":"2b12b15bd43462e60711944dd7283db8676611d9d76c82c2a01f64913e16a67e","baseten.json":"d155c434294b5167244cffb6dea6793f9669e91e8ab65b564f9510d81b330e37","cerebras.json":"9eaa554e1b02f3665f8f63e6432d253bf81351af7c72001054dd8108aa528a52","cloudflare-ai-gateway.json":"b62b46dbb24c9a5cd0c10ba5adb58aedc2a1c0616459f36b51e07bb15416e584","cloudflare-workers-ai.json":"07ef63208ff7517fd1a80962f18143e21de399640423329490b157f459ccf995","deepseek.json":"b5f9693ec641e9a957dc5f7a22042b3bb928bac3d7268406619b6f18e21c4b83","fireworks.json":"6283651d25a8861e7d42fe2bdb1cb7dd80802811dfaf61e40c11cc813408c294","github-copilot.json":"2628f6583c2509e1f17412e6a8a8f12cf20750cc8cb82ab4273c63155cee4746","google-vertex.json":"e1631109172dc1f7d7977570420a5bb86258bdd1088427e244a2c51545c4f24d","google.json":"7619bf03edd2a7acb06a2274a14b13c3a61354288abe029a758401d4de36a8fd","groq.json":"e4728fd72e358cd8f25e9a518e9b49a521ef44523d3debe38a7db9e0663c4077","huggingface.json":"a488b6f175b382277ccf7d487f877ef0c698994576bb55d2410838bf9c8c7c41","minimax-cn.json":"65d37e55a6d9585855f94b3fb7739308d107fe248ebd9e1001d1c5d4606ad2c4","minimax.json":"c7dc5765995ae77242916430929c7cc9a782589f7e483e13f7e01663190d028e","mistral.json":"be522597b22bceeb0bb9a0ba1781647649ffd19637d0c8e67b056d7b0ec33d52","moonshotai-cn.json":"c4e1801b5dfd61bebcaa33cbfc5ed0c69df14a3bee37da218a558668d817864e","moonshotai.json":"3dab637e7e2648792c786157f85f29026b93393f7098b77593c1180928d371c9","nvidia.json":"2ff6862206269af88a694e627c4b54753055357710adaf49ac8518d102c17407","openai-codex.json":"5b308f19ee369ba78113998361d8f8e6c160690b29947e6f07ccbc12b46289e6","openai.json":"203a1d6bf61178268edf3d3f0ad4a6408eded401c4472bda4ac0ec73142f38ce","opencode-go.json":"f97adb96bf613ee102585c6c4cd0a8cc8047d51c8cfe4cf2f98673afce09ee3d","opencode.json":"edb7363c10cd409684c0cce1c2e5d250af80c9c8e40fb6c76384ea4b32491f1d","opengateway.json":"98a5c5a0e8998579d8735da8f8db8d24842f570d6c835758c50d6801c22b8a10","openrouter.json":"0bb56f2b9429dd830b372cd326ab23987a03fff374eceba27a5aba25626bd979","qwen-token-plan-cn.json":"4bf520ed38e5c3045680d2ec2816fa8a69079dbe97f7b929767a63172288da6b","qwen-token-plan-individual.json":"eb040e78595853e980011308b1bf9caacae6dc8a91abbac5ffebd402515dd2a6","qwen-token-plan.json":"a5c67213745329ec3ba79f712f31c1c32a781d7ffb8c04f9819f36c27672531f","together.json":"927c707d06f2236cdab13f14c870fb58bce0614ba7287bbcd57cc9fd66d191ed","venice.json":"647ef3c78a9c6215a9759dd54985af96adde4757cf32f129448fced334c25d16","vercel-ai-gateway.json":"be9809f013a4dfbe6de0c19abc134cd7ea73856dbb12c592aef5e841921aac25","xai.json":"5947370c4a40ad85605f1a17ae09d4d6dd4f9ab120d14fabfb4c5a08a75e6f7e","xiaomi-token-plan-ams.json":"568b9992cf320536a65826e26a414afa5c0d17f083a01af4bd96658d9dd3e705","xiaomi-token-plan-cn.json":"c423857d0bbb0b126394eaf1ebb2a91bf2d1193cc5a4fe77843ff0f4536a0a80","xiaomi-token-plan-sgp.json":"008f1eb41037e93c5ae478f12815cd67bac1978f131ffefa602775bb60b63fea","xiaomi.json":"37acf451bb4364bdca2ecea6b7d962590d9974a87e80cfe34bb800be6a95c13b","zai-coding-cn.json":"c68da532c6e8fa126372e743a2474d9f483ac3260bf9b1fad3ee40183957e141","zai.json":"f42790c77fb4681a656897a9d860b939916c0ddf979a5f16856bce9573cdf64e"}}
|