@happyvertical/smrt-inference 0.60.17 → 0.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/AGENTS.md +35 -1
  2. package/README.md +86 -0
  3. package/agents/design-runs.md +110 -0
  4. package/agents/engines.md +458 -0
  5. package/dist/agent-cli/credentials.d.ts +28 -0
  6. package/dist/agent-cli/credentials.d.ts.map +1 -0
  7. package/dist/agent-cli/detect.d.ts +28 -0
  8. package/dist/agent-cli/detect.d.ts.map +1 -0
  9. package/dist/agent-cli/env.d.ts +14 -0
  10. package/dist/agent-cli/env.d.ts.map +1 -0
  11. package/dist/agent-cli/locate.d.ts +16 -0
  12. package/dist/agent-cli/locate.d.ts.map +1 -0
  13. package/dist/agent-cli/login.d.ts +30 -0
  14. package/dist/agent-cli/login.d.ts.map +1 -0
  15. package/dist/agent-cli/runner.d.ts +31 -0
  16. package/dist/agent-cli/runner.d.ts.map +1 -0
  17. package/dist/agent-cli/service.d.ts +20 -0
  18. package/dist/agent-cli/service.d.ts.map +1 -0
  19. package/dist/agent-cli/session.d.ts +42 -0
  20. package/dist/agent-cli/session.d.ts.map +1 -0
  21. package/dist/agent-cli/stream.d.ts +50 -0
  22. package/dist/agent-cli/stream.d.ts.map +1 -0
  23. package/dist/agent-cli/test-support.d.ts +21 -0
  24. package/dist/agent-cli/test-support.d.ts.map +1 -0
  25. package/dist/agent-cli/test-support.js +67 -0
  26. package/dist/agent-cli/test-support.js.map +1 -0
  27. package/dist/agent-cli/tools.d.ts +19 -0
  28. package/dist/agent-cli/tools.d.ts.map +1 -0
  29. package/dist/agent-cli/turn.d.ts +138 -0
  30. package/dist/agent-cli/turn.d.ts.map +1 -0
  31. package/dist/chatgpt/connection.d.ts +149 -0
  32. package/dist/chatgpt/connection.d.ts.map +1 -0
  33. package/dist/chatgpt/model.d.ts +42 -0
  34. package/dist/chatgpt/model.d.ts.map +1 -0
  35. package/dist/chatgpt/resolver.d.ts +39 -0
  36. package/dist/chatgpt/resolver.d.ts.map +1 -0
  37. package/dist/chatgpt/support.d.ts +36 -0
  38. package/dist/chatgpt/support.d.ts.map +1 -0
  39. package/dist/chunks/{InferenceOverrideCollection-ZpxhP0Zl.js → InferenceOverrideCollection-DrlOGPCI.js} +62 -3
  40. package/dist/chunks/InferenceOverrideCollection-DrlOGPCI.js.map +1 -0
  41. package/dist/chunks/work-profiles-DCgIbilc.js +484 -0
  42. package/dist/chunks/work-profiles-DCgIbilc.js.map +1 -0
  43. package/dist/design-run-store.d.ts +26 -0
  44. package/dist/design-run-store.d.ts.map +1 -0
  45. package/dist/design-run.d.ts +146 -0
  46. package/dist/design-run.d.ts.map +1 -0
  47. package/dist/engine-id.d.ts +5 -0
  48. package/dist/engine-id.d.ts.map +1 -0
  49. package/dist/engine-model.d.ts +56 -0
  50. package/dist/engine-model.d.ts.map +1 -0
  51. package/dist/engine-status.d.ts +37 -0
  52. package/dist/engine-status.d.ts.map +1 -0
  53. package/dist/index.d.ts +3 -0
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +2 -1
  56. package/dist/index.js.map +1 -1
  57. package/dist/manifest.json +182 -1
  58. package/dist/models/DesignRunRecord.d.ts +22 -0
  59. package/dist/models/DesignRunRecord.d.ts.map +1 -0
  60. package/dist/models.d.ts +1 -0
  61. package/dist/models.d.ts.map +1 -1
  62. package/dist/models.js +2 -2
  63. package/dist/node.js +1 -1
  64. package/dist/node.js.map +1 -1
  65. package/dist/server.d.ts +24 -0
  66. package/dist/server.d.ts.map +1 -1
  67. package/dist/server.js +2471 -150
  68. package/dist/server.js.map +1 -1
  69. package/dist/settings/controller.d.ts +111 -0
  70. package/dist/settings/controller.d.ts.map +1 -0
  71. package/dist/settings/host.d.ts +75 -0
  72. package/dist/settings/host.d.ts.map +1 -0
  73. package/dist/settings/key-store.d.ts +35 -0
  74. package/dist/settings/key-store.d.ts.map +1 -0
  75. package/dist/settings/resolver.d.ts +6 -2
  76. package/dist/settings/resolver.d.ts.map +1 -1
  77. package/dist/smrt-knowledge.json +93 -7
  78. package/dist/smrt-knowledge.okf.md +15 -5
  79. package/dist/work-profiles.d.ts +127 -0
  80. package/dist/work-profiles.d.ts.map +1 -0
  81. package/package.json +15 -10
  82. package/dist/chunks/InferenceOverrideCollection-ZpxhP0Zl.js.map +0 -1
@@ -0,0 +1,458 @@
1
+ # Local assistant engines (`./server`)
2
+
3
+ ## Codex containment (owner-authorized 2026-11-12 policy)
4
+
5
+ Codex 0.162.1 is usable. Enable **only `code_mode_host`** (when protection is on) in addition to the
6
+ existing modern MCP protocol feature. The host necessarily registers
7
+ `apply_patch`; shell/unified execution and all other optional machine features
8
+ stay disabled. Every Codex attempt (including resume/fallback) now gets a NEW
9
+ empty 0700 `<engine state>/run/turn-*/work` folder, removed in the existing
10
+ finally cleanup after completion, error, abort and timeout. Concurrent turns
11
+ never share it. User config/rules are ignored; project document bytes are zero
12
+ and bundled skills disabled. Schema/config files remain outside the writable
13
+ cwd and contain no credential.
14
+
15
+ Exact containment overrides: `sandbox_mode="workspace-write"`,
16
+ `sandbox_workspace_write.network_access=false`,
17
+ `sandbox_workspace_write.writable_roots=[]`,
18
+ `sandbox_workspace_write.exclude_slash_tmp=true`,
19
+ `sandbox_workspace_write.exclude_tmpdir_env_var=true`,
20
+ `approval_policy="never"`, `web_search="disabled"`,
21
+ `shell_environment_policy.inherit="none"`. No bypass, add-dir, full access or
22
+ terminal approval. Native sandbox policy controls writes/network, not parser
23
+ inspection after an effect. It permits reads according to platform policy; an
24
+ empty cwd is not a read-visibility jail. Provider and loopback MCP HTTP transports
25
+ run in the CLI parent; sandboxed model commands cannot use the network or inherit
26
+ the app's MCP token. API keys remain stripped from the CLI parent environment.
27
+
28
+ The secured spec opts `codexParser` into recognizing only `file_change` and
29
+ `command_execution` as confined built-ins. Record `agent_tool_confined` plus
30
+ fixed `apply_patch`/`exec_command` names, never their payload/path/output; continue
31
+ the app request. Unknown items, foreign MCP and unoffered app tools still stop
32
+ with W1's redacted name diagnostics. App mutations still require the existing
33
+ scoped MCP dispatcher and durable independent owner approval. Existing work
34
+ profiles, one-step classified fallback and child-group kill/timeout are retained.
35
+ Codex maximum effort maps to xhigh; explicit model remains `-m`.
36
+
37
+ Readiness exercises the exact invocation's help plus startup in a disposable
38
+ HOME/CODEX_HOME with no auth, token, proxy or reachable model endpoint; abort at
39
+ `turn.started`. Compatible 0.162.1 now passes; incompatible versions still return
40
+ plain `tool_host_policy` or invocation failure. This is a cheap local startup
41
+ preflight, not a billed inference test or proof of account entitlement.
42
+
43
+ Verified flags: installed `codex exec --help` 0.162.1 and
44
+ [OpenAI configuration reference](https://learn.chatgpt.com/docs/config-file/config-reference).
45
+ A separate native `codex sandbox -P smrt` control used a named profile with
46
+ `filesystem={"/"="read",":workspace_roots"="write"}` and
47
+ `network.enabled=false`: writing inside succeeded, a sibling write and connection
48
+ to a listening loopback HTTP socket were denied. This tests OS enforcement, not
49
+ a model response; the production exec uses the equivalent workspace overrides.
50
+
51
+ | Invariant / reachable trigger | Positive | Negative/control | Actor/context, executor/runtime | Edge / level / validation |
52
+ | --- | --- | --- | --- | --- |
53
+ | Private Codex attempts, including resume | Distinct empty 0700 roots, own-file writes disappear at cleanup | Failure/abort/timeout and concurrent runs cannot share cwd | Local owner, no DB executor; Node26 subprocess | CLI spec/stub; inference test |
54
+ | Confined incidental builtins | Patch/command item logs only fixed names, request finishes | Unknown item/foreign MCP/unoffered app tool still kills; token/arguments absent | Owner-bound app authority; OS sandbox independent of DB | Stream + full stub turn; inference test |
55
+ | Ready/startup | Native compatible CLI and stub with code host starts | Unsupported flags/host, missing runtime, signed-out, directory failure | Local process; no model request | Preflight; inference + exact desktop env tests |
56
+ | Ranked OpenAI choices/fallback | Strongest verified offered model, one lower on classified pre-output refusal, fixed wording/memo | Unknown IDs never guessed; no retry after text/tool, no engine/key fallback | Owner/account/catalog generation; existing preference store | Fake sign-in/catalog/model + host tests |
57
+ | Live app data / Stop | Live read/create via scoped MCP and Stop kills child; fixture held delete decided once | Customer delete remains absent; UI never decides through a model tool | Local owner/tenant, SQLite generated tools | Built product; docs/qa-live-engines.md |
58
+
59
+ Reuse: configured MCP reviewed inference/Svelte/template/app-shell and architecture
60
+ context queried disposable sandboxes, rank/fallback and connection composition.
61
+ Name + purpose `rg` in UI/Svelte/chat/core/inference found `buildAgentRun`,
62
+ `runProcess`, `codexParser`, `reportAgentFailure`, `strongestWorkModel`,
63
+ `runWorkModelWithFallback` and the existing connection catalog. Extend these
64
+ owning modules. New `rankOpenAIWorkModels`/`nextWorkModel` live in the existing
65
+ work-profiles module; no parallel engine, approval service or credential reader.
66
+
67
+ ## Historical 2026-11-11 incompatibility evidence (superseded by containment above)
68
+
69
+ Native probes on the installed CLI use its default model, disposable empty
70
+ HOME/CODEX_HOME, a loopback fake Responses provider with auth disabled, and one
71
+ fixture MCP read tool. No provider credential, account request or real model
72
+ turn is used. The fake reply only enumerates the host's tool registry and, in
73
+ the MCP-call control, invokes that fixture read. No built-in file/shell tool is
74
+ executed. These are protocol facts, not a claim of complete OS sandbox testing.
75
+
76
+ Common invocation: `exec --json --skip-git-repo-check --ignore-user-config
77
+ --ignore-rules`, prompt on stdin, private empty cwd, `--enable mcp_2026_07_28`,
78
+ and `-c sandbox_mode="read-only" -c approval_policy="never"
79
+ -c web_search="disabled"`. The app server is loopback, `required=true`, with
80
+ `bearer_token_env_var` naming the existing environment variable; no token goes
81
+ in argv or files. `default_tools_approval_mode="approve"` refers only to MCP
82
+ transport: the server still owns permissions and independent owner holds.
83
+
84
+ Baseline `--disable` features: `shell_tool`, `unified_exec`, `apps`, `plugins`,
85
+ `hooks`, `multi_agent`, `multi_agent_v2`, `view_image`, `image_generation`,
86
+ `browser_use`, `computer_use`, `in_app_browser`, `memories`, `skill_search`,
87
+ `tool_suggest`, `goals`, `code_mode`, `code_mode_host`,
88
+ `request_permissions_tool`. Native `features list` in the disposable home also
89
+ reports `apply_patch_freeform` as **removed/false**, not an available kill switch.
90
+
91
+ | Option tried (changes from baseline only) | Native result | Capability/security consequence |
92
+ | --- | --- | --- |
93
+ | No change: code host disabled | MCP discovery/list succeeds, but its tool is absent from the model registry; native execution returns `code-mode host is disabled` | Current supported app policy: fail closed as `tool_host_policy`; no model turn is started by readiness. |
94
+ | Enable only `code_mode_host` | Registry contains `mcp__smrt__probe` **and `apply_patch`**; fixture `tools/call` succeeds with protocol 2026-07-28 | App MCP works, but the model retains a built-in filesystem-editing interface. Read-only sandbox and never-approve remain; this does not satisfy “built-ins absent”. Not enabled by SMRT. |
95
+ | Also enable `code_mode_only_strict_3p_tools` | Same MCP + `apply_patch` registry | The strict flag does not remove the built-in tool. Not enabled. |
96
+ | Also enable both `code_mode_only` and `code_mode_only_strict_3p_tools` | Same registry | Combining the strict flags still does not yield MCP-only tools. Not enabled. |
97
+ | Enable `code_mode_host` and `code_mode` | Same registry | Legacy code-mode flag does not remove `apply_patch`. Not enabled. |
98
+ | Enable `code_mode_host` and `shell_tool` (keep `unified_exec` disabled) | Also registers `exec_command` and `write_stdin` | Adds a model-visible shell interface. Read-only/never-approve are narrower than full access but are not an app-only capability boundary. Not enabled. |
99
+
100
+ The empty cwd is not a filesystem visibility jail. A read-only sandbox permits
101
+ inspection according to its platform policy; it does not prove that arbitrary
102
+ absolute paths outside the cwd are invisible. No write/network boundary bypass
103
+ was attempted, and no platform-wide enforcement guarantee is inferred from
104
+ registry enumeration. Provider/MCP transport access is separate from a spawned
105
+ command's network policy. See the official [sandbox contract](https://learn.chatgpt.com/docs/sandboxing)
106
+ and [CLI flags](https://learn.chatgpt.com/docs/cli/reference).
107
+
108
+ Owner choices are: retain this refusal and use a compatible engine; request an
109
+ upstream built-in-tool allow-list/MCP-only host; or explicitly review a broader
110
+ filesystem/shell policy in a separate change. This implementation adopts only
111
+ the first choice. Connect AI says “Not supported with this Codex version yet”
112
+ and explains the file-tool conflict. No model downgrade, API billing fallback,
113
+ code-host enable or sandbox weakening is implemented.
114
+
115
+ Codex's app MCP server is required: it waits for the live catalog within its
116
+ startup timeout instead of continuing after the optional-server grace period
117
+ with no app tools. A failed required MCP startup reports fixed app-connection
118
+ words and a correlated `agent_mcp_unavailable` diagnostic, never child output.
119
+ All machine-tool, user-settings, token and loopback restrictions remain intact.
120
+
121
+ The legacy `assistant token failed:` diagnostic remains for LocalRuntimeError
122
+ token failures, using a fixed class label and allow-listed code only. It follows
123
+ the correlated failure record; arbitrary error names/messages are never logged.
124
+
125
+ `src/agent-cli/` owns discovery, CLI-reported authentication, login processes,
126
+ locked-down subprocess invocation, parsing, the process-tree lifetime, MCP token
127
+ lifetime and a subprocess-owned turn. `src/chatgpt/model.ts` adapts one model
128
+ round; `src/engine-model.ts` defines its model seam. `src/engine-status.ts`
129
+ composes connection diagnostics without selecting a default engine.
130
+
131
+ These modules never import app-shell, smrt-chat, app-runtime, a web framework or
132
+ a host model. Keep all value exports on `./server`; root and `./models` stay
133
+ browser-safe. Plain product labels are metadata, not branded UI.
134
+
135
+ ## Two host contracts
136
+
137
+ A chat-style host calls `createChatGPTModel({ connection, model?, toolNamespace,
138
+ settingsHref? })` then `EngineModel.complete({ messages, tools, maxTokens, signal,
139
+ onText })` for each round. It executes returned `toolCalls` through its own
140
+ policy, persists history and replays `raw` provider calls and tool responses.
141
+ Only `chat()` + `onProgress` reach the plan; token limits, sampling, reasoning,
142
+ response formats, user, forced tool choice and stream flags never do. The host
143
+ must bound total rounds/time/tokens. `EngineModelFailure` carries safe fixed
144
+ words and an optional host route; arbitrary provider errors need a generic
145
+ host error handler. Never expose/log an error's message, cause or SDK options.
146
+ There is no API-key fallback. Connection `clientOptions()` is the only credential
147
+ source; resolver selection remains explicit (`createChatGPTPlanResolver` with
148
+ `appliesTo` and host-verified principal). The SDK owns its credential file.
149
+
150
+ A subprocess host calls `runAgentTurn({ text, tool, mcpUrl, signal, emit, deps,
151
+ host })`. `tool` is `claude-code` or `codex`:
152
+
153
+ - `deps.locate`, `stateDir`, `baseEnv?`, `limits?` supply a discovered executable,
154
+ private app-owned state directory, base environment and time/result bounds.
155
+ - `deps.credentials` supplies `mint`/`revoke`. `tokenCredentials(store,
156
+ { holder, label, scopes })` adapts app-runtime's local MCP token store
157
+ structurally, with no dependency on app-runtime. The host verifies the owner
158
+ first, uses a distinct holder per concurrently active conversation, and
159
+ scopes the token to its policy. Tokens expire after 15 minutes by default;
160
+ custom turn bounds must stay below that or supply a longer-lived credential
161
+ implementation. Never persist the returned secret.
162
+ - `host.appendMessage` and `lastSession` own authenticated storage/session
163
+ continuity. `guidance()` returns the system guidance and current-turn prompt;
164
+ it runs again if an expired CLI session must restart.
165
+ - `host.allowTool` is a stream guard. The authenticated MCP endpoint must also
166
+ enforce the tool policy; stream inspection is no replacement for authorization.
167
+ - `host.approvals.subscribe/get` supplies only approvals belonging to this turn
168
+ and owner. It is an observation interface, with no approval decision method.
169
+ Correlation follows serial tool results in order; unrelated events must be
170
+ filtered by the host. `describeResult` supplies UI words and optional host
171
+ metadata (`details`, also persisted on the tool message); `completionNote?`
172
+ supplies a closing note for host-specific state such as drafts.
173
+
174
+ The host publishes canonical pending holds before returning a tool response.
175
+ A fast independent decision may already be approved/denied when inference reads
176
+ it; it remains a held call and emits the existing approval event, never an
177
+ ordinary successful result that bypasses chat's protected-result guard. Both CLI
178
+ fixtures cover pending, early-approved and early-denied correlation. Model output
179
+ does not supply approval identity or authority.
180
+ - `emit` receives text, tool_call, tool_result, approval_required,
181
+ approval_decided, done and error events. `done.stop` is complete, waiting,
182
+ aborted, timeout or error. Pending approvals return waiting; only the owner's
183
+ independent UI/authority can approve. Host callback/storage failures propagate
184
+ after process and token cleanup. CLI exit output is never forwarded.
185
+
186
+ ## Security invariants
187
+
188
+ Allow-list child environment variables: no provider API keys, endpoint overrides
189
+ or host secrets. Token only in child environment, never argv, logs or config
190
+ files. MCP must use HTTP loopback (127.0.0.1, localhost or ::1). Claude built-ins
191
+ are absent. Codex enables only its necessary code host and confines its patch
192
+ capability as specified above; shell, web and subagent features stay disabled.
193
+ User config/hooks/plugins are ignored. Codex workspaces are private, empty and
194
+ new per attempt. Stream guards reject foreign tools
195
+ and unknown Codex action kinds. Stop/timeout kills the process group (Windows
196
+ uses taskkill /T). CLI credentials are never read: query the CLI's own status
197
+ and run its own login command, which opens the vendor page itself.
198
+
199
+ Claude's `StructuredOutput` is accepted only when the host supplies
200
+ `outputSchema` (and thus `--json-schema`). It is a result channel: its call
201
+ and correlated result never become executable app tools or tool messages;
202
+ only the final `structured_output` is published, with intermediate prose
203
+ suppressed. Without a host schema it remains forbidden. All CLI lockdown
204
+ flags stay intact. Blocked tools report a bounded ASCII name (unsafe names
205
+ become `unknown`) and `builtin`, `unoffered_mcp`, or `unknown_item` in the
206
+ correlated guard diagnostic and safe error message, never their arguments.
207
+
208
+ Native continuation proof (2026-11-12 UTC): a fresh built product chat request
209
+ escalated before `app.addField` executed, then completed all three v2 design
210
+ passes with the exact core-owned proposal (`Members`, `Visit note`, text,
211
+ `expectedRevision: 1`). Each requested `fable` / maximum effort and reported
212
+ `claude-fable-5-1`; provider-reported effort was unavailable. Pass duration,
213
+ tokens and app-tool calls were respectively 26783 ms / 53618 / 1,
214
+ 28841 ms / 54889 / 1, and 26331 ms / 56277 / 1. All three accepted the native
215
+ `StructuredOutput` channel; no schema repair or write occurred. The identical
216
+ schema-enabled formatter event is forbidden by the base parser and accepted
217
+ as a non-executable result channel by this parser. Without a host schema it
218
+ remains forbidden. The earlier v1 proof completed its passes but could not
219
+ prepare a supported operation because write schemas were absent; v2 supplies
220
+ their metadata while retaining read-only execution. This proves proposal
221
+ completion, not final Apply, which requires the trusted durable host action seam.
222
+
223
+ Do not offer in-app Claude subscription login or proxy/store its credentials.
224
+ The person uses their own unmodified Claude Code CLI and its vendor login.
225
+ ChatGPT plan sign-in is a separate, opt-in preview for local open-source apps;
226
+ keep its published limitations visible to users.
227
+
228
+ ## Diagnostics and tests
229
+
230
+ `createAgentCliService()` creates a host-local 15-second detection cache and
231
+ login manager. `inferenceEngineStatus(engine, host)` asks only the selected
232
+ engine: host `apiStatus`, connection `status`, or CLI `cliStatus`. Host `actions`
233
+ provide navigation; inference has no hard-coded application routes.
234
+
235
+ `agent-cli/{detect,session,turn}.test.ts`, `engine-status.test.ts` and
236
+ `chatgpt/{model,support}.test.ts` use stub executables/fake providers only.
237
+ They cover missing/signed-out/unknown status, cache isolation, key stripping,
238
+ secret-free args/config/events/messages/logs, loopback rejection, built-in tool
239
+ lockdown, fail-closed guards, session continuity, tree death on abort/timeout,
240
+ token cleanup, model option restrictions, raw call replay and classified errors.
241
+ App-shell keeps integration tests for its real MCP owner policy, approvals,
242
+ drafts, guidance, persistence, sign-in resolver selection and settings routes.
243
+
244
+ Run package build/test/typecheck as documented in AGENTS.md. No live CLI or
245
+ provider account is needed. PostgreSQL tests remain optional and unrelated to
246
+ these Node subprocess/model adapters.
247
+
248
+ ## Reuse audit for the C2 extraction
249
+
250
+ Audited against base `06c0b64fe3`, including every added source file and its
251
+ exported types, helpers and constants. C2 adds no component, model, route or
252
+ MCP tool definition. CLI product/tool metadata and stream/model/host contracts
253
+ are the API introduced by moving existing shell behavior to its owning package.
254
+
255
+ Discovery used the configured **smrt-dev-mcp** server's
256
+ `review_smrt_project({ directory, detectDuplicates: true,
257
+ includeSourceEvidence: true })` on inference and app-shell, and
258
+ `build_context({ task: 'architecture', idea, rootDir })` for these purpose
259
+ queries: "local Claude Code/Codex CLI detection login sanitized environment
260
+ process tree MCP token invocation stream parser"; "ChatGPT plan model adapter
261
+ model round connection diagnostics authorization browser owner approval
262
+ observation fake CLI fixtures". `build_package_specialist_context` for inference
263
+ checked the proposed shared test entry. This server exposes architecture lookup
264
+ and manifest object lists; it has no standalone component/intent/recipe search
265
+ tool. The intent index and local source/catalog searches fill that gap.
266
+
267
+ Read `docs/knowledge/intents/index.md`, especially local credentials, prompts/AI,
268
+ auth and human approvals. Run name and purpose searches with `rg -n` over
269
+ `packages/{smrt-ui,smrt-svelte,chat,core,inference,app-runtime,smrt-app-mcp,cli,agents}`,
270
+ then repository-wide production-source searches. Also inspect
271
+ `smrt-desktop/src/bundler/{runtime,child-env}.ts`, `planner/src/lib/assistant/models.ts`,
272
+ `vitest/src/{index,test-db}.ts`, and the recipe/component knowledge catalogs.
273
+ The exact source audit is below; internal parsing/lookup helpers belong to the
274
+ same protocol implementation as their exported entry points.
275
+
276
+ | New source file (under `src/`) | Names/purpose searched | Existing capability reused or reason to retain |
277
+ | --- | --- | --- |
278
+ | `agent-cli/credentials.ts` | `AgentCredentials`, `McpTokenStoreLike`, `tokenCredentials`, `AGENT_TOKEN_TTL_SECONDS`; owner token mint/revoke/holder | Adapts app-runtime's existing `LocalMcpTokenStore.issue/revokeHolder`. No credential store added; structural interface prevents an inference-to-runtime dependency. |
279
+ | `agent-cli/detect.ts` | `AgentCliStatus`, `AgentCliLocation`, `cliEnv`, `locateCli`, `detectAgentCli(s)`, `versionOf`, `signedInFrom`; version/status parsing | Moves shell's existing CLI command-based discovery. Inference doctor probes provider endpoints, not installed CLI sessions. No equivalent in core/chat/UI/agents. |
280
+ | `agent-cli/env.ts` | `childEnv`, `nodeDir`, `allowed`; provider-key stripping, allow-list child environment | Desktop `buildChildEnv` forces build locale/npm policy, rejects MCP-token extras and omits CLI sign-in location variables. Its build-process contract is unsuitable; retain the existing shell CLI-specific allow-list. |
281
+ | `agent-cli/locate.ts` | `LocateDeps`, `defaultLocateDeps`, `candidateDirs`, `locateBinary`, `isExecutable`, `listDirs`, `names`, `findIn`, `viaLoginShell`; executable/PATH/login-shell lookup | Existing CLI/desktop runtime launchers run known binaries; none locate the owner's agent CLI in user install directories without credential reads. Moves shell's lookup and its private filesystem/name helpers. |
282
+ | `agent-cli/login.ts` | `AgentLogin`, `LoginSnapshot`, `LoginState`, `Running`, `LOGIN_TIMEOUT_MS`; vendor-owned CLI login | Reuses the CLI's own login/status commands, not a new auth/session store. app-runtime owner setup and users' browser sessions are different identities. |
283
+ | `agent-cli/runner.ts` | `RunOptions`, `RunResult`, `CollectResult`, `runProcess`, `runCollect`, `killTree`, `killNow`, `hookExit`; bounded stdin/stdout/stderr, process-group cleanup | Desktop bundler process tracking and ingestion extraction are private, different lifetime contracts. No public reusable runner supplies this stream/stdin/abort/timeout/redaction contract. Preserve the shell runner and private kill/exit hooks. |
284
+ | `agent-cli/service.ts` | `createAgentCliService`, `configureAgentCli`, `invalidateCliStatus`, `agentLogin`, `cliStatus`, `allCliStatus`, private `deps`; host-local detection cache/login lifecycle | Composes the moved detector/login manager; no existing CLI status cache. Inference settings cache stores settings, not installed CLI authentication. |
285
+ | `agent-cli/session.ts` | `AgentRunSpec`, `SpecInput`, `TOKEN_ENV`, `assertLoopbackUrl`, `buildAgentRun`, `toml`, `claudeSpec`, `codexSpec`; MCP-only Claude/Codex invocation | Moves shell's locked-down CLI protocol. MCP auth's private `validateUrl` permits HTTPS and forbids query scopes; desktop route grammar is path-only. Neither replaces this HTTP-loopback URL guard. Private TOML/spec helpers encode vendor-specific flags. |
286
+ | `agent-cli/stream.ts` | `AgentEvent`, `MCP_SERVER_NAME`, `shellToolName`, `claudeParser`, `codexParser`, `obj`, `str`, `parse`, `textOfContent`; fail-closed CLI event normalization | Chat's model/tool-loop progress does not parse vendor subprocess JSON. Preserve the shell protocol parsers and their internal JSON/text helpers. |
287
+ | `agent-cli/tools.ts` | `AgentTool`, `AgentToolInfo`, `AGENT_TOOLS`, `AGENT_TOOL_INFO`, `isAgentTool`; CLI product metadata | Moves the existing shell metadata; no new application tools. Core recipe/cookbook model metadata describes a different noun. |
288
+ | `agent-cli/turn.ts` | `AgentTurnStop/Event/Limits/Message/Options/Host`, `AgentEngineDeps`, `runAgentTurn`, `tokenFailureMessage`, `tokenFailureCode`, `cut`; result cutting | Moves shell turn behavior behind host callbacks. Chat `runAssistantTurn` owns a provider tool loop and persistence; importing it would violate layering. Approval observation delegates to host authority. Chat's private truncator uses a different output marker. Shell wire types now reuse these shared event/stop types. |
289
+ | `chatgpt/model.ts` | `ChatGPTModelOptions`, `createChatGPTModel`; plan-only model round | Reuses existing `ChatGPTPlanConnection.clientOptions`, SDK `getAI().chat` and failure classifier. Connection/resolver do not adapt model rounds; doctor is diagnostics. No alternate provider/login implementation added. |
290
+ | `chatgpt/support.ts` | `browserCommand`, `SpawnLike`, `openSystemBrowser`, `ChatGPTFailureNote`, `chatgptFailureNote`; authorization opener/failure words | Reuses `isChatGPTAuthorizationUrl` and `classifyChatGPTPlanFailure`. CLI `createBrowserOpener/openInBrowser` accepts arbitrary URLs, has no result contract/Windows quoting guard and depends on inference (cycle). Keep this specialized wrapper and fixed failure vocabulary. |
291
+ | `engine-model.ts` | `EngineModelToolCall/Request/Reply/Failure`, `EngineModel`, `engineModelReply`; model-round seam | Reuses SDK `AIMessage`, `AITool`, `AIToolCall`. Core `InferenceModelClient.message` is text-only; cookbook `EngineModel` is schema metadata; planner `AssistantModel` is WebLLM catalog data; chat's error type lacks action links and cannot be imported here. Flattened calls/raw replay require this seam. |
292
+ | `engine-status.ts` | `InferenceEngineId/Action/Status/StatusHost`, `cliTool`, `engineLabel`, `cliEngineStatus`, `chatgptEngineStatus`, `inferenceEngineStatus` | Composes existing connection status, moved CLI detection and host API diagnostics. Shell `AssistantEngineId/AssistantStatus` now alias these canonical types instead of repeating their shapes. No equivalent engine-choice dispatcher exists. smrt-ui `PageHeaderCrumb` is page ancestry and `ToastAction` executes a callback; neither is a framework-free engine remediation link contract. |
293
+ | `agent-cli/test-support.ts` | `tempDir`, `installStub`, `installFakeCli`, `fakeDeps`, `exists`; isolated CLI fixtures | Removed the parallel shell implementation. Shell re-exports inference's `./test-support` entry. smrt-vitest supplies databases/manifests, not CLI fixtures; smrt-ui test support supplies DOM/a11y. Reuse the existing Vite custom-entry mechanism and `?raw` asset loader, keeping the fixture usable from a built package. |
294
+ | `agent-cli/test-fixtures/stub-cli.mjs` | `start`, `say`, `mcpUrl`, `callTool`, `sessionOf`, `sibling`, `out`; CLI JSON protocol fakes, local tool calls, resume/dump/hang/failure scenarios | Deleted shell's duplicate fixture; one inference-owned fake serves both packages. This is test data, never a production engine or provider. |
295
+
296
+ Added `credentials.test.ts`, `turn.test.ts`, `chatgpt/model.test.ts` and
297
+ `engine-status.test.ts` exercise these contracts with test-local in-memory hosts,
298
+ spies and fake endpoints. Moved `detect.test.ts`, `session.test.ts` and
299
+ `chatgpt/support.test.ts` retain the original shell assertions. Their local
300
+ `setup`, `threadHost`, `turn`, `runOn`, `textOf`, `waitFor`, `alive`, request and
301
+ provider-factory setup/drive/assertion functions are test scenarios, not additional public
302
+ capabilities. Existing shell adapter and DOM tests remain in place.
303
+
304
+ The MCP reviews raised only existing hosted flag detection, existing shell
305
+ approval/polling code and a downstream-UI heuristic for inference. None is a
306
+ copy introduced by C2: inference remains framework-agnostic, and owner approval
307
+ authority stays with the host. This audit does not replace that authority.
308
+
309
+ ## Live desktop regression design (R7/R8)
310
+
311
+ | Behavior | Trigger / positive | Failure control | Actor / executor | Boundary / validation |
312
+ | --- | --- | --- | --- | --- |
313
+ | Process readiness | CLI help with locked invocation, own auth status, private writable cwd | Missing runtime/flags, signed-out CLI, inaccessible directory; no model request | Local owner; no database effect | Exact desktop environment + inference stub tests |
314
+ | Failure diagnostics | Start/stream failure logs reference, phase, fixed cause and code location | Credential-shaped message/output never logged | Server only; existing turn cleanup | Inference/chat tests and built-app log |
315
+ | Single failure | Failed turn restores draft and offers one retry | No duplicate banner, stored fallback or composer alert | Authenticated thread; ChatService | Dock component regression |
316
+ | Live effects | Both CLIs read lists and create a named member | Delete held until independent owner decision, replay refused, abort kills tree | Original owner/tenant; existing MCP dispatcher and durable authority | Built app, fresh SQLite; docs/qa-live-engines.md in product |
317
+
318
+ Reuse search: MCP reviews of inference, chat, desktop, Svelte and template host;
319
+ intent index; `rg` name/purpose searches for preflight, engine diagnostics,
320
+ reference/error IDs, environment helpers and retry presentation in owning
321
+ packages, core, smrt-ui and smrt-svelte. Extend existing detection, turn error
322
+ boundary and dock instead of adding a second engine or error presentation.
323
+
324
+ ## Owner work profiles
325
+
326
+ `work-profiles.ts` exports browser-safe `recommendedWorkProfile` and
327
+ `resolveWorkProfile`: `assist` defaults to high effort, `design` to maximum,
328
+ `background` to low. Design/assist API calls resolve to `best`; the host must
329
+ apply the selected tier to its existing inference client. Owner settings may
330
+ select engine/model/effort and each numeric budget, pass/repair counts,
331
+ automatic escalation and preview. These settings carry no tool authority.
332
+ The preferences package stores owner overrides; inference contains no storage.
333
+
334
+ Claude recommendations select the strongest installed alias, `fable`, then
335
+ `opus`, then `sonnet`; hosts can supply the installed alias inventory. Codex recommendations use the reviewed OpenAI model table. ChatGPT automatic
336
+ recommendations intersect that table with the signed-in account's live catalog.
337
+ `rankOpenAIWorkModels` annotates exact IDs only, preserving a future SDK's explicit
338
+ finite `intelligenceRank`; `strongestWorkModel` never infers strength from response
339
+ order or spelling. Reviewed 2026-11-12 against
340
+ [OpenAI's recommended models](https://learn.chatgpt.com/docs/models#recommended-models):
341
+ Astra, 6.1 Sol, 6.1 Terra, Luna. This is versioned app recommendation data grounded
342
+ in official descriptions, not an undocumented server quality field. Unknown IDs
343
+ remain selectable explicitly but never become automatic recommendations. Refresh
344
+ this table when the catalog adds a new model; an unknown-only catalog truthfully
345
+ has no automatic strongest choice. Both design and assist pick the strongest
346
+ ranked offered model. Background keeps its low-effort profile.
347
+
348
+ `ChatGPTPlanConnection.models()` retains ranks and its ten-minute account cache;
349
+ `defaultModel()` uses ranks. `createChatGPTModel` discovers the catalog when needed
350
+ and derives a single next-lower fallback from it. Host memos include account
351
+ connection generation, catalog and owner preference revision. Fixed fallback
352
+ wording is sent through existing text progress. The installed SDK still rejects
353
+ reasoning/format controls on plan requests; omit them, retain requested effort in
354
+ metadata, and never claim vendor enforcement. Live sign-in/entitlement/inference
355
+ requires the owner and is not proven by fake catalog tests.
356
+
357
+ The browser-safe root exports the same `engineLabel` used by server status;
358
+ product names come from the existing pure CLI metadata. No server-status graph
359
+ is imported by settings. `ResolvedWorkProfile.modelSelection` is derived display
360
+ evidence: `strongest` requires the recommended Claude `fable` alias or the
361
+ selected top-ranked catalog entry; an explicit model is `custom`, and an
362
+ unverified/provider selection is `configured`. Tier names alone do not establish
363
+ model strength. The metadata includes requested and resolved selection ids when
364
+ known; these are selection aliases, not a claimed provider-reported model.
365
+
366
+ `runAgentTurn({ profile, outputSchema })` supplies explicit model and effort,
367
+ Claude `--json-schema`, or Codex `--output-schema` through a private per-pass
368
+ file. Codex maximum maps to `model_reasoning_effort="xhigh"`. Existing machine
369
+ feature prohibitions and parser guards remain in force, including unknown
370
+ structured-output tool kinds: they are refused, never allowed as built-in tools.
371
+ Claude's final `structured_output` object is serialized for the host's schema
372
+ validator. A host still validates and bounds repair attempts through the design
373
+ run driver. ChatGPT's SDK rejects reasoning and JSON format controls, so its
374
+ adapter omits those unsupported controls; schema validation/repair stays host
375
+ side. Recorded effort is the requested policy where the provider cannot honor
376
+ an effort option; it is not a claim of vendor enforcement.
377
+
378
+ Token mint receives the pass timeout; `tokenCredentials` requests a lifetime
379
+ of at least that timeout plus one minute, retaining owner holder/scopes and
380
+ revocation at exit. CLI usage is recorded only when input/output token counts
381
+ are reported, otherwise unknown. `host.recordExecution` and stored assistant
382
+ `meta.workRun` (when a CLI session exists) carry profile, runtime-reported model (unknown when omitted),
383
+ requested alias/model, duration, tool count and
384
+ fallback. `createChatGPTModel` accepts the same profile and execution callback.
385
+
386
+ Both real invocation adapters wire `runWorkModelWithFallback` when a host
387
+ supplies a scoped fallback store and the next verified model. Only explicit
388
+ plan-model refusal codes qualify; arbitrary failures, policy refusals, quota,
389
+ network errors, published text or any tool activity never retry another model.
390
+ One fallback step is allowed, with shared fixed wording. The host persists the
391
+ memo under owner, engine, refused requested model and a connection/catalog key;
392
+ change the key after account/catalog or selection changes. No engine or billing
393
+ path fallback is performed. No live CLI/provider call is needed for tests.
394
+
395
+ For Settings, pass a freshly resolved profile through
396
+ `projectWorkModelSelection` with that same tenant-scoped store, owner, engine,
397
+ requested model and connection key. A remembered different model changes only
398
+ display metadata to `fallback`; `profile.model` remains the original request so
399
+ execution reads the same memo and cannot begin a fallback-of-fallback chain.
400
+ The projector only reads the existing memo: it performs no provider probe,
401
+ notification or write and exposes no connection key in the result. Hosts must
402
+ share their key derivation between display and execution, invalidating it after
403
+ connection/selection changes. The existing profile and browser-safety tests cover
404
+ selection evidence, scope, model immutability and the public label import.
405
+
406
+ Reuse audit: smrt-dev-mcp `review_smrt_project` on inference and
407
+ `build_context(task: architecture)` inventoried package exports/models. The
408
+ intent index and name/purpose searches across smrt-ui, smrt-svelte, chat, core
409
+ and inference found no existing work-intelligence resolver or owner-engine
410
+ fallback memo. `work-profiles.ts` owns that pure inference policy and reuses
411
+ `InferenceEngineId` moved unchanged to browser-safe `engine-id.ts`; existing session/turn/credentials/model adapters own all
412
+ execution. No UI helper, credential store, queue or approval system was added.
413
+
414
+ Native CLI budget enforcement is limited to the subprocess wall deadline and
415
+ observed tool-result truncation for display/history. The vendor has already
416
+ received the MCP result by then: this is not a model-context result bound.
417
+ Resource pages are bounded before context entry; generic MCP observations still
418
+ need a safe serializer with a minimum envelope preserving outcome, approvals and
419
+ cursors without inviting mutation retries. Claude's installed help has no per-call token or
420
+ step limit flag; Codex is contained by its native sandbox. Numeric
421
+ step/token settings remain host/driver admission and accounting budgets, not a
422
+ claim that a vendor CLI stops at those token counts. Hosts must reserve a
423
+ conservative allowance before a CLI pass when native usage is unknown and
424
+ must not count unknown usage as zero. The driver pauses future passes at run
425
+ exhaustion; a request already admitted may exceed a token estimate. Claude
426
+ aggregate usage includes cache reads/creation as well as uncached input/output;
427
+ Codex cached input is already part of input_tokens and is not counted twice.
428
+
429
+ A sessionless CLI pass records execution through `host.recordExecution`; its
430
+ message has no session metadata. Existing hosts retain the original tool/session
431
+ message union without fabricated session IDs.
432
+
433
+ ## Per-app local CLI protection (S1 owner setting)
434
+
435
+ Integration hold: protection-off is a tested local prototype pending an owner boundary decision. App-tool approval gates remain enforced, but unrestricted native commands can edit the app's database files directly. The current implementation does not provide an always-enforced raw-file deletion guarantee. Either scope that guarantee to app tools with an explicit warning, or retain app-data isolation through an OS confinement design before integrating this mode.
436
+
437
+ `AgentTurnOptions.protection` defaults to true; omitted means the containment documented above, unchanged. Only the verified owner settings route may persist false, after an explicit command/file risk confirmation. This is not an MCP/tool argument.
438
+
439
+ | Protection | Claude Code | Codex |
440
+ | --- | --- | --- |
441
+ | On (default) | Native tools absent; personal settings/plugins ignored | Required MCP/code host only; incidental built-ins confined to the private per-turn working folder |
442
+ | Off (owner confirmation) | Native shell/files/network and personal settings/plugins allowed; MCP bearer readable/exfiltratable by shell | Native tools and personal config/plugins allowed under the owner's OS authority; full-access sandbox |
443
+
444
+ With protection **off**, both engines start in persistent `<engine state>/work` (not the project/source tree). Claude Code 2.1.319 uses `--permission-mode bypassPermissions --permission-prompts none`: native operations run without a terminal prompt. Omit `--tools ""`, `--allowedTools`, `--strict-mcp-config`, `--setting-sources ""`, `--disable-slash-commands` and `--no-chrome` so the person's normal tools/config/plugins are available. The app's private `--mcp-config` still supplies its scoped endpoint by environment reference. The cookbook host sets engine state to the app data root, so its exact cwd is `<app data>/work`; protected Codex uses `<app data>/run/turn-*/work`. Other hosts may supply a dedicated engine-state subdirectory.
445
+
446
+ **Unprotected Claude token exposure:** the turn's app MCP bearer token is injected into the CLI environment (`SMRT_SHELL_MCP_TOKEN`). With shell access, the model can read that environment and exfiltrate the token over its native network tools. Output redaction protects the displayed/persisted answer only; it cannot prevent reading or exfiltration. This mode does not claim credential isolation. The owner must decide whether this switch ships.
447
+
448
+ The cookbook host mints only the offered tool slugs intersected with the turn's permission ceiling ([host binding](../../template-sveltekit/host/server.ts)); verification further intersects with the owner's live grants and requires active owner identity ([token store](../../app-runtime/src/local-mcp-tokens.ts)). The bearer can invoke those app reads/writes as that owner while valid, subject to live tool exposure and the same server approval checks; it cannot decide approvals or change owner-only safety settings. A stolen bearer is not cryptographically tied to its child process. Its intended MCP destination is HTTP loopback only ([URL validation](../src/agent-cli/session.ts)); that destination restriction does not prevent the unprotected shell sending the credential elsewhere. Expiry is fixed at `max(15 minutes, requested turn timeout + 60 seconds)` ([credentials](../src/agent-cli/credentials.ts)), not a sliding login. The turn revokes its holder on completion, error, Stop or timeout in `runAgentTurn`'s `finally`; revocation is best effort, so expiry remains the backstop. No token value appears in these docs.
449
+
450
+ Codex 0.162.1 off uses `sandbox_mode="danger-full-access"`, `approval_policy="never"`, `web_search="live"`; it omits the optional-feature disable list, `--ignore-user-config`, `--ignore-rules` and protected workspace overrides. This explicitly permits commands, files and network under the person's OS authority and own CLI config/plugins. Modern MCP and `code_mode_host` remain enabled for app tools. `shell_environment_policy.inherit="none"` remains forced in BOTH states: model shell commands do not inherit the app credential. Protection on retains the fresh 0700 per-attempt folder and cleanup. These flags were checked against installed `claude --help` and `codex exec --help`, not inferred.
451
+
452
+ Always: strip API-key environment variables, loopback-only MCP, short-lived owner-bound token in child environment (never argv/config/logs), app tool allow-list, owner deletion policy, Stop/timeout process-group kill and credential revocation. Off-mode native events record only sanitized tool names (`agent_tool_native`), not input/output; they do not fail an otherwise valid app request. Other app MCP tools remain fail-closed. Off-mode answers buffer to a message/tool boundary and reuse `redactInferenceSecret` to prevent split credential echoes reaching UI/history. Work-profile model/effort and classified one-step fallback are unchanged. Status/preflight caches are separated by protection mode.
453
+
454
+ Stub command specs, stream turns and credential-echo tests cover both modes. The shared ChatGPT connection accepts an optional SDK `begin().cancel` handle; without it, cancellation is explicitly unavailable and pending status remains truthful. Late/expired successful callbacks are signed out instead of silently reconnecting. SDK listener/state/timeout fixes belong upstream.
455
+
456
+ S1 live proof used the built `s1-settings` product with the desktop sidecar environment and four harmless turns, one engine/state pair each. Claude on refused shell access (zero tool calls); Claude off used Bash for `date +%F`. Codex on reported shell unavailable; Codex off used exec_command for the same harmless date command. Product `docs/qa-live-engines.md` carries the exact prompts, requested/reported models and final validation. These checks do not exercise ChatGPT sign-in or chat; its SDK event-stream fix remains unreleased.
457
+
458
+ ChatGPT failure diagnostics (V2): `reportAgentFailure('chatgpt', ...)` follows bounded own-data `cause` wrappers and records only allow-listed provider codes plus a bounded `req_` or UUID request id. It never logs error messages, account fields, response bodies, tokens or arbitrary metadata. The wire error remains the existing safe message; the correlated server reference identifies the cause. Tests exercise direct and wrapped SDK failures and rejection of secret-bearing message/account fields.
@@ -0,0 +1,28 @@
1
+ /** Longer than a turn may run, so a slow turn never loses its token. */
2
+ export declare const AGENT_TOKEN_TTL_SECONDS: number;
3
+ export interface AgentCredentials {
4
+ /** Mint the token for one turn (rotating any earlier one). */
5
+ mint(options?: {
6
+ timeoutMs: number;
7
+ }): Promise<string>;
8
+ /** Revoke it. Safe to call twice. */
9
+ revoke(): Promise<void>;
10
+ }
11
+ /** The slice of app-runtime's `LocalMcpTokenStore` used here. */
12
+ export interface McpTokenStoreLike {
13
+ issue(input: {
14
+ scopes: readonly string[];
15
+ expiresInSeconds?: number;
16
+ label?: string;
17
+ holder?: string;
18
+ }): Promise<{
19
+ token: string;
20
+ }>;
21
+ revokeHolder(holder: string): Promise<'revoked' | 'none'>;
22
+ }
23
+ export declare function tokenCredentials(store: () => Promise<McpTokenStoreLike | undefined>, options: {
24
+ holder: string;
25
+ scopes: readonly string[];
26
+ label: string;
27
+ }): AgentCredentials;
28
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/agent-cli/credentials.ts"],"names":[],"mappings":"AAIA,wEAAwE;AACxE,eAAO,MAAM,uBAAuB,QAAU,CAAC;AAE/C,MAAM,WAAW,gBAAgB;IAC/B,8DAA8D;IAC9D,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvD,qCAAqC;IACrC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,iEAAiE;AACjE,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,KAAK,EAAE;QACX,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;QAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC;CAC3D;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,EACnD,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpE,gBAAgB,CAwBlB"}
@@ -0,0 +1,28 @@
1
+ import { type LocateDeps } from './locate.js';
2
+ import { type AgentTool } from './tools.js';
3
+ /** What the browser may know about a tool. No path, no account detail. */
4
+ export interface AgentCliStatus {
5
+ tool: AgentTool;
6
+ label: string;
7
+ installed: boolean;
8
+ version?: string;
9
+ /** `null` when it could not be asked (the tool did not start). */
10
+ signedIn: boolean | null;
11
+ installUrl: string;
12
+ /** No model request: the exact locked command can start in this process environment. */
13
+ ready?: boolean;
14
+ startError?: 'runtime_unavailable' | 'cli_invocation' | 'working_directory' | 'tool_host_policy';
15
+ }
16
+ export interface AgentCliLocation {
17
+ path: string;
18
+ /** Directories the child needs on PATH (the binary's own, and node's). */
19
+ extraPath: string[];
20
+ }
21
+ export declare function cliEnv(location: AgentCliLocation, base?: Readonly<Record<string, string | undefined>>, extra?: Record<string, string>): Record<string, string>;
22
+ /** The binary's location plus the PATH additions its child needs. */
23
+ export declare function locateCli(tool: AgentTool, deps?: LocateDeps): Promise<AgentCliLocation | null>;
24
+ /** Cheap startup probe: exact locked flags and empty cwd, with --help and no model/token request. */
25
+ export declare function preflightAgentCli(tool: AgentTool, location: AgentCliLocation, baseEnv: LocateDeps['env'], protection?: boolean): Promise<Pick<AgentCliStatus, 'ready' | 'startError'>>;
26
+ export declare function detectAgentCli(tool: AgentTool, deps?: LocateDeps, protection?: boolean): Promise<AgentCliStatus>;
27
+ export declare function detectAgentClis(deps?: LocateDeps): Promise<AgentCliStatus[]>;
28
+ //# sourceMappingURL=detect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/agent-cli/detect.ts"],"names":[],"mappings":"AASA,OAAO,EAAqB,KAAK,UAAU,EAAgB,MAAM,aAAa,CAAC;AAG/E,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAG1E,0EAA0E;AAC1E,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,wFAAwF;IACxF,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EACP,qBAAqB,GACrB,gBAAgB,GAChB,mBAAmB,GACnB,kBAAkB,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAKD,wBAAgB,MAAM,CACpB,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAe,EAChE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKxB;AAED,qEAAqE;AACrE,wBAAsB,SAAS,CAC7B,IAAI,EAAE,SAAS,EACf,IAAI,GAAE,UAAgC,GACrC,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAGlC;AAsBD,qGAAqG;AACrG,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,EAC1B,UAAU,UAAO,GAChB,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,YAAY,CAAC,CAAC,CAmIvD;AAED,wBAAsB,cAAc,CAClC,IAAI,EAAE,SAAS,EACf,IAAI,GAAE,UAAgC,EACtC,UAAU,UAAO,GAChB,OAAO,CAAC,cAAc,CAAC,CAwCzB;AAED,wBAAsB,eAAe,CACnC,IAAI,GAAE,UAAgC,GACrC,OAAO,CAAC,cAAc,EAAE,CAAC,CAE3B"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The child's environment: the allow-listed part of `base`, with `extraPath`
3
+ * directories added to the front of PATH (a desktop app started from Finder has
4
+ * a minimal PATH, and an npm-installed CLI is a `#!/usr/bin/env node` script
5
+ * that needs `node` on it), plus `extra` variables (the MCP token, for a tool
6
+ * that reads it from the environment).
7
+ */
8
+ export declare function childEnv(base: Readonly<Record<string, string | undefined>>, options?: {
9
+ extraPath?: readonly string[];
10
+ extra?: Readonly<Record<string, string>>;
11
+ }): Record<string, string>;
12
+ /** The directory of the running Node (an npm CLI shim needs `node`). */
13
+ export declare function nodeDir(): string;
14
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/agent-cli/env.ts"],"names":[],"mappings":"AA4EA;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EAClD,OAAO,GAAE;IACP,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrC,GACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAcxB;AAED,wEAAwE;AACxE,wBAAgB,OAAO,IAAI,MAAM,CAEhC"}
@@ -0,0 +1,16 @@
1
+ import type { AgentTool } from './tools.js';
2
+ export interface LocateDeps {
3
+ env: Readonly<Record<string, string | undefined>>;
4
+ platform: NodeJS.Platform;
5
+ home: string;
6
+ /** Ask the login shell (POSIX only). Tests turn it off. */
7
+ loginShell: boolean;
8
+ /** System-wide install directories to check. Default: the usual ones. */
9
+ systemDirs?: readonly string[];
10
+ }
11
+ export declare function defaultLocateDeps(): LocateDeps;
12
+ /** Directories the CLIs usually install into, most likely first. */
13
+ export declare function candidateDirs(deps: Pick<LocateDeps, 'env' | 'platform' | 'home' | 'systemDirs'>): string[];
14
+ /** Absolute path of the tool's executable, or null when it is not installed. */
15
+ export declare function locateBinary(tool: AgentTool, deps?: LocateDeps): Promise<string | null>;
16
+ //# sourceMappingURL=locate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locate.d.ts","sourceRoot":"","sources":["../../src/agent-cli/locate.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAClD,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,UAAU,EAAE,OAAO,CAAC;IACpB,yEAAyE;IACzE,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAChC;AAED,wBAAgB,iBAAiB,IAAI,UAAU,CAO9C;AAuBD,oEAAoE;AACpE,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,GAAG,UAAU,GAAG,MAAM,GAAG,YAAY,CAAC,GACjE,MAAM,EAAE,CA8CV;AA8CD,gFAAgF;AAChF,wBAAsB,YAAY,CAChC,IAAI,EAAE,SAAS,EACf,IAAI,GAAE,UAAgC,GACrC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQxB"}
@@ -0,0 +1,30 @@
1
+ import { type LocateDeps } from './locate.js';
2
+ import { type AgentTool } from './tools.js';
3
+ /** How long a person has to finish signing in. */
4
+ export declare const LOGIN_TIMEOUT_MS: number;
5
+ export type LoginState = 'idle' | 'running' | 'finished' | 'failed';
6
+ export interface LoginSnapshot {
7
+ state: LoginState;
8
+ }
9
+ export declare class AgentLogin {
10
+ private readonly options;
11
+ private readonly running;
12
+ private readonly last;
13
+ constructor(options?: {
14
+ deps?: LocateDeps;
15
+ timeoutMs?: number;
16
+ /** Called when a sign-in process ends, so cached status is dropped. */
17
+ onEnd?(tool: AgentTool): void;
18
+ });
19
+ snapshot(tool: AgentTool): LoginSnapshot;
20
+ /**
21
+ * Start the tool's sign-in. `started` / `running` (one is already open) /
22
+ * `missing` (the tool is not installed).
23
+ */
24
+ start(tool: AgentTool): Promise<'started' | 'running' | 'missing'>;
25
+ /** Stop an open sign-in (the person closed the dialog). */
26
+ cancel(tool: AgentTool): void;
27
+ /** Tests: wait until the sign-in process has ended. */
28
+ settled(tool: AgentTool): Promise<void>;
29
+ }
30
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/agent-cli/login.ts"],"names":[],"mappings":"AAMA,OAAO,EAAqB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEjE,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAE7D,kDAAkD;AAClD,eAAO,MAAM,gBAAgB,QAAa,CAAC;AAE3C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEpE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,UAAU,CAAC;CACnB;AAOD,qBAAa,UAAU;IAKnB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoC;gBAGtC,OAAO,GAAE;QACxB,IAAI,CAAC,EAAE,UAAU,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,uEAAuE;QACvE,KAAK,CAAC,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAAC;KAC1B;IAGR,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,aAAa;IAKxC;;;OAGG;IACG,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IAwBxE,2DAA2D;IAC3D,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAI7B,uDAAuD;IACjD,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9C"}