@oar-sh/oar 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/.github/extensions/web-relay/extension.mjs +0 -3
  2. package/.github/extensions/web-relay/polling/heartbeat.mjs +2 -55
  3. package/.github/extensions/web-relay/polling/polling-loop.mjs +0 -1
  4. package/.github/extensions/web-relay/runtime/api-client.mjs +2 -34
  5. package/.github/extensions/web-relay/runtime/config-loader.mjs +2 -104
  6. package/.github/extensions/web-relay/runtime/send-and-wait-errors.mjs +2 -170
  7. package/.github/extensions/web-relay/runtime/session-io.mjs +1 -71
  8. package/.github/extensions/web-relay/runtime/worker-websocket-link.mjs +2 -325
  9. package/.github/extensions/web-relay/skills/prompt-context.mjs +2 -160
  10. package/CHANGELOG.md +269 -0
  11. package/README.md +407 -424
  12. package/bin/oar.js +142 -11
  13. package/package.json +8 -4
  14. package/server/README.md +59 -22
  15. package/server/claude-worker/claude-sdk-adapter.mjs +7 -2
  16. package/server/claude-worker/claude-session-process.mjs +1013 -45
  17. package/server/claude-worker/claude-session-worker.mjs +54 -9
  18. package/server/claude-worker/claude-turn-publisher.mjs +110 -19
  19. package/server/claude-worker/claude-worker-link-wiring.mjs +9 -0
  20. package/server/copilot-sdk-runtime.mjs +12 -3
  21. package/server/copilot-worker/copilot-ask-user-tool.mjs +89 -0
  22. package/server/copilot-worker/copilot-attachments.mjs +35 -2
  23. package/server/copilot-worker/copilot-continuation-signals.mjs +55 -0
  24. package/server/copilot-worker/copilot-model-switch.mjs +425 -0
  25. package/server/copilot-worker/copilot-prompt-context.mjs +20 -8
  26. package/server/copilot-worker/copilot-question-bridge.mjs +129 -16
  27. package/server/copilot-worker/copilot-sdk-adapter.mjs +59 -11
  28. package/server/copilot-worker/copilot-sdk-event-normalizer.mjs +136 -12
  29. package/server/copilot-worker/copilot-sdk-session-process.mjs +2753 -527
  30. package/server/copilot-worker/copilot-sdk-session-worker.mjs +94 -25
  31. package/server/cursor-worker/cursor-session-worker.mjs +5 -5
  32. package/server/cursor-worker/cursor-turn-runner.mjs +50 -4
  33. package/server/db-schema.mjs +61 -1
  34. package/server/features.mjs +155 -41
  35. package/server/grok-worker/grok-session-worker.mjs +5 -5
  36. package/server/grok-worker/grok-turn-runner.mjs +45 -4
  37. package/server/migrations/0004-steer-settle-markers.mjs +119 -0
  38. package/server/public/app/annotate-core.mjs +181 -0
  39. package/server/public/app/annotate-editor.js +617 -0
  40. package/server/public/app/api-client.js +86 -5
  41. package/server/public/app/ask-user-view.js +102 -13
  42. package/server/public/app/attachments-view.js +172 -3
  43. package/server/public/app/background-task-timeout-options.mjs +9 -0
  44. package/server/public/app/background-tasks-view.mjs +34 -19
  45. package/server/public/app/bootstrap.js +153 -69
  46. package/server/public/app/composer-control-state.mjs +52 -34
  47. package/server/public/app/context-tier-options.mjs +24 -4
  48. package/server/public/app/conversation-draft-sync.mjs +187 -0
  49. package/server/public/app/conversation-list-filter.mjs +86 -0
  50. package/server/public/app/conversation-preferences.mjs +47 -10
  51. package/server/public/app/conversation-provider-indicator.mjs +8 -0
  52. package/server/public/app/conversation-view.js +1032 -218
  53. package/server/public/app/emoji-view.js +2 -0
  54. package/server/public/app/font-scaling.js +4 -37
  55. package/server/public/app/journal-view.js +190 -24
  56. package/server/public/app/model-selector-options.mjs +185 -1
  57. package/server/public/app/new-conversation-model-choice.mjs +29 -9
  58. package/server/public/app/pwa-install.js +64 -136
  59. package/server/public/app/question-multi-select.mjs +52 -0
  60. package/server/public/app/reasoning-effort-labels.mjs +13 -3
  61. package/server/public/app/relay-prompt-sanitizer.mjs +26 -3
  62. package/server/public/app/router.js +120 -11
  63. package/server/public/app/settings-modal.js +225 -20
  64. package/server/public/app/settings-tabs.js +1 -1
  65. package/server/public/app/socket-handlers.js +47 -4
  66. package/server/public/app/steered-turn-merge.mjs +100 -0
  67. package/server/public/app/store.js +159 -16
  68. package/server/public/app/sync-outbox.mjs +16 -8
  69. package/server/public/app/tool-activity-emoji.mjs +36 -0
  70. package/server/public/app/transcript-viewport-anchor.mjs +210 -0
  71. package/server/public/app/update-ui.js +194 -0
  72. package/server/public/index.html +483 -24
  73. package/server/public/sw.js +7 -0
  74. package/server/relay-tools.md +2 -0
  75. package/server/relay.mjs +23 -21
  76. package/server/repositories/message-repository.mjs +78 -21
  77. package/server/repositories/question-repository.mjs +19 -1
  78. package/server/repositories/session-repository.mjs +7 -31
  79. package/server/routes/ask-user-routes.mjs +10 -0
  80. package/server/routes/messages-routes.mjs +689 -159
  81. package/server/routes/sessions-routes.mjs +574 -80
  82. package/server/server-runtime.mjs +393 -925
  83. package/server/services/claude-auth-service.mjs +7 -1
  84. package/server/services/cli-install-service.mjs +8 -27
  85. package/server/services/cli-process-runner.mjs +30 -0
  86. package/server/services/copilot-model-discovery-service.mjs +202 -0
  87. package/server/services/data-dir-resolution.mjs +47 -0
  88. package/server/services/grok-auth-service.mjs +9 -1
  89. package/server/services/live-turn-picker.mjs +47 -0
  90. package/server/services/model-variant-catalog-service.mjs +1183 -0
  91. package/server/services/oar-cli-helpers.mjs +6 -2
  92. package/server/services/relay-prompt-sanitizer.mjs +30 -3
  93. package/server/services/relay-question-context.mjs +46 -0
  94. package/server/services/sdk-session-import-service.mjs +144 -16
  95. package/server/services/sdk-session-sync-service.mjs +84 -27
  96. package/server/services/session-worker-registry-service.mjs +116 -3
  97. package/server/services/session-worker-supervisor-service.mjs +7 -1
  98. package/server/services/session-worker-websocket-service.mjs +119 -24
  99. package/server/services/status-event-service.mjs +8 -2
  100. package/server/services/steer-resend.mjs +45 -0
  101. package/server/services/update-check-service.mjs +220 -0
  102. package/server/services/update-install-service.mjs +279 -0
  103. package/server/services/windows-autostart-service.mjs +42 -6
  104. package/server/services/windows-boot-autostart-service.mjs +487 -0
  105. package/shared/ask-user-bridge.mjs +37 -5
  106. package/shared/background-task-timeout.mjs +12 -4
  107. package/shared/claude-model-catalog.mjs +49 -0
  108. package/shared/context-window-fallbacks.mjs +1 -0
  109. package/shared/control-poller.mjs +4 -1
  110. package/shared/copilot-model-order.mjs +182 -0
  111. package/shared/media-embed-instructions.mjs +35 -0
  112. package/shared/model-descriptors.mjs +181 -30
  113. package/shared/model-id.mjs +6 -0
  114. package/shared/pwa-app-name.mjs +44 -0
  115. package/shared/question-multi-select.mjs +16 -0
  116. package/shared/relay-stop-failure.mjs +15 -0
  117. package/shared/slash-command-guard.mjs +76 -0
  118. package/shared/steer-note.mjs +66 -0
  119. package/shared/steer-settle-failure.mjs +89 -0
  120. package/shared/steer-settle-markers.mjs +18 -0
  121. package/shared/update-semver.mjs +50 -0
  122. package/shared/worker-crash-guard.mjs +40 -14
  123. package/shared/worker-runtime/api-client.mjs +34 -0
  124. package/shared/worker-runtime/config-loader.mjs +104 -0
  125. package/shared/worker-runtime/heartbeat.mjs +109 -0
  126. package/shared/worker-runtime/prompt-context.mjs +160 -0
  127. package/shared/worker-runtime/runner-link-wiring.mjs +44 -0
  128. package/shared/worker-runtime/send-and-wait-errors.mjs +170 -0
  129. package/shared/worker-runtime/worker-websocket-link.mjs +436 -0
  130. package/server/claude-worker/claude-session-test-harness.mjs +0 -236
  131. package/server/claude-worker/fixtures/workflow-run-record.json +0 -1
  132. package/server/copilot-worker/copilot-sdk-test-harness.mjs +0 -329
  133. package/server/copilot-worker/fixtures/abort-turn.json +0 -588
  134. package/server/copilot-worker/fixtures/ask-user-turn.json +0 -1154
  135. package/server/copilot-worker/fixtures/background-timer-continuation.json +0 -445
  136. package/server/copilot-worker/fixtures/background-timer-turn.json +0 -497
  137. package/server/copilot-worker/fixtures/happy-turn.json +0 -566
  138. package/server/copilot-worker/fixtures/quota-turn.json +0 -647
  139. package/server/copilot-worker/fixtures/reasoning-turn.json +0 -625
  140. package/server/copilot-worker/fixtures/resume-turn.json +0 -700
  141. package/server/copilot-worker/fixtures/subagent-turn.json +0 -1378
  142. package/server/copilot-worker/fixtures/tool-permission-turn.json +0 -1293
  143. package/server/routes/messages-routes-test-harness.mjs +0 -111
  144. package/server/services/fixtures/claude-auth-stub.sh +0 -62
  145. package/server/services/fixtures/cli-install-stub.sh +0 -75
  146. package/server/services/fixtures/grok-stub.sh +0 -86
@@ -1,111 +0,0 @@
1
- // Shared scaffolding for the messages-routes test suites and the claude-worker
2
- // routes-integration test: the route-capturing fake express app, the res stub,
3
- // and the baseline deps stand-ins.
4
- //
5
- // server-runtime.mjs boots a live server on import, so the deps it injects are
6
- // reproduced here rather than imported. makeRouteDeps carries only the minimal
7
- // working defaults every suite shares; each suite supplies its own db/stmts —
8
- // the stub suites keep their hand-rolled fakes and prepared-statement mirrors,
9
- // the integration test passes a real better-sqlite3 database and the real
10
- // repositories. The harness owns the shape, the suite owns the fakes.
11
- import assert from 'node:assert/strict';
12
-
13
- import { registerMessagesRoutes } from './messages-routes.mjs';
14
-
15
- // Baseline deps: enough for registerMessagesRoutes to register every route
16
- // without touching a real server. Registration eagerly prepares statements for
17
- // many routes the suites never exercise, against tables they do not create —
18
- // the db stub absorbs those; suites that need real statement/transaction
19
- // semantics override db/stmts.
20
- export function makeRouteDeps(overrides = {}) {
21
- return {
22
- auth: (_req, _res, next) => next(),
23
- db: { prepare: () => ({ run() {}, get: () => null, all: () => [] }) },
24
- stmts: {},
25
- MAX_UPLOAD_BYTES: 1024 * 1024,
26
- touchCli: () => {},
27
- ensureSessionId: () => 'session-1',
28
- normalizeRelayMode: (value) => String(value || '').trim().toLowerCase() || null,
29
- DEFAULT_RELAY_MODE: 'default',
30
- DEFAULT_MODEL: 'gpt-5',
31
- normalizeAttachments: () => [],
32
- collectReferenceAttachmentsFromText: () => ({ attachments: [] }),
33
- mergeMessageAttachments: (left, right) => [...(left || []), ...(right || [])],
34
- resolveRequestedModel: (model) => ({
35
- ok: false,
36
- error: `Model "${String(model || '')}" is not supported`,
37
- available: [],
38
- }),
39
- getOpenAIProviderSettings: () => ({ configured: false, enabled: false, model: '', models: [] }),
40
- getCursorProviderSettings: () => ({ enabled: false, model: '', models: [] }),
41
- featureFlags: {},
42
- ...overrides,
43
- };
44
- }
45
-
46
- // Registers the routes on a fake express app and returns the captured handlers
47
- // as a Map keyed 'METHOD /path' (last handler wins, matching how the suites
48
- // always grabbed the terminal handler after the auth middleware).
49
- export function captureRoutes(deps, registerFn = registerMessagesRoutes) {
50
- const routes = new Map();
51
- const register = (method) => (routePath, ...handlers) => {
52
- routes.set(`${method} ${routePath}`, handlers[handlers.length - 1]);
53
- };
54
- const app = {
55
- post: register('POST'),
56
- get: register('GET'),
57
- patch: register('PATCH'),
58
- put: register('PUT'),
59
- delete: register('DELETE'),
60
- use() {},
61
- };
62
- registerFn(app, deps);
63
- return routes;
64
- }
65
-
66
- // Express res stub capturing status/body.
67
- export function makeRes() {
68
- const captured = { status: 200, body: null };
69
- const res = {
70
- setHeader() {},
71
- status(code) { captured.status = code; return res; },
72
- json(payload) { captured.body = payload; return res; },
73
- };
74
- return { res, captured };
75
- }
76
-
77
- // Dispatches into a captured handler and returns { status, body }.
78
- export async function invokeRoute(routes, method, routePath, { body = {}, headers = {}, query = {}, params = {}, socket = {} } = {}) {
79
- const handler = routes.get(`${String(method).toUpperCase()} ${routePath}`);
80
- assert.ok(handler, `${routePath} should be registered`);
81
- const { res, captured } = makeRes();
82
- await handler({ body, headers, query, params, socket }, res);
83
- return captured;
84
- }
85
-
86
- // Registers once and returns an invoker for one POST route — for suites that
87
- // drive the same handler repeatedly against one database.
88
- export function postHandler(routePath, deps) {
89
- const routes = captureRoutes(deps);
90
- assert.ok(routes.has(`POST ${routePath}`), `${routePath} should be registered`);
91
- return (body) => invokeRoute(routes, 'POST', routePath, { body });
92
- }
93
-
94
- // One-shot register + POST, the common form in the stub suites.
95
- export function invokePost(routePath, deps, body) {
96
- return postHandler(routePath, deps)(body);
97
- }
98
-
99
- // The worker runner's `api(method, path, body)` against the captured handlers:
100
- // dispatch with a fixed header set (e.g. the bridge identity header the live
101
- // worker sends) and surface non-2xx as a rejection like the worker's HTTP
102
- // client does.
103
- export function makeApi(routes, { headers = {} } = {}) {
104
- return async (method, routePath, body) => {
105
- const { status, body: responseBody } = await invokeRoute(routes, method, routePath, { body: body || {}, headers });
106
- if (status >= 400) {
107
- throw new Error(`${method} ${routePath} -> ${status}: ${JSON.stringify(responseBody)}`);
108
- }
109
- return responseBody;
110
- };
111
- }
@@ -1,62 +0,0 @@
1
- #!/bin/sh
2
- # Stand-in for the `claude` CLI auth subcommands, injected through
3
- # COPILOT_WEB_RELAY_CLAUDE_AUTH_BIN so the auth service can be exercised without
4
- # touching the host's real Claude login.
5
- #
6
- # Mirrors the shapes observed on CLI 2.1.247:
7
- # auth status --json -> one line of JSON
8
- # auth login -> browser notice, an OSC-8 + SGR wrapped authorize URL,
9
- # then `Paste code here if prompted > ` and a blocking read
10
- # auth logout -> removes the credentials file
11
- #
12
- # Fake credentials file path comes from CLAUDE_AUTH_STUB_CRED_FILE; "logged in"
13
- # means that file exists.
14
-
15
- CRED_FILE="${CLAUDE_AUTH_STUB_CRED_FILE:-}"
16
- AUTH_URL="${CLAUDE_AUTH_STUB_URL:-https://claude.com/oauth/authorize?code=true&client_id=stub-client&code_challenge=Xk3nQ7pLm2vB8sT1wY6zR0aC5dF9gH4jK7lN2oP3qS8&redirect_uri=https%3A%2F%2Fplatform.claude.com%2Foauth%2Fcode%2Fcallback}"
17
-
18
- command="$1 $2"
19
-
20
- case "$command" in
21
- "auth status")
22
- if [ -n "$CRED_FILE" ] && [ -f "$CRED_FILE" ]; then
23
- printf '{"loggedIn":true,"authMethod":"claudeai","apiProvider":null,"email":"stub@example.com","orgId":"org_stub","orgName":"Stub Org","subscriptionType":"max"}\n'
24
- else
25
- printf '{"loggedIn":false,"authMethod":null,"apiProvider":null,"email":null,"orgId":null,"orgName":null,"subscriptionType":null}\n'
26
- fi
27
- exit 0
28
- ;;
29
- "auth login")
30
- printf 'Opening browser to sign in…\n'
31
- # OSC-8 hyperlink (target + visible label) wrapped in SGR colour codes, the
32
- # exact shape the real CLI emits under a PTY.
33
- printf 'If the browser did not open, visit: \033]8;;%s\033\\\033[4;34m%s\033[0m\033]8;;\033\\\n' "$AUTH_URL" "$AUTH_URL"
34
- printf '\033[2mPaste code here if prompted > \033[0m'
35
- if ! read -r submitted_code; then
36
- printf '\nAborted.\n'
37
- exit 1
38
- fi
39
- if [ "$submitted_code" = "goodcode" ]; then
40
- if [ -n "$CRED_FILE" ]; then
41
- # Deliberately short fake tokens: anything with 20+ characters after
42
- # `sk-ant-` trips the secret scanner in server/test-hygiene.test.mjs.
43
- printf '{"claudeAiOauth":{"accessToken":"sk-ant-oat01-stub","refreshToken":"sk-ant-ort01-stub"}}\n' > "$CRED_FILE"
44
- fi
45
- printf '\nLogin successful. Logged in as stub@example.com\n'
46
- exit 0
47
- fi
48
- printf '\nOAuth error: invalid_grant - the authorization code is invalid or has expired.\n' >&2
49
- exit 1
50
- ;;
51
- "auth logout")
52
- if [ -n "$CRED_FILE" ]; then
53
- rm -f "$CRED_FILE"
54
- fi
55
- printf 'Logged out.\n'
56
- exit 0
57
- ;;
58
- *)
59
- printf 'claude-auth-stub: unsupported command: %s\n' "$*" >&2
60
- exit 2
61
- ;;
62
- esac
@@ -1,75 +0,0 @@
1
- #!/bin/sh
2
- # Stand-in for a vendor CLI installer, injected through
3
- # COPILOT_WEB_RELAY_CLI_INSTALL_COMMAND so the install flow can be exercised end
4
- # to end without ever fetching from x.ai / claude.ai or writing to the host's
5
- # real bin directories.
6
- #
7
- # The install service calls it as: cli-install-stub.sh <provider> <action>
8
- # (both values come from the frozen descriptor table, never from a request
9
- # body). It prints installer-shaped progress, then writes a fake binary into
10
- # CLI_INSTALL_STUB_BIN_DIR — which the relay is pointed at through
11
- # COPILOT_WEB_RELAY_CLI_BIN_DIR — so the resolve -> bind -> broadcast chain runs
12
- # against something real.
13
- #
14
- # CLI_INSTALL_STUB_BIN_DIR where the fake binary lands (required)
15
- # CLI_INSTALL_STUB_VERSION version the fake binary reports (default 9.9.9)
16
- # CLI_INSTALL_STUB_FAIL non-empty -> print an error and exit 1
17
- # CLI_INSTALL_STUB_SLEEP seconds to stall mid-install (cancel/timeout tests)
18
-
19
- provider="$1"
20
- action="$2"
21
- bin_dir="${CLI_INSTALL_STUB_BIN_DIR:-}"
22
- version="${CLI_INSTALL_STUB_VERSION:-9.9.9}"
23
-
24
- printf 'Installing %s (%s)…\n' "$provider" "$action"
25
- printf 'Resolving latest release for linux-x86_64\n'
26
-
27
- if [ -n "${CLI_INSTALL_STUB_SLEEP:-}" ]; then
28
- sleep "$CLI_INSTALL_STUB_SLEEP"
29
- fi
30
-
31
- if [ -n "${CLI_INSTALL_STUB_FAIL:-}" ]; then
32
- printf 'error: download failed (stub)\n' >&2
33
- exit 1
34
- fi
35
-
36
- if [ -z "$bin_dir" ]; then
37
- printf 'cli-install-stub: CLI_INSTALL_STUB_BIN_DIR is not set\n' >&2
38
- exit 2
39
- fi
40
-
41
- mkdir -p "$bin_dir"
42
- target="$bin_dir/$provider"
43
-
44
- # The fake binary answers exactly the probes cli-install-service runs: the
45
- # version banner in each descriptor's shape, `update --check --json` for Grok,
46
- # and `doctor` for Claude.
47
- cat > "$target" <<STUB
48
- #!/bin/sh
49
- case "\$1 \$2" in
50
- "--version ")
51
- case "$provider" in
52
- grok) printf 'grok %s (stubcommit) [stable]\n' "$version" ;;
53
- claude) printf '%s (Claude Code)\n' "$version" ;;
54
- *) printf '%s\n' "$version" ;;
55
- esac
56
- exit 0
57
- ;;
58
- "update --check")
59
- printf '{"currentVersion":"%s","latestVersion":"%s","updateAvailable":false,"installer":"internal","channel":"stable","autoUpdate":null,"error":null}\n' "$version" "$version"
60
- exit 0
61
- ;;
62
- "doctor ")
63
- printf 'Running: native (%s)\n' "$version"
64
- printf 'Path: %s\n' "$target"
65
- printf 'Auto-updates: enabled\n'
66
- exit 0
67
- ;;
68
- esac
69
- printf 'cli-stub: unsupported command: %s\n' "\$*" >&2
70
- exit 2
71
- STUB
72
- chmod +x "$target"
73
-
74
- printf 'Installed %s %s to %s\n' "$provider" "$version" "$target"
75
- exit 0
@@ -1,86 +0,0 @@
1
- #!/bin/sh
2
- # Stand-in for the `grok` CLI, injected through GROK_CLI_COMMAND so the auth
3
- # service (and the CLI install/probe path) can be exercised without touching the
4
- # host's real Grok login.
5
- #
6
- # Mirrors the shapes probed live on Grok Build 1.0.13 (2026-08-31):
7
- # --version -> `grok 1.0.13 (5e9a58528b76)`
8
- # update --check --json-> the machine-readable update payload
9
- # login --device-auth -> a device URL carrying the code, the code again on its
10
- # own line, one grey (SGR 90) warning line, then
11
- # `Waiting for authorization...` and a poll loop. No
12
- # TTY, no stdin read: the real CLI ignores stdin and
13
- # exits by itself once the browser authorises.
14
- # logout -> removes the fake auth.json
15
- #
16
- # The poll loop stands in for the browser: it exits 0 when GROK_STUB_SUCCESS_SENTINEL
17
- # appears (writing the fake auth store) and non-zero when GROK_STUB_FAILURE_SENTINEL
18
- # does. "Logged in" means GROK_STUB_AUTH_FILE exists, matching what
19
- # readGrokCliAuthKey() actually looks at.
20
-
21
- set -u
22
-
23
- VERSION="${GROK_STUB_VERSION:-1.0.13}"
24
- AUTH_FILE="${GROK_STUB_AUTH_FILE:-}"
25
- DEVICE_CODE="${GROK_STUB_DEVICE_CODE:-D7SV-M4TR}"
26
- DEVICE_URL="${GROK_STUB_DEVICE_URL:-https://accounts.x.ai/oauth2/device?user_code=${DEVICE_CODE}}"
27
- SUCCESS_SENTINEL="${GROK_STUB_SUCCESS_SENTINEL:-}"
28
- FAILURE_SENTINEL="${GROK_STUB_FAILURE_SENTINEL:-}"
29
- TIMEOUT_SECONDS="${GROK_STUB_TIMEOUT_SECONDS:-60}"
30
- POLL_SECONDS="${GROK_STUB_POLL_SECONDS:-0.2}"
31
- UPDATE_AVAILABLE="${GROK_STUB_UPDATE_AVAILABLE:-false}"
32
- LATEST_VERSION="${GROK_STUB_LATEST_VERSION:-$VERSION}"
33
-
34
- command="${1:-} ${2:-}"
35
-
36
- case "$command" in
37
- "--version "*|"--version")
38
- printf 'grok %s (5e9a58528b76)\n' "$VERSION"
39
- exit 0
40
- ;;
41
- "update --check")
42
- printf '{"currentVersion":"%s","latestVersion":"%s","updateAvailable":%s,"installer":"internal","channel":"stable","autoUpdate":null,"error":null}\n' \
43
- "$VERSION" "$LATEST_VERSION" "$UPDATE_AVAILABLE"
44
- exit 0
45
- ;;
46
- "login --device-auth")
47
- # Byte-for-byte the banner the real CLI printed under piped stdio, including
48
- # the blank lines and the one grey warning line — the escape-stripping in the
49
- # URL/code scrape is tested against exactly this.
50
- printf '\nTo sign in, open this URL in your browser:\n\n %s\n\n' "$DEVICE_URL"
51
- printf ' (Could not open browser automatically — open the URL above manually.)\n\n'
52
- printf 'Confirm this code in your browser:\n\n %s\n\n' "$DEVICE_CODE"
53
- printf '\033[90mOnly continue with a code you requested. Do not share it with anyone.\033[0m\n\n'
54
- printf 'Waiting for authorization...\n'
55
- deadline=$(( $(date +%s) + TIMEOUT_SECONDS ))
56
- while [ "$(date +%s)" -le "$deadline" ]; do
57
- if [ -n "$FAILURE_SENTINEL" ] && [ -f "$FAILURE_SENTINEL" ]; then
58
- printf '\nAuthorization failed: the device code expired.\n' >&2
59
- exit 1
60
- fi
61
- if [ -n "$SUCCESS_SENTINEL" ] && [ -f "$SUCCESS_SENTINEL" ]; then
62
- if [ -n "$AUTH_FILE" ]; then
63
- # Deliberately short fake key: anything 32+ characters long trips the
64
- # secret scanner in server/test-hygiene.test.mjs.
65
- printf '{"https://auth.x.ai::stub":{"key":"grok-stub-key","create_time":"2026-08-31T00:00:00Z","expires_at":"2099-01-01T00:00:00Z"}}\n' > "$AUTH_FILE"
66
- fi
67
- printf '\nSigned in.\n'
68
- exit 0
69
- fi
70
- sleep "$POLL_SECONDS"
71
- done
72
- printf '\nTimed out waiting for authorization.\n' >&2
73
- exit 1
74
- ;;
75
- "logout "*|"logout")
76
- if [ -n "$AUTH_FILE" ]; then
77
- rm -f "$AUTH_FILE"
78
- fi
79
- printf 'Signed out.\n'
80
- exit 0
81
- ;;
82
- *)
83
- printf 'grok-stub: unsupported command: %s\n' "$*" >&2
84
- exit 2
85
- ;;
86
- esac