@ai-agent-forge/agent-forge 0.88.8 → 0.88.9

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/bundled-plugins/agent-loop-policy/agent-forge.json +1 -1
  3. package/bundled-plugins/agent-loop-policy/plugin.json +1 -1
  4. package/bundled-plugins/alignment/agent-forge.json +1 -1
  5. package/bundled-plugins/alignment/plugin.json +1 -1
  6. package/bundled-plugins/browser-playwright/agent-forge.json +1 -1
  7. package/bundled-plugins/browser-playwright/plugin.json +1 -1
  8. package/bundled-plugins/coding-tools/agent-forge.json +1 -1
  9. package/bundled-plugins/coding-tools/plugin.json +1 -1
  10. package/bundled-plugins/compaction-policy/agent-forge.json +1 -1
  11. package/bundled-plugins/compaction-policy/plugin.json +1 -1
  12. package/bundled-plugins/overflow-policy/agent-forge.json +1 -1
  13. package/bundled-plugins/overflow-policy/plugin.json +1 -1
  14. package/bundled-plugins/provider-failover/agent-forge.json +1 -1
  15. package/bundled-plugins/provider-failover/plugin.json +1 -1
  16. package/bundled-plugins/retry-policy/agent-forge.json +1 -1
  17. package/bundled-plugins/retry-policy/plugin.json +1 -1
  18. package/dist/bundle/.build-manifest.json +9 -9
  19. package/dist/bundle/chunks/{chunk-ZS5JEI76.js → chunk-4BD6FSZA.js} +1 -1
  20. package/dist/bundle/chunks/{chunk-ISLHFRER.js → chunk-F73USSXE.js} +1 -1
  21. package/dist/bundle/chunks/{chunk-WJSKB3FC.js → chunk-HXGAAJQQ.js} +1 -1
  22. package/dist/bundle/chunks/{chunk-L2SXIPI5.js → chunk-VWNIFYQA.js} +3 -3
  23. package/dist/bundle/chunks/image-resize-worker.js +1 -1
  24. package/dist/bundle/chunks/{virtual-modules-2QGILFV7.js → virtual-modules-UQRUJLPM.js} +1 -1
  25. package/dist/bundle/cli.js +1 -1
  26. package/dist/bundle/client.js +1 -1
  27. package/dist/bundle/index.js +1 -1
  28. package/dist/bundle/rpc-entry.js +1 -1
  29. package/dist/core/i18n/locales/zh-cn/cli.d.ts.map +1 -1
  30. package/dist/core/i18n/locales/zh-cn/cli.js +2 -1
  31. package/dist/core/i18n/locales/zh-cn/cli.js.map +1 -1
  32. package/dist/plugins/ecosystem/catalog.d.ts +1 -1
  33. package/dist/plugins/ecosystem/catalog.d.ts.map +1 -1
  34. package/dist/plugins/ecosystem/catalog.js +10 -4
  35. package/dist/plugins/ecosystem/catalog.js.map +1 -1
  36. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts +6 -1
  37. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts.map +1 -1
  38. package/dist/plugins/ecosystem/node-plugin-bootstrap.js +11 -3
  39. package/dist/plugins/ecosystem/node-plugin-bootstrap.js.map +1 -1
  40. package/dist/plugins/ecosystem/plugin-bootstrap.d.ts +10 -0
  41. package/dist/plugins/ecosystem/plugin-bootstrap.d.ts.map +1 -1
  42. package/dist/plugins/ecosystem/plugin-bootstrap.js +66 -23
  43. package/dist/plugins/ecosystem/plugin-bootstrap.js.map +1 -1
  44. package/examples/extensions/with-deps/package-lock.json +2 -2
  45. package/examples/extensions/with-deps/package.json +1 -1
  46. package/examples/extensions/with-deps/plugin.json +1 -1
  47. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"node-plugin-bootstrap.js","sourceRoot":"","sources":["../../../src/plugins/ecosystem/node-plugin-bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,CAAC,EAAE,MAAM,0BAA0B,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAE5E,OAAO,EAAE,oCAAoC,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,EACN,4BAA4B,EAC5B,wBAA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AAE,EAAE,CAAC;oBACrC,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;wBACnC,OAAO,CAAC,KAAK,CACZ,CAAC,CAAC,iCAAiC,EAAE;4BACpC,QAAQ,EAAE,MAAM,CAAC,QAAQ;4BACzB,OAAO,EAAE,MAAM,CAAC,gBAAgB,IAAI,EAAE;yBACtC,CAAC,CACF,CAAC;oBACH,CAAC;yBAAM,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;wBACvC,OAAO,CAAC,KAAK,CACZ,CAAC,CACA,mGAAiG,EACjG,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,SAAS,IAAI,gBAAgB,EAAE,CACzE,CACD,CAAC;oBACH,CAAC;gBAAA,CACD,CAAC;SACH,CAAC,CAAC;IACJ,CAAC;YAAS,CAAC;QACV,MAAM,MAAM,GAAG,OAAO,CAAC;QACvB,OAAO,GAAG,SAAS,CAAC;QACpB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YACxD,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACzD,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["/**\n * Node wiring for the startup plugin bootstrap (design\n * `插件独立分发与启动装配设计.md` §4.4, §0.7).\n *\n * `AGENT_FORGE_PLUGIN_BOOTSTRAP=off` skips everything, including the local\n * comparison. The comparison dependency reads the global and project\n * plugin-state.json stores only — read-only, and it never constructs an HTTP\n * client, so an assembled environment starts offline (G3). Network objects\n * (npm acquisition host, install host) are built lazily inside the install\n * action and closed when the bootstrap finishes. Installs go through the\n * npm acquisition path exclusively and persist the `npm:<host>` source label\n * in the global plugin state (same prepare/install/activate/upsert\n * transaction shape as the CLI install flow, implemented as a library\n * function without going through the CLI layer).\n */\n\nimport { join } from \"node:path\";\nimport { CONFIG_DIR_NAME } from \"../../config.ts\";\nimport { t } from \"../../core/i18n/index.ts\";\nimport { isOfflineModeEnabled } from \"../../core/package-process-runner.ts\";\nimport type { PluginBootstrapFactoryEntryV1 } from \"./bootstrap-factory-manifest.ts\";\nimport { BOOTSTRAP_FACTORY_PLUGIN_MANIFEST_V1 } from \"./bootstrap-factory-manifest.ts\";\nimport {\n\tDEFAULT_PLUGIN_STATE_FILE_V1,\n\tdefaultPluginHostFactsV1,\n\tdefaultPluginInstallStoreDirectoryV1,\n\tprojectPluginScopeRefV1,\n} from \"./default-active-bindings.ts\";\nimport { createPluginInstallerV1, DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1, type PluginInstallerV1 } from \"./installer.ts\";\nimport {\n\tcreateNodePackageInstallHostV1,\n\ttype NodePackageInstallHostV1,\n\ttype NodeZipPackageLimitsV1,\n} from \"./node-package-install-host.ts\";\nimport { createNodePluginAcquisitionHostV1, type NodePluginAcquisitionHostV1 } from \"./node-plugin-acquisition-host.ts\";\nimport {\n\ttype PluginBootstrapActionV1,\n\ttype PluginBootstrapDepsV1,\n\ttype PluginBootstrapResultV1,\n\trunPluginBootstrapV1,\n} from \"./plugin-bootstrap.ts\";\nimport { createPluginStateStoreV1, type PluginStateRecordV1, type PluginStateStoreV1 } from \"./state.ts\";\n\n/** Environment variable disabling the startup bootstrap entirely (`off`). */\nexport const AGENT_FORGE_PLUGIN_BOOTSTRAP_ENV_V1 = \"AGENT_FORGE_PLUGIN_BOOTSTRAP\";\n\n/** The only recognized disabling value; every other value (and absence) keeps bootstrap on. */\nconst PLUGIN_BOOTSTRAP_DISABLED_VALUE_V1 = \"off\";\n\nexport interface NodePluginBootstrapOptionsV1 {\n\treadonly agentDir: string;\n\treadonly cwd: string;\n\t/** Defaults to the frozen factory manifest. */\n\treadonly manifest?: readonly PluginBootstrapFactoryEntryV1[];\n\t/** Bare http(s) npm registry origin; forwarded to the acquisition host. */\n\treadonly npmRegistry?: string;\n\t/** npm registry bearer token; forwarded to the acquisition host. */\n\treadonly npmToken?: string;\n\treadonly limits?: NodeZipPackageLimitsV1;\n\t/** Deterministic fetch replacement for tests. */\n\treadonly fetch?: typeof globalThis.fetch;\n\treadonly signal?: AbortSignal;\n\t/** Full dependency override for deterministic tests; the env switch still applies. */\n\treadonly deps?: PluginBootstrapDepsV1;\n\t/** Overrides the first-run progress line (stderr) for tests and hosts. */\n\treadonly onPendingInstalls?: (count: number) => void;\n\t/**\n\t * Overrides the per-plugin progress renderer (stderr) for tests and hosts.\n\t * The default prints one line per installed/aligned/failed entry and stays\n\t * silent for satisfied entries.\n\t */\n\treadonly onAction?: (action: PluginBootstrapActionV1) => void;\n}\n\nexport type NodePluginBootstrapResultV1 = PluginBootstrapResultV1 & {\n\t/**\n\t * Present when a posture switch short-circuited the run before any local\n\t * comparison: the wiring-level env off switch, or the offline posture\n\t * (设计 §4.4 offline 姿态门, 2026-10-03 — offline installs cannot succeed\n\t * and would only fail slowly, so the run is skipped immediately).\n\t */\n\treadonly skipped?: \"disabled\" | \"offline\";\n};\n\n/** Install-scoped boundaries; created lazily by the first install action. */\ninterface InstallSessionV1 {\n\treadonly acquisition: NodePluginAcquisitionHostV1;\n\treadonly installHost: NodePackageInstallHostV1;\n\treadonly installer: PluginInstallerV1;\n\treadonly stateStore: PluginStateStoreV1;\n}\n\nfunction readActiveVersions(\n\tstore: PluginStateStoreV1,\n\tscope: \"global\" | \"project\",\n\tscopeRef: string,\n\tsignal: AbortSignal | undefined,\n): Promise<ReadonlyMap<string, string>> {\n\treturn (async () => {\n\t\tconst result = await store.read({ ...(signal === undefined ? {} : { signal }) });\n\t\tif (result.status !== \"ok\" && result.status !== \"missing\")\n\t\t\tthrow new Error(\n\t\t\t\tt(\"plugin state read failed ({detail}) for the {scope} scope\", {\n\t\t\t\t\tdetail: result.diagnostics[0]?.code ?? result.status,\n\t\t\t\t\tscope,\n\t\t\t\t}),\n\t\t\t);\n\t\tconst versions = new Map<string, string>();\n\t\tfor (const record of result.snapshot.records) {\n\t\t\tif (record.state.scope !== scope || record.state.scopeRef !== scopeRef) continue;\n\t\t\t// Enabled is deliberately not filtered: a disabled plugin still owns\n\t\t\t// its active installation record, and bootstrap never touches it (G5).\n\t\t\tif (record.state.lifecycle !== \"active\") continue;\n\t\t\tversions.set(record.pluginId, record.pluginVersion);\n\t\t}\n\t\treturn versions;\n\t})();\n}\n\n/**\n * Previous active installation record for one plugin id in the bootstrap's\n * global installation scope, or undefined when the plugin has no active\n * global installation. Mirrors the CLI update transaction's previous lookup\n * (cli.ts `findCurrentStateRecord`): same plugin id, same scope/scopeRef,\n * lifecycle active — bootstrap installs exclusively into this scope, so only\n * a record here can have had its runtime disposed by host.activate.\n */\nasync function readPreviousActiveRecord(\n\tstore: PluginStateStoreV1,\n\tpluginId: string,\n\tsignal: AbortSignal | undefined,\n): Promise<PluginStateRecordV1 | undefined> {\n\tconst result = await store.read({ ...(signal === undefined ? {} : { signal }) });\n\tif (result.status !== \"ok\" && result.status !== \"missing\")\n\t\tthrow new Error(\n\t\t\tt(\"plugin state read failed ({detail}) for the {scope} scope\", {\n\t\t\t\tdetail: result.diagnostics[0]?.code ?? result.status,\n\t\t\t\tscope: \"global\",\n\t\t\t}),\n\t\t);\n\treturn result.snapshot.records.find(\n\t\t(record) =>\n\t\t\trecord.pluginId === pluginId &&\n\t\t\trecord.state.scope === \"global\" &&\n\t\t\trecord.state.scopeRef === DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1 &&\n\t\t\trecord.state.lifecycle === \"active\",\n\t);\n}\n\n/**\n * Run the startup bootstrap for one agent directory. The function resolves\n * with a structured result and never throws for per-plugin failures; only a\n * wiring-level construction error propagates to the caller (main.ts guards\n * startup with its own catch).\n */\nexport async function runNodePluginBootstrapV1(\n\toptions: NodePluginBootstrapOptionsV1,\n): Promise<NodePluginBootstrapResultV1> {\n\tif (process.env[AGENT_FORGE_PLUGIN_BOOTSTRAP_ENV_V1]?.trim() === PLUGIN_BOOTSTRAP_DISABLED_VALUE_V1) {\n\t\treturn Object.freeze({\n\t\t\tversion: 1,\n\t\t\tstatus: \"succeeded\",\n\t\t\tactions: Object.freeze([]),\n\t\t\tdiagnostics: Object.freeze([]),\n\t\t\tdurationMs: 0,\n\t\t\tskipped: \"disabled\",\n\t\t});\n\t}\n\tif (isOfflineModeEnabled()) {\n\t\treturn Object.freeze({\n\t\t\tversion: 1,\n\t\t\tstatus: \"succeeded\",\n\t\t\tactions: Object.freeze([]),\n\t\t\tdiagnostics: Object.freeze([\n\t\t\t\t{\n\t\t\t\t\tcode: \"bootstrap_skipped_offline\",\n\t\t\t\t\tmessage: t(\n\t\t\t\t\t\t\"Offline posture (AGENT_FORGE_OFFLINE) skips the startup plugin bootstrap; run `agent-forge plugin install <package>` explicitly to install plugins.\",\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t] as const),\n\t\t\tdurationMs: 0,\n\t\t\tskipped: \"offline\",\n\t\t});\n\t}\n\tif (options.deps !== undefined) {\n\t\treturn await runPluginBootstrapV1({\n\t\t\tmanifest: options.manifest ?? BOOTSTRAP_FACTORY_PLUGIN_MANIFEST_V1,\n\t\t\tdeps: options.deps,\n\t\t\t...(options.onPendingInstalls === undefined ? {} : { onPendingInstalls: options.onPendingInstalls }),\n\t\t\t...(options.onAction === undefined ? {} : { onAction: options.onAction }),\n\t\t});\n\t}\n\tlet session: InstallSessionV1 | undefined;\n\tconst ensureSession = async (): Promise<InstallSessionV1> => {\n\t\tif (session !== undefined) return session;\n\t\tconst acquisition = createNodePluginAcquisitionHostV1({\n\t\t\t...(options.npmRegistry === undefined ? {} : { npmRegistry: options.npmRegistry }),\n\t\t\t...(options.npmToken === undefined ? {} : { npmToken: options.npmToken }),\n\t\t\t...(options.fetch === undefined ? {} : { fetch: options.fetch }),\n\t\t\t...(options.limits === undefined ? {} : { limits: options.limits }),\n\t\t});\n\t\tconst installHost = await createNodePackageInstallHostV1({\n\t\t\topenArtifact: (input) => acquisition.openArtifact(input),\n\t\t\tinstallationDirectory: defaultPluginInstallStoreDirectoryV1(options.agentDir),\n\t\t\tpersistence: \"persistent\",\n\t\t\tsupportedScopes: [\"global\", \"project\"],\n\t\t\t...(options.limits === undefined ? {} : { ...options.limits }),\n\t\t});\n\t\tsession = {\n\t\t\tacquisition,\n\t\t\tinstallHost,\n\t\t\tinstaller: createPluginInstallerV1({ host: installHost }),\n\t\t\tstateStore: createPluginStateStoreV1({ filePath: join(options.agentDir, DEFAULT_PLUGIN_STATE_FILE_V1) }),\n\t\t};\n\t\treturn session;\n\t};\n\tconst deps: PluginBootstrapDepsV1 = {\n\t\tlistActive: async ({ signal }) => {\n\t\t\tconst globalVersions = readActiveVersions(\n\t\t\t\tcreatePluginStateStoreV1({ filePath: join(options.agentDir, DEFAULT_PLUGIN_STATE_FILE_V1) }),\n\t\t\t\t\"global\",\n\t\t\t\tDEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\tsignal,\n\t\t\t);\n\t\t\tconst projectVersions = readActiveVersions(\n\t\t\t\tcreatePluginStateStoreV1({ filePath: join(options.cwd, CONFIG_DIR_NAME, DEFAULT_PLUGIN_STATE_FILE_V1) }),\n\t\t\t\t\"project\",\n\t\t\t\tprojectPluginScopeRefV1(options.cwd),\n\t\t\t\tsignal,\n\t\t\t);\n\t\t\tconst [globalResult, projectResult] = await Promise.all([globalVersions, projectVersions]);\n\t\t\t// Project precedence mirrors active-binding resolution: a project\n\t\t\t// installation shadows the same plugin id from the global scope.\n\t\t\treturn new Map([...globalResult, ...projectResult]);\n\t\t},\n\t\tinstallFromNpm: async ({ npmName, range, signal }) => {\n\t\t\t// Download retry (设计 §4.4 下载重试, 2026-10-04): transient registry\n\t\t\t// failures retried with backoff at this wiring layer so the decision\n\t\t\t// loop stays pure. Abort propagates immediately between attempts.\n\t\t\tlet lastError: unknown;\n\t\t\tfor (let attempt = 1; attempt <= 3; attempt++) {\n\t\t\t\tif (signal?.aborted === true) throw lastError ?? new Error(\"install aborted\");\n\t\t\t\ttry {\n\t\t\t\t\treturn await installFromNpmOnce({ npmName, range, signal });\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlastError = error;\n\t\t\t\t\t// Abort during the attempt surfaces as the attempt's own error;\n\t\t\t\t\t// the loop-top check and the backoff listener cover the pauses.\n\t\t\t\t\tif (attempt === 3) throw error;\n\t\t\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\t\t\tconst timer = setTimeout(resolve, 400 * 2 ** (attempt - 1));\n\t\t\t\t\t\tsignal?.addEventListener(\n\t\t\t\t\t\t\t\"abort\",\n\t\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\t\t\t\treject(lastError);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ once: true },\n\t\t\t\t\t\t);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow lastError;\n\t\t},\n\t\t...(options.signal === undefined ? {} : { signal: options.signal }),\n\t};\n\tconst installFromNpmOnce = async (input: {\n\t\treadonly npmName: string;\n\t\treadonly range?: string;\n\t\treadonly signal?: AbortSignal;\n\t}): Promise<{ readonly pluginVersion: string; readonly source: string }> => {\n\t\tconst { npmName, range, signal } = input;\n\t\t{\n\t\t\tconst active = await ensureSession();\n\t\t\t// npm refs only (§0.7): scoped or plain names with the shared minimal\n\t\t\t// range subset; no github/gitee/url/local ref can be expressed here.\n\t\t\tconst ref = range === undefined ? npmName : `${npmName}@${range}`;\n\t\t\tconst acquired = await active.acquisition.resolvePackage({ ref, ...(signal === undefined ? {} : { signal }) });\n\t\t\tlet released = false;\n\t\t\tconst release = async (): Promise<void> => {\n\t\t\t\tif (released) return;\n\t\t\t\treleased = true;\n\t\t\t\tawait acquired.release();\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tconst verified = active.installer.prepare({\n\t\t\t\t\tmanifest: acquired.manifest,\n\t\t\t\t\tsource: acquired.source,\n\t\t\t\t\thost: defaultPluginHostFactsV1(),\n\t\t\t\t});\n\t\t\t\tif (verified.status !== \"verified\")\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tt(\"installer prepare rejected {pluginId}: {reason}\", {\n\t\t\t\t\t\t\tpluginId: acquired.manifest.id,\n\t\t\t\t\t\t\treason: verified.reason,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tconst installed = await active.installer.install({\n\t\t\t\t\trecord: verified.record,\n\t\t\t\t\tscope: \"global\",\n\t\t\t\t\tscopeRef: DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\t\tartifact: acquired.artifact,\n\t\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t\t});\n\t\t\t\tif (installed.status !== \"succeeded\")\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tt(\"plugin install failed ({code}) for {pluginId}\", {\n\t\t\t\t\t\t\tcode: installed.error.code,\n\t\t\t\t\t\t\tpluginId: acquired.manifest.id,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tconst activated = await active.installer.activate({\n\t\t\t\t\tinstallation: installed.installation,\n\t\t\t\t\trecord: verified.record,\n\t\t\t\t\tscope: \"global\",\n\t\t\t\t\tscopeRef: DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t\t});\n\t\t\t\tif (activated.status !== \"succeeded\") {\n\t\t\t\t\t// CLI update-transaction alignment (cli.ts activate-failure\n\t\t\t\t\t// path): host.activate disposed the previous runtime for this\n\t\t\t\t\t// installation key before the new candidate failed to commit,\n\t\t\t\t\t// so restore the previous active installation through the\n\t\t\t\t\t// installer rollback. Rollback runs before the failed\n\t\t\t\t\t// candidate is removed because host.rollback requires the\n\t\t\t\t\t// failed record to still exist.\n\t\t\t\t\tlet restoreFailure: string | undefined;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst previous = await readPreviousActiveRecord(active.stateStore, acquired.manifest.id, signal);\n\t\t\t\t\t\tif (previous !== undefined) {\n\t\t\t\t\t\t\tconst rolledBack = await active.installer.rollback({\n\t\t\t\t\t\t\t\tfailed: installed.installation,\n\t\t\t\t\t\t\t\tprevious: {\n\t\t\t\t\t\t\t\t\tversion: 1,\n\t\t\t\t\t\t\t\t\tpluginId: previous.pluginId,\n\t\t\t\t\t\t\t\t\tpluginVersion: previous.pluginVersion,\n\t\t\t\t\t\t\t\t\tmanifestDigest: previous.manifestDigest,\n\t\t\t\t\t\t\t\t\tscope: previous.state.scope,\n\t\t\t\t\t\t\t\t\tscopeRef: previous.state.scopeRef,\n\t\t\t\t\t\t\t\t\tinstallationRef: previous.installationRef,\n\t\t\t\t\t\t\t\t\tstate: \"active\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tscope: \"global\",\n\t\t\t\t\t\t\t\tscopeRef: DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\t\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (rolledBack.status !== \"succeeded\") restoreFailure = rolledBack.error.code;\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\trestoreFailure = error instanceof Error ? error.message : String(error);\n\t\t\t\t\t}\n\t\t\t\t\tawait active.installer\n\t\t\t\t\t\t.remove({\n\t\t\t\t\t\t\tinstallation: installed.installation,\n\t\t\t\t\t\t\tscope: \"global\",\n\t\t\t\t\t\t\tscopeRef: DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.catch(() => undefined);\n\t\t\t\t\tconst activationMessage = t(\"plugin activation failed ({code}) for {pluginId}\", {\n\t\t\t\t\t\tcode: activated.error.code,\n\t\t\t\t\t\tpluginId: acquired.manifest.id,\n\t\t\t\t\t});\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\trestoreFailure === undefined\n\t\t\t\t\t\t\t? activationMessage\n\t\t\t\t\t\t\t: `${activationMessage}; previous version restore failed: ${restoreFailure}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst persisted = await active.stateStore.upsert({\n\t\t\t\t\tinstallation: activated.installation,\n\t\t\t\t\tscope: \"global\",\n\t\t\t\t\tenabled: true,\n\t\t\t\t\tsource: acquired.source,\n\t\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t\t});\n\t\t\t\tif (persisted.status !== \"ok\") {\n\t\t\t\t\tawait active.installer\n\t\t\t\t\t\t.remove({\n\t\t\t\t\t\t\tinstallation: activated.installation,\n\t\t\t\t\t\t\tscope: \"global\",\n\t\t\t\t\t\t\tscopeRef: DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.catch(() => undefined);\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tt(\"plugin state persist failed ({status}) for {pluginId}\", {\n\t\t\t\t\t\t\tstatus: persisted.status,\n\t\t\t\t\t\t\tpluginId: acquired.manifest.id,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// 出厂对齐语义(duplicate_active 修复,2026-10-08):stateStore 的 upsert\n\t\t\t\t// 按 scope:scopeRef:pluginId@version 去重,多版本并存是 store 的合法形态;\n\t\t\t\t// 但 bootstrap 把该插件在 global scope 对齐到工厂 range——升级成功后同插件\n\t\t\t\t// 其他版本的 active binding 必须退役,否则 active-bindings 解析遇\n\t\t\t\t// duplicate_active 拒选(真实升级 0.88.5→0.88.6 实证)。只退役 state 记录、\n\t\t\t\t// 不删安装目录;退役失败降级保留残留(等同修复前状态,下次启动重试)。\n\t\t\t\tconst allRecords = await active.stateStore.read({ ...(signal === undefined ? {} : { signal }) });\n\t\t\t\tif (allRecords.status === \"ok\") {\n\t\t\t\t\tfor (const record of allRecords.snapshot.records) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\trecord.pluginId === activated.installation.pluginId &&\n\t\t\t\t\t\t\trecord.pluginVersion !== activated.installation.pluginVersion &&\n\t\t\t\t\t\t\trecord.state.scope === \"global\" &&\n\t\t\t\t\t\t\trecord.state.scopeRef === DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1 &&\n\t\t\t\t\t\t\trecord.state.lifecycle === \"active\"\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tawait active.stateStore\n\t\t\t\t\t\t\t\t.remove({\n\t\t\t\t\t\t\t\t\tpluginId: record.pluginId,\n\t\t\t\t\t\t\t\t\tpluginVersion: record.pluginVersion,\n\t\t\t\t\t\t\t\t\tscope: \"global\",\n\t\t\t\t\t\t\t\t\tscopeRef: DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\t\t\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t.catch(() => undefined);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { pluginVersion: activated.installation.pluginVersion, source: acquired.source };\n\t\t\t} finally {\n\t\t\t\tawait release();\n\t\t\t}\n\t\t}\n\t};\n\ttry {\n\t\treturn await runPluginBootstrapV1({\n\t\t\tmanifest: options.manifest ?? BOOTSTRAP_FACTORY_PLUGIN_MANIFEST_V1,\n\t\t\tdeps,\n\t\t\t// First-run progress line (设计 §4.4, 2026-10-03): a fresh install is\n\t\t\t// otherwise silent for the whole network install window.\n\t\t\tonPendingInstalls:\n\t\t\t\toptions.onPendingInstalls ??\n\t\t\t\t((count: number) => {\n\t\t\t\t\tconsole.error(t(\"First run: installing {count} factory plugins…\", { count }));\n\t\t\t\t}),\n\t\t\t// Per-plugin progress (设计 §4.4 逐插件进度, 2026-10-04): one stderr\n\t\t\t// line per installed/aligned/failed entry; satisfied entries stay\n\t\t\t// silent so an all-green startup prints nothing extra.\n\t\t\tonAction:\n\t\t\t\toptions.onAction ??\n\t\t\t\t((action: PluginBootstrapActionV1) => {\n\t\t\t\t\tif (action.status === \"installed\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\tt(\"{pluginId}: installed {version}\", {\n\t\t\t\t\t\t\t\tpluginId: action.pluginId,\n\t\t\t\t\t\t\t\tversion: action.installedVersion ?? \"\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if (action.status === \"failed\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\tt(\n\t\t\t\t\t\t\t\t\"{pluginId}: install failed ({code}) — startup continues; the next startup retries automatically\",\n\t\t\t\t\t\t\t\t{ pluginId: action.pluginId, code: action.errorCode ?? \"install_failed\" },\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t});\n\t} finally {\n\t\tconst active = session;\n\t\tsession = undefined;\n\t\tif (active !== undefined) {\n\t\t\tawait active.installHost.close().catch(() => undefined);\n\t\t\tawait active.acquisition.close().catch(() => undefined);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"node-plugin-bootstrap.js","sourceRoot":"","sources":["../../../src/plugins/ecosystem/node-plugin-bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,CAAC,EAAE,MAAM,0BAA0B,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAE5E,OAAO,EAAE,oCAAoC,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,EACN,4BAA4B,EAC5B,wBAAwB,EACxB,oCAAoC,EACpC,uBAAuB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,kCAAkC,EAA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,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;gBAAA,CAC1E,CAAC;YACH,6EAA8D;YAC9D,kEAAkE;YAClE,uDAAuD;YACvD,QAAQ,EACP,OAAO,CAAC,QAAQ;gBAChB,CAAC,CAAC,MAA+B,EAAE,EAAE,CAAC;oBACrC,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;wBACnC,OAAO,CAAC,KAAK,CACZ,CAAC,CAAC,iCAAiC,EAAE;4BACpC,QAAQ,EAAE,MAAM,CAAC,QAAQ;4BACzB,OAAO,EAAE,MAAM,CAAC,gBAAgB,IAAI,EAAE;yBACtC,CAAC,CACF,CAAC;oBACH,CAAC;yBAAM,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;wBACvC,OAAO,CAAC,KAAK,CACZ,CAAC,CACA,mGAAiG,EACjG,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,SAAS,IAAI,gBAAgB,EAAE,CACzE,CACD,CAAC;oBACH,CAAC;gBAAA,CACD,CAAC;SACH,CAAC,CAAC;IACJ,CAAC;YAAS,CAAC;QACV,MAAM,MAAM,GAAG,OAAO,CAAC;QACvB,OAAO,GAAG,SAAS,CAAC;QACpB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YACxD,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACzD,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["/**\n * Node wiring for the startup plugin bootstrap (design\n * `插件独立分发与启动装配设计.md` §4.4, §0.7).\n *\n * `AGENT_FORGE_PLUGIN_BOOTSTRAP=off` skips everything, including the local\n * comparison. The comparison dependency reads the global and project\n * plugin-state.json stores only — read-only, and it never constructs an HTTP\n * client, so an assembled environment starts offline (G3). Network objects\n * (npm acquisition host, install host) are built lazily inside the install\n * action and closed when the bootstrap finishes. Installs go through the\n * npm acquisition path exclusively and persist the `npm:<host>` source label\n * in the global plugin state (same prepare/install/activate/upsert\n * transaction shape as the CLI install flow, implemented as a library\n * function without going through the CLI layer).\n */\n\nimport { join } from \"node:path\";\nimport { CONFIG_DIR_NAME } from \"../../config.ts\";\nimport { t } from \"../../core/i18n/index.ts\";\nimport { isOfflineModeEnabled } from \"../../core/package-process-runner.ts\";\nimport type { PluginBootstrapFactoryEntryV1 } from \"./bootstrap-factory-manifest.ts\";\nimport { BOOTSTRAP_FACTORY_PLUGIN_MANIFEST_V1 } from \"./bootstrap-factory-manifest.ts\";\nimport {\n\tDEFAULT_PLUGIN_STATE_FILE_V1,\n\tdefaultPluginHostFactsV1,\n\tdefaultPluginInstallStoreDirectoryV1,\n\tprojectPluginScopeRefV1,\n} from \"./default-active-bindings.ts\";\nimport { createPluginInstallerV1, DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1, type PluginInstallerV1 } from \"./installer.ts\";\nimport {\n\tcreateNodePackageInstallHostV1,\n\ttype NodePackageInstallHostV1,\n\ttype NodeZipPackageLimitsV1,\n} from \"./node-package-install-host.ts\";\nimport { createNodePluginAcquisitionHostV1, type NodePluginAcquisitionHostV1 } from \"./node-plugin-acquisition-host.ts\";\nimport {\n\ttype PluginBootstrapActionV1,\n\ttype PluginBootstrapDepsV1,\n\ttype PluginBootstrapResultV1,\n\trunPluginBootstrapV1,\n} from \"./plugin-bootstrap.ts\";\nimport { createPluginStateStoreV1, type PluginStateRecordV1, type PluginStateStoreV1 } from \"./state.ts\";\n\n/** Environment variable disabling the startup bootstrap entirely (`off`). */\nexport const AGENT_FORGE_PLUGIN_BOOTSTRAP_ENV_V1 = \"AGENT_FORGE_PLUGIN_BOOTSTRAP\";\n\n/** The only recognized disabling value; every other value (and absence) keeps bootstrap on. */\nconst PLUGIN_BOOTSTRAP_DISABLED_VALUE_V1 = \"off\";\n\nexport interface NodePluginBootstrapOptionsV1 {\n\treadonly agentDir: string;\n\treadonly cwd: string;\n\t/** Defaults to the frozen factory manifest. */\n\treadonly manifest?: readonly PluginBootstrapFactoryEntryV1[];\n\t/** Bare http(s) npm registry origin; forwarded to the acquisition host. */\n\treadonly npmRegistry?: string;\n\t/** npm registry bearer token; forwarded to the acquisition host. */\n\treadonly npmToken?: string;\n\treadonly limits?: NodeZipPackageLimitsV1;\n\t/** Deterministic fetch replacement for tests. */\n\treadonly fetch?: typeof globalThis.fetch;\n\treadonly signal?: AbortSignal;\n\t/** Full dependency override for deterministic tests; the env switch still applies. */\n\treadonly deps?: PluginBootstrapDepsV1;\n\t/** Overrides the first-run/upgrade progress line (stderr) for tests and hosts. */\n\treadonly onPendingInstalls?: (count: number) => void;\n\t/** Overrides the per-entry \"installing…\" start line (stderr) for tests and hosts. */\n\treadonly onInstallStart?: (entry: { readonly npmName: string; readonly pluginId: string }) => void;\n\t/**\n\t * Overrides the per-plugin progress renderer (stderr) for tests and hosts.\n\t * The default prints one line per installed/aligned/failed entry and stays\n\t * silent for satisfied entries.\n\t */\n\treadonly onAction?: (action: PluginBootstrapActionV1) => void;\n}\n\nexport type NodePluginBootstrapResultV1 = PluginBootstrapResultV1 & {\n\t/**\n\t * Present when a posture switch short-circuited the run before any local\n\t * comparison: the wiring-level env off switch, or the offline posture\n\t * (设计 §4.4 offline 姿态门, 2026-10-03 — offline installs cannot succeed\n\t * and would only fail slowly, so the run is skipped immediately).\n\t */\n\treadonly skipped?: \"disabled\" | \"offline\";\n};\n\n/** Install-scoped boundaries; created lazily by the first install action. */\ninterface InstallSessionV1 {\n\treadonly acquisition: NodePluginAcquisitionHostV1;\n\treadonly installHost: NodePackageInstallHostV1;\n\treadonly installer: PluginInstallerV1;\n\treadonly stateStore: PluginStateStoreV1;\n}\n\nfunction readActiveVersions(\n\tstore: PluginStateStoreV1,\n\tscope: \"global\" | \"project\",\n\tscopeRef: string,\n\tsignal: AbortSignal | undefined,\n): Promise<ReadonlyMap<string, string>> {\n\treturn (async () => {\n\t\tconst result = await store.read({ ...(signal === undefined ? {} : { signal }) });\n\t\tif (result.status !== \"ok\" && result.status !== \"missing\")\n\t\t\tthrow new Error(\n\t\t\t\tt(\"plugin state read failed ({detail}) for the {scope} scope\", {\n\t\t\t\t\tdetail: result.diagnostics[0]?.code ?? result.status,\n\t\t\t\t\tscope,\n\t\t\t\t}),\n\t\t\t);\n\t\tconst versions = new Map<string, string>();\n\t\tfor (const record of result.snapshot.records) {\n\t\t\tif (record.state.scope !== scope || record.state.scopeRef !== scopeRef) continue;\n\t\t\t// Enabled is deliberately not filtered: a disabled plugin still owns\n\t\t\t// its active installation record, and bootstrap never touches it (G5).\n\t\t\tif (record.state.lifecycle !== \"active\") continue;\n\t\t\tversions.set(record.pluginId, record.pluginVersion);\n\t\t}\n\t\treturn versions;\n\t})();\n}\n\n/**\n * Previous active installation record for one plugin id in the bootstrap's\n * global installation scope, or undefined when the plugin has no active\n * global installation. Mirrors the CLI update transaction's previous lookup\n * (cli.ts `findCurrentStateRecord`): same plugin id, same scope/scopeRef,\n * lifecycle active — bootstrap installs exclusively into this scope, so only\n * a record here can have had its runtime disposed by host.activate.\n */\nasync function readPreviousActiveRecord(\n\tstore: PluginStateStoreV1,\n\tpluginId: string,\n\tsignal: AbortSignal | undefined,\n): Promise<PluginStateRecordV1 | undefined> {\n\tconst result = await store.read({ ...(signal === undefined ? {} : { signal }) });\n\tif (result.status !== \"ok\" && result.status !== \"missing\")\n\t\tthrow new Error(\n\t\t\tt(\"plugin state read failed ({detail}) for the {scope} scope\", {\n\t\t\t\tdetail: result.diagnostics[0]?.code ?? result.status,\n\t\t\t\tscope: \"global\",\n\t\t\t}),\n\t\t);\n\treturn result.snapshot.records.find(\n\t\t(record) =>\n\t\t\trecord.pluginId === pluginId &&\n\t\t\trecord.state.scope === \"global\" &&\n\t\t\trecord.state.scopeRef === DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1 &&\n\t\t\trecord.state.lifecycle === \"active\",\n\t);\n}\n\n/**\n * Run the startup bootstrap for one agent directory. The function resolves\n * with a structured result and never throws for per-plugin failures; only a\n * wiring-level construction error propagates to the caller (main.ts guards\n * startup with its own catch).\n */\nexport async function runNodePluginBootstrapV1(\n\toptions: NodePluginBootstrapOptionsV1,\n): Promise<NodePluginBootstrapResultV1> {\n\tif (process.env[AGENT_FORGE_PLUGIN_BOOTSTRAP_ENV_V1]?.trim() === PLUGIN_BOOTSTRAP_DISABLED_VALUE_V1) {\n\t\treturn Object.freeze({\n\t\t\tversion: 1,\n\t\t\tstatus: \"succeeded\",\n\t\t\tactions: Object.freeze([]),\n\t\t\tdiagnostics: Object.freeze([]),\n\t\t\tdurationMs: 0,\n\t\t\tskipped: \"disabled\",\n\t\t});\n\t}\n\tif (isOfflineModeEnabled()) {\n\t\treturn Object.freeze({\n\t\t\tversion: 1,\n\t\t\tstatus: \"succeeded\",\n\t\t\tactions: Object.freeze([]),\n\t\t\tdiagnostics: Object.freeze([\n\t\t\t\t{\n\t\t\t\t\tcode: \"bootstrap_skipped_offline\",\n\t\t\t\t\tmessage: t(\n\t\t\t\t\t\t\"Offline posture (AGENT_FORGE_OFFLINE) skips the startup plugin bootstrap; run `agent-forge plugin install <package>` explicitly to install plugins.\",\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t] as const),\n\t\t\tdurationMs: 0,\n\t\t\tskipped: \"offline\",\n\t\t});\n\t}\n\tif (options.deps !== undefined) {\n\t\treturn await runPluginBootstrapV1({\n\t\t\tmanifest: options.manifest ?? BOOTSTRAP_FACTORY_PLUGIN_MANIFEST_V1,\n\t\t\tdeps: options.deps,\n\t\t\t...(options.onPendingInstalls === undefined ? {} : { onPendingInstalls: options.onPendingInstalls }),\n\t\t\t...(options.onAction === undefined ? {} : { onAction: options.onAction }),\n\t\t});\n\t}\n\tlet session: InstallSessionV1 | undefined;\n\tconst ensureSession = async (): Promise<InstallSessionV1> => {\n\t\tif (session !== undefined) return session;\n\t\tconst acquisition = createNodePluginAcquisitionHostV1({\n\t\t\t...(options.npmRegistry === undefined ? {} : { npmRegistry: options.npmRegistry }),\n\t\t\t...(options.npmToken === undefined ? {} : { npmToken: options.npmToken }),\n\t\t\t...(options.fetch === undefined ? {} : { fetch: options.fetch }),\n\t\t\t...(options.limits === undefined ? {} : { limits: options.limits }),\n\t\t});\n\t\tconst installHost = await createNodePackageInstallHostV1({\n\t\t\topenArtifact: (input) => acquisition.openArtifact(input),\n\t\t\tinstallationDirectory: defaultPluginInstallStoreDirectoryV1(options.agentDir),\n\t\t\tpersistence: \"persistent\",\n\t\t\tsupportedScopes: [\"global\", \"project\"],\n\t\t\t...(options.limits === undefined ? {} : { ...options.limits }),\n\t\t});\n\t\tsession = {\n\t\t\tacquisition,\n\t\t\tinstallHost,\n\t\t\tinstaller: createPluginInstallerV1({ host: installHost }),\n\t\t\tstateStore: createPluginStateStoreV1({ filePath: join(options.agentDir, DEFAULT_PLUGIN_STATE_FILE_V1) }),\n\t\t};\n\t\treturn session;\n\t};\n\tconst deps: PluginBootstrapDepsV1 = {\n\t\tlistActive: async ({ signal }) => {\n\t\t\tconst globalVersions = readActiveVersions(\n\t\t\t\tcreatePluginStateStoreV1({ filePath: join(options.agentDir, DEFAULT_PLUGIN_STATE_FILE_V1) }),\n\t\t\t\t\"global\",\n\t\t\t\tDEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\tsignal,\n\t\t\t);\n\t\t\tconst projectVersions = readActiveVersions(\n\t\t\t\tcreatePluginStateStoreV1({ filePath: join(options.cwd, CONFIG_DIR_NAME, DEFAULT_PLUGIN_STATE_FILE_V1) }),\n\t\t\t\t\"project\",\n\t\t\t\tprojectPluginScopeRefV1(options.cwd),\n\t\t\t\tsignal,\n\t\t\t);\n\t\t\tconst [globalResult, projectResult] = await Promise.all([globalVersions, projectVersions]);\n\t\t\t// Project precedence mirrors active-binding resolution: a project\n\t\t\t// installation shadows the same plugin id from the global scope.\n\t\t\treturn new Map([...globalResult, ...projectResult]);\n\t\t},\n\t\tinstallFromNpm: async ({ npmName, range, signal }) => {\n\t\t\t// Download retry (设计 §4.4 下载重试, 2026-10-04): transient registry\n\t\t\t// failures retried with backoff at this wiring layer so the decision\n\t\t\t// loop stays pure. Abort propagates immediately between attempts.\n\t\t\tlet lastError: unknown;\n\t\t\tfor (let attempt = 1; attempt <= 3; attempt++) {\n\t\t\t\tif (signal?.aborted === true) throw lastError ?? new Error(\"install aborted\");\n\t\t\t\ttry {\n\t\t\t\t\treturn await installFromNpmOnce({ npmName, range, signal });\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlastError = error;\n\t\t\t\t\t// Abort during the attempt surfaces as the attempt's own error;\n\t\t\t\t\t// the loop-top check and the backoff listener cover the pauses.\n\t\t\t\t\tif (attempt === 3) throw error;\n\t\t\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\t\t\tconst timer = setTimeout(resolve, 400 * 2 ** (attempt - 1));\n\t\t\t\t\t\tsignal?.addEventListener(\n\t\t\t\t\t\t\t\"abort\",\n\t\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\t\t\t\treject(lastError);\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ once: true },\n\t\t\t\t\t\t);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow lastError;\n\t\t},\n\t\t...(options.signal === undefined ? {} : { signal: options.signal }),\n\t};\n\tconst installFromNpmOnce = async (input: {\n\t\treadonly npmName: string;\n\t\treadonly range?: string;\n\t\treadonly signal?: AbortSignal;\n\t}): Promise<{ readonly pluginVersion: string; readonly source: string }> => {\n\t\tconst { npmName, range, signal } = input;\n\t\t{\n\t\t\tconst active = await ensureSession();\n\t\t\t// npm refs only (§0.7): scoped or plain names with the shared minimal\n\t\t\t// range subset; no github/gitee/url/local ref can be expressed here.\n\t\t\tconst ref = range === undefined ? npmName : `${npmName}@${range}`;\n\t\t\tconst acquired = await active.acquisition.resolvePackage({ ref, ...(signal === undefined ? {} : { signal }) });\n\t\t\tlet released = false;\n\t\t\tconst release = async (): Promise<void> => {\n\t\t\t\tif (released) return;\n\t\t\t\treleased = true;\n\t\t\t\tawait acquired.release();\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tconst verified = active.installer.prepare({\n\t\t\t\t\tmanifest: acquired.manifest,\n\t\t\t\t\tsource: acquired.source,\n\t\t\t\t\thost: defaultPluginHostFactsV1(),\n\t\t\t\t});\n\t\t\t\tif (verified.status !== \"verified\")\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tt(\"installer prepare rejected {pluginId}: {reason}\", {\n\t\t\t\t\t\t\tpluginId: acquired.manifest.id,\n\t\t\t\t\t\t\treason: verified.reason,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tconst installed = await active.installer.install({\n\t\t\t\t\trecord: verified.record,\n\t\t\t\t\tscope: \"global\",\n\t\t\t\t\tscopeRef: DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\t\tartifact: acquired.artifact,\n\t\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t\t});\n\t\t\t\tif (installed.status !== \"succeeded\")\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tt(\"plugin install failed ({code}) for {pluginId}\", {\n\t\t\t\t\t\t\tcode: installed.error.code,\n\t\t\t\t\t\t\tpluginId: acquired.manifest.id,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tconst activated = await active.installer.activate({\n\t\t\t\t\tinstallation: installed.installation,\n\t\t\t\t\trecord: verified.record,\n\t\t\t\t\tscope: \"global\",\n\t\t\t\t\tscopeRef: DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t\t});\n\t\t\t\tif (activated.status !== \"succeeded\") {\n\t\t\t\t\t// CLI update-transaction alignment (cli.ts activate-failure\n\t\t\t\t\t// path): host.activate disposed the previous runtime for this\n\t\t\t\t\t// installation key before the new candidate failed to commit,\n\t\t\t\t\t// so restore the previous active installation through the\n\t\t\t\t\t// installer rollback. Rollback runs before the failed\n\t\t\t\t\t// candidate is removed because host.rollback requires the\n\t\t\t\t\t// failed record to still exist.\n\t\t\t\t\tlet restoreFailure: string | undefined;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst previous = await readPreviousActiveRecord(active.stateStore, acquired.manifest.id, signal);\n\t\t\t\t\t\tif (previous !== undefined) {\n\t\t\t\t\t\t\tconst rolledBack = await active.installer.rollback({\n\t\t\t\t\t\t\t\tfailed: installed.installation,\n\t\t\t\t\t\t\t\tprevious: {\n\t\t\t\t\t\t\t\t\tversion: 1,\n\t\t\t\t\t\t\t\t\tpluginId: previous.pluginId,\n\t\t\t\t\t\t\t\t\tpluginVersion: previous.pluginVersion,\n\t\t\t\t\t\t\t\t\tmanifestDigest: previous.manifestDigest,\n\t\t\t\t\t\t\t\t\tscope: previous.state.scope,\n\t\t\t\t\t\t\t\t\tscopeRef: previous.state.scopeRef,\n\t\t\t\t\t\t\t\t\tinstallationRef: previous.installationRef,\n\t\t\t\t\t\t\t\t\tstate: \"active\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tscope: \"global\",\n\t\t\t\t\t\t\t\tscopeRef: DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\t\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (rolledBack.status !== \"succeeded\") restoreFailure = rolledBack.error.code;\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\trestoreFailure = error instanceof Error ? error.message : String(error);\n\t\t\t\t\t}\n\t\t\t\t\tawait active.installer\n\t\t\t\t\t\t.remove({\n\t\t\t\t\t\t\tinstallation: installed.installation,\n\t\t\t\t\t\t\tscope: \"global\",\n\t\t\t\t\t\t\tscopeRef: DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.catch(() => undefined);\n\t\t\t\t\tconst activationMessage = t(\"plugin activation failed ({code}) for {pluginId}\", {\n\t\t\t\t\t\tcode: activated.error.code,\n\t\t\t\t\t\tpluginId: acquired.manifest.id,\n\t\t\t\t\t});\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\trestoreFailure === undefined\n\t\t\t\t\t\t\t? activationMessage\n\t\t\t\t\t\t\t: `${activationMessage}; previous version restore failed: ${restoreFailure}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst persisted = await active.stateStore.upsert({\n\t\t\t\t\tinstallation: activated.installation,\n\t\t\t\t\tscope: \"global\",\n\t\t\t\t\tenabled: true,\n\t\t\t\t\tsource: acquired.source,\n\t\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t\t});\n\t\t\t\tif (persisted.status !== \"ok\") {\n\t\t\t\t\tawait active.installer\n\t\t\t\t\t\t.remove({\n\t\t\t\t\t\t\tinstallation: activated.installation,\n\t\t\t\t\t\t\tscope: \"global\",\n\t\t\t\t\t\t\tscopeRef: DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.catch(() => undefined);\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tt(\"plugin state persist failed ({status}) for {pluginId}\", {\n\t\t\t\t\t\t\tstatus: persisted.status,\n\t\t\t\t\t\t\tpluginId: acquired.manifest.id,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// 出厂对齐语义(duplicate_active 修复,2026-10-08):stateStore 的 upsert\n\t\t\t\t// 按 scope:scopeRef:pluginId@version 去重,多版本并存是 store 的合法形态;\n\t\t\t\t// 但 bootstrap 把该插件在 global scope 对齐到工厂 range——升级成功后同插件\n\t\t\t\t// 其他版本的 active binding 必须退役,否则 active-bindings 解析遇\n\t\t\t\t// duplicate_active 拒选(真实升级 0.88.5→0.88.6 实证)。只退役 state 记录、\n\t\t\t\t// 不删安装目录;退役失败降级保留残留(等同修复前状态,下次启动重试)。\n\t\t\t\tconst allRecords = await active.stateStore.read({ ...(signal === undefined ? {} : { signal }) });\n\t\t\t\tif (allRecords.status === \"ok\") {\n\t\t\t\t\tfor (const record of allRecords.snapshot.records) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\trecord.pluginId === activated.installation.pluginId &&\n\t\t\t\t\t\t\trecord.pluginVersion !== activated.installation.pluginVersion &&\n\t\t\t\t\t\t\trecord.state.scope === \"global\" &&\n\t\t\t\t\t\t\trecord.state.scopeRef === DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1 &&\n\t\t\t\t\t\t\trecord.state.lifecycle === \"active\"\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tawait active.stateStore\n\t\t\t\t\t\t\t\t.remove({\n\t\t\t\t\t\t\t\t\tpluginId: record.pluginId,\n\t\t\t\t\t\t\t\t\tpluginVersion: record.pluginVersion,\n\t\t\t\t\t\t\t\t\tscope: \"global\",\n\t\t\t\t\t\t\t\t\tscopeRef: DEFAULT_GLOBAL_PLUGIN_SCOPE_REF_V1,\n\t\t\t\t\t\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t.catch(() => undefined);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { pluginVersion: activated.installation.pluginVersion, source: acquired.source };\n\t\t\t} finally {\n\t\t\t\tawait release();\n\t\t\t}\n\t\t}\n\t};\n\ttry {\n\t\treturn await runPluginBootstrapV1({\n\t\t\tmanifest: options.manifest ?? BOOTSTRAP_FACTORY_PLUGIN_MANIFEST_V1,\n\t\t\tdeps,\n\t\t\t// First-run/upgrade progress line (设计 §4.4, 2026-10-03; 升级对齐也计数\n\t\t\t// 2026-10-08): the npm alignment window is otherwise silent — a\n\t\t\t// 0.88.7→0.88.8 upgrade replayed at 38s with zero feedback.\n\t\t\tonPendingInstalls:\n\t\t\t\toptions.onPendingInstalls ??\n\t\t\t\t((count: number) => {\n\t\t\t\t\tconsole.error(t(\"Aligning {count} factory plugin(s) from npm…\", { count }));\n\t\t\t\t}),\n\t\t\t// Per-entry start line (2026-10-08 走查): npm metadata + tarball take\n\t\t\t// seconds per plugin; the waiting user sees which plugin is being\n\t\t\t// fetched before its completion line lands.\n\t\t\tonInstallStart:\n\t\t\t\toptions.onInstallStart ??\n\t\t\t\t((entry) => {\n\t\t\t\t\tconsole.error(t(\"{pluginId}: installing…\", { pluginId: entry.pluginId }));\n\t\t\t\t}),\n\t\t\t// Per-plugin progress (设计 §4.4 逐插件进度, 2026-10-04): one stderr\n\t\t\t// line per installed/aligned/failed entry; satisfied entries stay\n\t\t\t// silent so an all-green startup prints nothing extra.\n\t\t\tonAction:\n\t\t\t\toptions.onAction ??\n\t\t\t\t((action: PluginBootstrapActionV1) => {\n\t\t\t\t\tif (action.status === \"installed\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\tt(\"{pluginId}: installed {version}\", {\n\t\t\t\t\t\t\t\tpluginId: action.pluginId,\n\t\t\t\t\t\t\t\tversion: action.installedVersion ?? \"\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if (action.status === \"failed\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\tt(\n\t\t\t\t\t\t\t\t\"{pluginId}: install failed ({code}) — startup continues; the next startup retries automatically\",\n\t\t\t\t\t\t\t\t{ pluginId: action.pluginId, code: action.errorCode ?? \"install_failed\" },\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t});\n\t} finally {\n\t\tconst active = session;\n\t\tsession = undefined;\n\t\tif (active !== undefined) {\n\t\t\tawait active.installHost.close().catch(() => undefined);\n\t\t\tawait active.acquisition.close().catch(() => undefined);\n\t\t}\n\t}\n}\n"]}
@@ -96,6 +96,16 @@ export declare function runPluginBootstrapV1(input: {
96
96
  * itself stays free of console I/O.
97
97
  */
98
98
  readonly onPendingInstalls?: (count: number) => void;
99
+ /**
100
+ * Fired when an install/align actually starts (2026-10-08 启动走查): npm
101
+ * metadata + tarball take seconds per plugin, so the waiting user needs a
102
+ * per-entry start line, not only the completion lines. Upgrade alignments
103
+ * fire this too.
104
+ */
105
+ readonly onInstallStart?: (entry: {
106
+ readonly npmName: string;
107
+ readonly pluginId: string;
108
+ }) => void;
99
109
  /**
100
110
  * Fired after every per-entry action (设计 §4.4 逐插件进度, 2026-10-04):
101
111
  * the host renders one line per install/align/failure so the waiting user
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-bootstrap.d.ts","sourceRoot":"","sources":["../../../src/plugins/ecosystem/plugin-bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAIrF,eAAO,MAAM,2BAA2B,GAAa,CAAC;AAEtD,gFAAgF;AAChF,MAAM,MAAM,2BAA2B,GAAG,CAAC,KAAK,EAAE;IACjD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B,KAAK,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE3C,qFAAqF;AACrF,MAAM,MAAM,+BAA+B,GAAG,CAAC,KAAK,EAAE;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B,KAAK,OAAO,CAAC;IAAE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;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AAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,MAAM,uBAAuB,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE7D,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,2BAA2B,CAAC;IACrD,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,SAAS,uBAAuB,EAAE,CAAC;IACrD,QAAQ,CAAC,WAAW,EAAE,SAAS,2BAA2B,EAAE,CAAC;IAC7D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAWD,uEAAuE;AACvE,wBAAgB,+BAA+B,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAEpH;AAwBD;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE;IACjD,QAAQ,CAAC,QAAQ,EAAE,SAAS,6BAA6B,EAAE,CAAC;IAC5D,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC;;;;;;OAMG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,uBAAuB,KAAK,IAAI,CAAC;CAC9D,GAAG,OAAO,CAAC,uBAAuB,CAAC,CA6FnC","sourcesContent":["/**\n * Startup plugin bootstrap orchestrator (design\n * `插件独立分发与启动装配设计.md` §4.4, §0.7). Pure injectable decision loop\n * over the frozen factory manifest: every entry is compared against the\n * locally resolved active installations; missing plugins and factory entries\n * whose active version no longer satisfies the factory range are handed to\n * the npm install dependency — bootstrap never acquires through any other\n * source.\n *\n * Coverage rules (G5, with the 2026-10-04 install-and-use exception): a\n * satisfied range is skipped silently (zero acquisition calls, G3); a factory\n * entry whose range is unsatisfied is automatically realigned by installing\n * the factory range — factory plugins are version-locked to the running\n * framework, so an unsatisfied range is a broken compatibility state, not a\n * user preference to protect. User-installed third-party plugins are not in\n * the factory manifest and stay untouched. Failure semantics (G4): one\n * plugin's install failure is recorded and the loop continues; the run itself\n * never throws, and a failed entry self-heals on the next startup because it\n * stays unsatisfied. All effects live behind the injected dependencies, so\n * the loop is fully deterministic under mocks.\n */\n\nimport type { PluginBootstrapFactoryEntryV1 } from \"./bootstrap-factory-manifest.ts\";\nimport { selectNpmPackageVersionV1 } from \"./node-npm-registry-source.ts\";\nimport { PluginAcquisitionErrorV1 } from \"./plugin-acquisition.ts\";\n\nexport const PLUGIN_BOOTSTRAP_VERSION_V1 = 1 as const;\n\n/** Read-only local lookup of active installation versions (never networked). */\nexport type PluginBootstrapListActiveV1 = (input: {\n\treadonly signal?: AbortSignal;\n}) => Promise<ReadonlyMap<string, string>>;\n\n/** npm-only install action; resolves with the installed version and source label. */\nexport type PluginBootstrapInstallFromNpmV1 = (input: {\n\treadonly npmName: string;\n\treadonly range?: string;\n\treadonly signal?: AbortSignal;\n}) => Promise<{ readonly pluginVersion: string; readonly source: string }>;\n\nexport interface PluginBootstrapDepsV1 {\n\treadonly listActive: PluginBootstrapListActiveV1;\n\treadonly installFromNpm: PluginBootstrapInstallFromNpmV1;\n\t/** Deterministic clock for the observed duration; defaults to Date.now. */\n\treadonly now?: () => number;\n\t/** Cooperative cancellation; checked before each manifest entry. */\n\treadonly signal?: AbortSignal;\n}\n\nexport type PluginBootstrapActionStatusV1 = \"skipped\" | \"installed\" | \"failed\";\n\nexport type PluginBootstrapActionReasonV1 =\n\t| \"satisfies_range\"\n\t| \"installed\"\n\t| \"range_aligned\"\n\t| \"install_failed\"\n\t| \"align_failed\";\n\n/** One per-entry outcome; the version fields carry what each status observed. */\nexport interface PluginBootstrapActionV1 {\n\treadonly pluginId: string;\n\treadonly status: PluginBootstrapActionStatusV1;\n\treadonly reason: PluginBootstrapActionReasonV1;\n\treadonly npmName: string;\n\treadonly range?: string;\n\t/** Active version that decided a skipped outcome. */\n\treadonly activeVersion?: string;\n\t/** Version reported by the install action. */\n\treadonly installedVersion?: string;\n\t/** npm source label reported by the install action. */\n\treadonly source?: string;\n\t/** Acquisition or install failure code for failed actions. */\n\treadonly errorCode?: string;\n}\n\nexport type PluginBootstrapDiagnosticCodeV1 =\n\t| \"install_failed\"\n\t| \"list_active_failed\"\n\t| \"cancelled\"\n\t| \"bootstrap_failed\"\n\t| \"bootstrap_skipped_offline\";\n\nexport interface PluginBootstrapDiagnosticV1 {\n\treadonly code: PluginBootstrapDiagnosticCodeV1;\n\treadonly message: string;\n\treadonly pluginId?: string;\n}\n\nexport type PluginBootstrapStatusV1 = \"succeeded\" | \"failed\";\n\nexport interface PluginBootstrapResultV1 {\n\treadonly version: typeof PLUGIN_BOOTSTRAP_VERSION_V1;\n\t/** Aggregated outcome: failed (any failed entry) > succeeded. */\n\treadonly status: PluginBootstrapStatusV1;\n\treadonly actions: readonly PluginBootstrapActionV1[];\n\treadonly diagnostics: readonly PluginBootstrapDiagnosticV1[];\n\treadonly durationMs: number;\n}\n\n/**\n * A version satisfies a factory range under the same selection semantics npm\n * resolution uses: it is the version that would be picked if it were the only\n * candidate. Keeps local comparison and registry resolution consistent.\n */\nfunction satisfiesRangeV1(version: string, range: string | undefined): boolean {\n\treturn selectNpmPackageVersionV1([version], range) === version;\n}\n\n/** Executable repair command for diagnostics (G4 remediation hint). */\nexport function pluginBootstrapInstallCommandV1(entry: { readonly npmName: string; readonly range?: string }): string {\n\treturn `agent-forge plugin install ${entry.npmName}@${entry.range ?? \"latest\"}`;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction acquireErrorCode(error: unknown): string {\n\treturn error instanceof PluginAcquisitionErrorV1 ? error.code : \"install_failed\";\n}\n\nfunction actionOf(\n\tentry: PluginBootstrapFactoryEntryV1,\n\tstatus: PluginBootstrapActionStatusV1,\n\treason: PluginBootstrapActionReasonV1,\n): PluginBootstrapActionV1 {\n\treturn Object.freeze({\n\t\tpluginId: entry.pluginId,\n\t\tstatus,\n\t\treason,\n\t\tnpmName: entry.npmName,\n\t\t...(entry.range === undefined ? {} : { range: entry.range }),\n\t});\n}\n\n/**\n * Run the bootstrap decision loop. An empty manifest short-circuits before\n * any dependency is touched, so the factory-empty S1-c2 state performs zero\n * reads on real startups.\n */\nexport async function runPluginBootstrapV1(input: {\n\treadonly manifest: readonly PluginBootstrapFactoryEntryV1[];\n\treadonly deps: PluginBootstrapDepsV1;\n\t/**\n\t * Fired once after the local active-state read when at least one factory\n\t * entry has no active installation — the host's first-run progress line\n\t * hook (设计 §4.4 首装进度行, 2026-10-03): a fresh install is otherwise\n\t * silent for the whole network install window. Injected effect, the loop\n\t * itself stays free of console I/O.\n\t */\n\treadonly onPendingInstalls?: (count: number) => void;\n\t/**\n\t * Fired after every per-entry action (设计 §4.4 逐插件进度, 2026-10-04):\n\t * the host renders one line per install/align/failure so the waiting user\n\t * sees live state; skipped entries stay silent at the host's discretion.\n\t * Injected effect, the loop itself stays free of console I/O.\n\t */\n\treadonly onAction?: (action: PluginBootstrapActionV1) => void;\n}): Promise<PluginBootstrapResultV1> {\n\tconst now = input.deps.now ?? Date.now;\n\tconst startedAt = now();\n\tconst finish = (\n\t\tstatus: PluginBootstrapStatusV1,\n\t\tactions: readonly PluginBootstrapActionV1[],\n\t\tdiagnostics: readonly PluginBootstrapDiagnosticV1[],\n\t): PluginBootstrapResultV1 =>\n\t\tObject.freeze({\n\t\t\tversion: PLUGIN_BOOTSTRAP_VERSION_V1,\n\t\t\tstatus,\n\t\t\tactions: Object.freeze([...actions]),\n\t\t\tdiagnostics: Object.freeze([...diagnostics]),\n\t\t\tdurationMs: Math.max(0, now() - startedAt),\n\t\t});\n\tif (input.manifest.length === 0) return finish(\"succeeded\", [], []);\n\tconst signal = input.deps.signal;\n\tlet active: ReadonlyMap<string, string>;\n\ttry {\n\t\tactive = await input.deps.listActive({ ...(signal === undefined ? {} : { signal }) });\n\t} catch (error) {\n\t\treturn finish(\n\t\t\t\"failed\",\n\t\t\t[],\n\t\t\t[\n\t\t\t\t{\n\t\t\t\t\tcode: \"list_active_failed\",\n\t\t\t\t\tmessage: `Active plugin state could not be read; bootstrap installed nothing: ${errorMessage(error)}`,\n\t\t\t\t},\n\t\t\t],\n\t\t);\n\t}\n\tconst actions: PluginBootstrapActionV1[] = [];\n\tconst diagnostics: PluginBootstrapDiagnosticV1[] = [];\n\tconst record = (action: PluginBootstrapActionV1): void => {\n\t\tactions.push(action);\n\t\tinput.onAction?.(action);\n\t};\n\tif (input.onPendingInstalls !== undefined) {\n\t\tconst pending = input.manifest.filter((entry) => !active.has(entry.pluginId)).length;\n\t\tif (pending > 0) input.onPendingInstalls(pending);\n\t}\n\tfor (const entry of input.manifest) {\n\t\tif (signal?.aborted === true) {\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: \"cancelled\",\n\t\t\t\tmessage: \"Plugin bootstrap was cancelled before all factory entries were processed\",\n\t\t\t});\n\t\t\tbreak;\n\t\t}\n\t\tconst activeVersion = active.get(entry.pluginId);\n\t\tif (activeVersion !== undefined && satisfiesRangeV1(activeVersion, entry.range)) {\n\t\t\trecord(Object.freeze({ ...actionOf(entry, \"skipped\", \"satisfies_range\"), activeVersion }));\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst installed = await input.deps.installFromNpm({\n\t\t\t\tnpmName: entry.npmName,\n\t\t\t\t...(entry.range === undefined ? {} : { range: entry.range }),\n\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t});\n\t\t\trecord(\n\t\t\t\tObject.freeze({\n\t\t\t\t\t...actionOf(entry, \"installed\", activeVersion === undefined ? \"installed\" : \"range_aligned\"),\n\t\t\t\t\tinstalledVersion: installed.pluginVersion,\n\t\t\t\t\tsource: installed.source,\n\t\t\t\t}),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconst errorCode = acquireErrorCode(error);\n\t\t\tconst aligning = activeVersion !== undefined;\n\t\t\trecord(\n\t\t\t\tObject.freeze({ ...actionOf(entry, \"failed\", aligning ? \"align_failed\" : \"install_failed\"), errorCode }),\n\t\t\t);\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: \"install_failed\",\n\t\t\t\tpluginId: entry.pluginId,\n\t\t\t\tmessage: aligning\n\t\t\t\t\t? `Bootstrap could not align ${entry.pluginId} (active ${activeVersion}) to the factory range ` +\n\t\t\t\t\t\t`${entry.range ?? \"latest\"} from npm (${errorCode}: ${errorMessage(error)}). ` +\n\t\t\t\t\t\t`Startup continues; the factory range stays unsatisfied, so the next startup retries automatically. ` +\n\t\t\t\t\t\t`Run \\`${pluginBootstrapInstallCommandV1(entry)}\\` to align it now.`\n\t\t\t\t\t: `Bootstrap could not install ${entry.pluginId} from npm (${errorCode}: ${errorMessage(error)}). ` +\n\t\t\t\t\t\t`Startup continues without it; its capabilities stay unavailable until installed, ` +\n\t\t\t\t\t\t`and the next startup retries automatically. ` +\n\t\t\t\t\t\t`Run \\`${pluginBootstrapInstallCommandV1(entry)}\\` to install it manually.`,\n\t\t\t});\n\t\t}\n\t}\n\tconst status: PluginBootstrapStatusV1 = actions.some((action) => action.status === \"failed\")\n\t\t? \"failed\"\n\t\t: \"succeeded\";\n\treturn finish(status, actions, diagnostics);\n}\n"]}
1
+ {"version":3,"file":"plugin-bootstrap.d.ts","sourceRoot":"","sources":["../../../src/plugins/ecosystem/plugin-bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAIrF,eAAO,MAAM,2BAA2B,GAAa,CAAC;AAEtD,gFAAgF;AAChF,MAAM,MAAM,2BAA2B,GAAG,CAAC,KAAK,EAAE;IACjD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B,KAAK,OAA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,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACnG;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,uBAAuB,KAAK,IAAI,CAAC;CAC9D,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAgJnC","sourcesContent":["/**\n * Startup plugin bootstrap orchestrator (design\n * `插件独立分发与启动装配设计.md` §4.4, §0.7). Pure injectable decision loop\n * over the frozen factory manifest: every entry is compared against the\n * locally resolved active installations; missing plugins and factory entries\n * whose active version no longer satisfies the factory range are handed to\n * the npm install dependency — bootstrap never acquires through any other\n * source.\n *\n * Coverage rules (G5, with the 2026-10-04 install-and-use exception): a\n * satisfied range is skipped silently (zero acquisition calls, G3); a factory\n * entry whose range is unsatisfied is automatically realigned by installing\n * the factory range — factory plugins are version-locked to the running\n * framework, so an unsatisfied range is a broken compatibility state, not a\n * user preference to protect. User-installed third-party plugins are not in\n * the factory manifest and stay untouched. Failure semantics (G4): one\n * plugin's install failure is recorded and the loop continues; the run itself\n * never throws, and a failed entry self-heals on the next startup because it\n * stays unsatisfied. All effects live behind the injected dependencies, so\n * the loop is fully deterministic under mocks.\n */\n\nimport type { PluginBootstrapFactoryEntryV1 } from \"./bootstrap-factory-manifest.ts\";\nimport { selectNpmPackageVersionV1 } from \"./node-npm-registry-source.ts\";\nimport { PluginAcquisitionErrorV1 } from \"./plugin-acquisition.ts\";\n\nexport const PLUGIN_BOOTSTRAP_VERSION_V1 = 1 as const;\n\n/** Read-only local lookup of active installation versions (never networked). */\nexport type PluginBootstrapListActiveV1 = (input: {\n\treadonly signal?: AbortSignal;\n}) => Promise<ReadonlyMap<string, string>>;\n\n/** npm-only install action; resolves with the installed version and source label. */\nexport type PluginBootstrapInstallFromNpmV1 = (input: {\n\treadonly npmName: string;\n\treadonly range?: string;\n\treadonly signal?: AbortSignal;\n}) => Promise<{ readonly pluginVersion: string; readonly source: string }>;\n\nexport interface PluginBootstrapDepsV1 {\n\treadonly listActive: PluginBootstrapListActiveV1;\n\treadonly installFromNpm: PluginBootstrapInstallFromNpmV1;\n\t/** Deterministic clock for the observed duration; defaults to Date.now. */\n\treadonly now?: () => number;\n\t/** Cooperative cancellation; checked before each manifest entry. */\n\treadonly signal?: AbortSignal;\n}\n\nexport type PluginBootstrapActionStatusV1 = \"skipped\" | \"installed\" | \"failed\";\n\nexport type PluginBootstrapActionReasonV1 =\n\t| \"satisfies_range\"\n\t| \"installed\"\n\t| \"range_aligned\"\n\t| \"install_failed\"\n\t| \"align_failed\";\n\n/** One per-entry outcome; the version fields carry what each status observed. */\nexport interface PluginBootstrapActionV1 {\n\treadonly pluginId: string;\n\treadonly status: PluginBootstrapActionStatusV1;\n\treadonly reason: PluginBootstrapActionReasonV1;\n\treadonly npmName: string;\n\treadonly range?: string;\n\t/** Active version that decided a skipped outcome. */\n\treadonly activeVersion?: string;\n\t/** Version reported by the install action. */\n\treadonly installedVersion?: string;\n\t/** npm source label reported by the install action. */\n\treadonly source?: string;\n\t/** Acquisition or install failure code for failed actions. */\n\treadonly errorCode?: string;\n}\n\nexport type PluginBootstrapDiagnosticCodeV1 =\n\t| \"install_failed\"\n\t| \"list_active_failed\"\n\t| \"cancelled\"\n\t| \"bootstrap_failed\"\n\t| \"bootstrap_skipped_offline\";\n\nexport interface PluginBootstrapDiagnosticV1 {\n\treadonly code: PluginBootstrapDiagnosticCodeV1;\n\treadonly message: string;\n\treadonly pluginId?: string;\n}\n\nexport type PluginBootstrapStatusV1 = \"succeeded\" | \"failed\";\n\nexport interface PluginBootstrapResultV1 {\n\treadonly version: typeof PLUGIN_BOOTSTRAP_VERSION_V1;\n\t/** Aggregated outcome: failed (any failed entry) > succeeded. */\n\treadonly status: PluginBootstrapStatusV1;\n\treadonly actions: readonly PluginBootstrapActionV1[];\n\treadonly diagnostics: readonly PluginBootstrapDiagnosticV1[];\n\treadonly durationMs: number;\n}\n\n/**\n * A version satisfies a factory range under the same selection semantics npm\n * resolution uses: it is the version that would be picked if it were the only\n * candidate. Keeps local comparison and registry resolution consistent.\n */\nfunction satisfiesRangeV1(version: string, range: string | undefined): boolean {\n\treturn selectNpmPackageVersionV1([version], range) === version;\n}\n\n/** Executable repair command for diagnostics (G4 remediation hint). */\nexport function pluginBootstrapInstallCommandV1(entry: { readonly npmName: string; readonly range?: string }): string {\n\treturn `agent-forge plugin install ${entry.npmName}@${entry.range ?? \"latest\"}`;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction acquireErrorCode(error: unknown): string {\n\treturn error instanceof PluginAcquisitionErrorV1 ? error.code : \"install_failed\";\n}\n\nfunction actionOf(\n\tentry: PluginBootstrapFactoryEntryV1,\n\tstatus: PluginBootstrapActionStatusV1,\n\treason: PluginBootstrapActionReasonV1,\n): PluginBootstrapActionV1 {\n\treturn Object.freeze({\n\t\tpluginId: entry.pluginId,\n\t\tstatus,\n\t\treason,\n\t\tnpmName: entry.npmName,\n\t\t...(entry.range === undefined ? {} : { range: entry.range }),\n\t});\n}\n\n/**\n * Run the bootstrap decision loop. An empty manifest short-circuits before\n * any dependency is touched, so the factory-empty S1-c2 state performs zero\n * reads on real startups.\n */\nexport async function runPluginBootstrapV1(input: {\n\treadonly manifest: readonly PluginBootstrapFactoryEntryV1[];\n\treadonly deps: PluginBootstrapDepsV1;\n\t/**\n\t * Fired once after the local active-state read when at least one factory\n\t * entry has no active installation — the host's first-run progress line\n\t * hook (设计 §4.4 首装进度行, 2026-10-03): a fresh install is otherwise\n\t * silent for the whole network install window. Injected effect, the loop\n\t * itself stays free of console I/O.\n\t */\n\treadonly onPendingInstalls?: (count: number) => void;\n\t/**\n\t * Fired when an install/align actually starts (2026-10-08 启动走查): npm\n\t * metadata + tarball take seconds per plugin, so the waiting user needs a\n\t * per-entry start line, not only the completion lines. Upgrade alignments\n\t * fire this too.\n\t */\n\treadonly onInstallStart?: (entry: { readonly npmName: string; readonly pluginId: string }) => void;\n\t/**\n\t * Fired after every per-entry action (设计 §4.4 逐插件进度, 2026-10-04):\n\t * the host renders one line per install/align/failure so the waiting user\n\t * sees live state; skipped entries stay silent at the host's discretion.\n\t * Injected effect, the loop itself stays free of console I/O.\n\t */\n\treadonly onAction?: (action: PluginBootstrapActionV1) => void;\n}): Promise<PluginBootstrapResultV1> {\n\tconst now = input.deps.now ?? Date.now;\n\tconst startedAt = now();\n\tconst finish = (\n\t\tstatus: PluginBootstrapStatusV1,\n\t\tactions: readonly PluginBootstrapActionV1[],\n\t\tdiagnostics: readonly PluginBootstrapDiagnosticV1[],\n\t): PluginBootstrapResultV1 =>\n\t\tObject.freeze({\n\t\t\tversion: PLUGIN_BOOTSTRAP_VERSION_V1,\n\t\t\tstatus,\n\t\t\tactions: Object.freeze([...actions]),\n\t\t\tdiagnostics: Object.freeze([...diagnostics]),\n\t\t\tdurationMs: Math.max(0, now() - startedAt),\n\t\t});\n\tif (input.manifest.length === 0) return finish(\"succeeded\", [], []);\n\tconst signal = input.deps.signal;\n\tlet active: ReadonlyMap<string, string>;\n\ttry {\n\t\tactive = await input.deps.listActive({ ...(signal === undefined ? {} : { signal }) });\n\t} catch (error) {\n\t\treturn finish(\n\t\t\t\"failed\",\n\t\t\t[],\n\t\t\t[\n\t\t\t\t{\n\t\t\t\t\tcode: \"list_active_failed\",\n\t\t\t\t\tmessage: `Active plugin state could not be read; bootstrap installed nothing: ${errorMessage(error)}`,\n\t\t\t\t},\n\t\t\t],\n\t\t);\n\t}\n\tconst actions: PluginBootstrapActionV1[] = [];\n\tconst diagnostics: PluginBootstrapDiagnosticV1[] = [];\n\t// Per-entry results slot by manifest index: parallel workers complete out of\n\t// order, but actions/diagnostics and their callbacks keep a stable order —\n\t// onAction stays live (fires the moment an entry settles) while the arrays\n\t// the result carries always read in manifest order.\n\tconst slots: Array<{ actions: PluginBootstrapActionV1[]; diagnostics: PluginBootstrapDiagnosticV1[] }> =\n\t\tinput.manifest.map(() => ({ actions: [], diagnostics: [] }));\n\tconst record = (index: number, action: PluginBootstrapActionV1): void => {\n\t\tslots[index]!.actions.push(action);\n\t\tinput.onAction?.(action);\n\t};\n\tconst addDiagnostic = (index: number, diagnostic: PluginBootstrapDiagnosticV1): void => {\n\t\tslots[index]!.diagnostics.push(diagnostic);\n\t};\n\tif (input.onPendingInstalls !== undefined) {\n\t\t// Upgrades count too (2026-10-08 启动走查): an active version outside the\n\t\t// factory range goes through the same npm install window as a missing\n\t\t// one — counting only missing entries left upgrade startups silent for\n\t\t// the whole alignment (real replay: 9 plugins, 38s, zero feedback).\n\t\tconst pending = input.manifest.filter((entry) => {\n\t\t\tconst activeVersion = active.get(entry.pluginId);\n\t\t\treturn activeVersion === undefined || !satisfiesRangeV1(activeVersion, entry.range);\n\t\t}).length;\n\t\tif (pending > 0) input.onPendingInstalls(pending);\n\t}\n\tconst processEntry = async (index: number, entry: PluginBootstrapFactoryEntryV1): Promise<void> => {\n\t\tconst signal = input.deps.signal;\n\t\tconst activeVersion = active.get(entry.pluginId);\n\t\tif (activeVersion !== undefined && satisfiesRangeV1(activeVersion, entry.range)) {\n\t\t\trecord(index, Object.freeze({ ...actionOf(entry, \"skipped\", \"satisfies_range\"), activeVersion }));\n\t\t\treturn;\n\t\t}\n\t\tinput.onInstallStart?.({ npmName: entry.npmName, pluginId: entry.pluginId });\n\t\ttry {\n\t\t\tconst installed = await input.deps.installFromNpm({\n\t\t\t\tnpmName: entry.npmName,\n\t\t\t\t...(entry.range === undefined ? {} : { range: entry.range }),\n\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t});\n\t\t\trecord(\n\t\t\t\tindex,\n\t\t\t\tObject.freeze({\n\t\t\t\t\t...actionOf(entry, \"installed\", activeVersion === undefined ? \"installed\" : \"range_aligned\"),\n\t\t\t\t\tinstalledVersion: installed.pluginVersion,\n\t\t\t\t\tsource: installed.source,\n\t\t\t\t}),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconst errorCode = acquireErrorCode(error);\n\t\t\tconst aligning = activeVersion !== undefined;\n\t\t\trecord(\n\t\t\t\tindex,\n\t\t\t\tObject.freeze({ ...actionOf(entry, \"failed\", aligning ? \"align_failed\" : \"install_failed\"), errorCode }),\n\t\t\t);\n\t\t\taddDiagnostic(\n\t\t\t\tindex,\n\t\t\t\taligning\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tcode: \"install_failed\",\n\t\t\t\t\t\t\tpluginId: entry.pluginId,\n\t\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t\t`Bootstrap could not align ${entry.pluginId} (active ${activeVersion}) to the factory range ` +\n\t\t\t\t\t\t\t\t`${entry.range ?? \"latest\"} from npm (${errorCode}: ${errorMessage(error)}). ` +\n\t\t\t\t\t\t\t\t`Startup continues; the factory range stays unsatisfied, so the next startup retries automatically. ` +\n\t\t\t\t\t\t\t\t`Run \\`${pluginBootstrapInstallCommandV1(entry)}\\` to align it now.`,\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tcode: \"install_failed\",\n\t\t\t\t\t\t\tpluginId: entry.pluginId,\n\t\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t\t`Bootstrap could not install ${entry.pluginId} from npm (${errorCode}: ${errorMessage(error)}). ` +\n\t\t\t\t\t\t\t\t`Startup continues without it; its capabilities stay unavailable until installed, ` +\n\t\t\t\t\t\t\t\t`and the next startup retries automatically. ` +\n\t\t\t\t\t\t\t\t`Run \\`${pluginBootstrapInstallCommandV1(entry)}\\` to install it manually.`,\n\t\t\t\t\t\t},\n\t\t\t);\n\t\t}\n\t};\n\t// Bounded parallelism (2026-10-08 启动走查): serial npm alignment held a\n\t// 0.88.7→0.88.8 upgrade startup hostage for ~38s (9 plugins × metadata +\n\t// tarball, each silent). Four workers cut the wall time to roughly the\n\t// slowest four installs while the npm acquisition host and the per-plugin\n\t// activation chains stay per-key serialized underneath.\n\tconst WORKERS = 4;\n\tlet cursor = 0;\n\tlet cancelNoted = false;\n\tconst worker = async (): Promise<void> => {\n\t\twhile (cursor < input.manifest.length) {\n\t\t\tif (input.deps.signal?.aborted === true) {\n\t\t\t\tif (!cancelNoted) {\n\t\t\t\t\tcancelNoted = true;\n\t\t\t\t\tdiagnostics.push({\n\t\t\t\t\t\tcode: \"cancelled\",\n\t\t\t\t\t\tmessage: \"Plugin bootstrap was cancelled before all factory entries were processed\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst index = cursor++;\n\t\t\tawait processEntry(index, input.manifest[index]!);\n\t\t}\n\t};\n\tawait Promise.all(Array.from({ length: Math.min(WORKERS, input.manifest.length) }, worker));\n\tfor (const slot of slots) {\n\t\tactions.push(...slot.actions);\n\t\tdiagnostics.push(...slot.diagnostics);\n\t}\n\tconst status: PluginBootstrapStatusV1 = actions.some((action) => action.status === \"failed\")\n\t\t? \"failed\"\n\t\t: \"succeeded\";\n\treturn finish(status, actions, diagnostics);\n}\n"]}
@@ -81,35 +81,45 @@ export async function runPluginBootstrapV1(input) {
81
81
  }
82
82
  const actions = [];
83
83
  const diagnostics = [];
84
- const record = (action) => {
85
- actions.push(action);
84
+ // Per-entry results slot by manifest index: parallel workers complete out of
85
+ // order, but actions/diagnostics and their callbacks keep a stable order —
86
+ // onAction stays live (fires the moment an entry settles) while the arrays
87
+ // the result carries always read in manifest order.
88
+ const slots = input.manifest.map(() => ({ actions: [], diagnostics: [] }));
89
+ const record = (index, action) => {
90
+ slots[index].actions.push(action);
86
91
  input.onAction?.(action);
87
92
  };
93
+ const addDiagnostic = (index, diagnostic) => {
94
+ slots[index].diagnostics.push(diagnostic);
95
+ };
88
96
  if (input.onPendingInstalls !== undefined) {
89
- const pending = input.manifest.filter((entry) => !active.has(entry.pluginId)).length;
97
+ // Upgrades count too (2026-10-08 启动走查): an active version outside the
98
+ // factory range goes through the same npm install window as a missing
99
+ // one — counting only missing entries left upgrade startups silent for
100
+ // the whole alignment (real replay: 9 plugins, 38s, zero feedback).
101
+ const pending = input.manifest.filter((entry) => {
102
+ const activeVersion = active.get(entry.pluginId);
103
+ return activeVersion === undefined || !satisfiesRangeV1(activeVersion, entry.range);
104
+ }).length;
90
105
  if (pending > 0)
91
106
  input.onPendingInstalls(pending);
92
107
  }
93
- for (const entry of input.manifest) {
94
- if (signal?.aborted === true) {
95
- diagnostics.push({
96
- code: "cancelled",
97
- message: "Plugin bootstrap was cancelled before all factory entries were processed",
98
- });
99
- break;
100
- }
108
+ const processEntry = async (index, entry) => {
109
+ const signal = input.deps.signal;
101
110
  const activeVersion = active.get(entry.pluginId);
102
111
  if (activeVersion !== undefined && satisfiesRangeV1(activeVersion, entry.range)) {
103
- record(Object.freeze({ ...actionOf(entry, "skipped", "satisfies_range"), activeVersion }));
104
- continue;
112
+ record(index, Object.freeze({ ...actionOf(entry, "skipped", "satisfies_range"), activeVersion }));
113
+ return;
105
114
  }
115
+ input.onInstallStart?.({ npmName: entry.npmName, pluginId: entry.pluginId });
106
116
  try {
107
117
  const installed = await input.deps.installFromNpm({
108
118
  npmName: entry.npmName,
109
119
  ...(entry.range === undefined ? {} : { range: entry.range }),
110
120
  ...(signal === undefined ? {} : { signal }),
111
121
  });
112
- record(Object.freeze({
122
+ record(index, Object.freeze({
113
123
  ...actionOf(entry, "installed", activeVersion === undefined ? "installed" : "range_aligned"),
114
124
  installedVersion: installed.pluginVersion,
115
125
  source: installed.source,
@@ -118,21 +128,54 @@ export async function runPluginBootstrapV1(input) {
118
128
  catch (error) {
119
129
  const errorCode = acquireErrorCode(error);
120
130
  const aligning = activeVersion !== undefined;
121
- record(Object.freeze({ ...actionOf(entry, "failed", aligning ? "align_failed" : "install_failed"), errorCode }));
122
- diagnostics.push({
123
- code: "install_failed",
124
- pluginId: entry.pluginId,
125
- message: aligning
126
- ? `Bootstrap could not align ${entry.pluginId} (active ${activeVersion}) to the factory range ` +
131
+ record(index, Object.freeze({ ...actionOf(entry, "failed", aligning ? "align_failed" : "install_failed"), errorCode }));
132
+ addDiagnostic(index, aligning
133
+ ? {
134
+ code: "install_failed",
135
+ pluginId: entry.pluginId,
136
+ message: `Bootstrap could not align ${entry.pluginId} (active ${activeVersion}) to the factory range ` +
127
137
  `${entry.range ?? "latest"} from npm (${errorCode}: ${errorMessage(error)}). ` +
128
138
  `Startup continues; the factory range stays unsatisfied, so the next startup retries automatically. ` +
129
- `Run \`${pluginBootstrapInstallCommandV1(entry)}\` to align it now.`
130
- : `Bootstrap could not install ${entry.pluginId} from npm (${errorCode}: ${errorMessage(error)}). ` +
139
+ `Run \`${pluginBootstrapInstallCommandV1(entry)}\` to align it now.`,
140
+ }
141
+ : {
142
+ code: "install_failed",
143
+ pluginId: entry.pluginId,
144
+ message: `Bootstrap could not install ${entry.pluginId} from npm (${errorCode}: ${errorMessage(error)}). ` +
131
145
  `Startup continues without it; its capabilities stay unavailable until installed, ` +
132
146
  `and the next startup retries automatically. ` +
133
147
  `Run \`${pluginBootstrapInstallCommandV1(entry)}\` to install it manually.`,
134
- });
148
+ });
135
149
  }
150
+ };
151
+ // Bounded parallelism (2026-10-08 启动走查): serial npm alignment held a
152
+ // 0.88.7→0.88.8 upgrade startup hostage for ~38s (9 plugins × metadata +
153
+ // tarball, each silent). Four workers cut the wall time to roughly the
154
+ // slowest four installs while the npm acquisition host and the per-plugin
155
+ // activation chains stay per-key serialized underneath.
156
+ const WORKERS = 4;
157
+ let cursor = 0;
158
+ let cancelNoted = false;
159
+ const worker = async () => {
160
+ while (cursor < input.manifest.length) {
161
+ if (input.deps.signal?.aborted === true) {
162
+ if (!cancelNoted) {
163
+ cancelNoted = true;
164
+ diagnostics.push({
165
+ code: "cancelled",
166
+ message: "Plugin bootstrap was cancelled before all factory entries were processed",
167
+ });
168
+ }
169
+ return;
170
+ }
171
+ const index = cursor++;
172
+ await processEntry(index, input.manifest[index]);
173
+ }
174
+ };
175
+ await Promise.all(Array.from({ length: Math.min(WORKERS, input.manifest.length) }, worker));
176
+ for (const slot of slots) {
177
+ actions.push(...slot.actions);
178
+ diagnostics.push(...slot.diagnostics);
136
179
  }
137
180
  const status = actions.some((action) => action.status === "failed")
138
181
  ? "failed"
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-bootstrap.js","sourceRoot":"","sources":["../../../src/plugins/ecosystem/plugin-bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAU,CAAC;AAyEtD;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,OAAe,EAAE,KAAyB,EAAW;IAC9E,OAAO,yBAAyB,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,KAAK,OAAO,CAAC;AAAA,CAC/D;AAED,uEAAuE;AACvE,MAAM,UAAU,+BAA+B,CAAC,KAA4D,EAAU;IACrH,OAAO,8BAA8B,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,KAAK,IAAI,QAAQ,EAAE,CAAC;AAAA,CAChF;AAED,SAAS,YAAY,CAAC,KAAc,EAAU;IAC7C,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAAA,CAC9D;AAED,SAAS,gBAAgB,CAAC,KAAc,EAAU;IACjD,OAAO,KAAK,YAAY,wBAAwB,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC;AAAA,CACjF;AAED,SAAS,QAAQ,CAChB,KAAoC,EACpC,MAAqC,EACrC,MAAqC,EACX;IAC1B,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QAC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;oBAChB,CAAC,CAAC,6BAA6B,KAAK,CAAC,QAAQ,YAAY,aAAa,yBAAyB;wBAC9F,GAAG,KAAK,CAAC,KAAK,IAAI,QAAQ,cAAc,SAAS,KAAK,YAAY,CAAC,KAAK,CAAC,KAAK;wBAC9E,qGAAqG;wBACrG,SAAS,+BAA+B,CAAC,KAAK,CAAC,qBAAqB;oBACrE,CAAC,CAAC,+BAA+B,KAAK,CAAC,QAAQ,cAAc,SAAS,KAAK,YAAY,CAAC,KAAK,CAAC,KAAK;wBAClG,mFAAmF;wBACnF,8CAA8C;wBAC9C,SAAS,+BAA+B,CAAC,KAAK,CAAC,4BAA4B;aAC7E,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IACD,MAAM,MAAM,GAA4B,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC;QAC3F,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,WAAW,CAAC;IACf,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AAAA,CAC5C","sourcesContent":["/**\n * Startup plugin bootstrap orchestrator (design\n * `插件独立分发与启动装配设计.md` §4.4, §0.7). Pure injectable decision loop\n * over the frozen factory manifest: every entry is compared against the\n * locally resolved active installations; missing plugins and factory entries\n * whose active version no longer satisfies the factory range are handed to\n * the npm install dependency — bootstrap never acquires through any other\n * source.\n *\n * Coverage rules (G5, with the 2026-10-04 install-and-use exception): a\n * satisfied range is skipped silently (zero acquisition calls, G3); a factory\n * entry whose range is unsatisfied is automatically realigned by installing\n * the factory range — factory plugins are version-locked to the running\n * framework, so an unsatisfied range is a broken compatibility state, not a\n * user preference to protect. User-installed third-party plugins are not in\n * the factory manifest and stay untouched. Failure semantics (G4): one\n * plugin's install failure is recorded and the loop continues; the run itself\n * never throws, and a failed entry self-heals on the next startup because it\n * stays unsatisfied. All effects live behind the injected dependencies, so\n * the loop is fully deterministic under mocks.\n */\n\nimport type { PluginBootstrapFactoryEntryV1 } from \"./bootstrap-factory-manifest.ts\";\nimport { selectNpmPackageVersionV1 } from \"./node-npm-registry-source.ts\";\nimport { PluginAcquisitionErrorV1 } from \"./plugin-acquisition.ts\";\n\nexport const PLUGIN_BOOTSTRAP_VERSION_V1 = 1 as const;\n\n/** Read-only local lookup of active installation versions (never networked). */\nexport type PluginBootstrapListActiveV1 = (input: {\n\treadonly signal?: AbortSignal;\n}) => Promise<ReadonlyMap<string, string>>;\n\n/** npm-only install action; resolves with the installed version and source label. */\nexport type PluginBootstrapInstallFromNpmV1 = (input: {\n\treadonly npmName: string;\n\treadonly range?: string;\n\treadonly signal?: AbortSignal;\n}) => Promise<{ readonly pluginVersion: string; readonly source: string }>;\n\nexport interface PluginBootstrapDepsV1 {\n\treadonly listActive: PluginBootstrapListActiveV1;\n\treadonly installFromNpm: PluginBootstrapInstallFromNpmV1;\n\t/** Deterministic clock for the observed duration; defaults to Date.now. */\n\treadonly now?: () => number;\n\t/** Cooperative cancellation; checked before each manifest entry. */\n\treadonly signal?: AbortSignal;\n}\n\nexport type PluginBootstrapActionStatusV1 = \"skipped\" | \"installed\" | \"failed\";\n\nexport type PluginBootstrapActionReasonV1 =\n\t| \"satisfies_range\"\n\t| \"installed\"\n\t| \"range_aligned\"\n\t| \"install_failed\"\n\t| \"align_failed\";\n\n/** One per-entry outcome; the version fields carry what each status observed. */\nexport interface PluginBootstrapActionV1 {\n\treadonly pluginId: string;\n\treadonly status: PluginBootstrapActionStatusV1;\n\treadonly reason: PluginBootstrapActionReasonV1;\n\treadonly npmName: string;\n\treadonly range?: string;\n\t/** Active version that decided a skipped outcome. */\n\treadonly activeVersion?: string;\n\t/** Version reported by the install action. */\n\treadonly installedVersion?: string;\n\t/** npm source label reported by the install action. */\n\treadonly source?: string;\n\t/** Acquisition or install failure code for failed actions. */\n\treadonly errorCode?: string;\n}\n\nexport type PluginBootstrapDiagnosticCodeV1 =\n\t| \"install_failed\"\n\t| \"list_active_failed\"\n\t| \"cancelled\"\n\t| \"bootstrap_failed\"\n\t| \"bootstrap_skipped_offline\";\n\nexport interface PluginBootstrapDiagnosticV1 {\n\treadonly code: PluginBootstrapDiagnosticCodeV1;\n\treadonly message: string;\n\treadonly pluginId?: string;\n}\n\nexport type PluginBootstrapStatusV1 = \"succeeded\" | \"failed\";\n\nexport interface PluginBootstrapResultV1 {\n\treadonly version: typeof PLUGIN_BOOTSTRAP_VERSION_V1;\n\t/** Aggregated outcome: failed (any failed entry) > succeeded. */\n\treadonly status: PluginBootstrapStatusV1;\n\treadonly actions: readonly PluginBootstrapActionV1[];\n\treadonly diagnostics: readonly PluginBootstrapDiagnosticV1[];\n\treadonly durationMs: number;\n}\n\n/**\n * A version satisfies a factory range under the same selection semantics npm\n * resolution uses: it is the version that would be picked if it were the only\n * candidate. Keeps local comparison and registry resolution consistent.\n */\nfunction satisfiesRangeV1(version: string, range: string | undefined): boolean {\n\treturn selectNpmPackageVersionV1([version], range) === version;\n}\n\n/** Executable repair command for diagnostics (G4 remediation hint). */\nexport function pluginBootstrapInstallCommandV1(entry: { readonly npmName: string; readonly range?: string }): string {\n\treturn `agent-forge plugin install ${entry.npmName}@${entry.range ?? \"latest\"}`;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction acquireErrorCode(error: unknown): string {\n\treturn error instanceof PluginAcquisitionErrorV1 ? error.code : \"install_failed\";\n}\n\nfunction actionOf(\n\tentry: PluginBootstrapFactoryEntryV1,\n\tstatus: PluginBootstrapActionStatusV1,\n\treason: PluginBootstrapActionReasonV1,\n): PluginBootstrapActionV1 {\n\treturn Object.freeze({\n\t\tpluginId: entry.pluginId,\n\t\tstatus,\n\t\treason,\n\t\tnpmName: entry.npmName,\n\t\t...(entry.range === undefined ? {} : { range: entry.range }),\n\t});\n}\n\n/**\n * Run the bootstrap decision loop. An empty manifest short-circuits before\n * any dependency is touched, so the factory-empty S1-c2 state performs zero\n * reads on real startups.\n */\nexport async function runPluginBootstrapV1(input: {\n\treadonly manifest: readonly PluginBootstrapFactoryEntryV1[];\n\treadonly deps: PluginBootstrapDepsV1;\n\t/**\n\t * Fired once after the local active-state read when at least one factory\n\t * entry has no active installation — the host's first-run progress line\n\t * hook (设计 §4.4 首装进度行, 2026-10-03): a fresh install is otherwise\n\t * silent for the whole network install window. Injected effect, the loop\n\t * itself stays free of console I/O.\n\t */\n\treadonly onPendingInstalls?: (count: number) => void;\n\t/**\n\t * Fired after every per-entry action (设计 §4.4 逐插件进度, 2026-10-04):\n\t * the host renders one line per install/align/failure so the waiting user\n\t * sees live state; skipped entries stay silent at the host's discretion.\n\t * Injected effect, the loop itself stays free of console I/O.\n\t */\n\treadonly onAction?: (action: PluginBootstrapActionV1) => void;\n}): Promise<PluginBootstrapResultV1> {\n\tconst now = input.deps.now ?? Date.now;\n\tconst startedAt = now();\n\tconst finish = (\n\t\tstatus: PluginBootstrapStatusV1,\n\t\tactions: readonly PluginBootstrapActionV1[],\n\t\tdiagnostics: readonly PluginBootstrapDiagnosticV1[],\n\t): PluginBootstrapResultV1 =>\n\t\tObject.freeze({\n\t\t\tversion: PLUGIN_BOOTSTRAP_VERSION_V1,\n\t\t\tstatus,\n\t\t\tactions: Object.freeze([...actions]),\n\t\t\tdiagnostics: Object.freeze([...diagnostics]),\n\t\t\tdurationMs: Math.max(0, now() - startedAt),\n\t\t});\n\tif (input.manifest.length === 0) return finish(\"succeeded\", [], []);\n\tconst signal = input.deps.signal;\n\tlet active: ReadonlyMap<string, string>;\n\ttry {\n\t\tactive = await input.deps.listActive({ ...(signal === undefined ? {} : { signal }) });\n\t} catch (error) {\n\t\treturn finish(\n\t\t\t\"failed\",\n\t\t\t[],\n\t\t\t[\n\t\t\t\t{\n\t\t\t\t\tcode: \"list_active_failed\",\n\t\t\t\t\tmessage: `Active plugin state could not be read; bootstrap installed nothing: ${errorMessage(error)}`,\n\t\t\t\t},\n\t\t\t],\n\t\t);\n\t}\n\tconst actions: PluginBootstrapActionV1[] = [];\n\tconst diagnostics: PluginBootstrapDiagnosticV1[] = [];\n\tconst record = (action: PluginBootstrapActionV1): void => {\n\t\tactions.push(action);\n\t\tinput.onAction?.(action);\n\t};\n\tif (input.onPendingInstalls !== undefined) {\n\t\tconst pending = input.manifest.filter((entry) => !active.has(entry.pluginId)).length;\n\t\tif (pending > 0) input.onPendingInstalls(pending);\n\t}\n\tfor (const entry of input.manifest) {\n\t\tif (signal?.aborted === true) {\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: \"cancelled\",\n\t\t\t\tmessage: \"Plugin bootstrap was cancelled before all factory entries were processed\",\n\t\t\t});\n\t\t\tbreak;\n\t\t}\n\t\tconst activeVersion = active.get(entry.pluginId);\n\t\tif (activeVersion !== undefined && satisfiesRangeV1(activeVersion, entry.range)) {\n\t\t\trecord(Object.freeze({ ...actionOf(entry, \"skipped\", \"satisfies_range\"), activeVersion }));\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst installed = await input.deps.installFromNpm({\n\t\t\t\tnpmName: entry.npmName,\n\t\t\t\t...(entry.range === undefined ? {} : { range: entry.range }),\n\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t});\n\t\t\trecord(\n\t\t\t\tObject.freeze({\n\t\t\t\t\t...actionOf(entry, \"installed\", activeVersion === undefined ? \"installed\" : \"range_aligned\"),\n\t\t\t\t\tinstalledVersion: installed.pluginVersion,\n\t\t\t\t\tsource: installed.source,\n\t\t\t\t}),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconst errorCode = acquireErrorCode(error);\n\t\t\tconst aligning = activeVersion !== undefined;\n\t\t\trecord(\n\t\t\t\tObject.freeze({ ...actionOf(entry, \"failed\", aligning ? \"align_failed\" : \"install_failed\"), errorCode }),\n\t\t\t);\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: \"install_failed\",\n\t\t\t\tpluginId: entry.pluginId,\n\t\t\t\tmessage: aligning\n\t\t\t\t\t? `Bootstrap could not align ${entry.pluginId} (active ${activeVersion}) to the factory range ` +\n\t\t\t\t\t\t`${entry.range ?? \"latest\"} from npm (${errorCode}: ${errorMessage(error)}). ` +\n\t\t\t\t\t\t`Startup continues; the factory range stays unsatisfied, so the next startup retries automatically. ` +\n\t\t\t\t\t\t`Run \\`${pluginBootstrapInstallCommandV1(entry)}\\` to align it now.`\n\t\t\t\t\t: `Bootstrap could not install ${entry.pluginId} from npm (${errorCode}: ${errorMessage(error)}). ` +\n\t\t\t\t\t\t`Startup continues without it; its capabilities stay unavailable until installed, ` +\n\t\t\t\t\t\t`and the next startup retries automatically. ` +\n\t\t\t\t\t\t`Run \\`${pluginBootstrapInstallCommandV1(entry)}\\` to install it manually.`,\n\t\t\t});\n\t\t}\n\t}\n\tconst status: PluginBootstrapStatusV1 = actions.some((action) => action.status === \"failed\")\n\t\t? \"failed\"\n\t\t: \"succeeded\";\n\treturn finish(status, actions, diagnostics);\n}\n"]}
1
+ {"version":3,"file":"plugin-bootstrap.js","sourceRoot":"","sources":["../../../src/plugins/ecosystem/plugin-bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAU,CAAC;AAyEtD;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,OAAe,EAAE,KAAyB,EAAW;IAC9E,OAAO,yBAAyB,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,KAAK,OAAO,CAAC;AAAA,CAC/D;AAED,uEAAuE;AACvE,MAAM,UAAU,+BAA+B,CAAC,KAA4D,EAAU;IACrH,OAAO,8BAA8B,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,KAAK,IAAI,QAAQ,EAAE,CAAC;AAAA,CAChF;AAED,SAAS,YAAY,CAAC,KAAc,EAAU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,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5F,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9B,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;IACD,MAAM,MAAM,GAA4B,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC;QAC3F,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,WAAW,CAAC;IACf,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AAAA,CAC5C","sourcesContent":["/**\n * Startup plugin bootstrap orchestrator (design\n * `插件独立分发与启动装配设计.md` §4.4, §0.7). Pure injectable decision loop\n * over the frozen factory manifest: every entry is compared against the\n * locally resolved active installations; missing plugins and factory entries\n * whose active version no longer satisfies the factory range are handed to\n * the npm install dependency — bootstrap never acquires through any other\n * source.\n *\n * Coverage rules (G5, with the 2026-10-04 install-and-use exception): a\n * satisfied range is skipped silently (zero acquisition calls, G3); a factory\n * entry whose range is unsatisfied is automatically realigned by installing\n * the factory range — factory plugins are version-locked to the running\n * framework, so an unsatisfied range is a broken compatibility state, not a\n * user preference to protect. User-installed third-party plugins are not in\n * the factory manifest and stay untouched. Failure semantics (G4): one\n * plugin's install failure is recorded and the loop continues; the run itself\n * never throws, and a failed entry self-heals on the next startup because it\n * stays unsatisfied. All effects live behind the injected dependencies, so\n * the loop is fully deterministic under mocks.\n */\n\nimport type { PluginBootstrapFactoryEntryV1 } from \"./bootstrap-factory-manifest.ts\";\nimport { selectNpmPackageVersionV1 } from \"./node-npm-registry-source.ts\";\nimport { PluginAcquisitionErrorV1 } from \"./plugin-acquisition.ts\";\n\nexport const PLUGIN_BOOTSTRAP_VERSION_V1 = 1 as const;\n\n/** Read-only local lookup of active installation versions (never networked). */\nexport type PluginBootstrapListActiveV1 = (input: {\n\treadonly signal?: AbortSignal;\n}) => Promise<ReadonlyMap<string, string>>;\n\n/** npm-only install action; resolves with the installed version and source label. */\nexport type PluginBootstrapInstallFromNpmV1 = (input: {\n\treadonly npmName: string;\n\treadonly range?: string;\n\treadonly signal?: AbortSignal;\n}) => Promise<{ readonly pluginVersion: string; readonly source: string }>;\n\nexport interface PluginBootstrapDepsV1 {\n\treadonly listActive: PluginBootstrapListActiveV1;\n\treadonly installFromNpm: PluginBootstrapInstallFromNpmV1;\n\t/** Deterministic clock for the observed duration; defaults to Date.now. */\n\treadonly now?: () => number;\n\t/** Cooperative cancellation; checked before each manifest entry. */\n\treadonly signal?: AbortSignal;\n}\n\nexport type PluginBootstrapActionStatusV1 = \"skipped\" | \"installed\" | \"failed\";\n\nexport type PluginBootstrapActionReasonV1 =\n\t| \"satisfies_range\"\n\t| \"installed\"\n\t| \"range_aligned\"\n\t| \"install_failed\"\n\t| \"align_failed\";\n\n/** One per-entry outcome; the version fields carry what each status observed. */\nexport interface PluginBootstrapActionV1 {\n\treadonly pluginId: string;\n\treadonly status: PluginBootstrapActionStatusV1;\n\treadonly reason: PluginBootstrapActionReasonV1;\n\treadonly npmName: string;\n\treadonly range?: string;\n\t/** Active version that decided a skipped outcome. */\n\treadonly activeVersion?: string;\n\t/** Version reported by the install action. */\n\treadonly installedVersion?: string;\n\t/** npm source label reported by the install action. */\n\treadonly source?: string;\n\t/** Acquisition or install failure code for failed actions. */\n\treadonly errorCode?: string;\n}\n\nexport type PluginBootstrapDiagnosticCodeV1 =\n\t| \"install_failed\"\n\t| \"list_active_failed\"\n\t| \"cancelled\"\n\t| \"bootstrap_failed\"\n\t| \"bootstrap_skipped_offline\";\n\nexport interface PluginBootstrapDiagnosticV1 {\n\treadonly code: PluginBootstrapDiagnosticCodeV1;\n\treadonly message: string;\n\treadonly pluginId?: string;\n}\n\nexport type PluginBootstrapStatusV1 = \"succeeded\" | \"failed\";\n\nexport interface PluginBootstrapResultV1 {\n\treadonly version: typeof PLUGIN_BOOTSTRAP_VERSION_V1;\n\t/** Aggregated outcome: failed (any failed entry) > succeeded. */\n\treadonly status: PluginBootstrapStatusV1;\n\treadonly actions: readonly PluginBootstrapActionV1[];\n\treadonly diagnostics: readonly PluginBootstrapDiagnosticV1[];\n\treadonly durationMs: number;\n}\n\n/**\n * A version satisfies a factory range under the same selection semantics npm\n * resolution uses: it is the version that would be picked if it were the only\n * candidate. Keeps local comparison and registry resolution consistent.\n */\nfunction satisfiesRangeV1(version: string, range: string | undefined): boolean {\n\treturn selectNpmPackageVersionV1([version], range) === version;\n}\n\n/** Executable repair command for diagnostics (G4 remediation hint). */\nexport function pluginBootstrapInstallCommandV1(entry: { readonly npmName: string; readonly range?: string }): string {\n\treturn `agent-forge plugin install ${entry.npmName}@${entry.range ?? \"latest\"}`;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction acquireErrorCode(error: unknown): string {\n\treturn error instanceof PluginAcquisitionErrorV1 ? error.code : \"install_failed\";\n}\n\nfunction actionOf(\n\tentry: PluginBootstrapFactoryEntryV1,\n\tstatus: PluginBootstrapActionStatusV1,\n\treason: PluginBootstrapActionReasonV1,\n): PluginBootstrapActionV1 {\n\treturn Object.freeze({\n\t\tpluginId: entry.pluginId,\n\t\tstatus,\n\t\treason,\n\t\tnpmName: entry.npmName,\n\t\t...(entry.range === undefined ? {} : { range: entry.range }),\n\t});\n}\n\n/**\n * Run the bootstrap decision loop. An empty manifest short-circuits before\n * any dependency is touched, so the factory-empty S1-c2 state performs zero\n * reads on real startups.\n */\nexport async function runPluginBootstrapV1(input: {\n\treadonly manifest: readonly PluginBootstrapFactoryEntryV1[];\n\treadonly deps: PluginBootstrapDepsV1;\n\t/**\n\t * Fired once after the local active-state read when at least one factory\n\t * entry has no active installation — the host's first-run progress line\n\t * hook (设计 §4.4 首装进度行, 2026-10-03): a fresh install is otherwise\n\t * silent for the whole network install window. Injected effect, the loop\n\t * itself stays free of console I/O.\n\t */\n\treadonly onPendingInstalls?: (count: number) => void;\n\t/**\n\t * Fired when an install/align actually starts (2026-10-08 启动走查): npm\n\t * metadata + tarball take seconds per plugin, so the waiting user needs a\n\t * per-entry start line, not only the completion lines. Upgrade alignments\n\t * fire this too.\n\t */\n\treadonly onInstallStart?: (entry: { readonly npmName: string; readonly pluginId: string }) => void;\n\t/**\n\t * Fired after every per-entry action (设计 §4.4 逐插件进度, 2026-10-04):\n\t * the host renders one line per install/align/failure so the waiting user\n\t * sees live state; skipped entries stay silent at the host's discretion.\n\t * Injected effect, the loop itself stays free of console I/O.\n\t */\n\treadonly onAction?: (action: PluginBootstrapActionV1) => void;\n}): Promise<PluginBootstrapResultV1> {\n\tconst now = input.deps.now ?? Date.now;\n\tconst startedAt = now();\n\tconst finish = (\n\t\tstatus: PluginBootstrapStatusV1,\n\t\tactions: readonly PluginBootstrapActionV1[],\n\t\tdiagnostics: readonly PluginBootstrapDiagnosticV1[],\n\t): PluginBootstrapResultV1 =>\n\t\tObject.freeze({\n\t\t\tversion: PLUGIN_BOOTSTRAP_VERSION_V1,\n\t\t\tstatus,\n\t\t\tactions: Object.freeze([...actions]),\n\t\t\tdiagnostics: Object.freeze([...diagnostics]),\n\t\t\tdurationMs: Math.max(0, now() - startedAt),\n\t\t});\n\tif (input.manifest.length === 0) return finish(\"succeeded\", [], []);\n\tconst signal = input.deps.signal;\n\tlet active: ReadonlyMap<string, string>;\n\ttry {\n\t\tactive = await input.deps.listActive({ ...(signal === undefined ? {} : { signal }) });\n\t} catch (error) {\n\t\treturn finish(\n\t\t\t\"failed\",\n\t\t\t[],\n\t\t\t[\n\t\t\t\t{\n\t\t\t\t\tcode: \"list_active_failed\",\n\t\t\t\t\tmessage: `Active plugin state could not be read; bootstrap installed nothing: ${errorMessage(error)}`,\n\t\t\t\t},\n\t\t\t],\n\t\t);\n\t}\n\tconst actions: PluginBootstrapActionV1[] = [];\n\tconst diagnostics: PluginBootstrapDiagnosticV1[] = [];\n\t// Per-entry results slot by manifest index: parallel workers complete out of\n\t// order, but actions/diagnostics and their callbacks keep a stable order —\n\t// onAction stays live (fires the moment an entry settles) while the arrays\n\t// the result carries always read in manifest order.\n\tconst slots: Array<{ actions: PluginBootstrapActionV1[]; diagnostics: PluginBootstrapDiagnosticV1[] }> =\n\t\tinput.manifest.map(() => ({ actions: [], diagnostics: [] }));\n\tconst record = (index: number, action: PluginBootstrapActionV1): void => {\n\t\tslots[index]!.actions.push(action);\n\t\tinput.onAction?.(action);\n\t};\n\tconst addDiagnostic = (index: number, diagnostic: PluginBootstrapDiagnosticV1): void => {\n\t\tslots[index]!.diagnostics.push(diagnostic);\n\t};\n\tif (input.onPendingInstalls !== undefined) {\n\t\t// Upgrades count too (2026-10-08 启动走查): an active version outside the\n\t\t// factory range goes through the same npm install window as a missing\n\t\t// one — counting only missing entries left upgrade startups silent for\n\t\t// the whole alignment (real replay: 9 plugins, 38s, zero feedback).\n\t\tconst pending = input.manifest.filter((entry) => {\n\t\t\tconst activeVersion = active.get(entry.pluginId);\n\t\t\treturn activeVersion === undefined || !satisfiesRangeV1(activeVersion, entry.range);\n\t\t}).length;\n\t\tif (pending > 0) input.onPendingInstalls(pending);\n\t}\n\tconst processEntry = async (index: number, entry: PluginBootstrapFactoryEntryV1): Promise<void> => {\n\t\tconst signal = input.deps.signal;\n\t\tconst activeVersion = active.get(entry.pluginId);\n\t\tif (activeVersion !== undefined && satisfiesRangeV1(activeVersion, entry.range)) {\n\t\t\trecord(index, Object.freeze({ ...actionOf(entry, \"skipped\", \"satisfies_range\"), activeVersion }));\n\t\t\treturn;\n\t\t}\n\t\tinput.onInstallStart?.({ npmName: entry.npmName, pluginId: entry.pluginId });\n\t\ttry {\n\t\t\tconst installed = await input.deps.installFromNpm({\n\t\t\t\tnpmName: entry.npmName,\n\t\t\t\t...(entry.range === undefined ? {} : { range: entry.range }),\n\t\t\t\t...(signal === undefined ? {} : { signal }),\n\t\t\t});\n\t\t\trecord(\n\t\t\t\tindex,\n\t\t\t\tObject.freeze({\n\t\t\t\t\t...actionOf(entry, \"installed\", activeVersion === undefined ? \"installed\" : \"range_aligned\"),\n\t\t\t\t\tinstalledVersion: installed.pluginVersion,\n\t\t\t\t\tsource: installed.source,\n\t\t\t\t}),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconst errorCode = acquireErrorCode(error);\n\t\t\tconst aligning = activeVersion !== undefined;\n\t\t\trecord(\n\t\t\t\tindex,\n\t\t\t\tObject.freeze({ ...actionOf(entry, \"failed\", aligning ? \"align_failed\" : \"install_failed\"), errorCode }),\n\t\t\t);\n\t\t\taddDiagnostic(\n\t\t\t\tindex,\n\t\t\t\taligning\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tcode: \"install_failed\",\n\t\t\t\t\t\t\tpluginId: entry.pluginId,\n\t\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t\t`Bootstrap could not align ${entry.pluginId} (active ${activeVersion}) to the factory range ` +\n\t\t\t\t\t\t\t\t`${entry.range ?? \"latest\"} from npm (${errorCode}: ${errorMessage(error)}). ` +\n\t\t\t\t\t\t\t\t`Startup continues; the factory range stays unsatisfied, so the next startup retries automatically. ` +\n\t\t\t\t\t\t\t\t`Run \\`${pluginBootstrapInstallCommandV1(entry)}\\` to align it now.`,\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tcode: \"install_failed\",\n\t\t\t\t\t\t\tpluginId: entry.pluginId,\n\t\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t\t`Bootstrap could not install ${entry.pluginId} from npm (${errorCode}: ${errorMessage(error)}). ` +\n\t\t\t\t\t\t\t\t`Startup continues without it; its capabilities stay unavailable until installed, ` +\n\t\t\t\t\t\t\t\t`and the next startup retries automatically. ` +\n\t\t\t\t\t\t\t\t`Run \\`${pluginBootstrapInstallCommandV1(entry)}\\` to install it manually.`,\n\t\t\t\t\t\t},\n\t\t\t);\n\t\t}\n\t};\n\t// Bounded parallelism (2026-10-08 启动走查): serial npm alignment held a\n\t// 0.88.7→0.88.8 upgrade startup hostage for ~38s (9 plugins × metadata +\n\t// tarball, each silent). Four workers cut the wall time to roughly the\n\t// slowest four installs while the npm acquisition host and the per-plugin\n\t// activation chains stay per-key serialized underneath.\n\tconst WORKERS = 4;\n\tlet cursor = 0;\n\tlet cancelNoted = false;\n\tconst worker = async (): Promise<void> => {\n\t\twhile (cursor < input.manifest.length) {\n\t\t\tif (input.deps.signal?.aborted === true) {\n\t\t\t\tif (!cancelNoted) {\n\t\t\t\t\tcancelNoted = true;\n\t\t\t\t\tdiagnostics.push({\n\t\t\t\t\t\tcode: \"cancelled\",\n\t\t\t\t\t\tmessage: \"Plugin bootstrap was cancelled before all factory entries were processed\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst index = cursor++;\n\t\t\tawait processEntry(index, input.manifest[index]!);\n\t\t}\n\t};\n\tawait Promise.all(Array.from({ length: Math.min(WORKERS, input.manifest.length) }, worker));\n\tfor (const slot of slots) {\n\t\tactions.push(...slot.actions);\n\t\tdiagnostics.push(...slot.diagnostics);\n\t}\n\tconst status: PluginBootstrapStatusV1 = actions.some((action) => action.status === \"failed\")\n\t\t? \"failed\"\n\t\t: \"succeeded\";\n\treturn finish(status, actions, diagnostics);\n}\n"]}
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "agent-forge-extension-with-deps",
3
- "version": "0.88.8",
3
+ "version": "0.88.9",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "agent-forge-extension-with-deps",
9
- "version": "0.88.8",
9
+ "version": "0.88.9",
10
10
  "dependencies": {
11
11
  "ms": "^2.1.3"
12
12
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agent-forge-extension-with-deps",
3
3
  "private": true,
4
- "version": "0.88.8",
4
+ "version": "0.88.9",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "agent-forge.example.with-deps",
3
- "version": "0.88.8",
3
+ "version": "0.88.9",
4
4
  "hostVersion": ">=0.84.0",
5
5
  "apiVersion": "1-draft",
6
6
  "entry": "./index.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-agent-forge/agent-forge",
3
- "version": "0.88.8",
3
+ "version": "0.88.9",
4
4
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "agentForgeConfig": {