@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.34
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 +233 -0
- package/README.md +266 -201
- package/dist/adapters.d.ts +0 -4
- package/dist/adapters.js +11 -15
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +92 -50
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/cap.d.ts +8 -5
- package/dist/cap.js +12 -5
- package/dist/cli.js +39 -13
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +30 -2
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +0 -2
- package/dist/errors.js +6 -9
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +14 -15
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +32 -1
- package/dist/learned-workflow.js +100 -9
- package/dist/learning-routes.d.ts +8 -4
- package/dist/learning-routes.js +23 -9
- package/dist/learning-run.d.ts +9 -26
- package/dist/learning-run.js +22 -32
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -49
- package/dist/mcp-gateway.js +44 -135
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +6 -6
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +6 -7
- package/dist/model.js +43 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +121 -47
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +25 -60
- package/dist/propose.js +83 -39
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +10 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +15 -4
- package/dist/run-view.d.ts +7 -8
- package/dist/run-view.js +26 -7
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +6 -1
- package/dist/runner/adapter-loop.js +423 -53
- package/dist/runner/adapter-run-spec.d.ts +21 -8
- package/dist/runner/adapter-run-spec.js +90 -32
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +12 -2
- package/dist/runner/adapters/pi.js +16 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +36 -5
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +48 -14
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +45 -16
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.js +118 -8
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +24 -6
- package/dist/runner/journal-kinds.js +20 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/main.d.ts +56 -9
- package/dist/runner/main.js +127 -18
- package/dist/runner/mcp-claim.js +1 -2
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +133 -9
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +56 -10
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +63 -17
- package/dist/runs-over-store.d.ts +7 -2
- package/dist/runs-over-store.js +60 -14
- package/dist/seal-key.js +5 -43
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +1 -80
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +16 -38
- package/dist/server.js +145 -106
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +18 -2
- package/dist/store/postgres/connection.js +156 -32
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +49 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +41 -12
- package/dist/store/store.d.ts +35 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +9 -6
- package/dist/store-reads/journal.js +93 -17
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +53 -18
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +274 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +14 -42
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +30 -18
- package/dist/tools.js +97 -107
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +24 -6
- package/dist/workspace/computer-deps.js +108 -20
- package/dist/workspace/computer-for-claim.d.ts +12 -11
- package/dist/workspace/computer-for-claim.js +76 -15
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +3 -2
- package/dist/workspace/index.js +3 -3
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -14
- package/dist/workspace.js +3 -96
- package/package.json +13 -13
- package/templates/README.md +9 -3
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
package/dist/graph-view.d.ts
CHANGED
|
@@ -28,7 +28,6 @@ export type GraphInput = {
|
|
|
28
28
|
/** The run has ended: a node it never reached is `not_run`, not `pending`, and its store is read, lock-free. */
|
|
29
29
|
ended: boolean;
|
|
30
30
|
workflow: unknown;
|
|
31
|
-
storeFile: string;
|
|
32
31
|
/** The run's directory: its node log is there. */
|
|
33
32
|
root: string;
|
|
34
33
|
/** The run's input: what a map's items are read from before its state has them. */
|
|
@@ -37,10 +36,9 @@ export type GraphInput = {
|
|
|
37
36
|
modelCost: number | null;
|
|
38
37
|
/** How many of its llm calls' answers its node log held when its rows were last read: their cost is in `modelCost`. */
|
|
39
38
|
llmRead?: number;
|
|
40
|
-
/** The one store and a context:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
context?: Context;
|
|
39
|
+
/** The one store and a context: an ended run's view, pin and decisions are read from its journal (store.readJournal). */
|
|
40
|
+
store: Store;
|
|
41
|
+
context: Context;
|
|
44
42
|
};
|
|
45
43
|
export declare function runGraph(given: GraphInput): Promise<{
|
|
46
44
|
read_at: string;
|
package/dist/graph-view.js
CHANGED
|
@@ -15,20 +15,16 @@ const labelOf = (item) => {
|
|
|
15
15
|
return typeof named === "string" || typeof named === "number" ? String(named) : undefined;
|
|
16
16
|
};
|
|
17
17
|
export async function runGraph(given) {
|
|
18
|
-
const
|
|
19
|
-
import("@parcha/agentrun-dsl/graph"),
|
|
20
|
-
import("@parcha/pi-durable-agent/workflow"),
|
|
21
|
-
import("@parcha/agentrun-pi/durable"),
|
|
22
|
-
]);
|
|
18
|
+
const { graphNodeOf, nodeStatus, workflowGraph } = await import("@parcha/agentrun-dsl/graph");
|
|
23
19
|
const { id } = given.run;
|
|
24
20
|
const graph = workflowGraph(given.workflow);
|
|
25
21
|
let view;
|
|
26
22
|
let pin;
|
|
27
23
|
let receipts;
|
|
28
24
|
let readAt = new Date().toISOString();
|
|
29
|
-
if (given.ended
|
|
30
|
-
// From the one store's journal (store.readJournal)
|
|
31
|
-
//
|
|
25
|
+
if (given.ended) {
|
|
26
|
+
// From the one store's journal (store.readJournal): the run's view and pin as readWorkflowRun reads them, and its
|
|
27
|
+
// decisions as receipts.
|
|
32
28
|
const { store, context } = given;
|
|
33
29
|
const [{ decisionsOverStore }, { readWorkflowRunOver }] = await Promise.all([import("./store-reads/decisions.js"), import("./store-reads/workflow.js")]);
|
|
34
30
|
// The one reader of a workflow run's view over A (node status, outcome, escalation): the workflow-loop builder's.
|
|
@@ -45,12 +41,6 @@ export async function runGraph(given) {
|
|
|
45
41
|
}
|
|
46
42
|
receipts = await decisionsOverStore(store, id, context);
|
|
47
43
|
}
|
|
48
|
-
else if (given.ended) {
|
|
49
|
-
// Lock-free, as every server read of a run's database (run-db.ts): nothing made beside it, never a lock to wait on.
|
|
50
|
-
view = await readWorkflowRun({ runId: id, storePath: given.storeFile, revision: { body: { workflow: given.workflow } } }, { unlocked: true });
|
|
51
|
-
pin = (readJournal(given.storeFile, id, { unlocked: true })?.state?.pin) ?? {};
|
|
52
|
-
receipts = durableDecisions(given.storeFile, { unlocked: true });
|
|
53
|
-
}
|
|
54
44
|
else {
|
|
55
45
|
const live = await readLiveView(given.root);
|
|
56
46
|
pin = live?.pin ?? {};
|
package/dist/handed-values.d.ts
CHANGED
|
@@ -21,3 +21,12 @@ export declare function handedValuesOf(deps: {
|
|
|
21
21
|
}): Promise<{
|
|
22
22
|
refs: string[];
|
|
23
23
|
} | "unreadable">;
|
|
24
|
+
/** Why what an agent learned is withheld (403): a pointer of its sign-in can't be read here, so the cut would be shorter
|
|
25
|
+
* than what a note may hold. */
|
|
26
|
+
export declare const WITHHELD_LEARNING = "This server can't read the agent's browser sign-in (its seal key changed or is missing, or the sign-in is damaged), so what it learned is not shown.";
|
|
27
|
+
/** Every sign-in pointer agent `agentId` ever held, live and forgotten (the store keeps every forgotten one, never only
|
|
28
|
+
* the newest), at each vendor that keeps one (each at least MIN_SECRET long, as every cut takes them): what the learning
|
|
29
|
+
* routes cut beside the server's secrets, so a note, a skill or a run's learning that wrote one never shows it. `unreadable` when one does not open under this server's key, or a read
|
|
30
|
+
* fails: what the agent learned may hold that pointer, so it is withheld (WITHHELD_LEARNING), never shown over a
|
|
31
|
+
* shorter list. */
|
|
32
|
+
export declare function agentPointers(signIns: SignInReader | undefined, agentId: string): Promise<string[] | "unreadable">;
|
package/dist/handed-values.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// sign-ins (live and forgotten) opened to find each pointer the mark names (run-view.ts handedPointers). One read for
|
|
4
4
|
// every place that must cut a run of what it was handed: the store-backed run view (store-view.ts) and the runner's
|
|
5
5
|
// learning end (runner/learning-end.ts), which refuses to learn it.
|
|
6
|
+
import { MIN_SECRET } from "./learn/secrets.js";
|
|
6
7
|
import { handedMark, handedPointers } from "./run-view.js";
|
|
7
8
|
import { readLaunchBody } from "./run-launch.js";
|
|
8
9
|
import { keptVendor } from "./tool-plane.js";
|
|
@@ -34,3 +35,28 @@ export async function handedValuesOf(deps, store, runId, known) {
|
|
|
34
35
|
const browser = launch?.plane ? keptVendor(launch.plane).browser : undefined;
|
|
35
36
|
return handedPointers(deps.signIns, runRow.agentId, browser, handedOf(runRow));
|
|
36
37
|
}
|
|
38
|
+
/** The browser vendors that keep a sign-in (sign-ins-store.ts vendorOf). */
|
|
39
|
+
const SIGN_IN_VENDORS = ["browserbase", "kernel"];
|
|
40
|
+
/** Why what an agent learned is withheld (403): a pointer of its sign-in can't be read here, so the cut would be shorter
|
|
41
|
+
* than what a note may hold. */
|
|
42
|
+
export const WITHHELD_LEARNING = "This server can't read the agent's browser sign-in (its seal key changed or is missing, or the sign-in is damaged), so what it learned is not shown.";
|
|
43
|
+
/** Every sign-in pointer agent `agentId` ever held, live and forgotten (the store keeps every forgotten one, never only
|
|
44
|
+
* the newest), at each vendor that keeps one (each at least MIN_SECRET long, as every cut takes them): what the learning
|
|
45
|
+
* routes cut beside the server's secrets, so a note, a skill or a run's learning that wrote one never shows it. `unreadable` when one does not open under this server's key, or a read
|
|
46
|
+
* fails: what the agent learned may hold that pointer, so it is withheld (WITHHELD_LEARNING), never shown over a
|
|
47
|
+
* shorter list. */
|
|
48
|
+
export async function agentPointers(signIns, agentId) {
|
|
49
|
+
if (!signIns)
|
|
50
|
+
return [];
|
|
51
|
+
const refs = [];
|
|
52
|
+
for (const vendor of SIGN_IN_VENDORS) {
|
|
53
|
+
const live = await signIns.peek(agentId, vendor).catch(() => "unreadable");
|
|
54
|
+
const gone = await signIns.forgotten(agentId, vendor).catch(() => "unreadable");
|
|
55
|
+
if (live === "unreadable" || gone === "unreadable" || gone.unreadable)
|
|
56
|
+
return "unreadable";
|
|
57
|
+
if (live)
|
|
58
|
+
refs.push(live.ref);
|
|
59
|
+
refs.push(...gone.refs);
|
|
60
|
+
}
|
|
61
|
+
return [...new Set(refs)].filter((ref) => ref.length >= MIN_SECRET);
|
|
62
|
+
}
|
|
@@ -83,11 +83,6 @@ export declare function npmInstall(entry: HarnessInstallEntry, dir: string, pins
|
|
|
83
83
|
signal?: AbortSignal;
|
|
84
84
|
onKilled?: () => void;
|
|
85
85
|
}): Promise<void>;
|
|
86
|
-
/** Removes Claude Code as an earlier build installed it, at the top of `harnesses` (read-only, as it left it), so the
|
|
87
|
-
* per-harness installs can go in beside nothing: only when the directory holds that layout and nothing else (any other
|
|
88
|
-
* entry, a per-harness install among them, and it is left as it is). Nothing of the old tree is read or kept. Resolves
|
|
89
|
-
* true when it removed one. */
|
|
90
|
-
export declare function removeFlatInstall(harnesses: string): Promise<boolean>;
|
|
91
86
|
/** How long npm has to exit after a SIGTERM before it gets SIGKILL. Once npm writes (its reify), a SIGTERM only marks
|
|
92
87
|
* it: npm finishes the step under way, which waits on every tarball, before it rolls back and exits, so a slow tarball
|
|
93
88
|
* would hold a server's close. npm writes only into the staging directory, which the install removes. */
|
|
@@ -97,8 +92,7 @@ export declare const NPM_KILLED_WAIT_MS = 5000;
|
|
|
97
92
|
/** The file an install of a harness into `dir` (`<data>/harnesses/<harness>`) keeps in the data directory while it runs,
|
|
98
93
|
* for every process on this data (a runner beside the server, one of its own, or one in another container on the same
|
|
99
94
|
* volume): the installing host and process, and since when. A failed install leaves why in it until the next install;
|
|
100
|
-
* one that lands removes it. In the data directory,
|
|
101
|
-
* its flat install in it, which the install removes first (removeFlatInstall) and which a file of ours would keep. */
|
|
95
|
+
* one that lands removes it. In the data directory, beside `<data>/harnesses`: that directory holds the installs alone. */
|
|
102
96
|
export declare const installMarkOf: (dir: string) => string;
|
|
103
97
|
/** Where a run's claim stands on a harness that installs on first use, in `dir`: "installed" once it is whole; while an
|
|
104
98
|
* install runs (its mark started within INSTALL_TIMEOUT_MS, by a live process when it names this host; another host's
|
package/dist/harness-install.js
CHANGED
|
@@ -215,22 +215,6 @@ export async function npmInstall(entry, dir, pins, { lock = entry.lock, env = pr
|
|
|
215
215
|
throw error instanceof HarnessNotInstalled ? error : fail(error.message);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
-
/** What an earlier build left at the top of `<data>/harnesses`, when it installed Claude Code there itself: its
|
|
219
|
-
* package.json, its lock and its node_modules, and nothing else. */
|
|
220
|
-
const FLAT_INSTALL = new Set(["package.json", "package-lock.json", "node_modules"]);
|
|
221
|
-
/** Removes Claude Code as an earlier build installed it, at the top of `harnesses` (read-only, as it left it), so the
|
|
222
|
-
* per-harness installs can go in beside nothing: only when the directory holds that layout and nothing else (any other
|
|
223
|
-
* entry, a per-harness install among them, and it is left as it is). Nothing of the old tree is read or kept. Resolves
|
|
224
|
-
* true when it removed one. */
|
|
225
|
-
export async function removeFlatInstall(harnesses) {
|
|
226
|
-
const entries = await readdir(harnesses).catch((error) => (error.code === "ENOENT" ? [] : Promise.reject(error)));
|
|
227
|
-
if (!entries.length || !entries.every((name) => FLAT_INSTALL.has(name)) || !(entries.includes("package.json") || entries.includes("node_modules")))
|
|
228
|
-
return false;
|
|
229
|
-
await chmod(harnesses, (await lstat(harnesses)).mode | 0o700);
|
|
230
|
-
for (const name of entries)
|
|
231
|
-
await writable(join(harnesses, name), true).then(() => rm(join(harnesses, name), { recursive: true, force: true }));
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
218
|
/** Every file and directory under `dir` (no link followed) made writable by its owner, or read-only for everyone. */
|
|
235
219
|
async function writable(dir, on) {
|
|
236
220
|
const walk = async (path) => {
|
|
@@ -302,8 +286,7 @@ function runNpm(args, env, timeoutMs, signal, onKilled) {
|
|
|
302
286
|
/** The file an install of a harness into `dir` (`<data>/harnesses/<harness>`) keeps in the data directory while it runs,
|
|
303
287
|
* for every process on this data (a runner beside the server, one of its own, or one in another container on the same
|
|
304
288
|
* volume): the installing host and process, and since when. A failed install leaves why in it until the next install;
|
|
305
|
-
* one that lands removes it. In the data directory,
|
|
306
|
-
* its flat install in it, which the install removes first (removeFlatInstall) and which a file of ours would keep. */
|
|
289
|
+
* one that lands removes it. In the data directory, beside `<data>/harnesses`: that directory holds the installs alone. */
|
|
307
290
|
export const installMarkOf = (dir) => join(dirname(dirname(dir)), `.harness-install-${basename(dir)}.json`);
|
|
308
291
|
/** The mark written whole, beside it then renamed over it: a claim reading it while it changes reads the last mark or the
|
|
309
292
|
* new one, never part of one (which would read as no install). */
|
|
@@ -42,4 +42,11 @@ export interface OpenCodeAdapterOptions {
|
|
|
42
42
|
/** For tests: the fetch the model proxy forwards with. */
|
|
43
43
|
fetch?: typeof fetch;
|
|
44
44
|
}
|
|
45
|
+
/** The skills as the instructions list them: each by name and description, read with `read_skill_file`. The
|
|
46
|
+
* description as YAML reads it (learnedFront, the one front-matter reader: a quoted one's escapes decoded), so a quote
|
|
47
|
+
* in it reaches the model as a quote, never as `\"`; on one line. A SKILL.md that reader can't read whole is a
|
|
48
|
+
* revision's own skill the adapter's check accepted (skillProblems reads its name and description lines alone; a
|
|
49
|
+
* learned one never reaches a run unread, as the learning checker refuses it): its description is that line's
|
|
50
|
+
* (descriptionLine). */
|
|
51
|
+
export declare function skillsNote(skills: readonly Pick<HostSkill, "name" | "files">[]): string;
|
|
45
52
|
export declare function openCodeAdapter(options: OpenCodeAdapterOptions): AgentAdapter;
|
|
@@ -10,13 +10,14 @@
|
|
|
10
10
|
// skill's files with `read_skill_file`: OpenCode's own skills are off.
|
|
11
11
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
12
12
|
import { join } from "node:path";
|
|
13
|
-
import { READ_SKILL_FILE, readSkillFileTool, skillProblems, toolSchemaProblems } from "@parcha/agentrun-kernel";
|
|
13
|
+
import { READ_SKILL_FILE, hostedTool, readSkillFileTool, skillProblems, toolSchemaProblems } from "@parcha/agentrun-kernel";
|
|
14
14
|
import { abortedOutcome, openDrive, pendingSubmissions, SessionHalt } from "@parcha/agentrun-kernel/kernel";
|
|
15
15
|
import { recoveryNote, settleTurn, transcriptOf } from "@parcha/agentrun-kernel/process";
|
|
16
16
|
import { serialWriter, startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
17
17
|
import { openCodeHarness, sentSubmissions } from "./harness.js";
|
|
18
18
|
import { openCodePolicy, TOOL_PREFIX } from "./host/policy.js";
|
|
19
19
|
import { verifyOpenCode } from "./verify.js";
|
|
20
|
+
import { learnedFront } from "../learn/skills.js";
|
|
20
21
|
/** A name OpenCode keeps whole for an MCP tool (it turns anything else into `_`), short enough that `hands_<name>` is a
|
|
21
22
|
* function name the Responses API takes (at most 64). */
|
|
22
23
|
const TOOL_NAME = new RegExp(`^[A-Za-z0-9_-]{1,${64 - TOOL_PREFIX.length}}$`);
|
|
@@ -56,16 +57,32 @@ function adapterEvent(event) {
|
|
|
56
57
|
return undefined;
|
|
57
58
|
}
|
|
58
59
|
const turnsIn = (drive) => transcriptOf(drive.state()).filter((r) => r.data?.type === "turn");
|
|
59
|
-
/** The skills as the instructions list them: each by name and description, read with `read_skill_file`.
|
|
60
|
-
|
|
60
|
+
/** The skills as the instructions list them: each by name and description, read with `read_skill_file`. The
|
|
61
|
+
* description as YAML reads it (learnedFront, the one front-matter reader: a quoted one's escapes decoded), so a quote
|
|
62
|
+
* in it reaches the model as a quote, never as `\"`; on one line. A SKILL.md that reader can't read whole is a
|
|
63
|
+
* revision's own skill the adapter's check accepted (skillProblems reads its name and description lines alone; a
|
|
64
|
+
* learned one never reaches a run unread, as the learning checker refuses it): its description is that line's
|
|
65
|
+
* (descriptionLine). */
|
|
66
|
+
export function skillsNote(skills) {
|
|
61
67
|
const lines = ["You have these skills. Read a skill's SKILL.md with read_skill_file before you use it, and the files it names the same way."];
|
|
62
68
|
for (const skill of skills) {
|
|
63
|
-
const
|
|
64
|
-
const
|
|
69
|
+
const md = skill.files["SKILL.md"] ?? "";
|
|
70
|
+
const front = learnedFront(md);
|
|
71
|
+
const description = ((front ? front.description : descriptionLine(md)) ?? "").replace(/\s+/g, " ").trim();
|
|
65
72
|
lines.push(`- ${skill.name}: ${description}`);
|
|
66
73
|
}
|
|
67
74
|
return lines.join("\n");
|
|
68
75
|
}
|
|
76
|
+
/** A SKILL.md's `description:` line as the adapter's check reads it (skillProblems: the front matter's first
|
|
77
|
+
* `description:` line), its value without one pair of surrounding quotes; undefined with none. */
|
|
78
|
+
function descriptionLine(md) {
|
|
79
|
+
const front = /^---\r?\n([\s\S]*?)\r?\n---\r?\n/.exec(md)?.[1];
|
|
80
|
+
const value = front === undefined ? undefined : /^description:[ \t]*(\S.*?)\s*$/m.exec(front)?.[1];
|
|
81
|
+
if (value === undefined)
|
|
82
|
+
return undefined;
|
|
83
|
+
const quoted = /^(['"])(.*)\1$/.exec(value);
|
|
84
|
+
return quoted ? quoted[2] : value;
|
|
85
|
+
}
|
|
69
86
|
export function openCodeAdapter(options) {
|
|
70
87
|
const skills = options.skills ?? [];
|
|
71
88
|
const skillsWrong = skillProblems(skills);
|
|
@@ -120,7 +137,7 @@ export function openCodeAdapter(options) {
|
|
|
120
137
|
throw new Error("opencode: a session needs a private directory: the host lends one (io.dir), or pass sessionsDir");
|
|
121
138
|
// With skills the model also reads their files (read_skill_file), from the session's own copy of them.
|
|
122
139
|
const skillsDir = join(dir, "skills");
|
|
123
|
-
const tools = skills.length ? [...spec.tools, readSkillFileTool(skillsDir, skills.map((skill) => ({ name: skill.name, files: Object.keys(skill.files) })))] : spec.tools;
|
|
140
|
+
const tools = skills.length ? [...spec.tools, hostedTool(io, readSkillFileTool(skillsDir, skills.map((skill) => ({ name: skill.name, files: Object.keys(skill.files) }))))] : spec.tools;
|
|
124
141
|
if (skills.length) {
|
|
125
142
|
const { mkdirSync, writeFileSync } = await import("node:fs");
|
|
126
143
|
const { dirname } = await import("node:path");
|
|
@@ -5,5 +5,5 @@ export type { HostSkill } from "@parcha/agentrun-kernel";
|
|
|
5
5
|
export type { OpenCodeAdapterOptions, OpenCodeProvider } from "./adapter.js";
|
|
6
6
|
export type { ChildCommand, ConfineChild } from "./host/server.js";
|
|
7
7
|
export { OPENCODE_VERSION, findOpenCode, openCodeBinary } from "./binary.js";
|
|
8
|
-
export { verifyOpenCode, verifyOpenCodeBinary } from "./verify.js";
|
|
8
|
+
export { verifyOpenCode, verifyOpenCodeAsync, verifyOpenCodeBinary, verifyOpenCodeBinaryAsync } from "./verify.js";
|
|
9
9
|
export { OPENCODE_BINARY_SHA256, OPENCODE_INSTALL, OPENCODE_NPM_INTEGRITY, OpenCodeNotInstalled, OpenCodePinMismatch } from "./versions.js";
|
|
@@ -2,5 +2,5 @@ export { openCodeAdapter } from "./adapter.js";
|
|
|
2
2
|
/** The check the adapter runs on the host's skills when it is made: @parcha/agentrun-kernel's own, as the other adapters'. */
|
|
3
3
|
export { skillProblems } from "@parcha/agentrun-kernel";
|
|
4
4
|
export { OPENCODE_VERSION, findOpenCode, openCodeBinary } from "./binary.js";
|
|
5
|
-
export { verifyOpenCode, verifyOpenCodeBinary } from "./verify.js";
|
|
5
|
+
export { verifyOpenCode, verifyOpenCodeAsync, verifyOpenCodeBinary, verifyOpenCodeBinaryAsync } from "./verify.js";
|
|
6
6
|
export { OPENCODE_BINARY_SHA256, OPENCODE_INSTALL, OPENCODE_NPM_INTEGRITY, OpenCodeNotInstalled, OpenCodePinMismatch } from "./versions.js";
|
|
@@ -22,6 +22,14 @@ export declare function verifyOpenCodeBinary(found: {
|
|
|
22
22
|
} | undefined, pins?: OpenCodePins): {
|
|
23
23
|
path: string;
|
|
24
24
|
} | OpenCodePinMismatch | OpenCodeNotInstalled;
|
|
25
|
+
/** verifyOpenCodeBinary without holding the event loop (the kernel's checkedOnceAsync), its pass kept for it too. */
|
|
26
|
+
export declare function verifyOpenCodeBinaryAsync(found: {
|
|
27
|
+
path: string;
|
|
28
|
+
pkg?: string;
|
|
29
|
+
packageVersion?: string;
|
|
30
|
+
} | undefined, pins?: OpenCodePins): Promise<{
|
|
31
|
+
path: string;
|
|
32
|
+
} | OpenCodePinMismatch | OpenCodeNotInstalled>;
|
|
25
33
|
/** This machine's OpenCode checked against the pins: its path, or the typed error thrown. */
|
|
26
34
|
export declare function verifyOpenCode(found?: {
|
|
27
35
|
path: string;
|
|
@@ -30,3 +38,12 @@ export declare function verifyOpenCode(found?: {
|
|
|
30
38
|
} | undefined, pins?: OpenCodePins): {
|
|
31
39
|
path: string;
|
|
32
40
|
};
|
|
41
|
+
/** verifyOpenCode without holding the event loop: what a host awaits before it makes the adapter, whose own check then
|
|
42
|
+
* answers from what this kept. */
|
|
43
|
+
export declare function verifyOpenCodeAsync(found?: {
|
|
44
|
+
path: string;
|
|
45
|
+
pkg?: string;
|
|
46
|
+
packageVersion?: string;
|
|
47
|
+
} | undefined, pins?: OpenCodePins): Promise<{
|
|
48
|
+
path: string;
|
|
49
|
+
}>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// The installed OpenCode checked against the pins (src/versions.ts) before anything runs, with the typed errors a host
|
|
2
2
|
// maps to a run's failure line. Written for AgentRun.
|
|
3
|
-
import { execFileSync } from "node:child_process";
|
|
4
3
|
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
5
4
|
import { tmpdir } from "node:os";
|
|
6
5
|
import { join, resolve } from "node:path";
|
|
7
6
|
import { env } from "node:process";
|
|
8
|
-
import { checkedOnce,
|
|
7
|
+
import { checkedOnce, checkedOnceAsync } from "@parcha/agentrun-kernel/host";
|
|
9
8
|
import { findOpenCode, openCodePackages } from "./binary.js";
|
|
10
9
|
import { OPENCODE_BINARY_SHA256, OPENCODE_VERSION, OpenCodeNotInstalled, OpenCodePinMismatch } from "./versions.js";
|
|
11
10
|
/** The pins this package holds. */
|
|
@@ -19,6 +18,21 @@ export const openCodePins = () => ({ version: OPENCODE_VERSION, sha256: OPENCODE
|
|
|
19
18
|
* directory, where a relative `OPENCODE_BIN` names nothing.
|
|
20
19
|
*/
|
|
21
20
|
export function verifyOpenCodeBinary(found, pins = openCodePins()) {
|
|
21
|
+
const at = located(found, pins);
|
|
22
|
+
// Hashed a chunk at a time, and checked once per binary in this process while it stays the same file, unchanged (the
|
|
23
|
+
// kernel's checkedOnce): a host that checks it for each model it resolves, and a run's process that makes its adapter,
|
|
24
|
+
// check it once. Its reads hold the event loop: a host checks with verifyOpenCodeBinaryAsync first.
|
|
25
|
+
return at instanceof Error ? at : checkedOnce(at.path, at.key, () => checkBinary(at.path, pins.version, at.expected), passed);
|
|
26
|
+
}
|
|
27
|
+
/** verifyOpenCodeBinary without holding the event loop (the kernel's checkedOnceAsync), its pass kept for it too. */
|
|
28
|
+
export async function verifyOpenCodeBinaryAsync(found, pins = openCodePins()) {
|
|
29
|
+
const at = located(found, pins);
|
|
30
|
+
return at instanceof Error ? at : checkedOnceAsync(at.path, at.key, () => checkBinary(at.path, pins.version, at.expected), passed);
|
|
31
|
+
}
|
|
32
|
+
const passed = (result) => !(result instanceof Error);
|
|
33
|
+
/** The absolute path of `found`, there and of the pinned version, with the sha256 values it may have and the pins' key;
|
|
34
|
+
* or why not. */
|
|
35
|
+
function located(found, pins) {
|
|
22
36
|
if (!found)
|
|
23
37
|
return new OpenCodeNotInstalled("no OpenCode binary found for this platform, and OPENCODE_BIN is not set");
|
|
24
38
|
const path = resolve(found.path);
|
|
@@ -29,17 +43,15 @@ export function verifyOpenCodeBinary(found, pins = openCodePins()) {
|
|
|
29
43
|
// A binary from a platform package is checked against that package's pin; one named by OPENCODE_BIN (no package) against
|
|
30
44
|
// the pins of every package this machine may run.
|
|
31
45
|
const expected = (found.pkg ? [found.pkg] : openCodePackages()).map((pkg) => pins.sha256[pkg]).filter((sha) => typeof sha === "string");
|
|
32
|
-
|
|
33
|
-
// kernel's checkedOnce): a host that checks it for each model it resolves, and a run's process that makes its adapter,
|
|
34
|
-
// check it once.
|
|
35
|
-
return checkedOnce(path, JSON.stringify({ version: pins.version, expected }), () => checkBinary(path, pins.version, expected), (result) => !(result instanceof Error));
|
|
46
|
+
return { path, expected, key: JSON.stringify({ version: pins.version, expected }) };
|
|
36
47
|
}
|
|
37
|
-
/** The binary at `path` (absolute, there) against the sha256 values it may have and the version it must report
|
|
38
|
-
|
|
48
|
+
/** The binary at `path` (absolute, there) against the sha256 values it may have and the version it must report, as the
|
|
49
|
+
* steps it reads (the kernel's BinaryCheck). */
|
|
50
|
+
function* checkBinary(path, version, expected) {
|
|
39
51
|
if (expected.length) {
|
|
40
52
|
let sha256;
|
|
41
53
|
try {
|
|
42
|
-
sha256 =
|
|
54
|
+
sha256 = yield { kind: "sha256", path };
|
|
43
55
|
}
|
|
44
56
|
catch (error) {
|
|
45
57
|
return new OpenCodeNotInstalled(`${path} could not be read: ${String(error?.message ?? error).slice(0, 120)}`);
|
|
@@ -53,7 +65,7 @@ function checkBinary(path, version, expected) {
|
|
|
53
65
|
const home = mkdtempSync(join(tmpdir(), "agentrun-opencode-version-"));
|
|
54
66
|
try {
|
|
55
67
|
const dirs = { HOME: home, XDG_CONFIG_HOME: join(home, "config"), XDG_DATA_HOME: join(home, "data"), XDG_CACHE_HOME: join(home, "cache"), XDG_STATE_HOME: join(home, "state") };
|
|
56
|
-
reported =
|
|
68
|
+
reported = (yield { kind: "run", path, args: ["--version"], env: { PATH: env.PATH ?? "/usr/bin:/bin", ...dirs, OPENCODE_DISABLE_AUTOUPDATE: "1" }, cwd: home, timeoutMs: 20_000 }).trim();
|
|
57
69
|
}
|
|
58
70
|
catch (error) {
|
|
59
71
|
return new OpenCodeNotInstalled(`${path} could not be run: ${String(error?.message ?? error).slice(0, 120)}`);
|
|
@@ -73,3 +85,11 @@ export function verifyOpenCode(found = findOpenCode(), pins = openCodePins()) {
|
|
|
73
85
|
throw result;
|
|
74
86
|
return result;
|
|
75
87
|
}
|
|
88
|
+
/** verifyOpenCode without holding the event loop: what a host awaits before it makes the adapter, whose own check then
|
|
89
|
+
* answers from what this kept. */
|
|
90
|
+
export async function verifyOpenCodeAsync(found = findOpenCode(), pins = openCodePins()) {
|
|
91
|
+
const result = await verifyOpenCodeBinaryAsync(found, pins);
|
|
92
|
+
if (result instanceof Error)
|
|
93
|
+
throw result;
|
|
94
|
+
return result;
|
|
95
|
+
}
|
package/dist/harness-table.js
CHANGED
|
@@ -111,7 +111,12 @@ const BUILTIN = Object.freeze({
|
|
|
111
111
|
pins: async () => (await import("./adapters.js")).codexPins(),
|
|
112
112
|
}),
|
|
113
113
|
[openCodeFacts.id]: adapterEntry(openCodeFacts, async (env, needs) => (await import("./adapters.js")).opencodeOf(env, needs), {
|
|
114
|
-
|
|
114
|
+
// Checked as OpenCode is handed them (servedSkills, opencodeOf's): one size check on what it gets.
|
|
115
|
+
skillCheck: async () => {
|
|
116
|
+
const [{ packageSkillCheck }, { servedSkills }] = await Promise.all([import("./adapters.js"), import("./learn/skills.js")]);
|
|
117
|
+
const check = await packageSkillCheck(() => import("./harness-opencode/index.js"));
|
|
118
|
+
return check && ((skills) => check(servedSkills(skills)));
|
|
119
|
+
},
|
|
115
120
|
}),
|
|
116
121
|
});
|
|
117
122
|
const loaded = new Map();
|
package/dist/heard.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// - a trigger's firing whose words come from outside (a webhook body, a Slack or GitHub event): a trigger's input,
|
|
7
7
|
// with its source, never the user's;
|
|
8
8
|
// - any other message the server wrote (a raised cap's follow-up, an approval's resume): left out.
|
|
9
|
-
import { isUserEntry, originMatcher } from "
|
|
9
|
+
import { isUserEntry, originMatcher } from "./timeline/index.js";
|
|
10
10
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11
11
|
/** A user message's text parts, joined as the timeline joins them: an image or a file the message carries is no words. */
|
|
12
12
|
const textOf = (message) => {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FileHandle } from "node:fs/promises";
|
|
2
|
+
/** Keeps `handle` reachable until it is closed. A handle held and never closed stays open until the process exits. */
|
|
3
|
+
export declare function hold(handle: FileHandle): FileHandle;
|
|
4
|
+
/** `/proc/self/fd/<n>` for `handle`, held until it is closed (`hold`). */
|
|
5
|
+
export declare function fdPath(handle: FileHandle): string;
|
package/dist/held-fd.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const HELD = new Set();
|
|
2
|
+
/** Keeps `handle` reachable until it is closed. A handle held and never closed stays open until the process exits. */
|
|
3
|
+
export function hold(handle) {
|
|
4
|
+
if (!HELD.has(handle)) {
|
|
5
|
+
HELD.add(handle);
|
|
6
|
+
// A FileHandle is an EventEmitter that emits `close` once closed (Node's typings leave that out).
|
|
7
|
+
handle.once("close", () => HELD.delete(handle));
|
|
8
|
+
}
|
|
9
|
+
return handle;
|
|
10
|
+
}
|
|
11
|
+
/** `/proc/self/fd/<n>` for `handle`, held until it is closed (`hold`). */
|
|
12
|
+
export function fdPath(handle) {
|
|
13
|
+
return `/proc/self/fd/${hold(handle).fd}`;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** A host tool's answer, as HostTool.call gives it. */
|
|
2
|
+
export type HostAnswer = {
|
|
3
|
+
text: string;
|
|
4
|
+
isError?: boolean;
|
|
5
|
+
};
|
|
6
|
+
/** What the loop lends a call it runs: an MCP tool of the run by its catalog name (`mcp:<server>/<tool>`), as the loop
|
|
7
|
+
* wrapped it, or undefined when the run has no such tool; and, when a person approved the call it runs, the arguments
|
|
8
|
+
* its approval card showed them (the call's ask as journaled: what they saw, never what the gate would show now);
|
|
9
|
+
* undefined when no person approved it. */
|
|
10
|
+
export type HostCalls = {
|
|
11
|
+
readonly mcp: (tool: string) => ((args: unknown, ctx: {
|
|
12
|
+
callId: string;
|
|
13
|
+
signal: AbortSignal;
|
|
14
|
+
}) => Promise<HostAnswer>) | undefined;
|
|
15
|
+
readonly approved: Readonly<Record<string, unknown>> | undefined;
|
|
16
|
+
};
|
|
17
|
+
/** `work` with `lent` as the calls its tool may make. */
|
|
18
|
+
export declare const withHostCalls: <T>(lent: HostCalls, work: () => Promise<T>) => Promise<T>;
|
|
19
|
+
/** The calls the tool running now may make; undefined outside a loop's call (a server-side run, a test calling a tool). */
|
|
20
|
+
export declare const hostCalls: () => HostCalls | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// A call the run's own tools make of another tool of the run, through the same path the harness's calls take: the
|
|
2
|
+
// adapter loop sets it around each host tool's call (runner/adapter-loop.ts hosted), so a learned workflow's call node
|
|
3
|
+
// that names an MCP tool (learned-workflow.ts runEffect) runs that tool as the loop wrapped it: its flush before the side
|
|
4
|
+
// effect, its paid requests booked on the run's one ledger under the call id given, its record on a CLI's timeline, and
|
|
5
|
+
// the stop's abort. The gate is the caller's to ask first, with the run's own permissions; the loop says only what card
|
|
6
|
+
// a person approved the call it runs inside with (`approved`), so an approval covers what that card named and no more.
|
|
7
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
|
+
const calls = new AsyncLocalStorage();
|
|
9
|
+
/** `work` with `lent` as the calls its tool may make. */
|
|
10
|
+
export const withHostCalls = (lent, work) => calls.run(lent, work);
|
|
11
|
+
/** The calls the tool running now may make; undefined outside a loop's call (a server-side run, a test calling a tool). */
|
|
12
|
+
export const hostCalls = () => calls.getStore();
|
package/dist/host-tools.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
2
|
import { type ToolExecutionApi, type ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
3
|
import type { HostTool } from "@parcha/agentrun-kernel";
|
|
4
|
-
import type { DurableRun } from "@parcha/pi-durable-disk";
|
|
5
|
-
import type { Park, RunGate } from "./tool-gate.js";
|
|
6
4
|
export { workspaceRelative } from "./workspace-paths.js";
|
|
7
5
|
/** Each tool a harness other than pi runs here, by catalog name, and whether a call a crash cut off may run again.
|
|
8
6
|
* `learned_workflow` (learned-workflow.ts LEARNED_WORKFLOW_TOOL, named here as a string so the modules do not import
|
|
@@ -28,10 +26,9 @@ export type ToolResults = Map<string, {
|
|
|
28
26
|
export declare const HOST_API_MEMBERS: readonly ["env", "callId", "commit", "output", "outputWindow", "retainedOutput", "diagnostic", "agent", "models", "conversationId", "snapshot", "conversation", "waitForTask"];
|
|
29
27
|
/** The members a host tool's api gives only on a run's Harness: a remote executor's api has none of them. */
|
|
30
28
|
export declare const RUN_ONLY_MEMBERS: readonly ["conversationId", "snapshot", "conversation", "waitForTask"];
|
|
31
|
-
/** What one host tool's call reads of the run
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* (runner/adapter-run-spec.ts), so a tool runs and answers one way on both. */
|
|
29
|
+
/** What one host tool's call reads of the run: the run's environment (its file environment, the api's `env`), its
|
|
30
|
+
* harness's commit and its root agent (a paid call's booking and pi's read), the context and the results map, and the
|
|
31
|
+
* paid-call money seam, over the runner's claim Harness (runner/adapter-run-spec.ts). */
|
|
35
32
|
export interface HostToolCtx {
|
|
36
33
|
readonly context: Context;
|
|
37
34
|
readonly results: ToolResults;
|
|
@@ -44,12 +41,6 @@ export interface HostToolCtx {
|
|
|
44
41
|
readonly snapshot: ToolExecutionApi["snapshot"];
|
|
45
42
|
readonly conversation: ToolExecutionApi["conversation"];
|
|
46
43
|
readonly waitForTask: ToolExecutionApi["waitForTask"];
|
|
47
|
-
/** The run's tool gate and the park it takes; none for the gate's own run of an approved call (the adapter loop's own
|
|
48
|
-
* gate, which gates every host-tool call before its intent). */
|
|
49
|
-
readonly gated?: {
|
|
50
|
-
gate: RunGate;
|
|
51
|
-
park: Park;
|
|
52
|
-
};
|
|
53
44
|
/** A gate for a tool that cannot be run on the runner yet: undefined to run the call, else the refusal that is its answer,
|
|
54
45
|
* so the tool is listed but never run as a stub. No tool sets it now (learned_workflow runs for real on every session's
|
|
55
46
|
* model port); it stays the seam a not-yet-runnable tool refuses through. The paid tools the loop can book
|
|
@@ -59,15 +50,7 @@ export interface HostToolCtx {
|
|
|
59
50
|
} | undefined;
|
|
60
51
|
}
|
|
61
52
|
/** One pi ToolRegistration `tool` (named `name` by its catalog name) as the kernel's HostTool an adapter session takes:
|
|
62
|
-
* the
|
|
53
|
+
* the paid-call seam, then the tool on the run's environment and harness, its answer the text a
|
|
63
54
|
* model reads (the output or the failure, a write's or an error's path named relative to the run's folder). Undefined when
|
|
64
55
|
* `name` is not one a host runs (REPLAY). */
|
|
65
56
|
export declare function hostToolOf(name: string, tool: ToolRegistration, ctx: HostToolCtx): HostTool | undefined;
|
|
66
|
-
/** The host tools `names` names, on the run's coding source `coding`. `gated`: the run's tool gate, which every call
|
|
67
|
-
* passes, and the park it takes (harness-app.ts), told of a call it parked, whose turn the harness ends; none (the
|
|
68
|
-
* gate's own run of an approved call), each call runs as asked. `extra`: the run's own tools beyond the table (its
|
|
69
|
-
* learned_workflow, learned-workflow.ts), which the gate passes like the rest. */
|
|
70
|
-
export declare function hostTools(run: DurableRun, names: readonly string[], context: Context, results: ToolResults, coding?: readonly ToolRegistration[], gated?: {
|
|
71
|
-
gate: RunGate;
|
|
72
|
-
park: Park;
|
|
73
|
-
}, extra?: readonly ToolRegistration[]): HostTool[];
|
package/dist/host-tools.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { withAbortSignal } from "@earendil-works/chord/context";
|
|
2
2
|
import { createModels } from "@earendil-works/pi-ai/models";
|
|
3
3
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { monidTools } from "./monid.js";
|
|
7
|
-
import { booking } from "./paid-calls.js";
|
|
8
|
-
import { withSecrets } from "./secrets.js";
|
|
9
|
-
import { WEB_FETCH_TOOL, webFetchTool } from "./web-fetch.js";
|
|
10
|
-
import { WEB_SEARCH_TOOL, webSearchTool } from "./web-search.js";
|
|
4
|
+
import { WEB_FETCH_TOOL } from "./web-fetch.js";
|
|
5
|
+
import { WEB_SEARCH_TOOL } from "./web-search.js";
|
|
11
6
|
import { realOf, workspaceRelative } from "./workspace-paths.js";
|
|
12
|
-
import { localWorkspace } from "./workspace/index.js";
|
|
13
7
|
import { bounded, imagesOf, textOf } from "./workspace/executors.js";
|
|
14
8
|
export { workspaceRelative } from "./workspace-paths.js";
|
|
15
9
|
/** Each tool a harness other than pi runs here, by catalog name, and whether a call a crash cut off may run again.
|
|
@@ -42,7 +36,7 @@ const hostApi = (given) => new Proxy(given, {
|
|
|
42
36
|
/** The tools whose result is pi's own words about a path (`Successfully wrote to <path>`), never a file's text. */
|
|
43
37
|
const SAYS_PATH = new Set(["write", "edit"]);
|
|
44
38
|
/** One pi ToolRegistration `tool` (named `name` by its catalog name) as the kernel's HostTool an adapter session takes:
|
|
45
|
-
* the
|
|
39
|
+
* the paid-call seam, then the tool on the run's environment and harness, its answer the text a
|
|
46
40
|
* model reads (the output or the failure, a write's or an error's path named relative to the run's folder). Undefined when
|
|
47
41
|
* `name` is not one a host runs (REPLAY). */
|
|
48
42
|
export function hostToolOf(name, tool, ctx) {
|
|
@@ -54,15 +48,7 @@ export function hostToolOf(name, tool, ctx) {
|
|
|
54
48
|
description: tool.description,
|
|
55
49
|
inputSchema: tool.parameters,
|
|
56
50
|
replay,
|
|
57
|
-
async call(args, { callId, signal
|
|
58
|
-
// A replay (the kernel's attempt above 0) may follow an attempt that was sent: the gate's refusal then says so.
|
|
59
|
-
const refused = await ctx.gated?.gate.enter(name, args, callId, ctx.gated.park, (attempt ?? 0) > 0 ? { replayed: true } : {});
|
|
60
|
-
if (refused) {
|
|
61
|
-
const answer = { text: refused.text, isError: refused.isError };
|
|
62
|
-
ctx.results.set(callId, answer);
|
|
63
|
-
// A parked call did not run: the harness's session records it so (HostTool's `parked`).
|
|
64
|
-
return refused.parked ? { ...answer, parked: true } : answer;
|
|
65
|
-
}
|
|
51
|
+
async call(args, { callId, signal }) {
|
|
66
52
|
// The unready-tool seam: a tool that cannot be run on the runner yet is refused in words, never run as a stub.
|
|
67
53
|
const unsettled = ctx.settle?.(name, args, callId);
|
|
68
54
|
if (unsettled) {
|
|
@@ -100,46 +86,3 @@ export function hostToolOf(name, tool, ctx) {
|
|
|
100
86
|
},
|
|
101
87
|
};
|
|
102
88
|
}
|
|
103
|
-
/** The host tools `names` names, on the run's coding source `coding`. `gated`: the run's tool gate, which every call
|
|
104
|
-
* passes, and the park it takes (harness-app.ts), told of a call it parked, whose turn the harness ends; none (the
|
|
105
|
-
* gate's own run of an approved call), each call runs as asked. `extra`: the run's own tools beyond the table (its
|
|
106
|
-
* learned_workflow, learned-workflow.ts), which the gate passes like the rest. */
|
|
107
|
-
export function hostTools(run, names, context, results, coding = CodingTools.tools ?? [], gated, extra = []) {
|
|
108
|
-
// The coding source gives the coding tools and nothing else: the network tools are this machine's own, below.
|
|
109
|
-
const stray = coding.map((tool) => tool.name).filter((name) => !BOXED_TOOLS.includes(name));
|
|
110
|
-
if (stray.length)
|
|
111
|
-
throw new Error(`the coding source holds ${stray.join(", ")}, which is no coding tool`);
|
|
112
|
-
// Their paid requests (Parallel's) are booked under the call, in the run's store, as pi's are (paid-calls.ts).
|
|
113
|
-
const web = [webFetchTool(process.env), webSearchTool(process.env)].map(booking);
|
|
114
|
-
// monid's, only for a run that names one: its key is the one this process was handed over its pipe (secrets.ts),
|
|
115
|
-
// never in its environment, and its long answers go in the run's work/, the claim's as pi's (`where.work`), read at
|
|
116
|
-
// the call. They are outside the coding source, which holds the coding tools only.
|
|
117
|
-
const monid = names.some((name) => name.startsWith("monid.")) ? monidTools(withSecrets(process.env), () => localWorkspace(run.claim.work)) : [];
|
|
118
|
-
// `extra`: the run's own tools beyond the table, its learned_workflow (learned-workflow.ts) when its pin names one.
|
|
119
|
-
const tools = new Map([...coding, ...web, ...monid, ...extra].map((tool) => [tool.name, tool]));
|
|
120
|
-
// What each call reads of the run: its environment, its harness's commit and root agent (pi's read asks the calling
|
|
121
|
-
// agent for its model, for an image's limits; a non-pi run's root agent has no pi model, so read uses its default).
|
|
122
|
-
const ctx = {
|
|
123
|
-
context,
|
|
124
|
-
results,
|
|
125
|
-
...(gated ? { gated } : {}),
|
|
126
|
-
env: async () => await run.env({ conversationId: ROOT_CONVERSATION_ID, read: undefined }, context),
|
|
127
|
-
commit: (change, at, options) => run.harness.commit(change, at, options),
|
|
128
|
-
// The run's own Harness, read at the call as commit's is: a document, conversation or task of this run only.
|
|
129
|
-
snapshot: ((...args) => Reflect.apply(run.harness.snapshot, run.harness, args)),
|
|
130
|
-
conversation: ((id, at) => run.harness.conversation(id, at)),
|
|
131
|
-
waitForTask: (id, at) => run.harness.waitForTask(id, at),
|
|
132
|
-
agent: async (at) => {
|
|
133
|
-
const root = await run.harness.conversation(ROOT_CONVERSATION_ID, at);
|
|
134
|
-
if (!root)
|
|
135
|
-
throw new Error("the run has no root conversation");
|
|
136
|
-
return root.agent(at);
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
// The registrations are keyed by their wire names: the same name for every tool here but monid's.
|
|
140
|
-
return names.flatMap((name) => {
|
|
141
|
-
const tool = tools.get(wireName(name));
|
|
142
|
-
const host = tool ? hostToolOf(name, tool, ctx) : undefined;
|
|
143
|
-
return host ? [host] : [];
|
|
144
|
-
});
|
|
145
|
-
}
|
package/dist/host.d.ts
CHANGED
|
@@ -22,10 +22,8 @@ export declare function runsThatFit(harness: string, memory: number): number;
|
|
|
22
22
|
export declare const defaultMaxRuns: (memory: number) => number;
|
|
23
23
|
/** Why no run of `harness` can ever start on a host of `memory` bytes, in words; undefined when one fits. */
|
|
24
24
|
export declare function neverFits(harness: string, memory: number): string | undefined;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
/** The cap on how many runs at once: `given`, else `AGENTRUN_MAX_RUNS`, else the default for this host's memory. The
|
|
28
|
-
* memory each run reserves is checked beside it (runs.ts): both apply. */
|
|
25
|
+
/** The cap on how many runs at once: `given`, else `AGENTRUN_MAX_RUNS`, else the default for this host's memory. A runner
|
|
26
|
+
* holds at most this many; a run past it waits queued, never refused for a place. */
|
|
29
27
|
export declare function maxRunsOf(env: NodeJS.ProcessEnv, given?: number): number;
|
|
30
28
|
export type Health = {
|
|
31
29
|
status: "ok" | "failing";
|