@andorra-labs/code 0.1.17 → 0.1.18

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 (94) hide show
  1. package/dist/src/agent-execution.js +97 -11
  2. package/dist/src/andorra/errors.js +3 -0
  3. package/dist/src/app-server/protocol.d.ts +13 -2
  4. package/dist/src/app-server/protocol.js +1 -1
  5. package/dist/src/app-server/workspace.d.ts +19 -0
  6. package/dist/src/app-server/workspace.js +155 -4
  7. package/dist/src/app-server.d.ts +32 -1
  8. package/dist/src/app-server.js +622 -74
  9. package/dist/src/attachments.d.ts +10 -0
  10. package/dist/src/attachments.js +102 -7
  11. package/dist/src/automation-tool.js +2 -1
  12. package/dist/src/bridge/command.js +12 -0
  13. package/dist/src/bridge/control.d.ts +3 -1
  14. package/dist/src/bridge/control.js +7 -2
  15. package/dist/src/bridge/github.d.ts +108 -0
  16. package/dist/src/bridge/github.js +378 -0
  17. package/dist/src/bridge/host-ops.d.ts +1 -1
  18. package/dist/src/bridge/host-ops.js +11 -1
  19. package/dist/src/bridge/host.js +7 -4
  20. package/dist/src/bug-report-attachments.d.ts +48 -0
  21. package/dist/src/bug-report-attachments.js +327 -0
  22. package/dist/src/bug-report.d.ts +23 -3
  23. package/dist/src/bug-report.js +72 -9
  24. package/dist/src/cli.d.ts +1 -3
  25. package/dist/src/cli.js +10 -4
  26. package/dist/src/codex-provider.js +1 -1
  27. package/dist/src/coding-tools.js +9 -2
  28. package/dist/src/commands.d.ts +1 -1
  29. package/dist/src/commands.js +2 -1
  30. package/dist/src/completion.js +8 -4
  31. package/dist/src/config.js +3 -1
  32. package/dist/src/context-budget.js +15 -2
  33. package/dist/src/decision/DecisionEngine.d.ts +2 -0
  34. package/dist/src/decision/DecisionManager.d.ts +11 -0
  35. package/dist/src/decision/DecisionManager.js +36 -0
  36. package/dist/src/decision/applyTaskKind.d.ts +8 -0
  37. package/dist/src/decision/applyTaskKind.js +53 -0
  38. package/dist/src/decision/hostedPolicy.js +2 -1
  39. package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +2 -0
  40. package/dist/src/decision/providers/AndorraDecisionProvider.js +12 -0
  41. package/dist/src/decision/taskKind.d.ts +52 -0
  42. package/dist/src/decision/taskKind.js +76 -0
  43. package/dist/src/decision/types.d.ts +1 -1
  44. package/dist/src/default-graph.js +1 -1
  45. package/dist/src/efficiency.d.ts +5 -0
  46. package/dist/src/efficiency.js +5 -1
  47. package/dist/src/effort-routing.d.ts +27 -0
  48. package/dist/src/effort-routing.js +34 -0
  49. package/dist/src/evidence.d.ts +110 -0
  50. package/dist/src/evidence.js +195 -0
  51. package/dist/src/github-app/client.d.ts +19 -0
  52. package/dist/src/github-app/client.js +21 -1
  53. package/dist/src/github-names.d.ts +7 -0
  54. package/dist/src/github-names.js +7 -0
  55. package/dist/src/graph-preview.d.ts +2 -0
  56. package/dist/src/graph-preview.js +1 -0
  57. package/dist/src/graph-runner.js +1 -1
  58. package/dist/src/graph-server.js +4 -2
  59. package/dist/src/graph-ui/app.js +30 -0
  60. package/dist/src/graphs.d.ts +6 -0
  61. package/dist/src/graphs.js +7 -2
  62. package/dist/src/hardened-runtime.js +32 -21
  63. package/dist/src/model-health-cache.js +1 -1
  64. package/dist/src/model-override.d.ts +2 -1
  65. package/dist/src/model-override.js +9 -0
  66. package/dist/src/model-tiers.d.ts +3 -0
  67. package/dist/src/model-tiers.js +3 -3
  68. package/dist/src/provider-engine.d.ts +13 -1
  69. package/dist/src/provider-engine.js +74 -0
  70. package/dist/src/providers.d.ts +5 -0
  71. package/dist/src/providers.js +34 -8
  72. package/dist/src/pull-requests.d.ts +11 -1
  73. package/dist/src/pull-requests.js +53 -2
  74. package/dist/src/react-runtime.js +98 -15
  75. package/dist/src/remote/engine-pool.js +5 -5
  76. package/dist/src/runtime.d.ts +29 -1
  77. package/dist/src/runtime.js +8 -0
  78. package/dist/src/sessions.d.ts +24 -0
  79. package/dist/src/sessions.js +55 -2
  80. package/dist/src/skills/bundled/bug-report/SKILL.md +51 -7
  81. package/dist/src/skills/bundled/provenance.json +1 -1
  82. package/dist/src/task-checkout.d.ts +141 -0
  83. package/dist/src/task-checkout.js +558 -0
  84. package/dist/src/test-edit-guard.d.ts +30 -0
  85. package/dist/src/test-edit-guard.js +167 -2
  86. package/dist/src/thinking-level-detect.d.ts +11 -0
  87. package/dist/src/thinking-level-detect.js +47 -0
  88. package/dist/src/thinking-levels.d.ts +30 -0
  89. package/dist/src/thinking-levels.js +124 -0
  90. package/dist/src/timers.d.ts +1 -0
  91. package/dist/src/tool-catalog.js +1 -1
  92. package/dist/src/transcript.js +1 -1
  93. package/dist/src/types.d.ts +34 -0
  94. package/package.json +1 -1
@@ -11,6 +11,14 @@ export type PendingAttachment = {
11
11
  } | {
12
12
  kind: 'file';
13
13
  path: string;
14
+ } | {
15
+ kind: 'upload';
16
+ name: string;
17
+ dataBase64: string;
18
+ } | {
19
+ kind: 'stored-file';
20
+ name: string;
21
+ spoolId: string;
14
22
  };
15
23
  export interface UserAttachmentRef {
16
24
  id: string;
@@ -61,4 +69,6 @@ export declare function parseAppleScriptHex(text: string): string;
61
69
  export declare function readClipboardImage(): Promise<Buffer | undefined>;
62
70
  export declare function writeClipboardText(text: string): Promise<void>;
63
71
  export declare function parsePendingAttachments(value: unknown): PendingAttachment[];
72
+ /** Turn desktop paths into attachment data before the request crosses the Cloud relay. */
73
+ export declare function cloudAttachments(value: unknown): Promise<PendingAttachment[]>;
64
74
  export declare function defaultAttachmentsHome(): string;
@@ -1,12 +1,13 @@
1
1
  import { execFile } from 'node:child_process';
2
- import { existsSync, statSync } from 'node:fs';
3
- import { mkdir, readFile, readdir, realpath, rm, rename, stat, writeFile } from 'node:fs/promises';
2
+ import { constants, existsSync, statSync } from 'node:fs';
3
+ import { mkdir, open, readFile, readdir, realpath, rm, rename, stat, writeFile } from 'node:fs/promises';
4
4
  import { homedir } from 'node:os';
5
5
  import { join, relative, resolve, basename, dirname, isAbsolute, sep } from 'node:path';
6
6
  import { randomUUID } from 'node:crypto';
7
7
  export const MAX_ATTACHMENTS = 10;
8
8
  export const MAX_TEXT_ATTACHMENT_CHARS = 1_000_000;
9
9
  export const MAX_IMAGE_ATTACHMENT_BYTES = 5 * 1024 * 1024;
10
+ const MAX_CLOUD_ATTACHMENT_WIRE_BYTES = 12 * 1024 * 1024;
10
11
  export const PASTE_ATTACH_LINES = 24;
11
12
  export const PASTE_ATTACH_CHARS = 2_000;
12
13
  const MAX_PATH_PASTE_LINES = 8;
@@ -78,6 +79,8 @@ export function attachmentLabel(pending) {
78
79
  return pending.path;
79
80
  }
80
81
  }
82
+ if (pending.kind === 'upload' || pending.kind === 'stored-file')
83
+ return pending.name;
81
84
  if (pending.kind === 'image') {
82
85
  const bytes = Math.floor(pending.dataBase64.length * 3 / 4);
83
86
  return `${pending.name ?? 'clipboard.png'} (${formatBytes(bytes)})`;
@@ -132,6 +135,14 @@ export async function resolveAttachments(home, workspace, pendings, createdSpool
132
135
  refs.push({ id, kind: 'image', name, path, bytes: data.length, mimeType: pending.mimeType });
133
136
  images.push({ mimeType: pending.mimeType, data: data.toString('base64') });
134
137
  }
138
+ else if (pending.kind === 'upload' || pending.kind === 'stored-file') {
139
+ const data = pending.kind === 'upload' ? Buffer.from(pending.dataBase64, 'base64') : await readStoredAttachment(home, pending);
140
+ const name = sanitizeName(pending.name, 'attachment');
141
+ const { id, path } = await spool(home, name, file => writeFile(file, data, { mode: 0o600 }));
142
+ spooled.push({ path });
143
+ createdSpools?.push(dirname(path));
144
+ refs.push({ id, kind: 'file', name, path, bytes: data.length });
145
+ }
135
146
  else {
136
147
  const path = resolve(pending.path);
137
148
  const info = await stat(path).catch(() => undefined);
@@ -172,15 +183,24 @@ export function attachmentReferenceBlock(refs, options = {}) {
172
183
  }
173
184
  const SPOOL_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
174
185
  export async function attachmentReadRoots(home, refs) {
186
+ if (refs.length === 0)
187
+ return [];
175
188
  const base = attachmentsDirectory(home);
189
+ const canonicalBase = await realpath(base).catch(() => undefined);
190
+ if (canonicalBase === undefined)
191
+ return [];
176
192
  const roots = new Set();
177
193
  for (const ref of refs) {
178
- if (ref.kind === 'file')
179
- continue;
180
194
  const directory = dirname(ref.path);
181
- if (!SPOOL_ID.test(basename(directory)) || !pathInside(directory, base))
195
+ const spoolId = basename(directory);
196
+ if (!SPOOL_ID.test(spoolId) || relative(base, directory) !== spoolId)
197
+ continue;
198
+ // Uploaded files use the spool id as their ref id. Ordinary path attachments have independent ids.
199
+ if (ref.kind === 'file' && (ref.directory || ref.id !== spoolId))
182
200
  continue;
183
- roots.add(await realpath(directory).catch(() => directory));
201
+ const canonicalDirectory = await realpath(directory).catch(() => undefined);
202
+ if (canonicalDirectory !== undefined && relative(canonicalBase, canonicalDirectory) === spoolId)
203
+ roots.add(canonicalDirectory);
184
204
  }
185
205
  return [...roots];
186
206
  }
@@ -334,13 +354,88 @@ export function parsePendingAttachments(value) {
334
354
  throw new Error(`attachments[${index}] exceeds the ${formatBytes(MAX_IMAGE_ATTACHMENT_BYTES)} image limit`);
335
355
  return { kind: 'image', ...(name === undefined ? {} : { name }), mimeType: record.mimeType, dataBase64: record.dataBase64 };
336
356
  }
357
+ if (record.kind === 'stored-file') {
358
+ if (name === undefined || !validStoredAttachment(record.spoolId, name))
359
+ throw new Error(`attachments[${index}] must identify a stored attachment`);
360
+ return { kind: 'stored-file', name, spoolId: record.spoolId };
361
+ }
362
+ if (record.kind === 'upload') {
363
+ if (!name || typeof record.dataBase64 !== 'string' || record.dataBase64.length > Math.ceil(MAX_IMAGE_ATTACHMENT_BYTES / 3) * 4) {
364
+ throw new Error(`attachments[${index}] must be a named file up to 5 MB`);
365
+ }
366
+ const data = Buffer.from(record.dataBase64, 'base64');
367
+ if (data.length > MAX_IMAGE_ATTACHMENT_BYTES || data.toString('base64') !== record.dataBase64) {
368
+ throw new Error(`attachments[${index}] has invalid file data`);
369
+ }
370
+ return { kind: 'upload', name, dataBase64: record.dataBase64 };
371
+ }
337
372
  if (record.kind === 'file') {
338
373
  if (typeof record.path !== 'string' || !record.path.trim())
339
374
  throw new Error(`attachments[${index}].path must be a filesystem path`);
340
375
  return { kind: 'file', path: record.path };
341
376
  }
342
- throw new Error(`attachments[${index}].kind must be text, image, or file`);
377
+ throw new Error(`attachments[${index}].kind must be text, image, file, upload, or stored-file`);
343
378
  });
344
379
  }
380
+ /** Turn desktop paths into attachment data before the request crosses the Cloud relay. */
381
+ export async function cloudAttachments(value) {
382
+ const attachments = [];
383
+ let bytes = 2;
384
+ for (const pending of parsePendingAttachments(value)) {
385
+ let attachment = pending;
386
+ if (pending.kind === 'file') {
387
+ const name = basename(pending.path);
388
+ const data = await readAttachmentFile(pending.path, name);
389
+ const mimeType = imageSignatureMime(data);
390
+ const dataBase64 = data.toString('base64');
391
+ attachment = mimeType === undefined ? { kind: 'upload', name, dataBase64 } : { kind: 'image', name, mimeType, dataBase64 };
392
+ }
393
+ bytes += Buffer.byteLength(JSON.stringify(attachment)) + 1;
394
+ if (bytes > MAX_CLOUD_ATTACHMENT_WIRE_BYTES)
395
+ throw new Error('These attachments exceed the combined Cloud transfer limit. Send fewer attachments at a time.');
396
+ attachments.push(attachment);
397
+ }
398
+ return attachments;
399
+ }
400
+ function validStoredAttachment(spoolId, name) {
401
+ return typeof spoolId === 'string' && SPOOL_ID.test(spoolId) && name !== '' && sanitizeName(name, '') === name;
402
+ }
403
+ /** Resolve a returned attachment on the engine that created its spool, using its id and name only. */
404
+ async function readStoredAttachment(home, pending) {
405
+ const { name, spoolId } = pending;
406
+ if (!validStoredAttachment(spoolId, name))
407
+ throw new Error('Invalid stored attachment reference.');
408
+ const base = await realpath(attachmentsDirectory(home)).catch(() => undefined);
409
+ const entry = base === undefined ? undefined : await realpath(join(base, spoolId, name)).catch(() => undefined);
410
+ if (base === undefined || entry === undefined || relative(base, entry) !== join(spoolId, name)) {
411
+ throw new Error(`Attachment ${name} is no longer available on Cloud. Attach it again to resend.`);
412
+ }
413
+ return readAttachmentFile(entry, name);
414
+ }
415
+ async function readAttachmentFile(path, name) {
416
+ const file = await open(path, constants.O_RDONLY | constants.O_NONBLOCK)
417
+ .catch(() => { throw new Error(`Could not open attachment ${name}.`); });
418
+ try {
419
+ const info = await file.stat();
420
+ if (!info.isFile())
421
+ throw new Error(`Attach individual files to Cloud. ${name} is not a regular file.`);
422
+ if (info.size > MAX_IMAGE_ATTACHMENT_BYTES)
423
+ throw new Error(`${name} exceeds the 5 MB Cloud file limit.`);
424
+ const buffer = Buffer.alloc(info.size + 1);
425
+ let length = 0;
426
+ while (length < buffer.length) {
427
+ const { bytesRead } = await file.read(buffer, length, buffer.length - length, length);
428
+ if (bytesRead === 0)
429
+ break;
430
+ length += bytesRead;
431
+ }
432
+ if (length !== info.size)
433
+ throw new Error(`${name} changed while it was being attached. Try again.`);
434
+ return buffer.subarray(0, length);
435
+ }
436
+ finally {
437
+ await file.close();
438
+ }
439
+ }
345
440
  const throwName = (index) => { throw new Error(`attachments[${index}].name must be a string`); };
346
441
  export function defaultAttachmentsHome() { return process.env.ANDORRACODE_HOME || join(homedir(), '.andorracode'); }
@@ -46,7 +46,8 @@ export function createAutomationTool() {
46
46
  }
47
47
  const { action: _action, id: _id, ...input } = args;
48
48
  if (args.action === 'create') {
49
- input.project ??= context.workspace;
49
+ // Filed under the task's project, not under the worktree the task happens to work in.
50
+ input.project ??= context.project ?? context.workspace;
50
51
  input.execution = { ...context.wakeCarry, permissions: permissionMode(context) ?? 'ask-for-approval' };
51
52
  input.execution = Object.fromEntries(Object.entries(input.execution).filter(([key]) => ['provider', 'model', 'graph', 'permissions', 'reasoningEffort'].includes(key)));
52
53
  assertPlanMutationAllowed(context);
@@ -5,6 +5,7 @@ import { changeConfigFile, configDirectory, loadConfig } from '../config.js';
5
5
  import { ensureWorkFolder, MAX_BOOT_INPUT_BYTES, runCloudBoot } from './cloud.js';
6
6
  import { ControlError, environmentToken, heartbeat, linkPoll, linkStart } from './control.js';
7
7
  import { engineStoreFromEnvironment, HOST_RESTART_EXIT_CODE } from './engines.js';
8
+ import { installCredentialHelperFromEnvironment, runGitCredential } from './github.js';
8
9
  import { relayUrlFromEnvironment, runBridgeHost } from './host.js';
9
10
  import { linkAddress, openCommand, openOnThisComputer, overSshFromEnvironment } from './login-link.js';
10
11
  import { clearBridgeIdentity, readBridgeIdentity, shareFolder, writeBridgeIdentity } from './store.js';
@@ -232,6 +233,8 @@ async function run(print, apiBase, dependencies) {
232
233
  try {
233
234
  if (process.env.ANDORRA_CLOUD === '1') {
234
235
  await ensureWorkFolder(directory, dependencies.workDirectory).catch(error => print(`Could not share the work folder: ${message(error)}`));
236
+ // Clones made by an earlier engine name this file; it is pointed at the engine now running.
237
+ await installCredentialHelperFromEnvironment(directory).catch(error => print(`Could not write the Git credential helper: ${message(error)}`));
235
238
  }
236
239
  const outcome = await (dependencies.runHost ?? runBridgeHost)({
237
240
  directory,
@@ -314,6 +317,15 @@ export async function runBridgeCommand(args, print, dependencies = {}) {
314
317
  switch (command) {
315
318
  case 'cloud-boot':
316
319
  return runCloudBoot({ apiBase, directory: configDirectory(), stdin: await readBoundedStdin(), print });
320
+ case 'git-credential':
321
+ // Git runs this on a Cloud machine (see ./github.ts). Standard output goes to Git and carries the credential alone.
322
+ return runGitCredential({
323
+ action: rest[0], stdin: rest[0] === 'get' ? await readBoundedStdin() : '', apiBase, directory: configDirectory(), print,
324
+ warn: line => {
325
+ process.stderr.write(`${line}
326
+ `);
327
+ },
328
+ });
317
329
  case 'link':
318
330
  return link(rest, print, apiBase, dependencies);
319
331
  case 'run':
@@ -1,4 +1,4 @@
1
- export type ControlErrorCode = 'code_expired' | 'code_unknown' | 'code_used' | 'boot_expired' | 'boot_used' | 'boot_unknown' | 'environment_limit' | 'invalid_name' | 'not_found' | 'unauthorized' | 'cloud_not_enabled' | 'cloud_environment' | 'invalid_version' | 'cloud_unavailable' | 'stopping' | 'no_capacity' | 'unlinked' | 'network' | 'server';
1
+ export type ControlErrorCode = 'code_expired' | 'code_unknown' | 'code_used' | 'boot_expired' | 'boot_used' | 'boot_unknown' | 'environment_limit' | 'invalid_name' | 'not_found' | 'unauthorized' | 'cloud_not_enabled' | 'cloud_plan' | 'cloud_environment' | 'invalid_version' | 'cloud_unavailable' | 'stopping' | 'no_capacity' | 'unlinked' | 'network' | 'server';
2
2
  export declare class ControlError extends Error {
3
3
  readonly code: ControlErrorCode;
4
4
  constructor(code: ControlErrorCode, message: string);
@@ -34,6 +34,8 @@ export type CloudState = 'none' | 'starting' | 'running' | 'stopping' | 'stopped
34
34
  export interface CloudStatus {
35
35
  state: CloudState;
36
36
  enabled: boolean;
37
+ /** Why Cloud is not enabled, when the service says: `plan` is an account on the Free plan. */
38
+ reason?: 'plan';
37
39
  environmentId?: string;
38
40
  label?: string;
39
41
  version?: string;
@@ -176,10 +176,12 @@ const CLOUD_VERSION = /^\d{1,4}\.\d{1,4}\.\d{1,4}$/;
176
176
  const ISO_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$/;
177
177
  /** Keeps only the fields of a Cloud answer that have the expected shape; an unknown state is an error. */
178
178
  function cloudStatus(value) {
179
- const { state, enabled, environmentId, label, version, step, deleteAt, error, stopReason } = value;
179
+ const { state, enabled, reason, environmentId, label, version, step, deleteAt, error, stopReason } = value;
180
180
  if (typeof state !== 'string' || !CLOUD_STATES.includes(state))
181
181
  throw new ControlError('server', 'The Andorra service answered with an unknown Cloud state.');
182
182
  const status = { state: state, enabled: enabled === true };
183
+ if (enabled !== true && reason === 'plan')
184
+ status.reason = 'plan';
183
185
  if (typeof environmentId === 'string' && CLOUD_ENVIRONMENT_ID.test(environmentId))
184
186
  status.environmentId = environmentId;
185
187
  if (typeof label === 'string' && CLOUD_LABEL.test(label))
@@ -198,8 +200,11 @@ function cloudStatus(value) {
198
200
  }
199
201
  function cloudError(status, value) {
200
202
  const refusal = typeof value.error === 'string' ? CLOUD_REFUSALS[value.error] : undefined;
201
- if (refusal !== undefined && refusal.status === status)
203
+ if (refusal !== undefined && refusal.status === status) {
204
+ if (refusal.code === 'cloud_not_enabled' && value.reason === 'plan')
205
+ return new ControlError('cloud_plan', 'Cloud is not included in the Free plan.');
202
206
  return new ControlError(refusal.code, refusal.message);
207
+ }
203
208
  if (status === 401)
204
209
  return accountError(status, value);
205
210
  return new ControlError('cloud_unavailable', 'Cloud is not available right now. Try again in a moment.');
@@ -0,0 +1,108 @@
1
+ /** A clone still running after this long is stopped and reported as failed. */
2
+ export declare const CLONE_TIMEOUT_MS: number;
3
+ /** How long a clone request waits for the clone before answering `cloning`; a host operation has 30 seconds in all. */
4
+ export declare const CLONE_ANSWER_MS = 2000;
5
+ export type RepositoryTokenErrorCode = 'off' | 'not-connected' | 'not-covered' | 'not-cloud' | 'suspended' | 'permissions-pending' | 'not-allowed' | 'account-unavailable' | 'unlinked' | 'rate-limited' | 'network' | 'server';
6
+ export declare class RepositoryTokenError extends Error {
7
+ readonly code: RepositoryTokenErrorCode;
8
+ constructor(code: RepositoryTokenErrorCode, message: string);
9
+ }
10
+ export interface RepositoryToken {
11
+ token: string;
12
+ expiresAt: string;
13
+ login: string;
14
+ githubUserId: number;
15
+ push: boolean;
16
+ }
17
+ /** Asks the service for a token for one repository, as the machine `environmentToken` names. */
18
+ export declare function repositoryToken(apiBase: string, environmentTokenValue: string, owner: string, repo: string, fetcher?: typeof globalThis.fetch): Promise<RepositoryToken>;
19
+ /** The machine's own token for `owner/repo`: its secret is traded for an environment token, and that for the repository's. */
20
+ export declare function machineRepositoryToken(directory: string, apiBase: string, owner: string, repo: string): Promise<RepositoryToken>;
21
+ /** `owner/repo` from the path Git names in a credential request (`owner/repo.git`, with or without what follows it). */
22
+ export declare function repositoryOfPath(path: string | undefined): {
23
+ owner: string;
24
+ repo: string;
25
+ } | undefined;
26
+ /** A credential request as Git writes it: `key=value` lines up to a blank line. */
27
+ export declare function parseCredentialRequest(stdin: string): Record<string, string>;
28
+ export interface GitCredentialInput {
29
+ /** What Git asks: `get`, `store` or `erase`. */
30
+ action: string | undefined;
31
+ stdin: string;
32
+ apiBase: string;
33
+ directory: string;
34
+ /** Writes to Git: the credential, and nothing else. */
35
+ print(line: string): void;
36
+ /** Writes what a person reads in Git's own output. */
37
+ warn(line: string): void;
38
+ token?: typeof machineRepositoryToken;
39
+ }
40
+ /**
41
+ * Git's credential helper (`andorra bridge git-credential <action>`). It answers only a `get` for
42
+ * `https://github.com/<owner>/<repo>`; anything else gets no credential, and Git goes on to whatever else it has.
43
+ * `store` and `erase` do nothing: there is nothing kept to change.
44
+ */
45
+ export declare function runGitCredential(input: GitCredentialInput): Promise<number>;
46
+ export type CloneAnswer = {
47
+ state: 'cloning';
48
+ } | {
49
+ state: 'ready';
50
+ rootId: string;
51
+ name: string;
52
+ } | {
53
+ state: 'failed';
54
+ message: string;
55
+ };
56
+ export interface CloneDependencies {
57
+ directory: string;
58
+ apiBase: string;
59
+ /** Whether this machine is a Cloud instance: a linked workstation keeps its own Git credentials and clones nothing here. */
60
+ cloud: boolean;
61
+ /** The credential helper as Git's configuration names it (`!command`). */
62
+ helper: string;
63
+ git?: string;
64
+ token?: typeof machineRepositoryToken;
65
+ /** Where the repository is fetched from; tests point it at a local repository. */
66
+ remoteUrl?: (owner: string, repo: string) => string;
67
+ answerMs?: number;
68
+ }
69
+ /**
70
+ * The helper this process's own CLI provides, named by the paths it is running from. `settings` are set for the
71
+ * helper itself, so it reaches the same service and home as this machine's bridge even when the Git that runs it was
72
+ * started with a narrower environment (a task's command, say).
73
+ */
74
+ export declare function credentialHelperCommand(execPath?: string, script?: string | undefined, settings?: Record<string, string>): string;
75
+ /** The helper's file in the machine's Andorra home: the one path every clone's configuration names. */
76
+ export declare const CREDENTIAL_HELPER_FILE = "git-credential-andorra";
77
+ /**
78
+ * Writes the helper every clone names and answers it as Git's configuration takes it. A clone's configuration
79
+ * outlives the engine that made it, and an engine's own path changes with its version (old versions are pruned), so
80
+ * clones name this one file instead, and it is rewritten to run the current engine whenever the bridge starts and
81
+ * before every clone. It holds paths and the service's address: no secret.
82
+ */
83
+ export declare function installCredentialHelper(directory: string, options?: {
84
+ execPath?: string;
85
+ script?: string;
86
+ settings?: Record<string, string>;
87
+ }): Promise<string>;
88
+ /** The helper for this machine as its environment describes it, written afresh. */
89
+ export declare function installCredentialHelperFromEnvironment(directory: string, environment?: NodeJS.ProcessEnv): Promise<string>;
90
+ export declare function cloneDependenciesFromEnvironment(directory: string, environment?: NodeJS.ProcessEnv): Promise<CloneDependencies>;
91
+ /**
92
+ * The entry of `parent` that is `name` in any capitalisation, or `name` when there is none. GitHub's names ignore
93
+ * case and Cloud's disk does not, so a repository picked again under another spelling must find the folder it has.
94
+ */
95
+ export declare function spelledAs(parent: string, name: string): Promise<string>;
96
+ /**
97
+ * How many clones are running now. The bridge counts them as work, so it does not restart itself for a newer engine
98
+ * under a clone whose request was already answered `cloning`.
99
+ */
100
+ export declare function clonesRunning(): number;
101
+ /** Forgets every clone this process knows of (tests). */
102
+ export declare function resetCloneJobs(): void;
103
+ /**
104
+ * Clones `owner/repo` into the machine's first shared folder and registers it as a project. It never waits long:
105
+ * while the clone runs every call answers `cloning`, so a desktop asks again until it is `ready` or `failed`. A
106
+ * repository already cloned there is reused. A failure is reported once; asking after that starts again.
107
+ */
108
+ export declare function cloneRepository(dependencies: CloneDependencies, params: Record<string, unknown>): Promise<CloneAnswer>;