flavor-code 1.2.18 → 1.2.20
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/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/dist/{app-YE3I7JMR.js → app-5D5RSGQX.js} +1 -1
- package/dist/{chunk-JB57IX2A.js → chunk-A7PMQ22O.js} +1 -1
- package/dist/{chunk-STZQ3Y3P.js → chunk-AXLUVJKC.js} +701 -366
- package/dist/cli.js +3 -3
- package/dist/desktop/main.js +1000 -665
- package/dist/desktop/plugin-worker-entry.js +230 -0
- package/dist/evolve/loader.d.ts +1 -1
- package/dist/plugin-worker-entry.js +233 -0
- package/dist/plugins/host.d.ts +2 -3
- package/dist/plugins/sandbox-protocol.d.ts +72 -0
- package/dist/plugins/types.d.ts +3 -0
- package/dist/plugins/worker-host.d.ts +19 -0
- package/dist/sdk/index.js +2 -2
- package/dist/skills/arguments.d.ts +8 -0
- package/dist/skills/tool.d.ts +5 -0
- package/dist/ui/session.d.ts +1 -0
- package/package.json +5 -4
package/dist/desktop/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/desktop/main.ts
|
|
2
2
|
import { appendFileSync } from "fs";
|
|
3
3
|
import { readFile as readFile34, stat as stat15, writeFile as writeFile18 } from "fs/promises";
|
|
4
|
-
import { dirname as
|
|
4
|
+
import { dirname as dirname24, join as join41 } from "path";
|
|
5
5
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
6
6
|
import { app, BrowserWindow as BrowserWindow2, dialog, ipcMain, Menu, nativeImage, shell } from "electron";
|
|
7
7
|
|
|
@@ -2612,11 +2612,11 @@ function hexToLab(hex) {
|
|
|
2612
2612
|
const b = linearize(channels[2]);
|
|
2613
2613
|
const x = (0.4124564 * r + 0.3575761 * g + 0.1804375 * b) / 0.95047;
|
|
2614
2614
|
const y = 0.2126729 * r + 0.7151522 * g + 0.072175 * b;
|
|
2615
|
-
const
|
|
2615
|
+
const z44 = (0.0193339 * r + 0.119192 * g + 0.9503041 * b) / 1.08883;
|
|
2616
2616
|
const f = (t) => t > 8856e-6 ? Math.cbrt(t) : 7.787 * t + 16 / 116;
|
|
2617
2617
|
const fx = f(x);
|
|
2618
2618
|
const fy = f(y);
|
|
2619
|
-
const fz = f(
|
|
2619
|
+
const fz = f(z44);
|
|
2620
2620
|
return [116 * fy - 16, 500 * (fx - fy), 200 * (fy - fz)];
|
|
2621
2621
|
}
|
|
2622
2622
|
function deltaE76(left, right) {
|
|
@@ -8103,7 +8103,7 @@ function createIncidentReporter(options) {
|
|
|
8103
8103
|
import { spawn as spawn2 } from "child_process";
|
|
8104
8104
|
import { writeFile as writeFile7 } from "fs/promises";
|
|
8105
8105
|
import { join as join10 } from "path";
|
|
8106
|
-
import { z as
|
|
8106
|
+
import { z as z18 } from "zod";
|
|
8107
8107
|
|
|
8108
8108
|
// src/evolve/loader.ts
|
|
8109
8109
|
import { cp as cp2, mkdir as mkdir7, mkdtemp, readdir as readdir3, rm as rm4, stat as stat5, writeFile as writeFile5 } from "fs/promises";
|
|
@@ -8112,9 +8112,10 @@ import { join as join8, resolve as resolve9 } from "path";
|
|
|
8112
8112
|
|
|
8113
8113
|
// src/plugins/host.ts
|
|
8114
8114
|
import { lstatSync, realpathSync as realpathSync2 } from "fs";
|
|
8115
|
-
import { lstat as lstat3, open as open4, readdir as readdir2, realpath as
|
|
8115
|
+
import { lstat as lstat3, open as open4, readdir as readdir2, realpath as realpath6, stat as stat4, writeFile as writeFile4 } from "fs/promises";
|
|
8116
8116
|
import { isAbsolute as isAbsolute6, relative as relative6, resolve as resolve8, sep as sep6 } from "path";
|
|
8117
8117
|
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
8118
|
+
import { z as z17 } from "zod";
|
|
8118
8119
|
|
|
8119
8120
|
// src/plugins/types.ts
|
|
8120
8121
|
import { z as z16 } from "zod";
|
|
@@ -8144,10 +8145,188 @@ var PluginManifestSchema = z16.object({
|
|
|
8144
8145
|
}).strict()
|
|
8145
8146
|
}).strict();
|
|
8146
8147
|
|
|
8148
|
+
// src/plugins/worker-host.ts
|
|
8149
|
+
import { realpath as realpath5 } from "fs/promises";
|
|
8150
|
+
import { dirname as dirname7 } from "path";
|
|
8151
|
+
import { Worker as Worker2 } from "worker_threads";
|
|
8152
|
+
var DEFAULT_ACTIVATION_TIMEOUT_MS = 1e4;
|
|
8153
|
+
var DEFAULT_INVOCATION_TIMEOUT_MS = 3e4;
|
|
8154
|
+
var DEFAULT_MAX_OLD_SPACE_MB = 128;
|
|
8155
|
+
var DEFAULT_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
8156
|
+
async function startPluginSandbox(options) {
|
|
8157
|
+
const entryPath = await realpath5(options.entryPath);
|
|
8158
|
+
const pluginRoot = await realpath5(options.pluginRoot ?? dirname7(entryPath));
|
|
8159
|
+
const activationTimeoutMs = options.activationTimeoutMs ?? DEFAULT_ACTIVATION_TIMEOUT_MS;
|
|
8160
|
+
const invocationTimeoutMs = options.invocationTimeoutMs ?? DEFAULT_INVOCATION_TIMEOUT_MS;
|
|
8161
|
+
let configJson;
|
|
8162
|
+
try {
|
|
8163
|
+
configJson = JSON.stringify(options.config ?? {});
|
|
8164
|
+
} catch (error) {
|
|
8165
|
+
throw new Error(`Plugin sandbox config is not serializable: ${String(error)}`);
|
|
8166
|
+
}
|
|
8167
|
+
const workerEntry = new URL(import.meta.url.endsWith(".ts") ? "./plugin-worker-entry.ts" : "./plugin-worker-entry.js", import.meta.url);
|
|
8168
|
+
const worker = new Worker2(workerEntry, {
|
|
8169
|
+
workerData: { entryPath, pluginRoot, pluginName: options.pluginName, pluginVersion: options.pluginVersion, configJson },
|
|
8170
|
+
execArgv: ["--experimental-vm-modules", "--no-warnings"],
|
|
8171
|
+
resourceLimits: {
|
|
8172
|
+
maxOldGenerationSizeMb: options.maxOldSpaceMb ?? DEFAULT_MAX_OLD_SPACE_MB,
|
|
8173
|
+
maxYoungGenerationSizeMb: 16,
|
|
8174
|
+
codeRangeSizeMb: 16,
|
|
8175
|
+
stackSizeMb: 4
|
|
8176
|
+
}
|
|
8177
|
+
});
|
|
8178
|
+
let closed = false;
|
|
8179
|
+
let nextId = 1;
|
|
8180
|
+
const pending2 = /* @__PURE__ */ new Map();
|
|
8181
|
+
let disposeResolve;
|
|
8182
|
+
let disposeReject;
|
|
8183
|
+
let failWorker;
|
|
8184
|
+
const ready = await new Promise((resolveReady, rejectReady) => {
|
|
8185
|
+
let settled = false;
|
|
8186
|
+
const timer = setTimeout(() => {
|
|
8187
|
+
settled = true;
|
|
8188
|
+
closed = true;
|
|
8189
|
+
void worker.terminate();
|
|
8190
|
+
rejectReady(new Error(`Plugin activation sandbox timed out after ${activationTimeoutMs}ms`));
|
|
8191
|
+
}, activationTimeoutMs);
|
|
8192
|
+
const fail = (error) => {
|
|
8193
|
+
if (closed && settled) return;
|
|
8194
|
+
closed = true;
|
|
8195
|
+
clearTimeout(timer);
|
|
8196
|
+
for (const request of pending2.values()) {
|
|
8197
|
+
clearTimeout(request.timer);
|
|
8198
|
+
request.reject(error);
|
|
8199
|
+
}
|
|
8200
|
+
pending2.clear();
|
|
8201
|
+
disposeReject?.(error);
|
|
8202
|
+
if (!settled) {
|
|
8203
|
+
settled = true;
|
|
8204
|
+
rejectReady(error);
|
|
8205
|
+
}
|
|
8206
|
+
void worker.terminate();
|
|
8207
|
+
};
|
|
8208
|
+
failWorker = fail;
|
|
8209
|
+
worker.on("message", (raw) => {
|
|
8210
|
+
if (!isWorkerMessage(raw)) {
|
|
8211
|
+
fail(new Error("Plugin sandbox sent an invalid protocol message"));
|
|
8212
|
+
return;
|
|
8213
|
+
}
|
|
8214
|
+
const message2 = raw;
|
|
8215
|
+
if (message2.type === "fatal") {
|
|
8216
|
+
fail(new Error(message2.error));
|
|
8217
|
+
return;
|
|
8218
|
+
}
|
|
8219
|
+
if (message2.type === "ready") {
|
|
8220
|
+
if (settled || !isSandboxResult(message2.result)) {
|
|
8221
|
+
fail(new Error("Plugin sandbox sent an invalid or duplicate ready message"));
|
|
8222
|
+
return;
|
|
8223
|
+
}
|
|
8224
|
+
settled = true;
|
|
8225
|
+
clearTimeout(timer);
|
|
8226
|
+
resolveReady(message2.result);
|
|
8227
|
+
return;
|
|
8228
|
+
}
|
|
8229
|
+
if (!settled) {
|
|
8230
|
+
fail(new Error(`Plugin sandbox sent ${message2.type} before ready`));
|
|
8231
|
+
return;
|
|
8232
|
+
}
|
|
8233
|
+
if (message2.type === "response") {
|
|
8234
|
+
const request = pending2.get(message2.id);
|
|
8235
|
+
if (request === void 0) {
|
|
8236
|
+
fail(new Error("Plugin sandbox sent a response for an unknown request"));
|
|
8237
|
+
return;
|
|
8238
|
+
}
|
|
8239
|
+
pending2.delete(message2.id);
|
|
8240
|
+
clearTimeout(request.timer);
|
|
8241
|
+
if (message2.ok) {
|
|
8242
|
+
try {
|
|
8243
|
+
request.resolve(JSON.parse(message2.valueJson));
|
|
8244
|
+
} catch {
|
|
8245
|
+
fail(new Error("Plugin sandbox returned invalid JSON"));
|
|
8246
|
+
}
|
|
8247
|
+
} else request.reject(new Error(message2.error));
|
|
8248
|
+
return;
|
|
8249
|
+
}
|
|
8250
|
+
if (message2.type === "disposed") {
|
|
8251
|
+
closed = true;
|
|
8252
|
+
disposeResolve?.();
|
|
8253
|
+
void worker.terminate();
|
|
8254
|
+
}
|
|
8255
|
+
});
|
|
8256
|
+
worker.once("error", fail);
|
|
8257
|
+
worker.once("exit", (code) => {
|
|
8258
|
+
if (!closed) fail(new Error(`Plugin worker exited with code ${code}`));
|
|
8259
|
+
});
|
|
8260
|
+
});
|
|
8261
|
+
return {
|
|
8262
|
+
result: ready,
|
|
8263
|
+
invoke(kind, name, args) {
|
|
8264
|
+
if (closed) return Promise.reject(new Error("Plugin sandbox is closed"));
|
|
8265
|
+
let argsJson;
|
|
8266
|
+
try {
|
|
8267
|
+
argsJson = JSON.stringify(args);
|
|
8268
|
+
} catch (error) {
|
|
8269
|
+
return Promise.reject(new Error(`Plugin sandbox arguments are not serializable: ${String(error)}`));
|
|
8270
|
+
}
|
|
8271
|
+
const id = nextId++;
|
|
8272
|
+
return new Promise((resolveInvoke, rejectInvoke) => {
|
|
8273
|
+
const timer = setTimeout(() => {
|
|
8274
|
+
const error = new Error(`Plugin sandbox invocation timed out after ${invocationTimeoutMs}ms`);
|
|
8275
|
+
failWorker(error);
|
|
8276
|
+
}, invocationTimeoutMs);
|
|
8277
|
+
pending2.set(id, { resolve: (value) => resolveInvoke(value), reject: rejectInvoke, timer });
|
|
8278
|
+
worker.postMessage({ type: "invoke", id, kind, name, argsJson });
|
|
8279
|
+
});
|
|
8280
|
+
},
|
|
8281
|
+
dispose() {
|
|
8282
|
+
if (closed) return Promise.resolve();
|
|
8283
|
+
return new Promise((resolveDispose, rejectDispose) => {
|
|
8284
|
+
const timer = setTimeout(() => {
|
|
8285
|
+
const error = new Error(`Plugin sandbox shutdown timed out after ${DEFAULT_SHUTDOWN_TIMEOUT_MS}ms`);
|
|
8286
|
+
failWorker(error);
|
|
8287
|
+
}, DEFAULT_SHUTDOWN_TIMEOUT_MS);
|
|
8288
|
+
disposeResolve = () => {
|
|
8289
|
+
clearTimeout(timer);
|
|
8290
|
+
resolveDispose();
|
|
8291
|
+
};
|
|
8292
|
+
disposeReject = (error) => {
|
|
8293
|
+
clearTimeout(timer);
|
|
8294
|
+
rejectDispose(error);
|
|
8295
|
+
};
|
|
8296
|
+
worker.postMessage({ type: "shutdown" });
|
|
8297
|
+
});
|
|
8298
|
+
}
|
|
8299
|
+
};
|
|
8300
|
+
}
|
|
8301
|
+
function isWorkerMessage(value) {
|
|
8302
|
+
if (typeof value !== "object" || value === null || !("type" in value)) return false;
|
|
8303
|
+
const type = value.type;
|
|
8304
|
+
if (type === "disposed") return true;
|
|
8305
|
+
if (type === "fatal") return typeof value.error === "string";
|
|
8306
|
+
if (type === "ready") return "result" in value;
|
|
8307
|
+
if (type !== "response") return false;
|
|
8308
|
+
const response2 = value;
|
|
8309
|
+
return Number.isSafeInteger(response2.id) && typeof response2.ok === "boolean" && (response2.ok ? typeof response2.valueJson === "string" : typeof response2.error === "string");
|
|
8310
|
+
}
|
|
8311
|
+
function isSandboxResult(value) {
|
|
8312
|
+
if (typeof value !== "object" || value === null) return false;
|
|
8313
|
+
const result = value;
|
|
8314
|
+
if (!(result.ok === true && typeof result.name === "string" && typeof result.version === "string" && Array.isArray(result.registeredTools) && result.registeredTools.every((item) => typeof item === "string") && Array.isArray(result.registeredCommands) && result.registeredCommands.every((item) => typeof item === "string") && Array.isArray(result.registeredHooks) && result.registeredHooks.every((item) => typeof item === "string") && Array.isArray(result.registeredSkillRoots) && result.registeredSkillRoots.every((item) => typeof item === "string") && Array.isArray(result.registeredModelAdapters) && result.registeredModelAdapters.every((item) => typeof item === "string") && typeof result.contributions === "object" && result.contributions !== null)) return false;
|
|
8315
|
+
const contributions = result.contributions;
|
|
8316
|
+
const named = (item) => typeof item === "object" && item !== null && typeof item.name === "string";
|
|
8317
|
+
if (!Array.isArray(contributions.commands) || !contributions.commands.every((item) => named(item) && (item.description === void 0 || typeof item.description === "string"))) return false;
|
|
8318
|
+
if (!Array.isArray(contributions.tools) || !contributions.tools.every((item) => named(item) && typeof item.toolName === "string" && typeof item.description === "string" && (item.modelInputSchema === void 0 || typeof item.modelInputSchema === "object" && item.modelInputSchema !== null) && (item.readOnly === void 0 || typeof item.readOnly === "boolean"))) return false;
|
|
8319
|
+
if (!Array.isArray(contributions.hooks) || !contributions.hooks.every(named)) return false;
|
|
8320
|
+
if (!Array.isArray(contributions.skillRoots) || !contributions.skillRoots.every((item) => named(item) && typeof item.root === "string")) return false;
|
|
8321
|
+
if (!Array.isArray(contributions.modelAdapters) || !contributions.modelAdapters.every(named)) return false;
|
|
8322
|
+
const same = (left, right) => left.length === right.length && left.every((name, index) => name === right[index]?.name);
|
|
8323
|
+
return same(result.registeredCommands, contributions.commands) && same(result.registeredTools, contributions.tools) && same(result.registeredHooks, contributions.hooks) && same(result.registeredSkillRoots, contributions.skillRoots) && same(result.registeredModelAdapters, contributions.modelAdapters);
|
|
8324
|
+
}
|
|
8325
|
+
|
|
8147
8326
|
// src/plugins/host.ts
|
|
8148
8327
|
var MANIFEST = "flavor-plugin.json";
|
|
8149
8328
|
var MAX_MANIFEST_BYTES = 64 * 1024;
|
|
8150
|
-
var
|
|
8329
|
+
var DEFAULT_ACTIVATION_TIMEOUT_MS2 = 1e4;
|
|
8151
8330
|
var DEFAULT_UNLOAD_TIMEOUT_MS = 5e3;
|
|
8152
8331
|
var silentLogger = { debug() {
|
|
8153
8332
|
}, info() {
|
|
@@ -8164,7 +8343,7 @@ var PluginHost = class {
|
|
|
8164
8343
|
#loaded = false;
|
|
8165
8344
|
constructor(options) {
|
|
8166
8345
|
this.#options = options;
|
|
8167
|
-
this.#activationTimeoutMs = positiveTimeout(options.activationTimeoutMs,
|
|
8346
|
+
this.#activationTimeoutMs = positiveTimeout(options.activationTimeoutMs, DEFAULT_ACTIVATION_TIMEOUT_MS2, "activationTimeoutMs");
|
|
8168
8347
|
this.#unloadTimeoutMs = positiveTimeout(options.unloadTimeoutMs, DEFAULT_UNLOAD_TIMEOUT_MS, "unloadTimeoutMs");
|
|
8169
8348
|
}
|
|
8170
8349
|
get diagnostics() {
|
|
@@ -8278,7 +8457,7 @@ var PluginHost = class {
|
|
|
8278
8457
|
try {
|
|
8279
8458
|
const rootInfo = await lstat3(inputRoot);
|
|
8280
8459
|
if (!rootInfo.isDirectory() || rootInfo.isSymbolicLink()) throw new Error("Plugin root must be a static directory");
|
|
8281
|
-
const root = await
|
|
8460
|
+
const root = await realpath6(inputRoot);
|
|
8282
8461
|
const rawManifest = await readManifest2(resolve8(root, MANIFEST));
|
|
8283
8462
|
if (typeof rawManifest === "object" && rawManifest !== null && "name" in rawManifest && typeof rawManifest.name === "string") {
|
|
8284
8463
|
diagnosticLabel = rawManifest.name;
|
|
@@ -8298,18 +8477,79 @@ var PluginHost = class {
|
|
|
8298
8477
|
const claimed = [];
|
|
8299
8478
|
const state = { active: true, controller: new AbortController() };
|
|
8300
8479
|
let activation;
|
|
8480
|
+
const useSandbox = this.#options.sandbox === true;
|
|
8301
8481
|
try {
|
|
8302
8482
|
await verifyEntry(candidate.root, candidate.entry, candidate.entrySnapshot);
|
|
8303
|
-
|
|
8304
|
-
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
|
|
8308
|
-
|
|
8309
|
-
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8483
|
+
if (useSandbox) {
|
|
8484
|
+
const session = await bounded(
|
|
8485
|
+
startPluginSandbox({
|
|
8486
|
+
entryPath: candidate.entrySnapshot.physicalPath,
|
|
8487
|
+
pluginRoot: candidate.root,
|
|
8488
|
+
pluginName: plugin,
|
|
8489
|
+
pluginVersion: candidate.manifest.version,
|
|
8490
|
+
config: redactConfig(this.#options.config ?? {}),
|
|
8491
|
+
activationTimeoutMs: this.#activationTimeoutMs
|
|
8492
|
+
}),
|
|
8493
|
+
this.#activationTimeoutMs + 1e3,
|
|
8494
|
+
"Plugin sandbox activation"
|
|
8495
|
+
);
|
|
8496
|
+
disposers.push(() => session.dispose());
|
|
8497
|
+
const result = session.result;
|
|
8498
|
+
if (!result.ok) throw new Error(result.error ?? `Plugin "${plugin}" sandbox execution failed`);
|
|
8499
|
+
const context = this.#context(candidate, disposers, claimed, state);
|
|
8500
|
+
for (const command of result.contributions.commands) {
|
|
8501
|
+
context.registerCommand(command.name, (args, commandContext) => session.invoke("command", command.name, [
|
|
8502
|
+
args,
|
|
8503
|
+
{ workspace: commandContext.workspace }
|
|
8504
|
+
]), command.description);
|
|
8505
|
+
}
|
|
8506
|
+
for (const contribution of result.contributions.tools) {
|
|
8507
|
+
const tool = {
|
|
8508
|
+
name: contribution.toolName,
|
|
8509
|
+
description: contribution.description,
|
|
8510
|
+
inputSchema: z17.unknown(),
|
|
8511
|
+
...contribution.modelInputSchema === void 0 ? {} : { modelInputSchema: contribution.modelInputSchema },
|
|
8512
|
+
...contribution.readOnly === void 0 ? {} : { readOnly: contribution.readOnly },
|
|
8513
|
+
paths: () => [],
|
|
8514
|
+
execute: (input, _signal, toolContext) => session.invoke("tool", contribution.name, [
|
|
8515
|
+
input,
|
|
8516
|
+
toolContext === void 0 ? void 0 : { agent: toolContext.agent, ownerId: toolContext.ownerId }
|
|
8517
|
+
])
|
|
8518
|
+
};
|
|
8519
|
+
context.registerTool(contribution.name, tool);
|
|
8520
|
+
}
|
|
8521
|
+
for (const hook of result.contributions.hooks) {
|
|
8522
|
+
context.registerHook(
|
|
8523
|
+
hook.name,
|
|
8524
|
+
(event) => session.invoke("hook", hook.name, [event]),
|
|
8525
|
+
hook.options
|
|
8526
|
+
);
|
|
8527
|
+
}
|
|
8528
|
+
for (const skill of result.contributions.skillRoots) {
|
|
8529
|
+
context.registerSkillRoot(skill.name, skill.root);
|
|
8530
|
+
}
|
|
8531
|
+
for (const adapter of result.contributions.modelAdapters) {
|
|
8532
|
+
context.registerModelAdapter(adapter.name, {
|
|
8533
|
+
async *stream(request) {
|
|
8534
|
+
const safeRequest = { ...request, signal: void 0 };
|
|
8535
|
+
const events = await session.invoke("modelAdapter", adapter.name, [safeRequest]);
|
|
8536
|
+
for (const event of events) yield event;
|
|
8537
|
+
}
|
|
8538
|
+
});
|
|
8539
|
+
}
|
|
8540
|
+
await verifyEntry(candidate.root, candidate.entry, candidate.entrySnapshot);
|
|
8541
|
+
} else {
|
|
8542
|
+
const imported = import(`${pathToFileURL2(candidate.entrySnapshot.physicalPath).href}?flavor=${encodeURIComponent(plugin)}&v=${Date.now()}`);
|
|
8543
|
+
const module = await bounded(imported, this.#activationTimeoutMs, "Plugin import");
|
|
8544
|
+
await verifyEntry(candidate.root, candidate.entry, candidate.entrySnapshot);
|
|
8545
|
+
if (typeof module.activate !== "function") throw new Error("Plugin entry must export activate(context)");
|
|
8546
|
+
const context = this.#context(candidate, disposers, claimed, state);
|
|
8547
|
+
activation = Promise.resolve().then(() => module.activate(context));
|
|
8548
|
+
const deactivate = await bounded(activation, this.#activationTimeoutMs, "Plugin activation");
|
|
8549
|
+
if (deactivate !== void 0) {
|
|
8550
|
+
if (typeof deactivate !== "function") throw new Error("Plugin activate result must be a disposer or undefined");
|
|
8551
|
+
disposers.push(deactivate);
|
|
8552
|
+
}
|
|
8313
8553
|
}
|
|
8314
8554
|
this.#assertAllDeclaredRegistered(candidate, claimed);
|
|
8315
8555
|
const metadata = { name: plugin, version: candidate.manifest.version, source: candidate.source, root: candidate.root };
|
|
@@ -8473,7 +8713,7 @@ async function readManifest2(path) {
|
|
|
8473
8713
|
async function snapshotEntry(root, entry2) {
|
|
8474
8714
|
const lexicalStats = await lstat3(entry2, { bigint: true });
|
|
8475
8715
|
if (!lexicalStats.isFile() && !lexicalStats.isSymbolicLink()) throw new Error("Plugin entry must be a file");
|
|
8476
|
-
const physicalPath = await
|
|
8716
|
+
const physicalPath = await realpath6(entry2);
|
|
8477
8717
|
assertContained2(root, physicalPath, "Plugin entry symlink");
|
|
8478
8718
|
const physicalStats = await stat4(physicalPath, { bigint: true });
|
|
8479
8719
|
if (!physicalStats.isFile()) throw new Error("Plugin entry must resolve to a regular file");
|
|
@@ -8589,6 +8829,8 @@ var SCAFFOLD_ENTRY = (name) => `// ${name} \u2014 generated by /evolve improve <
|
|
|
8589
8829
|
// - context: { signal, config, logger, services, registerCommand,
|
|
8590
8830
|
// registerTool, registerHook, registerSkillRoot, registerModelAdapter }
|
|
8591
8831
|
// - every contribution you register MUST be declared in contributes
|
|
8832
|
+
// - sandbox verification only permits relative JS modules inside this plugin root;
|
|
8833
|
+
// Node.js built-ins, package imports, filesystem, and network APIs are unavailable
|
|
8592
8834
|
//
|
|
8593
8835
|
// Implement your fix here. Example \u2014 observe tool failures:
|
|
8594
8836
|
// ctx.registerHook("PostToolUseFailure", (event) => {
|
|
@@ -8628,7 +8870,9 @@ async function verifyFixPlugin(workspace, name) {
|
|
|
8628
8870
|
await cp2(pluginRoot, join8(sandbox, name), { recursive: true });
|
|
8629
8871
|
const host = new PluginHost({
|
|
8630
8872
|
projectPluginDirs: [sandbox],
|
|
8873
|
+
sandbox: true,
|
|
8631
8874
|
config: {},
|
|
8875
|
+
activationTimeoutMs: 5e3,
|
|
8632
8876
|
registrations: {
|
|
8633
8877
|
command: (commandName) => {
|
|
8634
8878
|
collected.commands.push(commandName);
|
|
@@ -8642,12 +8886,11 @@ async function verifyFixPlugin(workspace, name) {
|
|
|
8642
8886
|
skillRoot: () => () => void 0,
|
|
8643
8887
|
modelAdapter: () => () => void 0
|
|
8644
8888
|
},
|
|
8645
|
-
logger: {
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
|
|
8649
|
-
|
|
8650
|
-
}
|
|
8889
|
+
logger: { debug() {
|
|
8890
|
+
}, info() {
|
|
8891
|
+
}, warn() {
|
|
8892
|
+
}, error() {
|
|
8893
|
+
} }
|
|
8651
8894
|
});
|
|
8652
8895
|
await host.loadAll();
|
|
8653
8896
|
const loaded = host.loadedPlugins;
|
|
@@ -8706,7 +8949,7 @@ async function revertFixPlugin(workspace, name) {
|
|
|
8706
8949
|
// src/evolve/store.ts
|
|
8707
8950
|
import { createHash as createHash5 } from "crypto";
|
|
8708
8951
|
import { appendFile, mkdir as mkdir8, readFile as readFile7, rm as rm5, writeFile as writeFile6 } from "fs/promises";
|
|
8709
|
-
import { dirname as
|
|
8952
|
+
import { dirname as dirname8, join as join9 } from "path";
|
|
8710
8953
|
function normalizeError(message2) {
|
|
8711
8954
|
return String(message2 ?? "").replace(/\s+/g, " ").replace(/"[^"]*"/g, '"\u2026"').replace(/`[^`]*`/g, '"\u2026"').trim().slice(0, 160);
|
|
8712
8955
|
}
|
|
@@ -8735,7 +8978,7 @@ async function readJsonLines(file) {
|
|
|
8735
8978
|
}
|
|
8736
8979
|
}
|
|
8737
8980
|
async function writeJsonLines(file, records) {
|
|
8738
|
-
await mkdir8(
|
|
8981
|
+
await mkdir8(dirname8(file), { recursive: true, mode: 448 });
|
|
8739
8982
|
const body = records.map((record3) => JSON.stringify(record3)).join("\n");
|
|
8740
8983
|
await writeFile6(file, body.length > 0 ? `${body}
|
|
8741
8984
|
` : "", { encoding: "utf8", mode: 384 });
|
|
@@ -8763,7 +9006,7 @@ async function readRules(file) {
|
|
|
8763
9006
|
}
|
|
8764
9007
|
}
|
|
8765
9008
|
async function writeRules(file, rules) {
|
|
8766
|
-
await mkdir8(
|
|
9009
|
+
await mkdir8(dirname8(file), { recursive: true, mode: 448 });
|
|
8767
9010
|
await writeFile6(file, JSON.stringify(rules, null, 2), { encoding: "utf8", mode: 384 });
|
|
8768
9011
|
}
|
|
8769
9012
|
var EvolveStore = class {
|
|
@@ -9385,10 +9628,10 @@ ${result.stderr.slice(-4e3)}` : ""}`;
|
|
|
9385
9628
|
return USAGE;
|
|
9386
9629
|
},
|
|
9387
9630
|
toolDefinition() {
|
|
9388
|
-
const inputSchema =
|
|
9389
|
-
suggestionId:
|
|
9390
|
-
implementation:
|
|
9391
|
-
kind:
|
|
9631
|
+
const inputSchema = z18.object({
|
|
9632
|
+
suggestionId: z18.string().min(1).describe("Signal id from the evolve suggestions"),
|
|
9633
|
+
implementation: z18.string().min(1).describe("Concise description of the fix to implement (plugin plan, or the guardrail rule text when kind is prompt_rule)"),
|
|
9634
|
+
kind: z18.enum(["plugin", "prompt_rule"]).optional().describe(
|
|
9392
9635
|
"plugin (default): scaffold a fix plugin; prompt_rule: store a guardrail rule that is injected into future system prompts"
|
|
9393
9636
|
)
|
|
9394
9637
|
});
|
|
@@ -9437,9 +9680,9 @@ ${result.stderr.slice(-4e3)}` : ""}`;
|
|
|
9437
9680
|
}
|
|
9438
9681
|
|
|
9439
9682
|
// src/init/project.ts
|
|
9440
|
-
import { lstat as lstat4, mkdir as mkdir9, readdir as readdir4, readFile as readFile8, realpath as
|
|
9683
|
+
import { lstat as lstat4, mkdir as mkdir9, readdir as readdir4, readFile as readFile8, realpath as realpath7, writeFile as writeFile8 } from "fs/promises";
|
|
9441
9684
|
import { copyFileSync, mkdirSync, readdirSync, readFileSync } from "fs";
|
|
9442
|
-
import { basename as basename4, dirname as
|
|
9685
|
+
import { basename as basename4, dirname as dirname9, isAbsolute as isAbsolute7, join as join11, relative as relative7, sep as sep7 } from "path";
|
|
9443
9686
|
import { fileURLToPath } from "url";
|
|
9444
9687
|
var GENERATED_START = "<!-- flavor-code:start -->";
|
|
9445
9688
|
var GENERATED_END = "<!-- flavor-code:end -->";
|
|
@@ -9494,7 +9737,7 @@ function isContainedPath(root, candidate) {
|
|
|
9494
9737
|
async function pathKind(path, root) {
|
|
9495
9738
|
try {
|
|
9496
9739
|
const details = await lstat4(path);
|
|
9497
|
-
if (details.isSymbolicLink() || !isContainedPath(root, await
|
|
9740
|
+
if (details.isSymbolicLink() || !isContainedPath(root, await realpath7(path))) return void 0;
|
|
9498
9741
|
if (details.isFile()) return "file";
|
|
9499
9742
|
if (details.isDirectory()) return "directory";
|
|
9500
9743
|
return void 0;
|
|
@@ -9511,7 +9754,7 @@ async function readTextIfSmall(path, root) {
|
|
|
9511
9754
|
if (isMissingPathError(error)) return void 0;
|
|
9512
9755
|
throw error;
|
|
9513
9756
|
});
|
|
9514
|
-
if (details === void 0 || !details.isFile() || details.isSymbolicLink() || details.size > MAX_MANIFEST_BYTES2 || !isContainedPath(root, await
|
|
9757
|
+
if (details === void 0 || !details.isFile() || details.isSymbolicLink() || details.size > MAX_MANIFEST_BYTES2 || !isContainedPath(root, await realpath7(path))) {
|
|
9515
9758
|
return void 0;
|
|
9516
9759
|
}
|
|
9517
9760
|
return readFile8(path, "utf8");
|
|
@@ -9562,7 +9805,7 @@ async function sampleSourceExtensions(cwd, root, directories) {
|
|
|
9562
9805
|
const sampleDirectories = ["", ...directories].slice(0, 12);
|
|
9563
9806
|
for (const relativeDirectory of sampleDirectories) {
|
|
9564
9807
|
const absoluteDirectory = join11(cwd, relativeDirectory);
|
|
9565
|
-
if (!isContainedPath(root, await
|
|
9808
|
+
if (!isContainedPath(root, await realpath7(absoluteDirectory))) continue;
|
|
9566
9809
|
let entries;
|
|
9567
9810
|
try {
|
|
9568
9811
|
entries = await readdir4(absoluteDirectory, { withFileTypes: true });
|
|
@@ -9579,7 +9822,7 @@ async function sampleSourceExtensions(cwd, root, directories) {
|
|
|
9579
9822
|
return extensions;
|
|
9580
9823
|
}
|
|
9581
9824
|
async function inspectProject(cwd) {
|
|
9582
|
-
const root = await
|
|
9825
|
+
const root = await realpath7(cwd);
|
|
9583
9826
|
const sourceDirectories = [];
|
|
9584
9827
|
for (const directory of SOURCE_DIRECTORIES) {
|
|
9585
9828
|
if (await pathKind(join11(cwd, directory), root) === "directory") sourceDirectories.push(directory);
|
|
@@ -9813,7 +10056,7 @@ function isEntryIgnored(lines, entry2) {
|
|
|
9813
10056
|
}
|
|
9814
10057
|
async function addSessionsToGitignore(cwd) {
|
|
9815
10058
|
const path = join11(cwd, ".gitignore");
|
|
9816
|
-
const root = await
|
|
10059
|
+
const root = await realpath7(cwd);
|
|
9817
10060
|
await assertSafeManagedPath(path, root);
|
|
9818
10061
|
let existing;
|
|
9819
10062
|
try {
|
|
@@ -9836,7 +10079,7 @@ async function assertSafeManagedPath(path, root) {
|
|
|
9836
10079
|
if (details.isSymbolicLink()) {
|
|
9837
10080
|
throw new Error(`Refusing to overwrite managed file symbolic link: ${path}`);
|
|
9838
10081
|
}
|
|
9839
|
-
if (!isContainedPath(root, await
|
|
10082
|
+
if (!isContainedPath(root, await realpath7(path))) {
|
|
9840
10083
|
throw new Error(`Refusing to overwrite managed file outside the project: ${path}`);
|
|
9841
10084
|
}
|
|
9842
10085
|
} catch (error) {
|
|
@@ -9845,16 +10088,16 @@ async function assertSafeManagedPath(path, root) {
|
|
|
9845
10088
|
}
|
|
9846
10089
|
}
|
|
9847
10090
|
async function ensureFlavorDirectories(cwd) {
|
|
9848
|
-
const root = await
|
|
10091
|
+
const root = await realpath7(cwd);
|
|
9849
10092
|
const sessionsDir = join11(cwd, ".flavor", "sessions");
|
|
9850
10093
|
const skillsDir = join11(cwd, ".flavor", "skills");
|
|
9851
10094
|
const pluginsDir = join11(cwd, ".flavor", "plugins");
|
|
9852
10095
|
await mkdir9(sessionsDir, { recursive: true, mode: 448 });
|
|
9853
10096
|
await mkdir9(skillsDir, { recursive: true, mode: 448 });
|
|
9854
10097
|
await mkdir9(pluginsDir, { recursive: true, mode: 448 });
|
|
9855
|
-
const canonicalRoot = await
|
|
10098
|
+
const canonicalRoot = await realpath7(root);
|
|
9856
10099
|
for (const dir of [sessionsDir, skillsDir, pluginsDir]) {
|
|
9857
|
-
const canonical3 = await
|
|
10100
|
+
const canonical3 = await realpath7(dir);
|
|
9858
10101
|
if (!isContainedPath(canonicalRoot, canonical3)) {
|
|
9859
10102
|
throw new Error(`Directory escapes the workspace: ${dir}`);
|
|
9860
10103
|
}
|
|
@@ -9862,7 +10105,7 @@ async function ensureFlavorDirectories(cwd) {
|
|
|
9862
10105
|
}
|
|
9863
10106
|
async function createExampleFlavorConfig(cwd) {
|
|
9864
10107
|
const configPath = join11(cwd, ".flavor", "flavor.json");
|
|
9865
|
-
const root = await
|
|
10108
|
+
const root = await realpath7(cwd);
|
|
9866
10109
|
await assertSafeManagedPath(configPath, root);
|
|
9867
10110
|
try {
|
|
9868
10111
|
await lstat4(configPath);
|
|
@@ -9891,7 +10134,7 @@ async function createExampleFlavorConfig(cwd) {
|
|
|
9891
10134
|
};
|
|
9892
10135
|
await writeFile8(configPath, JSON.stringify(example, null, 2) + "\n");
|
|
9893
10136
|
}
|
|
9894
|
-
var CODEISLAND_SRC_DIR = join11(
|
|
10137
|
+
var CODEISLAND_SRC_DIR = join11(dirname9(fileURLToPath(import.meta.url)), "codeisland");
|
|
9895
10138
|
var CODEISLAND_FILES = ["flavor-plugin.json", "activate.mjs", "bridge.mjs"];
|
|
9896
10139
|
async function copyCodeIslandPlugin(cwd) {
|
|
9897
10140
|
const pluginDir = join11(cwd, ".flavor", "plugins", "codeisland");
|
|
@@ -9907,7 +10150,7 @@ async function copyCodeIslandPlugin(cwd) {
|
|
|
9907
10150
|
await writeFile8(join11(pluginDir, name), content);
|
|
9908
10151
|
}
|
|
9909
10152
|
}
|
|
9910
|
-
var ASTGRAPH_SRC_DIR = join11(
|
|
10153
|
+
var ASTGRAPH_SRC_DIR = join11(dirname9(fileURLToPath(import.meta.url)), "astgraph");
|
|
9911
10154
|
async function copyAstgraphPlugin(cwd) {
|
|
9912
10155
|
const pluginDir = join11(cwd, ".flavor", "plugins", "astgraph");
|
|
9913
10156
|
try {
|
|
@@ -9934,7 +10177,7 @@ async function initializeFlavor(cwd) {
|
|
|
9934
10177
|
await createExampleFlavorConfig(cwd);
|
|
9935
10178
|
const facts = await inspectProject(cwd);
|
|
9936
10179
|
const path = join11(cwd, "FLAVOR.md");
|
|
9937
|
-
const root = await
|
|
10180
|
+
const root = await realpath7(cwd);
|
|
9938
10181
|
await assertSafeManagedPath(path, root);
|
|
9939
10182
|
let existing;
|
|
9940
10183
|
try {
|
|
@@ -9968,8 +10211,8 @@ function buildLoopCyclePrompt(input) {
|
|
|
9968
10211
|
}
|
|
9969
10212
|
|
|
9970
10213
|
// src/loop/types.ts
|
|
9971
|
-
import { z as
|
|
9972
|
-
var LoopStatusSchema =
|
|
10214
|
+
import { z as z19 } from "zod";
|
|
10215
|
+
var LoopStatusSchema = z19.enum([
|
|
9973
10216
|
"running",
|
|
9974
10217
|
"succeeded",
|
|
9975
10218
|
"failed",
|
|
@@ -9979,65 +10222,65 @@ var LoopStatusSchema = z18.enum([
|
|
|
9979
10222
|
"no_progress",
|
|
9980
10223
|
"needs_human"
|
|
9981
10224
|
]);
|
|
9982
|
-
var LoopApprovalSchema =
|
|
9983
|
-
dimension:
|
|
9984
|
-
previousCheckpoint:
|
|
9985
|
-
newCheckpoint:
|
|
9986
|
-
usage:
|
|
9987
|
-
approvedAt:
|
|
10225
|
+
var LoopApprovalSchema = z19.object({
|
|
10226
|
+
dimension: z19.enum(["cycles", "tokens"]),
|
|
10227
|
+
previousCheckpoint: z19.number().int().nonnegative(),
|
|
10228
|
+
newCheckpoint: z19.number().int().positive(),
|
|
10229
|
+
usage: z19.number().int().nonnegative(),
|
|
10230
|
+
approvedAt: z19.string().datetime({ offset: true })
|
|
9988
10231
|
}).strict();
|
|
9989
|
-
var LoopVerificationCommandSchema =
|
|
9990
|
-
command:
|
|
9991
|
-
args:
|
|
9992
|
-
exitCode:
|
|
9993
|
-
stdout:
|
|
9994
|
-
stderr:
|
|
9995
|
-
truncated:
|
|
10232
|
+
var LoopVerificationCommandSchema = z19.object({
|
|
10233
|
+
command: z19.string().min(1),
|
|
10234
|
+
args: z19.array(z19.string()),
|
|
10235
|
+
exitCode: z19.number().int().nullable(),
|
|
10236
|
+
stdout: z19.string(),
|
|
10237
|
+
stderr: z19.string(),
|
|
10238
|
+
truncated: z19.boolean()
|
|
9996
10239
|
}).strict();
|
|
9997
|
-
var LoopVerificationEvidenceSchema =
|
|
9998
|
-
passed:
|
|
9999
|
-
commands:
|
|
10000
|
-
summary:
|
|
10240
|
+
var LoopVerificationEvidenceSchema = z19.object({
|
|
10241
|
+
passed: z19.boolean(),
|
|
10242
|
+
commands: z19.array(LoopVerificationCommandSchema),
|
|
10243
|
+
summary: z19.string()
|
|
10001
10244
|
}).strict();
|
|
10002
|
-
var LoopCycleEvidenceSchema =
|
|
10003
|
-
cycle:
|
|
10004
|
-
startedAt:
|
|
10005
|
-
completedAt:
|
|
10006
|
-
inputTokens:
|
|
10007
|
-
outputTokens:
|
|
10008
|
-
workspaceFingerprint:
|
|
10245
|
+
var LoopCycleEvidenceSchema = z19.object({
|
|
10246
|
+
cycle: z19.number().int().positive(),
|
|
10247
|
+
startedAt: z19.string().datetime({ offset: true }),
|
|
10248
|
+
completedAt: z19.string().datetime({ offset: true }),
|
|
10249
|
+
inputTokens: z19.number().int().nonnegative(),
|
|
10250
|
+
outputTokens: z19.number().int().nonnegative(),
|
|
10251
|
+
workspaceFingerprint: z19.string(),
|
|
10009
10252
|
verification: LoopVerificationEvidenceSchema
|
|
10010
10253
|
}).strict();
|
|
10011
|
-
var LoopStateSchema =
|
|
10012
|
-
version:
|
|
10013
|
-
loopId:
|
|
10014
|
-
goal:
|
|
10015
|
-
workspace:
|
|
10016
|
-
createdAt:
|
|
10017
|
-
updatedAt:
|
|
10254
|
+
var LoopStateSchema = z19.object({
|
|
10255
|
+
version: z19.literal(1),
|
|
10256
|
+
loopId: z19.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/),
|
|
10257
|
+
goal: z19.string().trim().min(1),
|
|
10258
|
+
workspace: z19.string().min(1),
|
|
10259
|
+
createdAt: z19.string().datetime({ offset: true }),
|
|
10260
|
+
updatedAt: z19.string().datetime({ offset: true }),
|
|
10018
10261
|
status: LoopStatusSchema,
|
|
10019
|
-
config:
|
|
10020
|
-
cycleStep:
|
|
10021
|
-
tokenStep:
|
|
10022
|
-
isolation:
|
|
10262
|
+
config: z19.object({
|
|
10263
|
+
cycleStep: z19.number().int().positive(),
|
|
10264
|
+
tokenStep: z19.number().int().positive(),
|
|
10265
|
+
isolation: z19.literal("auto")
|
|
10023
10266
|
}).strict(),
|
|
10024
|
-
budget:
|
|
10025
|
-
cyclesUsed:
|
|
10026
|
-
inputTokens:
|
|
10027
|
-
outputTokens:
|
|
10028
|
-
cycleCheckpoint:
|
|
10029
|
-
tokenCheckpoint:
|
|
10030
|
-
approvals:
|
|
10267
|
+
budget: z19.object({
|
|
10268
|
+
cyclesUsed: z19.number().int().nonnegative(),
|
|
10269
|
+
inputTokens: z19.number().int().nonnegative(),
|
|
10270
|
+
outputTokens: z19.number().int().nonnegative(),
|
|
10271
|
+
cycleCheckpoint: z19.number().int().positive(),
|
|
10272
|
+
tokenCheckpoint: z19.number().int().positive(),
|
|
10273
|
+
approvals: z19.array(LoopApprovalSchema)
|
|
10031
10274
|
}).strict(),
|
|
10032
|
-
cycles:
|
|
10033
|
-
terminalReason:
|
|
10275
|
+
cycles: z19.array(LoopCycleEvidenceSchema),
|
|
10276
|
+
terminalReason: z19.string().optional()
|
|
10034
10277
|
}).strict();
|
|
10035
|
-
var LoopEventSchema =
|
|
10036
|
-
version:
|
|
10037
|
-
type:
|
|
10038
|
-
timestamp:
|
|
10039
|
-
loopId:
|
|
10040
|
-
payload:
|
|
10278
|
+
var LoopEventSchema = z19.object({
|
|
10279
|
+
version: z19.literal(1),
|
|
10280
|
+
type: z19.enum(["created", "cycle_started", "cycle_completed", "verification", "budget_approved", "terminal"]),
|
|
10281
|
+
timestamp: z19.string().datetime({ offset: true }),
|
|
10282
|
+
loopId: z19.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/),
|
|
10283
|
+
payload: z19.record(z19.string(), z19.unknown())
|
|
10041
10284
|
}).strict();
|
|
10042
10285
|
|
|
10043
10286
|
// src/loop/budget.ts
|
|
@@ -10353,15 +10596,15 @@ import { writeFile as writeFile9, mkdir as mkdir10 } from "fs/promises";
|
|
|
10353
10596
|
import { join as join13 } from "path";
|
|
10354
10597
|
|
|
10355
10598
|
// src/goal/types.ts
|
|
10356
|
-
import { z as
|
|
10357
|
-
var GoalPhaseSchema =
|
|
10599
|
+
import { z as z20 } from "zod";
|
|
10600
|
+
var GoalPhaseSchema = z20.enum([
|
|
10358
10601
|
"idle",
|
|
10359
10602
|
"planning",
|
|
10360
10603
|
"executing",
|
|
10361
10604
|
"verifying",
|
|
10362
10605
|
"complete"
|
|
10363
10606
|
]);
|
|
10364
|
-
var GoalStatusSchema =
|
|
10607
|
+
var GoalStatusSchema = z20.enum([
|
|
10365
10608
|
"active",
|
|
10366
10609
|
"paused",
|
|
10367
10610
|
"achieved",
|
|
@@ -10369,43 +10612,43 @@ var GoalStatusSchema = z19.enum([
|
|
|
10369
10612
|
"blocked",
|
|
10370
10613
|
"failed"
|
|
10371
10614
|
]);
|
|
10372
|
-
var AcceptanceCriterionSchema =
|
|
10373
|
-
id:
|
|
10374
|
-
description:
|
|
10375
|
-
type:
|
|
10615
|
+
var AcceptanceCriterionSchema = z20.object({
|
|
10616
|
+
id: z20.number().int().positive(),
|
|
10617
|
+
description: z20.string().min(1),
|
|
10618
|
+
type: z20.enum(["gating", "evidence"])
|
|
10376
10619
|
}).strict();
|
|
10377
|
-
var PlanSchema =
|
|
10378
|
-
kind:
|
|
10379
|
-
criteria:
|
|
10380
|
-
verificationPlan:
|
|
10381
|
-
nonGoals:
|
|
10382
|
-
assumedScope:
|
|
10383
|
-
approach:
|
|
10384
|
-
checklist:
|
|
10620
|
+
var PlanSchema = z20.object({
|
|
10621
|
+
kind: z20.enum(["code-change", "analysis", "research"]),
|
|
10622
|
+
criteria: z20.array(AcceptanceCriterionSchema).min(1).max(32),
|
|
10623
|
+
verificationPlan: z20.string().min(1),
|
|
10624
|
+
nonGoals: z20.array(z20.string()).max(16),
|
|
10625
|
+
assumedScope: z20.array(z20.string()).max(16),
|
|
10626
|
+
approach: z20.string().optional(),
|
|
10627
|
+
checklist: z20.array(z20.string()).max(32).optional()
|
|
10385
10628
|
}).strict();
|
|
10386
|
-
var GapSchema =
|
|
10387
|
-
criterion:
|
|
10388
|
-
description:
|
|
10389
|
-
blocking:
|
|
10629
|
+
var GapSchema = z20.object({
|
|
10630
|
+
criterion: z20.string().min(1),
|
|
10631
|
+
description: z20.string().min(1),
|
|
10632
|
+
blocking: z20.enum(["model_fixable", "contradiction", "unverifiable"])
|
|
10390
10633
|
}).strict();
|
|
10391
|
-
var VerdictSchema =
|
|
10392
|
-
refuted:
|
|
10393
|
-
gaps:
|
|
10634
|
+
var VerdictSchema = z20.object({
|
|
10635
|
+
refuted: z20.boolean(),
|
|
10636
|
+
gaps: z20.array(GapSchema)
|
|
10394
10637
|
}).strict();
|
|
10395
|
-
var GoalStateSchema =
|
|
10396
|
-
id:
|
|
10397
|
-
objective:
|
|
10638
|
+
var GoalStateSchema = z20.object({
|
|
10639
|
+
id: z20.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/),
|
|
10640
|
+
objective: z20.string().min(1),
|
|
10398
10641
|
phase: GoalPhaseSchema,
|
|
10399
10642
|
status: GoalStatusSchema,
|
|
10400
10643
|
plan: PlanSchema.nullable(),
|
|
10401
|
-
planPath:
|
|
10402
|
-
verifyRounds:
|
|
10403
|
-
workerRounds:
|
|
10404
|
-
lastGaps:
|
|
10405
|
-
gapFingerprint:
|
|
10406
|
-
stallStreak:
|
|
10407
|
-
createdAt:
|
|
10408
|
-
updatedAt:
|
|
10644
|
+
planPath: z20.string().nullable(),
|
|
10645
|
+
verifyRounds: z20.number().int().min(0),
|
|
10646
|
+
workerRounds: z20.number().int().min(0),
|
|
10647
|
+
lastGaps: z20.array(GapSchema),
|
|
10648
|
+
gapFingerprint: z20.string(),
|
|
10649
|
+
stallStreak: z20.number().int().min(0),
|
|
10650
|
+
createdAt: z20.string().datetime({ offset: true }),
|
|
10651
|
+
updatedAt: z20.string().datetime({ offset: true })
|
|
10409
10652
|
}).strict();
|
|
10410
10653
|
|
|
10411
10654
|
// src/goal/planner.ts
|
|
@@ -10966,7 +11209,7 @@ function formatPriorGaps(gaps) {
|
|
|
10966
11209
|
import { constants as constants2 } from "fs";
|
|
10967
11210
|
import { randomUUID as randomUUID7 } from "crypto";
|
|
10968
11211
|
import { lstat as lstat5, mkdir as mkdir11, open as open5, rename as rename4, rm as rm6 } from "fs/promises";
|
|
10969
|
-
import { dirname as
|
|
11212
|
+
import { dirname as dirname10, join as join14, relative as relative9, resolve as resolve10, sep as sep8 } from "path";
|
|
10970
11213
|
var DEFAULT_MAX_BYTES = 1024 * 1024;
|
|
10971
11214
|
var GoalStore = class {
|
|
10972
11215
|
#workspace;
|
|
@@ -10979,7 +11222,7 @@ var GoalStore = class {
|
|
|
10979
11222
|
}
|
|
10980
11223
|
async save(input) {
|
|
10981
11224
|
const state = GoalStateSchema.parse(input);
|
|
10982
|
-
await assertNoSymlink(this.#workspace,
|
|
11225
|
+
await assertNoSymlink(this.#workspace, dirname10(this.#root));
|
|
10983
11226
|
await mkdir11(this.#root, { recursive: true, mode: 448 });
|
|
10984
11227
|
await assertNoSymlink(this.#workspace, this.#root);
|
|
10985
11228
|
const target = join14(this.#root, `${state.id}.json`);
|
|
@@ -11013,7 +11256,7 @@ async function assertNoSymlink(root, target) {
|
|
|
11013
11256
|
const chain = [];
|
|
11014
11257
|
while (cursor !== stop) {
|
|
11015
11258
|
chain.push(cursor);
|
|
11016
|
-
cursor =
|
|
11259
|
+
cursor = dirname10(cursor);
|
|
11017
11260
|
}
|
|
11018
11261
|
for (const path of chain.reverse()) {
|
|
11019
11262
|
try {
|
|
@@ -11099,8 +11342,8 @@ async function ensureWorktreeDirectoryIgnored(root) {
|
|
|
11099
11342
|
|
|
11100
11343
|
// src/loop/store.ts
|
|
11101
11344
|
import { constants as constants3 } from "fs";
|
|
11102
|
-
import { lstat as lstat6, mkdir as mkdir13, open as open6, readFile as readFile11, realpath as
|
|
11103
|
-
import { dirname as
|
|
11345
|
+
import { lstat as lstat6, mkdir as mkdir13, open as open6, readFile as readFile11, realpath as realpath8, rename as rename5, rm as rm7, stat as stat6 } from "fs/promises";
|
|
11346
|
+
import { dirname as dirname11, join as join16, relative as relative10, resolve as resolve12, sep as sep9 } from "path";
|
|
11104
11347
|
import { randomUUID as randomUUID8 } from "crypto";
|
|
11105
11348
|
var LOOP_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
11106
11349
|
var DEFAULT_MAX_BYTES2 = 5 * 1024 * 1024;
|
|
@@ -11182,7 +11425,7 @@ var LoopStore = class {
|
|
|
11182
11425
|
}
|
|
11183
11426
|
async #prepare(loopId) {
|
|
11184
11427
|
validateId(loopId);
|
|
11185
|
-
await assertNoSymlink2(this.#workspace,
|
|
11428
|
+
await assertNoSymlink2(this.#workspace, dirname11(this.#root));
|
|
11186
11429
|
await mkdir13(this.#root, { recursive: true, mode: 448 });
|
|
11187
11430
|
await assertNoSymlink2(this.#workspace, this.#root);
|
|
11188
11431
|
const directory = join16(this.#root, loopId);
|
|
@@ -11215,7 +11458,7 @@ async function assertNoSymlink2(root, target) {
|
|
|
11215
11458
|
const chain = [];
|
|
11216
11459
|
while (cursor !== stop) {
|
|
11217
11460
|
chain.push(cursor);
|
|
11218
|
-
cursor =
|
|
11461
|
+
cursor = dirname11(cursor);
|
|
11219
11462
|
}
|
|
11220
11463
|
for (const path of chain.reverse()) {
|
|
11221
11464
|
try {
|
|
@@ -11231,7 +11474,7 @@ function isWithin2(root, path) {
|
|
|
11231
11474
|
}
|
|
11232
11475
|
async function canonical(path) {
|
|
11233
11476
|
try {
|
|
11234
|
-
return await
|
|
11477
|
+
return await realpath8(resolve12(path));
|
|
11235
11478
|
} catch {
|
|
11236
11479
|
return resolve12(path);
|
|
11237
11480
|
}
|
|
@@ -11247,19 +11490,19 @@ import { join as join17 } from "path";
|
|
|
11247
11490
|
// src/tools/shell.ts
|
|
11248
11491
|
import { spawn as spawn3, spawnSync } from "child_process";
|
|
11249
11492
|
import { isAbsolute as isAbsolute8, relative as relative11, resolve as resolve13, sep as sep10 } from "path";
|
|
11250
|
-
import { z as
|
|
11493
|
+
import { z as z22 } from "zod";
|
|
11251
11494
|
|
|
11252
11495
|
// src/tools/jobs.ts
|
|
11253
|
-
import { z as
|
|
11254
|
-
var JobId =
|
|
11255
|
-
var ReadInput =
|
|
11256
|
-
var IdInput =
|
|
11496
|
+
import { z as z21 } from "zod";
|
|
11497
|
+
var JobId = z21.string().regex(/^job-[a-f0-9-]+$/);
|
|
11498
|
+
var ReadInput = z21.object({ id: JobId, cursor: z21.coerce.number().int().min(0).optional() });
|
|
11499
|
+
var IdInput = z21.object({ id: JobId });
|
|
11257
11500
|
function createJobTools(registry) {
|
|
11258
11501
|
const tools = [
|
|
11259
11502
|
{
|
|
11260
11503
|
name: "JobList",
|
|
11261
11504
|
description: "List background jobs owned by this agent",
|
|
11262
|
-
inputSchema:
|
|
11505
|
+
inputSchema: z21.object({}),
|
|
11263
11506
|
paths: () => [],
|
|
11264
11507
|
execute: async (_input, _signal, context) => registry.list(owner(context)),
|
|
11265
11508
|
presentResult: (output) => jobListPresentation(output)
|
|
@@ -11334,14 +11577,14 @@ var ELLIPSIS = "\u2026";
|
|
|
11334
11577
|
var TERMINATION_GRACE_MS = 250;
|
|
11335
11578
|
var TERMINATION_FAILURE_MS = 5e3;
|
|
11336
11579
|
var STREAM_CLOSE_GRACE_MS = 500;
|
|
11337
|
-
var ShellInput =
|
|
11338
|
-
command:
|
|
11339
|
-
args:
|
|
11340
|
-
cwd:
|
|
11341
|
-
timeoutMs:
|
|
11580
|
+
var ShellInput = z22.object({
|
|
11581
|
+
command: z22.string().min(1),
|
|
11582
|
+
args: z22.array(z22.string()),
|
|
11583
|
+
cwd: z22.string().min(1).nullable().optional(),
|
|
11584
|
+
timeoutMs: z22.coerce.number().int().positive().max(864e5).nullable().optional(),
|
|
11342
11585
|
// Accepts booleans and their string forms (weak-typed models emit "true");
|
|
11343
11586
|
// kept transform-free so the schema converts to JSON Schema for providers.
|
|
11344
|
-
background:
|
|
11587
|
+
background: z22.union([z22.boolean(), z22.string().refine((value) => value === "true" || value === "false")]).optional()
|
|
11345
11588
|
});
|
|
11346
11589
|
function normalizeShellCommand(input) {
|
|
11347
11590
|
const { command, args } = input;
|
|
@@ -11943,7 +12186,7 @@ function isEnvTruthy(value) {
|
|
|
11943
12186
|
|
|
11944
12187
|
// src/utils/log.ts
|
|
11945
12188
|
import { appendFile as appendFile3, mkdir as mkdir14 } from "fs/promises";
|
|
11946
|
-
import { dirname as
|
|
12189
|
+
import { dirname as dirname12, join as join18, resolve as resolve14 } from "path";
|
|
11947
12190
|
var pending = Promise.resolve();
|
|
11948
12191
|
var usagePending = Promise.resolve();
|
|
11949
12192
|
function usageLogPath() {
|
|
@@ -11962,7 +12205,7 @@ async function appendUsageLog(line) {
|
|
|
11962
12205
|
usagePending = usagePending.catch(() => void 0).then(async () => {
|
|
11963
12206
|
try {
|
|
11964
12207
|
const path = usageLogPath();
|
|
11965
|
-
await mkdir14(
|
|
12208
|
+
await mkdir14(dirname12(path), { recursive: true, mode: 448 });
|
|
11966
12209
|
const flag = truncateOnNextAppend ? "w" : "a";
|
|
11967
12210
|
truncateOnNextAppend = false;
|
|
11968
12211
|
await appendFile3(path, `${line}
|
|
@@ -11990,7 +12233,7 @@ var AuditLogger = class {
|
|
|
11990
12233
|
}
|
|
11991
12234
|
async #write(line) {
|
|
11992
12235
|
try {
|
|
11993
|
-
await mkdir14(
|
|
12236
|
+
await mkdir14(dirname12(this.#path), { recursive: true, mode: 448 });
|
|
11994
12237
|
await appendFile3(this.#path, line, { encoding: "utf8", mode: 384, flag: "a" });
|
|
11995
12238
|
} catch {
|
|
11996
12239
|
}
|
|
@@ -12575,7 +12818,7 @@ var ModelRegistry = class {
|
|
|
12575
12818
|
|
|
12576
12819
|
// src/mcp/client.ts
|
|
12577
12820
|
import { createHash as createHash7 } from "crypto";
|
|
12578
|
-
import { z as
|
|
12821
|
+
import { z as z23 } from "zod";
|
|
12579
12822
|
var McpManager = class {
|
|
12580
12823
|
#workspace;
|
|
12581
12824
|
#clientFactory;
|
|
@@ -12711,7 +12954,7 @@ async function listAllTools(client) {
|
|
|
12711
12954
|
function createMcpToolDefinition(serverName, timeoutMs, client, remote) {
|
|
12712
12955
|
if (remote.name.length === 0) throw new Error("MCP tool name must not be empty");
|
|
12713
12956
|
if (!isRecord4(remote.inputSchema)) throw new Error(`MCP tool "${remote.name}" has no JSON object input schema`);
|
|
12714
|
-
const inputSchema =
|
|
12957
|
+
const inputSchema = z23.fromJSONSchema(
|
|
12715
12958
|
remote.inputSchema
|
|
12716
12959
|
);
|
|
12717
12960
|
return {
|
|
@@ -12772,12 +13015,12 @@ import {
|
|
|
12772
13015
|
|
|
12773
13016
|
// src/utils/version.ts
|
|
12774
13017
|
import { readFileSync as readFileSync2 } from "fs";
|
|
12775
|
-
import { dirname as
|
|
13018
|
+
import { dirname as dirname13, join as join19 } from "path";
|
|
12776
13019
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
12777
13020
|
var cached;
|
|
12778
13021
|
function packageVersion() {
|
|
12779
13022
|
if (cached !== void 0) return cached;
|
|
12780
|
-
let directory =
|
|
13023
|
+
let directory = dirname13(fileURLToPath2(import.meta.url));
|
|
12781
13024
|
for (; ; ) {
|
|
12782
13025
|
try {
|
|
12783
13026
|
const manifest = JSON.parse(readFileSync2(join19(directory, "package.json"), "utf8"));
|
|
@@ -12787,7 +13030,7 @@ function packageVersion() {
|
|
|
12787
13030
|
}
|
|
12788
13031
|
} catch {
|
|
12789
13032
|
}
|
|
12790
|
-
const parent =
|
|
13033
|
+
const parent = dirname13(directory);
|
|
12791
13034
|
if (parent === directory) break;
|
|
12792
13035
|
directory = parent;
|
|
12793
13036
|
}
|
|
@@ -13147,7 +13390,7 @@ function escapeHtml(text) {
|
|
|
13147
13390
|
}
|
|
13148
13391
|
|
|
13149
13392
|
// src/auth/store.ts
|
|
13150
|
-
import { dirname as
|
|
13393
|
+
import { dirname as dirname14 } from "path";
|
|
13151
13394
|
async function retainOnlyCredentials(store, keepCredentialId) {
|
|
13152
13395
|
const tokens2 = await store.load();
|
|
13153
13396
|
const retained = Object.fromEntries(Object.entries(tokens2).filter(([id]) => id === keepCredentialId));
|
|
@@ -13158,7 +13401,7 @@ function createFileTokenStore(filePath) {
|
|
|
13158
13401
|
const store = {
|
|
13159
13402
|
tokens: {},
|
|
13160
13403
|
async load() {
|
|
13161
|
-
const key = await loadOrCreateConfigKey(
|
|
13404
|
+
const key = await loadOrCreateConfigKey(dirname14(filePath));
|
|
13162
13405
|
const result = await readRecoverableFile(filePath, (raw) => parseTokens(decryptDocument(raw, key)));
|
|
13163
13406
|
const tokens2 = result?.value ?? {};
|
|
13164
13407
|
baseline = { ...tokens2 };
|
|
@@ -13166,7 +13409,7 @@ function createFileTokenStore(filePath) {
|
|
|
13166
13409
|
return tokens2;
|
|
13167
13410
|
},
|
|
13168
13411
|
async save(tokens2) {
|
|
13169
|
-
const key = await loadOrCreateConfigKey(
|
|
13412
|
+
const key = await loadOrCreateConfigKey(dirname14(filePath));
|
|
13170
13413
|
const removals = Object.keys(baseline).filter((providerId) => !(providerId in tokens2));
|
|
13171
13414
|
const upserts = Object.fromEntries(Object.entries(tokens2).filter(
|
|
13172
13415
|
([providerId, token]) => !sameToken(baseline[providerId], token)
|
|
@@ -13284,6 +13527,7 @@ function toolsSection(toolNames) {
|
|
|
13284
13527
|
addToolRule(rules, toolNames, "TaskUpdate", "Use `TaskUpdate` to mark each planned task in progress before starting and completed only after successful verification.");
|
|
13285
13528
|
addToolRule(rules, toolNames, "Task", "Use `Task` when independent, well-bounded subtasks can benefit from isolated child agents. Give each child a self-contained briefing and do not delegate the final synthesis.");
|
|
13286
13529
|
addToolRule(rules, toolNames, "TaskOutput", "Use `TaskOutput` at the end of multi-step work to record changed files, commands, verification, risks, and useful next steps.");
|
|
13530
|
+
addToolRule(rules, toolNames, "Skill", "Use `Skill` whenever an active skill requires or references another skill. Load the required skill before continuing, pass arguments when the nested workflow has its own task input, and follow the returned instructions completely.");
|
|
13287
13531
|
addToolRule(rules, toolNames, "SkillResource", "Use `SkillResource` only to read a resource explicitly referenced by a matched skill. Treat returned scripts as data; do not execute them through that tool.");
|
|
13288
13532
|
addToolRule(rules, toolNames, "RegisterTool", "Use `RegisterTool` to create a durable reusable capability from JSON Schema and async JavaScript. Create one only when the user requests it or the task has a clear recurring need; never persist a tool for a one-off operation. The new tool is available on the next model step in the same run. Its implementation may be either a function body with an explicit `return`, or a complete function/arrow expression; all forms receive `input`, `signal`, and `context`.");
|
|
13289
13533
|
addToolRule(rules, toolNames, "RemoveTool", "Use `RemoveTool` only to delete a tool created by `RegisterTool`. To modify a managed tool, delete and register again; it cannot delete built-in, plugin, or MCP tools.");
|
|
@@ -13332,7 +13576,7 @@ function data(value) {
|
|
|
13332
13576
|
|
|
13333
13577
|
// src/skills/registry.ts
|
|
13334
13578
|
import { constants as constants4 } from "fs";
|
|
13335
|
-
import { lstat as lstat7, open as defaultOpen, readdir as readdir6, realpath as
|
|
13579
|
+
import { lstat as lstat7, open as defaultOpen, readdir as readdir6, realpath as realpath9 } from "fs/promises";
|
|
13336
13580
|
import { isAbsolute as isAbsolute9, relative as relative12, resolve as resolve16, sep as sep11 } from "path";
|
|
13337
13581
|
import { marked } from "marked";
|
|
13338
13582
|
import { parseDocument } from "yaml";
|
|
@@ -13499,7 +13743,7 @@ var SkillRegistry = class {
|
|
|
13499
13743
|
try {
|
|
13500
13744
|
const rootInfo = await lstat7(root);
|
|
13501
13745
|
if (rootInfo.isSymbolicLink() || !rootInfo.isDirectory()) throw new Error("Skill root must be a real directory");
|
|
13502
|
-
physicalRoot = await
|
|
13746
|
+
physicalRoot = await realpath9(root);
|
|
13503
13747
|
entries = await readdir6(root, { withFileTypes: true });
|
|
13504
13748
|
} catch (error) {
|
|
13505
13749
|
if (isMissing(error)) continue;
|
|
@@ -13512,7 +13756,7 @@ var SkillRegistry = class {
|
|
|
13512
13756
|
try {
|
|
13513
13757
|
if (entry2.isSymbolicLink()) throw new Error("Symlinked skill directories are not allowed");
|
|
13514
13758
|
if (!entry2.isDirectory()) continue;
|
|
13515
|
-
const physicalSkillRoot = await
|
|
13759
|
+
const physicalSkillRoot = await realpath9(skillRoot);
|
|
13516
13760
|
if (!isWithin3(physicalRoot, physicalSkillRoot)) throw new Error("Skill directory escapes its registry root");
|
|
13517
13761
|
const skillFile = resolve16(skillRoot, "SKILL.md");
|
|
13518
13762
|
const parsed = await readFrontmatterFile(
|
|
@@ -13654,7 +13898,7 @@ async function openVerifiedFile(path, root, label, opener, expected) {
|
|
|
13654
13898
|
const initial = await lstat7(path, { bigint: true });
|
|
13655
13899
|
if (initial.isSymbolicLink()) throw new Error(`${label} symlinks are not allowed`);
|
|
13656
13900
|
assertRegular(initial, label);
|
|
13657
|
-
const canonical3 = await
|
|
13901
|
+
const canonical3 = await realpath9(path);
|
|
13658
13902
|
if (!isWithin3(root, canonical3)) throw new Error(`${label} escapes the skill root`);
|
|
13659
13903
|
const noFollow = typeof constants4.O_NOFOLLOW === "number" ? constants4.O_NOFOLLOW : 0;
|
|
13660
13904
|
const handle = await opener(canonical3, constants4.O_RDONLY | noFollow);
|
|
@@ -13763,11 +14007,97 @@ function score(metadata, query) {
|
|
|
13763
14007
|
}
|
|
13764
14008
|
|
|
13765
14009
|
// src/skills/tool.ts
|
|
13766
|
-
import { z as
|
|
13767
|
-
|
|
13768
|
-
|
|
13769
|
-
|
|
14010
|
+
import { z as z24 } from "zod";
|
|
14011
|
+
|
|
14012
|
+
// src/skills/arguments.ts
|
|
14013
|
+
function expandSkillArguments(body, argumentsText) {
|
|
14014
|
+
const values = splitSkillArguments(argumentsText);
|
|
14015
|
+
const hasPlaceholder = /\$ARGUMENTS(?:\[\d+\])?|\$\d+/.test(body);
|
|
14016
|
+
let expanded = body.replace(/\$ARGUMENTS\[(\d+)\]/g, (_match, index) => values[Number(index)] ?? "");
|
|
14017
|
+
expanded = expanded.replace(/\$(\d+)/g, (_match, index) => values[Number(index)] ?? "");
|
|
14018
|
+
expanded = expanded.replace(/\$ARGUMENTS/g, argumentsText);
|
|
14019
|
+
if (!hasPlaceholder && argumentsText.trim() !== "") {
|
|
14020
|
+
expanded = `${expanded.trimEnd()}
|
|
14021
|
+
|
|
14022
|
+
ARGUMENTS: ${argumentsText}`;
|
|
14023
|
+
}
|
|
14024
|
+
return expanded;
|
|
14025
|
+
}
|
|
14026
|
+
function splitSkillArguments(input) {
|
|
14027
|
+
const result = [];
|
|
14028
|
+
let current = "";
|
|
14029
|
+
let quote;
|
|
14030
|
+
let started = false;
|
|
14031
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
14032
|
+
const character = input[index] ?? "";
|
|
14033
|
+
const next = input[index + 1];
|
|
14034
|
+
if (character === "\\" && quote !== "'" && next !== void 0 && (/\s/u.test(next) || next === "\\" || next === '"' || quote === void 0 && next === "'")) {
|
|
14035
|
+
current += next;
|
|
14036
|
+
index += 1;
|
|
14037
|
+
started = true;
|
|
14038
|
+
continue;
|
|
14039
|
+
}
|
|
14040
|
+
if (quote !== void 0) {
|
|
14041
|
+
if (character === quote) quote = void 0;
|
|
14042
|
+
else current += character;
|
|
14043
|
+
started = true;
|
|
14044
|
+
continue;
|
|
14045
|
+
}
|
|
14046
|
+
if (character === "'" || character === '"') {
|
|
14047
|
+
quote = character;
|
|
14048
|
+
started = true;
|
|
14049
|
+
continue;
|
|
14050
|
+
}
|
|
14051
|
+
if (/\s/u.test(character)) {
|
|
14052
|
+
if (started) {
|
|
14053
|
+
result.push(current);
|
|
14054
|
+
current = "";
|
|
14055
|
+
started = false;
|
|
14056
|
+
}
|
|
14057
|
+
continue;
|
|
14058
|
+
}
|
|
14059
|
+
current += character;
|
|
14060
|
+
started = true;
|
|
14061
|
+
}
|
|
14062
|
+
if (started) result.push(current);
|
|
14063
|
+
return result;
|
|
14064
|
+
}
|
|
14065
|
+
|
|
14066
|
+
// src/skills/tool.ts
|
|
14067
|
+
var SkillInput = z24.object({
|
|
14068
|
+
skill: z24.string().min(1),
|
|
14069
|
+
arguments: z24.string().optional()
|
|
13770
14070
|
}).strict();
|
|
14071
|
+
var SkillResourceInput = z24.object({
|
|
14072
|
+
skill: z24.string().min(1),
|
|
14073
|
+
reference: z24.string().min(1)
|
|
14074
|
+
}).strict();
|
|
14075
|
+
function createSkillTool(registry) {
|
|
14076
|
+
return {
|
|
14077
|
+
name: "Skill",
|
|
14078
|
+
description: "Load another discovered skill by name so composable workflows can follow its complete instructions; optional arguments use Claude-compatible $ARGUMENTS substitution",
|
|
14079
|
+
inputSchema: SkillInput,
|
|
14080
|
+
readOnly: true,
|
|
14081
|
+
paths: () => [],
|
|
14082
|
+
summarize: ({ skill }) => skill,
|
|
14083
|
+
renderForModel: (output) => {
|
|
14084
|
+
const value = output;
|
|
14085
|
+
return `Matched skill: ${value.skill}
|
|
14086
|
+
${value.content}`;
|
|
14087
|
+
},
|
|
14088
|
+
execute: async (input, signal) => {
|
|
14089
|
+
signal.throwIfAborted();
|
|
14090
|
+
const discovered = await registry.discover();
|
|
14091
|
+
const requested = input.skill.trim();
|
|
14092
|
+
const alias = requested.includes(":") ? requested.slice(requested.lastIndexOf(":") + 1) : requested;
|
|
14093
|
+
const skill = discovered.find((candidate) => candidate.name === requested) ?? discovered.find((candidate) => candidate.name === alias);
|
|
14094
|
+
if (skill === void 0) throw new Error(`Unknown skill: ${input.skill}`);
|
|
14095
|
+
const content = expandSkillArguments(await registry.loadBody(skill), input.arguments ?? "");
|
|
14096
|
+
signal.throwIfAborted();
|
|
14097
|
+
return { skill: skill.name, content };
|
|
14098
|
+
}
|
|
14099
|
+
};
|
|
14100
|
+
}
|
|
13771
14101
|
function createSkillResourceTool(registry) {
|
|
13772
14102
|
return {
|
|
13773
14103
|
name: "SkillResource",
|
|
@@ -13793,10 +14123,10 @@ function createSkillResourceTool(registry) {
|
|
|
13793
14123
|
|
|
13794
14124
|
// src/session/store.ts
|
|
13795
14125
|
import { constants as constants5 } from "fs";
|
|
13796
|
-
import { lstat as lstat8, mkdir as mkdir15, open as open7, readFile as readFile15, readdir as readdir7, realpath as
|
|
13797
|
-
import { basename as basename5, dirname as
|
|
14126
|
+
import { lstat as lstat8, mkdir as mkdir15, open as open7, readFile as readFile15, readdir as readdir7, realpath as realpath10, rename as rename6, rm as rm8, stat as stat7 } from "fs/promises";
|
|
14127
|
+
import { basename as basename5, dirname as dirname15, join as join20, relative as relative13, resolve as resolve17, sep as sep12 } from "path";
|
|
13798
14128
|
import { randomUUID as randomUUID9 } from "crypto";
|
|
13799
|
-
import { z as
|
|
14129
|
+
import { z as z25 } from "zod";
|
|
13800
14130
|
|
|
13801
14131
|
// src/ui/transcript.ts
|
|
13802
14132
|
function createTranscriptState() {
|
|
@@ -14329,91 +14659,91 @@ function addText(turn, text, onNewLine = false) {
|
|
|
14329
14659
|
// src/session/store.ts
|
|
14330
14660
|
var SESSION_VERSION = 3;
|
|
14331
14661
|
var DEFAULT_MAX_SESSION_BYTES = 5 * 1024 * 1024;
|
|
14332
|
-
var SessionIdSchema =
|
|
14333
|
-
var IsoDateSchema =
|
|
14334
|
-
var ToolCallSchema =
|
|
14335
|
-
id:
|
|
14336
|
-
name:
|
|
14337
|
-
input:
|
|
14662
|
+
var SessionIdSchema = z25.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/, "Invalid session id");
|
|
14663
|
+
var IsoDateSchema = z25.string().datetime({ offset: true });
|
|
14664
|
+
var ToolCallSchema = z25.object({
|
|
14665
|
+
id: z25.string().min(1).max(256),
|
|
14666
|
+
name: z25.string().min(1).max(256),
|
|
14667
|
+
input: z25.unknown()
|
|
14338
14668
|
}).strict();
|
|
14339
|
-
var TextContentBlockSchema =
|
|
14340
|
-
type:
|
|
14341
|
-
text:
|
|
14669
|
+
var TextContentBlockSchema = z25.object({
|
|
14670
|
+
type: z25.literal("text"),
|
|
14671
|
+
text: z25.string().max(DEFAULT_MAX_SESSION_BYTES)
|
|
14342
14672
|
}).strict();
|
|
14343
|
-
var ImageContentBlockSchema =
|
|
14344
|
-
type:
|
|
14345
|
-
source:
|
|
14346
|
-
mediaType:
|
|
14347
|
-
sha256:
|
|
14348
|
-
bytes:
|
|
14349
|
-
name:
|
|
14673
|
+
var ImageContentBlockSchema = z25.object({
|
|
14674
|
+
type: z25.literal("image"),
|
|
14675
|
+
source: z25.object({ type: z25.literal("file"), path: z25.string().min(1).max(32768) }).strict(),
|
|
14676
|
+
mediaType: z25.enum(["image/png", "image/jpeg", "image/webp"]),
|
|
14677
|
+
sha256: z25.string().regex(/^[a-f0-9]{64}$/),
|
|
14678
|
+
bytes: z25.number().int().positive().max(20 * 1024 * 1024),
|
|
14679
|
+
name: z25.string().min(1).max(255).optional()
|
|
14350
14680
|
}).strict();
|
|
14351
|
-
var UserContentSchema =
|
|
14352
|
-
|
|
14353
|
-
|
|
14681
|
+
var UserContentSchema = z25.union([
|
|
14682
|
+
z25.string().max(DEFAULT_MAX_SESSION_BYTES),
|
|
14683
|
+
z25.array(z25.discriminatedUnion("type", [TextContentBlockSchema, ImageContentBlockSchema])).min(1).max(100)
|
|
14354
14684
|
]);
|
|
14355
14685
|
var MessageMetadataShape = {
|
|
14356
|
-
toolCallId:
|
|
14357
|
-
toolCalls:
|
|
14686
|
+
toolCallId: z25.string().min(1).max(256).optional(),
|
|
14687
|
+
toolCalls: z25.array(ToolCallSchema).max(1e3).optional()
|
|
14358
14688
|
};
|
|
14359
|
-
var MessageSchema =
|
|
14360
|
-
|
|
14361
|
-
|
|
14362
|
-
|
|
14689
|
+
var MessageSchema = z25.discriminatedUnion("role", [
|
|
14690
|
+
z25.object({ role: z25.literal("user"), content: UserContentSchema, ...MessageMetadataShape }).strict(),
|
|
14691
|
+
z25.object({ role: z25.literal("assistant"), content: z25.string().max(DEFAULT_MAX_SESSION_BYTES), ...MessageMetadataShape }).strict(),
|
|
14692
|
+
z25.object({ role: z25.literal("tool"), content: z25.string().max(DEFAULT_MAX_SESSION_BYTES), ...MessageMetadataShape }).strict()
|
|
14363
14693
|
]);
|
|
14364
|
-
var LegacySummarySchema =
|
|
14365
|
-
var CompactBoundarySchema =
|
|
14366
|
-
summary:
|
|
14694
|
+
var LegacySummarySchema = z25.object({ role: z25.literal("system"), content: z25.string().max(DEFAULT_MAX_SESSION_BYTES) }).strict();
|
|
14695
|
+
var CompactBoundarySchema = z25.object({
|
|
14696
|
+
summary: z25.string().min(1).max(DEFAULT_MAX_SESSION_BYTES),
|
|
14367
14697
|
compactedAt: IsoDateSchema
|
|
14368
14698
|
}).strict();
|
|
14369
|
-
var StateSchema =
|
|
14370
|
-
var MemoryLifecycleSchema =
|
|
14371
|
-
status:
|
|
14372
|
-
taskId:
|
|
14373
|
-
messageStart:
|
|
14699
|
+
var StateSchema = z25.enum(["pending", "running", "completed", "failed", "blocked", "cancelled"]);
|
|
14700
|
+
var MemoryLifecycleSchema = z25.object({
|
|
14701
|
+
status: z25.enum(["active", "completed", "abandoned"]),
|
|
14702
|
+
taskId: z25.string().regex(/^memory-[A-Za-z0-9._-]{1,120}$/).optional(),
|
|
14703
|
+
messageStart: z25.number().int().min(0).max(5e4).optional(),
|
|
14374
14704
|
finalizedAt: IsoDateSchema.optional(),
|
|
14375
|
-
transcriptHash:
|
|
14705
|
+
transcriptHash: z25.string().regex(/^[a-f0-9]{64}$/).optional()
|
|
14376
14706
|
}).strict();
|
|
14377
|
-
var SessionBaseSchema =
|
|
14707
|
+
var SessionBaseSchema = z25.object({
|
|
14378
14708
|
sessionId: SessionIdSchema,
|
|
14379
14709
|
createdAt: IsoDateSchema,
|
|
14380
14710
|
updatedAt: IsoDateSchema,
|
|
14381
|
-
workspace:
|
|
14382
|
-
tasks:
|
|
14711
|
+
workspace: z25.object({ path: z25.string().min(1).max(32768) }).strict(),
|
|
14712
|
+
tasks: z25.object({
|
|
14383
14713
|
plan: TaskPlanSchema.optional(),
|
|
14384
14714
|
graph: TaskGraphSchema.optional(),
|
|
14385
|
-
states:
|
|
14386
|
-
results:
|
|
14715
|
+
states: z25.record(z25.string(), StateSchema),
|
|
14716
|
+
results: z25.record(z25.string(), SubagentResultSchema)
|
|
14387
14717
|
}).strict(),
|
|
14388
|
-
models:
|
|
14718
|
+
models: z25.object({ main: z25.string().min(1).max(1024), subagent: z25.string().min(1).max(1024) }).strict(),
|
|
14389
14719
|
permissionMode: PermissionModeSchema,
|
|
14390
14720
|
memory: MemoryLifecycleSchema.optional()
|
|
14391
14721
|
}).strict();
|
|
14392
14722
|
var SessionDocumentV1Schema = SessionBaseSchema.extend({
|
|
14393
|
-
version:
|
|
14394
|
-
conversation:
|
|
14723
|
+
version: z25.literal(1),
|
|
14724
|
+
conversation: z25.object({
|
|
14395
14725
|
summary: LegacySummarySchema.optional(),
|
|
14396
|
-
messages:
|
|
14726
|
+
messages: z25.array(MessageSchema).max(5e4)
|
|
14397
14727
|
}).strict()
|
|
14398
14728
|
}).strict();
|
|
14399
|
-
var ConversationSchema =
|
|
14729
|
+
var ConversationSchema = z25.object({
|
|
14400
14730
|
compact: CompactBoundarySchema.optional(),
|
|
14401
|
-
messages:
|
|
14731
|
+
messages: z25.array(MessageSchema).max(5e4)
|
|
14402
14732
|
}).strict();
|
|
14403
14733
|
var SessionDocumentV2Schema = SessionBaseSchema.extend({
|
|
14404
|
-
version:
|
|
14734
|
+
version: z25.literal(2),
|
|
14405
14735
|
conversation: ConversationSchema
|
|
14406
14736
|
}).strict();
|
|
14407
|
-
var TranscriptStateSchema =
|
|
14408
|
-
var TimelineSchema =
|
|
14409
|
-
version:
|
|
14737
|
+
var TranscriptStateSchema = z25.custom(isTranscriptState, "Invalid transcript state");
|
|
14738
|
+
var TimelineSchema = z25.object({
|
|
14739
|
+
version: z25.literal(1),
|
|
14410
14740
|
state: TranscriptStateSchema
|
|
14411
14741
|
}).strict();
|
|
14412
14742
|
var SessionDocumentSchema = SessionBaseSchema.extend({
|
|
14413
|
-
version:
|
|
14414
|
-
conversation:
|
|
14743
|
+
version: z25.literal(SESSION_VERSION),
|
|
14744
|
+
conversation: z25.object({
|
|
14415
14745
|
compact: CompactBoundarySchema.optional(),
|
|
14416
|
-
messages:
|
|
14746
|
+
messages: z25.array(MessageSchema).max(5e4)
|
|
14417
14747
|
}).strict(),
|
|
14418
14748
|
timeline: TimelineSchema
|
|
14419
14749
|
}).strict();
|
|
@@ -14589,14 +14919,14 @@ var SessionStore = class {
|
|
|
14589
14919
|
}
|
|
14590
14920
|
}
|
|
14591
14921
|
async #prepareDirectory() {
|
|
14592
|
-
await assertNoSymlink3(this.#workspace,
|
|
14922
|
+
await assertNoSymlink3(this.#workspace, dirname15(this.#sessions));
|
|
14593
14923
|
await mkdir15(this.#sessions, { recursive: true, mode: 448 });
|
|
14594
14924
|
await this.#assertSafeExistingDirectory();
|
|
14595
14925
|
}
|
|
14596
14926
|
async #assertSafeExistingDirectory() {
|
|
14597
14927
|
await assertNoSymlink3(this.#workspace, this.#sessions);
|
|
14598
|
-
const canonicalRoot = await
|
|
14599
|
-
const canonicalSessions = await
|
|
14928
|
+
const canonicalRoot = await realpath10(this.#workspace);
|
|
14929
|
+
const canonicalSessions = await realpath10(this.#sessions);
|
|
14600
14930
|
if (!isWithin4(canonicalRoot, canonicalSessions)) throw new Error("Session directory escapes the workspace");
|
|
14601
14931
|
}
|
|
14602
14932
|
async #quarantine(path) {
|
|
@@ -14753,7 +15083,7 @@ async function assertNoSymlink3(root, target) {
|
|
|
14753
15083
|
const chain = [];
|
|
14754
15084
|
while (cursor !== stop) {
|
|
14755
15085
|
chain.push(cursor);
|
|
14756
|
-
cursor =
|
|
15086
|
+
cursor = dirname15(cursor);
|
|
14757
15087
|
}
|
|
14758
15088
|
for (const path of chain.reverse()) {
|
|
14759
15089
|
try {
|
|
@@ -14769,7 +15099,7 @@ function isWithin4(root, path) {
|
|
|
14769
15099
|
}
|
|
14770
15100
|
async function canonical2(path) {
|
|
14771
15101
|
try {
|
|
14772
|
-
return await
|
|
15102
|
+
return await realpath10(resolve17(path));
|
|
14773
15103
|
} catch {
|
|
14774
15104
|
return resolve17(path);
|
|
14775
15105
|
}
|
|
@@ -14798,13 +15128,13 @@ function sanitize2(input, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
14798
15128
|
// src/session/tree.ts
|
|
14799
15129
|
import { randomUUID as randomUUID11 } from "crypto";
|
|
14800
15130
|
import { mkdir as mkdir17, readFile as readFile17, rename as rename8, writeFile as writeFile11 } from "fs/promises";
|
|
14801
|
-
import { dirname as
|
|
15131
|
+
import { dirname as dirname17, join as join22, resolve as resolve19 } from "path";
|
|
14802
15132
|
|
|
14803
15133
|
// src/session/checkpoint.ts
|
|
14804
15134
|
import { createHash as createHash10, randomUUID as randomUUID10 } from "crypto";
|
|
14805
15135
|
import { execFile as execFile2 } from "child_process";
|
|
14806
15136
|
import { lstat as lstat9, mkdir as mkdir16, open as open8, readFile as readFile16, readdir as readdir8, rename as rename7, rm as rm9, writeFile as writeFile10 } from "fs/promises";
|
|
14807
|
-
import { dirname as
|
|
15137
|
+
import { dirname as dirname16, join as join21, relative as relative14, resolve as resolve18, sep as sep13 } from "path";
|
|
14808
15138
|
var EXCLUDED = /* @__PURE__ */ new Set([".git", ".flavor", "node_modules", "dist", "build", "release", ".worktrees"]);
|
|
14809
15139
|
var MAX_FILE_BYTES = 16 * 1024 * 1024;
|
|
14810
15140
|
var MAX_TOTAL_BYTES = 128 * 1024 * 1024;
|
|
@@ -14890,7 +15220,7 @@ var WorkspaceCheckpointStore = class {
|
|
|
14890
15220
|
for (const file of checkpoint.files) {
|
|
14891
15221
|
const target = contained(this.#workspace, file.path);
|
|
14892
15222
|
const object = objects.get(file.digest);
|
|
14893
|
-
await mkdir16(
|
|
15223
|
+
await mkdir16(dirname16(target), { recursive: true });
|
|
14894
15224
|
const temporary = `${target}.${process.pid}.${randomUUID10()}.tmp`;
|
|
14895
15225
|
await writeFile10(temporary, object, { mode: file.mode });
|
|
14896
15226
|
await rename7(temporary, target);
|
|
@@ -14962,7 +15292,7 @@ function contained(workspace, path) {
|
|
|
14962
15292
|
return absolute;
|
|
14963
15293
|
}
|
|
14964
15294
|
async function atomicJson(path, value) {
|
|
14965
|
-
await mkdir16(
|
|
15295
|
+
await mkdir16(dirname16(path), { recursive: true });
|
|
14966
15296
|
const temporary = `${path}.${process.pid}.${randomUUID10()}.tmp`;
|
|
14967
15297
|
await writeFile10(temporary, `${JSON.stringify(value)}
|
|
14968
15298
|
`, { encoding: "utf8", mode: 384 });
|
|
@@ -15065,7 +15395,7 @@ var SessionHistory = class _SessionHistory {
|
|
|
15065
15395
|
leafId: this.#leafId,
|
|
15066
15396
|
nodes: this.#nodes
|
|
15067
15397
|
};
|
|
15068
|
-
await mkdir17(
|
|
15398
|
+
await mkdir17(dirname17(this.#path), { recursive: true });
|
|
15069
15399
|
const temporary = `${this.#path}.${process.pid}.${randomUUID11()}.tmp`;
|
|
15070
15400
|
await writeFile11(temporary, `${JSON.stringify(document)}
|
|
15071
15401
|
`, { encoding: "utf8", mode: 384 });
|
|
@@ -15093,45 +15423,45 @@ function isCode9(error, code) {
|
|
|
15093
15423
|
// src/sleep/organizer.ts
|
|
15094
15424
|
import { constants as constants6 } from "fs";
|
|
15095
15425
|
import { randomUUID as randomUUID12 } from "crypto";
|
|
15096
|
-
import { lstat as lstat10, mkdir as mkdir18, open as open9, readdir as readdir9, realpath as
|
|
15426
|
+
import { lstat as lstat10, mkdir as mkdir18, open as open9, readdir as readdir9, realpath as realpath11, rename as rename9, rm as rm10 } from "fs/promises";
|
|
15097
15427
|
import { isAbsolute as isAbsolute10, join as join23, relative as relative15, resolve as resolve20, sep as sep14 } from "path";
|
|
15098
|
-
import { z as
|
|
15099
|
-
var DateKeySchema =
|
|
15100
|
-
var ReviewSchema =
|
|
15101
|
-
title:
|
|
15102
|
-
taskSummary:
|
|
15103
|
-
executionReflection:
|
|
15104
|
-
decisionsAndLearnings:
|
|
15105
|
-
openQuestionsAndRisks:
|
|
15106
|
-
tomorrowPlan:
|
|
15107
|
-
toolUsage:
|
|
15108
|
-
totalCalls:
|
|
15109
|
-
shell:
|
|
15110
|
-
fileRead:
|
|
15111
|
-
fileWrite:
|
|
15112
|
-
search:
|
|
15113
|
-
lsp:
|
|
15114
|
-
subagent:
|
|
15115
|
-
other:
|
|
15428
|
+
import { z as z26 } from "zod";
|
|
15429
|
+
var DateKeySchema = z26.string().regex(/^\d{4}-\d{2}-\d{2}$/);
|
|
15430
|
+
var ReviewSchema = z26.object({
|
|
15431
|
+
title: z26.string().min(1).max(120),
|
|
15432
|
+
taskSummary: z26.array(z26.string().min(1)).min(1).max(20),
|
|
15433
|
+
executionReflection: z26.array(z26.string().min(1)).min(1).max(20),
|
|
15434
|
+
decisionsAndLearnings: z26.array(z26.string().min(1)).max(20),
|
|
15435
|
+
openQuestionsAndRisks: z26.array(z26.string().min(1)).max(20),
|
|
15436
|
+
tomorrowPlan: z26.array(z26.string().min(1)).min(1).max(20),
|
|
15437
|
+
toolUsage: z26.object({
|
|
15438
|
+
totalCalls: z26.number().int().min(0),
|
|
15439
|
+
shell: z26.number().int().min(0),
|
|
15440
|
+
fileRead: z26.number().int().min(0),
|
|
15441
|
+
fileWrite: z26.number().int().min(0),
|
|
15442
|
+
search: z26.number().int().min(0),
|
|
15443
|
+
lsp: z26.number().int().min(0),
|
|
15444
|
+
subagent: z26.number().int().min(0),
|
|
15445
|
+
other: z26.number().int().min(0)
|
|
15116
15446
|
}).strict(),
|
|
15117
|
-
tokenEstimate:
|
|
15118
|
-
estimatedInput:
|
|
15119
|
-
estimatedOutput:
|
|
15120
|
-
notes:
|
|
15447
|
+
tokenEstimate: z26.object({
|
|
15448
|
+
estimatedInput: z26.number().int().min(0),
|
|
15449
|
+
estimatedOutput: z26.number().int().min(0),
|
|
15450
|
+
notes: z26.string().max(200)
|
|
15121
15451
|
}).strict(),
|
|
15122
|
-
humanIntervention:
|
|
15123
|
-
approvalRequests:
|
|
15124
|
-
questionsAsked:
|
|
15125
|
-
summary:
|
|
15452
|
+
humanIntervention: z26.object({
|
|
15453
|
+
approvalRequests: z26.number().int().min(0),
|
|
15454
|
+
questionsAsked: z26.number().int().min(0),
|
|
15455
|
+
summary: z26.string().max(300)
|
|
15126
15456
|
}).strict(),
|
|
15127
|
-
qualityIndicators:
|
|
15128
|
-
hallucinationAlerts:
|
|
15129
|
-
failuresAndRetries:
|
|
15130
|
-
codeChangeSummary:
|
|
15131
|
-
overallAssessment:
|
|
15457
|
+
qualityIndicators: z26.object({
|
|
15458
|
+
hallucinationAlerts: z26.array(z26.string().min(1)).max(10),
|
|
15459
|
+
failuresAndRetries: z26.array(z26.string().min(1)).max(10),
|
|
15460
|
+
codeChangeSummary: z26.string().max(500),
|
|
15461
|
+
overallAssessment: z26.string().max(200)
|
|
15132
15462
|
}).strict(),
|
|
15133
|
-
knowledgeDeposits:
|
|
15134
|
-
worthRemembering:
|
|
15463
|
+
knowledgeDeposits: z26.object({
|
|
15464
|
+
worthRemembering: z26.array(z26.string().min(1)).max(10)
|
|
15135
15465
|
}).strict()
|
|
15136
15466
|
}).strict();
|
|
15137
15467
|
function localDateKey(date) {
|
|
@@ -15240,8 +15570,8 @@ Previous output was invalid. Repair it and return strict JSON only.`;
|
|
|
15240
15570
|
await mkdir18(flavorDirectory, { recursive: true, mode: 448 });
|
|
15241
15571
|
await assertNotSymlink(this.#sleepDirectory);
|
|
15242
15572
|
await mkdir18(this.#sleepDirectory, { recursive: true, mode: 448 });
|
|
15243
|
-
const root = await
|
|
15244
|
-
const target = await
|
|
15573
|
+
const root = await realpath11(this.#workspace);
|
|
15574
|
+
const target = await realpath11(this.#sleepDirectory);
|
|
15245
15575
|
if (!isWithin5(root, target)) throw new Error("Sleep directory escapes the workspace");
|
|
15246
15576
|
}
|
|
15247
15577
|
async #hasReport(date) {
|
|
@@ -15623,10 +15953,10 @@ function computeSessionStats(documents) {
|
|
|
15623
15953
|
|
|
15624
15954
|
// src/tools/files.ts
|
|
15625
15955
|
import { constants as constants7 } from "fs";
|
|
15626
|
-
import { mkdir as mkdir19, open as open10, readFile as readFile18, realpath as
|
|
15627
|
-
import { dirname as
|
|
15956
|
+
import { mkdir as mkdir19, open as open10, readFile as readFile18, realpath as realpath12, rename as rename10, rm as rm11, stat as stat8 } from "fs/promises";
|
|
15957
|
+
import { dirname as dirname18, isAbsolute as isAbsolute11, relative as relative16, resolve as resolve21, sep as sep15 } from "path";
|
|
15628
15958
|
import { randomUUID as randomUUID13 } from "crypto";
|
|
15629
|
-
import { z as
|
|
15959
|
+
import { z as z27 } from "zod";
|
|
15630
15960
|
|
|
15631
15961
|
// src/tools/file-diff.ts
|
|
15632
15962
|
var MAX_DIFF_PREVIEW_LINES = 120;
|
|
@@ -15732,18 +16062,18 @@ function truncateLines(lines) {
|
|
|
15732
16062
|
|
|
15733
16063
|
// src/tools/files.ts
|
|
15734
16064
|
var MAX_READ_BYTES = 1048576;
|
|
15735
|
-
var ReadInput2 =
|
|
15736
|
-
path:
|
|
15737
|
-
maxBytes:
|
|
15738
|
-
startLine:
|
|
15739
|
-
endLine:
|
|
16065
|
+
var ReadInput2 = z27.object({
|
|
16066
|
+
path: z27.string().min(1),
|
|
16067
|
+
maxBytes: z27.coerce.number().int().positive().max(MAX_READ_BYTES).nullable().optional(),
|
|
16068
|
+
startLine: z27.coerce.number().int().positive().nullable().optional(),
|
|
16069
|
+
endLine: z27.coerce.number().int().positive().nullable().optional(),
|
|
15740
16070
|
// Accepts booleans and their string forms (weak-typed models emit "true");
|
|
15741
16071
|
// kept transform-free so the schema converts to JSON Schema for providers.
|
|
15742
|
-
force:
|
|
16072
|
+
force: z27.union([z27.boolean(), z27.string().refine((value) => value === "true" || value === "false")]).nullable().optional()
|
|
15743
16073
|
});
|
|
15744
|
-
var WriteInput =
|
|
15745
|
-
var EditInput =
|
|
15746
|
-
var ApplyPatchInput =
|
|
16074
|
+
var WriteInput = z27.object({ path: z27.string().min(1), content: z27.string() });
|
|
16075
|
+
var EditInput = z27.object({ path: z27.string().min(1), oldText: z27.string().min(1), newText: z27.string() });
|
|
16076
|
+
var ApplyPatchInput = z27.object({ patch: z27.string().min(1) });
|
|
15747
16077
|
var FileObservationStore = class {
|
|
15748
16078
|
#versions = /* @__PURE__ */ new Map();
|
|
15749
16079
|
get(path) {
|
|
@@ -15951,22 +16281,22 @@ function createPathGuard(workspace) {
|
|
|
15951
16281
|
lexical,
|
|
15952
16282
|
existing: async (input) => {
|
|
15953
16283
|
const candidate = lexical(input);
|
|
15954
|
-
const physical = await
|
|
15955
|
-
if (!within2(await
|
|
16284
|
+
const physical = await realpath12(candidate);
|
|
16285
|
+
if (!within2(await realpath12(root), physical)) throw new Error("Path escapes the workspace through a symlink");
|
|
15956
16286
|
return physical;
|
|
15957
16287
|
},
|
|
15958
16288
|
destination: async (input) => {
|
|
15959
16289
|
const candidate = lexical(input);
|
|
15960
|
-
const physicalRoot = await
|
|
16290
|
+
const physicalRoot = await realpath12(root);
|
|
15961
16291
|
let ancestor = candidate;
|
|
15962
16292
|
while (true) {
|
|
15963
16293
|
try {
|
|
15964
|
-
const physical = await
|
|
16294
|
+
const physical = await realpath12(ancestor);
|
|
15965
16295
|
if (!within2(physicalRoot, physical)) throw new Error("Path escapes the workspace through a symlink");
|
|
15966
16296
|
break;
|
|
15967
16297
|
} catch (error) {
|
|
15968
16298
|
if (!isMissing2(error)) throw error;
|
|
15969
|
-
const parent =
|
|
16299
|
+
const parent = dirname18(ancestor);
|
|
15970
16300
|
if (parent === ancestor) throw error;
|
|
15971
16301
|
ancestor = parent;
|
|
15972
16302
|
}
|
|
@@ -15977,7 +16307,7 @@ function createPathGuard(workspace) {
|
|
|
15977
16307
|
}
|
|
15978
16308
|
async function atomicWrite(path, content, signal, expectedVersion) {
|
|
15979
16309
|
abortIfNeeded(signal);
|
|
15980
|
-
await mkdir19(
|
|
16310
|
+
await mkdir19(dirname18(path), { recursive: true });
|
|
15981
16311
|
const temporary = `${path}.${randomUUID13()}.tmp`;
|
|
15982
16312
|
try {
|
|
15983
16313
|
const handle = await open10(temporary, constants7.O_CREAT | constants7.O_EXCL | constants7.O_WRONLY, 384);
|
|
@@ -16337,10 +16667,10 @@ function matchesLines(source, start, expected) {
|
|
|
16337
16667
|
// src/tools/search.ts
|
|
16338
16668
|
import { spawn as spawn4 } from "child_process";
|
|
16339
16669
|
import { open as open11, opendir, stat as stat9 } from "fs/promises";
|
|
16340
|
-
import { dirname as
|
|
16670
|
+
import { dirname as dirname19, isAbsolute as isAbsolute12, relative as relative17, resolve as resolve22, sep as sep16 } from "path";
|
|
16341
16671
|
import { rgPath as bundledRgPath } from "@vscode/ripgrep";
|
|
16342
16672
|
import createIgnore from "ignore";
|
|
16343
|
-
import { z as
|
|
16673
|
+
import { z as z28 } from "zod";
|
|
16344
16674
|
var DEFAULT_RESULT_LIMIT = 1e3;
|
|
16345
16675
|
var DEFAULT_MAX_FILE_BYTES = 1048576;
|
|
16346
16676
|
var DEFAULT_MAX_SEARCH_BYTES = 16777216;
|
|
@@ -16414,18 +16744,18 @@ var FILE_TYPE_EXTENSIONS = {
|
|
|
16414
16744
|
python: [".py", ".pyi"],
|
|
16415
16745
|
typescript: [".ts", ".tsx", ".mts", ".cts"]
|
|
16416
16746
|
};
|
|
16417
|
-
var GlobInput =
|
|
16418
|
-
pattern:
|
|
16419
|
-
path:
|
|
16420
|
-
limit:
|
|
16747
|
+
var GlobInput = z28.object({
|
|
16748
|
+
pattern: z28.string().min(1),
|
|
16749
|
+
path: z28.string().min(1).describe('Workspace-relative search directory. Use JSON null, not the string "null", for the workspace root.').nullable().optional(),
|
|
16750
|
+
limit: z28.coerce.number().int().positive().max(1e5).nullable().optional()
|
|
16421
16751
|
});
|
|
16422
|
-
var GrepInput =
|
|
16423
|
-
pattern:
|
|
16424
|
-
path:
|
|
16425
|
-
glob:
|
|
16426
|
-
fileType:
|
|
16427
|
-
context:
|
|
16428
|
-
limit:
|
|
16752
|
+
var GrepInput = z28.object({
|
|
16753
|
+
pattern: z28.string().min(1),
|
|
16754
|
+
path: z28.string().min(1).describe('Workspace-relative search path. Use JSON null, not the string "null", for the workspace root.').nullable().optional(),
|
|
16755
|
+
glob: z28.string().min(1).nullable().optional(),
|
|
16756
|
+
fileType: z28.enum(FILE_TYPES).nullable().optional(),
|
|
16757
|
+
context: z28.coerce.number().int().nonnegative().max(100).nullable().optional(),
|
|
16758
|
+
limit: z28.coerce.number().int().positive().max(1e5).nullable().optional()
|
|
16429
16759
|
});
|
|
16430
16760
|
function createGlobTool(workspace, options = {}) {
|
|
16431
16761
|
const root = resolve22(workspace);
|
|
@@ -16809,7 +17139,7 @@ async function resolveGrepPath(root, path = ".") {
|
|
|
16809
17139
|
const candidate = scope(root, path);
|
|
16810
17140
|
try {
|
|
16811
17141
|
const info = await stat9(candidate);
|
|
16812
|
-
if (info.isFile()) return
|
|
17142
|
+
if (info.isFile()) return dirname19(candidate);
|
|
16813
17143
|
} catch {
|
|
16814
17144
|
}
|
|
16815
17145
|
return candidate;
|
|
@@ -17004,22 +17334,22 @@ import { lookup } from "dns/promises";
|
|
|
17004
17334
|
import { isIP } from "net";
|
|
17005
17335
|
import { request as httpRequest } from "http";
|
|
17006
17336
|
import { request as httpsRequest } from "https";
|
|
17007
|
-
import { z as
|
|
17008
|
-
var WebFetchInput =
|
|
17009
|
-
url:
|
|
17010
|
-
timeoutMs:
|
|
17011
|
-
maxBytes:
|
|
17337
|
+
import { z as z29 } from "zod";
|
|
17338
|
+
var WebFetchInput = z29.object({
|
|
17339
|
+
url: z29.string().url().max(8192),
|
|
17340
|
+
timeoutMs: z29.coerce.number().int().positive().max(12e4).optional(),
|
|
17341
|
+
maxBytes: z29.coerce.number().int().positive().max(10 * 1024 * 1024).optional()
|
|
17012
17342
|
});
|
|
17013
|
-
var WebSearchInput =
|
|
17014
|
-
query:
|
|
17015
|
-
maxResults:
|
|
17343
|
+
var WebSearchInput = z29.object({
|
|
17344
|
+
query: z29.string().trim().min(1).max(1e3),
|
|
17345
|
+
maxResults: z29.coerce.number().int().min(1).max(20).optional()
|
|
17016
17346
|
});
|
|
17017
17347
|
function createWebFetchTool() {
|
|
17018
17348
|
return {
|
|
17019
17349
|
name: "WebFetch",
|
|
17020
17350
|
description: "Fetch a public HTTP(S) page with SSRF protection and return readable text",
|
|
17021
17351
|
inputSchema: WebFetchInput,
|
|
17022
|
-
outputSchema:
|
|
17352
|
+
outputSchema: z29.object({ url: z29.string(), status: z29.number(), contentType: z29.string(), content: z29.string(), truncated: z29.boolean() }),
|
|
17023
17353
|
paths: () => [],
|
|
17024
17354
|
summarize: (input) => input.url,
|
|
17025
17355
|
presentCall: (input) => ({ kind: "web", title: `Fetching ${new URL(input.url).hostname}`, url: input.url }),
|
|
@@ -17045,7 +17375,7 @@ function createWebSearchTool(provider = createDefaultWebSearchProvider()) {
|
|
|
17045
17375
|
name: "WebSearch",
|
|
17046
17376
|
description: "Search the public web and return titles, URLs, and snippets",
|
|
17047
17377
|
inputSchema: WebSearchInput,
|
|
17048
|
-
outputSchema:
|
|
17378
|
+
outputSchema: z29.object({ query: z29.string(), results: z29.array(z29.object({ title: z29.string(), url: z29.string(), snippet: z29.string() })) }),
|
|
17049
17379
|
paths: () => [],
|
|
17050
17380
|
summarize: (input) => input.query,
|
|
17051
17381
|
presentCall: (input) => ({ kind: "web", title: `Searching: ${input.query}` }),
|
|
@@ -17311,9 +17641,9 @@ function charset(contentType) {
|
|
|
17311
17641
|
import { spawn as spawn5 } from "child_process";
|
|
17312
17642
|
import { existsSync as existsSync2 } from "fs";
|
|
17313
17643
|
import { access as access2, constants as constants8, readFile as readFile19 } from "fs/promises";
|
|
17314
|
-
import { basename as basename6, dirname as
|
|
17644
|
+
import { basename as basename6, dirname as dirname20, extname as extname2, isAbsolute as isAbsolute13, relative as relative18, resolve as resolve23, sep as sep17 } from "path";
|
|
17315
17645
|
import { fileURLToPath as fileURLToPath3, pathToFileURL as pathToFileURL3 } from "url";
|
|
17316
|
-
import { z as
|
|
17646
|
+
import { z as z30 } from "zod";
|
|
17317
17647
|
var LSP_REQUEST_TIMEOUT_MS = 15e3;
|
|
17318
17648
|
var LspConnection = class {
|
|
17319
17649
|
#process;
|
|
@@ -17528,7 +17858,7 @@ var LspBuffer = class {
|
|
|
17528
17858
|
}
|
|
17529
17859
|
};
|
|
17530
17860
|
var TYPESCRIPT_CLI = resolve23(
|
|
17531
|
-
|
|
17861
|
+
dirname20(fileURLToPath3(import.meta.resolve("typescript/package.json"))),
|
|
17532
17862
|
"lib",
|
|
17533
17863
|
"tsc.js"
|
|
17534
17864
|
);
|
|
@@ -17647,18 +17977,18 @@ var RealLspManager = class {
|
|
|
17647
17977
|
return connection;
|
|
17648
17978
|
}
|
|
17649
17979
|
};
|
|
17650
|
-
var LspFindRefsInput =
|
|
17651
|
-
file:
|
|
17652
|
-
line:
|
|
17653
|
-
character:
|
|
17980
|
+
var LspFindRefsInput = z30.object({
|
|
17981
|
+
file: z30.string().min(1),
|
|
17982
|
+
line: z30.coerce.number().int().nonnegative(),
|
|
17983
|
+
character: z30.coerce.number().int().nonnegative()
|
|
17654
17984
|
});
|
|
17655
|
-
var LspHoverInput =
|
|
17656
|
-
file:
|
|
17657
|
-
line:
|
|
17658
|
-
character:
|
|
17985
|
+
var LspHoverInput = z30.object({
|
|
17986
|
+
file: z30.string().min(1),
|
|
17987
|
+
line: z30.coerce.number().int().nonnegative(),
|
|
17988
|
+
character: z30.coerce.number().int().nonnegative()
|
|
17659
17989
|
});
|
|
17660
|
-
var LspDiagnosticsInput =
|
|
17661
|
-
file:
|
|
17990
|
+
var LspDiagnosticsInput = z30.object({
|
|
17991
|
+
file: z30.string().min(1)
|
|
17662
17992
|
});
|
|
17663
17993
|
function createLspTools(workspace, options = {}) {
|
|
17664
17994
|
const root = resolve23(workspace);
|
|
@@ -17884,7 +18214,7 @@ async function gitMarker(workspace) {
|
|
|
17884
18214
|
}
|
|
17885
18215
|
|
|
17886
18216
|
// src/git/insights.ts
|
|
17887
|
-
import { z as
|
|
18217
|
+
import { z as z31 } from "zod";
|
|
17888
18218
|
async function suggestCommitMessage(options, input, signal) {
|
|
17889
18219
|
const prompt = [
|
|
17890
18220
|
"Write a git commit message for the staged changes below.",
|
|
@@ -17923,17 +18253,17 @@ function cleanCommitMessage(raw) {
|
|
|
17923
18253
|
}
|
|
17924
18254
|
return kept.join("\n").trim().slice(0, 2e3);
|
|
17925
18255
|
}
|
|
17926
|
-
var ReviewFindingSchema =
|
|
17927
|
-
severity:
|
|
17928
|
-
file:
|
|
17929
|
-
line:
|
|
17930
|
-
issue:
|
|
17931
|
-
suggestion:
|
|
18256
|
+
var ReviewFindingSchema = z31.object({
|
|
18257
|
+
severity: z31.enum(["critical", "warning", "nit"]),
|
|
18258
|
+
file: z31.string(),
|
|
18259
|
+
line: z31.string().describe('Line number or hunk header the finding refers to, e.g. "42" or "@@ -10,4 +10,6 @@"'),
|
|
18260
|
+
issue: z31.string(),
|
|
18261
|
+
suggestion: z31.string()
|
|
17932
18262
|
}).strict();
|
|
17933
|
-
var ReviewReportSchema =
|
|
17934
|
-
summary:
|
|
17935
|
-
verdict:
|
|
17936
|
-
findings:
|
|
18263
|
+
var ReviewReportSchema = z31.object({
|
|
18264
|
+
summary: z31.string().describe("One-paragraph overall assessment of the change"),
|
|
18265
|
+
verdict: z31.enum(["ship", "ship-with-fixes", "needs-work"]),
|
|
18266
|
+
findings: z31.array(ReviewFindingSchema).max(20)
|
|
17937
18267
|
}).strict();
|
|
17938
18268
|
async function reviewDiff(options, input, signal) {
|
|
17939
18269
|
const prompt = [
|
|
@@ -17977,10 +18307,10 @@ function formatReviewReport(report) {
|
|
|
17977
18307
|
}
|
|
17978
18308
|
|
|
17979
18309
|
// src/git/tools.ts
|
|
17980
|
-
import { z as
|
|
17981
|
-
var GitHistoryInput =
|
|
17982
|
-
path:
|
|
17983
|
-
limit:
|
|
18310
|
+
import { z as z32 } from "zod";
|
|
18311
|
+
var GitHistoryInput = z32.object({
|
|
18312
|
+
path: z32.string().describe("File to inspect; omit for the whole repository history").optional(),
|
|
18313
|
+
limit: z32.number().int().min(1).max(50).describe("Maximum number of commits to return (default 20)").optional()
|
|
17984
18314
|
});
|
|
17985
18315
|
function createGitHistoryTool(workspace) {
|
|
17986
18316
|
return {
|
|
@@ -18009,18 +18339,18 @@ function createGitHistoryTool(workspace) {
|
|
|
18009
18339
|
}
|
|
18010
18340
|
|
|
18011
18341
|
// src/tools/ask-user-question.ts
|
|
18012
|
-
import { z as
|
|
18013
|
-
var QuestionOptionSchema =
|
|
18014
|
-
label:
|
|
18015
|
-
description:
|
|
18342
|
+
import { z as z33 } from "zod";
|
|
18343
|
+
var QuestionOptionSchema = z33.object({
|
|
18344
|
+
label: z33.string().trim().min(1),
|
|
18345
|
+
description: z33.string().trim().min(1)
|
|
18016
18346
|
});
|
|
18017
|
-
var QuestionSchema =
|
|
18018
|
-
question:
|
|
18019
|
-
header:
|
|
18020
|
-
options:
|
|
18347
|
+
var QuestionSchema = z33.object({
|
|
18348
|
+
question: z33.string().trim().min(1),
|
|
18349
|
+
header: z33.string().trim().min(1),
|
|
18350
|
+
options: z33.array(QuestionOptionSchema).min(1).max(4)
|
|
18021
18351
|
});
|
|
18022
|
-
var AskUserQuestionInput =
|
|
18023
|
-
questions:
|
|
18352
|
+
var AskUserQuestionInput = z33.object({
|
|
18353
|
+
questions: z33.array(QuestionSchema).min(1).max(4)
|
|
18024
18354
|
});
|
|
18025
18355
|
function hookAnswersFromUpdatedInput(updatedInput, questions) {
|
|
18026
18356
|
if (typeof updatedInput !== "object" || updatedInput === null) return void 0;
|
|
@@ -18104,20 +18434,20 @@ function createAskUserQuestionTool(handler) {
|
|
|
18104
18434
|
}
|
|
18105
18435
|
|
|
18106
18436
|
// src/tools/todo-write.ts
|
|
18107
|
-
import { z as
|
|
18108
|
-
var TodoStatusSchema =
|
|
18437
|
+
import { z as z34 } from "zod";
|
|
18438
|
+
var TodoStatusSchema = z34.enum([
|
|
18109
18439
|
"pending",
|
|
18110
18440
|
"in_progress",
|
|
18111
18441
|
"completed",
|
|
18112
18442
|
"cancelled"
|
|
18113
18443
|
]);
|
|
18114
|
-
var TodoItemSchema =
|
|
18115
|
-
content:
|
|
18444
|
+
var TodoItemSchema = z34.object({
|
|
18445
|
+
content: z34.string().trim().min(1),
|
|
18116
18446
|
status: TodoStatusSchema,
|
|
18117
|
-
activeForm:
|
|
18447
|
+
activeForm: z34.string().trim().min(1)
|
|
18118
18448
|
});
|
|
18119
|
-
var TodoWriteInput =
|
|
18120
|
-
todos:
|
|
18449
|
+
var TodoWriteInput = z34.object({
|
|
18450
|
+
todos: z34.array(TodoItemSchema).min(1).max(50)
|
|
18121
18451
|
});
|
|
18122
18452
|
function createTodoWriteTool() {
|
|
18123
18453
|
return {
|
|
@@ -18153,37 +18483,37 @@ function createTodoWriteTool() {
|
|
|
18153
18483
|
// src/tools/managed.ts
|
|
18154
18484
|
import { randomUUID as randomUUID14 } from "crypto";
|
|
18155
18485
|
import { link, lstat as lstat11, mkdir as mkdir20, readFile as readFile20, readdir as readdir10, unlink as unlink2, writeFile as writeFile12 } from "fs/promises";
|
|
18156
|
-
import { dirname as
|
|
18157
|
-
import { z as
|
|
18486
|
+
import { dirname as dirname21, join as join24, resolve as resolve24 } from "path";
|
|
18487
|
+
import { z as z35 } from "zod";
|
|
18158
18488
|
var MANAGED_TOOL_VERSION = 1;
|
|
18159
18489
|
var MAX_RECORD_BYTES = 256 * 1024;
|
|
18160
18490
|
var TOOL_NAME = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
18161
|
-
var JsonSchemaObject =
|
|
18491
|
+
var JsonSchemaObject = z35.record(z35.string(), z35.unknown()).superRefine((schema, context) => {
|
|
18162
18492
|
if (schema.type !== "object") {
|
|
18163
18493
|
context.addIssue({ code: "custom", message: "Tool input JSON Schema must have type object" });
|
|
18164
18494
|
}
|
|
18165
18495
|
});
|
|
18166
|
-
var RegisterManagedToolInputSchema =
|
|
18167
|
-
name:
|
|
18168
|
-
description:
|
|
18496
|
+
var RegisterManagedToolInputSchema = z35.object({
|
|
18497
|
+
name: z35.string().regex(TOOL_NAME).describe("Unique callable tool name using letters, digits, and underscores"),
|
|
18498
|
+
description: z35.string().min(1).max(4096).describe("Purpose and appropriate use of the generated tool"),
|
|
18169
18499
|
inputSchema: JsonSchemaObject.describe("Provider-facing JSON Schema with an object at the root"),
|
|
18170
|
-
implementation:
|
|
18500
|
+
implementation: z35.string().min(1).max(64 * 1024).describe(
|
|
18171
18501
|
"Async JavaScript function body, or complete function/arrow expression, receiving input, signal, and context; return the tool result"
|
|
18172
18502
|
),
|
|
18173
|
-
scope:
|
|
18503
|
+
scope: z35.enum(["project", "global"]).default("project").describe(
|
|
18174
18504
|
"Project persists in the current workspace; global persists for every workspace"
|
|
18175
18505
|
),
|
|
18176
|
-
agents:
|
|
18506
|
+
agents: z35.array(z35.enum(["main", "subagent"])).min(1).max(2).optional().describe(
|
|
18177
18507
|
"Agent roles allowed to call the generated tool; omit to allow both"
|
|
18178
18508
|
)
|
|
18179
18509
|
}).strict();
|
|
18180
|
-
var RemoveManagedToolInputSchema =
|
|
18181
|
-
name:
|
|
18182
|
-
scope:
|
|
18510
|
+
var RemoveManagedToolInputSchema = z35.object({
|
|
18511
|
+
name: z35.string().regex(TOOL_NAME).describe("Managed tool name to remove"),
|
|
18512
|
+
scope: z35.enum(["project", "global"]).optional().describe("Required only when the same name exists in both scopes")
|
|
18183
18513
|
}).strict();
|
|
18184
18514
|
var ManagedToolRecordSchema = RegisterManagedToolInputSchema.extend({
|
|
18185
|
-
version:
|
|
18186
|
-
createdAt:
|
|
18515
|
+
version: z35.literal(MANAGED_TOOL_VERSION),
|
|
18516
|
+
createdAt: z35.string().datetime()
|
|
18187
18517
|
}).strict();
|
|
18188
18518
|
var AsyncFunction = Object.getPrototypeOf(async function() {
|
|
18189
18519
|
}).constructor;
|
|
@@ -18370,7 +18700,7 @@ function createManagedToolManagementTools(options) {
|
|
|
18370
18700
|
const listTools = {
|
|
18371
18701
|
name: "ListRegisteredTools",
|
|
18372
18702
|
description: "List durable tools created through RegisterTool, including scope, path, and active precedence",
|
|
18373
|
-
inputSchema:
|
|
18703
|
+
inputSchema: z35.object({}).strict(),
|
|
18374
18704
|
agents: mainOnly,
|
|
18375
18705
|
paths: () => [],
|
|
18376
18706
|
execute: async (_input, signal) => {
|
|
@@ -18383,7 +18713,7 @@ function createManagedToolManagementTools(options) {
|
|
|
18383
18713
|
function compileDefinition(record3, scope2, workspace) {
|
|
18384
18714
|
let inputSchema;
|
|
18385
18715
|
try {
|
|
18386
|
-
inputSchema =
|
|
18716
|
+
inputSchema = z35.fromJSONSchema(record3.inputSchema);
|
|
18387
18717
|
} catch (error) {
|
|
18388
18718
|
throw new Error(`Invalid input schema for managed tool "${record3.name}": ${message(error)}`);
|
|
18389
18719
|
}
|
|
@@ -18437,7 +18767,7 @@ ${sourceUrl}`
|
|
|
18437
18767
|
}
|
|
18438
18768
|
}
|
|
18439
18769
|
async function writeExclusive(path, content) {
|
|
18440
|
-
await mkdir20(
|
|
18770
|
+
await mkdir20(dirname21(path), { recursive: true });
|
|
18441
18771
|
const temporary = `${path}.${randomUUID14()}.tmp`;
|
|
18442
18772
|
try {
|
|
18443
18773
|
await writeFile12(temporary, content, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
@@ -18483,7 +18813,7 @@ function isMissing4(error) {
|
|
|
18483
18813
|
}
|
|
18484
18814
|
|
|
18485
18815
|
// src/pals/protocol.ts
|
|
18486
|
-
import { z as
|
|
18816
|
+
import { z as z36 } from "zod";
|
|
18487
18817
|
var PROTOCOL_VERSION = 1;
|
|
18488
18818
|
var MAX_ALIAS_LENGTH = 64;
|
|
18489
18819
|
var MAX_MESSAGE_BYTES = 32 * 1024;
|
|
@@ -18500,65 +18830,65 @@ var MIN_UUID_PREFIX_LENGTH = 8;
|
|
|
18500
18830
|
function normalizePalIdentity(value) {
|
|
18501
18831
|
return value.trim().toLocaleLowerCase("en-US");
|
|
18502
18832
|
}
|
|
18503
|
-
var VersionSchema =
|
|
18504
|
-
var UuidSchema =
|
|
18505
|
-
var PrintableIdentitySchema =
|
|
18833
|
+
var VersionSchema = z36.literal(PROTOCOL_VERSION);
|
|
18834
|
+
var UuidSchema = z36.uuid();
|
|
18835
|
+
var PrintableIdentitySchema = z36.string().trim().min(1).max(MAX_ALIAS_LENGTH).refine(
|
|
18506
18836
|
(value) => !/[\p{Cc}\uD800-\uDFFF]/u.test(value),
|
|
18507
18837
|
"Identity must contain only printable non-control Unicode"
|
|
18508
18838
|
);
|
|
18509
18839
|
var PalAliasSchema = PrintableIdentitySchema;
|
|
18510
18840
|
var PalTargetSchema = PrintableIdentitySchema;
|
|
18511
|
-
var BoundedTextSchema =
|
|
18841
|
+
var BoundedTextSchema = z36.string().refine(
|
|
18512
18842
|
(value) => Buffer.byteLength(value, "utf8") <= MAX_MESSAGE_BYTES,
|
|
18513
18843
|
`Text must not exceed ${MAX_MESSAGE_BYTES} UTF-8 bytes`
|
|
18514
18844
|
);
|
|
18515
18845
|
var NonEmptyBoundedTextSchema = BoundedTextSchema.refine((value) => value.length > 0, "Text must not be empty");
|
|
18516
|
-
var CompletionDetailSchema =
|
|
18846
|
+
var CompletionDetailSchema = z36.string().trim().min(1).refine(
|
|
18517
18847
|
(value) => Buffer.byteLength(value, "utf8") <= MAX_COMPLETION_DETAIL_BYTES,
|
|
18518
18848
|
`Completion evidence must not exceed ${MAX_COMPLETION_DETAIL_BYTES} UTF-8 bytes`
|
|
18519
18849
|
);
|
|
18520
|
-
var PalPresenceSchema =
|
|
18850
|
+
var PalPresenceSchema = z36.object({
|
|
18521
18851
|
version: VersionSchema,
|
|
18522
18852
|
id: UuidSchema,
|
|
18523
18853
|
alias: PalAliasSchema,
|
|
18524
|
-
projectPath:
|
|
18854
|
+
projectPath: z36.string().min(1).refine(
|
|
18525
18855
|
(value) => Buffer.byteLength(value, "utf8") <= MAX_PROJECT_PATH_BYTES,
|
|
18526
18856
|
`Project path must not exceed ${MAX_PROJECT_PATH_BYTES} UTF-8 bytes`
|
|
18527
18857
|
),
|
|
18528
|
-
connectedAt:
|
|
18529
|
-
lastSeenAt:
|
|
18858
|
+
connectedAt: z36.iso.datetime(),
|
|
18859
|
+
lastSeenAt: z36.iso.datetime()
|
|
18530
18860
|
}).strict();
|
|
18531
|
-
var PalPresenceListSchema =
|
|
18532
|
-
var PalTaskMessageSchema =
|
|
18861
|
+
var PalPresenceListSchema = z36.array(PalPresenceSchema).max(MAX_ACTIVE_PALS);
|
|
18862
|
+
var PalTaskMessageSchema = z36.object({
|
|
18533
18863
|
version: VersionSchema,
|
|
18534
|
-
type:
|
|
18864
|
+
type: z36.literal("task"),
|
|
18535
18865
|
messageId: UuidSchema,
|
|
18536
18866
|
target: PalTargetSchema,
|
|
18537
18867
|
goal: NonEmptyBoundedTextSchema
|
|
18538
18868
|
}).strict();
|
|
18539
|
-
var PalTaskEventSchema =
|
|
18869
|
+
var PalTaskEventSchema = z36.object({
|
|
18540
18870
|
version: VersionSchema,
|
|
18541
|
-
type:
|
|
18871
|
+
type: z36.literal("task-event"),
|
|
18542
18872
|
messageId: UuidSchema,
|
|
18543
18873
|
taskId: UuidSchema,
|
|
18544
18874
|
senderId: UuidSchema,
|
|
18545
18875
|
recipientId: UuidSchema,
|
|
18546
|
-
status:
|
|
18876
|
+
status: z36.enum(["accepted", "started", "progress", "completed", "failed", "cancelled"]),
|
|
18547
18877
|
detail: BoundedTextSchema.optional()
|
|
18548
18878
|
}).strict();
|
|
18549
|
-
var DeliveryReceiptSchema =
|
|
18879
|
+
var DeliveryReceiptSchema = z36.object({
|
|
18550
18880
|
version: VersionSchema,
|
|
18551
|
-
type:
|
|
18881
|
+
type: z36.literal("delivery-receipt"),
|
|
18552
18882
|
messageId: UuidSchema,
|
|
18553
|
-
status:
|
|
18554
|
-
recipientIds:
|
|
18883
|
+
status: z36.enum(["delivered", "duplicate", "rejected"]),
|
|
18884
|
+
recipientIds: z36.array(UuidSchema).max(MAX_PARTICIPANTS),
|
|
18555
18885
|
error: BoundedTextSchema.optional()
|
|
18556
18886
|
}).strict();
|
|
18557
|
-
var CoWorkParticipantSchema =
|
|
18887
|
+
var CoWorkParticipantSchema = z36.object({
|
|
18558
18888
|
palId: UuidSchema,
|
|
18559
|
-
required:
|
|
18889
|
+
required: z36.boolean()
|
|
18560
18890
|
}).strict();
|
|
18561
|
-
var CoWorkProposalParticipantsSchema =
|
|
18891
|
+
var CoWorkProposalParticipantsSchema = z36.array(CoWorkParticipantSchema).min(2).max(MAX_PARTICIPANTS).superRefine((participants, context) => {
|
|
18562
18892
|
const seen = /* @__PURE__ */ new Set();
|
|
18563
18893
|
for (const [index, participant] of participants.entries()) {
|
|
18564
18894
|
const id = participant.palId.toLowerCase();
|
|
@@ -18568,19 +18898,19 @@ var CoWorkProposalParticipantsSchema = z35.array(CoWorkParticipantSchema).min(2)
|
|
|
18568
18898
|
seen.add(id);
|
|
18569
18899
|
}
|
|
18570
18900
|
});
|
|
18571
|
-
var CoWorkPlanTaskSchema =
|
|
18572
|
-
id:
|
|
18901
|
+
var CoWorkPlanTaskSchema = z36.object({
|
|
18902
|
+
id: z36.string().min(1).max(128),
|
|
18573
18903
|
assigneeId: UuidSchema,
|
|
18574
18904
|
description: NonEmptyBoundedTextSchema,
|
|
18575
|
-
dependsOn:
|
|
18905
|
+
dependsOn: z36.array(z36.string().min(1).max(128)).max(MAX_PLAN_TASKS)
|
|
18576
18906
|
}).strict();
|
|
18577
|
-
var CoWorkPlanSchema =
|
|
18907
|
+
var CoWorkPlanSchema = z36.object({
|
|
18578
18908
|
version: VersionSchema,
|
|
18579
18909
|
coWorkId: UuidSchema,
|
|
18580
|
-
epoch:
|
|
18910
|
+
epoch: z36.number().int().positive(),
|
|
18581
18911
|
goal: NonEmptyBoundedTextSchema,
|
|
18582
|
-
participants:
|
|
18583
|
-
tasks:
|
|
18912
|
+
participants: z36.array(CoWorkParticipantSchema).min(1).max(MAX_PARTICIPANTS),
|
|
18913
|
+
tasks: z36.array(CoWorkPlanTaskSchema).min(1).max(MAX_PLAN_TASKS)
|
|
18584
18914
|
}).strict().superRefine((plan, context) => {
|
|
18585
18915
|
if (Buffer.byteLength(JSON.stringify(plan), "utf8") > MAX_PLAN_ENCODED_BYTES) {
|
|
18586
18916
|
context.addIssue({ code: "custom", message: `Encoded plan must not exceed ${MAX_PLAN_ENCODED_BYTES} UTF-8 bytes` });
|
|
@@ -18630,7 +18960,7 @@ var CoWorkPlanSchema = z35.object({
|
|
|
18630
18960
|
}
|
|
18631
18961
|
}
|
|
18632
18962
|
});
|
|
18633
|
-
var CoWorkPhaseSchema =
|
|
18963
|
+
var CoWorkPhaseSchema = z36.enum([
|
|
18634
18964
|
"proposed",
|
|
18635
18965
|
"planning",
|
|
18636
18966
|
"prepared",
|
|
@@ -18640,30 +18970,30 @@ var CoWorkPhaseSchema = z35.enum([
|
|
|
18640
18970
|
"failed",
|
|
18641
18971
|
"cancelled"
|
|
18642
18972
|
]);
|
|
18643
|
-
var IntegrationResultSchema =
|
|
18644
|
-
passed:
|
|
18973
|
+
var IntegrationResultSchema = z36.object({
|
|
18974
|
+
passed: z36.boolean(),
|
|
18645
18975
|
evidence: CompletionDetailSchema
|
|
18646
18976
|
}).strict();
|
|
18647
|
-
var CoWorkCompletionAssertionSchema =
|
|
18977
|
+
var CoWorkCompletionAssertionSchema = z36.object({
|
|
18648
18978
|
participantId: UuidSchema,
|
|
18649
|
-
passed:
|
|
18979
|
+
passed: z36.boolean(),
|
|
18650
18980
|
detail: CompletionDetailSchema.optional()
|
|
18651
18981
|
}).strict();
|
|
18652
|
-
var CoWorkSnapshotSchema =
|
|
18982
|
+
var CoWorkSnapshotSchema = z36.object({
|
|
18653
18983
|
version: VersionSchema,
|
|
18654
18984
|
coWorkId: UuidSchema,
|
|
18655
|
-
epoch:
|
|
18985
|
+
epoch: z36.number().int().positive(),
|
|
18656
18986
|
phase: CoWorkPhaseSchema,
|
|
18657
18987
|
goal: NonEmptyBoundedTextSchema,
|
|
18658
|
-
participants:
|
|
18988
|
+
participants: z36.array(CoWorkParticipantSchema).min(1).max(MAX_PARTICIPANTS),
|
|
18659
18989
|
integrationOwnerId: UuidSchema,
|
|
18660
|
-
acceptedParticipantIds:
|
|
18661
|
-
planHash:
|
|
18990
|
+
acceptedParticipantIds: z36.array(UuidSchema).max(MAX_PARTICIPANTS),
|
|
18991
|
+
planHash: z36.string().regex(/^[a-f0-9]{64}$/).nullable(),
|
|
18662
18992
|
plan: CoWorkPlanSchema.nullable(),
|
|
18663
|
-
planAcceptedParticipantIds:
|
|
18664
|
-
readyParticipantIds:
|
|
18665
|
-
completedParticipantIds:
|
|
18666
|
-
completionAssertions:
|
|
18993
|
+
planAcceptedParticipantIds: z36.array(UuidSchema).max(MAX_PARTICIPANTS),
|
|
18994
|
+
readyParticipantIds: z36.array(UuidSchema).max(MAX_PARTICIPANTS),
|
|
18995
|
+
completedParticipantIds: z36.array(UuidSchema).max(MAX_PARTICIPANTS),
|
|
18996
|
+
completionAssertions: z36.array(CoWorkCompletionAssertionSchema).max(MAX_PARTICIPANTS),
|
|
18667
18997
|
integration: IntegrationResultSchema.nullable()
|
|
18668
18998
|
}).strict().superRefine((snapshot4, context) => {
|
|
18669
18999
|
if (Buffer.byteLength(JSON.stringify(snapshot4), "utf8") > MAX_SNAPSHOT_ENCODED_BYTES) {
|
|
@@ -18694,87 +19024,87 @@ var RequestBase = {
|
|
|
18694
19024
|
version: VersionSchema,
|
|
18695
19025
|
requestId: UuidSchema
|
|
18696
19026
|
};
|
|
18697
|
-
var RegisterRequestSchema =
|
|
19027
|
+
var RegisterRequestSchema = z36.object({
|
|
18698
19028
|
...RequestBase,
|
|
18699
|
-
type:
|
|
18700
|
-
authToken:
|
|
19029
|
+
type: z36.literal("register"),
|
|
19030
|
+
authToken: z36.string().regex(/^[a-f0-9]{64}$/).optional(),
|
|
18701
19031
|
presence: PalPresenceSchema
|
|
18702
19032
|
}).strict();
|
|
18703
|
-
var HeartbeatRequestSchema =
|
|
18704
|
-
var ListRequestSchema =
|
|
18705
|
-
var DisconnectRequestSchema =
|
|
18706
|
-
var ChatRequestSchema =
|
|
19033
|
+
var HeartbeatRequestSchema = z36.object({ ...RequestBase, type: z36.literal("heartbeat") }).strict();
|
|
19034
|
+
var ListRequestSchema = z36.object({ ...RequestBase, type: z36.literal("list") }).strict();
|
|
19035
|
+
var DisconnectRequestSchema = z36.object({ ...RequestBase, type: z36.literal("disconnect") }).strict();
|
|
19036
|
+
var ChatRequestSchema = z36.object({
|
|
18707
19037
|
...RequestBase,
|
|
18708
|
-
type:
|
|
19038
|
+
type: z36.literal("chat"),
|
|
18709
19039
|
messageId: UuidSchema,
|
|
18710
19040
|
target: PalTargetSchema,
|
|
18711
19041
|
message: NonEmptyBoundedTextSchema
|
|
18712
19042
|
}).strict();
|
|
18713
|
-
var TaskRequestSchema =
|
|
19043
|
+
var TaskRequestSchema = z36.object({
|
|
18714
19044
|
...RequestBase,
|
|
18715
|
-
type:
|
|
19045
|
+
type: z36.literal("task"),
|
|
18716
19046
|
messageId: UuidSchema,
|
|
18717
19047
|
target: PalTargetSchema,
|
|
18718
19048
|
goal: NonEmptyBoundedTextSchema
|
|
18719
19049
|
}).strict();
|
|
18720
|
-
var CoWorkProposeRequestSchema =
|
|
19050
|
+
var CoWorkProposeRequestSchema = z36.object({
|
|
18721
19051
|
...RequestBase,
|
|
18722
|
-
type:
|
|
19052
|
+
type: z36.literal("cowork-propose"),
|
|
18723
19053
|
coWorkId: UuidSchema,
|
|
18724
19054
|
goal: NonEmptyBoundedTextSchema,
|
|
18725
19055
|
participants: CoWorkProposalParticipantsSchema
|
|
18726
19056
|
}).strict();
|
|
18727
|
-
var CoWorkAcceptanceRequestSchema =
|
|
19057
|
+
var CoWorkAcceptanceRequestSchema = z36.object({
|
|
18728
19058
|
...RequestBase,
|
|
18729
|
-
type:
|
|
19059
|
+
type: z36.literal("cowork-accept"),
|
|
18730
19060
|
coWorkId: UuidSchema,
|
|
18731
|
-
epoch:
|
|
19061
|
+
epoch: z36.number().int().positive()
|
|
18732
19062
|
}).strict();
|
|
18733
|
-
var CoWorkPlanRequestSchema =
|
|
18734
|
-
var CoWorkPlanAcceptanceRequestSchema =
|
|
19063
|
+
var CoWorkPlanRequestSchema = z36.object({ ...RequestBase, type: z36.literal("cowork-plan"), plan: CoWorkPlanSchema }).strict();
|
|
19064
|
+
var CoWorkPlanAcceptanceRequestSchema = z36.object({
|
|
18735
19065
|
...RequestBase,
|
|
18736
|
-
type:
|
|
19066
|
+
type: z36.literal("cowork-plan-accept"),
|
|
18737
19067
|
coWorkId: UuidSchema,
|
|
18738
|
-
epoch:
|
|
18739
|
-
planHash:
|
|
19068
|
+
epoch: z36.number().int().positive(),
|
|
19069
|
+
planHash: z36.string().regex(/^[a-f0-9]{64}$/)
|
|
18740
19070
|
}).strict();
|
|
18741
|
-
var CoWorkReadyRequestSchema =
|
|
19071
|
+
var CoWorkReadyRequestSchema = z36.object({
|
|
18742
19072
|
...RequestBase,
|
|
18743
|
-
type:
|
|
19073
|
+
type: z36.literal("cowork-ready"),
|
|
18744
19074
|
coWorkId: UuidSchema,
|
|
18745
|
-
epoch:
|
|
18746
|
-
planHash:
|
|
19075
|
+
epoch: z36.number().int().positive(),
|
|
19076
|
+
planHash: z36.string().regex(/^[a-f0-9]{64}$/)
|
|
18747
19077
|
}).strict();
|
|
18748
|
-
var CoWorkCompleteRequestSchema =
|
|
19078
|
+
var CoWorkCompleteRequestSchema = z36.object({
|
|
18749
19079
|
...RequestBase,
|
|
18750
|
-
type:
|
|
19080
|
+
type: z36.literal("cowork-complete"),
|
|
18751
19081
|
coWorkId: UuidSchema,
|
|
18752
|
-
epoch:
|
|
18753
|
-
planHash:
|
|
18754
|
-
passed:
|
|
19082
|
+
epoch: z36.number().int().positive(),
|
|
19083
|
+
planHash: z36.string().regex(/^[a-f0-9]{64}$/),
|
|
19084
|
+
passed: z36.boolean(),
|
|
18755
19085
|
detail: CompletionDetailSchema.optional()
|
|
18756
19086
|
}).strict();
|
|
18757
|
-
var CoWorkIntegrationRequestSchema =
|
|
19087
|
+
var CoWorkIntegrationRequestSchema = z36.object({
|
|
18758
19088
|
...RequestBase,
|
|
18759
|
-
type:
|
|
19089
|
+
type: z36.literal("cowork-integration"),
|
|
18760
19090
|
coWorkId: UuidSchema,
|
|
18761
|
-
epoch:
|
|
18762
|
-
planHash:
|
|
18763
|
-
passed:
|
|
19091
|
+
epoch: z36.number().int().positive(),
|
|
19092
|
+
planHash: z36.string().regex(/^[a-f0-9]{64}$/),
|
|
19093
|
+
passed: z36.boolean(),
|
|
18764
19094
|
evidence: CompletionDetailSchema
|
|
18765
19095
|
}).strict();
|
|
18766
|
-
var CoWorkGetRequestSchema =
|
|
19096
|
+
var CoWorkGetRequestSchema = z36.object({
|
|
18767
19097
|
...RequestBase,
|
|
18768
|
-
type:
|
|
19098
|
+
type: z36.literal("cowork-get"),
|
|
18769
19099
|
coWorkId: UuidSchema
|
|
18770
19100
|
}).strict();
|
|
18771
|
-
var CoWorkCancelRequestSchema =
|
|
19101
|
+
var CoWorkCancelRequestSchema = z36.object({
|
|
18772
19102
|
...RequestBase,
|
|
18773
|
-
type:
|
|
19103
|
+
type: z36.literal("cowork-cancel"),
|
|
18774
19104
|
coWorkId: UuidSchema,
|
|
18775
19105
|
reason: NonEmptyBoundedTextSchema
|
|
18776
19106
|
}).strict();
|
|
18777
|
-
var BrokerRequestSchema =
|
|
19107
|
+
var BrokerRequestSchema = z36.discriminatedUnion("type", [
|
|
18778
19108
|
RegisterRequestSchema,
|
|
18779
19109
|
HeartbeatRequestSchema,
|
|
18780
19110
|
ListRequestSchema,
|
|
@@ -18791,49 +19121,49 @@ var BrokerRequestSchema = z35.discriminatedUnion("type", [
|
|
|
18791
19121
|
CoWorkGetRequestSchema,
|
|
18792
19122
|
CoWorkCancelRequestSchema
|
|
18793
19123
|
]);
|
|
18794
|
-
var BrokerOkResponseSchema =
|
|
19124
|
+
var BrokerOkResponseSchema = z36.object({
|
|
18795
19125
|
version: VersionSchema,
|
|
18796
|
-
type:
|
|
19126
|
+
type: z36.literal("ok"),
|
|
18797
19127
|
requestId: UuidSchema,
|
|
18798
|
-
data:
|
|
19128
|
+
data: z36.unknown()
|
|
18799
19129
|
}).strict();
|
|
18800
|
-
var BrokerErrorResponseSchema =
|
|
19130
|
+
var BrokerErrorResponseSchema = z36.object({
|
|
18801
19131
|
version: VersionSchema,
|
|
18802
|
-
type:
|
|
19132
|
+
type: z36.literal("error"),
|
|
18803
19133
|
requestId: UuidSchema,
|
|
18804
|
-
code:
|
|
19134
|
+
code: z36.enum(["invalid-request", "authentication-failed", "not-found", "ambiguous-target", "alias-conflict", "invalid-transition", "stale-epoch", "duplicate"]),
|
|
18805
19135
|
message: BoundedTextSchema
|
|
18806
19136
|
}).strict();
|
|
18807
|
-
var ChatEventSchema =
|
|
19137
|
+
var ChatEventSchema = z36.object({
|
|
18808
19138
|
version: VersionSchema,
|
|
18809
|
-
type:
|
|
19139
|
+
type: z36.literal("chat-event"),
|
|
18810
19140
|
messageId: UuidSchema,
|
|
18811
19141
|
senderId: UuidSchema,
|
|
18812
19142
|
recipientId: UuidSchema,
|
|
18813
19143
|
message: NonEmptyBoundedTextSchema
|
|
18814
19144
|
}).strict();
|
|
18815
|
-
var CoWorkEventSchema =
|
|
19145
|
+
var CoWorkEventSchema = z36.object({
|
|
18816
19146
|
version: VersionSchema,
|
|
18817
|
-
type:
|
|
18818
|
-
action:
|
|
19147
|
+
type: z36.literal("cowork-event"),
|
|
19148
|
+
action: z36.enum(["PROPOSE", "PLAN", "START", "END", "FAIL", "CANCEL"]),
|
|
18819
19149
|
actorId: UuidSchema,
|
|
18820
19150
|
coWorkId: UuidSchema,
|
|
18821
|
-
epoch:
|
|
18822
|
-
planHash:
|
|
19151
|
+
epoch: z36.number().int().positive(),
|
|
19152
|
+
planHash: z36.string().regex(/^[a-f0-9]{64}$/).nullable(),
|
|
18823
19153
|
snapshot: CoWorkSnapshotSchema
|
|
18824
19154
|
}).strict();
|
|
18825
|
-
var BrokerEventSchema =
|
|
18826
|
-
var BrokerEventResponseSchema =
|
|
19155
|
+
var BrokerEventSchema = z36.union([ChatEventSchema, PalTaskEventSchema, DeliveryReceiptSchema, CoWorkEventSchema]);
|
|
19156
|
+
var BrokerEventResponseSchema = z36.object({
|
|
18827
19157
|
version: VersionSchema,
|
|
18828
|
-
type:
|
|
19158
|
+
type: z36.literal("event"),
|
|
18829
19159
|
event: BrokerEventSchema
|
|
18830
19160
|
}).strict();
|
|
18831
|
-
var BrokerResponseSchema =
|
|
19161
|
+
var BrokerResponseSchema = z36.discriminatedUnion("type", [
|
|
18832
19162
|
BrokerOkResponseSchema,
|
|
18833
19163
|
BrokerErrorResponseSchema,
|
|
18834
19164
|
BrokerEventResponseSchema
|
|
18835
19165
|
]);
|
|
18836
|
-
var ControlFrameSchema =
|
|
19166
|
+
var ControlFrameSchema = z36.string().refine(
|
|
18837
19167
|
(frame) => Buffer.byteLength(frame, "utf8") <= MAX_CONTROL_FRAME_BYTES,
|
|
18838
19168
|
`Control frame must not exceed ${MAX_CONTROL_FRAME_BYTES} UTF-8 bytes`
|
|
18839
19169
|
);
|
|
@@ -19317,7 +19647,8 @@ var FlavorSession = class {
|
|
|
19317
19647
|
version: 1,
|
|
19318
19648
|
type: "SessionStart",
|
|
19319
19649
|
payload: { workspace: this.#services.workspace }
|
|
19320
|
-
}).then(() => {
|
|
19650
|
+
}).then(async (decision) => {
|
|
19651
|
+
if (decision.additionalContext !== void 0) await this.#services.addContext?.(decision.additionalContext);
|
|
19321
19652
|
this.#started = true;
|
|
19322
19653
|
});
|
|
19323
19654
|
return this.#startPromise;
|
|
@@ -19754,7 +20085,7 @@ var LANG_LABELS = /* @__PURE__ */ new Map([
|
|
|
19754
20085
|
]);
|
|
19755
20086
|
|
|
19756
20087
|
// src/hallucination/confidence.ts
|
|
19757
|
-
import { z as
|
|
20088
|
+
import { z as z37 } from "zod";
|
|
19758
20089
|
|
|
19759
20090
|
// src/hallucination/types.ts
|
|
19760
20091
|
var DEFAULT_SLIDING_WINDOW_SIZE = 20;
|
|
@@ -19767,12 +20098,12 @@ var DEFAULT_EVALUATION_TIMEOUT_MS = 2e3;
|
|
|
19767
20098
|
var MAX_QUERY_CHARS = 5e3;
|
|
19768
20099
|
var MAX_OUTPUT_CHARS = 1e4;
|
|
19769
20100
|
var MAX_EVIDENCE_CHARS = 6e3;
|
|
19770
|
-
var ConfidenceSchema =
|
|
19771
|
-
taskAlignment:
|
|
19772
|
-
evidenceGrounding:
|
|
19773
|
-
processReliability:
|
|
19774
|
-
reason:
|
|
19775
|
-
unsupportedClaims:
|
|
20101
|
+
var ConfidenceSchema = z37.object({
|
|
20102
|
+
taskAlignment: z37.number(),
|
|
20103
|
+
evidenceGrounding: z37.number(),
|
|
20104
|
+
processReliability: z37.number(),
|
|
20105
|
+
reason: z37.string(),
|
|
20106
|
+
unsupportedClaims: z37.array(z37.string()).max(3)
|
|
19776
20107
|
});
|
|
19777
20108
|
var PROMPT = `You are a fast, evidence-aware task-completion verifier.
|
|
19778
20109
|
|
|
@@ -21865,15 +22196,15 @@ function workspacePath(root, input) {
|
|
|
21865
22196
|
}
|
|
21866
22197
|
|
|
21867
22198
|
// src/tools/terminal.ts
|
|
21868
|
-
import { z as
|
|
22199
|
+
import { z as z38 } from "zod";
|
|
21869
22200
|
import { resolve as resolve29 } from "path";
|
|
21870
|
-
var Id =
|
|
21871
|
-
var OpenInput =
|
|
21872
|
-
var OptionalBoolean =
|
|
21873
|
-
var WriteInput2 =
|
|
21874
|
-
var ReadInput3 =
|
|
21875
|
-
var ResizeInput =
|
|
21876
|
-
var CloseInput =
|
|
22201
|
+
var Id = z38.string().regex(/^term-[a-f0-9-]+$/);
|
|
22202
|
+
var OpenInput = z38.object({ cwd: z38.string().optional(), shell: z38.string().optional(), args: z38.array(z38.string()).optional(), columns: z38.coerce.number().int().min(10).max(500).optional(), rows: z38.coerce.number().int().min(2).max(300).optional() });
|
|
22203
|
+
var OptionalBoolean = z38.union([z38.boolean(), z38.string().refine((value) => value === "true" || value === "false")]);
|
|
22204
|
+
var WriteInput2 = z38.object({ id: Id, data: z38.string().max(1e5), enter: OptionalBoolean.optional() });
|
|
22205
|
+
var ReadInput3 = z38.object({ id: Id, cursor: z38.coerce.number().int().min(0).optional() });
|
|
22206
|
+
var ResizeInput = z38.object({ id: Id, columns: z38.coerce.number().int().min(10).max(500), rows: z38.coerce.number().int().min(2).max(300) });
|
|
22207
|
+
var CloseInput = z38.object({ id: Id });
|
|
21877
22208
|
function createTerminalTools(terminals, workspace = process.cwd()) {
|
|
21878
22209
|
const tools = [
|
|
21879
22210
|
{
|
|
@@ -21949,7 +22280,7 @@ function createTerminalTools(terminals, workspace = process.cwd()) {
|
|
|
21949
22280
|
{
|
|
21950
22281
|
name: "TerminalList",
|
|
21951
22282
|
description: "List persistent terminals owned by this agent",
|
|
21952
|
-
inputSchema:
|
|
22283
|
+
inputSchema: z38.object({}),
|
|
21953
22284
|
paths: () => [],
|
|
21954
22285
|
execute: async (_input, _signal, context) => terminals.list(owner(context))
|
|
21955
22286
|
}
|
|
@@ -21984,7 +22315,7 @@ import { spawn as spawn7 } from "child_process";
|
|
|
21984
22315
|
import { createHash as createHash14, randomUUID as randomUUID19, timingSafeEqual } from "crypto";
|
|
21985
22316
|
import { chmod as chmod2, lstat as lstat12, mkdir as mkdir23, unlink as unlink5 } from "fs/promises";
|
|
21986
22317
|
import { createServer as createServer3, Socket } from "net";
|
|
21987
|
-
import { dirname as
|
|
22318
|
+
import { dirname as dirname23 } from "path";
|
|
21988
22319
|
|
|
21989
22320
|
// src/pals/auth.ts
|
|
21990
22321
|
import { randomBytes as randomBytes3, randomUUID as randomUUID17 } from "crypto";
|
|
@@ -22035,7 +22366,7 @@ function validatePalAuthToken(token) {
|
|
|
22035
22366
|
// src/pals/lifecycle.ts
|
|
22036
22367
|
import { randomUUID as randomUUID18 } from "crypto";
|
|
22037
22368
|
import { mkdir as mkdir22, open as open13, readFile as readFile24, rename as rename11, stat as stat11, unlink as unlink4 } from "fs/promises";
|
|
22038
|
-
import { dirname as
|
|
22369
|
+
import { dirname as dirname22 } from "path";
|
|
22039
22370
|
function defaultProcessAlive(pid) {
|
|
22040
22371
|
if (!Number.isSafeInteger(pid) || pid <= 0) return true;
|
|
22041
22372
|
try {
|
|
@@ -22056,7 +22387,7 @@ function parseMetadata(value) {
|
|
|
22056
22387
|
}
|
|
22057
22388
|
async function acquirePalFileLock(options) {
|
|
22058
22389
|
if (await options.endpointLive()) return void 0;
|
|
22059
|
-
await mkdir22(
|
|
22390
|
+
await mkdir22(dirname22(options.path), { recursive: true, mode: 448 });
|
|
22060
22391
|
const pid = options.pid ?? process.pid;
|
|
22061
22392
|
const now = options.now ?? Date.now;
|
|
22062
22393
|
const nonce = randomUUID18();
|
|
@@ -22525,7 +22856,7 @@ var PalClient = class {
|
|
|
22525
22856
|
};
|
|
22526
22857
|
|
|
22527
22858
|
// src/pals/tools.ts
|
|
22528
|
-
import { z as
|
|
22859
|
+
import { z as z39 } from "zod";
|
|
22529
22860
|
var DEFAULT_SHARE_BUDGET_BYTES = 128 * 1024;
|
|
22530
22861
|
var CollaborationShareGuard = class {
|
|
22531
22862
|
redact;
|
|
@@ -22546,25 +22877,25 @@ var CollaborationShareGuard = class {
|
|
|
22546
22877
|
return redacted;
|
|
22547
22878
|
}
|
|
22548
22879
|
};
|
|
22549
|
-
var Uuid =
|
|
22550
|
-
var Hash =
|
|
22880
|
+
var Uuid = z39.uuid();
|
|
22881
|
+
var Hash = z39.string().regex(/^[a-f0-9]{64}$/);
|
|
22551
22882
|
var Target = PalTargetSchema;
|
|
22552
|
-
var BoundedText =
|
|
22883
|
+
var BoundedText = z39.string().trim().min(1).refine(
|
|
22553
22884
|
(value) => Buffer.byteLength(value, "utf8") <= MAX_MESSAGE_BYTES,
|
|
22554
22885
|
`Text must not exceed ${MAX_MESSAGE_BYTES} UTF-8 bytes`
|
|
22555
22886
|
);
|
|
22556
|
-
var CompletionEvidence =
|
|
22887
|
+
var CompletionEvidence = z39.string().trim().min(1).refine(
|
|
22557
22888
|
(value) => Buffer.byteLength(value, "utf8") <= MAX_COMPLETION_DETAIL_BYTES,
|
|
22558
22889
|
`Completion evidence must not exceed ${MAX_COMPLETION_DETAIL_BYTES} UTF-8 bytes`
|
|
22559
22890
|
);
|
|
22560
|
-
var EmptyInput =
|
|
22561
|
-
var StateInput =
|
|
22562
|
-
var TokenInput =
|
|
22563
|
-
var SendInput =
|
|
22564
|
-
var PlanInput =
|
|
22565
|
-
var ProgressInput =
|
|
22566
|
-
var CompleteInput = TokenInput.extend({ passed:
|
|
22567
|
-
var IntegrateInput = TokenInput.extend({ passed:
|
|
22891
|
+
var EmptyInput = z39.object({}).strict();
|
|
22892
|
+
var StateInput = z39.object({ coWorkId: Uuid }).strict();
|
|
22893
|
+
var TokenInput = z39.object({ coWorkId: Uuid, epoch: z39.number().int().positive(), planHash: Hash }).strict();
|
|
22894
|
+
var SendInput = z39.object({ target: Target, message: BoundedText, coWorkId: Uuid.optional() }).strict();
|
|
22895
|
+
var PlanInput = z39.object({ plan: CoWorkPlanSchema }).strict();
|
|
22896
|
+
var ProgressInput = z39.object({ coWorkId: Uuid, target: Target, detail: BoundedText }).strict();
|
|
22897
|
+
var CompleteInput = TokenInput.extend({ passed: z39.boolean(), detail: CompletionEvidence }).strict();
|
|
22898
|
+
var IntegrateInput = TokenInput.extend({ passed: z39.boolean(), evidence: CompletionEvidence }).strict();
|
|
22568
22899
|
var sharedBytes = (...values) => values.reduce((total, value) => total + Buffer.byteLength(value, "utf8"), 0);
|
|
22569
22900
|
function resolvePresence(presences, target) {
|
|
22570
22901
|
const normalized = normalizePalIdentity(target);
|
|
@@ -23181,7 +23512,7 @@ async function createProductionRuntime(options) {
|
|
|
23181
23512
|
});
|
|
23182
23513
|
const skillsReady = skills.discover();
|
|
23183
23514
|
skillsReady.catch(() => void 0);
|
|
23184
|
-
tools.push(createSkillResourceTool(skills));
|
|
23515
|
+
tools.push(createSkillTool(skills), createSkillResourceTool(skills));
|
|
23185
23516
|
if (options.extraTools !== void 0) tools.push(...options.extraTools);
|
|
23186
23517
|
const flavor = await optionalText2(join29(workspace, "FLAVOR.md"));
|
|
23187
23518
|
const instructionBaseline = await workspaceInstructions.baseline();
|
|
@@ -23883,6 +24214,10 @@ async function createProductionRuntime(options) {
|
|
|
23883
24214
|
subagentModel: () => childModel,
|
|
23884
24215
|
llmServiceName: () => effectiveLlm?.serviceName,
|
|
23885
24216
|
permissionMode: () => harness.permissionMode,
|
|
24217
|
+
addContext: (content) => {
|
|
24218
|
+
const duplicate = harness.main.context.snapshot().messages.some((entry2) => entry2.role === "system" && entry2.content === content);
|
|
24219
|
+
if (!duplicate) harness.main.context.append({ role: "system", content });
|
|
24220
|
+
},
|
|
23886
24221
|
...palServices === void 0 ? {} : { pals: palServices },
|
|
23887
24222
|
run: (prompt, signal, runOptions) => {
|
|
23888
24223
|
interruptedTaskPlanNeedsReassessment = false;
|
|
@@ -24496,7 +24831,7 @@ async function* runMain(harness, skills, prompt, signal, setupError, memory, get
|
|
|
24496
24831
|
if (ideContext !== void 0) contexts.push(ideContext);
|
|
24497
24832
|
const skill = await skills.match(prompt);
|
|
24498
24833
|
if (skill !== void 0) contexts.push(`Matched skill: ${skill.name}
|
|
24499
|
-
${await skills.loadBody(skill)}`);
|
|
24834
|
+
${expandSkillArguments(await skills.loadBody(skill), prompt)}`);
|
|
24500
24835
|
const additionalContext = contexts.length === 0 ? void 0 : contexts.join("\n\n");
|
|
24501
24836
|
for await (const event of harness.main.loop.run({
|
|
24502
24837
|
prompt,
|
|
@@ -24531,7 +24866,7 @@ async function* runExplicitSkill(harness, skills, skillName, prompt, signal, set
|
|
|
24531
24866
|
}
|
|
24532
24867
|
const userPrompt = prompt || `Apply the ${skillName} skill.`;
|
|
24533
24868
|
const additionalContext = `Matched skill: ${skill.name}
|
|
24534
|
-
${await skills.loadBody(skill)}`;
|
|
24869
|
+
${expandSkillArguments(await skills.loadBody(skill), prompt)}`;
|
|
24535
24870
|
yield* harness.main.loop.run({ prompt: userPrompt, signal, additionalContext });
|
|
24536
24871
|
} catch (error) {
|
|
24537
24872
|
yield { type: "error", error: { code: "unknown", message: message(error) } };
|
|
@@ -25087,7 +25422,7 @@ import { basename as basename9, join as join39, resolve as resolve33 } from "pat
|
|
|
25087
25422
|
// src/d2c/workflow.ts
|
|
25088
25423
|
import { createHash as createHash17 } from "crypto";
|
|
25089
25424
|
import { join as join30 } from "path";
|
|
25090
|
-
import { z as
|
|
25425
|
+
import { z as z40 } from "zod";
|
|
25091
25426
|
|
|
25092
25427
|
// src/d2c/workflow-shared.ts
|
|
25093
25428
|
function reviewProgress(workflow) {
|
|
@@ -25110,91 +25445,91 @@ function buildD2cQualityRepairPrompt(task, issue) {
|
|
|
25110
25445
|
}
|
|
25111
25446
|
|
|
25112
25447
|
// src/d2c/workflow.ts
|
|
25113
|
-
var ReviewSchema2 =
|
|
25114
|
-
fingerprint:
|
|
25115
|
-
pageId:
|
|
25116
|
-
reportId:
|
|
25117
|
-
signature:
|
|
25118
|
-
label:
|
|
25119
|
-
decision:
|
|
25120
|
-
instruction:
|
|
25121
|
-
moduleId:
|
|
25122
|
-
moduleSourceFiles:
|
|
25123
|
-
updatedAt:
|
|
25448
|
+
var ReviewSchema2 = z40.object({
|
|
25449
|
+
fingerprint: z40.string().min(1).max(256),
|
|
25450
|
+
pageId: z40.string().min(1).max(128),
|
|
25451
|
+
reportId: z40.string().min(1).max(128),
|
|
25452
|
+
signature: z40.string().regex(/^[a-f0-9]{64}$/),
|
|
25453
|
+
label: z40.string().min(1).max(1e3),
|
|
25454
|
+
decision: z40.enum(["pending", "accepted", "needs-fix"]),
|
|
25455
|
+
instruction: z40.string().max(1e4).optional(),
|
|
25456
|
+
moduleId: z40.string().min(1).max(128).optional(),
|
|
25457
|
+
moduleSourceFiles: z40.array(z40.string().min(1).max(2048)).max(64).optional(),
|
|
25458
|
+
updatedAt: z40.iso.datetime()
|
|
25124
25459
|
}).strict();
|
|
25125
|
-
var InteractionRunSchema =
|
|
25126
|
-
schema:
|
|
25127
|
-
runAt:
|
|
25128
|
-
baseUrl:
|
|
25129
|
-
passed:
|
|
25130
|
-
total:
|
|
25131
|
-
failures:
|
|
25132
|
-
apiRequestCount:
|
|
25133
|
-
scenarios:
|
|
25134
|
-
id:
|
|
25135
|
-
pageUrl:
|
|
25136
|
-
passed:
|
|
25137
|
-
durationMs:
|
|
25138
|
-
apiRequestCount:
|
|
25139
|
-
failure:
|
|
25140
|
-
requests:
|
|
25460
|
+
var InteractionRunSchema = z40.object({
|
|
25461
|
+
schema: z40.literal(1),
|
|
25462
|
+
runAt: z40.iso.datetime(),
|
|
25463
|
+
baseUrl: z40.string().url().max(2048),
|
|
25464
|
+
passed: z40.boolean(),
|
|
25465
|
+
total: z40.number().int().nonnegative().max(5e4),
|
|
25466
|
+
failures: z40.number().int().nonnegative().max(5e4),
|
|
25467
|
+
apiRequestCount: z40.number().int().nonnegative().max(1e7),
|
|
25468
|
+
scenarios: z40.array(z40.object({
|
|
25469
|
+
id: z40.string().min(1).max(128),
|
|
25470
|
+
pageUrl: z40.string().url().max(2048),
|
|
25471
|
+
passed: z40.boolean(),
|
|
25472
|
+
durationMs: z40.number().int().nonnegative().max(864e5),
|
|
25473
|
+
apiRequestCount: z40.number().int().nonnegative().max(1e7),
|
|
25474
|
+
failure: z40.string().max(2e4).optional(),
|
|
25475
|
+
requests: z40.array(z40.object({ method: z40.string().min(1).max(16), path: z40.string().min(1).max(2048), status: z40.number().int().min(0).max(599) }).strict()).max(1e4).optional()
|
|
25141
25476
|
}).strict()).max(5e4),
|
|
25142
|
-
evidenceMode:
|
|
25477
|
+
evidenceMode: z40.enum(["contract", "autonomous", "contract-fallback"]).optional()
|
|
25143
25478
|
}).strict();
|
|
25144
|
-
var QualityJudgmentSchema =
|
|
25145
|
-
schema:
|
|
25146
|
-
runAt:
|
|
25147
|
-
model:
|
|
25148
|
-
visualScore:
|
|
25149
|
-
interactionScore:
|
|
25150
|
-
rawVisualScore:
|
|
25151
|
-
rawInteractionScore:
|
|
25152
|
-
staticVisualScore:
|
|
25153
|
-
deterministicInteractionPassed:
|
|
25154
|
-
overallScore:
|
|
25155
|
-
threshold:
|
|
25156
|
-
verdict:
|
|
25157
|
-
confidence:
|
|
25158
|
-
summary:
|
|
25159
|
-
strengths:
|
|
25160
|
-
evidenceMode:
|
|
25161
|
-
issues:
|
|
25162
|
-
category:
|
|
25163
|
-
severity:
|
|
25164
|
-
description:
|
|
25165
|
-
evidence:
|
|
25166
|
-
recommendation:
|
|
25167
|
-
selector:
|
|
25168
|
-
scoreImpact:
|
|
25169
|
-
id:
|
|
25170
|
-
decision:
|
|
25171
|
-
updatedAt:
|
|
25479
|
+
var QualityJudgmentSchema = z40.object({
|
|
25480
|
+
schema: z40.literal(1),
|
|
25481
|
+
runAt: z40.iso.datetime(),
|
|
25482
|
+
model: z40.string().min(1).max(256),
|
|
25483
|
+
visualScore: z40.number().min(0).max(100),
|
|
25484
|
+
interactionScore: z40.number().min(0).max(100),
|
|
25485
|
+
rawVisualScore: z40.number().min(0).max(100).optional(),
|
|
25486
|
+
rawInteractionScore: z40.number().min(0).max(100).optional(),
|
|
25487
|
+
staticVisualScore: z40.number().min(0).max(100),
|
|
25488
|
+
deterministicInteractionPassed: z40.boolean(),
|
|
25489
|
+
overallScore: z40.number().min(0).max(100),
|
|
25490
|
+
threshold: z40.number().min(0).max(100),
|
|
25491
|
+
verdict: z40.enum(["pass", "fail"]),
|
|
25492
|
+
confidence: z40.enum(["high", "medium", "low"]),
|
|
25493
|
+
summary: z40.string().min(1).max(4e3),
|
|
25494
|
+
strengths: z40.array(z40.string().min(1).max(1e3)).max(20),
|
|
25495
|
+
evidenceMode: z40.enum(["contract", "autonomous", "contract-fallback"]).optional(),
|
|
25496
|
+
issues: z40.array(z40.object({
|
|
25497
|
+
category: z40.enum(["visual", "interaction", "accessibility", "reliability"]),
|
|
25498
|
+
severity: z40.enum(["minor", "major", "critical"]),
|
|
25499
|
+
description: z40.string().min(1).max(2e3),
|
|
25500
|
+
evidence: z40.string().min(1).max(2e3).optional(),
|
|
25501
|
+
recommendation: z40.string().min(1).max(2e3),
|
|
25502
|
+
selector: z40.string().min(1).max(2048).optional(),
|
|
25503
|
+
scoreImpact: z40.number().min(0).max(30).optional(),
|
|
25504
|
+
id: z40.string().regex(/^quality-[a-f0-9]{20}$/).optional(),
|
|
25505
|
+
decision: z40.enum(["pending", "skipped", "fixing"]).optional(),
|
|
25506
|
+
updatedAt: z40.iso.datetime().optional()
|
|
25172
25507
|
}).strict()).max(100)
|
|
25173
25508
|
}).strict();
|
|
25174
|
-
var WorkflowSchema =
|
|
25175
|
-
schema:
|
|
25176
|
-
task:
|
|
25177
|
-
revision:
|
|
25178
|
-
stage:
|
|
25179
|
-
framework:
|
|
25180
|
-
activeReportId:
|
|
25181
|
-
activeBatchId:
|
|
25182
|
-
implementationDir:
|
|
25183
|
-
reviews:
|
|
25184
|
-
openapi:
|
|
25185
|
-
sourceName:
|
|
25186
|
-
importedAt:
|
|
25187
|
-
hash:
|
|
25188
|
-
version:
|
|
25189
|
-
title:
|
|
25190
|
-
baseUrl:
|
|
25509
|
+
var WorkflowSchema = z40.object({
|
|
25510
|
+
schema: z40.literal(1),
|
|
25511
|
+
task: z40.string().regex(D2C_TASK_PATTERN),
|
|
25512
|
+
revision: z40.number().int().nonnegative(),
|
|
25513
|
+
stage: z40.enum(["visual-review", "api-mapping", "integrating", "interaction-review", "quality-judge", "completed"]),
|
|
25514
|
+
framework: z40.enum(["vue", "react"]),
|
|
25515
|
+
activeReportId: z40.string().min(1).max(128),
|
|
25516
|
+
activeBatchId: z40.string().min(1).max(128).optional(),
|
|
25517
|
+
implementationDir: z40.string().min(1).max(32768),
|
|
25518
|
+
reviews: z40.array(ReviewSchema2).max(1e4),
|
|
25519
|
+
openapi: z40.object({
|
|
25520
|
+
sourceName: z40.string().min(1).max(255),
|
|
25521
|
+
importedAt: z40.iso.datetime(),
|
|
25522
|
+
hash: z40.string().regex(/^[a-f0-9]{64}$/),
|
|
25523
|
+
version: z40.string().min(1).max(32),
|
|
25524
|
+
title: z40.string().min(1).max(500),
|
|
25525
|
+
baseUrl: z40.string().max(4096).optional()
|
|
25191
25526
|
}).strict().optional(),
|
|
25192
|
-
mappings:
|
|
25193
|
-
integrationFiles:
|
|
25194
|
-
interaction:
|
|
25527
|
+
mappings: z40.array(z40.unknown()).max(5e3).optional(),
|
|
25528
|
+
integrationFiles: z40.array(z40.string().min(1).max(2048)).max(1e3).optional(),
|
|
25529
|
+
interaction: z40.object({ manualDecision: z40.enum(["pending", "accepted"]), automated: InteractionRunSchema.optional(), updatedAt: z40.iso.datetime() }).strict().optional(),
|
|
25195
25530
|
quality: QualityJudgmentSchema.optional(),
|
|
25196
|
-
qualityWaivers:
|
|
25197
|
-
updatedAt:
|
|
25531
|
+
qualityWaivers: z40.array(z40.object({ issueId: z40.string().regex(/^quality-[a-f0-9]{20}$/), updatedAt: z40.iso.datetime() }).strict()).max(100).optional(),
|
|
25532
|
+
updatedAt: z40.iso.datetime()
|
|
25198
25533
|
}).strict();
|
|
25199
25534
|
function pageId(report) {
|
|
25200
25535
|
return report.page?.id ?? "index";
|
|
@@ -25611,16 +25946,16 @@ function confirmApiMapping(mapping, operationKey, operations) {
|
|
|
25611
25946
|
// src/d2c/modules.ts
|
|
25612
25947
|
import { readFile as readFile26 } from "fs/promises";
|
|
25613
25948
|
import { isAbsolute as isAbsolute15, join as join31, normalize as normalize2, posix, sep as sep23, win32 as win322 } from "path";
|
|
25614
|
-
import { z as
|
|
25615
|
-
var ModuleSchema =
|
|
25616
|
-
id:
|
|
25617
|
-
label:
|
|
25618
|
-
sourceFiles:
|
|
25619
|
-
keywords:
|
|
25620
|
-
dataNeeds:
|
|
25621
|
-
actions:
|
|
25949
|
+
import { z as z41 } from "zod";
|
|
25950
|
+
var ModuleSchema = z41.object({
|
|
25951
|
+
id: z41.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/),
|
|
25952
|
+
label: z41.string().trim().min(1).max(200),
|
|
25953
|
+
sourceFiles: z41.array(z41.string().trim().min(1).max(2048)).min(1).max(64),
|
|
25954
|
+
keywords: z41.array(z41.string().trim().min(1).max(100)).max(100).optional(),
|
|
25955
|
+
dataNeeds: z41.array(z41.string().trim().min(1).max(100)).max(100).optional(),
|
|
25956
|
+
actions: z41.array(z41.string().trim().min(1).max(100)).max(100).optional()
|
|
25622
25957
|
}).strict();
|
|
25623
|
-
var ManifestSchema3 =
|
|
25958
|
+
var ManifestSchema3 = z41.object({ schema: z41.literal(1), modules: z41.array(ModuleSchema).min(1).max(500) }).passthrough();
|
|
25624
25959
|
function safeSource(path) {
|
|
25625
25960
|
if (isAbsolute15(path) || posix.isAbsolute(path) || win322.isAbsolute(path) || path.includes("\0")) return false;
|
|
25626
25961
|
const value = normalize2(path);
|
|
@@ -26062,7 +26397,7 @@ ${managed.output().slice(-4e3)}`);
|
|
|
26062
26397
|
import { createHash as createHash19, randomUUID as randomUUID23 } from "crypto";
|
|
26063
26398
|
import { copyFile as copyFile2, mkdir as mkdir25, readFile as readFile30, rename as rename13, stat as stat12, unlink as unlink6, writeFile as writeFile15 } from "fs/promises";
|
|
26064
26399
|
import { join as join34 } from "path";
|
|
26065
|
-
import { z as
|
|
26400
|
+
import { z as z42 } from "zod";
|
|
26066
26401
|
|
|
26067
26402
|
// src/e2e/prd-governance.ts
|
|
26068
26403
|
import { createHash as createHash18, randomUUID as randomUUID22 } from "crypto";
|
|
@@ -26181,38 +26516,38 @@ var RelativePrototypePath = "product/prototype/index.html";
|
|
|
26181
26516
|
var RelativeInteractionPath = "product/prototype/interaction-manifest.json";
|
|
26182
26517
|
var defaultPlanFileOperations = { rename: rename13, copyFile: copyFile2, unlink: unlink6 };
|
|
26183
26518
|
var planWriteQueues = /* @__PURE__ */ new Map();
|
|
26184
|
-
var PlanSchema2 =
|
|
26185
|
-
schema:
|
|
26186
|
-
task:
|
|
26187
|
-
revision:
|
|
26188
|
-
phase:
|
|
26189
|
-
framework:
|
|
26190
|
-
technology:
|
|
26191
|
-
frontend:
|
|
26192
|
-
backend:
|
|
26193
|
-
frontendSource:
|
|
26194
|
-
backendSource:
|
|
26519
|
+
var PlanSchema2 = z42.object({
|
|
26520
|
+
schema: z42.literal(1),
|
|
26521
|
+
task: z42.string().regex(D2C_TASK_PATTERN),
|
|
26522
|
+
revision: z42.number().int().nonnegative(),
|
|
26523
|
+
phase: z42.enum(["prd-generating", "prd-review", "design-generating", "design-review", "ready-for-d2c"]),
|
|
26524
|
+
framework: z42.enum(["vue", "react"]),
|
|
26525
|
+
technology: z42.object({
|
|
26526
|
+
frontend: z42.string().trim().min(1).max(64),
|
|
26527
|
+
backend: z42.string().trim().min(1).max(64),
|
|
26528
|
+
frontendSource: z42.enum(["default", "requirement"]),
|
|
26529
|
+
backendSource: z42.enum(["default", "requirement"])
|
|
26195
26530
|
}).strict().optional(),
|
|
26196
|
-
requirement:
|
|
26197
|
-
prd:
|
|
26198
|
-
approvedPrd:
|
|
26199
|
-
hash:
|
|
26200
|
-
approvedAt:
|
|
26201
|
-
criteria:
|
|
26531
|
+
requirement: z42.string().trim().min(2).max(5e4),
|
|
26532
|
+
prd: z42.object({ path: z42.literal(RelativePrdPath), updatedAt: z42.iso.datetime(), contentHash: z42.string().regex(/^[a-f0-9]{64}$/).optional() }).strict().optional(),
|
|
26533
|
+
approvedPrd: z42.object({
|
|
26534
|
+
hash: z42.string().regex(/^[a-f0-9]{64}$/),
|
|
26535
|
+
approvedAt: z42.iso.datetime(),
|
|
26536
|
+
criteria: z42.array(z42.object({ id: z42.string().regex(/^AC-\d{3,}$/), text: z42.string().trim().min(1).max(4e3) }).strict()).min(1).max(1e4)
|
|
26202
26537
|
}).strict().optional(),
|
|
26203
|
-
prototype:
|
|
26204
|
-
entryHtml:
|
|
26205
|
-
interactionManifest:
|
|
26206
|
-
updatedAt:
|
|
26207
|
-
contentHash:
|
|
26538
|
+
prototype: z42.object({
|
|
26539
|
+
entryHtml: z42.literal(RelativePrototypePath),
|
|
26540
|
+
interactionManifest: z42.literal(RelativeInteractionPath),
|
|
26541
|
+
updatedAt: z42.iso.datetime(),
|
|
26542
|
+
contentHash: z42.string().regex(/^[a-f0-9]{64}$/).optional()
|
|
26208
26543
|
}).strict().optional(),
|
|
26209
|
-
feedback:
|
|
26210
|
-
stage:
|
|
26211
|
-
message:
|
|
26212
|
-
updatedAt:
|
|
26544
|
+
feedback: z42.object({
|
|
26545
|
+
stage: z42.enum(["prd", "design"]),
|
|
26546
|
+
message: z42.string().trim().min(1).max(1e4),
|
|
26547
|
+
updatedAt: z42.iso.datetime()
|
|
26213
26548
|
}).strict().optional(),
|
|
26214
|
-
createdAt:
|
|
26215
|
-
updatedAt:
|
|
26549
|
+
createdAt: z42.iso.datetime(),
|
|
26550
|
+
updatedAt: z42.iso.datetime()
|
|
26216
26551
|
}).strict();
|
|
26217
26552
|
function d2cProductDirectory(workspace, task) {
|
|
26218
26553
|
if (!D2C_TASK_PATTERN.test(task)) throw new Error("Invalid D2C task name");
|
|
@@ -26373,10 +26708,10 @@ async function writeD2cProductPlan(workspace, plan, operations = defaultPlanFile
|
|
|
26373
26708
|
return parsed;
|
|
26374
26709
|
}
|
|
26375
26710
|
async function createD2cProductPlan(workspace, input, now = () => /* @__PURE__ */ new Date()) {
|
|
26376
|
-
const parsed =
|
|
26377
|
-
task:
|
|
26378
|
-
framework:
|
|
26379
|
-
requirement:
|
|
26711
|
+
const parsed = z42.object({
|
|
26712
|
+
task: z42.string().regex(D2C_TASK_PATTERN),
|
|
26713
|
+
framework: z42.enum(["vue", "react"]),
|
|
26714
|
+
requirement: z42.string().trim().min(2).max(5e4)
|
|
26380
26715
|
}).strict().parse(input);
|
|
26381
26716
|
const timestamp2 = now().toISOString();
|
|
26382
26717
|
if (await readD2cProductPlan(workspace, parsed.task) !== void 0) {
|
|
@@ -26608,31 +26943,31 @@ function createAcceptanceEvidence(coverage, run, now = /* @__PURE__ */ new Date(
|
|
|
26608
26943
|
// src/e2e/delivery-run.ts
|
|
26609
26944
|
import { createHash as createHash21 } from "crypto";
|
|
26610
26945
|
import { join as join35 } from "path";
|
|
26611
|
-
import { z as
|
|
26946
|
+
import { z as z43 } from "zod";
|
|
26612
26947
|
var DELIVERY_NODE_IDS = ["requirement", "prd", "design", "d2c", "api", "acceptance", "delivery"];
|
|
26613
|
-
var ArtifactSchema =
|
|
26614
|
-
path:
|
|
26615
|
-
hash:
|
|
26616
|
-
bytes:
|
|
26617
|
-
createdAt:
|
|
26948
|
+
var ArtifactSchema = z43.object({
|
|
26949
|
+
path: z43.string().min(1).max(32768),
|
|
26950
|
+
hash: z43.string().regex(/^[a-f0-9]{64}$/),
|
|
26951
|
+
bytes: z43.number().int().nonnegative(),
|
|
26952
|
+
createdAt: z43.iso.datetime()
|
|
26618
26953
|
}).strict();
|
|
26619
|
-
var NodeSchema =
|
|
26620
|
-
id:
|
|
26621
|
-
status:
|
|
26622
|
-
attempt:
|
|
26623
|
-
inputs:
|
|
26624
|
-
outputs:
|
|
26625
|
-
startedAt:
|
|
26626
|
-
completedAt:
|
|
26627
|
-
error:
|
|
26954
|
+
var NodeSchema = z43.object({
|
|
26955
|
+
id: z43.enum(DELIVERY_NODE_IDS),
|
|
26956
|
+
status: z43.enum(["pending", "running", "waiting-approval", "succeeded", "failed", "stale"]),
|
|
26957
|
+
attempt: z43.number().int().nonnegative(),
|
|
26958
|
+
inputs: z43.array(ArtifactSchema).max(1e4),
|
|
26959
|
+
outputs: z43.array(ArtifactSchema).max(1e4),
|
|
26960
|
+
startedAt: z43.iso.datetime().optional(),
|
|
26961
|
+
completedAt: z43.iso.datetime().optional(),
|
|
26962
|
+
error: z43.string().max(2e4).optional()
|
|
26628
26963
|
}).strict();
|
|
26629
|
-
var DeliveryRunSchema =
|
|
26630
|
-
schema:
|
|
26631
|
-
task:
|
|
26632
|
-
revision:
|
|
26633
|
-
nodes:
|
|
26634
|
-
createdAt:
|
|
26635
|
-
updatedAt:
|
|
26964
|
+
var DeliveryRunSchema = z43.object({
|
|
26965
|
+
schema: z43.literal(1),
|
|
26966
|
+
task: z43.string().regex(D2C_TASK_PATTERN),
|
|
26967
|
+
revision: z43.number().int().nonnegative(),
|
|
26968
|
+
nodes: z43.record(z43.enum(DELIVERY_NODE_IDS), NodeSchema),
|
|
26969
|
+
createdAt: z43.iso.datetime(),
|
|
26970
|
+
updatedAt: z43.iso.datetime()
|
|
26636
26971
|
}).strict();
|
|
26637
26972
|
var dependencies = {
|
|
26638
26973
|
requirement: [],
|
|
@@ -26765,7 +27100,7 @@ async function updateDeliveryRun(workspace, task, expectedRevision, mutation) {
|
|
|
26765
27100
|
}
|
|
26766
27101
|
|
|
26767
27102
|
// src/skills/manager.ts
|
|
26768
|
-
import { lstat as lstat13, mkdir as mkdir26, readFile as readFile32, readdir as readdir12, realpath as
|
|
27103
|
+
import { lstat as lstat13, mkdir as mkdir26, readFile as readFile32, readdir as readdir12, realpath as realpath13, rm as rm14, writeFile as writeFile16 } from "fs/promises";
|
|
26769
27104
|
import { homedir as homedir3 } from "os";
|
|
26770
27105
|
import { isAbsolute as isAbsolute16, join as join36, relative as relative24, resolve as resolve31, sep as sep24 } from "path";
|
|
26771
27106
|
import { stringify } from "yaml";
|
|
@@ -26862,7 +27197,7 @@ var SkillManager = class {
|
|
|
26862
27197
|
}
|
|
26863
27198
|
async #summary(metadata, disabled) {
|
|
26864
27199
|
const expected = this.#projectSkillDirectory(metadata.name);
|
|
26865
|
-
const editable = metadata.source === "project" && await
|
|
27200
|
+
const editable = metadata.source === "project" && await realpath13(expected).then((physical) => physical === metadata.root).catch(() => false);
|
|
26866
27201
|
return {
|
|
26867
27202
|
...metadata,
|
|
26868
27203
|
enabled: !disabled.has(metadata.name),
|
|
@@ -26914,14 +27249,14 @@ async function discoverPluginSkillRoots(directory) {
|
|
|
26914
27249
|
const roots = [];
|
|
26915
27250
|
for (const entry2 of entries) {
|
|
26916
27251
|
if (!entry2.isDirectory() || entry2.isSymbolicLink()) continue;
|
|
26917
|
-
const pluginRoot = await
|
|
27252
|
+
const pluginRoot = await realpath13(join36(directory, entry2.name));
|
|
26918
27253
|
try {
|
|
26919
27254
|
const manifest = PluginManifestSchema.parse(JSON.parse(await readFile32(join36(pluginRoot, "flavor-plugin.json"), "utf8")));
|
|
26920
27255
|
for (const contribution of manifest.contributes.skillRoots) {
|
|
26921
27256
|
const candidate = resolve31(pluginRoot, contribution.path);
|
|
26922
27257
|
const info = await lstat13(candidate);
|
|
26923
27258
|
if (!info.isDirectory() || info.isSymbolicLink()) continue;
|
|
26924
|
-
const physical = await
|
|
27259
|
+
const physical = await realpath13(candidate);
|
|
26925
27260
|
const relation = relative24(pluginRoot, physical);
|
|
26926
27261
|
if (relation === ".." || relation.startsWith(`..${sep24}`) || isAbsolute16(relation)) continue;
|
|
26927
27262
|
roots.push(physical);
|
|
@@ -27166,7 +27501,7 @@ function protocolLabel(type) {
|
|
|
27166
27501
|
|
|
27167
27502
|
// src/desktop/d2c-product-preview.ts
|
|
27168
27503
|
import { createReadStream as createReadStream2 } from "fs";
|
|
27169
|
-
import { realpath as
|
|
27504
|
+
import { realpath as realpath14, stat as stat13 } from "fs/promises";
|
|
27170
27505
|
import { createServer as createServer5 } from "http";
|
|
27171
27506
|
import { extname as extname3, isAbsolute as isAbsolute17, relative as relative25, resolve as resolve32, sep as sep25 } from "path";
|
|
27172
27507
|
var MIME_TYPES = {
|
|
@@ -27190,7 +27525,7 @@ function isInside(root, candidate) {
|
|
|
27190
27525
|
return delta === "" || !delta.startsWith(`..${sep25}`) && delta !== ".." && !isAbsolute17(delta);
|
|
27191
27526
|
}
|
|
27192
27527
|
async function startD2cProductPreview(rootDirectory) {
|
|
27193
|
-
const root = await
|
|
27528
|
+
const root = await realpath14(resolve32(rootDirectory));
|
|
27194
27529
|
const rootInfo = await stat13(root);
|
|
27195
27530
|
if (!rootInfo.isDirectory()) throw new Error("D2C product prototype directory is unavailable");
|
|
27196
27531
|
const server = createServer5(async (request, response2) => {
|
|
@@ -27204,7 +27539,7 @@ async function startD2cProductPreview(rootDirectory) {
|
|
|
27204
27539
|
if (pathname.includes("\0")) return sendNotFound(response2);
|
|
27205
27540
|
const unresolved = resolve32(root, `.${pathname}`);
|
|
27206
27541
|
if (!isInside(root, unresolved)) return sendNotFound(response2);
|
|
27207
|
-
const target = await
|
|
27542
|
+
const target = await realpath14(unresolved).catch(() => void 0);
|
|
27208
27543
|
if (target === void 0 || !isInside(root, target)) return sendNotFound(response2);
|
|
27209
27544
|
const info = await stat13(target);
|
|
27210
27545
|
if (!info.isFile()) return sendNotFound(response2);
|
|
@@ -28541,14 +28876,14 @@ ${reason.stack ?? ""}`;
|
|
|
28541
28876
|
|
|
28542
28877
|
// src/desktop/main.ts
|
|
28543
28878
|
installCrashGuard();
|
|
28544
|
-
var moduleDirectory =
|
|
28879
|
+
var moduleDirectory = dirname24(fileURLToPath4(import.meta.url));
|
|
28545
28880
|
var developmentUrl = process.env.FLAVOR_DESKTOP_DEV_URL;
|
|
28546
28881
|
var mainWindow;
|
|
28547
28882
|
var appMenu;
|
|
28548
28883
|
var quitting = false;
|
|
28549
28884
|
function logStartup(step, detail) {
|
|
28550
28885
|
try {
|
|
28551
|
-
const logPath = join41(
|
|
28886
|
+
const logPath = join41(dirname24(process.execPath), "flavor-code-startup.log");
|
|
28552
28887
|
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
28553
28888
|
appendFileSync(logPath, `[${ts}] ${step}${detail ? ` | ${detail}` : ""}
|
|
28554
28889
|
`);
|