@andorra-labs/code 0.1.5 → 0.1.7

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 (224) hide show
  1. package/dist/src/account-presentation.js +3 -3
  2. package/dist/src/agent-execution.d.ts +2 -0
  3. package/dist/src/agent-execution.js +526 -41
  4. package/dist/src/agent-mcp-catalog.d.ts +21 -0
  5. package/dist/src/agent-mcp-catalog.js +40 -0
  6. package/dist/src/agent-mcp.d.ts +36 -3
  7. package/dist/src/agent-mcp.js +114 -45
  8. package/dist/src/app-server/protocol.d.ts +57 -5
  9. package/dist/src/app-server/protocol.js +18 -1
  10. package/dist/src/app-server/workspace.d.ts +9 -1
  11. package/dist/src/app-server/workspace.js +50 -3
  12. package/dist/src/app-server.d.ts +115 -41
  13. package/dist/src/app-server.js +1316 -221
  14. package/dist/src/auth/AuthManager.d.ts +33 -1
  15. package/dist/src/auth/AuthManager.js +138 -10
  16. package/dist/src/auth/callback-page.d.ts +4 -0
  17. package/dist/src/auth/callback-page.js +70 -0
  18. package/dist/src/auth/callback.d.ts +39 -0
  19. package/dist/src/auth/callback.js +146 -22
  20. package/dist/src/auth/index.d.ts +10 -6
  21. package/dist/src/auth/index.js +2 -2
  22. package/dist/src/auth/store.d.ts +142 -3
  23. package/dist/src/auth/store.js +334 -13
  24. package/dist/src/auth/types.d.ts +17 -1
  25. package/dist/src/auth-commands.d.ts +11 -2
  26. package/dist/src/auth-commands.js +14 -7
  27. package/dist/src/automation-runner.d.ts +9 -0
  28. package/dist/src/automation-runner.js +22 -1
  29. package/dist/src/automation-tool.js +18 -3
  30. package/dist/src/automations.d.ts +5 -0
  31. package/dist/src/automations.js +11 -1
  32. package/dist/src/browser-captcha-tool.d.ts +54 -0
  33. package/dist/src/browser-captcha-tool.js +374 -0
  34. package/dist/src/browser-panel-tool.d.ts +7 -0
  35. package/dist/src/browser-panel-tool.js +74 -3
  36. package/dist/src/browser-runner.js +19 -4
  37. package/dist/src/browser-server.js +21 -1
  38. package/dist/src/browser-session.d.ts +16 -0
  39. package/dist/src/browser-session.js +35 -0
  40. package/dist/src/browser-ui/app.js +193 -3
  41. package/dist/src/browser-ui/style.css +15 -1
  42. package/dist/src/browser-view.d.ts +72 -4
  43. package/dist/src/browser-view.js +229 -17
  44. package/dist/src/capabilities.d.ts +9 -3
  45. package/dist/src/capabilities.js +20 -5
  46. package/dist/src/capsolver.d.ts +60 -0
  47. package/dist/src/capsolver.js +101 -0
  48. package/dist/src/claude-provider.d.ts +6 -0
  49. package/dist/src/claude-provider.js +34 -3
  50. package/dist/src/cli-executable.d.ts +33 -0
  51. package/dist/src/cli-executable.js +64 -0
  52. package/dist/src/cli-process.d.ts +47 -0
  53. package/dist/src/cli-process.js +113 -0
  54. package/dist/src/cli-sign-in.d.ts +68 -0
  55. package/dist/src/cli-sign-in.js +224 -0
  56. package/dist/src/cli.js +84 -26
  57. package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +1 -1
  58. package/dist/src/code-intelligence/CodeIntelligenceManager.js +5 -5
  59. package/dist/src/codex-provider.js +12 -0
  60. package/dist/src/coding-tools.d.ts +5 -0
  61. package/dist/src/coding-tools.js +98 -53
  62. package/dist/src/command-output-tap.d.ts +16 -0
  63. package/dist/src/command-output-tap.js +45 -0
  64. package/dist/src/command-screens.js +3 -3
  65. package/dist/src/commands.d.ts +15 -2
  66. package/dist/src/commands.js +14 -13
  67. package/dist/src/completion.d.ts +23 -5
  68. package/dist/src/completion.js +380 -17
  69. package/dist/src/config.d.ts +61 -0
  70. package/dist/src/config.js +276 -12
  71. package/dist/src/context-budget.d.ts +7 -0
  72. package/dist/src/context-budget.js +18 -1
  73. package/dist/src/deadline.js +6 -0
  74. package/dist/src/decision/FactContinuations.d.ts +41 -6
  75. package/dist/src/decision/FactContinuations.js +211 -64
  76. package/dist/src/decision/PreparedSteps.js +3 -1
  77. package/dist/src/decision/checks.d.ts +25 -0
  78. package/dist/src/decision/checks.js +77 -6
  79. package/dist/src/delegation-changes.d.ts +109 -0
  80. package/dist/src/delegation-changes.js +431 -0
  81. package/dist/src/extensions.d.ts +1 -0
  82. package/dist/src/extensions.js +16 -3
  83. package/dist/src/graph-provider-portability.js +2 -2
  84. package/dist/src/graph-quota.d.ts +1 -1
  85. package/dist/src/graph-quota.js +1 -1
  86. package/dist/src/graph-runner.js +35 -21
  87. package/dist/src/graph-selection.d.ts +6 -0
  88. package/dist/src/graph-selection.js +10 -0
  89. package/dist/src/graph-server.d.ts +8 -0
  90. package/dist/src/graph-server.js +76 -6
  91. package/dist/src/graph-sync.d.ts +65 -0
  92. package/dist/src/graph-sync.js +433 -13
  93. package/dist/src/graph-tool.d.ts +52 -0
  94. package/dist/src/graph-tool.js +136 -0
  95. package/dist/src/graph-ui/app.js +272 -50
  96. package/dist/src/graph-ui/controls.js +6 -0
  97. package/dist/src/graph-ui/drafts.js +39 -0
  98. package/dist/src/graph-ui/embed.js +1 -1
  99. package/dist/src/graph-ui/icons.js +1 -0
  100. package/dist/src/graph-ui/index.html +2 -2
  101. package/dist/src/graph-ui/skill-picker.js +242 -0
  102. package/dist/src/graph-ui/studio.css +7 -5
  103. package/dist/src/graph-ui/style.css +65 -12
  104. package/dist/src/graphs.d.ts +60 -5
  105. package/dist/src/graphs.js +191 -37
  106. package/dist/src/grok-provider.d.ts +50 -0
  107. package/dist/src/grok-provider.js +186 -0
  108. package/dist/src/handoffs.d.ts +13 -0
  109. package/dist/src/handoffs.js +31 -1
  110. package/dist/src/hardened-runtime.d.ts +4 -4
  111. package/dist/src/hardened-runtime.js +109 -9
  112. package/dist/src/managed-sign-in.d.ts +38 -0
  113. package/dist/src/managed-sign-in.js +169 -0
  114. package/dist/src/markdown.d.ts +5 -0
  115. package/dist/src/markdown.js +5 -2
  116. package/dist/src/mcp.js +11 -0
  117. package/dist/src/membership.d.ts +8 -1
  118. package/dist/src/membership.js +15 -5
  119. package/dist/src/model-metadata.js +14 -2
  120. package/dist/src/model-override.d.ts +10 -0
  121. package/dist/src/model-override.js +20 -0
  122. package/dist/src/opencode-cli-provider.d.ts +122 -0
  123. package/dist/src/opencode-cli-provider.js +415 -0
  124. package/dist/src/opencode-provider.js +23 -8
  125. package/dist/src/palette.d.ts +2 -0
  126. package/dist/src/palette.js +2 -0
  127. package/dist/src/permissions.d.ts +19 -1
  128. package/dist/src/permissions.js +30 -1
  129. package/dist/src/powershell-pool.d.ts +11 -2
  130. package/dist/src/powershell-pool.js +34 -5
  131. package/dist/src/provider-connection.js +36 -0
  132. package/dist/src/provider-engine.d.ts +2 -1
  133. package/dist/src/provider-engine.js +64 -13
  134. package/dist/src/provider-import.js +6 -1
  135. package/dist/src/provider-keys.d.ts +48 -0
  136. package/dist/src/provider-keys.js +121 -0
  137. package/dist/src/provider-settings.js +22 -3
  138. package/dist/src/providers.d.ts +12 -1
  139. package/dist/src/providers.js +27 -8
  140. package/dist/src/pull-requests.d.ts +123 -20
  141. package/dist/src/pull-requests.js +334 -84
  142. package/dist/src/qa/qa-authorize.js +9 -1
  143. package/dist/src/qa/runtime/ProcessManager.d.ts +6 -0
  144. package/dist/src/qa/runtime/ProcessManager.js +16 -0
  145. package/dist/src/react-runtime.js +106 -7
  146. package/dist/src/read-image.d.ts +30 -0
  147. package/dist/src/read-image.js +97 -0
  148. package/dist/src/remote/engine-pool.js +1 -1
  149. package/dist/src/run-progress.js +6 -1
  150. package/dist/src/run-records.d.ts +133 -27
  151. package/dist/src/run-records.js +320 -40
  152. package/dist/src/runtime.d.ts +38 -1
  153. package/dist/src/runtime.js +27 -4
  154. package/dist/src/save-lock.d.ts +11 -0
  155. package/dist/src/save-lock.js +29 -2
  156. package/dist/src/secret-redaction.d.ts +13 -0
  157. package/dist/src/secret-redaction.js +71 -0
  158. package/dist/src/session-summary.d.ts +10 -4
  159. package/dist/src/session-summary.js +14 -7
  160. package/dist/src/sessions.js +8 -2
  161. package/dist/src/shell.js +4 -1
  162. package/dist/src/side-panel.d.ts +1 -1
  163. package/dist/src/side-panel.js +1 -1
  164. package/dist/src/skill-commands.d.ts +2 -0
  165. package/dist/src/skill-commands.js +2 -0
  166. package/dist/src/skills/bundled/create-agent/SKILL.md +81 -0
  167. package/dist/src/skills/bundled/create-skill/SKILL.md +81 -0
  168. package/dist/src/skills/bundled/doctor/SKILL.md +43 -0
  169. package/dist/src/skills/bundled/graph-manager/SKILL.md +100 -0
  170. package/dist/src/skills/bundled/graph-manager/errors.md +38 -0
  171. package/dist/src/skills/bundled/graph-manager/patterns.md +78 -0
  172. package/dist/src/skills/bundled/manage-mcp/SKILL.md +75 -0
  173. package/dist/src/skills/bundled/manage-mcp/probe.md +165 -0
  174. package/dist/src/skills/bundled/manage-skills/SKILL.md +67 -0
  175. package/dist/src/skills/bundled/provenance.json +50 -0
  176. package/dist/src/skills/bundled/write-instructions/SKILL.md +42 -0
  177. package/dist/src/skills/invocable-skills.d.ts +41 -0
  178. package/dist/src/skills/invocable-skills.js +49 -0
  179. package/dist/src/skills/prompt-skills.d.ts +1 -0
  180. package/dist/src/skills/prompt-skills.js +33 -0
  181. package/dist/src/skills/runtime-skills.d.ts +4 -0
  182. package/dist/src/skills/runtime-skills.js +21 -0
  183. package/dist/src/structured-step.d.ts +55 -0
  184. package/dist/src/structured-step.js +85 -0
  185. package/dist/src/subagent-run.d.ts +1 -1
  186. package/dist/src/subagent-run.js +29 -33
  187. package/dist/src/telemetry/schema.d.ts +2 -2
  188. package/dist/src/telemetry/schema.js +3 -2
  189. package/dist/src/terminal-ui.d.ts +38 -0
  190. package/dist/src/terminal-ui.js +126 -28
  191. package/dist/src/timers.d.ts +21 -2
  192. package/dist/src/timers.js +12 -4
  193. package/dist/src/tool-dependencies.js +4 -0
  194. package/dist/src/tool-names.d.ts +18 -0
  195. package/dist/src/tool-names.js +26 -0
  196. package/dist/src/tools.d.ts +9 -0
  197. package/dist/src/tools.js +159 -20
  198. package/dist/src/trajectory.js +32 -12
  199. package/dist/src/transcript.js +5 -0
  200. package/dist/src/types.d.ts +36 -0
  201. package/dist/src/web-search.d.ts +59 -0
  202. package/dist/src/web-search.js +216 -0
  203. package/docs/agents/README.md +2 -2
  204. package/docs/agents/mcp-server.md +28 -3
  205. package/docs/agents/subagent-mode.md +7 -4
  206. package/docs/concepts/README.md +1 -1
  207. package/docs/concepts/security.md +4 -2
  208. package/docs/getting-started/accounts.md +15 -4
  209. package/docs/getting-started/configure-providers.md +30 -3
  210. package/docs/guides/README.md +1 -0
  211. package/docs/guides/browser.md +12 -0
  212. package/docs/guides/desktop-app.md +11 -4
  213. package/docs/guides/graph-builder.md +9 -1
  214. package/docs/guides/web-search.md +47 -0
  215. package/docs/reference/cli.md +4 -3
  216. package/docs/reference/config.md +4 -4
  217. package/docs/reference/slash-commands.md +2 -1
  218. package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +125 -0
  219. package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +295 -0
  220. package/docs/superpowers/specs/2026-11-01-pr-section-design.md +7 -0
  221. package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +206 -0
  222. package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +291 -0
  223. package/package.json +1 -1
  224. package/tests/permissions-test-plan.md +2 -1
@@ -3,7 +3,7 @@ import { AuthManager } from './AuthManager.js';
3
3
  export * from './types.js';
4
4
  export { AuthManager, AUTH_REFRESH_BUDGET_MS } from './AuthManager.js';
5
5
  export { credentialIdentity } from './AuthManager.js';
6
- export { KeyringCredentialStore } from './store.js';
6
+ export { KeyringCredentialStore, KeyringAbsentError, FileCredentialStore, FallbackCredentialStore, createCredentialStore } from './store.js';
7
7
  export function getAuthConfiguration() { return { ...AUTH_DEPLOYMENT }; }
8
8
  let manager;
9
9
  let signOutReporter;
@@ -15,7 +15,7 @@ let signOutReporter;
15
15
  export function setAuthSignOutReporter(reporter) { signOutReporter = reporter; }
16
16
  function auth() { return manager ??= new AuthManager({ config: getAuthConfiguration(), onSignOut: error => signOutReporter?.(error) }); }
17
17
  export const login = (options = {}) => auth().login(options);
18
- export const logout = (signal) => auth().logout(signal);
18
+ export const logout = (signal, options) => auth().logout(signal, options);
19
19
  export const getAccessToken = (signal) => auth().getAccessToken(signal);
20
20
  /**
21
21
  * The access token and the account it belongs to, read as one operation.
@@ -1,20 +1,159 @@
1
- import { type CredentialStore } from './types.js';
1
+ import { AuthError, type CredentialLocation, type CredentialStore } from './types.js';
2
2
  type NativeEntry = {
3
3
  getPassword(): Promise<string | undefined | null>;
4
4
  setPassword(value: string): Promise<void>;
5
5
  deleteCredential(): Promise<boolean>;
6
6
  };
7
7
  export type EntryFactory = (name: string) => Promise<NativeEntry>;
8
+ /** The opaque name one credential identity is stored under, in the OS store and in the session file. */
9
+ export declare function credentialScope(identity: string): string;
10
+ /**
11
+ * The machine has no credential store at all, as opposed to one that is locked or failing.
12
+ *
13
+ * Only this lets a Linux machine keep its session in the owner-only file, and only this lets a
14
+ * sign-out treat the keyring as holding nothing: a locked keyring still holds its tokens.
15
+ */
16
+ export declare class KeyringAbsentError extends AuthError {
17
+ constructor(message?: string, options?: {
18
+ cause?: unknown;
19
+ });
20
+ }
21
+ /** The OS credential store service that Andorra sign-ins are saved under, one scope per identity. */
22
+ export declare const SIGN_IN_SERVICE = "Andorra Code";
8
23
  /** Lazy native loading keeps offline BYOK usable on machines without a credential service. */
9
24
  export declare class KeyringCredentialStore implements CredentialStore {
10
25
  private readonly factory?;
11
- private readonly scope;
12
- constructor(identity: string, factory?: EntryFactory | undefined);
26
+ /** The opaque prefix every entry of this credential is stored under. */
27
+ readonly scope: string;
28
+ private readonly service;
29
+ /**
30
+ * @param identity - what the scope is derived from; with `options.scope` set, the scope itself.
31
+ * @param options.service - the OS store service the entries belong to (sign-ins by default).
32
+ */
33
+ constructor(identity: string, factory?: EntryFactory | undefined, options?: {
34
+ service?: string;
35
+ scope?: boolean;
36
+ });
13
37
  private entry;
14
38
  private manifest;
15
39
  read(): Promise<string | undefined>;
16
40
  /** Callers serialize access. Bank switching avoids partially replacing a valid credential. */
17
41
  write(value: string): Promise<void>;
42
+ /**
43
+ * Sign out: leave nothing of this credential in the OS store.
44
+ *
45
+ * The token-free tombstone is committed first, so a sign-out interrupted part way never leaves a
46
+ * readable session behind: until the last step, a reader sees the tombstone. Once every token
47
+ * chunk is gone the tombstone is removed too, manifest first, so the store ends empty rather than
48
+ * accumulating a signed-out entry per identity. An empty store reads as signed out with a fresh
49
+ * generation, which supersedes an in-flight login exactly as the tombstone's generation did.
50
+ */
51
+ clear(tombstone: string): Promise<void>;
52
+ /**
53
+ * Delete every entry of this credential. The manifest goes first, so an interrupted removal reads
54
+ * as empty rather than as a manifest naming chunks that are gone.
55
+ */
56
+ remove(): Promise<void>;
57
+ location(): Promise<CredentialLocation>;
58
+ }
59
+ /**
60
+ * Every credential scope the OS store holds under `service`, whichever identity or home wrote it.
61
+ *
62
+ * Scopes are hashes, so this cannot say which home a scope belongs to or whether it is still in
63
+ * use; only an explicit "sign out everywhere" acts on scopes other than the current one.
64
+ */
65
+ export declare function keyringScopes(service?: string): Promise<string[]>;
66
+ /**
67
+ * A session kept in one owner-only file, for machines that have no OS credential store: a VPS
68
+ * reached over SSH, a container, a minimal Linux install without Secret Service.
69
+ *
70
+ * The file is created 0600 inside a 0700 directory and replaced atomically, so a reader never
71
+ * sees a half-written session and no other local user can read it. It is still a plaintext file,
72
+ * which is why the OS store is preferred wherever one exists.
73
+ */
74
+ export declare class FileCredentialStore implements CredentialStore {
75
+ readonly path: string;
76
+ constructor(path: string);
77
+ /** Whether a session file (or a signed-out tombstone) exists. A store that cannot tell fails. */
78
+ exists(): Promise<boolean>;
79
+ read(): Promise<string | undefined>;
80
+ write(value: string): Promise<void>;
81
+ /**
82
+ * Replace the session with the tombstone and erase what interrupted writes left behind.
83
+ *
84
+ * A process killed between writing its temporary file and renaming it leaves a whole session
85
+ * beside the store, which no read ever sees and no sign-out would otherwise reach. Callers hold
86
+ * the auth lock, so no write of this store is in flight while the leftovers are removed.
87
+ */
88
+ clear(tombstone: string): Promise<void>;
89
+ /** Delete the session file and any interrupted writes beside it. */
90
+ remove(): Promise<void>;
91
+ private removeInterruptedWrites;
92
+ location(): Promise<CredentialLocation>;
93
+ }
94
+ export type CredentialStoreMode = 'auto' | 'keyring' | 'file';
95
+ /** `ANDORRA_CREDENTIAL_STORE=file|keyring` forces a store; anything else chooses automatically. */
96
+ export declare function credentialStoreMode(environment?: NodeJS.ProcessEnv): CredentialStoreMode;
97
+ /**
98
+ * The OS credential store, falling back to an owner-only file where the OS has none.
99
+ *
100
+ * The fallback exists for Linux and other Unix machines without Secret Service, which is what a
101
+ * VPS reached over SSH usually is. macOS and Windows always ship a credential store, so there a
102
+ * keyring failure means a locked or broken keychain and is reported instead of silently writing a
103
+ * plaintext file. Once a session file exists it stays the store, so concurrent processes and later
104
+ * runs never split one login between two places.
105
+ */
106
+ export declare class FallbackCredentialStore implements CredentialStore {
107
+ private readonly keyring;
108
+ private readonly file;
109
+ private readonly mode;
110
+ private readonly fallback;
111
+ constructor(keyring: CredentialStore, file: FileCredentialStore, mode?: CredentialStoreMode, fallback?: boolean);
112
+ /**
113
+ * Whether the file is the store. In automatic mode only a file that exists selects it: that is
114
+ * the one choice every process sees alike. A keyring failure alone never pins a process to a file
115
+ * nobody wrote, so a keyring that recovers, or that another process signed in through, is read
116
+ * again on the next call.
117
+ */
118
+ private useFile;
119
+ /** Run on the keyring; where this machine has none and the fallback applies, use the file for this
120
+ * call. A write there creates the file, which moves every process to it. A keyring that exists but
121
+ * is locked or failing is reported instead: it may hold the session, and a file beside it would
122
+ * hide that session rather than replace it. */
123
+ private keyringOr;
124
+ /** Clear the keyring. Only a machine without one has nothing to clear; a locked or failing keyring
125
+ * may still hold tokens, so its failure is reported. */
126
+ private clearReachableKeyring;
127
+ read(): Promise<string | undefined>;
128
+ write(value: string): Promise<void>;
129
+ /**
130
+ * The session held by whichever store is not in use.
131
+ *
132
+ * Either store can keep an older session beside the active one: the keyring's, from before
133
+ * `ANDORRA_CREDENTIAL_STORE=file` or hidden by a briefly unavailable keyring when a login fell
134
+ * back; the file's, when `ANDORRA_CREDENTIAL_STORE=keyring` is set after a fallback login. A store
135
+ * that cannot be read holds nothing this process can reach, which is the ordinary state of a
136
+ * keyring on a machine without one.
137
+ */
138
+ previous(): Promise<string | undefined>;
139
+ /**
140
+ * Sign out of both stores.
141
+ *
142
+ * Unlike reads and writes, a keyring clear never falls back just because it failed: a keyring
143
+ * that committed its tombstone and then could not delete an old token chunk still holds that
144
+ * token, and switching to the file would report a sign-out that left it behind. Only a keyring
145
+ * that cannot even be read holds nothing to clear, which is a machine without one.
146
+ *
147
+ * The other store is cleared too. A reachable keyring is cleared whether or not a session reads
148
+ * back from it, because an interrupted keyring write leaves token chunks without the manifest
149
+ * that would show them; failing to clear it is reported. While the keyring is the store, the file side is removed
150
+ * outright whatever it holds (a session, a tombstone, or only interrupted writes), so no plaintext
151
+ * token outlives the sign-out and automatic mode returns to the keyring rather than sticking to a
152
+ * signed-out file.
153
+ */
18
154
  clear(tombstone: string): Promise<void>;
155
+ location(): Promise<CredentialLocation>;
19
156
  }
157
+ /** The default store for a credential identity: see `FallbackCredentialStore`. */
158
+ export declare function createCredentialStore(identity: string, environment?: NodeJS.ProcessEnv): CredentialStore;
20
159
  export {};
@@ -1,23 +1,78 @@
1
- import { createHash } from 'node:crypto';
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { chmod, mkdir, open, readdir, readFile, rename, rm, stat } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import { basename, dirname, join } from 'node:path';
2
5
  import { AuthError } from './types.js';
3
6
  const CHUNKS = 32, CHUNK_SIZE = 1000;
7
+ /** The opaque name one credential identity is stored under, in the OS store and in the session file. */
8
+ export function credentialScope(identity) { return createHash('sha256').update(identity).digest('hex').slice(0, 32); }
9
+ /**
10
+ * The machine has no credential store at all, as opposed to one that is locked or failing.
11
+ *
12
+ * Only this lets a Linux machine keep its session in the owner-only file, and only this lets a
13
+ * sign-out treat the keyring as holding nothing: a locked keyring still holds its tokens.
14
+ */
15
+ export class KeyringAbsentError extends AuthError {
16
+ constructor(message = 'This machine has no OS credential store (no Secret Service is running).', options) { super('storage', message, options); this.name = 'KeyringAbsentError'; }
17
+ }
18
+ /**
19
+ * The errors a Linux machine without a credential store gives, observed through @napi-rs/keyring:
20
+ * no Secret Service registered on the session bus, no session bus at all, or a dead bus socket.
21
+ * A locked collection, a dismissed unlock prompt or any other failure is a store that exists.
22
+ */
23
+ const ABSENT_KEYRING = /not provided by any \.service files|org\.freedesktop\.DBus\.Error\.ServiceUnknown|dbus-daemon autolaunch|set your DBUS_SESSION_BUS_ADDRESS|Failed to connect to socket/i;
24
+ function errorText(error) {
25
+ const parts = [];
26
+ for (let current = error, depth = 0; current && depth < 6; depth++) {
27
+ parts.push(String(current.message ?? current));
28
+ current = current.cause;
29
+ }
30
+ return parts.join(' | ');
31
+ }
32
+ /** The failure to report for a keyring operation: absence stays recognisable, anything else gets `message`. */
33
+ function keyringFailure(error, message) {
34
+ if (error instanceof KeyringAbsentError)
35
+ return error;
36
+ if (ABSENT_KEYRING.test(errorText(error)))
37
+ return new KeyringAbsentError(undefined, { cause: error });
38
+ return new AuthError('storage', message, { cause: error });
39
+ }
40
+ const LOCKED_HINT = 'Unlock it and retry, or set ANDORRA_CREDENTIAL_STORE=file to keep the session in an owner-only file instead.';
41
+ /** The OS credential store service that Andorra sign-ins are saved under, one scope per identity. */
42
+ export const SIGN_IN_SERVICE = 'Andorra Code';
43
+ async function nativeKeyring() {
44
+ // A native module that does not load for this platform means there is no store to use.
45
+ try {
46
+ return await import('@napi-rs/keyring');
47
+ }
48
+ catch (error) {
49
+ throw new KeyringAbsentError('The OS credential store module is not available on this machine.', { cause: error });
50
+ }
51
+ }
4
52
  /** Lazy native loading keeps offline BYOK usable on machines without a credential service. */
5
53
  export class KeyringCredentialStore {
6
54
  factory;
55
+ /** The opaque prefix every entry of this credential is stored under. */
7
56
  scope;
8
- constructor(identity, factory) {
57
+ service;
58
+ /**
59
+ * @param identity - what the scope is derived from; with `options.scope` set, the scope itself.
60
+ * @param options.service - the OS store service the entries belong to (sign-ins by default).
61
+ */
62
+ constructor(identity, factory, options = {}) {
9
63
  this.factory = factory;
10
- this.scope = createHash('sha256').update(identity).digest('hex').slice(0, 32);
64
+ this.scope = options.scope ? identity : credentialScope(identity);
65
+ this.service = options.service ?? SIGN_IN_SERVICE;
11
66
  }
12
67
  async entry(name) {
13
68
  if (this.factory)
14
69
  return this.factory(`${this.scope}.${name}`);
70
+ const native = await nativeKeyring();
15
71
  try {
16
- const { AsyncEntry } = await import('@napi-rs/keyring');
17
- return new AsyncEntry('Andorra Code', `${this.scope}.${name}`, { linux: { store: 'secret-service' } });
72
+ return new native.AsyncEntry(this.service, `${this.scope}.${name}`, { linux: { store: 'secret-service' } });
18
73
  }
19
- catch {
20
- throw new AuthError('storage', 'The OS credential store is unavailable. Unlock your keychain or configure Linux Secret Service; no plaintext fallback is used.');
74
+ catch (error) {
75
+ throw keyringFailure(error, `The OS credential store could not be opened. ${LOCKED_HINT}`);
21
76
  }
22
77
  }
23
78
  async manifest() {
@@ -43,8 +98,8 @@ export class KeyringCredentialStore {
43
98
  }
44
99
  return Buffer.from(text, 'base64').toString('utf8');
45
100
  }
46
- catch {
47
- throw new AuthError('storage', 'Unable to read the OS credential store. Unlock it and retry.');
101
+ catch (error) {
102
+ throw keyringFailure(error, `Unable to read the OS credential store. ${LOCKED_HINT}`);
48
103
  }
49
104
  }
50
105
  /** Callers serialize access. Bank switching avoids partially replacing a valid credential. */
@@ -70,12 +125,20 @@ export class KeyringCredentialStore {
70
125
  catch { /* Retry on the next write or logout. */ }
71
126
  }
72
127
  }
73
- catch {
74
- throw new AuthError('storage', 'Unable to save credentials securely. Unlock the OS credential store and retry.');
128
+ catch (error) {
129
+ throw keyringFailure(error, `Unable to save credentials securely in the OS credential store. ${LOCKED_HINT}`);
75
130
  }
76
131
  }
132
+ /**
133
+ * Sign out: leave nothing of this credential in the OS store.
134
+ *
135
+ * The token-free tombstone is committed first, so a sign-out interrupted part way never leaves a
136
+ * readable session behind: until the last step, a reader sees the tombstone. Once every token
137
+ * chunk is gone the tombstone is removed too, manifest first, so the store ends empty rather than
138
+ * accumulating a signed-out entry per identity. An empty store reads as signed out with a fresh
139
+ * generation, which supersedes an in-flight login exactly as the tombstone's generation did.
140
+ */
77
141
  async clear(tombstone) {
78
- // Commit the token-free generation first so interrupted cleanup cannot expose old tokens.
79
142
  try {
80
143
  const text = Buffer.from(tombstone, 'utf8').toString('base64');
81
144
  if (!text || text.length > CHUNK_SIZE)
@@ -85,9 +148,267 @@ export class KeyringCredentialStore {
85
148
  for (let b = 0; b < 2; b++)
86
149
  for (let i = b === 0 ? 1 : 0; i < CHUNKS; i++)
87
150
  await (await this.entry(`${b}.${i}`)).deleteCredential();
151
+ await (await this.entry('manifest')).deleteCredential();
152
+ await (await this.entry('0.0')).deleteCredential();
153
+ }
154
+ catch (error) {
155
+ throw keyringFailure(error, 'Unable to clear all credentials from the OS store. Unlock it and run logout again.');
156
+ }
157
+ }
158
+ /**
159
+ * Delete every entry of this credential. The manifest goes first, so an interrupted removal reads
160
+ * as empty rather than as a manifest naming chunks that are gone.
161
+ */
162
+ async remove() {
163
+ try {
164
+ await (await this.entry('manifest')).deleteCredential();
165
+ for (let b = 0; b < 2; b++)
166
+ for (let i = 0; i < CHUNKS; i++)
167
+ await (await this.entry(`${b}.${i}`)).deleteCredential();
168
+ }
169
+ catch (error) {
170
+ throw keyringFailure(error, 'Unable to remove the credential from the OS store. Unlock it and retry.');
171
+ }
172
+ }
173
+ async location() { return { kind: 'keyring' }; }
174
+ }
175
+ /**
176
+ * Every credential scope the OS store holds under `service`, whichever identity or home wrote it.
177
+ *
178
+ * Scopes are hashes, so this cannot say which home a scope belongs to or whether it is still in
179
+ * use; only an explicit "sign out everywhere" acts on scopes other than the current one.
180
+ */
181
+ export async function keyringScopes(service = SIGN_IN_SERVICE) {
182
+ const native = await nativeKeyring();
183
+ let credentials;
184
+ try {
185
+ credentials = await native.findCredentialsAsync(service);
186
+ }
187
+ catch (error) {
188
+ throw keyringFailure(error, `Unable to list the OS credential store. ${LOCKED_HINT}`);
189
+ }
190
+ return [...new Set(credentials.map(item => /^([0-9a-f]{32})\./.exec(item.account)?.[1]).filter((scope) => scope !== undefined))];
191
+ }
192
+ /**
193
+ * A session kept in one owner-only file, for machines that have no OS credential store: a VPS
194
+ * reached over SSH, a container, a minimal Linux install without Secret Service.
195
+ *
196
+ * The file is created 0600 inside a 0700 directory and replaced atomically, so a reader never
197
+ * sees a half-written session and no other local user can read it. It is still a plaintext file,
198
+ * which is why the OS store is preferred wherever one exists.
199
+ */
200
+ export class FileCredentialStore {
201
+ path;
202
+ constructor(path) {
203
+ this.path = path;
204
+ }
205
+ /** Whether a session file (or a signed-out tombstone) exists. A store that cannot tell fails. */
206
+ async exists() {
207
+ try {
208
+ await stat(this.path);
209
+ return true;
210
+ }
211
+ catch (error) {
212
+ if (error.code === 'ENOENT')
213
+ return false;
214
+ throw new AuthError('storage', `Unable to read the credential file ${this.path}.`);
215
+ }
216
+ }
217
+ async read() {
218
+ try {
219
+ return await readFile(this.path, 'utf8');
220
+ }
221
+ catch (error) {
222
+ if (error.code === 'ENOENT')
223
+ return undefined;
224
+ throw new AuthError('storage', `Unable to read the credential file ${this.path}.`);
225
+ }
226
+ }
227
+ async write(value) {
228
+ const temporary = `${this.path}.${process.pid}.${randomUUID()}.tmp`;
229
+ try {
230
+ await mkdir(dirname(this.path), { recursive: true, mode: 0o700 });
231
+ const handle = await open(temporary, 'wx', 0o600);
232
+ try {
233
+ await handle.writeFile(value, 'utf8');
234
+ await handle.sync();
235
+ }
236
+ finally {
237
+ await handle.close();
238
+ }
239
+ await rename(temporary, this.path);
240
+ // A file that predates this write keeps the mode it was created with; rename replaced it,
241
+ // but an umask-widened or hand-made file must not stay readable by others.
242
+ await chmod(this.path, 0o600).catch(() => { });
88
243
  }
89
244
  catch {
90
- throw new AuthError('storage', 'Unable to clear all credentials from the OS store. Unlock it and run logout again.');
245
+ await rm(temporary, { force: true }).catch(() => { });
246
+ throw new AuthError('storage', `Unable to save credentials to ${this.path}. Check that the directory is writable.`);
91
247
  }
92
248
  }
249
+ /**
250
+ * Replace the session with the tombstone and erase what interrupted writes left behind.
251
+ *
252
+ * A process killed between writing its temporary file and renaming it leaves a whole session
253
+ * beside the store, which no read ever sees and no sign-out would otherwise reach. Callers hold
254
+ * the auth lock, so no write of this store is in flight while the leftovers are removed.
255
+ */
256
+ async clear(tombstone) {
257
+ await this.write(tombstone);
258
+ await this.removeInterruptedWrites();
259
+ }
260
+ /** Delete the session file and any interrupted writes beside it. */
261
+ async remove() {
262
+ try {
263
+ await rm(this.path, { force: true });
264
+ }
265
+ catch {
266
+ throw new AuthError('storage', `Unable to remove the credential file ${this.path}. Delete it by hand.`);
267
+ }
268
+ await this.removeInterruptedWrites();
269
+ }
270
+ async removeInterruptedWrites() {
271
+ const directory = dirname(this.path), prefix = `${basename(this.path)}.`;
272
+ try {
273
+ for (const name of await readdir(directory))
274
+ if (name.startsWith(prefix) && name.endsWith('.tmp'))
275
+ await rm(join(directory, name), { force: true });
276
+ }
277
+ catch (error) {
278
+ if (error.code === 'ENOENT')
279
+ return;
280
+ throw new AuthError('storage', `Signed out, but leftover credential files next to ${this.path} could not be removed. Delete ${this.path}.*.tmp by hand.`);
281
+ }
282
+ }
283
+ async location() { return { kind: 'file', path: this.path }; }
284
+ }
285
+ /** `ANDORRA_CREDENTIAL_STORE=file|keyring` forces a store; anything else chooses automatically. */
286
+ export function credentialStoreMode(environment = process.env) {
287
+ const value = environment.ANDORRA_CREDENTIAL_STORE?.trim().toLowerCase();
288
+ return value === 'file' || value === 'keyring' ? value : 'auto';
289
+ }
290
+ /**
291
+ * The OS credential store, falling back to an owner-only file where the OS has none.
292
+ *
293
+ * The fallback exists for Linux and other Unix machines without Secret Service, which is what a
294
+ * VPS reached over SSH usually is. macOS and Windows always ship a credential store, so there a
295
+ * keyring failure means a locked or broken keychain and is reported instead of silently writing a
296
+ * plaintext file. Once a session file exists it stays the store, so concurrent processes and later
297
+ * runs never split one login between two places.
298
+ */
299
+ export class FallbackCredentialStore {
300
+ keyring;
301
+ file;
302
+ mode;
303
+ fallback;
304
+ constructor(keyring, file, mode = 'auto', fallback = process.platform !== 'win32' && process.platform !== 'darwin') {
305
+ this.keyring = keyring;
306
+ this.file = file;
307
+ this.mode = mode;
308
+ this.fallback = fallback;
309
+ }
310
+ /**
311
+ * Whether the file is the store. In automatic mode only a file that exists selects it: that is
312
+ * the one choice every process sees alike. A keyring failure alone never pins a process to a file
313
+ * nobody wrote, so a keyring that recovers, or that another process signed in through, is read
314
+ * again on the next call.
315
+ */
316
+ async useFile() {
317
+ if (this.mode === 'file')
318
+ return true;
319
+ if (this.mode === 'keyring' || !this.fallback)
320
+ return false;
321
+ return this.file.exists();
322
+ }
323
+ /** Run on the keyring; where this machine has none and the fallback applies, use the file for this
324
+ * call. A write there creates the file, which moves every process to it. A keyring that exists but
325
+ * is locked or failing is reported instead: it may hold the session, and a file beside it would
326
+ * hide that session rather than replace it. */
327
+ async keyringOr(operation) {
328
+ if (await this.useFile())
329
+ return operation(this.file);
330
+ try {
331
+ return await operation(this.keyring);
332
+ }
333
+ catch (error) {
334
+ if (this.mode !== 'auto' || !this.fallback || !(error instanceof KeyringAbsentError))
335
+ throw error;
336
+ return operation(this.file);
337
+ }
338
+ }
339
+ /** Clear the keyring. Only a machine without one has nothing to clear; a locked or failing keyring
340
+ * may still hold tokens, so its failure is reported. */
341
+ async clearReachableKeyring(tombstone) {
342
+ try {
343
+ await this.keyring.clear(tombstone);
344
+ }
345
+ catch (error) {
346
+ if (!(error instanceof KeyringAbsentError))
347
+ throw error;
348
+ }
349
+ }
350
+ read() { return this.keyringOr(store => store.read()); }
351
+ write(value) { return this.keyringOr(store => store.write(value)); }
352
+ /**
353
+ * The session held by whichever store is not in use.
354
+ *
355
+ * Either store can keep an older session beside the active one: the keyring's, from before
356
+ * `ANDORRA_CREDENTIAL_STORE=file` or hidden by a briefly unavailable keyring when a login fell
357
+ * back; the file's, when `ANDORRA_CREDENTIAL_STORE=keyring` is set after a fallback login. A store
358
+ * that cannot be read holds nothing this process can reach, which is the ordinary state of a
359
+ * keyring on a machine without one.
360
+ */
361
+ async previous() {
362
+ const inactive = await this.useFile() ? this.keyring : this.file;
363
+ try {
364
+ const text = await inactive.read();
365
+ return text !== undefined && holdsSession(text) ? text : undefined;
366
+ }
367
+ catch {
368
+ return undefined;
369
+ }
370
+ }
371
+ /**
372
+ * Sign out of both stores.
373
+ *
374
+ * Unlike reads and writes, a keyring clear never falls back just because it failed: a keyring
375
+ * that committed its tombstone and then could not delete an old token chunk still holds that
376
+ * token, and switching to the file would report a sign-out that left it behind. Only a keyring
377
+ * that cannot even be read holds nothing to clear, which is a machine without one.
378
+ *
379
+ * The other store is cleared too. A reachable keyring is cleared whether or not a session reads
380
+ * back from it, because an interrupted keyring write leaves token chunks without the manifest
381
+ * that would show them; failing to clear it is reported. While the keyring is the store, the file side is removed
382
+ * outright whatever it holds (a session, a tombstone, or only interrupted writes), so no plaintext
383
+ * token outlives the sign-out and automatic mode returns to the keyring rather than sticking to a
384
+ * signed-out file.
385
+ */
386
+ async clear(tombstone) {
387
+ if (await this.useFile()) {
388
+ await this.file.clear(tombstone);
389
+ await this.clearReachableKeyring(tombstone);
390
+ return;
391
+ }
392
+ if (this.mode !== 'auto' || !this.fallback)
393
+ await this.keyring.clear(tombstone);
394
+ else
395
+ await this.clearReachableKeyring(tombstone);
396
+ await this.file.remove();
397
+ }
398
+ async location() { return await this.useFile() ? this.file.location() : { kind: 'keyring' }; }
399
+ }
400
+ /** Whether stored text carries a session, rather than a signed-out tombstone. Unreadable text counts. */
401
+ function holdsSession(text) {
402
+ try {
403
+ const value = JSON.parse(text);
404
+ return Boolean(value && typeof value === 'object' && value.session);
405
+ }
406
+ catch {
407
+ return true;
408
+ }
409
+ }
410
+ /** The default store for a credential identity: see `FallbackCredentialStore`. */
411
+ export function createCredentialStore(identity, environment = process.env) {
412
+ const home = environment.ANDORRACODE_HOME || join(homedir(), '.andorracode');
413
+ return new FallbackCredentialStore(new KeyringCredentialStore(identity), new FileCredentialStore(join(home, `credentials-${credentialScope(identity)}.json`)), credentialStoreMode(environment));
93
414
  }
@@ -5,10 +5,18 @@ export interface AuthConfiguration {
5
5
  redirectUri: string;
6
6
  apiBaseUrl: string;
7
7
  }
8
+ /** Where a session is kept: the OS credential store, or an owner-only file where no OS store exists. */
9
+ export type CredentialLocation = {
10
+ kind: 'keyring';
11
+ } | {
12
+ kind: 'file';
13
+ path: string;
14
+ };
8
15
  export interface AuthStatus {
9
16
  signedIn: boolean;
10
17
  subject?: string;
11
18
  expiresAt?: number;
19
+ storage?: CredentialLocation;
12
20
  }
13
21
  export declare class AuthError extends Error {
14
22
  readonly code: 'configuration' | 'storage' | 'busy' | 'cancelled' | 'callback' | 'network' | 'invalid_token' | 'login_required' | 'superseded';
@@ -19,6 +27,14 @@ export declare class AuthError extends Error {
19
27
  export interface CredentialStore {
20
28
  read(): Promise<string | undefined>;
21
29
  write(value: string): Promise<void>;
22
- /** Erase every token chunk, including interrupted writes, and retain only the supplied tombstone. */
30
+ /**
31
+ * Erase every token chunk, including interrupted writes. The tombstone is committed first so an
32
+ * interrupted clear never exposes a session; a store may then drop it too (the OS keyring does,
33
+ * and reads as empty), or keep it (the session file does, so it stays the store in use).
34
+ */
23
35
  clear(tombstone: string): Promise<void>;
36
+ /** Where the last successful write landed, when the store can say. */
37
+ location?(): Promise<CredentialLocation>;
38
+ /** A session still held by a store this one no longer uses, so sign-out can revoke it too. */
39
+ previous?(): Promise<string | undefined>;
24
40
  }
@@ -1,5 +1,14 @@
1
1
  /** Account commands load native credential storage only when account access is requested. */
2
- export declare function executeAuthCommand(action: string, options?: {
2
+ export interface AuthCommandOptions {
3
3
  signal?: AbortSignal;
4
4
  print?: (message: string) => void;
5
- }): Promise<string>;
5
+ /** Print the sign-in address instead of opening a browser on this machine. */
6
+ noBrowser?: boolean;
7
+ /** Read the callback address pasted back from the device that signed in. */
8
+ readCallback?: (prompt: string, signal: AbortSignal) => Promise<string>;
9
+ /** Offer the sign-in address on the clipboard where the screen cannot show it copyably. */
10
+ copyAddress?: (url: string) => void;
11
+ /** Logout only: also delete the sign-ins every other home or deployment saved on this machine. */
12
+ everywhere?: boolean;
13
+ }
14
+ export declare function executeAuthCommand(action: string, options?: AuthCommandOptions): Promise<string>;
@@ -1,11 +1,12 @@
1
1
  import { getAccountPresentation, SIGNED_OUT_ACCOUNT } from './account-presentation.js';
2
- /** Account commands load native credential storage only when account access is requested. */
3
2
  export async function executeAuthCommand(action, options = {}) {
4
3
  const auth = await import('./auth/index.js');
5
4
  switch (action) {
6
5
  case 'login': {
7
- await auth.login({ signal: options.signal, onMessage: options.print });
8
- const success = 'Signed in to Andorra Code. Your session is saved securely on this machine until you log out or access expires or is revoked.';
6
+ const status = await auth.login({ signal: options.signal, onMessage: options.print, noBrowser: options.noBrowser, readCallback: options.readCallback, copyAddress: options.copyAddress });
7
+ const success = status?.storage?.kind === 'file'
8
+ ? `Signed in to Andorra Code. This machine has no OS credential store, so your session is saved in ${status.storage.path}, readable only by your user, until you log out or access expires or is revoked.`
9
+ : 'Signed in to Andorra Code. Your session is saved securely on this machine until you log out or access expires or is revoked.';
9
10
  // Login has committed. A cancelled or unavailable status refresh cannot undo it.
10
11
  try {
11
12
  const account = await getAccountPresentation(options.signal);
@@ -15,14 +16,20 @@ export async function executeAuthCommand(action, options = {}) {
15
16
  return `${success}\nAccount status refresh did not complete. Use /auth status to retry.`;
16
17
  }
17
18
  }
18
- case 'logout':
19
- return ((await auth.logout(options.signal)).revoked
19
+ case 'logout': {
20
+ const result = await auth.logout(options.signal, options.everywhere ? { everywhere: true } : {});
21
+ const own = result.revoked
20
22
  ? 'Signed out of Andorra Code on this machine.'
21
- : 'Signed out locally. Remote token revocation could not be confirmed; retry login when connected if you need to manage account access.') + `\n${SIGNED_OUT_ACCOUNT.notice}`;
23
+ : 'Signed out locally. Remote token revocation could not be confirmed; retry login when connected if you need to manage account access.';
24
+ const others = result.others === undefined ? ''
25
+ : result.others.removed === 0 ? '\nNo other saved sign-ins were found in the OS credential store.'
26
+ : `\nRemoved ${result.others.removed} other saved sign-in${result.others.removed === 1 ? '' : 's'} from the OS credential store${result.others.revoked ? '.' : '; some of their tokens could not be revoked remotely (for example, ones issued by another deployment).'}`;
27
+ return `${own}${others}\n${SIGNED_OUT_ACCOUNT.notice}`;
28
+ }
22
29
  case 'status': {
23
30
  const account = await getAccountPresentation(options.signal);
24
31
  return `Andorra account: ${account.label}.\n${account.notice}`;
25
32
  }
26
- default: return 'Usage: andorra login | andorra logout | andorra auth status';
33
+ default: return 'Usage: andorra login | andorra logout [--all] | andorra auth status';
27
34
  }
28
35
  }