@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.60
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 +402 -1
- package/README.md +516 -190
- package/dist/acp-package.d.ts +5 -1
- package/dist/acp-package.js +19 -2
- package/dist/adapters.d.ts +23 -2
- package/dist/adapters.js +106 -33
- package/dist/agent-delete.d.ts +6 -9
- package/dist/agent-delete.js +5 -3
- package/dist/agent-package.js +11 -1
- package/dist/agents-store.js +1 -1
- package/dist/answer-text.d.ts +3 -0
- package/dist/answer-text.js +22 -0
- package/dist/api-only.d.ts +2 -2
- package/dist/api-only.js +3 -3
- package/dist/archil-routes.d.ts +4 -1
- package/dist/archil-routes.js +15 -12
- package/dist/archil-settings.d.ts +18 -8
- package/dist/archil-settings.js +35 -17
- package/dist/attach-conformance.js +5 -4
- package/dist/box-paths.d.ts +3 -2
- package/dist/box-paths.js +5 -4
- package/dist/browser-computer.d.ts +3 -8
- package/dist/browser-computer.js +12 -35
- package/dist/browser-cost.js +94 -20
- package/dist/capacity.d.ts +1 -1
- package/dist/capacity.js +3 -3
- package/dist/chatgpt-plan.d.ts +7 -0
- package/dist/chatgpt-plan.js +35 -11
- package/dist/claude-login-token.d.ts +20 -11
- package/dist/claude-login-token.js +175 -107
- package/dist/claude-login.d.ts +124 -33
- package/dist/claude-login.js +562 -85
- package/dist/claude-sign-in.d.ts +3 -0
- package/dist/claude-sign-in.js +10 -1
- package/dist/cli-learning/connections.js +1 -1
- package/dist/cli.js +323 -292
- package/dist/composio-made.d.ts +1 -6
- package/dist/composio-made.js +1 -6
- package/dist/composio-owners.d.ts +26 -0
- package/dist/composio-owners.js +36 -0
- package/dist/composio-preset.d.ts +56 -23
- package/dist/composio-preset.js +173 -77
- package/dist/composio-triggers.d.ts +4 -4
- package/dist/composio-triggers.js +6 -7
- package/dist/compute-cost.js +11 -2
- package/dist/computer-attach.d.ts +6 -3
- package/dist/computer-attach.js +41 -29
- package/dist/computer-held-routes.d.ts +1 -1
- package/dist/computer-held-routes.js +9 -4
- package/dist/computer-keys.d.ts +11 -1
- package/dist/computer-keys.js +26 -1
- package/dist/computer-record.js +3 -1
- package/dist/computer-view.d.ts +5 -3
- package/dist/computer-view.js +10 -6
- package/dist/computer-viewer.js +36 -7
- package/dist/computers.d.ts +2 -1
- package/dist/computers.js +6 -3
- package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
- package/dist/console/assets/backend-QnwGVBeU.js +166 -0
- package/dist/console/assets/index-DZi-muIj.js +629 -0
- package/dist/console/assets/share-pz61zIn9.js +6 -0
- package/dist/console/assets/styles-CcceGcu2.js +291 -0
- package/dist/console/assets/styles-fjQBFfMv.css +1 -0
- package/dist/console/index.html +4 -3
- package/dist/console/share.html +17 -0
- package/dist/decisions.d.ts +17 -7
- package/dist/decisions.js +41 -15
- package/dist/dial-relay.js +10 -4
- package/dist/docker-daemon.js +4 -5
- package/dist/docker-host-addresses.js +29 -11
- package/dist/email/account.d.ts +6 -0
- package/dist/email/account.js +6 -0
- package/dist/email/authentication.d.ts +21 -0
- package/dist/email/authentication.js +106 -0
- package/dist/email/email-faux.d.ts +11 -2
- package/dist/email/email-faux.js +21 -5
- package/dist/email/mail.d.ts +25 -0
- package/dist/email/mail.js +58 -2
- package/dist/email/names.js +2 -2
- package/dist/email/tools.d.ts +9 -4
- package/dist/email/tools.js +95 -13
- package/dist/env-switch.d.ts +12 -2
- package/dist/env-switch.js +23 -3
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/factory-activity.d.ts +68 -0
- package/dist/factory-activity.js +153 -0
- package/dist/factory-runs.d.ts +11 -0
- package/dist/factory-runs.js +52 -0
- package/dist/fal-price.d.ts +11 -1
- package/dist/fal-price.js +33 -0
- package/dist/faux-computers.js +1 -1
- package/dist/filed-answer.d.ts +2 -2
- package/dist/filed-answer.js +2 -2
- package/dist/filed-tool.d.ts +32 -0
- package/dist/filed-tool.js +122 -0
- package/dist/graph-served.d.ts +10 -5
- package/dist/graph-served.js +40 -10
- package/dist/handed-values.js +1 -2
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +45 -12
- package/dist/harness-keys.d.ts +1 -2
- package/dist/harness-keys.js +10 -8
- package/dist/harness-opencode/facts.js +2 -0
- package/dist/harness-recipe-entry.d.ts +9 -3
- package/dist/harness-recipe-entry.js +18 -9
- package/dist/harness-recipe.d.ts +21 -0
- package/dist/harness-recipe.js +25 -3
- package/dist/harness-table.d.ts +12 -0
- package/dist/harness-table.js +21 -6
- package/dist/harness.js +6 -2
- package/dist/helper-env.d.ts +4 -1
- package/dist/helper-env.js +4 -1
- package/dist/host-check.d.ts +2 -3
- package/dist/host-check.js +13 -7
- package/dist/hosted-search.js +1 -1
- package/dist/import-worker.js +2 -2
- package/dist/import.d.ts +20 -8
- package/dist/import.js +448 -187
- package/dist/key-refusal.d.ts +14 -2
- package/dist/key-refusal.js +97 -33
- package/dist/learn/audit.d.ts +28 -27
- package/dist/learn/audit.js +87 -62
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +35 -43
- package/dist/learn/commit.js +62 -270
- package/dist/learn/compile.d.ts +9 -6
- package/dist/learn/compile.js +51 -28
- package/dist/learn/corrections.js +1 -1
- package/dist/learn/delete.d.ts +5 -12
- package/dist/learn/delete.js +17 -30
- package/dist/learn/field-check.d.ts +111 -0
- package/dist/learn/field-check.js +174 -0
- package/dist/learn/forget-run.d.ts +16 -0
- package/dist/learn/forget-run.js +53 -0
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning-of.d.ts +0 -4
- package/dist/learn/learning-of.js +0 -5
- package/dist/learn/ledger.d.ts +32 -29
- package/dist/learn/ledger.js +26 -19
- package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
- package/dist/learn/{folder.js → legacy/folder.js} +4 -7
- package/dist/learn/legacy/place.d.ts +16 -0
- package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
- package/dist/learn/legacy/scrub.d.ts +28 -0
- package/dist/learn/legacy/scrub.js +258 -0
- package/dist/learn/promote.d.ts +119 -102
- package/dist/learn/promote.js +119 -262
- package/dist/learn/reset-ledger.d.ts +18 -0
- package/dist/learn/reset-ledger.js +14 -0
- package/dist/learn/rows.d.ts +186 -0
- package/dist/learn/rows.js +376 -0
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/workflow-draft.d.ts +4 -1
- package/dist/learn/workflow-draft.js +12 -2
- package/dist/learned-nodes.d.ts +8 -5
- package/dist/learned-nodes.js +8 -5
- package/dist/learned-workflow.d.ts +2 -1
- package/dist/learned-workflow.js +13 -10
- package/dist/learning-cost.d.ts +25 -8
- package/dist/learning-cost.js +23 -8
- package/dist/learning-reset.d.ts +1 -1
- package/dist/learning-reset.js +9 -11
- package/dist/learning-routes.d.ts +60 -81
- package/dist/learning-routes.js +187 -360
- package/dist/learning-setting.d.ts +6 -0
- package/dist/learning-setting.js +11 -1
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +2 -0
- package/dist/learning.d.ts +18 -24
- package/dist/learning.js +35 -66
- package/dist/listen-first.d.ts +5 -4
- package/dist/listen-first.js +4 -5
- package/dist/live-reach.d.ts +7 -0
- package/dist/live-reach.js +7 -0
- package/dist/mcp-api-only-origins.d.ts +15 -0
- package/dist/mcp-api-only-origins.js +40 -0
- package/dist/mcp-gateway.d.ts +22 -2
- package/dist/mcp-gateway.js +85 -11
- package/dist/mcp-oauth.d.ts +1 -1
- package/dist/mcp-oauth.js +3 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +3 -0
- package/dist/mcp-resources.d.ts +1 -1
- package/dist/mcp-secret-writes.d.ts +24 -2
- package/dist/mcp-secret-writes.js +30 -2
- package/dist/mcp-servers-store.d.ts +52 -14
- package/dist/mcp-servers-store.js +165 -61
- package/dist/mcp-sources.d.ts +1 -2
- package/dist/mcp-sources.js +1 -2
- package/dist/mcp-store.d.ts +5 -5
- package/dist/mcp-store.js +3 -3
- package/dist/mcp.js +1 -1
- package/dist/model-gateway.d.ts +1 -1
- package/dist/model-gateway.js +20 -36
- package/dist/native/discovery.d.ts +6 -0
- package/dist/native/discovery.js +14 -1
- package/dist/native/remote.d.ts +5 -0
- package/dist/native/remote.js +16 -0
- package/dist/native/runtime.js +3 -2
- package/dist/observation/observer.d.ts +6 -6
- package/dist/ollama-provider.d.ts +23 -9
- package/dist/ollama-provider.js +49 -20
- package/dist/openapi.js +290 -79
- package/dist/otel/genai.d.ts +83 -7
- package/dist/otel/genai.js +69 -9
- package/dist/otel/tracer.d.ts +42 -13
- package/dist/otel/tracer.js +241 -56
- package/dist/page.d.ts +7 -1
- package/dist/page.js +76 -22
- package/dist/paid-calls.d.ts +6 -4
- package/dist/paid-calls.js +15 -7
- package/dist/place-offers.d.ts +58 -34
- package/dist/place-offers.js +96 -54
- package/dist/place.d.ts +41 -20
- package/dist/place.js +97 -47
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +3 -2
- package/dist/provider.js +17 -8
- package/dist/purged-workflow.d.ts +0 -33
- package/dist/purged-workflow.js +3 -71
- package/dist/redact/match.d.ts +42 -9
- package/dist/redact/match.js +356 -54
- package/dist/run-census.d.ts +1 -1
- package/dist/run-census.js +4 -5
- package/dist/run-cut.js +4 -5
- package/dist/run-export-store.d.ts +15 -0
- package/dist/run-export-store.js +30 -0
- package/dist/run-export.d.ts +139 -0
- package/dist/run-export.js +379 -0
- package/dist/run-file-cut.d.ts +5 -0
- package/dist/run-file-cut.js +13 -0
- package/dist/run-launch.d.ts +3 -3
- package/dist/run-launch.js +16 -3
- package/dist/run-learning-served.d.ts +3 -3
- package/dist/run-learning-served.js +1 -1
- package/dist/run-listing.d.ts +1 -1
- package/dist/run-model-key.d.ts +15 -6
- package/dist/run-model-key.js +30 -31
- package/dist/run-reads-over-store.js +4 -4
- package/dist/run-secrets.js +3 -5
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +8 -5
- package/dist/runnable.js +26 -9
- package/dist/runner/adapter-loop.d.ts +35 -18
- package/dist/runner/adapter-loop.js +94 -47
- package/dist/runner/adapter-run-spec.d.ts +14 -1
- package/dist/runner/adapter-run-spec.js +73 -46
- package/dist/runner/adapters/pi.js +4 -2
- package/dist/runner/audit.d.ts +10 -9
- package/dist/runner/audit.js +64 -67
- package/dist/runner/beside.js +5 -6
- package/dist/runner/claim-secrets.d.ts +10 -3
- package/dist/runner/claim-secrets.js +29 -13
- package/dist/runner/cli-run-spec.d.ts +18 -0
- package/dist/runner/cli-run-spec.js +87 -58
- package/dist/runner/compare-end.d.ts +2 -3
- package/dist/runner/compare-end.js +30 -11
- package/dist/runner/conformance/harness.js +2 -3
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/disk-free.d.ts +15 -4
- package/dist/runner/disk-free.js +25 -7
- package/dist/runner/feedback-round.d.ts +1 -1
- package/dist/runner/feedback-round.js +2 -2
- package/dist/runner/harness-loops.js +3 -4
- package/dist/runner/held.d.ts +5 -12
- package/dist/runner/held.js +0 -25
- package/dist/runner/journal-kinds.d.ts +8 -2
- package/dist/runner/journal-kinds.js +23 -5
- package/dist/runner/learned-first.d.ts +0 -2
- package/dist/runner/learned-first.js +23 -7
- package/dist/runner/learning-end.d.ts +14 -24
- package/dist/runner/learning-end.js +52 -94
- package/dist/runner/learning-seed.d.ts +13 -16
- package/dist/runner/learning-seed.js +13 -23
- package/dist/runner/live-ticker.js +7 -5
- package/dist/runner/loop-contract.d.ts +0 -2
- package/dist/runner/loop.d.ts +7 -0
- package/dist/runner/loop.js +1 -0
- package/dist/runner/main.js +13 -12
- package/dist/runner/mcp-claim.js +21 -5
- package/dist/runner/mcp-run.d.ts +4 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/meta-tools.js +3 -2
- package/dist/runner/metrics.d.ts +7 -0
- package/dist/runner/metrics.js +19 -0
- package/dist/runner/model-route.d.ts +10 -7
- package/dist/runner/model-route.js +79 -15
- package/dist/runner/native-loop.js +12 -11
- package/dist/runner/presence.d.ts +1 -4
- package/dist/runner/presence.js +6 -8
- package/dist/runner/promotion.d.ts +39 -36
- package/dist/runner/promotion.js +168 -112
- package/dist/runner/redact.d.ts +3 -1
- package/dist/runner/redact.js +5 -3
- package/dist/runner/reflect-hook.d.ts +2 -2
- package/dist/runner/reflect-hook.js +4 -1
- package/dist/runner/responses-fetch.d.ts +36 -0
- package/dist/runner/responses-fetch.js +511 -0
- package/dist/runner/run-child-host.d.ts +21 -14
- package/dist/runner/run-child-host.js +187 -141
- package/dist/runner/run-child.js +11 -4
- package/dist/runner/runner-check.js +5 -1
- package/dist/runner/runner.d.ts +3 -4
- package/dist/runner/runner.js +13 -9
- package/dist/runner/sdk-loop.js +10 -12
- package/dist/runner/spec-holds.d.ts +8 -1
- package/dist/runner/spec-holds.js +9 -4
- package/dist/runner/workflow-calls.d.ts +9 -0
- package/dist/runner/workflow-calls.js +150 -0
- package/dist/runner/workflow-first.d.ts +120 -32
- package/dist/runner/workflow-first.js +218 -94
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/runs-over-store.js +8 -7
- package/dist/save-once.d.ts +14 -0
- package/dist/save-once.js +31 -0
- package/dist/scrub-command.d.ts +34 -31
- package/dist/scrub-command.js +116 -147
- package/dist/sdk/check.d.ts +1 -4
- package/dist/sdk/check.js +2 -3
- package/dist/sdk/runs.d.ts +26 -7
- package/dist/sdk/runs.js +194 -78
- package/dist/seal-key.js +4 -4
- package/dist/secret-cut.d.ts +3 -0
- package/dist/secret-cut.js +7 -1
- package/dist/secret-rules.d.ts +8 -1
- package/dist/secret-rules.js +482 -53
- package/dist/secrets.d.ts +55 -9
- package/dist/secrets.js +345 -21
- package/dist/server-fs.d.ts +1 -1
- package/dist/server-fs.js +1 -1
- package/dist/server-keys.d.ts +10 -3
- package/dist/server-keys.js +16 -3
- package/dist/server-secrets-store.js +2 -4
- package/dist/server.d.ts +30 -18
- package/dist/server.js +520 -238
- package/dist/share-context.d.ts +22 -0
- package/dist/share-context.js +76 -0
- package/dist/shell-lex.d.ts +105 -0
- package/dist/shell-lex.js +646 -0
- package/dist/sign-ins-store.d.ts +5 -7
- package/dist/sign-ins-store.js +12 -16
- package/dist/sign-ins.d.ts +7 -11
- package/dist/sign-ins.js +40 -41
- package/dist/skills/agentrun-serve/SKILL.md +5 -2
- package/dist/source-sync/auxiliary.js +2 -2
- package/dist/start-switches.d.ts +6 -5
- package/dist/start-switches.js +8 -4
- package/dist/stats.d.ts +5 -1
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/dialect.d.ts +4 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/mcp-record-keys.d.ts +10 -0
- package/dist/store/mcp-record-keys.js +13 -0
- package/dist/store/postgres/dialect.js +2 -0
- package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
- package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
- package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
- package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +60 -11
- package/dist/store/schema.js +147 -17
- package/dist/store/seal.d.ts +4 -1
- package/dist/store/sqlite/learning-rows.d.ts +23 -0
- package/dist/store/sqlite/learning-rows.js +559 -0
- package/dist/store/sqlite/run-launch.d.ts +3 -10
- package/dist/store/sqlite/run-launch.js +12 -23
- package/dist/store/sqlite/run-patch.d.ts +17 -10
- package/dist/store/sqlite/run-patch.js +50 -13
- package/dist/store/sqlite/store.d.ts +9 -0
- package/dist/store/sqlite/store.js +194 -46
- package/dist/store/store-schema.js +3 -4
- package/dist/store/store.d.ts +286 -38
- package/dist/store/store.js +27 -11
- package/dist/store-reads/analytics.d.ts +2 -1
- package/dist/store-reads/analytics.js +7 -5
- package/dist/store-reads/journal.d.ts +33 -3
- package/dist/store-reads/journal.js +99 -4
- package/dist/store-reads/learning.d.ts +50 -45
- package/dist/store-reads/learning.js +153 -116
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-reads/stats.d.ts +2 -2
- package/dist/store-reads/stats.js +13 -7
- package/dist/store-view.d.ts +24 -2
- package/dist/store-view.js +49 -17
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.js +29 -13
- package/dist/template-eval.d.ts +72 -9
- package/dist/template-eval.js +358 -64
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +31 -4
- package/dist/timeline/labels.d.ts +1 -1
- package/dist/timeline/labels.js +4 -3
- package/dist/timeline/timeline.d.ts +23 -11
- package/dist/timeline/timeline.js +115 -31
- package/dist/timeline/web-calls.d.ts +8 -6
- package/dist/timeline/web-calls.js +10 -6
- package/dist/tool-gate.d.ts +13 -1
- package/dist/tool-gate.js +43 -3
- package/dist/tool-keys-store.js +2 -4
- package/dist/tool-keys.d.ts +11 -0
- package/dist/tool-keys.js +16 -0
- package/dist/tool-plane.d.ts +54 -13
- package/dist/tool-plane.js +103 -32
- package/dist/tools.d.ts +5 -1
- package/dist/tools.js +7 -7
- package/dist/trigger-email.js +12 -6
- package/dist/triggers.d.ts +15 -34
- package/dist/triggers.js +119 -126
- package/dist/validate.d.ts +8 -1
- package/dist/validate.js +163 -23
- package/dist/web-fake.d.ts +2 -1
- package/dist/web-fake.js +8 -6
- package/dist/web-fetch.d.ts +8 -6
- package/dist/web-fetch.js +13 -11
- package/dist/web-holds.d.ts +34 -0
- package/dist/web-holds.js +89 -0
- package/dist/web-run.d.ts +32 -5
- package/dist/web-run.js +76 -28
- package/dist/web-save.js +23 -12
- package/dist/web-search.js +14 -25
- package/dist/wires.d.ts +4 -3
- package/dist/wires.js +5 -4
- package/dist/workspace/archil-claim.d.ts +12 -5
- package/dist/workspace/archil-claim.js +45 -5
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.d.ts +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/attach.js +52 -19
- package/dist/workspace/attached-computers.d.ts +6 -2
- package/dist/workspace/attached-computers.js +5 -4
- package/dist/workspace/computer-deps.d.ts +23 -6
- package/dist/workspace/computer-deps.js +38 -18
- package/dist/workspace/computer-for-claim.d.ts +21 -4
- package/dist/workspace/computer-for-claim.js +160 -54
- package/dist/workspace/computer-intervals.d.ts +2 -0
- package/dist/workspace/computer-intervals.js +1 -1
- package/dist/workspace/computer-janitor.d.ts +48 -14
- package/dist/workspace/computer-janitor.js +153 -44
- package/dist/workspace/computer-kept.d.ts +158 -32
- package/dist/workspace/computer-kept.js +288 -63
- package/dist/workspace/computer-providers.d.ts +19 -4
- package/dist/workspace/computer-providers.js +40 -6
- package/dist/workspace/index.d.ts +2 -3
- package/dist/workspace/index.js +2 -3
- package/dist/workspace/local.js +41 -1
- package/dist/workspace/mount-revoke-left.d.ts +31 -0
- package/dist/workspace/mount-revoke-left.js +72 -0
- package/dist/workspace/paired-route.js +4 -5
- package/dist/workspace/paths.d.ts +0 -4
- package/dist/workspace/paths.js +0 -6
- package/dist/workspace/resolve-computer.d.ts +5 -2
- package/dist/workspace/resolve-computer.js +9 -3
- package/dist/workspace/run-end-computers.d.ts +11 -5
- package/dist/workspace/run-end-computers.js +153 -28
- package/dist/workspace/run-tools.d.ts +22 -3
- package/dist/workspace/run-tools.js +17 -5
- package/dist/workspace/run-workspace.d.ts +14 -1
- package/dist/workspace/run-workspace.js +34 -1
- package/dist/workspace/workspace.d.ts +7 -1
- package/dist/workspace/workspace.js +1 -1
- package/package.json +13 -14
- package/skills/agentrun-serve/SKILL.md +5 -2
- package/templates/README.md +22 -6
- package/templates/TOOLS.md +46 -0
- package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
- package/dist/console/assets/index-Bwn1oTem.css +0 -1
- package/dist/console/assets/index-DPh29cyz.js +0 -747
- package/dist/workspace/learning-workspace.d.ts +0 -24
- /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
package/dist/claude-login.js
CHANGED
|
@@ -13,15 +13,17 @@
|
|
|
13
13
|
// for a server one person runs: it is refused where more than one person can start runs, `on` included, and the owner
|
|
14
14
|
// confirms they alone run agents here. It runs only in a runner place, on the machine the owner turned it on for.
|
|
15
15
|
import { createHash, randomBytes } from "node:crypto";
|
|
16
|
-
import { accessSync, chmodSync, closeSync, constants, existsSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, renameSync, rmSync,
|
|
16
|
+
import { accessSync, chmodSync, closeSync, constants, existsSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readlinkSync, readSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
17
17
|
import { homedir, userInfo } from "node:os";
|
|
18
|
-
import { delimiter, isAbsolute, join } from "node:path";
|
|
19
|
-
import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
|
|
20
|
-
import { registerSecretWrite } from "./secret-writes.js";
|
|
18
|
+
import { basename, delimiter, dirname, isAbsolute, join } from "node:path";
|
|
19
|
+
import { facts as claudeFacts, loginRefresh } from "@parcha/agentrun-harness-claude/facts";
|
|
20
|
+
import { registerSecretPage, registerSecretWrite } from "./secret-writes.js";
|
|
21
|
+
import { copyEnv } from "./secrets.js";
|
|
21
22
|
// Every operation here is the owner's session's alone (secret-writes.ts): no answer holds a credential, but turning a
|
|
22
23
|
// person's plan on for this server's runs, and starting its sign-in, are the owner's to do.
|
|
23
|
-
for (const operation of ["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLogin", "startClaudeLogin"])
|
|
24
|
+
for (const operation of ["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLogin", "startClaudeLogin", "signOutClaudeLogin"])
|
|
24
25
|
registerSecretWrite(operation, () => true);
|
|
26
|
+
registerSecretPage("signOutClaudeLogin", "/#/settings/keys");
|
|
25
27
|
/** The switch: `off` (or 0, false, no) turns the mode off on this server, `on` (or 1, true, yes) leaves it there past
|
|
26
28
|
* loopback; unset, the listen address decides (claudeLoginSwitchedOff). */
|
|
27
29
|
export const CLAUDE_LOGIN_ENV = "AGENTRUN_CLAUDE_CODE_LOGIN";
|
|
@@ -109,38 +111,270 @@ export function machineId(data) {
|
|
|
109
111
|
* read it against a working directory this server does not share. `source` says which rule gave the folder.
|
|
110
112
|
* `credentials`: the server's `CLAUDE_SECURESTORAGE_CONFIG_DIR` when it sets one the CLI takes as it is (an absolute
|
|
111
113
|
* path, or empty: `~/.claude`, and on macOS the Keychain item with no suffix), where the CLI keeps the tokens apart
|
|
112
|
-
* from the folder; a relative one is not taken, as above.
|
|
113
|
-
|
|
114
|
+
* from the folder; a relative one is not taken, as above. `uid`: the server's user, whose home (homeOf) holds the
|
|
115
|
+
* default folder. For the view alone: the folder is the real path this machine's login has (loginAt) where its user may
|
|
116
|
+
* use it, else the folder as the env names it (givenFolder). Nothing a CLI is handed comes from here. */
|
|
117
|
+
export function machineFolder(env = process.env, uid = process.geteuid?.()) {
|
|
114
118
|
const secure = env.CLAUDE_SECURESTORAGE_CONFIG_DIR;
|
|
115
119
|
const credentials = secure === "" || (secure && isAbsolute(secure)) ? { credentials: secure } : {};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
const folder = loginAt("machine", "", env, uid).login?.dir ?? givenFolder("machine", "", env);
|
|
121
|
+
return { folder, source: absolute(env, "CLAUDE_CONFIG_DIR") ? "CLAUDE_CONFIG_DIR" : "default", ...credentials };
|
|
122
|
+
}
|
|
123
|
+
/** AgentRun's own login directory in the data folder `data`. */
|
|
124
|
+
export const agentRunLoginDir = (data) => join(data, "claude-login");
|
|
125
|
+
/** The login's folder at `place` as the env names it, for the view to show where the login is refused: AgentRun's own
|
|
126
|
+
* in `data`, or this machine's `CLAUDE_CONFIG_DIR`, else `~/.claude` in the env's HOME. Never handed to a CLI. */
|
|
127
|
+
const givenFolder = (place, data, env) => (place === "agentrun" ? agentRunLoginDir(data) : (absolute(env, "CLAUDE_CONFIG_DIR") ?? join(absolute(env, "HOME") ?? homedir(), ".claude")));
|
|
128
|
+
/** The env's `name` when it is an absolute path, else undefined. */
|
|
129
|
+
const absolute = (env, name) => {
|
|
130
|
+
const value = env[name];
|
|
131
|
+
return value && isAbsolute(value) ? value : undefined;
|
|
132
|
+
};
|
|
133
|
+
/** The most links one path may pass through, as Linux's own limit (past it, ELOOP). */
|
|
134
|
+
const MAX_LINKS = 40;
|
|
135
|
+
/** A folder's mode bits that let its group write in it, and anyone, and the sticky bit, which keeps each entry in such a
|
|
136
|
+
* folder its maker's (/tmp, say). */
|
|
137
|
+
const GROUP_WRITE = 0o020;
|
|
138
|
+
const OTHER_WRITE = 0o002;
|
|
139
|
+
const STICKY = 0o1000;
|
|
140
|
+
/** The system's account files: its users (name:password:uid:gid:…) and its groups (name:password:gid:members). */
|
|
141
|
+
const PASSWD_FILE = "/etc/passwd";
|
|
142
|
+
const GROUP_FILE = "/etc/group";
|
|
143
|
+
/** The name service switch: for each database (`passwd`, `group`, …), the sources the system asks for its entries. */
|
|
144
|
+
const NSSWITCH_FILE = "/etc/nsswitch.conf";
|
|
145
|
+
/** The sources that serve users and groups from the account files alone. `files` reads them; `compat` reads them too, and
|
|
146
|
+
* asks a directory service only at a `+` or `-` line, which privateGroup refuses. Not `systemd`: besides its dynamic
|
|
147
|
+
* users it serves systemd's user records (userdb), whose membership records and homed users' `memberOf` put users in a
|
|
148
|
+
* group the group file does not list. Nor sss, ldap, nis, winbind, db or any other: their users and groups are not in
|
|
149
|
+
* these files. */
|
|
150
|
+
const LOCAL_SOURCES = new Set(["files", "compat"]);
|
|
151
|
+
/** Whether the name service switch takes users and groups from the account files alone, so that what they say of a group
|
|
152
|
+
* is all there is: its `passwd` and `group` lines, and an `initgroups` line where there is one (it, not `group`, then
|
|
153
|
+
* gives each user's other groups), name no source but LOCAL_SOURCES. A bracketed action (`[NOTFOUND=return]`) names
|
|
154
|
+
* none. False where it cannot say: no `passwd` or `group` line, or one that names no source. Throws where the file
|
|
155
|
+
* cannot be read (privateGroup's false). */
|
|
156
|
+
function localAccounts() {
|
|
157
|
+
const lines = readFileSync(NSSWITCH_FILE, "utf8").split("\n").map((line) => line.replace(/#.*/, ""));
|
|
158
|
+
const sourcesOf = (database) => lines.flatMap((line) => {
|
|
159
|
+
const entry = /^\s*([^\s:]+)\s*:(.*)$/.exec(line);
|
|
160
|
+
return entry && entry[1].toLowerCase() === database ? [entry[2].replace(/\[[^\]]*\]/g, " ").split(/\s+/).filter(Boolean)] : [];
|
|
161
|
+
});
|
|
162
|
+
const [users, groups, initgroups] = ["passwd", "group", "initgroups"].map(sourcesOf);
|
|
163
|
+
return users.length > 0 && groups.length > 0 && [...users, ...groups, ...initgroups].every((sources) => sources.length > 0 && sources.every((source) => LOCAL_SOURCES.has(source)));
|
|
164
|
+
}
|
|
165
|
+
/** A whole decimal id from an account file's field, else undefined (an empty field is no id). */
|
|
166
|
+
const idOf = (field) => (field !== undefined && /^\d+$/.test(field) ? Number(field) : undefined);
|
|
167
|
+
/** A group file's password fields that give the group no password there: `x`, `!` and `*` (locked), and none. Any other
|
|
168
|
+
* is one, and newgrp lets anyone who knows it into the group. `x` says only that the group's password, if it has one,
|
|
169
|
+
* is in /etc/gshadow, with the members newgrp lets in without it; a server without privileges cannot read that file,
|
|
170
|
+
* so this check does not, and a password or member gpasswd sets there is not seen (gpasswd -r and gpasswd -d remove
|
|
171
|
+
* them). */
|
|
172
|
+
const NO_GROUP_PASSWORD = new Set(["x", "!", "*", ""]);
|
|
173
|
+
/** The words a group-writable folder's refusal ends in where its group would be the user's private one but for a password
|
|
174
|
+
* the group file gives it: which group, and why. */
|
|
175
|
+
const groupPasswordWords = (group, gid) => ` Its group ${group} (gid ${gid}) would be the server's user's private group, but /etc/group gives it a password, which lets anyone who knows it join the group (newgrp); removing the password (gpasswd -r ${group}) mends that too.`;
|
|
176
|
+
/** Whether group `gid` is user `uid`'s private group, so a folder only its group and its owner may write in is still the
|
|
177
|
+
* user's alone (the umask ruling: a umask of 002, under a group of the user's own, makes folders 0775). Only where the
|
|
178
|
+
* name service switch takes users and groups from the account files alone (localAccounts), and as those files say,
|
|
179
|
+
* read as the system reads them (blanks before an entry skipped): `uid` has one entry, and no other entry has its name
|
|
180
|
+
* (a group's members are named, so a second account so named is in it too; a second entry with `uid`, an alias, is the
|
|
181
|
+
* user under a name the group may list); `gid` is its primary group; no other user has `gid` as theirs; the group file
|
|
182
|
+
* has `gid`, listing no member but that user, and gives it no password (NO_GROUP_PASSWORD). True where it is; else
|
|
183
|
+
* false, or, where only the password stands in the way, the words that say so (groupPasswordWords). False where it
|
|
184
|
+
* cannot say: a switch that also asks another source (a directory service, systemd's user records), or that it cannot
|
|
185
|
+
* read, a file it cannot read, a `+` or `-` line (the rest is a directory service's, whose members these files do not
|
|
186
|
+
* show), an id that is not a plain number (the system reads ` 1000` as 1000, which would hide an alias or a member),
|
|
187
|
+
* no entry for `uid`, or `gid` missing from the group file. */
|
|
188
|
+
function privateGroup(uid, gid) {
|
|
189
|
+
try {
|
|
190
|
+
if (!localAccounts())
|
|
191
|
+
return false;
|
|
192
|
+
const entries = (file) => readFileSync(file, "utf8")
|
|
193
|
+
.split("\n")
|
|
194
|
+
.map((line) => line.trimStart())
|
|
195
|
+
.filter((line) => line !== "" && !line.startsWith("#"))
|
|
196
|
+
.map((line) => line.split(":"));
|
|
197
|
+
const users = entries(PASSWD_FILE);
|
|
198
|
+
const groups = entries(GROUP_FILE);
|
|
199
|
+
if ([...users, ...groups].some((fields) => /^[+-]/.test(fields[0])))
|
|
200
|
+
return false;
|
|
201
|
+
if (users.some((fields) => idOf(fields[2]) === undefined || idOf(fields[3]) === undefined) || groups.some((fields) => idOf(fields[2]) === undefined))
|
|
202
|
+
return false;
|
|
203
|
+
const own = users.filter((fields) => idOf(fields[2]) === uid);
|
|
204
|
+
const name = own.length === 1 ? own[0][0] : undefined;
|
|
205
|
+
if (!name || idOf(own[0][3]) !== gid)
|
|
206
|
+
return false;
|
|
207
|
+
if (users.some((fields) => fields !== own[0] && fields[0] === name))
|
|
208
|
+
return false;
|
|
209
|
+
if (users.some((fields) => fields !== own[0] && idOf(fields[3]) === gid))
|
|
210
|
+
return false;
|
|
211
|
+
const its = groups.filter((fields) => idOf(fields[2]) === gid);
|
|
212
|
+
if (its.length === 0 || !its.every((fields) => (fields[3] ?? "").split(",").map((member) => member.trim()).every((member) => member === "" || member === name)))
|
|
213
|
+
return false;
|
|
214
|
+
const withPassword = its.find((fields) => !NO_GROUP_PASSWORD.has(fields[1] ?? ""));
|
|
215
|
+
return withPassword ? groupPasswordWords(withPassword[0], gid) : true;
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/** Where a folder with `mode` and group `gid` lets someone other than user `uid` write in it (anyone may, or its group
|
|
222
|
+
* may and that group is not the user's private one: privateGroup, asked once per group by `mine`), the words its
|
|
223
|
+
* refusal ends in, about its group (privateGroup's, else none: ""). Undefined where no one else may write in it. */
|
|
224
|
+
const openToOthers = (folder, mine) => {
|
|
225
|
+
if ((folder.mode & OTHER_WRITE) !== 0)
|
|
226
|
+
return "";
|
|
227
|
+
if ((folder.mode & GROUP_WRITE) === 0)
|
|
228
|
+
return undefined;
|
|
229
|
+
const group = mine(folder.gid);
|
|
230
|
+
return group === true ? undefined : group || "";
|
|
231
|
+
};
|
|
232
|
+
/** privateGroup for user `uid`, each group asked once: one walk (ownedFolder) reads the account files only where a folder
|
|
233
|
+
* its group may write in is met, and once per group. */
|
|
234
|
+
function privateGroupsOf(uid) {
|
|
235
|
+
const known = new Map();
|
|
236
|
+
return (gid) => {
|
|
237
|
+
let mine = known.get(gid);
|
|
238
|
+
if (mine === undefined)
|
|
239
|
+
known.set(gid, (mine = privateGroup(uid, gid)));
|
|
240
|
+
return mine;
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/** `dir` (absolute) walked one name at a time from the root, as the system walks it: an empty name (a trailing or
|
|
244
|
+
* doubled slash) and `.` name nothing, `..` goes to the folder above the real one reached so far, and each link is followed where it is met, and must be one user `uid` or root made, as must each
|
|
245
|
+
* link in the chain it leads through (another user's could be pointed elsewhere once this has looked). Gives the real
|
|
246
|
+
* folder the walk ends in (`real`: no link on its way) and the names still to make in it (`missing`, none where `dir`
|
|
247
|
+
* is there), or undefined where a link fails, a name past one still to make is `..` (from a link), or there is no way
|
|
248
|
+
* to look. */
|
|
249
|
+
function followLinks(uid, dir) {
|
|
250
|
+
try {
|
|
251
|
+
const names = dir.split("/");
|
|
252
|
+
let real = "/";
|
|
253
|
+
let links = 0;
|
|
254
|
+
for (let name = names.shift(); name !== undefined; name = names.shift()) {
|
|
255
|
+
if (name === "" || name === ".")
|
|
256
|
+
continue;
|
|
257
|
+
if (name === "..") {
|
|
258
|
+
real = dirname(real);
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
const next = join(real, name);
|
|
262
|
+
const entry = lstatSync(next, { throwIfNoEntry: false });
|
|
263
|
+
if (entry === undefined) {
|
|
264
|
+
const missing = [name, ...names].filter((left) => left !== "" && left !== ".");
|
|
265
|
+
return missing.includes("..") ? undefined : { real, missing };
|
|
266
|
+
}
|
|
267
|
+
if (!entry.isSymbolicLink()) {
|
|
268
|
+
real = next;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if ((entry.uid !== uid && entry.uid !== 0) || ++links > MAX_LINKS)
|
|
272
|
+
return undefined;
|
|
273
|
+
const target = readlinkSync(next);
|
|
274
|
+
if (isAbsolute(target))
|
|
275
|
+
real = "/";
|
|
276
|
+
names.unshift(...target.split("/"));
|
|
277
|
+
}
|
|
278
|
+
return { real, missing: [] };
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
// A file where a folder should be, or no way to look.
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/** Undefined where no user but `uid` and root can change what `real` (a real path, followLinks') leads to: each folder
|
|
286
|
+
* above it, from the root down, is a folder (no link) of that user's or root's that no one else may write in (anyone,
|
|
287
|
+
* or its group where that is not the user's private one: openToOthers, with `mine`), unless the sticky bit keeps each
|
|
288
|
+
* entry there its maker's. Else why not: a folder not theirs first, as a chmod mends no such folder, else the nearest
|
|
289
|
+
* open one. */
|
|
290
|
+
function wayHeld(uid, real, mine) {
|
|
291
|
+
try {
|
|
292
|
+
let open;
|
|
293
|
+
for (let at = dirname(real), last = real; at !== last; last = at, at = dirname(at)) {
|
|
294
|
+
const folder = lstatSync(at);
|
|
295
|
+
if (!folder.isDirectory() || (folder.uid !== uid && folder.uid !== 0))
|
|
296
|
+
return { not: "owned" };
|
|
297
|
+
const more = (folder.mode & STICKY) === 0 ? openToOthers(folder, mine) : undefined;
|
|
298
|
+
if (more !== undefined)
|
|
299
|
+
open ??= { not: "open", at, mode: folder.mode, more };
|
|
300
|
+
}
|
|
301
|
+
return open;
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
return { not: "owned" };
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/** Undefined where `real` is a folder (no link) of user `uid`'s that no one else may write in (openToOthers, with
|
|
308
|
+
* `mine`), sticky or not: they could put files of theirs in it, or, where the CLI makes a folder in it, make that
|
|
309
|
+
* folder first. Else why not. */
|
|
310
|
+
function heldFolder(uid, real, mine) {
|
|
311
|
+
try {
|
|
312
|
+
const folder = lstatSync(real);
|
|
313
|
+
if (!folder.isDirectory() || folder.uid !== uid)
|
|
314
|
+
return { not: "owned" };
|
|
315
|
+
const more = openToOthers(folder, mine);
|
|
316
|
+
return more === undefined ? undefined : { not: "open", at: real, mode: folder.mode, more };
|
|
317
|
+
}
|
|
318
|
+
catch {
|
|
319
|
+
return { not: "owned" };
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
/** The end of the words a folder open to others' writes (NotHeld's `open`) is refused in: which folder, its mode, and
|
|
323
|
+
* the chmod that closes it, then what more it says of its group (`more`). */
|
|
324
|
+
const openWords = (open) => `is open to writes by others than its owner: ${open.at} has mode ${(open.mode & 0o7777).toString(8).padStart(4, "0")}, which its group or anyone may write in. Make it writable by its owner alone (chmod g-w,o-w ${open.at}): a umask of 002 makes new folders so.${open.more}`;
|
|
325
|
+
/** The folder `dir` names, as the CLI is to get it, where it is one user `uid` owns; else why not. `dir` is walked as
|
|
326
|
+
* the system walks it, one name at a time (followLinks: a trailing slash or `.` names nothing, and a `..` goes up from
|
|
327
|
+
* the real folder reached so far, past any link, never from the text), so no slash hides a link and the folder is the
|
|
328
|
+
* one the CLI given `dir` would reach. Every link on its way is judged and followed, every folder above the real folder it leads to is held (wayHeld), and that folder
|
|
329
|
+
* is the user's own (heldFolder). `make`: where `dir` is not there yet, the nearest folder above it that is must be the
|
|
330
|
+
* user's own (heldFolder), since the CLI, run as that user, makes the rest there. The answer is the real path (no link
|
|
331
|
+
* left on it, plus the names still to make), which is what the login hands the CLI, so a link changed after this has
|
|
332
|
+
* looked redirects nothing, and no other user can change a folder on the way. This is the one ownership rule for the
|
|
333
|
+
* login's folders, the home's (homeOf) and those the env gives it (loginAt). `missing`: some of the folder is still to
|
|
334
|
+
* make. Else why not (NotHeld). */
|
|
335
|
+
function ownedFolder(uid, dir, make) {
|
|
336
|
+
if (!isAbsolute(dir))
|
|
337
|
+
return { not: "owned" };
|
|
338
|
+
const walked = followLinks(uid, dir);
|
|
339
|
+
if (walked === undefined || (walked.missing.length > 0 && !make))
|
|
340
|
+
return { not: "owned" };
|
|
341
|
+
// A folder that is not the user's first, as a chmod mends no such folder; else the open one.
|
|
342
|
+
const mine = privateGroupsOf(uid);
|
|
343
|
+
const way = wayHeld(uid, walked.real, mine);
|
|
344
|
+
const folder = heldFolder(uid, walked.real, mine);
|
|
345
|
+
const notHeld = way?.not === "owned" ? way : folder?.not === "owned" ? folder : (way ?? folder);
|
|
346
|
+
if (notHeld)
|
|
347
|
+
return notHeld;
|
|
348
|
+
return walked.missing.length > 0 ? { real: join(walked.real, ...walked.missing), missing: true } : { real: walked.real, missing: false };
|
|
349
|
+
}
|
|
350
|
+
/** The user `uid` as a refusal names it: its uid, and its name where this process runs as it. */
|
|
351
|
+
function userWords(uid) {
|
|
352
|
+
try {
|
|
353
|
+
const user = userInfo();
|
|
354
|
+
if (user.uid === uid && user.username)
|
|
355
|
+
return `uid ${uid} (${user.username})`;
|
|
356
|
+
}
|
|
357
|
+
catch {
|
|
358
|
+
// No entry for this user on this system.
|
|
359
|
+
}
|
|
360
|
+
return `uid ${uid}`;
|
|
119
361
|
}
|
|
120
362
|
/** The person's home: the home of the user this server runs as (`uid`, its effective uid), whose files the login's CLI
|
|
121
|
-
* writes. The env's `HOME` when it is an absolute path to a folder that user owns, else that user's own
|
|
122
|
-
* system has it (`os.userInfo()`), when it owns that
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
363
|
+
* writes. The env's `HOME` when it is an absolute path to a folder that user owns (ownedFolder), else that user's own
|
|
364
|
+
* home as the system has it (`os.userInfo()`), when it owns that; either as its real path (ownedFolder's), which the
|
|
365
|
+
* CLI is handed. So a server under a sudo that keeps `HOME` (root, with the person's) keeps its login in root's home,
|
|
366
|
+
* never root-owned files in the person's, and a service account that inherited someone's `HOME` reads its own. `apart`:
|
|
367
|
+
* the env gave a `HOME` and it was not that user's, so a terminal with that env's `HOME` is not in this home either,
|
|
368
|
+
* and the line the view shows carries it (the harness's loginCommand). Neither: `refused` says why in words, and there
|
|
369
|
+
* is no home. Each folder is walked once here (ownedFolder), and the home given is the walk's real path. Where there
|
|
370
|
+
* is no uid (Windows), the env's `HOME` when absolute, else `os.homedir()`. */
|
|
127
371
|
export function homeOf(env, uid = process.geteuid?.()) {
|
|
128
|
-
const given = env
|
|
372
|
+
const given = absolute(env, "HOME");
|
|
129
373
|
if (uid === undefined)
|
|
130
374
|
return { home: given ?? homedir() };
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
const stat = statSync(dir);
|
|
136
|
-
return stat.isDirectory() && stat.uid === uid;
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
if (owned(given))
|
|
143
|
-
return { home: given };
|
|
375
|
+
const fromEnv = given === undefined ? undefined : ownedFolder(uid, given, false);
|
|
376
|
+
if (fromEnv && fromEnv.not === undefined)
|
|
377
|
+
return { home: fromEnv.real };
|
|
144
378
|
let own;
|
|
145
379
|
try {
|
|
146
380
|
own = userInfo().homedir || undefined;
|
|
@@ -148,30 +382,94 @@ export function homeOf(env, uid = process.geteuid?.()) {
|
|
|
148
382
|
catch {
|
|
149
383
|
// No entry for this user on this system.
|
|
150
384
|
}
|
|
151
|
-
|
|
152
|
-
|
|
385
|
+
const fromOwn = own === undefined ? undefined : ownedFolder(uid, own, false);
|
|
386
|
+
if (fromOwn && fromOwn.not === undefined)
|
|
387
|
+
return { home: fromOwn.real, ...(given ? { apart: true } : {}) };
|
|
388
|
+
// A home that is the user's but open to others' writes says so, and how to close it: the env's HOME first.
|
|
389
|
+
const open = fromEnv?.not === "open" ? { which: "its HOME", home: given, ...fromEnv } : fromOwn?.not === "open" ? { which: "that user's own home", home: own, ...fromOwn } : undefined;
|
|
390
|
+
if (open)
|
|
391
|
+
return { refused: `Claude Code's login on this machine needs a home only this server's user may write in: it runs as ${userWords(uid)}, and ${open.which} (${open.home}) ${openWords(open)}` };
|
|
153
392
|
return {
|
|
154
|
-
home: own
|
|
155
|
-
refused: `Claude Code's login on this machine needs a home this server's user owns: it runs as uid ${uid}, and neither its HOME (${env.HOME || "unset"}) nor that user's own home (${own ?? "none on this system"}) is a folder it owns. Start the server as the person whose Claude plan it is.`,
|
|
393
|
+
refused: `Claude Code's login on this machine needs a home this server's user owns: it runs as ${userWords(uid)}, and neither its HOME (${env.HOME || "unset"}) nor that user's own home (${own ?? "none on this system"}) is a folder it owns. Start the server as the person whose Claude plan it is.`,
|
|
156
394
|
};
|
|
157
395
|
}
|
|
158
|
-
/** The
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
396
|
+
/** The folders the server's env gives this machine's login (loginAt), each with the variable that gives it: its config
|
|
397
|
+
* dir (`CLAUDE_CONFIG_DIR`), its credentials dir (`CLAUDE_SECURESTORAGE_CONFIG_DIR`, when absolute) and its profiles
|
|
398
|
+
* (`ANTHROPIC_CONFIG_DIR`, else `XDG_CONFIG_HOME`'s `anthropic`). Those the CLI takes from the home are not here: the
|
|
399
|
+
* home is homeOf's. */
|
|
400
|
+
function envFolders(env) {
|
|
401
|
+
const folders = [];
|
|
402
|
+
const config = absolute(env, "CLAUDE_CONFIG_DIR");
|
|
403
|
+
if (config)
|
|
404
|
+
folders.push(["CLAUDE_CONFIG_DIR", config]);
|
|
405
|
+
const secure = absolute(env, "CLAUDE_SECURESTORAGE_CONFIG_DIR");
|
|
406
|
+
if (secure)
|
|
407
|
+
folders.push(["CLAUDE_SECURESTORAGE_CONFIG_DIR", secure]);
|
|
408
|
+
const profiles = absolute(env, "ANTHROPIC_CONFIG_DIR");
|
|
409
|
+
const xdg = absolute(env, "XDG_CONFIG_HOME");
|
|
410
|
+
if (profiles)
|
|
411
|
+
folders.push(["ANTHROPIC_CONFIG_DIR", profiles]);
|
|
412
|
+
else if (xdg)
|
|
413
|
+
folders.push(["XDG_CONFIG_HOME", join(xdg, "anthropic")]);
|
|
414
|
+
return folders;
|
|
415
|
+
}
|
|
416
|
+
/** Why a login at `place` may not be used by this server's user (`uid`, its effective uid), in words; undefined when it
|
|
417
|
+
* may: loginAt's `refused`. `place` undefined (not known yet) asks the home alone, as AgentRun's own login does. A
|
|
418
|
+
* decision that hands a CLI a login takes it from loginAt itself, never from this and a second look. */
|
|
419
|
+
export function loginRefused(place, env, uid = process.geteuid?.()) {
|
|
420
|
+
return loginAt(place ?? "agentrun", "", env, uid).refused;
|
|
421
|
+
}
|
|
422
|
+
/** The login at `place` and the check of its folders, from one look at each (one walk, ownedFolder), so what a caller
|
|
423
|
+
* hands a CLI is what was checked: the login, or `refused`, why the server's user (`uid`, its effective uid unless
|
|
424
|
+
* given) may not use it, in words, and then no login at all, never one on the paths as given. The home first (homeOf).
|
|
425
|
+
* Then, for this machine's login, each folder the env gives it (envFolders): one the user owns, or would make in a
|
|
426
|
+
* folder it owns, on a way no other user can change (ownedFolder), else the CLI run as that user (root under a sudo
|
|
427
|
+
* that keeps the env, say) leaves its files in another user's folder, or in one another user can swap for theirs.
|
|
428
|
+
* AgentRun's own login keeps its folders in its data. Where there is no uid (Windows), nothing is refused, and the
|
|
429
|
+
* folders are as given.
|
|
430
|
+
*
|
|
431
|
+
* The directories: AgentRun's in `data`, or this machine's (machineFolder's rule, and the Anthropic profiles where the
|
|
432
|
+
* CLI looks for them: `ANTHROPIC_CONFIG_DIR`, else `$XDG_CONFIG_HOME/anthropic`, else `~/.config/anthropic`). This
|
|
433
|
+
* machine's on the CLI's default folder carries the person's home too, so the harness points the CLI at it as their
|
|
434
|
+
* own CLI runs, with no folder variable (the harness's signInEnv and loginEnv). This machine's with a credentials dir
|
|
435
|
+
* in the server's env (machineFolder's `credentials`) carries it as `secure`, absolute (empty: `~/.claude`,
|
|
436
|
+
* `unsuffixed`), so the CLI keeps the tokens where the person's own CLI with it does. A status check at either place
|
|
437
|
+
* runs on a copy of the account file (the harness's claudeLoginStatus). Every login carries the person's home as
|
|
438
|
+
* `userHome`, read here once (homeOf), so the status check, the sign-in and a run on macOS all run in that one home
|
|
439
|
+
* whatever reads it later (the harness's personHome), and `homeApart` where the env's HOME was not that home (homeOf's
|
|
440
|
+
* `apart`). AgentRun's carries `own`. The home and the folders the env gives are the real paths the walk ended in. */
|
|
441
|
+
export function loginAt(place, data, env = process.env, uid = process.geteuid?.()) {
|
|
442
|
+
const checked = homeOf(env, uid);
|
|
443
|
+
if (checked.refused !== undefined)
|
|
444
|
+
return { refused: checked.refused };
|
|
445
|
+
const { home, apart } = checked;
|
|
446
|
+
const homeAt = { userHome: home, ...(apart ? { homeApart: true } : {}) };
|
|
447
|
+
// `own`: no CLI of the person's uses AgentRun's folder, so the harness may delete the Keychain item a sign-in left
|
|
448
|
+
// there under "unknown" (its dropUnknownItem).
|
|
169
449
|
if (place === "agentrun")
|
|
170
|
-
return { dir:
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
|
|
450
|
+
return { login: { dir: agentRunLoginDir(data), profiles: join(agentRunLoginDir(data), "anthropic"), ...homeAt, own: true }, toMake: [] };
|
|
451
|
+
const real = new Map();
|
|
452
|
+
const toMake = [];
|
|
453
|
+
for (const [name, folder] of envFolders(env)) {
|
|
454
|
+
if (uid === undefined) {
|
|
455
|
+
real.set(name, folder);
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
const owned = ownedFolder(uid, folder, true);
|
|
459
|
+
const refused = `Claude Code's login on this machine needs its folders to be this server's user's own: it runs as ${userWords(uid)}, and ${folder}, the folder ${name} gives it,`;
|
|
460
|
+
if (owned.not === "open")
|
|
461
|
+
return { refused: `${refused} ${openWords(owned)}` };
|
|
462
|
+
if (owned.not === "owned")
|
|
463
|
+
return { refused: `${refused} is not a folder it owns, nor one it would make in a folder it owns. Start the server as the person whose Claude plan it is.` };
|
|
464
|
+
real.set(name, owned.real);
|
|
465
|
+
if (owned.missing)
|
|
466
|
+
toMake.push(owned.real);
|
|
467
|
+
}
|
|
468
|
+
const config = real.get("CLAUDE_CONFIG_DIR");
|
|
469
|
+
const credentials = env.CLAUDE_SECURESTORAGE_CONFIG_DIR === "" ? join(home, ".claude") : real.get("CLAUDE_SECURESTORAGE_CONFIG_DIR");
|
|
470
|
+
const secure = credentials === undefined ? {} : { secure: credentials, ...(env.CLAUDE_SECURESTORAGE_CONFIG_DIR === "" ? { unsuffixed: true } : {}) };
|
|
471
|
+
const profiles = real.get("ANTHROPIC_CONFIG_DIR") ?? real.get("XDG_CONFIG_HOME") ?? join(home, ".config", "anthropic");
|
|
472
|
+
return { login: { dir: config ?? join(home, ".claude"), profiles, ...(config === undefined ? { home } : {}), ...secure, ...homeAt }, toMake };
|
|
175
473
|
}
|
|
176
474
|
/** The setting as saved, or undefined when the mode is not on (or the row is not one this reads). */
|
|
177
475
|
export async function claudeLoginSetting(settings) {
|
|
@@ -183,11 +481,12 @@ export async function claudeLoginSetting(settings) {
|
|
|
183
481
|
/** Whether `setting` was turned on for this machine: the one whose data folder (`data`) holds its id (machineId). */
|
|
184
482
|
const thisMachine = (setting, data) => setting.machine === machineId(data);
|
|
185
483
|
/** The login a run here goes on: the setting's, when the switch is not off, this is the machine it was turned on for,
|
|
186
|
-
* and the server's user
|
|
187
|
-
|
|
188
|
-
|
|
484
|
+
* and the server's user (`uid`, its effective uid unless given) may use its folders: loginAt's login, from its one look
|
|
485
|
+
* at them. */
|
|
486
|
+
export function loginOf(setting, data, env, uid = process.geteuid?.()) {
|
|
487
|
+
if (!setting || claudeLoginOff(env) || !thisMachine(setting, data))
|
|
189
488
|
return undefined;
|
|
190
|
-
return loginAt(setting.place, data, env);
|
|
489
|
+
return loginAt(setting.place, data, env, uid).login;
|
|
191
490
|
}
|
|
192
491
|
const LOGIN = Symbol.for("agentrun.claude-login");
|
|
193
492
|
/** Whether `login` is a reader of its access token, not its directories. */
|
|
@@ -202,11 +501,12 @@ export function withClaudeLogin(env, login) {
|
|
|
202
501
|
return env;
|
|
203
502
|
}
|
|
204
503
|
/** `env` as a run at `place` reads it: a runner place keeps the login; any other place (a sandbox) gets a copy without it,
|
|
205
|
-
* so a revision's checks there ask for a key, as its run will.
|
|
504
|
+
* so a revision's checks there ask for a key, as its run will. The copy is copyEnv's, which keeps withSecrets' keys
|
|
505
|
+
* (read by name, never enumerated), where a spread would keep none. */
|
|
206
506
|
export function envAtPlace(env, place) {
|
|
207
507
|
if (place?.mode === "runner" || env[LOGIN] === undefined)
|
|
208
508
|
return env;
|
|
209
|
-
return withClaudeLogin(
|
|
509
|
+
return withClaudeLogin(copyEnv(env), undefined);
|
|
210
510
|
}
|
|
211
511
|
/** The login `env` carries, unless the switch is off. */
|
|
212
512
|
export function claudeLoginOf(env) {
|
|
@@ -282,22 +582,27 @@ export function turnOnBody(body) {
|
|
|
282
582
|
* can keep its login there; nothing in it is read. */
|
|
283
583
|
export function settingFor(place, data) {
|
|
284
584
|
if (place === "agentrun")
|
|
285
|
-
mkdirSync(
|
|
585
|
+
mkdirSync(agentRunLoginDir(data), { recursive: true, mode: 0o700 });
|
|
286
586
|
return { v: 1, place, machine: machineId(data), only_me: true };
|
|
287
587
|
}
|
|
288
588
|
/** The login a run of `harness` on this runner goes on: the saved setting's, read now, when the switch is not off, the
|
|
289
589
|
* harness runs on it, the run is in a runner place (`place`), and this is the machine it was turned on for; else none,
|
|
290
|
-
* and the run goes on the model keys. */
|
|
291
|
-
export async function loginForRun(settings, data, env, harness, place) {
|
|
590
|
+
* and the run goes on the model keys. `uid`: as loginOf's. */
|
|
591
|
+
export async function loginForRun(settings, data, env, harness, place, uid = process.geteuid?.()) {
|
|
292
592
|
if (harness === undefined || !LOGIN_HARNESSES.includes(harness) || claudeLoginOff(env) || place.mode !== "runner")
|
|
293
593
|
return undefined;
|
|
294
|
-
return loginOf(await claudeLoginSetting(settings), data, env);
|
|
594
|
+
return loginOf(await claudeLoginSetting(settings), data, env, uid);
|
|
295
595
|
}
|
|
296
596
|
/** The routes here (server.ts): every one answers 404, by its name, while the mode is off (`why`). */
|
|
297
|
-
export const CLAUDE_LOGIN_ROUTES = new Set(["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLogin", "startClaudeLogin"]);
|
|
597
|
+
export const CLAUDE_LOGIN_ROUTES = new Set(["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLogin", "startClaudeLogin", "signOutClaudeLogin"]);
|
|
598
|
+
/** Whether the claude-login routes answer here, the one rule the routes and capabilities' `features.claude_login` both
|
|
599
|
+
* read: none while the mode is switched off (`off`, claudeLoginSwitchedOff's reason), and none on an API-only server
|
|
600
|
+
* (`apiOnly`), whose route list holds none of them, so it refuses them before routing (server.ts). */
|
|
601
|
+
export const claudeLoginServed = (off, apiOnly) => !off && !apiOnly;
|
|
298
602
|
export const claudeLoginRouteOff = (name, why) => `${name}: Claude Code's login on this machine is off on this server: ${why}.`;
|
|
299
|
-
/** Why the routes may not turn the mode on or sign in now: the server's own refusal, else
|
|
300
|
-
|
|
603
|
+
/** Why the routes may not turn the mode on at `place`, or sign in there, now: the server's own refusal, else folders of
|
|
604
|
+
* the login its user may not use (loginRefused; `place` undefined, not known yet: the home alone). */
|
|
605
|
+
const refusedHere = (deps, place) => deps.refused() ?? loginRefused(place, deps.env, deps.uid);
|
|
301
606
|
/** What the one-owner rule gives the login's routes over a server's keys: `refused`, which counts the keys each time
|
|
302
607
|
* it is asked, and `turn`, the keys' own. The server's routes take both from here, and so does the test that runs the
|
|
303
608
|
* turn-on against a held revocation: neither is a value read once, or a turn of its own. */
|
|
@@ -305,6 +610,27 @@ export const oneOwnerDeps = (facts, keys) => ({
|
|
|
305
610
|
refused: () => whyNotOneOwner({ ...facts, keys: keys.count }),
|
|
306
611
|
turn: (work) => keys.inTurn(work),
|
|
307
612
|
});
|
|
613
|
+
/** The login `at` (loginAt's, at `place`, not refused) with its folders still to make made by AgentRun, 0700 whatever
|
|
614
|
+
* the umask, in the folders its check found the server's user's own (no other user can make them first there), and
|
|
615
|
+
* then checked again: the CLI is handed that check's login, or the route refuses in its words. Made so, a folder the
|
|
616
|
+
* CLI would make under a umask of 002 (0775, open to its group) is not refused once the CLI has signed in there, and the
|
|
617
|
+
* CLI, finding it made, leaves its mode. A folder that can't be made is left to the check again, and to the CLI. */
|
|
618
|
+
function madeLogin(at, place, deps) {
|
|
619
|
+
if (at.toMake.length === 0)
|
|
620
|
+
return at.login;
|
|
621
|
+
for (const folder of at.toMake) {
|
|
622
|
+
try {
|
|
623
|
+
mkdirSync(folder, { recursive: true, mode: 0o700 });
|
|
624
|
+
}
|
|
625
|
+
catch {
|
|
626
|
+
// Left to the check again.
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
const again = loginAt(place, deps.data, deps.env, deps.uid);
|
|
630
|
+
if (again.refused !== undefined)
|
|
631
|
+
throw new ClaudeLoginRefused("forbidden", again.refused);
|
|
632
|
+
return again.login;
|
|
633
|
+
}
|
|
308
634
|
/** A route's refusal in words, answered as its `code` (server.ts makes it an ApiError). */
|
|
309
635
|
export class ClaudeLoginRefused extends Error {
|
|
310
636
|
code;
|
|
@@ -317,19 +643,23 @@ export class ClaudeLoginRefused extends Error {
|
|
|
317
643
|
export async function claudeLoginView(deps) {
|
|
318
644
|
const setting = await claudeLoginSetting(deps.settings);
|
|
319
645
|
const place = setting?.place ?? "agentrun";
|
|
320
|
-
|
|
646
|
+
// One look at the login's folders decides the line, the folder shown and the status check (loginAt). Where they are
|
|
647
|
+
// refused there is no login: no line (it would sign in on folders the server's user may not use), and the folder is
|
|
648
|
+
// shown as the env names it.
|
|
649
|
+
const { login, refused: unusable } = loginAt(place, deps.data, deps.env, deps.uid);
|
|
321
650
|
const cli = loginCli(await deps.pinned(), deps.env);
|
|
322
651
|
const signIn = deps.signIns.view();
|
|
323
|
-
const
|
|
324
|
-
const
|
|
325
|
-
const base = { place, command: (await deps.claude()).claudeLoginCommand(login, cli ?? "claude"), can_start: deps.sameMachine && cli !== undefined && refused === undefined, ...(refused ? { refused } : {}), folder: login.dir, machine: machineFolder(deps.env), ...(signIn ? { sign_in: signIn } : {}) };
|
|
652
|
+
const refused = deps.refused() ?? unusable;
|
|
653
|
+
const base = { place, command: login ? (await deps.claude()).claudeLoginCommand(login, cli ?? "claude") : "", can_start: deps.sameMachine && cli !== undefined && refused === undefined, ...(refused ? { refused } : {}), folder: login?.dir ?? givenFolder(place, deps.data, deps.env), machine: machineFolder(deps.env, deps.uid), ...(signIn ? { sign_in: signIn } : {}) };
|
|
326
654
|
if (!setting)
|
|
327
655
|
return { state: "off", ...base };
|
|
328
656
|
if (!thisMachine(setting, deps.data))
|
|
329
657
|
return { state: "other_machine", ...base, can_start: false };
|
|
330
|
-
//
|
|
331
|
-
|
|
332
|
-
|
|
658
|
+
// Folders the server's user may not use: no login here (loginOf), and the CLI is not asked, since its check runs in
|
|
659
|
+
// that home, on those folders. Still turned on (dropRefusedLogin keeps it), so the view says so with why, and the
|
|
660
|
+
// owner can turn it off.
|
|
661
|
+
if (!login)
|
|
662
|
+
return { state: "refused", ...base };
|
|
333
663
|
if (!cli)
|
|
334
664
|
return { state: "no_cli", ...base };
|
|
335
665
|
try {
|
|
@@ -343,6 +673,20 @@ export async function claudeLoginView(deps) {
|
|
|
343
673
|
return { state: "unknown", ...base };
|
|
344
674
|
}
|
|
345
675
|
}
|
|
676
|
+
/** What AgentRun's own login folder (`<data>/claude-login`) leads to where it is a link (the link's text); else
|
|
677
|
+
* undefined, a folder or nothing there. */
|
|
678
|
+
function loginFolderLink(data) {
|
|
679
|
+
const dir = agentRunLoginDir(data);
|
|
680
|
+
try {
|
|
681
|
+
return lstatSync(dir, { throwIfNoEntry: false })?.isSymbolicLink() ? readlinkSync(dir) : undefined;
|
|
682
|
+
}
|
|
683
|
+
catch {
|
|
684
|
+
return undefined;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
/** Why a turn-on is refused where AgentRun's own login folder (`dir`) is a link (to `to`). A sign-out removes that folder
|
|
688
|
+
* whole, so it is one AgentRun keeps itself, and no link leads a sign-out into a folder elsewhere. */
|
|
689
|
+
export const loginFolderIsLink = (dir, to) => `AgentRun's own Claude login folder ${dir} is a link (to ${to}). AgentRun keeps its login in a folder of its own, which a sign-out removes whole, so it never follows a link there: remove the link, then turn it on again.`;
|
|
346
690
|
/** PUT /settings/claude-login: turned on, refused in one line where more than one person can start runs. A turn-on that
|
|
347
691
|
* moves the login to another place first ends a sign-in this server started that still waits: its CLI signs in at the
|
|
348
692
|
* old place, which the login no longer reads. One at the same place leaves it waiting, as it still signs in there. */
|
|
@@ -354,26 +698,38 @@ export async function turnOnClaudeLogin(deps, body) {
|
|
|
354
698
|
// is written, and the person starts the sign-in again once the key is revoked. The sign-in's stop and
|
|
355
699
|
// what follows the write (the reading again, the CLI's status) are outside the keys' turn, so a key's revocation never
|
|
356
700
|
// waits on the CLI.
|
|
357
|
-
const refusal = () => {
|
|
358
|
-
const refused = refusedHere(deps);
|
|
701
|
+
const refusal = (place) => {
|
|
702
|
+
const refused = refusedHere(deps, place);
|
|
359
703
|
if (refused)
|
|
360
704
|
throw new ClaudeLoginRefused("forbidden", refused);
|
|
361
705
|
};
|
|
362
706
|
const asked = await deps.turn(async () => {
|
|
363
|
-
refusal();
|
|
707
|
+
refusal(undefined);
|
|
364
708
|
const asked = turnOnBody(body);
|
|
365
709
|
if ("problem" in asked)
|
|
366
710
|
throw new ClaudeLoginRefused("input_invalid", asked.problem);
|
|
711
|
+
refusal(asked.place);
|
|
367
712
|
return asked;
|
|
368
713
|
});
|
|
369
714
|
await deps.signIns.serial(async (turn) => {
|
|
370
715
|
if ((await claudeLoginSetting(deps.settings))?.place !== asked.place)
|
|
371
716
|
await turn.stop();
|
|
372
717
|
await deps.turn(async () => {
|
|
373
|
-
refusal()
|
|
718
|
+
// The refusal and the login the server is handed are one look at the folders (loginAt).
|
|
719
|
+
const refused = deps.refused();
|
|
720
|
+
if (refused)
|
|
721
|
+
throw new ClaudeLoginRefused("forbidden", refused);
|
|
722
|
+
const at = loginAt(asked.place, deps.data, deps.env, deps.uid);
|
|
723
|
+
if (at.refused !== undefined)
|
|
724
|
+
throw new ClaudeLoginRefused("forbidden", at.refused);
|
|
725
|
+
const linked = asked.place === "agentrun" ? loginFolderLink(deps.data) : undefined;
|
|
726
|
+
if (linked !== undefined)
|
|
727
|
+
throw new ClaudeLoginRefused("forbidden", loginFolderIsLink(agentRunLoginDir(deps.data), linked));
|
|
728
|
+
// Its folders still to make are made here (madeLogin), so a sign-in from the line shown finds them made 0700.
|
|
729
|
+
const login = madeLogin(at, asked.place, deps);
|
|
374
730
|
const setting = settingFor(asked.place, deps.data);
|
|
375
731
|
await deps.settings.put(CLAUDE_LOGIN_SETTING, setting);
|
|
376
|
-
deps.saved(
|
|
732
|
+
deps.saved(claudeLoginOff(deps.env) ? undefined : login);
|
|
377
733
|
});
|
|
378
734
|
});
|
|
379
735
|
await deps.changed();
|
|
@@ -390,18 +746,130 @@ export async function turnOffClaudeLogin(deps) {
|
|
|
390
746
|
await deps.changed();
|
|
391
747
|
return claudeLoginView(deps);
|
|
392
748
|
}
|
|
749
|
+
/** What may remain where the CLI didn't confirm its own sign-out (`why`, the CLI's step as it went). */
|
|
750
|
+
const keychainMayRemain = (why) => `${why}, so on macOS its Keychain item for this login may remain: remove it in Keychain Access (its name starts with "Claude Code-credentials").`;
|
|
751
|
+
const KEYCHAIN_MAY_REMAIN = keychainMayRemain("Claude Code's own sign-out didn't confirm");
|
|
752
|
+
/** The Keychain's words where the CLI's step threw before the CLI ran (`failed`, the error's words), else where it didn't confirm. */
|
|
753
|
+
const keychainWords = (failed) => failed === undefined ? KEYCHAIN_MAY_REMAIN : keychainMayRemain(`Claude Code's own sign-out could not run (${failed})`);
|
|
754
|
+
/** What a sign-out answers beside `confirmed: false`: the login is gone here, and the CLI said nothing of its own copy. */
|
|
755
|
+
export const LOGIN_SIGN_OUT_UNCONFIRMED = `Signed out here: AgentRun's copy of the login is removed. ${KEYCHAIN_MAY_REMAIN}`;
|
|
756
|
+
/** What a sign-out answers beside `confirmed: false` where the CLI's step threw (`failed`, the error's words): the login is
|
|
757
|
+
* gone here all the same, and the CLI's own copy may remain. */
|
|
758
|
+
export const signOutCliFailed = (failed) => `Signed out here: AgentRun's copy of the login is removed. ${keychainWords(failed)}`;
|
|
759
|
+
/** What a sign-out answers beside `confirmed: false` where some of the login is still there (`left`: each thing, its path
|
|
760
|
+
* and why), and the Keychain's words too where the CLI didn't confirm its own sign-out (`keychain`), naming the CLI
|
|
761
|
+
* step's failure where it threw (`failed`). */
|
|
762
|
+
export const signOutLeft = (left, keychain, failed) => `Signed out here, and the mode is off, but some of AgentRun's copy of the login remains: ${left.join("; ")}. Remove it by hand before turning the mode on again.${keychain ? ` ${keychainWords(failed)}` : ""}`;
|
|
763
|
+
/** Why a sign-out of this machine's own login (`folder`, the person's `~/.claude` or CLAUDE_CONFIG_DIR) is refused. */
|
|
764
|
+
export const machineSignOutRefused = (folder) => `This is your own Claude Code login on this machine (${folder}), which AgentRun only uses: it never signs it out. Run \`claude auth logout\` in a terminal there to sign it out, or turn the mode off here.`;
|
|
765
|
+
/** POST /settings/claude-login/sign-out: AgentRun's own login (`<data>/claude-login`) signed out and removed, so the next
|
|
766
|
+
* turn-on finds none and the person signs in fresh, to the same account or another. In one turn on the sign-ins' queue
|
|
767
|
+
* (no sign-in or turn-on lands in between): a sign-in this server started that still waits is ended; the mode is turned
|
|
768
|
+
* off, so no new run goes on the login while it goes; the pinned CLI's own sign-out (the harness's claudeLogout) runs on
|
|
769
|
+
* the folder, so it removes its credentials file and, on macOS, the Keychain item named from the folder. It runs where
|
|
770
|
+
* the folder is gone too: a retry after a sign-out the CLI didn't confirm finds no folder, and the Keychain item may
|
|
771
|
+
* remain, so the answer is confirmed only where the CLI confirms. Then the folder is removed whatever the CLI said (a
|
|
772
|
+
* folder the CLI made as it signed out too) (credentials, account, profiles, the CLI's refresh lock, and
|
|
773
|
+
* the CLI's older lock beside it), with the login's signed-in note (noteAnswer) and this process's token reader of it
|
|
774
|
+
* (claude-login-token.ts forgetLoginTokens). Each removal stands alone: one that fails is named in the answer
|
|
775
|
+
* (signOutLeft, `confirmed` false), and the others, the reader's drop and the server's reread of the keys still happen.
|
|
776
|
+
* So with the CLI's step: a throw finding the CLI or loading the harness is named in the answer (signOutCliFailed), and
|
|
777
|
+
* every removal still runs.
|
|
778
|
+
* Where the folder is a link (put there after the turn-on, which refuses one), the link alone is removed, with the
|
|
779
|
+
* login's signed-in note: no CLI runs through it, nothing it leads to is touched, and the answer names it. Runs already going are left as a turn-off
|
|
780
|
+
* leaves them: each keeps the token its CLI holds, and fails in
|
|
781
|
+
* LOGIN_SIGNED_OUT's words at its next read of the login; one claimed on it and started while the mode is off is refused
|
|
782
|
+
* at its start (claude-login-token.ts LOGIN_CHANGED_SINCE_CLAIM). That check is of the folder, not the account, so one
|
|
783
|
+
* started after a turn-on and a new sign-in runs on that sign-in. A run whose CLI reads the folder itself (in the
|
|
784
|
+
* runner's process) holds the refresh token and may write a renewed pair back after the folder goes; nothing here
|
|
785
|
+
* removes it again. A login on this machine's own folder (`machine`) is the person's:
|
|
786
|
+
* refused (machineSignOutRefused), with nothing touched. */
|
|
787
|
+
export async function signOutClaudeLogin(deps) {
|
|
788
|
+
let off = false;
|
|
789
|
+
let signedOut = true;
|
|
790
|
+
let cliFailed;
|
|
791
|
+
const left = [];
|
|
792
|
+
const remove = (what, path, options) => {
|
|
793
|
+
try {
|
|
794
|
+
rmSync(path, options);
|
|
795
|
+
}
|
|
796
|
+
catch (error) {
|
|
797
|
+
left.push(`${what} ${path} (${error.code ?? String(error)})`);
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
try {
|
|
801
|
+
await deps.signIns.serial(async (turn) => {
|
|
802
|
+
if ((await claudeLoginSetting(deps.settings))?.place === "machine")
|
|
803
|
+
throw new ClaudeLoginRefused("forbidden", machineSignOutRefused(machineFolder(deps.env, deps.uid).folder));
|
|
804
|
+
await turn.stop();
|
|
805
|
+
await deps.settings.remove(CLAUDE_LOGIN_SETTING);
|
|
806
|
+
deps.saved(undefined);
|
|
807
|
+
off = true;
|
|
808
|
+
const dir = agentRunLoginDir(deps.data);
|
|
809
|
+
const linked = loginFolderLink(deps.data);
|
|
810
|
+
const note = answerFile(deps.data, { dir, profiles: join(dir, "anthropic") });
|
|
811
|
+
try {
|
|
812
|
+
if (linked !== undefined) {
|
|
813
|
+
// A link put there after the turn-on (which refuses one, loginFolderIsLink): the link alone goes, no CLI runs
|
|
814
|
+
// through it, and nothing it leads to is touched. The login's signed-in note, in the data folder, goes too.
|
|
815
|
+
signedOut = false;
|
|
816
|
+
remove("the link", dir, { force: true });
|
|
817
|
+
remove("the login's signed-in note", note, { force: true });
|
|
818
|
+
left.push(`${linked}, where the link ${dir} led, left as it was`);
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
// The CLI's step in its own try: a throw finding the CLI or loading the harness skips no removal below, and the
|
|
822
|
+
// answer names it.
|
|
823
|
+
try {
|
|
824
|
+
const { login } = loginAt("agentrun", deps.data, deps.env, deps.uid);
|
|
825
|
+
const cli = loginCli(await deps.pinned(), deps.env);
|
|
826
|
+
signedOut = login && cli ? await (await deps.claude()).claudeLogout(cli, login, pathOf(deps.env)) : false;
|
|
827
|
+
}
|
|
828
|
+
catch (error) {
|
|
829
|
+
signedOut = false;
|
|
830
|
+
cliFailed = error instanceof Error ? error.message : String(error);
|
|
831
|
+
}
|
|
832
|
+
// The older lock sits beside the folder in the data folder's real path. The folder's own real path is never
|
|
833
|
+
// followed: a link swapped in during the CLI's await would lead the lock's removal outside the data folder.
|
|
834
|
+
let beside = dir;
|
|
835
|
+
try {
|
|
836
|
+
beside = join(realpathSync(dirname(dir)), basename(dir));
|
|
837
|
+
}
|
|
838
|
+
catch {
|
|
839
|
+
// The folder as named.
|
|
840
|
+
}
|
|
841
|
+
remove("the login's folder", dir, { recursive: true, force: true });
|
|
842
|
+
remove("the CLI's older lock", `${beside}${loginRefresh.legacyLockSuffix}`, { recursive: true, force: true });
|
|
843
|
+
remove("the login's signed-in note", note, { force: true });
|
|
844
|
+
}
|
|
845
|
+
finally {
|
|
846
|
+
(await import("./claude-login-token.js")).forgetLoginTokens(dir);
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
finally {
|
|
851
|
+
if (off)
|
|
852
|
+
await deps.changed();
|
|
853
|
+
}
|
|
854
|
+
const message = left.length > 0 ? signOutLeft(left, !signedOut, cliFailed) : signedOut ? undefined : cliFailed !== undefined ? signOutCliFailed(cliFailed) : LOGIN_SIGN_OUT_UNCONFIRMED;
|
|
855
|
+
return { confirmed: message === undefined, ...(message ? { message } : {}), login: await claudeLoginView(deps) };
|
|
856
|
+
}
|
|
393
857
|
/** POST /settings/claude-login/login: the CLI's own sign-in, started on this machine, where it opens a browser, with the
|
|
394
858
|
* shown line's own variables (the harness's signInEnv), so it signs in where the status reads. A sign-in that
|
|
395
859
|
* still waits is ended first (deps.signIns). The browser code goes to the CLI, never here; the answer is the view as it
|
|
396
860
|
* is when the sign-in starts, its `sign_in` waiting. The setting is read, and the CLI started on it, in one turn. */
|
|
397
861
|
export async function startLoginHere(deps) {
|
|
398
|
-
const refused = refusedHere(deps);
|
|
862
|
+
const refused = refusedHere(deps, undefined);
|
|
399
863
|
if (refused)
|
|
400
864
|
throw new ClaudeLoginRefused("forbidden", refused);
|
|
401
865
|
await deps.signIns.serial(async (signIn) => {
|
|
402
866
|
const setting = await claudeLoginSetting(deps.settings);
|
|
403
867
|
if (!setting)
|
|
404
868
|
throw new ClaudeLoginRefused("agent_not_runnable", "Turn on Claude Code's login on this machine first.");
|
|
869
|
+
// The refusal and the login the CLI is started on are one look at the folders (loginAt).
|
|
870
|
+
const at = loginAt(setting.place, deps.data, deps.env, deps.uid);
|
|
871
|
+
if (at.refused !== undefined)
|
|
872
|
+
throw new ClaudeLoginRefused("forbidden", at.refused);
|
|
405
873
|
if (!thisMachine(setting, deps.data))
|
|
406
874
|
throw new ClaudeLoginRefused("agent_not_runnable", "It was turned on for another machine: sign in there.");
|
|
407
875
|
if (!deps.sameMachine)
|
|
@@ -411,22 +879,31 @@ export async function startLoginHere(deps) {
|
|
|
411
879
|
throw new ClaudeLoginRefused("agent_not_runnable", "No Claude Code CLI here yet: claude-agent's first run installs it, or run the command shown.");
|
|
412
880
|
// The person's home (the login's `userHome`) and desktop, so the CLI can open their browser.
|
|
413
881
|
const claude = await deps.claude();
|
|
414
|
-
|
|
882
|
+
// Its folders still to make are made first, and checked again (madeLogin): the CLI signs in on that check's login.
|
|
883
|
+
const login = madeLogin(at, setting.place, deps);
|
|
415
884
|
await signIn.start((timeoutMs) => claude.startClaudeLogin(cli, login, { ...pathOf(deps.env), display: deps.env, timeoutMs }));
|
|
416
885
|
});
|
|
417
886
|
return claudeLoginView(deps);
|
|
418
887
|
}
|
|
419
888
|
/** At the server's start: a setting saved where the mode is now off or refused (`why`: the switch, a listen address past
|
|
420
|
-
* loopback, a second token, the API-only profile
|
|
421
|
-
* is logged.
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
889
|
+
* loopback, a second token, the API-only profile) goes, so no runner, in this process or another, runs on it; the
|
|
890
|
+
* reason is logged. One whose folders the server's user may not use (loginRefused with `env`, for the setting's place)
|
|
891
|
+
* stays, and the reason is logged: every read refuses it in words while they are so (no run, no sign-in, the view's
|
|
892
|
+
* `refused`), and the person mends that with a chmod or by starting the server as the right user, which a deleted
|
|
893
|
+
* setting would have turned off for good, or turns it off (the view's `refused` state). A turn on `signIns`' queue, as
|
|
894
|
+
* every change of the setting is. */
|
|
895
|
+
export async function dropRefusedLogin(signIns, settings, why, env, log) {
|
|
425
896
|
await signIns.serial(async () => {
|
|
426
|
-
|
|
897
|
+
const setting = await claudeLoginSetting(settings);
|
|
898
|
+
if (!setting)
|
|
427
899
|
return;
|
|
428
|
-
|
|
429
|
-
|
|
900
|
+
if (why) {
|
|
901
|
+
await settings.remove(CLAUDE_LOGIN_SETTING);
|
|
902
|
+
return log(`Claude Code's login on this machine turned off: ${why}`);
|
|
903
|
+
}
|
|
904
|
+
const refused = loginRefused(setting.place, env);
|
|
905
|
+
if (refused)
|
|
906
|
+
log(`Claude Code's login on this machine is kept, and not used while it is refused: ${refused}`);
|
|
430
907
|
});
|
|
431
908
|
}
|
|
432
909
|
const pathOf = (env) => (env.PATH ? { path: env.PATH } : {});
|