@parcha/agentrun-serve 0.1.0-beta.53 → 0.1.0-beta.54

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 (66) hide show
  1. package/CHANGELOG.md +29 -2
  2. package/README.md +82 -13
  3. package/dist/agent-package.js +1 -1
  4. package/dist/agent-rows.d.ts +1 -1
  5. package/dist/agents-store.js +1 -1
  6. package/dist/api-only.d.ts +1 -2
  7. package/dist/api-only.js +1 -2
  8. package/dist/cli.js +6 -1
  9. package/dist/composio-preset.d.ts +3 -2
  10. package/dist/composio-preset.js +4 -3
  11. package/dist/computer-needs.d.ts +1 -1
  12. package/dist/computer-needs.js +1 -1
  13. package/dist/computer-setting.d.ts +4 -2
  14. package/dist/computers.d.ts +0 -2
  15. package/dist/computers.js +1 -1
  16. package/dist/console/assets/index-B_85An2t.js +745 -0
  17. package/dist/console/assets/index-n1YsbnYh.css +1 -0
  18. package/dist/console/index.html +2 -2
  19. package/dist/errors.d.ts +4 -0
  20. package/dist/errors.js +7 -0
  21. package/dist/github-connection.d.ts +50 -1
  22. package/dist/github-connection.js +96 -3
  23. package/dist/github-faux.d.ts +11 -2
  24. package/dist/github-faux.js +138 -7
  25. package/dist/github-pull-request.d.ts +37 -0
  26. package/dist/github-pull-request.js +110 -0
  27. package/dist/live-reach.d.ts +34 -7
  28. package/dist/live-reach.js +76 -11
  29. package/dist/mcp-probe.js +2 -2
  30. package/dist/openapi.js +108 -4
  31. package/dist/runner/adapter-run-spec.js +1 -1
  32. package/dist/runner/cli-run-spec.js +1 -1
  33. package/dist/runner/metrics.d.ts +4 -2
  34. package/dist/runner/metrics.js +15 -3
  35. package/dist/runner/pr-checkout.d.ts +21 -4
  36. package/dist/runner/pr-checkout.js +103 -4
  37. package/dist/runner/run-child-host.js +7 -4
  38. package/dist/runner/runner-check.d.ts +3 -0
  39. package/dist/runner/runner-check.js +23 -0
  40. package/dist/server.d.ts +11 -0
  41. package/dist/server.js +80 -10
  42. package/dist/store/agent-body.d.ts +2 -2
  43. package/dist/store/agent-body.js +2 -2
  44. package/dist/suggestions.d.ts +282 -0
  45. package/dist/suggestions.js +919 -0
  46. package/dist/telemetry.d.ts +8 -1
  47. package/dist/telemetry.js +12 -4
  48. package/dist/template-import.d.ts +17 -0
  49. package/dist/template-import.js +32 -0
  50. package/dist/templates.d.ts +78 -73
  51. package/dist/templates.js +10 -8
  52. package/dist/trigger-launch-hook.d.ts +5 -3
  53. package/dist/trigger-launch-hook.js +5 -4
  54. package/dist/triggers.js +1 -1
  55. package/dist/validate.d.ts +1 -1
  56. package/dist/validate.js +2 -2
  57. package/dist/workspace/synced-folder.d.ts +1 -1
  58. package/dist/workspace/synced-folder.js +11 -14
  59. package/launcher/agentrun-serve +1 -1
  60. package/package.json +10 -10
  61. package/templates/README.md +3 -2
  62. package/templates/agent-scout/agent.md +46 -0
  63. package/templates/agent-scout/skills/scout/SKILL.md +88 -0
  64. package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
  65. package/dist/console/assets/index-BFgyZzF_.js +0 -734
  66. package/dist/console/assets/index-DbilxljH.css +0 -1
package/dist/server.js CHANGED
@@ -174,6 +174,7 @@ import { templateApplied, templateTriggerSecret, templateWebhookSecrets, trigger
174
174
  import { openServerSecretsOverStore } from "./server-secrets-store.js";
175
175
  import { HOOK_TOLERANCE_S } from "./standard-webhooks.js";
176
176
  import { GitHubConnect, GitHubConnection, INSTALLED_PATH, startedHere as gitHubStartedHere, stateCookie } from "./github-connection.js";
177
+ import { SCOUT_TEMPLATE, Suggestions } from "./suggestions.js";
177
178
  import { FAUX_GITHUB, FAUX_GITHUB_FILE, startFauxGitHub } from "./github-faux.js";
178
179
  import { GITHUB_API } from "./github.js";
179
180
  import { bindingOf, REPO_NAME } from "./run-repo.js";
@@ -187,7 +188,7 @@ import { mcpNameOf as mcpToolOf, mcpToolName } from "./tool-names.js";
187
188
  import { CATCHUP_WINDOW_S, FAILURES_TO_PAUSE, HISTORY_KEPT, MIN_EVERY_S, SOURCE_KINDS, TARGET_KINDS, Triggers } from "./triggers.js";
188
189
  import { PAYLOAD_KEPT_BYTES } from "./trigger-adapter.js";
189
190
  import { applyBodyOf, choiceUnrunnable, COMPOSIO_TRIGGER_FIX, composioTriggerSkipped, COMPUTER_FIX, compiled, feedLeftEmpty, feedTriggerEmpty, githubTriggerUnconnected, githubTriggerWords, madeTriggerIssues, mcpSetUp, onServerName, onServers, packageDetail, packageModel, packageTiers, packageView, pickComputer, readPackages, notSetUpYet, serversFor, TemplateRegistry } from "./templates.js";
190
- import { deleteTemplate, dropRemovedUploads, importTemplate, loadImported, UPLOAD_PREFIX } from "./template-import.js";
191
+ import { applyImported, deleteTemplate, dropRemovedUploads, importTemplate, loadImported, UPLOAD_PREFIX } from "./template-import.js";
191
192
  import { templateInstallLink, templateLink, templatesLink } from "./console-links.js";
192
193
  import { GITHUB_HOSTS, IMPORT_LIMITS } from "./template-source.js";
193
194
  import { checkDefinitionBody, DEFAULT_INPUT_SCHEMA, definitionBodyIssues, EXTERNAL_NAME, ID, IDEMPOTENCY_TTL_S, inputIssues, inputSchemaOf, isObject, stable, unknownFields } from "./validate.js";
@@ -458,7 +459,6 @@ export const ROUTES = [
458
459
  { method: "DELETE", pattern: /^\/settings\/model-gateway$/, name: "deleteModelGateway" },
459
460
  { method: "POST", pattern: /^\/settings\/model-gateway\/test$/, name: "testModelGateway" },
460
461
  { method: "GET", pattern: /^\/settings\/mcp-servers$/, name: "listMcpServers" },
461
- // The saved servers' names alone, for a host that builds runs from them (served API-only too: api-only.ts).
462
462
  { method: "GET", pattern: /^\/settings\/mcp-server-names$/, name: "listMcpServerNames" },
463
463
  { method: "POST", pattern: /^\/settings\/mcp-servers\/preview$/, name: "previewMcpServer" },
464
464
  { method: "POST", pattern: /^\/settings\/mcp-servers\/composio\/tools$/, name: "listComposioTools" },
@@ -516,6 +516,14 @@ export const ROUTES = [
516
516
  { method: "POST", pattern: /^\/integrations\/github\/connect$/, name: "connectGitHub" },
517
517
  { method: "GET", pattern: /^\/integrations\/github\/callback$/, name: "gitHubCallback" },
518
518
  { method: "GET", pattern: /^\/integrations\/github\/installed$/, name: "gitHubInstalled" },
519
+ { method: "GET", pattern: /^\/integrations\/github\/repositories$/, name: "listGitHubRepositories" },
520
+ // Suggested agents (suggestions.ts): what the agent-scout template finds in a repository, and what a person decides.
521
+ { method: "GET", pattern: /^\/suggestions$/, name: "listSuggestions" },
522
+ { method: "POST", pattern: /^\/suggestions\/scans$/, name: "scanForSuggestions" },
523
+ { method: "GET", pattern: /^\/suggestions\/([^/]+)$/, name: "getSuggestion" },
524
+ { method: "POST", pattern: /^\/suggestions\/([^/]+)\/discard$/, name: "discardSuggestion" },
525
+ { method: "POST", pattern: /^\/suggestions\/([^/]+)\/restore$/, name: "restoreSuggestion" },
526
+ { method: "POST", pattern: /^\/suggestions\/([^/]+)\/create$/, name: "createSuggestedAgent" },
519
527
  // Answered before routing (mcp.ts), with the token only: listed here for the document.
520
528
  { method: "POST", pattern: /^\/mcp$/, name: "callMcp" },
521
529
  { method: "GET", pattern: /^\/agents\/([^/]+)\/learning$/, name: "getAgentLearning" },
@@ -1912,14 +1920,15 @@ async function startHolding(options, data, checked, stops) {
1912
1920
  const was = options.faux && options.fauxGitHub ? github.view() : undefined;
1913
1921
  if (was && was.slug !== FAUX_GITHUB.slug)
1914
1922
  throw new Error(`--faux-github connects a fake GitHub App, and this data directory has the GitHub App ${was.slug} connected: use a scratch data directory.`);
1915
- const fauxGitHub = options.faux && options.fauxGitHub ? await startFauxGitHub() : undefined;
1923
+ // Its repository as a bare git repository beside the data, so a run's checkout of it (agent-scout's) stays on this machine.
1924
+ const fauxGitHub = options.faux && options.fauxGitHub ? await startFauxGitHub({ webDir: join(data, "faux-github-web") }) : undefined;
1916
1925
  if (fauxGitHub) {
1917
1926
  stops.push(() => fauxGitHub.close());
1918
1927
  if (was)
1919
1928
  await github.remove();
1920
1929
  await github.save(fauxGitHub.app);
1921
1930
  await github.setInstallations([{ id: FAUX_GITHUB.installation, account: FAUX_GITHUB.account }]);
1922
- await writeFile(join(data, FAUX_GITHUB_FILE), `${JSON.stringify({ webhook_secret: fauxGitHub.app.webhookSecret, installation: FAUX_GITHUB.installation, account: FAUX_GITHUB.account, repositories: FAUX_GITHUB.repositories })}\n`, { mode: 0o600 });
1931
+ await writeFile(join(data, FAUX_GITHUB_FILE), `${JSON.stringify({ webhook_secret: fauxGitHub.app.webhookSecret, installation: FAUX_GITHUB.installation, account: FAUX_GITHUB.account, repositories: FAUX_GITHUB.repositories, api_url: fauxGitHub.url })}\n`, { mode: 0o600 });
1923
1932
  }
1924
1933
  const githubConnect = new GitHubConnect(github, { ...(options.publicUrl ? { publicUrl: options.publicUrl.replace(/\/+$/, "") } : {}), api: fauxGitHub?.url ?? options.githubApi ?? GITHUB_API, say: (fields) => log?.(logLine("github", fields)) });
1925
1934
  /** The connection a GitHub template or the console reads: the App's id, slug and installations, never a secret. */
@@ -1937,6 +1946,42 @@ async function startHolding(options, data, checked, stops) {
1937
1946
  return "token" in minted ? { api, hosts, token: minted.token } : { api, hosts, anonymous: "unusable" in minted ? minted.unusable : minted.failed };
1938
1947
  },
1939
1948
  };
1949
+ // Suggested agents (suggestions.ts): scans run the bundled agent-scout, applied once and reused (one apply at a time
1950
+ // on this server); a create pushes through the App's token for the one repository, then applies the package it pushed
1951
+ // as an imported template, so the agent here is made from the very files the pull request adds.
1952
+ let scouting;
1953
+ const suggestions = new Suggestions({
1954
+ settings: store.settings,
1955
+ github: { view: () => github.view(), settingsUrl: () => github.settingsUrl(), get api() { return githubConnect.api; }, repoInstallation: (repo, signal) => githubConnect.repoInstallation(repo, signal), tokenWith: (installation, repo, permissions, signal) => githubConnect.tokenWith(installation, repo, permissions, signal), revokeToken: (token) => githubConnect.revokeToken(token) },
1956
+ scoutAgent: () => (scouting ??= (async () => {
1957
+ const mine = (await agents.list()).find((one) => one.template?.id === SCOUT_TEMPLATE && !one.agent.archivedAt);
1958
+ if (mine)
1959
+ return mine.agent.id;
1960
+ const pkg = registry.get(SCOUT_TEMPLATE);
1961
+ if (!pkg)
1962
+ throw new ApiError("unavailable", `This server does not ship the ${SCOUT_TEMPLATE} template, which scans a repository.`);
1963
+ return (await applyTemplate(pkg, { parameters: {} })).applied.agent_id;
1964
+ })().finally(() => { scouting = undefined; })),
1965
+ startScan: async (agentId, content) => (await startRunOf(await needRunnableAgent(agentId), { input: { content } })).id,
1966
+ readRun: async (runId) => {
1967
+ const view = await viewOverStore(store, runId, viewDepsFor(ownOriginOf()));
1968
+ if (!view)
1969
+ return undefined;
1970
+ const result = isObject(view.result) ? view.result : undefined;
1971
+ const error = isObject(view.error) && typeof view.error.message === "string" ? view.error.message : typeof result?.output_error === "string" ? `Its answer did not meet the scout's schema: ${result.output_error}` : undefined;
1972
+ return { status: String(view.status), ...(result && result.output != null ? { output: result.output } : {}), ...(error ? { error } : {}), ...(typeof view.ended_at === "string" ? { endedAt: Date.parse(view.ended_at) } : {}) };
1973
+ },
1974
+ // Kept, then applied (template-import.ts applyImported): a thrown error means no agent was made. The package has no
1975
+ // trigger, so the apply makes the agent as its last write.
1976
+ cancelScan: async (runId) => { await cancel(store, await needRun(runId)); },
1977
+ agentFrom: async (id, sha) => (await agents.list()).find((one) => one.template?.id === id && one.template.sha === sha && !one.agent.archivedAt)?.agent.id,
1978
+ makeAgent: async (id, origin, files) => {
1979
+ const made = await applyImported({ registry, store, apply: (pkg) => applyTemplate(pkg, { parameters: {} }) }, id, origin, files);
1980
+ return { agentId: made.applied.agent_id, warnings: made.applied.warnings };
1981
+ },
1982
+ ...(options.publicUrl ? { publicUrl: options.publicUrl.replace(/\/+$/, "") } : {}),
1983
+ ...(options.onUsage ? { used: options.onUsage } : {}),
1984
+ });
1940
1985
  // A github_app MCP server's tools are listed with an installation token of the App, narrowed to one repository it covers
1941
1986
  // with metadata read (tokenForListing); a run's own is minted in the runner (runner/github-app.ts). Every token minted
1942
1987
  // is a server secret while it may be in use.
@@ -5569,7 +5614,7 @@ async function startHolding(options, data, checked, stops) {
5569
5614
  // Never through `idempotent`: its record keeps the body, and a body may hold a credential.
5570
5615
  case "listMcpServers":
5571
5616
  return send(res, 200, await mcpServers.list());
5572
- // Names only: no URL, auth type, header, tool or Composio record, so a token that may not read the list may read this.
5617
+ // Names only: what the API-only profile serves in place of the list.
5573
5618
  case "listMcpServerNames":
5574
5619
  return send(res, 200, { names: (await listMcpServers(store)).map((row) => row.name).sort() });
5575
5620
  case "getMcpServer":
@@ -5659,6 +5704,33 @@ async function startHolding(options, data, checked, stops) {
5659
5704
  const view = githubConnection();
5660
5705
  return send(res, 200, view ? { connected: true, ...view } : { connected: false });
5661
5706
  }
5707
+ case "listGitHubRepositories": {
5708
+ // The installations repaired from GitHub's own first, as getGitHubConnection does (at most once a minute): an
5709
+ // installation whose event was missed is listed, not hidden until a restart.
5710
+ await githubConnect.reconcile((detail) => triggers.turnOff("github", detail));
5711
+ const listed = await githubConnect.repositories(stopping.signal);
5712
+ if ("unusable" in listed)
5713
+ throw new ApiError("github_not_connected", listed.unusable);
5714
+ return send(res, 200, listed, { "cache-control": "no-store" });
5715
+ }
5716
+ case "listSuggestions":
5717
+ // The same repair first: the page's Refresh and Check again read installations as GitHub has them.
5718
+ await githubConnect.reconcile((detail) => triggers.turnOff("github", detail));
5719
+ return send(res, 200, await suggestions.list({ ...(url.searchParams.has("repo") ? { repo: url.searchParams.get("repo") } : {}), ...(url.searchParams.has("status") ? { status: url.searchParams.get("status") } : {}) }), { "cache-control": "no-store" });
5720
+ case "scanForSuggestions": {
5721
+ const scanned = await suggestions.scan(await bodyOf(req));
5722
+ return send(res, scanned.status, scanned.body, { location: `/v2/runs/${String(scanned.body.run_id)}` });
5723
+ }
5724
+ case "getSuggestion":
5725
+ return send(res, 200, await suggestions.get(id, stopping.signal, url.searchParams.get("name") ?? undefined), { "cache-control": "no-store" });
5726
+ case "discardSuggestion":
5727
+ return send(res, 200, await suggestions.discard(id));
5728
+ case "restoreSuggestion":
5729
+ return send(res, 200, await suggestions.restore(id));
5730
+ case "createSuggestedAgent": {
5731
+ const created = await suggestions.create(id, await bodyOf(req), stopping.signal);
5732
+ return send(res, created.status, created.body);
5733
+ }
5662
5734
  case "disconnectGitHub": {
5663
5735
  const view = githubConnection();
5664
5736
  if (!view)
@@ -5975,9 +6047,8 @@ async function startHolding(options, data, checked, stops) {
5975
6047
  const done = new AbortController();
5976
6048
  res.once("close", () => done.abort());
5977
6049
  const imported = await importTemplate(importDeps, body, done.signal);
5978
- const pickView = await computerHere([imported.pkg]);
5979
6050
  const uploaded = imported.pkg.id.startsWith(UPLOAD_PREFIX);
5980
- return send(res, imported.status, { template: { ...packageView(imported.pkg), computer_here: pickView(imported.pkg) }, ...(({ instructions, skill_files }) => ({ instructions, skill_files }))(packageDetail(imported.pkg)), publisher_trusted: imported.trusted, stored: imported.status === 201, replaced: imported.replaced, console_url: imported.status === 201 ? templateLink(linkOrigin(req), imported.pkg.id) : uploaded ? templatesLink(linkOrigin(req)) : templateInstallLink(linkOrigin(req), imported.pkg.origin?.source ?? imported.pkg.id) });
6051
+ return send(res, imported.status, { ...packageDetail(imported.pkg, await computerHere([imported.pkg])), publisher_trusted: imported.trusted, stored: imported.status === 201, replaced: imported.replaced, console_url: imported.status === 201 ? templateLink(linkOrigin(req), imported.pkg.id) : uploaded ? templatesLink(linkOrigin(req)) : templateInstallLink(linkOrigin(req), imported.pkg.origin?.source ?? imported.pkg.id) });
5981
6052
  }
5982
6053
  case "getTemplate": {
5983
6054
  // One package whole, a bundled one's too: as the list shows it, with the files an import's answer shows, for a
@@ -5985,9 +6056,7 @@ async function startHolding(options, data, checked, stops) {
5985
6056
  const pkg = registry.get(id);
5986
6057
  if (!pkg)
5987
6058
  throw new ApiError("not_found", `no template ${id}: GET /v2/templates lists them`);
5988
- const pickView = await computerHere([pkg]);
5989
- const { instructions, skill_files } = packageDetail(pkg);
5990
- return send(res, 200, { template: { ...packageView(pkg), computer_here: pickView(pkg) }, instructions, skill_files, console_url: templateLink(linkOrigin(req), pkg.id) });
6059
+ return send(res, 200, { ...packageDetail(pkg, await computerHere([pkg])), console_url: templateLink(linkOrigin(req), pkg.id) });
5991
6060
  }
5992
6061
  case "deleteTemplate":
5993
6062
  await deleteTemplate(importDeps, id);
@@ -6701,6 +6770,7 @@ async function startHolding(options, data, checked, stops) {
6701
6770
  dial: { ...(options.publicUrl ? { url: options.publicUrl.replace(/\/+$/, "") } : {}), tokens: attach.machineTokens, hub: attachHub },
6702
6771
  localInstall,
6703
6772
  own: mcpServers.own,
6773
+ ...(fauxGitHub ? { fauxGitHub: { api: fauxGitHub.url, ...(fauxGitHub.web ? { web: fauxGitHub.web } : {}) } } : {}),
6704
6774
  // Once: a second call, at any time, is the first one's promise, so a close repeated after the next server started
6705
6775
  // never writes this data root's record again (the next server's, by then).
6706
6776
  close: () => (stopped ??= stop()),
@@ -95,7 +95,7 @@ export type AgenticBody = {
95
95
  approvals?: "ask" | "never";
96
96
  inputSchema?: Record<string, unknown>;
97
97
  outputSchema?: Record<string, unknown>;
98
- checkout?: "pull_request";
98
+ checkout?: "pull_request" | "repository";
99
99
  };
100
100
  export type WorkflowBody = {
101
101
  workflow: Record<string, unknown>;
@@ -134,7 +134,7 @@ export type RevisionBodyInput = {
134
134
  approvals?: "ask" | "never";
135
135
  inputSchema?: Record<string, unknown>;
136
136
  outputSchema?: Record<string, unknown>;
137
- checkout?: "pull_request";
137
+ checkout?: "pull_request" | "repository";
138
138
  } | {
139
139
  kind: "workflow";
140
140
  workflow: unknown;
@@ -144,8 +144,8 @@ export function bodyOf(input) {
144
144
  invalid("the inputSchema is not a JSON object");
145
145
  if (input.outputSchema !== undefined && !isObject(input.outputSchema))
146
146
  invalid("the outputSchema is not a JSON object");
147
- if (input.checkout !== undefined && input.checkout !== "pull_request")
148
- invalid("the checkout is not pull_request");
147
+ if (input.checkout !== undefined && input.checkout !== "pull_request" && input.checkout !== "repository")
148
+ invalid("the checkout is not pull_request or repository");
149
149
  if (input.modelTiers !== undefined && !(isObject(input.modelTiers) && Object.keys(input.modelTiers).length && Object.entries(input.modelTiers).every(([tier, ref]) => (tier === "fast" || tier === "strong") && typeof ref === "string" && ref !== "")))
150
150
  invalid("the modelTiers are not fast and strong to a non-empty model");
151
151
  if (input.sdk !== undefined && (!isObject(input.sdk) || Object.keys(input.sdk).some(key => key !== "runtime" && key !== "platform") || !sdkBindingOf(input.sdk)))
@@ -0,0 +1,282 @@
1
+ import { type InputIssue } from "./errors.js";
2
+ import type { GitHubConnectionView, RepoInstallation } from "./github-connection.js";
3
+ import { type NewFile } from "./github-pull-request.js";
4
+ import type { Settings } from "./store/index.js";
5
+ import type { UsageEventName } from "./telemetry.js";
6
+ import { type Json } from "./validate.js";
7
+ /** The bundled template a scan runs. */
8
+ export declare const SCOUT_TEMPLATE = "agent-scout";
9
+ /** Where in the repository a created agent's package goes: `<dir>/<key>/agent.md`. */
10
+ export declare const PACKAGE_DIR = ".agentrun/agents";
11
+ /** What the token a pull request is made with holds, and no more: one repository, these permissions. */
12
+ export declare const PULL_PERMISSIONS: {
13
+ readonly contents: "write";
14
+ readonly pull_requests: "write";
15
+ readonly metadata: "read";
16
+ };
17
+ /** A create's claim on its suggestion, kept on its row in the shared store: one older than this was left by a server
18
+ * that stopped mid-create, and the next create takes it over. A create's GitHub calls and apply take seconds. */
19
+ export declare const CREATE_CLAIM_MS: number;
20
+ /** A scan's start, kept on its repository's row while its run is started: one older than this was left by a server that
21
+ * stopped mid-start, and the next scan takes it over. */
22
+ export declare const SCAN_CLAIM_MS: number;
23
+ declare const INPUT_TYPES: readonly ["string", "number", "integer", "boolean"];
24
+ declare const OUTPUT_TYPES: readonly ["string", "number", "integer", "boolean", "string_list"];
25
+ declare const LANGUAGES: {
26
+ readonly typescript: readonly [".ts", ".mts", ".cts"];
27
+ readonly javascript: readonly [".mjs", ".cjs"];
28
+ readonly python: readonly [".py"];
29
+ readonly other: readonly [".md"];
30
+ };
31
+ declare const TIERS: readonly ["fast", "balanced", "strong"];
32
+ declare const IMPACTS: readonly ["high", "medium", "low"];
33
+ export type Language = keyof typeof LANGUAGES;
34
+ export type InputField = {
35
+ name: string;
36
+ type: (typeof INPUT_TYPES)[number];
37
+ description: string;
38
+ required: boolean;
39
+ };
40
+ export type OutputField = {
41
+ name: string;
42
+ type: (typeof OUTPUT_TYPES)[number];
43
+ description: string;
44
+ enum?: string[];
45
+ };
46
+ export type Line = {
47
+ path: string;
48
+ line: number;
49
+ quote: string;
50
+ };
51
+ /** One suggestion, as checked here from the scout's answer. */
52
+ export type Suggestion = {
53
+ key: string;
54
+ title: string;
55
+ summary: string;
56
+ why: string;
57
+ impact: (typeof IMPACTS)[number];
58
+ evidence: Line[];
59
+ agent: {
60
+ name: string;
61
+ description: string;
62
+ instructions: string;
63
+ inputs: InputField[];
64
+ output: OutputField[];
65
+ tools: string[];
66
+ tier: (typeof TIERS)[number];
67
+ };
68
+ integration: {
69
+ language: Language;
70
+ path: string;
71
+ call_site: {
72
+ path: string;
73
+ line: number;
74
+ note: string;
75
+ };
76
+ };
77
+ };
78
+ export type Status = "open" | "discarded" | "created";
79
+ /** A suggestion as it is kept: what the scan found, where, and what a person decided. */
80
+ export type Item = {
81
+ id: string;
82
+ repo: string;
83
+ key: string;
84
+ status: Status;
85
+ suggestion: Suggestion;
86
+ scan: {
87
+ run_id: string;
88
+ commit: string;
89
+ at: number;
90
+ };
91
+ decided_at?: number;
92
+ created?: {
93
+ agent_id: string;
94
+ template_id: string;
95
+ branch?: string;
96
+ commit?: string;
97
+ pull_request?: {
98
+ number: number;
99
+ url: string;
100
+ };
101
+ pull_error?: string;
102
+ };
103
+ /** A create in flight, on any server sharing the store: `by` is that create's own id. Taken off when it ends. */
104
+ creating?: Claim;
105
+ /** The branch a create pushed, kept before it makes the agent: a create after a failed write finds the agent made
106
+ * from that template at that commit and reuses it, or deletes the branch when none was made. */
107
+ pushed?: {
108
+ branch: string;
109
+ commit: string;
110
+ template_id: string;
111
+ base: string;
112
+ };
113
+ };
114
+ /** A claim on a row in the shared store: when it was taken, and by which request (a random id of its own). */
115
+ export type Claim = {
116
+ at: number;
117
+ by: string;
118
+ };
119
+ /** A scan as it is kept: its run, and what was read of it once it ended. */
120
+ export type Scan = {
121
+ repo: string;
122
+ run_id: string;
123
+ agent_id: string;
124
+ started_at: number;
125
+ read?: {
126
+ status: "completed" | "failed" | "cancelled";
127
+ at: number;
128
+ app?: string;
129
+ commit?: string;
130
+ found: number;
131
+ dropped: string[];
132
+ skipped: number;
133
+ error?: string;
134
+ };
135
+ /** A new scan of the repository being started, on any server sharing the store; the row is that scan's once it has. */
136
+ starting?: Claim;
137
+ /** A reader writing this scan's suggestions, on any server sharing the store; taken off when it marks the scan read. */
138
+ settling?: Claim;
139
+ };
140
+ /** A run of the scout, as its view says. */
141
+ export type ScanRun = {
142
+ status: string;
143
+ output?: unknown;
144
+ error?: string;
145
+ endedAt?: number;
146
+ };
147
+ export type SuggestionsDeps = {
148
+ readonly settings: Pick<Settings, "get" | "put" | "putIfAbsent" | "replaceIf" | "removeIf" | "all">;
149
+ readonly github: {
150
+ view(): GitHubConnectionView | undefined;
151
+ settingsUrl(): string | undefined;
152
+ readonly api: string;
153
+ repoInstallation(repo: string, signal?: AbortSignal): Promise<RepoInstallation | {
154
+ unusable: string;
155
+ reason: "not_connected" | "not_installed" | "github_failed";
156
+ }>;
157
+ tokenWith(id: number, repo: string, permissions: Record<string, "read" | "write">, signal?: AbortSignal): Promise<{
158
+ token: string;
159
+ expiresAt: number;
160
+ } | {
161
+ unusable: string;
162
+ }>;
163
+ revokeToken(token: string): Promise<void>;
164
+ };
165
+ /** The scout agent's id: one agent-scout made here and not archived, else a new one applied from the bundled package. */
166
+ scoutAgent(): Promise<string>;
167
+ /** A run of the scout agent started with `content`: its id. */
168
+ startScan(agentId: string, content: string): Promise<string>;
169
+ /** A run's state; undefined when there is no such run. */
170
+ readRun(runId: string): Promise<ScanRun | undefined>;
171
+ /** A scan's run cancelled: one that started but whose scan could not be kept, so nothing would ever read it. */
172
+ cancelScan(runId: string): Promise<void>;
173
+ /** The package (its files, under the id and origin given) made into an agent here: applied, then kept beside the other
174
+ * imported templates. Throws what the apply refuses (a missing model key, say), with nothing made. */
175
+ makeAgent(id: string, origin: {
176
+ source: string;
177
+ sha: string;
178
+ publisher: string;
179
+ }, files: ReadonlyMap<string, Buffer>): Promise<{
180
+ agentId: string;
181
+ warnings: InputIssue[];
182
+ }>;
183
+ /** The agent made here from the imported template `id` at commit `sha`, not archived; undefined when there is none. */
184
+ agentFrom(id: string, sha: string): Promise<string | undefined>;
185
+ /** This server's public URL, which the pull request names as AGENTRUN_URL. */
186
+ readonly publicUrl?: string;
187
+ /** Told each time a scan starts, a suggestion is discarded and a suggested agent's pull request opens: the anonymous
188
+ * counts' `used` (telemetry.ts), which hears the event's name and nothing else. It never fails the request. */
189
+ readonly used?: (event: UsageEventName) => void;
190
+ readonly now?: () => number;
191
+ };
192
+ /** A suggestion's id: the same repository and key always give the same one, so a decision outlives every rescan. */
193
+ export declare const suggestionId: (repo: string, key: string) => string;
194
+ /** A path in a repository: relative, in forward slashes, with no `.` or `..` part, at most 300, and no character that
195
+ * ends a line in any language a client is written in: no control character (C0 or C1), no U+2028 or U+2029. */
196
+ export declare function repoPath(value: unknown): string | undefined;
197
+ /** One suggestion of the scout's answer, checked whole; or why it is dropped. */
198
+ export declare function checkSuggestion(raw: unknown): Suggestion | string;
199
+ /** The scout's answer read: what the app is, the commit it read, its suggestions that check (at most five, keys
200
+ * distinct), and why each other one was dropped; or why the answer itself is not one. */
201
+ export declare function readScoutAnswer(output: unknown, repo: string): {
202
+ app: string;
203
+ commit: string;
204
+ suggestions: Suggestion[];
205
+ dropped: string[];
206
+ } | {
207
+ invalid: string;
208
+ };
209
+ /** The environment variable that names a created agent's id in the app. */
210
+ export declare const agentVariable: (key: string) => string;
211
+ /** The answer's JSON Schema, from its fields. */
212
+ export declare function outputSchema(s: Suggestion): Json;
213
+ /** The agent's template package, as files from the package's own folder: agent.md and output.schema.json. */
214
+ export declare function packageFiles(s: Suggestion, name?: string): Map<string, Buffer>;
215
+ /** Whether the package checks as the server checks a bundled or imported one: its problems, or none. */
216
+ export declare function packageProblems(s: Suggestion, name?: string): string[];
217
+ /** The client a created agent's pull request adds, in the call site's language: no dependency, fetch or urllib alone. */
218
+ export declare function clientFile(s: Suggestion, repo: string, commit: string): NewFile;
219
+ /** The pull request's title and body. */
220
+ export declare function pullText(s: Suggestion, at: {
221
+ repo: string;
222
+ commit: string;
223
+ agentId: string;
224
+ publicUrl?: string;
225
+ }): {
226
+ title: string;
227
+ body: string;
228
+ };
229
+ /** The repository a body or query names, as owner/name; 422 under `field` for anything else. */
230
+ export declare function repoOf(value: unknown, field?: string): string;
231
+ /** Why a repository's installation can't open a pull request: the permissions it lacks, and where to grant them. */
232
+ export declare function missingPermissions(installation: RepoInstallation): string[];
233
+ export declare class Suggestions {
234
+ private readonly deps;
235
+ constructor(deps: SuggestionsDeps);
236
+ private now;
237
+ /** Whether a claim is held: taken, and not so old that the server holding it must have stopped. */
238
+ private held;
239
+ /** The anonymous counts told what was done: a hook that throws is the counts' problem, never the request's. */
240
+ private used;
241
+ private item;
242
+ private need;
243
+ /** `item` written over the one read as `was`: false when another write moved it first. */
244
+ private write;
245
+ /** Each scan as kept. */
246
+ private scans;
247
+ private items;
248
+ /** A scan's run read once it ended: its suggestions kept (a decided one left as it was decided, an open one of an
249
+ * older scan replaced, one the new answer no longer holds removed), and what was read kept on the scan. */
250
+ private settle;
251
+ private mark;
252
+ /** GET /v2/suggestions: GitHub's state, each scan, and the suggestions (`status`: open and created by default). */
253
+ list(query: {
254
+ repo?: string;
255
+ status?: string;
256
+ }): Promise<Json>;
257
+ /** POST /v2/suggestions/scans: a scan of `repo` started (or the one still running answered). */
258
+ scan(body: Json): Promise<{
259
+ status: 200 | 202;
260
+ body: Json;
261
+ }>;
262
+ /** GET /v2/suggestions/{id}: the suggestion whole, the files a create would add (rendered now), and whether this
263
+ * server's GitHub App can open its pull request (read from GitHub now), with what to do when it can't. */
264
+ get(id: string, signal?: AbortSignal, name?: string): Promise<Json>;
265
+ /** Whether a pull request can be opened on `repo` now, and if not, why and where to fix it. */
266
+ private readiness;
267
+ /** POST /v2/suggestions/{id}/discard: it goes away, and later scans are told not to suggest it again. */
268
+ discard(id: string): Promise<Json>;
269
+ /** POST /v2/suggestions/{id}/restore: a discarded suggestion back among the open ones (an undo). */
270
+ restore(id: string): Promise<Json>;
271
+ private decide;
272
+ /** POST /v2/suggestions/{id}/create: the agent made here and its pull request opened (or what is missing to). A
273
+ * suggestion created already answers as it is; one whose agent was made but whose pull request failed opens only that. */
274
+ create(id: string, body: Json, signal?: AbortSignal): Promise<{
275
+ status: 200 | 201;
276
+ body: Json;
277
+ }>;
278
+ /** A create's claim taken off its suggestion's row, whatever the create wrote there; never another create's. */
279
+ private release;
280
+ private creating;
281
+ }
282
+ export {};