fivefold 0.1.0__py3-none-any.whl

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.
Files changed (128) hide show
  1. fivefold/__init__.py +4 -0
  2. fivefold/_data/db/bootstrap.sql +26 -0
  3. fivefold/_data/db/migrations/0001_schemas.sql +67 -0
  4. fivefold/_data/db/migrations/0002_gateway.sql +224 -0
  5. fivefold/_data/db/migrations/0003_gateway_record_0010.sql +91 -0
  6. fivefold/_data/db/migrations/0004_harness.sql +141 -0
  7. fivefold/_data/db/migrations/0005_sim.sql +679 -0
  8. fivefold/_data/db/migrations/0006_gateway_reads.sql +66 -0
  9. fivefold/_data/db/migrations/0007_eval.sql +33 -0
  10. fivefold/_data/db/migrations/0008_run_stop.sql +18 -0
  11. fivefold/_data/db/migrations/0009_message_copies.sql +69 -0
  12. fivefold/_data/db/migrations/0010_gateway_g1_check.sql +14 -0
  13. fivefold/_data/db/migrations/0011_model_calls.sql +37 -0
  14. fivefold/_data/db/migrations/0012_recovery_latency.sql +23 -0
  15. fivefold/_data/db/migrations/0013_split_topology.sql +33 -0
  16. fivefold/_data/db/migrations/0014_tool_call_args.sql +20 -0
  17. fivefold/_data/db/registry/0001_registry.sql +31 -0
  18. fivefold/_data/faults/expected.yaml +406 -0
  19. fivefold/_data/scenarios/dev/dev-001-single-po.yaml +45 -0
  20. fivefold/_data/scenarios/dev/dev-002-human-approval.yaml +47 -0
  21. fivefold/agents/__init__.py +7 -0
  22. fivefold/agents/branch.py +187 -0
  23. fivefold/agents/checkpoint.py +77 -0
  24. fivefold/agents/connection.py +153 -0
  25. fivefold/agents/live.py +492 -0
  26. fivefold/agents/policy.py +426 -0
  27. fivefold/agents/remote.py +333 -0
  28. fivefold/agents/replay.py +170 -0
  29. fivefold/agents/scripted.py +122 -0
  30. fivefold/agents/tools.py +229 -0
  31. fivefold/agents/worker.py +164 -0
  32. fivefold/domain/__init__.py +5 -0
  33. fivefold/domain/api.py +517 -0
  34. fivefold/domain/authority.py +149 -0
  35. fivefold/domain/contracts.py +80 -0
  36. fivefold/domain/identity.py +113 -0
  37. fivefold/domain/prices.py +178 -0
  38. fivefold/domain/report.py +92 -0
  39. fivefold/domain/rules.py +346 -0
  40. fivefold/domain/scenario.py +524 -0
  41. fivefold/evaluator/__init__.py +155 -0
  42. fivefold/evaluator/__main__.py +127 -0
  43. fivefold/evaluator/authorization.py +146 -0
  44. fivefold/evaluator/checks.py +331 -0
  45. fivefold/evaluator/evaluate.py +109 -0
  46. fivefold/evaluator/evidence.py +392 -0
  47. fivefold/evaluator/freshness.py +136 -0
  48. fivefold/evaluator/liveness.py +236 -0
  49. fivefold/evaluator/load.py +354 -0
  50. fivefold/evaluator/metrics.py +95 -0
  51. fivefold/evaluator/records.py +452 -0
  52. fivefold/evaluator/recovery.py +209 -0
  53. fivefold/evaluator/report.py +1096 -0
  54. fivefold/evaluator/result.py +344 -0
  55. fivefold/evaluator/store.py +83 -0
  56. fivefold/faults/__init__.py +5 -0
  57. fivefold/faults/catalog.py +278 -0
  58. fivefold/faults/plan.py +538 -0
  59. fivefold/gateway/__init__.py +6 -0
  60. fivefold/gateway/admin.py +179 -0
  61. fivefold/gateway/admin_api.py +398 -0
  62. fivefold/gateway/codec.py +372 -0
  63. fivefold/gateway/destination.py +64 -0
  64. fivefold/gateway/dispatcher.py +379 -0
  65. fivefold/gateway/freshness.py +83 -0
  66. fivefold/gateway/invariants.py +761 -0
  67. fivefold/gateway/memory.py +277 -0
  68. fivefold/gateway/pg_store.py +657 -0
  69. fivefold/gateway/records.py +592 -0
  70. fivefold/gateway/server.py +102 -0
  71. fivefold/gateway/sim_client.py +295 -0
  72. fivefold/gateway/state_machine.py +376 -0
  73. fivefold/gateway/steps.py +897 -0
  74. fivefold/gateway/store.py +635 -0
  75. fivefold/gateway/tools.py +424 -0
  76. fivefold/gateway/twin.py +199 -0
  77. fivefold/gateway/wire.py +138 -0
  78. fivefold/harness/__init__.py +6 -0
  79. fivefold/harness/actors.py +230 -0
  80. fivefold/harness/cells.py +303 -0
  81. fivefold/harness/clock.py +209 -0
  82. fivefold/harness/demo.py +397 -0
  83. fivefold/harness/fault_effects.py +122 -0
  84. fivefold/harness/live_options.py +159 -0
  85. fivefold/harness/log.py +540 -0
  86. fivefold/harness/mcp_link.py +409 -0
  87. fivefold/harness/migrations.py +520 -0
  88. fivefold/harness/models.py +368 -0
  89. fivefold/harness/registry.py +105 -0
  90. fivefold/harness/reports.py +100 -0
  91. fivefold/harness/rng.py +57 -0
  92. fivefold/harness/run.py +881 -0
  93. fivefold/harness/scheduler.py +441 -0
  94. fivefold/harness/sim_points.py +215 -0
  95. fivefold/harness/split/__init__.py +34 -0
  96. fivefold/harness/split/__main__.py +275 -0
  97. fivefold/harness/split/credentials.py +74 -0
  98. fivefold/harness/split/faults.py +75 -0
  99. fivefold/harness/split/gateway.py +769 -0
  100. fivefold/harness/split/hops.py +291 -0
  101. fivefold/harness/split/lifecycle.py +322 -0
  102. fivefold/harness/split/rundir.py +152 -0
  103. fivefold/harness/split/service.py +157 -0
  104. fivefold/harness/split/simulator.py +432 -0
  105. fivefold/harness/study.py +643 -0
  106. fivefold/harness/transport.py +533 -0
  107. fivefold/paths.py +24 -0
  108. fivefold/py.typed +0 -0
  109. fivefold/recorder/__init__.py +18 -0
  110. fivefold/recorder/__main__.py +308 -0
  111. fivefold/recorder/cassette.py +322 -0
  112. fivefold/recorder/playback.py +316 -0
  113. fivefold/recorder/recording.py +133 -0
  114. fivefold/sim/__init__.py +37 -0
  115. fivefold/sim/config.py +52 -0
  116. fivefold/sim/endpoint.py +176 -0
  117. fivefold/sim/ledger.py +583 -0
  118. fivefold/sim/service.py +834 -0
  119. fivefold/viewer/__init__.py +14 -0
  120. fivefold/viewer/__main__.py +75 -0
  121. fivefold/viewer/app.py +122 -0
  122. fivefold/viewer/records.py +108 -0
  123. fivefold/viewer/source.py +196 -0
  124. fivefold/viewer/timeline.py +61 -0
  125. fivefold-0.1.0.dist-info/METADATA +169 -0
  126. fivefold-0.1.0.dist-info/RECORD +128 -0
  127. fivefold-0.1.0.dist-info/WHEEL +4 -0
  128. fivefold-0.1.0.dist-info/licenses/LICENSE +202 -0
@@ -0,0 +1,66 @@
1
+ -- Reads and write calls (decision record 0001, items 13 to 17).
2
+ --
3
+ -- gw.read holds every read the gateway served, with the fact's value, so a later check
4
+ -- can compare the cited version's fields with the current ones (0004, dependency
5
+ -- rules); a proposal cites reads by their ids.
6
+ -- gw.proposal holds every write call with its outcome, admitted or refused. The gateway
7
+ -- only ever adds rows to either table: ff_gw has no UPDATE or DELETE privilege on them,
8
+ -- and triggers reject both. The run's state row numbers both, so ids have no gaps.
9
+
10
+ ALTER TABLE gw.run_state
11
+ ADD COLUMN last_read_no bigint NOT NULL DEFAULT 0,
12
+ ADD COLUMN last_proposal_no bigint NOT NULL DEFAULT 0;
13
+
14
+ -- A closed run stays closed, and its counters never go back.
15
+ CREATE OR REPLACE FUNCTION gw.keep_run_state() RETURNS trigger LANGUAGE plpgsql AS $$
16
+ BEGIN
17
+ IF (OLD.run_closed AND NOT NEW.run_closed)
18
+ OR NEW.last_action_no < OLD.last_action_no
19
+ OR NEW.last_seq < OLD.last_seq
20
+ OR NEW.last_call_no < OLD.last_call_no
21
+ OR NEW.last_read_no < OLD.last_read_no
22
+ OR NEW.last_proposal_no < OLD.last_proposal_no
23
+ THEN
24
+ RAISE EXCEPTION 'the run cannot reopen and its counters cannot go back';
25
+ END IF;
26
+ RETURN NEW;
27
+ END
28
+ $$;
29
+
30
+ CREATE TABLE gw.read (
31
+ read_id text PRIMARY KEY CHECK (read_id ~ '^R-[0-9]{4,}$'),
32
+ key text NOT NULL,
33
+ version bigint NOT NULL,
34
+ data jsonb NOT NULL CHECK (jsonb_typeof(data) = 'object'),
35
+ vt bigint NOT NULL
36
+ );
37
+
38
+ CREATE INDEX read_by_fact ON gw.read (key, version);
39
+
40
+ -- `args` holds the business arguments in normal form, or, for a call refused with
41
+ -- invalid_args, the arguments as the agent sent them. `action_id` names the action the
42
+ -- call created or attached to, or the one an intent_busy or intent_done refusal names.
43
+ CREATE TABLE gw.proposal (
44
+ proposal_id text PRIMARY KEY CHECK (proposal_id ~ '^P-[0-9]{4,}$'),
45
+ operation text NOT NULL,
46
+ intent_id text,
47
+ args jsonb NOT NULL CHECK (jsonb_typeof(args) = 'object'),
48
+ based_on jsonb NOT NULL CHECK (jsonb_typeof(based_on) = 'array'),
49
+ admission text NOT NULL CHECK (admission IN ('admitted', 'attached', 'refused')),
50
+ reason text CHECK (reason IN (
51
+ 'invalid_args', 'unknown_intent', 'wrong_operation', 'unknown_read', 'missing_basis',
52
+ 'intent_busy', 'intent_done', 'run_closed'
53
+ )),
54
+ action_id text REFERENCES gw.action (action_id),
55
+ vt bigint NOT NULL,
56
+ CHECK ((admission = 'refused') = (reason IS NOT NULL)),
57
+ CHECK (admission = 'refused' OR action_id IS NOT NULL)
58
+ );
59
+
60
+ REVOKE UPDATE, DELETE ON gw.read, gw.proposal FROM ff_gw;
61
+
62
+ CREATE TRIGGER read_is_append_only BEFORE UPDATE OR DELETE ON gw.read
63
+ FOR EACH ROW EXECUTE FUNCTION gw.reject_row_change();
64
+
65
+ CREATE TRIGGER proposal_is_append_only BEFORE UPDATE OR DELETE ON gw.proposal
66
+ FOR EACH ROW EXECUTE FUNCTION gw.reject_row_change();
@@ -0,0 +1,33 @@
1
+ -- The evaluator's results (decision records 0004 and 0008).
2
+ --
3
+ -- The evaluator connects as ff_eval and is the only writer here; ff_viewer reads. The
4
+ -- default privileges in 0001_schemas.sql give ff_eval SELECT, INSERT, UPDATE and DELETE
5
+ -- on every table here, and ff_viewer SELECT. No other role has any privilege.
6
+ --
7
+ -- Results are derived data: scoring a run again replaces its rows, in one transaction.
8
+
9
+ -- One row per run: the verdict over the properties evaluated, the metrics, and the whole
10
+ -- result as the evaluator's JSON (src/fivefold/evaluator/result.py).
11
+ CREATE TABLE eval.run_result (
12
+ run_id text PRIMARY KEY,
13
+ verdict text NOT NULL CHECK (verdict IN ('pass', 'pass_unresolved', 'fail')),
14
+ evaluated smallint[] NOT NULL CHECK (
15
+ cardinality(evaluated) BETWEEN 1 AND 5 AND evaluated <@ '{1, 2, 3, 4, 5}'
16
+ ),
17
+ metrics jsonb NOT NULL CHECK (jsonb_typeof(metrics) = 'object'),
18
+ result jsonb NOT NULL CHECK (jsonb_typeof(result) = 'object')
19
+ );
20
+
21
+ -- One row per run and property (spec, Data model: eval.Result). A property that fails
22
+ -- names at least one reason code, and one that passes or is not yet evaluated names none.
23
+ CREATE TABLE eval.result (
24
+ run_id text NOT NULL REFERENCES eval.run_result (run_id) ON DELETE CASCADE,
25
+ property smallint NOT NULL CHECK (property BETWEEN 1 AND 5),
26
+ name text NOT NULL,
27
+ verdict text NOT NULL CHECK (verdict IN ('pass', 'fail', 'not_evaluated')),
28
+ reason_codes text[] NOT NULL,
29
+ metrics jsonb NOT NULL CHECK (jsonb_typeof(metrics) = 'object'),
30
+ failures jsonb NOT NULL CHECK (jsonb_typeof(failures) = 'array'),
31
+ PRIMARY KEY (run_id, property),
32
+ CHECK ((verdict = 'fail') = (cardinality(reason_codes) > 0))
33
+ );
@@ -0,0 +1,18 @@
1
+ -- When the harness stopped the run (decision records 0004 and 0009).
2
+ --
3
+ -- The run stops at the end of the drain window. The evaluator judges "at the end" at this
4
+ -- time: for example, whether an approval is still valid and unused (0004, property 4).
5
+ -- Time passes in a quiet drain window without any record, so the latest record is not
6
+ -- the end. One row, written once when the run stops, and never changed.
7
+ CREATE TABLE harness.run_stop (
8
+ run_id text PRIMARY KEY REFERENCES harness.run (run_id),
9
+ stopped_vt bigint NOT NULL CHECK (stopped_vt >= 0),
10
+ stopped_wall_at timestamptz NOT NULL DEFAULT now()
11
+ );
12
+
13
+ CREATE UNIQUE INDEX run_stops_once ON harness.run_stop ((true));
14
+
15
+ CREATE TRIGGER run_stop_is_append_only BEFORE UPDATE OR DELETE ON harness.run_stop
16
+ FOR EACH ROW EXECUTE FUNCTION harness.reject_change();
17
+
18
+ REVOKE UPDATE, DELETE ON harness.run_stop FROM ff_harness;
@@ -0,0 +1,69 @@
1
+ -- Copies of requests, and the answers they get (decision record 0006, fault F4).
2
+ --
3
+ -- F4 delivers a request twice. The second delivery is a message of its own, which the
4
+ -- transport made: its sender sent the request once. `copy_of` names the request it
5
+ -- copies, so a reader can tell a copy from a request a component sent. A copy carries
6
+ -- the request exactly as sent, on the same hop, at the same virtual time; the trigger
7
+ -- below holds every insert to that. The transport never delivers the answer to a copy:
8
+ -- it drops it with reason `answer_to_copy` (0006, transport rules). An MCP notification
9
+ -- passes the same fault point as a request, so it can be copied too; it has no answer.
10
+ --
11
+ -- `copy_of` is history like the rest of the message: set when the copy is logged, never
12
+ -- changed afterwards.
13
+
14
+ ALTER TABLE harness.message_log
15
+ ADD COLUMN copy_of bigint REFERENCES harness.message_log (seq),
16
+ ADD CONSTRAINT message_log_copy_check CHECK (
17
+ copy_of IS NULL OR (kind <> 'answer' AND copy_of < seq)
18
+ );
19
+
20
+ ALTER TABLE harness.message_log
21
+ DROP CONSTRAINT message_log_drop_reason_check,
22
+ ADD CONSTRAINT message_log_drop_reason_check CHECK (drop_reason IN (
23
+ 'fault', 'receiver_down', 'caller_timed_out', 'caller_crashed', 'answer_to_copy'
24
+ ));
25
+
26
+ -- A copy repeats a request (or notification) that a component sent, field for field.
27
+ CREATE FUNCTION harness.check_copy() RETURNS trigger LANGUAGE plpgsql AS $$
28
+ DECLARE
29
+ original harness.message_log%ROWTYPE;
30
+ BEGIN
31
+ IF NEW.copy_of IS NULL THEN
32
+ RETURN NEW;
33
+ END IF;
34
+ SELECT * INTO original FROM harness.message_log WHERE seq = NEW.copy_of;
35
+ IF NOT FOUND
36
+ OR original.kind = 'answer'
37
+ OR original.copy_of IS NOT NULL
38
+ OR (NEW.hop, NEW.kind, NEW.sender, NEW.receiver, NEW.api, NEW.intent_id,
39
+ NEW.idempotency_key, NEW.body, NEW.sent_vt)
40
+ IS DISTINCT FROM
41
+ (original.hop, original.kind, original.sender, original.receiver, original.api,
42
+ original.intent_id, original.idempotency_key, original.body, original.sent_vt)
43
+ THEN
44
+ RAISE EXCEPTION 'message % is not a copy of request %', NEW.seq, NEW.copy_of;
45
+ END IF;
46
+ RETURN NEW;
47
+ END
48
+ $$;
49
+
50
+ CREATE TRIGGER message_log_copies_repeat_a_request BEFORE INSERT ON harness.message_log
51
+ FOR EACH ROW EXECUTE FUNCTION harness.check_copy();
52
+
53
+ -- The history rule of 0004_harness.sql, now covering `copy_of` too.
54
+ CREATE OR REPLACE FUNCTION harness.keep_message_history() RETURNS trigger LANGUAGE plpgsql AS $$
55
+ BEGIN
56
+ IF OLD.fate IS NOT NULL
57
+ OR (NEW.seq, NEW.hop, NEW.kind, NEW.sender, NEW.receiver, NEW.api, NEW.correlation,
58
+ NEW.intent_id, NEW.idempotency_key, NEW.answer_class, NEW.body, NEW.sent_vt,
59
+ NEW.copy_of)
60
+ IS DISTINCT FROM
61
+ (OLD.seq, OLD.hop, OLD.kind, OLD.sender, OLD.receiver, OLD.api, OLD.correlation,
62
+ OLD.intent_id, OLD.idempotency_key, OLD.answer_class, OLD.body, OLD.sent_vt,
63
+ OLD.copy_of)
64
+ THEN
65
+ RAISE EXCEPTION 'message % is history; only its fate can be set, once', OLD.seq;
66
+ END IF;
67
+ RETURN NEW;
68
+ END
69
+ $$;
@@ -0,0 +1,14 @@
1
+ -- G1's check before a send (decision record 0008).
2
+ --
3
+ -- G1 is authorization only: before its one send it asks the approvals service for the
4
+ -- approval (0002, rule 17) and reads no fact. Its attempt rows say so with a check kind of
5
+ -- their own, `authority_only`, which records the approval it found and no basis.
6
+
7
+ ALTER TABLE gw.attempt DROP CONSTRAINT attempt_check_kind_check;
8
+
9
+ ALTER TABLE gw.attempt ADD CONSTRAINT attempt_check_kind_check
10
+ CHECK (check_kind IN ('full', 'exact_only', 'exempt', 'authority_only'));
11
+
12
+ ALTER TABLE gw.attempt ADD CONSTRAINT attempt_authority_only_checks_no_fact
13
+ CHECK (check_kind <> 'authority_only'
14
+ OR (check_approval IS NOT NULL AND check_basis IS NULL));
@@ -0,0 +1,37 @@
1
+ -- The harness's log of model calls (decision records 0004 and 0009).
2
+ --
3
+ -- One row per model call of an agent worker, written once the call is answered: the
4
+ -- worker, the call's number in the run, the virtual times it was asked and answered, the
5
+ -- run's model, and the reply's input and output tokens. Record 0004's token and cost
6
+ -- metrics come from these rows. A reply that reports no usage, as every scripted reply
7
+ -- does, has no tokens. A call the live adapter refused at the spend cap names the reason
8
+ -- in `refused`, and has no tokens either: nothing was sent.
9
+ --
10
+ -- `call_no` counts the run's calls from 1 in the order they were answered, which is the
11
+ -- order of the run's cassette (0009). It is not a harness event number: model calls take
12
+ -- none of the counter that orders messages, faults, actor actions and reports. `wall_ms`,
13
+ -- the call's wall-clock duration, and `wall_at` are for metrics only (0009).
14
+ --
15
+ -- The rows are history: a trigger refuses every change, and ff_harness can only insert
16
+ -- and select. The default privileges in 0001_schemas.sql give ff_eval and ff_viewer
17
+ -- SELECT, so the evaluator can read them.
18
+
19
+ CREATE TABLE harness.model_call (
20
+ call_no bigint PRIMARY KEY CHECK (call_no >= 1),
21
+ worker text NOT NULL,
22
+ asked_vt bigint NOT NULL CHECK (asked_vt >= 0),
23
+ answered_vt bigint NOT NULL CHECK (answered_vt >= asked_vt),
24
+ model text NOT NULL,
25
+ input_tokens bigint CHECK (input_tokens >= 0),
26
+ output_tokens bigint CHECK (output_tokens >= 0),
27
+ refused text CHECK (refused IN ('spend_cap')),
28
+ wall_ms double precision NOT NULL CHECK (wall_ms >= 0),
29
+ wall_at timestamptz NOT NULL DEFAULT now(),
30
+ CHECK ((input_tokens IS NULL) = (output_tokens IS NULL)),
31
+ CHECK (refused IS NULL OR input_tokens IS NULL)
32
+ );
33
+
34
+ CREATE TRIGGER model_call_is_append_only BEFORE UPDATE OR DELETE ON harness.model_call
35
+ FOR EACH ROW EXECUTE FUNCTION harness.reject_change();
36
+
37
+ REVOKE UPDATE, DELETE ON harness.model_call FROM ff_harness;
@@ -0,0 +1,23 @@
1
+ -- What recovery latency reads from the harness (decision record 0014).
2
+ --
3
+ -- `fault_log.intent_id` names the task intent a fault touched: the intent of the message,
4
+ -- action or tool call it acted on (0014, decision 2). It is null for F9, which touches
5
+ -- every task intent, and for a fault on a message without an intent, such as a read. F10
6
+ -- acts on the next `count` status answers after it fires, which can concern several
7
+ -- intents. So besides the row written when F10 fires, the harness writes one row for
8
+ -- each status answer F10 changes, with that answer as `target_seq` and its intent. A
9
+ -- fault row is history: the intent is set when the row is written, never later.
10
+ --
11
+ -- `message_log.delivered_wall_at` is the wall-clock time of a delivery, set with its fate.
12
+ -- LangGraph's retry backoff holds a run in wall time, so a message's send (`wall_at`) and
13
+ -- its delivery can be far apart. Like every wall-clock column, it is for metrics only and
14
+ -- never decides anything (0009). A dropped message has none. The history rule of
15
+ -- 0009_message_copies.sql lets it be set once, with the fate, and never changed.
16
+
17
+ ALTER TABLE harness.fault_log ADD COLUMN intent_id text;
18
+
19
+ ALTER TABLE harness.message_log
20
+ ADD COLUMN delivered_wall_at timestamptz,
21
+ ADD CONSTRAINT message_log_delivered_wall_at_check CHECK (
22
+ delivered_wall_at IS NULL OR fate IS NOT DISTINCT FROM 'delivered'
23
+ );
@@ -0,0 +1,33 @@
1
+ -- The split topology (decision record 0009): the simulator and the gateway run as separate
2
+ -- services, for people who bring their own agent, and each writes the harness's records of
3
+ -- the traffic it sees.
4
+ --
5
+ -- One counter numbers every harness event in order (0004_harness.sql). The inproc harness
6
+ -- keeps it in memory. In the split topology two processes write the records, so they draw
7
+ -- their numbers from this sequence. The default privileges in 0001_schemas.sql give
8
+ -- ff_harness USAGE, SELECT and UPDATE on it.
9
+ CREATE SEQUENCE harness.event_seq AS bigint MINVALUE 1;
10
+
11
+ -- The split run's clock origin: the host's monotonic milliseconds at virtual time 0 (0009:
12
+ -- "In the split topology, the virtual clock follows the host's monotonic clock"). The first
13
+ -- service of the run to start sets it, and every process of the run reads it, so on one host
14
+ -- they all read the same virtual time. One row, written once and never changed.
15
+ CREATE TABLE harness.clock_origin (
16
+ origin_ms bigint NOT NULL,
17
+ set_wall_at timestamptz NOT NULL DEFAULT now()
18
+ );
19
+
20
+ CREATE UNIQUE INDEX clock_origin_is_one_row ON harness.clock_origin ((true));
21
+
22
+ CREATE TRIGGER clock_origin_is_append_only BEFORE UPDATE OR DELETE ON harness.clock_origin
23
+ FOR EACH ROW EXECUTE FUNCTION harness.reject_change();
24
+
25
+ REVOKE UPDATE, DELETE ON harness.clock_origin FROM ff_harness;
26
+
27
+ -- A split run's agent is the user's own. The harness runs no model for it, so the run
28
+ -- records its model adapter as `external`, with the model the user names.
29
+ ALTER TABLE harness.run
30
+ DROP CONSTRAINT run_model_adapter_check,
31
+ ADD CONSTRAINT run_model_adapter_check CHECK (
32
+ model_adapter IN ('scripted', 'live', 'replay', 'external')
33
+ );
@@ -0,0 +1,20 @@
1
+ -- The arguments of each logged call (decision record 0003, data model: `tool_call: seq,
2
+ -- tool, args, result, action_id, vt`; docs/spec.md, Data model, ToolCall).
3
+ --
4
+ -- `args` holds the arguments of the call a response answers, as the gateway received
5
+ -- them, decoded from JSON: a write's business arguments, `intent_id`, `based_on`, `note`
6
+ -- and any field outside its schema; `get_action_status`'s action id and wait; a final
7
+ -- report's claims. Both topologies refuse an agent's message holding a NUL character
8
+ -- before the gateway sees it (`fivefold.harness.log.holds_nul`), and the store keeps each
9
+ -- value as `fivefold.gateway.codec.storable` makes it.
10
+ --
11
+ -- NOT NULL, with no default. A run database is migrated before its run starts, so every
12
+ -- database the repository migrates has no logged call yet when this file runs. The
13
+ -- arguments of calls logged before this file were never recorded, and an empty object
14
+ -- would say there were none, so a database whose `gw.tool_call` already holds rows
15
+ -- cannot take this file: PostgreSQL refuses a NOT NULL column with no default on a table
16
+ -- with rows, the file rolls back and the runner stops. Run databases are disposable
17
+ -- (0007); make a new one.
18
+
19
+ ALTER TABLE gw.tool_call
20
+ ADD COLUMN args jsonb NOT NULL CHECK (jsonb_typeof(args) = 'object');
@@ -0,0 +1,31 @@
1
+ -- The run registry (decision records 0009 and 0012).
2
+ --
3
+ -- The registry is a small database of its own, `fivefold_registry` unless the environment
4
+ -- variable FIVEFOLD_REGISTRY_DB names another, on the same server as the run databases.
5
+ -- It has one row per run database, so the viewer can list runs without opening each one.
6
+ -- The harness writes a run's row as the run starts, as role ff_registry; the viewer reads
7
+ -- the rows as role ff_viewer, which can only select. No other role has any privilege here.
8
+ --
9
+ -- A row is keyed by its database's name. A run id names a run's choices, and two
10
+ -- databases can hold runs with the same id: a recording and its replay, for example.
11
+ -- When a database is created again under its old name, as each demo's is, the harness
12
+ -- replaces the row; when a run database is dropped, the harness removes it.
13
+ -- `created_wall_at` is wall-clock time, for display only (0009).
14
+
15
+ CREATE SCHEMA registry;
16
+
17
+ GRANT USAGE ON SCHEMA registry TO ff_registry, ff_viewer;
18
+ ALTER DEFAULT PRIVILEGES IN SCHEMA registry
19
+ GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO ff_registry;
20
+ ALTER DEFAULT PRIVILEGES IN SCHEMA registry
21
+ GRANT SELECT ON TABLES TO ff_viewer;
22
+
23
+ CREATE TABLE registry.run (
24
+ database_name text PRIMARY KEY CHECK (database_name ~ '^[a-z_][a-z0-9_]{0,62}$'),
25
+ run_id text NOT NULL,
26
+ scenario_id text NOT NULL,
27
+ config text NOT NULL CHECK (config IN ('B0', 'G1', 'G2')),
28
+ contract text NOT NULL CHECK (contract IN ('C0', 'C1', 'C2', 'C3')),
29
+ seed bigint NOT NULL,
30
+ created_wall_at timestamptz NOT NULL DEFAULT now()
31
+ );