omp-superagent 0.1.7 → 0.1.9

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 (122) hide show
  1. package/DESIGN.md +27 -16
  2. package/README.ko.md +40 -19
  3. package/README.md +43 -18
  4. package/THIRD_PARTY_NOTICES.md +11 -11
  5. package/config.example.json +2 -1
  6. package/docs/OPERATIONS.md +285 -85
  7. package/docs/design/execution.md +133 -24
  8. package/docs/design/messaging.md +235 -50
  9. package/docs/discord-voice.md +8 -4
  10. package/docs/releases/0.1.8.md +21 -0
  11. package/docs/releases/0.1.9.md +18 -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/notices/darwin-arm64/Cargo-LICENSES.txt +2 -0
  17. package/host-owner/bin/notices/darwin-arm64/Cargo-SOURCES.txt +2 -0
  18. package/host-owner/bin/notices/darwin-arm64/crates/bitflags-2.13.2/LICENSE-APACHE +201 -0
  19. package/host-owner/bin/notices/darwin-arm64/crates/bitflags-2.13.2/LICENSE-MIT +25 -0
  20. package/host-owner/bin/notices/darwin-arm64/crates/rustix-1.1.6/COPYRIGHT +29 -0
  21. package/host-owner/bin/notices/darwin-arm64/crates/rustix-1.1.6/LICENSE-APACHE +201 -0
  22. package/host-owner/bin/notices/darwin-arm64/crates/rustix-1.1.6/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  23. package/host-owner/bin/notices/darwin-arm64/crates/rustix-1.1.6/LICENSE-MIT +23 -0
  24. package/host-owner/bin/notices/darwin-x64/Cargo-LICENSES.txt +2 -0
  25. package/host-owner/bin/notices/darwin-x64/Cargo-SOURCES.txt +2 -0
  26. package/host-owner/bin/notices/darwin-x64/crates/bitflags-2.13.2/LICENSE-APACHE +201 -0
  27. package/host-owner/bin/notices/darwin-x64/crates/bitflags-2.13.2/LICENSE-MIT +25 -0
  28. package/host-owner/bin/notices/darwin-x64/crates/rustix-1.1.6/COPYRIGHT +29 -0
  29. package/host-owner/bin/notices/darwin-x64/crates/rustix-1.1.6/LICENSE-APACHE +201 -0
  30. package/host-owner/bin/notices/darwin-x64/crates/rustix-1.1.6/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  31. package/host-owner/bin/notices/darwin-x64/crates/rustix-1.1.6/LICENSE-MIT +23 -0
  32. package/host-owner/bin/notices/linux-arm64/Cargo-LICENSES.txt +3 -0
  33. package/host-owner/bin/notices/linux-arm64/Cargo-SOURCES.txt +3 -0
  34. package/host-owner/bin/notices/linux-arm64/crates/bitflags-2.13.2/LICENSE-APACHE +201 -0
  35. package/host-owner/bin/notices/linux-arm64/crates/bitflags-2.13.2/LICENSE-MIT +25 -0
  36. package/host-owner/bin/notices/linux-arm64/crates/linux-raw-sys-0.12.1/COPYRIGHT +29 -0
  37. package/host-owner/bin/notices/linux-arm64/crates/linux-raw-sys-0.12.1/LICENSE-APACHE +201 -0
  38. package/host-owner/bin/notices/linux-arm64/crates/linux-raw-sys-0.12.1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  39. package/host-owner/bin/notices/linux-arm64/crates/linux-raw-sys-0.12.1/LICENSE-MIT +23 -0
  40. package/host-owner/bin/notices/linux-arm64/crates/rustix-1.1.6/COPYRIGHT +29 -0
  41. package/host-owner/bin/notices/linux-arm64/crates/rustix-1.1.6/LICENSE-APACHE +201 -0
  42. package/host-owner/bin/notices/linux-arm64/crates/rustix-1.1.6/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  43. package/host-owner/bin/notices/linux-arm64/crates/rustix-1.1.6/LICENSE-MIT +23 -0
  44. package/host-owner/bin/notices/linux-x64/Cargo-LICENSES.txt +3 -0
  45. package/host-owner/bin/notices/linux-x64/Cargo-SOURCES.txt +3 -0
  46. package/host-owner/bin/notices/linux-x64/crates/bitflags-2.13.2/LICENSE-APACHE +201 -0
  47. package/host-owner/bin/notices/linux-x64/crates/bitflags-2.13.2/LICENSE-MIT +25 -0
  48. package/host-owner/bin/notices/linux-x64/crates/linux-raw-sys-0.12.1/COPYRIGHT +29 -0
  49. package/host-owner/bin/notices/linux-x64/crates/linux-raw-sys-0.12.1/LICENSE-APACHE +201 -0
  50. package/host-owner/bin/notices/linux-x64/crates/linux-raw-sys-0.12.1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  51. package/host-owner/bin/notices/linux-x64/crates/linux-raw-sys-0.12.1/LICENSE-MIT +23 -0
  52. package/host-owner/bin/notices/linux-x64/crates/rustix-1.1.6/COPYRIGHT +29 -0
  53. package/host-owner/bin/notices/linux-x64/crates/rustix-1.1.6/LICENSE-APACHE +201 -0
  54. package/host-owner/bin/notices/linux-x64/crates/rustix-1.1.6/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  55. package/host-owner/bin/notices/linux-x64/crates/rustix-1.1.6/LICENSE-MIT +23 -0
  56. package/host-owner/bin/omp-host-owner-darwin-arm64 +0 -0
  57. package/host-owner/bin/omp-host-owner-darwin-x64 +0 -0
  58. package/host-owner/bin/omp-host-owner-linux-arm64 +0 -0
  59. package/host-owner/bin/omp-host-owner-linux-x64 +0 -0
  60. package/package.json +17 -15
  61. package/skills/head/SKILL.md +3 -11
  62. package/skills/head/references/routing.md +23 -17
  63. package/skills/head/references/supervision.md +13 -1
  64. package/skills/lane/references/workflow.md +8 -8
  65. package/src/cli.ts +6 -3
  66. package/src/config.ts +5 -0
  67. package/src/contracts.ts +95 -10
  68. package/src/cron-jobs.ts +443 -19
  69. package/src/cron-pr-intake.ts +257 -0
  70. package/src/discord-command-registration.ts +34 -186
  71. package/src/extension.ts +31 -3
  72. package/src/gateway-client.ts +11 -59
  73. package/src/gateway-protocol.ts +35 -1
  74. package/src/head-quota.ts +80 -0
  75. package/src/head-recovery.ts +249 -1
  76. package/src/host-extension.ts +194 -5
  77. package/src/host-protocol.ts +16 -9
  78. package/src/host-sdk-helper.ts +105 -10
  79. package/src/host.ts +111 -29
  80. package/src/installed-omp.ts +116 -4
  81. package/src/lane-models.ts +8 -0
  82. package/src/managed-ulw-probe.ts +22 -20
  83. package/src/managed-ulw.ts +137 -24
  84. package/src/messenger-command-catalog.json +6 -3
  85. package/src/messenger-commands.ts +9 -2
  86. package/src/native-presets.ts +32 -5
  87. package/src/omp-usage.ts +254 -36
  88. package/src/operator.ts +77 -0
  89. package/src/pr-github-schema.ts +2 -0
  90. package/src/pr-github.ts +4 -2
  91. package/src/pr-intake-automation.ts +315 -0
  92. package/src/pr-intake-comment.ts +225 -0
  93. package/src/pr-intake-fix.ts +232 -0
  94. package/src/pr-intake-github.ts +479 -0
  95. package/src/pr-intake-material.ts +229 -0
  96. package/src/pr-intake-mode.ts +59 -0
  97. package/src/pr-intake-review.ts +397 -0
  98. package/src/pr-intake-tree.ts +68 -0
  99. package/src/pr-intake-work.ts +29 -0
  100. package/src/pr-review-models.ts +28 -0
  101. package/src/result-attachment.ts +60 -79
  102. package/src/runtime.ts +2968 -449
  103. package/src/setup-profiles.ts +26 -65
  104. package/src/slack-command-registration.ts +48 -197
  105. package/src/store.ts +507 -87
  106. package/src/superkit-skills.ts +22 -0
  107. package/src/telegram-command-languages.json +17 -0
  108. package/src/telegram-command-registration.ts +32 -134
  109. package/src/topic-history.ts +30 -17
  110. package/src/worker-bridge.ts +21 -0
  111. package/src/worker-enrollment.ts +2 -1
  112. package/src/worker-host.ts +0 -24
  113. package/src/worker-serve-prepare.ts +19 -0
  114. package/src/worker-service.ts +51 -47
  115. package/scripts/ci.ts +0 -44
  116. package/scripts/release.ts +0 -112
  117. package/scripts/test-omp.sh +0 -43
  118. package/src/discord-commands.ts +0 -29
  119. package/src/discord-markdown.ts +0 -172
  120. package/src/slack-commands.ts +0 -18
  121. package/src/telegram-signal.ts +0 -14
  122. package/src/worker-stdio.ts +0 -61
@@ -1,5 +1,5 @@
1
- import { constants, fstatSync, lstatSync, openSync, closeSync, readSync, realpathSync } from "node:fs";
2
- import { basename, isAbsolute, relative, resolve, sep } from "node:path";
1
+ import { isAbsolute } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
3
  import type { ExtensionAPI } from "@oh-my-pi/pi-coding-agent";
4
4
  import { Type } from "@sinclair/typebox";
5
5
  import type { Inbound } from "./contracts";
@@ -7,11 +7,17 @@ import type { Inbound } from "./contracts";
7
7
  const MAX_RESULT_ATTACHMENT_BYTES = 8 * 1024 * 1024;
8
8
  export const RESULT_ATTACH_TOOL = "result_attach";
9
9
 
10
- export interface ResultAttachmentPayload {
10
+ export interface ResultAttachmentSnapshot {
11
11
  readonly name: string;
12
- readonly data: string;
12
+ readonly size: number;
13
+ readonly sha256: string;
14
+ readonly snapshotId: string;
15
+ readonly fileIdentity: string;
13
16
  }
14
17
 
18
+ // Read-only compatibility with output rows persisted before the native spool.
19
+ export type ResultAttachmentPayload = ResultAttachmentSnapshot | { readonly name: string; readonly data: string };
20
+
15
21
  interface NativeSession {
16
22
  readonly sessionId: string;
17
23
  readonly sessionFile: string;
@@ -59,89 +65,64 @@ export function isOriginalAttachmentMessage({ id, messageId, route }: Inbound):
59
65
  : `${route.platform}:${route.accountId}:${route.channelId}:${messageId}:original`);
60
66
  }
61
67
 
62
- function inside(root: string, file: string): boolean {
63
- const delta = relative(root, file);
64
- return delta === "" || delta !== ".." && !delta.startsWith(`..${sep}`) && !isAbsolute(delta);
65
- }
68
+ const binary = fileURLToPath(new URL(`../gateway/bin/omp-gateway-${process.platform}-${process.arch}`, import.meta.url));
66
69
 
67
- /** Store the bytes, not a mutable file path to be opened later by the Gateway. */
68
- export function stageResultAttachment(path: string, scope: {
69
- readonly cwd: string;
70
- readonly privatePaths: readonly string[];
71
- }): ResultAttachmentPayload {
70
+ type StageCommand =
71
+ | { readonly action: "stage"; readonly stateDir: string; readonly cwd: string; readonly path: string; readonly privatePaths: readonly string[] }
72
+ | { readonly action: "discard"; readonly stateDir: string; readonly snapshotId: string }
73
+ | { readonly action: "prune"; readonly stateDir: string };
74
+
75
+ function runStage(command: StageCommand): unknown {
72
76
  try {
73
- if (!validPath(path)) throw new ResultAttachmentError("Use a literal, non-hidden workspace-relative file path");
74
- const root = resolve(scope.cwd);
75
- if (realpathSync(root) !== root) throw new ResultAttachmentError("The canonical workspace root has changed");
76
- const originalRoot = lstatSync(root, { bigint: true });
77
- const file = resolve(root, path);
78
- const name = basename(file);
79
- if (Buffer.byteLength(name) > 180 || !/^[\p{L}\p{N}\p{M}_. -]+$/u.test(name))
80
- throw new ResultAttachmentError("The result attachment has an unsupported filename");
81
- const privateEntries = scope.privatePaths.map(privatePath => {
82
- let canonical = resolve(privatePath);
83
- try {
84
- canonical = realpathSync(canonical);
85
- return { canonical, stat: lstatSync(canonical, { bigint: true }) };
86
- } catch (error) {
87
- if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;
88
- return { canonical };
89
- }
77
+ const child = Bun.spawnSync([binary, "__stage-result-attachment"], {
78
+ env: {}, stdin: Buffer.from(JSON.stringify(command)), stdout: "pipe", stderr: "ignore", timeout: 5_000,
90
79
  });
91
- const checkPrivate = () => {
92
- if (realpathSync(root) !== root) throw new ResultAttachmentError("The canonical workspace root has changed");
93
- const rootStat = lstatSync(root, { bigint: true });
94
- if (rootStat.dev !== originalRoot.dev || rootStat.ino !== originalRoot.ino)
95
- throw new ResultAttachmentError("The canonical workspace root has changed");
96
- if (privateEntries.some(entry => inside(entry.canonical, file)))
97
- throw new ResultAttachmentError("Private state cannot be sent as a result attachment");
98
- // Also compare filesystem identities (e.g. case-insensitive volumes).
99
- let current = root;
100
- for (const part of ["", ...path.split("/")]) {
101
- current = resolve(current, part);
102
- const stat = lstatSync(current, { bigint: true });
103
- if (stat.isSymbolicLink()) throw new ResultAttachmentError("Result attachment paths cannot follow links");
104
- if (privateEntries.some(entry => entry.stat?.dev === stat.dev && entry.stat.ino === stat.ino))
105
- throw new ResultAttachmentError("Private state cannot be sent as a result attachment");
106
- }
107
- };
108
- checkPrivate();
109
- if (realpathSync(file) !== file) throw new ResultAttachmentError("Result attachment paths cannot follow links");
110
- // lstat and the identity checks pin the observed directory entry to the
111
- // descriptor. Nonblocking open cannot hang if it is replaced with a FIFO.
112
- const initial = lstatSync(file, { bigint: true });
113
- if (!initial.isFile() || initial.nlink !== 1n)
114
- throw new ResultAttachmentError("A result attachment must be a regular file without hard links");
115
- const fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
116
- try {
117
- const same = (stat: typeof initial) => stat.isFile() && stat.nlink === 1n
118
- && stat.dev === initial.dev && stat.ino === initial.ino && stat.size === initial.size
119
- && stat.mtimeNs === initial.mtimeNs && stat.ctimeNs === initial.ctimeNs;
120
- if (!same(fstatSync(fd, { bigint: true }))) throw new ResultAttachmentError("The attachment changed before staging");
121
- if (initial.size < 1n || initial.size > MAX_RESULT_ATTACHMENT_BYTES)
122
- throw new ResultAttachmentError("Result attachments must be nonempty and at most 8 MiB");
123
- const bytes = Buffer.allocUnsafe(Number(initial.size));
124
- let offset = 0;
125
- while (offset < bytes.length) {
126
- const count = readSync(fd, bytes, offset, bytes.length - offset, offset);
127
- if (!count) break;
128
- offset += count;
129
- }
130
- if (offset !== bytes.length || !same(fstatSync(fd, { bigint: true }))
131
- || realpathSync(file) !== file || !same(lstatSync(file, { bigint: true }))) {
132
- throw new ResultAttachmentError("The attachment changed during staging");
133
- }
134
- checkPrivate();
135
- return { name, data: bytes.toString("base64") };
136
- } finally {
137
- closeSync(fd);
138
- }
80
+ if (child.exitCode !== 0 || child.stdout.length > 4_096)
81
+ throw new ResultAttachmentError("The native result attachment helper did not complete");
82
+ const response = asRecord(JSON.parse(child.stdout.toString("utf8")));
83
+ if (response?.ok === true) return response.value;
84
+ if (response?.ok === false && typeof response.error === "string") throw new ResultAttachmentError(response.error);
85
+ throw new ResultAttachmentError("The native result attachment helper returned no receipt");
139
86
  } catch (error) {
140
87
  if (error instanceof ResultAttachmentError) throw error;
141
- throw new ResultAttachmentError("The requested result attachment could not be read safely", { cause: error });
88
+ // Do not attach an exception that could include the command's private paths.
89
+ throw new ResultAttachmentError("The native result attachment helper is unavailable");
142
90
  }
143
91
  }
144
92
 
93
+ export function isResultAttachmentSnapshot(value: unknown): value is ResultAttachmentSnapshot {
94
+ const snapshot = asRecord(value);
95
+ return snapshot !== null && Object.keys(snapshot).length === 5 &&
96
+ typeof snapshot.name === "string" && validPath(snapshot.name) && Buffer.byteLength(snapshot.name) <= 180 &&
97
+ /^[\p{L}\p{N}\p{M}_. -]+$/u.test(snapshot.name) &&
98
+ typeof snapshot.size === "number" && Number.isSafeInteger(snapshot.size) &&
99
+ snapshot.size > 0 && snapshot.size <= MAX_RESULT_ATTACHMENT_BYTES &&
100
+ typeof snapshot.sha256 === "string" && /^[a-f0-9]{64}$/.test(snapshot.sha256) &&
101
+ typeof snapshot.snapshotId === "string" && /^[a-f0-9]{32}$/.test(snapshot.snapshotId) &&
102
+ typeof snapshot.fileIdentity === "string" && /^\d+:\d+$/.test(snapshot.fileIdentity);
103
+ }
104
+
105
+ /** The helper publishes a private immutable snapshot before queue admission. */
106
+ export function stageResultAttachment(path: string, scope: {
107
+ readonly stateDir: string;
108
+ readonly cwd: string;
109
+ readonly privatePaths: readonly string[];
110
+ }): ResultAttachmentSnapshot {
111
+ if (!validPath(path)) throw new ResultAttachmentError("Use a literal, non-hidden workspace-relative file path");
112
+ const receipt = runStage({ action: "stage", ...scope, path });
113
+ if (!isResultAttachmentSnapshot(receipt) || receipt.name !== path.split("/").at(-1))
114
+ throw new ResultAttachmentError("The native result attachment receipt does not match the request");
115
+ return receipt;
116
+ }
117
+
118
+ export function discardResultAttachment(stateDir: string, snapshotId: string): void {
119
+ runStage({ action: "discard", stateDir, snapshotId });
120
+ }
121
+
122
+ export function pruneResultAttachments(stateDir: string): void {
123
+ runStage({ action: "prune", stateDir });
124
+ }
125
+
145
126
  export function registerResultAttach(pi: ExtensionAPI, submit?: (intent: ResultAttachmentIntent) => string): void {
146
127
  pi.on("tool_call", (event, ctx) => {
147
128
  if (event.toolName === RESULT_ATTACH_TOOL && ctx.agent.kind !== "main")