omp-superagent 0.1.13 → 0.1.16

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 (78) hide show
  1. package/DESIGN.md +8 -5
  2. package/THIRD_PARTY_NOTICES.md +6 -0
  3. package/assets/architecture-dark.svg +4 -4
  4. package/assets/architecture.ko-dark.svg +4 -4
  5. package/assets/architecture.ko.svg +4 -4
  6. package/assets/architecture.mmd +5 -5
  7. package/assets/architecture.svg +4 -4
  8. package/config.example.json +1 -0
  9. package/docs/OPERATIONS.en.md +80 -23
  10. package/docs/OPERATIONS.md +73 -18
  11. package/docs/design/execution.md +180 -43
  12. package/docs/design/messaging.md +62 -10
  13. package/docs/releases/0.1.15.md +13 -0
  14. package/docs/releases/0.1.16.md +9 -0
  15. package/gateway/bin/omp-gateway-darwin-arm64 +0 -0
  16. package/gateway/bin/omp-gateway-darwin-x64 +0 -0
  17. package/gateway/bin/omp-gateway-linux-arm64 +0 -0
  18. package/gateway/bin/omp-gateway-linux-x64 +0 -0
  19. package/host-owner/bin/omp-host-owner-darwin-arm64 +0 -0
  20. package/host-owner/bin/omp-host-owner-darwin-x64 +0 -0
  21. package/host-owner/bin/omp-host-owner-linux-arm64 +0 -0
  22. package/host-owner/bin/omp-host-owner-linux-x64 +0 -0
  23. package/package.json +6 -3
  24. package/scripts/prepare-worker-memory.ts +37 -0
  25. package/skills/head/SKILL.md +29 -47
  26. package/skills/head/references/routing.md +35 -16
  27. package/skills/head/references/supervision.md +10 -14
  28. package/skills/lane/SKILL.md +14 -16
  29. package/skills/lane/references/workflow.md +14 -27
  30. package/src/cli.ts +56 -56
  31. package/src/config/config.ts +14 -0
  32. package/src/contracts.ts +38 -30
  33. package/src/cron/cron-jobs.ts +4 -3
  34. package/src/cron/cron-pr-intake.ts +1 -2
  35. package/src/extension.ts +69 -24
  36. package/src/gateway/gateway-client.ts +24 -15
  37. package/src/group/group-runner.ts +3 -2
  38. package/src/group-runner-extension.ts +7 -3
  39. package/src/host-extension.ts +109 -2
  40. package/src/host-sdk-helper.ts +6 -1
  41. package/src/lane/decision-tool.ts +2 -3
  42. package/src/lane/lane-report.ts +8 -30
  43. package/src/lane/lane-rows.ts +1 -1
  44. package/src/lane/workflow.ts +44 -3
  45. package/src/lane-extension.ts +5 -46
  46. package/src/messaging/discord-context.ts +8 -6
  47. package/src/messaging/discord-work-thread.ts +36 -0
  48. package/src/omp/host-protocol.ts +4 -3
  49. package/src/omp/host.ts +24 -7
  50. package/src/omp/managed-super.ts +43 -27
  51. package/src/omp/native-sessions.ts +12 -0
  52. package/src/omp/worker-memory-import.ts +410 -0
  53. package/src/omp/worker-memory-sdk.ts +8 -0
  54. package/src/operator/setup.ts +8 -13
  55. package/src/pr/pr-github-schema.ts +9 -0
  56. package/src/pr/pr-github.ts +6 -2
  57. package/src/pr/pr-intake-automation.ts +11 -8
  58. package/src/pr/pr-intake-fix.ts +2 -5
  59. package/src/pr/pr-intake-review.ts +7 -7
  60. package/src/routing/topic-history.ts +2 -2
  61. package/src/runtime/controller.ts +720 -468
  62. package/src/runtime/head-recovery.ts +7 -7
  63. package/src/runtime/head-superstack.ts +83 -0
  64. package/src/runtime/result-attachments.ts +3 -1
  65. package/src/runtime/worker-memory.ts +156 -0
  66. package/src/storage/deferred-routing.ts +1 -7
  67. package/src/storage/store.ts +465 -372
  68. package/src/worker/worker-host.ts +3 -2
  69. package/src/worker/worker-ledger.ts +20 -11
  70. package/src/worker/worker-memory-page.ts +83 -0
  71. package/src/worker/worker-memory-proofs.ts +260 -0
  72. package/src/worker/worker-memory-source.ts +305 -0
  73. package/src/worker/worker-memory-storage.ts +130 -0
  74. package/src/worker/worker-profile.ts +2 -0
  75. package/src/worker/worker-repository.ts +92 -7
  76. package/src/worker/worker-request.ts +1 -0
  77. package/src/worker/worker-service.ts +25 -8
  78. package/src/worker/worker-wire.ts +20 -6
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generated bridge entry for standalone OMP, where runtime extensions cannot
3
+ * resolve these pinned SDK internals through its legacy virtual registry.
4
+ */
5
+ export { computeMnemopiBankScope } from "@oh-my-pi/pi-coding-agent/mnemopi/config";
6
+ export { insertLiveEmbeddings } from "@oh-my-pi/pi-mnemopi/core/beam/helpers";
7
+ export { embed, fastembedModelName } from "@oh-my-pi/pi-mnemopi/core/embeddings";
8
+ export { getMnemopiRuntimeOptions, withMnemopiRuntimeOptions } from "@oh-my-pi/pi-mnemopi/core/runtime-options";
@@ -3,7 +3,6 @@ import {
3
3
  openSync, readFileSync, realpathSync, unlinkSync, writeSync,
4
4
  } from "node:fs";
5
5
  import { dirname, isAbsolute, join, resolve } from "node:path";
6
- import { fileURLToPath } from "node:url";
7
6
  import { isatty } from "node:tty";
8
7
  import { setImmediate as yieldToSignals } from "node:timers/promises";
9
8
  import { credentialEnvNames, hostPaths, parseConfig, type Config } from "../config/config";
@@ -15,7 +14,7 @@ import {
15
14
  import { applyConsentedMnemopi, canEnableGlobalMemory, inspectManagedMemory, memoryBlockReason } from "../omp/managed-memory";
16
15
  import { inspectNativeJudge } from "./setup-judge";
17
16
 
18
- const root = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
17
+ const root = resolve(import.meta.dir, "../..");
19
18
 
20
19
  class SetupCancelled extends Error {
21
20
  constructor(saved = false) {
@@ -167,7 +166,6 @@ export async function setup(configPath: string): Promise<void> {
167
166
  const path = resolve(configPath);
168
167
  const terminal = new Terminal();
169
168
  let configTemporary: string | undefined;
170
- let createdConfig = false;
171
169
  try {
172
170
  const previousConfig = currentConfig(path);
173
171
  const previousCredentials = readCredentialFile(path);
@@ -183,10 +181,11 @@ export async function setup(configPath: string): Promise<void> {
183
181
  ({ config, text } = await newConfig(terminal, path));
184
182
  }
185
183
  hostPaths(config, "main");
186
- await inspectInstalledOmp(config.command, credentialEnvNames(config));
184
+ const credentialNames = credentialEnvNames(config);
185
+ await inspectInstalledOmp(config.command, credentialNames);
187
186
  const values = Object.assign(Object.create(null) as Record<string, string>, previousCredentials?.values);
188
187
  let replacing = false;
189
- for (const name of credentialEnvNames(config)) {
188
+ for (const name of credentialNames) {
190
189
  const old = Object.hasOwn(values, name) ? values[name] : undefined;
191
190
  const explicit = process.env[name];
192
191
  const configured = !!(explicit || old);
@@ -225,7 +224,7 @@ export async function setup(configPath: string): Promise<void> {
225
224
  : "Write configuration/credentials?");
226
225
  // Snapshot the same environment-over-file precedence used by start before
227
226
  // native settings imports can populate unrelated dotenv values.
228
- const profileCredentials = Object.fromEntries(credentialEnvNames(config).map(name => [name, process.env[name] || values[name]!]));
227
+ const profileCredentials = Object.fromEntries(credentialNames.map(name => [name, process.env[name] || values[name]!]));
229
228
  // Deliver pending cancellation before entering the synchronous commit section.
230
229
  await yieldToSignals();
231
230
  terminal.check();
@@ -233,17 +232,13 @@ export async function setup(configPath: string): Promise<void> {
233
232
  unchanged(path, previousConfig);
234
233
  assertCredentialsUnchanged(path, previousCredentials);
235
234
  terminal.check();
236
- if (configTemporary) {
237
- linkSync(configTemporary, path); // Exclusive creation: never overwrite another config.
238
- createdConfig = true;
239
- }
235
+ if (configTemporary) linkSync(configTemporary, path); // Exclusive creation: never overwrite another config.
240
236
  try { writeCredentials(path, values, previousCredentials); }
241
237
  catch (error) {
242
- if (createdConfig && configTemporary) {
238
+ if (configTemporary) {
243
239
  const staged = lstatSync(configTemporary);
244
240
  const current = lstatSync(path);
245
241
  if (staged.dev === current.dev && staged.ino === current.ino) unlinkSync(path);
246
- createdConfig = false;
247
242
  }
248
243
  throw error;
249
244
  }
@@ -260,7 +255,7 @@ export async function setup(configPath: string): Promise<void> {
260
255
  console.log(`Setup saved but is incomplete. ${memoryBlockReason(memory)} No service was started by setup.`);
261
256
  process.exitCode = 1;
262
257
  }
263
- if (createdConfig) {
258
+ if (configTemporary) {
264
259
  const judge = await inspectNativeJudge(config.headCwd);
265
260
  if (judge.status === "unknown") {
266
261
  console.log("Setup saved, but native OMP judge configuration could not be verified; judge configuration is unknown, not confirmed missing. Native model settings were not changed by this check.");
@@ -87,6 +87,15 @@ export function parseWire<T extends TSchema>(schema: T, output: string): Static<
87
87
  return value;
88
88
  }
89
89
 
90
+ /** Count key tokens in already parsed JSON, including duplicate keys hidden by JSON.parse. */
91
+ export function hasExactJsonPropertyCount(source: string, expected: number): boolean {
92
+ let count = 0;
93
+ for (const token of source.matchAll(/"(?:[^"\\]|\\[\s\S])*"/g)) {
94
+ if (/^\s*:/.test(source.slice(token.index + token[0].length))) count++;
95
+ }
96
+ return count === expected;
97
+ }
98
+
90
99
  export function pages<T extends TSchema>(schema: T) {
91
100
  return Type.Array(schema, { minItems: 1 });
92
101
  }
@@ -38,8 +38,12 @@ export function parsePrRef(value: string): PrRef {
38
38
  return { owner: owner.toLowerCase(), repo: repo.toLowerCase(), number };
39
39
  }
40
40
 
41
+ function checkedPrRef(ref: PrRef): PrRef {
42
+ return parsePrRef(`${ref.owner}/${ref.repo}#${ref.number}`);
43
+ }
44
+
41
45
  export function prKey(ref: PrRef): string {
42
- const parsed = parsePrRef(`${ref.owner}/${ref.repo}#${ref.number}`);
46
+ const parsed = checkedPrRef(ref);
43
47
  return `${parsed.owner}/${parsed.repo}#${parsed.number}`;
44
48
  }
45
49
 
@@ -85,7 +89,7 @@ function checkAttempt(run: Static<typeof checkPageSchema>["check_runs"][number])
85
89
  export async function readPrSnapshot(
86
90
  ref: PrRef, options: { readonly previousHead?: string; readonly signal: AbortSignal },
87
91
  ): Promise<PrSnapshot> {
88
- const parsed = parsePrRef(prKey(ref));
92
+ const parsed = checkedPrRef(ref);
89
93
  const root = `repos/${parsed.owner}/${parsed.repo}`;
90
94
  const endpoint = `${root}/pulls/${parsed.number}`;
91
95
  const { signal } = options;
@@ -1,7 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { Type, type Static } from "@sinclair/typebox/type";
3
3
  import type { StorePort } from "../contracts";
4
- import { PrReadError, parseWire, sha40 as sha } from "./pr-github-schema";
4
+ import { hasExactJsonPropertyCount, PrReadError, parseWire, sha40 as sha } from "./pr-github-schema";
5
5
  import { inspectIntakeComment, publishIntakeComment } from "./pr-intake-comment";
6
6
  import { applyIntakeFix, parseIntakeFix, reconcileIntakeFix } from "./pr-intake-fix";
7
7
  import { inspectIntakeMerge, mergeIntakePull } from "./pr-intake-github";
@@ -98,12 +98,16 @@ function unresolved(receipt: Receipt | undefined): receipt is Extract<Receipt, {
98
98
  return receipt?.state === "pending" || receipt?.state === "unknown";
99
99
  }
100
100
 
101
+ export function hasUnresolvedIntakeWrites(state: Pick<Ledger, "comments" | "fix" | "merge">): boolean {
102
+ return state.comments.some(unresolved) || unresolved(state.fix) || unresolved(state.merge);
103
+ }
104
+
101
105
  export function prIntakeManualHold(
102
106
  store: Pick<StorePort, "getMeta">, scope: Scope, action: "pr-review" | "pr-fix" | "pr-merge", head?: string,
103
107
  ): string | null {
104
108
  const state = readPrIntakeAutomation(store, scope);
105
109
  if (!state) return null;
106
- if (state.comments.some(unresolved) || unresolved(state.fix) || unresolved(state.merge))
110
+ if (hasUnresolvedIntakeWrites(state))
107
111
  return "An automatic GitHub write is unresolved for this PR. Reconcile it read-only before any new review or write.";
108
112
  if (state.merge?.state === "confirmed") return `GitHub already confirmed merge ${state.merge.id}.`;
109
113
  if (state.fix?.state === "confirmed" && state.fix.head === head)
@@ -126,9 +130,7 @@ function parseVerdict(answer: string) {
126
130
  const summary = snippets.reduce((text, snippet) => snippet ? text.replaceAll(snippet, "[source omitted]") : text, value.summary);
127
131
  return { verdict: "fix" as const, summary, proposal };
128
132
  }
129
- const keys = [...answer.matchAll(/"(?:[^"\\]|\\[\s\S])*"/g)]
130
- .filter(token => /^\s*:/.test(answer.slice(token.index + token[0].length)));
131
- return keys.length === 2 && Object.keys(value).length === 2 ? { ...value, verdict: value.verdict } : null;
133
+ return hasExactJsonPropertyCount(answer, 2) && Object.keys(value).length === 2 ? { ...value, verdict: value.verdict } : null;
132
134
  } catch (error) {
133
135
  if (error instanceof PrReadError) return null;
134
136
  throw error;
@@ -256,14 +258,15 @@ export async function advancePrIntakeAutomation(r: ReviewRound, d: PrIntakeAutom
256
258
  case "confirmed":
257
259
  if (kind === "fix" && !attempted) throw new PrIntakeAutomationError("Fix confirmation lacks its durable send fence.");
258
260
  saveEffect(kind, { ...entry, state: "confirmed", id: result.id });
259
- return { ...result, attempted };
261
+ break;
260
262
  case "unknown":
261
263
  saveEffect(kind, { ...entry, state: "unknown" });
262
- return { ...result, attempted };
264
+ break;
263
265
  case "blocked":
264
266
  if (attempted) saveEffect(kind, { ...entry, state: "refused", reason: result.reason });
265
- return { ...result, attempted };
267
+ break;
266
268
  }
269
+ return { ...result, attempted };
267
270
  };
268
271
  try {
269
272
  if (!savedComment) {
@@ -1,6 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { Type, type Static } from "@sinclair/typebox/type";
3
- import { parseWire, PrReadError, sha40 as oid } from "./pr-github-schema";
3
+ import { hasExactJsonPropertyCount, parseWire, PrReadError, sha40 as oid } from "./pr-github-schema";
4
4
  import { openIntakeGitHubSession, queryIntakeGitHub, type IntakeRepositoryIdentity } from "./pr-intake-github";
5
5
  import {
6
6
  intakeEvidenceDeadlineMs, IntakeMaterialError, readIntakeDiff, readIntakePullIdentity, serializeIntakeDiff,
@@ -87,10 +87,7 @@ export function parseIntakeFix(text: string): IntakeFixProposal | null {
87
87
  if (Buffer.byteLength(text) > 64 * 1024) return null;
88
88
  try {
89
89
  const { path, old, replacement, summary } = parseWire(verdict, text);
90
- // JSON.parse alone silently accepts an object that states two different verdicts.
91
- const keys = [...text.matchAll(/"(?:[^"\\]|\\[\s\S])*"/g)]
92
- .filter(token => /^\s*:/.test(text.slice(token.index + token[0].length)));
93
- if (keys.length !== Object.keys(verdict.properties).length) return null;
90
+ if (!hasExactJsonPropertyCount(text, Object.keys(verdict.properties).length)) return null;
94
91
  const proposal = { path, old, replacement };
95
92
  return summary.trim() && safeProposal(proposal) ? proposal : null;
96
93
  } catch (error) {
@@ -1,15 +1,15 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { physicalRoute, routeKey, type Inbound, type InputRecord, type Lane, type Route, type StorePort } from "../contracts";
3
3
  import { compareMessageIds } from "../routing/message-order";
4
- import type { CronJobs } from "../cron/cron-jobs";
4
+ import type { CronJobs, CronPrJob } from "../cron/cron-jobs";
5
5
  import type { CronPrCandidate, CronPrIntake } from "../cron/cron-pr-intake";
6
- import type { CronPrJob } from "../cron/cron-jobs";
7
6
  import { hasIntakeReplyRoute, intakeThreadKey, intakeStatusKey, intakeWorkId, intakeWorkPrefix } from "./pr-intake-work";
7
+ import { hasExactJsonPropertyCount } from "./pr-github-schema";
8
8
  import { inspectIntakeMerge, mergeIntakePull } from "./pr-intake-github";
9
9
  import { applyIntakeFix, intakeFixDigest, parseIntakeFix, reconcileIntakeFix } from "./pr-intake-fix";
10
10
  import { readIntakeMaterial, readIntakeMaterialTarget } from "./pr-intake-material";
11
11
  import { inspectIntakeComment, publishIntakeComment } from "./pr-intake-comment";
12
- import { advancePrIntakeAutomation, prIntakeManualHold, readPrIntakeAutomation } from "./pr-intake-automation";
12
+ import { advancePrIntakeAutomation, hasUnresolvedIntakeWrites, prIntakeManualHold, readPrIntakeAutomation } from "./pr-intake-automation";
13
13
  import type { PrIntakeMode } from "./pr-intake-mode";
14
14
 
15
15
  export class PrControlError extends Error {}
@@ -51,7 +51,7 @@ function approved(text: string): boolean {
51
51
  try {
52
52
  const result: unknown = JSON.parse(text);
53
53
  return typeof result === "object" && result !== null && Object.keys(result).length === 2
54
- && [...text.matchAll(/"(?:[^"\\]|\\[\s\S])*"/g)].filter(token => /^\s*:/.test(text.slice(token.index + token[0].length))).length === 2
54
+ && hasExactJsonPropertyCount(text, 2)
55
55
  && "verdict" in result && result.verdict === "approve" && "summary" in result
56
56
  && typeof result.summary === "string" && result.summary.trim().length > 0;
57
57
  } catch { return false; }
@@ -68,7 +68,7 @@ export class PrReviews {
68
68
 
69
69
  needsReconciliation(scope: Pick<ReviewRound, "repositoryId" | "number">): boolean {
70
70
  const state = readPrIntakeAutomation(this.store, scope);
71
- return !!state && [...state.comments, state.fix, state.merge].some(entry => entry?.state === "unknown" || entry?.state === "pending");
71
+ return state !== null && hasUnresolvedIntakeWrites(state);
72
72
  }
73
73
 
74
74
  laneRound(laneId: string): ReviewRound | null {
@@ -209,7 +209,7 @@ export class PrReviews {
209
209
  // after the answer has been sent. It is not a later confirmation.
210
210
  const event = command.messageId ?? command.interactionId;
211
211
  if (!output?.remoteId || !event || compareMessageIds("discord", event, output.remoteId) !== 1) return null;
212
- return digest(JSON.stringify([r.inputId, r.epoch, input?.requestId, input?.generation, output?.remoteId, answer]));
212
+ return digest(JSON.stringify([r.inputId, r.epoch, input?.requestId, input?.generation, output.remoteId, answer]));
213
213
  }
214
214
 
215
215
  private next(r: ReviewRound): string {
@@ -314,7 +314,7 @@ export class PrReviews {
314
314
  return "이전 GitHub 변경을 확인하지 못했습니다. GitHub PR과 커밋 이력을 직접 대조하세요. 이 등록에서는 모호한 쓰기를 다시 보내지 않습니다.";
315
315
  }
316
316
  if (effect?.state === "confirmed") {
317
- if (action === "pr-status" || action !== "pr-review" || effect.action === "pr-merge" || head === previous.head)
317
+ if (action !== "pr-review" || effect.action === "pr-merge" || head === previous.head)
318
318
  return `GitHub 확인: ${effect.action} ${effect.sha}. ${effect.action === "pr-fix" ? `이 스레드에서 /cron pr-review ${jobId} ${number} ${effect.sha} 로 새 HEAD를 다시 검토하세요.` : "종료되었습니다."}`;
319
319
  }
320
320
  if (action === "pr-status") {
@@ -204,7 +204,7 @@ function* excerptWindows(text: string): Iterable<string> {
204
204
  }
205
205
  }
206
206
 
207
- function visibleLine(text: string, limit: number): string {
207
+ function visibleLine(text: string, limit?: number): string {
208
208
  return ownerRoutingProse(text).slice(0, limit).replace(/[\s\p{Cc}\p{Cf}]+/gu, " ").trim();
209
209
  }
210
210
 
@@ -235,7 +235,7 @@ export function pastTopicQuery(text: string): string | null {
235
235
 
236
236
  function routingRequest(text: string) {
237
237
  if (text.length > MAX_QUERY) return null;
238
- const subject = ownerRoutingProse(text).replace(/[\s\p{Cc}\p{Cf}]+/gu, " ").trim();
238
+ const subject = visibleLine(text);
239
239
  // Past-topic aliases treat "fix" as a bug descriptor. In ordinary text an
240
240
  // action alone should not make one otherwise ambiguous term a direct match.
241
241
  const terms = new Set(wordTokens(subject.replace(/\b(?:fix(?:es|ed|ing)?|debug(?:s|ged|ging)?)\b/giu, " "))