@andorra-labs/code 0.1.11 → 0.1.12

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 (114) hide show
  1. package/README.md +8 -2
  2. package/THIRD_PARTY_NOTICES.md +15 -0
  3. package/dist/src/agent-execution.js +15 -3
  4. package/dist/src/agent-mcp.js +5 -0
  5. package/dist/src/app-server/protocol.d.ts +8 -1
  6. package/dist/src/app-server/protocol.js +1 -1
  7. package/dist/src/app-server.d.ts +15 -0
  8. package/dist/src/app-server.js +89 -10
  9. package/dist/src/browser-panel-tool.d.ts +24 -3
  10. package/dist/src/browser-panel-tool.js +80 -6
  11. package/dist/src/browser-runner.js +3 -1
  12. package/dist/src/browser-view.d.ts +16 -0
  13. package/dist/src/browser-view.js +38 -2
  14. package/dist/src/claude-provider.js +15 -2
  15. package/dist/src/cli.d.ts +2 -1
  16. package/dist/src/cli.js +175 -43
  17. package/dist/src/code-intelligence/CodeIntelligenceManager.js +1 -1
  18. package/dist/src/codex-provider.js +6 -3
  19. package/dist/src/coding-tools.d.ts +2 -1
  20. package/dist/src/coding-tools.js +39 -31
  21. package/dist/src/completion.d.ts +43 -1
  22. package/dist/src/completion.js +145 -4
  23. package/dist/src/config.d.ts +1 -0
  24. package/dist/src/config.js +2 -0
  25. package/dist/src/decision/PreparedSteps.js +1 -1
  26. package/dist/src/delegation-changes.js +19 -2
  27. package/dist/src/diff-preview.d.ts +1 -0
  28. package/dist/src/diff-preview.js +12 -3
  29. package/dist/src/engine-streams.d.ts +22 -0
  30. package/dist/src/engine-streams.js +16 -0
  31. package/dist/src/extensions.js +17 -6
  32. package/dist/src/file-read-key.d.ts +8 -0
  33. package/dist/src/file-read-key.js +12 -0
  34. package/dist/src/graph-editor-session.js +2 -1
  35. package/dist/src/graph-health.d.ts +21 -0
  36. package/dist/src/graph-health.js +46 -0
  37. package/dist/src/graph-manager-chat.d.ts +52 -3
  38. package/dist/src/graph-manager-chat.js +50 -5
  39. package/dist/src/graph-runner.js +23 -3
  40. package/dist/src/graph-server.d.ts +1 -1
  41. package/dist/src/graph-server.js +39 -18
  42. package/dist/src/graph-ui/app.js +100 -30
  43. package/dist/src/graph-ui/controls.css +52 -0
  44. package/dist/src/graph-ui/icons.js +3 -0
  45. package/dist/src/graph-ui/index.html +2 -2
  46. package/dist/src/graph-ui/manager-state.js +141 -3
  47. package/dist/src/graph-ui/manager.css +2 -2
  48. package/dist/src/graph-ui/manager.js +328 -66
  49. package/dist/src/graph-ui/model-picker.js +279 -0
  50. package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
  51. package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
  52. package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
  53. package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
  54. package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
  55. package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
  56. package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
  57. package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
  58. package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
  59. package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
  60. package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
  61. package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
  62. package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
  63. package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
  64. package/dist/src/graphs.d.ts +2 -0
  65. package/dist/src/graphs.js +7 -7
  66. package/dist/src/mcp.d.ts +52 -14
  67. package/dist/src/mcp.js +285 -128
  68. package/dist/src/memory/ProjectMemory.d.ts +77 -0
  69. package/dist/src/memory/ProjectMemory.js +310 -0
  70. package/dist/src/memory/index.d.ts +1 -0
  71. package/dist/src/memory/index.js +1 -0
  72. package/dist/src/opencode-provider.js +5 -6
  73. package/dist/src/package-name.d.ts +3 -0
  74. package/dist/src/package-name.js +3 -0
  75. package/dist/src/provider-engine.js +2 -2
  76. package/dist/src/qa/runtime/PtyManager.js +2 -1
  77. package/dist/src/react-runtime.js +16 -8
  78. package/dist/src/remote/cert.d.ts +1 -1
  79. package/dist/src/remote/cert.js +2 -7
  80. package/dist/src/remote/client.js +1 -1
  81. package/dist/src/remote/pem.d.ts +6 -0
  82. package/dist/src/remote/pem.js +11 -0
  83. package/dist/src/run-records.js +49 -10
  84. package/dist/src/runtime.d.ts +2 -0
  85. package/dist/src/sessions.d.ts +3 -1
  86. package/dist/src/sessions.js +5 -3
  87. package/dist/src/sign-in-detection.d.ts +82 -0
  88. package/dist/src/sign-in-detection.js +197 -0
  89. package/dist/src/sign-in-offer.d.ts +35 -0
  90. package/dist/src/sign-in-offer.js +116 -0
  91. package/dist/src/skills/bundled/graph-manager/SKILL.md +22 -4
  92. package/dist/src/skills/bundled/provenance.json +1 -1
  93. package/dist/src/skills/runtime-skills.d.ts +6 -0
  94. package/dist/src/skills/runtime-skills.js +13 -0
  95. package/dist/src/stray-files.d.ts +14 -0
  96. package/dist/src/stray-files.js +81 -0
  97. package/dist/src/subagent-run.js +6 -1
  98. package/dist/src/terminal-ui.d.ts +1 -1
  99. package/dist/src/terminal-ui.js +9 -3
  100. package/dist/src/tool-activity.js +1 -1
  101. package/dist/src/tool-schema-compatibility.d.ts +7 -2
  102. package/dist/src/tool-schema-compatibility.js +8 -4
  103. package/dist/src/transcript.d.ts +5 -0
  104. package/dist/src/transcript.js +11 -3
  105. package/dist/src/types.d.ts +2 -0
  106. package/dist/src/untracked-file-removal.d.ts +3 -0
  107. package/dist/src/untracked-file-removal.js +125 -0
  108. package/dist/src/update-check.js +1 -1
  109. package/dist/src/update.d.ts +11 -1
  110. package/dist/src/update.js +27 -5
  111. package/dist/src/workspace-git-metadata.d.ts +15 -0
  112. package/dist/src/workspace-git-metadata.js +50 -1
  113. package/dist/src/workspace-instructions.js +1 -1
  114. package/package.json +1 -1
@@ -170,7 +170,9 @@ export declare function carryRailOwnedFields(record: SavedSession, stored: Saved
170
170
  /**
171
171
  * A saved history as a reader displays it. A turn recorded before completion parsing decoded a
172
172
  * twice-escaped summary still holds a backslash and an "n" where its line breaks belong, and its
173
- * markdown draws as one literal paragraph; the stored record is left as written.
173
+ * markdown draws as one literal paragraph. A turn recorded before the host removed completion fields
174
+ * a model echoed as text under its answer (`stripEchoedEnvelope`) still shows them. The stored
175
+ * record is left as written.
174
176
  */
175
177
  export declare function displayHistory(history: ConversationTurn[]): ConversationTurn[];
176
178
  /** Stable opaque grouping key derived from the raw workspace path, before any secret redaction. */
@@ -4,7 +4,7 @@ import { mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promise
4
4
  import { join, resolve } from 'node:path';
5
5
  import { stripVTControlCharacters } from 'node:util';
6
6
  import { setTimeout as delay } from 'node:timers/promises';
7
- import { decodeDoubleEscapedSummary } from './completion.js';
7
+ import { decodeDoubleEscapedSummary, stripEchoedEnvelope } from './completion.js';
8
8
  import { redactSecrets } from './secret-redaction.js';
9
9
  /** Extract a short local task label without a model request. */
10
10
  export const sessionName = (prompt) => {
@@ -132,11 +132,13 @@ export function carryRailOwnedFields(record, stored) {
132
132
  /**
133
133
  * A saved history as a reader displays it. A turn recorded before completion parsing decoded a
134
134
  * twice-escaped summary still holds a backslash and an "n" where its line breaks belong, and its
135
- * markdown draws as one literal paragraph; the stored record is left as written.
135
+ * markdown draws as one literal paragraph. A turn recorded before the host removed completion fields
136
+ * a model echoed as text under its answer (`stripEchoedEnvelope`) still shows them. The stored
137
+ * record is left as written.
136
138
  */
137
139
  export function displayHistory(history) {
138
140
  return history.map(turn => {
139
- const summary = decodeDoubleEscapedSummary(turn.completion.summary);
141
+ const summary = stripEchoedEnvelope(decodeDoubleEscapedSummary(turn.completion.summary), turn.completion.outcome);
140
142
  return summary === turn.completion.summary ? turn : { ...turn, completion: { ...turn.completion, summary } };
141
143
  });
142
144
  }
@@ -0,0 +1,82 @@
1
+ import type { Config } from './config.js';
2
+ import type { ProviderConfig } from './providers.js';
3
+ /**
4
+ * Finding the vendor CLIs a person is already signed in to, and turning the ones they pick into
5
+ * provider entries.
6
+ *
7
+ * These four provider types run through the CLI's own login, so nothing here reads, copies or stores
8
+ * a credential: detection asks each CLI what it would tell its own user, and an import writes a
9
+ * configuration entry that names the type. Only display text and model ids leave this module.
10
+ */
11
+ export declare const DETECTABLE_SIGN_IN_TYPES: readonly ["claude", "codex", "grok", "opencode"];
12
+ export type DetectableSignInType = typeof DETECTABLE_SIGN_IN_TYPES[number];
13
+ export declare function isDetectableSignInType(value: unknown): value is DetectableSignInType;
14
+ /** One signed-in CLI with no provider yet. `model` is the preselection; OpenCode never has one. */
15
+ export interface DetectedSignIn {
16
+ type: DetectableSignInType;
17
+ email?: string;
18
+ planType?: string;
19
+ detail?: string;
20
+ models: string[];
21
+ model?: string;
22
+ }
23
+ /** What one CLI says about itself, before any of it is trusted for display. */
24
+ export interface SignInProbe {
25
+ signedIn: boolean;
26
+ email?: string;
27
+ planType?: string;
28
+ detail?: string;
29
+ models: string[];
30
+ defaultModel?: string;
31
+ }
32
+ export type SignInProbes = Record<DetectableSignInType, (signal: AbortSignal) => Promise<SignInProbe>>;
33
+ export interface DetectOptions {
34
+ /** Types to leave alone: no process is started for them. Unknown names are ignored. */
35
+ skip?: readonly string[];
36
+ probes?: Partial<SignInProbes>;
37
+ /** The bound on each probe; the slowest reader bounds itself at 45 seconds. */
38
+ timeoutMs?: number;
39
+ }
40
+ export interface DetectionResult {
41
+ signIns: DetectedSignIn[];
42
+ timedOut: DetectableSignInType[];
43
+ }
44
+ /**
45
+ * The readers the product already uses, each behind a look for its executable.
46
+ *
47
+ * The resolvers only inspect the machine — none installs or downloads — so a CLI that is absent
48
+ * answers signed-out without a process being started for it.
49
+ */
50
+ export declare function defaultSignInProbes(): SignInProbes;
51
+ /**
52
+ * Ask every CLI that has no provider yet whether it is signed in.
53
+ *
54
+ * Each probe stands alone: one that fails, is absent or outlives the bound contributes nothing and
55
+ * never fails the call. A type that already has a provider is not asked — for Codex that is any
56
+ * Codex provider, since a second one is always given a fresh, signed-out account slot.
57
+ */
58
+ export declare function detectSignIns(config: Pick<Config, 'providers'>, signal: AbortSignal, options?: DetectOptions): Promise<DetectionResult>;
59
+ export interface SignInImport {
60
+ type: DetectableSignInType;
61
+ model: string;
62
+ }
63
+ /** The provider entry for one detected sign-in with the model the person chose from its catalog. */
64
+ export declare function importedProvider(detected: DetectedSignIn, model: string, taken: (id: string) => boolean): ProviderConfig;
65
+ /**
66
+ * Whether the active provider could start a task as configured. Only two things say it could not:
67
+ * there is no active provider, or it names a key variable that is unset and holds no saved key. A
68
+ * provider that asks for no key at all (a local server, a private gateway) is someone's deliberate
69
+ * choice and is never displaced by an import.
70
+ */
71
+ export declare function providerCanRun(config: Pick<Config, 'provider' | 'providers'>, env?: NodeJS.ProcessEnv): boolean;
72
+ /**
73
+ * The configuration after importing the chosen sign-ins.
74
+ *
75
+ * A type that gained a provider since detection is skipped rather than duplicated: the file is
76
+ * shared with other windows and the CLI. The first entry added becomes the active provider only
77
+ * when the current one could not start a task.
78
+ */
79
+ export declare function applySignInImports(config: Config, detected: readonly DetectedSignIn[], imports: readonly SignInImport[], env?: NodeJS.ProcessEnv): {
80
+ config: Config;
81
+ added: string[];
82
+ };
@@ -0,0 +1,197 @@
1
+ import { resolveClaudeExecutable } from './claude-executable.js';
2
+ import { readClaudeCatalog, readClaudeSignIn } from './claude-provider.js';
3
+ import { resolveCliExecutable } from './cli-executable.js';
4
+ import { readCodexModels } from './codex-auth.js';
5
+ import { resolveCodexExecutable } from './codex-executable.js';
6
+ import { connectCodex } from './codex-rpc.js';
7
+ import { GROK_BASE_URL, GROK_EXECUTABLE, readGrokCatalog } from './grok-provider.js';
8
+ import { OPENCODE_BASE_URL, OPENCODE_EXECUTABLE, readOpenCodeCatalog, sharedOpenCodeServer } from './opencode-cli-provider.js';
9
+ import { uniqueProviderId } from './provider-import.js';
10
+ /**
11
+ * Finding the vendor CLIs a person is already signed in to, and turning the ones they pick into
12
+ * provider entries.
13
+ *
14
+ * These four provider types run through the CLI's own login, so nothing here reads, copies or stores
15
+ * a credential: detection asks each CLI what it would tell its own user, and an import writes a
16
+ * configuration entry that names the type. Only display text and model ids leave this module.
17
+ */
18
+ export const DETECTABLE_SIGN_IN_TYPES = ['claude', 'codex', 'grok', 'opencode'];
19
+ export function isDetectableSignInType(value) {
20
+ return DETECTABLE_SIGN_IN_TYPES.includes(value);
21
+ }
22
+ const SIGNED_OUT = { signedIn: false, models: [] };
23
+ const MAX_MODELS = 5000;
24
+ /** OpenCode lists every model of every upstream provider it has connected; no entry stores all of them. */
25
+ const FIXED_BASE_URL = {
26
+ claude: 'https://api.anthropic.com', codex: 'https://chatgpt.com/backend-api/codex', grok: GROK_BASE_URL, opencode: OPENCODE_BASE_URL,
27
+ };
28
+ const DISPLAY_NAME = { claude: 'Claude', codex: 'ChatGPT', grok: 'Grok', opencode: 'OpenCode' };
29
+ /**
30
+ * The readers the product already uses, each behind a look for its executable.
31
+ *
32
+ * The resolvers only inspect the machine — none installs or downloads — so a CLI that is absent
33
+ * answers signed-out without a process being started for it.
34
+ */
35
+ export function defaultSignInProbes() {
36
+ const present = async (resolve) => { try {
37
+ await resolve();
38
+ return true;
39
+ }
40
+ catch {
41
+ return false;
42
+ } };
43
+ return {
44
+ claude: async (signal) => {
45
+ if (!await present(() => resolveClaudeExecutable()))
46
+ return SIGNED_OUT;
47
+ // Side by side rather than one after the other: each is its own CLI start, and the TUI's whole
48
+ // look is bounded in seconds.
49
+ const [account, catalog] = await Promise.all([readClaudeSignIn(signal), readClaudeCatalog(signal)]);
50
+ if (!account.signedIn || !catalog.signedIn)
51
+ return SIGNED_OUT;
52
+ const { models } = catalog;
53
+ return { signedIn: true, models, ...(account.email ? { email: account.email } : {}), ...(account.planType ? { planType: account.planType } : {}) };
54
+ },
55
+ codex: async (signal) => {
56
+ if (!await present(() => resolveCodexExecutable({ signal })))
57
+ return SIGNED_OUT;
58
+ // The default home: a detected login is the one the person's own codex command uses. The
59
+ // connection is this probe's own and follows its signal, so a look that is abandoned stops the
60
+ // app-server it started instead of leaving it to finish on its own clock.
61
+ const rpc = await connectCodex(signal);
62
+ try {
63
+ const account = (await rpc.request('account/read', { refreshToken: false }))?.account;
64
+ if (account?.type !== 'chatgpt')
65
+ return SIGNED_OUT;
66
+ const models = await readCodexModels(rpc);
67
+ signal.throwIfAborted();
68
+ const preferred = models.find(model => model.isDefault)?.id;
69
+ return { signedIn: true, models: models.map(model => model.id), ...(preferred ? { defaultModel: preferred } : {}),
70
+ ...(typeof account.email === 'string' ? { email: account.email } : {}), ...(typeof account.planType === 'string' ? { planType: account.planType } : {}) };
71
+ }
72
+ finally {
73
+ rpc.close();
74
+ }
75
+ },
76
+ grok: async (signal) => {
77
+ if (!await present(() => resolveCliExecutable(GROK_EXECUTABLE)))
78
+ return SIGNED_OUT;
79
+ const catalog = await readGrokCatalog(signal);
80
+ return { signedIn: catalog.signedIn, models: catalog.models, ...(catalog.email ? { email: catalog.email } : {}) };
81
+ },
82
+ opencode: async (signal) => {
83
+ if (!await present(() => resolveCliExecutable(OPENCODE_EXECUTABLE)))
84
+ return SIGNED_OUT;
85
+ const catalog = await readOpenCodeCatalog(signal, sharedOpenCodeServer());
86
+ const count = catalog.connected.length;
87
+ return { signedIn: count > 0, models: catalog.models.map(model => model.id), detail: `${count} provider${count === 1 ? '' : 's'} connected` };
88
+ },
89
+ };
90
+ }
91
+ function displayText(value, max) {
92
+ return typeof value === 'string' && value.trim() && value.length <= max && !/[\u0000-\u001f\u007f]/.test(value) ? value : undefined;
93
+ }
94
+ function usableModels(models) {
95
+ const kept = [];
96
+ if (!Array.isArray(models))
97
+ return kept;
98
+ for (const model of models) {
99
+ if (kept.length >= MAX_MODELS)
100
+ break;
101
+ if (typeof model === 'string' && model.trim() && model.length <= 500 && !/[\u0000-\u001f\u007f]/.test(model) && !kept.includes(model))
102
+ kept.push(model);
103
+ }
104
+ return kept;
105
+ }
106
+ function describe(type, probe) {
107
+ if (probe.signedIn !== true)
108
+ return undefined;
109
+ const models = usableModels(probe.models);
110
+ if (!models.length)
111
+ return undefined;
112
+ const email = displayText(probe.email, 320);
113
+ const planType = displayText(probe.planType, 100);
114
+ const detail = displayText(probe.detail, 200);
115
+ // OpenCode's catalog spans upstream providers the person may pay for per use: choosing one is theirs.
116
+ const model = type === 'opencode' ? undefined : probe.defaultModel !== undefined && models.includes(probe.defaultModel) ? probe.defaultModel : models[0];
117
+ return { type, ...(email ? { email } : {}), ...(planType ? { planType } : {}), ...(detail ? { detail } : {}), models, ...(model ? { model } : {}) };
118
+ }
119
+ /**
120
+ * Ask every CLI that has no provider yet whether it is signed in.
121
+ *
122
+ * Each probe stands alone: one that fails, is absent or outlives the bound contributes nothing and
123
+ * never fails the call. A type that already has a provider is not asked — for Codex that is any
124
+ * Codex provider, since a second one is always given a fresh, signed-out account slot.
125
+ */
126
+ export async function detectSignIns(config, signal, options = {}) {
127
+ const probes = { ...(options.probes && DETECTABLE_SIGN_IN_TYPES.every(type => options.probes?.[type]) ? {} : defaultSignInProbes()), ...options.probes };
128
+ const timeoutMs = options.timeoutMs ?? 45_000;
129
+ const timedOut = [];
130
+ const wanted = DETECTABLE_SIGN_IN_TYPES.filter(type => !options.skip?.includes(type) && !config.providers.some(provider => provider.type === type));
131
+ const found = await Promise.all(wanted.map(async (type) => {
132
+ const deadline = AbortSignal.timeout(timeoutMs);
133
+ const bounded = AbortSignal.any([signal, deadline]);
134
+ try {
135
+ const probe = await new Promise((resolve, reject) => {
136
+ // A reader that ignores its signal must not hold the call past the bound.
137
+ bounded.addEventListener('abort', () => reject(new Error('aborted')), { once: true });
138
+ if (bounded.aborted) {
139
+ reject(new Error('aborted'));
140
+ return;
141
+ }
142
+ probes[type](bounded).then(resolve, reject);
143
+ });
144
+ return describe(type, probe);
145
+ }
146
+ catch {
147
+ if (deadline.aborted && !signal.aborted)
148
+ timedOut.push(type);
149
+ return undefined;
150
+ }
151
+ }));
152
+ return { signIns: found.filter((item) => item !== undefined), timedOut: DETECTABLE_SIGN_IN_TYPES.filter(type => timedOut.includes(type)) };
153
+ }
154
+ /** The provider entry for one detected sign-in with the model the person chose from its catalog. */
155
+ export function importedProvider(detected, model, taken) {
156
+ if (!detected.models.includes(model))
157
+ throw new Error(`${model} is not one of the models ${DISPLAY_NAME[detected.type]} lists.`);
158
+ const models = detected.type === 'opencode' ? [model] : [model, ...detected.models.filter(item => item !== model)];
159
+ return { id: uniqueProviderId(taken, detected.type), type: detected.type, baseUrl: FIXED_BASE_URL[detected.type], model, models, name: DISPLAY_NAME[detected.type] };
160
+ }
161
+ /**
162
+ * Whether the active provider could start a task as configured. Only two things say it could not:
163
+ * there is no active provider, or it names a key variable that is unset and holds no saved key. A
164
+ * provider that asks for no key at all (a local server, a private gateway) is someone's deliberate
165
+ * choice and is never displaced by an import.
166
+ */
167
+ export function providerCanRun(config, env = process.env) {
168
+ const active = config.providers.find(provider => provider.id === config.provider);
169
+ if (!active)
170
+ return false;
171
+ return !(active.apiKeyEnv && !env[active.apiKeyEnv] && !active.apiKey);
172
+ }
173
+ /**
174
+ * The configuration after importing the chosen sign-ins.
175
+ *
176
+ * A type that gained a provider since detection is skipped rather than duplicated: the file is
177
+ * shared with other windows and the CLI. The first entry added becomes the active provider only
178
+ * when the current one could not start a task.
179
+ */
180
+ export function applySignInImports(config, detected, imports, env = process.env) {
181
+ const providers = [...config.providers];
182
+ const added = [];
183
+ for (const choice of imports) {
184
+ const found = detected.find(item => item.type === choice.type);
185
+ if (!found)
186
+ throw new Error(`${DISPLAY_NAME[choice.type] ?? 'That tool'} was not detected as signed in.`);
187
+ const entry = importedProvider(found, choice.model, id => providers.some(provider => provider.id === id));
188
+ if (providers.some(provider => provider.type === choice.type))
189
+ continue;
190
+ providers.push(entry);
191
+ added.push(entry.id);
192
+ }
193
+ const next = { ...config, providers };
194
+ if (added.length && !providerCanRun(config, env))
195
+ next.provider = added[0];
196
+ return { config: next, added };
197
+ }
@@ -0,0 +1,35 @@
1
+ import { type DetectionResult } from './sign-in-detection.js';
2
+ /**
3
+ * The terminal's one-time offer to add the vendor CLIs a person is already signed in to.
4
+ *
5
+ * It runs before the interface starts, the way the update offer does, so it is bounded hard: the
6
+ * tools get eight seconds between them, and a tool that does not answer in time is tried again on
7
+ * the next launch, three launches at most. Nothing here may fail startup.
8
+ */
9
+ export interface SignInOfferState {
10
+ done?: boolean;
11
+ attempts?: number; /** Tools already answered about while another was still being retried. */
12
+ answered?: string[];
13
+ }
14
+ export declare function readSignInOfferState(home?: string): Promise<SignInOfferState>;
15
+ export declare function writeSignInOfferState(state: SignInOfferState, home?: string): Promise<void>;
16
+ /**
17
+ * What a typed answer chooses among `count` listed accounts: every index for an empty answer or
18
+ * yes, `'none'` for no, the named ones for numbers, and undefined for anything else.
19
+ */
20
+ export declare function parseSignInAnswer(answer: string, count: number): number[] | 'none' | undefined;
21
+ export interface SignInOfferOptions {
22
+ home?: string;
23
+ env?: NodeJS.ProcessEnv;
24
+ ask: (question: string) => Promise<string>;
25
+ write: (text: string) => void;
26
+ /** Overridable so a test never spawns a CLI. */
27
+ detect?: (home: string, signal: AbortSignal, skip: readonly string[]) => Promise<DetectionResult>;
28
+ }
29
+ /**
30
+ * Offer once per configuration home. Returns the ids of the providers added; never throws.
31
+ *
32
+ * OpenCode is named but never added here: its models span upstream providers that may bill per use,
33
+ * and choosing one is what the `/providers` screen is for.
34
+ */
35
+ export declare function offerSignInImport(options: SignInOfferOptions): Promise<string[]>;
@@ -0,0 +1,116 @@
1
+ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { stripVTControlCharacters } from 'node:util';
4
+ import { changeConfigFile, configDirectory, loadConfig } from './config.js';
5
+ import { applySignInImports, detectSignIns } from './sign-in-detection.js';
6
+ const DETECT_TIMEOUT_MS = 8_000;
7
+ const MAX_ATTEMPTS = 3;
8
+ const NAME = { claude: 'Claude', codex: 'ChatGPT', grok: 'Grok', opencode: 'OpenCode' };
9
+ const statePath = (home) => join(home, 'sign-in-offer.json');
10
+ export async function readSignInOfferState(home = configDirectory()) {
11
+ try {
12
+ const value = JSON.parse(await readFile(statePath(home), 'utf8'));
13
+ if (!value || typeof value !== 'object' || Array.isArray(value))
14
+ return {};
15
+ const record = value;
16
+ return {
17
+ ...(record.done === true ? { done: true } : {}),
18
+ ...(Number.isSafeInteger(record.attempts) && record.attempts > 0 ? { attempts: record.attempts } : {}),
19
+ ...(Array.isArray(record.answered) && record.answered.length > 0 && record.answered.length <= 8 && record.answered.every(item => typeof item === 'string') ? { answered: record.answered } : {}),
20
+ };
21
+ }
22
+ catch {
23
+ return {};
24
+ }
25
+ }
26
+ export async function writeSignInOfferState(state, home = configDirectory()) {
27
+ await mkdir(home, { recursive: true });
28
+ const target = statePath(home);
29
+ const temporary = `${target}.${process.pid}.tmp`;
30
+ await writeFile(temporary, JSON.stringify(state) + '\n', 'utf8');
31
+ await rename(temporary, target);
32
+ }
33
+ /**
34
+ * What a typed answer chooses among `count` listed accounts: every index for an empty answer or
35
+ * yes, `'none'` for no, the named ones for numbers, and undefined for anything else.
36
+ */
37
+ export function parseSignInAnswer(answer, count) {
38
+ const value = answer.trim().toLowerCase();
39
+ if (value === '' || value === 'y' || value === 'yes')
40
+ return Array.from({ length: count }, (_, index) => index);
41
+ if (value === 'n' || value === 'no')
42
+ return 'none';
43
+ const parts = value.split(/[\s,]+/).filter(Boolean);
44
+ if (!parts.length || parts.some(part => !/^\d{1,3}$/.test(part)))
45
+ return undefined;
46
+ const picked = [...new Set(parts.map(part => Number(part) - 1))].sort((a, b) => a - b);
47
+ return picked.some(index => index < 0 || index >= count) ? undefined : picked;
48
+ }
49
+ function plain(text) {
50
+ return stripVTControlCharacters(text).replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, '');
51
+ }
52
+ function summary(signIn) {
53
+ return [signIn.email, signIn.planType].filter(Boolean).join(' · ') || signIn.detail || 'signed in';
54
+ }
55
+ function listed(names) {
56
+ return names.length <= 1 ? names.join('') : `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
57
+ }
58
+ /**
59
+ * Offer once per configuration home. Returns the ids of the providers added; never throws.
60
+ *
61
+ * OpenCode is named but never added here: its models span upstream providers that may bill per use,
62
+ * and choosing one is what the `/providers` screen is for.
63
+ */
64
+ export async function offerSignInImport(options) {
65
+ const home = options.home ?? configDirectory();
66
+ const write = (text) => options.write(plain(text));
67
+ try {
68
+ const state = await readSignInOfferState(home);
69
+ if (state.done)
70
+ return [];
71
+ const attempts = (state.attempts ?? 0) + 1;
72
+ write('Looking for accounts you\'re already signed in to...\n');
73
+ const detect = options.detect ?? (async (directory, signal, skip) => detectSignIns(await loadConfig(directory), signal, { timeoutMs: DETECT_TIMEOUT_MS, skip }));
74
+ // A tool the person already answered about is not looked for again while a slow one is retried.
75
+ const answered = state.answered ?? [];
76
+ const { signIns, timedOut } = await detect(home, AbortSignal.timeout(DETECT_TIMEOUT_MS + 1_000), answered);
77
+ // A tool that ran out of time gets another launch, but not forever.
78
+ const finished = timedOut.length === 0 || attempts >= MAX_ATTEMPTS;
79
+ const addable = signIns.filter(signIn => signIn.type !== 'opencode' && signIn.model !== undefined);
80
+ const settle = (asked = false) => {
81
+ const known = [...new Set([...answered, ...(asked ? addable.map(signIn => signIn.type) : [])])];
82
+ return writeSignInOfferState(finished ? { done: true } : { attempts, ...(known.length ? { answered: known } : {}) }, home);
83
+ };
84
+ if (signIns.some(signIn => signIn.type === 'opencode'))
85
+ write('OpenCode is signed in too. Run /providers to add it with a model.\n');
86
+ if (!addable.length) {
87
+ await settle();
88
+ return [];
89
+ }
90
+ write('Found accounts you\'re already signed in to:\n');
91
+ addable.forEach((signIn, index) => write(` ${index + 1}. ${NAME[signIn.type].padEnd(8)} ${summary(signIn)}\n`));
92
+ let choice;
93
+ while (choice === undefined)
94
+ choice = parseSignInAnswer(await options.ask(`Add ${addable.length === 1 ? 'it as a provider' : 'them as providers'}? [Y]es / [n]o / numbers to pick (e.g. 1): `), addable.length);
95
+ if (choice === 'none') {
96
+ await settle(true);
97
+ return [];
98
+ }
99
+ const chosen = choice.map(index => addable[index]);
100
+ const imports = chosen.map(signIn => ({ type: signIn.type, model: signIn.model }));
101
+ let added = [];
102
+ const saved = await changeConfigFile(home, current => {
103
+ const applied = applySignInImports(current, chosen, imports, options.env ?? process.env);
104
+ added = applied.added;
105
+ return applied.config;
106
+ });
107
+ const names = saved.providers.filter(provider => added.includes(provider.id)).map(provider => provider.name ?? provider.id);
108
+ write(names.length ? `Added ${listed(names)}. Change models or add more with /providers.\n` : 'Those accounts already have providers.\n');
109
+ await settle(true);
110
+ return added;
111
+ }
112
+ catch {
113
+ // Startup continues exactly as it would have: the offer is a convenience, not a step.
114
+ return [];
115
+ }
116
+ }
@@ -33,12 +33,25 @@ changes with the product; this skill does not repeat it.
33
33
 
34
34
  ## 3. Understand what the user wants
35
35
 
36
- Ask until you can answer each of these:
36
+ Do what the user asks. When their message says what to build or change, work the answers below out of the
37
+ request, the canvas and the graph guide, and start building: an edit to an existing graph rarely needs a
38
+ question. Ask only when something you cannot infer would change the graph's shape (a vague request for a new
39
+ workflow, say), and then ask once, about that alone. Never ask the user to look up a field value or option:
40
+ the graph guide and the validation messages name every accepted value. The one exception is the provider and
41
+ model of an agent, covered below: when the user did not name it, ask before publishing.
42
+
43
+ What you need to know:
37
44
 
38
45
  - What the workflow is for, and what finished looks like.
39
46
  - The stages, in order, and what each one hands to the next.
40
47
  - Where work loops back (a failed review returns to the builder), and how many attempts are allowed.
41
48
  - Which provider and model each agent uses: list them with `andorra_providers_list` and use those ids only.
49
+ The user chooses these, not you. When the request does not name a provider and model for an agent you add,
50
+ or for one whose model you change, you may draft the node with a likely choice so the build can go on, but
51
+ ask the user before you publish: name each such agent, the provider and model you drafted, and the
52
+ alternatives `andorra_providers_list` offers, and wait for their answer. One question covers every agent
53
+ left unspecified. Keep an existing node's provider and model unless the request changes them; that needs no
54
+ question.
42
55
  - What each agent may touch (read only, write files, run shell, open pull requests).
43
56
  - What input a run needs beyond the task text.
44
57
  - When the workflow opens, reviews or fixes pull requests: which agent owns the PR and its review comments.
@@ -55,8 +68,12 @@ review --pass--> done (end)
55
68
  review --fail--> build (at most 3 rounds: limits.maxNodeVisits = 3, a per-node ceiling)
56
69
  ```
57
70
 
58
- Get the user's approval of the sketch before building anything. `patterns.md` in this skill has tested
59
- shapes for common workflows; read it with `read_skill_resource` (path `patterns.md`) when one fits.
71
+ For a concrete request, build straight away; do not stop for approval of a sketch. In Graph Studio each draft
72
+ change appears on the user's canvas as you make it, and nothing is saved until the user approves the publish,
73
+ so that approval is their review, except for an unspecified provider and model, which you still ask about
74
+ before publishing (see above). Sketch first and wait only when designing a new graph from a vague request.
75
+ `patterns.md` in this skill has tested shapes for common workflows; read it with `read_skill_resource` (path
76
+ `patterns.md`) when one fits.
60
77
 
61
78
  ## 4. Build or change it
62
79
 
@@ -107,7 +124,8 @@ and the upsert reply's `placed` says where it went.
107
124
  ## 5. Validate, show, publish
108
125
 
109
126
  1. `andorra_graph_validate` and fix every issue it reports; `errors.md` in this skill maps each code to its
110
- fix. Do not publish around an issue.
127
+ fix. Do not publish around an issue. If any agent's provider and model came from you rather than the user,
128
+ ask now (section 3) and apply their answer before going on.
111
129
  2. Describe the change to the user in chat, in plain words, before publishing. Outside Full Access, publishing
112
130
  asks the user to approve or deny, and that prompt shows only the raw call; under Full Access it publishes
113
131
  without a prompt, so do not promise one. Either way this description is what the user verifies against:
@@ -714,7 +714,7 @@
714
714
  {
715
715
  "source": "src/skills/bundled/graph-manager/SKILL.md",
716
716
  "asset": "graph-manager/SKILL.md",
717
- "sha256": "06019dce82a2ea72f4121f37111481f8bdd63d39b2d1ac1ab479405424cc7708"
717
+ "sha256": "a980212344b3cb2a23dc0968729150799c9f43a9b4a55cf6bfee3d72b07430a5"
718
718
  },
719
719
  {
720
720
  "source": "src/skills/bundled/graph-manager/errors.md",
@@ -14,6 +14,12 @@ export interface RuntimeSkill extends ProjectSkill {
14
14
  }
15
15
  /** Andorra's own skills, as registered: what a person can type and the agent can load by id. */
16
16
  export declare function bundledSkillCatalog(): readonly Pick<RuntimeSkill, 'id' | 'description' | 'path' | 'requiredTools'>[];
17
+ /**
18
+ * The disk directory a bundled skill's files live in, by the same names the catalog and the Skill tool
19
+ * resolve (`andorra:name` in full, or its unique short name); undefined when the id names no bundled
20
+ * skill. This is what lets a client read a built-in skill's SKILL.md without installing it.
21
+ */
22
+ export declare function bundledSkillDirectory(id: string): string | undefined;
17
23
  export declare function discoverRuntimeSkills(workspace: string, signal: AbortSignal, toolNames?: string[], includeProject?: boolean): Promise<RuntimeSkill[]>;
18
24
  /** The catalog skill a name loads, as the Skill tool resolves it; undefined when none would load. */
19
25
  export declare function matchRuntimeSkill(skills: RuntimeSkill[], name: string): RuntimeSkill | undefined;
@@ -35,6 +35,19 @@ const bundled = [
35
35
  export function bundledSkillCatalog() {
36
36
  return bundled.map(({ id, description, path, requiredTools }) => ({ id, description, path, ...(requiredTools ? { requiredTools: [...requiredTools] } : {}) }));
37
37
  }
38
+ /**
39
+ * The disk directory a bundled skill's files live in, by the same names the catalog and the Skill tool
40
+ * resolve (`andorra:name` in full, or its unique short name); undefined when the id names no bundled
41
+ * skill. This is what lets a client read a built-in skill's SKILL.md without installing it.
42
+ */
43
+ export function bundledSkillDirectory(id) {
44
+ const canonical = canonicalSkillId(id);
45
+ const exact = bundled.find(item => item.id === canonical);
46
+ const matches = exact ? [exact] : bundled.filter(item => item.id.split(':').at(-1) === canonical);
47
+ if (!exact && matches.length !== 1)
48
+ return undefined;
49
+ return join(BUNDLED_ROOT, dirname((exact ?? matches[0]).path));
50
+ }
38
51
  const inside = (root, target) => { const value = relative(root, target); return !isAbsolute(value) && value !== '..' && !value.startsWith(`..${sep}`); };
39
52
  /** Linux's proc fd paths let Node perform a no-follow walk relative to pinned
40
53
  * directory handles. Every lookup below '/' contains exactly one component;
@@ -0,0 +1,14 @@
1
+ /** Whether Windows reads this file name as a device (`nul`, `con`, `com1`, also with an extension). */
2
+ export declare function isWindowsDeviceName(name: string): boolean;
3
+ /** Why a new file with this name is almost certainly a mistake, or undefined when the name is ordinary. */
4
+ export declare function strayNameReason(name: string, directory: string, platform?: NodeJS.Platform): string | undefined;
5
+ /** The entry names of a directory, or undefined when it cannot be listed or is too large to compare. */
6
+ export declare function directoryNames(directory: string): Promise<Set<string> | undefined>;
7
+ /** The note for the entries that appeared in `directory` since `before` and have a stray name; empty when none did. */
8
+ export declare function strayFileNotice(directory: string, before: Set<string> | undefined, platform?: NodeJS.Platform): Promise<string>;
9
+ /**
10
+ * Runs a shell tool's command and adds the stray-file note to whatever it reports. A command that
11
+ * fails reports through its error, so the note is added there too: the command that leaves such a
12
+ * file behind has usually failed on the next line.
13
+ */
14
+ export declare function withStrayFileNotice(directory: string, run: () => Promise<string>): Promise<string>;