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.
- package/DESIGN.md +36 -20
- package/README.ko.md +140 -33
- package/README.md +165 -41
- package/THIRD_PARTY_NOTICES.md +9 -7
- package/config.example.json +3 -1
- package/docs/OPERATIONS.md +395 -157
- package/docs/design/execution.md +156 -22
- package/docs/design/messaging.md +258 -52
- package/docs/discord-voice.md +8 -4
- package/docs/releases/0.1.7.md +25 -0
- package/docs/releases/0.1.8.md +21 -0
- package/gateway/bin/omp-gateway-darwin-arm64 +0 -0
- package/gateway/bin/omp-gateway-darwin-x64 +0 -0
- package/gateway/bin/omp-gateway-linux-arm64 +0 -0
- package/gateway/bin/omp-gateway-linux-x64 +0 -0
- package/host-owner/bin/omp-host-owner-darwin-arm64 +0 -0
- package/host-owner/bin/omp-host-owner-darwin-x64 +0 -0
- package/host-owner/bin/omp-host-owner-linux-arm64 +0 -0
- package/host-owner/bin/omp-host-owner-linux-x64 +0 -0
- package/package.json +9 -9
- package/scripts/ci.ts +4 -4
- package/scripts/test-omp.sh +2 -1
- package/skills/head/SKILL.md +26 -5
- package/skills/head/references/routing.md +68 -33
- package/skills/head/references/supervision.md +20 -4
- package/skills/lane/references/workflow.md +16 -7
- package/src/board.ts +5 -3
- package/src/cli.ts +161 -19
- package/src/config.ts +21 -1
- package/src/contracts.ts +63 -8
- package/src/cron-jobs.ts +443 -19
- package/src/cron-pr-intake.ts +257 -0
- package/src/discord-markdown.ts +350 -123
- package/src/extension.ts +78 -13
- package/src/gateway-client.ts +8 -2
- package/src/head-quota.ts +80 -0
- package/src/head-recovery.ts +40 -1
- package/src/host-extension.ts +122 -4
- package/src/host-inventory-manifest.ts +2 -2
- package/src/host-protocol.ts +11 -0
- package/src/host-sdk-helper.ts +121 -12
- package/src/host.ts +175 -57
- package/src/installed-omp.ts +116 -4
- package/src/lane-rows.ts +44 -4
- package/src/lane-watch.ts +339 -0
- package/src/managed-memory-helper.ts +13 -10
- package/src/managed-memory.ts +62 -27
- package/src/managed-ulw-probe.ts +75 -20
- package/src/managed-ulw.ts +174 -21
- package/src/messenger-command-catalog.json +2 -2
- package/src/native-launch-profile.ts +4 -2
- package/src/native-presets.ts +32 -5
- package/src/native-sessions.ts +3 -1
- package/src/native-settings.ts +47 -9
- package/src/observation-request.ts +23 -0
- package/src/omp-usage.ts +254 -36
- package/src/pr-github-schema.ts +5 -1
- package/src/pr-github.ts +68 -19
- package/src/pr-intake-automation.ts +316 -0
- package/src/pr-intake-comment.ts +226 -0
- package/src/pr-intake-fix.ts +233 -0
- package/src/pr-intake-github.ts +480 -0
- package/src/pr-intake-material.ts +230 -0
- package/src/pr-intake-mode.ts +59 -0
- package/src/pr-intake-review.ts +397 -0
- package/src/pr-intake-tree.ts +69 -0
- package/src/pr-intake-work.ts +29 -0
- package/src/pr-watch.ts +91 -32
- package/src/runtime.ts +2702 -391
- package/src/setup-judge.ts +1 -1
- package/src/setup.ts +12 -16
- package/src/store.ts +429 -86
- package/src/topic-history.ts +243 -47
- package/src/worker-checkout.ts +106 -0
- package/src/worker-destination.ts +10 -0
- package/src/worker-doctor.ts +66 -0
- package/src/worker-enrollment.ts +165 -0
- package/src/worker-host.ts +180 -0
- package/src/worker-ledger.ts +188 -0
- package/src/worker-placement.ts +78 -0
- package/src/worker-profile.ts +274 -0
- package/src/worker-registration.ts +288 -0
- package/src/worker-repository.ts +233 -0
- package/src/worker-request.ts +74 -0
- package/src/worker-service.ts +230 -0
- package/src/worker-stdio.ts +61 -0
- package/src/worker-trust.ts +36 -0
- package/src/worker-wire.ts +204 -0
- package/src/workflow.ts +81 -32
- package/src/setup-memory.ts +0 -21
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
|
|
2
|
+
import { isAbsolute, join } from "node:path";
|
|
3
|
+
import { Type, type Static, type TSchema } from "@sinclair/typebox/type";
|
|
4
|
+
import { Value } from "@sinclair/typebox/value";
|
|
5
|
+
import type { Lane } from "./contracts";
|
|
6
|
+
import type { HostOptions } from "./host";
|
|
7
|
+
import { parseWorkerDestination } from "./worker-destination";
|
|
8
|
+
|
|
9
|
+
/** Only the enrollment CLI chooses destinations/keys. Lane prompts never supply SSH argv. */
|
|
10
|
+
export interface WorkerRepo { readonly id: string; readonly cwd: string }
|
|
11
|
+
export interface WorkerDescription {
|
|
12
|
+
readonly workerId: string; readonly platform: "linux" | "darwin"; readonly stateDir: string;
|
|
13
|
+
readonly repos: readonly WorkerRepo[]; readonly capacity: number; readonly active: number;
|
|
14
|
+
}
|
|
15
|
+
export interface WorkerRegistration {
|
|
16
|
+
readonly destination: string; readonly identityFile: string; readonly description: WorkerDescription;
|
|
17
|
+
readonly default?: boolean;
|
|
18
|
+
readonly defaultRepository?: { readonly root: string; readonly repoId: string };
|
|
19
|
+
}
|
|
20
|
+
export interface WorkerPolicy {
|
|
21
|
+
readonly workerId: string; readonly stateDir: string; readonly repos: readonly WorkerRepo[];
|
|
22
|
+
readonly capacity: number; readonly command: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface RemotePlacement {
|
|
25
|
+
readonly workerId: string; readonly repoId: string; readonly revision: string;
|
|
26
|
+
readonly subdir: string; readonly stateDir: string;
|
|
27
|
+
}
|
|
28
|
+
export interface WorkerSelector {
|
|
29
|
+
readonly target?: "local" | "remote"; readonly platform?: "linux" | "darwin"; readonly worker?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface WorkerLaneRef {
|
|
32
|
+
readonly laneId: string; readonly generation: number; readonly repoId: string;
|
|
33
|
+
readonly revision: string; readonly subdir: string;
|
|
34
|
+
}
|
|
35
|
+
export interface WorkerProbe {
|
|
36
|
+
readonly socket: boolean; readonly sessionFile: boolean; readonly pidAlive: boolean; readonly ownerAlive: boolean;
|
|
37
|
+
readonly uncertain: boolean; readonly pid: number | null; readonly sessionId: string | null;
|
|
38
|
+
/** Exact absent generation that the worker will no longer admit. */
|
|
39
|
+
readonly sealedGeneration?: number;
|
|
40
|
+
/** Exact generation whose persisted native exit the worker verified. */
|
|
41
|
+
readonly exitGeneration?: number;
|
|
42
|
+
}
|
|
43
|
+
export type WorkerLaunch = Pick<HostOptions, "model" | "modelPreset" | "subagentConcurrency">;
|
|
44
|
+
export const WORKER_HEADER_BYTES = 64 * 1024;
|
|
45
|
+
type Endpoint = Pick<WorkerRegistration, "destination" | "identityFile">;
|
|
46
|
+
|
|
47
|
+
const natural = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });
|
|
48
|
+
const positive = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });
|
|
49
|
+
const text = Type.String({ minLength: 1 });
|
|
50
|
+
const absolute = Type.String({ pattern: "^/[^\\u0000]*$" });
|
|
51
|
+
export const WorkerDescriptionSchema = Type.Object({
|
|
52
|
+
workerId: text, platform: Type.Union([Type.Literal("linux"), Type.Literal("darwin")]),
|
|
53
|
+
stateDir: absolute, repos: Type.Array(Type.Object({ id: text, cwd: absolute }), { minItems: 1 }),
|
|
54
|
+
capacity: positive, active: natural,
|
|
55
|
+
});
|
|
56
|
+
const probe = Type.Object({
|
|
57
|
+
socket: Type.Boolean(), sessionFile: Type.Boolean(), pidAlive: Type.Boolean(), ownerAlive: Type.Boolean(),
|
|
58
|
+
uncertain: Type.Boolean(), pid: Type.Union([positive, Type.Null()]), sessionId: Type.Union([text, Type.Null()]),
|
|
59
|
+
sealedGeneration: Type.Optional(positive), exitGeneration: Type.Optional(positive),
|
|
60
|
+
});
|
|
61
|
+
const opened = Type.Object({ pid: positive });
|
|
62
|
+
const attached = Type.Object({ pid: positive, sessionId: text, sessionFile: absolute });
|
|
63
|
+
const reply = Type.Union([
|
|
64
|
+
Type.Object({ ok: Type.Literal(true), value: Type.Unknown() }),
|
|
65
|
+
Type.Object({ ok: Type.Literal(false), error: Type.String() }),
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
function decode<S extends TSchema>(line: Buffer, schema: S): Static<S> {
|
|
69
|
+
const result: unknown = JSON.parse(line.toString("utf8"));
|
|
70
|
+
if (!Value.Check(reply, result)) throw new Error("Invalid worker response envelope");
|
|
71
|
+
if (!result.ok) throw new Error(`Worker refused operation: ${result.error}`);
|
|
72
|
+
if (!Value.Check(schema, result.value)) throw new Error("Invalid worker response");
|
|
73
|
+
return result.value;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function startSSH(endpoint: Endpoint) {
|
|
77
|
+
const destination = parseWorkerDestination(endpoint.destination);
|
|
78
|
+
if (!destination || !isAbsolute(endpoint.identityFile)) {
|
|
79
|
+
throw new Error("Invalid registered SSH endpoint");
|
|
80
|
+
}
|
|
81
|
+
// Never borrow a multiplexed connection authenticated with another key, or
|
|
82
|
+
// forward the operator's agent, ports or terminal into the worker account.
|
|
83
|
+
const child = spawn("ssh", ["-F", "/dev/null", "-T", "-o", "BatchMode=yes", "-o", "StrictHostKeyChecking=yes",
|
|
84
|
+
"-o", "ClearAllForwardings=yes", "-o", "ForwardAgent=no", "-o", "ForwardX11=no",
|
|
85
|
+
"-o", "ControlPath=none", "-o", "IdentitiesOnly=yes", "-o", "IdentityAgent=none",
|
|
86
|
+
"-o", "PreferredAuthentications=publickey", "-o", "ConnectTimeout=8",
|
|
87
|
+
...(destination.port ? ["-p", destination.port] : []),
|
|
88
|
+
"-i", endpoint.identityFile, "--", destination.login, "omp-sa-worker-v1"], { stdio: "pipe" });
|
|
89
|
+
// Drain diagnostics without collecting or relaying possibly sensitive peer output.
|
|
90
|
+
child.stderr.resume();
|
|
91
|
+
return child;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Stop exactly at the newline; an attach response and the native ready frame
|
|
95
|
+
* can share one SSH packet. Leave remaining bytes in the paused stdout stream. */
|
|
96
|
+
function readHeader(child: ChildProcessWithoutNullStreams): Promise<Buffer> {
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
const chunks: Buffer[] = [];
|
|
99
|
+
let length = 0;
|
|
100
|
+
const cleanup = () => {
|
|
101
|
+
child.stdout.off("readable", receive);
|
|
102
|
+
child.stdout.off("end", ended);
|
|
103
|
+
child.stdout.off("error", fail);
|
|
104
|
+
child.stdin.off("error", fail);
|
|
105
|
+
child.off("error", fail);
|
|
106
|
+
};
|
|
107
|
+
const fail = (error: Error) => { cleanup(); reject(error); };
|
|
108
|
+
const ended = () => fail(new Error("SSH disconnected before a worker receipt; do not redispatch an uncertain operation"));
|
|
109
|
+
const receive = () => {
|
|
110
|
+
let chunk: Buffer | null;
|
|
111
|
+
while ((chunk = child.stdout.read()) !== null) {
|
|
112
|
+
const end = chunk.indexOf(10);
|
|
113
|
+
length += end < 0 ? chunk.length : end;
|
|
114
|
+
if (length > WORKER_HEADER_BYTES) { fail(new Error("Worker response exceeds header limit")); return; }
|
|
115
|
+
chunks.push(end < 0 ? chunk : chunk.subarray(0, end));
|
|
116
|
+
if (end < 0) continue;
|
|
117
|
+
cleanup();
|
|
118
|
+
if (end + 1 < chunk.length) child.stdout.unshift(chunk.subarray(end + 1));
|
|
119
|
+
resolve(Buffer.concat(chunks, length));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
child.once("error", fail);
|
|
124
|
+
child.stdout.once("end", ended);
|
|
125
|
+
child.stdout.once("error", fail);
|
|
126
|
+
child.stdin.once("error", fail);
|
|
127
|
+
child.stdout.on("readable", receive);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function exchange<S extends TSchema>(endpoint: Endpoint, request: object, schema: S, attach: boolean) {
|
|
132
|
+
const payload = Buffer.from(`${JSON.stringify({ version: 1, ...request })}\n`);
|
|
133
|
+
if (payload.length > WORKER_HEADER_BYTES) throw new Error("Worker request exceeds header limit");
|
|
134
|
+
const { checkWorkerIdentity } = await import("./worker-registration");
|
|
135
|
+
checkWorkerIdentity(endpoint.identityFile);
|
|
136
|
+
const child = startSSH(endpoint);
|
|
137
|
+
const exited = new Promise<number | null>((resolve, reject) => {
|
|
138
|
+
child.once("error", reject);
|
|
139
|
+
child.once("close", resolve);
|
|
140
|
+
});
|
|
141
|
+
// On attach, the child can exit after this call returns. Its stdout closure
|
|
142
|
+
// then signals detach to the stock RPC client, never native Host death.
|
|
143
|
+
void exited.catch(() => {});
|
|
144
|
+
const timer = setTimeout(() => child.kill("SIGKILL"), 60_000);
|
|
145
|
+
try {
|
|
146
|
+
const response = readHeader(child);
|
|
147
|
+
if (attach) child.stdin.write(payload);
|
|
148
|
+
else child.stdin.end(payload);
|
|
149
|
+
const value = decode(await response, schema);
|
|
150
|
+
if (!attach) {
|
|
151
|
+
child.stdout.resume();
|
|
152
|
+
if (await exited !== 0) throw new Error("SSH exited unsuccessfully; worker operation outcome may be unknown");
|
|
153
|
+
}
|
|
154
|
+
return { value, child };
|
|
155
|
+
} catch (error) {
|
|
156
|
+
child.kill();
|
|
157
|
+
throw error;
|
|
158
|
+
} finally { clearTimeout(timer); }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export async function workerDescribe(endpoint: Endpoint, workspace?: Pick<WorkerLaneRef, "repoId" | "revision" | "subdir">): Promise<WorkerDescription> {
|
|
162
|
+
return (await exchange(endpoint, { op: "describe", workspace }, WorkerDescriptionSchema, false)).value;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function lookupWorker(stateDir: string, remote: RemotePlacement): Promise<WorkerRegistration> {
|
|
166
|
+
const { listWorkers } = await import("./worker-registration");
|
|
167
|
+
const matches = (await listWorkers(stateDir)).filter(reg => reg.description.workerId === remote.workerId);
|
|
168
|
+
const [reg] = matches;
|
|
169
|
+
if (matches.length !== 1 || !reg || reg.description.stateDir !== remote.stateDir
|
|
170
|
+
|| !reg.description.repos.some(repo => repo.id === remote.repoId)) {
|
|
171
|
+
throw new Error("Remote lane has no matching verified worker registration");
|
|
172
|
+
}
|
|
173
|
+
return reg;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function remoteLanePaths(remote: Pick<RemotePlacement, "stateDir">, laneId: string) {
|
|
177
|
+
if (!/^lane-[A-Za-z0-9_-]+$/.test(laneId) || !isAbsolute(remote.stateDir)) throw new Error("Invalid remote lane path");
|
|
178
|
+
return { sessionFile: join(remote.stateDir, "sessions", laneId, "session.jsonl"), socketPath: join(remote.stateDir, "run", `${laneId}.sock`) };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function workerRef(lane: Pick<Lane, "id" | "remote" | "generation">): WorkerLaneRef {
|
|
182
|
+
if (!lane.remote) throw new Error("Lane is not assigned to a worker");
|
|
183
|
+
const { repoId, revision, subdir } = lane.remote;
|
|
184
|
+
return { laneId: lane.id, generation: lane.generation, repoId, revision, subdir };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export async function workerProbe(reg: WorkerRegistration, ref: WorkerLaneRef, reconcile = false): Promise<WorkerProbe> {
|
|
188
|
+
return (await exchange(reg, { op: "probe", workerId: reg.description.workerId, ref, ...(reconcile && { reconcile: true }) },
|
|
189
|
+
probe, false)).value;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export async function workerOpen(reg: WorkerRegistration, ref: WorkerLaneRef, launch: WorkerLaunch) {
|
|
193
|
+
return (await exchange(reg, { op: "open", workerId: reg.description.workerId, ref, launch }, opened, false)).value;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export async function workerConnect(reg: WorkerRegistration, ref: WorkerLaneRef) {
|
|
197
|
+
const { HostConnection } = await import("./host");
|
|
198
|
+
const { value, child } = await exchange(reg, { op: "attach", workerId: reg.description.workerId, ref }, attached, true);
|
|
199
|
+
if (value.sessionFile !== remoteLanePaths(reg.description, ref.laneId).sessionFile) {
|
|
200
|
+
child.kill();
|
|
201
|
+
throw new Error("Worker attached to an unexpected session file");
|
|
202
|
+
}
|
|
203
|
+
return HostConnection.fromWorker(child.stdout, child.stdin, () => child.kill(), value);
|
|
204
|
+
}
|
package/src/workflow.ts
CHANGED
|
@@ -1,32 +1,41 @@
|
|
|
1
|
-
import { WORKFLOW_NAMES, type WorkflowActivation, type WorkflowChoice, type WorkflowName } from "./contracts";
|
|
1
|
+
import { WORKFLOW_NAMES, type InputRecord, type WorkflowActivation, type WorkflowChoice, type WorkflowName } from "./contracts";
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
//
|
|
3
|
+
// Public commands and leading delimiters match omp-superkit ulw.ts at c11a6e4.
|
|
4
|
+
// Skill paths and persisted native keys are deliberately not public selectors.
|
|
5
|
+
const legacyCommands = {
|
|
6
|
+
super: "ulw", "super-plan": "ulw-plan", "super-loop": "ulw-loop", "super-run": "ulw-execute",
|
|
7
|
+
"super-graph": "mass-ulw", "super-research": "ulw-research",
|
|
8
|
+
} as const satisfies Record<Exclude<WorkflowName, "jevify">, string>;
|
|
9
|
+
type LegacyWorkflowName = typeof legacyCommands[keyof typeof legacyCommands];
|
|
10
|
+
const canonical = new RegExp(String.raw`^(${Object.keys(legacyCommands).join("|")})\b(?![-_.]?[A-Za-z0-9])(?=[\s:.,!?]|$)`, "i");
|
|
5
11
|
const aliases: Array<[WorkflowName, RegExp]> = [
|
|
6
|
-
["
|
|
7
|
-
["
|
|
8
|
-
["
|
|
9
|
-
["
|
|
10
|
-
["
|
|
12
|
+
["super-research", /^(?:ulw|mass[\s-]*ulw|ulw[\s-]*mass|mulw|meth)[\s-]*research\b/i],
|
|
13
|
+
["super-graph", /^(?:mass[\s-]*ulw|ulw[\s-]*mass|mulw|meth)\b/i],
|
|
14
|
+
["super-plan", /^ulw[\s-]*plan\b/i],
|
|
15
|
+
["super-loop", /^ulw[\s-]*loop\b/i],
|
|
16
|
+
["super-run", /^ulw[\s-]*execute\b/i],
|
|
11
17
|
];
|
|
12
18
|
const identifierTail = /^(?:[-_][A-Za-z0-9]|\.[A-Za-z0-9]|[-_.]?[A-Za-z0-9]*[/\\])/;
|
|
19
|
+
const leadingUri = /^\s*\/?[a-z][a-z0-9+.-]*:\/\//i;
|
|
13
20
|
const nativeWords = /(?<![\p{L}\p{N}_./\\-])(?<!::)(?:ultrathink|orchestrate|workflowz|jevify)(?![\p{L}\p{N}_/\\-])(?!\.[\p{L}\p{N}_-])(?!\()/u;
|
|
14
21
|
const nativeWord: Partial<Record<WorkflowName, string>> = {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
22
|
+
"super-plan": "ultrathink", "super-loop": "orchestrate", "super-run": "orchestrate",
|
|
23
|
+
"super-graph": "workflowz", "super-research": "workflowz",
|
|
17
24
|
};
|
|
18
25
|
|
|
19
|
-
/**
|
|
20
|
-
function invocation(text: string): { name: WorkflowName; length: number } | null {
|
|
21
|
-
// Unlike
|
|
26
|
+
/** Parse the spelling of an invocation; only admission may choose it. */
|
|
27
|
+
function invocation(text: string): { name: WorkflowName; length: number; legacy?: true } | null {
|
|
28
|
+
// Unlike SUPER commands, native jevify is lowercase prose, never a slash command.
|
|
22
29
|
const native = /^\s*jevify(?=$|[\s:.,!?])/.exec(text);
|
|
23
30
|
if (native && !identifierTail.test(text.slice(native[0].length))) return { name: "jevify", length: native[0].length };
|
|
24
31
|
const prefix = /^\s*\/?/.exec(text)![0].length;
|
|
25
32
|
const leading = text.slice(prefix);
|
|
33
|
+
const primary = canonical.exec(leading);
|
|
34
|
+
if (primary) return { name: primary[0].toLowerCase() as WorkflowName, length: prefix + primary[0].length };
|
|
26
35
|
for (const [name, expression] of aliases) {
|
|
27
36
|
const match = expression.exec(leading);
|
|
28
37
|
if (match && /^(?:[\s:.,!?]|$)/.test(leading.slice(match[0].length))
|
|
29
|
-
&& !identifierTail.test(leading.slice(match[0].length))) return { name, length: prefix + match[0].length };
|
|
38
|
+
&& !identifierTail.test(leading.slice(match[0].length))) return { name, length: prefix + match[0].length, legacy: true };
|
|
30
39
|
}
|
|
31
40
|
const plain = /^(?:ultrawork|ulw)\b/i.exec(leading);
|
|
32
41
|
if (!plain) return null;
|
|
@@ -35,11 +44,22 @@ function invocation(text: string): { name: WorkflowName; length: number } | null
|
|
|
35
44
|
// Native ULW permits a suffix only for its named workflow family; unsupported
|
|
36
45
|
// identifiers and paths are data. Do not search past quotes or negations.
|
|
37
46
|
if (identifierTail.test(tail) && !/^[-_](?:loop|plan|research|execute|mass)(?![-_.]?[A-Za-z0-9])/i.test(tail)) return null;
|
|
38
|
-
return { name: "
|
|
47
|
+
return { name: "super", length: prefix + plain[0].length, legacy: true };
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
export function leadingWorkflow(text: string): WorkflowName | null {
|
|
42
|
-
|
|
51
|
+
const match = invocation(text);
|
|
52
|
+
// Upstream masks URLs before reading its SUPER/ULW selectors. Do not
|
|
53
|
+
// accidentally admit one just because a real command may use a colon.
|
|
54
|
+
return match && (match.name === "jevify" || !leadingUri.test(text)) ? match.name : null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Read old coordination identities without making aliases valid manager inputs. */
|
|
58
|
+
export function storedWorkflowName(name: string): WorkflowName {
|
|
59
|
+
for (const canonical of WORKFLOW_NAMES) {
|
|
60
|
+
if (canonical === name || canonical !== "jevify" && legacyCommands[canonical] === name) return canonical;
|
|
61
|
+
}
|
|
62
|
+
throw new Error("Unknown stored workflow identity");
|
|
43
63
|
}
|
|
44
64
|
|
|
45
65
|
export function workflowChoice(value: WorkflowChoice | undefined): WorkflowChoice | null {
|
|
@@ -52,13 +72,21 @@ export function workflowChoice(value: WorkflowChoice | undefined): WorkflowChoic
|
|
|
52
72
|
return { name: value.name, reason: value.reason };
|
|
53
73
|
}
|
|
54
74
|
|
|
55
|
-
|
|
56
|
-
|
|
75
|
+
type WorkflowSource = Pick<InputRecord, "id" | "workflow">;
|
|
76
|
+
|
|
77
|
+
function admittedUserWorkflow(source: WorkflowSource): WorkflowName | null {
|
|
78
|
+
const workflow = source.workflow;
|
|
79
|
+
return workflow?.provenance === "user" && workflow.sourceId === source.id ? workflow.name : null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Head selection is typed authority; use the original admission, not today's parser. */
|
|
83
|
+
export function headWorkflow(source: WorkflowSource, choice: WorkflowChoice | undefined): WorkflowActivation | null {
|
|
57
84
|
const selected = workflowChoice(choice);
|
|
58
85
|
if (!selected) return null;
|
|
59
|
-
const user =
|
|
60
|
-
if (user && user !== selected.name)
|
|
61
|
-
|
|
86
|
+
const user = admittedUserWorkflow(source);
|
|
87
|
+
if (user && user !== selected.name)
|
|
88
|
+
throw new Error("Head workflow conflicts with the original user's workflow invocation");
|
|
89
|
+
return { ...selected, sourceId: source.id, provenance: "head" };
|
|
62
90
|
}
|
|
63
91
|
|
|
64
92
|
/** Native matchers must not treat routing/brief/report prose as user keywords. */
|
|
@@ -70,25 +98,46 @@ export function workflowContext(envelope: string): string {
|
|
|
70
98
|
}
|
|
71
99
|
|
|
72
100
|
/** Keep user native keywords (including quoted/negative ones) byte-for-byte. */
|
|
73
|
-
export function workflowPrompt(activation: WorkflowActivation
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
101
|
+
export function workflowPrompt(activation: WorkflowActivation, source: WorkflowSource & { text: string }, envelope: string,
|
|
102
|
+
{ legacyCommand, worker = false }: { legacyCommand?: LegacyWorkflowName; worker?: boolean } = {}): string {
|
|
103
|
+
// A pending handoff can predate the current vocabulary. An ordinary task
|
|
104
|
+
// heading is not a user's selector or a reason to suppress a native default.
|
|
105
|
+
const leading = admittedUserWorkflow(source) === activation.name ? invocation(source.text) : null;
|
|
106
|
+
const selected = leading?.name === activation.name ? leading : null;
|
|
107
|
+
const invocationText = selected ? source.text.slice(0, selected.length) : "";
|
|
108
|
+
const argumentsText = source.text.slice(invocationText.length);
|
|
109
|
+
const explicitDelimiter = selected ? /^\S/.exec(argumentsText)?.[0] ?? "" : "";
|
|
78
110
|
const keyword = nativeWord[activation.name];
|
|
79
111
|
// Apply only the native bridge's default. A raw user mention, even quoted or
|
|
80
112
|
// negated, suppresses that default and is left for OMP's native prose matcher.
|
|
81
113
|
// Check before adding context, whose metadata must not change this decision.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
114
|
+
const nativeDefault = keyword && !explicitDelimiter && !nativeWords.test(argumentsText) ? ` ${keyword}` : "";
|
|
115
|
+
// A resident old Host still understands the original ULW user aliases. Keep
|
|
116
|
+
// their spelling, because e.g. "ulwplan" does not arm the same session policy
|
|
117
|
+
// as "ulw-plan". Only synthesized selectors use the old registration name.
|
|
118
|
+
const keepInvocation = selected && (!legacyCommand || selected.legacy);
|
|
119
|
+
// A worker takes ordinary prose, not native slash-command dispatch.
|
|
120
|
+
const prefix = worker ? invocationText.replace(/^(\s*)\//, "$1") : invocationText;
|
|
121
|
+
const request = keepInvocation
|
|
122
|
+
? `${prefix}${nativeDefault}${argumentsText}`
|
|
123
|
+
: `${legacyCommand ?? activation.name}${explicitDelimiter}${nativeDefault}\n\n${source.text}`;
|
|
86
124
|
return `${request}\n\n${workflowContext(envelope)}`;
|
|
87
125
|
}
|
|
88
126
|
|
|
89
|
-
|
|
127
|
+
function advertisedCommand(value: unknown, name: string, description: string): boolean {
|
|
90
128
|
if (!value || typeof value !== "object" || !("commands" in value) || !Array.isArray(value.commands)) return false;
|
|
91
129
|
return value.commands.some(command => command && typeof command === "object"
|
|
92
130
|
&& command.name === name && command.source === "extension"
|
|
93
|
-
&& command.description ===
|
|
131
|
+
&& command.description === description);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function advertisedWorkflow(value: unknown, name: WorkflowName): boolean {
|
|
135
|
+
return name !== "jevify" && advertisedCommand(value, name, name === "super" ? "Enable SUPER mode" : `Run the ${name} workflow`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Pre-rename extension registrations, not the new extension's legacy aliases. */
|
|
139
|
+
export function advertisedLegacyWorkflow(value: unknown, name: WorkflowName): LegacyWorkflowName | undefined {
|
|
140
|
+
if (name === "jevify") return undefined;
|
|
141
|
+
const legacy = legacyCommands[name];
|
|
142
|
+
return advertisedCommand(value, legacy, `Run the OMP-adapted ${legacy} workflow`) ? legacy : undefined;
|
|
94
143
|
}
|
package/src/setup-memory.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
2
|
-
import { canEnableGlobalMemory, effectiveMnemopi, type MnemopiReport, type MnemopiStatus } from "./managed-memory";
|
|
3
|
-
|
|
4
|
-
/** Only after explicit global consent and successful setup publication. */
|
|
5
|
-
export async function saveMnemopiPreference(settings: Settings, expected: MnemopiStatus): Promise<MnemopiReport> {
|
|
6
|
-
try {
|
|
7
|
-
const current = await effectiveMnemopi(settings);
|
|
8
|
-
if (!canEnableGlobalMemory(current) || !Bun.deepEquals(current, expected)) {
|
|
9
|
-
return { memory: current, updated: false };
|
|
10
|
-
}
|
|
11
|
-
const { editNativeGlobalConfig, readNativeSettings } = await import("./native-settings");
|
|
12
|
-
const [updated] = await editNativeGlobalConfig(settings, [{ path: "memory.backend", value: "mnemopi" }],
|
|
13
|
-
async actual => Bun.deepEquals(await effectiveMnemopi(actual), expected));
|
|
14
|
-
// The native writer preserves concurrent settings. Report what the new process
|
|
15
|
-
// will resolve, not the user's consent or a transient staged value.
|
|
16
|
-
return { memory: await effectiveMnemopi(await readNativeSettings(settings)), updated: updated === true };
|
|
17
|
-
} catch {
|
|
18
|
-
// Native parse or lock errors can contain private settings.
|
|
19
|
-
return { memory: { status: "unknown" }, updated: false };
|
|
20
|
-
}
|
|
21
|
-
}
|