@bastani/atomic 0.10.4-alpha.2 → 0.10.5-alpha.1
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/CHANGELOG.md +238 -0
- package/dist/_shared/chunk-CDOYTDYM.js +4 -0
- package/dist/_shared/chunk-CDOYTDYM.js.map +1 -0
- package/dist/_shared/compile-cache-warmup-host-RU5L7I7A.js +1 -1
- package/dist/_shared/dist-KOELCESV.js +48 -3
- package/dist/_shared/fork-row-index-UAUAQRD5.js +47 -2
- package/dist/_shared/http-YFAPTIZD.js +16 -4
- package/dist/_shared/http-YFAPTIZD.js.map +1 -1
- package/dist/_shared/lib-4PES5P4V.js +59 -14
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +1706 -258
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +317 -64
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js.map +1 -1
- package/dist/_shared/{mode-shared-HP7GUA7J.js → mode-shared-2QJSCUM6.js} +432 -81
- package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -0
- package/dist/_shared/p0-cli-BB45ZQY6.js +3482 -0
- package/dist/_shared/p0-cli-BB45ZQY6.js.map +1 -0
- package/dist/_shared/p0-cli-GUFK7TPN.js +2 -2838
- package/dist/_shared/p0-cli-GUFK7TPN.js.map +1 -1
- package/dist/_shared/{p1a-prewarm-YK3KDTLN.js → p1a-prewarm-UQY3X2UK.js} +270 -73
- package/dist/_shared/p1a-prewarm-UQY3X2UK.js.map +1 -0
- package/dist/_shared/{p1b-elig-PXQA2FYP.js → p1b-elig-ENCUPKKJ.js} +190 -121
- package/dist/_shared/p1b-elig-ENCUPKKJ.js.map +1 -0
- package/dist/_shared/p2-common-YLSYXMDQ.js +1 -3
- package/dist/_shared/p2-common-YLSYXMDQ.js.map +1 -1
- package/dist/_shared/p2-shell-TJBYQMCJ.js +1 -1
- package/dist/_shared/p2-shell-main-B2WIALFD.js +500 -127
- package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +4 -4
- package/dist/_shared/sdk-WQIOHVKO.js +56 -11
- package/dist/_shared/session-data-AHTU7IS6.js +48 -3
- package/dist/_shared/session-manager-list-2BLEEZVG.js +2 -2
- package/dist/_shared/settings-startup-65YEWRV2.js.map +1 -1
- package/dist/_shared/sql-session-store-5FD3WBMZ.js +57 -12
- package/dist/_shared/{startup-0-0-X4NF3GKM.js → startup-0-0-TYUFUOJZ.js} +528 -321
- package/dist/_shared/startup-0-0-TYUFUOJZ.js.map +1 -0
- package/dist/_shared/{startup-0-1-7QTG6VJZ.js → startup-0-1-D4LGGINF.js} +284 -81
- package/dist/_shared/startup-0-1-D4LGGINF.js.map +1 -0
- package/dist/_shared/{startup-0-2-KFDYPDJK.js → startup-0-2-SZGQIWHI.js} +483 -154
- package/dist/_shared/startup-0-2-SZGQIWHI.js.map +1 -0
- package/dist/_shared/startup-0-3-T4DVFYWX.js +340 -110
- package/dist/_shared/startup-0-3-T4DVFYWX.js.map +1 -1
- package/dist/_shared/startup-0-4-HN5EB4K7.js +261 -59
- package/dist/_shared/startup-0-4-HN5EB4K7.js.map +1 -1
- package/dist/_shared/startup-0-5-OHJNE6JH.js +421 -148
- package/dist/_shared/startup-0-5-OHJNE6JH.js.map +1 -1
- package/dist/_shared/startup-10-0-TDQNBDDL.js +62 -11
- package/dist/_shared/startup-10-0-TDQNBDDL.js.map +1 -1
- package/dist/_shared/startup-12-0-55AAXBJZ.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +12 -11
- package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +53 -158
- package/dist/_shared/startup-15-0-YUKGAC63.js.map +1 -1
- package/dist/_shared/startup-15-1-4S7FLMNG.js +231 -46
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +115 -35
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/{startup-8-1-KQJBDKRU.js → startup-8-1-SJW2GMAM.js} +203 -62
- package/dist/_shared/startup-8-1-SJW2GMAM.js.map +1 -0
- package/dist/_shared/storage-command-7MGXLJGZ.js +55 -10
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +47 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +48 -3
- package/dist/builtin/intercom/CHANGELOG.md +59 -0
- package/dist/builtin/intercom/README.md +0 -1
- package/dist/builtin/intercom/broker/broker-instance.ts +13 -57
- package/dist/builtin/intercom/broker/broker-process.ts +30 -10
- package/dist/builtin/intercom/broker/broker-routing.ts +12 -2
- package/dist/builtin/intercom/broker/broker.bundle.mjs +2557 -498
- package/dist/builtin/intercom/broker/broker.ts +164 -55
- package/dist/builtin/intercom/broker/client.ts +36 -16
- package/dist/builtin/intercom/broker/control.ts +83 -20
- package/dist/builtin/intercom/broker/durable-ended-queue.ts +65 -19
- package/dist/builtin/intercom/broker/host-command-environment.ts +7 -2
- package/dist/builtin/intercom/broker/multinode-router.ts +1675 -387
- package/dist/builtin/intercom/broker/multinode-state-store.ts +10 -0
- package/dist/builtin/intercom/broker/paths.ts +68 -6
- package/dist/builtin/intercom/broker/pending-send-registry.ts +5 -0
- package/dist/builtin/intercom/broker/registration-bounds.ts +38 -0
- package/dist/builtin/intercom/broker/retiring-broker-check.ts +178 -0
- package/dist/builtin/intercom/broker/return-paths.ts +268 -7
- package/dist/builtin/intercom/broker/send-handler.ts +253 -28
- package/dist/builtin/intercom/broker/send-order-gate.ts +410 -0
- package/dist/builtin/intercom/broker/spawn.ts +950 -202
- package/dist/builtin/intercom/broker/sql-lease-store.ts +37 -0
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +7 -0
- package/dist/builtin/intercom/broker/windows-cwd.ts +546 -0
- package/dist/builtin/intercom/index.bundle.mjs +3506 -2328
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/intercom/retry-policy.ts +4 -0
- package/dist/builtin/intercom/types.ts +2 -0
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +46 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +336 -86
- package/dist/builtin/web-access/CHANGELOG.md +12 -0
- package/dist/builtin/web-access/index.bundle.mjs +23 -38
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/bun/cli.js +1 -1
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/internal-intercom-broker.js +119 -4
- package/dist/bun/internal-intercom-broker.js.map +1 -1
- package/dist/bun/register-theme-validator.js +6 -0
- package/dist/bun/register-theme-validator.js.map +1 -0
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +1102 -0
- package/dist/cli/auth-cli.code.js.map +1 -0
- package/dist/cli/auth-cli.impl.js +36 -0
- package/dist/cli/auth-cli.impl.js.map +1 -0
- package/dist/cli/auth-cli.js +30 -1096
- package/dist/cli/auth-cli.js.map +1 -1
- package/dist/cli/blueprint-command.code.js +906 -0
- package/dist/cli/blueprint-command.code.js.map +1 -0
- package/dist/cli/blueprint-command.impl.js +36 -0
- package/dist/cli/blueprint-command.impl.js.map +1 -0
- package/dist/cli/blueprint-command.js +30 -900
- package/dist/cli/blueprint-command.js.map +1 -1
- package/dist/cli/intercom-command.code.js +153 -0
- package/dist/cli/intercom-command.code.js.map +1 -0
- package/dist/cli/intercom-command.impl.js +36 -0
- package/dist/cli/intercom-command.impl.js.map +1 -0
- package/dist/cli/intercom-command.js +33 -105
- package/dist/cli/intercom-command.js.map +1 -1
- package/dist/cli/list-models.code.js +60 -0
- package/dist/cli/list-models.code.js.map +1 -0
- package/dist/cli/list-models.impl.js +36 -0
- package/dist/cli/list-models.impl.js.map +1 -0
- package/dist/cli/list-models.js +33 -57
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/session-picker.code.js +55 -0
- package/dist/cli/session-picker.code.js.map +1 -0
- package/dist/cli/session-picker.impl.js +36 -0
- package/dist/cli/session-picker.impl.js.map +1 -0
- package/dist/cli/session-picker.js +33 -52
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli/startup-ui.code.js +5 -0
- package/dist/cli/startup-ui.code.js.map +1 -0
- package/dist/cli/startup-ui.impl.js +36 -0
- package/dist/cli/startup-ui.impl.js.map +1 -0
- package/dist/cli/startup-ui.js +35 -4
- package/dist/cli/storage-command.code.js +3 -0
- package/dist/cli/storage-command.code.js.map +1 -0
- package/dist/cli/storage-command.impl.js +36 -0
- package/dist/cli/storage-command.impl.js.map +1 -0
- package/dist/cli/storage-command.js +35 -2
- package/dist/cli/storage-search-session.code.js +189 -0
- package/dist/cli/storage-search-session.code.js.map +1 -0
- package/dist/cli/storage-search-session.impl.js +36 -0
- package/dist/cli/storage-search-session.impl.js.map +1 -0
- package/dist/cli/storage-search-session.js +33 -186
- package/dist/cli/storage-search-session.js.map +1 -1
- package/dist/cli/team-command.code.js +217 -0
- package/dist/cli/team-command.code.js.map +1 -0
- package/dist/cli/team-command.impl.js +36 -0
- package/dist/cli/team-command.impl.js.map +1 -0
- package/dist/cli/team-command.js +32 -213
- package/dist/cli/team-command.js.map +1 -1
- package/dist/cli.js +60 -11
- package/dist/cli.js.map +1 -1
- package/dist/config.js +1 -1
- package/dist/core/agent-session-methods.d.ts +4 -3
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +5 -0
- package/dist/core/compaction/compaction.d.ts +6 -0
- package/dist/core/compaction/model-resolver.d.ts +1 -1
- package/dist/core/debug.code.js +3 -0
- package/dist/core/debug.code.js.map +1 -0
- package/dist/core/debug.impl.js +36 -0
- package/dist/core/debug.impl.js.map +1 -0
- package/dist/core/debug.js +35 -2
- package/dist/core/default-model-api-prewarm.d.ts +5 -0
- package/dist/core/export-html/card-projection.code.js +257 -0
- package/dist/core/export-html/card-projection.code.js.map +1 -0
- package/dist/core/export-html/card-projection.impl.js +36 -0
- package/dist/core/export-html/card-projection.impl.js.map +1 -0
- package/dist/core/export-html/card-projection.js +34 -255
- package/dist/core/export-html/card-projection.js.map +1 -1
- package/dist/core/export-html/index.code.js +655 -0
- package/dist/core/export-html/index.code.js.map +1 -0
- package/dist/core/export-html/index.impl.js +36 -0
- package/dist/core/export-html/index.impl.js.map +1 -0
- package/dist/core/export-html/index.js +30 -604
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/json-spans.code.js +3 -0
- package/dist/core/export-html/json-spans.code.js.map +1 -0
- package/dist/core/export-html/json-spans.impl.js +36 -0
- package/dist/core/export-html/json-spans.impl.js.map +1 -0
- package/dist/core/export-html/json-spans.js +35 -2
- package/dist/core/export-html/oversized-render-inputs.code.js +125 -0
- package/dist/core/export-html/oversized-render-inputs.code.js.map +1 -0
- package/dist/core/export-html/oversized-render-inputs.impl.js +36 -0
- package/dist/core/export-html/oversized-render-inputs.impl.js.map +1 -0
- package/dist/core/export-html/oversized-render-inputs.js +31 -120
- package/dist/core/export-html/oversized-render-inputs.js.map +1 -1
- package/dist/core/export-html/tool-renderer.code.js +350 -0
- package/dist/core/export-html/tool-renderer.code.js.map +1 -0
- package/dist/core/export-html/tool-renderer.impl.js +36 -0
- package/dist/core/export-html/tool-renderer.impl.js.map +1 -0
- package/dist/core/export-html/tool-renderer.js +33 -347
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/jiti-loader.code.js +3 -0
- package/dist/core/extensions/jiti-loader.code.js.map +1 -0
- package/dist/core/extensions/jiti-loader.impl.js +36 -0
- package/dist/core/extensions/jiti-loader.impl.js.map +1 -0
- package/dist/core/extensions/jiti-loader.js +35 -2
- package/dist/core/extensions/jiti-static-loader.code.js +3 -0
- package/dist/core/extensions/jiti-static-loader.code.js.map +1 -0
- package/dist/core/extensions/jiti-static-loader.impl.js +36 -0
- package/dist/core/extensions/jiti-static-loader.impl.js.map +1 -0
- package/dist/core/extensions/jiti-static-loader.js +35 -2
- package/dist/core/extensions/loader-host-modules.code.js +3 -0
- package/dist/core/extensions/loader-host-modules.code.js.map +1 -0
- package/dist/core/extensions/loader-host-modules.impl.js +36 -0
- package/dist/core/extensions/loader-host-modules.impl.js.map +1 -0
- package/dist/core/extensions/loader-host-modules.js +35 -2
- package/dist/core/extensions/loader-virtual-modules.d.ts +1 -6
- package/dist/core/extensions/loader-virtual-modules.js +1 -1
- package/dist/core/extensions/runner-context.js +3 -3
- package/dist/core/extensions/session-events.d.ts +4 -0
- package/dist/core/extensions/session-events.js.map +1 -1
- package/dist/core/intercom-broker-control-host.code.js +5 -0
- package/dist/core/intercom-broker-control-host.code.js.map +1 -0
- package/dist/core/intercom-broker-control-host.impl.js +36 -0
- package/dist/core/intercom-broker-control-host.impl.js.map +1 -0
- package/dist/core/intercom-broker-control-host.js +35 -4
- package/dist/core/intercom-broker-control.code.js +63 -0
- package/dist/core/intercom-broker-control.code.js.map +1 -0
- package/dist/core/intercom-broker-control.d.ts +21 -0
- package/dist/core/intercom-broker-control.impl.js +36 -0
- package/dist/core/intercom-broker-control.impl.js.map +1 -0
- package/dist/core/intercom-broker-control.js +35 -17
- package/dist/core/intercom-broker-control.js.map +1 -1
- package/dist/core/package-manager-storage-adapters.code.js +3 -0
- package/dist/core/package-manager-storage-adapters.code.js.map +1 -0
- package/dist/core/package-manager-storage-adapters.impl.js +36 -0
- package/dist/core/package-manager-storage-adapters.impl.js.map +1 -0
- package/dist/core/package-manager-storage-adapters.js +35 -2
- package/dist/core/process-start-token.d.ts +8 -2
- package/dist/core/process-tree-containment.d.ts +27 -0
- package/dist/core/queued-message-delivery.d.ts +5 -2
- package/dist/core/resume/blueprint/process.d.ts +3 -1
- package/dist/core/sdk.code.js +9 -0
- package/dist/core/sdk.code.js.map +1 -0
- package/dist/core/sdk.impl.js +36 -0
- package/dist/core/sdk.impl.js.map +1 -0
- package/dist/core/sdk.js +35 -8
- package/dist/core/session-manager-core.d.ts +15 -5
- package/dist/core/session-manager-core.js +195 -38
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-list.code.js +3 -0
- package/dist/core/session-manager-list.code.js.map +1 -0
- package/dist/core/session-manager-list.impl.js +36 -0
- package/dist/core/session-manager-list.impl.js.map +1 -0
- package/dist/core/session-manager-list.js +35 -2
- package/dist/core/session-manager-types.d.ts +20 -0
- package/dist/core/session-manager.code.js +8 -0
- package/dist/core/session-manager.code.js.map +1 -0
- package/dist/core/session-manager.d.ts +1 -1
- package/dist/core/session-manager.impl.js +36 -0
- package/dist/core/session-manager.impl.js.map +1 -0
- package/dist/core/session-manager.js +35 -7
- package/dist/core/session-storage.code.js +3 -0
- package/dist/core/session-storage.code.js.map +1 -0
- package/dist/core/session-storage.impl.js +36 -0
- package/dist/core/session-storage.impl.js.map +1 -0
- package/dist/core/session-storage.js +35 -2
- package/dist/core/storage/file-identity.d.ts +3 -0
- package/dist/core/storage/file-identity.js +296 -86
- package/dist/core/storage/file-identity.js.map +1 -1
- package/dist/core/storage/index.d.ts +1 -1
- package/dist/core/storage/index.js +52 -7
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +47 -2
- package/dist/core/storage/node-sqlite.js +49 -4
- package/dist/core/storage/node-sqlite.js.map +1 -1
- package/dist/core/storage/offline-snapshot-file.code.js +37 -0
- package/dist/core/storage/offline-snapshot-file.code.js.map +1 -0
- package/dist/core/storage/offline-snapshot-file.impl.js +36 -0
- package/dist/core/storage/offline-snapshot-file.impl.js.map +1 -0
- package/dist/core/storage/offline-snapshot-file.js +33 -34
- package/dist/core/storage/offline-snapshot-file.js.map +1 -1
- package/dist/core/storage/provider.js +52 -7
- package/dist/core/storage/selection.js +49 -4
- package/dist/core/storage/session/branch-fork-source.code.js +146 -0
- package/dist/core/storage/session/branch-fork-source.code.js.map +1 -0
- package/dist/core/storage/session/branch-fork-source.impl.js +36 -0
- package/dist/core/storage/session/branch-fork-source.impl.js.map +1 -0
- package/dist/core/storage/session/branch-fork-source.js +32 -97
- package/dist/core/storage/session/branch-fork-source.js.map +1 -1
- package/dist/core/storage/session/card-view.code.js +60 -0
- package/dist/core/storage/session/card-view.code.js.map +1 -0
- package/dist/core/storage/session/card-view.impl.js +36 -0
- package/dist/core/storage/session/card-view.impl.js.map +1 -0
- package/dist/core/storage/session/card-view.js +34 -58
- package/dist/core/storage/session/card-view.js.map +1 -1
- package/dist/core/storage/session/child-reader.code.js +139 -0
- package/dist/core/storage/session/child-reader.code.js.map +1 -0
- package/dist/core/storage/session/child-reader.d.ts +1 -0
- package/dist/core/storage/session/child-reader.impl.js +36 -0
- package/dist/core/storage/session/child-reader.impl.js.map +1 -0
- package/dist/core/storage/session/child-reader.js +33 -91
- package/dist/core/storage/session/child-reader.js.map +1 -1
- package/dist/core/storage/session/chunked-resume-projection.code.js +3 -0
- package/dist/core/storage/session/chunked-resume-projection.code.js.map +1 -0
- package/dist/core/storage/session/chunked-resume-projection.impl.js +36 -0
- package/dist/core/storage/session/chunked-resume-projection.impl.js.map +1 -0
- package/dist/core/storage/session/chunked-resume-projection.js +35 -2
- package/dist/core/storage/session/expanded-child-details.code.js +684 -0
- package/dist/core/storage/session/expanded-child-details.code.js.map +1 -0
- package/dist/core/storage/session/expanded-child-details.impl.js +36 -0
- package/dist/core/storage/session/expanded-child-details.impl.js.map +1 -0
- package/dist/core/storage/session/expanded-child-details.js +31 -634
- package/dist/core/storage/session/expanded-child-details.js.map +1 -1
- package/dist/core/storage/session/fork-row-bytes.code.js +3 -0
- package/dist/core/storage/session/fork-row-bytes.code.js.map +1 -0
- package/dist/core/storage/session/fork-row-bytes.impl.js +36 -0
- package/dist/core/storage/session/fork-row-bytes.impl.js.map +1 -0
- package/dist/core/storage/session/fork-row-bytes.js +35 -2
- package/dist/core/storage/session/fork-row-index.code.js +3 -0
- package/dist/core/storage/session/fork-row-index.code.js.map +1 -0
- package/dist/core/storage/session/fork-row-index.impl.js +36 -0
- package/dist/core/storage/session/fork-row-index.impl.js.map +1 -0
- package/dist/core/storage/session/fork-row-index.js +35 -2
- package/dist/core/storage/session/fork-staging.code.js +580 -0
- package/dist/core/storage/session/fork-staging.code.js.map +1 -0
- package/dist/core/storage/session/fork-staging.impl.js +36 -0
- package/dist/core/storage/session/fork-staging.impl.js.map +1 -0
- package/dist/core/storage/session/fork-staging.js +30 -574
- package/dist/core/storage/session/fork-staging.js.map +1 -1
- package/dist/core/storage/session/fork-window.code.js +522 -0
- package/dist/core/storage/session/fork-window.code.js.map +1 -0
- package/dist/core/storage/session/fork-window.impl.js +36 -0
- package/dist/core/storage/session/fork-window.impl.js.map +1 -0
- package/dist/core/storage/session/fork-window.js +30 -471
- package/dist/core/storage/session/fork-window.js.map +1 -1
- package/dist/core/storage/session/history-pages.code.js +3 -0
- package/dist/core/storage/session/history-pages.code.js.map +1 -0
- package/dist/core/storage/session/history-pages.impl.js +36 -0
- package/dist/core/storage/session/history-pages.impl.js.map +1 -0
- package/dist/core/storage/session/history-pages.js +35 -2
- package/dist/core/storage/session/jsonl-entry-projection.code.js +3 -0
- package/dist/core/storage/session/jsonl-entry-projection.code.js.map +1 -0
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +36 -0
- package/dist/core/storage/session/jsonl-entry-projection.impl.js.map +1 -0
- package/dist/core/storage/session/jsonl-entry-projection.js +35 -2
- package/dist/core/storage/session/jsonl-session-store.code.js +3 -0
- package/dist/core/storage/session/jsonl-session-store.code.js.map +1 -0
- package/dist/core/storage/session/jsonl-session-store.impl.js +36 -0
- package/dist/core/storage/session/jsonl-session-store.impl.js.map +1 -0
- package/dist/core/storage/session/jsonl-session-store.js +35 -2
- package/dist/core/storage/session/memory-session-store.code.js +3 -0
- package/dist/core/storage/session/memory-session-store.code.js.map +1 -0
- package/dist/core/storage/session/memory-session-store.impl.js +36 -0
- package/dist/core/storage/session/memory-session-store.impl.js.map +1 -0
- package/dist/core/storage/session/memory-session-store.js +35 -2
- package/dist/core/storage/session/pinned-branch-resume.code.js +117 -0
- package/dist/core/storage/session/pinned-branch-resume.code.js.map +1 -0
- package/dist/core/storage/session/pinned-branch-resume.impl.js +36 -0
- package/dist/core/storage/session/pinned-branch-resume.impl.js.map +1 -0
- package/dist/core/storage/session/pinned-branch-resume.js +33 -69
- package/dist/core/storage/session/pinned-branch-resume.js.map +1 -1
- package/dist/core/storage/session/released-history-files.code.js +465 -0
- package/dist/core/storage/session/released-history-files.code.js.map +1 -0
- package/dist/core/storage/session/released-history-files.impl.js +36 -0
- package/dist/core/storage/session/released-history-files.impl.js.map +1 -0
- package/dist/core/storage/session/released-history-files.js +32 -461
- package/dist/core/storage/session/released-history-files.js.map +1 -1
- package/dist/core/storage/session/resident-fork-rows.code.js +57 -0
- package/dist/core/storage/session/resident-fork-rows.code.js.map +1 -0
- package/dist/core/storage/session/resident-fork-rows.impl.js +36 -0
- package/dist/core/storage/session/resident-fork-rows.impl.js.map +1 -0
- package/dist/core/storage/session/resident-fork-rows.js +32 -53
- package/dist/core/storage/session/resident-fork-rows.js.map +1 -1
- package/dist/core/storage/session/session-resume.code.js +3 -0
- package/dist/core/storage/session/session-resume.code.js.map +1 -0
- package/dist/core/storage/session/session-resume.impl.js +36 -0
- package/dist/core/storage/session/session-resume.impl.js.map +1 -0
- package/dist/core/storage/session/session-resume.js +35 -2
- package/dist/core/storage/session/snapshot-cut.code.js +3 -0
- package/dist/core/storage/session/snapshot-cut.code.js.map +1 -0
- package/dist/core/storage/session/snapshot-cut.impl.js +36 -0
- package/dist/core/storage/session/snapshot-cut.impl.js.map +1 -0
- package/dist/core/storage/session/snapshot-cut.js +35 -2
- package/dist/core/storage/session/snapshot-history.code.js +107 -0
- package/dist/core/storage/session/snapshot-history.code.js.map +1 -0
- package/dist/core/storage/session/snapshot-history.impl.js +36 -0
- package/dist/core/storage/session/snapshot-history.impl.js.map +1 -0
- package/dist/core/storage/session/snapshot-history.js +34 -60
- package/dist/core/storage/session/snapshot-history.js.map +1 -1
- package/dist/core/storage/session/sql-session-store.code.js +3 -0
- package/dist/core/storage/session/sql-session-store.code.js.map +1 -0
- package/dist/core/storage/session/sql-session-store.impl.js +36 -0
- package/dist/core/storage/session/sql-session-store.impl.js.map +1 -0
- package/dist/core/storage/session/sql-session-store.js +35 -2
- package/dist/core/storage/session/tree-outline.code.js +3 -0
- package/dist/core/storage/session/tree-outline.code.js.map +1 -0
- package/dist/core/storage/session/tree-outline.impl.js +36 -0
- package/dist/core/storage/session/tree-outline.impl.js.map +1 -0
- package/dist/core/storage/session/tree-outline.js +35 -2
- package/dist/core/storage/session/tree-presentation.code.js +342 -0
- package/dist/core/storage/session/tree-presentation.code.js.map +1 -0
- package/dist/core/storage/session/tree-presentation.impl.js +36 -0
- package/dist/core/storage/session/tree-presentation.impl.js.map +1 -0
- package/dist/core/storage/session/tree-presentation.js +31 -337
- package/dist/core/storage/session/tree-presentation.js.map +1 -1
- package/dist/core/storage/session/types.d.ts +26 -0
- package/dist/core/storage/storage-status.code.js +3 -0
- package/dist/core/storage/storage-status.code.js.map +1 -0
- package/dist/core/storage/storage-status.impl.js +36 -0
- package/dist/core/storage/storage-status.impl.js.map +1 -0
- package/dist/core/storage/storage-status.js +35 -2
- package/dist/core/storage/team.code.js +3 -0
- package/dist/core/storage/team.code.js.map +1 -0
- package/dist/core/storage/team.impl.js +36 -0
- package/dist/core/storage/team.impl.js.map +1 -0
- package/dist/core/storage/team.js +35 -2
- package/dist/core/structured-output/index.code.js +3 -0
- package/dist/core/structured-output/index.code.js.map +1 -0
- package/dist/core/structured-output/index.impl.js +36 -0
- package/dist/core/structured-output/index.impl.js.map +1 -0
- package/dist/core/structured-output/index.js +35 -2
- package/dist/core/tasks/command-output.d.ts +4 -1
- package/dist/core/tasks/supervisor.d.ts +2 -0
- package/dist/core/tasks/task-completion-entry.code.js +254 -0
- package/dist/core/tasks/task-completion-entry.code.js.map +1 -0
- package/dist/core/tasks/task-completion-entry.impl.js +36 -0
- package/dist/core/tasks/task-completion-entry.impl.js.map +1 -0
- package/dist/core/tasks/task-completion-entry.js +33 -251
- package/dist/core/tasks/task-completion-entry.js.map +1 -1
- package/dist/core/tasks/task-file-history.code.js +424 -0
- package/dist/core/tasks/task-file-history.code.js.map +1 -0
- package/dist/core/tasks/task-file-history.impl.js +36 -0
- package/dist/core/tasks/task-file-history.impl.js.map +1 -0
- package/dist/core/tasks/task-file-history.js +32 -375
- package/dist/core/tasks/task-file-history.js.map +1 -1
- package/dist/core/tasks/task-reference-archive.code.js +514 -0
- package/dist/core/tasks/task-reference-archive.code.js.map +1 -0
- package/dist/core/tasks/task-reference-archive.js +34 -467
- package/dist/core/tasks/task-reference-archive.js.map +1 -1
- package/dist/core/tasks/task-reference-identity.code.js +164 -0
- package/dist/core/tasks/task-reference-identity.code.js.map +1 -0
- package/dist/core/tasks/task-reference-identity.js +32 -160
- package/dist/core/tasks/task-reference-identity.js.map +1 -1
- package/dist/core/tasks/task-reference-stream.code.js +3 -0
- package/dist/core/tasks/task-reference-stream.code.js.map +1 -0
- package/dist/core/tasks/task-reference-stream.impl.js +36 -0
- package/dist/core/tasks/task-reference-stream.impl.js.map +1 -0
- package/dist/core/tasks/task-reference-stream.js +35 -2
- package/dist/core/tasks/task-unsaved-answer.code.js +3 -0
- package/dist/core/tasks/task-unsaved-answer.code.js.map +1 -0
- package/dist/core/tasks/task-unsaved-answer.impl.js +36 -0
- package/dist/core/tasks/task-unsaved-answer.impl.js.map +1 -0
- package/dist/core/tasks/task-unsaved-answer.js +35 -2
- package/dist/core/tasks/task-view-source.code.js +3 -0
- package/dist/core/tasks/task-view-source.code.js.map +1 -0
- package/dist/core/tasks/task-view-source.d.ts +9 -0
- package/dist/core/tasks/task-view-source.impl.js +36 -0
- package/dist/core/tasks/task-view-source.impl.js.map +1 -0
- package/dist/core/tasks/task-view-source.js +35 -2
- package/dist/core/tools/read-url.code.js +1530 -0
- package/dist/core/tools/read-url.code.js.map +1 -0
- package/dist/core/tools/read-url.impl.js +36 -0
- package/dist/core/tools/read-url.impl.js.map +1 -0
- package/dist/core/tools/read-url.js +30 -1524
- package/dist/core/tools/read-url.js.map +1 -1
- package/dist/core/worktree-snapshot/blob-store.js +50 -5
- package/dist/core/worktree-snapshot/errors.code.js +6 -0
- package/dist/core/worktree-snapshot/errors.code.js.map +1 -0
- package/dist/core/worktree-snapshot/errors.impl.js +36 -0
- package/dist/core/worktree-snapshot/errors.impl.js.map +1 -0
- package/dist/core/worktree-snapshot/errors.js +35 -5
- package/dist/core/worktree-snapshot/session-index-reset.code.js +136 -0
- package/dist/core/worktree-snapshot/session-index-reset.code.js.map +1 -0
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +36 -0
- package/dist/core/worktree-snapshot/session-index-reset.impl.js.map +1 -0
- package/dist/core/worktree-snapshot/session-index-reset.js +34 -134
- package/dist/core/worktree-snapshot/session-index-reset.js.map +1 -1
- package/dist/extensions/codemode/execute.code.js +618 -0
- package/dist/extensions/codemode/execute.code.js.map +1 -0
- package/dist/extensions/codemode/execute.impl.js +36 -0
- package/dist/extensions/codemode/execute.impl.js.map +1 -0
- package/dist/extensions/codemode/execute.js +30 -612
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/renderer.code.js +110 -0
- package/dist/extensions/codemode/renderer.code.js.map +1 -0
- package/dist/extensions/codemode/renderer.impl.js +36 -0
- package/dist/extensions/codemode/renderer.impl.js.map +1 -0
- package/dist/extensions/codemode/renderer.js +33 -107
- package/dist/extensions/codemode/renderer.js.map +1 -1
- package/dist/extensions/mcp/cli.code.js +565 -0
- package/dist/extensions/mcp/cli.code.js.map +1 -0
- package/dist/extensions/mcp/cli.impl.js +36 -0
- package/dist/extensions/mcp/cli.impl.js.map +1 -0
- package/dist/extensions/mcp/cli.js +32 -561
- package/dist/extensions/mcp/cli.js.map +1 -1
- package/dist/extensions/mcp/cli.lazy.code.js +52 -0
- package/dist/extensions/mcp/cli.lazy.code.js.map +1 -0
- package/dist/extensions/mcp/cli.lazy.impl.js +36 -0
- package/dist/extensions/mcp/cli.lazy.impl.js.map +1 -0
- package/dist/extensions/mcp/cli.lazy.js +36 -7
- package/dist/extensions/mcp/cli.lazy.js.map +1 -1
- package/dist/extensions/mcp/client/transports/stdio.d.ts +2 -0
- package/dist/extensions/mcp/runtime.code.js +5 -0
- package/dist/extensions/mcp/runtime.code.js.map +1 -0
- package/dist/extensions/mcp/runtime.impl.js +36 -0
- package/dist/extensions/mcp/runtime.impl.js.map +1 -0
- package/dist/extensions/mcp/runtime.js +35 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -8
- package/dist/main-first-time-setup.code.js +12 -0
- package/dist/main-first-time-setup.code.js.map +1 -0
- package/dist/main-first-time-setup.impl.js +36 -0
- package/dist/main-first-time-setup.impl.js.map +1 -0
- package/dist/main-first-time-setup.js +35 -11
- package/dist/main-first-time-setup.js.map +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.js +2 -2
- package/dist/modes/interactive/agent-view/agent-view-switcher.d.ts +6 -1
- package/dist/modes/interactive/agent-view/contracts.d.ts +4 -0
- package/dist/modes/interactive/chat-reader-records.d.ts +1 -1
- package/dist/modes/interactive/components/stored-tree-view.code.js +338 -0
- package/dist/modes/interactive/components/stored-tree-view.code.js.map +1 -0
- package/dist/modes/interactive/components/stored-tree-view.impl.js +36 -0
- package/dist/modes/interactive/components/stored-tree-view.impl.js.map +1 -0
- package/dist/modes/interactive/components/stored-tree-view.js +33 -290
- package/dist/modes/interactive/components/stored-tree-view.js.map +1 -1
- package/dist/modes/interactive/components/task-selection-state.d.ts +8 -3
- package/dist/modes/interactive/components/task-transcript-page.d.ts +1 -0
- package/dist/modes/interactive/components/user-message-selector-archive.code.js +191 -0
- package/dist/modes/interactive/components/user-message-selector-archive.code.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +36 -0
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector-archive.js +34 -189
- package/dist/modes/interactive/components/user-message-selector-archive.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +6 -0
- package/dist/modes/interactive/interactive-mode-deps.js +4 -0
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +1 -1
- package/dist/modes/interactive/interactive-queueing.d.ts +4 -0
- package/dist/modes/interactive/interactive-render-chat.d.ts +22 -0
- package/dist/modes/interactive/interactive-startup.d.ts +2 -0
- package/dist/modes/interactive/program-status-reporter.d.ts +2 -1
- package/dist/modes/interactive/startup-shell-eligibility.js +1 -1
- package/dist/modes/interactive/steering-queue-controller.d.ts +4 -0
- package/dist/modes/interactive/theme/theme-schema-factory.d.ts +26 -0
- package/dist/modes/interactive/theme/theme-schema.d.ts +4 -5
- package/dist/modes/interactive-engine/engine-prewarm.d.ts +30 -5
- package/dist/modes/interactive-engine/engine-prewarm.js +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +7 -0
- package/dist/modes/interactive-engine/protocol.d.ts +32 -1
- package/dist/modes/rpc/agent-view-rpc-types.d.ts +12 -1
- package/dist/modes/rpc/agent-view-rpc-types.js.map +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +3 -1
- package/dist/modes/rpc/rpc-types.d.ts +12 -0
- package/dist/package-manager-cli.code.js +1140 -0
- package/dist/package-manager-cli.code.js.map +1 -0
- package/dist/package-manager-cli.impl.js +36 -0
- package/dist/package-manager-cli.impl.js.map +1 -0
- package/dist/package-manager-cli.js +36 -1067
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/rpc-entry.js +2 -2
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/10.js +1 -1
- package/dist/startup-stages/11.js +1 -1
- package/dist/startup-stages/12.js +1 -1
- package/dist/startup-stages/13.js +1 -0
- package/dist/startup-stages/2.js +1 -7
- package/dist/startup-stages/3.js +6 -2
- package/dist/startup-stages/4.js +2 -1
- package/dist/startup-stages/5.js +1 -7
- package/dist/startup-stages/6.js +7 -10
- package/dist/startup-stages/7.js +10 -3
- package/dist/startup-stages/8.js +3 -6
- package/dist/startup-stages/9.js +6 -1
- package/dist/startup-stages/stages.json +1 -1
- package/dist/utils/canonical-path.js +2 -0
- package/dist/utils/canonical-path.js.map +1 -1
- package/dist/utils/child-process.d.ts +41 -1
- package/dist/utils/compile-cache-warmup-host.js +63 -18
- package/dist/utils/compile-cache-warmup-host.js.map +1 -1
- package/dist/utils/credential-redaction.d.ts +50 -1
- package/dist/utils/interactive-engine-bootstrap.d.ts +2 -0
- package/dist/utils/interactive-engine-env.d.ts +2 -0
- package/dist/utils/memoize-async.d.ts +32 -0
- package/dist/utils/memoize-async.js +91 -0
- package/dist/utils/memoize-async.js.map +1 -0
- package/dist/utils/photon.js +19 -29
- package/dist/utils/photon.js.map +1 -1
- package/dist/utils/shell.d.ts +7 -4
- package/dist/utils/startup-database-spare.code.js +108 -0
- package/dist/utils/startup-database-spare.code.js.map +1 -0
- package/dist/utils/startup-database-spare.impl.js +36 -0
- package/dist/utils/startup-database-spare.impl.js.map +1 -0
- package/dist/utils/startup-database-spare.js +33 -105
- package/dist/utils/startup-database-spare.js.map +1 -1
- package/dist/utils/tools-manager.code.js +3 -0
- package/dist/utils/tools-manager.code.js.map +1 -0
- package/dist/utils/tools-manager.impl.js +36 -0
- package/dist/utils/tools-manager.impl.js.map +1 -0
- package/dist/utils/tools-manager.js +35 -2
- package/dist/utils/windows-cwd.js +585 -0
- package/dist/utils/windows-cwd.js.map +1 -0
- package/docs/extensions.md +1 -1
- package/docs/getting-started/installation.md +2 -0
- package/docs/intercom/operations.md +1 -0
- package/docs/reference/cli.md +2 -2
- package/package.json +24 -24
- package/dist/_shared/mode-shared-HP7GUA7J.js.map +0 -1
- package/dist/_shared/p1a-prewarm-YK3KDTLN.js.map +0 -1
- package/dist/_shared/p1b-elig-PXQA2FYP.js.map +0 -1
- package/dist/_shared/startup-0-0-X4NF3GKM.js.map +0 -1
- package/dist/_shared/startup-0-1-7QTG6VJZ.js.map +0 -1
- package/dist/_shared/startup-0-2-KFDYPDJK.js.map +0 -1
- package/dist/_shared/startup-8-1-KQJBDKRU.js.map +0 -1
package/dist/cli/auth-cli.js
CHANGED
|
@@ -1,1102 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
var AuthCommandError = class extends Error {
|
|
20
|
-
exitCode;
|
|
21
|
-
constructor(message, exitCode = 1) {
|
|
22
|
-
super(message);
|
|
23
|
-
this.exitCode = exitCode;
|
|
24
|
-
this.name = "AuthCommandError";
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const AUTH_COMMAND_USAGE = {
|
|
28
|
-
check: `${APP_NAME} auth check [--provider <provider>] [--model <model>] [--json] [--credentials] [--no-refresh]`,
|
|
29
|
-
api_key: `${APP_NAME} auth print-api-key --model <model> [--provider <provider>]`,
|
|
30
|
-
bearer_token: `${APP_NAME} auth print-bearer-token --model <model> [--provider <provider>] [--min-expiry <duration>]`
|
|
31
|
-
};
|
|
32
|
-
function getAuthCommandName(kind) {
|
|
33
|
-
return kind === "check" ? "auth check" : kind === "api_key" ? "auth print-api-key" : "auth print-bearer-token";
|
|
34
|
-
}
|
|
35
|
-
function getAuthCommandUsage(kind) {
|
|
36
|
-
return AUTH_COMMAND_USAGE[kind];
|
|
37
|
-
}
|
|
38
|
-
const AUTH_HELP_SUBCOMMANDS = /* @__PURE__ */ new Set([
|
|
39
|
-
"login",
|
|
40
|
-
"logout",
|
|
41
|
-
"print-api-key",
|
|
42
|
-
"print-bearer-token",
|
|
43
|
-
"check"
|
|
44
|
-
]);
|
|
45
|
-
const AUTH_VALUE_OPTIONS = /* @__PURE__ */ new Set([
|
|
46
|
-
"--model",
|
|
47
|
-
"--provider",
|
|
48
|
-
"--min-expiry"
|
|
49
|
-
]);
|
|
50
|
-
function isAuthCommandHelp(args) {
|
|
51
|
-
if (args[0] !== "auth") return false;
|
|
52
|
-
const subcommand = args[1];
|
|
53
|
-
if (subcommand === void 0 || subcommand === "help" || subcommand === "--help" || subcommand === "-h") return true;
|
|
54
|
-
if (!AUTH_HELP_SUBCOMMANDS.has(subcommand)) return false;
|
|
55
|
-
const hasValueOptions = subcommand === "check" || subcommand === "print-api-key" || subcommand === "print-bearer-token";
|
|
56
|
-
for (let index = 2; index < args.length; index++) {
|
|
57
|
-
const arg = args[index];
|
|
58
|
-
if (arg === "--") return false;
|
|
59
|
-
if (hasValueOptions && AUTH_VALUE_OPTIONS.has(arg)) {
|
|
60
|
-
index++;
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
if (arg === "--help" || arg === "-h") return true;
|
|
64
|
-
}
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
function printAuthCommandHelp() {
|
|
68
|
-
console.error(`Usage:
|
|
69
|
-
${APP_NAME} auth login <provider> [--api-key] [--no-browser]
|
|
70
|
-
${APP_NAME} auth logout <provider>
|
|
71
|
-
${APP_NAME} auth print-api-key --model <model> [--provider <provider>]
|
|
72
|
-
${APP_NAME} auth print-bearer-token --model <model> [--provider <provider>] [--min-expiry <duration>]
|
|
73
|
-
${APP_NAME} auth check [--provider <provider>] [--model <model>] [--json] [--credentials] [--no-refresh]
|
|
74
|
-
|
|
75
|
-
login signs in to a provider with an account in the browser, or saves an API key with
|
|
76
|
-
--api-key, then exits. --no-browser does not open a browser and uses another sign-in
|
|
77
|
-
method, such as a device code; it cannot be combined with --api-key. login needs an
|
|
78
|
-
interactive terminal. logout removes the stored credentials; environment variables and
|
|
79
|
-
models.json config are unchanged, and it exits 0 when nothing is stored.
|
|
80
|
-
|
|
81
|
-
Credential print commands write one configured credential alone on stdout. Everything else —
|
|
82
|
-
warnings, provider selection, refresh notices, and help — goes to stderr. --model is
|
|
83
|
-
required for these exports, so no ambient model can emit a credential you did not name.
|
|
84
|
-
|
|
85
|
-
Auth checks require at least one of --provider or --model. They print ready, not_ready,
|
|
86
|
-
or invalid on stdout and refresh expired OAuth credentials by default; --no-refresh
|
|
87
|
-
prevents a refresh and any auth.json mutation. --json includes the resolved provider
|
|
88
|
-
when one is found, plus auth type and a reason when it is not ready. --credentials is
|
|
89
|
-
an explicit export that needs --provider or an exact --model target; on a ready check
|
|
90
|
-
it writes the credential, or includes it in JSON. A non-ready raw export leaves stdout
|
|
91
|
-
empty and reports status on stderr.
|
|
92
|
-
|
|
93
|
-
--min-expiry accepts ms, s, m, or h (for example 30m) and applies only to
|
|
94
|
-
print-bearer-token, where it defaults to 30m. A token with less than that
|
|
95
|
-
remaining is refreshed first. It remains reserved after --, so print-api-key
|
|
96
|
-
still rejects it in either spelling.
|
|
97
|
-
|
|
98
|
-
Credential-export exit codes:
|
|
99
|
-
0 credential written to stdout
|
|
100
|
-
1 usage error
|
|
101
|
-
2 no credential configured
|
|
102
|
-
3 provider ambiguous
|
|
103
|
-
4 credential kind unsupported for that provider
|
|
104
|
-
5 refresh failed (the stored credential is left untouched)
|
|
105
|
-
6 provider cannot mint a token that lives long enough
|
|
106
|
-
7 the provider's OAuth credential could not be used
|
|
107
|
-
8 the credential could not be written (nothing was emitted)
|
|
108
|
-
9 the credential was written only in part; stdout holds an unusable
|
|
109
|
-
fragment, which the caller must discard rather than use
|
|
110
|
-
|
|
111
|
-
Auth-check exit codes:
|
|
112
|
-
0 provider is ready
|
|
113
|
-
1 provider is not ready
|
|
114
|
-
2 auth state or command is invalid
|
|
115
|
-
8 with --credentials, the credential could not be written
|
|
116
|
-
9 with --credentials, only part of the credential was written`);
|
|
117
|
-
}
|
|
118
|
-
function parseDuration(value, exitCode) {
|
|
119
|
-
const match = value ? /^(\d+)(ms|s|m|h)$/iu.exec(value) : void 0;
|
|
120
|
-
if (!match) throw new AuthCommandError("--min-expiry must use a duration such as 30m or 1h", exitCode);
|
|
121
|
-
const unit = match[2].toLowerCase();
|
|
122
|
-
const scale = unit === "ms" ? 1 : unit === "s" ? 1e3 : unit === "m" ? 6e4 : 36e5;
|
|
123
|
-
return Number(match[1]) * scale;
|
|
124
|
-
}
|
|
125
|
-
/** Parse the `atomic auth` command surface before normal startup. */
|
|
126
|
-
function parseAuthCommand(args) {
|
|
127
|
-
if (args[0] !== "auth") return void 0;
|
|
128
|
-
const kind = args[1] === "check" ? "check" : args[1] === "print-api-key" ? "api_key" : args[1] === "print-bearer-token" ? "bearer_token" : void 0;
|
|
129
|
-
if (!kind) throw new AuthCommandError(`Unknown auth command "${args[1] ?? ""}". Use "${APP_NAME} auth login", "${APP_NAME} auth logout", "${APP_NAME} auth print-api-key", "${APP_NAME} auth print-bearer-token", or "${APP_NAME} auth check".`);
|
|
130
|
-
const exitCode = kind === "check" ? 2 : 1;
|
|
131
|
-
const commandArgs = [];
|
|
132
|
-
let json = false;
|
|
133
|
-
let credentials = false;
|
|
134
|
-
let noRefresh = false;
|
|
135
|
-
let minExpiryMs;
|
|
136
|
-
let optionsEnded = false;
|
|
137
|
-
for (let index = 2; index < args.length; index++) {
|
|
138
|
-
const arg = args[index];
|
|
139
|
-
if (arg === "--") {
|
|
140
|
-
optionsEnded = true;
|
|
141
|
-
commandArgs.push(arg);
|
|
142
|
-
continue;
|
|
143
|
-
}
|
|
144
|
-
const inlineMinExpiry = arg.startsWith("--min-expiry=") ? arg.slice(13) : void 0;
|
|
145
|
-
if (arg === "--min-expiry" || inlineMinExpiry !== void 0) {
|
|
146
|
-
if (kind !== "bearer_token") throw new AuthCommandError("--min-expiry is only supported by print-bearer-token", exitCode);
|
|
147
|
-
minExpiryMs = parseDuration(inlineMinExpiry ?? args[++index], exitCode);
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
if (!optionsEnded && (arg === "--json" || arg === "--credentials" || arg === "--no-refresh")) {
|
|
151
|
-
if (kind !== "check") throw new AuthCommandError(`${arg} is only supported by auth check`, exitCode);
|
|
152
|
-
if (arg === "--json") json = true;
|
|
153
|
-
else if (arg === "--credentials") credentials = true;
|
|
154
|
-
else noRefresh = true;
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
commandArgs.push(arg);
|
|
158
|
-
}
|
|
159
|
-
return minExpiryMs === void 0 ? {
|
|
160
|
-
kind,
|
|
161
|
-
args: commandArgs,
|
|
162
|
-
json,
|
|
163
|
-
credentials,
|
|
164
|
-
noRefresh
|
|
165
|
-
} : {
|
|
166
|
-
kind,
|
|
167
|
-
args: commandArgs,
|
|
168
|
-
json,
|
|
169
|
-
credentials,
|
|
170
|
-
noRefresh,
|
|
171
|
-
minExpiryMs
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function validateAuthCheckArgs(args) {
|
|
175
|
-
const provider = args.provider?.trim() || void 0;
|
|
176
|
-
const model = args.model?.trim() || void 0;
|
|
177
|
-
if (args.unknownFlags.size > 0) {
|
|
178
|
-
const option = args.unknownFlags.keys().next().value;
|
|
179
|
-
throw new AuthCommandError(`Unknown option --${option} for "auth check".`);
|
|
180
|
-
}
|
|
181
|
-
if (args.apiKey !== void 0 || args.messages.length > 0 || args.fileArgs.length > 0) throw new AuthCommandError("Auth checks only accept --provider and --model");
|
|
182
|
-
if (!provider && !model) throw new AuthCommandError("Auth checks require --provider <provider> or --model <model>");
|
|
183
|
-
return {
|
|
184
|
-
provider,
|
|
185
|
-
model
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
// dist/cli/credential-print.js
|
|
189
|
-
/**
|
|
190
|
-
* `atomic auth print-api-key` / `atomic auth print-bearer-token` and the
|
|
191
|
-
* explicit `atomic auth check --credentials` export path.
|
|
192
|
-
*
|
|
193
|
-
* The only door in Atomic whose purpose is emitting a secret. Everything here
|
|
194
|
-
* exists to keep that egress narrow:
|
|
195
|
-
* - the secret leaves as a `Secret`, which cannot be interpolated, serialized,
|
|
196
|
-
* or inspected, and is consumed exactly once by the stdout writer;
|
|
197
|
-
* - every export has an explicit target: the print commands require `--model`,
|
|
198
|
-
* and auth checks require `--provider` or an exact `--model` plus
|
|
199
|
-
* `--credentials`;
|
|
200
|
-
* - there is no `--output <file>` and no clipboard path — stdout only;
|
|
201
|
-
* - every failure is a distinct exit code, and stdout stays empty on all of
|
|
202
|
-
* them but one — `CredentialTruncated` (exit 9) exists to report the case
|
|
203
|
-
* where it cannot be, because bytes already left and cannot be recalled;
|
|
204
|
-
* - a failed OAuth refresh never mutates the stored credential.
|
|
205
|
-
*
|
|
206
|
-
* One residual, and it is upstream: when a model infers several eligible
|
|
207
|
-
* providers, each is asked for its credential before the ambiguity is known, so
|
|
208
|
-
* a *successful* refresh can rotate and persist a credential this command then
|
|
209
|
-
* declines to emit (exit 3). See the note on the `getAuth()` call in the
|
|
210
|
-
* candidate loop.
|
|
211
|
-
*/
|
|
212
|
-
/** Bearer tokens are refreshed unless they still have this much life left. */
|
|
213
|
-
const DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS = 18e5;
|
|
214
|
-
/**
|
|
215
|
-
* Exported so a test can walk the whole taxonomy: every declared code has to
|
|
216
|
-
* name an exercised path, and the record type makes a new member without an
|
|
217
|
-
* exit code a compile error rather than a review miss.
|
|
218
|
-
*
|
|
219
|
-
* Every one of these leaves stdout empty except `CredentialTruncated`, which
|
|
220
|
-
* exists to report the one case where it cannot be: bytes already went out and
|
|
221
|
-
* cannot be recalled. `STDOUT_EMPTY_ON_EXIT` names that split so the taxonomy
|
|
222
|
-
* test asserts it rather than assuming it.
|
|
223
|
-
*/
|
|
224
|
-
const EXIT_CODES = {
|
|
225
|
-
Usage: 1,
|
|
226
|
-
NoCredentialConfigured: 2,
|
|
227
|
-
ProviderAmbiguous: 3,
|
|
228
|
-
KindUnsupportedForProvider: 4,
|
|
229
|
-
RefreshFailed: 5,
|
|
230
|
-
MinValidityUnreachable: 6,
|
|
231
|
-
OAuthUnavailable: 7,
|
|
232
|
-
CredentialNotEmitted: 8,
|
|
233
|
-
CredentialTruncated: 9
|
|
234
|
-
};
|
|
235
|
-
new Set(Object.keys(EXIT_CODES).filter((code) => code !== "CredentialTruncated"));
|
|
236
|
-
var CredentialPrintError = class extends Error {
|
|
237
|
-
code;
|
|
238
|
-
exitCode;
|
|
239
|
-
constructor(code, message, options) {
|
|
240
|
-
super(message, options);
|
|
241
|
-
this.name = "CredentialPrintError";
|
|
242
|
-
this.code = code;
|
|
243
|
-
this.exitCode = EXIT_CODES[code];
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
/**
|
|
247
|
-
* A credential in transit.
|
|
248
|
-
*
|
|
249
|
-
* Every path that would copy the value into a string is closed: `toString`,
|
|
250
|
-
* `toJSON`, and `Symbol.toPrimitive` throw rather than return, so a template
|
|
251
|
-
* literal, `JSON.stringify`, or string concatenation fails loudly instead of
|
|
252
|
-
* leaking into a log line, a transcript, or an error message. `inspect` — which
|
|
253
|
-
* `console.log` and Node's error formatting use — renders a placeholder.
|
|
254
|
-
*
|
|
255
|
-
* `take()` is the single exit, and it works once.
|
|
256
|
-
*/
|
|
257
|
-
var Secret = class {
|
|
258
|
-
#value;
|
|
259
|
-
constructor(value) {
|
|
260
|
-
this.#value = value;
|
|
261
|
-
}
|
|
262
|
-
/** Consume the secret. A second call is a bug, not a second read. */
|
|
263
|
-
take() {
|
|
264
|
-
const value = this.#value;
|
|
265
|
-
if (value === void 0) throw new Error("Secret has already been consumed");
|
|
266
|
-
this.#value = void 0;
|
|
267
|
-
return value;
|
|
268
|
-
}
|
|
269
|
-
toString() {
|
|
270
|
-
throw new Error("A Secret cannot be converted to a string; use take()");
|
|
271
|
-
}
|
|
272
|
-
toJSON() {
|
|
273
|
-
throw new Error("A Secret cannot be serialized; use take()");
|
|
274
|
-
}
|
|
275
|
-
[Symbol.toPrimitive]() {
|
|
276
|
-
throw new Error("A Secret cannot be interpolated; use take()");
|
|
277
|
-
}
|
|
278
|
-
[inspect.custom]() {
|
|
279
|
-
return "[Secret]";
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
/**
|
|
283
|
-
* The only function in `src` that opens a `Secret`.
|
|
284
|
-
*
|
|
285
|
-
* Its two `Secret.take()` calls are the only call sites in `src`, and the
|
|
286
|
-
* source-wide credential-egress test pins that list. This function builds one
|
|
287
|
-
* payload and returns it only to `emitCredential`; no caller receives a plain
|
|
288
|
-
* credential string.
|
|
289
|
-
*/
|
|
290
|
-
function credentialPayload(secret, jsonFields) {
|
|
291
|
-
if (jsonFields === void 0) return `${secret.take()}\n`;
|
|
292
|
-
const { status, provider, authType } = jsonFields;
|
|
293
|
-
if (typeof status !== "string" || typeof provider !== "string" || authType !== void 0 && typeof authType !== "string") throw new Error("Invalid credential JSON fields");
|
|
294
|
-
const fields = JSON.stringify({
|
|
295
|
-
status,
|
|
296
|
-
provider,
|
|
297
|
-
...authType === void 0 ? {} : { authType }
|
|
298
|
-
});
|
|
299
|
-
if (fields === void 0 || !fields.startsWith("{") || !fields.endsWith("}")) throw new Error("Invalid credential JSON envelope");
|
|
300
|
-
return `${fields.slice(0, -1)},"credentials":${JSON.stringify(secret.take())}}\n`;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* The single credential egress in `src`.
|
|
304
|
-
*
|
|
305
|
-
* `credentialPayload` opens the secret only while building this one payload,
|
|
306
|
-
* and this guarded write is the only path that hands it to real stdout. A
|
|
307
|
-
* caller — `main.ts` included — receives a `Secret` it cannot read, print, or
|
|
308
|
-
* serialize, so it cannot add a second export path without crossing this door.
|
|
309
|
-
* `test/credential-print.test.ts` pins both the `take()` sites and every
|
|
310
|
-
* data-bearing real-stdout write in `packages/coding-agent/src`.
|
|
311
|
-
*
|
|
312
|
-
* A failed payload write is answered from the stream rather than from the shape
|
|
313
|
-
* of the error, because `bytesWritten` says how much of the credential actually
|
|
314
|
-
* left and the right report differs for each amount.
|
|
315
|
-
*
|
|
316
|
-
* Nothing left — the write call threw, or the callback failed with the counter
|
|
317
|
-
* unmoved — is `CredentialNotEmitted` (exit 8) with stdout provably empty,
|
|
318
|
-
* which is what that exit promises. It must not fall through to the caller's
|
|
319
|
-
* credential-resolution catch, which would report exit 2.
|
|
320
|
-
*
|
|
321
|
-
* All of it left and the failure came after: the caller holds the credential it
|
|
322
|
-
* asked for, so this is reported on stderr with the exit code left at 0, for
|
|
323
|
-
* the same reason the trailing drain is. A non-zero exit over a stream carrying
|
|
324
|
-
* a whole credential is the thing this door never produces.
|
|
325
|
-
*
|
|
326
|
-
* Part of it left is neither. Those bytes cannot be recalled, so stdout is not
|
|
327
|
-
* empty and cannot be made empty; but they are a fragment, not a credential,
|
|
328
|
-
* and reporting success over them would hand a caller a truncated secret it
|
|
329
|
-
* cannot tell from a whole one. That case gets `CredentialTruncated` (exit 9),
|
|
330
|
-
* the one code in this taxonomy whose contract is *not* an empty stdout —
|
|
331
|
-
* stated as such in `EXIT_CODES` and asserted through `STDOUT_EMPTY_ON_EXIT`,
|
|
332
|
-
* rather than left for a caller to discover.
|
|
333
|
-
*/
|
|
334
|
-
async function emitCredential(secret, jsonFields) {
|
|
335
|
-
const payload = credentialPayload(secret, jsonFields);
|
|
336
|
-
try {
|
|
337
|
-
await writeRawStdoutOnce(payload);
|
|
338
|
-
} catch (error) {
|
|
339
|
-
if (error instanceof RawStdoutWriteError && error.emitted === "all") {
|
|
340
|
-
console.error(`Warning: the credential reached stdout but the write did not complete cleanly: ${error.message}`);
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
if (error instanceof RawStdoutWriteError && error.emitted === "partial") throw new CredentialPrintError("CredentialTruncated", "Only part of the credential reached stdout; discard the output, it is not a usable credential", { cause: error });
|
|
344
|
-
throw new CredentialPrintError("CredentialNotEmitted", "Failed to write the credential to stdout; nothing was emitted", { cause: error });
|
|
345
|
-
}
|
|
346
|
-
try {
|
|
347
|
-
await flushRawStdout();
|
|
348
|
-
} catch (error) {
|
|
349
|
-
console.error(`Warning: the credential was written to stdout but the stream did not drain cleanly: ${error instanceof Error ? error.message : String(error)}`);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* The single place a thrown value becomes an exit code for this door.
|
|
354
|
-
*
|
|
355
|
-
* `main.ts` routes every failure through here. Every code it can produce leaves
|
|
356
|
-
* stdout empty, so an exit code from this door never contradicts the stream.
|
|
357
|
-
*/
|
|
358
|
-
function toCredentialPrintError(error) {
|
|
359
|
-
if (error instanceof CredentialPrintError) return error;
|
|
360
|
-
return new CredentialPrintError("NoCredentialConfigured", error instanceof Error ? error.message : "Failed to resolve credential", { cause: error });
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* The only two fields of `Args` this door accepts.
|
|
364
|
-
*
|
|
365
|
-
* Validation is an allowlist rather than a list of refusals, because the
|
|
366
|
-
* refusal list only held while the dispatcher happened to ignore every other
|
|
367
|
-
* flag. `--export <path>`, `--session-dir <path>`, `--print`, and `--help` are
|
|
368
|
-
* all parsed by `parseArgs`; under an exclusion check they passed silently and
|
|
369
|
-
* the door's "no file sink" guarantee rested on a downstream accident.
|
|
370
|
-
*/
|
|
371
|
-
const ACCEPTED_ARG_FIELDS = /* @__PURE__ */ new Set(["model", "provider"]);
|
|
372
|
-
/** Names every field of a parsed `Args` that the caller actually set. */
|
|
373
|
-
function populatedArgFields(args) {
|
|
374
|
-
const populated = [];
|
|
375
|
-
for (const [field, value] of Object.entries(args)) {
|
|
376
|
-
if (ACCEPTED_ARG_FIELDS.has(field) || value === void 0) continue;
|
|
377
|
-
if (Array.isArray(value)) {
|
|
378
|
-
if (value.length > 0) populated.push(field);
|
|
379
|
-
} else if (value instanceof Map) {
|
|
380
|
-
if (value.size > 0) populated.push(field);
|
|
381
|
-
} else populated.push(field);
|
|
382
|
-
}
|
|
383
|
-
return populated;
|
|
384
|
-
}
|
|
385
|
-
function validateCredentialPrintArgs(args) {
|
|
386
|
-
if (!args.model?.trim()) throw new CredentialPrintError("Usage", "Credential printing requires --model <model>");
|
|
387
|
-
if (args.apiKey !== void 0) throw new CredentialPrintError("Usage", "Credential printing reads configured credentials; --api-key is not supported");
|
|
388
|
-
const refused = populatedArgFields(args);
|
|
389
|
-
if (refused.length > 0) throw new CredentialPrintError("Usage", `Credential printing only accepts --provider and --model (refused: ${refused.join(", ")})`);
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* pi-ai raises three different `oauth`-coded failures from
|
|
393
|
-
* `dist/auth/resolve.js`, and only one of them is a failed refresh.
|
|
394
|
-
*
|
|
395
|
-
* `OAuth auth derivation failed for <provider>` is thrown after
|
|
396
|
-
* `credentials.modify` has already persisted a rotated credential, and also on
|
|
397
|
-
* the branch where no refresh was attempted at all — so it gets its own code
|
|
398
|
-
* and a message that makes no claim about the stored credential. Treating it as
|
|
399
|
-
* `RefreshFailed` asserted a rollback the command never verified.
|
|
400
|
-
*
|
|
401
|
-
* Classification reads the raw message, because redaction could rewrite the
|
|
402
|
-
* phrase it matches on; only the text that becomes a user-facing message is
|
|
403
|
-
* redacted. The unredacted error stays reachable as `cause`, which this door
|
|
404
|
-
* never logs.
|
|
405
|
-
*
|
|
406
|
-
* `test/credential-print.test.ts` pins both phrases against the installed
|
|
407
|
-
* pi-ai build, so an upstream rewording fails the suite rather than silently
|
|
408
|
-
* collapsing exit 6 into exit 5.
|
|
409
|
-
*/
|
|
410
|
-
function classifyOAuthFailure(error) {
|
|
411
|
-
const detail = redactCredentialShapes(error.message);
|
|
412
|
-
if (error.message.includes("expires too soon")) return new CredentialPrintError("MinValidityUnreachable", `The provider refreshed the token but it still expires sooner than requested: ${detail}`, { cause: error });
|
|
413
|
-
if (error.message.startsWith("OAuth refresh failed for")) return new CredentialPrintError("RefreshFailed", `${detail} (the stored credential changes only if the provider completes this refresh later)`, { cause: error });
|
|
414
|
-
return new CredentialPrintError("OAuthUnavailable", detail, { cause: error });
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* Providers whose credential the caller could have meant.
|
|
418
|
-
*
|
|
419
|
-
* With `--provider` the caller named one, so failing to resolve it is an error.
|
|
420
|
-
* Without it, eligibility is *not* narrowed to providers holding a persisted
|
|
421
|
-
* credential: a provider authenticated by an environment variable or a custom
|
|
422
|
-
* resolver has nothing in `auth.json`, and filtering on that list dropped it
|
|
423
|
-
* before `getAuth()` could produce its working key. Candidacy is therefore
|
|
424
|
-
* "offers the named model", and `getAuth()` — the same call a real request
|
|
425
|
-
* makes — decides which candidate actually authenticates.
|
|
426
|
-
*/
|
|
427
|
-
function candidateModels(args, modelRuntime) {
|
|
428
|
-
if (args.provider) {
|
|
429
|
-
const resolved = resolveCliModel({
|
|
430
|
-
cliProvider: args.provider,
|
|
431
|
-
cliModel: args.model,
|
|
432
|
-
modelRuntime
|
|
433
|
-
});
|
|
434
|
-
if (resolved.error || !resolved.model) throw new CredentialPrintError("NoCredentialConfigured", resolved.error ?? "Unable to resolve the requested provider/model");
|
|
435
|
-
return [resolved.model];
|
|
436
|
-
}
|
|
437
|
-
const catalog = modelRuntime.getModels();
|
|
438
|
-
const models = [];
|
|
439
|
-
for (const provider of modelRuntime.getProviders()) {
|
|
440
|
-
const resolved = resolveModelReference({
|
|
441
|
-
text: args.model ?? "",
|
|
442
|
-
provider: provider.id,
|
|
443
|
-
thinkingSuffix: "strict",
|
|
444
|
-
fuzzy: true
|
|
445
|
-
}, catalog, () => true);
|
|
446
|
-
if (resolved.status === "resolved") models.push(resolved.model);
|
|
447
|
-
}
|
|
448
|
-
if (models.length === 0) throw new CredentialPrintError("NoCredentialConfigured", `Model "${args.model}" not found among the available providers. Use --list-models to see available models.`);
|
|
449
|
-
return models;
|
|
450
|
-
}
|
|
451
|
-
function bearerFromHeaders(headers) {
|
|
452
|
-
const authorization = Object.entries(headers ?? {}).find(([name]) => name.toLowerCase() === "authorization")?.[1];
|
|
453
|
-
return typeof authorization === "string" ? extractBearerToken(authorization) : void 0;
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Resolve exactly one credential for a named provider/model pair.
|
|
457
|
-
*
|
|
458
|
-
* Goes through `ModelRuntime.getAuth()`, the same request-auth path a real
|
|
459
|
-
* model call uses, so an OAuth credential is refreshed and persisted by the one
|
|
460
|
-
* implementation that already handles concurrent refresh under a lock.
|
|
461
|
-
*/
|
|
462
|
-
async function resolveCredentialForPrint(args, modelRuntime, kind, minExpiryMs) {
|
|
463
|
-
validateCredentialPrintArgs(args);
|
|
464
|
-
const wantedAuthType = kind === "api_key" ? "api_key" : "oauth";
|
|
465
|
-
const resolvedAuthTypes = /* @__PURE__ */ new Map();
|
|
466
|
-
const models = candidateModels(args, modelRuntime);
|
|
467
|
-
for (const { provider } of models) {
|
|
468
|
-
if (resolvedAuthTypes.has(provider)) continue;
|
|
469
|
-
resolvedAuthTypes.set(provider, (await modelRuntime.checkAuth(provider))?.type);
|
|
470
|
-
}
|
|
471
|
-
const authFailureIsFatal = args.provider !== void 0 || models.length === 1;
|
|
472
|
-
const credentials = [];
|
|
473
|
-
let deferredDiagnosis;
|
|
474
|
-
for (const model of models) {
|
|
475
|
-
if (resolvedAuthTypes.get(model.provider) !== wantedAuthType) continue;
|
|
476
|
-
let auth;
|
|
477
|
-
try {
|
|
478
|
-
auth = await modelRuntime.getAuth(model, kind === "bearer_token" ? { minOAuthValidityMs: minExpiryMs ?? 18e5 } : {});
|
|
479
|
-
} catch (error) {
|
|
480
|
-
const diagnosis = error instanceof ModelsError && error.code === "oauth" ? classifyOAuthFailure(error) : void 0;
|
|
481
|
-
if (!authFailureIsFatal) {
|
|
482
|
-
deferredDiagnosis ??= diagnosis;
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
if (diagnosis) throw diagnosis;
|
|
486
|
-
throw new CredentialPrintError("NoCredentialConfigured", redactCredentialShapes(error instanceof Error ? error.message : String(error)), { cause: error });
|
|
487
|
-
}
|
|
488
|
-
const value = kind === "bearer_token" ? auth?.auth.apiKey ?? bearerFromHeaders(auth?.auth.headers) : auth?.auth.apiKey;
|
|
489
|
-
if (value) credentials.push({
|
|
490
|
-
providerId: model.provider,
|
|
491
|
-
value
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
if (credentials.length === 1) return new Secret(credentials[0].value);
|
|
495
|
-
if (credentials.length === 0) {
|
|
496
|
-
if (deferredDiagnosis) throw deferredDiagnosis;
|
|
497
|
-
const providerId = models[0]?.provider;
|
|
498
|
-
const type = providerId ? resolvedAuthTypes.get(providerId) : void 0;
|
|
499
|
-
if (args.provider && kind === "api_key" && type === "oauth") throw new CredentialPrintError("KindUnsupportedForProvider", `Provider "${providerId}" is configured with OAuth, not an API key`);
|
|
500
|
-
if (args.provider && kind === "bearer_token" && type === "api_key") throw new CredentialPrintError("KindUnsupportedForProvider", `Provider "${providerId}" is not configured with an OAuth bearer token`);
|
|
501
|
-
throw new CredentialPrintError("NoCredentialConfigured", `No usable ${kind === "api_key" ? "API key" : "OAuth bearer token"} is configured`);
|
|
502
|
-
}
|
|
503
|
-
throw new CredentialPrintError("ProviderAmbiguous", `Model "${args.model}" has multiple configured providers (${credentials.map(({ providerId }) => providerId).join(", ")}). Specify --provider.`);
|
|
504
|
-
}
|
|
505
|
-
// dist/cli/auth-check.js
|
|
506
|
-
async function storedOAuthIsExpired(providerId, credentials) {
|
|
507
|
-
const credential = await credentials?.read(providerId);
|
|
508
|
-
return credential?.type === "oauth" && Date.now() >= credential.expires;
|
|
509
|
-
}
|
|
510
|
-
async function checkProviderAuth(args, modelRuntime, options = { refresh: false }) {
|
|
511
|
-
const { provider: cliProvider, model: cliModel } = validateAuthCheckArgs(args);
|
|
512
|
-
let provider = cliProvider;
|
|
513
|
-
if (cliModel) {
|
|
514
|
-
const resolved = resolveCliModel({
|
|
515
|
-
cliProvider,
|
|
516
|
-
cliModel,
|
|
517
|
-
modelRuntime
|
|
518
|
-
});
|
|
519
|
-
if (resolved.error || !resolved.model) throw new AuthCommandError(resolved.error ?? `Unable to resolve model "${cliModel}"`);
|
|
520
|
-
provider = resolved.model.provider;
|
|
521
|
-
}
|
|
522
|
-
if (!provider) throw new AuthCommandError("Unable to resolve an auth provider");
|
|
523
|
-
if (modelRuntime.getError()) return {
|
|
524
|
-
status: "invalid",
|
|
525
|
-
provider,
|
|
526
|
-
reason: "invalid_state"
|
|
527
|
-
};
|
|
528
|
-
if (!modelRuntime.getProvider(provider)) return {
|
|
529
|
-
status: "not_ready",
|
|
530
|
-
provider,
|
|
531
|
-
reason: "provider_not_found"
|
|
532
|
-
};
|
|
533
|
-
try {
|
|
534
|
-
const auth = await modelRuntime.checkAuth(provider);
|
|
535
|
-
if (!auth) return {
|
|
536
|
-
status: "not_ready",
|
|
537
|
-
provider,
|
|
538
|
-
reason: "credentials_not_configured"
|
|
539
|
-
};
|
|
540
|
-
if (options.refresh) {
|
|
541
|
-
if (!await modelRuntime.getAuth(provider)) return {
|
|
542
|
-
status: "not_ready",
|
|
543
|
-
provider,
|
|
544
|
-
reason: "credentials_not_configured"
|
|
545
|
-
};
|
|
546
|
-
} else if (auth.type === "oauth" && await storedOAuthIsExpired(provider, options.credentials)) return {
|
|
547
|
-
status: "not_ready",
|
|
548
|
-
provider,
|
|
549
|
-
reason: "credential_expired"
|
|
550
|
-
};
|
|
551
|
-
return {
|
|
552
|
-
status: "ready",
|
|
553
|
-
provider,
|
|
554
|
-
authType: auth.type
|
|
555
|
-
};
|
|
556
|
-
} catch (error) {
|
|
557
|
-
if (error instanceof ModelsError && error.code === "oauth") return {
|
|
558
|
-
status: "not_ready",
|
|
559
|
-
provider,
|
|
560
|
-
reason: "credential_not_available"
|
|
561
|
-
};
|
|
562
|
-
return {
|
|
563
|
-
status: "invalid",
|
|
564
|
-
provider,
|
|
565
|
-
reason: "invalid_state"
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* A credential export must name one target, not accept the CLI resolver's fuzzy
|
|
571
|
-
* cross-provider match. Provider flags are explicit; a model-only export is
|
|
572
|
-
* explicit only when its exact reference resolves uniquely to the provider.
|
|
573
|
-
*/
|
|
574
|
-
function hasExplicitCredentialExportTarget(args, modelRuntime, provider) {
|
|
575
|
-
const { provider: cliProvider, model: cliModel } = validateAuthCheckArgs(args);
|
|
576
|
-
if (cliProvider) return true;
|
|
577
|
-
if (!cliModel) return false;
|
|
578
|
-
return findExactModelReferenceMatch(cliModel, [...modelRuntime.getModels()])?.provider.toLowerCase() === provider.toLowerCase();
|
|
579
|
-
}
|
|
580
|
-
function getAuthCredential(auth) {
|
|
581
|
-
if (auth?.auth.apiKey) return auth.auth.apiKey;
|
|
582
|
-
const authorization = Object.entries(auth?.auth.headers ?? {}).find(([name]) => name.toLowerCase() === "authorization")?.[1];
|
|
583
|
-
return typeof authorization === "string" ? extractBearerToken(authorization) : void 0;
|
|
584
|
-
}
|
|
585
|
-
/** Resolve the credential that the checked provider would use, without exposing it to callers. */
|
|
586
|
-
async function getProviderCredential(providerId, modelRuntime, credentials, options) {
|
|
587
|
-
if (!options.refresh) {
|
|
588
|
-
const stored = await credentials.read(providerId);
|
|
589
|
-
if (stored?.type === "oauth") return stored.expires - Date.now() >= 18e5 ? new Secret(stored.access) : void 0;
|
|
590
|
-
}
|
|
591
|
-
const credential = getAuthCredential(await modelRuntime.getAuth(providerId, { minOAuthValidityMs: DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS }));
|
|
592
|
-
return credential === void 0 ? void 0 : new Secret(credential);
|
|
593
|
-
}
|
|
594
|
-
async function createAuthCheckModelRuntime(credentials) {
|
|
595
|
-
const runtime = await ModelRuntime.create({
|
|
596
|
-
credentials,
|
|
597
|
-
modelsStore: new InMemoryCodingAgentModelsStore(),
|
|
598
|
-
allowModelNetwork: false,
|
|
599
|
-
refreshOnCreate: false
|
|
600
|
-
});
|
|
601
|
-
await runtime.reloadCredentials({ refreshAvailability: false });
|
|
602
|
-
return runtime;
|
|
603
|
-
}
|
|
604
|
-
// dist/core/provider-matching.js
|
|
605
|
-
/** Match provider IDs and display names exactly, ignoring case and surrounding whitespace in the reference. */
|
|
606
|
-
function findMatchingProviders(providers, providerRef) {
|
|
607
|
-
const normalized = providerRef.trim().toLowerCase();
|
|
608
|
-
if (!normalized) return [];
|
|
609
|
-
return providers.filter((provider) => provider.id.toLowerCase() === normalized || provider.name.toLowerCase() === normalized);
|
|
610
|
-
}
|
|
611
|
-
/**
|
|
612
|
-
* Resolve a reference for a command that acts on one provider; `providers` have distinct IDs. A reference equal to a
|
|
613
|
-
* provider ID selects that provider. Otherwise it must match exactly one provider as {@link findMatchingProviders}
|
|
614
|
-
* does, so a display name that several providers share is ambiguous instead of selecting whichever comes first.
|
|
615
|
-
*/
|
|
616
|
-
function resolveProviderReference(providers, providerRef) {
|
|
617
|
-
const trimmed = providerRef.trim();
|
|
618
|
-
if (!trimmed) return { type: "none" };
|
|
619
|
-
const exact = providers.find((provider) => provider.id === trimmed);
|
|
620
|
-
if (exact) return {
|
|
621
|
-
type: "match",
|
|
622
|
-
provider: exact
|
|
623
|
-
};
|
|
624
|
-
const matches = findMatchingProviders(providers, trimmed);
|
|
625
|
-
if (matches.length > 1) return {
|
|
626
|
-
type: "ambiguous",
|
|
627
|
-
providerIds: matches.map((provider) => provider.id).sort()
|
|
628
|
-
};
|
|
629
|
-
return matches[0] ? {
|
|
630
|
-
type: "match",
|
|
631
|
-
provider: matches[0]
|
|
632
|
-
} : { type: "none" };
|
|
633
|
-
}
|
|
634
|
-
// dist/cli/auth-login.js
|
|
635
|
-
const AUTH_LOGIN_USAGE = `${APP_NAME} auth login <provider> [--api-key] [--no-browser]`;
|
|
636
|
-
/** Run `atomic auth login <provider>` in the terminal and return the process exit code. */
|
|
637
|
-
async function runAuthLogin(args, options) {
|
|
638
|
-
const { modelRuntime, terminal, signal } = options;
|
|
639
|
-
const parsed = parseLoginRequest(args);
|
|
640
|
-
if (parsed.type === "invalid") {
|
|
641
|
-
terminal.error(parsed.message);
|
|
642
|
-
return 1;
|
|
643
|
-
}
|
|
644
|
-
const { request } = parsed;
|
|
645
|
-
const { providerRef } = request;
|
|
646
|
-
const resolution = resolveProviderReference(modelRuntime.getProviders(), providerRef);
|
|
647
|
-
if (resolution.type === "ambiguous") {
|
|
648
|
-
terminal.error(`"${replaceControlCharacters(providerRef)}" matches more than one provider. Use a provider ID.`);
|
|
649
|
-
terminal.error(`Matching providers: ${resolution.providerIds.join(", ")}`);
|
|
650
|
-
return 1;
|
|
651
|
-
}
|
|
652
|
-
if (resolution.type === "none") {
|
|
653
|
-
const loginProviders = modelRuntime.getProviders().filter((candidate) => candidate.auth.oauth || candidate.auth.apiKey?.login).map((candidate) => candidate.id).sort();
|
|
654
|
-
terminal.error(`Unknown provider "${replaceControlCharacters(providerRef)}".`);
|
|
655
|
-
terminal.error(`Providers: ${loginProviders.join(", ")}`);
|
|
656
|
-
return 1;
|
|
657
|
-
}
|
|
658
|
-
const { provider } = resolution;
|
|
659
|
-
if (!terminal.interactive) {
|
|
660
|
-
terminal.error(`"${AUTH_LOGIN_USAGE}" requires an interactive terminal`);
|
|
661
|
-
return 1;
|
|
662
|
-
}
|
|
663
|
-
const authType = selectAuthType(provider, request.apiKey);
|
|
664
|
-
if (authType.type === "unavailable") {
|
|
665
|
-
terminal.error(authType.message);
|
|
666
|
-
return 1;
|
|
667
|
-
}
|
|
668
|
-
try {
|
|
669
|
-
await modelRuntime.login(provider.id, authType.type, createLoginInteraction(provider.id, authType.type, request, terminal, signal), { getDeviceId: options.getDeviceId });
|
|
670
|
-
} catch (error) {
|
|
671
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
672
|
-
if (error instanceof CredentialSynchronizationError) terminal.error(`Logged in to ${provider.name}, but local model state could not be synchronized: ${message}`);
|
|
673
|
-
else if (isOAuthLoginCancelled(error, signal)) terminal.error("Login cancelled.");
|
|
674
|
-
else terminal.error(`Failed to log in to ${provider.name}: ${message}`);
|
|
675
|
-
return 1;
|
|
676
|
-
}
|
|
677
|
-
terminal.write(`${authType.type === "oauth" ? `Logged in to ${provider.name}` : `Saved API key for ${provider.name}`}. Credentials saved to ${getAuthPath()}`);
|
|
678
|
-
await refreshProviderCatalog(provider, modelRuntime, terminal, signal);
|
|
679
|
-
return 0;
|
|
680
|
-
}
|
|
681
|
-
function parseLoginRequest(args) {
|
|
682
|
-
const usage = {
|
|
683
|
-
type: "invalid",
|
|
684
|
-
message: `Usage: ${AUTH_LOGIN_USAGE}`
|
|
685
|
-
};
|
|
686
|
-
const request = {
|
|
687
|
-
providerRef: "",
|
|
688
|
-
apiKey: false,
|
|
689
|
-
browser: true
|
|
690
|
-
};
|
|
691
|
-
for (const arg of args) if (arg === "--api-key") request.apiKey = true;
|
|
692
|
-
else if (arg === "--no-browser") request.browser = false;
|
|
693
|
-
else if (arg.startsWith("-") || request.providerRef) return usage;
|
|
694
|
-
else request.providerRef = arg;
|
|
695
|
-
if (!request.providerRef) return usage;
|
|
696
|
-
if (request.apiKey && !request.browser) return {
|
|
697
|
-
type: "invalid",
|
|
698
|
-
message: "--no-browser only applies to account sign-in; omit it with --api-key."
|
|
699
|
-
};
|
|
700
|
-
return {
|
|
701
|
-
type: "valid",
|
|
702
|
-
request
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
/**
|
|
706
|
-
* Account login unless `apiKey` asks for an API key. Providers without account login use their API key login, since
|
|
707
|
-
* that is the only way in.
|
|
708
|
-
*/
|
|
709
|
-
function selectAuthType(provider, apiKey) {
|
|
710
|
-
const hasApiKeyLogin = provider.auth.apiKey?.login !== void 0;
|
|
711
|
-
if (!apiKey && provider.auth.oauth) return { type: "oauth" };
|
|
712
|
-
if (hasApiKeyLogin) return { type: "api_key" };
|
|
713
|
-
if (apiKey && provider.auth.oauth) return {
|
|
714
|
-
type: "unavailable",
|
|
715
|
-
message: `${provider.name} has no API key login. Omit --api-key to sign in.`
|
|
716
|
-
};
|
|
717
|
-
const method = provider.auth.apiKey?.name ?? "ambient credentials";
|
|
718
|
-
return {
|
|
719
|
-
type: "unavailable",
|
|
720
|
-
message: `${provider.name} is configured outside ${APP_NAME} (${method}).`
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
/** Adapt provider prompts and events to the command's selected sign-in method. */
|
|
724
|
-
function createLoginInteraction(providerId, authType, request, terminal, signal) {
|
|
725
|
-
const methodChoice = authType === "api_key" ? "ask" : request.browser ? "browser" : "other";
|
|
726
|
-
let skippedMethods = [];
|
|
727
|
-
async function selectMethod(prompt, promptSignal) {
|
|
728
|
-
const [first, ...others] = prompt.options;
|
|
729
|
-
if (methodChoice === "ask" || !first) return selectInTerminal(prompt.message, prompt.options, terminal, promptSignal);
|
|
730
|
-
if (methodChoice === "browser") {
|
|
731
|
-
skippedMethods = others.map((option) => option.label);
|
|
732
|
-
return first.id;
|
|
733
|
-
}
|
|
734
|
-
const [onlyOther, ...moreOthers] = others;
|
|
735
|
-
if (!onlyOther) return first.id;
|
|
736
|
-
if (moreOthers.length > 0) return selectInTerminal(prompt.message, others, terminal, promptSignal);
|
|
737
|
-
terminal.write(`${prompt.message} ${onlyOther.label}`);
|
|
738
|
-
return onlyOther.id;
|
|
739
|
-
}
|
|
740
|
-
return {
|
|
741
|
-
signal,
|
|
742
|
-
prompt(prompt) {
|
|
743
|
-
const promptSignal = prompt.signal ? AbortSignal.any([signal, prompt.signal]) : signal;
|
|
744
|
-
if (prompt.type === "select") return selectMethod(prompt, promptSignal);
|
|
745
|
-
const placeholder = prompt.placeholder ? ` (${prompt.placeholder})` : "";
|
|
746
|
-
const message = `${prompt.message}${placeholder}: `;
|
|
747
|
-
return prompt.type === "secret" ? terminal.secret(message, promptSignal) : terminal.question(message, promptSignal);
|
|
748
|
-
},
|
|
749
|
-
notify(event) {
|
|
750
|
-
if (event.type === "auth_url") {
|
|
751
|
-
terminal.write(`Open this URL to sign in:\n ${displayUrl(event.url)}`);
|
|
752
|
-
if (event.instructions) terminal.write(event.instructions);
|
|
753
|
-
const target = webUrl(event.url);
|
|
754
|
-
if (target !== void 0 && request.browser) terminal.openUrl(target);
|
|
755
|
-
const rerun = `"${APP_NAME} auth login ${providerId} --no-browser"`;
|
|
756
|
-
const [onlyMethod, ...moreMethods] = skippedMethods;
|
|
757
|
-
if (onlyMethod !== void 0 && moreMethods.length === 0) terminal.write(`To use "${onlyMethod}" instead, run ${rerun}`);
|
|
758
|
-
else if (onlyMethod !== void 0) {
|
|
759
|
-
const labels = skippedMethods.map((label) => `"${label}"`).join(", ");
|
|
760
|
-
terminal.write(`Other sign-in methods: ${labels}. Run ${rerun} to choose one.`);
|
|
1
|
+
// Written by the build (scripts/in-place-update-gate.mjs): when this module's code cannot load in a process of an earlier release
|
|
2
|
+
// that an in-place update left running, the process is told to restart.
|
|
3
|
+
let module;
|
|
4
|
+
try {
|
|
5
|
+
module = await import("./auth-cli.code.js");
|
|
6
|
+
} catch (error) {
|
|
7
|
+
const root = new URL("../", import.meta.url);
|
|
8
|
+
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
9
|
+
const key = `${root.href}#0.10.5-alpha.1`;
|
|
10
|
+
let release = releases.get(key);
|
|
11
|
+
if (release === undefined) {
|
|
12
|
+
const current = (async () => {
|
|
13
|
+
for (const path of ["modes/interactive/interactive-mode-deps.js","_shared/chunk-CDOYTDYM.js","_shared/p0-cli-GUFK7TPN.js"]) {
|
|
14
|
+
try {
|
|
15
|
+
const held = await import(new URL(path, root).href);
|
|
16
|
+
if (typeof held.VERSION === "string") return { version: held.VERSION, name: held.APP_NAME };
|
|
17
|
+
} catch {
|
|
18
|
+
// Not a file this process can load: the next.
|
|
761
19
|
}
|
|
762
|
-
} else if (event.type === "device_code") {
|
|
763
|
-
terminal.write(`Open ${displayUrl(event.verificationUri)} and enter code: ${event.userCode}`);
|
|
764
|
-
const target = webUrl(event.verificationUri);
|
|
765
|
-
if (target !== void 0 && request.browser && event.openBrowserOnConfirm !== false) terminal.openUrl(target);
|
|
766
|
-
terminal.write("Waiting for authentication...");
|
|
767
|
-
} else if (event.type === "info") {
|
|
768
|
-
terminal.write(event.message);
|
|
769
|
-
for (const link of event.links ?? []) terminal.write(` ${link.label ? `${link.label}: ` : ""}${displayUrl(link.url)}`);
|
|
770
|
-
} else terminal.write(event.message);
|
|
771
|
-
}
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
async function selectInTerminal(message, options, terminal, signal) {
|
|
775
|
-
terminal.write(message);
|
|
776
|
-
options.forEach((option, index) => {
|
|
777
|
-
terminal.write(` ${index + 1}. ${option.label}${option.description ? ` - ${option.description}` : ""}`);
|
|
778
|
-
});
|
|
779
|
-
while (true) {
|
|
780
|
-
const answer = (await terminal.question(`Select 1-${options.length}: `, signal)).trim();
|
|
781
|
-
const option = /^\d+$/u.test(answer) ? options[Number(answer) - 1] : void 0;
|
|
782
|
-
if (option) return option.id;
|
|
783
|
-
terminal.write(`Enter a number from 1 to ${options.length}.`);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
/** Fetch the provider's model catalog now, since dynamic catalogs stay empty until the first authenticated refresh. */
|
|
787
|
-
async function refreshProviderCatalog(provider, modelRuntime, terminal, signal) {
|
|
788
|
-
const cancelled = () => {
|
|
789
|
-
terminal.write(`Skipped the ${provider.name} model catalog refresh; ${APP_NAME} refreshes it on next start.`);
|
|
790
|
-
};
|
|
791
|
-
try {
|
|
792
|
-
const result = await modelRuntime.refresh({
|
|
793
|
-
providers: [provider.id],
|
|
794
|
-
signal: AbortSignal.any([signal, AbortSignal.timeout(15e3)])
|
|
795
|
-
});
|
|
796
|
-
if (signal.aborted) cancelled();
|
|
797
|
-
else if (result.aborted) terminal.write(`The ${provider.name} model catalog refresh timed out; ${APP_NAME} refreshes it on next start.`);
|
|
798
|
-
else if (result.errors.size > 0) terminal.write(`The ${provider.name} model catalog could not be refreshed; ${APP_NAME} retries on next start.`);
|
|
799
|
-
} catch (error) {
|
|
800
|
-
if (signal.aborted) {
|
|
801
|
-
cancelled();
|
|
802
|
-
return;
|
|
803
|
-
}
|
|
804
|
-
terminal.write(`The ${provider.name} model catalog could not be refreshed: ${error instanceof Error ? error.message : String(error)}`);
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
// dist/cli/auth-logout.js
|
|
808
|
-
const AUTH_LOGOUT_USAGE = `${APP_NAME} auth logout <provider>`;
|
|
809
|
-
/**
|
|
810
|
-
* Run `atomic auth logout <provider>`: remove the credential `atomic auth login` or /login stored, and return the exit
|
|
811
|
-
* code. Environment variables and models.json config stay, as with /logout.
|
|
812
|
-
*/
|
|
813
|
-
async function runAuthLogout(args, options) {
|
|
814
|
-
const { modelRuntime, terminal, signal } = options;
|
|
815
|
-
const [providerRef, ...rest] = args;
|
|
816
|
-
if (providerRef === void 0 || providerRef.startsWith("-") || rest.length > 0) {
|
|
817
|
-
terminal.error(`Usage: ${AUTH_LOGOUT_USAGE}`);
|
|
818
|
-
return 1;
|
|
819
|
-
}
|
|
820
|
-
let stored;
|
|
821
|
-
try {
|
|
822
|
-
stored = await modelRuntime.listCredentials();
|
|
823
|
-
} catch (error) {
|
|
824
|
-
terminal.error(`Could not read stored credentials: ${error instanceof Error ? error.message : String(error)}`);
|
|
825
|
-
return 1;
|
|
826
|
-
}
|
|
827
|
-
const providers = modelRuntime.getProviders();
|
|
828
|
-
const unloaded = stored.filter((credential) => !providers.some((provider) => provider.id === credential.providerId)).map((credential) => ({
|
|
829
|
-
id: credential.providerId,
|
|
830
|
-
name: credential.providerId
|
|
831
|
-
}));
|
|
832
|
-
const resolution = resolveProviderReference([...providers, ...unloaded], providerRef);
|
|
833
|
-
if (resolution.type === "ambiguous") {
|
|
834
|
-
terminal.error(`"${replaceControlCharacters(providerRef)}" matches more than one provider. Use a provider ID.`);
|
|
835
|
-
terminal.error(`Matching providers: ${resolution.providerIds.join(", ")}`);
|
|
836
|
-
return 1;
|
|
837
|
-
}
|
|
838
|
-
if (resolution.type === "none") {
|
|
839
|
-
terminal.error(`Unknown provider "${replaceControlCharacters(providerRef)}".`);
|
|
840
|
-
const storedIds = stored.map((credential) => credential.providerId).sort();
|
|
841
|
-
terminal.error(`Stored credentials: ${storedIds.join(", ") || "none"}`);
|
|
842
|
-
return 1;
|
|
843
|
-
}
|
|
844
|
-
const providerName = resolution.provider.name;
|
|
845
|
-
const credential = stored.find((candidate) => candidate.providerId === resolution.provider.id);
|
|
846
|
-
if (!credential) {
|
|
847
|
-
terminal.write(`No stored credentials for ${providerName}. Environment variables and models.json config are unchanged.`);
|
|
848
|
-
return 0;
|
|
849
|
-
}
|
|
850
|
-
try {
|
|
851
|
-
await modelRuntime.logout(credential.providerId, { signal });
|
|
852
|
-
} catch (error) {
|
|
853
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
854
|
-
if (error instanceof CredentialSynchronizationError) terminal.error(`Credentials removed for ${providerName}, but local model state could not be synchronized: ${message}`);
|
|
855
|
-
else terminal.error(`Logout failed: ${message}`);
|
|
856
|
-
return 1;
|
|
857
|
-
}
|
|
858
|
-
terminal.write(credential.type === "oauth" ? `Logged out of ${providerName}.` : `Removed stored API key for ${providerName}. Environment variables and models.json config are unchanged.`);
|
|
859
|
-
return 0;
|
|
860
|
-
}
|
|
861
|
-
// dist/cli/auth-terminal.js
|
|
862
|
-
/**
|
|
863
|
-
* Terminal I/O on stdin and stdout. `onInterrupt` runs on Ctrl+C or EOF in a question, and on Ctrl+C, Ctrl+D or EOF
|
|
864
|
-
* in a secret.
|
|
865
|
-
*/
|
|
866
|
-
function createProcessLoginTerminal(onInterrupt) {
|
|
867
|
-
return {
|
|
868
|
-
interactive: process.stdin.isTTY === true && process.stdout.isTTY === true,
|
|
869
|
-
write: (line) => process.stdout.write(`${line}\n`),
|
|
870
|
-
error: (line) => process.stderr.write(`${line}\n`),
|
|
871
|
-
question: (message, signal) => questionTerminal(message, {
|
|
872
|
-
signal,
|
|
873
|
-
output: process.stdout,
|
|
874
|
-
onInterrupt
|
|
875
|
-
}),
|
|
876
|
-
secret: (message, signal) => readSecret(message, signal, onInterrupt),
|
|
877
|
-
openUrl: openBrowser
|
|
878
|
-
};
|
|
879
|
-
}
|
|
880
|
-
function readSecret(message, signal, onInterrupt) {
|
|
881
|
-
const stdin = process.stdin;
|
|
882
|
-
return new Promise((resolve, reject) => {
|
|
883
|
-
if (signal.aborted) {
|
|
884
|
-
reject(signal.reason);
|
|
885
|
-
return;
|
|
886
|
-
}
|
|
887
|
-
let value = "";
|
|
888
|
-
const finish = () => {
|
|
889
|
-
stdin.off("data", onData);
|
|
890
|
-
stdin.off("end", onEnd);
|
|
891
|
-
signal.removeEventListener("abort", onAbort);
|
|
892
|
-
stdin.setRawMode(false);
|
|
893
|
-
stdin.pause();
|
|
894
|
-
process.stdout.write("\n");
|
|
895
|
-
};
|
|
896
|
-
const onAbort = () => {
|
|
897
|
-
finish();
|
|
898
|
-
reject(signal.reason);
|
|
899
|
-
};
|
|
900
|
-
const onEnd = () => onInterrupt();
|
|
901
|
-
const onData = (data) => {
|
|
902
|
-
const chunk = data.toString("utf8");
|
|
903
|
-
if (chunk.startsWith("\x1B")) return;
|
|
904
|
-
for (const char of chunk) {
|
|
905
|
-
if (char === "\r" || char === "\n") {
|
|
906
|
-
finish();
|
|
907
|
-
resolve(value);
|
|
908
|
-
return;
|
|
909
|
-
}
|
|
910
|
-
if (char === "" || char === "") {
|
|
911
|
-
onInterrupt();
|
|
912
|
-
return;
|
|
913
|
-
}
|
|
914
|
-
if (char === "" || char === "\b") value = Array.from(value).slice(0, -1).join("");
|
|
915
|
-
else if (char >= " ") value += char;
|
|
916
20
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
stdin.on("data", onData);
|
|
922
|
-
stdin.once("end", onEnd);
|
|
923
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
// dist/cli/auth-cli.js
|
|
927
|
-
function authCheckErrorMessage(error) {
|
|
928
|
-
return error instanceof AuthCommandError ? error.message : "Failed to check provider readiness";
|
|
929
|
-
}
|
|
930
|
-
/**
|
|
931
|
-
* `atomic auth …` owns provider-readiness checks and the credential-export
|
|
932
|
-
* door. Its stdout guard routes all ordinary writes to stderr while a command
|
|
933
|
-
* resolves. A readiness result reaches real stdout only as a status record;
|
|
934
|
-
* the opt-in credential branch passes a Secret to emitCredential, the sole
|
|
935
|
-
* code path that can open it and write it to stdout.
|
|
936
|
-
*/
|
|
937
|
-
async function runAuthCheckCommand(command, parsed) {
|
|
938
|
-
validateAuthCheckArgs(parsed);
|
|
939
|
-
let result;
|
|
940
|
-
let credentials;
|
|
941
|
-
let modelRuntime;
|
|
942
|
-
try {
|
|
943
|
-
credentials = command.noRefresh ? new ReadOnlyAuthStorage() : AuthStorage.create();
|
|
944
|
-
modelRuntime = await createAuthCheckModelRuntime(credentials);
|
|
945
|
-
result = await checkProviderAuth(parsed, modelRuntime, {
|
|
946
|
-
refresh: !command.noRefresh,
|
|
947
|
-
credentials
|
|
948
|
-
});
|
|
949
|
-
} catch (error) {
|
|
950
|
-
console.error(chalk.red(`Error: ${authCheckErrorMessage(error)}`));
|
|
951
|
-
result = {
|
|
952
|
-
status: "invalid",
|
|
953
|
-
reason: "invalid_state"
|
|
954
|
-
};
|
|
955
|
-
}
|
|
956
|
-
let credentialEmitted = false;
|
|
957
|
-
if (command.credentials && result.status === "ready" && credentials && modelRuntime) {
|
|
958
|
-
const readyResult = result;
|
|
959
|
-
if (!hasExplicitCredentialExportTarget(parsed, modelRuntime, readyResult.provider)) {
|
|
960
|
-
console.error(chalk.red("Error: Credential export requires --provider or an exact --model target"));
|
|
961
|
-
result = {
|
|
962
|
-
status: "invalid",
|
|
963
|
-
provider: readyResult.provider,
|
|
964
|
-
reason: "invalid_state"
|
|
965
|
-
};
|
|
966
|
-
} else try {
|
|
967
|
-
const credential = await getProviderCredential(readyResult.provider, modelRuntime, credentials, { refresh: !command.noRefresh });
|
|
968
|
-
if (credential) {
|
|
969
|
-
await emitCredential(credential, command.json ? {
|
|
970
|
-
status: readyResult.status,
|
|
971
|
-
provider: readyResult.provider,
|
|
972
|
-
authType: readyResult.authType
|
|
973
|
-
} : void 0);
|
|
974
|
-
credentialEmitted = true;
|
|
975
|
-
} else result = {
|
|
976
|
-
status: "not_ready",
|
|
977
|
-
provider: readyResult.provider,
|
|
978
|
-
reason: "credential_not_available"
|
|
979
|
-
};
|
|
980
|
-
} catch (error) {
|
|
981
|
-
if (error instanceof CredentialPrintError) throw error;
|
|
982
|
-
console.error(chalk.red("Error: Failed to resolve credential for export"));
|
|
983
|
-
result = {
|
|
984
|
-
status: "invalid",
|
|
985
|
-
provider: readyResult.provider,
|
|
986
|
-
reason: "invalid_state"
|
|
987
|
-
};
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
if (!credentialEmitted) {
|
|
991
|
-
if (command.credentials && !command.json) console.error(result.status);
|
|
992
|
-
else {
|
|
993
|
-
const output = command.json ? JSON.stringify(result) : result.status;
|
|
994
|
-
writeRawStdout(`${output}\n`);
|
|
995
|
-
await flushRawStdout();
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
process.exitCode = result.status === "ready" ? 0 : result.status === "not_ready" ? 1 : 2;
|
|
999
|
-
}
|
|
1000
|
-
async function runAuthLoginCommand(args) {
|
|
1001
|
-
const settingsManager = SettingsManager.create(process.cwd(), getAgentDir(), { projectTrusted: false });
|
|
1002
|
-
const modelRuntime = await ModelRuntime.create({ allowModelNetwork: false });
|
|
1003
|
-
const controller = new AbortController();
|
|
1004
|
-
const interrupt = () => controller.abort();
|
|
1005
|
-
process.on("SIGINT", interrupt);
|
|
1006
|
-
try {
|
|
1007
|
-
return await runAuthLogin(args, {
|
|
1008
|
-
modelRuntime,
|
|
1009
|
-
terminal: createProcessLoginTerminal(interrupt),
|
|
1010
|
-
getDeviceId: () => settingsManager.getOrCreateDeviceId(),
|
|
1011
|
-
signal: controller.signal
|
|
21
|
+
return undefined;
|
|
22
|
+
})().then((found) => {
|
|
23
|
+
if (found === undefined && releases.get(key) === current) releases.delete(key);
|
|
24
|
+
return found;
|
|
1012
25
|
});
|
|
1013
|
-
|
|
1014
|
-
|
|
26
|
+
releases.set(key, current);
|
|
27
|
+
release = current;
|
|
1015
28
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
terminal: {
|
|
1021
|
-
write: (line) => console.log(line),
|
|
1022
|
-
error: (line) => console.error(line)
|
|
1023
|
-
},
|
|
1024
|
-
signal: AbortSignal.timeout(15e3)
|
|
29
|
+
const running = await release;
|
|
30
|
+
if (running === undefined || running.version === "0.10.5-alpha.1") throw error;
|
|
31
|
+
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.5-alpha.1 while this session was running; restart it to keep using this feature.", {
|
|
32
|
+
cause: error,
|
|
1025
33
|
});
|
|
1026
34
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
printAuthCommandHelp();
|
|
1030
|
-
return true;
|
|
1031
|
-
}
|
|
1032
|
-
if (args[0] === "auth" && args[1] === "login") {
|
|
1033
|
-
process.exitCode = await runAuthLoginCommand(args.slice(2).filter((arg) => arg !== "--offline"));
|
|
1034
|
-
return true;
|
|
1035
|
-
}
|
|
1036
|
-
if (args[0] === "auth" && args[1] === "logout") {
|
|
1037
|
-
process.exitCode = await runAuthLogoutCommand(args.slice(2).filter((arg) => arg !== "--offline"));
|
|
1038
|
-
return true;
|
|
1039
|
-
}
|
|
1040
|
-
let command;
|
|
1041
|
-
try {
|
|
1042
|
-
command = parseAuthCommand(args);
|
|
1043
|
-
} catch (error) {
|
|
1044
|
-
const failure = error instanceof AuthCommandError ? error : new AuthCommandError("Failed to parse auth command");
|
|
1045
|
-
console.error(chalk.red(`Error: ${failure.message}`));
|
|
1046
|
-
process.exitCode = failure.exitCode;
|
|
1047
|
-
return true;
|
|
1048
|
-
}
|
|
1049
|
-
if (!command) return false;
|
|
1050
|
-
takeOverStdout();
|
|
1051
|
-
try {
|
|
1052
|
-
const parsed = parseArgs(command.args);
|
|
1053
|
-
if (parsed.debug) setEnvValue(ENV_DEBUG, "1");
|
|
1054
|
-
if (command.kind === "check") {
|
|
1055
|
-
if (parsed.unknownFlags.size > 0) {
|
|
1056
|
-
const option = parsed.unknownFlags.keys().next().value;
|
|
1057
|
-
console.error(chalk.red(`Unknown option --${option} for "${getAuthCommandName(command.kind)}".`));
|
|
1058
|
-
console.error(chalk.dim(`Use "${getAuthCommandUsage(command.kind)}".`));
|
|
1059
|
-
process.exitCode = 2;
|
|
1060
|
-
return true;
|
|
1061
|
-
}
|
|
1062
|
-
const errors = parsed.diagnostics.filter((diagnostic) => diagnostic.type === "error");
|
|
1063
|
-
if (errors.length > 0) {
|
|
1064
|
-
for (const error of errors) console.error(chalk.red(`Error: ${error.message}`));
|
|
1065
|
-
process.exitCode = 2;
|
|
1066
|
-
return true;
|
|
1067
|
-
}
|
|
1068
|
-
} else if (parsed.diagnostics.some((diagnostic) => diagnostic.type === "error")) {
|
|
1069
|
-
for (const diagnostic of parsed.diagnostics) console.error(chalk.red(`Error: ${diagnostic.message}`));
|
|
1070
|
-
process.exitCode = 1;
|
|
1071
|
-
return true;
|
|
1072
|
-
}
|
|
1073
|
-
if (command.kind === "check") {
|
|
1074
|
-
try {
|
|
1075
|
-
await runAuthCheckCommand(command, parsed);
|
|
1076
|
-
} catch (error) {
|
|
1077
|
-
if (error instanceof CredentialPrintError) {
|
|
1078
|
-
console.error(chalk.red(`Error: ${error.message}`));
|
|
1079
|
-
process.exitCode = error.exitCode;
|
|
1080
|
-
} else {
|
|
1081
|
-
console.error(chalk.red(`Error: ${authCheckErrorMessage(error)}`));
|
|
1082
|
-
process.exitCode = 2;
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
return true;
|
|
1086
|
-
}
|
|
1087
|
-
try {
|
|
1088
|
-
validateCredentialPrintArgs(parsed);
|
|
1089
|
-
await emitCredential(await resolveCredentialForPrint(parsed, await ModelRuntime.create({ allowModelNetwork: false }), command.kind, command.minExpiryMs), void 0);
|
|
1090
|
-
} catch (error) {
|
|
1091
|
-
const failure = toCredentialPrintError(error);
|
|
1092
|
-
console.error(chalk.red(`Error: ${failure.message}`));
|
|
1093
|
-
process.exitCode = failure.exitCode;
|
|
1094
|
-
}
|
|
1095
|
-
} finally {
|
|
1096
|
-
restoreStdout();
|
|
1097
|
-
}
|
|
1098
|
-
return true;
|
|
1099
|
-
}
|
|
1100
|
-
export { runAuthCommand };
|
|
1101
|
-
|
|
1102
|
-
//# sourceMappingURL=auth-cli.js.map
|
|
35
|
+
export const { runAuthCommand } = module;
|
|
36
|
+
//# sourceMappingURL=auth-cli.js.map
|