Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 132 additions & 16 deletions docs/FACTORY.md

Large diffs are not rendered by default.

197 changes: 197 additions & 0 deletions docs/FACTORY_AUTONOMY.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/architecture.declared.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
{"from": "syberlabs-eval", "to": "syberlabs-primitives"},
{"from": "syberlabs-eval", "to": "syberlabs-signing"},
{"from": "syberlabs-factory", "to": "syberlabs-build-thread"},
{"from": "syberlabs-factory", "to": "syberlabs-git"},
{"from": "syberlabs-factory", "to": "syberlabs-primitives"},
{"from": "syberlabs-factory", "to": "syberlabs-signing"},
{"from": "syberlabs-git", "to": "syberlabs-admission"},
Expand Down
1 change: 1 addition & 0 deletions spec/GAPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@ The schemas describe SyberWork as it behaves. They are not enforced at runtime e

63. **The GitHits pilot's example pacing and license reading rest on GitHits' documentation, not on observed traffic.** (1) The host paces `example` calls to one per 40 s per host (`syberlabs/githits_pace.py`, called by the launcher entry); GitHits' limit is per organization, so two hosts, or an operator's own `syberlabs githits example` (not paced), share the organization's budget without seeing each other's slots. (2) A loopback base URL is not paced unless `SYBERLABS_GITHITS_PACE_SECONDS` asks: a loopback proxy that forwards to GitHits would go unpaced. (3) Calls queued behind several others wait one interval each, so a Bash tool timeout shorter than the queue ends a call before it is sent, and the host then flags it `githits_unrecorded`. (4) The time file is plain text a process of the same user can rewrite; it paces cooperating processes and is no security boundary. (5) The license reading admits an example's `References`/`Sources` links by their `(SPDX)` and passes an example with neither code (a fenced, indented or HTML block) nor a source; inline code in prose is not read as code, and the three documented shapes (`complete`, `degraded`, `no_example` in the pinned OpenAPI document) are the only evidence of what real responses look like until the first live example is recorded. (6) The engineering smoke pins Claude Code 2.1.312 exactly because the host and the pilot VM run it; that version's flags were not re-checked here.
64. **The GitHits launcher fails closed before the network, and the treatment runs on a hooked API lane; neither is verified live, and other lookups on a `--bare` lane are still caught only after the fact.** The live canary of 2026-10-30 (Claude Code 2.1.312 on a Freestyle Linux VM) settled 56 (2): a `--settings` `PreToolUse` hook does not run under `--bare`, so `propose --claude-code --bare --githits` let the model run the launcher with no guard, and the client sent the lookup (`sent: true`) before the host stopped the run `provider_guard_inactive`. Now the launcher's entry sends nothing without claiming the hook's MAC-verified decision for its exact argv (`query_guard.claim_launch`; refused calls are recorded `status: unguarded`, `sent: false`), and `--githits` refuses `--bare` and runs on `--lane api-hooked` (the API key without `--bare`, a fresh `CLAUDE_CONFIG_DIR` and home per call, `--disable-slash-commands`; `docs/CLAUDE_CODE.md`). Not solved: (1) a decision is bound to the launcher's arguments (their SHA-256) and claimed once, not to a tool use id, which the launcher cannot see; a process holding the per-call key (a stdio MCP server, a shell under `--allow-code-tools-with-mcp`) can still sign a decision for its own arguments, as it could before; (2) the hook's words and the launcher's argv agree for plain words and quoted strings under a POSIX shell; a shell or platform that hands over different bytes (Git Bash's argument conversion to a Windows process, a non-UTF-8 byte) refuses a legitimate lookup (fail closed), which no live run has exercised; (3) WebSearch, WebFetch and `--mcp-config` (`mcp__githits__*`) lookups on a `--bare` lane have no pre-send gate: the hook does not run, so they still leave and are flagged `unguarded` afterwards; only `--githits` refuses `--bare`, and `api-hooked` or a login lane is where those tools are guarded; (4) `api-hooked` has run only against the stand-in `claude`: whether 2.1.312 with an empty config directory and home starts headless on `ANTHROPIC_API_KEY` (`apiKeySource`) and runs the hook is for its first live call, and the flags were read from 2.1.309's `--help` because 2.1.312's was not on the building machine; managed (policy) settings still load, `--setting-sources` has no value meaning `--settings` alone, `USERPROFILE` moves only on Windows, and the worktree's memory files (`CLAUDE.md`) are read in both arms, so the lane needs `--trusted-tree`; (5) the example license parser now reads any ATX or bold heading that names a source or reference ("## Source code" included) as a sources section and a fenced or indented block inside a blockquote as code, both of which can only drop more examples (fail closed); how often that drops a usable GitHits example is not measured; (6) the default deny-list (`SyberLabs`, `sykosyber`, `pypi:syberwork`, `deepwiki.com`, `deepwiki.org`) detects a fork of a SyberLabs repository only by its name (`githits.FORK_NAMES`) in a result's URL or a target, so a renamed fork, a vendored copy, or SyberLabs code mirrored under another name and site still passes, and no mirror or front-end other than DeepWiki is listed.
65. **The factory's goal gate is an owner signature, not yet a kernel approval; the candidate's process still shares memory with its recorder; the behavior-change label is per contract.** `factory-goal-gate` (2026-11-02, on the factory slice of #154) closes the slice's verification findings: `spec promote`, `canonize` and `retire` need a human actor and an approval that verifies (`factory approve` signs it with the owner's seed through the certificate module's Ed25519 and DSSE; `spec promote` verifies it under the owner key the ledger pins (`owner_key_set`; `factory owner`), never a key the caller names, resolves every `--verdict` to a ledger `review` that accepted the very variant on disk, refuses an approver who proposed or reviewed it, stores the approval under `approvals/` and cites its `approval_recorded` hash from the `spec_changed`); every artifact load checks the file against the digest the ledger recorded and `verify` covers artifacts, so an edited golden journal refuses the check instead of becoming its baseline; the candidate runs under `python -I` in a host-owned scratch directory, is never told the ledger's path, writes a journal sealed per record under a per-run key the parent holds, reports over a nonce-bound private pipe, and the parent reads the `end` record itself and refuses a journal with no end, a planted line or a mismatching report; `verify` recomputes the policy from the evidence and `signed: true` needs a verifying signature; reviewer independence is the provider family the command declared, not the caller's name, and an unrecorded family refuses; subprocess argv, cwd, socket addresses and the tests tail are scrubbed of credential shapes; the viewer builds its DOM with `textContent` and carries no payloads; ledger appends use the kernel journal's lock, fsync and torn-tail repair, and the projection rebuilds when the log moved; the tests check honours the contract's timeout, `full_suite` means the suite ran to completion, and a timed-out suite or recording has its process tree stopped; after the independent verification of #164 (2026-11-02), the candidate's process and the test suite run under the Build Thread's scrubbed environment without the host's signing seed or the check's `--seed-env` variable, a killed run's journal is not delivered, and `Approved` is constructible by `verify_approval` only. What remains: (1) the approval is the owner's signature over the spec's content digest, not an `approved` event on a kernel goal case, because the factory has no case to hang one on; the trust model is exactly this: promotion is bound to the owner key the ledger pins, not to the caller of the host CLI; the pin's bootstrap (`factory owner --public KEY`, or the first `--owner-public` on a ledger that pins none) is the one unsigned act, done by the operator by hand, so whoever pins first on an empty ledger owns it (a Class C act), after which only the pinned key approves (`owner_key_mismatch` otherwise, `owner_key_unset` before any pin) and only the pinned key rotates (`owner_key_rotation` otherwise); after the delta verification of the pin (2026-11-02, M3) the key is read through the ledger's verified lineage, not its newest `owner_key_set`: one bare bootstrap, then rotations whose `previous` is the key pinned before them and whose stored envelope verifies under it, so an appended pin, a rotation the pinned key did not sign, a stale `previous` or a malformed keyid fails `verify` and refuses the gate at `owner_key_lineage` with no fallback to an earlier key, `spec promote|canonize|retire` verify the ledger before the gate reads it, `factory check` verifies it again after the test suite and before attesting, and `set_owner_key` reads and appends under one lock; after the second delta verification (2026-11-02, M4: the rotation envelope named the two keys only, so an honest `A -> B` envelope replayed by an append after the owner rotated `B` away, given a ledger write and `B`'s seed) the envelope (`owner-key/v1`; a `v0` envelope is refused) is signed over the `seq` of the pin it replaces and the ledger head at signing, the walk checks both against the chain and refuses a `rotation_digest` cited twice (`owner_key_lineage: ... rotation replayed`), so an envelope verifies at the one position it was signed for and a seed the owner rotated away re-pins nothing by append; the pin is therefore as strong as the ledger's verified lineage, and the boundary that remains is (3), an attacker who rewrites the whole chain consistently from the rotation they want undone, which the deferred `tlog`/`witness` anchoring closes; the ledger event is the citation the consolidation's §1.2 asks for, the journal hash is not; (2) io observation runs in the candidate's process, so code there can reach `_factory_harness._CURRENT[-1]` and its key through `sys.modules` and write records the seal accepts, or call the recorder's own `__exit__`; the seal and the channel raise the cost of a forgery, they are not a sandbox, and the recommendation on the open owner question stands: evidence with a person in the path, not the auto class; (3) a candidate that learns the ledger's absolute path from the contract in its worktree can still write to it between the check's two verifications only by forging a consistent unkeyed chain and matching digests, which `verify` does not distinguish from an honest ledger across runs; the same rewrite is the only way left to re-pin a key the owner rotated away, since every rotation is bound to its position and none is accepted twice; anchoring the chain head in `tlog`/`witness` is the fix; (4) the behavior-change label is `--behavior-change` on the check's argv, per contract, not a field of the ticket; (5) `independence` reads the model the command declared, so a command that lies about its model passes as it does for `model_usage`; (6) `verify_journal` reads text, so a journal whose line endings were rewritten verifies by content while the ledger's byte digest refuses it, which is the intended division, and the approval likewise covers the spec's content digest (parsed, `history` excluded), so a re-serialized file is the same spec and an edit to the file's `history` after signing is not covered, the ledger's `spec_changed` events being the history of record; (7) before this packet the ledger had no cross-process lock (two commands on one home could fork the chain, detected by `append` but not prevented) and `docs/FACTORY.md` said 18 tests where the file defined 35; both are fixed here. The consolidation's other C1 items (`serves`, `mission_ref`, `done_when` on specs, mandatory `human_owner` on tickets, `promote` renamed `pass`, `tickets.py`, `codemap.py`) are not in this packet.
6 changes: 6 additions & 0 deletions syberlabs/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ def _stop(proc: subprocess.Popen) -> None:
proc.wait()


# The two routines another host-side runner reuses (the factory's harness and its tests runner), under public
# names: the scrubbed environment a check runs under, and the stop of a check's whole process tree.
scrubbed_environment = _environment
stop_tree = _stop


def run_check(argv: list[str], cwd: Path, env: dict, timeout: int, max_output: int, log: Path,
stdin: Path | None = None) -> dict:
"""Run one check. ``stdin`` is a file handed to the command's standard input; without one it reads nothing."""
Expand Down
10 changes: 10 additions & 0 deletions syberlabs/factory/attest.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ def policy(predicate: dict, *, require_tests: bool = False, mutation_threshold:
return {"promote": promote, "reasons": reasons}


GATE_PARAMETERS = ("require_tests", "mutation_threshold", "max_drift", "level")


def recompute(predicate: dict) -> dict:
"""The policy's result computed again from the predicate's evidence and gate, so a verifier compares
what the signer wrote under ``policy`` with what the evidence says. Unknown gate keys are ignored."""
gate = {k: v for k, v in (predicate.get("gate") or {}).items() if k in GATE_PARAMETERS}
return policy(predicate, **gate)


def sign(document: dict, seed: bytes) -> dict:
"""A one-signature DSSE envelope over the canonical statement. ``keyid`` is the public key, hex."""
return sign_dsse(PAYLOAD_TYPE, canonical(document).encode("utf-8"), seed)
Expand Down
Loading
Loading