omp-superagent 0.1.6 → 0.1.8

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 (90) hide show
  1. package/DESIGN.md +36 -20
  2. package/README.ko.md +140 -33
  3. package/README.md +165 -41
  4. package/THIRD_PARTY_NOTICES.md +9 -7
  5. package/config.example.json +3 -1
  6. package/docs/OPERATIONS.md +395 -157
  7. package/docs/design/execution.md +156 -22
  8. package/docs/design/messaging.md +258 -52
  9. package/docs/discord-voice.md +8 -4
  10. package/docs/releases/0.1.7.md +25 -0
  11. package/docs/releases/0.1.8.md +21 -0
  12. package/gateway/bin/omp-gateway-darwin-arm64 +0 -0
  13. package/gateway/bin/omp-gateway-darwin-x64 +0 -0
  14. package/gateway/bin/omp-gateway-linux-arm64 +0 -0
  15. package/gateway/bin/omp-gateway-linux-x64 +0 -0
  16. package/host-owner/bin/omp-host-owner-darwin-arm64 +0 -0
  17. package/host-owner/bin/omp-host-owner-darwin-x64 +0 -0
  18. package/host-owner/bin/omp-host-owner-linux-arm64 +0 -0
  19. package/host-owner/bin/omp-host-owner-linux-x64 +0 -0
  20. package/package.json +9 -9
  21. package/scripts/ci.ts +4 -4
  22. package/scripts/test-omp.sh +2 -1
  23. package/skills/head/SKILL.md +26 -5
  24. package/skills/head/references/routing.md +68 -33
  25. package/skills/head/references/supervision.md +20 -4
  26. package/skills/lane/references/workflow.md +16 -7
  27. package/src/board.ts +5 -3
  28. package/src/cli.ts +161 -19
  29. package/src/config.ts +21 -1
  30. package/src/contracts.ts +63 -8
  31. package/src/cron-jobs.ts +443 -19
  32. package/src/cron-pr-intake.ts +257 -0
  33. package/src/discord-markdown.ts +350 -123
  34. package/src/extension.ts +78 -13
  35. package/src/gateway-client.ts +8 -2
  36. package/src/head-quota.ts +80 -0
  37. package/src/head-recovery.ts +40 -1
  38. package/src/host-extension.ts +122 -4
  39. package/src/host-inventory-manifest.ts +2 -2
  40. package/src/host-protocol.ts +11 -0
  41. package/src/host-sdk-helper.ts +121 -12
  42. package/src/host.ts +175 -57
  43. package/src/installed-omp.ts +116 -4
  44. package/src/lane-rows.ts +44 -4
  45. package/src/lane-watch.ts +339 -0
  46. package/src/managed-memory-helper.ts +13 -10
  47. package/src/managed-memory.ts +62 -27
  48. package/src/managed-ulw-probe.ts +75 -20
  49. package/src/managed-ulw.ts +174 -21
  50. package/src/messenger-command-catalog.json +2 -2
  51. package/src/native-launch-profile.ts +4 -2
  52. package/src/native-presets.ts +32 -5
  53. package/src/native-sessions.ts +3 -1
  54. package/src/native-settings.ts +47 -9
  55. package/src/observation-request.ts +23 -0
  56. package/src/omp-usage.ts +254 -36
  57. package/src/pr-github-schema.ts +5 -1
  58. package/src/pr-github.ts +68 -19
  59. package/src/pr-intake-automation.ts +316 -0
  60. package/src/pr-intake-comment.ts +226 -0
  61. package/src/pr-intake-fix.ts +233 -0
  62. package/src/pr-intake-github.ts +480 -0
  63. package/src/pr-intake-material.ts +230 -0
  64. package/src/pr-intake-mode.ts +59 -0
  65. package/src/pr-intake-review.ts +397 -0
  66. package/src/pr-intake-tree.ts +69 -0
  67. package/src/pr-intake-work.ts +29 -0
  68. package/src/pr-watch.ts +91 -32
  69. package/src/runtime.ts +2702 -391
  70. package/src/setup-judge.ts +1 -1
  71. package/src/setup.ts +12 -16
  72. package/src/store.ts +429 -86
  73. package/src/topic-history.ts +243 -47
  74. package/src/worker-checkout.ts +106 -0
  75. package/src/worker-destination.ts +10 -0
  76. package/src/worker-doctor.ts +66 -0
  77. package/src/worker-enrollment.ts +165 -0
  78. package/src/worker-host.ts +180 -0
  79. package/src/worker-ledger.ts +188 -0
  80. package/src/worker-placement.ts +78 -0
  81. package/src/worker-profile.ts +274 -0
  82. package/src/worker-registration.ts +288 -0
  83. package/src/worker-repository.ts +233 -0
  84. package/src/worker-request.ts +74 -0
  85. package/src/worker-service.ts +230 -0
  86. package/src/worker-stdio.ts +61 -0
  87. package/src/worker-trust.ts +36 -0
  88. package/src/worker-wire.ts +204 -0
  89. package/src/workflow.ts +81 -32
  90. package/src/setup-memory.ts +0 -21
@@ -0,0 +1,257 @@
1
+ import { Type, type Static } from "@sinclair/typebox/type";
2
+ import { Value } from "@sinclair/typebox/value";
3
+ import { routeKey, type InputRecord, type OutputRecord, type StorePort } from "./contracts";
4
+ import type { CronJobs, CronPrJob } from "./cron-jobs";
5
+ import { parsePrRef } from "./pr-github";
6
+ import { PrReadError } from "./pr-github-schema";
7
+ import { intakeStatusKey } from "./pr-intake-work";
8
+
9
+ const offerPrefix = "cron-pr:offer:";
10
+ const githubId = Type.Readonly(Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }));
11
+ const identitySchema = Type.Object({ repositoryId: githubId, ownerId: githubId });
12
+ const pullSchema = Type.Object({
13
+ number: Type.Readonly(Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER })),
14
+ head: Type.Readonly(Type.String({ pattern: "^[0-9a-fA-F]{40}$" })),
15
+ author: Type.Readonly(Type.String({ minLength: 1 })),
16
+ createdAt: Type.Readonly(Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER })),
17
+ });
18
+ const candidateSchema = Type.Object({
19
+ ...pullSchema.properties,
20
+ ...identitySchema.properties,
21
+ jobId: Type.Readonly(Type.String()),
22
+ outputId: Type.Readonly(Type.String()),
23
+ epoch: Type.Readonly(Type.String()),
24
+ policyRevision: Type.Optional(Type.Readonly(Type.String())),
25
+ });
26
+ const offerSchema = Type.Object({
27
+ ...candidateSchema.properties,
28
+ claimedBy: Type.Readonly(Type.Union([Type.String(), Type.Null()])),
29
+ });
30
+ const ledgerSchema = Type.Object({ identity: identitySchema, candidates: Type.Array(offerSchema) });
31
+ const resultSchema = Type.Object({
32
+ ...identitySchema.properties, self: Type.String({ minLength: 1 }), pulls: Type.Array(pullSchema),
33
+ });
34
+
35
+ type RepositoryIdentity = Static<typeof identitySchema>;
36
+ type Offer = Static<typeof offerSchema>;
37
+ export type CronPrCandidate = Static<typeof candidateSchema>;
38
+ export interface IntakeScan {
39
+ readonly job: CronPrJob;
40
+ readonly entries: readonly { candidate: CronPrCandidate; head: string | null }[];
41
+ }
42
+ export type ReadIntakePulls = (repository: string, signal: AbortSignal) => Promise<RepositoryIdentity & {
43
+ readonly self: string;
44
+ readonly pulls: readonly Static<typeof pullSchema>[];
45
+ }>;
46
+
47
+ class CronPrIntakeError extends Error {}
48
+
49
+ export function normalizeIntakeRepository(input: string): string | null {
50
+ try {
51
+ const { owner, repo } = parsePrRef(`${input}#1`);
52
+ return `${owner}/${repo}`;
53
+ } catch (error) {
54
+ if (error instanceof PrReadError && error.reason === "reference") return null;
55
+ throw error;
56
+ }
57
+ }
58
+
59
+ export function isPrIntakeOffer(outputId: string): boolean {
60
+ return outputId.startsWith(offerPrefix);
61
+ }
62
+
63
+ function ledgerKey(repository: string): string { return `cron-pr:ledger:${repository}`; }
64
+ function outcomeKey(runId: string): string { return `cron-pr:outcome:${runId}`; }
65
+
66
+ function ledger(store: StorePort, repository: string): Static<typeof ledgerSchema> | null {
67
+ const raw = store.getMeta(ledgerKey(repository));
68
+ if (raw === null) return null;
69
+ const parsed: unknown = JSON.parse(raw);
70
+ if (!Value.Check(ledgerSchema, parsed)) throw new CronPrIntakeError("Damaged PR intake offer ledger.");
71
+ return parsed;
72
+ }
73
+
74
+ function sameIdentity(left: RepositoryIdentity, right: RepositoryIdentity): boolean {
75
+ return left.repositoryId === right.repositoryId && left.ownerId === right.ownerId;
76
+ }
77
+
78
+ function action(candidate: CronPrCandidate): string {
79
+ return `/cron pr-review ${candidate.jobId} ${candidate.number} ${candidate.head}`;
80
+ }
81
+
82
+ function offerText(repository: string, candidate: CronPrCandidate): string {
83
+ if (candidate.policyRevision) return `${repository}#${candidate.number} — 새 외부 PR (${candidate.head}). 등록한 단계에 따라 이 메시지에 전용 검토 스레드를 엽니다. 상태: /cron show ${candidate.jobId} ${candidate.number}\n수동 검토:\n${action(candidate)}`;
84
+ return `New external pull request: ${repository}#${candidate.number}. `
85
+ + `The following owner command starts a read-only review; it does not merge or change the pull request.\n\n${action(candidate)}`;
86
+ }
87
+
88
+ export function describePrIntake(store: StorePort, job: CronPrJob, number: number | null): string {
89
+ const candidates = ledger(store, job.repository)?.candidates.filter(candidate => candidate.jobId === job.id) ?? [];
90
+ const summary = job.lastRunId ? store.getMeta(outcomeKey(job.lastRunId)) : null;
91
+ const newest = [...candidates].reverse();
92
+ const selected = number === null ? newest.slice(0, 10) : newest.filter(candidate => candidate.number === number);
93
+ const open = !job.paused && !job.removed && job.stopBoundary === store.getMeta("head:stop-boundary");
94
+ const lines = selected.map(candidate => {
95
+ const status = candidate.claimedBy !== null
96
+ ? store.output(candidate.outputId)?.state ?? "not queued; no automatic replay"
97
+ : candidate.epoch === job.epoch && open
98
+ ? "deferred; up to one offer per scan" : "deferred offer suppressed; manual review only";
99
+ const progress = store.getMeta(intakeStatusKey(job.id, candidate.number));
100
+ return `${action(candidate)} (${status})${progress ? ` — ${progress}` : ""}`;
101
+ });
102
+ return [
103
+ summary,
104
+ lines.length ? `Recorded PR offers:\n${lines.join("\n")}` : "No matching PR offers recorded.",
105
+ number === null && newest.length > selected.length ? `Showing the latest ${selected.length} of ${newest.length}; use /cron show ${job.id} PR_NUMBER for an older offer.` : null,
106
+ ].filter(Boolean).join("\n");
107
+ }
108
+
109
+ /** Read-only controller: no native prompts, synthetic owner inputs, or PR actions. */
110
+ export class CronPrIntake {
111
+ private readonly fetching = new Map<string, { readonly input: InputRecord; readonly abort: AbortController }>();
112
+
113
+ constructor(
114
+ private readonly store: StorePort,
115
+ private readonly jobs: CronJobs,
116
+ private readonly readIntakePulls: ReadIntakePulls,
117
+ ) {}
118
+
119
+ cancelInactive(): void {
120
+ for (const { input, abort } of this.fetching.values()) {
121
+ if (!this.jobs.pendingPrRun(input)) abort.abort();
122
+ }
123
+ }
124
+
125
+ candidate(job: CronPrJob, number: number): CronPrCandidate | null {
126
+ const saved = ledger(this.store, job.repository);
127
+ if (!saved) return null;
128
+ return saved.candidates.find(candidate => candidate.jobId === job.id && candidate.number === number
129
+ && sameIdentity(saved.identity, candidate)) ?? null;
130
+ }
131
+
132
+ canDeliver(output: OutputRecord): boolean {
133
+ if (!isPrIntakeOffer(output.id)) return false;
134
+ const [repository, number, extra] = output.id.slice(offerPrefix.length).split(":");
135
+ if (!repository || normalizeIntakeRepository(repository) !== repository || !number || extra !== undefined) return false;
136
+ const saved = ledger(this.store, repository);
137
+ if (!saved) return false;
138
+ const candidate = saved.candidates.find(item => item.outputId === output.id && item.claimedBy !== null && sameIdentity(saved.identity, item));
139
+ if (!candidate) return false;
140
+ const active = this.jobs.activePrEnrollment(candidate.jobId);
141
+ return active !== null && active.job.repository === repository && candidate.epoch === active.job.epoch
142
+ && output.sourceId === active.source.id && routeKey(output.route) === routeKey(active.source.route)
143
+ && output.text === offerText(repository, candidate);
144
+ }
145
+
146
+ async consume(input: InputRecord, signal: AbortSignal): Promise<IntakeScan | undefined> {
147
+ if (signal.aborted || this.fetching.has(input.id) || input.state !== "pending" || !this.jobs.isPrIntakeRun(input)) return;
148
+ const enrollment = this.jobs.pendingPrRun(input);
149
+ if (!enrollment) {
150
+ if (!this.store.getMeta("head:restart-fence")) this.store.settle(input.id, "cancelled");
151
+ return;
152
+ }
153
+ const abort = new AbortController();
154
+ const workSignal = AbortSignal.any([signal, abort.signal]);
155
+ this.fetching.set(input.id, { input, abort });
156
+ try {
157
+ const result = await this.read(enrollment.job.repository, workSignal);
158
+ // In-flight work is not authority: pause/removal, stop, replacement, or
159
+ // the loss of the original authenticated source can all revoke this receipt.
160
+ if (workSignal.aborted) return;
161
+ const current = this.jobs.pendingPrRun(input);
162
+ if (!current || current.job.epoch !== enrollment.job.epoch) {
163
+ if (!this.store.getMeta("head:restart-fence")) this.store.settle(input.id, "cancelled");
164
+ return;
165
+ }
166
+ if (result === null) {
167
+ this.finish(input.id, "GitHub lookup failed; no new offers were made.", "cancelled");
168
+ return;
169
+ }
170
+ const self = result.self.toLowerCase();
171
+ if (!current.job.repository.startsWith(`${self}/`)) {
172
+ this.finish(input.id, "Authenticated GitHub account does not match the repository owner; no new offers were made.", "cancelled");
173
+ return;
174
+ }
175
+ const saved = ledger(this.store, current.job.repository);
176
+ if (saved && !sameIdentity(saved.identity, result)) {
177
+ this.finish(input.id, "GitHub repository or owner identity changed; no new offers were made.", "cancelled");
178
+ return;
179
+ }
180
+ const identity = { repositoryId: result.repositoryId, ownerId: result.ownerId };
181
+ const policy = this.jobs.prPolicy(current.job.id);
182
+ const prior = saved?.candidates ?? [];
183
+ const seen = new Set(prior.map(candidate => candidate.number));
184
+ const observed = new Map<number, string>();
185
+ const added: Offer[] = [];
186
+ for (const pull of result.pulls) {
187
+ if (pull.author.toLowerCase() === self || pull.createdAt <= current.job.eligibleAfter || observed.has(pull.number)) continue;
188
+ const head = pull.head.toLowerCase();
189
+ observed.set(pull.number, head);
190
+ if (seen.has(pull.number)) continue;
191
+ added.push({
192
+ number: pull.number, head, author: pull.author, createdAt: pull.createdAt, claimedBy: null,
193
+ ...identity, jobId: current.job.id, epoch: current.job.epoch,
194
+ ...(policy ? { policyRevision: policy.revision } : {}),
195
+ outputId: `${offerPrefix}${current.job.repository}:${pull.number}`,
196
+ });
197
+ }
198
+ const candidates = [...prior, ...added];
199
+ let chosen: Offer | undefined;
200
+ let chosenIndex = -1;
201
+ // The run's claim consumes its one slot even if the process died before
202
+ // queueing. Old-epoch/closed candidates remain inspectable. An unclaimed
203
+ // offer gets its currently observed SHA, so pushes during the backlog
204
+ // do not make an otherwise eligible PR permanently unannouncable.
205
+ if (!prior.some(candidate => candidate.claimedBy === input.id)) {
206
+ for (const [index, candidate] of candidates.entries()) {
207
+ const head = observed.get(candidate.number);
208
+ if (candidate.claimedBy !== null || candidate.jobId !== current.job.id || candidate.epoch !== current.job.epoch
209
+ || head === undefined) continue;
210
+ if (!chosen || candidate.createdAt < chosen.createdAt
211
+ || candidate.createdAt === chosen.createdAt && candidate.number < chosen.number) {
212
+ chosenIndex = index;
213
+ chosen = { ...candidate, head };
214
+ }
215
+ }
216
+ }
217
+ if (chosen) candidates[chosenIndex] = { ...chosen, claimedBy: input.id };
218
+ if (!saved || added.length || chosen) {
219
+ // Commit discovery and claim together before touching the outbox. A
220
+ // non-retryable claim is distinct from deferred discovery.
221
+ this.store.setMeta(ledgerKey(current.job.repository), JSON.stringify({ identity, candidates }));
222
+ }
223
+ if (chosen) {
224
+ try {
225
+ this.store.queueOutput({
226
+ id: chosen.outputId, sourceId: current.source.id, route: current.source.route,
227
+ text: offerText(current.job.repository, chosen),
228
+ });
229
+ } catch (error) {
230
+ this.finish(input.id, "The PR offer was claimed but outbox creation was interrupted; inspect the recorded status.", "cancelled");
231
+ throw error;
232
+ }
233
+ }
234
+ this.finish(input.id, `GitHub lookup recorded ${added.length} new PR candidates; ${chosen ? "one offer queued" : "no offer queued"}.`, "done");
235
+ return { job: current.job, entries: candidates.flatMap(candidate =>
236
+ candidate.jobId === current.job.id && candidate.epoch === current.job.epoch && candidate.claimedBy !== null
237
+ && candidate.policyRevision ? [{ candidate, head: observed.get(candidate.number) ?? null }] : []) };
238
+ } finally {
239
+ this.fetching.delete(input.id);
240
+ }
241
+ }
242
+
243
+ private async read(repository: string, signal: AbortSignal) {
244
+ try {
245
+ const snapshot: unknown = await this.readIntakePulls(repository, signal);
246
+ return Value.Check(resultSchema, snapshot) ? snapshot : null;
247
+ } catch (error) {
248
+ if (error instanceof Error) return null;
249
+ throw error;
250
+ }
251
+ }
252
+
253
+ private finish(runId: string, note: string, state: "done" | "cancelled"): void {
254
+ this.store.setMeta(outcomeKey(runId), note);
255
+ this.store.settle(runId, state);
256
+ }
257
+ }