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
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Run a repository-controlled command (e.g. the project's test suite during Verify) under bubblewrap:
3
+ * whole filesystem read-only, ONE writable root (the repository), private /tmp, no network, HOME credential and
4
+ * agent-state directories masked. Refuses if bubblewrap is unavailable (fail closed, ADR-0010).
5
+ */
6
+ import { existsSync, lstatSync, realpathSync, statSync } from 'node:fs';
7
+ import { isAbsolute, join } from 'node:path';
8
+ import { HOME_SECRET_GLOBS } from '../../../packages/rules/src/index.js';
9
+ import { runProcess } from '../../process-runner/src/index.js';
10
+ const BWRAP = ['/usr/bin/bwrap', '/bin/bwrap'].find(p => existsSync(p));
11
+ /** Agent and memory state are as sensitive as credentials (transcripts, memories, approvals). */
12
+ const EXTRA_HOME_MASKS = ['.claude', '.codex', '.claude-mem', '.gnupg', '.local/state/taskquoin', '.config/gh'];
13
+ export async function sandboxedToolAvailable() {
14
+ if (!BWRAP || process.platform !== 'linux')
15
+ return false;
16
+ const r = await runProcess({ bin: BWRAP, args: ['--ro-bind', '/', '/', '--unshare-net', '--dev', '/dev', '/bin/true'], cwd: '/', env: {}, timeoutMs: 10_000, maxOutputBytes: 1000 });
17
+ return r.status === 'completed';
18
+ }
19
+ /** Service socket directories: a read-only bind does NOT prevent connect() on a Unix socket (Codex R3). */
20
+ export function defaultMaskDirs() {
21
+ const c = ['/run', '/var/run', process.env.XDG_RUNTIME_DIR].filter((x) => !!x && existsSync(x)).map(x => realpathSync(x));
22
+ return [...new Set(c)];
23
+ }
24
+ /**
25
+ * With the host network, DNS must still work although /run is masked: when resolv.conf really lives under a masked dir
26
+ * (systemd-resolved: /etc/resolv.conf → /run/systemd/resolve/stub-resolv.conf), bind that file back read-only.
27
+ */
28
+ export function dnsBinds(masks, resolv = '/etc/resolv.conf') {
29
+ let real;
30
+ try {
31
+ real = realpathSync(resolv);
32
+ }
33
+ catch {
34
+ return [];
35
+ }
36
+ return masks.some(d => real === d || real.startsWith(d + '/')) ? ['--ro-bind', real, real] : [];
37
+ }
38
+ export function bwrapArgs(o) {
39
+ // Own PID namespace + --die-with-parent: every descendant (even setsid()) dies with the sandbox (Codex R4 N6).
40
+ const a = ['--die-with-parent', ...(o.shareNetwork ? [] : ['--unshare-net']), '--unshare-ipc', '--unshare-uts', '--unshare-pid', '--new-session',
41
+ '--ro-bind', '/', '/', '--dev', '/dev', '--proc', '/proc', '--tmpfs', '/tmp'];
42
+ if (o.hideHome && existsSync(o.home))
43
+ a.push('--tmpfs', realpathSync(o.home));
44
+ for (const d of o.hideDirs ?? [])
45
+ if (existsSync(d))
46
+ a.push('--tmpfs', realpathSync(d));
47
+ const visible = o.mountAt ?? o.writableRoot;
48
+ a.push('--bind', o.writableRoot, visible);
49
+ for (const w of o.extraWritable ?? [])
50
+ a.push('--bind', w, w);
51
+ for (const p of o.readOnly ?? [])
52
+ if (existsSync(p))
53
+ a.push('--ro-bind', p, p);
54
+ for (const { src, dst } of o.readOnlyAt ?? [])
55
+ if (existsSync(src))
56
+ a.push('--ro-bind', src, dst);
57
+ const masks = o.hideHome ? [] : [...new Set([...HOME_SECRET_GLOBS.map(g => g.replace(/\/\*\*$/, '')), ...EXTRA_HOME_MASKS])];
58
+ for (const rel of masks) {
59
+ let p = join(o.home, rel);
60
+ if (!existsSync(p))
61
+ continue;
62
+ // bubblewrap cannot mount over a symlink (WSL: ~/.aws → /mnt/c/…): mask its real target instead.
63
+ if (lstatSync(p).isSymbolicLink()) {
64
+ p = realpathSync(p);
65
+ if (p === '/tmp' || p.startsWith('/tmp/'))
66
+ continue; // target already hidden by the private /tmp
67
+ }
68
+ if (p === visible || visible.startsWith(p + '/'))
69
+ continue;
70
+ if (statSync(p).isDirectory())
71
+ a.push('--tmpfs', p);
72
+ else
73
+ a.push('--ro-bind', '/dev/null', p);
74
+ }
75
+ const maskDirs = o.maskDirs ?? defaultMaskDirs();
76
+ for (const d of maskDirs) {
77
+ if (d === visible || visible.startsWith(d + '/') || !existsSync(d))
78
+ continue;
79
+ a.push('--tmpfs', d);
80
+ }
81
+ if (o.shareNetwork)
82
+ a.push(...dnsBinds(maskDirs));
83
+ // hideFiles are VISIBLE paths: under the clean-room mount (and not under a read-only bind from the host) the file
84
+ // lives in the room, so that is where its existence is checked (Codex CR3 #1).
85
+ const under = (f, d) => f === d || f.startsWith(d + '/');
86
+ const hostOf = (f) => (o.mountAt && under(f, visible) && !(o.readOnly ?? []).some(ro => under(f, ro)) ? join(o.writableRoot, f.slice(visible.length)) : f);
87
+ for (const f of o.hideFiles ?? []) {
88
+ const h = hostOf(f);
89
+ if (existsSync(h) && statSync(h).isFile())
90
+ a.push('--ro-bind', '/dev/null', f);
91
+ }
92
+ a.push('--chdir', o.cwd);
93
+ return a;
94
+ }
95
+ export async function runSandboxedTool(req, o, signal) {
96
+ if (!isAbsolute(req.bin))
97
+ throw new Error(`binary "${req.bin}" must be an absolute path`);
98
+ if (!isAbsolute(o.writableRoot))
99
+ throw new Error(`writable root "${o.writableRoot}" must be an absolute path`);
100
+ if (o.mountAt !== undefined && !isAbsolute(o.mountAt))
101
+ throw new Error(`mount point "${o.mountAt}" must be an absolute path`);
102
+ if (!(await sandboxedToolAvailable()))
103
+ throw new Error('bubblewrap unavailable; refusing to run a repository command unsandboxed (ADR-0010)');
104
+ return runProcess({ ...req, bin: BWRAP, args: [...bwrapArgs({ ...o, cwd: req.cwd }), '--', req.bin, ...req.args] }, signal);
105
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Complete workspace scan (Codex R3/R4 N10): every directory except the top-level .git is walked (dependency trees
3
+ * included), symlinks are never followed, any directory that cannot be listed makes the scan INCOMPLETE (callers fail
4
+ * closed), symlinks whose target is outside the workspace are reported. Produces concrete paths because OS sandboxes
5
+ * take paths, not globs.
6
+ */
7
+ import { readdirSync, realpathSync } from 'node:fs';
8
+ import { matchGlob, SECRET_READ_GLOBS } from '../../../packages/rules/src/index.js';
9
+ const INSTRUCTION_FILES = new Set(['CLAUDE.md', 'AGENTS.md']);
10
+ /** `includeRootGit`: scanning an inherited dependency dir, not a repository — its `.git` is ordinary content. */
11
+ export function scanWorkspace(root, limit = 200_000, o = {}) {
12
+ const r = { complete: true, instructionFiles: [], secretFiles: [], externalLinks: [], links: [], secretLinks: [], entries: 0 };
13
+ const stack = [root];
14
+ while (stack.length) {
15
+ const dir = stack.pop();
16
+ let list;
17
+ try {
18
+ list = readdirSync(dir, { withFileTypes: true });
19
+ }
20
+ catch (e) {
21
+ return { ...r, complete: false, problem: `cannot list ${dir} (${e.code})` };
22
+ }
23
+ for (const e of list) {
24
+ if (++r.entries > limit)
25
+ return { ...r, complete: false, problem: `more than ${limit} entries` };
26
+ const p = `${dir}/${e.name}`;
27
+ const rel = p.slice(root.length + 1);
28
+ if (e.isSymbolicLink()) {
29
+ r.links.push(p);
30
+ if (SECRET_READ_GLOBS.some(g => matchGlob(g, rel)))
31
+ r.secretLinks.push(p);
32
+ try {
33
+ const t = realpathSync(p);
34
+ if (t !== root && !t.startsWith(root + '/'))
35
+ r.externalLinks.push(p);
36
+ }
37
+ catch { /* dangling: nothing reachable */ }
38
+ continue;
39
+ }
40
+ if (e.isDirectory()) {
41
+ if (o.includeRootGit || !(dir === root && e.name === '.git'))
42
+ stack.push(p);
43
+ continue;
44
+ }
45
+ if (INSTRUCTION_FILES.has(e.name) && dir !== root)
46
+ r.instructionFiles.push(p);
47
+ if (SECRET_READ_GLOBS.some(g => matchGlob(g, rel)))
48
+ r.secretFiles.push(p);
49
+ }
50
+ }
51
+ return r;
52
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * claude-mem (thedotmack/claude-mem 15.18.4, Apache-2.0) adapter for MemoryPort — ADR-0009, ADR-0010.
3
+ * Talks to the LOCAL worker HTTP API only (/api/health, /api/search, /api/memory/save). Never loads the plugin's hooks,
4
+ * MCP server or observer into governed runs. Refuses to operate when claude-mem itself is configured to sync off-box.
5
+ * Note: the worker API is unauthenticated on loopback (it only rejects browser cross-origin requests) — any local
6
+ * process can write memories. Recalled text is therefore always framed as untrusted.
7
+ */
8
+ import { readFileSync } from 'node:fs';
9
+ import { homedir } from 'node:os';
10
+ import { join } from 'node:path';
11
+ /** Literal loopback addresses only — `localhost` depends on name resolution (Codex R3). */
12
+ const LOOPBACK = new Set(['127.0.0.1', '[::1]', '::1']);
13
+ const ID_RE = /^[A-Za-z0-9._-]{1,64}$/;
14
+ const OFFBOX_KEYS = ['CLAUDE_MEM_CLOUD_SYNC_TOKEN', 'CLAUDE_MEM_CLOUD_SYNC_HUB_URL', 'CLAUDE_MEM_PRO_MEMORY_KEY', 'CLAUDE_MEM_PRO_MEMORY_BASE_URL'];
15
+ export class ClaudeMemMemory {
16
+ base;
17
+ timeoutMs;
18
+ maxChars;
19
+ settingsFile;
20
+ constructor(o = {}) {
21
+ this.base = new URL(o.baseUrl ?? 'http://127.0.0.1:37700');
22
+ if (this.base.protocol !== 'http:' || !LOOPBACK.has(this.base.hostname))
23
+ throw new Error(`claude-mem worker must be a loopback http URL (ADR-0010 local-only), got ${o.baseUrl}`);
24
+ this.timeoutMs = o.timeoutMs ?? 3000;
25
+ this.maxChars = o.maxRecallChars ?? 8000;
26
+ this.settingsFile = o.settingsFile ?? join(homedir(), '.claude-mem', 'settings.json');
27
+ }
28
+ /** ADR-0010: claude-mem must not be configured to send memories off-box. Unknown configuration ⇒ refuse. Values are never read out. */
29
+ async localOnlyCheck() {
30
+ let raw;
31
+ try {
32
+ raw = JSON.parse(readFileSync(this.settingsFile, 'utf8'));
33
+ }
34
+ catch {
35
+ return { ok: false, reason: `claude-mem settings unreadable (${this.settingsFile}); cannot verify local-only` };
36
+ }
37
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
38
+ return { ok: false, reason: 'claude-mem settings are not an object; cannot verify local-only' };
39
+ const s = raw;
40
+ const badType = OFFBOX_KEYS.filter(k => s[k] !== undefined && typeof s[k] !== 'string');
41
+ if (badType.length)
42
+ return { ok: false, reason: `claude-mem settings have unexpected types (${badType.join(', ')}); cannot verify local-only` };
43
+ const on = OFFBOX_KEYS.filter(k => typeof s[k] === 'string' && s[k].trim() !== '');
44
+ if (on.length)
45
+ return { ok: false, reason: `claude-mem cloud sync / hosted memory is configured (${on.join(', ')}); local-only policy forbids it` };
46
+ if (s.CLAUDE_MEM_WORKER_HOST !== undefined && typeof s.CLAUDE_MEM_WORKER_HOST !== 'string')
47
+ return { ok: false, reason: 'claude-mem CLAUDE_MEM_WORKER_HOST has an unexpected type; cannot verify local-only' };
48
+ const host = typeof s.CLAUDE_MEM_WORKER_HOST === 'string' ? s.CLAUDE_MEM_WORKER_HOST : '127.0.0.1';
49
+ if (!LOOPBACK.has(host))
50
+ return { ok: false, reason: `claude-mem worker host ${host} is not loopback` };
51
+ return { ok: true };
52
+ }
53
+ async call(path, init) {
54
+ const ac = new AbortController();
55
+ const t = setTimeout(() => ac.abort(), this.timeoutMs);
56
+ try {
57
+ const res = await fetch(new URL(path, this.base), { method: init?.method ?? 'GET', body: init?.body, signal: ac.signal, redirect: 'error',
58
+ headers: init ? { 'content-type': 'application/json' } : undefined });
59
+ if (!res.ok)
60
+ throw new Error(`claude-mem ${path} → HTTP ${res.status}`);
61
+ return await res.json();
62
+ }
63
+ finally {
64
+ clearTimeout(t);
65
+ }
66
+ }
67
+ async available() {
68
+ try {
69
+ return (await this.call('/api/health')).status === 'ok';
70
+ }
71
+ catch {
72
+ return false;
73
+ }
74
+ }
75
+ async recall(query, project) {
76
+ try {
77
+ if (!(await this.localOnlyCheck()).ok)
78
+ return undefined;
79
+ const qs = new URLSearchParams({ query: query.slice(0, 500), project, limit: '10' });
80
+ const r = await this.call(`/api/search?${qs}`);
81
+ const text = (r.content ?? []).filter(c => c.type === 'text' && typeof c.text === 'string').map(c => c.text).join('\n');
82
+ if (!text.trim())
83
+ return undefined;
84
+ return { source: 'claude-mem', project, query, text: text.slice(0, this.maxChars), truncated: text.length > this.maxChars };
85
+ }
86
+ catch {
87
+ return undefined;
88
+ }
89
+ }
90
+ async record(s) {
91
+ if (!ID_RE.test(s.runId) || s.runId.includes('..'))
92
+ throw new Error(`invalid runId ${JSON.stringify(s.runId)}`);
93
+ const check = await this.localOnlyCheck();
94
+ if (!check.ok)
95
+ return { recorded: false, reason: check.reason };
96
+ const lines = [
97
+ `Taskquoin governed run ${s.runId} (workflow ${s.workflow}) finished with status ${s.status}.`,
98
+ s.tests ? `Tests: ${s.tests.passed} passed, ${s.tests.failed} failed (verified by Taskquoin, not by the model).` : 'Tests: verified by Taskquoin in its sandbox (see decisions).',
99
+ `Files changed (${s.filesChanged.length}): ${s.filesChanged.slice(0, 50).join(', ') || 'none'}`,
100
+ ...s.decisions.slice(0, 20).map(d => `Decision: ${d.slice(0, 200)}`),
101
+ ];
102
+ try {
103
+ await this.call('/api/memory/save', { method: 'POST', body: JSON.stringify({
104
+ title: `Taskquoin run ${s.runId}: ${s.workflow} ${s.status}`.slice(0, 200), text: lines.join('\n'), project: s.project,
105
+ metadata: { source: 'taskquoin', runId: s.runId, workflow: s.workflow, status: s.status },
106
+ }) });
107
+ return { recorded: true };
108
+ }
109
+ catch (e) {
110
+ return { recorded: false, reason: e.message };
111
+ }
112
+ }
113
+ }
114
+ /** Framing lives in the application layer (used by the workflow); re-exported for compatibility. */
115
+ export { memoryContextBlock } from '../../../packages/application/src/index.js';
@@ -0,0 +1 @@
1
+ export * from "./claude-mem.js";
@@ -0,0 +1 @@
1
+ export * from "./runner.js";
@@ -0,0 +1,123 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { isAbsolute } from 'node:path';
3
+ /**
4
+ * Environment keys a runtime CLI may receive. Credentials for connectors, loader hooks
5
+ * (LD_PRELOAD, NODE_OPTIONS, BASH_ENV…) and endpoint overrides (ANTHROPIC_BASE_URL…) are refused.
6
+ * Runtime auth relies on HOME (OAuth/keychain files), not on env tokens.
7
+ */
8
+ export const ALLOWED_ENV_KEYS = ['PATH', 'HOME', 'USER', 'LOGNAME', 'SHELL', 'LANG', 'LC_ALL', 'LC_CTYPE', 'TERM', 'TZ', 'TMPDIR',
9
+ // traffic-reducing switches only (ADR-0010)
10
+ 'CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC', 'DISABLE_TELEMETRY', 'DISABLE_ERROR_REPORTING', 'DISABLE_AUTOUPDATER', 'BASH_MAX_OUTPUT_LENGTH',
11
+ // set by the orchestrator's git adapter only (temporary index), never passed to agents
12
+ 'GIT_INDEX_FILE',
13
+ // OpenCode isolation (project B): its own dirs, switches and generated config — paths and switches, never a credential
14
+ 'XDG_CONFIG_HOME', 'XDG_DATA_HOME', 'XDG_CACHE_HOME', 'XDG_STATE_HOME',
15
+ 'OPENCODE_DISABLE_AUTOUPDATE', 'OPENCODE_DISABLE_PROJECT_CONFIG', 'OPENCODE_DISABLE_CLAUDE_CODE', 'OPENCODE_DISABLE_MODELS_FETCH',
16
+ 'OPENCODE_DISABLE_LSP_DOWNLOAD', 'OPENCODE_PURE', 'OPENCODE_MODELS_PATH', 'OPENCODE_CONFIG_CONTENT'];
17
+ const TEST_DOUBLE_PREFIX = 'TQ_FAKE_';
18
+ function validate(req) {
19
+ if (!isAbsolute(req.bin))
20
+ throw new Error(`binary "${req.bin}" must be an absolute path (resolved by doctor, never via PATH at run time)`);
21
+ for (const k of Object.keys(req.env)) {
22
+ if (!ALLOWED_ENV_KEYS.includes(k) && !k.startsWith(TEST_DOUBLE_PREFIX))
23
+ throw new Error(`env key "${k}" is not allowed (allowlist: ${ALLOWED_ENV_KEYS.join(', ')})`);
24
+ }
25
+ }
26
+ /** Drop a trailing incomplete UTF-8 sequence so decoding never yields U+FFFD from our own truncation. */
27
+ function trimUtf8(buf) {
28
+ let i = buf.length - 1;
29
+ let cont = 0;
30
+ while (i >= 0 && cont < 3 && (buf[i] & 0xc0) === 0x80) {
31
+ i--;
32
+ cont++;
33
+ }
34
+ if (i < 0)
35
+ return buf;
36
+ const lead = buf[i];
37
+ const need = lead >= 0xf0 ? 3 : lead >= 0xe0 ? 2 : lead >= 0xc0 ? 1 : 0;
38
+ return need > cont ? buf.subarray(0, i) : buf;
39
+ }
40
+ /**
41
+ * Spawn in its own process group with a validated environment, a hard timeout and cancellation that
42
+ * both escalate SIGTERM → SIGKILL on the whole group, and a shared output byte budget.
43
+ * The group is SIGKILLed after the child exits too, so same-group orphans do not survive.
44
+ * Rejects only for invalid requests; child failures are reported in the result.
45
+ */
46
+ export async function runProcess(req, signal) {
47
+ validate(req);
48
+ const started = Date.now();
49
+ if (signal?.aborted)
50
+ return { status: 'cancelled', exitCode: null, signal: null, stdout: '', stderr: '', truncated: false, durationMs: 0 };
51
+ return new Promise((resolve) => {
52
+ const posix = process.platform !== 'win32';
53
+ const child = spawn(req.bin, req.args, { cwd: req.cwd, env: req.env, detached: posix, stdio: ['pipe', 'pipe', 'pipe'] });
54
+ const out = [];
55
+ const err = [];
56
+ let used = 0;
57
+ let truncated = false;
58
+ let reason;
59
+ let settled = false;
60
+ let graceTimer;
61
+ const take = (sink) => (chunk) => {
62
+ const room = req.maxOutputBytes - used;
63
+ if (room <= 0) {
64
+ truncated = true;
65
+ return;
66
+ }
67
+ const part = chunk.length > room ? chunk.subarray(0, room) : chunk;
68
+ if (part.length < chunk.length)
69
+ truncated = true;
70
+ sink.push(part);
71
+ used += part.length;
72
+ };
73
+ child.stdout.on('data', take(out));
74
+ child.stderr.on('data', take(err));
75
+ const killGroup = (sig) => {
76
+ try {
77
+ if (posix && child.pid)
78
+ process.kill(-child.pid, sig);
79
+ else
80
+ child.kill(sig);
81
+ }
82
+ catch { /* group already gone */ }
83
+ };
84
+ const terminate = (why) => {
85
+ if (reason)
86
+ return;
87
+ reason = why;
88
+ killGroup('SIGTERM');
89
+ graceTimer = setTimeout(() => killGroup('SIGKILL'), req.killGraceMs ?? 500);
90
+ };
91
+ const timer = setTimeout(() => terminate('timeout'), req.timeoutMs);
92
+ const onAbort = () => terminate('cancelled');
93
+ signal?.addEventListener('abort', onAbort, { once: true });
94
+ const finish = (exitCode, sig) => {
95
+ if (settled)
96
+ return;
97
+ settled = true;
98
+ clearTimeout(timer);
99
+ if (graceTimer)
100
+ clearTimeout(graceTimer);
101
+ signal?.removeEventListener('abort', onAbort);
102
+ killGroup('SIGKILL'); // reap anything left in the group, whether or not we initiated termination
103
+ const status = reason ?? (exitCode === 0 ? 'completed' : 'failed');
104
+ resolve({
105
+ status, exitCode, signal: sig,
106
+ stdout: trimUtf8(Buffer.concat(out)).toString('utf8'), stderr: trimUtf8(Buffer.concat(err)).toString('utf8'),
107
+ truncated, durationMs: Date.now() - started,
108
+ });
109
+ };
110
+ child.on('error', (e) => { take(err)(Buffer.from(String(e))); finish(null, null); });
111
+ child.on('close', finish);
112
+ child.stdin.on('error', () => { });
113
+ child.stdin.end(req.stdin ?? '');
114
+ });
115
+ }
116
+ /** Run `<bin> [prefix] --version` and return the first x.y.z, only if the process succeeded (Codex R3: ignore failures). */
117
+ export async function verifyBinaryVersion(bin, prefixArgs = [], env = {}) {
118
+ const r = await runProcess({ bin, args: [...prefixArgs, '--version'], cwd: '/', env: { PATH: env.PATH ?? '', ...(env.HOME ? { HOME: env.HOME } : {}) }, timeoutMs: 15_000, maxOutputBytes: 10_000 });
119
+ const v = /\b(\d+\.\d+\.\d+)\b/.exec(r.stdout)?.[1];
120
+ if (r.status !== 'completed' || !v)
121
+ throw new Error(`cannot verify the version of ${bin} (status ${r.status})`);
122
+ return v;
123
+ }
@@ -0,0 +1,116 @@
1
+ {
2
+ "runtime": "api",
3
+ "runtimeVersion": "1",
4
+ "measuredOn": "2026-11-16",
5
+ "evidence": "By construction, proven by deterministic tests against a local fake provider (adapters/runtime-api/test/executor.test.ts). The provider itself receives the code: that is the project's explicit consent (providers listed in taskquoin.yaml, ADR-0016).",
6
+ "entries": {
7
+ "fs.read": [
8
+ {
9
+ "class": "ENFORCED",
10
+ "granularity": "pattern",
11
+ "holdsFor": [
12
+ "deny-all"
13
+ ],
14
+ "evidence": "measured",
15
+ "mechanism": "no tool interface: the adapter sends one text request and reads one text answer \u2014 the model gets no file, shell, network, VCS, connector or configuration access; tool calls in an answer fail the run",
16
+ "evidenceRef": "adapters/runtime-api/test/executor.test.ts (request body without tools; tool_calls \u2192 failed; redirect refused)"
17
+ }
18
+ ],
19
+ "fs.write": [
20
+ {
21
+ "class": "ENFORCED",
22
+ "granularity": "pattern",
23
+ "holdsFor": [
24
+ "deny-all"
25
+ ],
26
+ "evidence": "measured",
27
+ "mechanism": "no tool interface: the adapter sends one text request and reads one text answer \u2014 the model gets no file, shell, network, VCS, connector or configuration access; tool calls in an answer fail the run",
28
+ "evidenceRef": "adapters/runtime-api/test/executor.test.ts (request body without tools; tool_calls \u2192 failed; redirect refused)"
29
+ }
30
+ ],
31
+ "shell.run": [
32
+ {
33
+ "class": "ENFORCED",
34
+ "granularity": "pattern",
35
+ "holdsFor": [
36
+ "deny-all"
37
+ ],
38
+ "evidence": "measured",
39
+ "mechanism": "no tool interface: the adapter sends one text request and reads one text answer \u2014 the model gets no file, shell, network, VCS, connector or configuration access; tool calls in an answer fail the run",
40
+ "evidenceRef": "adapters/runtime-api/test/executor.test.ts (request body without tools; tool_calls \u2192 failed; redirect refused)"
41
+ }
42
+ ],
43
+ "net.egress": [
44
+ {
45
+ "class": "ENFORCED",
46
+ "granularity": "pattern",
47
+ "holdsFor": [
48
+ "deny-all"
49
+ ],
50
+ "evidence": "measured",
51
+ "mechanism": "no tool interface: the adapter sends one text request and reads one text answer \u2014 the model gets no file, shell, network, VCS, connector or configuration access; tool calls in an answer fail the run",
52
+ "evidenceRef": "adapters/runtime-api/test/executor.test.ts (request body without tools; tool_calls \u2192 failed; redirect refused)"
53
+ }
54
+ ],
55
+ "vcs.commit": [
56
+ {
57
+ "class": "ENFORCED",
58
+ "granularity": "pattern",
59
+ "holdsFor": [
60
+ "deny-all"
61
+ ],
62
+ "evidence": "measured",
63
+ "mechanism": "no tool interface: the adapter sends one text request and reads one text answer \u2014 the model gets no file, shell, network, VCS, connector or configuration access; tool calls in an answer fail the run",
64
+ "evidenceRef": "adapters/runtime-api/test/executor.test.ts (request body without tools; tool_calls \u2192 failed; redirect refused)"
65
+ }
66
+ ],
67
+ "vcs.push": [
68
+ {
69
+ "class": "ENFORCED",
70
+ "granularity": "pattern",
71
+ "holdsFor": [
72
+ "deny-all"
73
+ ],
74
+ "evidence": "measured",
75
+ "mechanism": "no tool interface: the adapter sends one text request and reads one text answer \u2014 the model gets no file, shell, network, VCS, connector or configuration access; tool calls in an answer fail the run",
76
+ "evidenceRef": "adapters/runtime-api/test/executor.test.ts (request body without tools; tool_calls \u2192 failed; redirect refused)"
77
+ }
78
+ ],
79
+ "connector.read": [
80
+ {
81
+ "class": "ENFORCED",
82
+ "granularity": "pattern",
83
+ "holdsFor": [
84
+ "deny-all"
85
+ ],
86
+ "evidence": "measured",
87
+ "mechanism": "no tool interface: the adapter sends one text request and reads one text answer \u2014 the model gets no file, shell, network, VCS, connector or configuration access; tool calls in an answer fail the run",
88
+ "evidenceRef": "adapters/runtime-api/test/executor.test.ts (request body without tools; tool_calls \u2192 failed; redirect refused)"
89
+ }
90
+ ],
91
+ "connector.write": [
92
+ {
93
+ "class": "ENFORCED",
94
+ "granularity": "pattern",
95
+ "holdsFor": [
96
+ "deny-all"
97
+ ],
98
+ "evidence": "measured",
99
+ "mechanism": "no tool interface: the adapter sends one text request and reads one text answer \u2014 the model gets no file, shell, network, VCS, connector or configuration access; tool calls in an answer fail the run",
100
+ "evidenceRef": "adapters/runtime-api/test/executor.test.ts (request body without tools; tool_calls \u2192 failed; redirect refused)"
101
+ }
102
+ ],
103
+ "config.modify": [
104
+ {
105
+ "class": "ENFORCED",
106
+ "granularity": "pattern",
107
+ "holdsFor": [
108
+ "deny-all"
109
+ ],
110
+ "evidence": "measured",
111
+ "mechanism": "no tool interface: the adapter sends one text request and reads one text answer \u2014 the model gets no file, shell, network, VCS, connector or configuration access; tool calls in an answer fail the run",
112
+ "evidenceRef": "adapters/runtime-api/test/executor.test.ts (request body without tools; tool_calls \u2192 failed; redirect refused)"
113
+ }
114
+ ]
115
+ }
116
+ }
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Text-only judge over an OpenAI-compatible chat API (multi-LLM project A, ADR-0016). One request, one answer:
3
+ * `POST <url>/chat/completions` with the agent's instructions (system) and the task (user) — no tools, no functions,
4
+ * no temperature. Redirects are refused (the code never goes to another host). 429 / 5xx / timeouts / network errors
5
+ * are retried twice (2 s, 8 s, or a Retry-After under 30 s), then TransientProviderError is thrown so the workflow
6
+ * stops in a resumable state. The key is read from the environment at call time and never appears anywhere else.
7
+ */
8
+ import { assertTicket, invocationDigest } from '../../../packages/application/src/index.js';
9
+ import { normalizeGrants } from '../../../packages/domain/src/index.js';
10
+ export const API_RUNTIME_VERSION = '1';
11
+ const RETRY_WAITS_MS = [2000, 8000];
12
+ const MAX_RETRY_AFTER_S = 30;
13
+ const MAX_ERROR_CHARS = 300;
14
+ /** The provider kept failing in a way that may pass later (rate limit, outage, timeout): the run can be resumed. */
15
+ export class TransientProviderError extends Error {
16
+ constructor(message) { super(message); this.name = 'TransientProviderError'; }
17
+ }
18
+ async function readCapped(res, cap) {
19
+ if (!res.body)
20
+ return { text: '', truncated: false };
21
+ const reader = res.body.getReader();
22
+ const chunks = [];
23
+ let size = 0;
24
+ for (;;) {
25
+ const { done, value } = await reader.read();
26
+ if (done)
27
+ break;
28
+ size += value.byteLength;
29
+ if (size > cap) {
30
+ await reader.cancel();
31
+ return { text: '', truncated: true };
32
+ }
33
+ chunks.push(value);
34
+ }
35
+ return { text: Buffer.concat(chunks).toString('utf8'), truncated: false };
36
+ }
37
+ export class ApiExecutor {
38
+ runtime = 'api';
39
+ p;
40
+ env;
41
+ sleep;
42
+ constructor(p, o = {}) {
43
+ this.p = p;
44
+ this.env = o.env ?? process.env;
45
+ this.sleep = o.sleep ?? ((ms) => new Promise(r => setTimeout(r, ms)));
46
+ }
47
+ async run(req, signal) {
48
+ assertTicket(req.ticket, 'api', API_RUNTIME_VERSION, req.agent.capabilities, req.agent.id);
49
+ if (Object.keys(normalizeGrants(req.agent.capabilities)).length)
50
+ throw new Error('refusing: an api judge has no capability (text in, text out)');
51
+ const started = Date.now();
52
+ const endpoint = this.p.url.replace(/\/+$/, '') + '/chat/completions';
53
+ const origin = new URL(endpoint).origin;
54
+ const base = { runtime: 'api', runtimeVersion: API_RUNTIME_VERSION, exitCode: null,
55
+ command: { bin: origin, args: [this.p.model], cwd: req.cwd },
56
+ effectiveConfigDigest: invocationDigest(origin, [this.p.model, this.p.tokenField, String(this.p.maxOutputTokens)], {}),
57
+ inventory: { tools: [], mcpServers: [], plugins: [], skills: [], agents: [req.agent.id], model: this.p.model }, unsupported: [] };
58
+ const key = this.p.keyEnv ? this.env[this.p.keyEnv] : undefined;
59
+ // The key is removed from the WHOLE text first, then cut (cutting first could leave a fragment of the key).
60
+ const scrub = (s) => (key ? s.split(key).join('[redacted]') : s);
61
+ const redact = (s) => scrub(s).slice(0, MAX_ERROR_CHARS);
62
+ const done = (status, extra) => ({ ...base, status, stdoutTruncated: false, stderr: '', durationMs: Date.now() - started, ...extra });
63
+ if (this.p.keyEnv && !key?.trim())
64
+ return done('failed', { stderr: `${this.p.id}: ${this.p.keyEnv} absente — rien n'a été envoyé` });
65
+ const body = JSON.stringify({ model: this.p.model, messages: [{ role: 'system', content: req.agent.prompt }, { role: 'user', content: req.task }],
66
+ [this.p.tokenField]: this.p.maxOutputTokens, stream: false });
67
+ for (let attempt = 0;; attempt++) {
68
+ const o = await this.attempt(endpoint, body, key, req.maxOutputBytes, signal);
69
+ if (signal?.aborted)
70
+ return done('cancelled', { stderr: 'cancelled' });
71
+ if (o.kind === 'ok') {
72
+ const n = (x) => (typeof x === 'number' && Number.isFinite(x) && x >= 0 ? x : undefined); // never trust a provider's types
73
+ const inputTokens = n(o.usage?.prompt_tokens), outputTokens = n(o.usage?.completion_tokens);
74
+ return done('completed', { exitCode: 0, terminalMessage: scrub(o.content), // a provider echoing the key never gets it stored
75
+ usage: { ...(inputTokens !== undefined ? { inputTokens } : {}), ...(outputTokens !== undefined ? { outputTokens } : {}) } });
76
+ }
77
+ if (o.kind === 'fail')
78
+ return done('failed', { stderr: redact(`${this.p.id}: ${o.why}`), stdoutTruncated: !!o.truncated });
79
+ if (attempt >= RETRY_WAITS_MS.length)
80
+ throw new TransientProviderError(redact(`${this.p.id}: ${o.why} (after ${attempt + 1} attempts)`));
81
+ await this.sleep(o.retryAfterS !== undefined && o.retryAfterS < MAX_RETRY_AFTER_S ? o.retryAfterS * 1000 : RETRY_WAITS_MS[attempt]);
82
+ }
83
+ }
84
+ async attempt(endpoint, body, key, cap, signal) {
85
+ let res;
86
+ try {
87
+ res = await fetch(endpoint, { method: 'POST', body, redirect: 'error',
88
+ headers: { 'content-type': 'application/json', accept: 'application/json', ...(key ? { authorization: `Bearer ${key}` } : {}) },
89
+ signal: AbortSignal.any([AbortSignal.timeout(this.p.timeoutSeconds * 1000), ...(signal ? [signal] : [])]) });
90
+ }
91
+ catch (e) {
92
+ const err = e;
93
+ const msg = `${err.message} ${err.cause?.message ?? ''}`;
94
+ if (/redirect/i.test(msg))
95
+ return { kind: 'fail', why: 'redirect refused — the code is never sent to another host' };
96
+ return { kind: 'transient', why: err.name === 'TimeoutError' ? `no answer within ${this.p.timeoutSeconds} s` : `network error (${msg.trim()})` };
97
+ }
98
+ let read;
99
+ try {
100
+ read = await readCapped(res, cap);
101
+ }
102
+ catch (e) {
103
+ return { kind: 'transient', why: `connection lost while reading (${e.message})` };
104
+ }
105
+ if (res.status === 429 || res.status >= 500) {
106
+ const ra = Number(res.headers.get('retry-after'));
107
+ return { kind: 'transient', why: `HTTP ${res.status}`, ...(Number.isFinite(ra) && ra >= 0 && res.headers.get('retry-after') ? { retryAfterS: ra } : {}) };
108
+ }
109
+ if (res.status >= 300)
110
+ return { kind: 'fail', why: `HTTP ${res.status}: ${read.text}` }; // cut AFTER the key is removed (run)
111
+ if (read.truncated)
112
+ return { kind: 'fail', why: 'answer larger than the output budget', truncated: true };
113
+ let data;
114
+ try {
115
+ data = JSON.parse(read.text);
116
+ }
117
+ catch {
118
+ return { kind: 'fail', why: 'the answer is not JSON (proxy or wrong url?)' };
119
+ }
120
+ const m = data?.choices?.[0]?.message;
121
+ if (!m)
122
+ return { kind: 'fail', why: 'no choices[0].message in the answer' };
123
+ if (Array.isArray(m.tool_calls) && m.tool_calls.length)
124
+ return { kind: 'fail', why: 'the model asked for tools — a judge answers with text only' };
125
+ if (data.choices[0].finish_reason === 'length')
126
+ return { kind: 'fail', why: `réponse coupée à maxOutputTokens ${this.p.maxOutputTokens} — augmentez providers.${this.p.id}.maxOutputTokens dans taskquoin.yaml` };
127
+ if (typeof m.content !== 'string' || !m.content.trim())
128
+ return { kind: 'fail', why: 'empty answer' };
129
+ return { kind: 'ok', content: m.content, ...(data.usage ? { usage: data.usage } : {}) };
130
+ }
131
+ }
@@ -0,0 +1 @@
1
+ export * from "./executor.js";