@george-veras/acta 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 George Véras Valentim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <img src="logo.png" alt="Acta logo: a seal ring enclosing the letter A, crossed by a pulse line" width="220">
3
+ </p>
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ # Acta
6
+
7
+ **React holds that the interface is a function of the state. Acta holds that coordination is a function of the state, when the components interpret.**
8
+
9
+ Acta is a framework proposal for multi-agent systems whose components are language models: one store, changed only by named transitions serialized through a single commit point; effects subscribed to the slice of state they read, declared beside the work that needs them, running after the commit, once per state version; timers and failures as transitions like any other; a transition log that replays the state at any point.
10
+
11
+ In Latin, acta are the things done and recorded. In Portuguese, an ata is the official record of what was decided. Both meanings are the design: nothing happens outside a recorded transition, and the agents act on acts.
12
+
13
+ ## Status
14
+
15
+ Design proposal, December 2026. Acta claims no new science: it is a proposed interpretation of established results in coordination and state management, restated as a discipline for teams of language-model agents. The full design, its open questions and its build order live in [PROPOSAL.md](PROPOSAL.md). Acta is being developed in the open from a running reference operation: a one-person software company whose agent team coordinates through shared state files today, and whose field laws Acta generalizes.
16
+
17
+ Documentation lives at [acta.works](https://acta.works).
18
+
19
+ ## Where it comes from
20
+
21
+ The essay that produced Acta: **The state is the body**, by George Véras Valentim.
22
+
23
+ - [English](https://georgeveras.com/the-state-is-the-body.html)
24
+ - [Português](https://georgeveras.com/the-state-is-the-body-pt.html)
25
+ - [Français](https://georgeveras.com/the-state-is-the-body-fr.html)
26
+ - The essay's living document, with its failure cases: [the-state-is-the-body](https://github.com/george-veras/the-state-is-the-body)
27
+
28
+ ## Contributing
29
+
30
+ Corrections, counterexamples and design criticism are the contribution this project needs most at this stage. See [CONTRIBUTING.md](CONTRIBUTING.md). The Discussions tab is the common place for the design debate; Issues are for named defects in the proposal, each with its receipt.
31
+
32
+ ## License
33
+
34
+ MIT for code and text alike, so the design can travel. See [LICENSE](LICENSE).
package/SPEC.md ADDED
@@ -0,0 +1,107 @@
1
+ # Acta MCP Server: Build Specification
2
+
3
+ Status: build specification, December 2026. Companion to [PROPOSAL.md](PROPOSAL.md), which carries the design and its reasons. This document carries the construction: what the server is, piece by piece, and the order it is built in.
4
+
5
+ ## Purpose
6
+
7
+ Acta's installable form is an MCP server. Any agent that speaks MCP (Claude Code, Claude, other vendors' agents) connects to it and coordinates with the rest of its team through one store, changed only by named transitions, with effects subscribed to slices of state. The server enforces the discipline, so the discipline no longer depends on the virtue of the operators.
8
+
9
+ Thesis, unchanged: coordination is a function of the state, when the components interpret.
10
+
11
+ ## Architecture
12
+
13
+ One server process owns the store. State is divided into named slices. Every write is a transition: a named, validated operation applied through a single commit queue, appended to an append-only log, and assigned the next state version. After each commit, the effects subscribed to the changed slices run, once per version. There is no other write path.
14
+
15
+ ### The store
16
+
17
+ - Slices are declared in configuration: a name, a JSON schema for its content, and its initial value.
18
+ - The store is a single file (JSONL log plus snapshot) in v0; SQLite is the named successor when a real workload asks for it. One writer: the server process. The single commit point is literal, not a metaphor.
19
+
20
+ ### Transitions
21
+
22
+ - A transition is declared with: a name, the slice it writes, an input schema, the seats allowed to call it, and an optional guard (a precondition over the current slice value).
23
+ - Through MCP, each transition is exposed as a tool. Calling the tool proposes the transition: the server validates the seat, the schema and the guard, then serializes it through the commit queue. A rejected call returns the reason as data, never a silent failure.
24
+ - Every committed transition is a log record: `{ seq, version, at, seat, transition, slice, payload, baseVersion }`.
25
+
26
+ ### Reads
27
+
28
+ - Slices are exposed as MCP resources (`acta://state/<slice>`), each read stamped with the state version it reflects. An agent never asks another agent how things are; it reads the slice.
29
+
30
+ ### Effects
31
+
32
+ - An effect is declared server-side, in the server's configuration code, not over MCP: the slice it reads, the work it depends on (named beside the work, per the proposal), and its handler.
33
+ - Execution semantics: after commit, once per state version, over at-least-once delivery, with the idempotency key `(effect, version)`. An effect's output is itself a transition, called through the same commit path. An effect's failure is a transition too: the failure enters the state, where other effects and seats can see it.
34
+ - Effects run in the server process in v0 (handlers are local modules). Remote effects are an open question in PROPOSAL.md, not a v0 feature.
35
+
36
+ ### Deadlines
37
+
38
+ - A transition may carry a deadline registration: at commit time, the server records a deadline (an instant and the transition to write if it passes unfulfilled). When the instant passes, the server itself commits the expiry transition. An absence becomes a fact in the state, with its own transition, never a silence that a poller must interpret.
39
+
40
+ ### Seats
41
+
42
+ - A seat is a named caller identity with a manifest: the transitions it may emit and the slices it may read. Each seat authenticates with its own token; the server refuses calls outside the manifest.
43
+ - A human is a seat like any other, with one declared difference: a human seat's work has no bounded execution time, so work waiting on a human is a state with its own deadline, never an invisible wait.
44
+
45
+ ### The log and replay
46
+
47
+ - The log is append-only. A CLI (`acta replay`) folds the log from any snapshot and prints the state at any version, for audit and for debugging a team after the fact.
48
+ - `acta inspect` prints the current version, the slices, the registered transitions, effects and seats, and the last N log records.
49
+
50
+ ## Configuration shape (code-first, TypeScript)
51
+
52
+ ```ts
53
+ import { defineActa } from "@acta/server";
54
+
55
+ export default defineActa({
56
+ slices: {
57
+ queue: { schema: QueueState, initial: { fronts: [] } },
58
+ pulse: { schema: PulseState, initial: {} },
59
+ },
60
+ transitions: {
61
+ deposit: { slice: "queue", seats: ["builder"], input: DepositInput },
62
+ land: { slice: "queue", seats: ["coordinator"], input: LandInput },
63
+ stop: { slice: "pulse", seats: ["watcher", "coordinator"], input: StopInput },
64
+ },
65
+ effects: [
66
+ { reads: "queue", after: ["deposit"], run: verifyDeposit },
67
+ ],
68
+ seats: {
69
+ builder: { token: env("ACTA_SEAT_BUILDER") },
70
+ coordinator: { token: env("ACTA_SEAT_COORDINATOR") },
71
+ watcher: { token: env("ACTA_SEAT_WATCHER") },
72
+ },
73
+ });
74
+ ```
75
+
76
+ The names in this sketch are the reference operation's own vocabulary, as an example. A team's domain names its own transitions; Acta supplies the mechanics.
77
+
78
+ ## Transports
79
+
80
+ - v0: stdio, the transport every MCP client already speaks.
81
+ - Second: streamable HTTP, for teams whose agents run in different processes and machines. The commit point stays one server either way.
82
+
83
+ ## Build order
84
+
85
+ - **S1, core:** store, commit queue, transition registry, log, replay and inspect CLI. Acceptance: the configuration sketch above runs; two scripted callers commit transitions concurrently and the log shows them serialized, each with its version; replay reproduces the state at any version.
86
+ - **S2, MCP surface:** transitions as tools, slices as resources, over stdio. Acceptance: Claude Code connects, reads a slice with its version stamp, calls a transition, and a second client sees the new version on its next read.
87
+ - **S3, effects:** subscriptions by slice, once per version with idempotency keys, effect output and effect failure as transitions. Acceptance: the deposit example: a deposit transition fires the verification effect exactly once per version, and a forced effect failure appears in the state as a failure transition.
88
+ - **S4, seats and deadlines:** manifests enforced, deadline registration and expiry transitions. Acceptance: a call outside a seat's manifest is refused with the reason; a deadline passing without its deposit writes the expiry transition by itself.
89
+ - **S5, first real user:** the Mandato reference operation's launcher hook writes its deposit through the server, and the verification effect replaces the clock-scheduled watchdog for that deposit. Acceptance: a live build session's deposit is verified in minutes from the event, with the deadline transition standing as the only clock in the path.
90
+ - **S6, public demo and v0.1:** a five-minute demo, two agents and one shared bug, the scenario the field keeps describing without a mechanism; npm publication as v0.1 with the demo in the README.
91
+
92
+ ## Non-goals for v0
93
+
94
+ - No multi-writer distribution. One commit point is the thesis, not a limitation to apologize for.
95
+ - No user interface. The state is the interface; clients already render resources.
96
+ - No exactly-once guarantee across a server crash mid-effect beyond the idempotency key discipline: at-least-once delivery, once-per-version effect bookkeeping, and failures written back as state.
97
+ - No remote effect handlers, no plugin marketplace, no hosted service.
98
+
99
+ ## Carried open questions
100
+
101
+ From PROPOSAL.md, unchanged: effect ordering when several effects read the same slice; slice granularity guidance; exactly-once across mid-effect crashes; how a human seat's silence deadline is set without becoming a nagging machine. The build answers them in the order real use raises them, and each answer lands here as an amendment with its case.
102
+
103
+ ## Construction notes (amendments from the build)
104
+
105
+ - **S1 (2026-12-05): the transition's reducer is named `apply`.** The configuration sketch above declares a transition's name, slice, seats and input schema, but does not say who computes the slice's next value. The build names that piece: every transition declaration carries `apply(current, payload)`, a pure function returning the next slice value. The commit path validates the result against the slice schema before committing; an invalid result is a refusal, returned as data. There is still no other write path.
106
+ - **S3 (2026-12-05): the effect declaration, completed.** An effect declares `name` (its idempotency identity), `reads` (the slice it subscribes to), optional `after` (only these transitions trigger it), `seat` (the seat its emitted transitions are proposed as), optional `failureTransition`, and `run`. Bookkeeping for the (effect, version) keys persists beside the log (`<log>.effects.json`), so a restart never re-runs a completed pair, and versions committed before a crash, or before the effect existed, are caught up at boot: at-least-once, made safe by the keys. A failure is committed through the declared `failureTransition` with payload `{ effect, version, error }`; if even that commit is refused, the bookkeeping entry is the failure's record. One guard the sketch did not anticipate: an unbroken cascade of effects retriggering each other is capped at 64 runs, and anything past the cap is recorded as failed with the cap as its reason, never silently dropped.
107
+ - **S4 (2026-12-05): seat manifests, tokens, and the deadline registry.** A seat declaration may now carry a `token` and a `manifest` (the transitions that seat may ever emit). A proposal as a tokened seat must present the token (the MCP server presents `ACTA_SEAT_TOKEN`), and a proposal outside the manifest is refused with the reason, even where the transition itself would allow the seat; `defineActa` rejects a manifest that promises a transition which does not allow the seat. A deadline is registered at runtime against the current version: it names the awaited transition, an optional `matchPayload` subset the awaited record's payload must carry (one front's deposit does not satisfy another front's deadline), the expiry transition and the seat that emits it. Satisfaction is derived from the log, so it survives restarts with no bookkeeping to trust; the registry itself persists beside the log (`<log>.deadlines.json`). The server's one clock act is explicit: `checkDeadlines()`, called by the embedder on its own cadence, writes each due, unsatisfied deadline's expiry through the commit queue, exactly once; a refused expiry stays open and is retried at the next check, in the open.
@@ -0,0 +1,3 @@
1
+ import { type ActaConfig } from "../src/index.ts";
2
+ declare const config: ActaConfig;
3
+ export default config;
@@ -0,0 +1,81 @@
1
+ import { defineActa } from "../src/index.js";
2
+ // The S4 sketch made runnable: seats with manifests and tokens, and a
3
+ // deposit deadline. The builder seat is narrowed by its manifest to
4
+ // the deposit alone and must present its token; the coordinator seat
5
+ // is unrestricted. A deadline registered for a front's deposit writes
6
+ // the depositMissed transition by itself when the due time passes
7
+ // without the deposit, which is the house watchdog doctrine with the
8
+ // clock replaced by a state transition.
9
+ const config = defineActa({
10
+ slices: {
11
+ queue: {
12
+ schema: {
13
+ type: "object",
14
+ properties: { fronts: { type: "array", items: { type: "string" } } },
15
+ required: ["fronts"],
16
+ },
17
+ initial: { fronts: [] },
18
+ },
19
+ alerts: {
20
+ schema: {
21
+ type: "object",
22
+ properties: { missed: { type: "array", items: { type: "string" } } },
23
+ required: ["missed"],
24
+ },
25
+ initial: { missed: [] },
26
+ },
27
+ },
28
+ transitions: {
29
+ deposit: {
30
+ slice: "queue",
31
+ seats: ["builder", "coordinator"],
32
+ input: {
33
+ type: "object",
34
+ properties: { front: { type: "string" } },
35
+ required: ["front"],
36
+ },
37
+ apply: (slice, payload) => {
38
+ const queue = slice;
39
+ const { front } = payload;
40
+ return { fronts: [...queue.fronts, front] };
41
+ },
42
+ },
43
+ land: {
44
+ slice: "queue",
45
+ // The transition itself allows both seats; what keeps the
46
+ // builder from landing a front is its own manifest, which is
47
+ // the point of a manifest: the seat's declared scope narrows
48
+ // what the transition would otherwise permit.
49
+ seats: ["builder", "coordinator"],
50
+ input: {
51
+ type: "object",
52
+ properties: { front: { type: "string" } },
53
+ required: ["front"],
54
+ },
55
+ apply: (slice, payload) => {
56
+ const queue = slice;
57
+ const { front } = payload;
58
+ return { fronts: queue.fronts.filter((f) => f !== front) };
59
+ },
60
+ },
61
+ depositMissed: {
62
+ slice: "alerts",
63
+ seats: ["coordinator"],
64
+ input: {
65
+ type: "object",
66
+ properties: { deadline: { type: "string" } },
67
+ required: ["deadline"],
68
+ },
69
+ apply: (slice, payload) => {
70
+ const alerts = slice;
71
+ const { deadline } = payload;
72
+ return { missed: [...alerts.missed, deadline] };
73
+ },
74
+ },
75
+ },
76
+ seats: {
77
+ builder: { token: "builder-token", manifest: { transitions: ["deposit"] } },
78
+ coordinator: {},
79
+ },
80
+ });
81
+ export default config;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import { mkdtempSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { Acta, Log } from "../src/index.js";
5
+ import config from "./sketch.js";
6
+ // Two scripted callers, one builder and one coordinator, committing
7
+ // concurrently against one store. The log is the receipt: serialized,
8
+ // one version each, in commit order.
9
+ const dir = mkdtempSync(join(tmpdir(), "acta-demo-"));
10
+ const logPath = join(dir, "log.jsonl");
11
+ const acta = new Acta(config, { logPath });
12
+ const builder = (async () => {
13
+ for (const front of ["alpha", "beta", "gamma"]) {
14
+ const result = await acta.propose("builder", "deposit", { front });
15
+ console.log("builder deposit", front, "->", JSON.stringify(result.ok ? `v${result.version}` : result.reason));
16
+ }
17
+ })();
18
+ const coordinator = (async () => {
19
+ const result = await acta.propose("coordinator", "land", { front: "alpha" });
20
+ console.log("coordinator land alpha ->", JSON.stringify(result.ok ? `v${result.version}` : result.reason));
21
+ })();
22
+ await Promise.all([builder, coordinator]);
23
+ console.log("--- log ---");
24
+ for (const record of new Log(logPath).readAll()) {
25
+ console.log(`#${record.seq} v${record.version} ${record.seat} ${record.transition} ${JSON.stringify(record.payload)}`);
26
+ }
27
+ console.log("--- state at current version ---");
28
+ console.log(JSON.stringify(acta.read("queue"), null, 2));
29
+ console.log(`log file: ${logPath}`);
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../src/config.ts").ActaConfig;
2
+ export default _default;
@@ -0,0 +1,155 @@
1
+ import { defineActa } from "../src/index.js";
2
+ // The SPEC S3 acceptance example, as a runnable config: a deposit on
3
+ // the queue fires the verification effect exactly once per version;
4
+ // the effect's output is a transition (verify, on the checks slice);
5
+ // a forced effect failure appears in the state as a failure
6
+ // transition (effectFailed, on the alerts slice).
7
+ const FrontList = {
8
+ type: "object",
9
+ required: ["fronts"],
10
+ additionalProperties: false,
11
+ properties: {
12
+ fronts: {
13
+ type: "array",
14
+ items: {
15
+ type: "object",
16
+ required: ["id", "state"],
17
+ properties: {
18
+ id: { type: "string" },
19
+ state: { type: "string", enum: ["deposited", "landed"] },
20
+ },
21
+ },
22
+ },
23
+ },
24
+ };
25
+ const ChecksState = {
26
+ type: "object",
27
+ required: ["verified"],
28
+ additionalProperties: false,
29
+ properties: { verified: { type: "array", items: { type: "string" } } },
30
+ };
31
+ const AlertsState = {
32
+ type: "object",
33
+ required: ["failures"],
34
+ additionalProperties: false,
35
+ properties: {
36
+ failures: {
37
+ type: "array",
38
+ items: {
39
+ type: "object",
40
+ required: ["effect", "version", "error"],
41
+ properties: {
42
+ effect: { type: "string" },
43
+ version: { type: "integer" },
44
+ error: { type: "string" },
45
+ },
46
+ },
47
+ },
48
+ },
49
+ };
50
+ const FrontInput = {
51
+ type: "object",
52
+ required: ["front"],
53
+ additionalProperties: false,
54
+ properties: { front: { type: "string", minLength: 1 } },
55
+ };
56
+ const FailureInput = {
57
+ type: "object",
58
+ required: ["effect", "version", "error"],
59
+ additionalProperties: false,
60
+ properties: {
61
+ effect: { type: "string" },
62
+ version: { type: "integer" },
63
+ error: { type: "string" },
64
+ },
65
+ };
66
+ async function verifyDeposit(ctx) {
67
+ const front = ctx.record.payload.front;
68
+ if (front === "boom")
69
+ throw new Error("verification exploded, on purpose");
70
+ const outcome = await ctx.emit("verify", { front });
71
+ if (!outcome.ok)
72
+ throw new Error(`verify refused: ${outcome.reason ?? "unknown"}`);
73
+ }
74
+ export default defineActa({
75
+ slices: {
76
+ queue: { schema: FrontList, initial: { fronts: [] } },
77
+ checks: { schema: ChecksState, initial: { verified: [] } },
78
+ alerts: { schema: AlertsState, initial: { failures: [] } },
79
+ },
80
+ transitions: {
81
+ deposit: {
82
+ slice: "queue",
83
+ seats: ["builder"],
84
+ input: FrontInput,
85
+ guard: (slice, payload) => {
86
+ const queue = slice;
87
+ const front = payload.front;
88
+ return queue.fronts.some((f) => f.id === front)
89
+ ? `front "${front}" is already deposited`
90
+ : true;
91
+ },
92
+ apply: (slice, payload) => {
93
+ const queue = slice;
94
+ const front = payload.front;
95
+ return { fronts: [...queue.fronts, { id: front, state: "deposited" }] };
96
+ },
97
+ },
98
+ verify: {
99
+ slice: "checks",
100
+ seats: ["verifier"],
101
+ input: FrontInput,
102
+ apply: (slice, payload) => {
103
+ const checks = slice;
104
+ const front = payload.front;
105
+ return { verified: [...checks.verified, front] };
106
+ },
107
+ },
108
+ land: {
109
+ slice: "queue",
110
+ seats: ["coordinator"],
111
+ input: FrontInput,
112
+ guard: (slice, payload) => {
113
+ const queue = slice;
114
+ const front = payload.front;
115
+ const found = queue.fronts.find((f) => f.id === front);
116
+ if (!found)
117
+ return `front "${front}" was never deposited`;
118
+ if (found.state === "landed")
119
+ return `front "${front}" is already landed`;
120
+ return true;
121
+ },
122
+ apply: (slice, payload) => {
123
+ const queue = slice;
124
+ const front = payload.front;
125
+ return {
126
+ fronts: queue.fronts.map((f) => (f.id === front ? { ...f, state: "landed" } : f)),
127
+ };
128
+ },
129
+ },
130
+ effectFailed: {
131
+ slice: "alerts",
132
+ seats: ["verifier"],
133
+ input: FailureInput,
134
+ apply: (slice, payload) => {
135
+ const alerts = slice;
136
+ return { failures: [...alerts.failures, payload] };
137
+ },
138
+ },
139
+ },
140
+ effects: [
141
+ {
142
+ name: "verify-deposit",
143
+ reads: "queue",
144
+ after: ["deposit"],
145
+ seat: "verifier",
146
+ failureTransition: "effectFailed",
147
+ run: verifyDeposit,
148
+ },
149
+ ],
150
+ seats: {
151
+ builder: {},
152
+ verifier: {},
153
+ coordinator: {},
154
+ },
155
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../src/config.ts").ActaConfig;
2
+ export default _default;
@@ -0,0 +1,102 @@
1
+ import { defineActa } from "../src/index.js";
2
+ // The SPEC.md configuration sketch, made runnable: the reference
3
+ // operation's own vocabulary as the example. Two scripted callers
4
+ // commit concurrently; the log shows them serialized, each with its
5
+ // version; replay reproduces the state.
6
+ const QueueState = {
7
+ type: "object",
8
+ required: ["fronts"],
9
+ additionalProperties: false,
10
+ properties: {
11
+ fronts: {
12
+ type: "array",
13
+ items: {
14
+ type: "object",
15
+ required: ["id", "state"],
16
+ properties: {
17
+ id: { type: "string" },
18
+ state: { type: "string", enum: ["deposited", "landed"] },
19
+ },
20
+ },
21
+ },
22
+ },
23
+ };
24
+ const PulseState = {
25
+ type: "object",
26
+ additionalProperties: false,
27
+ properties: {
28
+ stopped: { type: "boolean" },
29
+ cause: { type: "string" },
30
+ },
31
+ };
32
+ const DepositInput = {
33
+ type: "object",
34
+ required: ["front"],
35
+ additionalProperties: false,
36
+ properties: { front: { type: "string", minLength: 1 } },
37
+ };
38
+ const LandInput = DepositInput;
39
+ const StopInput = {
40
+ type: "object",
41
+ required: ["cause"],
42
+ additionalProperties: false,
43
+ properties: { cause: { type: "string", minLength: 1 } },
44
+ };
45
+ export default defineActa({
46
+ slices: {
47
+ queue: { schema: QueueState, initial: { fronts: [] } },
48
+ pulse: { schema: PulseState, initial: {} },
49
+ },
50
+ transitions: {
51
+ deposit: {
52
+ slice: "queue",
53
+ seats: ["builder"],
54
+ input: DepositInput,
55
+ guard: (slice, payload) => {
56
+ const queue = slice;
57
+ const front = payload.front;
58
+ return queue.fronts.some((f) => f.id === front)
59
+ ? `front "${front}" is already deposited`
60
+ : true;
61
+ },
62
+ apply: (slice, payload) => {
63
+ const queue = slice;
64
+ const front = payload.front;
65
+ return { fronts: [...queue.fronts, { id: front, state: "deposited" }] };
66
+ },
67
+ },
68
+ land: {
69
+ slice: "queue",
70
+ seats: ["coordinator"],
71
+ input: LandInput,
72
+ guard: (slice, payload) => {
73
+ const queue = slice;
74
+ const front = payload.front;
75
+ const found = queue.fronts.find((f) => f.id === front);
76
+ if (!found)
77
+ return `front "${front}" was never deposited`;
78
+ if (found.state === "landed")
79
+ return `front "${front}" is already landed`;
80
+ return true;
81
+ },
82
+ apply: (slice, payload) => {
83
+ const queue = slice;
84
+ const front = payload.front;
85
+ return {
86
+ fronts: queue.fronts.map((f) => (f.id === front ? { ...f, state: "landed" } : f)),
87
+ };
88
+ },
89
+ },
90
+ stop: {
91
+ slice: "pulse",
92
+ seats: ["watcher", "coordinator"],
93
+ input: StopInput,
94
+ apply: (_slice, payload) => ({ stopped: true, cause: payload.cause }),
95
+ },
96
+ },
97
+ seats: {
98
+ builder: {},
99
+ coordinator: {},
100
+ watcher: {},
101
+ },
102
+ });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ // acta inspect: current version, slices, registered transitions and
3
+ // seats, and the last N log records.
4
+ // acta replay: fold the log and print the state at any version.
5
+ // acta serve: run the MCP server over stdio, serving one seat.
6
+ //
7
+ // Usage:
8
+ // acta inspect --config <config.ts> --log <log.jsonl> [--tail 10]
9
+ // acta replay --config <config.ts> --log <log.jsonl> [--to <version>]
10
+ // acta serve --config <config.ts> --log <log.jsonl> --seat <seat>
11
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
12
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
13
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
14
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
15
+ });
16
+ }
17
+ return path;
18
+ };
19
+ import { resolve } from "node:path";
20
+ import { pathToFileURL } from "node:url";
21
+ import { Acta } from "./store.js";
22
+ import { Log } from "./log.js";
23
+ import { startMcpServer } from "./mcp.js";
24
+ function arg(flag) {
25
+ const index = process.argv.indexOf(flag);
26
+ return index >= 0 ? process.argv[index + 1] : undefined;
27
+ }
28
+ async function loadConfig(path) {
29
+ const mod = await import(__rewriteRelativeImportExtension(pathToFileURL(resolve(path)).href));
30
+ const config = (mod.default ?? mod.config);
31
+ if (!config || !config.slices || !config.transitions) {
32
+ throw new Error(`config at ${path} does not export an Acta configuration`);
33
+ }
34
+ return config;
35
+ }
36
+ const command = process.argv[2];
37
+ const configPath = arg("--config");
38
+ const logPath = arg("--log");
39
+ if (!command || !configPath || !logPath) {
40
+ console.error("usage: acta <inspect|replay|serve> --config <config.ts> --log <log.jsonl> [--to N] [--tail N] [--seat S]");
41
+ process.exit(2);
42
+ }
43
+ const config = await loadConfig(configPath);
44
+ if (command === "serve") {
45
+ const seat = arg("--seat") ?? process.env.ACTA_SEAT;
46
+ if (!seat) {
47
+ console.error("acta serve needs a seat: --seat <seat> or ACTA_SEAT");
48
+ process.exit(2);
49
+ }
50
+ if (!(seat in config.seats)) {
51
+ console.error(`unknown seat "${seat}"`);
52
+ process.exit(2);
53
+ }
54
+ const acta = new Acta(config, { logPath });
55
+ startMcpServer(acta, config, seat);
56
+ }
57
+ else if (command === "inspect") {
58
+ const records = new Log(logPath).readAll();
59
+ const { version } = Acta.replay(config, records);
60
+ const tail = Number(arg("--tail") ?? "10");
61
+ console.log(`version: ${version}`);
62
+ console.log(`slices: ${Object.keys(config.slices).join(", ")}`);
63
+ console.log(`transitions: ${Object.entries(config.transitions)
64
+ .map(([name, decl]) => `${name} -> ${decl.slice} [${decl.seats.join(", ")}]`)
65
+ .join("; ")}`);
66
+ console.log(`seats: ${Object.keys(config.seats).join(", ")}`);
67
+ console.log(`log records: ${records.length}`);
68
+ for (const record of records.slice(-tail)) {
69
+ console.log(`#${record.seq} v${record.version} ${record.at} ${record.seat} ${record.transition} ${JSON.stringify(record.payload)}`);
70
+ }
71
+ }
72
+ else if (command === "replay") {
73
+ const records = new Log(logPath).readAll();
74
+ const to = arg("--to");
75
+ const { state, version } = Acta.replay(config, records, {
76
+ toVersion: to ? Number(to) : undefined,
77
+ });
78
+ console.log(JSON.stringify({ version, state }, null, 2));
79
+ }
80
+ else {
81
+ console.error(`unknown command "${command}"`);
82
+ process.exit(2);
83
+ }