@andorra-labs/code 0.1.15 → 0.1.17
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.
- package/dist/src/acp-agent.d.ts +6 -0
- package/dist/src/acp-agent.js +15 -4
- package/dist/src/agent-definitions.js +29 -6
- package/dist/src/agent-execution.js +15 -10
- package/dist/src/agent-mcp-catalog.js +1 -0
- package/dist/src/agent-mcp.d.ts +4 -1
- package/dist/src/agent-mcp.js +46 -10
- package/dist/src/andorra/entry.d.ts +10 -0
- package/dist/src/andorra/entry.js +18 -4
- package/dist/src/andorra/hosted.d.ts +2 -1
- package/dist/src/andorra/hosted.js +2 -1
- package/dist/src/andorra/notices.d.ts +5 -0
- package/dist/src/andorra/notices.js +7 -0
- package/dist/src/andorra/state.d.ts +3 -2
- package/dist/src/andorra/state.js +4 -4
- package/dist/src/andorra/terminal.js +7 -2
- package/dist/src/anthropic-credentials.js +2 -0
- package/dist/src/app-server/error.d.ts +5 -0
- package/dist/src/app-server/error.js +7 -0
- package/dist/src/app-server/protocol.d.ts +22 -44
- package/dist/src/app-server/protocol.js +5 -1
- package/dist/src/app-server/workspace.d.ts +89 -0
- package/dist/src/app-server/workspace.js +457 -11
- package/dist/src/app-server.d.ts +465 -32
- package/dist/src/app-server.js +3308 -517
- package/dist/src/auth/deployment.js +2 -2
- package/dist/src/bridge/cloud.d.ts +27 -0
- package/dist/src/bridge/cloud.js +187 -0
- package/dist/src/bridge/command.d.ts +30 -0
- package/dist/src/bridge/command.js +347 -0
- package/dist/src/bridge/control.d.ts +68 -0
- package/dist/src/bridge/control.js +233 -0
- package/dist/src/bridge/engines.d.ts +90 -0
- package/dist/src/bridge/engines.js +601 -0
- package/dist/src/bridge/host-ops.d.ts +9 -0
- package/dist/src/bridge/host-ops.js +129 -0
- package/dist/src/bridge/host.d.ts +47 -0
- package/dist/src/bridge/host.js +540 -0
- package/dist/src/bridge/link.d.ts +38 -0
- package/dist/src/bridge/link.js +508 -0
- package/dist/src/bridge/login-link.d.ts +29 -0
- package/dist/src/bridge/login-link.js +54 -0
- package/dist/src/bridge/protocol.d.ts +136 -0
- package/dist/src/bridge/protocol.js +11 -0
- package/dist/src/bridge/store.d.ts +12 -0
- package/dist/src/bridge/store.js +61 -0
- package/dist/src/bridge/wording.d.ts +6 -0
- package/dist/src/bridge/wording.js +10 -0
- package/dist/src/browser-runner.js +1 -0
- package/dist/src/browser-server.js +7 -1
- package/dist/src/browser-ui/style.css +3 -3
- package/dist/src/browser-ui/tokens.css +28 -17
- package/dist/src/change-authors.d.ts +41 -0
- package/dist/src/change-authors.js +146 -0
- package/dist/src/claude-provider.js +3 -1
- package/dist/src/cli.js +202 -38
- package/dist/src/codex-errors.js +4 -1
- package/dist/src/coding-tools.js +15 -15
- package/dist/src/command-screens.d.ts +6 -0
- package/dist/src/command-screens.js +19 -14
- package/dist/src/commands.d.ts +14 -1
- package/dist/src/compaction-phrases.d.ts +4 -0
- package/dist/src/compaction-phrases.js +20 -0
- package/dist/src/completion.js +82 -5
- package/dist/src/config.d.ts +71 -3
- package/dist/src/config.js +202 -77
- package/dist/src/context-compaction.js +2 -1
- package/dist/src/deadline.js +13 -1
- package/dist/src/decision/DecisionManager.js +3 -2
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/decision/requestPhrases.d.ts +4 -0
- package/dist/src/decision/requestPhrases.js +22 -0
- package/dist/src/default-graph.js +1 -1
- package/dist/src/file-diff.d.ts +4 -0
- package/dist/src/file-diff.js +2 -1
- package/dist/src/github-app/agent-writes.d.ts +102 -0
- package/dist/src/github-app/agent-writes.js +320 -0
- package/dist/src/github-app/client.d.ts +349 -0
- package/dist/src/github-app/client.js +810 -0
- package/dist/src/github-app/event-source.d.ts +208 -0
- package/dist/src/github-app/event-source.js +684 -0
- package/dist/src/github-app/metrics.d.ts +32 -0
- package/dist/src/github-app/metrics.js +49 -0
- package/dist/src/github-app/review-loop.d.ts +274 -0
- package/dist/src/github-app/review-loop.js +1177 -0
- package/dist/src/github-app/review-node.d.ts +81 -0
- package/dist/src/github-app/review-node.js +205 -0
- package/dist/src/github-app/review-post.d.ts +73 -0
- package/dist/src/github-app/review-post.js +139 -0
- package/dist/src/github-app/review-text.d.ts +107 -0
- package/dist/src/github-app/review-text.js +1133 -0
- package/dist/src/github-app/review-threads.d.ts +47 -0
- package/dist/src/github-app/review-threads.js +107 -0
- package/dist/src/github-app/reviewer.d.ts +121 -0
- package/dist/src/github-app/reviewer.js +598 -0
- package/dist/src/github-app/store.d.ts +59 -0
- package/dist/src/github-app/store.js +148 -0
- package/dist/src/github-app/triggers.d.ts +141 -0
- package/dist/src/github-app/triggers.js +441 -0
- package/dist/src/github-inbox.d.ts +55 -0
- package/dist/src/github-inbox.js +153 -0
- package/dist/src/github-names.d.ts +8 -0
- package/dist/src/github-names.js +8 -0
- package/dist/src/glob-search.d.ts +61 -0
- package/dist/src/glob-search.js +180 -0
- package/dist/src/graph-health.js +13 -4
- package/dist/src/graph-manager-chat.js +1 -1
- package/dist/src/graph-preview.d.ts +46 -0
- package/dist/src/graph-preview.js +55 -0
- package/dist/src/graph-provider-portability.js +34 -11
- package/dist/src/graph-quota.d.ts +29 -2
- package/dist/src/graph-quota.js +68 -10
- package/dist/src/graph-runner.js +88 -10
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +11 -9
- package/dist/src/graph-sync.js +3 -3
- package/dist/src/graph-ui/app.js +201 -40
- package/dist/src/graph-ui/controls.css +1 -0
- package/dist/src/graph-ui/embed.js +2 -2
- package/dist/src/graph-ui/icons.js +3 -1
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graph-ui/manager.css +1 -1
- package/dist/src/graph-ui/manager.js +2 -2
- package/dist/src/graph-ui/sidebar.js +30 -0
- package/dist/src/graph-ui/studio-canvas.js +26 -13
- package/dist/src/graph-ui/studio.css +15 -7
- package/dist/src/graph-ui/studio.js +26 -5
- package/dist/src/graph-ui/style.css +77 -45
- package/dist/src/graph-ui/theme.js +3 -36
- package/dist/src/graph-ui/tokens.css +28 -20
- package/dist/src/graphs.d.ts +34 -1
- package/dist/src/graphs.js +162 -17
- package/dist/src/image-input.d.ts +16 -0
- package/dist/src/image-input.js +41 -0
- package/dist/src/membership.d.ts +30 -1
- package/dist/src/membership.js +48 -8
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +7 -1
- package/dist/src/model-metadata.js +39 -17
- package/dist/src/model-relay/local.d.ts +116 -0
- package/dist/src/model-relay/local.js +468 -0
- package/dist/src/model-relay/remote.d.ts +129 -0
- package/dist/src/model-relay/remote.js +252 -0
- package/dist/src/model-relay/runs.d.ts +34 -0
- package/dist/src/model-relay/runs.js +146 -0
- package/dist/src/model-relay/wire.d.ts +5 -0
- package/dist/src/model-relay/wire.js +5 -0
- package/dist/src/plan-pass.d.ts +59 -0
- package/dist/src/plan-pass.js +165 -0
- package/dist/src/project-registry.d.ts +21 -0
- package/dist/src/project-registry.js +74 -0
- package/dist/src/provider-engine.js +3 -0
- package/dist/src/provider-import.d.ts +0 -12
- package/dist/src/provider-import.js +7 -195
- package/dist/src/providers.d.ts +40 -2
- package/dist/src/providers.js +93 -23
- package/dist/src/pull-request-checks.d.ts +26 -0
- package/dist/src/pull-request-checks.js +56 -0
- package/dist/src/pull-request-conversation.d.ts +134 -0
- package/dist/src/pull-request-conversation.js +221 -0
- package/dist/src/pull-request-create.d.ts +175 -0
- package/dist/src/pull-request-create.js +392 -0
- package/dist/src/pull-request-details.d.ts +242 -0
- package/dist/src/pull-request-details.js +614 -0
- package/dist/src/pull-request-edit.d.ts +23 -0
- package/dist/src/pull-request-edit.js +91 -0
- package/dist/src/pull-request-logs.d.ts +87 -0
- package/dist/src/pull-request-logs.js +183 -0
- package/dist/src/pull-request-merge.d.ts +112 -0
- package/dist/src/pull-request-merge.js +258 -0
- package/dist/src/pull-request-review.d.ts +137 -0
- package/dist/src/pull-request-review.js +401 -0
- package/dist/src/pull-requests.d.ts +369 -8
- package/dist/src/pull-requests.js +524 -55
- package/dist/src/react-runtime.js +38 -5
- package/dist/src/remote/engine-pool.d.ts +88 -4
- package/dist/src/remote/engine-pool.js +379 -90
- package/dist/src/remote/roots.d.ts +19 -0
- package/dist/src/remote/roots.js +45 -7
- package/dist/src/remote/types.d.ts +0 -44
- package/dist/src/run-control.d.ts +17 -0
- package/dist/src/run-control.js +47 -0
- package/dist/src/run-progress.d.ts +10 -0
- package/dist/src/run-progress.js +122 -0
- package/dist/src/run-records.d.ts +7 -2
- package/dist/src/run-records.js +71 -6
- package/dist/src/runtime.d.ts +9 -1
- package/dist/src/runtime.js +24 -4
- package/dist/src/session-changes.d.ts +35 -0
- package/dist/src/session-changes.js +194 -6
- package/dist/src/session-monitor.js +2 -1
- package/dist/src/session-reaper.d.ts +1 -1
- package/dist/src/session-reaper.js +6 -1
- package/dist/src/session-summary.d.ts +2 -1
- package/dist/src/session-summary.js +2 -1
- package/dist/src/sessions.d.ts +11 -1
- package/dist/src/sessions.js +17 -4
- package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
- package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
- package/dist/src/skills/bundled/provenance.json +2 -2
- package/dist/src/skills/runtime-skills.js +1 -1
- package/dist/src/subagent-run.js +1 -0
- package/dist/src/telemetry/capture-core.d.ts +17 -0
- package/dist/src/telemetry/capture-core.js +59 -1
- package/dist/src/telemetry/classify.d.ts +3 -1
- package/dist/src/telemetry/classify.js +37 -0
- package/dist/src/telemetry/emitter.d.ts +17 -0
- package/dist/src/telemetry/emitter.js +76 -5
- package/dist/src/telemetry/schema.d.ts +47 -2
- package/dist/src/telemetry/schema.js +120 -5
- package/dist/src/telemetry/surface.d.ts +3 -1
- package/dist/src/telemetry/surface.js +4 -1
- package/dist/src/telemetry/uploader.d.ts +6 -1
- package/dist/src/telemetry/uploader.js +22 -3
- package/dist/src/terminal-ui.d.ts +1 -0
- package/dist/src/terminal-ui.js +10 -3
- package/dist/src/test-edit-guard.d.ts +7 -0
- package/dist/src/test-edit-guard.js +49 -1
- package/dist/src/timers.d.ts +2 -0
- package/dist/src/tools.js +59 -9
- package/dist/src/transcript.js +8 -2
- package/dist/src/types.d.ts +7 -0
- package/dist/src/usage-analytics.js +18 -10
- package/package.json +6 -1
- package/dist/src/remote/cert.d.ts +0 -11
- package/dist/src/remote/cert.js +0 -87
- package/dist/src/remote/client.d.ts +0 -119
- package/dist/src/remote/client.js +0 -544
- package/dist/src/remote/command.d.ts +0 -4
- package/dist/src/remote/command.js +0 -194
- package/dist/src/remote/errors.d.ts +0 -11
- package/dist/src/remote/errors.js +0 -14
- package/dist/src/remote/network.d.ts +0 -22
- package/dist/src/remote/network.js +0 -102
- package/dist/src/remote/pairing.d.ts +0 -63
- package/dist/src/remote/pairing.js +0 -299
- package/dist/src/remote/pem.d.ts +0 -2
- package/dist/src/remote/pem.js +0 -7
- package/dist/src/remote/serve.d.ts +0 -68
- package/dist/src/remote/serve.js +0 -244
- package/dist/src/remote/server.d.ts +0 -21
- package/dist/src/remote/server.js +0 -406
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { randomBytes, randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { isCursor, isEngineId, isMentionCommentId, GITHUB_COVERAGE_STATES } from './client.js';
|
|
5
|
+
/**
|
|
6
|
+
* What the GitHub App event source keeps under `<home>/github-app/`. A desktop engine and a CLI on one home
|
|
7
|
+
* share these files; only the process that holds the pull-request watcher's lease writes them.
|
|
8
|
+
*
|
|
9
|
+
* - `engine.json`: this home's engine id, 22 base64url characters, so a desktop and a bridge machine on one
|
|
10
|
+
* account do not overwrite each other's subscriptions.
|
|
11
|
+
* - `cursor.json`: the inbox cursor the next pull starts after.
|
|
12
|
+
* - `state.json`: the coverage the lease holder last saw, so `github.status` in another process on the same
|
|
13
|
+
* home answers the same coverage without subscribing itself.
|
|
14
|
+
* - `mentions.json`: the comments that mentioned the App's bot which this home has already acted on (their node
|
|
15
|
+
* ids and when), so a notice pulled again after a restart wakes nothing. Never a comment's text.
|
|
16
|
+
* - `own-comments.json`: the comments the agent's own writes made in the last 2 hours (node ids and links), so
|
|
17
|
+
* a mention in one of them never wakes the task (written by whichever process made the write).
|
|
18
|
+
*/
|
|
19
|
+
export const githubAppDirectory = (home) => join(home, 'github-app');
|
|
20
|
+
async function readJson(path) {
|
|
21
|
+
let text;
|
|
22
|
+
try {
|
|
23
|
+
text = await readFile(path, 'utf8');
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code === 'ENOENT')
|
|
27
|
+
return undefined;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const value = JSON.parse(text);
|
|
32
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function writeJson(path, value) {
|
|
39
|
+
await mkdir(join(path, '..'), { recursive: true });
|
|
40
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
41
|
+
await writeFile(temporary, `${JSON.stringify(value, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
42
|
+
try {
|
|
43
|
+
await rename(temporary, path);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
await rm(temporary, { force: true });
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export const newEngineId = () => randomBytes(16).toString('base64url');
|
|
51
|
+
/** This home's engine id, created on first use. A malformed file is replaced, so the service never sees a bad id. */
|
|
52
|
+
export async function engineId(home) {
|
|
53
|
+
const path = join(githubAppDirectory(home), 'engine.json');
|
|
54
|
+
const stored = await readJson(path);
|
|
55
|
+
if (isEngineId(stored?.engine))
|
|
56
|
+
return stored.engine;
|
|
57
|
+
const engine = newEngineId();
|
|
58
|
+
await writeJson(path, { version: 1, engine });
|
|
59
|
+
return engine;
|
|
60
|
+
}
|
|
61
|
+
export async function readCursor(home) {
|
|
62
|
+
const stored = await readJson(join(githubAppDirectory(home), 'cursor.json'));
|
|
63
|
+
return isCursor(stored?.cursor) ? stored.cursor : undefined;
|
|
64
|
+
}
|
|
65
|
+
export async function writeCursor(home, cursor, now) {
|
|
66
|
+
const path = join(githubAppDirectory(home), 'cursor.json');
|
|
67
|
+
if (cursor === undefined) {
|
|
68
|
+
await rm(path, { force: true });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
await writeJson(path, { version: 1, cursor, updatedAt: new Date(now).toISOString() });
|
|
72
|
+
}
|
|
73
|
+
export async function readSharedCoverage(home) {
|
|
74
|
+
const stored = await readJson(join(githubAppDirectory(home), 'state.json'));
|
|
75
|
+
if (!stored || typeof stored.updatedAt !== 'string' || !['off', 'events', 'polling'].includes(String(stored.mode)))
|
|
76
|
+
return undefined;
|
|
77
|
+
const pullRequests = {};
|
|
78
|
+
const listed = stored.pullRequests;
|
|
79
|
+
if (listed && typeof listed === 'object' && !Array.isArray(listed)) {
|
|
80
|
+
for (const [sessionId, entry] of Object.entries(listed)) {
|
|
81
|
+
const value = entry;
|
|
82
|
+
if (!/^[A-Za-z0-9_-]{1,128}$/.test(sessionId) || typeof value?.url !== 'string' || !GITHUB_COVERAGE_STATES.includes(String(value.coverage)))
|
|
83
|
+
continue;
|
|
84
|
+
pullRequests[sessionId] = { url: value.url, coverage: value.coverage };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
updatedAt: stored.updatedAt, mode: stored.mode, pullRequests,
|
|
89
|
+
...(GITHUB_COVERAGE_STATES.includes(String(stored.reason)) ? { reason: stored.reason } : {}),
|
|
90
|
+
...(typeof stored.connected === 'boolean' ? { connected: stored.connected } : {}),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export async function writeSharedCoverage(home, state) {
|
|
94
|
+
await writeJson(join(githubAppDirectory(home), 'state.json'), { version: 1, ...state });
|
|
95
|
+
}
|
|
96
|
+
/** How long a handled mention is remembered: the service keeps a notice 7 days, so it cannot come back later. */
|
|
97
|
+
export const MENTION_MEMORY_MS = 8 * 24 * 60 * 60_000;
|
|
98
|
+
/** At most this many handled mentions are remembered (the oldest go first). */
|
|
99
|
+
export const MENTION_MEMORY = 500;
|
|
100
|
+
/** The comment ids this home acted on, with when: entries older than `MENTION_MEMORY_MS` are left out. */
|
|
101
|
+
export async function readMentions(home, now) {
|
|
102
|
+
const stored = await readJson(join(githubAppDirectory(home), 'mentions.json'));
|
|
103
|
+
const handled = new Map();
|
|
104
|
+
const listed = Array.isArray(stored?.comments) ? stored.comments : [];
|
|
105
|
+
for (const entry of listed.slice(-MENTION_MEMORY)) {
|
|
106
|
+
const value = entry;
|
|
107
|
+
const at = typeof value?.at === 'string' ? Date.parse(value.at) : Number.NaN;
|
|
108
|
+
if (typeof value?.id !== 'string' || !isMentionCommentId(value.id) || !Number.isFinite(at) || now - at > MENTION_MEMORY_MS)
|
|
109
|
+
continue;
|
|
110
|
+
handled.set(value.id, at);
|
|
111
|
+
}
|
|
112
|
+
return handled;
|
|
113
|
+
}
|
|
114
|
+
export async function writeMentions(home, handled) {
|
|
115
|
+
const comments = [...handled.entries()].sort((a, b) => a[1] - b[1]).slice(-MENTION_MEMORY).map(([id, at]) => ({ id, at: new Date(at).toISOString() }));
|
|
116
|
+
await writeJson(join(githubAppDirectory(home), 'mentions.json'), { version: 1, comments });
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Comments the engine's own writes made on a PR (the agent's replies and comments, through the bot or gh), kept
|
|
120
|
+
* so a `request` notice for one of them never wakes the task that wrote it: a reply posted through gh is the
|
|
121
|
+
* person's, and one that names the bot would otherwise ask for the task again. Any process on the home may
|
|
122
|
+
* add one; the lease holder reads them. Ids and links only, never the text.
|
|
123
|
+
*/
|
|
124
|
+
export const OWN_COMMENT_MEMORY_MS = 2 * 60 * 60_000;
|
|
125
|
+
const OWN_COMMENTS = 200;
|
|
126
|
+
export async function readOwnComments(home, now) {
|
|
127
|
+
const stored = await readJson(join(githubAppDirectory(home), 'own-comments.json'));
|
|
128
|
+
const listed = Array.isArray(stored?.comments) ? stored.comments : [];
|
|
129
|
+
const comments = [];
|
|
130
|
+
for (const entry of listed.slice(-OWN_COMMENTS)) {
|
|
131
|
+
const value = entry;
|
|
132
|
+
const at = typeof value?.at === 'string' ? Date.parse(value.at) : Number.NaN;
|
|
133
|
+
if (!Number.isFinite(at) || now - at > OWN_COMMENT_MEMORY_MS)
|
|
134
|
+
continue;
|
|
135
|
+
const id = typeof value?.id === 'string' && /^[A-Za-z0-9_=+/-]{4,200}$/.test(value.id) ? value.id : undefined;
|
|
136
|
+
const url = typeof value?.url === 'string' && value.url.startsWith('https://github.com/') && value.url.length <= 2048 ? value.url : undefined;
|
|
137
|
+
if (id !== undefined || url !== undefined)
|
|
138
|
+
comments.push({ ...(id === undefined ? {} : { id }), ...(url === undefined ? {} : { url }), at });
|
|
139
|
+
}
|
|
140
|
+
return comments;
|
|
141
|
+
}
|
|
142
|
+
export async function rememberOwnComment(home, comment, now) {
|
|
143
|
+
const kept = await readOwnComments(home, now).catch(() => []);
|
|
144
|
+
kept.push({ ...comment, at: now });
|
|
145
|
+
await writeJson(join(githubAppDirectory(home), 'own-comments.json'), {
|
|
146
|
+
version: 1, comments: kept.slice(-OWN_COMMENTS).map(entry => ({ ...(entry.id === undefined ? {} : { id: entry.id }), ...(entry.url === undefined ? {} : { url: entry.url }), at: new Date(entry.at).toISOString() })),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { type AutoFixWrites, type GhRunner, type SessionPullRequest } from '../pull-requests.js';
|
|
2
|
+
import type { GitHubAppClient, MentionNotice } from './client.js';
|
|
3
|
+
/**
|
|
4
|
+
* "@andorra-code" comment triggers (`design/specs/github-app.md`, "Phase 3"). The receiver writes a `request`
|
|
5
|
+
* notice when the person whose task tracks a PR mentions the App's bot in a comment on it; the notice carries
|
|
6
|
+
* the comment's node id and URL, never its text. For each one, this:
|
|
7
|
+
*
|
|
8
|
+
* 1. confirms, with gh on this computer, that the commenter is the person here: one of this machine's signed-in
|
|
9
|
+
* gh accounts, with push access to the repository (`GET /repos/{owner}/{repo}` as that account, its
|
|
10
|
+
* `permissions`), and that the comment is theirs (its node, read as that account: the author is the
|
|
11
|
+
* commenter, and nobody else edited it last). Anything else drops the notice;
|
|
12
|
+
* 2. wakes the session once per comment id, with the `mention` wake kind and a prompt that names the comment
|
|
13
|
+
* and the bot. The agent reads the comment itself, through gh;
|
|
14
|
+
* 3. then, and only once the wake was armed, asks the service to react 👀 (`POST /v1/github/writes`, `react`).
|
|
15
|
+
*
|
|
16
|
+
* gh or the service failing for a moment is retried (about 5 seconds, 30 seconds and 2 minutes later) while the
|
|
17
|
+
* comment is less than an hour old; the comment id is held meanwhile, so a second notice for it does nothing.
|
|
18
|
+
*
|
|
19
|
+
* `github.app.triggers: false` in the config switches all of it off on this installation. Comment ids already
|
|
20
|
+
* acted on are kept in `<home>/github-app/mentions.json`, so a notice pulled again after a restart wakes nothing.
|
|
21
|
+
* A notice for a comment the agent's pull_request tool made (`own-comments.json`), or for a comment written
|
|
22
|
+
* more than an hour ago (`commentAt`, or the notice's own time), is ignored.
|
|
23
|
+
*/
|
|
24
|
+
/** The repository permissions, as `GET /repos/{owner}/{repo}` reports them to an account, that may wake a task. */
|
|
25
|
+
export declare const MENTION_PERMISSIONS: readonly string[];
|
|
26
|
+
/** How long one attempt at the 👀 may take. */
|
|
27
|
+
export declare const REACTION_BUDGET_MS = 10000;
|
|
28
|
+
/** A mention in a comment written longer ago than this wakes nothing (a notice that waited, or one sent again). */
|
|
29
|
+
export declare const MENTION_MAX_AGE_MS: number;
|
|
30
|
+
/** How long closing waits for a mention whose gh read is still in flight; it can wake nothing after that. */
|
|
31
|
+
export declare const STOP_WAIT_MS = 2000;
|
|
32
|
+
/** The pauses before trying again after gh or the service failed for a moment. */
|
|
33
|
+
export declare const RETRY_DELAYS_MS: readonly number[];
|
|
34
|
+
/**
|
|
35
|
+
* The prompt a mention wakes the task with: who asked, which comment (its link and node id) and what kind it is,
|
|
36
|
+
* to stop if the comment is not theirs alone, and who the agent's answer posts as. The comment's text never
|
|
37
|
+
* enters it.
|
|
38
|
+
*/
|
|
39
|
+
export declare function mentionPrompt(notice: Pick<MentionNotice, 'actor' | 'commentUrl' | 'commentKind' | 'commentId'>, pullRequest: Pick<SessionPullRequest, 'url' | 'ghUser'>, writes: AutoFixWrites): string;
|
|
40
|
+
/** A definite no: the mention wakes nothing, and (unless `remember` is false) is remembered as handled. */
|
|
41
|
+
export declare class MentionRefused extends Error {
|
|
42
|
+
readonly reason: 'not-signed-in' | 'no-access' | 'not-author' | 'edited' | 'gone';
|
|
43
|
+
/** Whether the no is remembered as the comment's answer: not when this computer cannot tell who is signed in. */
|
|
44
|
+
readonly remember: boolean;
|
|
45
|
+
constructor(reason: 'not-signed-in' | 'no-access' | 'not-author' | 'edited' | 'gone', message: string, options?: {
|
|
46
|
+
remember?: boolean;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Confirms a mention on this computer, with gh. The commenter must be the person here: one of this machine's
|
|
51
|
+
* signed-in gh accounts, whose read of the tracked repository says it may push (write, maintain or admin, a
|
|
52
|
+
* custom role with write included). The comment, read by its node id as that account, must be theirs: its
|
|
53
|
+
* author the commenter, and nobody else its last editor. Throws `MentionRefused` for a definite no, and any other
|
|
54
|
+
* error when gh could not say (the caller tries again). Answers the confirming account.
|
|
55
|
+
*/
|
|
56
|
+
export declare function confirmMention(gh: GhRunner, pullRequest: Pick<SessionPullRequest, 'owner' | 'repo'>, notice: Pick<MentionNotice, 'actor' | 'commentId' | 'commentKind' | 'commentUrl'>): Promise<string>;
|
|
57
|
+
export interface MentionTriggerOptions {
|
|
58
|
+
home: string;
|
|
59
|
+
gh: GhRunner;
|
|
60
|
+
client: Pick<GitHubAppClient, 'write'>;
|
|
61
|
+
/** `github.app.triggers` is not false here. */
|
|
62
|
+
enabled(): Promise<boolean>;
|
|
63
|
+
/** Who the agent's answer posts as on this session's PR (the pull_request tool's own rule), and the bot's login. */
|
|
64
|
+
writes(sessionId: string): Promise<AutoFixWrites>;
|
|
65
|
+
/** Wakes the session with the prompt, as Fix with Agent does, and answers the wake's id. */
|
|
66
|
+
wake(sessionId: string, prompt: string, pullRequest: SessionPullRequest): string;
|
|
67
|
+
log?(level: 'info' | 'warn', detail: string): void;
|
|
68
|
+
now?(): number;
|
|
69
|
+
/** How long one attempt at the 👀 may take (tests shorten it). */
|
|
70
|
+
reactionBudgetMs?: number;
|
|
71
|
+
/** The pauses before each retry (tests shorten them). */
|
|
72
|
+
retryDelaysMs?: readonly number[];
|
|
73
|
+
/** How long `stop()` waits for mentions in flight (tests shorten it). */
|
|
74
|
+
stopWaitMs?: number;
|
|
75
|
+
requestId?(): string;
|
|
76
|
+
}
|
|
77
|
+
export type MentionOutcome = {
|
|
78
|
+
kind: 'woke';
|
|
79
|
+
wakeId: string;
|
|
80
|
+
reacted: boolean;
|
|
81
|
+
prompt: string;
|
|
82
|
+
account: string;
|
|
83
|
+
} | {
|
|
84
|
+
kind: 'ignored';
|
|
85
|
+
reason: 'off' | 'stale' | 'own' | 'duplicate' | 'not-tracked' | MentionRefused['reason'] | 'unconfirmed' | 'wake-failed' | 'stopped';
|
|
86
|
+
detail?: string;
|
|
87
|
+
};
|
|
88
|
+
export declare class MentionTriggers {
|
|
89
|
+
private readonly options;
|
|
90
|
+
private handled?;
|
|
91
|
+
private loading?;
|
|
92
|
+
/** Comment ids being looked at now, retries included: a second notice for one does nothing. */
|
|
93
|
+
private readonly busy;
|
|
94
|
+
private readonly running;
|
|
95
|
+
private readonly abort;
|
|
96
|
+
private stopped;
|
|
97
|
+
private readonly now;
|
|
98
|
+
/** This process's own writes, beside `own-comments.json` (which any process on the home adds to). */
|
|
99
|
+
private readonly own;
|
|
100
|
+
/** Every write to `mentions.json` and `own-comments.json` from this process, one after another. */
|
|
101
|
+
private saving;
|
|
102
|
+
constructor(options: MentionTriggerOptions);
|
|
103
|
+
/** Acts on one `request` notice for a session whose PR it names. Never throws. */
|
|
104
|
+
handle(sessionId: string, notice: MentionNotice): Promise<MentionOutcome>;
|
|
105
|
+
/**
|
|
106
|
+
* This process holds the watcher's lease again: another process may have acted on mentions meanwhile, so what
|
|
107
|
+
* was read of `mentions.json` is read again before the next one.
|
|
108
|
+
*/
|
|
109
|
+
reload(): void;
|
|
110
|
+
/** One write to the GitHub App's files at a time from this process. */
|
|
111
|
+
private serialized;
|
|
112
|
+
/**
|
|
113
|
+
* A comment the agent's pull_request tool made (its node id, its link, or both): a mention in it never wakes the
|
|
114
|
+
* task. Kept here and in `own-comments.json` for 2 hours; a failed save is logged, and this process still knows it.
|
|
115
|
+
*/
|
|
116
|
+
rememberOwn(comment: {
|
|
117
|
+
id?: string;
|
|
118
|
+
url?: string;
|
|
119
|
+
}): Promise<void>;
|
|
120
|
+
private ownComment;
|
|
121
|
+
/** Every notice handed in so far has been acted on (for tests and for closing). */
|
|
122
|
+
settled(): Promise<void>;
|
|
123
|
+
/** Cancels a retry's wait or a reaction in flight, and waits for the rest; later notices are ignored. */
|
|
124
|
+
stop(): Promise<void>;
|
|
125
|
+
private memory;
|
|
126
|
+
/** Records a comment as acted on, merged with what other processes saved meanwhile (`mentions.json` is shared). */
|
|
127
|
+
private markHandled;
|
|
128
|
+
/** When the comment was written: the receiver's `commentAt`, else the notice's own time, else when first seen. */
|
|
129
|
+
private writtenAt;
|
|
130
|
+
/** Waits before a retry; false when the engine is stopping. */
|
|
131
|
+
private pause;
|
|
132
|
+
/** The tracked PR, if this session still tracks the one the notice names (by owner, name and number). */
|
|
133
|
+
private tracked;
|
|
134
|
+
private run;
|
|
135
|
+
/**
|
|
136
|
+
* The 👀 on the comment, through the service, once the task has woken. A failure the service may get past is
|
|
137
|
+
* asked again with the same request id (so it reacts once), on the retry schedule, while the comment is under
|
|
138
|
+
* an hour old.
|
|
139
|
+
*/
|
|
140
|
+
private react;
|
|
141
|
+
}
|