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.
- package/CHANGELOG.md +62 -0
- package/LICENSE +55 -0
- package/README.md +227 -2
- package/SECURITY.md +26 -0
- package/adapters/git/src/git.js +250 -0
- package/adapters/git/src/index.js +1 -0
- package/adapters/hooks-claude/src/canonical.js +45 -0
- package/adapters/hooks-claude/src/index.js +2 -0
- package/adapters/hooks-claude/src/main.js +58 -0
- package/adapters/hooks-claude/src/payload.js +40 -0
- package/adapters/host-probe/src/index.js +2 -0
- package/adapters/host-probe/src/ollama.js +18 -0
- package/adapters/host-probe/src/probe.js +107 -0
- package/adapters/local-tool/src/fingerprint.js +56 -0
- package/adapters/local-tool/src/index.js +4 -0
- package/adapters/local-tool/src/local-tool.js +22 -0
- package/adapters/local-tool/src/sandboxed.js +105 -0
- package/adapters/local-tool/src/scan.js +52 -0
- package/adapters/memory-claude-mem/src/claude-mem.js +115 -0
- package/adapters/memory-claude-mem/src/index.js +1 -0
- package/adapters/process-runner/src/index.js +1 -0
- package/adapters/process-runner/src/runner.js +123 -0
- package/adapters/runtime-api/src/capabilities.json +116 -0
- package/adapters/runtime-api/src/executor.js +131 -0
- package/adapters/runtime-api/src/index.js +1 -0
- package/adapters/runtime-claude/src/capabilities.json +375 -0
- package/adapters/runtime-claude/src/command.js +34 -0
- package/adapters/runtime-claude/src/executor.js +162 -0
- package/adapters/runtime-claude/src/index.js +4 -0
- package/adapters/runtime-claude/src/permissions.js +76 -0
- package/adapters/runtime-claude/src/stream.js +60 -0
- package/adapters/runtime-codex/src/capabilities.json +192 -0
- package/adapters/runtime-codex/src/command.js +36 -0
- package/adapters/runtime-codex/src/executor.js +83 -0
- package/adapters/runtime-codex/src/index.js +4 -0
- package/adapters/runtime-codex/src/scratch.js +32 -0
- package/adapters/runtime-codex/src/stream.js +39 -0
- package/adapters/runtime-opencode/src/capabilities.json +149 -0
- package/adapters/runtime-opencode/src/config.js +33 -0
- package/adapters/runtime-opencode/src/credentials.js +130 -0
- package/adapters/runtime-opencode/src/executor.js +127 -0
- package/adapters/runtime-opencode/src/facts.js +43 -0
- package/adapters/runtime-opencode/src/hosts.js +16 -0
- package/adapters/runtime-opencode/src/hosts.json +3 -0
- package/adapters/runtime-opencode/src/index.js +6 -0
- package/adapters/runtime-opencode/src/mounts.js +58 -0
- package/adapters/runtime-opencode/src/stream.js +63 -0
- package/adapters/skill-store/src/index.js +1 -0
- package/adapters/skill-store/src/skill-store.js +162 -0
- package/adapters/store-fs/src/index.js +2 -0
- package/adapters/store-fs/src/store.js +201 -0
- package/adapters/store-fs/src/trusted-dir.js +37 -0
- package/apps/cli/src/console.js +432 -0
- package/apps/cli/src/dashboard-approve.js +259 -0
- package/apps/cli/src/dashboard-data.js +424 -0
- package/apps/cli/src/dashboard.js +500 -0
- package/apps/cli/src/history.js +35 -0
- package/apps/cli/src/home.js +18 -0
- package/apps/cli/src/i18n/en.js +527 -0
- package/apps/cli/src/i18n/index.js +90 -0
- package/apps/cli/src/i18n/languages.js +25 -0
- package/apps/cli/src/i18n/locales/ar.json +526 -0
- package/apps/cli/src/i18n/locales/de.json +505 -0
- package/apps/cli/src/i18n/locales/es.json +505 -0
- package/apps/cli/src/i18n/locales/fa.json +505 -0
- package/apps/cli/src/i18n/locales/fr.json +505 -0
- package/apps/cli/src/i18n/locales/he.json +505 -0
- package/apps/cli/src/i18n/locales/hi.json +505 -0
- package/apps/cli/src/i18n/locales/id.json +491 -0
- package/apps/cli/src/i18n/locales/it.json +505 -0
- package/apps/cli/src/i18n/locales/ja.json +491 -0
- package/apps/cli/src/i18n/locales/ko.json +491 -0
- package/apps/cli/src/i18n/locales/nl.json +505 -0
- package/apps/cli/src/i18n/locales/pl.json +512 -0
- package/apps/cli/src/i18n/locales/pt-BR.json +505 -0
- package/apps/cli/src/i18n/locales/ru.json +512 -0
- package/apps/cli/src/i18n/locales/th.json +491 -0
- package/apps/cli/src/i18n/locales/tr.json +505 -0
- package/apps/cli/src/i18n/locales/uk.json +512 -0
- package/apps/cli/src/i18n/locales/vi.json +491 -0
- package/apps/cli/src/i18n/locales/zh-CN.json +491 -0
- package/apps/cli/src/i18n/locales/zh-TW.json +491 -0
- package/apps/cli/src/i18n/width.js +40 -0
- package/apps/cli/src/layout.js +18 -0
- package/apps/cli/src/main.js +830 -0
- package/apps/cli/src/preferences.js +46 -0
- package/apps/cli/src/runtime-notices.js +41 -0
- package/apps/cli/src/safe-text.js +3 -0
- package/apps/cli/src/shortcut.js +82 -0
- package/apps/cli/src/skills-cli.js +112 -0
- package/apps/cli/src/tui/caps.js +31 -0
- package/apps/cli/src/tui/components/agent-list.js +58 -0
- package/apps/cli/src/tui/components/approval-center.js +145 -0
- package/apps/cli/src/tui/components/approval.js +95 -0
- package/apps/cli/src/tui/components/dashboard-frame.js +293 -0
- package/apps/cli/src/tui/components/diff-viewer.js +549 -0
- package/apps/cli/src/tui/components/event-viewer.js +46 -0
- package/apps/cli/src/tui/components/help-panel.js +59 -0
- package/apps/cli/src/tui/components/home.js +185 -0
- package/apps/cli/src/tui/components/logo.js +67 -0
- package/apps/cli/src/tui/components/panel.js +70 -0
- package/apps/cli/src/tui/components/status-bar.js +96 -0
- package/apps/cli/src/tui/components/timeline.js +120 -0
- package/apps/cli/src/tui/keys.js +139 -0
- package/apps/cli/src/tui/neutral.js +68 -0
- package/apps/cli/src/tui/screen.js +111 -0
- package/apps/cli/src/tui/text.js +165 -0
- package/apps/cli/src/tui/tokens.js +89 -0
- package/apps/cli/src/tui/view.js +64 -0
- package/apps/cli/src/upgrade-check.js +86 -0
- package/apps/cli/src/upgrade-cli.js +168 -0
- package/apps/cli/src/workflow-cli.js +674 -0
- package/package.json +29 -4
- package/packages/application/src/index.js +8 -0
- package/packages/application/src/lib/digest.js +7 -0
- package/packages/application/src/ports/memory.js +1 -0
- package/packages/application/src/ports/runtime-executor.js +1 -0
- package/packages/application/src/projection/run-view.js +194 -0
- package/packages/application/src/projection/squad-view.js +33 -0
- package/packages/application/src/use-cases/prepare-run.js +68 -0
- package/packages/application/src/workflow/feature-governed.js +420 -0
- package/packages/application/src/workflow/gate-signals.js +40 -0
- package/packages/application/src/workflow/prompts.js +81 -0
- package/packages/config/src/config.js +372 -0
- package/packages/config/src/index.js +1 -0
- package/packages/domain/src/capabilities.js +13 -0
- package/packages/domain/src/capability-matrix.js +63 -0
- package/packages/domain/src/enforcement.js +95 -0
- package/packages/domain/src/index.js +4 -0
- package/packages/domain/src/policy.js +32 -0
- package/packages/rules/src/glob.js +47 -0
- package/packages/rules/src/index.js +5 -0
- package/packages/rules/src/inherit.js +19 -0
- package/packages/rules/src/lists.js +41 -0
- package/packages/rules/src/rules.js +79 -0
- package/packages/rules/src/shell.js +83 -0
- package/packages/skills/src/index.js +1 -0
- package/packages/skills/src/skills.js +108 -0
- package/skills/code-review/SKILL.md +51 -0
- package/skills/egm-design/LICENSE +202 -0
- package/skills/egm-design/SKILL.md +68 -0
- package/skills/egm-design/references/feature-spec-standard.md +39 -0
- package/skills/egm-implementation-readiness/LICENSE +202 -0
- package/skills/egm-implementation-readiness/SKILL.md +67 -0
- package/skills/egm-implementation-readiness/references/implementation-readiness-standard.md +37 -0
- package/skills/first-party.lock.json +10 -0
- package/skills/planning-contract/SKILL.md +51 -0
- package/skills/ponytail/LICENSE +21 -0
- package/skills/ponytail/SKILL.md +56 -0
- package/skills/security-review/SKILL.md +58 -0
- package/skills/tdd/SKILL.md +52 -0
- package/skills/unslop/LICENSE +396 -0
- package/skills/unslop/SKILL.md +239 -0
- package/skills/unslop/references/cjk.md +34 -0
- package/skills/unslop/references/effects.md +113 -0
- package/skills/unslop/references/refs.md +17 -0
- package/skills/unslop/references/rtl.md +111 -0
- package/skills/unslop/references/signs.md +122 -0
- package/skills/unslop/references/tokens.md +139 -0
- package/skills/unslop/references/visuals.md +84 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orchestrator-side git (host). Never by an agent (ADR-0011). Tree-based governance (ADR-0013, Codex R4 N1/N2):
|
|
3
|
+
* - every invocation disables repository hooks and fsmonitor (no repository-controlled code runs on the host);
|
|
4
|
+
* - the candidate is a tree id computed through a TEMPORARY index (the developer's index is never touched);
|
|
5
|
+
* - diffs and policy checks are tree-to-tree, NUL-delimited, without rename detection;
|
|
6
|
+
* - the commit is `git commit-tree <approved tree> -p <expected parent>` + compare-and-swap `update-ref`:
|
|
7
|
+
* exactly the approved tree, on the expected parent, without hooks or filters.
|
|
8
|
+
*/
|
|
9
|
+
import { mkdtempSync, readdirSync, rmSync } from 'node:fs';
|
|
10
|
+
import { isAbsolute, join } from 'node:path';
|
|
11
|
+
import { runProcess } from '../../process-runner/src/index.js';
|
|
12
|
+
const BRANCH_RE = /^taskquoin\/[A-Za-z0-9._-]{1,64}$/;
|
|
13
|
+
const OID_RE = /^[0-9a-f]{40}$/;
|
|
14
|
+
/** Safe defaults for every git call made by Taskquoin. */
|
|
15
|
+
export const SAFE_GIT_CONFIG = ['-c', 'core.hooksPath=/dev/null', '-c', 'core.fsmonitor=false', '-c', 'core.quotePath=false', '-c', 'diff.renames=false'];
|
|
16
|
+
export class GitWorkspace {
|
|
17
|
+
o;
|
|
18
|
+
constructor(o) { this.o = o; }
|
|
19
|
+
async git(args, extraEnv = {}, maxOutputBytes = 64 * 1024 * 1024) {
|
|
20
|
+
const r = await runProcess({ bin: this.o.gitBin, args: [...SAFE_GIT_CONFIG, ...args], cwd: this.o.cwd, env: { ...this.o.env, ...extraEnv }, timeoutMs: 120_000, maxOutputBytes });
|
|
21
|
+
if (r.status !== 'completed')
|
|
22
|
+
throw new Error(`git ${args[0]} failed: ${r.stderr.slice(0, 500)}`);
|
|
23
|
+
if (r.truncated)
|
|
24
|
+
throw new Error(`git ${args[0]} output exceeded the limit`);
|
|
25
|
+
return r.stdout;
|
|
26
|
+
}
|
|
27
|
+
async isClean() { return (await this.git(['status', '--porcelain'])).trim() === ''; }
|
|
28
|
+
async head() { return (await this.git(['rev-parse', 'HEAD'])).trim(); }
|
|
29
|
+
async currentBranch() { return (await this.git(['rev-parse', '--abbrev-ref', 'HEAD'])).trim(); }
|
|
30
|
+
async branchHead(branch) { return (await this.git(['rev-parse', `refs/heads/${branch}`])).trim(); }
|
|
31
|
+
async startRunBranch(name) {
|
|
32
|
+
if (!BRANCH_RE.test(name) || name.includes('..'))
|
|
33
|
+
throw new Error(`invalid branch name ${JSON.stringify(name)}`);
|
|
34
|
+
const base = await this.head();
|
|
35
|
+
await this.git(['switch', '-q', '-c', name]);
|
|
36
|
+
return base;
|
|
37
|
+
}
|
|
38
|
+
/** Tree id of the working tree (tracked + untracked-not-ignored) relative to `base`, via a temporary index. */
|
|
39
|
+
async candidateTree(base) {
|
|
40
|
+
if (!OID_RE.test(base))
|
|
41
|
+
throw new Error('invalid base commit');
|
|
42
|
+
const dir = mkdtempSync(join(this.o.scratchDir, 'idx-'));
|
|
43
|
+
const env = { GIT_INDEX_FILE: join(dir, 'index') };
|
|
44
|
+
try {
|
|
45
|
+
await this.git(['read-tree', base], env);
|
|
46
|
+
await this.git(['add', '-A'], env);
|
|
47
|
+
return (await this.git(['write-tree'], env)).trim();
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
rmSync(dir, { recursive: true, force: true });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** The entry at exactly `path` in `treeish` (ls-tree output filtered on the exact name), or undefined. */
|
|
54
|
+
async treeEntry(treeish, path) {
|
|
55
|
+
for (const line of (await this.git(['ls-tree', '-z', treeish, '--', path])).split('\0')) {
|
|
56
|
+
const tab = line.indexOf('\t');
|
|
57
|
+
if (tab < 0 || line.slice(tab + 1) !== path)
|
|
58
|
+
continue;
|
|
59
|
+
const [mode, , oid] = line.slice(0, tab).split(' ');
|
|
60
|
+
return { mode, oid };
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
/** Write exactly `tree` into the empty directory `dir` (clean room, ADR-0014): no .git, no ignored files. */
|
|
65
|
+
async materialize(tree, dir) {
|
|
66
|
+
if (!OID_RE.test(tree))
|
|
67
|
+
throw new Error('invalid tree id');
|
|
68
|
+
if (!isAbsolute(dir) || readdirSync(dir).length)
|
|
69
|
+
throw new Error(`clean room ${dir} is not empty`);
|
|
70
|
+
const idx = mkdtempSync(join(this.o.scratchDir, 'idx-'));
|
|
71
|
+
const env = { GIT_INDEX_FILE: join(idx, 'index') };
|
|
72
|
+
try {
|
|
73
|
+
await this.git(['read-tree', tree], env);
|
|
74
|
+
await this.git(['checkout-index', '-a', `--prefix=${dir.endsWith('/') ? dir : dir + '/'}`], env);
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
rmSync(idx, { recursive: true, force: true });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Tree id of a directory outside the repository (e.g. the clean room after the tests), relative to `base`. */
|
|
81
|
+
async dirTree(dir, base) {
|
|
82
|
+
if (!OID_RE.test(base) || !isAbsolute(dir))
|
|
83
|
+
throw new Error('invalid base or directory');
|
|
84
|
+
const idx = mkdtempSync(join(this.o.scratchDir, 'idx-'));
|
|
85
|
+
const env = { GIT_INDEX_FILE: join(idx, 'index') };
|
|
86
|
+
try {
|
|
87
|
+
await this.git(['read-tree', base], env);
|
|
88
|
+
await this.git(['--work-tree', dir, 'add', '-A'], env);
|
|
89
|
+
return (await this.git(['write-tree'], env)).trim();
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
rmSync(idx, { recursive: true, force: true });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Paths of the working directory that an ignore rule matches, collapsed at the matching directory (`node_modules`,
|
|
97
|
+
* not its files; not `apps/` merely because it only holds ignored files). `--no-optional-locks`: the developer's
|
|
98
|
+
* index is never refreshed or written.
|
|
99
|
+
*/
|
|
100
|
+
async ignoredEntries() {
|
|
101
|
+
const out = await this.git(['--no-optional-locks', 'status', '--porcelain=v1', '-z', '--ignored=matching', '--untracked-files=normal']);
|
|
102
|
+
return out.split('\0').filter(l => l.startsWith('!! ')).map(l => l.slice(3))
|
|
103
|
+
.map(p => (p.endsWith('/') ? { path: p.slice(0, -1), dir: true } : { path: p, dir: false }));
|
|
104
|
+
}
|
|
105
|
+
/** base tree + only the changed paths accepted by `isTest` (deletions included): the tree that must FAIL (RED proof). */
|
|
106
|
+
async redTree(base, green, isTest) {
|
|
107
|
+
const changed = (await this.changes(base, green)).filter(c => isTest(c.path));
|
|
108
|
+
const dir = mkdtempSync(join(this.o.scratchDir, 'idx-'));
|
|
109
|
+
const env = { GIT_INDEX_FILE: join(dir, 'index') };
|
|
110
|
+
try {
|
|
111
|
+
await this.git(['read-tree', base], env);
|
|
112
|
+
for (const c of changed) {
|
|
113
|
+
if (c.status === 'D') {
|
|
114
|
+
await this.git(['update-index', '--force-remove', '--', c.path], env);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const e = await this.treeEntry(green, c.path);
|
|
118
|
+
if (!e)
|
|
119
|
+
throw new Error(`changed path ${JSON.stringify(c.path)} not found in the verified tree`);
|
|
120
|
+
await this.git(['update-index', '--add', '--cacheinfo', `${e.mode},${e.oid},${c.path}`], env);
|
|
121
|
+
}
|
|
122
|
+
return (await this.git(['write-tree'], env)).trim();
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
rmSync(dir, { recursive: true, force: true });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The diff a JUDGE receives (multi-LLM A3): per changed path, in order. Never sent to a judge (placeholders instead):
|
|
130
|
+
* a path `isSecret` accepts; a binary change (git's verdict OR a NUL byte in either side — .gitattributes cannot force
|
|
131
|
+
* text); and any file containing a line of a secret file of the base or the candidate tree (a renamed or copied
|
|
132
|
+
* secret, final review). The human approves the full diff.
|
|
133
|
+
*/
|
|
134
|
+
async judgeDiff(base, tree, isSecret) {
|
|
135
|
+
const parts = [];
|
|
136
|
+
for (const e of (await this.judgeView(base, tree, isSecret)).entries) {
|
|
137
|
+
if (e.kind === 'secret')
|
|
138
|
+
parts.push(`[fichier secret modifié : ${e.path} — contenu non envoyé]`);
|
|
139
|
+
else if (e.kind === 'binary')
|
|
140
|
+
parts.push(`[changement binaire : ${e.path}]`);
|
|
141
|
+
else if (e.kind === 'secret-content')
|
|
142
|
+
parts.push(`[fichier masqué : contient des lignes d'un fichier secret — ${e.path}]`);
|
|
143
|
+
else
|
|
144
|
+
parts.push((await this.git(['diff', '--no-color', '--no-renames', '--no-ext-diff', '--no-textconv', base, tree, '--', `:(literal)${e.path}`])).replace(/\n$/, ''));
|
|
145
|
+
}
|
|
146
|
+
return parts.join('\n') + (parts.length ? '\n' : '');
|
|
147
|
+
}
|
|
148
|
+
/** Full new text of the added/modified files a judge may see (see judgeDiff), in path order, within `budgetChars`. */
|
|
149
|
+
async changedTexts(base, tree, isSecret, budgetChars) {
|
|
150
|
+
const view = await this.judgeView(base, tree, isSecret);
|
|
151
|
+
const wanted = view.entries.filter(e => e.kind === 'text' && e.status !== 'D');
|
|
152
|
+
const out = [];
|
|
153
|
+
let used = 0;
|
|
154
|
+
for (let i = 0; i < wanted.length; i++) {
|
|
155
|
+
const text = view.newText.get(wanted[i].path);
|
|
156
|
+
if (used + text.length > budgetChars) {
|
|
157
|
+
out.push({ path: '…', text: `[budget atteint : ${wanted.length - i} fichier(s) non inclus]` });
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
out.push({ path: wanted[i].path, text });
|
|
161
|
+
used += text.length;
|
|
162
|
+
}
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
async judgeView(base, tree, isSecret) {
|
|
166
|
+
const gitBinary = await this.binaryPaths(base, tree);
|
|
167
|
+
const secretLines = new Set([...(await this.secretLinesOf(base, isSecret)), ...(await this.secretLinesOf(tree, isSecret))]);
|
|
168
|
+
const blob = async (rev, path) => { try {
|
|
169
|
+
return await this.git(['cat-file', 'blob', `${rev}:${path}`]);
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return undefined;
|
|
173
|
+
} };
|
|
174
|
+
const entries = [];
|
|
175
|
+
const newText = new Map();
|
|
176
|
+
for (const c of await this.changes(base, tree)) {
|
|
177
|
+
if (isSecret(c.path)) {
|
|
178
|
+
entries.push({ ...c, kind: 'secret' });
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const sides = [c.status === 'A' ? undefined : await blob(base, c.path), c.status === 'D' ? undefined : await blob(tree, c.path)];
|
|
182
|
+
if (gitBinary.has(c.path) || sides.some(t => t !== undefined && t.slice(0, 8000).includes('\0'))) {
|
|
183
|
+
entries.push({ ...c, kind: 'binary' });
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (sides.some(t => t !== undefined && t.split('\n').some(l => secretLines.has(l.trim())))) {
|
|
187
|
+
entries.push({ ...c, kind: 'secret-content' });
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
entries.push({ ...c, kind: 'text' });
|
|
191
|
+
if (sides[1] !== undefined)
|
|
192
|
+
newText.set(c.path, sides[1]);
|
|
193
|
+
}
|
|
194
|
+
return { entries, newText };
|
|
195
|
+
}
|
|
196
|
+
/** Meaningful lines (≥ 8 chars, not comments) of every secret file of `rev`: a file containing one is a moved/copied secret. */
|
|
197
|
+
async secretLinesOf(rev, isSecret) {
|
|
198
|
+
const paths = (await this.git(['ls-tree', '-r', '-z', '--name-only', rev])).split('\0').filter(Boolean).filter(isSecret);
|
|
199
|
+
const lines = [];
|
|
200
|
+
for (const p of paths) {
|
|
201
|
+
const text = await this.git(['cat-file', 'blob', `${rev}:${p}`]);
|
|
202
|
+
for (const l of text.split('\n')) {
|
|
203
|
+
const t = l.trim();
|
|
204
|
+
if (t.length >= 8 && !t.startsWith('#'))
|
|
205
|
+
lines.push(t);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return lines;
|
|
209
|
+
}
|
|
210
|
+
/** Paths whose change is binary according to git (`git diff --numstat` reports "-\t-"). */
|
|
211
|
+
async binaryPaths(base, tree) {
|
|
212
|
+
const out = await this.git(['diff', '--numstat', '-z', '--no-renames', base, tree]);
|
|
213
|
+
return new Set(out.split('\0').filter(Boolean).filter(r => r.startsWith('-\t-\t')).map(r => r.slice(4)));
|
|
214
|
+
}
|
|
215
|
+
async diff(base, tree) {
|
|
216
|
+
return this.git(['diff', '--binary', '--no-color', '--no-renames', '--no-ext-diff', '--no-textconv', base, tree]);
|
|
217
|
+
}
|
|
218
|
+
async changes(base, tree) {
|
|
219
|
+
const out = await this.git(['diff', '--name-status', '-z', '--no-renames', base, tree]);
|
|
220
|
+
const parts = out.split('\0');
|
|
221
|
+
const res = [];
|
|
222
|
+
for (let i = 0; i + 1 < parts.length; i += 2)
|
|
223
|
+
if (parts[i])
|
|
224
|
+
res.push({ status: parts[i], path: parts[i + 1] });
|
|
225
|
+
return res;
|
|
226
|
+
}
|
|
227
|
+
/** Paths of gitlinks (submodules) in a tree — unsupported in governed runs. */
|
|
228
|
+
async gitlinks(tree) {
|
|
229
|
+
const out = await this.git(['ls-tree', '-r', '-z', tree]);
|
|
230
|
+
return out.split('\0').filter(Boolean).filter(l => l.startsWith('160000 ')).map(l => l.slice(l.indexOf('\t') + 1));
|
|
231
|
+
}
|
|
232
|
+
async treeOf(commit) { return (await this.git(['rev-parse', `${commit}^{tree}`])).trim(); }
|
|
233
|
+
/** Commit exactly `tree` on `parent`, moving `branch` only if it still points at `parent` (compare-and-swap). */
|
|
234
|
+
async commitTree(tree, parent, branch, message) {
|
|
235
|
+
if (!OID_RE.test(tree) || !OID_RE.test(parent))
|
|
236
|
+
throw new Error('invalid tree or parent id');
|
|
237
|
+
if (!BRANCH_RE.test(branch))
|
|
238
|
+
throw new Error(`invalid branch name ${JSON.stringify(branch)}`);
|
|
239
|
+
const current = await this.branchHead(branch);
|
|
240
|
+
if (current !== parent)
|
|
241
|
+
throw new Error(`branch ${branch} moved (expected ${parent.slice(0, 12)}, found ${current.slice(0, 12)})`);
|
|
242
|
+
const sha = (await this.git(['commit-tree', tree, '-p', parent, '-m', message])).trim();
|
|
243
|
+
await this.git(['update-ref', `refs/heads/${branch}`, sha, parent]);
|
|
244
|
+
if ((await this.treeOf(sha)) !== tree)
|
|
245
|
+
throw new Error('committed tree differs from the approved tree');
|
|
246
|
+
if ((await this.currentBranch()) === branch)
|
|
247
|
+
await this.git(['reset', '-q']); // sync the index to the new HEAD; working tree untouched
|
|
248
|
+
return sha;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./git.js";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { lstatSync, readlinkSync } from 'node:fs';
|
|
2
|
+
import { dirname, isAbsolute, normalize } from 'node:path';
|
|
3
|
+
const MAX_HOPS = 40;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve `input` to the physical path a write would reach: symlinks are followed component by component (including
|
|
6
|
+
* the final one), `..` applies to the already-resolved prefix (kernel semantics), a non-existent tail is appended
|
|
7
|
+
* lexically. Throws on symlink loops. Never touches file contents.
|
|
8
|
+
*/
|
|
9
|
+
export function physicalPath(input, cwd = process.cwd()) {
|
|
10
|
+
return walk(isAbsolute(input) ? input : `${cwd}/${input}`, 0);
|
|
11
|
+
}
|
|
12
|
+
function walk(abs, hops) {
|
|
13
|
+
const parts = abs.split('/').filter(p => p !== '');
|
|
14
|
+
let cur = '/';
|
|
15
|
+
for (let i = 0; i < parts.length; i++) {
|
|
16
|
+
const part = parts[i];
|
|
17
|
+
if (part === '.')
|
|
18
|
+
continue;
|
|
19
|
+
if (part === '..') {
|
|
20
|
+
cur = dirname(cur);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const next = cur === '/' ? `/${part}` : `${cur}/${part}`;
|
|
24
|
+
let isLink;
|
|
25
|
+
try {
|
|
26
|
+
isLink = lstatSync(next).isSymbolicLink();
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
const code = e.code;
|
|
30
|
+
if (code === 'ENOENT' || code === 'ENOTDIR')
|
|
31
|
+
return normalize([next, ...parts.slice(i + 1)].join('/')); // non-existent: rest is lexical
|
|
32
|
+
throw new Error(`cannot resolve ${next}: ${code}`); // EACCES, ELOOP… ⇒ caller fails closed
|
|
33
|
+
}
|
|
34
|
+
if (isLink) {
|
|
35
|
+
if (hops + 1 > MAX_HOPS)
|
|
36
|
+
throw new Error(`symlink loop at ${next}`);
|
|
37
|
+
const target = readlinkSync(next);
|
|
38
|
+
const resolved = isAbsolute(target) ? target : `${cur}/${target}`;
|
|
39
|
+
const rest = parts.slice(i + 1).join('/');
|
|
40
|
+
return walk(rest ? `${resolved}/${rest}` : resolved, hops + 1);
|
|
41
|
+
}
|
|
42
|
+
cur = next;
|
|
43
|
+
}
|
|
44
|
+
return cur;
|
|
45
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Taskquoin PreToolUse hook for Claude Code. Contract (ADR-0003): read JSON on stdin, exit 0 = defer to the normal
|
|
4
|
+
* permission system (never "allow"), exit 2 = deny with the reason on stderr. FAIL CLOSED: any parse, policy or
|
|
5
|
+
* canonicalisation error ⇒ exit 2. Never exits 1 (Claude treats other non-zero codes as non-blocking).
|
|
6
|
+
* Usage: node main.ts --policy <policy.json>
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
9
|
+
import { resolve } from 'node:path';
|
|
10
|
+
import { evaluateRules } from '../../../packages/rules/src/index.js';
|
|
11
|
+
import { physicalPath } from "./canonical.js";
|
|
12
|
+
import { mapPayload } from "./payload.js";
|
|
13
|
+
function deny(reason) { process.stderr.write(`Taskquoin BLOCKED — ${reason}\n`); process.exit(2); }
|
|
14
|
+
function loadPolicy(file) {
|
|
15
|
+
if (!file)
|
|
16
|
+
throw new Error('--policy <file> is required');
|
|
17
|
+
const p = JSON.parse(readFileSync(file, 'utf8'));
|
|
18
|
+
const s = (k) => { if (typeof p[k] !== 'string' || !p[k].startsWith('/'))
|
|
19
|
+
throw new Error(`policy.${k} must be an absolute path`); return physicalPath(p[k]); };
|
|
20
|
+
if (!Array.isArray(p.writeGlobs) || p.writeGlobs.some(g => typeof g !== 'string'))
|
|
21
|
+
throw new Error('policy.writeGlobs must be a string array');
|
|
22
|
+
const vcs = p.vcs;
|
|
23
|
+
if (!vcs || typeof vcs.commit !== 'boolean' || typeof vcs.push !== 'boolean')
|
|
24
|
+
throw new Error('policy.vcs.{commit,push} must be booleans');
|
|
25
|
+
let frozenRoots;
|
|
26
|
+
if (p.frozenRoots !== undefined) {
|
|
27
|
+
if (!Array.isArray(p.frozenRoots) || p.frozenRoots.some(f => typeof f !== 'string' || !f.startsWith('/')))
|
|
28
|
+
throw new Error('policy.frozenRoots must be absolute paths');
|
|
29
|
+
frozenRoots = p.frozenRoots.map(f => physicalPath(f));
|
|
30
|
+
}
|
|
31
|
+
return { projectRoot: s('projectRoot'), home: s('home'), writeGlobs: p.writeGlobs, vcs: { commit: vcs.commit, push: vcs.push },
|
|
32
|
+
...(p.controlStore !== undefined ? { controlStore: s('controlStore') } : {}), ...(frozenRoots ? { frozenRoots } : {}) };
|
|
33
|
+
}
|
|
34
|
+
function main() {
|
|
35
|
+
const argv = process.argv.slice(2);
|
|
36
|
+
const policy = loadPolicy(argv[argv.indexOf('--policy') + 1] && argv.includes('--policy') ? argv[argv.indexOf('--policy') + 1] : undefined);
|
|
37
|
+
const { cwd, tool, mapped } = mapPayload(JSON.parse(readFileSync(0, 'utf8')));
|
|
38
|
+
let violations = [];
|
|
39
|
+
if (mapped.kind === 'write' || mapped.kind === 'read') {
|
|
40
|
+
for (const raw of mapped.rawPaths) {
|
|
41
|
+
// Both views must pass: lexical (what permission rules see) and physical (what the kernel will touch).
|
|
42
|
+
const candidates = [...new Set([resolve(cwd, raw), physicalPath(raw, cwd)])];
|
|
43
|
+
violations = violations.concat(evaluateRules({ kind: mapped.kind, paths: candidates }, policy).violations);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (mapped.kind === 'shell') {
|
|
47
|
+
violations = evaluateRules({ kind: 'shell', command: mapped.command }, policy).violations;
|
|
48
|
+
}
|
|
49
|
+
if (violations.length)
|
|
50
|
+
deny(`${tool}: ${violations.map(v => `${v.rule} ${v.reason}`).join('; ')}`);
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
main();
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
deny(`hook could not evaluate the call, failing closed: ${e.message}`);
|
|
58
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const isObj = (x) => typeof x === 'object' && x !== null && !Array.isArray(x);
|
|
2
|
+
function str(input, key, tool) {
|
|
3
|
+
const v = input[key];
|
|
4
|
+
if (typeof v !== 'string' || v === '')
|
|
5
|
+
throw new Error(`${tool}: tool_input.${key} missing or not a string`);
|
|
6
|
+
return v;
|
|
7
|
+
}
|
|
8
|
+
export function mapPayload(payload) {
|
|
9
|
+
if (!isObj(payload))
|
|
10
|
+
throw new Error('payload is not an object');
|
|
11
|
+
if (typeof payload.tool_name !== 'string')
|
|
12
|
+
throw new Error('payload.tool_name missing');
|
|
13
|
+
if (typeof payload.cwd !== 'string' || !payload.cwd.startsWith('/'))
|
|
14
|
+
throw new Error('payload.cwd missing or not absolute');
|
|
15
|
+
const tool = payload.tool_name;
|
|
16
|
+
const input = isObj(payload.tool_input) ? payload.tool_input : {};
|
|
17
|
+
let mapped;
|
|
18
|
+
switch (tool) {
|
|
19
|
+
case 'Write':
|
|
20
|
+
case 'Edit':
|
|
21
|
+
case 'MultiEdit':
|
|
22
|
+
mapped = { kind: 'write', rawPaths: [str(input, 'file_path', tool)] };
|
|
23
|
+
break;
|
|
24
|
+
case 'NotebookEdit':
|
|
25
|
+
mapped = { kind: 'write', rawPaths: [str(input, 'notebook_path', tool)] };
|
|
26
|
+
break;
|
|
27
|
+
case 'Read':
|
|
28
|
+
mapped = { kind: 'read', rawPaths: [str(input, 'file_path', tool)] };
|
|
29
|
+
break;
|
|
30
|
+
case 'Grep':
|
|
31
|
+
case 'Glob':
|
|
32
|
+
mapped = { kind: 'read', rawPaths: [typeof input.path === 'string' && input.path ? input.path : payload.cwd] };
|
|
33
|
+
break;
|
|
34
|
+
case 'Bash':
|
|
35
|
+
mapped = { kind: 'shell', command: str(input, 'command', tool) };
|
|
36
|
+
break;
|
|
37
|
+
default: mapped = { kind: 'none' };
|
|
38
|
+
}
|
|
39
|
+
return { cwd: payload.cwd, tool, mapped };
|
|
40
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local Ollama detection for `taskquoin init` (multi-LLM A): asks the LOCAL server which models are installed. Nothing
|
|
3
|
+
* leaves the machine; any failure (nothing listening, timeout, not Ollama) is just "not detected".
|
|
4
|
+
*/
|
|
5
|
+
export async function probeOllama(o = {}) {
|
|
6
|
+
try {
|
|
7
|
+
const res = await fetch(`${(o.url ?? 'http://localhost:11434').replace(/\/+$/, '')}/api/tags`, { redirect: 'error', signal: AbortSignal.timeout(o.timeoutMs ?? 500) });
|
|
8
|
+
if (!res.ok)
|
|
9
|
+
return undefined;
|
|
10
|
+
const data = await res.json();
|
|
11
|
+
if (!Array.isArray(data.models))
|
|
12
|
+
return undefined;
|
|
13
|
+
return data.models.map(m => m.name).filter((n) => typeof n === 'string' && n.length > 0);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host facts gathered OUTSIDE any model (doctor / preflight): absolute runtime binaries and versions, Claude Bash
|
|
3
|
+
* sandbox availability (bubblewrap + socat usable), local-tool network isolation, git root. Never reads secrets.
|
|
4
|
+
*/
|
|
5
|
+
import { accessSync, constants, existsSync, lstatSync, realpathSync, statSync } from 'node:fs';
|
|
6
|
+
import { delimiter, dirname, join, isAbsolute } from 'node:path';
|
|
7
|
+
import { runProcess } from '../../process-runner/src/index.js';
|
|
8
|
+
import { localToolIsolationAvailable, sandboxedToolAvailable } from '../../local-tool/src/index.js';
|
|
9
|
+
export function findOnPath(name, PATH) {
|
|
10
|
+
for (const dir of PATH.split(delimiter)) {
|
|
11
|
+
if (!dir.startsWith('/'))
|
|
12
|
+
continue; // relative PATH entries are ignored (a repository could shadow binaries)
|
|
13
|
+
const p = join(dir, name);
|
|
14
|
+
try {
|
|
15
|
+
if (statSync(p).isFile()) {
|
|
16
|
+
accessSync(p, constants.X_OK);
|
|
17
|
+
return realpathSync(p);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch { /* next */ }
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
export async function binaryVersion(bin, PATH, HOME) {
|
|
25
|
+
const r = await runProcess({ bin, args: ['--version'], cwd: '/', env: { PATH, HOME }, timeoutMs: 15_000, maxOutputBytes: 10_000 });
|
|
26
|
+
if (r.status !== 'completed')
|
|
27
|
+
return undefined; // a failing binary has no trustworthy version (Codex R3)
|
|
28
|
+
return /\b(\d+\.\d+\.\d+)\b/.exec(r.stdout)?.[1];
|
|
29
|
+
}
|
|
30
|
+
/** bubblewrap + socat present on PATH and bwrap can create an unprivileged network namespace. */
|
|
31
|
+
export async function bashSandboxAvailable(PATH) {
|
|
32
|
+
const bwrap = findOnPath('bwrap', PATH);
|
|
33
|
+
const socat = findOnPath('socat', PATH);
|
|
34
|
+
if (!bwrap || !socat)
|
|
35
|
+
return false;
|
|
36
|
+
const r = await runProcess({ bin: bwrap, args: ['--ro-bind', '/', '/', '--unshare-net', '--dev', '/dev', '/bin/true'], cwd: '/', env: { PATH }, timeoutMs: 10_000, maxOutputBytes: 1000 });
|
|
37
|
+
return r.status === 'completed';
|
|
38
|
+
}
|
|
39
|
+
/** Where Claude's native installer keeps every version it downloaded. */
|
|
40
|
+
export const claudeVersionsDir = (HOME) => join(HOME, '.local/share/claude/versions');
|
|
41
|
+
/**
|
|
42
|
+
* Why a file may not be run as the measured runtime; `undefined` = trusted. lstat, never stat: a link is refused,
|
|
43
|
+
* and the file and its directory must be ours and closed to group and others (nobody else can swap the binary).
|
|
44
|
+
* Only a path that is not there is `missing`; any other error (permissions, a loop) is `unreadable`.
|
|
45
|
+
*/
|
|
46
|
+
export function untrustedReason(file, uid, lstat = lstatSync) {
|
|
47
|
+
try {
|
|
48
|
+
const f = lstat(file);
|
|
49
|
+
if (f.isSymbolicLink())
|
|
50
|
+
return 'link';
|
|
51
|
+
if (!f.isFile())
|
|
52
|
+
return 'not a file';
|
|
53
|
+
if ((f.mode & 0o100) === 0)
|
|
54
|
+
return 'not executable';
|
|
55
|
+
const d = lstat(dirname(file));
|
|
56
|
+
if (d.isSymbolicLink())
|
|
57
|
+
return 'link';
|
|
58
|
+
if (!d.isDirectory())
|
|
59
|
+
return 'parent not a directory';
|
|
60
|
+
if (f.uid !== uid || d.uid !== uid)
|
|
61
|
+
return 'not owned';
|
|
62
|
+
if ((f.mode & 0o022) !== 0 || (d.mode & 0o022) !== 0)
|
|
63
|
+
return 'writable by others';
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
const code = e.code;
|
|
68
|
+
return code === 'ENOENT' || code === 'ENOTDIR' ? 'missing' : 'unreadable';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export async function probeHost(o) {
|
|
72
|
+
const runtimes = {};
|
|
73
|
+
for (const name of ['claude', 'codex', 'opencode']) {
|
|
74
|
+
const bin = findOnPath(name, o.PATH);
|
|
75
|
+
if (bin)
|
|
76
|
+
runtimes[name] = { bin, version: await binaryVersion(bin, o.PATH, o.HOME) };
|
|
77
|
+
}
|
|
78
|
+
const c = o.claude;
|
|
79
|
+
const uid = process.getuid?.();
|
|
80
|
+
let claudeCandidate;
|
|
81
|
+
if (c && uid !== undefined && isAbsolute(o.HOME) && runtimes.claude?.version !== c.measured) {
|
|
82
|
+
const cand = join(claudeVersionsDir(o.HOME), c.measured);
|
|
83
|
+
const untrusted = untrustedReason(cand, uid);
|
|
84
|
+
if (untrusted !== 'missing') {
|
|
85
|
+
// Trust and version first: with `path`, switching to `auto` must be the remedy only when it would really help.
|
|
86
|
+
const reason = untrusted
|
|
87
|
+
?? (await binaryVersion(cand, o.PATH, o.HOME) !== c.measured ? 'version mismatch' : c.selection === 'path' ? 'selection path' : undefined);
|
|
88
|
+
if (reason === undefined) {
|
|
89
|
+
const path = runtimes.claude;
|
|
90
|
+
runtimes.claude = { bin: cand, version: c.measured, ...(path ? { installed: path } : {}) };
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
claudeCandidate = { bin: cand, reason };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const git = findOnPath('git', o.PATH);
|
|
97
|
+
let gitRoot;
|
|
98
|
+
if (git) {
|
|
99
|
+
const r = await runProcess({ bin: git, args: ['rev-parse', '--show-toplevel'], cwd: o.cwd, env: { PATH: o.PATH, HOME: o.HOME }, timeoutMs: 10_000, maxOutputBytes: 10_000 });
|
|
100
|
+
if (r.status === 'completed') {
|
|
101
|
+
const t = r.stdout.trim();
|
|
102
|
+
if (t && existsSync(t))
|
|
103
|
+
gitRoot = realpathSync(t);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return { runtimes, bashSandbox: await bashSandboxAvailable(o.PATH), localIsolation: await localToolIsolationAvailable(), fileSandbox: await sandboxedToolAvailable(), node: process.execPath, git, gitRoot, ...(claudeCandidate ? { claudeCandidate } : {}) };
|
|
107
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata fingerprints of ignored files (ADR-0014). An entry is `ino:size:mode:ctimeNs`: an unprivileged process can
|
|
3
|
+
* forge mtime (`touch -d`) but not ctime, and replacing a file changes the inode. Symlinks are recorded, never
|
|
4
|
+
* followed. Nothing is read: cost is one lstat per entry (~230 ms for 43k entries, measured).
|
|
5
|
+
*/
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { lstatSync, readdirSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
const fp = (s) => `${s.ino}:${s.size}:${s.mode}:${s.ctimeNs}`;
|
|
10
|
+
const stat = (p) => { try {
|
|
11
|
+
return lstatSync(p, { bigint: true });
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return undefined;
|
|
15
|
+
} };
|
|
16
|
+
/** Every path under `rel` (itself included) → fingerprint, depth-first, sorted; symlinks are leaves. */
|
|
17
|
+
function walk(root, rel, out, exclude = []) {
|
|
18
|
+
if (exclude.some(x => rel === x || rel.startsWith(x + '/')))
|
|
19
|
+
return;
|
|
20
|
+
const s = stat(join(root, rel));
|
|
21
|
+
if (!s)
|
|
22
|
+
return;
|
|
23
|
+
out[rel] = fp(s);
|
|
24
|
+
if (!s.isDirectory())
|
|
25
|
+
return;
|
|
26
|
+
for (const name of readdirSync(join(root, rel)).sort())
|
|
27
|
+
walk(root, `${rel}/${name}`, out, exclude);
|
|
28
|
+
}
|
|
29
|
+
/** Fingerprint of each entry (files) or of everything under it (directories), keyed by repository-relative path;
|
|
30
|
+
* `exclude` = sub-paths covered elsewhere (inherited roots nested in an ignored directory). */
|
|
31
|
+
export function fingerprintEntries(root, entries, exclude = []) {
|
|
32
|
+
const out = {};
|
|
33
|
+
for (const e of entries)
|
|
34
|
+
walk(root, e.path, out, exclude);
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
/** Dependency roots → one digest per first-level child (and the root itself): small, and names what changed. */
|
|
38
|
+
export function dependencyDigests(root, roots) {
|
|
39
|
+
const out = {};
|
|
40
|
+
for (const r of roots) {
|
|
41
|
+
const s = stat(join(root, r));
|
|
42
|
+
if (!s) {
|
|
43
|
+
out[r] = 'absent';
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
out[r] = fp(s);
|
|
47
|
+
if (!s.isDirectory())
|
|
48
|
+
continue;
|
|
49
|
+
for (const name of readdirSync(join(root, r)).sort()) {
|
|
50
|
+
const all = {};
|
|
51
|
+
walk(root, `${r}/${name}`, all);
|
|
52
|
+
out[`${r}/${name}`] = createHash('sha256').update(Object.entries(all).map(([p, f]) => `${p}\0${f}`).join('\n')).digest('hex');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run a local tool (scanner, Graphify CLI, AnyDoc, …) with NO network (ADR-0010): fresh user + network namespace via
|
|
3
|
+
* util-linux `unshare -rn` — no root needed, not even loopback is reachable. Refuses to run if isolation is unavailable
|
|
4
|
+
* (fail closed: a "local" tool that could reach the network is not run).
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import { isAbsolute } from 'node:path';
|
|
8
|
+
import { runProcess } from '../../process-runner/src/index.js';
|
|
9
|
+
const UNSHARE = ['/usr/bin/unshare', '/bin/unshare'].find(p => existsSync(p));
|
|
10
|
+
export async function localToolIsolationAvailable() {
|
|
11
|
+
if (!UNSHARE || process.platform !== 'linux')
|
|
12
|
+
return false;
|
|
13
|
+
const r = await runProcess({ bin: UNSHARE, args: ['-rn', '--', '/bin/true'], cwd: '/', env: {}, timeoutMs: 5000, maxOutputBytes: 1000 });
|
|
14
|
+
return r.status === 'completed';
|
|
15
|
+
}
|
|
16
|
+
export async function runLocalTool(req, signal) {
|
|
17
|
+
if (!isAbsolute(req.bin))
|
|
18
|
+
throw new Error(`binary "${req.bin}" must be an absolute path`);
|
|
19
|
+
if (!(await localToolIsolationAvailable()))
|
|
20
|
+
throw new Error('network isolation (unshare -rn) unavailable on this host; refusing to run a local tool with network access (ADR-0010)');
|
|
21
|
+
return runProcess({ ...req, bin: UNSHARE, args: ['-rn', '--', req.bin, ...req.args] }, signal);
|
|
22
|
+
}
|