@automaton-labs/aib 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/cli.js +2 -2
- package/dist/commands/config-command.js +1 -3
- package/dist/commands/config-output.js +8 -0
- package/dist/commands/help-command.js +7 -3
- package/dist/commands/init-workspace.js +1 -3
- package/dist/commands/inspect-tree.js +3 -3
- package/dist/commands/reveal-command.js +5 -0
- package/dist/commands/session-workspace.js +4 -4
- package/dist/commands/sync-command.js +2 -2
- package/dist/config/local-config.js +3 -3
- package/dist/config/resolve-command-alias.js +1 -1
- package/dist/config/tsconfig-discovery.js +1 -0
- package/dist/config/workspace-root.js +3 -3
- package/dist/config/workspace-state.js +1 -1
- package/dist/dsl/aib-dsl.js +1 -1
- package/dist/help/bootstrap.md +108 -94
- package/dist/help/docs/config-setup.aliases.md +56 -0
- package/dist/help/docs/config-setup.excludes.md +45 -0
- package/dist/help/docs/config-setup.import-normalize.md +86 -0
- package/dist/help/docs/config-setup.import-rules.md +96 -0
- package/dist/help/docs/config-setup.tsconfigs.md +33 -0
- package/dist/help/docs/first-setup.md +292 -0
- package/dist/help/docs/help-protocol.md +26 -0
- package/dist/help/docs/inspect.cycles.md +38 -0
- package/dist/help/docs/inspect.md +1 -0
- package/dist/help/docs/inspect.tree.md +8 -6
- package/dist/help/docs/modulePlan.md +3 -0
- package/dist/help/docs/move.md +3 -0
- package/dist/help/docs/mutation.md +3 -0
- package/dist/help/docs/patterns.md +16 -118
- package/dist/help/docs/qr.md +6 -2
- package/dist/help/docs/quick-map.md +30 -0
- package/dist/help/docs/reveal.md +30 -0
- package/dist/help/dsl/bootstrap.md +108 -94
- package/dist/help/dsl/docs/config-setup.aliases.md +56 -0
- package/dist/help/dsl/docs/config-setup.excludes.md +45 -0
- package/dist/help/dsl/docs/config-setup.import-normalize.md +86 -0
- package/dist/help/dsl/docs/config-setup.import-rules.md +96 -0
- package/dist/help/dsl/docs/config-setup.tsconfigs.md +33 -0
- package/dist/help/dsl/docs/first-setup.md +292 -0
- package/dist/help/dsl/docs/help-protocol.md +26 -0
- package/dist/help/dsl/docs/inspect.cycles.md +38 -0
- package/dist/help/dsl/docs/inspect.md +1 -0
- package/dist/help/dsl/docs/inspect.tree.md +8 -6
- package/dist/help/dsl/docs/modulePlan.md +3 -0
- package/dist/help/dsl/docs/move.md +3 -0
- package/dist/help/dsl/docs/mutation.md +3 -0
- package/dist/help/dsl/docs/patterns.md +16 -118
- package/dist/help/dsl/docs/qr.md +6 -2
- package/dist/help/dsl/docs/quick-map.md +30 -0
- package/dist/help/dsl/docs/reveal.md +30 -0
- package/dist/help/dsl/full.md +108 -94
- package/dist/help/dsl/topics/config-setup.aliases.md +54 -0
- package/dist/help/dsl/topics/config-setup.excludes.md +43 -0
- package/dist/help/dsl/topics/config-setup.import-normalize.md +84 -0
- package/dist/help/dsl/topics/config-setup.import-rules.md +94 -0
- package/dist/help/dsl/topics/config-setup.tsconfigs.md +31 -0
- package/dist/help/dsl/topics/first-setup.md +290 -0
- package/dist/help/dsl/topics/help-protocol.md +24 -0
- package/dist/help/dsl/topics/inspect.cycles.md +36 -0
- package/dist/help/dsl/topics/inspect.md +1 -0
- package/dist/help/dsl/topics/inspect.tree.md +8 -6
- package/dist/help/dsl/topics/modulePlan.md +3 -0
- package/dist/help/dsl/topics/move.md +3 -0
- package/dist/help/dsl/topics/mutation.md +3 -0
- package/dist/help/dsl/topics/patterns.md +16 -118
- package/dist/help/dsl/topics/qr.md +6 -2
- package/dist/help/dsl/topics/quick-map.md +28 -0
- package/dist/help/dsl/topics/reveal.md +28 -0
- package/dist/help/full.md +108 -94
- package/dist/help/help-meta.json +57 -17
- package/dist/help/index.md +60 -0
- package/dist/help/json/bootstrap.md +108 -94
- package/dist/help/json/docs/config-setup.aliases.md +56 -0
- package/dist/help/json/docs/config-setup.excludes.md +45 -0
- package/dist/help/json/docs/config-setup.import-normalize.md +86 -0
- package/dist/help/json/docs/config-setup.import-rules.md +96 -0
- package/dist/help/json/docs/config-setup.tsconfigs.md +33 -0
- package/dist/help/json/docs/first-setup.md +292 -0
- package/dist/help/json/docs/help-protocol.md +26 -0
- package/dist/help/json/docs/inspect.cycles.md +38 -0
- package/dist/help/json/docs/inspect.md +1 -0
- package/dist/help/json/docs/inspect.tree.md +8 -6
- package/dist/help/json/docs/modulePlan.md +3 -0
- package/dist/help/json/docs/move.md +3 -0
- package/dist/help/json/docs/mutation.md +3 -0
- package/dist/help/json/docs/patterns.md +16 -118
- package/dist/help/json/docs/qr.md +6 -2
- package/dist/help/json/docs/quick-map.md +30 -0
- package/dist/help/json/docs/reveal.md +30 -0
- package/dist/help/json/full.md +108 -94
- package/dist/help/json/topics/config-setup.aliases.md +54 -0
- package/dist/help/json/topics/config-setup.excludes.md +43 -0
- package/dist/help/json/topics/config-setup.import-normalize.md +84 -0
- package/dist/help/json/topics/config-setup.import-rules.md +94 -0
- package/dist/help/json/topics/config-setup.tsconfigs.md +31 -0
- package/dist/help/json/topics/first-setup.md +290 -0
- package/dist/help/json/topics/help-protocol.md +24 -0
- package/dist/help/json/topics/inspect.cycles.md +36 -0
- package/dist/help/json/topics/inspect.md +1 -0
- package/dist/help/json/topics/inspect.tree.md +8 -6
- package/dist/help/json/topics/modulePlan.md +3 -0
- package/dist/help/json/topics/move.md +3 -0
- package/dist/help/json/topics/mutation.md +3 -0
- package/dist/help/json/topics/patterns.md +16 -118
- package/dist/help/json/topics/qr.md +6 -2
- package/dist/help/json/topics/quick-map.md +28 -0
- package/dist/help/json/topics/reveal.md +28 -0
- package/dist/help/topics/config-setup.aliases.md +54 -0
- package/dist/help/topics/config-setup.excludes.md +43 -0
- package/dist/help/topics/config-setup.import-normalize.md +84 -0
- package/dist/help/topics/config-setup.import-rules.md +94 -0
- package/dist/help/topics/config-setup.tsconfigs.md +31 -0
- package/dist/help/topics/first-setup.md +290 -0
- package/dist/help/topics/help-protocol.md +24 -0
- package/dist/help/topics/inspect.cycles.md +36 -0
- package/dist/help/topics/inspect.md +1 -0
- package/dist/help/topics/inspect.tree.md +8 -6
- package/dist/help/topics/modulePlan.md +3 -0
- package/dist/help/topics/move.md +3 -0
- package/dist/help/topics/mutation.md +3 -0
- package/dist/help/topics/patterns.md +16 -118
- package/dist/help/topics/qr.md +6 -2
- package/dist/help/topics/quick-map.md +28 -0
- package/dist/help/topics/reveal.md +28 -0
- package/dist/runtime/run-command.js +1 -1
- package/dist/session/server.js +3 -3
- package/dist/shared/diagnostic-catalog.js +1 -1
- package/dist/shared/errors.js +6 -5
- package/extension/vscode-refactor-bridge-extension.vsix +0 -0
- package/package.json +1 -1
- package/runtimes/launcher/win-x64/aib.exe +0 -0
- package/scripts/install-windows-launcher.cjs +1 -0
- package/scripts/provision-runtime.cjs +99 -41
|
@@ -10,6 +10,9 @@ Use it when a large file should be refactored into several target files.
|
|
|
10
10
|
|
|
11
11
|
modulePlan orchestrates semantic moves and updates affected references/imports.
|
|
12
12
|
|
|
13
|
+
If imports created by modulePlan do not match the repo style, run:
|
|
14
|
+
aib help config-setup.import-rules
|
|
15
|
+
|
|
13
16
|
Use +expectEmpty when your modulePlan intent is to move all declarations out of the source file.
|
|
14
17
|
It does not change the move behavior; it only asks output to report remaining source declarations if any remain.
|
|
15
18
|
Use it only when remaining declarations would mean the split did not match your intent.
|
package/dist/help/topics/move.md
CHANGED
|
@@ -10,6 +10,9 @@ Move is semantic; it moves supported declarations and updates affected imports/r
|
|
|
10
10
|
Use it for focused extraction into a single target file.
|
|
11
11
|
For large file splitting across several target files, use modulePlan.
|
|
12
12
|
|
|
13
|
+
If imports created by move do not match the repo style, run:
|
|
14
|
+
aib help config-setup.import-rules
|
|
15
|
+
|
|
13
16
|
Move to file:
|
|
14
17
|
move toFile preview --stdin
|
|
15
18
|
move toFile execute --stdin
|
|
@@ -3,6 +3,9 @@ Successful mutations update affected references and imports.
|
|
|
3
3
|
|
|
4
4
|
After a successful mutation, do not manually patch the same imports unless aib reports a follow-up or checks show a real issue.
|
|
5
5
|
|
|
6
|
+
If move/modulePlan imports do not match the repo style, run:
|
|
7
|
+
aib help config-setup.import-rules
|
|
8
|
+
|
|
6
9
|
AIB mutations are designed to reduce manual checking.
|
|
7
10
|
Your job is to express the intent in DSL.
|
|
8
11
|
AIB's job is to convert that intent into code changes.
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
To refresh help protocol:
|
|
2
|
+
aib help help-protocol
|
|
3
|
+
|
|
1
4
|
Use aib before broad file reads when the question is about TS/JS structure, references, dependencies, or focused code.
|
|
5
|
+
Use qr for cross-OS quick reads of text files, logs, JSON, scripts, and line windows.
|
|
6
|
+
It is not a replacement for inspect.
|
|
2
7
|
Use normal text search when the question is just text.
|
|
3
8
|
|
|
4
9
|
For a first pass in a new codebase, map directories before reading files:
|
|
@@ -40,124 +45,17 @@ aib execution status last
|
|
|
40
45
|
|
|
41
46
|
This is an escape hatch for recovering the latest mutation status/result.
|
|
42
47
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
"pathAliases": {
|
|
57
|
-
"svc": "src/services",
|
|
58
|
-
"cli": "packages/cli/src",
|
|
59
|
-
"ext": "packages/extension/src"
|
|
60
|
-
},
|
|
61
|
-
"importRules": [
|
|
62
|
-
{
|
|
63
|
-
"scope": ".",
|
|
64
|
-
"specifier": "shortest",
|
|
65
|
-
"ending": "auto",
|
|
66
|
-
"builtin": "bare",
|
|
67
|
-
"unusedImports": "remove"
|
|
68
|
-
}
|
|
69
|
-
],
|
|
70
|
-
"importNormalize": [
|
|
71
|
-
{
|
|
72
|
-
"scope": "src",
|
|
73
|
-
"to": "shortestAlias",
|
|
74
|
-
"exclude": ["src/generated"]
|
|
75
|
-
}
|
|
76
|
-
],
|
|
77
|
-
"inspect.graph.exclude": [
|
|
78
|
-
"**/* copy.ts"
|
|
79
|
-
]
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
pathAliases define short request aliases for paths agents repeat in aib commands.
|
|
83
|
-
Use them to reduce input tokens for repeated inspect and mutation work.
|
|
84
|
-
|
|
85
|
-
Aliases are for aib request paths. They do not change TypeScript imports by themselves.
|
|
86
|
-
For import style after mutations, use importRules.
|
|
87
|
-
|
|
88
|
-
importRules control imports created or expanded by move/modulePlan mutation cleanup.
|
|
89
|
-
They do not rewrite the whole project.
|
|
90
|
-
|
|
91
|
-
AIB starts from IDE/TS import preferences.
|
|
92
|
-
For mutation cleanup, matching importRules in aib.json take priority.
|
|
93
|
-
|
|
94
|
-
Do not assume IDE/TS defaults match the repo style.
|
|
95
|
-
Set importRules before large move/modulePlan work so imports do not need manual cleanup.
|
|
96
|
-
|
|
97
|
-
Fields:
|
|
98
|
-
scope repo-relative file or directory scope; most specific scope wins
|
|
99
|
-
specifier relative|shortest|project-relative|non-relative
|
|
100
|
-
ending auto|minimal|index|js
|
|
101
|
-
builtin node|bare
|
|
102
|
-
unusedImports remove|preserve
|
|
103
|
-
|
|
104
|
-
Defaults:
|
|
105
|
-
specifier omitted IDE/TS decides
|
|
106
|
-
ending omitted IDE/TS decides
|
|
107
|
-
builtin omitted keep TS/project builtin style
|
|
108
|
-
unusedImports omitted keep unused imports
|
|
109
|
-
|
|
110
|
-
specifier:
|
|
111
|
-
relative best for local relative imports
|
|
112
|
-
shortest best for shortest valid alias/path output
|
|
113
|
-
project-relative best for root-relative project imports
|
|
114
|
-
non-relative best for package or alias imports
|
|
115
|
-
|
|
116
|
-
ending:
|
|
117
|
-
minimal best for extensionless TS imports
|
|
118
|
-
js best for ESM-style TS projects that require .js
|
|
119
|
-
auto leaves the decision to TypeScript
|
|
120
|
-
index best for explicit index import style
|
|
121
|
-
|
|
122
|
-
builtin:
|
|
123
|
-
node path -> node:path; best for explicit Node builtin imports
|
|
124
|
-
bare node:path -> path; best for bare Node builtin imports
|
|
125
|
-
omit field keeps TypeScript/project output; add builtin if agents keep fixing this manually
|
|
126
|
-
|
|
127
|
-
unusedImports:
|
|
128
|
-
remove clean unused imports in mutation-touched files
|
|
129
|
-
preserve keep unused imports
|
|
130
|
-
omit same as preserve
|
|
131
|
-
|
|
132
|
-
Mutation-touched files are files where TS produced edits: source/target files and any reference/update files TS changed.
|
|
133
|
-
Recommended value: remove
|
|
134
|
-
|
|
135
|
-
importNormalize defines reusable defaults for aib imports normalize.
|
|
136
|
-
Use it when the same normalize request would otherwise be repeated.
|
|
137
|
-
|
|
138
|
-
It affects explicit import normalize commands only.
|
|
139
|
-
It does not run automatically during move/modulePlan; use importRules for mutation-time cleanup.
|
|
140
|
-
|
|
141
|
-
Fields:
|
|
142
|
-
scope repo-relative file or directory scope; most specific scope wins
|
|
143
|
-
to relative|alias|shortestAlias
|
|
144
|
-
preferAlias tsconfig paths pattern used when to=alias
|
|
145
|
-
exclude files, directories, or glob-like patterns to skip
|
|
146
|
-
|
|
147
|
-
to:
|
|
148
|
-
relative rewrite resolved local imports to relative paths
|
|
149
|
-
alias rewrite resolved local imports to a matching tsconfig alias
|
|
150
|
-
shortestAlias rewrite to the shortest valid alias specifier
|
|
151
|
-
|
|
152
|
-
preferAlias:
|
|
153
|
-
@shared/* prefer one alias pattern when several aliases can resolve the same file
|
|
154
|
-
|
|
155
|
-
inspect.graph.exclude skips files before graph builds the model.
|
|
156
|
-
Use it for generated files, backups, local copies, or other paths that make graph output noisy.
|
|
157
|
-
|
|
158
|
-
Excluded files do not affect graph counts, hubs, entrypoints, leaves, edges, imports, importedBy, or saved graph files.
|
|
159
|
-
|
|
160
|
-
Leave feedback while working.
|
|
48
|
+
Config excludes can hide files from tree/graph/sync output.
|
|
49
|
+
|
|
50
|
+
AIB has four config exclude fields:
|
|
51
|
+
inspect.graph.exclude
|
|
52
|
+
inspect.tree.files.exclude
|
|
53
|
+
inspect.tree.onlyDirs.exclude
|
|
54
|
+
sync.tsconfig.exclude
|
|
55
|
+
|
|
56
|
+
For all of them, node_modules, .git, dist, build, out, and .tmp are skipped by default.
|
|
57
|
+
|
|
58
|
+
Important: leave feedback while working.
|
|
161
59
|
|
|
162
60
|
aib is built for agents. Agent feedback is the main signal for improving output, docs, mutations, and token efficiency.
|
|
163
61
|
|
package/dist/help/topics/qr.md
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
Use qr
|
|
1
|
+
Use qr for cross-OS quick reads of text files: ts, js, cmd, sh, json, log, txt, ndjson, etc.
|
|
2
|
+
Use it for compact line windows and batching.
|
|
2
3
|
qr supports AIB path aliases.
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
It is not a replacement for inspect.
|
|
5
6
|
Use it as a token-efficient way to read text data when semantic inspect is not needed.
|
|
6
7
|
|
|
8
|
+
For focused text reads, prefer qr over cat/Get-Content/type, especially when aliases, line windows, or batching help.
|
|
9
|
+
Use shell reads only when piping into shell tooling or qr is unavailable.
|
|
10
|
+
|
|
7
11
|
Controls:
|
|
8
12
|
-h N head; first N lines
|
|
9
13
|
-t N tail; last N lines
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Read:
|
|
2
|
+
qr quick reads: ts, js, cmd, sh, json, log, txt, etc.
|
|
3
|
+
view hidden/truncated output
|
|
4
|
+
|
|
5
|
+
Inspect:
|
|
6
|
+
file
|
|
7
|
+
imports
|
|
8
|
+
exports
|
|
9
|
+
members
|
|
10
|
+
code
|
|
11
|
+
deps
|
|
12
|
+
usages
|
|
13
|
+
graph
|
|
14
|
+
tree
|
|
15
|
+
duplicates
|
|
16
|
+
cycles
|
|
17
|
+
|
|
18
|
+
Mutate:
|
|
19
|
+
rename
|
|
20
|
+
move
|
|
21
|
+
modulePlan
|
|
22
|
+
refactor batch
|
|
23
|
+
imports normalize
|
|
24
|
+
|
|
25
|
+
Other:
|
|
26
|
+
config
|
|
27
|
+
prefs
|
|
28
|
+
reveal tsconfig and tsconfig alias discovery
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Use reveal to inspect TypeScript config discovery used by AIB.
|
|
2
|
+
|
|
3
|
+
Reveal is for config/setup diagnosis.
|
|
4
|
+
Use it when aliases, sync, imports normalize, or tsconfig excludes depend on which tsconfig files AIB sees.
|
|
5
|
+
|
|
6
|
+
Commands:
|
|
7
|
+
aib reveal tsconfigs
|
|
8
|
+
aib reveal tsaliases
|
|
9
|
+
|
|
10
|
+
tsconfigs shows visible TypeScript configs and config-excluded configs.
|
|
11
|
+
tsaliases shows baseUrl, paths, extends, inherited paths, duplicated inherited paths, and overridden inherited paths.
|
|
12
|
+
|
|
13
|
+
Controls:
|
|
14
|
+
all show all output instead of compact output
|
|
15
|
+
nec no config excludes; ignore sync.tsconfig.exclude
|
|
16
|
+
ned no default excludes
|
|
17
|
+
limit max visible groups/items before + N more
|
|
18
|
+
|
|
19
|
+
Examples:
|
|
20
|
+
aib reveal tsconfigs
|
|
21
|
+
aib reveal tsconfigs +all
|
|
22
|
+
aib reveal tsconfigs +nec limit=20
|
|
23
|
+
aib reveal tsaliases
|
|
24
|
+
aib reveal tsaliases +all
|
|
25
|
+
aib reveal tsaliases +nec
|
|
26
|
+
|
|
27
|
+
Use tsconfigs before tuning sync.tsconfig.exclude.
|
|
28
|
+
Use tsaliases before creating AIB pathAliases or configuring import normalization.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.runCommand
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.runCommand=z;const P=require("../commands/list-instances"),b=require("../commands/ping"),k=require("../commands/runtime-info"),S=require("../commands/print-config"),R=require("../commands/init-skill-usage"),x=require("../commands/init-workspace"),A=require("../commands/inspect"),c=require("../commands/captured-input"),E=require("../commands/module-plan-command"),D=require("../commands/rename-command"),N=require("../commands/move-command"),O=require("../commands/refactor-command"),U=require("../commands/imports-command"),W=require("../commands/execution-command"),T=require("../commands/observability-command"),M=require("../commands/help-command"),F=require("../commands/generate-docs-command"),j=require("../commands/feedback-command"),Q=require("../commands/doctor"),G=require("../commands/diagnostics-command"),H=require("../commands/session-workspace"),y=require("../commands/session-workspace"),I=require("../config/path-aliases"),J=require("../commands/runtime-command"),K=require("../commands/sync-command"),L=require("../commands/reveal-command"),p=require("../client/transport-options"),m=require("../shared/errors"),l=require("./input-source"),$=require("../config/workspace-state");async function z(n){return(0,y.runWithSessionOverride)(n.sessionId,()=>B(n))}async function B(n){const{command:o,restArgs:d,cwd:r,instanceId:_,metricsSpans:C}=n,u=V(o)?(0,$.ensureWorkspaceState)(r):null,g=u?(0,y.readSessionPathAliasOverrides)(r):{},f={...u?.pathAliases??{},...g},e=(0,I.expandPathAliasesInArgs)(r,d,f),a=await(0,l.resolveCommandInputSource)({command:o,cwd:r,restArgs:e,...n.stdinPayload!==void 0?{preResolvedPayload:(0,I.expandPathAliasesInJson)(r,n.stdinPayload,f)}:{},...n.stdinInputSource!==void 0?{preResolvedSource:n.stdinInputSource}:{}}),s=a.payload,t={};_!==void 0&&(t.explicitInstanceId=_),n.autoStartIde!==void 0&&(t.autoStartIde=n.autoStartIde),n.transport!==void 0&&(t.transport=n.transport),n.metricsEnabled===!0&&(t.metricsEnabled=!0),u&&(t.importRules=u.importRules,t.mutationComments=u.mutationComments);const w=(0,p.getPreferredTransport)();n.transport&&(0,p.setPreferredTransport)(n.transport);try{switch(o){case"doctor":return(0,Q.runDoctor)({cwd:r,runtime:e.includes("--runtime"),verbose:e.includes("--verbose"),json:e.includes("--json")});case"diagnostics":return await(0,G.runDiagnosticsCommand)(e),{ok:!0,command:"diagnostics"};case"session":return(0,H.runSessionWorkspaceCommand)(r,e,s);case"init":return(0,x.runInitWorkspace)(r,d);case"help":return(0,M.runHelpCommand)(e);case"generate-docs":return(0,F.runGenerateDocsCommand)(r,d);case"sync":return(0,K.runSyncCommand)(r,e);case"reveal":return(0,L.runRevealCommand)(r,e);case"observability":return(0,T.runObservabilityCommand)(r,e);case"feedback":case"note":return(0,j.runFeedbackCommand)(r,d,o);case"runtime":return(0,J.runRuntimeCommand)(r,e);case"imports":return(0,c.attachCapturedInput)(r,"imports",s,await(0,U.runImportsCommand)(r,e,s,t,C),a.source);case"listInstances":return(0,P.runListInstances)();case"ping":return(0,b.runPing)(r,t);case"runtimeInfo":return(0,k.runRuntimeInfo)(r,t);case"printConfig":return(0,S.runPrintConfig)(r,t);case"initSkillUsage":case"init-skill-usage":{const i=e.findIndex(h=>h==="--cli-name"),q=i>=0&&e[i+1]?e[i+1]:"aib",v={cwd:r,cliName:q??"aib"};return v.resolveOptions=t,(0,R.runInitSkillUsage)(v)}case"inspect":return(0,c.attachCapturedInput)(r,e[0]==="graph"?"graph":"inspect",s,await(0,A.runInspect)(r,e,s,t),a.source);case"modulePlan":return(0,c.attachCapturedInput)(r,"modulePlan",s,await(0,E.runModulePlanCommand)(r,e,s,t,n.modulePlanExecutionId?{executionId:n.modulePlanExecutionId}:{}),a.source);case"execution":return(0,W.runExecutionCommand)(r,e);case"rename":{if(!(e[0]==="apply"&&typeof e[1]=="string"&&!e[1].startsWith("--"))&&(0,l.commandRequiresPayload)(o,e,a))throw new m.CliError("STDIN_REQUIRED","rename preview/apply/validate expects a payload on stdin or --from, except preview-id apply/help.");return(0,c.attachCapturedInput)(r,"rename",s,await(0,D.runRenameCommand)(r,e,s,t),a.source)}case"move":{if(!(e[0]==="toFile"&&e[1]==="apply"&&typeof e[2]=="string"&&!e[2].startsWith("--"))&&(0,l.commandRequiresPayload)(o,e,a))throw new m.CliError("STDIN_REQUIRED","move toFile preview/apply/validate expects a payload on stdin or --from.");return(0,c.attachCapturedInput)(r,"move",s,await(0,N.runMoveCommand)(r,e,s,t),a.source)}case"refactor":{if(!(e[0]==="batch"&&e[1]==="apply"&&typeof e[2]=="string"&&!e[2].startsWith("--"))&&(0,l.commandRequiresPayload)(o,e,a))throw new m.CliError("STDIN_REQUIRED","refactor batch preview/apply/validate expects a payload on stdin or --from, except preview-id apply/help.");return(0,c.attachCapturedInput)(r,"refactor",s,await(0,O.runRefactorCommand)(r,e,s,t),a.source)}default:throw new m.CliError("UNKNOWN_COMMAND",`Unknown command: ${o}`,{availableCommands:["doctor","diagnostics","listInstances","ping","runtimeInfo","printConfig","init-skill-usage","init","help","generate-docs","sync","reveal","inspect","imports","execution","move","rename","refactor","modulePlan","session","runtime","trace","observability","feedback","note"]})}}finally{(0,p.setPreferredTransport)(w)}}function V(n){return n!=="init"&&n!=="help"&&n!=="generate-docs"&&n!=="observability"&&n!=="feedback"&&n!=="note"&&n!=="runtime"&&n!=="diagnostics"&&n!=="doctor"&&n!=="reveal"}
|
package/dist/session/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var ee=exports&&exports.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var s=Object.getOwnPropertyDescriptor(t,n);(!s||("get"in s?!t.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,s)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),te=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),H=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(n){var r=[];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(r[r.length]=s);return r},e(t)};return function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var r=e(t),s=0;s<r.length;s++)r[s]!=="default"&&ee(n,t,r[s]);return te(n,t),n}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.CliSessionServer=void 0,exports.runSessionServerCli=Ce;const x=H(require("node:fs")),ne=H(require("node:http")),re=require("../shared/agent-text"),oe=require("../shared/event-loop"),g=require("../shared/errors"),
|
|
1
|
+
"use strict";var ee=exports&&exports.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var s=Object.getOwnPropertyDescriptor(t,n);(!s||("get"in s?!t.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,s)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),te=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),H=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(n){var r=[];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(r[r.length]=s);return r},e(t)};return function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var r=e(t),s=0;s<r.length;s++)r[s]!=="default"&&ee(n,t,r[s]);return te(n,t),n}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.CliSessionServer=void 0,exports.runSessionServerCli=Ce;const x=H(require("node:fs")),ne=H(require("node:http")),re=require("../shared/agent-text"),oe=require("../shared/event-loop"),g=require("../shared/errors"),P=require("../shared/metrics"),se=require("../shared/stdout"),U=require("../shared/presentation"),ie=require("../tracing/trace"),V=require("../runtime/run-command"),ae=require("../config/resolve-command-alias"),D=require("../config/auto-start-ide"),a=require("../config/env-vars"),ue=require("../client/transport-options"),N=require("./paths"),O=require("../commands/module-plan-cache"),de=require("../commands/execution-command"),R=require("../payloads/read-stdin-json"),A=require("../commands/module-plan-timeout"),d=require("../diagnostics/module-plan-timeline"),G=require("../commands/mutation-execution-cache"),ce=!1,le=!1;function me(e){x.mkdirSync((0,N.getSessionDir)(),{recursive:!0}),x.writeFileSync((0,N.getSessionInfoPath)(),JSON.stringify(e,null,2)),x.writeFileSync((0,N.getSessionUrlPath)(),`${e.url}
|
|
2
2
|
`)}function fe(){x.rmSync((0,N.getSessionInfoPath)(),{force:!0}),x.rmSync((0,N.getSessionUrlPath)(),{force:!0})}async function k(e){const t=[];for await(const n of e)t.push(Buffer.isBuffer(n)?n:Buffer.from(String(n)));return Buffer.concat(t).toString("utf8")}function E(e,t,n){const r=JSON.stringify(n,null,2);e.writeHead(t,{"content-type":"application/json; charset=utf-8","content-length":Buffer.byteLength(r)}),e.end(r)}function C(e,t){if(e.destroyed||e.writableEnded)return;e.write(`${JSON.stringify(t)}
|
|
3
|
-
`);const n=e;typeof n.flush=="function"&&n.flush()}function pe(e,t,n,r){if(e!==null)return(0,R.parseStdinPayload)(e,{command:t,restArgs:n,...r!==void 0?{format:r}:{}})}function
|
|
4
|
-
`)}class K{server;constructor(){this.server=ne.createServer((t,n)=>{this.handleRequest(t,n)})}async handleRequest(t,n){if(t.method==="GET"&&t.url==="/health"){E(n,200,{ok:!0,pid:process.pid});return}if(t.method==="POST"&&t.url==="/run")try{const r=await k(t),s=r?JSON.parse(r):{};if(typeof s.command!="string"||!Array.isArray(s.restArgs)||typeof s.cwd!="string")throw new g.CliError("INVALID_SESSION_REQUEST","Invalid session request payload.");const i=Pe(s.stdinInputSource),o={command:s.command,restArgs:s.restArgs.filter(p=>typeof p=="string"),cwd:s.cwd,stdinPayload:s.stdinPayload,metricsEnabled:s.metricsEnabled===!0};i!==void 0&&(o.stdinInputSource=i);const u=J(s.transport),f=Ie(s.env);u&&(o.transport=u),o.autoStartIde=(0,D.autoStartIdePolicyFromSession)(s.autoStartIde)??(0,D.resolveAutoStartIdePolicy)();const c=o.metricsEnabled?[]:void 0;c&&(o.metricsSpans=c),typeof s.instanceId=="string"&&(o.instanceId=s.instanceId),typeof s.sessionId=="string"&&(o.sessionId=s.sessionId),typeof s.modulePlanExecutionId=="string"&&(o.modulePlanExecutionId=s.modulePlanExecutionId),s.suppressModulePlanStreamStart===!0&&(o.suppressModulePlanStreamStart=!0);const I=(0,S.metricsNow)(),y=F(f,()=>(0,V.runCommand)(o)).then(p=>((0,S.recordSpan)(c,"session.runCommand",I),p),p=>{throw(0,S.recordSpan)(c,"session.runCommand",I),p}),l=j(o);if(l>0){const p=await W(o,y,l);if(p.status==="deadline"){y.catch(()=>{}),(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.deadline.output.start",{deadlineMs:l});const v=await B(o,l);(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.response.write.start",{mode:"deadline"}),E(n,200,v),(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.response.write.end",{mode:"deadline"});return}const P=p.result;(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.response.write.start",{mode:"result"}),E(n,200,c?(0,S.appendMetrics)(P,c):P),(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.response.write.end",{mode:"result"});return}const m=await y;(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.response.write.start",{mode:"no-deadline"}),E(n,200,c?(0,S.appendMetrics)(m,c):m),(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.response.write.end",{mode:"no-deadline"});return}catch(r){E(n,500,(0,g.errorPayload)(r));return}if(t.method==="POST"&&t.url==="/cli"){let r=null,s=0,i=null;try{i=await X(t),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.request.parsed",{command:i.input.command,args:i.input.restArgs}),s=Date.now(),r=Y(i,s);const o=i.env,u=(0,S.metricsNow)();(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.runCommand.start");const f=F(o,()=>(0,V.runCommand)(i.input)).then(l=>((0,S.recordSpan)(i.spans,"session.runCommand",u),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.runCommand.resolved"),l),l=>{throw(0,S.recordSpan)(i.spans,"session.runCommand",u),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.runCommand.rejected",{error:l instanceof Error?l.message:String(l)}),l}),c=j(i.input);if(c>0){const l=await W(i.input,f,c);if(l.status==="deadline"){f.catch(()=>{}),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.deadline.output.start",{deadlineMs:c});const P=h(await B(i.input,c));M(r,i,P,0,s),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.response.write.start",{mode:"deadline"}),E(n,200,P),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.response.write.end",{mode:"deadline"});return}const m=l.result,p=h(i.spans?(0,S.appendMetrics)(m,i.spans):m);M(r,i,p,0,s),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.response.write.start",{mode:"result"}),E(n,200,p),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.response.write.end",{mode:"result"});return}const I=await f,y=h(i.spans?(0,S.appendMetrics)(I,i.spans):I);M(r,i,y,0,s),E(n,200,y);return}catch(o){const u=h((0,g.errorPayload)(o));M(r,i,u,1,s),E(n,500,u);return}}if(t.method==="POST"&&t.url==="/cli/stream"){let r=null,s=null,i=0,o=null;try{if(o=await X(t,{streamGate:!0}),!Q(o.input)){n.writeHead(204),n.end();return}z(n),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.request.parsed",{command:o.input.command,args:o.input.restArgs}),i=Date.now(),s=Y(o,i),r=we(n,o.input);const u=o.env,f=(0,S.metricsNow)();(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.runCommand.start");const c=F(u,()=>(0,V.runCommand)(o.input)).then(m=>((0,S.recordSpan)(o.spans,"session.runCommand",f),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.runCommand.resolved"),m),m=>{throw(0,S.recordSpan)(o.spans,"session.runCommand",f),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.runCommand.rejected",{error:m instanceof Error?m.message:String(m)}),m}),I=j(o.input);if(I>0){const m=await W(o.input,c,I);if(m.status==="deadline"){c.catch(()=>{}),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.deadline.output.start",{deadlineMs:I});const v=h(await B(o.input,I));M(s,o,v,0,i),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.response.write.start",{mode:"deadline"}),C(n,{type:"result",payload:v}),n.end(),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.response.write.end",{mode:"deadline"});return}const p=m.result,P=h(o.spans?(0,S.appendMetrics)(p,o.spans):p);M(s,o,P,0,i),C(n,{type:"result",payload:P}),n.end();return}const y=await c,l=h(o.spans?(0,S.appendMetrics)(y,o.spans):y);M(s,o,l,0,i),C(n,{type:"result",payload:l}),n.end();return}catch(u){n.headersSent||z(n);const f=h((0,g.errorPayload)(u));M(s,o,f,1,i),C(n,{type:"error",payload:f}),n.end();return}finally{r&&clearInterval(r)}}E(n,404,{ok:!1,error:"Not found"})}async serve(){await new Promise((s,i)=>{this.server.once("error",i),this.server.listen(0,"127.0.0.1",()=>s())});const t=this.server.address();if(!t||typeof t=="string")throw new Error("Failed to determine aib session address.");me({pid:process.pid,host:"127.0.0.1",port:t.port,url:`http://127.0.0.1:${t.port}`,startedAt:new Date().toISOString()});let n=!1;const r=()=>{n||(n=!0,fe(),this.server.close(()=>{process.exit(0)}),setTimeout(()=>{process.exit(0)},1e3).unref())};process.on("SIGTERM",r),process.on("SIGINT",r)}}exports.CliSessionServer=K;function Q(e){return e.command==="diagnostics"&&e.restArgs[0]==="timeout-stream"}function z(e){e.writeHead(200,{"content-type":"application/x-ndjson; charset=utf-8","cache-control":"no-cache","x-accel-buffering":"no"}),e.flushHeaders()}async function X(e,t={}){const n=await k(e),r=new URLSearchParams(n),s=r.get("command")??r.get("method")??"",i=r.get("cwd")??"",o=r.get("instanceId")??void 0,u=r.get("sessionId")??void 0,f=r.get("modulePlanExecutionId")??void 0,c=r.get("suppressModulePlanStreamStart")==="true",I=r.get("metricsEnabled")==="true",y=J(r.get("transport")),l=(0,D.autoStartIdePolicyFromSession)(r.get("autoStartIde"))??(0,D.resolveAutoStartIdePolicy)(),m=Ee(r.get("traceDir")),p=ge(r);if(!s.trim())throw new g.CliError("MISSING_COMMAND","Missing command.");if(!i.trim())throw new g.CliError("MISSING_CWD","Missing cwd.");const P=I?[]:void 0,v=(0,S.metricsNow)(),T=await(0,ae.resolveCanonicalCommandAlias)(s.trim(),i,o,l);(0,S.recordSpan)(P,"session.aliasResolution",v);const b=(0,R.stripStdinFormatFlags)(r.getAll("arg")),L=b.restArgs,w={command:T,restArgs:L,cwd:i,metricsEnabled:I,autoStartIde:l};if(y&&(w.transport=y),o&&(w.instanceId=o),u&&(w.sessionId=u),f&&(w.modulePlanExecutionId=f),c&&(w.suppressModulePlanStreamStart=!0),P&&(w.metricsSpans=P),t.streamGate===!0&&!Q(w))return{input:w,spans:P,...m!==void 0?{traceDir:m}:{},env:p};const q=Se(r.get("stdin"),T,L,b.format),_={command:T,restArgs:L,cwd:i,stdinPayload:pe(r.get("stdin"),T,L,b.format),metricsEnabled:I,autoStartIde:l};return q!==void 0&&(_.stdinInputSource=q),y&&(_.transport=y),o&&(_.instanceId=o),u&&(_.sessionId=u),f&&(_.modulePlanExecutionId=f),c&&(_.suppressModulePlanStreamStart=!0),P&&(_.metricsSpans=P),{input:_,spans:P,...m!==void 0?{traceDir:m}:{},env:p}}function ge(e){const t={},n=[[a.CLI_ENV.metrics,e.get("metrics")??""],[a.CLI_ENV.metricsDir,e.get("metricsDir")??""],[a.CLI_ENV.metricsTag,e.get("metricsTag")??""],[a.CLI_ENV.mutationImpactMetrics,e.get("mutationImpactMetrics")??""],[a.CLI_ENV.mutationImpactStream,e.get("mutationImpactStream")??""],[a.CLI_ENV.testMoveToFileFailEntity,e.get("testMoveToFileFailEntity")??""],[a.CLI_ENV.testPostMutationCyclesDelayMs,e.get("testPostMutationCyclesDelayMs")??""],[a.CLI_ENV.testRefactorBatchDelayMs,e.get("testRefactorBatchDelayMs")??""],[a.CLI_ENV.testRenameDelayMs,e.get("testRenameDelayMs")??""],[a.CLI_ENV.modulePlanSyncWaitMs,e.get("modulePlanSyncWaitMs")??""],[a.CLI_ENV.refactorBatchSyncWaitMs,e.get("refactorBatchSyncWaitMs")??""],[a.CLI_ENV.renameSyncWaitMs,e.get("renameSyncWaitMs")??""],[a.CLI_ENV.modulePlanDebugTimeline,e.get("modulePlanDebugTimeline")??""],[a.CLI_ENV.trace,e.get("trace")??""],[a.CLI_ENV.failureSnapshots,e.get("failureSnapshots")??""],[a.CLI_ENV.productStorageDir,e.get("productStorageDir")??""]];for(const[r,s]of n){const i=s.trim();i&&(t[r]=i)}return t}function Ee(e){if(e===null)return;const t=e.trim();return t||void 0}function Y(e,t){return e.traceDir?(0,ie.startTrace)({cwd:e.input.cwd,argv:[e.input.command,...e.input.restArgs],command:e.input.command,restArgs:e.input.restArgs,...e.input.stdinPayload!==void 0?{stdinPayload:e.input.stdinPayload}:{},traceDir:e.traceDir,startedAtMs:t}):null}function M(e,t,n,r,s){if(!e?.enabled||!t)return;const i=(0,U.createCliPresentationEnvelope)(n);e.complete({output:i.tracePayload,exitCode:n.ok===!1?1:r,durationMs:Date.now()-s,...t.input.transport?{transport:t.input.transport}:{}})}function h(e){return(0,U.createCliPresentationEnvelope)(e).payload}function we(e,t){if(!Me(t))return null;const n=t.modulePlanExecutionId??(0,O.buildModulePlanExecutionId)();t.modulePlanExecutionId=n;const r=Date.now(),s=Z(t),i=s?`
|
|
3
|
+
`);const n=e;typeof n.flush=="function"&&n.flush()}function pe(e,t,n,r){if(e!==null)return(0,R.parseStdinPayload)(e,{command:t,restArgs:n,...r!==void 0?{format:r}:{}})}function Pe(e,t,n,r){if(e!==null)return(0,R.parseInputPayloadWithSource)(e,{command:t,restArgs:n,...r!==void 0?{format:r}:{}}).source}function Se(e){if(e==null)return;if(!e||typeof e!="object"||Array.isArray(e))throw new g.CliError("INVALID_SESSION_REQUEST","Invalid stdin input source.");const t=e;if(t.format!=="json"&&t.format!=="dsl"||typeof t.text!="string")throw new g.CliError("INVALID_SESSION_REQUEST","Invalid stdin input source.");return{format:t.format,text:t.text}}function J(e){if(e==null||e==="")return;const t=(0,ue.parseExtensionTransport)(e);if(!t)throw new g.CliError("INVALID_TRANSPORT","Expected transport to be either http or websocket.");return t}function Ie(e){if(!e||typeof e!="object"||Array.isArray(e))return{};const t=new Set([a.CLI_ENV.managedHostScript,a.CLI_ENV.managedHostKind,a.CLI_ENV.managedHostRunDir,a.CLI_ENV.codeServerPath,a.CLI_ENV.extensionVsix,a.CLI_ENV.ideCommand,a.CLI_ENV.chromePath,a.CLI_ENV.managedHostWaitMs,a.CLI_ENV.workspaceRoot,a.CLI_ENV.disableWatchers,a.CLI_ENV.trace,a.CLI_ENV.traceDir,a.CLI_ENV.failureSnapshots,a.CLI_ENV.productStorageDir,a.CLI_ENV.metrics,a.CLI_ENV.metricsDir,a.CLI_ENV.metricsTag,a.CLI_ENV.mutationImpactMetrics,a.CLI_ENV.mutationImpactStream,a.CLI_ENV.testMoveToFileFailEntity,a.CLI_ENV.testPostMutationCyclesDelayMs,a.CLI_ENV.testRefactorBatchDelayMs,a.CLI_ENV.testRenameDelayMs,a.CLI_ENV.modulePlanSyncWaitMs,a.CLI_ENV.refactorBatchSyncWaitMs,a.CLI_ENV.renameSyncWaitMs,a.CLI_ENV.modulePlanDebugTimeline]),n={};for(const[r,s]of Object.entries(e))t.has(r)&&typeof s=="string"&&(n[r]=s);return n}async function F(e,t){const n=Object.entries(e);if(n.length===0)return t();const r=new Map;for(const[s,i]of n)r.set(s,process.env[s]),process.env[s]=i;try{return await t()}finally{for(const[s,i]of r)i===void 0?delete process.env[s]:process.env[s]=i}}async function W(e,t,n){return(0,d.recordModulePlanTimeline)(e.cwd,e.modulePlanExecutionId,"session.deadline.wait.start",{deadlineMs:n}),(0,G.waitForMutationDeadline)(t.then(r=>((0,d.recordModulePlanTimeline)(e.cwd,e.modulePlanExecutionId,"session.deadline.runPromise.resolved"),r)),n,()=>(0,d.recordModulePlanTimeline)(e.cwd,e.modulePlanExecutionId,"session.deadline.timer.fired",{deadlineMs:n}))}function j(e){if(e.command!=="modulePlan")return 0;const t=e.restArgs[0]??"";return t!=="execute"&&t!=="apply"?0:(0,G.readMutationSyncWaitMs)(process.env[a.CLI_ENV.modulePlanSyncWaitMs],12e4)}async function B(e,t){const n=e.modulePlanExecutionId??"last";await(0,oe.yieldToEventLoop)();let r;try{(0,d.recordModulePlanTimeline)(e.cwd,n,"session.inProgress.status.read.start",{elapsedMs:t}),r=(0,de.runExecutionCommand)(e.cwd,["status",n]),(0,d.recordModulePlanTimeline)(e.cwd,n,"session.inProgress.status.read.end",{status:typeof r.status=="string"?r.status:null,phase:typeof r.phase=="string"?r.phase:null,summary:typeof r.summary=="string"?r.summary:null})}catch{(0,d.recordModulePlanTimeline)(e.cwd,n,"session.inProgress.status.read.failed",{elapsedMs:t}),r={operation:"execution.status",executionId:n,status:"running",summary:"in progress"}}const s=Z(e),i=s?s.estimatedDurationMs-t:null,o=ye(r,e,i);return(0,re.attachAgentText)({...r,operation:r.operation??"execution.status",executionId:n,status:r.status??"running",...i!==null?{estimatedRemainingMs:Math.max(0,i)}:{}},o)}function ye(e,t,n){const r=typeof e.executionId=="string"?e.executionId:t.modulePlanExecutionId??"last",i=[`modulePlan.${t.restArgs[0]??"execute"} ${r}`];return typeof e.summary=="string"&&e.summary.length>0&&i.push(e.summary),e.phase==="preview"&&i.push("previewing plan"),e.phase==="mutation"&&i.push("applying mutation"),e.phase==="postMutation.cycles"&&(i.push("mutation completed"),i.push("checking cycles")),i.push(`status: aib execution status ${r}`),n!==null&&i.push(n>0?`estimated remaining: ${(0,A.formatModulePlanTimeoutEstimate)(Math.max(n,5e3))}`:"estimated remaining: check status again soon"),i.join(`
|
|
4
|
+
`)}class K{server;constructor(){this.server=ne.createServer((t,n)=>{this.handleRequest(t,n)})}async handleRequest(t,n){if(t.method==="GET"&&t.url==="/health"){E(n,200,{ok:!0,pid:process.pid});return}if(t.method==="POST"&&t.url==="/run")try{const r=await k(t),s=r?JSON.parse(r):{};if(typeof s.command!="string"||!Array.isArray(s.restArgs)||typeof s.cwd!="string")throw new g.CliError("INVALID_SESSION_REQUEST","Invalid session request payload.");const i=Se(s.stdinInputSource),o={command:s.command,restArgs:s.restArgs.filter(p=>typeof p=="string"),cwd:s.cwd,stdinPayload:s.stdinPayload,metricsEnabled:s.metricsEnabled===!0};i!==void 0&&(o.stdinInputSource=i);const u=J(s.transport),f=Ie(s.env);u&&(o.transport=u),o.autoStartIde=(0,D.autoStartIdePolicyFromSession)(s.autoStartIde)??(0,D.resolveAutoStartIdePolicy)();const c=o.metricsEnabled?[]:void 0;c&&(o.metricsSpans=c),typeof s.instanceId=="string"&&(o.instanceId=s.instanceId),typeof s.sessionId=="string"&&(o.sessionId=s.sessionId),typeof s.modulePlanExecutionId=="string"&&(o.modulePlanExecutionId=s.modulePlanExecutionId),s.suppressModulePlanStreamStart===!0&&(o.suppressModulePlanStreamStart=!0);const I=(0,P.metricsNow)(),y=F(f,()=>(0,V.runCommand)(o)).then(p=>((0,P.recordSpan)(c,"session.runCommand",I),p),p=>{throw(0,P.recordSpan)(c,"session.runCommand",I),p}),l=j(o);if(l>0){const p=await W(o,y,l);if(p.status==="deadline"){y.catch(()=>{}),(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.deadline.output.start",{deadlineMs:l});const v=await B(o,l);(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.response.write.start",{mode:"deadline"}),E(n,200,v),(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.response.write.end",{mode:"deadline"});return}const S=p.result;(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.response.write.start",{mode:"result"}),E(n,200,c?(0,P.appendMetrics)(S,c):S),(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.response.write.end",{mode:"result"});return}const m=await y;(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.response.write.start",{mode:"no-deadline"}),E(n,200,c?(0,P.appendMetrics)(m,c):m),(0,d.recordModulePlanTimeline)(o.cwd,o.modulePlanExecutionId,"session.run.response.write.end",{mode:"no-deadline"});return}catch(r){E(n,500,(0,g.errorPayload)(r));return}if(t.method==="POST"&&t.url==="/cli"){let r=null,s=0,i=null;try{i=await X(t),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.request.parsed",{command:i.input.command,args:i.input.restArgs}),s=Date.now(),r=Y(i,s);const o=i.env,u=(0,P.metricsNow)();(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.runCommand.start");const f=F(o,()=>(0,V.runCommand)(i.input)).then(l=>((0,P.recordSpan)(i.spans,"session.runCommand",u),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.runCommand.resolved"),l),l=>{throw(0,P.recordSpan)(i.spans,"session.runCommand",u),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.runCommand.rejected",{error:l instanceof Error?l.message:String(l)}),l}),c=j(i.input);if(c>0){const l=await W(i.input,f,c);if(l.status==="deadline"){f.catch(()=>{}),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.deadline.output.start",{deadlineMs:c});const S=h(await B(i.input,c));M(r,i,S,0,s),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.response.write.start",{mode:"deadline"}),E(n,200,S),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.response.write.end",{mode:"deadline"});return}const m=l.result,p=h(i.spans?(0,P.appendMetrics)(m,i.spans):m);M(r,i,p,0,s),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.response.write.start",{mode:"result"}),E(n,200,p),(0,d.recordModulePlanTimeline)(i.input.cwd,i.input.modulePlanExecutionId,"session.cli.response.write.end",{mode:"result"});return}const I=await f,y=h(i.spans?(0,P.appendMetrics)(I,i.spans):I);M(r,i,y,0,s),E(n,200,y);return}catch(o){const u=h((0,g.errorPayload)(o));M(r,i,u,1,s),E(n,500,u);return}}if(t.method==="POST"&&t.url==="/cli/stream"){let r=null,s=null,i=0,o=null;try{if(o=await X(t,{streamGate:!0}),!Q(o.input)){n.writeHead(204),n.end();return}z(n),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.request.parsed",{command:o.input.command,args:o.input.restArgs}),i=Date.now(),s=Y(o,i),r=we(n,o.input);const u=o.env,f=(0,P.metricsNow)();(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.runCommand.start");const c=F(u,()=>(0,V.runCommand)(o.input)).then(m=>((0,P.recordSpan)(o.spans,"session.runCommand",f),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.runCommand.resolved"),m),m=>{throw(0,P.recordSpan)(o.spans,"session.runCommand",f),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.runCommand.rejected",{error:m instanceof Error?m.message:String(m)}),m}),I=j(o.input);if(I>0){const m=await W(o.input,c,I);if(m.status==="deadline"){c.catch(()=>{}),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.deadline.output.start",{deadlineMs:I});const v=h(await B(o.input,I));M(s,o,v,0,i),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.response.write.start",{mode:"deadline"}),C(n,{type:"result",payload:v}),n.end(),(0,d.recordModulePlanTimeline)(o.input.cwd,o.input.modulePlanExecutionId,"session.cliStream.response.write.end",{mode:"deadline"});return}const p=m.result,S=h(o.spans?(0,P.appendMetrics)(p,o.spans):p);M(s,o,S,0,i),C(n,{type:"result",payload:S}),n.end();return}const y=await c,l=h(o.spans?(0,P.appendMetrics)(y,o.spans):y);M(s,o,l,0,i),C(n,{type:"result",payload:l}),n.end();return}catch(u){n.headersSent||z(n);const f=h((0,g.errorPayload)(u));M(s,o,f,1,i),C(n,{type:"error",payload:f}),n.end();return}finally{r&&clearInterval(r)}}E(n,404,{ok:!1,error:"Not found"})}async serve(){await new Promise((s,i)=>{this.server.once("error",i),this.server.listen(0,"127.0.0.1",()=>s())});const t=this.server.address();if(!t||typeof t=="string")throw new Error("Failed to determine aib session address.");me({pid:process.pid,host:"127.0.0.1",port:t.port,url:`http://127.0.0.1:${t.port}`,startedAt:new Date().toISOString()});let n=!1;const r=()=>{n||(n=!0,fe(),this.server.close(()=>{process.exit(0)}),setTimeout(()=>{process.exit(0)},1e3).unref())};process.on("SIGTERM",r),process.on("SIGINT",r),await new Promise(()=>{})}}exports.CliSessionServer=K;function Q(e){return e.command==="diagnostics"&&e.restArgs[0]==="timeout-stream"}function z(e){e.writeHead(200,{"content-type":"application/x-ndjson; charset=utf-8","cache-control":"no-cache","x-accel-buffering":"no"}),e.flushHeaders()}async function X(e,t={}){const n=await k(e),r=new URLSearchParams(n),s=r.get("command")??r.get("method")??"",i=r.get("cwd")??"",o=r.get("instanceId")??void 0,u=r.get("sessionId")??void 0,f=r.get("modulePlanExecutionId")??void 0,c=r.get("suppressModulePlanStreamStart")==="true",I=r.get("metricsEnabled")==="true",y=J(r.get("transport")),l=(0,D.autoStartIdePolicyFromSession)(r.get("autoStartIde"))??(0,D.resolveAutoStartIdePolicy)(),m=Ee(r.get("traceDir")),p=ge(r);if(!s.trim())throw new g.CliError("MISSING_COMMAND","Missing command.");if(!i.trim())throw new g.CliError("MISSING_CWD","Missing cwd.");const S=I?[]:void 0,v=(0,P.metricsNow)(),T=await(0,ae.resolveCanonicalCommandAlias)(s.trim(),i,o,l);(0,P.recordSpan)(S,"session.aliasResolution",v);const b=(0,R.stripStdinFormatFlags)(r.getAll("arg")),L=b.restArgs,w={command:T,restArgs:L,cwd:i,metricsEnabled:I,autoStartIde:l};if(y&&(w.transport=y),o&&(w.instanceId=o),u&&(w.sessionId=u),f&&(w.modulePlanExecutionId=f),c&&(w.suppressModulePlanStreamStart=!0),S&&(w.metricsSpans=S),t.streamGate===!0&&!Q(w))return{input:w,spans:S,...m!==void 0?{traceDir:m}:{},env:p};const q=Pe(r.get("stdin"),T,L,b.format),_={command:T,restArgs:L,cwd:i,stdinPayload:pe(r.get("stdin"),T,L,b.format),metricsEnabled:I,autoStartIde:l};return q!==void 0&&(_.stdinInputSource=q),y&&(_.transport=y),o&&(_.instanceId=o),u&&(_.sessionId=u),f&&(_.modulePlanExecutionId=f),c&&(_.suppressModulePlanStreamStart=!0),S&&(_.metricsSpans=S),{input:_,spans:S,...m!==void 0?{traceDir:m}:{},env:p}}function ge(e){const t={},n=[[a.CLI_ENV.metrics,e.get("metrics")??""],[a.CLI_ENV.metricsDir,e.get("metricsDir")??""],[a.CLI_ENV.metricsTag,e.get("metricsTag")??""],[a.CLI_ENV.mutationImpactMetrics,e.get("mutationImpactMetrics")??""],[a.CLI_ENV.mutationImpactStream,e.get("mutationImpactStream")??""],[a.CLI_ENV.testMoveToFileFailEntity,e.get("testMoveToFileFailEntity")??""],[a.CLI_ENV.testPostMutationCyclesDelayMs,e.get("testPostMutationCyclesDelayMs")??""],[a.CLI_ENV.testRefactorBatchDelayMs,e.get("testRefactorBatchDelayMs")??""],[a.CLI_ENV.testRenameDelayMs,e.get("testRenameDelayMs")??""],[a.CLI_ENV.modulePlanSyncWaitMs,e.get("modulePlanSyncWaitMs")??""],[a.CLI_ENV.refactorBatchSyncWaitMs,e.get("refactorBatchSyncWaitMs")??""],[a.CLI_ENV.renameSyncWaitMs,e.get("renameSyncWaitMs")??""],[a.CLI_ENV.modulePlanDebugTimeline,e.get("modulePlanDebugTimeline")??""],[a.CLI_ENV.trace,e.get("trace")??""],[a.CLI_ENV.failureSnapshots,e.get("failureSnapshots")??""],[a.CLI_ENV.productStorageDir,e.get("productStorageDir")??""]];for(const[r,s]of n){const i=s.trim();i&&(t[r]=i)}return t}function Ee(e){if(e===null)return;const t=e.trim();return t||void 0}function Y(e,t){return e.traceDir?(0,ie.startTrace)({cwd:e.input.cwd,argv:[e.input.command,...e.input.restArgs],command:e.input.command,restArgs:e.input.restArgs,...e.input.stdinPayload!==void 0?{stdinPayload:e.input.stdinPayload}:{},traceDir:e.traceDir,startedAtMs:t}):null}function M(e,t,n,r,s){if(!e?.enabled||!t)return;const i=(0,U.createCliPresentationEnvelope)(n);e.complete({output:i.tracePayload,exitCode:n.ok===!1?1:r,durationMs:Date.now()-s,...t.input.transport?{transport:t.input.transport}:{}})}function h(e){return(0,U.createCliPresentationEnvelope)(e).payload}function we(e,t){if(!Me(t))return null;const n=t.modulePlanExecutionId??(0,O.buildModulePlanExecutionId)();t.modulePlanExecutionId=n;const r=Date.now(),s=Z(t),i=s?`
|
|
5
5
|
estimated: ${(0,A.formatModulePlanTimeoutEstimate)(s.estimatedDurationMs)}`:"";if(t.suppressModulePlanStreamStart||C(e,{type:"start",text:`modulePlan.${t.restArgs[0]??"execute"} ${n}
|
|
6
6
|
status: aib execution status ${n}${i}`,data:{operation:`modulePlan.${t.restArgs[0]??"execute"}`,executionId:n,...s?{estimatedTimeoutMs:s.recommendedTimeoutMs,estimatedDurationMs:s.estimatedDurationMs,suggestedFirstCheckMs:s.suggestedFirstCheckMs,rowCount:s.rowCount,symbolCount:s.symbolCount}:{}}}),!le)return null;let o=r;return setInterval(()=>{try{const u=(0,O.readModulePlanExecutionStatus)(t.cwd,n),f=Date.parse(u.startedAt);if(Number.isFinite(f)&&f+1e3<r){o=$(e,o);return}if(!(u.completedRows>0||u.failedRows>0||u.filesWritten.length>0)){o=$(e,o);return}C(e,{type:"progress",text:`progress: ${u.completedRows}/${u.rowCount} rows${_e(u.completedEntities,u.entityCount)}, ${u.filesWritten.length} files`,data:{operation:u.operation,executionId:u.executionId,status:u.status,completedRows:u.completedRows,failedRows:u.failedRows,rowCount:u.rowCount,completedEntities:u.completedEntities,entityCount:u.entityCount,filesWritten:u.filesWritten.length}})}catch{o=$(e,o)}},5e3)}function $(e,t){if(!ce)return t;const n=Date.now();return n-t<3e4?t:(C(e,{type:"progress",text:"modulePlan still running",data:{operation:"modulePlan",status:"running"}}),n)}function _e(e,t){return!t||t<=0?"":`, ${Math.floor((e??0)/t*100)}% entities`}function Me(e){if(e.command!=="modulePlan")return!1;const t=e.restArgs[0]??"";return t==="execute"||t==="apply"}function Z(e){const t=e.restArgs[0]??"";if(t==="execute")return(0,A.estimateModulePlanTimeoutFromRequest)(e.stdinPayload);if(t!=="apply")return null;const n=he(e.restArgs);if(!n)return null;try{return(0,A.estimateModulePlanTimeoutFromRequest)((0,O.readModulePlanRecord)(e.cwd,n).normalizedRequest)}catch{return null}}function he(e){const t=e.indexOf("--plan");if(t>=0){const r=e[t+1];return r&&!r.startsWith("--")?r:null}return e.slice(1).find(r=>!r.startsWith("--"))??null}async function Ce(){const e=process.argv[3]||"status";if(e!=="serve"){(0,se.printJson)((0,g.errorPayload)(new g.CliError("UNKNOWN_SESSION_COMMAND",`Unknown aib session command: ${e}`))),process.exitCode=1;return}await new K().serve()}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.withHints=o,exports.noIdeInstance=p,exports.protocolVersionUnsupported=d,exports.capabilityNotAvailable=I,exports.transportNotAvailable=h,exports.buildAutoStartHints=b;const r=require("../config/env-vars"),i=require("./errors"),n=require("./hints"),s=require("./protocol");function o(t,e){return{...t,hints:e}}function p(t={}){return new i.CliError("NO_IDE_INSTANCE","No compatible IDE instance was found for the requested cwd.",o(t,[(0,n.commandHint)("aib --cwd <path> --auto-start-ide ping","Retry with managed VS Code serve-web auto-start."),(0,n.actionHint)("Open the target project in VS Code or Cursor with the extension installed.")]))}function d(t,e=null){return new i.CliError("PROTOCOL_VERSION_UNSUPPORTED",`The selected IDE instance uses protocol version ${String(t.protocolVersion??"unknown")}, but this CLI requires version ${s.SUPPORTED_PROTOCOL_VERSION}.`,o({instanceId:t.instanceId,requiredProtocolVersion:s.SUPPORTED_PROTOCOL_VERSION,actualProtocolVersion:l(t.protocolVersion),extensionVersion:c(t.extensionVersion),requiredCapability:e},[(0,n.actionHint)("Install a newer extension VSIX that supports this CLI protocol."),(0,n.actionHint)("Reload the IDE window after installing the latest extension."),(0,n.commandHint)("aib listInstances","Check which IDE instances are currently registered.")]))}function I(t,e){return new i.CliError("CAPABILITY_NOT_AVAILABLE",`The selected IDE instance does not support ${e}.`,o({instanceId:t.instanceId,protocolVersion:l(t.protocolVersion),extensionVersion:c(t.extensionVersion),requiredCapability:e,availableCapabilities:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.withHints=o,exports.noIdeInstance=p,exports.protocolVersionUnsupported=d,exports.capabilityNotAvailable=I,exports.transportNotAvailable=h,exports.buildAutoStartHints=b;const r=require("../config/env-vars"),i=require("./errors"),n=require("./hints"),s=require("./protocol");function o(t,e){return{...t,hints:e}}function p(t={}){return new i.CliError("NO_IDE_INSTANCE","No compatible IDE instance was found for the requested cwd.",o(t,[(0,n.commandHint)("aib --cwd <path> --auto-start-ide ping","Retry with managed VS Code serve-web auto-start."),(0,n.actionHint)("Open the target project in VS Code or Cursor with the extension installed.")]))}function d(t,e=null){return new i.CliError("PROTOCOL_VERSION_UNSUPPORTED",`The selected IDE instance uses protocol version ${String(t.protocolVersion??"unknown")}, but this CLI requires version ${s.SUPPORTED_PROTOCOL_VERSION}.`,o({instanceId:t.instanceId,requiredProtocolVersion:s.SUPPORTED_PROTOCOL_VERSION,actualProtocolVersion:l(t.protocolVersion),extensionVersion:c(t.extensionVersion),requiredCapability:e},[(0,n.actionHint)("Install a newer extension VSIX that supports this CLI protocol."),(0,n.actionHint)("Reload the IDE window after installing the latest extension."),(0,n.commandHint)("aib listInstances","Check which IDE instances are currently registered.")]))}function I(t,e){return new i.CliError("CAPABILITY_NOT_AVAILABLE",`The selected IDE instance does not support ${e}.`,o({instanceId:t.instanceId,protocolVersion:l(t.protocolVersion),extensionVersion:c(t.extensionVersion),requiredCapability:e,availableCapabilities:f(t.capabilities)},[(0,n.actionHint)("Install a newer extension VSIX that supports this capability."),(0,n.commandHint)("npm --prefix packages/extension run package:vsix","Build a fresh local VSIX artifact."),(0,n.actionHint)("Reload the IDE window after installing the latest extension.")]))}function h(t,e){const a=Object.keys(t.transports??{}),u=e==="websocket"&&a.includes("http")?[(0,n.commandHint)("aib --transport http <command>","Retry with the available HTTP transport.")]:[];return new i.CliError("TRANSPORT_NOT_AVAILABLE",`The selected IDE instance does not expose ${e} transport.`,o({instanceId:t.instanceId,requestedTransport:e,availableTransports:a},[...u,(0,n.actionHint)("Install or reload an extension build that exposes the requested transport.")]))}function b(){return[(0,n.commandHint)("aib help first-setup","Set up aib.json at the intended repository root before managed IDE auto-start."),(0,n.commandHint)("aib --no-auto-start-ide <command>","Disable environment auto-start for a single command."),(0,n.configHint)(r.CLI_ENV.installConfig,"Optional product-boundary config file with an extensionVsix path."),(0,n.configHint)(r.CLI_ENV.extensionVsix,"Optional product-boundary path to the packaged VSIX used by managed IDE startup."),(0,n.configHint)(r.CLI_ENV.managedHostScript,"Optional managed host script override when packaged CLI assets are not available.")]}function l(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function c(t){return typeof t=="string"?t:null}function f(t){return Array.isArray(t)?t.filter(e=>typeof e=="string"):[]}
|
package/dist/shared/errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CliError=void 0,exports.errorPayload=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CliError=void 0,exports.errorPayload=E;const m=require("./agent-text");class f extends Error{code;details;constructor(n,s,i){super(s),this.code=n,this.details=i}}exports.CliError=f;function p(e){return Array.isArray(e)&&e.every(n=>n!==null&&typeof n=="object"&&typeof n.kind=="string"&&typeof n.description=="string")}function r(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"?e:Array.isArray(e)?e.map(n=>r(n)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([n,s])=>[n,r(s)])):String(e)}function A(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const n=e.hints;return p(n)?r(n):null}function _(e){return!!(e&&typeof e=="object"&&Array.isArray(e.issues))}function I(e){return!e||e.length===0?"<root>":e.map(n=>String(n)).join(".")}function N(e){return e.issues.map(n=>({path:I(n.path),message:typeof n.message=="string"?n.message:"Invalid value.",...typeof n.code=="string"?{code:n.code}:{}}))}function E(e){if(e instanceof f){const n={ok:!1,code:e.code,error:e.message,details:e.details?r(e.details):null},s=S(e);s&&(n[m.AGENT_TEXT_FIELD]=s);const i=A(e.details);return i?{...n,hints:i}:n}return _(e)?{ok:!1,code:"INVALID_INPUT",error:"Input JSON does not match the expected command shape.",details:{issues:N(e)}}:{ok:!1,code:"UNEXPECTED_ERROR",error:e instanceof Error?e.message:String(e),details:null}}function S(e){if(e.code==="EMPTY_STDIN")return["DSL payload on stdin","","PowerShell:","@'","<input>","'@ | aib <command> --stdin","","Bash/Zsh:","cat <<'EOF' | aib <command> --stdin","<input>","EOF","","cmd.exe:","type request.dsl | aib <command> --stdin"].join(`
|
|
2
2
|
`);if(e.code==="INVALID_STDIN_DSL"){const n=a(e.details),s=c(n.cause);return["invalid DSL stdin",...s?["",s]:[],"","Fix the DSL line and rerun the command."].join(`
|
|
3
3
|
`)}if(e.code==="INVALID_STDIN_FORMAT")return["invalid stdin format","","Use:","--stdin-format auto","--stdin-format dsl"].join(`
|
|
4
4
|
`);if(e.code==="INPUT_SOURCE_CONFLICT"||e.code.endsWith("_INPUT_SOURCE_CONFLICT"))return["input source conflict","","Use only one input source:","--stdin","--from <handle-or-file>","--from-json <file>","--from-dsl <file>"].join(`
|
|
@@ -8,21 +8,22 @@
|
|
|
8
8
|
`);if(e.code==="STDIN_DSL_UNSUPPORTED")return["DSL stdin is not supported for this command","","Use JSON input for this command, or run a DSL-capable command."].join(`
|
|
9
9
|
`);if(e.code.startsWith("INVALID_")&&e.code.endsWith("_JSON_FILE")){const n=a(e.details),s=c(n.file);return["input file could not be read",...s?["",`file: ${s}`]:[],"","Check the path or saved input handle."].join(`
|
|
10
10
|
`)}if(e.code==="UNKNOWN_COMMAND"){const n=a(e.details),s=Array.isArray(n.availableCommands)?n.availableCommands.filter(o=>typeof o=="string"):[],i=["help","config","sync","inspect","modulePlan","move","rename","imports","session","feedback"],t=s.length>0?i.filter(o=>o==="config"||s.includes(o)):i;return[e.message.replace(/^Unknown command:/,"unknown command:"),...t.length>0?["",`Common commands: ${t.join(", ")}`]:[],"","Run:","aib help"].join(`
|
|
11
|
-
`)}if(e.code==="INVALID_INSPECT_OP")return["invalid inspect operation","","Use: file, imports, exports, members, code, deps, usages, duplicates, graph, tree, cycles","","Example:","aib inspect file src/service.ts"].join(`
|
|
11
|
+
`)}if(e.code==="HELP_TOPIC_NOT_FOUND")return e.message;if(e.code==="INVALID_INSPECT_OP")return["invalid inspect operation","","Use: file, imports, exports, members, code, deps, usages, duplicates, graph, tree, cycles","","Example:","aib inspect file src/service.ts"].join(`
|
|
12
12
|
`);if(e.code==="MODULE_PLAN_SOURCE_REQUIRED")return["modulePlan needs a source file","","DSL:","@source src/large-service.ts","module src/large-service.core.ts: LargeService createLargeService"].join(`
|
|
13
13
|
`);if(e.code==="MODULE_PLAN_MODULES_REQUIRED")return["modulePlan needs at least one target module","","DSL:","@source src/large-service.ts","module src/large-service.core.ts: LargeService createLargeService"].join(`
|
|
14
14
|
`);if(e.code==="NORMALIZE_IMPORTS_SCOPE_REQUIRED")return["imports normalize needs a file or directory scope","","DSL:","imports.normalize scope=src/features to=shortestAlias","","CLI:","aib imports normalize preview src/features"].join(`
|
|
15
15
|
`);if(e.code==="INVALID_NORMALIZE_IMPORTS_MODE")return["imports normalize --to expects relative, alias, or shortestAlias","","Example:","aib imports normalize preview src/features --to shortestAlias"].join(`
|
|
16
|
-
`);if(e.code==="WORKSPACE_ROOT_NOT_INITIALIZED")return["aib workspace not initialized","","No aib.json was found.","
|
|
16
|
+
`);if(e.code==="WORKSPACE_ROOT_NOT_INITIALIZED")return["aib workspace not initialized","","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(`
|
|
17
17
|
`);if(e.code==="EXECUTION_NOT_FOUND"||e.code==="MODULE_PLAN_EXECUTION_NOT_FOUND"||e.code==="REFACTOR_BATCH_EXECUTION_NOT_FOUND"){const n=a(e.details);return[`execution not found: ${c(n.executionId)??"last"}`,"","No execution status exists for this id.","Run a long mutation first, or check the execution id."].join(`
|
|
18
18
|
`)}if(e.code==="SESSION_HANDLE_NOT_FOUND"){const n=a(e.details),s=c(n.handle)??"unknown",i=c(n.sessionDir);return[`handle not found: ${s}`,...i?["",`session: ${i}`]:[],"","The artifact may have been cleared or was never saved."].join(`
|
|
19
|
-
`)}if(e.code==="
|
|
19
|
+
`)}if(e.code==="SESSION_WORKSPACE_NOT_INITIALIZED")return["Session workspace is not initialized.","","Create a session:","aib session init --name <name>","","Refresh session guidance:","aib help session"].join(`
|
|
20
|
+
`);if(e.code==="AMBIGUOUS_ENTITY_SELECTOR")return g(e);if(e.code==="INVALID_PATH_ALIAS_TARGET"||e.code==="SESSION_ALIASES_SET_USAGE")return["invalid path alias","","Use:","aib session aliases set <name> <path>","","Example:","aib session aliases set svc src/services"].join(`
|
|
20
21
|
`);if(e.code==="AIB_CONFIG_INVALID"||e.code==="INVALID_PATH_ALIASES"||e.code==="INVALID_PATH_ALIAS_NAME"||e.code==="INVALID_PATH_ALIAS_TARGET"||e.code==="RESERVED_PATH_ALIAS_NAME")return h(e);if(e.code==="UNKNOWN_SESSION_PREF"){const n=a(e.details),s=Array.isArray(n.available)?n.available.filter(i=>typeof i=="string"):[];return[e.message.toLowerCase(),...s.length>0?["","Available prefs:",...s.slice(0,12).map(i=>`- ${i}`),...s.length>12?[`+ ${s.length-12} more`]:[]]:[],"","Run:","aib session prefs get --all"].join(`
|
|
21
22
|
`)}if(e.code==="INVALID_SESSION_PREF_VALUE")return["invalid session preference value","",e.message,"","Run:","aib session prefs get --all"].join(`
|
|
22
23
|
`);if(e.code==="UNKNOWN_SESSION_PREFS_COMMAND")return["unknown session prefs command","","Use:","aib session prefs get","aib session prefs set <key> <value>","aib session prefs clear [key]"].join(`
|
|
23
24
|
`);if(e.code==="UNKNOWN_SESSION_ALIASES_COMMAND")return["unknown session aliases command","","Use:","aib session aliases get","aib session aliases set <name> <path>","aib session aliases clear [name]"].join(`
|
|
24
25
|
`);if(e.code==="UNKNOWN_PATH_ALIAS"){const n=a(e.details),s=c(n.alias),i=Array.isArray(n.available)?n.available.filter(t=>typeof t=="string"):[];return[`unknown AIB path alias: @${s??""}`,"",i.length>0?`Available aliases: ${i.map(t=>`@${t}`).join(", ")}`:"No AIB path aliases are configured.",...i.length>0?["Run:","aib sync"]:["Check config:","aib config","or run:","aib sync"]].join(`
|
|
25
|
-
`)}return null}function
|
|
26
|
+
`)}return null}function g(e){const n=a(e.details),s=Array.isArray(n.ambiguities)?n.ambiguities.filter(t=>t!==null&&typeof t=="object"&&!Array.isArray(t)):[];if(s.length>0){const t=s.map(l=>c(l.entity)).filter(l=>l!==null),o=[t.length===1?`ambiguous entity: ${t[0]}`:`ambiguous entities: ${t.join(", ")}`,"","Use available:"];for(const l of s){const d=Array.isArray(l.suggestions)?l.suggestions.filter(u=>typeof u=="string"&&u.length>0):[];d.length>0&&o.push(`- ${d.join(", ")}`)}return o.join(`
|
|
26
27
|
`)}const i=Array.isArray(n.suggestions)?n.suggestions.filter(t=>typeof t=="string"&&t.length>0):[];return[e.message,...i.length>0?["","Use available:",`- ${i.join(", ")}`]:[]].join(`
|
|
27
28
|
`)}function h(e){const n=["aib config invalid","",e.message];if(e.code==="INVALID_PATH_ALIAS_NAME"&&n.push("Use alias names without @, for example:",'"pathAliases": {',' "svc": "src/services"',"}"),e.code==="RESERVED_PATH_ALIAS_NAME"){const s=a(e.details),i=Array.isArray(s.reserved)?s.reserved.filter(t=>typeof t=="string"):[];i.length>0&&n.push(`Reserved aliases: ${i.join(", ")}`)}return n.push("","Edit aib.json, then run:","aib sync"),n.join(`
|
|
28
29
|
`)}function a(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function c(e){return typeof e=="string"&&e.length>0?e:null}
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|
|
@@ -50,6 +50,7 @@ if (!npmPrefix) {
|
|
|
50
50
|
|
|
51
51
|
fs.mkdirSync(npmPrefix, { recursive: true });
|
|
52
52
|
fs.copyFileSync(launcherPath, path.join(npmPrefix, "aib.exe"));
|
|
53
|
+
fs.writeFileSync(path.join(npmPrefix, "aib.node-cli.txt"), `${path.join(packageRoot, "dist", "bin", "aib.js")}\n`, "utf8");
|
|
53
54
|
|
|
54
55
|
const ps1ShimPath = path.join(npmPrefix, "aib.ps1");
|
|
55
56
|
const ps1BackupPath = path.join(npmPrefix, "aib.ps1.bak");
|