@culture.dev/agents 0.15.3 → 0.16.1
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 +22 -0
- package/dist/contract-schemas/api.json +73 -15
- package/dist/contract-schemas/branches.json +163 -0
- package/dist/contract-schemas/capabilities.json +133 -6
- package/dist/contract-schemas/common.json +9 -3
- package/dist/contract-schemas/control-action.json +91 -14
- package/dist/contract-schemas/error.json +189 -48
- package/dist/contract-schemas/event.json +185 -2
- package/dist/contract-schemas/run.json +111 -4
- package/dist/contract-schemas/version.json +2 -2
- package/dist/src/contract/generated/branches.d.ts +34 -0
- package/dist/src/contract/generated/branches.js +3 -0
- package/dist/src/contract/generated/branches.js.map +1 -0
- package/dist/src/contract/generated/capabilities.d.ts +39 -7
- package/dist/src/contract/generated/common.d.ts +5 -3
- package/dist/src/contract/generated/control-action.d.ts +30 -11
- package/dist/src/contract/generated/error.d.ts +31 -7
- package/dist/src/contract/generated/event.d.ts +57 -8
- package/dist/src/contract/generated/index.d.ts +37 -12
- package/dist/src/contract/generated/run.d.ts +23 -5
- package/dist/src/contract/generated/version.d.ts +2 -2
- package/dist/src/contract/ids.d.ts +6 -3
- package/dist/src/contract/ids.js +5 -2
- package/dist/src/contract/ids.js.map +1 -1
- package/dist/src/contract/index.d.ts +1 -1
- package/dist/src/contract/index.js +1 -1
- package/dist/src/contract/index.js.map +1 -1
- package/dist/src/daemon/branch-routes.d.ts +13 -0
- package/dist/src/daemon/branch-routes.js +41 -0
- package/dist/src/daemon/branch-routes.js.map +1 -0
- package/dist/src/daemon/daemon.js +10 -2
- package/dist/src/daemon/daemon.js.map +1 -1
- package/dist/src/daemon/harness-catalog.d.ts +6 -0
- package/dist/src/daemon/harness-catalog.js +20 -0
- package/dist/src/daemon/harness-catalog.js.map +1 -1
- package/dist/src/daemon/limits.d.ts +31 -0
- package/dist/src/daemon/limits.js +61 -0
- package/dist/src/daemon/limits.js.map +1 -0
- package/dist/src/daemon/main.d.ts +10 -0
- package/dist/src/daemon/main.js +161 -41
- package/dist/src/daemon/main.js.map +1 -1
- package/dist/src/daemon/ports.d.ts +21 -11
- package/dist/src/daemon/routes.d.ts +3 -0
- package/dist/src/daemon/routes.js +26 -5
- package/dist/src/daemon/routes.js.map +1 -1
- package/dist/src/daemon/secrets.d.ts +24 -0
- package/dist/src/daemon/secrets.js +52 -0
- package/dist/src/daemon/secrets.js.map +1 -0
- package/dist/src/daemon/submitter.d.ts +9 -0
- package/dist/src/daemon/submitter.js +23 -0
- package/dist/src/daemon/submitter.js.map +1 -0
- package/dist/src/harness/claude-code/index.js +1 -1
- package/dist/src/harness/claude-code/index.js.map +1 -1
- package/dist/src/harness/common/capabilities.d.ts +26 -2
- package/dist/src/harness/common/capabilities.js +31 -6
- package/dist/src/harness/common/capabilities.js.map +1 -1
- package/dist/src/harness/common/guard.d.ts +2 -1
- package/dist/src/harness/common/guard.js +6 -0
- package/dist/src/harness/common/guard.js.map +1 -1
- package/dist/src/harness/common/run-driver.d.ts +6 -1
- package/dist/src/harness/common/run-driver.js +20 -3
- package/dist/src/harness/common/run-driver.js.map +1 -1
- package/dist/src/harness/common/sandbox-workspace.d.ts +5 -1
- package/dist/src/harness/common/sandbox-workspace.js +12 -3
- package/dist/src/harness/common/sandbox-workspace.js.map +1 -1
- package/dist/src/harness/common/types.d.ts +8 -0
- package/dist/src/harness/config.d.ts +5 -0
- package/dist/src/harness/config.js +7 -3
- package/dist/src/harness/config.js.map +1 -1
- package/dist/src/harness/index.js +2 -2
- package/dist/src/harness/index.js.map +1 -1
- package/dist/src/harness/opencode/index.js +1 -1
- package/dist/src/harness/opencode/index.js.map +1 -1
- package/dist/src/harness/stub/backend.d.ts +3 -0
- package/dist/src/harness/stub/backend.js +50 -1
- package/dist/src/harness/stub/backend.js.map +1 -1
- package/dist/src/harness/stub/index.d.ts +7 -1
- package/dist/src/harness/stub/index.js +10 -2
- package/dist/src/harness/stub/index.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/publish/config.d.ts +25 -0
- package/dist/src/publish/config.js +47 -0
- package/dist/src/publish/config.js.map +1 -0
- package/dist/src/publish/envelope.d.ts +61 -0
- package/dist/src/publish/envelope.js +109 -0
- package/dist/src/publish/envelope.js.map +1 -0
- package/dist/src/publish/index.d.ts +22 -0
- package/dist/src/publish/index.js +35 -0
- package/dist/src/publish/index.js.map +1 -0
- package/dist/src/publish/log-tail.d.ts +31 -0
- package/dist/src/publish/log-tail.js +172 -0
- package/dist/src/publish/log-tail.js.map +1 -0
- package/dist/src/publish/publisher.d.ts +34 -0
- package/dist/src/publish/publisher.js +207 -0
- package/dist/src/publish/publisher.js.map +1 -0
- package/dist/src/publish/transport.d.ts +14 -0
- package/dist/src/publish/transport.js +69 -0
- package/dist/src/publish/transport.js.map +1 -0
- package/dist/src/runs/admission.d.ts +27 -0
- package/dist/src/runs/admission.js +97 -0
- package/dist/src/runs/admission.js.map +1 -0
- package/dist/src/runs/answer.d.ts +24 -0
- package/dist/src/runs/answer.js +99 -0
- package/dist/src/runs/answer.js.map +1 -0
- package/dist/src/runs/base-commit.d.ts +6 -0
- package/dist/src/runs/base-commit.js +23 -0
- package/dist/src/runs/base-commit.js.map +1 -0
- package/dist/src/runs/branches.d.ts +23 -0
- package/dist/src/runs/branches.js +115 -0
- package/dist/src/runs/branches.js.map +1 -0
- package/dist/src/runs/control.d.ts +12 -4
- package/dist/src/runs/control.js +14 -6
- package/dist/src/runs/control.js.map +1 -1
- package/dist/src/runs/gateway.d.ts +25 -0
- package/dist/src/runs/gateway.js +122 -0
- package/dist/src/runs/gateway.js.map +1 -0
- package/dist/src/runs/keys.d.ts +21 -0
- package/dist/src/runs/keys.js +50 -0
- package/dist/src/runs/keys.js.map +1 -0
- package/dist/src/runs/limits.d.ts +15 -0
- package/dist/src/runs/limits.js +37 -0
- package/dist/src/runs/limits.js.map +1 -0
- package/dist/src/runs/ports.d.ts +3 -0
- package/dist/src/runs/ports.js.map +1 -1
- package/dist/src/runs/reattach.d.ts +37 -0
- package/dist/src/runs/reattach.js +70 -0
- package/dist/src/runs/reattach.js.map +1 -0
- package/dist/src/runs/scan.d.ts +11 -6
- package/dist/src/runs/scan.js +12 -15
- package/dist/src/runs/scan.js.map +1 -1
- package/dist/src/runs/service.d.ts +57 -7
- package/dist/src/runs/service.js +160 -95
- package/dist/src/runs/service.js.map +1 -1
- package/dist/src/runs/submit.d.ts +34 -0
- package/dist/src/runs/submit.js +92 -0
- package/dist/src/runs/submit.js.map +1 -0
- package/dist/src/sandbox/host-command.js +5 -1
- package/dist/src/sandbox/host-command.js.map +1 -1
- package/dist/src/sandbox/run-sandbox.d.ts +8 -2
- package/dist/src/sandbox/run-sandbox.js +10 -3
- package/dist/src/sandbox/run-sandbox.js.map +1 -1
- package/dist/src/store/derive.js +3 -0
- package/dist/src/store/derive.js.map +1 -1
- package/dist/src/store/entries.d.ts +29 -0
- package/dist/src/store/entries.js +41 -0
- package/dist/src/store/entries.js.map +1 -0
- package/dist/src/store/event-log.d.ts +3 -3
- package/dist/src/store/event-log.js +2 -2
- package/dist/src/store/event-log.js.map +1 -1
- package/dist/src/store/files.d.ts +4 -0
- package/dist/src/store/files.js +4 -0
- package/dist/src/store/files.js.map +1 -1
- package/dist/src/store/idempotency.d.ts +79 -0
- package/dist/src/store/idempotency.js +281 -0
- package/dist/src/store/idempotency.js.map +1 -0
- package/dist/src/store/index.d.ts +8 -0
- package/dist/src/store/index.js +5 -0
- package/dist/src/store/index.js.map +1 -1
- package/dist/src/store/questions.d.ts +40 -0
- package/dist/src/store/questions.js +90 -0
- package/dist/src/store/questions.js.map +1 -0
- package/dist/src/store/retention.d.ts +13 -0
- package/dist/src/store/retention.js +74 -0
- package/dist/src/store/retention.js.map +1 -0
- package/dist/src/store/run-store.d.ts +4 -0
- package/dist/src/store/run-store.js +20 -4
- package/dist/src/store/run-store.js.map +1 -1
- package/dist/src/store/startup.d.ts +9 -0
- package/dist/src/store/startup.js +92 -0
- package/dist/src/store/startup.js.map +1 -0
- package/dist/src/store/summary.d.ts +7 -0
- package/dist/src/store/summary.js +126 -0
- package/dist/src/store/summary.js.map +1 -0
- package/dist/src/store/version.d.ts +10 -0
- package/dist/src/store/version.js +46 -0
- package/dist/src/store/version.js.map +1 -0
- package/dist/src/trace/config.d.ts +31 -0
- package/dist/src/trace/config.js +69 -0
- package/dist/src/trace/config.js.map +1 -0
- package/dist/src/trace/follower.d.ts +20 -0
- package/dist/src/trace/follower.js +196 -0
- package/dist/src/trace/follower.js.map +1 -0
- package/dist/src/trace/index.d.ts +21 -0
- package/dist/src/trace/index.js +42 -0
- package/dist/src/trace/index.js.map +1 -0
- package/dist/src/trace/otlp.d.ts +11 -0
- package/dist/src/trace/otlp.js +52 -0
- package/dist/src/trace/otlp.js.map +1 -0
- package/dist/src/trace/spans.d.ts +28 -0
- package/dist/src/trace/spans.js +120 -0
- package/dist/src/trace/spans.js.map +1 -0
- package/dist/src/worker/answer.d.ts +29 -0
- package/dist/src/worker/answer.js +53 -0
- package/dist/src/worker/answer.js.map +1 -0
- package/dist/src/worker/asking.d.ts +22 -0
- package/dist/src/worker/asking.js +21 -0
- package/dist/src/worker/asking.js.map +1 -0
- package/dist/src/worker/control.d.ts +7 -1
- package/dist/src/worker/control.js +22 -10
- package/dist/src/worker/control.js.map +1 -1
- package/dist/src/worker/delivery.d.ts +2 -2
- package/dist/src/worker/delivery.js +1 -1
- package/dist/src/worker/delivery.js.map +1 -1
- package/dist/src/worker/driver.d.ts +46 -1
- package/dist/src/worker/fake-driver.d.ts +35 -1
- package/dist/src/worker/fake-driver.js +45 -0
- package/dist/src/worker/fake-driver.js.map +1 -1
- package/dist/src/worker/main.js +4 -1
- package/dist/src/worker/main.js.map +1 -1
- package/dist/src/worker/questions.d.ts +67 -0
- package/dist/src/worker/questions.js +152 -0
- package/dist/src/worker/questions.js.map +1 -0
- package/dist/src/worker/run-loop.d.ts +19 -1
- package/dist/src/worker/run-loop.js +91 -25
- package/dist/src/worker/run-loop.js.map +1 -1
- package/dist/src/worker/spawn.d.ts +9 -1
- package/dist/src/worker/spawn.js +12 -3
- package/dist/src/worker/spawn.js.map +1 -1
- package/package.json +3 -2
- package/policy/profiles/culture-agents-claude-subscription.yaml +1 -1
- package/policy/profiles/culture-agents-local-gateway.yaml +1 -1
|
@@ -7,7 +7,7 @@ import { openCodeCore, OPENCODE_TRANSPORT } from "./capabilities.js";
|
|
|
7
7
|
export function createDriver(context) {
|
|
8
8
|
const options = context.options;
|
|
9
9
|
const run = context.run;
|
|
10
|
-
const driver = new RunDriver(new SandboxWorkspaceFactory(run.id, run.repo, options.sandbox), new OpenCodeBackend(options.opencode), {
|
|
10
|
+
const driver = new RunDriver(new SandboxWorkspaceFactory(run.id, run.repo, options.sandbox, undefined, run.base_commit), new OpenCodeBackend(options.opencode), {
|
|
11
11
|
task: run.task,
|
|
12
12
|
commitMessage: `run ${run.id}: changes by opencode`,
|
|
13
13
|
...(options.stopSettleMs === undefined ? {} : { stopSettleMs: options.stopSettleMs }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/harness/opencode/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAwB,MAAM,gCAAgC,CAAC;AAC/F,OAAO,EAAE,eAAe,EAAyB,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAQrE,MAAM,UAAU,YAAY,CAAC,OAAsB;IACjD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAgC,CAAC;IACzD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACxB,MAAM,MAAM,G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,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC;KAChI,CAAC,CAAC;IACH,MAAM,GAAG,GAAG,kBAAkB,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,kBAAkB,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC;IAC7I,OAAO,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import type { AskedQuestion } from "../../worker/driver.js";
|
|
1
2
|
import type { HarnessBackend, HarnessSession, Workspace } from "../common/types.js";
|
|
2
3
|
export interface StubBehaviour {
|
|
3
4
|
/** Delay before each step. Default 150 ms. */
|
|
4
5
|
stepMs?: number;
|
|
5
6
|
}
|
|
6
7
|
export declare function parseFiles(text: string): string[] | null;
|
|
8
|
+
/** The question a task asks first, or null. */
|
|
9
|
+
export declare function parseAsk(task: string): AskedQuestion | null;
|
|
7
10
|
export declare class StubBackend implements HarnessBackend<Workspace> {
|
|
8
11
|
private readonly behaviour;
|
|
9
12
|
constructor(behaviour?: StubBehaviour);
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* files: a.txt, b.txt write these files one at a time (content: the name), then finish
|
|
6
6
|
* fail: <message> end the turn as failed
|
|
7
7
|
* hang run until interrupted
|
|
8
|
+
* ask: <text> first ask the operator <text> (free text, plus the choices of a
|
|
9
|
+
* `choices: a, b` line) and wait; the answer is echoed as text
|
|
10
|
+
* approval: <text> first ask approval for the writes and wait; deny skips them
|
|
8
11
|
*
|
|
9
12
|
* A steer whose text contains `files: ...` replaces the files not yet written; any other steer
|
|
10
13
|
* is acknowledged as a diagnostic. Interrupt stops before the next step.
|
|
@@ -24,6 +27,19 @@ export function parseFiles(text) {
|
|
|
24
27
|
}
|
|
25
28
|
/** True when one line of the task holds only `hang`, in any letter case, with any space around it. */
|
|
26
29
|
const hasHangLine = (task) => task.split(/[\n\r\u2028\u2029]/).some((line) => /^hang$/i.test(line.trim()));
|
|
30
|
+
/** The question a task asks first, or null. */
|
|
31
|
+
export function parseAsk(task) {
|
|
32
|
+
const line = (key) => new RegExp(String.raw `^\s*${key}:\s*(.+)$`, "im").exec(task)?.[1]?.trim() ?? null;
|
|
33
|
+
const approval = line("approval");
|
|
34
|
+
if (approval !== null)
|
|
35
|
+
return { ref: "stub-approval-1", kind: "approval", text: approval, choices: [], free_text: false, multiple: false, tool: "write" };
|
|
36
|
+
const ask = line("ask");
|
|
37
|
+
if (ask === null)
|
|
38
|
+
return null;
|
|
39
|
+
const labels = (line("choices") ?? "").split(",").map((c) => c.trim()).filter((c) => c !== "");
|
|
40
|
+
const choices = labels.slice(0, 50).map((label, i) => ({ id: `c${i + 1}`, label: label.slice(0, 500) }));
|
|
41
|
+
return { ref: "stub-question-1", kind: "question", text: ask, choices, free_text: true, multiple: false };
|
|
42
|
+
}
|
|
27
43
|
class StubTurn {
|
|
28
44
|
workdir;
|
|
29
45
|
stepMs;
|
|
@@ -31,6 +47,7 @@ class StubTurn {
|
|
|
31
47
|
abort = new AbortController();
|
|
32
48
|
pending = [];
|
|
33
49
|
written = [];
|
|
50
|
+
asked = null;
|
|
34
51
|
constructor(workdir, stepMs) {
|
|
35
52
|
this.workdir = workdir;
|
|
36
53
|
this.stepMs = stepMs;
|
|
@@ -54,7 +71,17 @@ class StubTurn {
|
|
|
54
71
|
await new Promise((resolve) => signal.addEventListener("abort", () => resolve(), { once: true }));
|
|
55
72
|
return { kind: "interrupted" };
|
|
56
73
|
}
|
|
57
|
-
|
|
74
|
+
const asked = parseAsk(task);
|
|
75
|
+
let denied = false;
|
|
76
|
+
if (asked !== null) {
|
|
77
|
+
const reply = await this.waitForAnswer(asked, signal);
|
|
78
|
+
if (reply === null)
|
|
79
|
+
return { kind: "interrupted" };
|
|
80
|
+
denied = reply.decision === "deny";
|
|
81
|
+
const given = [reply.decision, reply.choice_ids?.join(", "), reply.answer].filter((x) => x !== undefined).join(" / ");
|
|
82
|
+
this.out("text", `stub got the answer: ${given.slice(0, 500)}`);
|
|
83
|
+
}
|
|
84
|
+
this.pending = denied ? [] : (parseFiles(task) ?? []);
|
|
58
85
|
const interrupted = () => ({ kind: "interrupted" });
|
|
59
86
|
let waited = false;
|
|
60
87
|
// Each write follows its own pause, and the pending list is read afresh every time: a steer
|
|
@@ -69,6 +96,23 @@ class StubTurn {
|
|
|
69
96
|
return finish(signal.aborted ? interrupted() : this.completed());
|
|
70
97
|
}, { signal, onAbort: interrupted });
|
|
71
98
|
}
|
|
99
|
+
/** Raise the question and hold the turn until it is answered (the reply) or interrupted (null). */
|
|
100
|
+
waitForAnswer(asked, signal) {
|
|
101
|
+
return new Promise((resolve) => {
|
|
102
|
+
if (signal.aborted)
|
|
103
|
+
return resolve(null);
|
|
104
|
+
this.asked = { ref: asked.ref, resolve };
|
|
105
|
+
signal.addEventListener("abort", () => resolve(null), { once: true });
|
|
106
|
+
this.queue.push({ type: "question", question: asked });
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
answer(ref, reply) {
|
|
110
|
+
if (this.asked?.ref !== ref)
|
|
111
|
+
throw new Error(`The stub has no pending request ${ref}.`);
|
|
112
|
+
const { resolve } = this.asked;
|
|
113
|
+
this.asked = null;
|
|
114
|
+
resolve(reply);
|
|
115
|
+
}
|
|
72
116
|
async writeNext() {
|
|
73
117
|
const name = this.pending.shift();
|
|
74
118
|
this.out("tool_call", JSON.stringify({ file_path: name }), "write");
|
|
@@ -115,6 +159,11 @@ export class StubBackend {
|
|
|
115
159
|
throw new Error("The stub turn has ended.");
|
|
116
160
|
t.steer(text);
|
|
117
161
|
},
|
|
162
|
+
answer: async (ref, reply) => {
|
|
163
|
+
if (t.ended)
|
|
164
|
+
throw new Error("The stub turn has ended.");
|
|
165
|
+
t.answer(ref, reply);
|
|
166
|
+
},
|
|
118
167
|
interrupt: async () => t.interrupt(),
|
|
119
168
|
};
|
|
120
169
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../../../../src/harness/stub/backend.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../../../../src/harness/stub/backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAShD,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,CAAC,GAAG,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACpB,OAAQ,CAAC,CAAC,CAAC,CAAY;SACpB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;SAC9B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;AACxD,CAAC;AAED,sGAAsG;AACtG,MAAM,WAAW,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAE5H,+CAA+C;AAC/C,MAAM,UAAU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,KAAK,EAAE,EAAE;wBAC3B,IAAI,CAAC,CAAC,KAAK;4BAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;wBACzD,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;oBACvB,CAAC;oBACD,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE;iBACrC,CAAC;YACJ,CAAC;YACD,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE;SACrC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* in-process harness. It imports no AI SDK, OpenShell or vendor package (a test walks its import
|
|
4
4
|
* graph), so swapping it in for a real harness proves the rest of the system is harness-neutral.
|
|
5
5
|
*/
|
|
6
|
-
import type { CapabilitySet } from "../../contract/index.js";
|
|
6
|
+
import type { Capabilities, CapabilitySet } from "../../contract/index.js";
|
|
7
7
|
import type { Driver, DriverContext } from "../../worker/driver.js";
|
|
8
8
|
export interface StubDriverOptions {
|
|
9
9
|
ref: string;
|
|
@@ -15,4 +15,10 @@ export interface StubDriverOptions {
|
|
|
15
15
|
}
|
|
16
16
|
export declare const STUB_TRANSPORT = "in-process stub harness over a host temp clone (no sandbox, no vendor code)";
|
|
17
17
|
export declare function stubCore(): Pick<CapabilitySet, "submit" | "stream" | "steer" | "cancel">;
|
|
18
|
+
/** The stub has no sandbox: its clone per run is a temporary directory on the host, still never a worktree. */
|
|
19
|
+
export declare const STUB_ISOLATION: import("../../contract/index.js").Capability;
|
|
20
|
+
/** The stub asks when its task says `ask:` or `approval:`, so the mock stage exercises the whole question path. */
|
|
21
|
+
export declare const STUB_ANSWER: import("../../contract/index.js").Capability;
|
|
22
|
+
/** The stub's capability document (the registry and the driver report the same one). */
|
|
23
|
+
export declare function stubCapabilities(): Capabilities;
|
|
18
24
|
export declare function createDriver(context: DriverContext): Driver;
|
|
@@ -12,10 +12,18 @@ export function stubCore() {
|
|
|
12
12
|
cancel: supported(),
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
+
/** The stub has no sandbox: its clone per run is a temporary directory on the host, still never a worktree. */
|
|
16
|
+
export const STUB_ISOLATION = supported("Each run works in its own temporary clone of the repository on the host (the stub has no sandbox), made from the commit recorded at submit, and its commits return only to its own runs/<run_id> branch. No git worktree is created, and the host checkout and index are never written.");
|
|
17
|
+
/** The stub asks when its task says `ask:` or `approval:`, so the mock stage exercises the whole question path. */
|
|
18
|
+
export const STUB_ANSWER = supported("The stub asks only when its task has a line `ask: <text>` (a free-text question with the choices of a `choices: a, b` line) or `approval: <text>` (an approval of its writes; deny skips them). It waits for the answer in the same turn.", "The question waits in the worker process: if the worker ends, the question ends with the run.", "A question has its own time limit of 12 hours, or less when the operator configured less; the run's deadline pauses while it is pending. The limit is the worker's rule: no real harness was measured holding a question for 12 hours (the probe held 5 minutes).");
|
|
19
|
+
/** The stub's capability document (the registry and the driver report the same one). */
|
|
20
|
+
export function stubCapabilities() {
|
|
21
|
+
return capabilityDocument({ harness: "stub", available: true, version: "stub-1", transport: STUB_TRANSPORT, core: stubCore(), answer: STUB_ANSWER, isolation: STUB_ISOLATION });
|
|
22
|
+
}
|
|
15
23
|
export function createDriver(context) {
|
|
16
24
|
const options = context.options;
|
|
17
25
|
const run = context.run;
|
|
18
|
-
const driver = new RunDriver(new StubWorkspaceFactory(run.id, run.repo, { ref: options.ref, identity: options.identity }), new StubBackend(options.stepMs === undefined ? {} : { stepMs: options.stepMs }), { task: run.task, commitMessage: `run ${run.id}: changes by stub`, processSettleMs: 0 });
|
|
19
|
-
return guardDriver(driver,
|
|
26
|
+
const driver = new RunDriver(new StubWorkspaceFactory(run.id, run.repo, { ref: run.base_commit ?? options.ref, identity: options.identity }), new StubBackend(options.stepMs === undefined ? {} : { stepMs: options.stepMs }), { task: run.task, commitMessage: `run ${run.id}: changes by stub`, processSettleMs: 0 });
|
|
27
|
+
return guardDriver(driver, stubCapabilities());
|
|
20
28
|
}
|
|
21
29
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/harness/stub/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAQtD,MAAM,CAAC,MAAM,cAAc,GAAG,6EAA6E,CAAC;AAE5G,MAAM,UAAU,QAAQ;IACtB,OAAO;QACL,MAAM,EAAE,SAAS,CAAC,uEAAuE,CAAC;QAC1F,MAAM,EAAE,SAAS,EAAE;QACnB,KAAK,EAAE,SAAS,CAAC,+DAA+D,CAAC;QACjF,MAAM,EAAE,SAAS,EAAE;KACpB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAsB;IACjD,MAAM,OAAO,GAAG,OAAO,CAAC,OAA4B,CAAC;IACrD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACxB,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B,IAAI,oBAAoB,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/harness/stub/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,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AC/G,IAAI,WAAW,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,EAC/E,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,GAAG,CAAC,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC,EAAE,CACxF,CAAC;IACF,OAAO,WAAW,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;AACjD,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Package version. Must equal `version` in package.json (checked by test/version.test.ts). */
|
|
2
|
-
export declare const version = "0.
|
|
2
|
+
export declare const version = "0.16.1";
|
package/dist/src/index.js
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the broker is. Publishing is off unless `CULTURE_AGENTS_BROKER_URL` is set: the address
|
|
3
|
+
* is configuration of the host the core runs on and is never read from a tracked file.
|
|
4
|
+
*
|
|
5
|
+
* The value is `mqtt://<loopback address>[:<port>]`, for example `mqtt://127.0.0.1:1883` (the
|
|
6
|
+
* port defaults to 1883). The events broker is anonymous and bound to loopback, so the core
|
|
7
|
+
* publishes only to its own host: an address that is not loopback is refused, and so are a user
|
|
8
|
+
* name or password, a path, and any other scheme (the broker has no TLS listener).
|
|
9
|
+
*/
|
|
10
|
+
export declare const BROKER_URL_ENV = "CULTURE_AGENTS_BROKER_URL";
|
|
11
|
+
export declare const DEFAULT_BROKER_PORT = 1883;
|
|
12
|
+
export interface PublishConfig {
|
|
13
|
+
/** The address as the core uses it: `mqtt://<host>:<port>`. */
|
|
14
|
+
url: string;
|
|
15
|
+
host: string;
|
|
16
|
+
port: number;
|
|
17
|
+
}
|
|
18
|
+
/** The configured value cannot be used. The message never repeats a user name or password. */
|
|
19
|
+
export declare class PublishConfigError extends Error {
|
|
20
|
+
readonly name = "PublishConfigError";
|
|
21
|
+
}
|
|
22
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
23
|
+
/** The broker configuration, or null when publishing is off. Throws `PublishConfigError` for a value that cannot be used. */
|
|
24
|
+
export declare function loadPublishConfig(env?: Env): PublishConfig | null;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the broker is. Publishing is off unless `CULTURE_AGENTS_BROKER_URL` is set: the address
|
|
3
|
+
* is configuration of the host the core runs on and is never read from a tracked file.
|
|
4
|
+
*
|
|
5
|
+
* The value is `mqtt://<loopback address>[:<port>]`, for example `mqtt://127.0.0.1:1883` (the
|
|
6
|
+
* port defaults to 1883). The events broker is anonymous and bound to loopback, so the core
|
|
7
|
+
* publishes only to its own host: an address that is not loopback is refused, and so are a user
|
|
8
|
+
* name or password, a path, and any other scheme (the broker has no TLS listener).
|
|
9
|
+
*/
|
|
10
|
+
export const BROKER_URL_ENV = "CULTURE_AGENTS_BROKER_URL";
|
|
11
|
+
export const DEFAULT_BROKER_PORT = 1883;
|
|
12
|
+
/** The configured value cannot be used. The message never repeats a user name or password. */
|
|
13
|
+
export class PublishConfigError extends Error {
|
|
14
|
+
name = "PublishConfigError";
|
|
15
|
+
}
|
|
16
|
+
const LOOPBACK_V4 = /^127(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}$/;
|
|
17
|
+
/** The broker configuration, or null when publishing is off. Throws `PublishConfigError` for a value that cannot be used. */
|
|
18
|
+
export function loadPublishConfig(env = process.env) {
|
|
19
|
+
const raw = env[BROKER_URL_ENV]?.trim();
|
|
20
|
+
if (raw === undefined || raw === "")
|
|
21
|
+
return null;
|
|
22
|
+
const refuse = (what) => {
|
|
23
|
+
throw new PublishConfigError(`${BROKER_URL_ENV} ${what}; expected mqtt://127.0.0.1:${DEFAULT_BROKER_PORT} or another loopback address`);
|
|
24
|
+
};
|
|
25
|
+
let url;
|
|
26
|
+
try {
|
|
27
|
+
url = new URL(raw);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return refuse("is not a URL");
|
|
31
|
+
}
|
|
32
|
+
if (url.protocol !== "mqtt:")
|
|
33
|
+
return refuse("must use the mqtt scheme");
|
|
34
|
+
if (url.username !== "" || url.password !== "")
|
|
35
|
+
return refuse("must not hold a user name or password");
|
|
36
|
+
if ((url.pathname !== "" && url.pathname !== "/") || url.search !== "" || url.hash !== "")
|
|
37
|
+
return refuse("must not hold a path, query or fragment");
|
|
38
|
+
const host = url.hostname.toLowerCase();
|
|
39
|
+
if (!(host === "localhost" || host === "[::1]" || LOOPBACK_V4.test(host))) {
|
|
40
|
+
return refuse("must name a loopback address (the broker is anonymous, so the core publishes only to its own host)");
|
|
41
|
+
}
|
|
42
|
+
const port = url.port === "" ? DEFAULT_BROKER_PORT : Number(url.port);
|
|
43
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
44
|
+
return refuse("must name a TCP port");
|
|
45
|
+
return { url: `mqtt://${host}:${port}`, host: host === "[::1]" ? "::1" : host, port };
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/publish/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,2BAA2B,CAAC;AAC1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AASxC,8FAA8F;AAC9F,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACzB,IAAI,GAAG,oBAAoB,CAAC;CAC/C;AAID,MAAM,WAAW,GAAG,4CAA4C,CAAC;AAEjE,6HAA6H;AAC7H,MAAM,UAAU,iBAAiB,CAAC,MAAW,OAAO,CAAC,GAAG;IACtD,MAAM,GAAG,GAAG,GAAG,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,CAAC;IACxC,IAA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CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,KAAK;QAAE,OAAO,MAAM,CAAC,sBAAsB,CAAC,CAAC;IAC/F,OAAO,EAAE,GAAG,EAAE,UAAU,IAAI,IAAI,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC;AACxF,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** Every type the core publishes starts with this. No other product publishes under it. */
|
|
2
|
+
export declare const TYPE_PREFIX = "agents.run";
|
|
3
|
+
/** Consumers subscribe to types of up to this many segments; a longer type would be dropped silently. */
|
|
4
|
+
export declare const MAX_TYPE_SEGMENTS = 4;
|
|
5
|
+
/** The broker's envelope schema version. */
|
|
6
|
+
export declare const SCHEMA_VERSION = "1";
|
|
7
|
+
/** First topic level of every envelope topic. */
|
|
8
|
+
export declare const TOPIC_PREFIX = "events";
|
|
9
|
+
/** A fact cannot be published in the broker's envelope. The caller holds the run there; it never guesses. */
|
|
10
|
+
export declare class EnvelopeError extends Error {
|
|
11
|
+
readonly name = "EnvelopeError";
|
|
12
|
+
}
|
|
13
|
+
/** What is published about one run event. */
|
|
14
|
+
export interface RunFact {
|
|
15
|
+
run_id: string;
|
|
16
|
+
/** The event's kind in the run log, for example `run.state`. */
|
|
17
|
+
kind: string;
|
|
18
|
+
/** The run's state after this event. */
|
|
19
|
+
state: string;
|
|
20
|
+
cursor: number;
|
|
21
|
+
/** The event's time in the run log. */
|
|
22
|
+
time: string;
|
|
23
|
+
}
|
|
24
|
+
export interface BrokerEnvelope {
|
|
25
|
+
id: string;
|
|
26
|
+
type: string;
|
|
27
|
+
source: string;
|
|
28
|
+
time: string;
|
|
29
|
+
schemaVersion: string;
|
|
30
|
+
runId: string;
|
|
31
|
+
data: {
|
|
32
|
+
run_id: string;
|
|
33
|
+
kind: string;
|
|
34
|
+
state: string;
|
|
35
|
+
cursor: number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface BrokerMessage {
|
|
39
|
+
topic: string;
|
|
40
|
+
/** The envelope as compact JSON: what is sent. */
|
|
41
|
+
payload: string;
|
|
42
|
+
envelope: BrokerEnvelope;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The type of one run event: `agents.run.<state>` for a state transition (`agents.run.succeeded`),
|
|
46
|
+
* and `agents.run.<kind without "run.">` for every other kind (`agents.run.output`). Always three
|
|
47
|
+
* segments. A kind or state that is not one lowercase word is refused.
|
|
48
|
+
*/
|
|
49
|
+
export declare function eventType(kind: string, state: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* The id of one run event: `<run id>:<cursor>`. It depends on nothing else, so publishing the same
|
|
52
|
+
* event again gives the same id. When that would pass the broker's 128-character limit (a run id
|
|
53
|
+
* may be 127), the run id is replaced by `sha256.` and the hex SHA-256 of the run id.
|
|
54
|
+
*/
|
|
55
|
+
export declare function eventId(runId: string, cursor: number): string;
|
|
56
|
+
/** The topic of a type: `agents.run.succeeded` -> `events/agents/run/succeeded`. */
|
|
57
|
+
export declare function topicFor(type: string): string;
|
|
58
|
+
/** The envelope `source` of this core: an absolute URI naming the product and the node. */
|
|
59
|
+
export declare function sourceFor(node: string): string;
|
|
60
|
+
/** Build the message for one fact. Throws `EnvelopeError` when the broker's reader would drop it. */
|
|
61
|
+
export declare function buildMessage(fact: RunFact, source: string): BrokerMessage;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The message the core publishes for one run event: the broker's existing envelope, carrying
|
|
3
|
+
* lifecycle facts only.
|
|
4
|
+
*
|
|
5
|
+
* The broker is the workspace's events broker (events-cli: Mosquitto on loopback, anonymous). Its
|
|
6
|
+
* consumers read a CloudEvents-shaped JSON envelope and drop, for good, any payload that does not
|
|
7
|
+
* parse as one. events-cli has no schema file, only its reader, so the rules are restated here and
|
|
8
|
+
* checked before anything is published (events_cli/core/envelope.py, events_cli/core/topics.py and
|
|
9
|
+
* docs/contract.md in that repository):
|
|
10
|
+
*
|
|
11
|
+
* - required fields `id`, `type`, `source`, `time`, `schemaVersion`, `data`; an unknown top-level
|
|
12
|
+
* field is refused, so everything of ours goes inside `data`; absent fields are omitted;
|
|
13
|
+
* - `type` is lowercase dotted segments; `id` and `runId` are at most 128 printable characters
|
|
14
|
+
* without whitespace; `source` is an absolute URI; `time` is RFC 3339 in UTC;
|
|
15
|
+
* - the topic is `events/` plus the type with each dot as a topic level;
|
|
16
|
+
* - delivery is at-least-once, so consumers dedupe on `id`.
|
|
17
|
+
*
|
|
18
|
+
* What a message holds: the run id, the event kind, the run's state after the event, the cursor
|
|
19
|
+
* and the time. Never the prompt, harness output, a tool result, a question or an answer: the
|
|
20
|
+
* broker accepts anonymous local subscribers, which is wider than the owner-only run logs. A
|
|
21
|
+
* subscriber that wants content reads it from the core by cursor.
|
|
22
|
+
*/
|
|
23
|
+
import { createHash } from "node:crypto";
|
|
24
|
+
/** Every type the core publishes starts with this. No other product publishes under it. */
|
|
25
|
+
export const TYPE_PREFIX = "agents.run";
|
|
26
|
+
/** Consumers subscribe to types of up to this many segments; a longer type would be dropped silently. */
|
|
27
|
+
export const MAX_TYPE_SEGMENTS = 4;
|
|
28
|
+
/** The broker's envelope schema version. */
|
|
29
|
+
export const SCHEMA_VERSION = "1";
|
|
30
|
+
/** First topic level of every envelope topic. */
|
|
31
|
+
export const TOPIC_PREFIX = "events";
|
|
32
|
+
const MAX_ID_LENGTH = 128;
|
|
33
|
+
const MAX_TYPE_LENGTH = 128;
|
|
34
|
+
const ID = /^[A-Za-z0-9][A-Za-z0-9._:+/=@-]*$/;
|
|
35
|
+
const TYPE = /^[a-z0-9]+(?:[._-][a-z0-9]+)*$/;
|
|
36
|
+
/** One type segment of ours: a word, which may hold `_` (as `timed_out` does) but no separator. */
|
|
37
|
+
const WORD = /^[a-z0-9]+(?:_[a-z0-9]+)*$/;
|
|
38
|
+
/** RFC 3339 in UTC with a `Z`: the form the event log writes. */
|
|
39
|
+
const TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
|
|
40
|
+
const NODE = /^[a-z0-9]{1,32}$/;
|
|
41
|
+
/** A fact cannot be published in the broker's envelope. The caller holds the run there; it never guesses. */
|
|
42
|
+
export class EnvelopeError extends Error {
|
|
43
|
+
name = "EnvelopeError";
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The type of one run event: `agents.run.<state>` for a state transition (`agents.run.succeeded`),
|
|
47
|
+
* and `agents.run.<kind without "run.">` for every other kind (`agents.run.output`). Always three
|
|
48
|
+
* segments. A kind or state that is not one lowercase word is refused.
|
|
49
|
+
*/
|
|
50
|
+
export function eventType(kind, state) {
|
|
51
|
+
if (!kind.startsWith("run.") || !WORD.test(kind.slice(4)))
|
|
52
|
+
throw new EnvelopeError(`event kind ${JSON.stringify(kind)} cannot be published as a type`);
|
|
53
|
+
if (kind !== "run.state")
|
|
54
|
+
return `${TYPE_PREFIX}.${kind.slice(4)}`;
|
|
55
|
+
if (!WORD.test(state))
|
|
56
|
+
throw new EnvelopeError(`state ${JSON.stringify(state)} cannot be published as a type`);
|
|
57
|
+
return `${TYPE_PREFIX}.${state}`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The id of one run event: `<run id>:<cursor>`. It depends on nothing else, so publishing the same
|
|
61
|
+
* event again gives the same id. When that would pass the broker's 128-character limit (a run id
|
|
62
|
+
* may be 127), the run id is replaced by `sha256.` and the hex SHA-256 of the run id.
|
|
63
|
+
*/
|
|
64
|
+
export function eventId(runId, cursor) {
|
|
65
|
+
if (!Number.isSafeInteger(cursor) || cursor < 1)
|
|
66
|
+
throw new EnvelopeError(`cursor ${String(cursor)} is not a positive integer`);
|
|
67
|
+
const plain = `${runId}:${cursor}`;
|
|
68
|
+
if (plain.length <= MAX_ID_LENGTH)
|
|
69
|
+
return plain;
|
|
70
|
+
return `sha256.${createHash("sha256").update(runId, "utf8").digest("hex")}:${cursor}`;
|
|
71
|
+
}
|
|
72
|
+
/** The topic of a type: `agents.run.succeeded` -> `events/agents/run/succeeded`. */
|
|
73
|
+
export function topicFor(type) {
|
|
74
|
+
if (type.length > MAX_TYPE_LENGTH || !TYPE.test(type))
|
|
75
|
+
throw new EnvelopeError(`type ${JSON.stringify(type)} is not lowercase dotted segments`);
|
|
76
|
+
const segments = type.split(".");
|
|
77
|
+
if (segments.length > MAX_TYPE_SEGMENTS)
|
|
78
|
+
throw new EnvelopeError(`type ${type} has more than ${MAX_TYPE_SEGMENTS} segments`);
|
|
79
|
+
return [TOPIC_PREFIX, ...segments].join("/");
|
|
80
|
+
}
|
|
81
|
+
/** The envelope `source` of this core: an absolute URI naming the product and the node. */
|
|
82
|
+
export function sourceFor(node) {
|
|
83
|
+
if (!NODE.test(node))
|
|
84
|
+
throw new EnvelopeError("the node name is not a mesh node name");
|
|
85
|
+
return `app://culture-agents/${node}`;
|
|
86
|
+
}
|
|
87
|
+
/** Build the message for one fact. Throws `EnvelopeError` when the broker's reader would drop it. */
|
|
88
|
+
export function buildMessage(fact, source) {
|
|
89
|
+
if (fact.run_id.length > MAX_ID_LENGTH || !ID.test(fact.run_id))
|
|
90
|
+
throw new EnvelopeError("the run id cannot be an envelope identifier");
|
|
91
|
+
if (!TIME.test(fact.time))
|
|
92
|
+
throw new EnvelopeError("the event time is not an RFC 3339 UTC timestamp");
|
|
93
|
+
if (!URL.canParse(source) || /\s/.test(source))
|
|
94
|
+
throw new EnvelopeError("the source is not an absolute URI");
|
|
95
|
+
const type = eventType(fact.kind, fact.state);
|
|
96
|
+
if (!WORD.test(fact.state))
|
|
97
|
+
throw new EnvelopeError(`state ${JSON.stringify(fact.state)} cannot be published`);
|
|
98
|
+
const envelope = {
|
|
99
|
+
id: eventId(fact.run_id, fact.cursor),
|
|
100
|
+
type,
|
|
101
|
+
source,
|
|
102
|
+
time: fact.time,
|
|
103
|
+
schemaVersion: SCHEMA_VERSION,
|
|
104
|
+
runId: fact.run_id,
|
|
105
|
+
data: { run_id: fact.run_id, kind: fact.kind, state: fact.state, cursor: fact.cursor },
|
|
106
|
+
};
|
|
107
|
+
return { topic: topicFor(type), payload: JSON.stringify(envelope), envelope };
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=envelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../../src/publish/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,2FAA2F;AAC3F,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY,CAAC;AACxC,yGAAyG;AACzG,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC,4CAA4C;AAC5C,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAClC,iDAAiD;AACjD,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAErC,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,EAAE,GAAG,mCAAmC,CAAC;AAC/C,MAAM,IAAI,GAAG,gCAAgC,CAAC;AAC9C,mGAAmG;AACnG,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAC1C,iEAAiE;AACjE,MAAM,IAAI,GAAG,kDAAkD,CAAC;AAChE,MAAM,IAAI,GAAG,kBAAkB,CAAC;AAEhC,6GAA6G;AAC7G,MAAM,OAAO,aAAc,SAAQ,KAAK;IACpB,IAAI,GAAG,eAAe,CAAC;CAC1C;AA+BD;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,KAAa;IACnD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CA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AAmB;QAC/B,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;QACrC,IAAI;QACJ,MAAM;QACN,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,aAAa,EAAE,cAAc;QAC7B,KAAK,EAAE,IAAI,CAAC,MAAM;QAClB,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;KACvF,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Publisher } from "./publisher.js";
|
|
2
|
+
export { BROKER_URL_ENV, DEFAULT_BROKER_PORT, PublishConfigError, loadPublishConfig } from "./config.js";
|
|
3
|
+
export type { PublishConfig } from "./config.js";
|
|
4
|
+
export { EnvelopeError, MAX_TYPE_SEGMENTS, SCHEMA_VERSION, TOPIC_PREFIX, TYPE_PREFIX, buildMessage, eventId, eventType, sourceFor, topicFor } from "./envelope.js";
|
|
5
|
+
export type { BrokerEnvelope, BrokerMessage, RunFact } from "./envelope.js";
|
|
6
|
+
export { LogHeldError, POSITION_FILE, pendingFacts, readPosition, writePosition } from "./log-tail.js";
|
|
7
|
+
export type { PendingFact, PublishPosition } from "./log-tail.js";
|
|
8
|
+
export { createPublisher } from "./publisher.js";
|
|
9
|
+
export type { BrokerTransport, Publisher, PublisherOptions } from "./publisher.js";
|
|
10
|
+
export interface StartPublishingOptions {
|
|
11
|
+
stateDir: string;
|
|
12
|
+
node: string;
|
|
13
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
14
|
+
/** Where one-line diagnostics go (the core's stderr). */
|
|
15
|
+
log: (line: string) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Start publishing when a broker is configured; resolves to null when it is not, or when the
|
|
19
|
+
* configuration cannot be used (said in one line). It never throws and never waits for the
|
|
20
|
+
* broker: the core starts and serves the same way with the broker up, down or absent.
|
|
21
|
+
*/
|
|
22
|
+
export declare function startPublishing(options: StartPublishingOptions): Promise<Publisher | null>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Publishing run events to the workspace's events broker, as a second transport next to the run
|
|
3
|
+
* logs. Off unless a broker address is configured. See `publisher.ts` for the guarantees and
|
|
4
|
+
* `envelope.ts` for what a message holds.
|
|
5
|
+
*/
|
|
6
|
+
import { loadPublishConfig, BROKER_URL_ENV } from "./config.js";
|
|
7
|
+
import { sourceFor } from "./envelope.js";
|
|
8
|
+
import { createPublisher } from "./publisher.js";
|
|
9
|
+
export { BROKER_URL_ENV, DEFAULT_BROKER_PORT, PublishConfigError, loadPublishConfig } from "./config.js";
|
|
10
|
+
export { EnvelopeError, MAX_TYPE_SEGMENTS, SCHEMA_VERSION, TOPIC_PREFIX, TYPE_PREFIX, buildMessage, eventId, eventType, sourceFor, topicFor } from "./envelope.js";
|
|
11
|
+
export { LogHeldError, POSITION_FILE, pendingFacts, readPosition, writePosition } from "./log-tail.js";
|
|
12
|
+
export { createPublisher } from "./publisher.js";
|
|
13
|
+
/**
|
|
14
|
+
* Start publishing when a broker is configured; resolves to null when it is not, or when the
|
|
15
|
+
* configuration cannot be used (said in one line). It never throws and never waits for the
|
|
16
|
+
* broker: the core starts and serves the same way with the broker up, down or absent.
|
|
17
|
+
*/
|
|
18
|
+
export async function startPublishing(options) {
|
|
19
|
+
try {
|
|
20
|
+
const config = loadPublishConfig(options.env ?? process.env);
|
|
21
|
+
if (config === null)
|
|
22
|
+
return null;
|
|
23
|
+
// Loaded only when publishing is on: a core without a broker never loads the MQTT client.
|
|
24
|
+
const { connectBroker } = await import("./transport.js");
|
|
25
|
+
const publisher = createPublisher({ stateDir: options.stateDir, source: sourceFor(options.node), transport: connectBroker(config), warn: options.log });
|
|
26
|
+
publisher.start();
|
|
27
|
+
options.log(`culture-agents core: publishing run events to the broker at ${config.url} (${BROKER_URL_ENV}).`);
|
|
28
|
+
return publisher;
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
options.log(`culture-agents core: run events are not published: ${err instanceof Error ? err.message : String(err)}`);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/publish/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEzG,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEnK,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEvG,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAWjD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAA+B;IACnE,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QACjC,0FAA0F;QAC1F,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACzD,MAAM,SAAS,GAAG,eAAe,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACxJ,SAAS,CAAC,KAAK,EAAE,CAAC;QAClB,OAAO,CAAC,GAAG,CAAC,+DAA+D,MAAM,CAAC,GAAG,KAAK,cAAc,IAAI,CAAC,CAAC;QAC9G,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,sDAAsD,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACtH,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RunFact } from "./envelope.js";
|
|
2
|
+
/** File name of the publish position inside a run directory. */
|
|
3
|
+
export declare const POSITION_FILE = "published.json";
|
|
4
|
+
export interface PublishPosition {
|
|
5
|
+
/** Cursor of the last published event; 0 when nothing is published. */
|
|
6
|
+
cursor: number;
|
|
7
|
+
/** Byte offset in the log just past that event's line. */
|
|
8
|
+
offset: number;
|
|
9
|
+
/** The run's state after that event; null before event 1. */
|
|
10
|
+
state: string | null;
|
|
11
|
+
}
|
|
12
|
+
export declare const START: PublishPosition;
|
|
13
|
+
/** The log cannot be published past this point: a complete line breaks a rule of the log. */
|
|
14
|
+
export declare class LogHeldError extends Error {
|
|
15
|
+
readonly name = "LogHeldError";
|
|
16
|
+
}
|
|
17
|
+
/** The recorded position; `START` when the file is absent or does not hold a usable position. */
|
|
18
|
+
export declare function readPosition(dir: string): PublishPosition;
|
|
19
|
+
/** Record the position (0600, replaced atomically). */
|
|
20
|
+
export declare function writePosition(dir: string, position: PublishPosition): void;
|
|
21
|
+
/** One event to publish, with the position that holds once it is published. */
|
|
22
|
+
export interface PendingFact {
|
|
23
|
+
fact: RunFact;
|
|
24
|
+
after: PublishPosition;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The next events to publish after `position`, at most `max`. A position whose offset does not
|
|
28
|
+
* match the log (the file was edited, or the position is damaged) is not trusted: the log is read
|
|
29
|
+
* from its start and events up to `position.cursor` are passed over, so none is skipped.
|
|
30
|
+
*/
|
|
31
|
+
export declare function pendingFacts(dir: string, runId: string, position: PublishPosition, max: number): PendingFact[];
|