aegisone 1.0.32 → 1.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/aegis.js +322 -1
- package/package.json +5 -4
- package/scripts/bump.mjs +211 -1
- package/scripts/bundle.js +129 -1
- package/scripts/predist.mjs +976 -1
- package/src/child.js +285 -1
- package/src/dispatch.js +269 -1
- package/src/doctor.js +639 -1
- package/src/host.js +111 -1
- package/src/permissions.js +383 -1
- package/src/probes.js +159 -1
- package/src/release.js +409 -1
- package/vendor/cli/package.json +7 -3
- package/vendor/cli/scripts/check.mjs +52 -1
- package/vendor/cli/scripts/demo.mjs +94 -1
- package/vendor/cli/scripts/predist.mjs +75 -1
- package/vendor/cli/scripts/runtests.mjs +56 -1
- package/vendor/cli/scripts/seal-gate.mjs +74 -1
- package/vendor/cli/src/agents.js +139 -1
- package/vendor/cli/src/app.js +2957 -1
- package/vendor/cli/src/art.js +289 -1
- package/vendor/cli/src/chatflow.js +3023 -1
- package/vendor/cli/src/checkpoint.js +90 -1
- package/vendor/cli/src/clipboard.js +424 -1
- package/vendor/cli/src/cloudsync.js +528 -1
- package/vendor/cli/src/commands.js +4089 -1
- package/vendor/cli/src/config.js +581 -1
- package/vendor/cli/src/connect.js +349 -1
- package/vendor/cli/src/credentials.js +33 -1
- package/vendor/cli/src/deps.js +232 -1
- package/vendor/cli/src/devrun.js +187 -1
- package/vendor/cli/src/diff.js +333 -1
- package/vendor/cli/src/diffview.js +296 -1
- package/vendor/cli/src/engine.js +297 -1
- package/vendor/cli/src/entitlement.js +355 -1
- package/vendor/cli/src/events.js +707 -1
- package/vendor/cli/src/export.js +67 -1
- package/vendor/cli/src/filepreview.js +153 -1
- package/vendor/cli/src/fingerprint.js +592 -1
- package/vendor/cli/src/format.js +259 -1
- package/vendor/cli/src/fuzzy.js +119 -1
- package/vendor/cli/src/history.js +423 -1
- package/vendor/cli/src/init.js +175 -1
- package/vendor/cli/src/input.js +139 -1
- package/vendor/cli/src/keys.js +183 -1
- package/vendor/cli/src/markdown.js +306 -1
- package/vendor/cli/src/models.js +507 -1
- package/vendor/cli/src/naming.js +57 -1
- package/vendor/cli/src/overlays.js +462 -1
- package/vendor/cli/src/panels.js +1418 -1
- package/vendor/cli/src/ping.js +226 -1
- package/vendor/cli/src/presence.js +238 -1
- package/vendor/cli/src/render.js +516 -1
- package/vendor/cli/src/screen.js +518 -1
- package/vendor/cli/src/screens.js +896 -1
- package/vendor/cli/src/secret.js +59 -1
- package/vendor/cli/src/securefs.js +359 -1
- package/vendor/cli/src/settings.js +155 -1
- package/vendor/cli/src/shared.js +52 -1
- package/vendor/cli/src/sharedpaths.js +53 -1
- package/vendor/cli/src/signup.js +156 -1
- package/vendor/cli/src/summarize.js +95 -1
- package/vendor/cli/src/sysdiag.js +585 -1
- package/vendor/cli/src/system.js +40 -1
- package/vendor/cli/src/theme.js +570 -1
- package/vendor/cli/src/title.js +220 -1
- package/vendor/cli/src/todos.js +115 -1
- package/vendor/cli/src/tokens.js +263 -1
- package/vendor/cli/src/topup.js +210 -1
- package/vendor/cli/src/update.js +191 -1
- package/vendor/cli/vendor/client/aegis.js +2441 -1
- package/vendor/cli/vendor/client/attest.js +518 -1
- package/vendor/cli/vendor/client/authorship-key.js +410 -1
- package/vendor/cli/vendor/client/auto-provision.js +134 -1
- package/vendor/cli/vendor/client/brain-catalog.js +268 -1
- package/vendor/cli/vendor/client/byok-catalog.js +199 -1
- package/vendor/cli/vendor/client/catalog-client.js +487 -1
- package/vendor/cli/vendor/client/conversation-export.js +177 -1
- package/vendor/cli/vendor/client/credentials.js +494 -1
- package/vendor/cli/vendor/client/device-fingerprint.js +141 -1
- package/vendor/cli/vendor/client/drive-connect.js +110 -1
- package/vendor/cli/vendor/client/drive-upload.js +234 -1
- package/vendor/cli/vendor/client/env-file.js +1273 -1
- package/vendor/cli/vendor/client/fingerprint.js +1064 -1
- package/vendor/cli/vendor/client/foreign-memory.js +669 -1
- package/vendor/cli/vendor/client/google-signin.js +133 -1
- package/vendor/cli/vendor/client/hooks.js +430 -1
- package/vendor/cli/vendor/client/model-discovery.js +373 -1
- package/vendor/cli/vendor/client/naming.js +283 -1
- package/vendor/cli/vendor/client/platform.js +937 -1
- package/vendor/cli/vendor/client/prefs.js +351 -1
- package/vendor/cli/vendor/client/presence-constants.js +107 -1
- package/vendor/cli/vendor/client/presence.js +438 -1
- package/vendor/cli/vendor/client/record-vault.js +1055 -3
- package/vendor/cli/vendor/client/session-store.js +575 -1
- package/vendor/cli/vendor/client/topup.js +297 -1
- package/vendor/cli/vendor/client/touch.js +458 -1
- package/vendor/cli/vendor/client/update.js +763 -1
- package/vendor/cli/vendor/client/user-models.js +381 -1
- package/vendor/cli/vendor/desktop/lib/local/agents.js +105 -1
- package/vendor/cli/vendor/desktop/lib/local/attachments.js +276 -1
- package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1045 -1
- package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1028 -1
- package/vendor/cli/vendor/desktop/lib/local/context.js +125 -1
- package/vendor/cli/vendor/desktop/lib/local/engine.js +3666 -1
- package/vendor/cli/vendor/desktop/lib/local/entitlement.js +660 -1
- package/vendor/cli/vendor/desktop/lib/local/git-scope.js +228 -1
- package/vendor/cli/vendor/desktop/lib/local/local.js +2145 -1
- package/vendor/cli/vendor/desktop/lib/local/prompt.js +280 -1
- package/vendor/cli/vendor/desktop/lib/local/queue.js +560 -1
- package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +238 -1
- package/vendor/cli/vendor/desktop/lib/local/spill.js +75 -1
- package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +300 -1
- package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +235 -1
- package/vendor/cli/vendor/desktop/lib/settings.js +890 -1
- package/vendor/cli/vendor/desktop/renderer/usage.js +1239 -1
- package/vendor/cli/vendor/hosts/install.js +638 -1
- package/vendor/cli/vendor/hosts/openai-shim.js +515 -1
- package/vendor/cli/vendor/hosts/spec.js +164 -1
- package/vendor/cli/vendor/hosts/targets.js +346 -1
- package/vendor/cli/vendor/mcp/server.js +221 -1
- package/vendor/cli/vendor/mcp/tools.js +408 -1
- package/vendor/cli/vendor/one/src/child.js +285 -1
- package/vendor/cli/vendor/one/src/permissions.js +383 -1
- package/vendor/desktop/bin/aegis.js +32 -1
- package/vendor/desktop/lib/account-key.js +56 -1
- package/vendor/desktop/lib/auto.js +461 -1
- package/vendor/desktop/lib/avatar/companion.js +698 -1
- package/vendor/desktop/lib/avatar/cosmetics.js +532 -1
- package/vendor/desktop/lib/avatar/events.js +344 -1
- package/vendor/desktop/lib/avatar/holder-turn.js +350 -1
- package/vendor/desktop/lib/avatar/holders.js +612 -1
- package/vendor/desktop/lib/avatar/identity.js +641 -1
- package/vendor/desktop/lib/avatar/level.js +368 -1
- package/vendor/desktop/lib/avatar/mirror.js +524 -1
- package/vendor/desktop/lib/avatar/persona.js +388 -1
- package/vendor/desktop/lib/avatar/profile.js +977 -1
- package/vendor/desktop/lib/avatar/register.js +307 -1
- package/vendor/desktop/lib/avatar/store.js +472 -1
- package/vendor/desktop/lib/avatar/tiers.js +38 -1
- package/vendor/desktop/lib/avatar/transfer.js +415 -1
- package/vendor/desktop/lib/avatar/turn.js +216 -1
- package/vendor/desktop/lib/avatar/voice.js +328 -1
- package/vendor/desktop/lib/avatar/xp.js +404 -1
- package/vendor/desktop/lib/deep-link.js +120 -1
- package/vendor/desktop/lib/fingerprint.js +347 -2
- package/vendor/desktop/lib/google-connect.js +323 -1
- package/vendor/desktop/lib/local/agents.js +105 -1
- package/vendor/desktop/lib/local/attachments.js +276 -1
- package/vendor/desktop/lib/local/autonomous.js +1045 -1
- package/vendor/desktop/lib/local/claude-pro.js +1028 -1
- package/vendor/desktop/lib/local/context.js +125 -1
- package/vendor/desktop/lib/local/engine.js +3666 -1
- package/vendor/desktop/lib/local/entitlement.js +660 -1
- package/vendor/desktop/lib/local/git-scope.js +228 -1
- package/vendor/desktop/lib/local/local.js +2145 -1
- package/vendor/desktop/lib/local/prompt.js +280 -1
- package/vendor/desktop/lib/local/queue.js +560 -1
- package/vendor/desktop/lib/local/session-rounds.js +238 -1
- package/vendor/desktop/lib/local/spill.js +75 -1
- package/vendor/desktop/lib/local/telemetry.js +470 -1
- package/vendor/desktop/lib/local/turn-guard.js +300 -1
- package/vendor/desktop/lib/local/worktree-lock.js +235 -1
- package/vendor/desktop/lib/provider-key-mirror.js +252 -1
- package/vendor/desktop/lib/quick-launcher.js +84 -1
- package/vendor/desktop/lib/settings.js +890 -1
- package/vendor/desktop/lib/sync/memory-queue.js +60 -1
- package/vendor/desktop/lib/sync/persist-gate.js +148 -1
- package/vendor/desktop/lib/sync/sessions.js +106 -1
- package/vendor/desktop/lib/window-state.js +66 -1
- package/vendor/desktop/package.json +5 -3
- package/vendor/desktop/preload.js +679 -1
- package/vendor/desktop/renderer/app.js +7250 -1
- package/vendor/desktop/renderer/avatar/assemble.js +335 -1
- package/vendor/desktop/renderer/avatar/avatar.js +380 -1
- package/vendor/desktop/renderer/avatar/cards.js +141 -1
- package/vendor/desktop/renderer/avatar/hud.js +206 -1
- package/vendor/desktop/renderer/avatar/machine.js +213 -1
- package/vendor/desktop/renderer/avatar/pane.js +439 -1
- package/vendor/desktop/renderer/avatar/parts.js +437 -1
- package/vendor/desktop/renderer/budget.js +172 -1
- package/vendor/desktop/renderer/companion.js +223 -1
- package/vendor/desktop/renderer/diff.js +359 -1
- package/vendor/desktop/renderer/diffview.js +336 -1
- package/vendor/desktop/renderer/filepreview.js +211 -1
- package/vendor/desktop/renderer/fingerprint.js +789 -3
- package/vendor/desktop/renderer/markdown.js +168 -1
- package/vendor/desktop/renderer/provider-mark.js +311 -1
- package/vendor/desktop/renderer/provider-toolbar.js +134 -1
- package/vendor/desktop/renderer/providers.js +259 -1
- package/vendor/desktop/renderer/quick.js +285 -1
- package/vendor/desktop/renderer/stream-policy.js +387 -1
- package/vendor/desktop/renderer/transcript-view.js +323 -1
- package/vendor/desktop/renderer/usage.js +1239 -1
- package/vendor/desktop/vendor/aegis.js +2441 -1
- package/vendor/desktop/vendor/attest.js +518 -1
- package/vendor/desktop/vendor/authorship-key.js +410 -1
- package/vendor/desktop/vendor/auto-provision.js +134 -1
- package/vendor/desktop/vendor/brain-catalog.js +268 -1
- package/vendor/desktop/vendor/byok-catalog.js +199 -1
- package/vendor/desktop/vendor/catalog-client.js +487 -1
- package/vendor/desktop/vendor/conversation-export.js +177 -1
- package/vendor/desktop/vendor/credentials.js +494 -1
- package/vendor/desktop/vendor/device-fingerprint.js +141 -1
- package/vendor/desktop/vendor/drive-connect.js +110 -1
- package/vendor/desktop/vendor/drive-upload.js +234 -1
- package/vendor/desktop/vendor/env-file.js +1273 -1
- package/vendor/desktop/vendor/fingerprint.js +1064 -1
- package/vendor/desktop/vendor/foreign-memory.js +669 -1
- package/vendor/desktop/vendor/google-signin.js +133 -1
- package/vendor/desktop/vendor/hooks.js +430 -1
- package/vendor/desktop/vendor/model-discovery.js +373 -1
- package/vendor/desktop/vendor/naming.js +283 -1
- package/vendor/desktop/vendor/platform.js +937 -1
- package/vendor/desktop/vendor/prefs.js +351 -1
- package/vendor/desktop/vendor/presence-constants.js +107 -1
- package/vendor/desktop/vendor/presence.js +438 -1
- package/vendor/desktop/vendor/record-vault.js +1055 -3
- package/vendor/desktop/vendor/session-store.js +575 -1
- package/vendor/desktop/vendor/topup.js +297 -1
- package/vendor/desktop/vendor/touch.js +458 -1
- package/vendor/desktop/vendor/update.js +763 -1
- package/vendor/desktop/vendor/user-models.js +381 -1
- package/LICENSE +0 -661
- package/SOURCE-OFFER.txt +0 -9
package/scripts/predist.mjs
CHANGED
|
@@ -1,4 +1,979 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
4
|
-
import e from"node:fs";import r from"node:path";import{spawnSync as s}from"node:child_process";import{fileURLToPath as t,pathToFileURL as o}from"node:url";import{createRequire as n}from"node:module";const i=r.dirname(t(import.meta.url)),a=n(import.meta.url);export const ONE_DIR=r.join(i,"..");export const REPO_DIR=r.join(ONE_DIR,"..");export const CLI_DIR=r.join(REPO_DIR,"cli");export const DESKTOP_DIR=r.join(REPO_DIR,"desktop");export const CLI_VENDOR=r.join(CLI_DIR,"vendor");export const DESKTOP_VENDOR=r.join(DESKTOP_DIR,"vendor");export const ONE_VENDOR=r.join(ONE_DIR,"vendor");export const MANIFEST=[{src:"client/aegis.js",shapes:["mirror","flat"],note:"the thin transport — the one implementation of the wire format"},{src:"client/update.js",shapes:["mirror","flat"],note:"the npm update checker (the desktop own update path)"},{src:"client/foreign-memory.js",shapes:["mirror","flat"],note:"required by mcp/tools.js as ../client/foreign-memory.js"},{src:"client/credentials.js",shapes:["mirror","flat"],note:"the account credential store, shared by all three hosts"},{src:"client/session-store.js",shapes:["mirror","flat"],note:"the unified session store — one list in every host"},{src:"client/naming.js",shapes:["mirror","flat"],note:"the conversation-naming ladder — ONE implementation for the terminal and the window (cli/src/naming.js re-exports it)"},{src:"client/prefs.js",shapes:["mirror","flat"],note:"the shared non-secret preference store (D5) — the CLI and the desktop store both read/write it"},{src:"client/env-file.js",shapes:["mirror","flat"],note:"the shared ~/.aegiscode/.env loader, resolved before any key is read"},{src:"client/auto-provision.js",shapes:["mirror","flat"],note:"free device key on first launch; requires ./device-fingerprint.js"},{src:"client/device-fingerprint.js",shapes:["mirror","flat"],note:"the machine identity auto-provision.js and presence.js require"},{src:"client/presence.js",shapes:["mirror","flat"],note:"the heartbeat beacon; requires ./presence-constants.js and ./device-fingerprint.js"},{src:"client/presence-constants.js",shapes:["mirror","flat"],note:"the beacon constants — a package without them loses the beacon silently"},{src:"client/touch.js",shapes:["mirror","flat"],note:"phi(alpha): the digest module fingerprint.js requires as ./touch.js"},{src:"client/fingerprint.js",shapes:["mirror","flat"],note:"phi(alpha): the sealed session record, resolved by src/fingerprint.js"},{src:"client/authorship-key.js",shapes:["mirror","flat"],note:"phi(alpha): the authorship key, required by ./attest.js and ./record-vault.js"},{src:"client/attest.js",shapes:["mirror","flat"],note:"phi(alpha): attestation, requires ./fingerprint.js and ./authorship-key.js"},{src:"client/record-vault.js",shapes:["mirror","flat"],note:"the vault, and its refusal to copy the key with the record"},{src:"client/brain-catalog.js",shapes:["mirror","flat"],note:"the pooled-brain rule, required at load time by the engine and src/models.js"},{src:"client/byok-catalog.js",shapes:["mirror","flat"],note:"the BYOK model additions the server catalog does not name"},{src:"client/catalog-client.js",shapes:["mirror","flat"],note:"the server's cached catalog, layered between the shipped additions and the user's own models"},{src:"client/user-models.js",shapes:["mirror","flat"],note:"the models the USER declares, in one file both hosts read (requires ./credentials.js)"},{src:"client/model-discovery.js",shapes:["mirror","flat"],note:"asks the vendor what it serves, so adding a new model is not a memory test (requires ./user-models.js)"},{src:"client/hooks.js",shapes:["mirror","flat"],note:"the shared hook layer behind /hooks and the repo guard installer"},{src:"client/platform.js",shapes:["mirror","flat"],note:"the ONE place that decides which OS this is (Phase 30.1)"},{src:"client/topup.js",shapes:["mirror","flat"],note:"the token-bank top-up: amount bounds, the balance reading, and the credit watch every host drives"},{src:"client/google-signin.js",shapes:["mirror","flat"],note:"the localhost half of aegis1's desktop Google OAuth round-trip; `connect --google` drives it"},{src:"client/drive-connect.js",shapes:["mirror","flat"],note:"the desktop half of aegis1's Drive OAuth (/connect/drive, /api/drive/token); requires ./aegis.js only via the caller"},{src:"client/drive-upload.js",shapes:["mirror","flat"],note:"the Drive v3 REST wrapper that uploads the memory backup and one conversation per save"},{src:"client/conversation-export.js",shapes:["mirror","flat"],note:"the authorship stamp at the top of every uploaded file, and the two backup scope names"},{src:"mcp/tools.js",shapes:["mirror"],note:"the shared tool registry; requires ../client/foreign-memory.js"},{src:"mcp/server.js",shapes:["mirror"],note:"the stdio MCP server every installed editor config names (compiled, never required)"},{src:"hosts/spec.js",shapes:["mirror"],note:"the canonical server spec, staged under its own directory so it finds vendor/mcp/server.js"},{src:"hosts/targets.js",shapes:["mirror"],note:"the editor target registry"},{src:"hosts/install.js",shapes:["mirror"],note:"the merge-only installer behind aegiscode mcp install"},{src:"hosts/openai-shim.js",shapes:["mirror"],note:"the loopback OpenAI-compatible shim"},{src:"desktop/renderer/usage.js",shapes:["mirror"],note:"the pure usage mapping shared by the window and the terminal"},{src:"desktop/lib/local/engine.js",shapes:["mirror"],note:"the agent loop, reused as-is (one loop, not a second one drifting)"},{src:"desktop/lib/local/claude-pro.js",shapes:["mirror"],note:"the Claude Code Pro transport; requires ./../../one/src/child.js at call time"},{src:"one/src/child.js",shapes:["mirror"],note:"the ONE claude-child argv builder (rule 4); resolved by claude-pro.js at call time"},{src:"one/src/permissions.js",shapes:["mirror"],note:"resolvePosture() — the permission half of the argv, resolved at call time"},{src:"desktop/lib/local/local.js",shapes:["mirror"],note:"the local model transport and its fail-closed base-URL check"},{src:"desktop/lib/local/context.js",shapes:["mirror"],note:"the token-budget trimmer local.js requires at load"},{src:"desktop/lib/local/attachments.js",shapes:["mirror"],note:"content-part builder for dropped files; required at load by engine.js and local.js"},{src:"desktop/lib/local/session-rounds.js",shapes:["mirror"],note:"interrupted-turn bookkeeping; required at load by engine.js"},{src:"desktop/lib/local/tools.js",shapes:["mirror"],note:"the tool implementations (persistent shell, editFile, grep, exec)"},{src:"desktop/lib/local/shell.js",shapes:["mirror"],note:"the persistent shell, required by tools.js"},{src:"desktop/lib/local/integrity.js",shapes:["mirror"],note:"the desktop second gate; required at load by shell.js and tools.js, and the seal over its own four units"},{src:"desktop/main.js",shapes:["mirror"],bytesOnly:!0,note:"seal unit d1 — hashed by integrity.js as BYTES and never required from the mirror, so its own requires (the whole Electron main-process closure) are not staged behind it"},{src:"desktop/lib/local/spill.js",shapes:["mirror"],note:"oversized-output spill, required at load by tools.js and shell.js"},{src:"desktop/lib/local/exec-plan.js",shapes:["mirror"],note:"exec one-shot eligibility classifier, required at load by engine.js"},{src:"desktop/lib/local/agents.js",shapes:["mirror"],note:"Task subagents"},{src:"desktop/lib/local/prompt.js",shapes:["mirror"],note:"the system prompt builder"},{src:"desktop/lib/settings.js",shapes:["mirror"],note:"the provider-config store (base URL + key per provider)"},{src:"desktop/lib/local/turn-guard.js",shapes:["mirror"],note:"engine.js requires it at load; it requires ./git-scope.js"},{src:"desktop/lib/local/worktree-lock.js",shapes:["mirror"],note:"engine.js requires it at load"},{src:"desktop/lib/local/git-scope.js",shapes:["mirror"],note:"the write-scope rule turn-guard.js and the queues share"},{src:"desktop/lib/local/queue.js",shapes:["mirror"],note:"the autonomous work queue"},{src:"desktop/lib/local/autonomous.js",shapes:["mirror"],note:"the unattended worker; requires ./queue.js and ./git-scope.js"},{src:"desktop/lib/local/entitlement.js",shapes:["mirror"],note:"the shared Pro gate (account probe injected by the caller)"},{src:"desktop/lib/local/covenant.js",shapes:["mirror"],note:"the pre-action gate engine.js requires unconditionally at load"},{src:"desktop/lib/local/aegis-seal.mjs",shapes:["mirror"],note:"the codec covenant.js requires the first time it decodes"},{src:"covenant/aegis.seal",shapes:["mirror","nested"],note:"the sealed covenant (AES/1 container) — path shape is load-bearing"},{src:"covenant/README.md",shapes:["mirror","nested"],note:"the decode notice shipped beside the artifact"},{src:"tools/agent-gate.mjs",shapes:["mirror","flat"],note:"the in-process half of the lock; without it a packaged app had NO gate"}];export function entriesFor(e){const s=[];for(const t of MANIFEST){if(!t.shapes.includes(e))continue;let o;if("mirror"===e)o=r.join(CLI_VENDOR,t.src);else if("flat"===e)o=r.join(DESKTOP_VENDOR,r.basename(t.src));else{if("nested"!==e)throw new Error(`predist: unknown shape ${e}`);o=r.join(DESKTOP_VENDOR,t.src)}s.push({src:t.src,dest:o,from:r.join(REPO_DIR,t.src)})}return s}export const SHAPES=["mirror","flat","nested"];const c=[["cli",CLI_DIR,["bin","src","vendor","scripts","package.json","README.md","LICENSE"]],["desktop",DESKTOP_DIR,["main.js","preload.js","lib","renderer","bin","vendor","package.json","README.md"]]],l=new Set(["node_modules","release",".git",".cache","out"]);function d(s,t){const o=e=>l.has(e)||e.endsWith(".log"),n=(s,t)=>{if(e.mkdirSync(r.dirname(t),{recursive:!0}),e.copyFileSync(s,t),!e.readFileSync(s).equals(e.readFileSync(t)))throw new Error(`predist: bundle copy differs from source: ${r.relative(REPO_DIR,s)}`)},i=(s,a)=>{const c=e.lstatSync(s);if(!c.isSymbolicLink())if(c.isFile())n(s,r.join(t,a));else for(const t of e.readdirSync(s))o(t)||i(r.join(s,t),a?r.join(a,t):t)};e.lstatSync(s).isFile()?n(s,t):i(s,"")}const p=12e4,h=6e5,u=50,m="AEGISONE_PREDIST_LOCK_TOKEN";let f=null,g=!1,j=0;function y(e){try{return process.kill(e,0),!0}catch(e){return Boolean(e)&&"EPERM"===e.code}}const v=e=>new Promise((r=>setTimeout(r,e)));function b(){if(j>0)return void j--;const r=f,s=g,t=process.env[m];if(f=null,g=!1,r&&s){t&&delete process.env[m];try{e.unlinkSync(r)}catch{}}}export async function acquireStageLock(s){if(f)return j++,b;const t=s&&s.stdout||process.stdout;return await async function(s){const t=function(){const s=r.join(REPO_DIR,".git");let t=s;try{if(!e.lstatSync(s).isDirectory()){const o=/^gitdir:\s*(.+)$/m.exec(e.readFileSync(s,"utf8"));o&&(t=r.resolve(REPO_DIR,o[1].trim()))}}catch{t=s}return r.join(t,"aegisone-predist.lock")}(),o=Date.now()+p,n=process.env[m]||null;let i=null,a=!1;for(;;){if(n)try{const r=String(e.readFileSync(t,"utf8")).split("\n")[1];if(r&&r.trim()===n)return f=t,void(g=!1)}catch{}try{i=`${Date.now().toString(36)}-${process.pid}-${Math.random().toString(36).slice(2,10)}`;const r=e.openSync(t,"wx");return e.writeSync(r,`${process.pid}\n${i}\n`),e.closeSync(r),f=t,g=!0,void(process.env[m]=i)}catch(e){if(!e||"EEXIST"!==e.code)throw e}let r=null,c=0;try{r=e.statSync(t),c=Number(String(e.readFileSync(t,"utf8")).split("\n")[0].trim())}catch{continue}if(Date.now()-r.mtimeMs>h||Number.isFinite(c)&&c>0&&!y(c)){s(`predist: breaking an abandoned staging lock (pid ${c||"unknown"})`);try{e.unlinkSync(t)}catch{}}else{if(Date.now()>o)throw new Error(`predist: another stager (pid ${c||"unknown"}) has held ${t} for over ${Math.round(p/1e3)}s. Staging is destructive — it removes and rewrites cli/vendor, desktop/vendor and one/vendor — so it will not run concurrently with a peer. Wait for it, or delete the lock if that process is gone.`);a||(a=!0,s(`predist: another stager (pid ${c||"unknown"}) is running — waiting for it (concurrent staging would read a vendor tree the peer is rewriting)`)),await v(u+Math.floor(Math.random()*u))}}}((e=>t.write(`${e}\n`))),b}function w(s,t){t&&e.rmSync(t,{recursive:!0,force:!0});const o=[];for(const t of s){if(!e.existsSync(t.from))throw new Error(`predist: missing shared module: ${t.src} (expected at ${t.from})`);if(e.mkdirSync(r.dirname(t.dest),{recursive:!0}),e.copyFileSync(t.from,t.dest),!e.readFileSync(t.from).equals(e.readFileSync(t.dest)))throw new Error(`predist: staged copy differs from source: ${t.src}`);o.push(t)}return o}export async function stage(t){const n=t||{},i=n.io||{},l=i.stdout||process.stdout,p=(i.stderr||process.stderr,Array.isArray(n.shapes)?n.shapes:[...SHAPES,"bundle"]),h=e=>p.includes(e),u=e=>l.write(`${e}\n`),m=await acquireStageLock(i);try{return await async function({want:t,log:n}){const i={mirror:null,flat:null,nested:null,bundle:null};if(t("mirror")){const e=w(entriesFor("mirror"),CLI_VENDOR);n(`predist: staged ${e.length} shared modules into cli/vendor/`);for(const r of e)n(` ${r.src} -> vendor/${r.src}`);i.mirror={staged:e.length}}if(t("nested")&&(i.nested={staged:w(entriesFor("nested"),null).length}),t("flat")){const e=w(entriesFor("flat"),null);for(const r of e)n(`staged ${r.dest}`);i.flat={staged:e.length}}if(t("mirror")&&t("flat"))for(const s of MANIFEST){if(!s.shapes.includes("mirror")||!s.shapes.includes("flat"))continue;const t=r.join(CLI_VENDOR,s.src),o=r.join(DESKTOP_VENDOR,r.basename(s.src));if(!e.readFileSync(t).equals(e.readFileSync(o)))throw new Error(`predist: the two shapes disagree for ${s.src}`)}if(t("mirror")){const s=function(s){const t=r.join(CLI_VENDOR,"mcp","tools.js");delete a.cache[a.resolve(t)];const{createTools:o}=a(t),n=o({apiBase:"http://127.0.0.1",apiKey:"predist-probe",randomUUID:()=>"id"}).toolList().length;if(0===n)throw new Error("predist: staged registry exposes no tools");const i=a("node:vm"),c=r.join(CLI_VENDOR,"mcp","server.js");new i.Script(e.readFileSync(c,"utf8"),{filename:c});const l=r.join(CLI_VENDOR,"hosts"),d=a(r.join(l,"spec.js")),p=a(r.join(l,"install.js")),h=a(r.join(l,"targets.js")),u=d.resolveServer({AEGIS_MCP_SERVER:""});if(!u.exists||u.path!==c)throw new Error(`predist: staged hosts/spec.js resolves the server as ${u.path} (exists: ${u.exists}), expected ${c}. An installed aegiscode would write editor configs pointing at a file the package never shipped. Candidates were:\n ${u.candidates.join("\n ")}`);const m=h.getTarget("vscode"),f=p.planTarget(m,"user",{ctx:p.hostCtx({home:r.join(CLI_VENDOR,".predist-home"),env:{},cwd:REPO_DIR}),specOpts:{env:{AEGIS_MCP_SERVER:""}}}),g=JSON.stringify(f.after||"");if(f.error||!f.changed||!g.includes(JSON.stringify(c).slice(1,-1)))throw new Error(`predist: a planned vscode install does not name the staged server (error: ${f.error&&f.error.message}, changed: ${f.changed})`);if("function"!=typeof a(r.join(l,"openai-shim.js")).createShimServer)throw new Error("predist: staged hosts/openai-shim.js exposes no createShimServer");return{count:n,targets:h.targetIds().length,staged:s.length}}(entriesFor("mirror"));n(`predist: staged registry loads standalone (${s.count} tools)`),n(`predist: editor layer verified (${s.targets} host targets, server resolves to vendor/mcp/server.js, shim loads)`);const t=await async function(){const e=r.join(CLI_VENDOR,"tools","agent-gate.mjs");if("function"!=typeof(await import(o(e).href)).run)throw new Error("predist: staged tools/agent-gate.mjs exposes no run()");return e}();n(`predist: ${r.relative(REPO_DIR,t)} loads standalone and exposes run()`),i.mirror.proof=s}if(t("flat")){const s=function(s){const t=new Set(s.map((e=>r.basename(e.dest))));for(const o of s){const s=e.readFileSync(o.dest,"utf8").replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1");for(const e of s.matchAll(/require\(\s*'((?:\.\.?\/)[^']+)'\s*\)/g)){const s=e[1];if(r.basename(s).replace(/\.[cm]?js$/,""),s.replace(/^\.\//,"").startsWith("../"))throw new Error(`predist: flat-staged ${r.basename(o.dest)} requires '${s}', which escapes vendor/ — flattening only works for same-directory requires (add the target to the manifest, or stop staging this file flat)`);const n=s.replace(/^\.\//,"");if(!t.has(n))throw new Error(`predist: flat-staged ${r.basename(o.dest)} requires '${s}', which is not staged into desktop/vendor/ — the packaged app would throw MODULE_NOT_FOUND before the window could open`)}}const o=a(r.join(DESKTOP_VENDOR,"aegis.js"));if(!o||0===Object.keys(o).length)throw new Error("predist: staged desktop/vendor/aegis.js loads but exports nothing");return{files:s.length,exports:Object.keys(o).length}}(entriesFor("flat"));n(`predist: flattened tree is self-contained (${s.files} files, ${s.exports} transport exports) — no staged module escapes vendor/`),i.flat.proof=s}if(t("bundle")){for(const[s,t,o]of c){const i=r.join(ONE_VENDOR,s);e.rmSync(i,{recursive:!0,force:!0});for(const s of o){const o=r.join(t,s);if(!e.existsSync(o)){if("LICENSE"===s||"README.md"===s)continue;throw new Error(`predist: bundle source missing: ${r.relative(REPO_DIR,o)}`)}d(o,r.join(i,s))}n(`staged the ${s} face into one/vendor/${s}/`)}const t=function(){const t=r.join(ONE_VENDOR,"cli"),o=r.join(t,"src","deps.js"),n=s(process.execPath,["-e","const d=require(process.argv[1]);console.log(JSON.stringify(d.paths))",o],{cwd:t,encoding:"utf8"});if(0!==n.status)throw new Error(`predist: the bundled CLI does not load: ${n.stderr||n.stdout}`);const i=JSON.parse(n.stdout),a=[];let l=0;for(const[e,s]of Object.entries(i)){const t=r.relative(ONE_VENDOR,s);t.startsWith("..")||r.isAbsolute(t)?a.push(`${e} -> ${s}`):"cli"!==t.split(r.sep)[0]&&l++}if(a.length)throw new Error(`predist: the bundled CLI resolves these shared modules OUTSIDE the bundle (${ONE_VENDOR}) — the product tarball would depend on a repo checkout:\n `+a.join("\n "));if(!e.existsSync(r.join(t,"bin","aegiscode.js")))throw new Error("predist: the bundle has no cli/bin/aegiscode.js");const d=[];for(const[s,t,o]of c)for(const n of o){const o=r.join(ONE_VENDOR,s,n);let i=null,a=null;try{i=e.lstatSync(r.join(t,n))}catch{continue}try{a=e.lstatSync(o)}catch{d.push(`${s}/${n} -> missing`);continue}i.isFile()&&!a.isFile()&&d.push(`${s}/${n} -> not a regular file`),i.isDirectory()&&!a.isDirectory()&&d.push(`${s}/${n} -> not a directory`)}if(d.length)throw new Error(`predist: the bundle staged these in the wrong shape:\n ${d.join("\n ")}`);return{modules:Object.keys(i).length,inSiblingFace:l}}();n(`predist: the bundled CLI resolves ${t.modules} shared modules from inside one/vendor/ (${t.inSiblingFace} through the bundled desktop face) — no repo checkout needed`),i.bundle=t}return i}({want:h,log:u})}finally{m()}}export async function main(e,r){const s=r||{},t=Array.isArray(e)?e:[],o=t.includes("--quiet")?{write:()=>!0}:s.stdout||process.stdout,n=s.stderr||process.stderr;let i;t.includes("--mirror-only")?i=["mirror"]:t.includes("--flat-only")?i=["flat","nested"]:t.includes("--bundle-only")&&(i=["bundle"]);try{return await stage({shapes:i,io:{stdout:o,stderr:n}}),0}catch(e){return n.write(`${e&&e.message}\n`),1}}!function(){const e=process.argv[1];let s=!1;if(e)try{s=r.resolve(e)===t(import.meta.url)}catch{s=!1}s&&main(process.argv.slice(2)).then((e=>{process.exitCode=e}))}();
|
|
4
|
+
// AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
|
|
5
|
+
// Conveying a modified copy, or running one as a network service, owes the
|
|
6
|
+
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
7
|
+
/**
|
|
8
|
+
* AEGISONE — the ONLY vendoring stager (plan D6).
|
|
9
|
+
*
|
|
10
|
+
* Before this file there were two stagers with two hand-maintained manifests:
|
|
11
|
+
* `cli/scripts/predist.mjs` (about forty modules, staged under `cli/vendor/`
|
|
12
|
+
* keeping the repo's relative shape) and `desktop/scripts/predist.mjs` (a
|
|
13
|
+
* subset of the same modules, staged FLAT into `desktop/vendor/`, because
|
|
14
|
+
* electron-builder cannot reach outside the app directory). Two lists of the
|
|
15
|
+
* same repo-relative paths, drifting independently, each with its own copy of
|
|
16
|
+
* the "why is this file here" reasoning.
|
|
17
|
+
*
|
|
18
|
+
* Now there is ONE manifest — `MANIFEST`, below — and it is the only place a
|
|
19
|
+
* staged path is written down. Each row records which SHAPE(s) that module must
|
|
20
|
+
* appear in:
|
|
21
|
+
*
|
|
22
|
+
* mirror → `<cli>/vendor/<repo-relative path>` (the CLI's self-similar tree)
|
|
23
|
+
* flat → `<desktop>/vendor/<basename>` (electron-builder's app dir)
|
|
24
|
+
* nested → `<desktop>/vendor/<repo-relative path>` (artifacts whose SHAPE is
|
|
25
|
+
* load-bearing: the seal is
|
|
26
|
+
* resolved at ../../vendor/
|
|
27
|
+
* covenant/aegis.seal)
|
|
28
|
+
*
|
|
29
|
+
* …plus a fourth output that only AEGISONE needs: the PRODUCT BUNDLE
|
|
30
|
+
* (`one/vendor/cli/**`, `one/vendor/desktop/**`), which is what makes
|
|
31
|
+
* `npm i -g aegisone` a single install with both faces inside it. The bundle
|
|
32
|
+
* is a copy of the already-staged trees, so it inherits both shapes verbatim
|
|
33
|
+
* and `sharedpaths.js`'s two-layout rule resolves inside it with no change.
|
|
34
|
+
*
|
|
35
|
+
* Two things this file refuses to do:
|
|
36
|
+
*
|
|
37
|
+
* 1. **It never trusts a copy.** Every staged file is re-read and compared
|
|
38
|
+
* against its source; a mismatch is a hard failure, because a stale vendor
|
|
39
|
+
* tree is how a published package ships last month's behaviour.
|
|
40
|
+
* 2. **It never trusts a comment.** Both existing proofs are carried over and
|
|
41
|
+
* actually executed here: the CLI's staged registry must LOAD from inside
|
|
42
|
+
* `cli/vendor/` (not from the repo), and the desktop's flattened tree must
|
|
43
|
+
* be self-contained (no staged file may require a path that escapes
|
|
44
|
+
* `vendor/`) — which is the property flattening silently depends on.
|
|
45
|
+
*
|
|
46
|
+
* THE SEAM RULE (Phase 30.1, and the standing rule for everything under `one/`):
|
|
47
|
+
* no `process.*` read happens at module scope. Every read is inside a function,
|
|
48
|
+
* `main(argv, io)` takes its streams and arguments as parameters, and this
|
|
49
|
+
* module is therefore importable by a test without running the staging. There
|
|
50
|
+
* is also no `process.platform` anywhere in this file: nothing here branches on
|
|
51
|
+
* the OS. Where a host list is needed it comes from `client/platform.js`, and
|
|
52
|
+
* the copies themselves are `fs` calls with no platform vocabulary in them.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
import fs from 'node:fs';
|
|
56
|
+
import path from 'node:path';
|
|
57
|
+
import { spawnSync } from 'node:child_process';
|
|
58
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
59
|
+
import { createRequire } from 'node:module';
|
|
60
|
+
|
|
61
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
62
|
+
const require = createRequire(import.meta.url);
|
|
63
|
+
|
|
64
|
+
/** `one/` */
|
|
65
|
+
export const ONE_DIR = path.join(HERE, '..');
|
|
66
|
+
/** the repository root (`aegiscode-plugin/`) */
|
|
67
|
+
export const REPO_DIR = path.join(ONE_DIR, '..');
|
|
68
|
+
export const CLI_DIR = path.join(REPO_DIR, 'cli');
|
|
69
|
+
export const DESKTOP_DIR = path.join(REPO_DIR, 'desktop');
|
|
70
|
+
export const CLI_VENDOR = path.join(CLI_DIR, 'vendor');
|
|
71
|
+
export const DESKTOP_VENDOR = path.join(DESKTOP_DIR, 'vendor');
|
|
72
|
+
export const ONE_VENDOR = path.join(ONE_DIR, 'vendor');
|
|
73
|
+
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// THE MANIFEST — one row per shared module, one place a path is written down.
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
//
|
|
78
|
+
// `src` repo-relative path of the file that lives at the repo root.
|
|
79
|
+
// `shapes` where it must appear: 'mirror' (cli/vendor, repo-shaped),
|
|
80
|
+
// 'flat' (desktop/vendor, basename only), 'nested' (desktop/vendor,
|
|
81
|
+
// repo-shaped — only for artifacts whose shape the requiring code
|
|
82
|
+
// depends on).
|
|
83
|
+
//
|
|
84
|
+
// A row appears ONCE even when both hosts need it. That is the whole point of
|
|
85
|
+
// D6: the desktop's flat set is a subset of the CLI's mirror set, and the old
|
|
86
|
+
// pair of scripts restated those nineteen paths in two files.
|
|
87
|
+
//
|
|
88
|
+
// Comment discipline: the old per-file notes are preserved verbatim-ish, but
|
|
89
|
+
// none of them is load-bearing any more. Nothing parses these comments (the
|
|
90
|
+
// `src:`/`shapes:` fields are matched as an object by test/one-vendor.test.mjs),
|
|
91
|
+
// so a stray apostrophe can no longer swallow the next manifest row — which is
|
|
92
|
+
// exactly the trap the old single-quote-paired parsers fell into.
|
|
93
|
+
export const MANIFEST = [
|
|
94
|
+
// ── the shared client: transport, stores, identity, catalogues ───────────
|
|
95
|
+
{ src: 'client/aegis.js', shapes: ['mirror', 'flat'],
|
|
96
|
+
note: 'the thin transport — the one implementation of the wire format' },
|
|
97
|
+
{ src: 'client/update.js', shapes: ['mirror', 'flat'],
|
|
98
|
+
note: 'the npm update checker (the desktop own update path)' },
|
|
99
|
+
{ src: 'client/foreign-memory.js', shapes: ['mirror', 'flat'],
|
|
100
|
+
note: 'required by mcp/tools.js as ../client/foreign-memory.js' },
|
|
101
|
+
{ src: 'client/credentials.js', shapes: ['mirror', 'flat'],
|
|
102
|
+
note: 'the account credential store, shared by all three hosts' },
|
|
103
|
+
{ src: 'client/session-store.js', shapes: ['mirror', 'flat'],
|
|
104
|
+
note: 'the unified session store — one list in every host' },
|
|
105
|
+
{ src: 'client/naming.js', shapes: ['mirror', 'flat'],
|
|
106
|
+
note: 'the conversation-naming ladder — ONE implementation for the terminal and the window (cli/src/naming.js re-exports it)' },
|
|
107
|
+
{ src: 'client/prefs.js', shapes: ['mirror', 'flat'],
|
|
108
|
+
note: 'the shared non-secret preference store (D5) — the CLI and the desktop store both read/write it' },
|
|
109
|
+
{ src: 'client/env-file.js', shapes: ['mirror', 'flat'],
|
|
110
|
+
note: 'the shared ~/.aegiscode/.env loader, resolved before any key is read' },
|
|
111
|
+
{ src: 'client/auto-provision.js', shapes: ['mirror', 'flat'],
|
|
112
|
+
note: 'free device key on first launch; requires ./device-fingerprint.js' },
|
|
113
|
+
{ src: 'client/device-fingerprint.js', shapes: ['mirror', 'flat'],
|
|
114
|
+
note: 'the machine identity auto-provision.js and presence.js require' },
|
|
115
|
+
{ src: 'client/presence.js', shapes: ['mirror', 'flat'],
|
|
116
|
+
note: 'the heartbeat beacon; requires ./presence-constants.js and ./device-fingerprint.js' },
|
|
117
|
+
{ src: 'client/presence-constants.js', shapes: ['mirror', 'flat'],
|
|
118
|
+
note: 'the beacon constants — a package without them loses the beacon silently' },
|
|
119
|
+
{ src: 'client/touch.js', shapes: ['mirror', 'flat'],
|
|
120
|
+
note: 'phi(alpha): the digest module fingerprint.js requires as ./touch.js' },
|
|
121
|
+
{ src: 'client/fingerprint.js', shapes: ['mirror', 'flat'],
|
|
122
|
+
note: 'phi(alpha): the sealed session record, resolved by src/fingerprint.js' },
|
|
123
|
+
{ src: 'client/authorship-key.js', shapes: ['mirror', 'flat'],
|
|
124
|
+
note: 'phi(alpha): the authorship key, required by ./attest.js and ./record-vault.js' },
|
|
125
|
+
{ src: 'client/attest.js', shapes: ['mirror', 'flat'],
|
|
126
|
+
note: 'phi(alpha): attestation, requires ./fingerprint.js and ./authorship-key.js' },
|
|
127
|
+
{ src: 'client/record-vault.js', shapes: ['mirror', 'flat'],
|
|
128
|
+
note: 'the vault, and its refusal to copy the key with the record' },
|
|
129
|
+
{ src: 'client/brain-catalog.js', shapes: ['mirror', 'flat'],
|
|
130
|
+
note: 'the pooled-brain rule, required at load time by the engine and src/models.js' },
|
|
131
|
+
{ src: 'client/byok-catalog.js', shapes: ['mirror', 'flat'],
|
|
132
|
+
note: 'the BYOK model additions the server catalog does not name' },
|
|
133
|
+
{ src: 'client/catalog-client.js', shapes: ['mirror', 'flat'],
|
|
134
|
+
note: 'the server\'s cached catalog, layered between the shipped additions and the user\'s own models' },
|
|
135
|
+
{ src: 'client/user-models.js', shapes: ['mirror', 'flat'],
|
|
136
|
+
note: 'the models the USER declares, in one file both hosts read (requires ./credentials.js)' },
|
|
137
|
+
{ src: 'client/model-discovery.js', shapes: ['mirror', 'flat'],
|
|
138
|
+
note: 'asks the vendor what it serves, so adding a new model is not a memory test (requires ./user-models.js)' },
|
|
139
|
+
{ src: 'client/hooks.js', shapes: ['mirror', 'flat'],
|
|
140
|
+
note: 'the shared hook layer behind /hooks and the repo guard installer' },
|
|
141
|
+
{ src: 'client/platform.js', shapes: ['mirror', 'flat'],
|
|
142
|
+
note: 'the ONE place that decides which OS this is (Phase 30.1)' },
|
|
143
|
+
{ src: 'client/topup.js', shapes: ['mirror', 'flat'],
|
|
144
|
+
note: 'the token-bank top-up: amount bounds, the balance reading, and the credit watch every host drives' },
|
|
145
|
+
{ src: 'client/google-signin.js', shapes: ['mirror', 'flat'],
|
|
146
|
+
note: 'the localhost half of aegis1\'s desktop Google OAuth round-trip; `connect --google` drives it' },
|
|
147
|
+
{ src: 'client/drive-connect.js', shapes: ['mirror', 'flat'],
|
|
148
|
+
note: 'the desktop half of aegis1\'s Drive OAuth (/connect/drive, /api/drive/token); requires ./aegis.js only via the caller' },
|
|
149
|
+
{ src: 'client/drive-upload.js', shapes: ['mirror', 'flat'],
|
|
150
|
+
note: 'the Drive v3 REST wrapper that uploads the memory backup and one conversation per save' },
|
|
151
|
+
{ src: 'client/conversation-export.js', shapes: ['mirror', 'flat'],
|
|
152
|
+
note: 'the authorship stamp at the top of every uploaded file, and the two backup scope names' },
|
|
153
|
+
|
|
154
|
+
// ── the MCP host surface ────────────────────────────────────────────────
|
|
155
|
+
{ src: 'mcp/tools.js', shapes: ['mirror'],
|
|
156
|
+
note: 'the shared tool registry; requires ../client/foreign-memory.js' },
|
|
157
|
+
{ src: 'mcp/server.js', shapes: ['mirror'],
|
|
158
|
+
note: 'the stdio MCP server every installed editor config names (compiled, never required)' },
|
|
159
|
+
{ src: 'hosts/spec.js', shapes: ['mirror'],
|
|
160
|
+
note: 'the canonical server spec, staged under its own directory so it finds vendor/mcp/server.js' },
|
|
161
|
+
{ src: 'hosts/targets.js', shapes: ['mirror'],
|
|
162
|
+
note: 'the editor target registry' },
|
|
163
|
+
{ src: 'hosts/install.js', shapes: ['mirror'],
|
|
164
|
+
note: 'the merge-only installer behind aegiscode mcp install' },
|
|
165
|
+
{ src: 'hosts/openai-shim.js', shapes: ['mirror'],
|
|
166
|
+
note: 'the loopback OpenAI-compatible shim' },
|
|
167
|
+
|
|
168
|
+
// ── the engine the CLI reuses from the desktop app ──────────────────────
|
|
169
|
+
{ src: 'desktop/renderer/usage.js', shapes: ['mirror'],
|
|
170
|
+
note: 'the pure usage mapping shared by the window and the terminal' },
|
|
171
|
+
{ src: 'desktop/lib/local/engine.js', shapes: ['mirror'],
|
|
172
|
+
note: 'the agent loop, reused as-is (one loop, not a second one drifting)' },
|
|
173
|
+
// engine.js requires ./claude-pro.js at load (the Claude Code Pro class'
|
|
174
|
+
// transport), exactly as local.js requires ./context.js — and with exactly
|
|
175
|
+
// the same consequence when the row is absent: the staged engine throws
|
|
176
|
+
// MODULE_NOT_FOUND from inside vendor/, and the packaged CLI does not load at
|
|
177
|
+
// all. test/one-manifest-complete.test.mjs derives the dependency, so this is
|
|
178
|
+
// a red line there rather than a mystery in cli-package.
|
|
179
|
+
{ src: 'desktop/lib/local/claude-pro.js', shapes: ['mirror'],
|
|
180
|
+
note: 'the Claude Code Pro transport; requires ./../../one/src/child.js at call time' },
|
|
181
|
+
// The Pro class' argv half. claude-pro.js resolves these at CALL time through
|
|
182
|
+
// path.join (not a relative require), so the manifest-completeness scan cannot
|
|
183
|
+
// see them — which is why they are written down here by hand and why they were
|
|
184
|
+
// missed. `one/src/permissions.js` reaches the CLI's own rule evaluator at
|
|
185
|
+
// cli/src/permissions.js, itself resolved through the staged `../vendor/cli/`
|
|
186
|
+
// layout ('mirror' stages them at cli/vendor/cli/src/…, which is the second
|
|
187
|
+
// candidate that module looks in).
|
|
188
|
+
{ src: 'one/src/child.js', shapes: ['mirror'],
|
|
189
|
+
note: 'the ONE claude-child argv builder (rule 4); resolved by claude-pro.js at call time' },
|
|
190
|
+
{ src: 'one/src/permissions.js', shapes: ['mirror'],
|
|
191
|
+
note: 'resolvePosture() — the permission half of the argv, resolved at call time' },
|
|
192
|
+
{ src: 'desktop/lib/local/local.js', shapes: ['mirror'],
|
|
193
|
+
note: 'the local model transport and its fail-closed base-URL check' },
|
|
194
|
+
// The row whose ABSENCE broke the packaged CLI: `local.js` requires
|
|
195
|
+
// `./context.js` at load (for the token-budget trimmer), context.js is a
|
|
196
|
+
// committed module — and it had no manifest row, so no staged tree ever
|
|
197
|
+
// carried it. `require('./context.js')` then threw MODULE_NOT_FOUND from
|
|
198
|
+
// inside vendor/, which is the failure test/cli-approval.test.mjs and
|
|
199
|
+
// test/cli-package.test.mjs were reporting: the packaged CLI could not load
|
|
200
|
+
// at all. A manifest that lists a module's DEPENDENCIES by hand is exactly
|
|
201
|
+
// where this hides, so test/one-manifest-complete.test.mjs now derives the
|
|
202
|
+
// rule instead of trusting the list.
|
|
203
|
+
{ src: 'desktop/lib/local/context.js', shapes: ['mirror'],
|
|
204
|
+
note: 'the token-budget trimmer local.js requires at load' },
|
|
205
|
+
// Required at load by BOTH engine.js and local.js, for the content-part
|
|
206
|
+
// handling a dropped attachment produces. Same absence as the context.js
|
|
207
|
+
// row above: the module existed, the manifest did not name it, so no staged
|
|
208
|
+
// tree carried it and `require('./attachments.js')` threw MODULE_NOT_FOUND
|
|
209
|
+
// from inside vendor/. test/one-manifest-complete.test.mjs derives this.
|
|
210
|
+
{ src: 'desktop/lib/local/attachments.js', shapes: ['mirror'],
|
|
211
|
+
note: 'content-part builder for dropped files; required at load by engine.js and local.js' },
|
|
212
|
+
{ src: 'desktop/lib/local/session-rounds.js', shapes: ['mirror'],
|
|
213
|
+
note: 'interrupted-turn bookkeeping; required at load by engine.js' },
|
|
214
|
+
{ src: 'desktop/lib/local/tools.js', shapes: ['mirror'],
|
|
215
|
+
note: 'the tool implementations (persistent shell, editFile, grep, exec)' },
|
|
216
|
+
{ src: 'desktop/lib/local/shell.js', shapes: ['mirror'],
|
|
217
|
+
note: 'the persistent shell, required by tools.js' },
|
|
218
|
+
// The desktop interlock, and the three units it hashes that the mirror did not
|
|
219
|
+
// already carry. `shell.js` and `tools.js` require ./integrity.js AT LOAD since
|
|
220
|
+
// e25c369 — before that commit they did not, which is why the row was never
|
|
221
|
+
// needed and why this went unnoticed: every published tree was staged before
|
|
222
|
+
// the require existed, so the shipped CLI loaded a mirror that predated it.
|
|
223
|
+
// A freshly staged tree throws MODULE_NOT_FOUND from cli/vendor and the CLI
|
|
224
|
+
// does not start (test/cli-platform-parity.test.mjs dies on the require).
|
|
225
|
+
//
|
|
226
|
+
// `integrity.js` alone is WORSE than leaving it out: `check()` needs all four
|
|
227
|
+
// UNITS to compute a digest, and an absent unit returns `d1`, which is
|
|
228
|
+
// `tripped` — so `armed()` would answer true and shell.js/tools.js/exec-plan
|
|
229
|
+
// would refuse to spawn. The mirror is byte-identical to the sealed source,
|
|
230
|
+
// so staging all four makes its digest equal the seal and the gate passes.
|
|
231
|
+
// `main.js` is one of the four but is only ever read as BYTES — nothing in the
|
|
232
|
+
// mirror requires it — so staging it drags no Electron closure in behind it.
|
|
233
|
+
// The other three are already rows above; this is the seal and its entry.
|
|
234
|
+
{ src: 'desktop/lib/local/integrity.js', shapes: ['mirror'],
|
|
235
|
+
note: 'the desktop second gate; required at load by shell.js and tools.js, and the seal over its own four units' },
|
|
236
|
+
{ src: 'desktop/main.js', shapes: ['mirror'], bytesOnly: true,
|
|
237
|
+
note: 'seal unit d1 — hashed by integrity.js as BYTES and never required from the mirror, so its own requires (the whole Electron main-process closure) are not staged behind it' },
|
|
238
|
+
{ src: 'desktop/lib/local/spill.js', shapes: ['mirror'],
|
|
239
|
+
note: 'oversized-output spill, required at load by tools.js and shell.js' },
|
|
240
|
+
{ src: 'desktop/lib/local/exec-plan.js', shapes: ['mirror'],
|
|
241
|
+
note: 'exec one-shot eligibility classifier, required at load by engine.js' },
|
|
242
|
+
{ src: 'desktop/lib/local/agents.js', shapes: ['mirror'],
|
|
243
|
+
note: 'Task subagents' },
|
|
244
|
+
{ src: 'desktop/lib/local/prompt.js', shapes: ['mirror'],
|
|
245
|
+
note: 'the system prompt builder' },
|
|
246
|
+
{ src: 'desktop/lib/settings.js', shapes: ['mirror'],
|
|
247
|
+
note: 'the provider-config store (base URL + key per provider)' },
|
|
248
|
+
{ src: 'desktop/lib/local/turn-guard.js', shapes: ['mirror'],
|
|
249
|
+
note: 'engine.js requires it at load; it requires ./git-scope.js' },
|
|
250
|
+
{ src: 'desktop/lib/local/worktree-lock.js', shapes: ['mirror'],
|
|
251
|
+
note: 'engine.js requires it at load' },
|
|
252
|
+
{ src: 'desktop/lib/local/git-scope.js', shapes: ['mirror'],
|
|
253
|
+
note: 'the write-scope rule turn-guard.js and the queues share' },
|
|
254
|
+
{ src: 'desktop/lib/local/queue.js', shapes: ['mirror'],
|
|
255
|
+
note: 'the autonomous work queue' },
|
|
256
|
+
{ src: 'desktop/lib/local/autonomous.js', shapes: ['mirror'],
|
|
257
|
+
note: 'the unattended worker; requires ./queue.js and ./git-scope.js' },
|
|
258
|
+
{ src: 'desktop/lib/local/entitlement.js', shapes: ['mirror'],
|
|
259
|
+
note: 'the shared Pro gate (account probe injected by the caller)' },
|
|
260
|
+
{ src: 'desktop/lib/local/covenant.js', shapes: ['mirror'],
|
|
261
|
+
note: 'the pre-action gate engine.js requires unconditionally at load' },
|
|
262
|
+
{ src: 'desktop/lib/local/aegis-seal.mjs', shapes: ['mirror'],
|
|
263
|
+
note: 'the codec covenant.js requires the first time it decodes' },
|
|
264
|
+
|
|
265
|
+
// ── the sealed covenant: the one row whose SHAPE is load-bearing ────────
|
|
266
|
+
// covenant.js resolves the artifact at `../../vendor/covenant/aegis.seal`
|
|
267
|
+
// relative to itself, so it must keep the repo's path under vendor/ — flat
|
|
268
|
+
// staging would place it where nothing looks, and the host would then report
|
|
269
|
+
// `available: false` and enforce only the hard-coded immutable trio while
|
|
270
|
+
// every other clause is silently gone.
|
|
271
|
+
{ src: 'covenant/aegis.seal', shapes: ['mirror', 'nested'],
|
|
272
|
+
note: 'the sealed covenant (AES/1 container) — path shape is load-bearing' },
|
|
273
|
+
{ src: 'covenant/README.md', shapes: ['mirror', 'nested'],
|
|
274
|
+
note: 'the decode notice shipped beside the artifact' },
|
|
275
|
+
|
|
276
|
+
// ── the agent-key gate ─────────────────────────────────────────────────
|
|
277
|
+
{ src: 'tools/agent-gate.mjs', shapes: ['mirror', 'flat'],
|
|
278
|
+
note: 'the in-process half of the lock; without it a packaged app had NO gate' },
|
|
279
|
+
];
|
|
280
|
+
|
|
281
|
+
/** Rows in a given shape: `{src, dest}` pairs, destination computed here only. */
|
|
282
|
+
export function entriesFor(shape) {
|
|
283
|
+
const out = [];
|
|
284
|
+
for (const row of MANIFEST) {
|
|
285
|
+
if (!row.shapes.includes(shape)) continue;
|
|
286
|
+
let dest;
|
|
287
|
+
if (shape === 'mirror') dest = path.join(CLI_VENDOR, row.src);
|
|
288
|
+
else if (shape === 'flat') dest = path.join(DESKTOP_VENDOR, path.basename(row.src));
|
|
289
|
+
else if (shape === 'nested') dest = path.join(DESKTOP_VENDOR, row.src);
|
|
290
|
+
else throw new Error(`predist: unknown shape ${shape}`);
|
|
291
|
+
out.push({ src: row.src, dest, from: path.join(REPO_DIR, row.src) });
|
|
292
|
+
}
|
|
293
|
+
return out;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Every distinct shape named by the manifest, in a stable order. */
|
|
297
|
+
export const SHAPES = ['mirror', 'flat', 'nested'];
|
|
298
|
+
|
|
299
|
+
// ---------------------------------------------------------------------------
|
|
300
|
+
// The product bundle: `one/vendor/cli/**` and `one/vendor/desktop/**`
|
|
301
|
+
// ---------------------------------------------------------------------------
|
|
302
|
+
//
|
|
303
|
+
// `npm pack one/` has to produce a package that BOOTS. The two faces keep their
|
|
304
|
+
// self-similar shape inside it, which is why no resolver changed to make this
|
|
305
|
+
// work: `cli/src/sharedpaths.js` tries `<cli>/../../client` (absent in the
|
|
306
|
+
// bundle, so it falls through) and then `<cli>/vendor/client` — staged above,
|
|
307
|
+
// inside the bundle. The bundle is copied from the already-verified trees, so
|
|
308
|
+
// the byte-identity proof covers these bytes too.
|
|
309
|
+
const BUNDLE_SOURCES = [
|
|
310
|
+
['cli', CLI_DIR, ['bin', 'src', 'vendor', 'scripts', 'package.json', 'README.md', 'LICENSE']],
|
|
311
|
+
[
|
|
312
|
+
'desktop',
|
|
313
|
+
DESKTOP_DIR,
|
|
314
|
+
['main.js', 'preload.js', 'lib', 'renderer', 'bin', 'vendor', 'package.json', 'README.md'],
|
|
315
|
+
],
|
|
316
|
+
];
|
|
317
|
+
|
|
318
|
+
/** Directory names that must never be copied into a published bundle. */
|
|
319
|
+
const BUNDLE_EXCLUDE = new Set(['node_modules', 'release', '.git', '.cache', 'out']);
|
|
320
|
+
|
|
321
|
+
function copyTree(from, toDir) {
|
|
322
|
+
const skip = (name) => BUNDLE_EXCLUDE.has(name) || name.endsWith('.log');
|
|
323
|
+
const copyFile = (file, dest) => {
|
|
324
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
325
|
+
fs.copyFileSync(file, dest);
|
|
326
|
+
if (!fs.readFileSync(file).equals(fs.readFileSync(dest))) {
|
|
327
|
+
throw new Error(`predist: bundle copy differs from source: ${path.relative(REPO_DIR, file)}`);
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
const walk = (dir, rel) => {
|
|
331
|
+
const stat = fs.lstatSync(dir);
|
|
332
|
+
// Symlinks are skipped rather than followed: a bundle that resolved through
|
|
333
|
+
// one would pack a path that only exists on the machine that built it.
|
|
334
|
+
if (stat.isSymbolicLink()) return;
|
|
335
|
+
if (stat.isFile()) {
|
|
336
|
+
copyFile(dir, path.join(toDir, rel));
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
for (const name of fs.readdirSync(dir)) {
|
|
340
|
+
if (skip(name)) continue;
|
|
341
|
+
walk(path.join(dir, name), rel ? path.join(rel, name) : name);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
// When `from` is a file, `toDir` is the file's FINAL path — not a directory to
|
|
345
|
+
// append the basename to. The bundle's `parts` mix directories and files
|
|
346
|
+
// (`bin`, `src`, … alongside `package.json`, `main.js`, `LICENSE`), and
|
|
347
|
+
// treating both as directories nested every file one level too deep:
|
|
348
|
+
// `one/vendor/cli/package.json/package.json`, `one/vendor/desktop/main.js/main.js`.
|
|
349
|
+
// The module-resolution proof did not notice, because `deps.js` resolves the
|
|
350
|
+
// shared modules and never the face's own entry point — so the tarball packed
|
|
351
|
+
// and installed cleanly with no `main.js` anywhere in it. Only
|
|
352
|
+
// `test/one-pack-boot.test.mjs` (ON2's real gate: pack → temp prefix → run)
|
|
353
|
+
// exposed it; `proveBundle` now asserts the shapes directly.
|
|
354
|
+
if (fs.lstatSync(from).isFile()) copyFile(from, toDir);
|
|
355
|
+
else walk(from, '');
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// ---------------------------------------------------------------------------
|
|
359
|
+
// Mutual exclusion — one stager at a time per checkout
|
|
360
|
+
// ---------------------------------------------------------------------------
|
|
361
|
+
//
|
|
362
|
+
// Staging is destructive by construction: `stageFiles(entries, CLI_VENDOR)`
|
|
363
|
+
// removes `cli/vendor/` outright and re-copies every module into it, and the
|
|
364
|
+
// bundle step does the same to `one/vendor/<face>/`. Two stagers in the same
|
|
365
|
+
// checkout therefore cannot merely interleave harmlessly — the second one's
|
|
366
|
+
// `rmSync` unlinks the tree the first one is still reading, and the first one's
|
|
367
|
+
// per-file byte comparison (`readFileSync(from).equals(readFileSync(dest))`)
|
|
368
|
+
// then fails, or the second one's copy is read half-written.
|
|
369
|
+
//
|
|
370
|
+
// That is not hypothetical: `test/one-vendor.test.mjs` and
|
|
371
|
+
// `test/one-pack-boot.test.mjs` each shell out to this file, so running the
|
|
372
|
+
// suite with block-level concurrency puts two stagers in the same tree at once.
|
|
373
|
+
// Both pass alone and each can fail when overlapped, which reads as a flaky
|
|
374
|
+
// gate rather than as the data race it is. The lock below is what makes the
|
|
375
|
+
// gate honest under concurrency instead of pretending the race is a test bug.
|
|
376
|
+
//
|
|
377
|
+
// The lock file lives in this checkout's OWN git directory, and that location
|
|
378
|
+
// is load-bearing three ways over:
|
|
379
|
+
//
|
|
380
|
+
// * It cannot be the OS temp dir — resolving that is an OS answer, and `one/`'s
|
|
381
|
+
// seam rule (asserted by test/one-vendor.test.mjs) forbids this file from
|
|
382
|
+
// knowing the platform at all: that answer belongs to `client/platform.js`.
|
|
383
|
+
// * It cannot be `one/`, `cli/` or the repo root: an untracked lock file there
|
|
384
|
+
// is visible to `git status` and one `git add -A` from being committed.
|
|
385
|
+
// * It cannot be under any vendor tree, because `stageFiles(entries, CLI_VENDOR)`
|
|
386
|
+
// deletes those — the lock would be destroyed by the very thing it guards.
|
|
387
|
+
//
|
|
388
|
+
// `.git` is per-checkout (so the `aegiscode-plugin-verify-main` worktree locks
|
|
389
|
+
// independently, correctly), is never packed by `npm pack`, and is reachable
|
|
390
|
+
// from every stager for this tree. In a linked worktree `.git` is a FILE
|
|
391
|
+
// (`gitdir: …`) rather than a directory, so it is followed to its gitdir.
|
|
392
|
+
const LOCK_WAIT_MS = 120000; // how long to wait for a peer before giving up
|
|
393
|
+
const LOCK_STALE_MS = 600000; // a lock older than this is abandoned, not held
|
|
394
|
+
const LOCK_POLL_MS = 50;
|
|
395
|
+
/** The token a holder hands to its own descendants through the environment. */
|
|
396
|
+
const LOCK_ENV = 'AEGISONE_PREDIST_LOCK_TOKEN';
|
|
397
|
+
|
|
398
|
+
/** The lock file this process is inside, or null. */
|
|
399
|
+
let LOCK_HELD = null;
|
|
400
|
+
/** Only the process that CREATED the lock unlinks it. */
|
|
401
|
+
let LOCK_OWNS = false;
|
|
402
|
+
/** In-process nesting: a reader may hold the lock while stage() is called. */
|
|
403
|
+
let LOCK_DEPTH = 0;
|
|
404
|
+
|
|
405
|
+
function lockFile() {
|
|
406
|
+
const dotGit = path.join(REPO_DIR, '.git');
|
|
407
|
+
let dir = dotGit;
|
|
408
|
+
try {
|
|
409
|
+
if (!fs.lstatSync(dotGit).isDirectory()) {
|
|
410
|
+
const m = /^gitdir:\s*(.+)$/m.exec(fs.readFileSync(dotGit, 'utf8'));
|
|
411
|
+
if (m) dir = path.resolve(REPO_DIR, m[1].trim());
|
|
412
|
+
}
|
|
413
|
+
} catch {
|
|
414
|
+
dir = dotGit; // no `.git` at all (an exported tree): the open below reports it
|
|
415
|
+
}
|
|
416
|
+
return path.join(dir, 'aegisone-predist.lock');
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** Is `pid` a live process? Signal 0 tests existence without signalling. */
|
|
420
|
+
function pidAlive(pid) {
|
|
421
|
+
try {
|
|
422
|
+
process.kill(pid, 0);
|
|
423
|
+
return true;
|
|
424
|
+
} catch (error) {
|
|
425
|
+
// EPERM means it exists and belongs to someone else — still alive.
|
|
426
|
+
return Boolean(error) && error.code === 'EPERM';
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Take the staging lock, or adopt the one an ANCESTOR already holds.
|
|
434
|
+
*
|
|
435
|
+
* Waiting is the right failure mode against a peer, and failing fast would not
|
|
436
|
+
* be: the peer is about to produce exactly the tree this run wants, so the two
|
|
437
|
+
* are not so much competing for a resource as queueing for it. A stale lock is
|
|
438
|
+
* broken (dead pid, or older than LOCK_STALE_MS) so a killed stager cannot wedge
|
|
439
|
+
* every later run — the alternative, a lock no one can clear, trades a rare
|
|
440
|
+
* flake for a permanent one.
|
|
441
|
+
*
|
|
442
|
+
* ADOPTION is what makes the lock usable by a *reader*. `test/one-vendor.test.mjs`
|
|
443
|
+
* asserts on the staged trees, and it also spawns both wrapper scripts with
|
|
444
|
+
* `spawnSync` — which BLOCKS its own process. If those children had to queue for
|
|
445
|
+
* a lock their parent is holding, the parent would block waiting for a child
|
|
446
|
+
* that is waiting for the parent: a guaranteed 120-second deadlock, in the gate
|
|
447
|
+
* that is supposed to prove staging works. So the holder writes a random token
|
|
448
|
+
* into the lock file and exports it; a descendant that sees its OWN token in the
|
|
449
|
+
* file is the same logical stager, runs immediately, and leaves the unlinking to
|
|
450
|
+
* the process that created it.
|
|
451
|
+
*/
|
|
452
|
+
async function takeLock(log) {
|
|
453
|
+
const file = lockFile();
|
|
454
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
455
|
+
const inherited = process.env[LOCK_ENV] || null;
|
|
456
|
+
let token = null;
|
|
457
|
+
let announced = false;
|
|
458
|
+
for (;;) {
|
|
459
|
+
// Adopt before waiting: the lock is held by our own ancestor.
|
|
460
|
+
if (inherited) {
|
|
461
|
+
try {
|
|
462
|
+
const tokenLine = String(fs.readFileSync(file, 'utf8')).split('\n')[1];
|
|
463
|
+
// The token match IS the test: it is a random value that only ever
|
|
464
|
+
// existed inside this process tree, so a foreign holder's file cannot
|
|
465
|
+
// match it and we will queue for that one like anybody else.
|
|
466
|
+
if (tokenLine && tokenLine.trim() === inherited) {
|
|
467
|
+
LOCK_HELD = file;
|
|
468
|
+
LOCK_OWNS = false;
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
} catch {
|
|
472
|
+
/* no lock file: fall through and take it normally */
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
try {
|
|
476
|
+
token = `${Date.now().toString(36)}-${process.pid}-${Math.random().toString(36).slice(2, 10)}`;
|
|
477
|
+
const fd = fs.openSync(file, 'wx'); // atomic create-or-fail
|
|
478
|
+
fs.writeSync(fd, `${process.pid}\n${token}\n`);
|
|
479
|
+
fs.closeSync(fd);
|
|
480
|
+
LOCK_HELD = file;
|
|
481
|
+
LOCK_OWNS = true;
|
|
482
|
+
// Handed to every descendant for the duration, so a stager this process
|
|
483
|
+
// spawns (the two wrappers the suite runs) does not deadlock against us.
|
|
484
|
+
process.env[LOCK_ENV] = token;
|
|
485
|
+
return;
|
|
486
|
+
} catch (error) {
|
|
487
|
+
if (!error || error.code !== 'EEXIST') throw error;
|
|
488
|
+
}
|
|
489
|
+
// Somebody holds it. Decide whether they are still alive.
|
|
490
|
+
let stat = null;
|
|
491
|
+
let holder = 0;
|
|
492
|
+
try {
|
|
493
|
+
stat = fs.statSync(file);
|
|
494
|
+
holder = Number(String(fs.readFileSync(file, 'utf8')).split('\n')[0].trim());
|
|
495
|
+
} catch {
|
|
496
|
+
continue; // released between the open and the stat — retry immediately
|
|
497
|
+
}
|
|
498
|
+
const abandoned =
|
|
499
|
+
Date.now() - stat.mtimeMs > LOCK_STALE_MS ||
|
|
500
|
+
(Number.isFinite(holder) && holder > 0 && !pidAlive(holder));
|
|
501
|
+
if (abandoned) {
|
|
502
|
+
log(`predist: breaking an abandoned staging lock (pid ${holder || 'unknown'})`);
|
|
503
|
+
try {
|
|
504
|
+
fs.unlinkSync(file);
|
|
505
|
+
} catch {
|
|
506
|
+
/* the holder released it first — the next open will succeed */
|
|
507
|
+
}
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
if (Date.now() > deadline) {
|
|
511
|
+
throw new Error(
|
|
512
|
+
`predist: another stager (pid ${holder || 'unknown'}) has held ${file} for over ` +
|
|
513
|
+
`${Math.round(LOCK_WAIT_MS / 1000)}s. Staging is destructive — it removes and ` +
|
|
514
|
+
'rewrites cli/vendor, desktop/vendor and one/vendor — so it will not run ' +
|
|
515
|
+
'concurrently with a peer. Wait for it, or delete the lock if that process is gone.'
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
if (!announced) {
|
|
519
|
+
announced = true;
|
|
520
|
+
log(
|
|
521
|
+
`predist: another stager (pid ${holder || 'unknown'}) is running — waiting for it ` +
|
|
522
|
+
'(concurrent staging would read a vendor tree the peer is rewriting)'
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
await sleep(LOCK_POLL_MS + Math.floor(Math.random() * LOCK_POLL_MS));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function releaseLock() {
|
|
530
|
+
if (LOCK_DEPTH > 0) {
|
|
531
|
+
LOCK_DEPTH--;
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
const file = LOCK_HELD;
|
|
535
|
+
const owns = LOCK_OWNS;
|
|
536
|
+
const token = process.env[LOCK_ENV];
|
|
537
|
+
LOCK_HELD = null;
|
|
538
|
+
LOCK_OWNS = false;
|
|
539
|
+
if (!file || !owns) return; // an adopted lock is released by its creator
|
|
540
|
+
if (token) delete process.env[LOCK_ENV];
|
|
541
|
+
try {
|
|
542
|
+
fs.unlinkSync(file);
|
|
543
|
+
} catch {
|
|
544
|
+
/* already gone, or broken as stale by a peer — either way we no longer hold it */
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Hold the staging lock across an arbitrary span — staging AND the reads that
|
|
550
|
+
* check what was staged — releasing when the returned function is called.
|
|
551
|
+
*
|
|
552
|
+
* Exported because a reader is a legitimate participant: whoever asserts on
|
|
553
|
+
* `cli/vendor/` while another process may be re-staging it has the same race as
|
|
554
|
+
* two stagers do, and `stage()`'s own critical section ends too early to cover
|
|
555
|
+
* the assertions that follow it. Re-entrant in-process (a holder may call
|
|
556
|
+
* `stage()`), and adopted by descendants through LOCK_ENV — see `takeLock`.
|
|
557
|
+
*
|
|
558
|
+
* @param {{stdout?: object}} [io] where the "waiting for a peer" line is written
|
|
559
|
+
* @returns {Promise<() => void>} the release function
|
|
560
|
+
*/
|
|
561
|
+
export async function acquireStageLock(io) {
|
|
562
|
+
if (LOCK_HELD) {
|
|
563
|
+
LOCK_DEPTH++;
|
|
564
|
+
return releaseLock;
|
|
565
|
+
}
|
|
566
|
+
const out = (io && io.stdout) || process.stdout;
|
|
567
|
+
await takeLock((line) => out.write(`${line}\n`));
|
|
568
|
+
return releaseLock;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// ---------------------------------------------------------------------------
|
|
572
|
+
// Staging primitives
|
|
573
|
+
// ---------------------------------------------------------------------------
|
|
574
|
+
|
|
575
|
+
function stageFiles(entries, removeRoot) {
|
|
576
|
+
if (removeRoot) fs.rmSync(removeRoot, { recursive: true, force: true });
|
|
577
|
+
const staged = [];
|
|
578
|
+
for (const entry of entries) {
|
|
579
|
+
if (!fs.existsSync(entry.from)) {
|
|
580
|
+
throw new Error(`predist: missing shared module: ${entry.src} (expected at ${entry.from})`);
|
|
581
|
+
}
|
|
582
|
+
fs.mkdirSync(path.dirname(entry.dest), { recursive: true });
|
|
583
|
+
fs.copyFileSync(entry.from, entry.dest);
|
|
584
|
+
if (!fs.readFileSync(entry.from).equals(fs.readFileSync(entry.dest))) {
|
|
585
|
+
throw new Error(`predist: staged copy differs from source: ${entry.src}`);
|
|
586
|
+
}
|
|
587
|
+
staged.push(entry);
|
|
588
|
+
}
|
|
589
|
+
return staged;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// ---------------------------------------------------------------------------
|
|
593
|
+
// Proofs
|
|
594
|
+
// ---------------------------------------------------------------------------
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* The CLI's standalone-load proof, carried over unchanged in substance: the
|
|
598
|
+
* staged registry must build from inside `cli/vendor/`, the editor layer must
|
|
599
|
+
* resolve the STAGED server (not a checkout path), and the staged gate module
|
|
600
|
+
* must load.
|
|
601
|
+
*/
|
|
602
|
+
function proveMirror(staged) {
|
|
603
|
+
const toolsPath = path.join(CLI_VENDOR, 'mcp', 'tools.js');
|
|
604
|
+
delete require.cache[require.resolve(toolsPath)];
|
|
605
|
+
const { createTools } = require(toolsPath);
|
|
606
|
+
const tools = createTools({
|
|
607
|
+
apiBase: 'http://127.0.0.1',
|
|
608
|
+
apiKey: 'predist-probe',
|
|
609
|
+
randomUUID: () => 'id',
|
|
610
|
+
});
|
|
611
|
+
const count = tools.toolList().length;
|
|
612
|
+
if (count === 0) throw new Error('predist: staged registry exposes no tools');
|
|
613
|
+
|
|
614
|
+
// mcp/server.js registers process.stdin handlers at LOAD time and exports
|
|
615
|
+
// nothing, so requiring it would take over this process's stdin and it would
|
|
616
|
+
// never exit. It is verified by COMPILING it instead.
|
|
617
|
+
const vm = require('node:vm');
|
|
618
|
+
const serverJs = path.join(CLI_VENDOR, 'mcp', 'server.js');
|
|
619
|
+
new vm.Script(fs.readFileSync(serverJs, 'utf8'), { filename: serverJs });
|
|
620
|
+
|
|
621
|
+
const hostsDir = path.join(CLI_VENDOR, 'hosts');
|
|
622
|
+
const spec = require(path.join(hostsDir, 'spec.js'));
|
|
623
|
+
const install = require(path.join(hostsDir, 'install.js'));
|
|
624
|
+
const targets = require(path.join(hostsDir, 'targets.js'));
|
|
625
|
+
|
|
626
|
+
// An empty AEGIS_MCP_SERVER so a developer's own override cannot mask a
|
|
627
|
+
// broken staged tree: the candidate asserted on must be the staged one.
|
|
628
|
+
const resolved = spec.resolveServer({ AEGIS_MCP_SERVER: '' });
|
|
629
|
+
if (!resolved.exists || resolved.path !== serverJs) {
|
|
630
|
+
throw new Error(
|
|
631
|
+
`predist: staged hosts/spec.js resolves the server as ${resolved.path} ` +
|
|
632
|
+
`(exists: ${resolved.exists}), expected ${serverJs}. An installed aegiscode ` +
|
|
633
|
+
`would write editor configs pointing at a file the package never shipped. ` +
|
|
634
|
+
`Candidates were:\n ${resolved.candidates.join('\n ')}`
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// Plan one real install against a throwaway home: the exact document
|
|
639
|
+
// `aegiscode mcp install vscode` would write, so the cheapest possible proof
|
|
640
|
+
// that the packaged command points at a file that exists.
|
|
641
|
+
const vscode = targets.getTarget('vscode');
|
|
642
|
+
const plan = install.planTarget(vscode, 'user', {
|
|
643
|
+
ctx: install.hostCtx({ home: path.join(CLI_VENDOR, '.predist-home'), env: {}, cwd: REPO_DIR }),
|
|
644
|
+
specOpts: { env: { AEGIS_MCP_SERVER: '' } },
|
|
645
|
+
});
|
|
646
|
+
const wrote = JSON.stringify(plan.after || '');
|
|
647
|
+
if (
|
|
648
|
+
plan.error ||
|
|
649
|
+
!plan.changed ||
|
|
650
|
+
!wrote.includes(JSON.stringify(serverJs).slice(1, -1))
|
|
651
|
+
) {
|
|
652
|
+
throw new Error(
|
|
653
|
+
`predist: a planned vscode install does not name the staged server ` +
|
|
654
|
+
`(error: ${plan.error && plan.error.message}, changed: ${plan.changed})`
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
const shim = require(path.join(hostsDir, 'openai-shim.js'));
|
|
659
|
+
if (typeof shim.createShimServer !== 'function') {
|
|
660
|
+
throw new Error('predist: staged hosts/openai-shim.js exposes no createShimServer');
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
return { count, targets: targets.targetIds().length, staged: staged.length };
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/** The gate is an ES module, so its proof is a dynamic import. */
|
|
667
|
+
async function proveGate() {
|
|
668
|
+
const gateStagedPath = path.join(CLI_VENDOR, 'tools', 'agent-gate.mjs');
|
|
669
|
+
const gateMod = await import(pathToFileURL(gateStagedPath).href);
|
|
670
|
+
if (typeof gateMod.run !== 'function') {
|
|
671
|
+
throw new Error('predist: staged tools/agent-gate.mjs exposes no run()');
|
|
672
|
+
}
|
|
673
|
+
return gateStagedPath;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* The desktop's standalone-load proof — the property flattening depends on and
|
|
678
|
+
* which nothing asserted before: a flat-staged module must resolve its siblings
|
|
679
|
+
* from the SAME vendor directory. A `require('../client/...')` that survived
|
|
680
|
+
* flattening would resolve outside the packaged app (electron-builder cannot
|
|
681
|
+
* ship those files at all), so it is a hard failure here rather than a
|
|
682
|
+
* MODULE_NOT_FOUND in a user's window.
|
|
683
|
+
*/
|
|
684
|
+
/**
|
|
685
|
+
* Drop comments before scanning for requires. `client/aegis.js` documents its
|
|
686
|
+
* own usage as `require('./client/aegis.js')` inside a JSDoc block, which a raw
|
|
687
|
+
* scan reads as a self-referential dependency — the first run of this proof
|
|
688
|
+
* failed on exactly that line, which is why the strip is here and not in a
|
|
689
|
+
* comment promising it happens.
|
|
690
|
+
*/
|
|
691
|
+
function stripComments(source) {
|
|
692
|
+
return source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/(^|[^:])\/\/.*$/gm, '$1');
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function proveFlat(staged) {
|
|
696
|
+
const flatNames = new Set(staged.map((e) => path.basename(e.dest)));
|
|
697
|
+
for (const entry of staged) {
|
|
698
|
+
const src = stripComments(fs.readFileSync(entry.dest, 'utf8'));
|
|
699
|
+
for (const m of src.matchAll(/require\(\s*'((?:\.\.?\/)[^']+)'\s*\)/g)) {
|
|
700
|
+
const spec = m[1];
|
|
701
|
+
const target = path.basename(spec).replace(/\.[cm]?js$/, '');
|
|
702
|
+
const sibling = spec.replace(/^\.\//, '');
|
|
703
|
+
if (sibling.startsWith('../')) {
|
|
704
|
+
throw new Error(
|
|
705
|
+
`predist: flat-staged ${path.basename(entry.dest)} requires '${spec}', ` +
|
|
706
|
+
'which escapes vendor/ — flattening only works for same-directory requires ' +
|
|
707
|
+
`(add the target to the manifest, or stop staging this file flat)${target ? '' : ''}`
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
const asFile = spec.replace(/^\.\//, '');
|
|
711
|
+
if (!flatNames.has(asFile)) {
|
|
712
|
+
throw new Error(
|
|
713
|
+
`predist: flat-staged ${path.basename(entry.dest)} requires '${spec}', ` +
|
|
714
|
+
`which is not staged into desktop/vendor/ — the packaged app would throw ` +
|
|
715
|
+
'MODULE_NOT_FOUND before the window could open'
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
// …and the transport itself must actually LOAD from the flattened tree.
|
|
722
|
+
const transport = require(path.join(DESKTOP_VENDOR, 'aegis.js'));
|
|
723
|
+
if (!transport || Object.keys(transport).length === 0) {
|
|
724
|
+
throw new Error('predist: staged desktop/vendor/aegis.js loads but exports nothing');
|
|
725
|
+
}
|
|
726
|
+
return { files: staged.length, exports: Object.keys(transport).length };
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* The bundle proof: `one/vendor/cli` must resolve EVERY shared module from
|
|
731
|
+
* inside the PRODUCT BUNDLE (`one/vendor/`), never from the repo checkout.
|
|
732
|
+
*
|
|
733
|
+
* The boundary is the bundle root and not `one/vendor/cli`, and that is not a
|
|
734
|
+
* softened assertion — it is the layout rule itself. The bundle keeps the repo's
|
|
735
|
+
* shape with the two faces as SIBLINGS (`one/vendor/cli`, `one/vendor/desktop`),
|
|
736
|
+
* so `cli/src/deps.js`'s repo-shaped candidate `../desktop/renderer/usage.js`
|
|
737
|
+
* lands on the bundled desktop face exactly as it does in a checkout. The first
|
|
738
|
+
* run of this proof failed on that path, which is how the rule got written down
|
|
739
|
+
* here instead of being assumed: it is the sibling face copy, one directory
|
|
740
|
+
* over, not the repo.
|
|
741
|
+
*
|
|
742
|
+
* It runs as a child process with its cwd inside the bundle, so a path that only
|
|
743
|
+
* exists in the repo fails here rather than after `npm i -g aegisone`.
|
|
744
|
+
*/
|
|
745
|
+
function proveBundle() {
|
|
746
|
+
const bundleCli = path.join(ONE_VENDOR, 'cli');
|
|
747
|
+
const depsPath = path.join(bundleCli, 'src', 'deps.js');
|
|
748
|
+
const script =
|
|
749
|
+
'const d=require(process.argv[1]);' +
|
|
750
|
+
'console.log(JSON.stringify(d.paths))';
|
|
751
|
+
const res = spawnSync(process.execPath, ['-e', script, depsPath], {
|
|
752
|
+
cwd: bundleCli,
|
|
753
|
+
encoding: 'utf8',
|
|
754
|
+
});
|
|
755
|
+
if (res.status !== 0) {
|
|
756
|
+
throw new Error(`predist: the bundled CLI does not load: ${res.stderr || res.stdout}`);
|
|
757
|
+
}
|
|
758
|
+
const paths = JSON.parse(res.stdout);
|
|
759
|
+
const outside = [];
|
|
760
|
+
let inSiblingFace = 0;
|
|
761
|
+
for (const [name, p] of Object.entries(paths)) {
|
|
762
|
+
const rel = path.relative(ONE_VENDOR, p);
|
|
763
|
+
if (rel.startsWith('..') || path.isAbsolute(rel)) {
|
|
764
|
+
outside.push(`${name} -> ${p}`);
|
|
765
|
+
continue;
|
|
766
|
+
}
|
|
767
|
+
if (rel.split(path.sep)[0] !== 'cli') inSiblingFace++;
|
|
768
|
+
}
|
|
769
|
+
if (outside.length) {
|
|
770
|
+
throw new Error(
|
|
771
|
+
'predist: the bundled CLI resolves these shared modules OUTSIDE the bundle ' +
|
|
772
|
+
`(${ONE_VENDOR}) — the product tarball would depend on a repo checkout:\n ` +
|
|
773
|
+
outside.join('\n ')
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
const binShipped = fs.existsSync(path.join(bundleCli, 'bin', 'aegiscode.js'));
|
|
777
|
+
if (!binShipped) throw new Error('predist: the bundle has no cli/bin/aegiscode.js');
|
|
778
|
+
|
|
779
|
+
// Every bundled part keeps the shape its SOURCE had. This is the assertion
|
|
780
|
+
// that would have caught `main.js/main.js`: the module-resolution proof above
|
|
781
|
+
// says nothing about a face's own entry point, so a bundle can pass every
|
|
782
|
+
// check here and still pack without the file the desktop face is launched by.
|
|
783
|
+
const wrongShape = [];
|
|
784
|
+
for (const [name, dir, parts] of BUNDLE_SOURCES) {
|
|
785
|
+
for (const part of parts) {
|
|
786
|
+
const dest = path.join(ONE_VENDOR, name, part);
|
|
787
|
+
let srcStat = null;
|
|
788
|
+
let destStat = null;
|
|
789
|
+
try {
|
|
790
|
+
srcStat = fs.lstatSync(path.join(dir, part));
|
|
791
|
+
} catch {
|
|
792
|
+
continue; // reported by the staging loop
|
|
793
|
+
}
|
|
794
|
+
try {
|
|
795
|
+
destStat = fs.lstatSync(dest);
|
|
796
|
+
} catch {
|
|
797
|
+
wrongShape.push(`${name}/${part} -> missing`);
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
if (srcStat.isFile() && !destStat.isFile()) wrongShape.push(`${name}/${part} -> not a regular file`);
|
|
801
|
+
if (srcStat.isDirectory() && !destStat.isDirectory()) wrongShape.push(`${name}/${part} -> not a directory`);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
if (wrongShape.length) {
|
|
805
|
+
throw new Error(`predist: the bundle staged these in the wrong shape:\n ${wrongShape.join('\n ')}`);
|
|
806
|
+
}
|
|
807
|
+
return { modules: Object.keys(paths).length, inSiblingFace };
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
// ---------------------------------------------------------------------------
|
|
811
|
+
// The one entry point
|
|
812
|
+
// ---------------------------------------------------------------------------
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Stage every requested shape, then prove what was staged.
|
|
816
|
+
*
|
|
817
|
+
* @param {object} [opts]
|
|
818
|
+
* @param {string[]} [opts.shapes] subset of SHAPES plus 'bundle'
|
|
819
|
+
* @param {object} [opts.io] { stdout, stderr } — injectable, so a test can
|
|
820
|
+
* capture this without capturing the process
|
|
821
|
+
* @returns {Promise<object>} a report of what was staged and proven
|
|
822
|
+
*/
|
|
823
|
+
export async function stage(opts) {
|
|
824
|
+
const o = opts || {};
|
|
825
|
+
const io = o.io || {};
|
|
826
|
+
const out = io.stdout || process.stdout;
|
|
827
|
+
const errOut = io.stderr || process.stderr;
|
|
828
|
+
const shapes = Array.isArray(o.shapes) ? o.shapes : [...SHAPES, 'bundle'];
|
|
829
|
+
const want = (s) => shapes.includes(s);
|
|
830
|
+
const log = (line) => out.write(`${line}\n`);
|
|
831
|
+
|
|
832
|
+
// The whole body is one critical section: every shape below removes and
|
|
833
|
+
// rewrites a shared tree, and the proofs read those trees back. Held from
|
|
834
|
+
// here to the end, released even when a proof throws — a thrown proof that
|
|
835
|
+
// kept the lock would wedge every later run in this checkout. A caller that
|
|
836
|
+
// already holds it (a test asserting on the staged trees) keeps holding it:
|
|
837
|
+
// `acquireStageLock` nests in-process.
|
|
838
|
+
const release = await acquireStageLock(io);
|
|
839
|
+
try {
|
|
840
|
+
return await stageLocked({ want, log });
|
|
841
|
+
} finally {
|
|
842
|
+
release();
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
async function stageLocked({ want, log }) {
|
|
847
|
+
const report = { mirror: null, flat: null, nested: null, bundle: null };
|
|
848
|
+
|
|
849
|
+
if (want('mirror')) {
|
|
850
|
+
const staged = stageFiles(entriesFor('mirror'), CLI_VENDOR);
|
|
851
|
+
log(`predist: staged ${staged.length} shared modules into cli/vendor/`);
|
|
852
|
+
for (const e of staged) log(` ${e.src} -> vendor/${e.src}`);
|
|
853
|
+
report.mirror = { staged: staged.length };
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
if (want('nested')) {
|
|
857
|
+
report.nested = { staged: stageFiles(entriesFor('nested'), null).length };
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
if (want('flat')) {
|
|
861
|
+
const staged = stageFiles(entriesFor('flat'), null);
|
|
862
|
+
for (const e of staged) log(`staged ${e.dest}`);
|
|
863
|
+
report.flat = { staged: staged.length };
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// One manifest, two shapes: wherever a module appears twice, the two copies
|
|
867
|
+
// must be byte-identical to EACH OTHER as well as to the source. Nothing
|
|
868
|
+
// asserted this before, and it is the whole payoff of a single manifest.
|
|
869
|
+
if (want('mirror') && want('flat')) {
|
|
870
|
+
for (const row of MANIFEST) {
|
|
871
|
+
if (!row.shapes.includes('mirror') || !row.shapes.includes('flat')) continue;
|
|
872
|
+
const a = path.join(CLI_VENDOR, row.src);
|
|
873
|
+
const b = path.join(DESKTOP_VENDOR, path.basename(row.src));
|
|
874
|
+
if (!fs.readFileSync(a).equals(fs.readFileSync(b))) {
|
|
875
|
+
throw new Error(`predist: the two shapes disagree for ${row.src}`);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
if (want('mirror')) {
|
|
881
|
+
const p = proveMirror(entriesFor('mirror'));
|
|
882
|
+
log(`predist: staged registry loads standalone (${p.count} tools)`);
|
|
883
|
+
log(
|
|
884
|
+
`predist: editor layer verified (${p.targets} host targets, ` +
|
|
885
|
+
`server resolves to vendor/mcp/server.js, shim loads)`
|
|
886
|
+
);
|
|
887
|
+
const gate = await proveGate();
|
|
888
|
+
log(`predist: ${path.relative(REPO_DIR, gate)} loads standalone and exposes run()`);
|
|
889
|
+
report.mirror.proof = p;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
if (want('flat')) {
|
|
893
|
+
const p = proveFlat(entriesFor('flat'));
|
|
894
|
+
log(
|
|
895
|
+
`predist: flattened tree is self-contained (${p.files} files, ` +
|
|
896
|
+
`${p.exports} transport exports) — no staged module escapes vendor/`
|
|
897
|
+
);
|
|
898
|
+
report.flat.proof = p;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
if (want('bundle')) {
|
|
902
|
+
for (const [name, dir, parts] of BUNDLE_SOURCES) {
|
|
903
|
+
const to = path.join(ONE_VENDOR, name);
|
|
904
|
+
fs.rmSync(to, { recursive: true, force: true });
|
|
905
|
+
for (const part of parts) {
|
|
906
|
+
const from = path.join(dir, part);
|
|
907
|
+
if (!fs.existsSync(from)) {
|
|
908
|
+
if (part === 'LICENSE' || part === 'README.md') continue;
|
|
909
|
+
throw new Error(`predist: bundle source missing: ${path.relative(REPO_DIR, from)}`);
|
|
910
|
+
}
|
|
911
|
+
copyTree(from, path.join(to, part));
|
|
912
|
+
}
|
|
913
|
+
log(`staged the ${name} face into one/vendor/${name}/`);
|
|
914
|
+
}
|
|
915
|
+
const p = proveBundle();
|
|
916
|
+
log(
|
|
917
|
+
`predist: the bundled CLI resolves ${p.modules} shared modules from inside ` +
|
|
918
|
+
`one/vendor/ (${p.inSiblingFace} through the bundled desktop face) — ` +
|
|
919
|
+
'no repo checkout needed'
|
|
920
|
+
);
|
|
921
|
+
report.bundle = p;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
return report;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* CLI entry. `argv` and the streams are parameters so the seam survives: a test
|
|
929
|
+
* passes its own, and nothing in this file reads the process at module scope.
|
|
930
|
+
*/
|
|
931
|
+
export async function main(argv, io) {
|
|
932
|
+
const o = io || {};
|
|
933
|
+
const args = Array.isArray(argv) ? argv : [];
|
|
934
|
+
// `--quiet` is not cosmetic: `prepack` runs this stager, and `npm pack --json`
|
|
935
|
+
// interleaves hook stdout with its own JSON report. A caller that parses that
|
|
936
|
+
// report (`test/one-pack-boot.test.mjs`) gets the progress lines instead of
|
|
937
|
+
// JSON and fails. So the progress stream is silenced here rather than by
|
|
938
|
+
// every caller remembering to.
|
|
939
|
+
const quiet = args.includes('--quiet');
|
|
940
|
+
const sink = { write: () => true };
|
|
941
|
+
const out = quiet ? sink : o.stdout || process.stdout;
|
|
942
|
+
const errOut = o.stderr || process.stderr;
|
|
943
|
+
let shapes;
|
|
944
|
+
if (args.includes('--mirror-only')) shapes = ['mirror'];
|
|
945
|
+
else if (args.includes('--flat-only')) shapes = ['flat', 'nested'];
|
|
946
|
+
else if (args.includes('--bundle-only')) shapes = ['bundle'];
|
|
947
|
+
try {
|
|
948
|
+
await stage({ shapes, io: { stdout: out, stderr: errOut } });
|
|
949
|
+
return 0;
|
|
950
|
+
} catch (error) {
|
|
951
|
+
errOut.write(`${error && error.message}\n`);
|
|
952
|
+
return 1;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* Run when — and only when — this file was started directly
|
|
958
|
+
* (`node one/scripts/predist.mjs`). The process reads live inside a function on
|
|
959
|
+
* purpose: the seam rule for `one/` is that no `process.*` is read at module
|
|
960
|
+
* scope, and this is the file that would have broken it.
|
|
961
|
+
*/
|
|
962
|
+
function runIfDirect() {
|
|
963
|
+
const entry = process.argv[1];
|
|
964
|
+
let direct = false;
|
|
965
|
+
if (entry) {
|
|
966
|
+
try {
|
|
967
|
+
direct = path.resolve(entry) === fileURLToPath(import.meta.url);
|
|
968
|
+
} catch {
|
|
969
|
+
direct = false;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
if (!direct) return false;
|
|
973
|
+
main(process.argv.slice(2)).then((code) => {
|
|
974
|
+
process.exitCode = code;
|
|
975
|
+
});
|
|
976
|
+
return true;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
runIfDirect();
|