@automaton-labs/aib 0.0.5 → 0.0.7
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 +4 -2
- package/dist/commands/apply-module-plan.js +3 -3
- package/dist/commands/background-command.js +2 -0
- package/dist/commands/captured-input.js +1 -2
- package/dist/commands/config-command.js +2 -1
- package/dist/commands/config-output.js +10 -8
- package/dist/commands/control-plane-command.js +1 -0
- package/dist/commands/declaration-command.js +7 -0
- package/dist/commands/declaration-execution-cache.js +1 -0
- package/dist/commands/declaration-format.js +1 -0
- package/dist/commands/declaration-preview-cache.js +2 -0
- package/dist/commands/doctor.js +3 -1
- package/dist/commands/execution-command.js +1 -1
- package/dist/commands/file-command.js +1 -0
- package/dist/commands/file-move-to-dir-execution-cache.js +1 -0
- package/dist/commands/file-move-to-dir-preview-cache.js +2 -0
- package/dist/commands/file-move-to-dir.js +5 -0
- package/dist/commands/file-mutation-runtime.js +1 -0
- package/dist/commands/file-refactor-batch-execution-cache.js +1 -0
- package/dist/commands/file-refactor-batch-preview-cache.js +2 -0
- package/dist/commands/file-refactor-batch.js +5 -0
- package/dist/commands/file-rename-execution-cache.js +1 -0
- package/dist/commands/file-rename-preview-cache.js +2 -0
- package/dist/commands/file-rename.js +5 -0
- package/dist/commands/help-command.js +5 -5
- package/dist/commands/host-command.js +1 -0
- package/dist/commands/inspect-cycles.js +3 -3
- package/dist/commands/inspect-format.js +15 -15
- package/dist/commands/inspect-tree.js +2 -2
- package/dist/commands/inspect.js +12 -12
- package/dist/commands/move-to-file.js +2 -2
- package/dist/commands/ota-command.js +2 -0
- package/dist/commands/quick-read.js +8 -8
- package/dist/commands/refactor-batch.js +4 -4
- package/dist/commands/rename-entities.js +4 -4
- package/dist/commands/result-view.js +6 -5
- package/dist/commands/session-workspace.js +7 -7
- package/dist/commands/worker-command.js +1 -0
- package/dist/config/defaults.js +1 -1
- package/dist/config/env-vars.js +1 -1
- package/dist/config/path-aliases.js +1 -1
- package/dist/config/resolve-command-alias.js +1 -1
- package/dist/config/workspace-root.js +3 -3
- package/dist/content/content-bundle.js +1 -1
- package/dist/dsl/aib-dsl.js +1 -1
- package/dist/dsl/declaration-dsl.js +1 -0
- package/dist/dsl/file-move-to-dir-dsl.js +1 -0
- package/dist/dsl/file-refactor-batch-dsl.js +1 -0
- package/dist/dsl/file-rename-dsl.js +1 -0
- package/dist/help/bootstrap.bash.md +907 -0
- package/dist/help/bootstrap.md +105 -144
- package/dist/help/{json/bootstrap.md → bootstrap.pwsh.md} +216 -397
- package/dist/help/docs/dsl.md +4 -3
- package/dist/help/docs/file.move.md +46 -0
- package/dist/help/docs/file.rename.md +35 -0
- package/dist/help/docs/help-format.md +4 -7
- package/dist/help/docs/inspect.code.md +5 -5
- package/dist/help/docs/inspect.deps.md +7 -7
- package/dist/help/docs/inspect.file.md +2 -1
- package/dist/help/docs/inspect.graph.md +3 -3
- package/dist/help/docs/inspect.md +5 -5
- package/dist/help/docs/mutation.md +23 -13
- package/dist/help/docs/patterns.md +1 -5
- package/dist/help/docs/qr.md +7 -22
- package/dist/help/docs/quick-map.md +1 -0
- package/dist/help/docs/recipe.file-layout.md +15 -0
- package/dist/help/docs/rg.md +22 -0
- package/dist/help/docs/selectors.md +3 -2
- package/dist/help/docs/session.md +1 -1
- package/dist/help/dsl/bootstrap.bash.md +907 -0
- package/dist/help/dsl/bootstrap.md +105 -144
- package/dist/help/{json/full.md → dsl/bootstrap.pwsh.md} +216 -397
- package/dist/help/dsl/docs/dsl.md +4 -3
- package/dist/help/dsl/docs/file.move.md +46 -0
- package/dist/help/dsl/docs/file.rename.md +35 -0
- package/dist/help/dsl/docs/help-format.md +4 -7
- package/dist/help/dsl/docs/inspect.code.md +5 -5
- package/dist/help/dsl/docs/inspect.deps.md +7 -7
- package/dist/help/dsl/docs/inspect.file.md +2 -1
- package/dist/help/dsl/docs/inspect.graph.md +3 -3
- package/dist/help/dsl/docs/inspect.md +5 -5
- package/dist/help/dsl/docs/mutation.md +23 -13
- package/dist/help/dsl/docs/patterns.md +1 -5
- package/dist/help/dsl/docs/qr.md +7 -22
- package/dist/help/dsl/docs/quick-map.md +1 -0
- package/dist/help/dsl/docs/recipe.file-layout.md +15 -0
- package/dist/help/dsl/docs/rg.md +22 -0
- package/dist/help/dsl/docs/selectors.md +3 -2
- package/dist/help/dsl/docs/session.md +1 -1
- package/dist/help/dsl/full.md +105 -144
- package/dist/help/dsl/help-index.md +44 -0
- package/dist/help/dsl/tokens/qr.inline.examples.md +2 -0
- package/dist/help/dsl/tokens/stdin.examples.bash.md +8 -0
- package/dist/help/dsl/tokens/stdin.examples.pwsh.md +8 -0
- package/dist/help/dsl/tokens/stdin.examples.with-qr.bash.md +12 -0
- package/dist/help/dsl/tokens/stdin.examples.with-qr.pwsh.md +12 -0
- package/dist/help/dsl/topics/dsl.md +4 -3
- package/dist/help/dsl/topics/file.move.md +44 -0
- package/dist/help/dsl/topics/file.rename.md +33 -0
- package/dist/help/dsl/topics/help-format.md +4 -7
- package/dist/help/dsl/topics/inspect.code.md +5 -5
- package/dist/help/dsl/topics/inspect.deps.md +7 -7
- package/dist/help/dsl/topics/inspect.file.md +2 -1
- package/dist/help/dsl/topics/inspect.graph.md +3 -3
- package/dist/help/dsl/topics/inspect.md +5 -5
- package/dist/help/dsl/topics/mutation.md +23 -13
- package/dist/help/dsl/topics/patterns.md +1 -5
- package/dist/help/dsl/topics/qr.md +7 -22
- package/dist/help/dsl/topics/quick-map.md +1 -0
- package/dist/help/dsl/topics/recipe.file-layout.md +13 -0
- package/dist/help/dsl/topics/rg.md +20 -0
- package/dist/help/dsl/topics/selectors.md +3 -2
- package/dist/help/dsl/topics/session.md +1 -1
- package/dist/help/full.md +105 -144
- package/dist/help/help-index.md +44 -0
- package/dist/help/help-meta.json +45 -29
- package/dist/help/index.md +32 -75
- package/dist/help/tokens/qr.inline.examples.md +2 -0
- package/dist/help/tokens/stdin.examples.bash.md +8 -0
- package/dist/help/tokens/stdin.examples.pwsh.md +8 -0
- package/dist/help/tokens/stdin.examples.with-qr.bash.md +12 -0
- package/dist/help/tokens/stdin.examples.with-qr.pwsh.md +12 -0
- package/dist/help/topics/dsl.md +4 -3
- package/dist/help/topics/file.move.md +44 -0
- package/dist/help/topics/file.rename.md +33 -0
- package/dist/help/topics/help-format.md +4 -7
- package/dist/help/topics/inspect.code.md +5 -5
- package/dist/help/topics/inspect.deps.md +7 -7
- package/dist/help/topics/inspect.file.md +2 -1
- package/dist/help/topics/inspect.graph.md +3 -3
- package/dist/help/topics/inspect.md +5 -5
- package/dist/help/topics/mutation.md +23 -13
- package/dist/help/topics/patterns.md +1 -5
- package/dist/help/topics/qr.md +7 -22
- package/dist/help/topics/quick-map.md +1 -0
- package/dist/help/topics/recipe.file-layout.md +13 -0
- package/dist/help/topics/rg.md +20 -0
- package/dist/help/topics/selectors.md +3 -2
- package/dist/help/topics/session.md +1 -1
- package/dist/host/capabilities.js +1 -0
- package/dist/ide-launch/common.cjs +162 -162
- package/dist/managed-host/extension-vsix-resolver.js +1 -1
- package/dist/managed-host/manage-serve-web-host.cjs +141 -141
- package/dist/managed-host/serve-web-autostart.js +1 -1
- package/dist/managed-host/serve-web-host.cjs +1985 -1660
- package/dist/observability/config.js +1 -1
- package/dist/payloads/read-stdin-json.js +1 -1
- package/dist/rg-wrapper/core.js +6 -0
- package/dist/rg-wrapper/options.js +1 -0
- package/dist/rtk-wrapper/core.js +2 -0
- package/dist/runtime/input-source.js +1 -1
- package/dist/runtime/managed-runtime-provisioning.js +1 -1
- package/dist/runtime/run-command.js +1 -1
- package/dist/selectors/parse-entities.js +1 -1
- package/dist/session/daemon-state.js +2 -0
- package/dist/session/server.js +7 -6
- package/dist/shared/errors.js +14 -13
- package/dist/shared/operations.js +1 -1
- package/dist/shared/protocol.js +1 -1
- package/dist/shared/routes.js +1 -1
- package/dist/shared/stdin-examples.js +1 -0
- package/dist/shared/types.js +1 -1
- package/dist/tool-runtime/runtime-tools.js +1 -0
- package/dist/tracing/trace.js +5 -3
- package/dist/workers/control-plane/aib-control-plane-worker.cjs +80 -0
- package/dist/workers/control-plane/client-config.default.json +3 -0
- package/dist/workers/product-storage.js +1 -0
- package/dist/workers/registry.js +1 -0
- package/extension/vscode-refactor-bridge-extension.vsix +0 -0
- package/package.json +6 -4
- package/runtimes/launcher/linux-x64/aib +0 -0
- package/runtimes/launcher/win-x64/aib.exe +0 -0
- package/runtimes/tools/rg/darwin-arm64/rg +0 -0
- package/runtimes/tools/rg/darwin-x64/rg +0 -0
- package/runtimes/tools/rg/linux-arm64/rg +0 -0
- package/runtimes/tools/rg/linux-x64/rg +0 -0
- package/runtimes/tools/rg/manifest.json +36 -0
- package/runtimes/tools/rg/win32-x64/rg.exe +0 -0
- package/runtimes/tools/rtk/darwin-arm64/rtk +0 -0
- package/runtimes/tools/rtk/darwin-x64/rtk +0 -0
- package/runtimes/tools/rtk/linux-arm64/rtk +0 -0
- package/runtimes/tools/rtk/linux-x64/rtk +0 -0
- package/runtimes/tools/rtk/manifest.json +36 -0
- package/runtimes/tools/rtk/win32-x64/rtk.exe +0 -0
- package/scripts/provision-runtime.cjs +25 -1
- package/dist/help/json/docs/basics.md +0 -15
- package/dist/help/json/docs/config-setup.aliases.md +0 -56
- package/dist/help/json/docs/config-setup.excludes.md +0 -45
- package/dist/help/json/docs/config-setup.import-normalize.md +0 -86
- package/dist/help/json/docs/config-setup.import-rules.md +0 -96
- package/dist/help/json/docs/config-setup.tsconfigs.md +0 -33
- package/dist/help/json/docs/dsl.md +0 -25
- package/dist/help/json/docs/first-setup.md +0 -292
- package/dist/help/json/docs/help-format.md +0 -12
- package/dist/help/json/docs/help-protocol.md +0 -26
- package/dist/help/json/docs/imports.normalize.md +0 -47
- package/dist/help/json/docs/inspect.code.md +0 -41
- package/dist/help/json/docs/inspect.cycles.md +0 -38
- package/dist/help/json/docs/inspect.deps.md +0 -46
- package/dist/help/json/docs/inspect.duplicates.md +0 -65
- package/dist/help/json/docs/inspect.exports.md +0 -40
- package/dist/help/json/docs/inspect.file.md +0 -38
- package/dist/help/json/docs/inspect.graph.md +0 -139
- package/dist/help/json/docs/inspect.imports.md +0 -15
- package/dist/help/json/docs/inspect.md +0 -88
- package/dist/help/json/docs/inspect.members.md +0 -32
- package/dist/help/json/docs/inspect.tree.md +0 -32
- package/dist/help/json/docs/inspect.usages.md +0 -61
- package/dist/help/json/docs/modulePlan.md +0 -73
- package/dist/help/json/docs/move.md +0 -56
- package/dist/help/json/docs/mutation.md +0 -65
- package/dist/help/json/docs/patterns.md +0 -76
- package/dist/help/json/docs/prefs.md +0 -40
- package/dist/help/json/docs/qr.md +0 -37
- package/dist/help/json/docs/quick-map.md +0 -30
- package/dist/help/json/docs/refactor.batch.md +0 -72
- package/dist/help/json/docs/rename.md +0 -47
- package/dist/help/json/docs/reveal.md +0 -30
- package/dist/help/json/docs/selectors.md +0 -23
- package/dist/help/json/docs/session.md +0 -77
- package/dist/help/json/docs/view.md +0 -30
- package/dist/help/json/snippets/agents.md +0 -14
- package/dist/help/json/topics/basics.md +0 -13
- package/dist/help/json/topics/config-setup.aliases.md +0 -54
- package/dist/help/json/topics/config-setup.excludes.md +0 -43
- package/dist/help/json/topics/config-setup.import-normalize.md +0 -84
- package/dist/help/json/topics/config-setup.import-rules.md +0 -94
- package/dist/help/json/topics/config-setup.tsconfigs.md +0 -31
- package/dist/help/json/topics/dsl.md +0 -23
- package/dist/help/json/topics/first-setup.md +0 -290
- package/dist/help/json/topics/help-format.md +0 -10
- package/dist/help/json/topics/help-protocol.md +0 -24
- package/dist/help/json/topics/imports.normalize.md +0 -45
- package/dist/help/json/topics/inspect.code.md +0 -39
- package/dist/help/json/topics/inspect.cycles.md +0 -36
- package/dist/help/json/topics/inspect.deps.md +0 -44
- package/dist/help/json/topics/inspect.duplicates.md +0 -37
- package/dist/help/json/topics/inspect.exports.md +0 -38
- package/dist/help/json/topics/inspect.file.md +0 -36
- package/dist/help/json/topics/inspect.graph.md +0 -137
- package/dist/help/json/topics/inspect.imports.md +0 -13
- package/dist/help/json/topics/inspect.md +0 -86
- package/dist/help/json/topics/inspect.members.md +0 -30
- package/dist/help/json/topics/inspect.tree.md +0 -22
- package/dist/help/json/topics/inspect.usages.md +0 -59
- package/dist/help/json/topics/modulePlan.md +0 -60
- package/dist/help/json/topics/move.md +0 -46
- package/dist/help/json/topics/mutation.md +0 -63
- package/dist/help/json/topics/patterns.md +0 -74
- package/dist/help/json/topics/prefs.md +0 -38
- package/dist/help/json/topics/qr.md +0 -35
- package/dist/help/json/topics/quick-map.md +0 -28
- package/dist/help/json/topics/refactor.batch.md +0 -61
- package/dist/help/json/topics/rename.md +0 -42
- package/dist/help/json/topics/reveal.md +0 -28
- package/dist/help/json/topics/selectors.md +0 -21
- package/dist/help/json/topics/session.md +0 -59
- package/dist/help/json/topics/view.md +0 -28
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var oe=exports&&exports.__createBinding||(Object.create?(function(e,t,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}):(function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]})),ae=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),J=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(r){var n=[];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[n.length]=o);return n},e(t)};return function(t){if(t&&t.__esModule)return t;var r={};if(t!=null)for(var n=e(t),o=0;o<n.length;o++)n[o]!=="default"&&oe(r,t,n[o]);return ae(r,t),r}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.runRefactorBatch=de,exports.readCachedRefactorBatchExecution=he;const G=J(require("node:fs")),M=J(require("node:path")),A=require("zod"),ie=require("../client/http-client"),w=require("../config/env-vars"),se=require("../config/product-storage"),ce=require("../shared/routes"),ue=require("../shared/protocol"),P=require("../shared/agent-text"),le=require("../shared/errors"),fe=require("./refactor-batch-builder"),
|
|
2
|
-
`)}function we(e,t,r,n,o){const a=(0,x.readRefactorBatchExecutionStatus)(e,t),u=Math.max(0,n-o),s={operation:"execution.status",executionId:a.executionId,status:a.status,phase:a.phase,summary:F(a),progress:`${a.completedRows}/${a.rowCount}`,filesWritten:a.filesWritten,updatedAt:a.updatedAt,estimatedRemainingMs:u};return(0,P.attachAgentText)(s,ge(r,a,u))}function ge(e,t,r){return[`${e} ${t.executionId}`,F(t),"applying mutation"
|
|
3
|
-
`)}function
|
|
4
|
-
`)}function F(e){return e.status==="completed"?`completed, ${e.completedRows}/${e.rowCount} rows, ${e.filesWritten.length} files written`:e.status==="failed"?`failed, ${e.completedRows}/${e.rowCount} rows, ${e.failedRows} failed`:`in progress, ${e.completedRows}/${e.rowCount} rows`}function
|
|
1
|
+
"use strict";var oe=exports&&exports.__createBinding||(Object.create?(function(e,t,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}):(function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]})),ae=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),J=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(r){var n=[];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[n.length]=o);return n},e(t)};return function(t){if(t&&t.__esModule)return t;var r={};if(t!=null)for(var n=e(t),o=0;o<n.length;o++)n[o]!=="default"&&oe(r,t,n[o]);return ae(r,t),r}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.runRefactorBatch=de,exports.readCachedRefactorBatchExecution=he;const G=J(require("node:fs")),M=J(require("node:path")),A=require("zod"),ie=require("../client/http-client"),w=require("../config/env-vars"),se=require("../config/product-storage"),ce=require("../shared/routes"),ue=require("../shared/protocol"),P=require("../shared/agent-text"),le=require("../shared/errors"),fe=require("./refactor-batch-builder"),C=require("./refactor-batch-preview-cache"),x=require("./refactor-batch-execution-cache"),K=require("./mutation-execution-cache"),j=require("./shared"),q=A.z.object({operations:A.z.array(A.z.unknown()).min(1).optional(),requests:A.z.array(A.z.unknown()).min(1).optional(),continueOnError:A.z.boolean().optional(),execution:A.z.literal("sequential").optional()}).passthrough().refine(e=>Array.isArray(e.operations)||Array.isArray(e.requests),{message:"refactor batch expects operations[] or requests[]."});async function de(e,t,r={},n="preview",o={}){if(n==="apply"&&o.previewId){const u=L();if(u>0){const s=U(e,o.previewId),h=q.parse(z(s.normalizedPayload,!0));return X(e,h,r,"apply",{...o,previewId:o.previewId},u)}return pe(e,o.previewId,r,o)}const a=q.parse(t);return(n==="execute"||n==="apply")&&L()>0?X(e,a,r,n,o,L()):N(e,a,r,n,o)}async function pe(e,t,r,n){const o=U(e,t),a=q.parse(z(o.normalizedPayload,!0));return N(e,a,r,"apply",{...n,previewId:t})}function U(e,t){const r=(0,C.readRefactorBatchPreviewRecord)(e,t),n=r.files.find(o=>G.existsSync(o.file)!==o.existed||(0,C.hashFileIfExists)(o.file)!==o.hash);if(n)throw new le.CliError("REFACTOR_BATCH_PREVIEW_FILES_CHANGED","Touched files changed after refactor batch preview. Rerun preview.",{previewId:t,file:k(e,n.file)});return r}async function X(e,t,r,n,o,a){const u=(0,x.buildRefactorBatchExecutionId)(),s=`refactor.batch.${n}`,h=Ae(t),p=(0,x.createRefactorBatchExecutionStatus)(e,u,s,Q(t));(0,x.writeRefactorBatchExecutionStatus)(e,p);const f=Date.now(),y=$e(),R=be(()=>(0,se.runWithProductStorageOverride)(y[w.CLI_ENV.productStorageDir],()=>Ce(y,async()=>{try{const l=await N(e,t,r,n,o),g=Y(l);return p.status=l.ok===!1?"failed":"completed",p.phase="completed",p.completedRows=g.filter(i=>i.ok!==!1).length,p.failedRows=g.filter(i=>i.ok===!1).length,p.filesWritten=xe(l),p.result=l,l.ok===!1&&(p.error=c(l.code)??"REFACTOR_BATCH_FAILED"),(0,x.writeRefactorBatchExecutionStatus)(e,p),l}catch(l){throw p.status="failed",p.phase="completed",p.error=l instanceof Error?l.message:String(l),(0,x.writeRefactorBatchExecutionStatus)(e,p),l}}))),m=await _e(R,a);return m.status==="result"?m.result:(R.catch(()=>{}),we(e,u,s,h,Date.now()-f))}async function N(e,t,r,n,o){await Be();const a=await(0,j.resolveCompatibleTargetInstance)(e,ue.CLI_COMMAND_IDS.refactorBatch,r),u=await(0,j.fetchEffectiveConfig)(a.entry,r),s=(0,fe.buildExtensionRefactorBatchPayload)(t,u),h=await(0,ie.postJson)(a.entry,ce.EXTENSION_ROUTES.refactorBatch,s.payload,(0,j.extensionRequestOptions)(r)),p=me(e,h),f={ok:p.batchOk===!0,...p.batchOk===!0?{}:{code:"REFACTOR_BATCH_FAILED"},operation:`refactor.batch.${n}`,builder:s.summary,response:p};if(n==="preview"&&f.ok!==!1){const R=z(t,!1),m=(0,C.buildRefactorBatchPreviewId)(R),l=Ie(e,s.payload),g=(0,C.buildRefactorBatchPreviewHash)(R,l,f);(0,C.writeRefactorBatchPreviewRecord)(e,{previewId:m,previewHash:g,createdAt:new Date().toISOString(),cwd:M.resolve(e),normalizedPayload:R,files:l,builder:s.summary,previewResult:f}),f.previewId=m,f.next=`aib refactor batch apply ${m}`}const y={...o,...typeof f.previewId=="string"?{previewId:f.previewId}:{},...typeof f.next=="string"?{next:f.next}:{}};return(0,P.attachAgentText)(f,Re(e,s.summary,p,n,y))}function he(e,t){const r=(0,x.readRefactorBatchExecutionStatus)(e,t);if((r.status==="completed"||r.status==="failed")&&r.result)return r.result;const n={operation:"execution.status",executionId:r.executionId,status:r.status,phase:r.phase,summary:F(r),progress:`${r.completedRows}/${r.rowCount}`,filesWritten:r.filesWritten,updatedAt:r.updatedAt,...r.error?{error:r.error}:{}};return(0,P.attachAgentText)(n,ve(r))}function me(e,t){const r=Array.isArray(t.rows)?t.rows.map(n=>ye(e,n)):[];return{ok:t.ok===!0,operation:c(t.operation),contract:t.contract??null,execution:c(t.execution),continueOnError:t.continueOnError===!0,batchOk:t.batchOk===!0,batchStatus:c(t.batchStatus),requestedOperationCount:v(t.requestedOperationCount),plannedOperationCount:v(t.plannedOperationCount),attemptedRowCount:v(t.attemptedRowCount),rowCount:v(t.rowCount),passedRowCount:v(t.passedRowCount),failedRowCount:v(t.failedRowCount),skippedRowCount:v(t.skippedRowCount),guidance:t.guidance??null,rows:r,...t._metrics?{_metrics:t._metrics}:{}}}function ye(e,t){if(!t||typeof t!="object"||Array.isArray(t))return{ok:!1,error:"Invalid batch row shape."};const r=t;return r.skipped===!0?T({index:v(r.index),id:c(r.id),kind:c(r.kind),planned:r.planned===!0,attempted:!1,outcome:c(r.outcome),skipped:!0,skipReason:c(r.skipReason),error:c(r.error)}):T({index:v(r.index),id:c(r.id),kind:c(r.kind),planned:r.planned===!0,attempted:r.attempted===!0,outcome:c(r.outcome),ok:r.ok===!0,statusCode:v(r.statusCode),durationMs:v(r.durationMs),applied:r.applied===!0,touchedFiles:E(r.touchedFiles).map(n=>k(e,n)),savedFiles:E(r.savedFiles).map(n=>k(e,n)),error:c(r.error),response:Le(r.response)})}function Re(e,t,r,n,o={}){const a=Array.isArray(r.rows)?r.rows.filter(l=>!!l&&typeof l=="object"&&!Array.isArray(l)):[],u=a.filter(l=>l.outcome==="applied").length,s=a.filter(l=>l.outcome==="validated").length,h=typeof r.failedRowCount=="number"?r.failedRowCount:a.filter(l=>l.ok===!1).length,p=n==="execute"||n==="apply"||n==="validate"?n:u>0?"apply":"preview",f=[];o.routedFrom==="move.toFile"&&(f.push("move.toFile routed to refactor.batch"),f.push(""));const y=Me(t,e),R=Fe(t);if(f.push(Ee(p,o)),f.push(Se(p,{movePlan:y,renamePlan:R},a,u,s,h)),(y||R)&&a.length>0)ke(f,{movePlan:y,renamePlan:R},a);else for(const l of a){const g=c(l.id)??`row ${v(l.index)??"?"}`,i=c(l.kind)??"operation",b=c(l.outcome)??(l.ok===!0?"ok":"failed");f.push(`${Pe(i)} ${je(g)} ${b}`)}const m=D(a.flatMap(l=>E(l.savedFiles)));return m.length>0&&(f.push("filesWritten:"),f.push(...m)),o.next&&f.push(`next: ${o.next}`),f.join(`
|
|
2
|
+
`)}function we(e,t,r,n,o){const a=(0,x.readRefactorBatchExecutionStatus)(e,t),u=Math.max(0,n-o),s={operation:"execution.status",executionId:a.executionId,status:a.status,phase:a.phase,summary:F(a),progress:`${a.completedRows}/${a.rowCount}`,filesWritten:a.filesWritten,updatedAt:a.updatedAt,estimatedRemainingMs:u};return(0,P.attachAgentText)(s,ge(r,a,u))}function ge(e,t,r){return[`${e} ${t.executionId}`,F(t),"applying mutation",r>0?`estimated remaining: ${Ne(Math.max(r,5e3))}`:"estimated remaining: check status again soon"].join(`
|
|
3
|
+
`)}function ve(e){const t=[`${e.operation} ${e.executionId}`,F(e)];return e.status==="running"&&t.push("applying mutation"),e.error&&t.push(e.error),t.join(`
|
|
4
|
+
`)}function F(e){return e.status==="completed"?`completed, ${e.completedRows}/${e.rowCount} rows, ${e.filesWritten.length} files written`:e.status==="failed"?`failed, ${e.completedRows}/${e.rowCount} rows, ${e.failedRows} failed`:`in progress, ${e.completedRows}/${e.rowCount} rows`}function be(e){return new Promise((t,r)=>{setImmediate(()=>{e().then(t,r)})})}async function _e(e,t){return(0,K.waitForMutationDeadline)(e,t)}function L(){return(0,K.readMutationSyncWaitMs)(process.env[w.CLI_ENV.refactorBatchSyncWaitMs],12e4)}function Ae(e){return 12e3+Q(e)*2e3}function Q(e){const t=Array.isArray(e.operations)?e.operations:Array.isArray(e.requests)?e.requests:[];let r=0;for(const n of t){if(!_(n)){r+=1;continue}const o=Array.isArray(n.entities)?n.entities:Array.isArray(n.symbols)?n.symbols:[],a=Array.isArray(n.renames)?n.renames:[];r+=Math.max(1,o.length,a.length)}return Math.max(1,r)}function xe(e){const t=Y(e);return D(t.flatMap(r=>E(r.savedFiles)))}function Y(e){const t=_(e.response)?e.response:null;return Array.isArray(t?.rows)?t.rows.filter(_):[]}async function Be(){const e=process.env[w.CLI_ENV.testRefactorBatchDelayMs];if(!e)return;const t=Number.parseInt(e,10);!Number.isFinite(t)||t<=0||await new Promise(r=>setTimeout(r,Math.min(t,12e4)))}function $e(){const e=[w.CLI_ENV.productStorageDir,w.CLI_ENV.trace,w.CLI_ENV.traceDir,w.CLI_ENV.metrics,w.CLI_ENV.metricsDir,w.CLI_ENV.metricsTag,w.CLI_ENV.mutationImpactMetrics,w.CLI_ENV.mutationImpactStream,w.CLI_ENV.testMoveToFileFailEntity,w.CLI_ENV.testRefactorBatchDelayMs],t={};for(const r of e)t[r]=process.env[r];return t}async function Ce(e,t){const r={};for(const[n,o]of Object.entries(e))r[n]=process.env[n],o===void 0?delete process.env[n]:process.env[n]=o;try{return await t()}finally{for(const[n,o]of Object.entries(r))o===void 0?delete process.env[n]:process.env[n]=o}}function Ie(e,t){const r=Array.isArray(t.operations)?t.operations.filter(_):[],n=new Set;for(const o of r){const a=_(o.body)?o.body:{},u=c(a.sourceFile),s=c(a.targetFile);u&&n.add(Z(e,u)),s&&n.add(Z(e,s))}return Array.from(n).sort((o,a)=>o.localeCompare(a)).map(o=>({file:o,existed:G.existsSync(o),hash:(0,C.hashFileIfExists)(o)}))}function Z(e,t){return M.normalize(M.isAbsolute(t)?t:M.resolve(e,t))}function Ee(e,t){return e==="preview"&&t.previewId?`refactor.batch.preview ${t.previewId}`:`refactor.batch.${e}`}function Se(e,t,r,n,o,a){const u=t.movePlan?.rows??[],s=t.renamePlan?.rows??[];if(u.length===0&&s.length===0)return`${r.length} rows, ${n>0?`${n} applied`:`${o} validated`}${a>0?`, ${a} failed`:""}`;const h=new Map(r.map(d=>[c(d.id),d]).filter(d=>!!d[0])),p=r.find(d=>d.ok===!1||d.outcome==="failed")??null,f=p?c(p.id):null,y=f?u.some(d=>d.id===f):!1,R=f?s.some(d=>d.id===f):!1,m=new Set(r.filter(d=>d.outcome==="applied").map(d=>c(d.id)).filter(d=>!!d)),l=new Set(r.filter(d=>d.outcome==="validated").map(d=>c(d.id)).filter(d=>!!d)),g=new Set(u.map(d=>d.targetFile)).size,i=D(r.flatMap(d=>E(d.savedFiles))).length,b=u.filter(d=>m.has(d.id)||l.has(d.id)).length,B=s.filter(d=>m.has(d.id)||l.has(d.id)).length;if(p){const d=[...s,...u],V=f?d.findIndex($=>$.id===f):-1,H=d.filter(($,ne)=>!m.has($.id)&&!l.has($.id)&&$.id!==f&&(V<0||ne>V||!h.has($.id))).length,I=[];return B>0&&I.push(`${B} ${B===1?"rename":"renames"} applied`),b>0&&I.push(`${b} ${b===1?"symbol":"symbols"} moved`),I.push(y?"1 symbol failed":R?"1 rename failed":"1 failed"),H>0&&I.push(`${H} not run`),I.join(", ")}const S=[];s.length>0&&S.push(`${s.length} ${s.length===1?"rename":"renames"}`),u.length>0&&(S.push(`${u.length} ${u.length===1?"symbol":"symbols"}`),S.push(`${g} ${g===1?"target":"targets"}`));const O=S.join(", ");if(e==="preview"||e==="validate")return`${O} ready`;const W=s.length>0?"applied":"moved";return i>0?`${O} ${W}; ${i} ${i===1?"file":"files"} written`:`${O} ${W}`}function Me(e,t){const n=(Array.isArray(e.rows)?e.rows.filter(_):[]).filter(a=>c(a.op)==="move");if(n.length===0)return null;const o=[];for(const a of n){const u=Array.isArray(a.builtRows)?a.builtRows.filter(_):[];for(const s of u){const h=c(s.id),p=c(s.entity),f=c(s.targetFile);h&&p&&f&&o.push({id:h,entity:p,targetFile:k(t,f)})}}return o.length>0?{rows:o}:null}function Fe(e){const r=(Array.isArray(e.rows)?e.rows.filter(_):[]).filter(o=>c(o.op)==="rename");if(r.length===0)return null;const n=[];for(const o of r){const a=Array.isArray(o.builtRows)?o.builtRows.filter(_):[];for(const u of a){const s=c(u.id),h=c(u.entity),p=c(u.newName);s&&h&&p&&n.push({id:s,entity:h,newName:p})}}return n.length>0?{rows:n}:null}function ke(e,t,r){const n=t.movePlan?.rows??[],o=t.renamePlan?.rows??[],a=new Map(r.map(i=>[c(i.id),i]).filter(i=>!!i[0])),u=new Set(r.filter(i=>i.outcome==="applied").map(i=>c(i.id)).filter(i=>!!i)),s=r.find(i=>i.ok===!1||i.outcome==="failed")??null,h=s?c(s.id):null,p=h?n.find(i=>i.id===h)??null:null,f=h?o.find(i=>i.id===h)??null:null,y=[...o,...n];if(s===null&&y.every(i=>u.has(i.id)||a.get(i.id)?.outcome==="validated")){ee(e,o,a,u),te(e,n,a,u);return}if(ee(e,o.filter(i=>u.has(i.id)),a,u),te(e,n.filter(i=>u.has(i.id)),a,u),s){e.push("failed:"),p?e.push(`${p.entity} -> ${p.targetFile}`):f&&e.push(`${f.entity} -> ${f.newName}`);const i=_(s.response)?s.response:null,b=c(i?.code)??c(i?.errorCode)??c(s.statusCode),B=qe(c(s.error)??(i?c(i.error):null));b&&e.push(`code: ${b}`),B&&e.push(B)}const m=h??null,l=m?y.findIndex(i=>i.id===m):-1,g=y.filter((i,b)=>!u.has(i.id)&&i.id!==h&&(l<0||b>l||!a.has(i.id)));g.length>0&&(e.push("not run:"),e.push(re(g.map(i=>i.entity),15)))}function ee(e,t,r,n){const o=t.filter(a=>n.has(a.id)||r.get(a.id)?.outcome==="validated");if(o.length!==0){e.push("renames:");for(const a of o)e.push(`${a.entity} -> ${a.newName}`)}}function te(e,t,r,n){const o=t.filter(a=>n.has(a.id)||r.get(a.id)?.outcome==="validated");o.length!==0&&(e.push("moves:"),Oe(e,o))}function Oe(e,t){const r=new Map;for(const n of t){const o=r.get(n.targetFile)??[];o.push(n.entity),r.set(n.targetFile,o)}for(const[n,o]of r)e.push(`${n}: ${re(o,15)}`)}function Pe(e){return e==="moveRefactor"?"move":e==="renameSymbol"?"rename":e}function je(e){const t=e.indexOf(":");return t>=0?e.slice(t+1):e}function D(e){return Array.from(new Set(e))}function re(e,t){const r=e.slice(0,t),n=e.length-r.length;return n>0?`${r.join(", ")}, + ${n} more`:r.join(", ")}function qe(e){return e?.replace(/^TypeScript refactor failed: Debug Failure\. False expression: /,"")??null}function Ne(e){const t=Math.max(1,Math.round(e/1e3));return t<60?`~${t} sec`:`~${Math.max(1,Math.round(t/60))} min`}function _(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function k(e,t){const r=t.replace(/\\/g,"/"),n=e.replace(/\\/g,"/").replace(/\/$/,""),o=r.toLowerCase(),a=n.toLowerCase();return o.startsWith(`${a}/`)?r.slice(n.length+1):r}function Le(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e;return T({ok:t.ok===!0,code:c(t.code),errorCode:c(t.errorCode),error:c(t.error),hint:c(t.hint),execute:typeof t.execute=="boolean"?t.execute:null,applied:typeof t.applied=="boolean"?t.applied:null})}function c(e){return typeof e=="string"?e:null}function v(e){return typeof e=="number"?e:null}function E(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function T(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t==null?!1:!(Array.isArray(t)&&t.length===0)))}function z(e,t){const r=Array.isArray(e.operations)?e.operations:Array.isArray(e.requests)?e.requests:null;if(!r)return{...e,execute:t};const{operations:n,...o}=e;return{...o,requests:r.map(a=>a&&typeof a=="object"&&!Array.isArray(a)?{...a,execute:t}:a),execute:t}}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ie=exports&&exports.__createBinding||(Object.create?(function(e,n,t,
|
|
2
|
-
`)}function be(e){const n=[`${e.operation} ${e.executionId}`,k(e)];return e.status==="running"&&
|
|
3
|
-
`)}function k(e){return e.status==="completed"?`completed, ${e.completedRows}/${e.rowCount} renames, ${e.filesWritten.length} files written`:e.status==="failed"?`failed, ${e.completedRows}/${e.rowCount} renames, ${e.failedRows} failed`:`in progress, ${e.completedRows}/${e.rowCount} renames`}function
|
|
4
|
-
`)}function
|
|
1
|
+
"use strict";var ie=exports&&exports.__createBinding||(Object.create?(function(e,n,t,r){r===void 0&&(r=t);var i=Object.getOwnPropertyDescriptor(n,t);(!i||("get"in i?!n.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return n[t]}}),Object.defineProperty(e,r,i)}):(function(e,n,t,r){r===void 0&&(r=t),e[r]=n[t]})),oe=exports&&exports.__setModuleDefault||(Object.create?(function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}):function(e,n){e.default=n}),T=exports&&exports.__importStar||(function(){var e=function(n){return e=Object.getOwnPropertyNames||function(t){var r=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[r.length]=i);return r},e(n)};return function(n){if(n&&n.__esModule)return n;var t={};if(n!=null)for(var r=e(n),i=0;i<r.length;i++)r[i]!=="default"&&ie(t,n,r[i]);return oe(t,n),t}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.runRenameEntities=de,exports.readCachedRenameExecution=ge;const N=T(require("node:fs")),d=T(require("node:path")),R=require("zod"),se=require("../client/http-client"),v=require("../config/env-vars"),ae=require("../config/product-storage"),ce=require("../shared/routes"),le=require("../shared/protocol"),E=require("../shared/agent-text"),I=require("../shared/errors"),_=require("./shared"),ue=require("../selectors/parse-entities"),fe=require("./entity-resolution"),me=require("../shared/types"),$=require("./rename-preview-cache"),x=require("./rename-execution-cache"),j=require("./mutation-execution-cache"),pe=require("./inspect-symbol-query"),V=require("./rename-input"),M=require("../metrics/central-metrics"),K=R.z.object({sourceFile:R.z.string().min(1).optional(),file:R.z.string().min(1).optional(),renames:V.RenamesInputSchema,execute:R.z.boolean().optional()}).superRefine((e,n)=>{!e.sourceFile&&!e.file&&n.addIssue({code:"custom",path:["sourceFile"],message:"rename expects sourceFile or file."})}).transform(e=>({sourceFile:e.sourceFile??e.file??"",renames:(0,V.normalizeRenamesInput)(e.renames),...e.execute!==void 0?{execute:e.execute}:{}}));async function de(e,n,t={},r=[]){if(r.includes("--help"))return ot();const i=ne(r,"--preview")??ne(r,"--preview-id");if(i){const s=W();return s>0?he(e,i,t,s):ye(e,i,t)}const o=K.parse(n);return o.execute===!0&&W()>0?U(e,o,t,"execute",W()):P(e,o,t)}async function ye(e,n,t){const r=z(e,n),i=B(r),o=await P(e,i,t,{previewId:n});return H(o,r)}async function he(e,n,t,r){const i=z(e,n),o=B(i);return U(e,o,t,"apply",r,{previewId:n,record:i})}function z(e,n){const t=(0,$.readRenamePreviewRecord)(e,n);if((0,$.hashFile)(t.sourceFile)!==t.sourceHash)throw new I.CliError("RENAME_PREVIEW_SOURCE_CHANGED","Source file changed after rename preview. Rerun rename preview.",{previewId:n,sourceFile:S(e,t.sourceFile)});return t}function B(e){return K.parse({...e.normalizedPayload,execute:!0})}function H(e,n){const t=A(e.api)&&e.api.status==="preserved-via-alias",r=e.ok===!1?"Fix the rename request and rerun preview.":t||e.api!==void 0?"If public API rename is intended, update consumers explicitly.":null,i=A(n.previewResult)?n.previewResult.api:void 0,o={...e,operation:"rename.apply",...i!==void 0?{api:i}:{},...r?{next:r}:{}};return(0,E.attachAgentText)(o,G(o))}async function U(e,n,t,r,i,o){const s=(0,x.buildRenameExecutionId)(),c=`rename.${r}`,l=Fe(n),a=(0,x.createRenameExecutionStatus)(e,s,c,J(n));(0,x.writeRenameExecutionStatus)(e,a);const p=Date.now(),h=$e(),m=we(()=>(0,ae.runWithProductStorageOverride)(h[v.CLI_ENV.productStorageDir],()=>_e(h,async()=>{try{const u=o?H(await P(e,n,t,{previewId:o.previewId}),o.record):await P(e,n,t),f=Se(u);return a.status=u.ok===!1?"failed":"completed",a.phase="completed",a.completedRows=f.filter(g=>g.ok!==!1).length,a.failedRows=f.filter(g=>g.ok===!1).length,a.filesWritten=xe(u),a.result=u,u.ok===!1&&(a.error=rt(u.code)??"RENAME_FAILED"),(0,x.writeRenameExecutionStatus)(e,a),u}catch(u){throw a.status="failed",a.phase="completed",a.error=u instanceof Error?u.message:String(u),(0,x.writeRenameExecutionStatus)(e,a),u}}))),y=await(0,j.waitForMutationDeadline)(m,i);return y.status==="result"?y.result:(m.catch(()=>{}),ve(e,s,c,l,Date.now()-p))}async function P(e,n,t,r){await Ne();const i=await(0,_.resolveCompatibleTargetInstance)(e,le.CLI_COMMAND_IDS.renameEntities,t),o=await(0,_.fetchEffectiveConfig)(i.entry,t),s=Ie(e,n.sourceFile),c=n.execute===!0,l=(0,ue.parseEntitySelectors)(n.renames.map(f=>f.entity),o),a=new Map;for(const f of n.renames)a.set(f.entity.trim(),f);await(0,fe.ensureSelectorsResolvable)(i.entry,s,l,o,(0,_.extensionRequestOptions)(t));const p=[];for(const f of l){const g=a.get(f.raw);if(!g)throw new Error(`Rename operation not found for selector: ${f.raw}`);const F=(0,M.startCentralMetricSpan)({kind:"mutation.entity",operation:c?"rename.execute":"rename.preview",cwd:d.resolve(e),sourceFile:S(e,s),entity:f.raw,newName:g.newName,totalEntities:l.length});try{const b=await(0,se.postJson)(i.entry,ce.EXTENSION_ROUTES.renameSymbol,{sourceFile:s,symbolName:f.symbolName,symbolKind:f.symbolKind,...f.parentName?{parentName:f.parentName}:{},newName:g.newName,execute:c,impactMetrics:(0,M.mutationImpactMetricsEnabled)()},(0,_.extensionRequestOptions)(t)),O=Pe(e,o,f,g.newName,b);p.push(O),F.end(Re(b,O,l.length))}catch(b){p.push(Me(o,f,g.newName,b)),F.end({ok:!1,code:b instanceof I.CliError?b.code:"RENAME_FAILED",error:b instanceof Error?b.message:String(b),totalEntities:l.length})}}const h=p.every(f=>f.ok!==!1),m=nt(s,n.renames,l,c),y=await Ze(i.entry,s,l,n.renames,p,o,e,t),u=Ee(e,s,c,l,p,h,y,i.entry.workspaceFolders);if(!c&&h){const f=(0,$.buildRenamePreviewId)(m),g=(0,$.hashFile)(s),F=(0,$.buildRenamePreviewHash)(m,g,u);(0,$.writeRenamePreviewRecord)(e,{previewId:f,previewHash:F,createdAt:new Date().toISOString(),cwd:d.resolve(e),sourceFile:s,sourceHash:g,normalizedPayload:m,previewResult:u}),u.previewId=f,u.next=`aib rename apply ${f}`}return Ce(e,u),(0,E.attachAgentText)(u,G(u))}function ge(e,n){const t=(0,x.readRenameExecutionStatus)(e,n);if((t.status==="completed"||t.status==="failed")&&t.result)return t.result;const r={operation:"execution.status",executionId:t.executionId,status:t.status,phase:t.phase,summary:k(t),progress:`${t.completedRows}/${t.rowCount}`,filesWritten:t.filesWritten,updatedAt:t.updatedAt,...t.error?{error:t.error}:{}};return(0,E.attachAgentText)(r,be(t))}function ve(e,n,t,r,i){const o=(0,x.readRenameExecutionStatus)(e,n),s=Math.max(0,r-i),c={operation:"execution.status",executionId:o.executionId,status:o.status,phase:o.phase,summary:k(o),progress:`${o.completedRows}/${o.rowCount}`,filesWritten:o.filesWritten,updatedAt:o.updatedAt,estimatedRemainingMs:s};return(0,E.attachAgentText)(c,Ae(t,o,s))}function Ae(e,n,t){return[`${e} ${n.executionId}`,k(n),"applying mutation",t>0?`estimated remaining: ${it(Math.max(t,5e3))}`:"estimated remaining: check status again soon"].join(`
|
|
2
|
+
`)}function be(e){const n=[`${e.operation} ${e.executionId}`,k(e)];return e.status==="running"&&n.push("applying mutation"),e.error&&n.push(e.error),n.join(`
|
|
3
|
+
`)}function k(e){return e.status==="completed"?`completed, ${e.completedRows}/${e.rowCount} renames, ${e.filesWritten.length} files written`:e.status==="failed"?`failed, ${e.completedRows}/${e.rowCount} renames, ${e.failedRows} failed`:`in progress, ${e.completedRows}/${e.rowCount} renames`}function we(e){return new Promise((n,t)=>{setImmediate(()=>{e().then(n,t)})})}function W(){return(0,j.readMutationSyncWaitMs)(process.env[v.CLI_ENV.renameSyncWaitMs],12e4)}function Fe(e){return 12e3+J(e)*2e3}function J(e){return Math.max(1,e.renames.length)}function xe(e){return(Array.isArray(e.filesWritten)?e.filesWritten:Array.isArray(e.files)?e.files:[]).filter(t=>typeof t=="string"&&!t.startsWith("+"))}function Se(e){const n=Array.isArray(e.renames)?e.renames.map(r=>({ok:typeof r=="string"&&!r.includes("failed")})):e.rename?[{ok:e.ok!==!1}]:[];if(n.length>0)return n;const t=Array.isArray(e.failed)?e.failed.filter(A):[];return t.length>0?t.map(r=>({...r,ok:!1})):[{ok:e.ok!==!1}]}async function Ne(){const e=process.env[v.CLI_ENV.testRenameDelayMs];if(!e)return;const n=Number.parseInt(e,10);!Number.isFinite(n)||n<=0||await new Promise(t=>setTimeout(t,Math.min(n,12e4)))}function $e(){const e=[v.CLI_ENV.productStorageDir,v.CLI_ENV.trace,v.CLI_ENV.traceDir,v.CLI_ENV.metrics,v.CLI_ENV.metricsDir,v.CLI_ENV.metricsTag,v.CLI_ENV.mutationImpactMetrics,v.CLI_ENV.mutationImpactStream,v.CLI_ENV.testRenameDelayMs],n={};for(const t of e)n[t]=process.env[t];return n}async function _e(e,n){const t={};for(const[r,i]of Object.entries(e))t[r]=process.env[r],i===void 0?delete process.env[r]:process.env[r]=i;try{return await n()}finally{for(const[r,i]of Object.entries(t))i===void 0?delete process.env[r]:process.env[r]=i}}function Ce(e,n){(0,M.recordCentralMetric)({kind:"mutation.summary",operation:typeof n.operation=="string"?n.operation:"rename",cwd:d.resolve(e),ok:n.ok!==!1,sourceFile:typeof n.file=="string"?n.file:null,summary:typeof n.summary=="string"?n.summary:null,filesWrittenCount:Array.isArray(n.filesWritten)?n.filesWritten.filter(t=>typeof t=="string"&&!t.startsWith("+")).length:0})}function Re(e,n,t){const r=A(e.renameImpact)?e.renameImpact:{};return{ok:e.ok!==!1,totalEntities:t,editCount:typeof n.editCount=="number"?n.editCount:0,changedFileCount:Array.isArray(n.allFiles)?n.allFiles.length:0,savedFileCount:Array.isArray(n.allSavedFiles)?n.allSavedFiles.length:0,...(0,M.mutationImpactMetricsEnabled)()?{impactCollectionMs:typeof r.impactCollectionMs=="number"?r.impactCollectionMs:null,impact:{locationCount:typeof r.locationCount=="number"?r.locationCount:null,fileCount:typeof r.fileCount=="number"?r.fileCount:null,impactCollectionMs:typeof r.impactCollectionMs=="number"?r.impactCollectionMs:null},changedFiles:Array.isArray(n.allFiles)?n.allFiles:[],savedFiles:Array.isArray(n.allSavedFiles)?n.allSavedFiles:[]}:{},configFilePath:typeof e.configFilePath=="string"?e.configFilePath:null}}function Ee(e,n,t,r,i,o,s,c){const l=i.reduce((u,f)=>u+te(f.editCount),0),a=Qe(i),p=De(i),h=i.map((u,f)=>({oldName:r[f]?.symbolName??(typeof u.oldName=="string"?u.oldName:u.entity),newName:u.newName})),m=Oe(e,c,i,h,a,n)??Te(e,c,a,h);return{...o?{}:{ok:!1},operation:t?"rename.execute":"rename.preview",file:S(e,n),...r.length===1?{rename:q(i[0],!1)}:{renames:i.map(u=>q(u,!0))},summary:t?`${p.length} ${p.length===1?"file":"files"} written, ${l} edits`:r.length===1?`${a.length} ${a.length===1?"file":"files"}, ${l} edits`:`${r.length} symbols, ${a.length} ${a.length===1?"file":"files"}, ${l} edits`,...t?{}:{files:D(a,5)},...t?{filesWritten:D(p,5)}:{},...o?{}:{failed:i.filter(u=>u.ok===!1).map(u=>ke(u))},...m?{api:We(m)}:{},...o?{}:{next:"Fix failed rename rows and rerun preview."}}}function Ie(e,n){const t=n.trim();return d.normalize(d.isAbsolute(t)?t:d.resolve(e,t))}function Me(e,n,t,r){const i=r instanceof I.CliError&&A(r.details)?r.details:{},o=A(i.details)?i.details:{},s=Z(e,o.candidates),c=A(o.sourceConsistency)?Q(o.sourceConsistency):null;return{entity:n.raw,oldName:n.symbolName,acceptedSelector:C(n,e),newName:t,ok:!1,code:r instanceof I.CliError?r.code:"RENAME_FAILED",error:r instanceof Error?r.message:String(r),...c?{source:c}:{},...s.length>0?{candidates:s}:{},next:s.length>0?"Retry with one of the candidate selectors.":"Run inspect file for this source file, then retry with a canonical selector."}}function Pe(e,n,t,r,i){const o=A(i.locationPreview)?i.locationPreview:{},s=Array.isArray(o.locations)?o.locations.filter(A):[],c=tt(e,s),l=Be(s,t.symbolName,r),a=l.length>0?[]:He(e,c,t.symbolName,r,typeof i.sourceFile=="string"?i.sourceFile:null),p=A(i.sourceConsistency)?Q(i.sourceConsistency):null;return i.ok!==!1?{entity:t.raw,oldName:t.symbolName,...typeof i.sourceFile=="string"?{sourceFilePath:i.sourceFile}:{},acceptedSelector:C(t,n),newName:r,ok:!0,editCount:s.length,...typeof i.configFilePath=="string"?{projectConfig:S(e,i.configFilePath)}:{},allFiles:c.map(({file:m,count:y})=>`${m} x${y}`),files:D(c.map(({file:m,count:y})=>`${m} x${y}`),5),...l.length+a.length>0?{apiAliases:[...l,...a]}:{},...p?{source:p}:{},...i.applied!==void 0?{applied:i.applied===!0}:{},...Array.isArray(i.savedFiles)?{allSavedFiles:i.savedFiles.filter(m=>typeof m=="string").map(m=>S(e,m)),savedFiles:D(i.savedFiles.filter(m=>typeof m=="string").map(m=>S(e,m)),5)}:{}}:{entity:t.raw,acceptedSelector:C(t,n),newName:r,ok:!1,code:typeof i.code=="string"?i.code:"RENAME_FAILED",error:typeof i.error=="string"?i.error:"Rename failed.",...p?{source:p}:{},candidates:Z(n,i.candidates),next:"Use one of the candidates or rerun inspect file if the file changed."}}function q(e,n){const t=typeof e.acceptedSelector=="string"?e.acceptedSelector:e.entity,r=e.ok===!1?"failed":`${te(e.editCount)} edits`,i=n?`, ${r}`:"";return`${t} -> ${e.newName}${i}`}function ke(e){const n={rename:q(e,!1),code:typeof e.code=="string"?e.code:"RENAME_FAILED",error:typeof e.error=="string"?e.error:"Rename failed."};for(const t of["source","candidates","next"])e[t]!==void 0&&(n[t]=e[t]);return n}function De(e){const n=new Set;for(const t of e){const r=Array.isArray(t.allSavedFiles)?t.allSavedFiles:t.savedFiles;if(Array.isArray(r))for(const i of r)typeof i=="string"&&!i.startsWith("+")&&n.add(i)}return Array.from(n)}function We(e){const n=typeof e.aliases=="string"?e.aliases:"aliases",t=typeof e.consumers=="string"?e.consumers:"",r=/^(\d+)\s+/.exec(t),i=r?Number(r[1]):0,o=n.startsWith("1 ")?"name":"names";return i>0?`old ${o} preserved by ${n}; ${t} still use old names`:`old ${o} preserved by ${n}`}function G(e){if(e.ok===!1)return null;const n=typeof e.operation=="string"?e.operation:"";if(n!=="rename.preview"&&n!=="rename.execute"&&n!=="rename.apply")return null;const t=[],r=typeof e.previewId=="string"?e.previewId:"";if(t.push(r&&n==="rename.preview"?`${n} ${r}`:n),typeof e.file=="string"&&t.push(e.file),typeof e.rename=="string")t.push(e.rename);else if(Array.isArray(e.renames))for(const i of e.renames)typeof i=="string"&&t.push(qe(i));return typeof e.summary=="string"&&t.push(e.summary),Le(t,Array.isArray(e.filesWritten)?e.filesWritten:e.files),typeof e.api=="string"&&t.push(`api: ${e.api}`),typeof e.next=="string"&&t.push(`next: ${e.next}`),t.join(`
|
|
4
|
+
`)}function qe(e){return e.replace(/,\s+\d+\s+edits$/,"")}function Le(e,n){if(Array.isArray(n))for(const t of n)typeof t=="string"&&e.push(t)}function Oe(e,n,t,r,i,o){const s=Ke(t),c=ze(e,t,r),l=Ve(e,i,o,r),a=L([...s,...c,...l]);if(a.length===0)return null;const p=Je(e,t),h=ee(e,n),m=X(h,a.map(y=>y.oldName),p);return{status:"preserved-via-alias",aliases:`${a.length} ${a.length===1?"alias":"aliases"}`,consumers:`${m.length} ${m.length===1?"file":"files"} not rewritten`,hint:"Public API names were preserved through re-export aliases. Consumers still use old names."}}function Te(e,n,t,r){if(!t.some(l=>/(^|[/\\])index\.(ts|tsx|mts|cts) x\d+$/i.test(l))||r.length===0)return null;const o=je(e,t),s=ee(e,n),c=X(s,r.map(l=>l.oldName),o);return{status:"preserved-via-alias",aliases:`${r.length} ${r.length===1?"alias":"aliases"}`,consumers:`${c.length} ${c.length===1?"file":"files"} not rewritten`,hint:"Public API names were preserved through re-export aliases. Consumers still use old names."}}function je(e,n){const t=new Set;for(const r of n){if(typeof r!="string"||r.startsWith("+"))continue;const i=/^(.*) x(\d+)$/.exec(r);i&&t.add(w(d.resolve(e,i[1])))}return t}function Ve(e,n,t,r){const i=w(t),o=[];for(const s of n){if(typeof s!="string"||s.startsWith("+"))continue;const c=/^(.*) x(\d+)$/.exec(s);if(!c)continue;const l=d.resolve(e,c[1]);if(w(l)===i)continue;if(/^index\.(ts|tsx|mts|cts)$/i.test(d.basename(l))){o.push(...r);continue}let a="";try{a=N.readFileSync(l,"utf8")}catch{continue}if(!(!a.includes("export")||!a.includes("from")))for(const p of r)a.includes(p.oldName)&&o.push(p)}return L(o)}function Ke(e){const n=[];for(const t of e)if(Array.isArray(t.apiAliases))for(const r of t.apiAliases)A(r)&&typeof r.oldName=="string"&&typeof r.newName=="string"&&n.push({oldName:r.oldName,newName:r.newName});return L(n)}function L(e){const n=new Set;return e.filter(t=>{const r=`${t.newName} as ${t.oldName}`;return n.has(r)?!1:(n.add(r),!0)})}function ze(e,n,t){const r=[];for(const o of n){const s=typeof o.sourceFilePath=="string"?w(o.sourceFilePath):null,c=Array.isArray(o.allFiles)?o.allFiles:[];for(const l of c){if(typeof l!="string"||l.startsWith("+"))continue;const a=/^(.*) x(\d+)$/.exec(l);if(!a)continue;const p=d.resolve(e,a[1]);if(s&&w(p)===s)continue;let h="";try{h=N.readFileSync(p,"utf8")}catch{continue}if(!(!h.includes("export")||!h.includes("from")))for(const m of t)h.includes(m.oldName)&&r.push(m)}}const i=new Set;return r.filter(o=>{const s=`${o.newName} as ${o.oldName}`;return i.has(s)?!1:(i.add(s),!0)})}function Be(e,n,t){const r=new RegExp(`\\b${Y(t)}\\s+as\\s+${Y(n)}\\b`);return e.filter(o=>typeof o.replacementPreview=="string"&&(r.test(o.replacementPreview)||Ue(o,n,t))).map(o=>({oldName:n,newName:t,...typeof o.fileName=="string"?{fileName:o.fileName}:{}})).slice(0,20)}function He(e,n,t,r,i){const o=i?w(i):null,s=[];for(const{file:c}of n){const l=d.resolve(e,c);if(o&&w(l)===o)continue;let a="";try{a=N.readFileSync(l,"utf8")}catch{continue}!a.includes(t)||!a.includes("export")||!a.includes("from")||s.push({oldName:t,newName:r,fileName:l})}return s.slice(0,20)}function Ue(e,n,t){if(typeof e.fileName!="string"||typeof e.replacementPreview!="string"||!e.replacementPreview.includes(t))return!1;let r="";try{r=N.readFileSync(e.fileName,"utf8")}catch{return!1}return r.includes(n)&&r.includes("export")&&r.includes("from")}function Je(e,n){const t=new Set;for(const r of n){const i=Array.isArray(r.allFiles)?r.allFiles:[];for(const o of i){if(typeof o!="string"||o.startsWith("+"))continue;const s=/^(.*) x(\d+)$/.exec(o);s&&t.add(w(d.resolve(e,s[1])))}}return t}function X(e,n,t){const r=Array.from(new Set(n.filter(s=>s.length>0)));if(r.length===0)return[];const i=[],o=new Set;for(const s of e)for(const c of Ge(s,5e3)){const l=w(c);if(t.has(l)||o.has(l))continue;o.add(l);let a="";try{a=N.readFileSync(c,"utf8")}catch{continue}r.some(p=>a.includes(p))&&i.push(c)}return i}function Ge(e,n){const t=[],r=[d.resolve(e)];for(;r.length>0&&t.length<n;){const i=r.pop();if(!i)continue;let o=[];try{o=N.readdirSync(i,{withFileTypes:!0})}catch{continue}for(const s of o){if(t.length>=n)break;if(s.isDirectory()){if(Xe(s.name))continue;r.push(d.join(i,s.name));continue}s.isFile()&&Ye(s.name)&&t.push(d.join(i,s.name))}}return t}function Xe(e){return[".git",".aib-plan-cache",".aib-preview",".aib-trace",".tmp","dist","node_modules","out"].includes(e)}function Ye(e){return/\.(ts|tsx|mts|cts)$/i.test(e)&&!/\.d\.(ts|mts|cts)$/i.test(e)}function w(e){return d.normalize(e).toLowerCase()}function Y(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Qe(e){const n=new Map;for(const t of e){const r=Array.isArray(t.allFiles)?t.allFiles:t.files;if(Array.isArray(r))for(const i of r){if(typeof i!="string"||i.startsWith("+"))continue;const o=/^(.*) x(\d+)$/.exec(i);if(!o)continue;const s=o[1],c=Number(o[2]);n.set(s,(n.get(s)??0)+c)}}return Array.from(n.entries()).sort((t,r)=>t[0].localeCompare(r[0])).map(([t,r])=>`${t} x${r}`)}function st(e,n){return Array.from(new Set(n.map(t=>t.projectConfig).filter(t=>typeof t=="string"&&t.length>0))).sort((t,r)=>t.localeCompare(r))}async function Ze(e,n,t,r,i,o,s,c){const l=new Set(t.map(y=>y.symbolName)),a=new Set(r.map(y=>y.newName.trim())),p=Array.from(l).filter(y=>y.length>0);if(p.length===0)return[];const h=et(n,i,s).slice(0,40),m=[];for(const y of h){let u;try{u=await(0,pe.queryTopLevelInspectSymbols)(e,y,(0,_.extensionRequestOptions)(c))}catch{continue}for(const f of u){if(typeof f.name!="string")continue;const g=f.name;if(!p.some(b=>g.includes(b))||l.has(g)||a.has(g))continue;const F=typeof f.kind=="string"?f.kind.toLowerCase():"";m.push(C({raw:g,symbolName:g,symbolKind:re(F)?F:null},o))}}return Array.from(new Set(m)).sort((y,u)=>y.localeCompare(u))}function et(e,n,t){const r=new Set([e]);for(const i of n){const o=Array.isArray(i.allFiles)?i.allFiles:[];for(const s of o){if(typeof s!="string"||s.startsWith("+"))continue;const c=/^(.*) x(\d+)$/.exec(s);c&&r.add(d.resolve(t,c[1]))}}return Array.from(r)}function tt(e,n){const t=new Map;for(const r of n){if(typeof r.fileName!="string")continue;const i=S(e,r.fileName);t.set(i,(t.get(i)??0)+1)}return Array.from(t.entries()).sort((r,i)=>r[0].localeCompare(i[0])).map(([r,i])=>({file:r,count:i}))}function Q(e){return e.documentMatchesDisk===!0&&e.documentIsDirty!==!0?null:{documentMatchesDisk:e.documentMatchesDisk===!0,documentIsDirty:e.documentIsDirty===!0}}function nt(e,n,t,r){return{sourceFile:e,renames:n.map((i,o)=>({entity:t[o]?.raw??i.entity.trim(),symbolName:t[o]?.symbolName??i.entity.trim(),...t[o]?.symbolKind?{symbolKind:t[o]?.symbolKind}:{},...t[o]?.parentName?{parentName:t[o]?.parentName}:{},newName:i.newName})),execute:r}}function Z(e,n){return Array.isArray(n)?n.filter(A).slice(0,8).map(t=>{const r=typeof t.name=="string"?t.name:"",i=typeof t.kind=="string"?t.kind.toLowerCase():"",o=Array.isArray(t.path)?t.path.filter(c=>typeof c=="string"):[],s=o.length>1?o[o.length-2]:void 0;return{name:r,kind:i,selector:C({raw:s?`${s}.${r}`:r,symbolName:r,symbolKind:re(i)?i:null,...s?{parentName:s}:{}},e)}}):[]}function C(e,n){const t=e.parentName?`${e.parentName}.${e.symbolName}`:e.symbolName;return e.symbolKind?`${n.entityKindAliases[e.symbolKind]}${n.selectorSeparator}${t}`:e.raw}function ee(e,n){const t=w(d.resolve(e)),r=[];for(const i of n.map(o=>d.resolve(o))){const o=w(i);if(t===o||o.startsWith(`${t}/`)){r.push(i);continue}t.startsWith(`${o}/`)&&r.push(d.resolve(e))}return r.length===0?[d.resolve(e)]:Array.from(new Set(r))}function D(e,n){const t=e.slice(0,n),r=e.length-t.length;return r>0?[...t,`+ ${r} more`]:t}function te(e){return typeof e=="number"?e:0}function rt(e){return typeof e=="string"?e:null}function it(e){const n=Math.max(1,Math.ceil(e/1e3));return n<60?`~${n} sec`:`~${Math.ceil(n/60)} min`}function S(e,n){return d.relative(e,n).replace(/\\/g,"/")}function ne(e,n){const t=e.indexOf(n);if(t<0)return null;const r=e[t+1];return r&&!r.startsWith("--")?r:null}function ot(){return{ok:!0,command:"rename",usage:"aib rename preview <sourceFile> <entity> <newName> | aib rename preview --stdin | aib rename execute --stdin | aib rename apply <previewId>",preview:{sourceFile:"src/path/to/source-file.ts",renames:[{entity:"OldSymbolName",newName:"NewSymbolName"}],execute:!1},apply:"aib rename apply rename_abc123",notes:["Use execute:false first when selector resolution is uncertain.","Preview returns previewId, file/edit summary, and candidate selectors on failure.","Apply by previewId refuses to run if the source file changed after preview."]}}function A(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function re(e){return me.ENTITY_KIND_IDS.includes(e)}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.runResultViewCommand=S;const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.runResultViewCommand=S;const h=require("../shared/agent-text"),p=require("../shared/errors"),D=require("./declaration-format"),b=require("./inspect-cycles"),x=require("./session-workspace");function S(t,e,n){if(n!==void 0)return N(t,n);const r=e.find(u=>!u.startsWith("--"));if(!r)throw new p.CliError("VIEW_HANDLE_REQUIRED","Usage: aib view aib:res_<id>");const i=R(r),s=U(e.slice(1));if(i.short)return M(t,(0,x.readSessionResultViewJson)(t,i.id),s,r);if(i.kind==="cycles")return(0,b.buildCyclesViewResponse)((0,x.readSessionResultJson)(t,i.kind,i.id),{...s.detail!==void 0?{detail:A(s.detail)}:{},...s.offset!==void 0?{offset:s.offset}:{},...s.limit!==void 0?{limit:s.limit}:{},...s.index!==void 0?{index:s.index}:{},...s.kind!==void 0?{kind:E(s.kind)}:{},resultHandle:r});const d={ok:!1,code:"UNSUPPORTED_RESULT_VIEW",error:`aib view does not support result kind: ${i.kind}`};return(0,h.attachAgentText)(d,`unsupported result view: ${i.kind}`)}function N(t,e){const n=Array.isArray(e.views),r=Array.isArray(e.views)?e.views:[],i=n?r.filter(m):m(e.view)?[e.view]:m(e)?[e]:[];if(i.length===0)throw new p.CliError("VIEW_HANDLE_REQUIRED","view expects a handle.");const s=i.map((u,f)=>{try{return T(t,u)}catch(c){if(!n||i.length===1)throw c;return{...(0,p.errorPayload)(c),index:f}}});if(s.length===1)return s[0];const d=s.filter(u=>m(u)&&u.ok===!1).length;return(0,h.attachAgentText)({ok:d===0,...d>0?{batchOk:!1,failedCount:d}:{},results:s},s.map(u=>{if(!m(u))return"";const f=(0,h.readAgentText)(u);return typeof f=="string"?f.trimEnd():""}).filter(u=>u!=="").join(`
|
|
2
2
|
|
|
3
|
-
`))}function
|
|
4
|
-
`);let
|
|
5
|
-
`)}function
|
|
6
|
-
`)}function
|
|
3
|
+
`))}function T(t,e){const n=o(e.handle)??o(e.from)??"";if(!n)throw new p.CliError("VIEW_HANDLE_REQUIRED","view expects a handle.");const r=R(n),i={...o(e.detail)!==void 0?{detail:o(e.detail)}:{},...y(e.offset)!==void 0?{offset:y(e.offset)}:{},...y(e.limit)!==void 0?{limit:y(e.limit)}:{},...y(e.index)!==void 0?{index:y(e.index)}:{},...o(e.kind)!==void 0?{kind:o(e.kind)}:{},...k(e.only).length>0?{only:k(e.only)}:{},...k(e.except).length>0?{except:k(e.except)}:{}};return r.short?M(t,(0,x.readSessionResultViewJson)(t,r.id),i,n):r.kind==="cycles"?(0,b.buildCyclesViewResponse)((0,x.readSessionResultJson)(t,r.kind,r.id),{...i.detail!==void 0?{detail:A(i.detail)}:{},...i.offset!==void 0?{offset:i.offset}:{},...i.limit!==void 0?{limit:i.limit}:{},...i.index!==void 0?{index:i.index}:{},...i.kind!==void 0?{kind:E(i.kind)}:{},resultHandle:n}):(0,h.attachAgentText)({ok:!1,code:"UNSUPPORTED_RESULT_VIEW",error:`aib view does not support result kind: ${r.kind}`},`unsupported result view: ${r.kind}`)}function R(t){if(/^aib:res_[A-Za-z0-9_-]+$/.test(t))return{kind:"view",id:t.slice(4),short:!0};const e=t.split(":");if(e.length!==4||e[0]!=="aib"||e[1]!=="result"||!e[2]||!e[3])throw new p.CliError("INVALID_RESULT_HANDLE",`Invalid result handle: ${t}`,{expected:"aib:res_<id>"});return{kind:e[2],id:e[3],short:!1}}function U(t){const e={},n=_(t,"--detail"),r=I(t,"--offset"),i=I(t,"--limit"),s=I(t,"--index"),d=_(t,"--kind"),u=$(t,"--only").flatMap(w),f=$(t,"--except").flatMap(w);return n!==void 0&&(e.detail=n),r!==void 0&&(e.offset=r),i!==void 0&&(e.limit=i),s!==void 0&&(e.index=s),d!==void 0&&(e.kind=d),u.length>0&&(e.only=u),f.length>0&&(e.except=f),e}function M(t,e,n,r){const i=o(e.kind);return e.op==="cycles"?(0,b.buildCyclesViewResponse)(e,{...n.detail!==void 0?{detail:A(n.detail)}:{},...n.offset!==void 0?{offset:n.offset}:{},...n.limit!==void 0?{limit:n.limit}:{},...n.index!==void 0?{index:n.index}:{},...n.kind!==void 0?{kind:E(n.kind)}:{},resultHandle:r}):i==="code"?O(e,n,r):i==="members"||i==="duplicates"||i==="usages"?W(e,n,r,i):i==="declarationMutation"?F(t,e,r):(0,h.attachAgentText)({ok:!1,code:"UNSUPPORTED_RESULT_VIEW",error:`aib view does not support result kind: ${i??"unknown"}`},`unsupported result view: ${i??"unknown"}`)}function W(t,e,n,r){const i=Array.isArray(t.items)?t.items.filter(m):[],s=L(i,e,g=>[o(g.name),o(g.text)?.split(/\s+/)[0]]),d=Math.max(0,e.offset??0),u=s.length||1,f=Math.max(1,e.limit??u),c=s.slice(d,d+f),l=Math.max(0,s.length-d-c.length),a={ok:!0,op:"view",handle:n,kind:r,source:o(t.source)??"inspect",...o(t.file)!==void 0?{file:o(t.file)}:{},...o(t.entity)!==void 0?{entity:o(t.entity)}:{},...o(t.target)!==void 0?{target:o(t.target)}:{},...o(t.detail)!==void 0?{detail:o(t.detail)}:{},items:c,offset:d,limit:f,...l>0?{hidden:l}:{}};return(0,h.attachAgentText)(a,P(a))}function O(t,e,n){const r=Array.isArray(t.items)?t.items.filter(m):[],i=L(r,e,a=>[o(a.entity),o(a.name)]),s=Math.max(0,e.offset??0),d=i.length||1,u=Math.max(1,e.limit??d),f=i.slice(s,s+u),c=Math.max(0,i.length-s-f.length),l={ok:!0,op:"view",handle:n,kind:"code",source:o(t.source)??"inspect",items:f,offset:s,limit:u,...c>0?{hidden:c}:{},...f.length===0&&r.length>0&&J(e)?{noMatches:!0}:{}};return(0,h.attachAgentText)(l,j(l))}function j(t){const e=[],n=Array.isArray(t.items)?t.items.filter(m):[];if(n.length===0&&t.noMatches===!0)return e.push("no hidden code matched view filters"),e.join(`
|
|
4
|
+
`);let r="";for(const s of n){const d=o(s.file)??"";d&&d!==r&&(e.length>0&&e.push(""),e.push(`// ${d}`),r=d);const u=o(s.entity)??"",f=o(s.meta)??o(s.rangeMeta)??"",c=[u,f].filter(a=>a!=="").join(" ");c&&e.push(`// ${c}`);const l=o(s.code);l&&e.push(l.trimEnd())}const i=y(t.hidden)??0;return i>0&&e.push(`+ ${i} more hidden code blocks`),e.join(`
|
|
5
|
+
`)}function P(t){const e=[],n=o(t.file),r=o(t.target),i=o(t.kind)??"",s=o(t.detail);n?e.push(`// ${n}`):i==="usages"?e.push(s?`usages ${s}`:"usages"):r&&e.push(`duplicates ${r}`);const d=o(t.entity);d&&e.push(`// ${d}:`);const u=Array.isArray(t.items)?t.items.filter(m):[];if(i==="usages")for(const[c,l]of H(u,a=>o(a.name)??"")){c&&e.push(`${c}:`);for(const a of l){const g=o(a.text);g&&e.push(g.trimEnd())}}else for(const c of u){const l=o(c.text);l&&e.push(l.trimEnd())}const f=y(t.hidden)??0;return f>0&&e.push(`+ ${f} more hidden ${i==="members"?"members":i==="usages"?"usages":"items"}`),e.join(`
|
|
6
|
+
`)}function H(t,e){const n=new Map;for(const r of t){const i=e(r),s=n.get(i)??[];s.push(r),n.set(i,s)}return Array.from(n.entries())}function A(t){if(t==="summary"||t==="sum")return"summary";if(t==="imports"||t==="files")return t;throw new p.CliError("INVALID_CYCLES_DETAIL","aib view cycles --detail expects summary, imports, or files.")}function E(t){if(t==="runtime"||t==="type-only"||t==="mixed")return t;throw new p.CliError("INVALID_CYCLES_KIND","aib view cycles --kind expects runtime, type-only, or mixed.")}function _(t,e){const n=t.indexOf(e),r=n>=0?t[n+1]:void 0;return r&&!r.startsWith("--")?r:void 0}function F(t,e,n){const r=Array.isArray(e.rows)?e.rows.filter(m):[],i=o(e.operation)==="addMissing"?"addMissing":"remove",s={ok:!0,op:"view",handle:n,kind:"declarationMutation",operation:i,rows:r};return(0,h.attachAgentText)(s,q(t,s))}function q(t,e){const n=[`${o(e.operation)??"declaration"} ${o(e.handle)??""}`.trim()],r=Array.isArray(e.rows)?e.rows.filter(m):[];return n.push(...(0,D.formatDeclarationMutationDetails)(t,o(e.operation)==="addMissing"?"addMissing":"remove",r)),n.join(`
|
|
7
|
+
`)}function $(t,e){const n=[];for(let r=0;r<t.length;r+=1){if(t[r]!==e)continue;const i=t[r+1];i&&!i.startsWith("--")&&n.push(i)}return n}function I(t,e){const n=_(t,e);if(n===void 0)return;const r=Number(n),i=e==="--offset"?0:1;if(!Number.isInteger(r)||r<i)throw new p.CliError("INVALID_VIEW_OPTION",`${e} expects ${i===0?"a non-negative":"a positive"} integer.`);return r}function m(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function o(t){return typeof t=="string"&&t!==""?t:void 0}function y(t){return typeof t=="number"&&Number.isFinite(t)?t:void 0}function Y(t,e){const n=t[e];return typeof n=="number"&&Number.isFinite(n)?n:0}function k(t){return typeof t=="string"&&t!==""?w(t):Array.isArray(t)?t.filter(e=>typeof e=="string"&&e!=="").flatMap(w):[]}function L(t,e,n){const r=e.only??[],i=e.except??[],s=r.length>0?t.filter(d=>C(n(d),r)):t;return i.length===0?s:s.filter(d=>!C(n(d),i))}function J(t){return(t.only?.length??0)>0||(t.except?.length??0)>0}function C(t,e){return t.some(n=>n!==void 0&&e.some(r=>B(n,r)))}function B(t,e){if(t===e)return!0;const n=t.split(".").pop()??t,r=e.split(".").pop()??e;return n===r&&!e.includes(".")}function w(t){const e=t.trim();return(K(e)??V(e)).flatMap(Q)}function Q(t){const e=t.trim(),n=e.match(/^(.+)\.\{(.+)\}$/);if(n){const r=n[1],i=n[2];if(r&&i)return V(i).map(s=>`${r}.${s}`)}return e?[e]:[]}function K(t){if(!t.startsWith("[")||!t.endsWith("]"))return null;const e=t.slice(1,-1).trim();return e?V(e):[]}function V(t){const e=[];let n="",r=0;for(const i of t){if(i==="{"?r+=1:i==="}"&&r>0&&(r-=1),i===","&&r===0){n.trim()&&e.push(n.trim()),n="";continue}n+=i}return n.trim()&&e.push(n.trim()),e}
|
|
@@ -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(`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var d=exports&&exports.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.runWorkerCommand=_;const c=d(require("node:fs")),i=d(require("node:path")),p=require("node:child_process"),y=require("../shared/errors"),k=require("../workers/registry"),g=require("../workers/product-storage");function _(r,e){if((e[0]??"")==="status")return h();const o=w(e),n=S(),t=(0,k.resolveWorkerRoute)({route:o.route,cliVersion:n,...o.registryPath?{registryPath:o.registryPath}:{}}),s=(0,p.spawnSync)(process.execPath,[t.script,...o.workerArgs],{cwd:r,encoding:"utf8",env:{...process.env,AIB_WORKER_ROUTE:t.route.route,AIB_WORKER_ID:t.route.workerId,AIB_WORKER_VERSION:t.route.version,AIB_WORKER_CWD:r}}),u=v(s.stdout),a=s.status===0&&u.ok!==!1;return{ok:a,command:"worker",route:t.route.route,worker:{workerId:t.route.workerId,version:t.route.version,script:t.script,registryPath:t.registryPath,status:s.status??null},payload:u,...a?{}:{error:m(u)??(s.stderr.trim()||"worker failed"),stderr:s.stderr.trim()}}}function h(){const r=(0,g.productStorageRoot)(),e=i.default.join(r,"workers","worker-routes.json"),o=i.default.join(r,"workers","activation-status.json"),n=l(e),t=l(o),s=j(i.default.join(r,"workers","bundles"));return{ok:!0,command:"worker",action:"status",registryPath:e,statusPath:o,registryVersion:f(n?.registryVersion)??f(t?.active?.registryVersion)??null,routeCount:Array.isArray(n?.routes)?n.routes.length:0,active:t?.active??null,previous:t?.previous??null,lastError:t?.lastError??null,workerBundles:s}}function w(r){let e,o;const n=[];let t=!1;for(let s=0;s<r.length;s+=1){const u=r[s],a=r[s+1];if(u!==void 0){if(!t&&u==="--registry"&&a){e=i.default.resolve(a),s+=1;continue}if(!t&&u==="--"){t=!0;continue}if(!o&&!t){o=u;continue}n.push(u)}}if(!o)throw new y.CliError("WORKER_USAGE","Usage: aib worker [--registry <path>] <route> -- <worker args>");return{route:o,...e?{registryPath:e}:{},workerArgs:n}}function v(r){try{const e=JSON.parse(r);return e&&typeof e=="object"&&!Array.isArray(e)?e:{ok:!1,error:"worker produced non-object json stdout"}}catch{return{ok:!1,error:r.trim()?`worker produced non-json stdout: ${r.trim()}`:"worker produced no stdout"}}}function m(r){return typeof r.error=="string"?r.error:null}function S(){const r=i.default.resolve(__dirname,"..","..","package.json");try{const e=JSON.parse(c.default.readFileSync(r,"utf8"));return typeof e.version=="string"?e.version:"0.0.0"}catch{return"0.0.0"}}function l(r){try{const e=JSON.parse(c.default.readFileSync(r,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:null}catch{return null}}function f(r){return typeof r=="string"&&r.trim()?r:null}function j(r){if(!c.default.existsSync(r))return[];const e=[];for(const o of c.default.readdirSync(r,{withFileTypes:!0})){if(!o.isDirectory())continue;const n=i.default.join(r,o.name,"activation-status.json"),t=l(n);t&&e.push({workerId:o.name,statusPath:n,active:t.active??null,previous:t.previous??null,lastError:t.lastError??null})}return e.sort((o,n)=>String(o.workerId).localeCompare(String(n.workerId)))}
|
package/dist/config/defaults.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_EFFECTIVE_CONFIG=void 0,exports.DEFAULT_EFFECTIVE_CONFIG={methodAliases:{ping:"ping",runtimeInfo:"runtimeInfo",printConfig:"printConfig",listInstances:"listInstances",initSkillUsage:"init-skill-usage",help:"help",inspect:"inspect",imports:"imports",move:"move",rename:"rename",refactor:"refactor",execution:"execution",modulePlan:"modulePlan"},entityKindAliases:{class:"c",interface:"i",type:"t",function:"f",variable:"v",enum:"e",method:"m",property:"p"},selectorSeparator:"-"};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_EFFECTIVE_CONFIG=void 0,exports.DEFAULT_EFFECTIVE_CONFIG={methodAliases:{ping:"ping",runtimeInfo:"runtimeInfo",printConfig:"printConfig",listInstances:"listInstances",initSkillUsage:"init-skill-usage",help:"help",inspect:"inspect",imports:"imports",move:"move",rename:"rename",refactor:"refactor",execution:"execution",modulePlan:"modulePlan"},entityKindAliases:{class:"c",interface:"i",type:"t",function:"f",variable:"v",enum:"e",namespace:"ns",method:"m",property:"p"},selectorSeparator:"-"};
|
package/dist/config/env-vars.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CLI_ENV=void 0,exports.CLI_ENV={autoStartIde:"AIB_AUTO_START_IDE",installConfig:"AIB_INSTALL_CONFIG",managedHostScript:"AIB_MANAGED_HOST_SCRIPT",managedHostKind:"AIB_MANAGED_HOST_KIND",managedHostRunDir:"AIB_MANAGED_HOST_RUN_DIR",codeServerPath:"AIB_CODE_SERVER_PATH",nodePath:"AIB_NODE_PATH",extensionVsix:"AIB_EXTENSION_VSIX",ideCommand:"AIB_IDE_COMMAND",chromePath:"AIB_CHROME_PATH",runtimeArchive:"AIB_RUNTIME_ARCHIVE",runtimeUrl:"AIB_RUNTIME_URL",runtimeManifest:"AIB_RUNTIME_MANIFEST",runtimeManifestUrl:"AIB_RUNTIME_MANIFEST_URL",managedHostWaitMs:"AIB_MANAGED_HOST_WAIT_MS",workspaceRoot:"AIB_WORKSPACE_ROOT",helpDir:"AIB_HELP_DIR",trace:"AIB_TRACE",traceDir:"AIB_TRACE_DIR",failureSnapshots:"AIB_FAILURE_SNAPSHOTS",productStorageDir:"AIB_PRODUCT_STORAGE_DIR",cliSessionDir:"AIB_CLI_SESSION_DIR",disableWatchers:"AIB_DISABLE_WATCHERS",session:"AIB",legacySession:"AIB_SESSION",transport:"AIB_TRANSPORT",metrics:"AIB_METRICS",metricsDir:"AIB_METRICS_DIR",metricsTag:"AIB_METRICS_TAG",mutationImpactMetrics:"AIB_MUTATION_IMPACT_METRICS",mutationImpactStream:"AIB_MUTATION_IMPACT_STREAM",testPostMutationCyclesDelayMs:"AIB_TEST_POST_MUTATION_CYCLES_DELAY_MS",testMoveToFileFailEntity:"AIB_TEST_MOVE_TO_FILE_FAIL_ENTITY",testRefactorBatchDelayMs:"AIB_TEST_REFACTOR_BATCH_DELAY_MS",testRenameDelayMs:"AIB_TEST_RENAME_DELAY_MS",modulePlanSyncWaitMs:"AIB_MODULE_PLAN_SYNC_WAIT_MS",refactorBatchSyncWaitMs:"AIB_REFACTOR_BATCH_SYNC_WAIT_MS",renameSyncWaitMs:"AIB_RENAME_SYNC_WAIT_MS",modulePlanDebugTimeline:"AIB_DEBUG_MODULE_PLAN_TIMELINE",forceDsl:"AIB_FORCE_DSL"};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CLI_ENV=void 0,exports.CLI_ENV={autoStartIde:"AIB_AUTO_START_IDE",installConfig:"AIB_INSTALL_CONFIG",managedHostScript:"AIB_MANAGED_HOST_SCRIPT",managedHostKind:"AIB_MANAGED_HOST_KIND",managedHostRunDir:"AIB_MANAGED_HOST_RUN_DIR",codeServerPath:"AIB_CODE_SERVER_PATH",nodePath:"AIB_NODE_PATH",extensionVsix:"AIB_EXTENSION_VSIX",ideCommand:"AIB_IDE_COMMAND",chromePath:"AIB_CHROME_PATH",rtkPath:"AIB_RTK_PATH",rgPath:"AIB_RG_PATH",runtimeArchive:"AIB_RUNTIME_ARCHIVE",runtimeUrl:"AIB_RUNTIME_URL",runtimeManifest:"AIB_RUNTIME_MANIFEST",runtimeManifestUrl:"AIB_RUNTIME_MANIFEST_URL",managedHostWaitMs:"AIB_MANAGED_HOST_WAIT_MS",workspaceRoot:"AIB_WORKSPACE_ROOT",helpDir:"AIB_HELP_DIR",helpShell:"AIB_HELP_SHELL",trace:"AIB_TRACE",traceDir:"AIB_TRACE_DIR",failureSnapshots:"AIB_FAILURE_SNAPSHOTS",productStorageDir:"AIB_PRODUCT_STORAGE_DIR",cliSessionDir:"AIB_CLI_SESSION_DIR",disableWatchers:"AIB_DISABLE_WATCHERS",session:"AIB",legacySession:"AIB_SESSION",transport:"AIB_TRANSPORT",metrics:"AIB_METRICS",metricsDir:"AIB_METRICS_DIR",metricsTag:"AIB_METRICS_TAG",controlPlaneUrl:"AIB_CONTROL_PLANE_URL",controlPlaneUpload:"AIB_CONTROL_PLANE_UPLOAD",controlPlaneChannel:"AIB_CONTROL_PLANE_CHANNEL",mutationImpactMetrics:"AIB_MUTATION_IMPACT_METRICS",mutationImpactStream:"AIB_MUTATION_IMPACT_STREAM",testPostMutationCyclesDelayMs:"AIB_TEST_POST_MUTATION_CYCLES_DELAY_MS",testMoveToFileFailEntity:"AIB_TEST_MOVE_TO_FILE_FAIL_ENTITY",testRefactorBatchDelayMs:"AIB_TEST_REFACTOR_BATCH_DELAY_MS",testRenameDelayMs:"AIB_TEST_RENAME_DELAY_MS",testFileMoveToDirDelayMs:"AIB_TEST_FILE_MOVE_TO_DIR_DELAY_MS",testFileMoveToDirRowDelayMs:"AIB_TEST_FILE_MOVE_TO_DIR_ROW_DELAY_MS",testFileMoveToDirImportsDelayMs:"AIB_TEST_FILE_MOVE_TO_DIR_IMPORTS_DELAY_MS",testFileMoveToDirFailImports:"AIB_TEST_FILE_MOVE_TO_DIR_FAIL_IMPORTS",testFileRenameDelayMs:"AIB_TEST_FILE_RENAME_DELAY_MS",testFileRenameRowDelayMs:"AIB_TEST_FILE_RENAME_ROW_DELAY_MS",testFileRenameImportsDelayMs:"AIB_TEST_FILE_RENAME_IMPORTS_DELAY_MS",testFileRenameFailImports:"AIB_TEST_FILE_RENAME_FAIL_IMPORTS",testFileRefactorBatchDelayMs:"AIB_TEST_FILE_REFACTOR_BATCH_DELAY_MS",testFileRefactorBatchRowDelayMs:"AIB_TEST_FILE_REFACTOR_BATCH_ROW_DELAY_MS",testFileRefactorBatchImportsDelayMs:"AIB_TEST_FILE_REFACTOR_BATCH_IMPORTS_DELAY_MS",testFileRefactorBatchFailImports:"AIB_TEST_FILE_REFACTOR_BATCH_FAIL_IMPORTS",disableFileMutationImportPostProcess:"AIB_DISABLE_FILE_MUTATION_IMPORT_POST_PROCESS",disableFileMoveImportPostProcess:"AIB_DISABLE_FILE_MOVE_IMPORT_POST_PROCESS",modulePlanSyncWaitMs:"AIB_MODULE_PLAN_SYNC_WAIT_MS",refactorBatchSyncWaitMs:"AIB_REFACTOR_BATCH_SYNC_WAIT_MS",renameSyncWaitMs:"AIB_RENAME_SYNC_WAIT_MS",fileMoveToDirSyncWaitMs:"AIB_FILE_MOVE_TO_DIR_SYNC_WAIT_MS",fileRenameSyncWaitMs:"AIB_FILE_RENAME_SYNC_WAIT_MS",fileRefactorBatchSyncWaitMs:"AIB_FILE_REFACTOR_BATCH_SYNC_WAIT_MS",modulePlanDebugTimeline:"AIB_DEBUG_MODULE_PLAN_TIMELINE",forceDsl:"AIB_FORCE_DSL"};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var P=exports&&exports.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var a=Object.getOwnPropertyDescriptor(e,r);(!a||("get"in a?!e.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,a)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),
|
|
1
|
+
"use strict";var P=exports&&exports.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var a=Object.getOwnPropertyDescriptor(e,r);(!a||("get"in a?!e.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,a)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),y=exports&&exports.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),g=exports&&exports.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(n[n.length]=a);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),a=0;a<n.length;a++)n[a]!=="default"&&P(r,e,n[a]);return y(r,e),r}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.readConfigPathAliases=h,exports.effectivePathAliases=w,exports.expandPathAliasesInArgs=O,exports.expandPathAliasesInJson=E,exports.expandPathAliasValue=c,exports.normalizePathAliasMap=f,exports.normalizePathAliasName=_;const l=g(require("node:path")),A=require("./workspace-root"),s=require("../shared/errors"),m="pathAliases",p=new Set(["aib","file","source","target","scope","save","op"]);function h(t){const e=(0,A.resolveWorkspaceRoot)(t);return e?f(e.config[m],"aib.json pathAliases"):{}}function w(t,e={}){return{...h(t),...f(e,"session path aliases")}}function O(t,e,r){return Object.keys(r).length===0?e:e.map(n=>c(t,n,r))}function E(t,e,r){return e===void 0||Object.keys(r).length===0?e:u(t,e,r)}function c(t,e,r){if(e.includes("*"))return e;const n=e.match(/^@([A-Za-z][A-Za-z0-9_-]*)(?:(?:\/|\\)(.*))?$/);if(!n)return e;const a=n[1]??"",i=n[2]??"",o=r[a];if(!o)throw new s.CliError("UNKNOWN_PATH_ALIAS",`Unknown path alias: @${a}`,{alias:a,available:Object.keys(r).sort()});const b=(0,A.resolveWorkspaceRoot)(t)?.root??t;return l.normalize(l.resolve(b,o,i))}function f(t,e){if(t==null)return{};if(!d(t))throw new s.CliError("INVALID_PATH_ALIASES",`${e} must be an object of alias name to path.`);const r={};for(const[n,a]of Object.entries(t)){const i=_(n,e);if(typeof a!="string"||a.trim()==="")throw new s.CliError("INVALID_PATH_ALIAS_TARGET",`${e}.${n} must be a non-empty path string.`);r[i]=a.trim().replace(/\\/g,"/")}return r}function _(t,e){const r=t.trim();if(!/^[A-Za-z][A-Za-z0-9_-]*$/.test(r))throw new s.CliError("INVALID_PATH_ALIAS_NAME",`${e} has invalid alias name: ${t}`,{expected:"Alias names must match /^[A-Za-z][A-Za-z0-9_-]*$/."});if(p.has(r))throw new s.CliError("RESERVED_PATH_ALIAS_NAME",`${e} uses reserved alias name: ${r}`,{alias:r,reserved:Array.from(p).sort()});return r}function u(t,e,r){if(typeof e=="string")return c(t,e,r);if(Array.isArray(e))return e.map(n=>u(t,n,r));if(d(e)){const n=Object.fromEntries(Object.entries(e).map(([i,o])=>[i,u(t,o,r)])),a=typeof e.scope=="string"?e.scope:"";return a.startsWith("@")&&n.scope!==a&&typeof n.displayScope!="string"&&typeof n.display_scope!="string"&&(n.displayScope=a),n}return e}function d(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isRemovedAgentCommand=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isRemovedAgentCommand=v,exports.resolveCanonicalCommandAlias=O;const r=require("../commands/shared"),c=require("../shared/errors"),M=require("../shared/types"),d=require("../rtk-wrapper/core"),h=new Set(["doctor","diagnostics","init","runtime","session","sync","reveal","trace","control-plane","background","worker","host","ota","observability","feedback","note","generate-docs","config","view","qr","rg",...d.RTK_PASSTHROUGH_COMMANDS]),a=new Set(M.CANONICAL_METHOD_IDS),l=new Set(["applyModulePlan","validateModulePlan","findImporters","findUnusedImports","moveToFile","renameEntities","refactorBatch","normalizeImports","input"]);function v(e){return l.has(e)}function _(e){const s=new Map;for(const[o,t]of Object.entries(e)){if(!a.has(o)||!t)continue;const n=s.get(t)??[];n.push(o),s.set(t,n)}return s}async function O(e,s,o,t){if(l.has(e)||h.has(e)||a.has(e))return e;try{const n={};o!==void 0&&(n.explicitInstanceId=o),t!==void 0&&(n.autoStartIde=t);const u=await(0,r.resolveTargetInstance)(s,n),f=await(0,r.fetchEffectiveConfig)(u.entry),i=_(f.methodAliases).get(e);if(!i||i.length===0)return e;if(i.length>1)throw new c.CliError("AMBIGUOUS_COMMAND_ALIAS",`Alias "${e}" resolves to multiple commands.`,{alias:e,canonicalCommands:i});const[A]=i;return A??e}catch(n){if(n instanceof c.CliError&&n.code==="AMBIGUOUS_COMMAND_ALIAS")throw n;return e}}
|