agent-neckbeard 1.1.28 → 1.1.30
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/CHANGELOG.md +12 -0
- package/README.md +28 -30
- package/dist/archil.d.ts +73 -0
- package/dist/archil.js +673 -0
- package/dist/build.cjs +129 -5160
- package/dist/build.d.cts +9 -5
- package/dist/build.d.ts +9 -5
- package/dist/build.js +4 -6
- package/dist/{chunk-JF5YPOBY.js → chunk-FHNQ5DNA.js} +3235 -511
- package/dist/{chunk-M7XNBKG4.js → chunk-I5GIWADK.js} +29 -7
- package/dist/chunk-I5NULOJP.js +129 -0
- package/dist/chunk-PKUGXECR.js +13 -0
- package/dist/chunk-QA4L7ZI2.js +72 -0
- package/dist/{chunk-KG6SJM74.js → chunk-VHBDBB3N.js} +8 -5
- package/dist/cli.cjs +124 -5154
- package/dist/cli.js +7 -8
- package/dist/define-gdmBe9RA.d.ts +227 -0
- package/dist/durable.d.ts +53 -0
- package/dist/durable.js +92 -0
- package/dist/index.cjs +720 -833
- package/dist/index.d.cts +139 -78
- package/dist/index.d.ts +139 -78
- package/dist/index.js +12 -11
- package/dist/inside.d.ts +15 -0
- package/dist/inside.js +530 -0
- package/dist/{invoke-client-P2CPBYTF.js → invoke-client-QB2NTZ3L.js} +1 -2
- package/dist/pi-watch-legacy.d.ts +4503 -0
- package/dist/serve.cjs +9 -309
- package/dist/serve.d.cts +14 -1
- package/dist/serve.d.ts +14 -1
- package/dist/serve.js +3 -5
- package/docs/AGENT.md +95 -59
- package/docs/DAYTONA.md +2 -0
- package/docs/DOCKER.md +0 -1
- package/docs/E2B.md +1 -1
- package/docs/LEGACY.md +1 -8
- package/docs/MODAL.md +1 -1
- package/package.json +57 -23
- package/types/pi-watch.d.cts +68 -0
- package/dist/chunk-33IXN6MM.js +0 -21
- package/dist/chunk-6P5I7ZCH.js +0 -2552
- package/dist/chunk-M3FISP7J.js +0 -377
- package/dist/sandbox-capabilities-CFjnZ_kB.d.cts +0 -77
- package/dist/sandbox-capabilities-CFjnZ_kB.d.ts +0 -77
- package/dist/serve-Dan1HQKN.d.cts +0 -89
- package/dist/serve-Dan1HQKN.d.ts +0 -89
- package/dist/supervisor.cjs +0 -5731
- package/dist/supervisor.d.cts +0 -482
- package/dist/supervisor.d.ts +0 -482
- package/dist/supervisor.js +0 -3187
- package/docs/SUPERVISOR.md +0 -258
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BRAINTRUST_PACKAGE,
|
|
3
3
|
BRAINTRUST_VERSIONS,
|
|
4
|
-
PI_PACKAGE,
|
|
5
4
|
isDefinedAgent,
|
|
6
5
|
isSupportedBraintrustVersion,
|
|
7
6
|
resolveImageTag
|
|
8
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-FHNQ5DNA.js";
|
|
9
8
|
|
|
10
9
|
// src/build.ts
|
|
11
10
|
import { execFile } from "child_process";
|
|
@@ -22,6 +21,17 @@ import { spawn } from "child_process";
|
|
|
22
21
|
import { mkdtemp, rm } from "fs/promises";
|
|
23
22
|
import { tmpdir } from "os";
|
|
24
23
|
import path from "path";
|
|
24
|
+
|
|
25
|
+
// src/archil-image.ts
|
|
26
|
+
import { execFileSync } from "child_process";
|
|
27
|
+
function archilToolsImage(definition, tag) {
|
|
28
|
+
if (!tag || !/^[0-9a-f]{40}$/.test(tag) || !definition.registry) {
|
|
29
|
+
throw new Error("Archil tools images require a registry and one full commit SHA tag.");
|
|
30
|
+
}
|
|
31
|
+
return definition.registry.replace(/\/+$/, "") + "/" + definition.name + "-tools:" + tag;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/push.ts
|
|
25
35
|
async function pushAgent(options) {
|
|
26
36
|
const log = options.onLog ?? (() => void 0);
|
|
27
37
|
const packageDir = path.resolve(options.cwd ?? process.cwd());
|
|
@@ -36,13 +46,17 @@ async function buildAndPush(options, packageDir, outDir, log) {
|
|
|
36
46
|
const { agent } = await buildAgent({
|
|
37
47
|
module: options.module,
|
|
38
48
|
...options.exportName ? { exportName: options.exportName } : {},
|
|
49
|
+
toolsOnly: Boolean(options.archilDockerfile),
|
|
39
50
|
cwd: packageDir,
|
|
40
51
|
outDir,
|
|
41
52
|
onLog: log
|
|
42
53
|
});
|
|
43
54
|
const tags = options.tags?.length ? options.tags : [resolveImageTag()];
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
if (options.archilDockerfile && tags.length !== 1) {
|
|
56
|
+
throw new Error("Archil tools images require a registry and one full commit SHA tag.");
|
|
57
|
+
}
|
|
58
|
+
const images = options.archilDockerfile ? [archilToolsImage(agent.definition, tags[0])] : agent.definition.image ? [agent.definition.image] : tags.map((tag) => agent.imageRef(tag));
|
|
59
|
+
const dockerfile = path.resolve(packageDir, options.archilDockerfile ?? agent.definition.build?.dockerfile ?? "sandbox/Dockerfile");
|
|
46
60
|
const tagArgs = images.flatMap((image) => ["--tag", image]);
|
|
47
61
|
const platformArgs = ["--platform", "linux/amd64"];
|
|
48
62
|
const command = options.docker ?? "docker";
|
|
@@ -64,7 +78,8 @@ async function buildAndPush(options, packageDir, outDir, log) {
|
|
|
64
78
|
await docker(command, ["build", "--file", dockerfile, ...platformArgs, ...tagArgs, outDir]);
|
|
65
79
|
if (!options.dryRun) for (const image of images) await docker(command, ["push", image]);
|
|
66
80
|
}
|
|
67
|
-
if (options.dryRun) return { images, artifacts: [], deleted: [] };
|
|
81
|
+
if (options.dryRun || options.archilDockerfile) return { images, artifacts: [], deleted: [] };
|
|
82
|
+
if (!("forImage" in agent)) throw new Error("Archil agents require a tools-only image build.");
|
|
68
83
|
const clients = images.map((image) => agent.forImage(image));
|
|
69
84
|
for (const client of clients) await client.prepare({ onLog: log, refresh: true });
|
|
70
85
|
const artifacts = clients.map((client) => client.artifactName);
|
|
@@ -101,11 +116,19 @@ async function buildAgent(options) {
|
|
|
101
116
|
const outDir = path2.resolve(packageDir, options.outDir ?? "dist-sandbox");
|
|
102
117
|
const module = path2.resolve(packageDir, options.module);
|
|
103
118
|
const { agent, exportName } = await loadAgent(module, options.exportName);
|
|
119
|
+
if (!options.toolsOnly && !("forImage" in agent)) throw new Error("Archil agents require a tools-only image build.");
|
|
104
120
|
await resetOutDir(packageDir, outDir, module);
|
|
105
121
|
const skills = await installSkills(packageDir, path2.join(outDir, ".agents", "skills"), options.onLog);
|
|
122
|
+
const index = [...skills.own, ...skills.locked].map((name) => `- ${name}: /app/.agents/skills/${name}/SKILL.md`).join("\n");
|
|
123
|
+
await writeFile(path2.join(outDir, ".agents", "skills", "index.txt"), index);
|
|
124
|
+
if (options.toolsOnly) {
|
|
125
|
+
return { agent, outDir, dependencies: {}, skills };
|
|
126
|
+
}
|
|
106
127
|
const entry = [
|
|
107
128
|
`import * as agentModule from ${JSON.stringify(module)};`,
|
|
108
|
-
`agentModule[${JSON.stringify(exportName)}]
|
|
129
|
+
`const agent = agentModule[${JSON.stringify(exportName)}];`,
|
|
130
|
+
`import { openInsideConversation, serveConversation } from ${JSON.stringify(path2.join(path2.dirname(neckbeardRequire.resolve("agent-neckbeard")), "inside.js"))};`,
|
|
131
|
+
"serveConversation(agent.definition.createSession ?? (() => openInsideConversation(agent.definition.pi, undefined, agent.definition.maxTurnDurationMs))).catch((error) => {",
|
|
109
132
|
" console.error(error);",
|
|
110
133
|
" process.exit(1);",
|
|
111
134
|
"});"
|
|
@@ -204,7 +227,6 @@ async function bundle(entry, packageDir, outDir, external, piSession) {
|
|
|
204
227
|
});
|
|
205
228
|
if (piSession) {
|
|
206
229
|
const pin = (name, version) => versions.set(name, (versions.get(name) ?? /* @__PURE__ */ new Set()).add(version));
|
|
207
|
-
pin(PI_PACKAGE, await installedVersion(packageDir, PI_PACKAGE));
|
|
208
230
|
if (traced) {
|
|
209
231
|
const version = await installedVersion(packageDir, BRAINTRUST_PACKAGE);
|
|
210
232
|
if (!isSupportedBraintrustVersion(version)) {
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// src/durable-harness.ts
|
|
2
|
+
import { createRegistry, Harness, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
3
|
+
import { getOrThrow } from "@earendil-works/pi-durable/env";
|
|
4
|
+
import { CodingTools } from "@earendil-works/pi-durable/tools";
|
|
5
|
+
import { withoutAbortSignal } from "@earendil-works/chord/context";
|
|
6
|
+
async function openDurableHarness({ definition, storage, executionEnv, models, onReport, init }, context) {
|
|
7
|
+
const pi = definition.pi;
|
|
8
|
+
if (!pi) throw new Error("A durable harness requires a Pi definition.");
|
|
9
|
+
const separator = pi.model.indexOf("/");
|
|
10
|
+
if (separator < 1 || separator === pi.model.length - 1) throw new Error("Expected provider/model.");
|
|
11
|
+
const registry = createRegistry();
|
|
12
|
+
registry.install(CodingTools);
|
|
13
|
+
const getEnv = typeof executionEnv === "function" ? executionEnv : () => executionEnv;
|
|
14
|
+
const harness = await Harness.open(storage, { registry, models, env: getEnv, onReport }, context);
|
|
15
|
+
try {
|
|
16
|
+
const rootEnv = await getEnv({ conversationId: ROOT_CONVERSATION_ID, cwd: pi.cwd, read: harness }, context);
|
|
17
|
+
if (!rootEnv) throw new Error("Missing execution environment for the root conversation");
|
|
18
|
+
const result = await rootEnv.readTextFile("/app/.agents/skills/index.txt", context);
|
|
19
|
+
const index = !result.ok && result.error.code === "not_found" ? "" : getOrThrow(result);
|
|
20
|
+
const agent = {
|
|
21
|
+
model: { provider: pi.model.slice(0, separator), modelId: pi.model.slice(separator + 1) },
|
|
22
|
+
instructions: [pi.systemPrompt, index && "Available skills:\n" + index].filter(Boolean).join("\n\n"),
|
|
23
|
+
tools: pi.tools?.map((name) => {
|
|
24
|
+
const tool = CodingTools.tools?.find((tool2) => tool2.name === name);
|
|
25
|
+
if (!tool) throw new Error(`Unknown Pi Durable tool: ${name}`);
|
|
26
|
+
return tool;
|
|
27
|
+
}),
|
|
28
|
+
cwd: rootEnv.cwd,
|
|
29
|
+
thinkingLevel: pi.thinkingLevel
|
|
30
|
+
};
|
|
31
|
+
const restored = await harness.conversation(ROOT_CONVERSATION_ID, context);
|
|
32
|
+
if (restored) {
|
|
33
|
+
await restored.configure({ ...agent, tools: agent.tools ?? null, thinkingLevel: agent.thinkingLevel ?? null }, context);
|
|
34
|
+
return { harness, root: restored };
|
|
35
|
+
}
|
|
36
|
+
const root = await harness.root(context, { agent, init });
|
|
37
|
+
return { harness, root };
|
|
38
|
+
} catch (error) {
|
|
39
|
+
await harness.close(withoutAbortSignal(context));
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function closeDurableResources(harness, storage, executionEnv, context) {
|
|
44
|
+
try {
|
|
45
|
+
if (harness) await harness.close(context);
|
|
46
|
+
else await storage.close(context);
|
|
47
|
+
} finally {
|
|
48
|
+
await executionEnv?.cleanup(context);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/durable-turn.ts
|
|
53
|
+
import { InboxDoc, LiveDoc } from "@earendil-works/pi-durable";
|
|
54
|
+
var durableWatchWindow = { min: 1, max: 4 };
|
|
55
|
+
async function prepareSubmissionStop(tx, conversationId, id) {
|
|
56
|
+
const { run } = await tx.doc(LiveDoc, conversationId);
|
|
57
|
+
if (!run?.inputs.includes(id)) return;
|
|
58
|
+
const inbox = await tx.doc(InboxDoc, conversationId);
|
|
59
|
+
inbox.items = inbox.items.filter((item) => {
|
|
60
|
+
if (item.mode === "write" || item.onAbort === "keep") return true;
|
|
61
|
+
tx.settleSubmission(item.id, { status: "unanswered", reason: "aborted" });
|
|
62
|
+
return false;
|
|
63
|
+
});
|
|
64
|
+
return run.taskId;
|
|
65
|
+
}
|
|
66
|
+
function turnRequestId(turnId) {
|
|
67
|
+
return JSON.stringify(["turn", turnId]);
|
|
68
|
+
}
|
|
69
|
+
function steerRequestId(turnId, steerId) {
|
|
70
|
+
return JSON.stringify(["steer", turnId, steerId]);
|
|
71
|
+
}
|
|
72
|
+
function parseDurableRequestId(requestId) {
|
|
73
|
+
if (!requestId?.startsWith("[")) return;
|
|
74
|
+
let parts;
|
|
75
|
+
try {
|
|
76
|
+
parts = JSON.parse(requestId);
|
|
77
|
+
} catch {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!Array.isArray(parts) || typeof parts[1] !== "string") return;
|
|
81
|
+
if (parts[0] === "turn" && parts.length === 2) return { turnId: parts[1] };
|
|
82
|
+
if (parts[0] === "steer" && parts.length === 3 && typeof parts[2] === "string") return { turnId: parts[1], steerId: parts[2] };
|
|
83
|
+
}
|
|
84
|
+
async function lastPlacedInput(storage, primary, context) {
|
|
85
|
+
const owner = parseDurableRequestId(primary.requestId);
|
|
86
|
+
if (!owner || owner.steerId !== void 0) return primary;
|
|
87
|
+
let cursor;
|
|
88
|
+
do {
|
|
89
|
+
const page = await storage.scanSubmissions({ conversationId: primary.conversationId, order: "descending" }, 64, cursor, context);
|
|
90
|
+
for (const record of page.items) {
|
|
91
|
+
if (record.id <= primary.id) return primary;
|
|
92
|
+
if (record.type !== "input" || record.entry === void 0 || record.status === "placed") continue;
|
|
93
|
+
const id = parseDurableRequestId(record.requestId);
|
|
94
|
+
if (id?.turnId === owner.turnId && id.steerId !== void 0) return record;
|
|
95
|
+
}
|
|
96
|
+
cursor = page.next;
|
|
97
|
+
} while (cursor);
|
|
98
|
+
return primary;
|
|
99
|
+
}
|
|
100
|
+
async function durableTurnResult(storage, submission, context) {
|
|
101
|
+
submission = await lastPlacedInput(storage, submission, context);
|
|
102
|
+
if (submission.status === "unanswered") {
|
|
103
|
+
const detail = submission.detail;
|
|
104
|
+
const error = typeof detail === "string" ? detail : detail == null ? submission.reason : JSON.stringify(detail);
|
|
105
|
+
return { outcome: submission.reason === "aborted" ? "aborted" : "failed", error };
|
|
106
|
+
}
|
|
107
|
+
if (submission.type !== "input") throw new Error("Expected an input submission");
|
|
108
|
+
const saved = await storage.entry(submission.answer, context);
|
|
109
|
+
return answerFromEntry(saved?.entry);
|
|
110
|
+
}
|
|
111
|
+
function answerFromEntry(entry) {
|
|
112
|
+
const message = entry?.model?.find((item) => item.role === "assistant");
|
|
113
|
+
if (!message) return { outcome: "failed", error: "The agent did not reply." };
|
|
114
|
+
if (message.stopReason !== "stop") return { outcome: "failed", error: message.errorMessage || "The agent stopped with " + message.stopReason + "." };
|
|
115
|
+
const answer = message.content.flatMap((block) => block.type === "text" ? [block.text] : []).join("\n").trim() || null;
|
|
116
|
+
return { outcome: "completed", answer };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
openDurableHarness,
|
|
121
|
+
closeDurableResources,
|
|
122
|
+
durableWatchWindow,
|
|
123
|
+
prepareSubmissionStop,
|
|
124
|
+
turnRequestId,
|
|
125
|
+
steerRequestId,
|
|
126
|
+
parseDurableRequestId,
|
|
127
|
+
durableTurnResult,
|
|
128
|
+
answerFromEntry
|
|
129
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/serve.ts
|
|
2
|
+
var insideEntry = "agent-neckbeard/inside";
|
|
3
|
+
async function serve({ createSession, ...options }) {
|
|
4
|
+
const inside = await import(
|
|
5
|
+
/* webpackIgnore: true */
|
|
6
|
+
insideEntry
|
|
7
|
+
);
|
|
8
|
+
return inside.serveConversation(createSession, options);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
serve
|
|
13
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/timeout.ts
|
|
2
|
+
function settleOperation(operation, options = {}) {
|
|
3
|
+
const { abort, timeout } = options;
|
|
4
|
+
if (abort?.signal.aborted) throw abort.createError();
|
|
5
|
+
if (!abort && !timeout) {
|
|
6
|
+
try {
|
|
7
|
+
return Promise.resolve(operation());
|
|
8
|
+
} catch (error) {
|
|
9
|
+
return Promise.reject(error);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
let settled = false;
|
|
14
|
+
let timer;
|
|
15
|
+
const cleanup = () => {
|
|
16
|
+
if (timer !== void 0) {
|
|
17
|
+
clearTimeout(timer);
|
|
18
|
+
timer = void 0;
|
|
19
|
+
}
|
|
20
|
+
abort?.signal.removeEventListener("abort", onAbort);
|
|
21
|
+
};
|
|
22
|
+
const settle = (callback) => {
|
|
23
|
+
if (settled) return;
|
|
24
|
+
settled = true;
|
|
25
|
+
cleanup();
|
|
26
|
+
callback();
|
|
27
|
+
};
|
|
28
|
+
const onAbort = () => settle(() => reject(abort.createError()));
|
|
29
|
+
abort?.signal.addEventListener("abort", onAbort, { once: true });
|
|
30
|
+
if (timeout) {
|
|
31
|
+
timer = setTimeout(
|
|
32
|
+
() => settle(() => reject(timeout.createError())),
|
|
33
|
+
timeout.timeoutMs
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
let task;
|
|
37
|
+
try {
|
|
38
|
+
task = operation();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
settle(() => reject(error));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
void Promise.resolve(task).then(
|
|
44
|
+
(value) => settle(() => resolve(value)),
|
|
45
|
+
(error) => settle(() => reject(error))
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function untilAborted(operation, signal) {
|
|
50
|
+
if (signal?.aborted) return Promise.reject(abortError(signal));
|
|
51
|
+
return settleOperation(operation, signal ? { abort: { signal, createError: () => abortError(signal) } } : {});
|
|
52
|
+
}
|
|
53
|
+
function abortError(signal) {
|
|
54
|
+
if (signal.reason instanceof Error) return signal.reason;
|
|
55
|
+
const error = new Error("Operation aborted.");
|
|
56
|
+
error.name = "AbortError";
|
|
57
|
+
return error;
|
|
58
|
+
}
|
|
59
|
+
function withTimeout(task, timeoutMs, message) {
|
|
60
|
+
return settleOperation(() => task, {
|
|
61
|
+
timeout: {
|
|
62
|
+
timeoutMs,
|
|
63
|
+
createError: () => new Error(message)
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
settleOperation,
|
|
70
|
+
untilAborted,
|
|
71
|
+
withTimeout
|
|
72
|
+
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// src/serialized-error.ts
|
|
2
|
+
function isSerializedError(value) {
|
|
3
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
4
|
+
const candidate = value;
|
|
5
|
+
return typeof candidate.message === "string" && (candidate.name === void 0 || typeof candidate.name === "string") && (candidate.stack === void 0 || typeof candidate.stack === "string");
|
|
6
|
+
}
|
|
4
7
|
|
|
5
8
|
// src/runtime/protocol.ts
|
|
6
9
|
var RUNTIME_PROTOCOL_VERSION = 1;
|
|
@@ -44,7 +47,7 @@ function hasValidMetadata(candidate) {
|
|
|
44
47
|
// src/sse-framing.ts
|
|
45
48
|
var IncompleteSseFrameError = class extends Error {
|
|
46
49
|
};
|
|
47
|
-
async function* decodeSseStream(chunks) {
|
|
50
|
+
async function* decodeSseStream(chunks, options = {}) {
|
|
48
51
|
let buffer = "";
|
|
49
52
|
for await (const chunk of chunks) {
|
|
50
53
|
buffer += chunk;
|
|
@@ -61,6 +64,7 @@ async function* decodeSseStream(chunks) {
|
|
|
61
64
|
}
|
|
62
65
|
const tail = buffer.trim();
|
|
63
66
|
if (tail.length > 0) {
|
|
67
|
+
if (options.requireTerminator) throw new IncompleteSseFrameError("Stream ended during an SSE frame.");
|
|
64
68
|
let parsed;
|
|
65
69
|
try {
|
|
66
70
|
parsed = parseFrame(tail);
|
|
@@ -92,6 +96,5 @@ export {
|
|
|
92
96
|
RUNTIME_PROTOCOL_VERSION,
|
|
93
97
|
RUNTIME_ABORT_GRACE_MS,
|
|
94
98
|
isHarnessEvent,
|
|
95
|
-
IncompleteSseFrameError,
|
|
96
99
|
decodeSseStream
|
|
97
100
|
};
|