geneseed 5.0.3 → 5.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +3 -3
- package/SHIPPED.md +2 -2
- package/adapters/claude-code/README.md +5 -1
- package/adapters/openclaude/README.md +3 -1
- package/adapters/opencode/plugins/geneseed-workflow.js +1 -1
- package/adapters/opencode/workflows/_runtime.js +1 -1
- package/bin/geneseed-cli.mjs +3 -0
- package/bin/geneseed-hook.mjs +10 -2
- package/docs/PRD.md +1 -1
- package/docs/README.md +4 -1
- package/docs/concepts/enforcement-table.md +1 -1
- package/docs/concepts/exclusions.md +1 -1
- package/docs/concepts/factories.md +151 -0
- package/docs/concepts/hooks.md +1 -1
- package/docs/concepts/host-matrix.md +1 -0
- package/docs/concepts/loop-gates.md +3 -0
- package/docs/concepts/loops.md +1 -0
- package/docs/concepts/rules.md +1 -1
- package/docs/extending.md +5 -1
- package/docs/guides/autostart.md +2 -0
- package/docs/guides/run-a-factory.md +88 -0
- package/docs/guides/set-up-ownership.md +1 -0
- package/docs/reference/factory-actions.md +22 -0
- package/docs/reference/loop-actions.md +1 -1
- package/docs/reference/plugin-activity.md +1 -1
- package/docs/web-ui.md +35 -2
- package/harness.config.json +1 -1
- package/js/README.md +20 -2
- package/js/build/args.mjs +14 -2
- package/js/build/source.mjs +19 -0
- package/js/cli-table.json +166 -2
- package/js/factory/cli.mjs +153 -0
- package/js/factory/graph.mjs +245 -0
- package/js/factory/registry.mjs +71 -0
- package/js/factory/state.mjs +429 -0
- package/js/hosts/activity.mjs +3 -3
- package/js/hosts/geneseed-dir.mjs +1 -1
- package/js/hosts/gitref.mjs +21 -0
- package/js/hosts/hooks-context.mjs +63 -9
- package/js/hosts/hooks-prims.mjs +1 -1
- package/js/hosts/settings.mjs +5 -4
- package/js/inspect/checks-authoring.mjs +11 -1
- package/js/inspect/cost.mjs +91 -5
- package/js/inspect/doctor.mjs +2 -1
- package/js/inspect/inventory.mjs +1 -1
- package/js/loop/catalog.mjs +24 -12
- package/js/loop/cli.mjs +21 -15
- package/js/loop/graph.mjs +13 -4
- package/js/loop/registry.mjs +65 -28
- package/js/loop/state.mjs +18 -8
- package/js/web/api.mjs +43 -1
- package/js/web/catalog.mjs +38 -2
- package/js/web/daemon.mjs +136 -6
- package/js/web/handler.mjs +14 -5
- package/js/web/routes.mjs +10 -3
- package/js/web/server.mjs +4 -1
- package/package.json +1 -1
- package/registry.json +14 -0
- package/src/AGENT.md.tmpl +5 -7
- package/src/bricks/docs-update.md +5 -0
- package/src/bricks/holdout-write.md +23 -0
- package/src/bricks/holdout.md +25 -0
- package/src/bricks/intake.md +18 -0
- package/src/bricks/merge-gate.md +22 -0
- package/src/bricks/pr-open.md +21 -0
- package/src/bricks/retro.md +17 -0
- package/src/bricks/test.md +4 -1
- package/src/bricks/triage.md +19 -0
- package/src/doctrines/comms.md +29 -41
- package/src/doctrines/craft.md +3 -10
- package/src/doctrines/ops.md +4 -15
- package/src/doctrines/rigor.md +1 -5
- package/src/factories/analysis-to-build.json +34 -0
- package/src/factories/bug-report-to-fix.json +32 -0
- package/src/factories/issue-to-pr.json +49 -0
- package/src/skills/_checkpoints.md +1 -0
- package/src/skills/adhd.md +1 -1
- package/src/skills/factory-forge.md +97 -0
- package/src/skills/factory.md +126 -0
- package/src/skills/parallel-agents.md +1 -1
- package/src/skills/workflow.md +2 -1
- package/themes/_TEMPLATE.json +4 -2
- package/themes/biker.json +4 -2
- package/themes/commentator.json +4 -2
- package/themes/cyberpunk.json +4 -2
- package/themes/gamer.json +4 -2
- package/themes/imperial.json +4 -2
- package/themes/joker.json +4 -2
- package/themes/marvin.json +4 -2
- package/themes/mean.json +4 -2
- package/themes/military.json +4 -2
- package/themes/neutral.json +4 -2
- package/themes/pirate.json +4 -2
- package/themes/sports.json +4 -2
- package/themes/verstappen.json +4 -2
- package/themes/wizard.json +4 -2
- package/web/dist/assets/ActiveLoops-BTHIaRhn.js +1 -0
- package/web/dist/assets/{Activity-Ck_Xffpo.js → Activity-BaoxwVFH.js} +1 -1
- package/web/dist/assets/{ActivityDetail-CBxVS4mU.js → ActivityDetail-C_bFD0rW.js} +1 -1
- package/web/dist/assets/{Bonsai-BlOwsvW6.js → Bonsai-B01lLf0m.js} +1 -1
- package/web/dist/assets/{CopyButton-DFMOIGbe.js → CopyButton-Bc66KPyA.js} +1 -1
- package/web/dist/assets/Dashboard-X7GZzGJp.js +2 -0
- package/web/dist/assets/{Docs-D_2Jt6gU.js → Docs-LRYVnGLG.js} +2 -2
- package/web/dist/assets/Factories-ARenKBiP.js +1 -0
- package/web/dist/assets/{GreenhouseView-WalcX5bp.js → GreenhouseView-CfWR2-sX.js} +1 -1
- package/web/dist/assets/{Installs-UGiPDMDt.js → Installs-nfFHnovH.js} +3 -3
- package/web/dist/assets/{JournalView-CZtXQz-v.js → JournalView-lpOHcHKK.js} +1 -1
- package/web/dist/assets/{Kits-XQHsazCN.js → Kits-Bw5EQl_i.js} +1 -1
- package/web/dist/assets/Laws-CnZJ0wjZ.js +4 -0
- package/web/dist/assets/LibRows-Hqvf1beK.js +1 -0
- package/web/dist/assets/Library-JaSsp6Yr.js +3 -0
- package/web/dist/assets/Loops-ZaHC5MVl.js +2 -0
- package/web/dist/assets/{OperatorHudView-CeDw5qMB.js → OperatorHudView-CggG0_sK.js} +1 -1
- package/web/dist/assets/{Personal-PVmGA2-M.js → Personal-BObvlb70.js} +2 -2
- package/web/dist/assets/{Settings-DWuxwh4i.js → Settings-BFfPMPc9.js} +1 -1
- package/web/dist/assets/{Tabs-d2RIRAKT.js → Tabs-B594Pad_.js} +1 -1
- package/web/dist/assets/api-DLDVY3K-.js +1 -0
- package/web/dist/assets/{index-BNttaGQb.js → index-DsLmKHw0.js} +3 -3
- package/web/dist/assets/index-DvPjphz0.css +1 -0
- package/web/dist/index.html +3 -3
- package/web/dist/assets/Dashboard-BUdUTjbB.js +0 -2
- package/web/dist/assets/Laws-B6A55S-2.js +0 -4
- package/web/dist/assets/Library-D7L0Wdbh.js +0 -3
- package/web/dist/assets/Loops-C0loS73u.js +0 -2
- package/web/dist/assets/RailCats-BGZnJ6fa.js +0 -1
- package/web/dist/assets/api-BMFDSXoB.js +0 -1
- package/web/dist/assets/index-BEI5ugYQ.css +0 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
group: reference
|
|
3
|
+
order: 2.5
|
|
4
|
+
title: "Factory actions"
|
|
5
|
+
kind: "concept"
|
|
6
|
+
section: "CLI & environment"
|
|
7
|
+
description: "The geneseed factory actions, one line each."
|
|
8
|
+
---
|
|
9
|
+
The actions of `geneseed factory`, the state machine that carries one work item through a graph of stages to an open PR. A stage is a brick or a whole loop (`loop:<template>`). A **fork** is a brick that declares a named outcome (one other than `pass`, `fail`, `error` or `none`), each outcome with its own edge to its own lane. An edge target or a cycle node may be `$lane`: the stage the run's most recent fork chose. The run state lives in `FACTORY.md` at the worktree root, beside the child loop's `LOOP.md` ([Loop actions](loop-actions.md)). Each action prints one JSON object and exits 1 on a refusal.
|
|
10
|
+
|
|
11
|
+
| action | what it does |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `check` | checks every factory in the catalogue, or one factory (`--factory <name or .json file>`): the factory has a name and no stage twice, every stage exists, every outcome has one edge, `$close` is reachable, every cycle is declared with a `max` from 1 to 5, each cycle is entered only at its first stage, and every route back targets the first stage of a cycle that holds its source. `$lane` needs a fork on every path to it, and a fork's own edge never targets it. In those checks, `$lane` stands for every lane of every fork. A factory that still uses the retired `loop:$triaged` stage or `loops` list gets a problem that names the replacement; nothing rewrites the file |
|
|
14
|
+
| `list` | lists the factories of the three origins (shipped, global, project), with description, category and origin |
|
|
15
|
+
| `init` | writes a fresh `FACTORY.md` from a factory, under a title, a requirement and an optional `--input` (an issue URL, a file path or pasted text). A factory that fails `check` is refused before any stage runs. Each `init` also registers the run in `factories.json`, beside the loop registry |
|
|
16
|
+
| `next` | returns the next thing to do: run a brick stage, run a loop (with `notes` to start it with, and the `task` when a spec set tasks: the spec's `path`, the task `count` and this task's `index`), answer an `awaiting` gate, or a terminal. A fork stage also gets `lanes`: each outcome it may report, with the stage it leads to. Refused while a `LOOP.md` exists that is not `done` or `stopped` (an unreadable one counts as running): the child loop finishes first. On a loop stage, refused while any `LOOP.md` is left: `git rm -f LOOP.md` and commit that removal before `geneseed loop init`. On a loop stage, `next` also records the launch in `FACTORY.md`: the loop template, the HEAD commit and the time. When a later stage routes back to the loop stage that ran the tasks, after its last task passed (red CI at `merge-gate`, or a failed `holdout`), `next` hands out one extra task: the last `index` again, with `extra` set to the stage and outcome that sent it back (`"merge-gate reported fail"`). That lap spends the route's cycle and the transition ceilings like any other, and gives no fresh budget |
|
|
17
|
+
| `record` | records the current stage's outcome and follows its edge. A loop stage reports `pass` (its loop closed) or `fail` (it stopped), and only after `next` launched it. While its `LOOP.md` is still there, that file must name the stage's template, a `stopped` one admits only `fail`, and a `done` one only `pass`. With no `LOOP.md` left, `pass` and `fail` both need a HEAD that moved since `next`: the loop's close commit, or the commit that removes a stopped loop's `LOOP.md`. That is enough for `fail`. `pass` also needs the loop registry to show a `geneseed loop init` in this worktree after `next`. Without it, `pass` is refused: record it while the `done` `LOOP.md` is still at the root, or report `fail`. The registry does not keep a loop's final status, so a stopped loop whose `LOOP.md` was removed by hand can still pass. `--carry` hands a reason to the next stage; a re-entered loop starts with it as a note. On a fork, the outcome names the lane: the stage its edge reaches is stored as the run's `lane`, and an edge to `$lane` goes there. A route to `$lane` with no lane on record is refused. `--spec <path>` records a spec inside the worktree: the first loop stage recorded after it runs once per numbered item under its first `Tasks` heading, 20 at most. The count is frozen at the first `--spec`: a later one may keep or lower it, never raise it. After a stage outside a loop, pipe `git status --porcelain --untracked-files=all` on stdin. Plain `--porcelain` shows a new directory as one line (`?? specs/`), so a new spec is refused. The tree must be clean (a `mutate` brick such as a `docs-update` lane commits its change first), with two exceptions: engine files, and the run's spec at `specs/<slug>/spec.md` (the one recorded now, else the one on record). No stdin at all (a terminal) is refused. An empty pipe reads as a clean tree. Refused, as `next` is, while a child loop owns the worktree. Every state action also refuses a `FACTORY.md` that does not parse, or one that holds any of these: counters that are not non-negative integers, a run-wide ceiling above 600, a gate amend count above 3, a `lane` that no fork of the factory leads to, an unknown status, a `history` or `cycles` that is not a list, or a factory that no longer passes `check` |
|
|
18
|
+
| `decide` | answers a held `gate: human` stage: `ok` follows the edge (an edge to `$lane` goes to the lane on record), `no` stops, `amend` re-runs the stage with the `--note` as its carry (three times at most) |
|
|
19
|
+
|
|
20
|
+
A route back into a cycle spends the cycle whose first stage is the route's target; past its `max` the run stops. A run stops too after 30 stage transitions, counted again for each spec task the run reaches for the first time, and after 30 transitions per task of the first recorded spec (30 without a spec) over the whole run. That run-wide ceiling is set once and never changes.
|
|
21
|
+
|
|
22
|
+
Run `geneseed factory --help` for the full flag list.
|
|
@@ -11,7 +11,7 @@ The actions of `geneseed loop`, the state machine behind [Loops](../concepts/loo
|
|
|
11
11
|
| action | what it does |
|
|
12
12
|
|---|---|
|
|
13
13
|
| `check` | lists templates and every brick (available, unavailable, overridden); validates one graph file (`--graph`) or one brick file (`--brick`) |
|
|
14
|
-
| `init` | writes a fresh `LOOP.md` from a template or graph file, under a title, requirement and trust preset |
|
|
14
|
+
| `init` | writes a fresh `LOOP.md` from a template or graph file, under a title, requirement and trust preset; `--note` or `--note-file <path>` gives the loop the note it starts with (a factory hands its carry here). Each `init` also stamps the worktree's row in the loop registry with the time, which `geneseed factory record` reads ([Factory actions](factory-actions.md)); `--factory <slug>` stores on that row the factory run this loop is a stage of |
|
|
15
15
|
| `next` | the only driver of the cycle — returns the next thing to do: run a node, score a card, answer an `awaiting`, or a terminal |
|
|
16
16
|
| `score` | scores a declared card (`--declared`) before a mutate node runs, or the real diff (`--diff`, numstat piped on stdin) before a commit |
|
|
17
17
|
| `record` | records a brick's reported outcome and advances the graph; `--note` or `--note-file <path>` carries a finding into `LOOP.md`'s notes for the bricks after it: a plan survives the unit, and `review` and `mutation-check` findings last until `apply` reports. `test` cannot report `pass` when that note lists a check as `SKIPPED`: the record is refused and `LOOP.md` does not change |
|
|
@@ -12,7 +12,7 @@ One of the [OpenCode plugins](opencode-plugins.md). [Environment variables](envi
|
|
|
12
12
|
|
|
13
13
|
**When it runs.** On session events. A sub-agent's child session (one with a `parentID`) is folded into its root session: it becomes an `agents[]` row (`{id, type, status: "running" | "done"}`, the child's id and agent), and its files join the root's `files` with `by` set to the child's id. Only learn's throwaway `geneseed-*` sessions are skipped. On OpenCode 2 the files come from `session.step.ended`, which carries no line counts, so those read `null`. A session whose process died, went stale (30 minutes untouched) or ended leaves the live list and is listed as ended; the reader never deletes a file.
|
|
14
14
|
|
|
15
|
-
**Claude Code, OpenClaude and Bob.** Their hooks write the same files into `activity/` beside the install (`~/.claude/activity/`, `<repo>/.claude/activity/`, `~/.bob/activity/`). No hook is added per tool call: the writer runs after the hooks that already run — the gates, `context` and `learn` — plus `geneseed-hook activity` on `UserPromptSubmit` and, on Claude Code and OpenClaude, `SessionEnd`
|
|
15
|
+
**Claude Code, OpenClaude and Bob.** Their hooks write the same files into `activity/` beside the install (`~/.claude/activity/`, `<repo>/.claude/activity/`, `~/.bob/activity/`). No hook is added per tool call: the writer runs after the hooks that already run — the gates, `context` and `learn` — plus `geneseed-hook activity` on `UserPromptSubmit` and, on Claude Code and OpenClaude, `SessionEnd` (their `SubagentStart` runs `context`, which records the same way). So a Claude session's phase moves on the gated tools (`Bash`, `PowerShell`, `Write`, `Edit`, `NotebookEdit`, `Skill`, `Agent`, `Task`), and the rest of the turn — every tool call, the model, the token totals, the last reply — arrives at `Stop`, read from the transcript where the previous `Stop` left off (at most 2 MB per turn). Bob sends no transcript, so a Bob session shows only the calls its `tool-gate` sees, and leaves the live list by staleness alone (Bob has no `SessionEnd`). Bob's `SessionStart` is recorded only after a compaction (`source: "compact"`, counted as one): a startup or resume fires just before the first prompt, which records the session anyway. Bob 2.2.3 writes every hook's payload to stdin and closes it, so reading it there is safe. These writers have no resident process, so their snapshots carry `pid: null` and stay live by staleness alone. Recorded: tool names, each changed file's path relative to the session's git root (a file outside the root, or a session outside any repo, keeps its basename only; a path is never stored absolute; labels show basenames), who changed it (the session or a subagent's `agent_id`), the subagents, the prompt count, the context size and the compactions, line counts, todo text, and 240-character snippets of the prompt and the last reply — never a shell command, a file's content or an edit's text — and any credential the secrets gate would catch in a snippet is written as `[redacted]`. A project install's `activity/` gets its own `.gitignore` (`*`), and the writer never writes through, or sweeps, an `activity/` or `activity/archive/` that is a link. Nothing is recorded in a repo listed in `excludes.json`, or inside a model CLI that `learn` started.
|
|
16
16
|
|
|
17
17
|
**Archive.** On `SessionStart` and `SessionEnd` the hook writer moves every snapshot that is no longer live into `activity/archive/`, keeping the newest 50 and none older than 7 days. `/api/activity` returns them, with the stale and dead ones still in `activity/`, in its `ended` list — capped there by the same rule, since the OpenCode plugin never sweeps.
|
|
18
18
|
|
package/docs/web-ui.md
CHANGED
|
@@ -70,7 +70,7 @@ Every `/api/*` read takes and checks the pair, with these exceptions:
|
|
|
70
70
|
- `/api/ping` and `/api/jobs` ignore it.
|
|
71
71
|
- The machine-wide reads also ignore it: `/api/update`, `/api/installs`, `/api/fleet`, `/api/migrate/preview`,
|
|
72
72
|
`/api/kits`, `/api/usage`, `/api/gates`, `/api/excludes`, `/api/mcp`, `/api/loops/active`,
|
|
73
|
-
`/api/activity`, and the Library's skill, agent, memory and notebook lists,
|
|
73
|
+
`/api/factories/active`, `/api/activity`, and the Library's skill, agent, memory and notebook lists,
|
|
74
74
|
`/api/catalog/skills`, `/api/catalog/agents`, `/api/catalog/memory` and
|
|
75
75
|
`/api/catalog/notebook`. Such a read does not check the pair, and its answer does not change
|
|
76
76
|
with the pair. The Activity detail (`/api/activity/<id>`) and the Activity toggle still take
|
|
@@ -91,6 +91,15 @@ it. The order is the host order (OpenCode, Claude Code, Bob, OpenClaude), then g
|
|
|
91
91
|
project. The item's `install` field names the copy, and its `installs` field names every
|
|
92
92
|
install that has the id.
|
|
93
93
|
|
|
94
|
+
Agents opens on a pinned row for the **primary agent** (the theme's `PRIMARY_AGENT` noun), with a
|
|
95
|
+
**base** pill: every agent inherits its root file. Each agent's detail, the primary's included,
|
|
96
|
+
shows a **Loadout** panel: what the agent loads, block by block (the root file by section, the
|
|
97
|
+
session files or, for a sub-agent, your user rules, both catalogues, the Adept's spec), and the
|
|
98
|
+
rules it follows, marked where its spec cites them. `GET /api/loadout` (the primary) and
|
|
99
|
+
`/api/loadout/<agent>` serve it, install-scoped like `/api/item/`; the figures are the same
|
|
100
|
+
measurements as the Overview's always-on cost. The project root's own `user-rules.md` is not
|
|
101
|
+
counted, because it depends on the session's working directory.
|
|
102
|
+
|
|
94
103
|
A request that names no install reads the **default install**: the one you chose on the Installs
|
|
95
104
|
page (*Make default* on an active row), while it stays active. With no choice, it is the first
|
|
96
105
|
active one in the console's one install order (`fleetSort`): host order (opencode, claude, bob,
|
|
@@ -143,7 +152,7 @@ before its data. The Constitution waits for the picked install's own overview to
|
|
|
143
152
|
before it would read as armed.
|
|
144
153
|
|
|
145
154
|
The rail groups its pages under small mono headers, each with a square in the group's tint: the
|
|
146
|
-
Overview alone, then **Govern** (Constitution, Personal), **Build** (Library, Kits, Loops), **Run**
|
|
155
|
+
Overview alone, then **Govern** (Constitution, Personal), **Build** (Library, Kits, Loops, Factories), **Run**
|
|
147
156
|
(Installs, Activity) and **Help** (Docs, Settings). Each icon sits in a 28 px chip tinted by its group
|
|
148
157
|
(`--sb-<group>-bg` and `-ink` in `styles.css`; light mode has pastel chips with deep ink, 5.3:1 or
|
|
149
158
|
better). The lit page gets a raised row and `aria-current="page"`; a count badge is muted mono on the
|
|
@@ -338,6 +347,30 @@ screen the run list stacks above the detail.
|
|
|
338
347
|
the page's only write), what an awaiting loop waits on (launch / declared / actual / a
|
|
339
348
|
human gate, with its node) — the answer is given in the agent's session, never here — and
|
|
340
349
|
its ring with the current node filled, with its iteration history under it.
|
|
350
|
+
- **Factories** (`#/factories`) — the factory catalogue `geneseed factory` runs from, read-only,
|
|
351
|
+
in the Loops page's three panes with two sections. **Templates** are grouped by origin; the
|
|
352
|
+
reader draws the selected factory as a vertical graph (`web/src/lib/factoryFlow.js`): each
|
|
353
|
+
stage on the row of its longest path from `start`, top to bottom, joined by lines; a brick a
|
|
354
|
+
grey block, a fork amber, a `loop:` stage on the main path a teal block holding its loop's
|
|
355
|
+
ring. The targets of a fork share a row, side by side, each lane labelled with its outcome,
|
|
356
|
+
and join again at the first stage every lane reaches. Each route back (an edge into a cycle's
|
|
357
|
+
first stage, the edge that spends a lap, `$lane` included) is a rail on the left labelled
|
|
358
|
+
`↺ <cycle> · max N`, the smallest cycle that holds it; every stop edge on the main path runs
|
|
359
|
+
into one rail on the right, ending at the `stop` cap, and a lane's own stop edge is a
|
|
360
|
+
`fail → stop` tag under its box. A `gate: human` brick wears the
|
|
361
|
+
person badge. The graph never scrolls sideways: it fits its pane. Lanes side by side come
|
|
362
|
+
first; when the rails do not fit, they become tags under the stage they leave, and the lanes
|
|
363
|
+
shrink to compact boxes (named without `loop:`). Only when even those do not fit (below about
|
|
364
|
+
524 px for five lanes) do the lanes stack as a list. Under it: a legend, the cycles in
|
|
365
|
+
words, the `geneseed factory init` command with a Copy button, and the
|
|
366
|
+
factory's rules. It reads `GET /api/factories/catalog` for the install the *Install:* picker
|
|
367
|
+
names. **Active** is every run `geneseed factory init` registered on this machine
|
|
368
|
+
(`GET /api/factories/active`, polled every 5 s, the graph read from each run's `FACTORY.md`),
|
|
369
|
+
grouped as Loops › Active is; the reader shows the run's stage, transitions, task number, its
|
|
370
|
+
child loop's step and iteration, what it awaits, and its graph with the current stage lit,
|
|
371
|
+
the lane its last fork took (the run's `lane`, else read from its `history`) lit, the child loop's node lit in
|
|
372
|
+
the stage's ring and each cycle's laps as `n / max`. No run
|
|
373
|
+
reports tab: a run's report lives in its own worktree.
|
|
341
374
|
- **Profile** (`#/profile`) — `PROFILE.md`: who you are and how you like to work, one card
|
|
342
375
|
per file: the shared one every global install reads, tagged `shared`, and each project
|
|
343
376
|
install's own. Opens rendered; **Edit** is a whole-file editor. The save carries
|
package/harness.config.json
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
"_comment": "version is a human-readable release label only; the canonical identity of an installed harness is the source fingerprint stamped in .geneseed-version (see `harness version`), not this string.",
|
|
3
3
|
"theme": "neutral",
|
|
4
4
|
"product": "Geneseed",
|
|
5
|
-
"version": "5.0.
|
|
5
|
+
"version": "5.0.4"
|
|
6
6
|
}
|
package/js/README.md
CHANGED
|
@@ -21,6 +21,7 @@ js/hosts/ where it stops being a renderer and touches the machine
|
|
|
21
21
|
js/inspect/ the read-only half: doctor, status, diff, validate, catalog
|
|
22
22
|
js/lib/ primitives, every one a deliberate divergence from the Node default
|
|
23
23
|
js/loop/ `geneseed loop` — the state machine over LOOP.md, and what it steps through
|
|
24
|
+
js/factory/ `geneseed factory` — the state machine over FACTORY.md, one level above loops
|
|
24
25
|
js/maintain/ lifecycle verbs that change an install that already exists
|
|
25
26
|
js/ui/ what it prints at a terminal
|
|
26
27
|
js/web/ the `geneseed web` console
|
|
@@ -103,7 +104,7 @@ user co-owns, and the hook verbs those emitted configs then run.
|
|
|
103
104
|
| `usage.mjs` | The usage counter `tool-gate` runs: one `{day, kind, name}` line per Skill or subagent call into `notebook/usage.jsonl`. Hook path: builtins only, silent, never throws |
|
|
104
105
|
| `memory-files.mjs` | The memory store's file format — `frontmatter`, `MEMORY.md` index writes, agent lessons, consolidate — the `user-rules.md` parser, the draft's format and the fold's ledger reader. No spawn: the CLI, web console and fold import it |
|
|
105
106
|
| `geneseed-dir.mjs` | The Node writers into a project's `<git root>/.geneseed/`: the personal-by-default `.gitignore` (`GENESEED_GITIGNORE`, pinned to the two OpenCode copies), and the protected-checks seed every project emit runs (`seedProtectedChecks`: seed once when absent, then the user's — never recorded, rewritten or uninstalled). Never throws, never writes through a link. Spawn-free |
|
|
106
|
-
| `gitref.mjs` | fs/path-only: `gitRootOf`, `gitDirOf`, `gitCommonDirOf`, `currentBranch`, `protectedBranches`, `stashExists`, `loopLaunched` — read straight off `.git`, never spawn git. Shared by `hooks.mjs`'s git-gate, `loss.mjs` and `js/loop/cli.mjs`'s commit-message writer |
|
|
107
|
+
| `gitref.mjs` | fs/path-only: `gitRootOf`, `gitDirOf`, `gitCommonDirOf`, `currentBranch`, `protectedBranches`, `stashExists`, `loopLaunched`, `headCommit` — read straight off `.git`, never spawn git. Shared by `hooks.mjs`'s git-gate, `loss.mjs` and `js/loop/cli.mjs`'s commit-message writer; `headCommit` by `js/factory/cli.mjs` (R2) |
|
|
107
108
|
| `loss.mjs` | Law IV calibrated to real loss: `lossReason` decides whether a command would really lose data (protected branch, unpushed branch, dirty tree, stash, reflog, files git cannot restore) and fails closed. The gate path's one `git` spawn, reached only after `LOSS_CANDIDATE_RE` matched. Twin: the OpenCode guard plugin |
|
|
108
109
|
| `settings.mjs` | Merges into user-owned `settings.json`/`opencode.json` (one `loadJsonObject` reader for all of them) and the managed blocks |
|
|
109
110
|
| `shim.mjs` | The machine-wide hook shim: its path, body, liveness (`shimDead`, read on every CLI run), `hookPrefix`/`hookRunnerEntry`; and the web console's login launcher (`autostartState`/`autostartInstall`/`autostartRemove`). Kept cheap to import |
|
|
@@ -185,7 +186,7 @@ transition, score and stop is computed here.
|
|
|
185
186
|
|---|---|
|
|
186
187
|
| `graph.mjs` | `checkGraph` — the rules a loop graph must satisfy before a node runs: nodes name real bricks, edges cover every outcome, `$close` is reachable, every cycle is inside a declared loop |
|
|
187
188
|
| `score.mjs` | The risk arithmetic: `WEIGHTS`, `PRESETS`, `declaredRisk`/`actualRisk`/`decide`, `parseNumstat`. Pure — no import but node builtins |
|
|
188
|
-
| `catalog.mjs` | `loadCatalog` — bricks
|
|
189
|
+
| `catalog.mjs` | `loadCatalog` — bricks, loop templates and factories from shipped/global/project origins, later overrides earlier BY NAME |
|
|
189
190
|
| `state.mjs` | The engine itself: `initState`, `nextStep`, `scoreDeclared`/`scoreDiff`, `recordOutcome`, `decideAwaiting`, `renderLoopFile`/`parseLoopFile` |
|
|
190
191
|
| `cli.mjs` | `geneseed loop check\|init\|next\|score\|record\|decide` — the only face either a model or a human reaches this engine through |
|
|
191
192
|
| `registry.mjs` | `loops.json` under XDG — the launched-loop identity list `loop init` records into and the Active tab's `activeLoops`/`setLoopPreset` read and rewrite |
|
|
@@ -203,6 +204,23 @@ fails. `activeLoops` saves the registry back only when the kept set actually cha
|
|
|
203
204
|
root, a loop newly seen finished or seen running again) — a routine poll from the Active tab must
|
|
204
205
|
never be a write.
|
|
205
206
|
|
|
207
|
+
## `js/factory/` — the factory engine
|
|
208
|
+
|
|
209
|
+
`geneseed factory` — the loop engine one level up: a state machine over a graph of stages (a
|
|
210
|
+
brick or a whole loop; a fork's named outcomes pick its lane), persisted as a JSON block in
|
|
211
|
+
`FACTORY.md` beside `LOOP.md`. A child loop runs through `js/loop/` unchanged.
|
|
212
|
+
|
|
213
|
+
| module | owns |
|
|
214
|
+
|---|---|
|
|
215
|
+
| `graph.mjs` | `checkFactory` — the rules a factory must satisfy before a stage runs: stages exist, edges cover every outcome, `$close` is reachable, every cycle is declared (the loop engine's `undeclaredCycles`), `$lane` only behind a fork. Also the fork helpers the engine shares: `isFork`, `lanesOf`, `laneTargets`, `spentCycle` |
|
|
216
|
+
| `state.mjs` | The engine itself: `initFactory`, `nextStage`, `recordStage`, `decideFactory`, `renderFactoryFile`/`parseFactoryFile`, `validateFactoryState`, `countSpecTasks` |
|
|
217
|
+
| `cli.mjs` | `geneseed factory check\|list\|init\|next\|record\|decide` — the only face of this engine |
|
|
218
|
+
| `registry.mjs` | `factories.json` beside `loops.json`: `recordFactory` (called by `factory init`) and `activeFactories`, on the loop registry's own `loadRows`/`saveRows`/`sweepRows`. A run and its child loop share a root, which is how a reader groups them |
|
|
219
|
+
|
|
220
|
+
**Before editing:** `FACTORY.md` is in `js/loop/state.mjs`'s `ENGINE_FILES`, so a child loop never
|
|
221
|
+
scores it; the clean-tree check after a stage outside a loop filters with that same list. `cli.mjs`
|
|
222
|
+
may not spawn, and refuses `next`/`record` while a `LOOP.md` exists at the root.
|
|
223
|
+
|
|
206
224
|
## `js/maintain/` — lifecycle
|
|
207
225
|
|
|
208
226
|
Verbs that change an install that already exists, as opposed to rendering one.
|
package/js/build/args.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { withPlatformNewlines } from '../lib/fs.mjs';
|
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import {
|
|
14
14
|
CONFIG, discoverNames, GATE_SWITCHES, PACK_ORDER, SRC, knownRuleIds, knownSkillIds, linkedSkillIds, loadKits,
|
|
15
|
-
resolveSkillNames, skillAliases,
|
|
15
|
+
resolveSkillNames, retiredRuleAddresses, skillAliases,
|
|
16
16
|
} from './source.mjs';
|
|
17
17
|
// The loop engine's trust presets — the `--trust` choices. `score.mjs` imports nothing, which is
|
|
18
18
|
// what lets it sit inside this module's `child_process` ban.
|
|
@@ -67,8 +67,12 @@ export function configDefaults() {
|
|
|
67
67
|
// as a flag, and `parseExcludeRules` dies on it — every rebuild of that install,
|
|
68
68
|
// forever. Unknown ids are dropped with a WARN; the known ones still bind.
|
|
69
69
|
const known = knownRuleIds();
|
|
70
|
+
const retired = retiredRuleAddresses(known);
|
|
70
71
|
const ids = data.excludeRules.map((x) => x.trim().replace(/[ \t]+/, '.'));
|
|
71
|
-
const
|
|
72
|
+
for (const id of ids.filter((x) => retired.has(x))) {
|
|
73
|
+
warnRetiredRule(id, retired, `${path.basename(CONFIG)} "excludeRules"`);
|
|
74
|
+
}
|
|
75
|
+
const unknown = ids.filter((id) => !known.includes(id) && !retired.has(id));
|
|
72
76
|
if (unknown.length) {
|
|
73
77
|
process.stderr.write(`[geneseed] WARN: ${path.basename(CONFIG)} "excludeRules" names `
|
|
74
78
|
+ `unknown rule(s) ${unknown.map((id) => `'${id.replace('.', ' ')}'`).join(', ')}`
|
|
@@ -174,9 +178,11 @@ function parseExcludeRules(value) {
|
|
|
174
178
|
const s = value.trim();
|
|
175
179
|
if (s === 'none' || s === '') return [];
|
|
176
180
|
const known = knownRuleIds();
|
|
181
|
+
const retired = retiredRuleAddresses(known);
|
|
177
182
|
const out = [];
|
|
178
183
|
for (const raw of s.split(',').map((x) => x.trim()).filter(Boolean)) {
|
|
179
184
|
const id = raw.replace(/[ \t]+/, '.');
|
|
185
|
+
if (retired.has(id)) { warnRetiredRule(id, retired, '--exclude-rules'); continue; }
|
|
180
186
|
if (!known.includes(id)) {
|
|
181
187
|
die(2, `argument --exclude-rules: invalid choice: '${raw}' (choose from `
|
|
182
188
|
+ `${known.map((c) => `'${c.replace('.', ' ')}'`).join(', ')}, or 'none')`);
|
|
@@ -186,6 +192,12 @@ function parseExcludeRules(value) {
|
|
|
186
192
|
return [...new Set(out)].sort();
|
|
187
193
|
}
|
|
188
194
|
|
|
195
|
+
/** One stderr line for a retired address: it excludes nothing now, and the build goes on. */
|
|
196
|
+
function warnRetiredRule(id, retired, where) {
|
|
197
|
+
process.stderr.write(`[geneseed] WARN: ${where}: '${id.replace('.', ' ')}' was retired `
|
|
198
|
+
+ `(${retired.get(id)}) — ignoring it.\n`);
|
|
199
|
+
}
|
|
200
|
+
|
|
189
201
|
/**
|
|
190
202
|
* `--exclude-skills "bruno,openscad"` -> the cfg's skill exclusion array.
|
|
191
203
|
*
|
package/js/build/source.mjs
CHANGED
|
@@ -88,6 +88,8 @@ export const RULE_ID_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
|
88
88
|
export const RETIRED_RULE_IDS = {
|
|
89
89
|
'external-gate': { was: 'Law IX', liveAs: 'DOCTRINE', note: 'moved to the rigor pack' },
|
|
90
90
|
'absence-is-a-claim': { was: 'Law XI', liveAs: null, note: 'folded into verify-before-asserting' },
|
|
91
|
+
// 2026-11-08: both rules set the reply format and shared one example, so one rule now holds both.
|
|
92
|
+
'mark-the-ask': { was: 'comms 5', liveAs: null, note: 'merged into comms 1, Codes and Markers' },
|
|
91
93
|
};
|
|
92
94
|
|
|
93
95
|
/**
|
|
@@ -388,6 +390,23 @@ export function knownRuleIds() {
|
|
|
388
390
|
return ruleCanon(SRC).rules.filter((r) => r.kind === 'DOCTRINE').map((r) => `${r.pack}.${r.n}`);
|
|
389
391
|
}
|
|
390
392
|
|
|
393
|
+
/**
|
|
394
|
+
* `<pack>.<n>` -> why it names nothing now, for every retired doctrine rule whose address no
|
|
395
|
+
* live rule took over. Read off `RETIRED_RULE_IDS`' `was`, so the reason has one home. An
|
|
396
|
+
* install that excluded `comms 5` replays it on every rebuild; refusing it would break that
|
|
397
|
+
* rebuild forever, so the flag parsers warn and drop it instead. A live address is never
|
|
398
|
+
* retired: a rule appended later at the same number takes the address back.
|
|
399
|
+
*/
|
|
400
|
+
export function retiredRuleAddresses(known = knownRuleIds()) {
|
|
401
|
+
const out = new Map();
|
|
402
|
+
for (const { was, note } of Object.values(RETIRED_RULE_IDS)) {
|
|
403
|
+
const m = /^([a-z]+) (\d+)$/.exec(was);
|
|
404
|
+
const id = m && `${m[1]}.${m[2]}`;
|
|
405
|
+
if (id && PACK_ORDER.includes(m[1]) && !known.includes(id)) out.set(id, note);
|
|
406
|
+
}
|
|
407
|
+
return out;
|
|
408
|
+
}
|
|
409
|
+
|
|
391
410
|
/**
|
|
392
411
|
* Every skill this checkout ships: a flat `skills/<name>.md` (authoring `_` files are not
|
|
393
412
|
* skills) or a vendored `skills/<name>/` folder. The one enumerator `--exclude-skills` closes
|
package/js/cli-table.json
CHANGED
|
@@ -663,6 +663,157 @@
|
|
|
663
663
|
"options": [],
|
|
664
664
|
"mutex": []
|
|
665
665
|
},
|
|
666
|
+
{
|
|
667
|
+
"name": "factory",
|
|
668
|
+
"help": "run a factory: carry one work item through a graph of bricks and whole loops to an open PR (check/list/init/next/record/decide)",
|
|
669
|
+
"description": "",
|
|
670
|
+
"positionals": [
|
|
671
|
+
{
|
|
672
|
+
"names": [],
|
|
673
|
+
"dest": "action",
|
|
674
|
+
"metavar": null,
|
|
675
|
+
"help": "",
|
|
676
|
+
"choices": [
|
|
677
|
+
"check",
|
|
678
|
+
"list",
|
|
679
|
+
"init",
|
|
680
|
+
"next",
|
|
681
|
+
"record",
|
|
682
|
+
"decide"
|
|
683
|
+
],
|
|
684
|
+
"default": null,
|
|
685
|
+
"required": true,
|
|
686
|
+
"nargs": null,
|
|
687
|
+
"is_flag": false,
|
|
688
|
+
"type": null,
|
|
689
|
+
"hidden": false
|
|
690
|
+
}
|
|
691
|
+
],
|
|
692
|
+
"options": [
|
|
693
|
+
{
|
|
694
|
+
"names": ["--factory"],
|
|
695
|
+
"dest": "factory",
|
|
696
|
+
"metavar": null,
|
|
697
|
+
"help": "a factory name or a .json factory file (check, init)",
|
|
698
|
+
"choices": null,
|
|
699
|
+
"default": null,
|
|
700
|
+
"required": false,
|
|
701
|
+
"nargs": null,
|
|
702
|
+
"is_flag": false,
|
|
703
|
+
"type": null,
|
|
704
|
+
"hidden": false
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
"names": ["--title"],
|
|
708
|
+
"dest": "title",
|
|
709
|
+
"metavar": null,
|
|
710
|
+
"help": "the run's title, written into FACTORY.md",
|
|
711
|
+
"choices": null,
|
|
712
|
+
"default": null,
|
|
713
|
+
"required": false,
|
|
714
|
+
"nargs": null,
|
|
715
|
+
"is_flag": false,
|
|
716
|
+
"type": null,
|
|
717
|
+
"hidden": false
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
"names": ["--requirement"],
|
|
721
|
+
"dest": "requirement",
|
|
722
|
+
"metavar": null,
|
|
723
|
+
"help": "the work item the run exists to carry to a PR",
|
|
724
|
+
"choices": null,
|
|
725
|
+
"default": null,
|
|
726
|
+
"required": false,
|
|
727
|
+
"nargs": null,
|
|
728
|
+
"is_flag": false,
|
|
729
|
+
"type": null,
|
|
730
|
+
"hidden": false
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
"names": ["--input"],
|
|
734
|
+
"dest": "input",
|
|
735
|
+
"metavar": null,
|
|
736
|
+
"help": "where the work item came from: an issue URL, a file path or pasted text (init)",
|
|
737
|
+
"choices": null,
|
|
738
|
+
"default": null,
|
|
739
|
+
"required": false,
|
|
740
|
+
"nargs": null,
|
|
741
|
+
"is_flag": false,
|
|
742
|
+
"type": null,
|
|
743
|
+
"hidden": false
|
|
744
|
+
},
|
|
745
|
+
{
|
|
746
|
+
"names": ["--outcome"],
|
|
747
|
+
"dest": "outcome",
|
|
748
|
+
"metavar": null,
|
|
749
|
+
"help": "the stage's reported outcome, one of its declared outcomes",
|
|
750
|
+
"choices": null,
|
|
751
|
+
"default": null,
|
|
752
|
+
"required": false,
|
|
753
|
+
"nargs": null,
|
|
754
|
+
"is_flag": false,
|
|
755
|
+
"type": null,
|
|
756
|
+
"hidden": false
|
|
757
|
+
},
|
|
758
|
+
{
|
|
759
|
+
"names": ["--spec"],
|
|
760
|
+
"dest": "spec",
|
|
761
|
+
"metavar": null,
|
|
762
|
+
"help": "the spec a stage wrote; its ordered tasks replay the next loop stage once each (record)",
|
|
763
|
+
"choices": null,
|
|
764
|
+
"default": null,
|
|
765
|
+
"required": false,
|
|
766
|
+
"nargs": null,
|
|
767
|
+
"is_flag": false,
|
|
768
|
+
"type": null,
|
|
769
|
+
"hidden": false
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
"names": ["--carry"],
|
|
773
|
+
"dest": "carry",
|
|
774
|
+
"metavar": null,
|
|
775
|
+
"help": "the reason the next stage must hear, such as why CI failed; a re-entered loop starts with it as a note (record)",
|
|
776
|
+
"choices": null,
|
|
777
|
+
"default": null,
|
|
778
|
+
"required": false,
|
|
779
|
+
"nargs": null,
|
|
780
|
+
"is_flag": false,
|
|
781
|
+
"type": null,
|
|
782
|
+
"hidden": false
|
|
783
|
+
},
|
|
784
|
+
{
|
|
785
|
+
"names": ["--verdict"],
|
|
786
|
+
"dest": "verdict",
|
|
787
|
+
"metavar": null,
|
|
788
|
+
"help": "the user's answer to a held gate",
|
|
789
|
+
"choices": [
|
|
790
|
+
"ok",
|
|
791
|
+
"no",
|
|
792
|
+
"amend"
|
|
793
|
+
],
|
|
794
|
+
"default": null,
|
|
795
|
+
"required": false,
|
|
796
|
+
"nargs": null,
|
|
797
|
+
"is_flag": false,
|
|
798
|
+
"type": null,
|
|
799
|
+
"hidden": false
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
"names": ["--note"],
|
|
803
|
+
"dest": "note",
|
|
804
|
+
"metavar": null,
|
|
805
|
+
"help": "a note attached to a decide verdict; an amend hands it to the re-run stage",
|
|
806
|
+
"choices": null,
|
|
807
|
+
"default": null,
|
|
808
|
+
"required": false,
|
|
809
|
+
"nargs": null,
|
|
810
|
+
"is_flag": false,
|
|
811
|
+
"type": null,
|
|
812
|
+
"hidden": false
|
|
813
|
+
}
|
|
814
|
+
],
|
|
815
|
+
"mutex": []
|
|
816
|
+
},
|
|
666
817
|
{
|
|
667
818
|
"name": "git-gate",
|
|
668
819
|
"help": "PreToolUse hook: ASK before a history-discarding git act (Deletion Is Deliberate), a recursive scan of a whole filesystem (Commands Must Return) and every git commit/push (Consent Before Push backstop)",
|
|
@@ -1081,7 +1232,7 @@
|
|
|
1081
1232
|
"names": ["--note"],
|
|
1082
1233
|
"dest": "note",
|
|
1083
1234
|
"metavar": null,
|
|
1084
|
-
"help": "a note attached to a record or a decide verdict, written into LOOP.md so it survives the unit",
|
|
1235
|
+
"help": "a note attached to a record or a decide verdict, written into LOOP.md so it survives the unit; on init, the note the loop starts with",
|
|
1085
1236
|
"choices": null,
|
|
1086
1237
|
"default": null,
|
|
1087
1238
|
"required": false,
|
|
@@ -1094,7 +1245,20 @@
|
|
|
1094
1245
|
"names": ["--note-file"],
|
|
1095
1246
|
"dest": "note_file",
|
|
1096
1247
|
"metavar": null,
|
|
1097
|
-
"help": "record's note read from this file instead of the command line (CRLF folded, trimmed) — for a multi-line note or one that mentions git commit/push",
|
|
1248
|
+
"help": "record's or init's note read from this file instead of the command line (CRLF folded, trimmed) — for a multi-line note or one that mentions git commit/push",
|
|
1249
|
+
"choices": null,
|
|
1250
|
+
"default": null,
|
|
1251
|
+
"required": false,
|
|
1252
|
+
"nargs": null,
|
|
1253
|
+
"is_flag": false,
|
|
1254
|
+
"type": null,
|
|
1255
|
+
"hidden": false
|
|
1256
|
+
},
|
|
1257
|
+
{
|
|
1258
|
+
"names": ["--factory"],
|
|
1259
|
+
"dest": "factory",
|
|
1260
|
+
"metavar": null,
|
|
1261
|
+
"help": "on init, the slug of the factory run this loop is a stage of, stored on the loop's registry row",
|
|
1098
1262
|
"choices": null,
|
|
1099
1263
|
"default": null,
|
|
1100
1264
|
"required": false,
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `geneseed factory <action>` — the factory engine's only face, built as `geneseed loop` is
|
|
3
|
+
* (`js/loop/cli.mjs`): one JSON object per action, exit 1 on any refusal, no spawn. git and
|
|
4
|
+
* `gh`/`glab` are the model's job; the porcelain reaches `record` on stdin, and a TTY stdin reads
|
|
5
|
+
* as `null` ("none given"), never as a clean tree.
|
|
6
|
+
*
|
|
7
|
+
* FACTORY.md LIVES AT THE GIT ROOT, beside LOOP.md, for the same reason LOOP.md does: the loop
|
|
8
|
+
* engine filters both out of every diff by their root-relative name (`ENGINE_FILES`). So the root
|
|
9
|
+
* is found by walking up to `.git`, never taken from the caller. The same root answers R3: the
|
|
10
|
+
* status in the LOOP.md there (`loopStatus`) goes to the engine, which refuses while it is neither
|
|
11
|
+
* `done` nor `stopped`, holds a loop stage's outcome to it (R2: stopped is fail, done is pass), and
|
|
12
|
+
* refuses `next` on a loop stage while any LOOP.md is left. A loop that ends on `$stop` leaves its
|
|
13
|
+
* LOOP.md in place, so without that read R2 could never be recorded. A LOOP.md that does not parse
|
|
14
|
+
* counts as running: refusing is the safe side, and `loop` itself refuses it too. Its graph name
|
|
15
|
+
* (`loopTemplate`) and the HEAD commit (`headCommit`, read off disk) go along: `next` on a loop
|
|
16
|
+
* stage stores the launch in FACTORY.md with the time now, so `next` writes, and `record` checks
|
|
17
|
+
* the loop against it — with the loop registry's last `loop init` time for this root
|
|
18
|
+
* (`loopInitAt`, a read of `loops.json`, no write), which a `pass` with no LOOP.md left needs.
|
|
19
|
+
*
|
|
20
|
+
* THE PORCELAIN IS TRUSTED AS PIPED. A TTY stdin is `null` and the engine refuses it after a
|
|
21
|
+
* stage outside a loop (J5); an empty pipe (or a null device) reads as a clean tree, and nothing
|
|
22
|
+
* here can tell it from one. The Rite pipes `git status --porcelain --untracked-files=all`, so a
|
|
23
|
+
* new spec reaches the engine as its own path, never folded into its directory.
|
|
24
|
+
*
|
|
25
|
+
* `--spec` IS READ HERE, not in the state module: the engine stays pure, and the CLI is the one
|
|
26
|
+
* layer that may read files. The path is stored root-relative with forward slashes, the form a
|
|
27
|
+
* porcelain line carries it in, and a path outside the root is refused before it is read.
|
|
28
|
+
*/
|
|
29
|
+
import { readFileSync } from 'node:fs';
|
|
30
|
+
import path from 'node:path';
|
|
31
|
+
import { readText, isFile, printOut } from '../lib/fs.mjs';
|
|
32
|
+
import { gitRootOf, headCommit, currentBranch } from '../hosts/gitref.mjs';
|
|
33
|
+
import { loadCatalog } from '../loop/catalog.mjs';
|
|
34
|
+
import { LOOP_FILE, parseLoopFile } from '../loop/state.mjs';
|
|
35
|
+
import { loopInitAt } from '../loop/registry.mjs';
|
|
36
|
+
import { recordFactory } from './registry.mjs';
|
|
37
|
+
import { checkFactory, factoryCatalogProblems } from './graph.mjs';
|
|
38
|
+
import {
|
|
39
|
+
FACTORY_FILE, initFactory, nextStage, recordStage, decideFactory, writeFactoryFile, parseFactoryFile,
|
|
40
|
+
validateFactoryState, countSpecTasks,
|
|
41
|
+
} from './state.mjs';
|
|
42
|
+
|
|
43
|
+
const emit = (obj) => { printOut(`${JSON.stringify(obj)}\n`); return obj.error || obj.ok === false ? 1 : 0; };
|
|
44
|
+
const stdin = () => (process.stdin.isTTY ? null : readFileSync(0, 'utf8'));
|
|
45
|
+
const byName = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
46
|
+
|
|
47
|
+
/** R3: the LOOP.md at `root` — its status (`running` when it does not parse) and graph name; nulls without one. */
|
|
48
|
+
function loopFileOf(root) {
|
|
49
|
+
const file = path.join(root, LOOP_FILE);
|
|
50
|
+
if (!isFile(file)) return { loopStatus: null, loopTemplate: null };
|
|
51
|
+
try {
|
|
52
|
+
const loop = parseLoopFile(readText(file));
|
|
53
|
+
return { loopStatus: String(loop?.status ?? 'running'), loopTemplate: loop?.graph?.name ?? null };
|
|
54
|
+
} catch { return { loopStatus: 'running', loopTemplate: null }; }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function requireRoot() {
|
|
58
|
+
const root = gitRootOf(process.cwd());
|
|
59
|
+
if (!root) throw new Error('not inside a git repository');
|
|
60
|
+
return root;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* R4: an unreadable FACTORY.md throws in `parseFactoryFile` or `validateFactoryState`, before `fn`
|
|
65
|
+
* runs or anything is written.
|
|
66
|
+
*/
|
|
67
|
+
function withState(fn) {
|
|
68
|
+
const root = requireRoot();
|
|
69
|
+
const file = path.join(root, FACTORY_FILE);
|
|
70
|
+
if (!isFile(file)) throw new Error(`${file} does not exist — run \`geneseed factory init\` first`);
|
|
71
|
+
const state = parseFactoryFile(readText(file));
|
|
72
|
+
const catalog = loadCatalog({ projectRoot: root });
|
|
73
|
+
validateFactoryState(state, catalog);
|
|
74
|
+
const result = fn(state, catalog, { root, head: headCommit(root), ...loopFileOf(root) });
|
|
75
|
+
writeFactoryFile(file, state);
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function resolveFactory(spec, catalog) {
|
|
80
|
+
if (spec.endsWith('.json')) return JSON.parse(readText(path.resolve(spec)));
|
|
81
|
+
const f = catalog.factories.get(spec);
|
|
82
|
+
if (!f) throw new Error(`no factory named ${JSON.stringify(spec)}`);
|
|
83
|
+
const { origin, ...factory } = f;
|
|
84
|
+
return factory;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const ACTIONS = {
|
|
88
|
+
check(args) {
|
|
89
|
+
const root = gitRootOf(process.cwd()) ?? process.cwd();
|
|
90
|
+
const catalog = loadCatalog({ projectRoot: root });
|
|
91
|
+
if (args.factory) {
|
|
92
|
+
const problems = checkFactory(resolveFactory(args.factory, catalog), catalog);
|
|
93
|
+
return { ok: !problems.length, problems };
|
|
94
|
+
}
|
|
95
|
+
const problems = factoryCatalogProblems(catalog);
|
|
96
|
+
return { ok: !problems.length, problems, factories: [...catalog.factories.keys()].sort(byName) };
|
|
97
|
+
},
|
|
98
|
+
list() {
|
|
99
|
+
const root = gitRootOf(process.cwd()) ?? process.cwd();
|
|
100
|
+
const { factories } = loadCatalog({ projectRoot: root });
|
|
101
|
+
return {
|
|
102
|
+
factories: [...factories.values()].sort((a, b) => byName(a.name, b.name)).map((f) => ({
|
|
103
|
+
name: f.name, description: f.description ?? '', category: f.category ?? null, origin: f.origin,
|
|
104
|
+
})),
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
init(args) {
|
|
108
|
+
const root = requireRoot();
|
|
109
|
+
const file = path.join(root, FACTORY_FILE);
|
|
110
|
+
if (isFile(file)) throw new Error(`${file} already exists — a factory is already running here`);
|
|
111
|
+
if (!args.title || !args.requirement || !args.factory) throw new Error('init needs --title, --requirement and --factory');
|
|
112
|
+
const catalog = loadCatalog({ projectRoot: root });
|
|
113
|
+
const factory = resolveFactory(args.factory, catalog);
|
|
114
|
+
const problems = checkFactory(factory, catalog);
|
|
115
|
+
if (problems.length) return { error: 'the factory does not pass factory check', problems };
|
|
116
|
+
const state = initFactory({ title: args.title, requirement: args.requirement, factory, input: args.input ?? null });
|
|
117
|
+
writeFactoryFile(file, state);
|
|
118
|
+
// Best-effort, as `loop init`'s `recordLoop`: the registry is how the console finds the run.
|
|
119
|
+
recordFactory({ root, branch: currentBranch(root), factory: factory.name, title: args.title });
|
|
120
|
+
return { file, factory: factory.name, stage: state.stage, status: state.status };
|
|
121
|
+
},
|
|
122
|
+
next: () => withState((s, c, { loopStatus, head }) => nextStage(s, c, { loopStatus, head, now: new Date().toISOString() })),
|
|
123
|
+
record(args) {
|
|
124
|
+
if (!args.outcome) throw new Error('record needs --outcome');
|
|
125
|
+
const porcelain = stdin();
|
|
126
|
+
return withState((s, c, { root, loopStatus, loopTemplate, head }) => {
|
|
127
|
+
let specPath = null; let taskCount = null;
|
|
128
|
+
if (args.spec) {
|
|
129
|
+
const abs = path.resolve(root, args.spec);
|
|
130
|
+
const rel = path.relative(root, abs);
|
|
131
|
+
if (!rel || rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) throw new Error(`--spec ${args.spec} is outside the worktree`);
|
|
132
|
+
let text;
|
|
133
|
+
try { text = readText(abs); } catch (e) { throw new Error(`cannot read --spec ${args.spec}: ${e.message}`, { cause: e }); }
|
|
134
|
+
specPath = rel.replaceAll('\\', '/');
|
|
135
|
+
taskCount = countSpecTasks(text);
|
|
136
|
+
}
|
|
137
|
+
return recordStage(s, c, args.outcome, {
|
|
138
|
+
porcelain: porcelain === null ? null : porcelain.replace(/\r\n/g, '\n').trimEnd(),
|
|
139
|
+
specPath, taskCount, carry: args.carry ?? null, loopStatus, loopTemplate, head,
|
|
140
|
+
loopInitAt: loopInitAt(root),
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
decide: (args) => withState((s, c) => decideFactory(s, c, args.verdict, args.note ?? '')),
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export function cmdFactory(args) {
|
|
148
|
+
try {
|
|
149
|
+
return emit(ACTIONS[args.action](args));
|
|
150
|
+
} catch (e) {
|
|
151
|
+
return emit({ error: e.message });
|
|
152
|
+
}
|
|
153
|
+
}
|