@automaton-labs/aib 0.0.5 → 0.0.6
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/dist/bin/cli.js +2 -2
- package/dist/commands/config-command.js +2 -1
- package/dist/commands/config-output.js +10 -8
- package/dist/commands/doctor.js +2 -1
- package/dist/commands/help-command.js +4 -4
- package/dist/commands/inspect-format.js +1 -1
- package/dist/commands/quick-read.js +8 -8
- package/dist/commands/result-view.js +5 -5
- package/dist/commands/session-workspace.js +7 -7
- package/dist/config/workspace-root.js +3 -3
- package/dist/help/bootstrap.md +4 -7
- package/dist/help/docs/help-format.md +4 -7
- package/dist/help/dsl/bootstrap.md +4 -7
- package/dist/help/dsl/docs/help-format.md +4 -7
- package/dist/help/dsl/full.md +4 -7
- package/dist/help/dsl/topics/help-format.md +4 -7
- package/dist/help/full.md +4 -7
- package/dist/help/help-meta.json +5 -5
- package/dist/help/json/bootstrap.md +4 -7
- package/dist/help/json/docs/help-format.md +4 -7
- package/dist/help/json/full.md +4 -7
- package/dist/help/json/topics/help-format.md +4 -7
- package/dist/help/topics/help-format.md +4 -7
- package/dist/managed-host/serve-web-autostart.js +1 -1
- package/dist/managed-host/serve-web-host.cjs +193 -79
- package/dist/observability/config.js +1 -1
- package/dist/payloads/read-stdin-json.js +1 -1
- package/dist/runtime/managed-runtime-provisioning.js +1 -1
- package/dist/runtime/run-command.js +1 -1
- package/dist/session/server.js +7 -5
- package/dist/shared/errors.js +14 -13
- package/dist/shared/stdin-examples.js +3 -0
- package/dist/tracing/trace.js +5 -3
- package/extension/vscode-refactor-bridge-extension.vsix +0 -0
- package/package.json +1 -1
- package/runtimes/launcher/linux-x64/aib +0 -0
- package/runtimes/launcher/win-x64/aib.exe +0 -0
- package/scripts/provision-runtime.cjs +25 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";var De=exports&&exports.__createBinding||(Object.create?(function(e,t,n,s){s===void 0&&(s=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,s,i)}):(function(e,t,n,s){s===void 0&&(s=n),e[s]=t[n]})),$e=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),ie=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(n){var s=[];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(s[s.length]=i);return s},e(t)};return function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var s=e(t),i=0;i<s.length;i++)s[i]!=="default"&&De(n,t,s[i]);return $e(n,t),n}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.isSessionHandle=M,exports.runWithSessionOverride=Ue,exports.runSessionWorkspaceCommand=Fe,exports.resolveSessionFileArgument=B,exports.saveSessionOutputJson=qe,exports.saveSessionOutputText=et,exports.saveSessionResultJson=tt,exports.saveSessionResultViewJson=nt,exports.readSessionResultViewJson=st,exports.readSessionResultJson=it,exports.captureSessionInputJson=rt,exports.captureSessionInput=ae,exports.sessionWorkspaceExists=ot,exports.useSessionGuidance=ue,exports.readSessionBooleanPref=at,exports.readSessionNumberPref=ut,exports.readSessionStringPref=ct,exports.readEffectiveSessionPathAliases=lt,exports.readSessionPathAliasOverrides=ft,exports.tryResolveCurrentSessionId=Ut;const l=ie(require("node:fs")),c=ie(require("node:path")),xe=require("node:async_hooks"),E=require("../config/env-vars"),
|
|
2
|
-
`));(0,
|
|
1
|
+
"use strict";var De=exports&&exports.__createBinding||(Object.create?(function(e,t,n,s){s===void 0&&(s=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,s,i)}):(function(e,t,n,s){s===void 0&&(s=n),e[s]=t[n]})),$e=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),ie=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(n){var s=[];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(s[s.length]=i);return s},e(t)};return function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var s=e(t),i=0;i<s.length;i++)s[i]!=="default"&&De(n,t,s[i]);return $e(n,t),n}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.isSessionHandle=M,exports.runWithSessionOverride=Ue,exports.runSessionWorkspaceCommand=Fe,exports.resolveSessionFileArgument=B,exports.saveSessionOutputJson=qe,exports.saveSessionOutputText=et,exports.saveSessionResultJson=tt,exports.saveSessionResultViewJson=nt,exports.readSessionResultViewJson=st,exports.readSessionResultJson=it,exports.captureSessionInputJson=rt,exports.captureSessionInput=ae,exports.sessionWorkspaceExists=ot,exports.useSessionGuidance=ue,exports.readSessionBooleanPref=at,exports.readSessionNumberPref=ut,exports.readSessionStringPref=ct,exports.readEffectiveSessionPathAliases=lt,exports.readSessionPathAliasOverrides=ft,exports.tryResolveCurrentSessionId=Ut;const l=ie(require("node:fs")),c=ie(require("node:path")),xe=require("node:async_hooks"),E=require("../config/env-vars"),_=require("../config/workspace-root"),b=require("../config/path-aliases"),m=require("../shared/agent-text"),u=require("../shared/errors"),je=c.join(".tmp","aib"),U="sessionDir",Ce="session.json",we="active.json",Re="aib:",Le="s_",Pe="last",Te="_last.json",F=new xe.AsyncLocalStorage,ke=["graph","inspect","code","slice","members","exports","deps","usages","duplicates","execution","rename","move","refactor","modulePlan","imports"],We=["inspect","graph","rename","move","refactor","modulePlan","imports","generic"],O={"guidance.nextLimit":{type:"number",default:2,min:0,max:100,hidden:!0},"diagnostics.hintLimit":{type:"number",default:2,min:0,max:100,hidden:!0},"inspect.code.show":{type:"boolean",default:!0,hidden:!0},"inspect.code.maxNonEmptyLines":{type:"number",default:120,min:1,max:1e4},"inspect.code.meta":{type:"boolean",default:!0,hidden:!0},"inspect.members.maxItems":{type:"number",default:20,min:1,max:1e3},"inspect.members.all":{type:"boolean",default:!1,hidden:!0},"inspect.exports.ranges":{type:"boolean",default:!1,hidden:!0},"inspect.exports.resolveStar":{type:"boolean",default:!1,hidden:!0},"inspect.graph.hubs":{type:"boolean",default:!0},"inspect.graph.entrypoints":{type:"boolean",default:!0},"inspect.graph.leaves":{type:"boolean",default:!0},"inspect.graph.edges":{type:"boolean",default:!0},"inspect.graph.symbols":{type:"boolean",default:!1,hidden:!0},"inspect.graph.symbolUsage":{type:"boolean",default:!1},"inspect.usages.detail":{type:"string",default:"locations",values:["summary","locations","code"],hidden:!0},"inspect.usages.maxLocations":{type:"number",default:12,min:1,max:1e4},"inspect.usages.maxCodeBlocks":{type:"number",default:8,min:1,max:1e4},"inspect.usages.excludeTarget":{type:"boolean",default:!1,hidden:!0}};function M(e){return e.startsWith(Re)}function Ue(e,t){return e?F.run(e,t):t()}function Fe(e,t,n){const s=t[0]??"status",i=(0,_.resolveWorkspaceRoot)(e);if(!i){if(s==="status")return(0,m.attachAgentText)({initialized:!1,active:null,source:"none",available:[],next:"Run aib help first-setup"},["session not ready","","No aib.json was found.","","If you are a user:","ask your agent to set up AIB for this repo:","aib help first-setup","","If you are an agent:","run:","aib help first-setup","","Then follow the setup from the intended repository root."].join(`
|
|
2
|
+
`));(0,_.resolveRequiredWorkspaceRoot)(e)}const r=i?.root??e;if(Rt(r),s==="init")return dt(r,t.slice(1));if(s==="status")return Dt(r);if(s==="list")return St(r);if(s==="use")return ht(r,t.slice(1));if(s==="where")return mt(r,t.slice(1));if(s==="read")return It(r,t.slice(1),n);if(s==="write")return Je(r,t.slice(1),n);if(s==="prefs")return Be(r,t.slice(1),n);if(s==="aliases")return Me(r,t.slice(1),n);if(s==="clear")return Ct(r);throw new u.CliError("UNKNOWN_SESSION_WORKSPACE_COMMAND",`Unknown session workspace command: ${s}`)}function Me(e,t,n){const s=t[0]??"get";if(s==="get"){const i=A(e),r=(0,b.readConfigPathAliases)(e),o=(0,b.normalizePathAliasMap)(i.pathAliases??{},"session path aliases"),a={aliases:(0,b.effectivePathAliases)(e,o),config:r,session:o};return(0,m.attachAgentText)(a,V(a))}if(s==="set"){const i=A(e),r=t.includes("--stdin")?Ve(n):ze(t.slice(1)),o=(0,b.normalizePathAliasMap)(i.pathAliases??{},"session path aliases"),a={};for(const[d,p]of Object.entries(r)){const S=(0,b.normalizePathAliasName)(d,"session path aliases");if(typeof p!="string"||p.trim()==="")throw new u.CliError("INVALID_PATH_ALIAS_TARGET",`session path alias ${d} must be a non-empty path string.`);o[S]=p.trim().replace(/\\/g,"/"),a[S]=o[S]}i.pathAliases=o,g(e,i);const f={updated:a,aliases:(0,b.effectivePathAliases)(e,o)};return(0,m.attachAgentText)(f,V(f))}if(s==="clear"){const i=A(e),r=t.slice(1).filter(d=>!d.startsWith("--")),o=(0,b.normalizePathAliasMap)(i.pathAliases??{},"session path aliases"),a=[];if(r.length===0)a.push(...Object.keys(o).sort()),delete i.pathAliases;else{for(const d of r){const p=(0,b.normalizePathAliasName)(d,"session path aliases");Object.prototype.hasOwnProperty.call(o,p)&&(a.push(p),delete o[p])}Object.keys(o).length>0?i.pathAliases=o:delete i.pathAliases}g(e,i);const f={cleared:a,aliases:(0,b.effectivePathAliases)(e,i.pathAliases??{})};return(0,m.attachAgentText)(f,V(f))}throw new u.CliError("UNKNOWN_SESSION_ALIASES_COMMAND",`Unknown session aliases command: ${s}`,{expected:"aib session aliases get | set | clear"})}function Ve(e){if(!y(e))throw new u.CliError("INVALID_SESSION_ALIASES_STDIN","session aliases set --stdin expects a JSON object.");const t=y(e.aliases)?e.aliases:e,n={};for(const[s,i]of Object.entries(t))typeof i=="string"&&(n[s]=i);return n}function ze(e){if(e.length===0||e.length%2!==0)throw new u.CliError("SESSION_ALIASES_SET_USAGE","Usage: aib session aliases set <name> <path> [<name> <path>...] or session aliases set --stdin");const t={};for(let n=0;n<e.length;n+=2)t[e[n]??""]=e[n+1]??"";return t}function V(e){if(y(e.updated))return re("aliases.updated",e.updated);if(Array.isArray(e.cleared)){const t=e.cleared.filter(n=>typeof n=="string");return t.length>0?["aliases.cleared",...t].join(`
|
|
3
3
|
`):"aliases.cleared none"}if(y(e.aliases)){const t=re("aliases",e.aliases).split(`
|
|
4
4
|
`);return t.length===1&&t.push("none"),t.join(`
|
|
5
5
|
`)}return null}function re(e,t){const n=[e];for(const[s,i]of Object.entries(t).sort(([r],[o])=>r.localeCompare(o)))n.push(`@${s}/=${String(i)}`);return n.join(`
|
|
6
|
-
`)}function Je(e,t,n){const s=t[0]??"",i=t[1]??"";if(!s||!i)throw new u.CliError("SESSION_WRITE_USAGE","Usage: aib session write <kind> <name> --stdin");if(n===void 0)throw new u.CliError("STDIN_REQUIRED","session write expects JSON on stdin and the --stdin flag.");const r=A(e),o=Z(r,s,i);x(o,n);const a=C(r,"inputs",s,i,o);Ne(r,s,n),g(e,r);const f={written:a.handle,file:h(e,o)},d=ue(e,"session.write.from",`Use with --from ${a.handle}`);return d&&(f.next=d),f}function Be(e,t,n){const s=t[0]??"get";if(s==="get"){const i=A(e),r=t.includes("--all"),o=t.slice(1).find(p=>!p.startsWith("--")),a=r?Ye(i):Ze(i.prefs??{}),f=Ke(a,o),d=r?{prefs:f}:{overrides:f,defaults:"omitted; use session prefs get --all"};return(0,m.attachAgentText)(d,z(d))}if(s==="set"){const i=A(e),r=t.includes("--stdin")?He(n):Ge(t.slice(1)),o=i.prefs??{},a={};for(const[d,p]of Object.entries(r)){const S=oe(d),
|
|
6
|
+
`)}function Je(e,t,n){const s=t[0]??"",i=t[1]??"";if(!s||!i)throw new u.CliError("SESSION_WRITE_USAGE","Usage: aib session write <kind> <name> --stdin");if(n===void 0)throw new u.CliError("STDIN_REQUIRED","session write expects JSON on stdin and the --stdin flag.");const r=A(e),o=Z(r,s,i);x(o,n);const a=C(r,"inputs",s,i,o);Ne(r,s,n),g(e,r);const f={written:a.handle,file:h(e,o)},d=ue(e,"session.write.from",`Use with --from ${a.handle}`);return d&&(f.next=d),f}function Be(e,t,n){const s=t[0]??"get";if(s==="get"){const i=A(e),r=t.includes("--all"),o=t.slice(1).find(p=>!p.startsWith("--")),a=r?Ye(i):Ze(i.prefs??{}),f=Ke(a,o),d=r?{prefs:f}:{overrides:f,defaults:"omitted; use session prefs get --all"};return(0,m.attachAgentText)(d,z(d))}if(s==="set"){const i=A(e),r=t.includes("--stdin")?He(n):Ge(t.slice(1)),o=i.prefs??{},a={};for(const[d,p]of Object.entries(r)){const S=oe(d),N=Qe(S,p);o[S]=N,a[S]=N}i.prefs=o,g(e,i);const f={updated:a};return(0,m.attachAgentText)(f,z(f))}if(s==="clear"){const i=A(e),r=t.slice(1).filter(d=>!d.startsWith("--")),o=i.prefs??{},a=[];if(r.length===0)a.push(...Object.keys(o).sort()),delete i.prefs;else{for(const d of r){const p=oe(d);Object.prototype.hasOwnProperty.call(o,p)&&(a.push(p),delete o[p])}Object.keys(o).length>0?i.prefs=o:delete i.prefs}g(e,i);const f={cleared:a};return(0,m.attachAgentText)(f,z(f))}throw new u.CliError("UNKNOWN_SESSION_PREFS_COMMAND",`Unknown session prefs command: ${s}`,{expected:"aib session prefs get | set | clear"})}function Ke(e,t){if(!t)return e;const n={};for(const[s,i]of Object.entries(e))(s===t||s.startsWith(`${t}.`))&&(n[s]=i);return n}function z(e){if(y(e.updated))return J("prefs.updated",e.updated);if(Array.isArray(e.cleared)){const t=e.cleared.filter(n=>typeof n=="string");return t.length>0?["prefs.cleared",...t].join(`
|
|
7
7
|
`):"prefs.cleared none"}if(y(e.overrides)){const t=J("prefs",e.overrides).split(`
|
|
8
8
|
`);return t.length===1&&t.push("no overrides"),typeof e.defaults=="string"&&t.push(e.defaults),t.join(`
|
|
9
9
|
`)}return y(e.prefs)?J("prefs",e.prefs):null}function J(e,t){const n=[e];for(const[s,i]of Object.entries(t).sort(([r],[o])=>r.localeCompare(o)))n.push(`${s}=${String(i)}`);return n.join(`
|
|
10
10
|
`)}function He(e){if(!y(e))throw new u.CliError("INVALID_SESSION_PREFS_STDIN","session prefs set --stdin expects a JSON object.");const t=y(e.prefs)?e.prefs:e,n={};for(const[s,i]of Object.entries(t))n[s]=i;return n}function Ge(e){if(e.length===0||e.length%2!==0)throw new u.CliError("SESSION_PREFS_SET_USAGE","Usage: aib session prefs set <key> <value> [<key> <value>...] or session prefs set --stdin");const t={};for(let n=0;n<e.length;n+=2){const s=e[n]??"",i=e[n+1]??"";t[s]=i}return t}function oe(e){if(Object.prototype.hasOwnProperty.call(O,e))return e;throw new u.CliError("UNKNOWN_SESSION_PREF",`Unknown session preference: ${e}`,{available:Object.keys(O)})}function Qe(e,t){const n=O[e];if(n.type==="boolean"){if(typeof t=="boolean")return t;if(typeof t=="string"){const i=t.trim().toLowerCase();if(i==="true")return!0;if(i==="false")return!1}throw new u.CliError("INVALID_SESSION_PREF_VALUE",`${e} expects true or false.`)}if(n.type==="string"){if(typeof t!="string")throw new u.CliError("INVALID_SESSION_PREF_VALUE",`${e} expects one of: ${n.values.join(", ")}.`);const i=t.trim();if(!n.values.includes(i))throw new u.CliError("INVALID_SESSION_PREF_VALUE",`${e} expects one of: ${n.values.join(", ")}.`);return i}const s=typeof t=="number"?t:typeof t=="string"?Number(t):NaN;if(!Number.isInteger(s)||s<n.min||s>n.max)throw new u.CliError("INVALID_SESSION_PREF_VALUE",`${e} expects an integer from ${n.min} to ${n.max}.`);return s}function Ye(e){const t={};for(const n of Object.keys(O)){const s=O[n];"hidden"in s&&s.hidden||(s.type==="boolean"?t[n]=ce(e,n,s.default):s.type==="number"?t[n]=K(e,n,s.default):t[n]=le(e,n,s.default))}return t}function Ze(e){const t={};for(const[n,s]of Object.entries(e))Xe(n)||(t[n]=s);return t}function Xe(e){if(!Object.prototype.hasOwnProperty.call(O,e))return!1;const t=O[e];return"hidden"in t&&t.hidden===!0}function B(e,t){if(!M(t))return t;const n=A(e),s=Oe(t),i=s.scope==="input"?n.inputs:n.outputs,r=s.scope==="input"?s.kind:s.scope,o=i[r],a=s.name==="last"?o?.last:s.name,f=a?o?.items[a]:void 0;if(!f)throw new u.CliError("SESSION_HANDLE_NOT_FOUND",`Session handle not found: ${t}`,{handle:t,sessionDir:h(e,n.rootDir)});return f.file}function qe(e,t,n,s){const i=A(e),r=Ae(i,t,n,".json");l.mkdirSync(c.dirname(r),{recursive:!0}),l.writeFileSync(r,`${JSON.stringify(s,null,2)}
|
|
11
|
-
`);const o=C(i,"outputs",t,n,r);return g(e,i),{saved:o.handle,last:`aib:${t}:last`,file:h(e,r)}}function et(e,t,n,s,i=".txt"){const r=A(e),o=Ae(r,t,n,i);l.mkdirSync(c.dirname(o),{recursive:!0}),l.writeFileSync(o,s);const a=C(r,"outputs",t,n,o);return g(e,r),{saved:a.handle,last:`aib:${t}:last`,file:h(e,o)}}function tt(e,t,n,s){const i=v(e);if(!i)return null;const r=I(t),o=I(n),a=c.join(i.rootDir,"outputs","result",r,`${o}.json`);return x(a,s),{saved:`aib:result:${r}:${o}`,file:h(e,a)}}function nt(e,t,n){const s=v(e);if(!s)return null;const i=I(t),r=c.join(s.rootDir,"outputs","result",`${i}.json`);return x(r,n),{saved:`aib:${i}`,file:h(e,r)}}function st(e,t){const n=A(e),s=I(t),i=c.join(n.rootDir,"outputs","result",`${s}.json`);if(!l.existsSync(i))throw new u.CliError("SESSION_RESULT_NOT_FOUND",`Result handle not found: aib:${s}`,{handle:`aib:${s}`,sessionDir:h(e,n.rootDir)});const r=JSON.parse(l.readFileSync(i,"utf8"));if(!r||typeof r!="object"||Array.isArray(r))throw new u.CliError("INVALID_SESSION_RESULT",`Result artifact is not a JSON object: aib:${s}`);return r}function it(e,t,n){const s=A(e),i=I(t),r=I(n),o=c.join(s.rootDir,"outputs","result",i,`${r}.json`);if(!l.existsSync(o))throw new u.CliError("SESSION_RESULT_NOT_FOUND",`Result handle not found: aib:result:${i}:${r}`,{handle:`aib:result:${i}:${r}`,sessionDir:h(e,s.rootDir)});const a=JSON.parse(l.readFileSync(o,"utf8"));if(!a||typeof a!="object"||Array.isArray(a))throw new u.CliError("INVALID_SESSION_RESULT",`Result artifact is not a JSON object: aib:result:${i}:${r}`);return a}function rt(e,t,n,s){return ae(e,t,n,s,{format:"json",text:JSON.stringify(s,null,2)})}function ae(e,t,n,s,i){const r=v(e);if(!r)return null;const o=i??{format:"json",text:JSON.stringify(s,null,2)},a=o.format==="dsl"?Z(r,t,n,".dsl"):Z(r,t,n,".json");o.format==="dsl"?(_e(a,o.text),x(Ft(r,t,n),s)):x(a,s);const f=C(r,"inputs",t,n,a);return Ne(r,t,s,o),g(e,r),{handle:f.handle,file:h(e,a)}}function ot(e){return l.existsSync(L(e))}function ue(e,t,n,s=-1){const i=v(e);if(!i)return n;const r=s>=0?s:K(i,"guidance.nextLimit",2),o=i.guidance??{},a=o[t]??{shown:0,limit:r};if(a.limit=r,a.shown>=a.limit){o[t]=a,i.guidance=o,g(e,i);return}return a.shown+=1,o[t]=a,i.guidance=o,g(e,i),n}function at(e,t,n){const s=v(e),i=O[t],r=typeof n=="boolean"?n:i.type==="boolean"?i.default:!1;return s?ce(s,t,r):r}function ut(e,t,n){const s=v(e),i=O[t],r=typeof n=="number"?n:i.type==="number"?i.default:0;return s?K(s,t,
|
|
11
|
+
`);const o=C(i,"outputs",t,n,r);return g(e,i),{saved:o.handle,last:`aib:${t}:last`,file:h(e,r)}}function et(e,t,n,s,i=".txt"){const r=A(e),o=Ae(r,t,n,i);l.mkdirSync(c.dirname(o),{recursive:!0}),l.writeFileSync(o,s);const a=C(r,"outputs",t,n,o);return g(e,r),{saved:a.handle,last:`aib:${t}:last`,file:h(e,o)}}function tt(e,t,n,s){const i=v(e);if(!i)return null;const r=I(t),o=I(n),a=c.join(i.rootDir,"outputs","result",r,`${o}.json`);return x(a,s),{saved:`aib:result:${r}:${o}`,file:h(e,a)}}function nt(e,t,n){const s=v(e);if(!s)return null;const i=I(t),r=c.join(s.rootDir,"outputs","result",`${i}.json`);return x(r,n),{saved:`aib:${i}`,file:h(e,r)}}function st(e,t){const n=A(e),s=I(t),i=c.join(n.rootDir,"outputs","result",`${s}.json`);if(!l.existsSync(i))throw new u.CliError("SESSION_RESULT_NOT_FOUND",`Result handle not found: aib:${s}`,{handle:`aib:${s}`,sessionDir:h(e,n.rootDir)});const r=JSON.parse(l.readFileSync(i,"utf8"));if(!r||typeof r!="object"||Array.isArray(r))throw new u.CliError("INVALID_SESSION_RESULT",`Result artifact is not a JSON object: aib:${s}`);return r}function it(e,t,n){const s=A(e),i=I(t),r=I(n),o=c.join(s.rootDir,"outputs","result",i,`${r}.json`);if(!l.existsSync(o))throw new u.CliError("SESSION_RESULT_NOT_FOUND",`Result handle not found: aib:result:${i}:${r}`,{handle:`aib:result:${i}:${r}`,sessionDir:h(e,s.rootDir)});const a=JSON.parse(l.readFileSync(o,"utf8"));if(!a||typeof a!="object"||Array.isArray(a))throw new u.CliError("INVALID_SESSION_RESULT",`Result artifact is not a JSON object: aib:result:${i}:${r}`);return a}function rt(e,t,n,s){return ae(e,t,n,s,{format:"json",text:JSON.stringify(s,null,2)})}function ae(e,t,n,s,i){const r=v(e);if(!r)return null;const o=i??{format:"json",text:JSON.stringify(s,null,2)},a=o.format==="dsl"?Z(r,t,n,".dsl"):Z(r,t,n,".json");o.format==="dsl"?(_e(a,o.text),x(Ft(r,t,n),s)):x(a,s);const f=C(r,"inputs",t,n,a);return Ne(r,t,s,o),g(e,r),{handle:f.handle,file:h(e,a)}}function ot(e){return l.existsSync(L(e))}function ue(e,t,n,s=-1){const i=v(e);if(!i)return n;const r=s>=0?s:K(i,"guidance.nextLimit",2),o=i.guidance??{},a=o[t]??{shown:0,limit:r};if(a.limit=r,a.shown>=a.limit){o[t]=a,i.guidance=o,g(e,i);return}return a.shown+=1,o[t]=a,i.guidance=o,g(e,i),n}function at(e,t,n){const s=v(e),i=O[t],r=typeof n=="boolean"?n:i.type==="boolean"?i.default:!1;return s?ce(s,t,r):r}function ut(e,t,n){const s=v(e),i=O[t],r=typeof n=="number"?n:i.type==="number"?i.default:0,o=(0,_.readWorkspaceNumberConfig)(e,t,r);return s?K(s,t,o):o}function ct(e,t,n){const s=v(e),i=O[t],r=typeof n=="string"?n:i.type==="string"?i.default:"";return s?le(s,t,r):r}function lt(e){try{const t=v(e);return(0,b.effectivePathAliases)(e,t?.pathAliases??{})}catch(t){if(t instanceof u.CliError&&t.code==="MULTIPLE_AIB_SESSIONS")return(0,b.effectivePathAliases)(e,{});throw t}}function ft(e){try{const t=v(e);return(0,b.normalizePathAliasMap)(t?.pathAliases??{},"session path aliases")}catch(t){if(t instanceof u.CliError&&t.code==="MULTIPLE_AIB_SESSIONS")return{};throw t}}function ce(e,t,n){const s=e.prefs?.[t];return typeof s=="boolean"?s:n}function K(e,t,n){const s=e.prefs?.[t];return typeof s=="number"&&Number.isFinite(s)?s:n}function le(e,t,n){const s=e.prefs?.[t];return typeof s=="string"?s:n}function dt(e,t){const n=w(t,"--dir"),s=Q(e,n,!0),i=w(t,"--name"),r=$(i??Y()??Jt()),o=c.join(s.rootDir,r),a=new Date().toISOString(),d=R(e,r)??{version:1,sessionId:r,cwd:c.resolve(e),rootDir:o,createdAt:a,updatedAt:a,outputs:{},inputs:{},guidance:{}};d.sessionId=r,d.rootDir=o,d.updatedAt=a,me(d),g(e,d),be(e,d,!0);const p=D(e),S=p?Object.keys(p.sessions).length:1,N={session:r,dir:h(e,d.rootDir),sessionDir:h(e,s.rootDir),sessionDirSource:s.source,sessionCount:S,bind:`${E.CLI_ENV.session}=${r}`,next:S===1?"Run AIB commands without -s for now. AIB will tell you if multiple sessions exist.":`Use aib -s ${r} <command> or set ${E.CLI_ENV.session}=${r}.`};return s.ignoredRequestedDir&&(N.note=`${U} from aib.json is in effect; --dir was ignored.`,N.requestedDir=s.ignoredRequestedDir),(0,m.attachAgentText)(N,pt(N))}function pt(e){const t=String(e.session??""),n=typeof e.sessionCount=="number"?e.sessionCount:1,s=[`session ready: ${t}`,""];return typeof e.note=="string"&&e.note&&(s.push("aib.json sessionDir is in effect; --dir was ignored."),s.push("")),n===1?(s.push("Only one AIB session exists in this repo."),s.push("You can run AIB commands without -s for now."),s.push("AIB will tell you if multiple sessions exist and you need to choose one.")):(s.push("Multiple AIB sessions exist in this repo."),s.push("Use this session explicitly:"),s.push(`aib -s ${t} <command>`),s.push(""),s.push("Or bind it in this shell:"),s.push(`${E.CLI_ENV.session}=${t}`)),s.join(`
|
|
12
12
|
`)}function St(e){const t=D(e),n=k(e);return{active:n.sessionId??t?.activeSessionId??null,source:n.source,sessions:t?Object.values(t.sessions).sort((s,i)=>s.sessionId.localeCompare(i.sessionId)).map(s=>`${s.sessionId} -> ${h(e,s.rootDir)}`):[]}}function ht(e,t){const n=t[0]??"";if(!n)throw new u.CliError("SESSION_USE_ID_REQUIRED","Usage: aib session use <sessionId>");const s=$(n),i=D(e),r=i?.sessions[s];if(!r)throw new u.CliError("SESSION_NOT_FOUND",`Session not found: ${s}`,{available:i?Object.keys(i.sessions).sort():[]});return T(e,{...i??ge(e),activeSessionId:s}),{session:s,dir:h(e,r.rootDir),bind:`${E.CLI_ENV.session}=${s}`,next:`Use aib -s ${s} <command> or set ${E.CLI_ENV.session}=${s}.`}}function mt(e,t){const n=t[0]??"";if(!n)throw new u.CliError("SESSION_WHERE_HANDLE_REQUIRED","Usage: aib session where <handle>");const s=B(e,n),i={handle:n,file:h(e,s)};return(0,m.attachAgentText)(i,[n,i.file].join(`
|
|
13
|
-
`))}function It(e,t,n){if(t.includes("--stdin")){if(!y(n))throw new u.CliError("INVALID_SESSION_READ_STDIN","session read --stdin expects a JSON object payload.");const r=yt(n);if(r.length===1){const a=H(e,r[0]);return(0,m.attachAgentText)(a,G(a))}const o={reads:r.map(a=>gt(e,a))};return(0,m.attachAgentText)(o,G(o))}const s=t[0]??"";if(!s)throw new u.CliError("SESSION_READ_HANDLE_REQUIRED","Usage: aib session read <handle> [--head <n> | --offset <n> --limit <n>]");const i=H(e,{handle:s,...vt(t.slice(1))});return(0,m.attachAgentText)(i,G(i))}function yt(e){if(Array.isArray(e.reads))return e.reads.map((t,n)=>{if(typeof t=="string"){if(!M(t))throw new u.CliError("INVALID_SESSION_READ_ROW",`session read row at index ${n} must be an aib: handle string or an object.`);return{handle:t}}if(!y(t))throw new u.CliError("INVALID_SESSION_READ_ROW",`session read row at index ${n} must be an aib: handle string or an object.`);return fe(t,n)});if(typeof e.handle=="string"||typeof e.read=="string")return[fe(e,0)];throw new u.CliError("INVALID_SESSION_READ_STDIN","Expected { reads: [{ handle }] } or { handle }.")}function fe(e,t){const n=X(e.handle)??X(e.read);if(!n)throw new u.CliError("SESSION_READ_HANDLE_REQUIRED",`session read row at index ${t} requires handle.`);return{handle:n,...e.rawInput===!0?{rawInput:!0}:{},...pe(e,t)}}function gt(e,t){try{return H(e,t)}catch(n){if(n instanceof u.CliError){const s=y(n.details)?n.details:{};return{read:t.handle,error:n.code,...typeof s.next=="string"?{next:s.next}:{}}}return{read:t.handle,error:"UNEXPECTED_ERROR"}}}function H(e,t){Ot(t);const n=Oe(t.handle),s=B(e,t.handle);if(n.scope==="input"&&!t.rawInput){const r=Nt(n.kind,t.handle);return{read:t.handle,file:h(e,s),next:r?`Edit file, then rerun: ${r}`:"Edit file, then rerun the command with --from <handle>."}}if(n.scope==="graph"||n.scope==="usages"){const r=n.scope==="graph"?`aib inspect graph --from-file ${t.handle} --focus <file>`:`aib inspect usages --from-file ${t.handle} --focus <name>`;throw new u.CliError("SESSION_ARTIFACT_NOT_READABLE",`${n.scope} artifacts are reusable indexes, not agent-readable context.`,{handle:t.handle,kind:n.scope,next:r})}if(n.scope==="duplicates"){const r=l.readFileSync(s,"utf8");return{read:t.handle,content:bt(e,t.handle,s,r,t)}}const i=l.readFileSync(s,"utf8");return{read:t.handle,content:At(s,i,t)}}function bt(e,t,n,s,i){const r=Et(e,t,n,s);return i.head!==void 0||i.offset!==void 0||i.limit!==void 0?Se(r,i):r}function Et(e,t,n,s){let i;try{i=JSON.parse(s)}catch{return de(t,n,s)}if(!y(i))return de(t,n,s);const r=[],o=Array.isArray(i.targetPaths)?i.targetPaths.filter(S=>typeof S=="string"&&S!==""):[],a=o.length===1?h(e,o[0]):o.length>1?`${o.length} scopes`:"";r.push(a?`duplicates ${a}`:"duplicates");const f=typeof i.summary=="string"?i.summary:`${j(i.itemCount)} ${te(j(i.itemCount),"name")}`;r.push(f);const d=Array.isArray(i.items)?i.items.filter(y):[];for(const S of d){const
|
|
13
|
+
`))}function It(e,t,n){if(t.includes("--stdin")){if(!y(n))throw new u.CliError("INVALID_SESSION_READ_STDIN","session read --stdin expects a JSON object payload.");const r=yt(n);if(r.length===1){const a=H(e,r[0]);return(0,m.attachAgentText)(a,G(a))}const o={reads:r.map(a=>gt(e,a))};return(0,m.attachAgentText)(o,G(o))}const s=t[0]??"";if(!s)throw new u.CliError("SESSION_READ_HANDLE_REQUIRED","Usage: aib session read <handle> [--head <n> | --offset <n> --limit <n>]");const i=H(e,{handle:s,...vt(t.slice(1))});return(0,m.attachAgentText)(i,G(i))}function yt(e){if(Array.isArray(e.reads))return e.reads.map((t,n)=>{if(typeof t=="string"){if(!M(t))throw new u.CliError("INVALID_SESSION_READ_ROW",`session read row at index ${n} must be an aib: handle string or an object.`);return{handle:t}}if(!y(t))throw new u.CliError("INVALID_SESSION_READ_ROW",`session read row at index ${n} must be an aib: handle string or an object.`);return fe(t,n)});if(typeof e.handle=="string"||typeof e.read=="string")return[fe(e,0)];throw new u.CliError("INVALID_SESSION_READ_STDIN","Expected { reads: [{ handle }] } or { handle }.")}function fe(e,t){const n=X(e.handle)??X(e.read);if(!n)throw new u.CliError("SESSION_READ_HANDLE_REQUIRED",`session read row at index ${t} requires handle.`);return{handle:n,...e.rawInput===!0?{rawInput:!0}:{},...pe(e,t)}}function gt(e,t){try{return H(e,t)}catch(n){if(n instanceof u.CliError){const s=y(n.details)?n.details:{};return{read:t.handle,error:n.code,...typeof s.next=="string"?{next:s.next}:{}}}return{read:t.handle,error:"UNEXPECTED_ERROR"}}}function H(e,t){Ot(t);const n=Oe(t.handle),s=B(e,t.handle);if(n.scope==="input"&&!t.rawInput){const r=Nt(n.kind,t.handle);return{read:t.handle,file:h(e,s),next:r?`Edit file, then rerun: ${r}`:"Edit file, then rerun the command with --from <handle>."}}if(n.scope==="graph"||n.scope==="usages"){const r=n.scope==="graph"?`aib inspect graph --from-file ${t.handle} --focus <file>`:`aib inspect usages --from-file ${t.handle} --focus <name>`;throw new u.CliError("SESSION_ARTIFACT_NOT_READABLE",`${n.scope} artifacts are reusable indexes, not agent-readable context.`,{handle:t.handle,kind:n.scope,next:r})}if(n.scope==="duplicates"){const r=l.readFileSync(s,"utf8");return{read:t.handle,content:bt(e,t.handle,s,r,t)}}const i=l.readFileSync(s,"utf8");return{read:t.handle,content:At(s,i,t)}}function bt(e,t,n,s,i){const r=Et(e,t,n,s);return i.head!==void 0||i.offset!==void 0||i.limit!==void 0?Se(r,i):r}function Et(e,t,n,s){let i;try{i=JSON.parse(s)}catch{return de(t,n,s)}if(!y(i))return de(t,n,s);const r=[],o=Array.isArray(i.targetPaths)?i.targetPaths.filter(S=>typeof S=="string"&&S!==""):[],a=o.length===1?h(e,o[0]):o.length>1?`${o.length} scopes`:"";r.push(a?`duplicates ${a}`:"duplicates");const f=typeof i.summary=="string"?i.summary:`${j(i.itemCount)} ${te(j(i.itemCount),"name")}`;r.push(f);const d=Array.isArray(i.items)?i.items.filter(y):[];for(const S of d){const N=typeof S.name=="string"?S.name:"",ve=j(S.declarationCount),ne=j(S.variantCount),se=j(S.exactCopyCount);N&&r.push(`${N} x${ve}, ${ne} ${te(ne,"variant")}${se>0?`, exact x${se}`:""}`)}const p=j(i.hiddenItemCount);return p>0&&r.push(`+ ${p} ${te(p,"name")}`),r.push(`raw: aib session where ${t}`),r.join(`
|
|
14
14
|
`)}function de(e,t,n){return[`saved artifact ${e}`,`${n.length} bytes`,`raw: ${t}`].join(`
|
|
15
15
|
`)}function At(e,t,n){if(n.head!==void 0||n.offset!==void 0||n.limit!==void 0)return Se(t,n);if(c.extname(e).toLowerCase()!==".json")return t;try{return JSON.parse(t)}catch{return t}}function G(e){const t=Array.isArray(e.reads)?e.reads.filter(y):[e];if(t.length===0)return null;const n=[],s=t.length>1;for(const i of t){const r=typeof i.read=="string"?i.read:"",o=i.content,a=_t(o);if(a!==null){s&&r&&n.push(`// ${r}`),n.push(a.trimEnd());continue}if(typeof i.file=="string"){s&&r?n.push(`// ${r}`):r&&n.push(`input ${r}`),n.push(`file: ${i.file}`),typeof i.next=="string"&&n.push(`next: ${i.next}`);continue}const f=typeof i.error=="string"?i.error:"";if(f){s&&r&&n.push(`// ${r}`),n.push(`error: ${f}`),typeof i.next=="string"&&n.push(`next: ${i.next}`);continue}return null}return n.join(`
|
|
16
16
|
`)}function _t(e){return typeof e=="string"?e:e===void 0?null:JSON.stringify(e,null,2)}function Nt(e,t){return e==="inspect"?`aib inspect --from ${t}`:e==="graph"?`aib inspect graph --from ${t}`:e==="rename"?`aib rename preview --from ${t}`:e==="move"?`aib move toFile preview --from ${t}`:e==="refactor"?`aib refactor batch preview --from ${t}`:e==="modulePlan"?`aib modulePlan preview --from ${t}`:e==="imports"?`aib imports normalize preview --from ${t}`:null}function Ot(e){if(e.head!==void 0&&(e.offset!==void 0||e.limit!==void 0))throw new u.CliError("SESSION_READ_RANGE_CONFLICT","Use either head or offset/limit, not both.")}function vt(e){const t={},n=w(e,"--head"),s=w(e,"--offset"),i=w(e,"--limit");return n!==void 0&&(t.head=n),s!==void 0&&(t.offset=s),i!==void 0&&(t.limit=i),{...e.includes("--raw-input")?{rawInput:!0}:{},...pe(t,0)}}function pe(e,t){const n=q(e.head,`session read row at index ${t} has invalid head.`),s=q(e.offset,`session read row at index ${t} has invalid offset.`),i=zt(e.limit,`session read row at index ${t} has invalid limit.`);return{...n!==void 0?{head:n}:{},...s!==void 0?{offset:s}:{},...i!==void 0?{limit:i}:{}}}function Se(e,t){if(t.head===void 0&&t.offset===void 0&&t.limit===void 0)return e;const n=e.split(/\r?\n/),s=t.head!==void 0?0:t.offset??0,i=t.head!==void 0?t.head:t.limit!==void 0?s+t.limit:void 0;return n.slice(s,i).join(`
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
`)}function Ct(e){const t=k(e),n=D(e),s=n?Object.keys(n.sessions).sort():[];if(t.source==="ambiguous")return(0,m.attachAgentText)({ok:!1,code:"MULTIPLE_AIB_SESSIONS",error:"Multiple AIB sessions exist. Select one explicitly.",available:s,next:"Use aib -s <session> session clear."},wt(s));const i=t.sessionId?R(e,t.sessionId):null;if(!i)return(0,m.attachAgentText)({cleared:!1,reason:"session-not-initialized"},["No AIB sessions exist in this repo.","","Create one:","aib session init --name <name>"].join(`
|
|
22
22
|
`));he(i,{touch:!0}),g(e,i);const r=i.sessionId??t.sessionId??"";return(0,m.attachAgentText)({cleared:!0,session:r,dir:h(e,i.rootDir)},[`session cleared: ${r}`,"","Inputs and outputs were pruned.","You can keep using this session."].join(`
|
|
23
23
|
`))}function he(e,t){l.rmSync(c.join(e.rootDir,"inputs"),{recursive:!0,force:!0}),l.rmSync(c.join(e.rootDir,"outputs"),{recursive:!0,force:!0}),e.inputs={},e.outputs={},e.guidance={},t.touch&&(e.updatedAt=new Date().toISOString()),me(e)}function wt(e){return["multiple AIB sessions","","available:",...e,"","Clear one explicitly only if it is yours:","aib -s <session> session clear","","If none of these sessions is yours, create a new one:","aib session init --name <name>"].join(`
|
|
24
|
-
`)}function Rt(e){const t=Lt(e),n=D(e);if(!n)return;const s=Date.now();let i=!1;for(const[r,o]of Object.entries(n.sessions)){const a=P(o.rootDir);if(!l.existsSync(a)){delete n.sessions[r],i=!0,n.activeSessionId===r&&delete n.activeSessionId;continue}const f=Date.parse(o.updatedAt);if(!Number.isFinite(f))continue;const d=s-f;if(t.autoDelete&&t.ttlDeleteMs>0&&d>t.ttlDeleteMs){l.rmSync(o.rootDir,{recursive:!0,force:!0}),delete n.sessions[r],i=!0,n.activeSessionId===r&&delete n.activeSessionId;continue}if(t.autoClean&&t.ttlCleanMs>0&&d>t.ttlCleanMs){const p=Ie(e,o.rootDir,r);p&&(he(p,{touch:!1}),Pt(p))}}if(i){if(!n.activeSessionId){const r=Object.keys(n.sessions).sort()[0];r&&(n.activeSessionId=r)}T(e,n)}}function Lt(e){const t=(0,
|
|
24
|
+
`)}function Rt(e){const t=Lt(e),n=D(e);if(!n)return;const s=Date.now();let i=!1;for(const[r,o]of Object.entries(n.sessions)){const a=P(o.rootDir);if(!l.existsSync(a)){delete n.sessions[r],i=!0,n.activeSessionId===r&&delete n.activeSessionId;continue}const f=Date.parse(o.updatedAt);if(!Number.isFinite(f))continue;const d=s-f;if(t.autoDelete&&t.ttlDeleteMs>0&&d>t.ttlDeleteMs){l.rmSync(o.rootDir,{recursive:!0,force:!0}),delete n.sessions[r],i=!0,n.activeSessionId===r&&delete n.activeSessionId;continue}if(t.autoClean&&t.ttlCleanMs>0&&d>t.ttlCleanMs){const p=Ie(e,o.rootDir,r);p&&(he(p,{touch:!1}),Pt(p))}}if(i){if(!n.activeSessionId){const r=Object.keys(n.sessions).sort()[0];r&&(n.activeSessionId=r)}T(e,n)}}function Lt(e){const t=(0,_.readWorkspaceNumberConfig)(e,"session.ttlMinutes",60),n=(0,_.readWorkspaceNumberConfig)(e,"session.ttlDeleteMinutes",t),s=(0,_.readWorkspaceNumberConfig)(e,"session.ttlCleanMinutes",t);return{autoDelete:(0,_.readWorkspaceBooleanConfig)(e,"session.autoDelete",!0),ttlDeleteMs:n>0?n*6e4:0,autoClean:(0,_.readWorkspaceBooleanConfig)(e,"session.autoClean",!0),ttlCleanMs:s>0?s*6e4:0}}function me(e){for(const t of ke)l.mkdirSync(c.join(e.rootDir,"outputs",t),{recursive:!0});for(const t of We)l.mkdirSync(c.join(e.rootDir,"inputs",t),{recursive:!0})}function R(e,t){const s=D(e)?.sessions[t];return s?Ie(e,s.rootDir,t):null}function v(e){const t=Ee(e);return t.sessionId?R(e,t.sessionId):null}function Ie(e,t,n){try{const s=JSON.parse(l.readFileSync(P(t),"utf8"));if(!s||typeof s!="object"||Array.isArray(s))return null;const i=s;return i.version!==1||typeof i.rootDir!="string"?null:(i.sessionId=i.sessionId??n,i)}catch{return null}}function A(e){const t=v(e);if(!t)throw new u.CliError("SESSION_WORKSPACE_NOT_INITIALIZED","Session workspace is not initialized.",{session:Y()??null,next:"Run aib session init --name <name>",help:"aib help session"});return g(e,t),t}function g(e,t){t.updatedAt=new Date().toISOString(),l.mkdirSync(t.rootDir,{recursive:!0}),l.writeFileSync(P(t.rootDir),`${JSON.stringify(t,null,2)}
|
|
25
25
|
`),be(e,t,!1)}function Pt(e){l.mkdirSync(e.rootDir,{recursive:!0}),l.writeFileSync(P(e.rootDir),`${JSON.stringify(e,null,2)}
|
|
26
|
-
`)}function Q(e,t,n=!1){const s=(0,
|
|
26
|
+
`)}function Q(e,t,n=!1){const s=(0,_.resolveWorkspaceRoot)(e),i=s?.root??e,r=s?X(s.config[U]):void 0;if(r)return{rootDir:ye(i,r),source:"aib.json",...t?{ignoredRequestedDir:t}:{}};const a=ye(i,t??je);return n&&s&&(0,_.updateWorkspaceConfig)(i,{[U]:Tt(i,a)}),{rootDir:a,source:t?"request":"default"}}function ye(e,t){const n=c.resolve(e,t);return c.basename(n).toLowerCase()==="aib"?n:c.join(n,"aib")}function Tt(e,t){const n=c.relative(e,t);return n&&!n.startsWith("..")&&!c.isAbsolute(n)?n.replace(/\\/g,"/"):t.replace(/\\/g,"/")}function L(e){return c.join(Q(e).rootDir,Ce)}function kt(e){return c.join(Q(e).rootDir,we)}function P(e){return c.join(e,"session.json")}function D(e){try{const t=JSON.parse(l.readFileSync(L(e),"utf8"));if(!t||typeof t!="object"||Array.isArray(t))return null;const n=t;return n.version!==1||!n.sessions||typeof n.sessions!="object"?null:{version:1,cwd:typeof n.cwd=="string"?n.cwd:c.resolve(e),...typeof n.activeSessionId=="string"?{activeSessionId:n.activeSessionId}:{},sessions:n.sessions}}catch{return null}}function T(e,t){t.cwd=c.resolve((0,_.resolveWorkspaceRoot)(e)?.root??e),l.mkdirSync(c.dirname(L(e)),{recursive:!0}),l.writeFileSync(L(e),`${JSON.stringify(t,null,2)}
|
|
27
27
|
`),Wt(e,t.activeSessionId)}function ge(e){return{version:1,cwd:c.resolve(e),sessions:{}}}function Wt(e,t){const n=kt(e);if(l.mkdirSync(c.dirname(n),{recursive:!0}),!t){l.rmSync(n,{force:!0});return}l.writeFileSync(n,`${JSON.stringify({sessionId:t,updatedAt:new Date().toISOString()},null,2)}
|
|
28
28
|
`)}function be(e,t,n){const s=t.sessionId??Y()??"";if(!s)return;const i=D(e)??ge(e);i.sessions[s]={sessionId:s,rootDir:t.rootDir,createdAt:i.sessions[s]?.createdAt??t.createdAt,updatedAt:t.updatedAt},(n||!i.activeSessionId)&&(i.activeSessionId=s),T(e,i)}function Bt(e,t){const n=D(e);if(!(!n||!t)){if(delete n.sessions[t],n.activeSessionId===t){const s=Object.keys(n.sessions).sort()[0];s?n.activeSessionId=s:delete n.activeSessionId}T(e,n)}}function Ee(e){const t=F.getStore();if(t)return{sessionId:$(t),source:"override"};const n=process.env[E.CLI_ENV.session];if(n&&n.trim())return{sessionId:$(n),source:"env"};const s=process.env[E.CLI_ENV.legacySession];if(s&&s.trim())return{sessionId:$(s),source:"legacy-env"};const i=D(e),r=i?Object.keys(i.sessions).sort():[];if(r.length===1)return{sessionId:r[0],source:"single"};if(r.length>1)throw new u.CliError("MULTIPLE_AIB_SESSIONS","Multiple AIB sessions exist. Select one explicitly.",{available:r,next:`Use aib -s <session> <command> or set ${E.CLI_ENV.session}=<session>.`});return{sessionId:null,source:"none"}}function k(e){try{return Ee(e)}catch(t){if(t instanceof u.CliError&&t.code==="MULTIPLE_AIB_SESSIONS")return{sessionId:null,source:"ambiguous"};throw t}}function Ut(e){const t=k(e);return{sessionId:t.sessionId,sessionSource:t.source}}function Y(){const e=F.getStore();if(e)return $(e);const t=process.env[E.CLI_ENV.session];if(t&&t.trim())return $(t);const n=process.env[E.CLI_ENV.legacySession];return n&&n.trim()?$(n):null}function Ae(e,t,n,s){return c.join(e.rootDir,"outputs",I(t),`${I(n)}${ee(s)}`)}function Z(e,t,n,s=".json"){return c.join(e.rootDir,"inputs",I(t),`${I(n)}${ee(s)}`)}function Ft(e,t,n){return c.join(e.rootDir,"inputs",I(t),`${I(n)}.compiled.json`)}function W(e,t,n=".json"){return c.join(e.rootDir,"inputs",I(t),n===".json"?Te:`_last${ee(n)}`)}function x(e,t){l.mkdirSync(c.dirname(e),{recursive:!0}),l.writeFileSync(e,`${JSON.stringify(t,null,2)}
|
|
29
29
|
`)}function _e(e,t){l.mkdirSync(c.dirname(e),{recursive:!0}),l.writeFileSync(e,t.endsWith(`
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`,"utf8");const
|
|
3
|
-
`,"utf8"),r}function
|
|
1
|
+
"use strict";var b=exports&&exports.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var s=Object.getOwnPropertyDescriptor(t,n);(!s||("get"in s?!t.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,s)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),v=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),_=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(n){var r=[];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(r[r.length]=s);return r},e(t)};return function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var r=e(t),s=0;s<r.length;s++)r[s]!=="default"&&b(n,t,r[s]);return v(n,t),n}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.MATERIALIZED_INSPECT_DEFAULTS=exports.AIB_CONFIG_FILE_NAME=void 0,exports.initWorkspaceRoot=D,exports.resolveWorkspaceRoot=g,exports.resolveRequiredWorkspaceRoot=C,exports.readWorkspaceNumberConfig=O,exports.readWorkspaceBooleanConfig=h,exports.readWorkspaceStringConfig=A,exports.updateWorkspaceConfig=w,exports.workspaceConfigSummary=k,exports.isPathInsideOrEqual=F;const l=_(require("node:fs")),o=_(require("node:path")),E=require("./env-vars"),M=require("../shared/errors");exports.AIB_CONFIG_FILE_NAME="aib.json",exports.MATERIALIZED_INSPECT_DEFAULTS={"inspect.code.maxNonEmptyLines":120,"inspect.usages.maxLocations":12,"inspect.usages.maxCodeBlocks":8,"inspect.members.maxItems":20};function D(e,t={}){const n=o.join(o.resolve(e),exports.AIB_CONFIG_FILE_NAME),r=l.existsSync(n),s=r?m(n):{},f=a(t.sessionDir)??a(s.sessionDir),d=i(s["session.ttlMinutes"]),p=i(s["session.ttlCleanMinutes"])??d??60,I=i(s["session.ttlDeleteMinutes"])??d??60,c={...s,"workspace.root":a(s["workspace.root"])??".",...f?{sessionDir:f}:{},"session.autoDelete":u(s["session.autoDelete"])??!0,"session.ttlDeleteMinutes":I,"session.autoClean":u(s["session.autoClean"])??!0,"session.ttlCleanMinutes":p,"runtime.managedIdeTtlMinutes":i(s["runtime.managedIdeTtlMinutes"])??15,"runtime.managedIdeWatchdogIntervalMs":i(s["runtime.managedIdeWatchdogIntervalMs"])??3e4,"runtime.autoStopManagedIde":u(s["runtime.autoStopManagedIde"])??!0,...r?{}:exports.MATERIALIZED_INSPECT_DEFAULTS};l.writeFileSync(n,`${JSON.stringify(c,null,2)}
|
|
2
|
+
`,"utf8");const S=i(c["session.ttlCleanMinutes"])??60,y=i(c["runtime.managedIdeTtlMinutes"])??15,N=!r||JSON.stringify(s)!==JSON.stringify(c);return{status:r?N?"updated":"unchanged":"created",...r?{}:{created:exports.AIB_CONFIG_FILE_NAME},configPath:n,root:o.resolve(e),"workspace.root":a(c["workspace.root"])??".",...f?{sessionDir:f}:{},"session.autoClean":u(c["session.autoClean"])??!0,"session.ttlCleanMinutes":S,"session.autoDelete":u(c["session.autoDelete"])??!0,"session.ttlDeleteMinutes":i(c["session.ttlDeleteMinutes"])??60,"runtime.autoStopManagedIde":u(c["runtime.autoStopManagedIde"])??!0,"runtime.managedIdeTtlMinutes":y,...f?{}:{next:"Set the default session directory: aib config --session-dir .tmp/aib"}}}function g(e){const t=a(process.env[E.CLI_ENV.workspaceRoot]);if(t){const d=o.resolve(e,t),p=o.join(d,exports.AIB_CONFIG_FILE_NAME),I=l.existsSync(p)?m(p):{"workspace.root":"."};return{root:d,configPath:p,config:I}}const n=T(e);if(!n)return null;const r=m(n),s=o.dirname(n),f=a(r["workspace.root"])??".";return{root:o.resolve(s,f),configPath:n,config:r}}function C(e){const t=g(e);if(t)return t;const n=L(e,".git");throw new M.CliError("WORKSPACE_ROOT_NOT_INITIALIZED","Workspace root is not initialized.",{cwd:o.resolve(e),...n?{detectedGitRoot:n}:{},next:"Run aib help first-setup from the intended repository root."})}function O(e,t,n){const r=g(e);return(r?i(r.config[t]):null)??n}function h(e,t,n){const r=g(e);return(r?u(r.config[t]):null)??n}function A(e,t,n){const r=g(e);return(r?a(r.config[t]):null)??n}function w(e,t){const n=C(e),r={...n.config,...t};return l.writeFileSync(n.configPath,`${JSON.stringify(r,null,2)}
|
|
3
|
+
`,"utf8"),r}function k(e){const t=i(e["session.ttlMinutes"]);return{"workspace.root":a(e["workspace.root"])??".",...a(e.sessionDir)?{sessionDir:a(e.sessionDir)}:{},"session.autoClean":u(e["session.autoClean"])??!0,"session.ttlCleanMinutes":i(e["session.ttlCleanMinutes"])??t??60,"session.autoDelete":u(e["session.autoDelete"])??!0,"session.ttlDeleteMinutes":i(e["session.ttlDeleteMinutes"])??t??60,"runtime.autoStopManagedIde":u(e["runtime.autoStopManagedIde"])??!0,"runtime.managedIdeTtlMinutes":i(e["runtime.managedIdeTtlMinutes"])??15}}function F(e,t){const n=o.resolve(e).toLowerCase(),r=o.resolve(t).toLowerCase();return r===n||r.startsWith(`${n}${o.sep}`)}function T(e){let t=o.resolve(e);const n=o.parse(t).root;for(;;){const r=o.join(t,exports.AIB_CONFIG_FILE_NAME);if(l.existsSync(r)&&l.statSync(r).isFile())return r;if(t===n)break;const s=o.dirname(t);if(s===t)break;t=s}return null}function L(e,t){let n=o.resolve(e);const r=o.parse(n).root;for(;;){if(l.existsSync(o.join(n,t)))return n;if(n===r)break;const s=o.dirname(n);if(s===n)break;n=s}return null}function m(e){try{const t=JSON.parse(l.readFileSync(e,"utf8"));return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}catch(t){throw new M.CliError("AIB_CONFIG_INVALID","aib.json must be valid JSON.",{file:e,error:t instanceof Error?t.message:String(t)})}}function a(e){return typeof e=="string"&&e.trim()?e.trim():null}function i(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.trim()){const t=Number(e);return Number.isFinite(t)?t:null}return null}function u(e){if(typeof e=="boolean")return e;if(typeof e!="string")return null;const t=e.trim().toLowerCase();return["1","true","yes","on"].includes(t)?!0:["0","false","no","off"].includes(t)?!1:null}
|
package/dist/help/bootstrap.md
CHANGED
|
@@ -13,13 +13,10 @@ session prefs get
|
|
|
13
13
|
Run:
|
|
14
14
|
aib session prefs get
|
|
15
15
|
|
|
16
|
-
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
17
|
-
Stdin Run lines include the aib prefix to avoid confusion.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@'
|
|
21
|
-
<input>
|
|
22
|
-
'@ | aib <command> --stdin
|
|
16
|
+
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
17
|
+
Stdin Run lines include the aib prefix to avoid confusion.
|
|
18
|
+
|
|
19
|
+
{{stdin.examples}}
|
|
23
20
|
|
|
24
21
|
Basics
|
|
25
22
|
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
Inline commands below omit the aib prefix.
|
|
4
4
|
Run them as: aib <command>
|
|
5
5
|
|
|
6
|
-
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
7
|
-
Stdin Run lines include the aib prefix to avoid confusion.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@'
|
|
11
|
-
<input>
|
|
12
|
-
'@ | aib <command> --stdin
|
|
6
|
+
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
7
|
+
Stdin Run lines include the aib prefix to avoid confusion.
|
|
8
|
+
|
|
9
|
+
{{stdin.examples}}
|
|
@@ -13,13 +13,10 @@ session prefs get
|
|
|
13
13
|
Run:
|
|
14
14
|
aib session prefs get
|
|
15
15
|
|
|
16
|
-
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
17
|
-
Stdin Run lines include the aib prefix to avoid confusion.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@'
|
|
21
|
-
<input>
|
|
22
|
-
'@ | aib <command> --stdin
|
|
16
|
+
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
17
|
+
Stdin Run lines include the aib prefix to avoid confusion.
|
|
18
|
+
|
|
19
|
+
{{stdin.examples}}
|
|
23
20
|
|
|
24
21
|
Basics
|
|
25
22
|
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
Inline commands below omit the aib prefix.
|
|
4
4
|
Run them as: aib <command>
|
|
5
5
|
|
|
6
|
-
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
7
|
-
Stdin Run lines include the aib prefix to avoid confusion.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@'
|
|
11
|
-
<input>
|
|
12
|
-
'@ | aib <command> --stdin
|
|
6
|
+
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
7
|
+
Stdin Run lines include the aib prefix to avoid confusion.
|
|
8
|
+
|
|
9
|
+
{{stdin.examples}}
|
package/dist/help/dsl/full.md
CHANGED
|
@@ -13,13 +13,10 @@ session prefs get
|
|
|
13
13
|
Run:
|
|
14
14
|
aib session prefs get
|
|
15
15
|
|
|
16
|
-
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
17
|
-
Stdin Run lines include the aib prefix to avoid confusion.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@'
|
|
21
|
-
<input>
|
|
22
|
-
'@ | aib <command> --stdin
|
|
16
|
+
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
17
|
+
Stdin Run lines include the aib prefix to avoid confusion.
|
|
18
|
+
|
|
19
|
+
{{stdin.examples}}
|
|
23
20
|
|
|
24
21
|
Basics
|
|
25
22
|
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
Inline commands below omit the aib prefix.
|
|
2
2
|
Run them as: aib <command>
|
|
3
3
|
|
|
4
|
-
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
5
|
-
Stdin Run lines include the aib prefix to avoid confusion.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@'
|
|
9
|
-
<input>
|
|
10
|
-
'@ | aib <command> --stdin
|
|
4
|
+
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
5
|
+
Stdin Run lines include the aib prefix to avoid confusion.
|
|
6
|
+
|
|
7
|
+
{{stdin.examples}}
|
package/dist/help/full.md
CHANGED
|
@@ -13,13 +13,10 @@ session prefs get
|
|
|
13
13
|
Run:
|
|
14
14
|
aib session prefs get
|
|
15
15
|
|
|
16
|
-
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
17
|
-
Stdin Run lines include the aib prefix to avoid confusion.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@'
|
|
21
|
-
<input>
|
|
22
|
-
'@ | aib <command> --stdin
|
|
16
|
+
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
17
|
+
Stdin Run lines include the aib prefix to avoid confusion.
|
|
18
|
+
|
|
19
|
+
{{stdin.examples}}
|
|
23
20
|
|
|
24
21
|
Basics
|
|
25
22
|
|
package/dist/help/help-meta.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"helpVersion": "0.1.0",
|
|
4
|
-
"generatedAt": "2026-05-
|
|
5
|
-
"sourceCommit": "
|
|
6
|
-
"contentHash": "sha256:
|
|
4
|
+
"generatedAt": "2026-05-30T02:39:54+03:00",
|
|
5
|
+
"sourceCommit": "e42cd68",
|
|
6
|
+
"contentHash": "sha256:c1e6c894a137b4b22612357c4b35458b5ea5d4de808efb9a495c77752b599e72",
|
|
7
7
|
"topics": {
|
|
8
8
|
"help-format": {
|
|
9
|
-
"contentHash": "sha256:
|
|
10
|
-
"docsHash": "sha256:
|
|
9
|
+
"contentHash": "sha256:b1a0a6ca2a5ac2e61285854e8dd3c951a329073f139ccca50ebe519c2ca0484e",
|
|
10
|
+
"docsHash": "sha256:44a26ac23ba47f1cff5cedcf61bba16df2d3403db01cf73627da02a3eff0986e"
|
|
11
11
|
},
|
|
12
12
|
"help-protocol": {
|
|
13
13
|
"contentHash": "sha256:4d31b0ac5d262f8cbe0da0d883324723efa869a0a0e8edc588795872db47b885",
|
|
@@ -13,13 +13,10 @@ session prefs get
|
|
|
13
13
|
Run:
|
|
14
14
|
aib session prefs get
|
|
15
15
|
|
|
16
|
-
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
17
|
-
Stdin Run lines include the aib prefix to avoid confusion.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@'
|
|
21
|
-
<input>
|
|
22
|
-
'@ | aib <command> --stdin
|
|
16
|
+
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
17
|
+
Stdin Run lines include the aib prefix to avoid confusion.
|
|
18
|
+
|
|
19
|
+
{{stdin.examples}}
|
|
23
20
|
|
|
24
21
|
Basics
|
|
25
22
|
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
Inline commands below omit the aib prefix.
|
|
4
4
|
Run them as: aib <command>
|
|
5
5
|
|
|
6
|
-
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
7
|
-
Stdin Run lines include the aib prefix to avoid confusion.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@'
|
|
11
|
-
<input>
|
|
12
|
-
'@ | aib <command> --stdin
|
|
6
|
+
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
7
|
+
Stdin Run lines include the aib prefix to avoid confusion.
|
|
8
|
+
|
|
9
|
+
{{stdin.examples}}
|
package/dist/help/json/full.md
CHANGED
|
@@ -13,13 +13,10 @@ session prefs get
|
|
|
13
13
|
Run:
|
|
14
14
|
aib session prefs get
|
|
15
15
|
|
|
16
|
-
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
17
|
-
Stdin Run lines include the aib prefix to avoid confusion.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@'
|
|
21
|
-
<input>
|
|
22
|
-
'@ | aib <command> --stdin
|
|
16
|
+
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
17
|
+
Stdin Run lines include the aib prefix to avoid confusion.
|
|
18
|
+
|
|
19
|
+
{{stdin.examples}}
|
|
23
20
|
|
|
24
21
|
Basics
|
|
25
22
|
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
Inline commands below omit the aib prefix.
|
|
2
2
|
Run them as: aib <command>
|
|
3
3
|
|
|
4
|
-
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
5
|
-
Stdin Run lines include the aib prefix to avoid confusion.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@'
|
|
9
|
-
<input>
|
|
10
|
-
'@ | aib <command> --stdin
|
|
4
|
+
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
5
|
+
Stdin Run lines include the aib prefix to avoid confusion.
|
|
6
|
+
|
|
7
|
+
{{stdin.examples}}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
Inline commands below omit the aib prefix.
|
|
2
2
|
Run them as: aib <command>
|
|
3
3
|
|
|
4
|
-
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
5
|
-
Stdin Run lines include the aib prefix to avoid confusion.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@'
|
|
9
|
-
<input>
|
|
10
|
-
'@ | aib <command> --stdin
|
|
4
|
+
Stdin examples show command and input separately to avoid shell-specific syntax.
|
|
5
|
+
Stdin Run lines include the aib prefix to avoid confusion.
|
|
6
|
+
|
|
7
|
+
{{stdin.examples}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var x=exports&&exports.__createBinding||(Object.create?(function(t,e,n,r){r===void 0&&(r=n);var s=Object.getOwnPropertyDescriptor(e,n);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,s)}):(function(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]})),D=exports&&exports.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),M=exports&&exports.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(n){var r=[];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(r[r.length]=s);return r},t(e)};return function(e){if(e&&e.__esModule)return e;var n={};if(e!=null)for(var r=t(e),s=0;s<r.length;s++)r[s]!=="default"&&x(n,e,r[s]);return D(n,e),n}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.startManagedServeWebForCwd=W,exports.stopManagedServeWebForCwd=R,exports.stopAllManagedServeWeb=L,exports.killAllManagedServeWeb=O,exports.statusManagedServeWebForCwd=V,exports.statusAllManagedServeWeb=H,exports.cleanupExpiredManagedServeWebForCwd=j;const g=M(require("node:fs")),c=M(require("node:path")),_=require("node:child_process"),u=require("../config/env-vars"),l=require("../shared/errors"),w=require("../shared/diagnostics"),S=require("./extension-vsix-resolver"),h=require("../config/workspace-root"),
|
|
1
|
+
"use strict";var x=exports&&exports.__createBinding||(Object.create?(function(t,e,n,r){r===void 0&&(r=n);var s=Object.getOwnPropertyDescriptor(e,n);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,s)}):(function(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]})),D=exports&&exports.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),M=exports&&exports.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(n){var r=[];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(r[r.length]=s);return r},t(e)};return function(e){if(e&&e.__esModule)return e;var n={};if(e!=null)for(var r=t(e),s=0;s<r.length;s++)r[s]!=="default"&&x(n,e,r[s]);return D(n,e),n}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.startManagedServeWebForCwd=W,exports.stopManagedServeWebForCwd=R,exports.stopAllManagedServeWeb=L,exports.killAllManagedServeWeb=O,exports.statusManagedServeWebForCwd=V,exports.statusAllManagedServeWeb=H,exports.cleanupExpiredManagedServeWebForCwd=j;const g=M(require("node:fs")),c=M(require("node:path")),_=require("node:child_process"),u=require("../config/env-vars"),l=require("../shared/errors"),w=require("../shared/diagnostics"),S=require("./extension-vsix-resolver"),h=require("../config/workspace-root"),k=require("../runtime/bundled-node"),A=require("../runtime/managed-runtime-provisioning");function N(){const t=[c.resolve(__dirname),process.cwd()];for(const e of t){let n=e;for(;;){const r=c.join(n,"scripts","managed-host","manage-serve-web-host.cjs"),s=c.join(n,"package.json");if(g.existsSync(r)&&g.existsSync(s))return n;const o=c.dirname(n);if(o===n)break;n=o}}return null}function E(t){const e=process.env[t];return e&&e.trim()?c.resolve(e.trim()):null}function C(t){const e=process.env[t];return e&&e.trim()?e.trim():null}function T(){const t=process.env[u.CLI_ENV.managedHostWaitMs];if(t===void 0||t.trim()==="")return 45e3;const e=Number(t);if(!Number.isInteger(e)||e<=0)throw new l.CliError("AUTO_START_IDE_INVALID_WAIT_MS",`Expected ${u.CLI_ENV.managedHostWaitMs} to be a positive integer.`,{env:u.CLI_ENV.managedHostWaitMs,value:t,hints:(0,w.buildAutoStartIdeHints)()});return e}function f(){const t=E(u.CLI_ENV.managedHostScript),e=T(),n=C(u.CLI_ENV.ideCommand),r=E(u.CLI_ENV.chromePath),s=E(u.CLI_ENV.managedHostRunDir),o=N(),a=c.resolve(__dirname,"..","..");(0,A.ensureManagedRuntimeProvisioned)(a);const i=C(u.CLI_ENV.managedHostKind)??y(a),d=(0,k.resolveNodeRuntime)(a);if(t){const m=(0,S.resolveExtensionVsixPath)({repoRoot:o,packageRoot:a});return{scriptPath:t,vsixPath:m.path,vsixSource:m.source,cwd:c.dirname(t),waitMs:e,ideCommand:n,hostKind:i,chromePath:r,runDir:s,nodeCommand:d.command,nodeSource:d.source,source:"env"}}const p=c.join(__dirname,"manage-serve-web-host.cjs");if(g.existsSync(p)){const m=(0,S.resolveExtensionVsixPath)({repoRoot:o,packageRoot:a});return{scriptPath:p,vsixPath:m.path,vsixSource:m.source,cwd:c.resolve(__dirname,"..",".."),waitMs:e,ideCommand:n,hostKind:i,chromePath:r,runDir:s,nodeCommand:d.command,nodeSource:d.source,source:"packaged-cli"}}if(o){const m=(0,S.resolveExtensionVsixPath)({repoRoot:o,packageRoot:a});return{scriptPath:c.join(o,"scripts","managed-host","manage-serve-web-host.cjs"),vsixPath:m.path,vsixSource:m.source,cwd:o,waitMs:e,ideCommand:n,hostKind:i,chromePath:r,runDir:s,nodeCommand:d.command,nodeSource:d.source,source:"repo-dev-fallback"}}throw new l.CliError("AUTO_START_IDE_UNAVAILABLE","Managed IDE auto-start is unavailable because no packaged managed-host assets or development repo managed-host scripts were found.",{searchedFrom:[c.resolve(__dirname),process.cwd()],optionalEnv:[u.CLI_ENV.managedHostScript,u.CLI_ENV.extensionVsix],hints:(0,w.buildAutoStartIdeHints)()})}function y(t){const e=c.join(t,"runtimes","code-server","node_modules","code-server","out","node","entry.js");return g.existsSync(e)&&(0,A.managedRuntimePlatformStatus)(t).ok?"code-server":null}function b(t,e,n,r){if(!g.existsSync(t))throw new l.CliError(e,n,{...r,hints:(0,w.buildAutoStartIdeHints)(),path:t})}function v(t){try{return JSON.parse(t)}catch(e){throw new l.CliError("AUTO_START_IDE_INVALID_OUTPUT","Managed IDE host returned non-JSON output.",{stdout:t,parseError:e instanceof Error?e.message:String(e)})}}async function W(t){const e=f(),r=(0,h.resolveRequiredWorkspaceRoot)(t).root,s=P(r),o=F(r);b(e.scriptPath,"AUTO_START_IDE_SCRIPT_NOT_FOUND","Managed IDE auto-start needs a managed host script.",{env:u.CLI_ENV.managedHostScript,source:e.source}),b(e.vsixPath,"AUTO_START_IDE_VSIX_NOT_FOUND","Managed IDE auto-start needs a packaged extension VSIX.",{env:u.CLI_ENV.extensionVsix,source:e.source,vsixSource:e.vsixSource,hint:e.source==="repo-dev-fallback"?"Run npm --prefix packages/extension run package:vsix before using --auto-start-ide.":`Set ${u.CLI_ENV.extensionVsix} to an existing packaged VSIX path.`});const a=[e.scriptPath,"start","--fixture",r,"--vsix",e.vsixPath,"--wait-ms",String(e.waitMs),"--ttl-ms",String(s),"--interval-ms",String(o)];e.ideCommand&&a.push("--ide-command",e.ideCommand),e.hostKind&&a.push("--host-kind",e.hostKind),e.chromePath&&a.push("--chrome-path",e.chromePath),e.runDir&&a.push("--run-dir",e.runDir);const i=(0,_.spawnSync)(e.nodeCommand,a,{cwd:e.cwd,encoding:"utf8",windowsHide:!0,timeout:e.waitMs+45e3,stdio:["ignore","pipe","pipe"]}),d=i.stdout??"",p=d.trim()?v(d):null;if(i.status!==0||!p||p.ok!==!0)throw new l.CliError("AUTO_START_IDE_FAILED","Managed IDE auto-start failed.",{status:i.status,signal:i.signal,error:i.error?i.error.message:null,stdout:d,stderr:i.stderr??"",runtime:{source:e.source,scriptPath:e.scriptPath,vsixPath:e.vsixPath,vsixSource:e.vsixSource,waitMs:e.waitMs,ideCommand:e.ideCommand,hostKind:e.hostKind,chromePath:e.chromePath,runDir:e.runDir,nodeCommand:e.nodeCommand,nodeSource:e.nodeSource},hints:(0,w.buildAutoStartIdeHints)(),payload:p});return p}async function R(t){const e=f(),n=(0,h.resolveRequiredWorkspaceRoot)(t),r=[e.scriptPath,"stop","--fixture",n.root];e.ideCommand&&r.push("--ide-command",e.ideCommand),e.hostKind&&r.push("--host-kind",e.hostKind);const s=(0,_.spawnSync)(e.nodeCommand,r,{cwd:e.cwd,encoding:"utf8",windowsHide:!0,timeout:3e4,stdio:["ignore","pipe","pipe"]}),o=s.stdout??"",a=o.trim()?v(o):null;if(s.status!==0||!a||a.ok!==!0)throw new l.CliError("MANAGED_IDE_STOP_FAILED","Managed IDE stop failed.",{status:s.status,signal:s.signal,error:s.error?s.error.message:null,stdout:o,stderr:s.stderr??"",workspaceRoot:n.root});return K(n.root,a)}async function L(){return I(["stop","--all"],"MANAGED_IDE_STOP_FAILED")}async function O(){return I(["kill","--all"],"MANAGED_IDE_KILL_FAILED")}async function V(t){const e=f(),n=(0,h.resolveRequiredWorkspaceRoot)(t),r=[e.scriptPath,"status","--fixture",n.root];e.ideCommand&&r.push("--ide-command",e.ideCommand),e.hostKind&&r.push("--host-kind",e.hostKind);const s=(0,_.spawnSync)(e.nodeCommand,r,{cwd:e.cwd,encoding:"utf8",windowsHide:!0,timeout:3e4,stdio:["ignore","pipe","pipe"]}),o=s.stdout??"",a=o.trim()?v(o):null;if(s.status!==0||!a||a.ok!==!0)throw new l.CliError("MANAGED_IDE_STATUS_FAILED","Managed IDE status failed.",{status:s.status,signal:s.signal,error:s.error?s.error.message:null,stdout:o,stderr:s.stderr??"",workspaceRoot:n.root});return q(n.root,a)}async function H(){return I(["status","--all"],"MANAGED_IDE_STATUS_FAILED")}async function j(t){const e=f(),n=(0,h.resolveRequiredWorkspaceRoot)(t),r=P(n.root),s=[e.scriptPath,"cleanup","--ttl-ms",String(r)];e.ideCommand&&s.push("--ide-command",e.ideCommand),e.hostKind&&s.push("--host-kind",e.hostKind);const o=(0,_.spawnSync)(e.nodeCommand,s,{cwd:e.cwd,encoding:"utf8",windowsHide:!0,timeout:3e4,stdio:["ignore","pipe","pipe"]}),a=o.stdout??"",i=a.trim()?v(a):null;if(o.status!==0||!i||i.ok!==!0)throw new l.CliError("MANAGED_IDE_CLEANUP_FAILED","Managed IDE cleanup failed.",{status:o.status,signal:o.signal,error:o.error?o.error.message:null,stdout:a,stderr:o.stderr??"",workspaceRoot:n.root});return i}function I(t,e){const n=f(),r=(0,_.spawnSync)(n.nodeCommand,[n.scriptPath,...t],{cwd:n.cwd,encoding:"utf8",windowsHide:!0,timeout:45e3,stdio:["ignore","pipe","pipe"]}),s=r.stdout??"",o=s.trim()?v(s):null;if(r.status!==0||!o||o.ok!==!0)throw new l.CliError(e,"Managed IDE runtime command failed.",{status:r.status,signal:r.signal,error:r.error?r.error.message:null,stdout:s,stderr:r.stderr??"",args:t});return o}function P(t){if(!(0,h.readWorkspaceBooleanConfig)(t,"runtime.autoStopManagedIde",!0))return 0;const n=(0,h.readWorkspaceNumberConfig)(t,"runtime.managedIdeTtlMinutes",15);return n>0?Math.round(n*6e4):0}function F(t){const e=(0,h.readWorkspaceNumberConfig)(t,"runtime.managedIdeWatchdogIntervalMs",3e4);return e>0?Math.round(e):3e4}function K(t,e){return{stopped:e.stopped===!0,workspaceRoot:t,...typeof e.hostId=="string"?{hostId:e.hostId}:{},...typeof e.reason=="string"?{reason:e.reason}:{}}}function q(t,e){const n=e.metadata&&typeof e.metadata=="object"&&!Array.isArray(e.metadata)?e.metadata:{},r=e.health&&typeof e.health=="object"&&!Array.isArray(e.health)?e.health:{};return{ok:!0,workspaceRoot:t,workspace:".",hostId:typeof e.hostId=="string"?e.hostId:null,host:typeof n.hostKind=="string"?n.hostKind:"managed",running:e.running===!0,healthy:e.healthy===!0,reason:typeof e.reason=="string"?e.reason:null,health:{serveWebAlive:r.serveWebAlive===!0,browserAlive:r.browserAlive===!0,extensionHostAlive:r.extensionHostAlive===!0,workspaceMatches:r.workspaceMatches===!0,vsixMatches:r.vsixMatches===!0}}}
|