taskquoin 0.0.0-stage → 2026.12.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.
Files changed (160) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/LICENSE +55 -0
  3. package/README.md +227 -2
  4. package/SECURITY.md +26 -0
  5. package/adapters/git/src/git.js +250 -0
  6. package/adapters/git/src/index.js +1 -0
  7. package/adapters/hooks-claude/src/canonical.js +45 -0
  8. package/adapters/hooks-claude/src/index.js +2 -0
  9. package/adapters/hooks-claude/src/main.js +58 -0
  10. package/adapters/hooks-claude/src/payload.js +40 -0
  11. package/adapters/host-probe/src/index.js +2 -0
  12. package/adapters/host-probe/src/ollama.js +18 -0
  13. package/adapters/host-probe/src/probe.js +107 -0
  14. package/adapters/local-tool/src/fingerprint.js +56 -0
  15. package/adapters/local-tool/src/index.js +4 -0
  16. package/adapters/local-tool/src/local-tool.js +22 -0
  17. package/adapters/local-tool/src/sandboxed.js +105 -0
  18. package/adapters/local-tool/src/scan.js +52 -0
  19. package/adapters/memory-claude-mem/src/claude-mem.js +115 -0
  20. package/adapters/memory-claude-mem/src/index.js +1 -0
  21. package/adapters/process-runner/src/index.js +1 -0
  22. package/adapters/process-runner/src/runner.js +123 -0
  23. package/adapters/runtime-api/src/capabilities.json +116 -0
  24. package/adapters/runtime-api/src/executor.js +131 -0
  25. package/adapters/runtime-api/src/index.js +1 -0
  26. package/adapters/runtime-claude/src/capabilities.json +375 -0
  27. package/adapters/runtime-claude/src/command.js +34 -0
  28. package/adapters/runtime-claude/src/executor.js +162 -0
  29. package/adapters/runtime-claude/src/index.js +4 -0
  30. package/adapters/runtime-claude/src/permissions.js +76 -0
  31. package/adapters/runtime-claude/src/stream.js +60 -0
  32. package/adapters/runtime-codex/src/capabilities.json +192 -0
  33. package/adapters/runtime-codex/src/command.js +36 -0
  34. package/adapters/runtime-codex/src/executor.js +83 -0
  35. package/adapters/runtime-codex/src/index.js +4 -0
  36. package/adapters/runtime-codex/src/scratch.js +32 -0
  37. package/adapters/runtime-codex/src/stream.js +39 -0
  38. package/adapters/runtime-opencode/src/capabilities.json +149 -0
  39. package/adapters/runtime-opencode/src/config.js +33 -0
  40. package/adapters/runtime-opencode/src/credentials.js +130 -0
  41. package/adapters/runtime-opencode/src/executor.js +127 -0
  42. package/adapters/runtime-opencode/src/facts.js +43 -0
  43. package/adapters/runtime-opencode/src/hosts.js +16 -0
  44. package/adapters/runtime-opencode/src/hosts.json +3 -0
  45. package/adapters/runtime-opencode/src/index.js +6 -0
  46. package/adapters/runtime-opencode/src/mounts.js +58 -0
  47. package/adapters/runtime-opencode/src/stream.js +63 -0
  48. package/adapters/skill-store/src/index.js +1 -0
  49. package/adapters/skill-store/src/skill-store.js +162 -0
  50. package/adapters/store-fs/src/index.js +2 -0
  51. package/adapters/store-fs/src/store.js +201 -0
  52. package/adapters/store-fs/src/trusted-dir.js +37 -0
  53. package/apps/cli/src/console.js +432 -0
  54. package/apps/cli/src/dashboard-approve.js +259 -0
  55. package/apps/cli/src/dashboard-data.js +424 -0
  56. package/apps/cli/src/dashboard.js +500 -0
  57. package/apps/cli/src/history.js +35 -0
  58. package/apps/cli/src/home.js +18 -0
  59. package/apps/cli/src/i18n/en.js +527 -0
  60. package/apps/cli/src/i18n/index.js +90 -0
  61. package/apps/cli/src/i18n/languages.js +25 -0
  62. package/apps/cli/src/i18n/locales/ar.json +526 -0
  63. package/apps/cli/src/i18n/locales/de.json +505 -0
  64. package/apps/cli/src/i18n/locales/es.json +505 -0
  65. package/apps/cli/src/i18n/locales/fa.json +505 -0
  66. package/apps/cli/src/i18n/locales/fr.json +505 -0
  67. package/apps/cli/src/i18n/locales/he.json +505 -0
  68. package/apps/cli/src/i18n/locales/hi.json +505 -0
  69. package/apps/cli/src/i18n/locales/id.json +491 -0
  70. package/apps/cli/src/i18n/locales/it.json +505 -0
  71. package/apps/cli/src/i18n/locales/ja.json +491 -0
  72. package/apps/cli/src/i18n/locales/ko.json +491 -0
  73. package/apps/cli/src/i18n/locales/nl.json +505 -0
  74. package/apps/cli/src/i18n/locales/pl.json +512 -0
  75. package/apps/cli/src/i18n/locales/pt-BR.json +505 -0
  76. package/apps/cli/src/i18n/locales/ru.json +512 -0
  77. package/apps/cli/src/i18n/locales/th.json +491 -0
  78. package/apps/cli/src/i18n/locales/tr.json +505 -0
  79. package/apps/cli/src/i18n/locales/uk.json +512 -0
  80. package/apps/cli/src/i18n/locales/vi.json +491 -0
  81. package/apps/cli/src/i18n/locales/zh-CN.json +491 -0
  82. package/apps/cli/src/i18n/locales/zh-TW.json +491 -0
  83. package/apps/cli/src/i18n/width.js +40 -0
  84. package/apps/cli/src/layout.js +18 -0
  85. package/apps/cli/src/main.js +830 -0
  86. package/apps/cli/src/preferences.js +46 -0
  87. package/apps/cli/src/runtime-notices.js +41 -0
  88. package/apps/cli/src/safe-text.js +3 -0
  89. package/apps/cli/src/shortcut.js +82 -0
  90. package/apps/cli/src/skills-cli.js +112 -0
  91. package/apps/cli/src/tui/caps.js +31 -0
  92. package/apps/cli/src/tui/components/agent-list.js +58 -0
  93. package/apps/cli/src/tui/components/approval-center.js +145 -0
  94. package/apps/cli/src/tui/components/approval.js +95 -0
  95. package/apps/cli/src/tui/components/dashboard-frame.js +293 -0
  96. package/apps/cli/src/tui/components/diff-viewer.js +549 -0
  97. package/apps/cli/src/tui/components/event-viewer.js +46 -0
  98. package/apps/cli/src/tui/components/help-panel.js +59 -0
  99. package/apps/cli/src/tui/components/home.js +185 -0
  100. package/apps/cli/src/tui/components/logo.js +67 -0
  101. package/apps/cli/src/tui/components/panel.js +70 -0
  102. package/apps/cli/src/tui/components/status-bar.js +96 -0
  103. package/apps/cli/src/tui/components/timeline.js +120 -0
  104. package/apps/cli/src/tui/keys.js +139 -0
  105. package/apps/cli/src/tui/neutral.js +68 -0
  106. package/apps/cli/src/tui/screen.js +111 -0
  107. package/apps/cli/src/tui/text.js +165 -0
  108. package/apps/cli/src/tui/tokens.js +89 -0
  109. package/apps/cli/src/tui/view.js +64 -0
  110. package/apps/cli/src/upgrade-check.js +86 -0
  111. package/apps/cli/src/upgrade-cli.js +168 -0
  112. package/apps/cli/src/workflow-cli.js +674 -0
  113. package/package.json +29 -4
  114. package/packages/application/src/index.js +8 -0
  115. package/packages/application/src/lib/digest.js +7 -0
  116. package/packages/application/src/ports/memory.js +1 -0
  117. package/packages/application/src/ports/runtime-executor.js +1 -0
  118. package/packages/application/src/projection/run-view.js +194 -0
  119. package/packages/application/src/projection/squad-view.js +33 -0
  120. package/packages/application/src/use-cases/prepare-run.js +68 -0
  121. package/packages/application/src/workflow/feature-governed.js +420 -0
  122. package/packages/application/src/workflow/gate-signals.js +40 -0
  123. package/packages/application/src/workflow/prompts.js +81 -0
  124. package/packages/config/src/config.js +372 -0
  125. package/packages/config/src/index.js +1 -0
  126. package/packages/domain/src/capabilities.js +13 -0
  127. package/packages/domain/src/capability-matrix.js +63 -0
  128. package/packages/domain/src/enforcement.js +95 -0
  129. package/packages/domain/src/index.js +4 -0
  130. package/packages/domain/src/policy.js +32 -0
  131. package/packages/rules/src/glob.js +47 -0
  132. package/packages/rules/src/index.js +5 -0
  133. package/packages/rules/src/inherit.js +19 -0
  134. package/packages/rules/src/lists.js +41 -0
  135. package/packages/rules/src/rules.js +79 -0
  136. package/packages/rules/src/shell.js +83 -0
  137. package/packages/skills/src/index.js +1 -0
  138. package/packages/skills/src/skills.js +108 -0
  139. package/skills/code-review/SKILL.md +51 -0
  140. package/skills/egm-design/LICENSE +202 -0
  141. package/skills/egm-design/SKILL.md +68 -0
  142. package/skills/egm-design/references/feature-spec-standard.md +39 -0
  143. package/skills/egm-implementation-readiness/LICENSE +202 -0
  144. package/skills/egm-implementation-readiness/SKILL.md +67 -0
  145. package/skills/egm-implementation-readiness/references/implementation-readiness-standard.md +37 -0
  146. package/skills/first-party.lock.json +10 -0
  147. package/skills/planning-contract/SKILL.md +51 -0
  148. package/skills/ponytail/LICENSE +21 -0
  149. package/skills/ponytail/SKILL.md +56 -0
  150. package/skills/security-review/SKILL.md +58 -0
  151. package/skills/tdd/SKILL.md +52 -0
  152. package/skills/unslop/LICENSE +396 -0
  153. package/skills/unslop/SKILL.md +239 -0
  154. package/skills/unslop/references/cjk.md +34 -0
  155. package/skills/unslop/references/effects.md +113 -0
  156. package/skills/unslop/references/refs.md +17 -0
  157. package/skills/unslop/references/rtl.md +111 -0
  158. package/skills/unslop/references/signs.md +122 -0
  159. package/skills/unslop/references/tokens.md +139 -0
  160. package/skills/unslop/references/visuals.md +84 -0
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "taskquoin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2026.12.0",
4
+ "description": "Taskquoin — governed execution for coding agents (Claude Code, Codex)",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "bin": {
8
+ "taskquoin": "apps/cli/src/main.js"
9
+ },
10
+ "engines": {
11
+ "node": ">=22.18"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/malek-berrahal/taskquoin.git"
16
+ },
17
+ "homepage": "https://github.com/malek-berrahal/taskquoin#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/malek-berrahal/taskquoin/issues"
20
+ },
21
+ "taskquoin": {
22
+ "measured": {
23
+ "claude": "2.1.327",
24
+ "codex": "0.157.1",
25
+ "opencode": "1.19.5"
26
+ }
27
+ },
28
+ "dependencies": {
29
+ "yaml": "2.9.1"
30
+ }
31
+ }
@@ -0,0 +1,8 @@
1
+ export * from "./ports/runtime-executor.js";
2
+ export * from "./lib/digest.js";
3
+ export * from "./ports/memory.js";
4
+ export * from "./use-cases/prepare-run.js";
5
+ export * from "./workflow/feature-governed.js";
6
+ export * from "./workflow/prompts.js";
7
+ export * from "./projection/run-view.js";
8
+ export * from "./projection/squad-view.js";
@@ -0,0 +1,7 @@
1
+ import { createHash } from 'node:crypto';
2
+ /** Stable digest of an invocation (no prompt: it is on stdin). */
3
+ export function invocationDigest(bin, args, env) {
4
+ const h = createHash('sha256');
5
+ h.update(JSON.stringify({ bin, args, env: Object.keys(env).sort().map(k => `${k}=${env[k]}`) }));
6
+ return `sha256:${h.digest('hex')}`;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,194 @@
1
+ /**
2
+ * RunView (console V2 / dashboard, spec §6): the run as the console timeline and the dashboard show it. A pure
3
+ * projection — no I/O, no clock — of the stored RunState and its event log (as `readEvents` returns it, possibly cut
4
+ * at its head) onto the nine logical steps. It decides nothing and invents nothing: what is not recorded is absent.
5
+ *
6
+ * - Times are the state machine's. A history entry is written when a node is LEFT, so a step ends at its last entry
7
+ * and starts at the entry before its first one (the first step at the time in the run id, UTC). A step in progress
8
+ * (running, waiting) starts when the run entered it this time — after a loop back, not at its first visit.
9
+ * - `durationMs` (done or failed steps) is the time spent in the step, summed over its passes: a pass counts its
10
+ * agents' own `durationMs` when every agent of the pass reported one, else its history time. A pass resumed after
11
+ * an interruption has no known start (a resume writes nothing): without agent times the step has no duration.
12
+ * - Passes through implement / verify / red-check / review are `attempts` of their step (n = pass number in the step,
13
+ * the outcome from history; a pass in progress is the last attempt, outcome `running`). An attempt names its
14
+ * artifact (`verify-N`…, N = the run's attempt number) only when the stored one can be that pass's: a later pass
15
+ * with the same N (re-verify after a commit approval, resume) overwrites it. An attempt has its own start and duration
16
+ * by the step's rules: a pass resumed after an interruption has no known start; a pass in progress has no duration.
17
+ * - The current step takes the run's status (interrupted and needs-human: failed); a status this projection does not
18
+ * know gives `unknown`, never an invented failure.
19
+ * - `outcome` is the step's last history outcome (the critique's verdicts, who approved a gate, a loop's last pass,
20
+ * the stop that failed it) for a step done, failed, waiting or unknown; none for a step in progress (its pass has
21
+ * none yet) nor for one pending again after a loop back (that outcome belongs to a pass the run went back before).
22
+ * - agent, runtime and model are those of the step's latest agent run, from `agent.started` / `agent.finished` only.
23
+ * `runs` lists every agent run of the step's last pass (several judges), the pass in progress for a running step; a
24
+ * pass resumed after an interruption includes the part before it (a resume continues it: judges who answered are
25
+ * not asked again). None when no agent ran.
26
+ * - Free text (`reason`, outcomes, agent / runtime / model, artifact names, branch, times…) is returned as stored, as
27
+ * the type parameter `S` (`projectRun` gives `RunView<string>`: raw). A screen never prints it raw: the CLI's
28
+ * `shownRun()` (apps/cli/src/tui/view.ts) neutralises the whole view once into `RunView<Neutral>`, the only view a
29
+ * renderer accepts (ADR-0019 decision 3), and carries the count of marked characters.
30
+ */
31
+ import { pendingApproval } from "../workflow/feature-governed.js";
32
+ /** Logical steps in pipeline order; `pass` = the artifact prefix of a loop node's pass; `artifacts` = the step's names. */
33
+ const STEPS = [
34
+ { id: 'planning', nodes: ['recall', 'plan'], artifacts: /^(memory|plan)$/ },
35
+ { id: 'critique', nodes: ['challenge'], artifacts: /^challenge(-.+)?$/ },
36
+ { id: 'plan-approval', nodes: ['approve-plan'] },
37
+ { id: 'implementation', nodes: ['implement'], pass: 'implement', artifacts: /^(workspace-baseline|implement-\d+)$/ },
38
+ { id: 'verify', nodes: ['verify'], pass: 'verify', artifacts: /^(verify|ignored)-\d+$/ },
39
+ { id: 'red-proof', nodes: ['red-check'], pass: 'red', artifacts: /^red-\d+$/ },
40
+ { id: 'review', nodes: ['review'], pass: 'review', artifacts: /^(diff-\d+|review-\d+(-.+)?)$/ },
41
+ { id: 'commit-approval', nodes: ['approve-commit'] },
42
+ { id: 'commit', nodes: ['commit', 'record', 'done'] },
43
+ ];
44
+ const STEP_OF = new Map(STEPS.flatMap((s, i) => s.nodes.map(n => [n, i])));
45
+ const ACTIVE = { running: 'running', 'waiting-approval': 'waiting', completed: 'done', failed: 'failed', 'needs-human': 'failed', interrupted: 'failed' };
46
+ /** Events written with a history entry: `step()` → node.transition, `stop()` → run.<status> (never run.completed). */
47
+ const STOP_EVENTS = new Set(['run.failed', 'run.waiting-approval', 'run.needs-human', 'run.interrupted']);
48
+ /** Outcomes of a pass the run stopped in: it may have ended before writing its artifact. */
49
+ const STOPPED = new Set(['failed', 'needs-human', 'interrupted']);
50
+ const str = (v) => (typeof v === 'string' && v !== '' ? v : undefined);
51
+ const sum = (xs) => (xs.every(x => x !== undefined) ? xs.reduce((a, b) => a + b, 0) : undefined);
52
+ const between = (from, to) => {
53
+ const d = from === undefined ? NaN : Date.parse(to) - Date.parse(from);
54
+ return Number.isFinite(d) && d >= 0 ? d : undefined;
55
+ };
56
+ /** `run-YYYYMMDDTHHMMSS-xxxxxx` (UTC, as `taskquoin run` names runs) → ISO time; undefined for any other id. */
57
+ export function runIdTime(runId) {
58
+ const m = /^run-(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})-/.exec(runId);
59
+ if (!m)
60
+ return undefined;
61
+ const iso = new Date(Date.UTC(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +m[6])).toISOString();
62
+ return iso.startsWith(`${m[1]}-${m[2]}-${m[3]}T${m[4]}:${m[5]}:${m[6]}`) ? iso : undefined; // no rolled-over date
63
+ }
64
+ /**
65
+ * The agent runs of each history entry, and those after the last entry (the pass in progress). Agent events belong to
66
+ * the next event written with a history entry; the k-th such event of a node is that node's k-th entry. A log cut at
67
+ * its head has fewer of them: they are matched to the last entries. More than entries means the log is ahead of
68
+ * state.json (an event is appended just before each save): matched to the first ones.
69
+ */
70
+ function agentRuns(state, history, events) {
71
+ const marks = [];
72
+ let runs = [], next;
73
+ for (const e of events) {
74
+ if (typeof e !== 'object' || e === null || typeof e.type !== 'string')
75
+ continue;
76
+ if (typeof e.runId === 'string' && e.runId !== state.runId)
77
+ continue;
78
+ const agent = str(e.agent);
79
+ if (e.type === 'agent.started' && agent)
80
+ runs.push({ agent, runtime: str(e.runtime), open: true });
81
+ else if (e.type === 'agent.finished' && agent) {
82
+ let r = runs.findLast(x => x.open && x.agent === agent);
83
+ if (!r)
84
+ runs.push(r = { agent, open: true }); // a log older than agent.started
85
+ r.open = false;
86
+ r.runtime = str(e.runtime) ?? r.runtime;
87
+ r.model = str(e.model);
88
+ r.durationMs = typeof e.durationMs === 'number' && Number.isFinite(e.durationMs) && e.durationMs >= 0 ? e.durationMs : undefined;
89
+ }
90
+ else if ((e.type === 'node.transition' || STOP_EVENTS.has(e.type)) && typeof e.node === 'string') {
91
+ marks.push({ node: e.node, runs });
92
+ runs = [];
93
+ next = e.type === 'node.transition' ? str(e.next) : e.node;
94
+ }
95
+ }
96
+ const byEntry = history.map(() => []);
97
+ const entries = new Map(), marked = new Map();
98
+ const add = (m, k, v) => { const xs = m.get(k); if (xs)
99
+ xs.push(v);
100
+ else
101
+ m.set(k, [v]); };
102
+ history.forEach((h, i) => add(entries, h.node, i));
103
+ for (const m of marks)
104
+ add(marked, m.node, m.runs);
105
+ for (const [node, ms] of marked) {
106
+ const es = entries.get(node) ?? [];
107
+ const off = ms.length >= es.length ? 0 : es.length - ms.length;
108
+ for (let j = 0; j < Math.min(ms.length, es.length); j++)
109
+ byEntry[es[off + j]] = ms[j];
110
+ }
111
+ return { byEntry, live: next === undefined || next === state.current ? runs : [] };
112
+ }
113
+ export function projectRun(state, events) {
114
+ const history = state.history ?? [], stored = state.artifacts ?? {};
115
+ const runStart = runIdTime(state.runId);
116
+ const startOf = (i) => (i > 0 ? history[i - 1].at : runStart);
117
+ const { byEntry, live } = agentRuns(state, history, events);
118
+ const current = STEP_OF.get(state.current) ?? -1;
119
+ const running = state.status === 'running';
120
+ // The run's attempt number at each entry: set by `implemented:N`; verify, red-check and review passes use it.
121
+ let att;
122
+ const attemptOf = history.map(h => {
123
+ if (h.node !== 'implement')
124
+ return att;
125
+ const m = /^implemented:(\d+)$/.exec(h.outcome);
126
+ return m ? (att = Number(m[1])) : undefined;
127
+ });
128
+ /** A pass's start: the entry before it, unknown when it was resumed after an interruption (a resume writes nothing). */
129
+ const passStart = (i) => (i > 0 && history[i - 1].outcome === 'interrupted' ? undefined : startOf(i));
130
+ /** A pass's time: its agents' own, else the history's (unknown when its start is). */
131
+ const passMs = (i) => {
132
+ const ms = sum(byEntry[i].map(r => (r.open ? undefined : r.durationMs)));
133
+ if (byEntry[i].length && ms !== undefined)
134
+ return ms;
135
+ return between(passStart(i), history[i].at);
136
+ };
137
+ const steps = STEPS.map((def, idx) => {
138
+ const mine = history.flatMap((h, i) => (STEP_OF.get(h.node) === idx ? [i] : []));
139
+ const st = idx === current ? ACTIVE[state.status] ?? 'unknown' : idx < current ? 'done' : 'pending';
140
+ const inProgress = idx === current && running;
141
+ const artifacts = def.artifacts ? Object.keys(stored).filter(n => def.artifacts.test(n)) : [];
142
+ const attempts = def.pass ? mine.map((i, k) => {
143
+ const n = attemptOf[i];
144
+ let name = n === undefined ? undefined : `${def.pass}-${n}`;
145
+ if (name && def.id === 'review' && !Object.hasOwn(stored, name))
146
+ name = `diff-${n}`; // stopped before the judges
147
+ const same = mine.filter(j => attemptOf[j] === n);
148
+ const its = name !== undefined && Object.hasOwn(stored, name) && (same.length === 1 || (same.at(-1) === i && !STOPPED.has(history[i].outcome)));
149
+ const from = passStart(i), ms = passMs(i);
150
+ return { n: k + 1, outcome: history[i].outcome, endedAt: history[i].at, ...(its ? { artifact: name } : {}),
151
+ ...(from !== undefined ? { startedAt: from } : {}), ...(ms !== undefined ? { durationMs: ms } : {}) };
152
+ }) : [];
153
+ if (def.pass && inProgress) {
154
+ const from = history.length ? passStart(history.length) : runStart; // the pass in progress began at the last entry
155
+ attempts.push({ n: attempts.length + 1, outcome: 'running', ...(from !== undefined ? { startedAt: from } : {}) });
156
+ }
157
+ if (st === 'pending')
158
+ return { id: def.id, state: st, attempts, artifacts };
159
+ let startedAt, endedAt, durationMs;
160
+ if (st === 'running' || st === 'waiting') {
161
+ const j = history.findLastIndex(h => STEP_OF.get(h.node) !== idx);
162
+ startedAt = j >= 0 ? history[j].at : runStart;
163
+ }
164
+ else if (mine.length) {
165
+ startedAt = startOf(mine[0]);
166
+ endedAt = history[mine.at(-1)].at;
167
+ durationMs = sum(mine.map(passMs));
168
+ }
169
+ const last = [...mine.flatMap(i => byEntry[i]), ...(inProgress ? live : [])].at(-1);
170
+ const outcome = st !== 'running' && mine.length ? history[mine.at(-1)].outcome : undefined;
171
+ // The last pass: from its last entry (or the end of history while in progress) back through the interruptions it resumed.
172
+ const end = inProgress ? history.length : mine.length ? mine.at(-1) + 1 : 0;
173
+ let from = inProgress ? end : end - 1;
174
+ while (from > 0 && STEP_OF.get(history[from - 1].node) === idx && history[from - 1].outcome === 'interrupted')
175
+ from--;
176
+ const runs = [...byEntry.slice(Math.max(from, 0), end).flat(), ...(inProgress ? live : [])]
177
+ .map(({ agent, runtime, model, durationMs }) => ({ agent, ...(runtime ? { runtime } : {}), ...(model ? { model } : {}), ...(durationMs !== undefined ? { durationMs } : {}) }));
178
+ return {
179
+ id: def.id, state: st,
180
+ ...(startedAt !== undefined ? { startedAt } : {}), ...(endedAt !== undefined ? { endedAt } : {}), ...(durationMs !== undefined ? { durationMs } : {}),
181
+ ...(last ? { agent: last.agent } : {}), ...(last?.runtime ? { runtime: last.runtime } : {}), ...(last?.model ? { model: last.model } : {}),
182
+ attempts, artifacts, ...(outcome !== undefined ? { outcome } : {}), ...(runs.length ? { runs } : {}),
183
+ };
184
+ });
185
+ const p = pendingApproval(state);
186
+ return {
187
+ runId: state.runId, status: state.status, current: state.current, attempts: state.attempts,
188
+ ...(typeof state.branch === 'string' ? { branch: state.branch } : {}),
189
+ startedAt: runStart ?? '', steps,
190
+ ...(p ? { pending: { gate: p.node === 'approve-plan' ? 'plan' : 'commit', binding: p.binding } } : {}),
191
+ ...(typeof state.reason === 'string' ? { reason: state.reason } : {}),
192
+ ...(typeof state.commit === 'string' ? { commit: state.commit } : {}),
193
+ };
194
+ }
@@ -0,0 +1,33 @@
1
+ /** An agent can run only when its gate certifies it, its runtime is installed and every skill loads. */
2
+ export const isReady = (g) => g.ok && g.runtimeFound && !(g.skillErrors?.length);
3
+ const upperFirst = (id) => (id ? id[0].toUpperCase() + id.slice(1) : id);
4
+ const DEFAULT_LABELS = { role: upperFirst, absent: (rt) => `${rt} not found`, testerRole: 'Tester', testerUnavailable: 'bubblewrap unavailable' };
5
+ export function projectSquad(agents, verdict, testerReady, labels = DEFAULT_LABELS) {
6
+ const squad = Object.entries(agents).map(([id, a]) => {
7
+ const g = verdict(id);
8
+ const state = !isReady(g) ? 'blocked' : g.acceptedRisks.length ? 'risk' : 'ready';
9
+ let kind, detail;
10
+ if (!g.runtimeFound) {
11
+ kind = 'absent';
12
+ detail = a.runtime;
13
+ }
14
+ else if (!g.ok) {
15
+ kind = 'failure';
16
+ detail = (g.failures[0]?.message ?? '').split(' — ')[0];
17
+ }
18
+ else if (g.skillErrors?.length) {
19
+ kind = 'skill';
20
+ detail = g.skillErrors[0];
21
+ }
22
+ else if (g.acceptedRisks.length) {
23
+ kind = 'risks';
24
+ detail = g.acceptedRisks.map(r => r.capability).join(', ');
25
+ }
26
+ const note = kind === 'absent' ? labels.absent(a.runtime) : detail;
27
+ const who = `${id} · ${a.runtime === 'api' ? `api:${a.provider ?? ''}` : a.runtime === 'opencode' ? `opencode:${(a.model ?? '').split('/')[0]}` : a.runtime}`;
28
+ return { role: labels.role(id), who, state, agent: id, runtime: a.runtime, ...(note ? { note, noteKind: kind, detail } : {}) };
29
+ });
30
+ squad.push(testerReady ? { role: labels.testerRole, who: 'verify · bubblewrap', state: 'ready', runtime: 'bubblewrap' }
31
+ : { role: labels.testerRole, who: 'verify · bubblewrap', state: 'blocked', runtime: 'bubblewrap', note: labels.testerUnavailable, noteKind: 'tester' });
32
+ return squad;
33
+ }
@@ -0,0 +1,68 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { normalizeGrants, resolveEnforcement } from '../../../domain/src/index.js';
3
+ /** Restrictions that are always mandatory; repository configuration can add to them, never remove (Codex R3 #2). */
4
+ export const BUILTIN_MANDATORY = ['fs.write', 'net.egress', 'config.modify', 'connector.write', 'vcs.commit', 'vcs.push'];
5
+ export function failureDigest(message) {
6
+ return 'sha256:' + createHash('sha256').update(message).digest('hex');
7
+ }
8
+ /** YYYY-MM-DD that is a real calendar date. */
9
+ export function isRealDate(s) {
10
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(s))
11
+ return false;
12
+ const d = new Date(`${s}T00:00:00Z`);
13
+ return !Number.isNaN(d.getTime()) && d.toISOString().slice(0, 10) === s;
14
+ }
15
+ /** Order-independent digest of normalized grants. */
16
+ export function capabilitiesDigest(grants) {
17
+ const g = normalizeGrants(grants);
18
+ const canon = Object.keys(g).sort().map(k => [k, [...g[k]].sort()]);
19
+ return 'sha256:' + createHash('sha256').update(JSON.stringify(canon)).digest('hex');
20
+ }
21
+ export const TICKET_TTL_MS = 15 * 60_000;
22
+ /**
23
+ * Executors call this before spawning. Throws on a missing, expired or mismatched ticket (Codex R4 N9). A ticket is a
24
+ * composition safeguard against accidental bypass inside Taskquoin's own process — NOT authentication.
25
+ */
26
+ export function assertTicket(ticket, runtime, verifiedVersion, grants, agentId, now = new Date()) {
27
+ if (!ticket || ticket.kind !== 'taskquoin.gate-ticket.v1')
28
+ throw new Error('refusing to spawn: no gate ticket (every governed run must pass prepareRun)');
29
+ if (ticket.agentId !== agentId)
30
+ throw new Error(`refusing to spawn: ticket is for agent ${ticket.agentId}, request is for ${agentId}`);
31
+ const age = now.getTime() - Date.parse(ticket.issuedAt);
32
+ if (!(age >= 0 && age <= TICKET_TTL_MS))
33
+ throw new Error('refusing to spawn: gate ticket expired or not yet valid');
34
+ if (ticket.runtime !== runtime)
35
+ throw new Error(`refusing to spawn: ticket is for ${ticket.runtime}, executor is ${runtime}`);
36
+ if (ticket.runtimeVersion !== verifiedVersion)
37
+ throw new Error(`refusing to spawn: ticket certified ${runtime} ${ticket.runtimeVersion}, binary is ${verifiedVersion}`);
38
+ if (ticket.capabilitiesDigest !== capabilitiesDigest(grants))
39
+ throw new Error('refusing to spawn: request capabilities differ from the certified ones');
40
+ }
41
+ /**
42
+ * The gate before every run (Codex R1 N1 / R1.2 M5). Pure. An owner exception never certifies anything: it records an
43
+ * accepted, time-limited risk so the run may proceed; it is reported in doctor output and the run's audit events.
44
+ */
45
+ export function prepareRun(input) {
46
+ if (input.agent.runtime !== input.matrix.runtime)
47
+ throw new Error(`agent "${input.agentId}" runs on ${input.agent.runtime} but the matrix is for ${input.matrix.runtime}`);
48
+ const mandatory = [...new Set([...BUILTIN_MANDATORY, ...input.mandatory])];
49
+ const restrictions = mandatory.map(capability => ({ capability, mandatory: true }));
50
+ const r = resolveEnforcement(restrictions, input.agent.capabilities, input.matrix, input.facts);
51
+ const today = input.now.toISOString().slice(0, 10);
52
+ const failures = [];
53
+ const acceptedRisks = [];
54
+ for (const f of r.failures) {
55
+ // An exception applies only to the very failure it accepted, on the same runtime version, until the end of its
56
+ // expiry day (UTC, inclusive).
57
+ const ex = input.exceptions.find(e => e.agent === input.agentId && e.capability === f.capability
58
+ && e.runtimeVersion === input.facts.runtimeVersion && e.failureDigest === failureDigest(f.message));
59
+ if (ex && isRealDate(ex.expires) && ex.expires >= today)
60
+ acceptedRisks.push({ ...ex, message: f.message });
61
+ else
62
+ failures.push(ex ? { ...f, message: `${f.message} (owner exception expired on ${ex.expires})` } : f);
63
+ }
64
+ const ok = failures.length === 0;
65
+ const ticket = ok ? { kind: 'taskquoin.gate-ticket.v1', agentId: input.agentId, runtime: input.agent.runtime, runtimeVersion: input.facts.runtimeVersion,
66
+ capabilitiesDigest: capabilitiesDigest(input.agent.capabilities), issuedAt: input.now.toISOString() } : undefined;
67
+ return { ok, resolved: r.resolved, failures, warnings: r.warnings, acceptedRisks, ...(ticket ? { ticket } : {}) };
68
+ }