aegiscode 6.8.19 → 6.8.21
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/package.json +4 -2
- package/scripts/check.mjs +50 -0
- package/scripts/predist.mjs +11 -0
- package/src/commands.js +41 -35
- package/src/devrun.js +80 -6
- package/src/panels.js +2 -1
- package/src/summarize.js +3 -1
- package/vendor/client/aegis.js +13 -0
- package/vendor/client/authorship-key.js +45 -4
- package/vendor/client/byok-catalog.js +49 -1
- package/vendor/client/hooks.js +427 -0
- package/vendor/client/platform.js +410 -0
- package/vendor/desktop/lib/local/engine.js +85 -3
- package/vendor/desktop/lib/local/shell.js +393 -39
- package/vendor/desktop/lib/local/tools.js +156 -13
- package/vendor/desktop/lib/settings.js +36 -1
- package/vendor/desktop/renderer/usage.js +30 -0
- package/vendor/tools/agent-gate.mjs +99 -14
|
@@ -45,7 +45,36 @@ const path = require('node:path');
|
|
|
45
45
|
const { pathToFileURL } = require('node:url');
|
|
46
46
|
const { agentRoles } = require('./agents.js');
|
|
47
47
|
|
|
48
|
+
// The ONE platform module (client/platform.js, Phase 30.1). This file used to
|
|
49
|
+
// carry a private `shellSpec()` that read `process.platform` directly, which
|
|
50
|
+
// meant the Windows half of the decision could only ever be exercised on a
|
|
51
|
+
// Windows host — and this project has no Windows runner. Resolved the same two
|
|
52
|
+
// ways this repo resolves every shared module (see engine.js): repo-relative in
|
|
53
|
+
// a checkout and in the CLI's mirrored vendor tree, then the staged app-dir
|
|
54
|
+
// copy a packaged desktop build carries. A missing copy would leave `exec` with
|
|
55
|
+
// no shell at all, so the failure is loud here rather than lazily deferred: the
|
|
56
|
+
// fallback loads or this module does not.
|
|
57
|
+
let platform;
|
|
58
|
+
try {
|
|
59
|
+
platform = require('../../../client/platform.js');
|
|
60
|
+
} catch (err) {
|
|
61
|
+
try {
|
|
62
|
+
platform = require('../../vendor/platform.js');
|
|
63
|
+
} catch {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`tools.js: cannot load the shared platform module (client/platform.js, ` +
|
|
66
|
+
`or its staged copy): ${err && err.message ? err.message : err}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
48
71
|
const OUTPUT_CAP = 30_000; // chars fed back to the model per tool result
|
|
72
|
+
|
|
73
|
+
// The dialect probe (Phase 30.3), from the same module the session lives in: a
|
|
74
|
+
// one-shot `exec` must run the command in a shell that was PROBED to speak the
|
|
75
|
+
// dialect the command is written in, never in an unprobed `$SHELL`. Lives next
|
|
76
|
+
// to this file in every tree that has it (repo, CLI vendor, packaged app dir).
|
|
77
|
+
const shells = require('./shell.js');
|
|
49
78
|
const READ_LINE_CAP = 2000; // default line limit for readFile
|
|
50
79
|
const MATCH_CAP = 100; // max glob/grep hits per call
|
|
51
80
|
// readFileSync loads the whole file before `limit` ever truncates — refuse
|
|
@@ -181,6 +210,40 @@ const SCHEMAS = {
|
|
|
181
210
|
additionalProperties: false,
|
|
182
211
|
},
|
|
183
212
|
},
|
|
213
|
+
hooks: {
|
|
214
|
+
name: 'hooks',
|
|
215
|
+
description:
|
|
216
|
+
'Hook status for this machine, from the same shared implementation the CLI\'s /hooks uses: ' +
|
|
217
|
+
'the merged settings.json hook config (~/.aegis, ./.aegis, ~/.aegiscode, ./.aegiscode, ~/.claude) ' +
|
|
218
|
+
'and whether this repo\'s .githooks/ guard hooks are actually installed (core.hooksPath). ' +
|
|
219
|
+
'Read-only. Use installHooks to install them.',
|
|
220
|
+
parameters: {
|
|
221
|
+
type: 'object',
|
|
222
|
+
properties: {
|
|
223
|
+
sub: { type: 'string', enum: ['status', 'list'], description: 'status (default) or the full config listing' },
|
|
224
|
+
cwd: { type: 'string', description: 'Repo to inspect (default: the working directory)' },
|
|
225
|
+
},
|
|
226
|
+
required: [],
|
|
227
|
+
additionalProperties: false,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
installHooks: {
|
|
231
|
+
name: 'installHooks',
|
|
232
|
+
description:
|
|
233
|
+
'Install this repo\'s guard hooks: point git\'s core.hooksPath at .githooks/ (the agent-key ' +
|
|
234
|
+
'gate, the secret scan, the invariant lock) and make them executable. Idempotent, and verified ' +
|
|
235
|
+
'by reading the config back. Pass dry_run to see the exact commands without running them. ' +
|
|
236
|
+
'Without this, a fresh clone runs NO guard hooks.',
|
|
237
|
+
parameters: {
|
|
238
|
+
type: 'object',
|
|
239
|
+
properties: {
|
|
240
|
+
cwd: { type: 'string', description: 'Repo to install into (default: the working directory)' },
|
|
241
|
+
dry_run: { type: 'boolean', description: 'Print the commands instead of running them' },
|
|
242
|
+
},
|
|
243
|
+
required: [],
|
|
244
|
+
additionalProperties: false,
|
|
245
|
+
},
|
|
246
|
+
},
|
|
184
247
|
task: {
|
|
185
248
|
name: 'task',
|
|
186
249
|
description:
|
|
@@ -298,9 +361,10 @@ function editFile(args = {}) {
|
|
|
298
361
|
// applyWriteChecked/applyEditChecked, which are the only functions engine.js
|
|
299
362
|
// calls once the user has approved.
|
|
300
363
|
|
|
301
|
-
/** exec/writeFile/editFile change machine state
|
|
302
|
-
* never do — this is the
|
|
303
|
-
|
|
364
|
+
/** exec/writeFile/editFile/installHooks change machine state (installHooks
|
|
365
|
+
* writes git config); listDir/glob/grep/readFile/hooks never do — this is the
|
|
366
|
+
* set the approval gate checks against. */
|
|
367
|
+
const MUTATING_TOOLS = new Set(['exec', 'writeFile', 'editFile', 'installHooks']);
|
|
304
368
|
|
|
305
369
|
function sha256(text) {
|
|
306
370
|
return crypto.createHash('sha256').update(text == null ? '' : text, 'utf8').digest('hex');
|
|
@@ -627,14 +691,6 @@ function grep({ pattern, path: root } = {}) {
|
|
|
627
691
|
}
|
|
628
692
|
}
|
|
629
693
|
|
|
630
|
-
/** Shell to run `exec` in: cmd.exe on Windows, $SHELL (or /bin/sh) elsewhere. */
|
|
631
|
-
function shellSpec() {
|
|
632
|
-
if (process.platform === 'win32') {
|
|
633
|
-
return { cmd: process.env.ComSpec || 'cmd.exe', arg: '/d /s /c' };
|
|
634
|
-
}
|
|
635
|
-
return { cmd: process.env.SHELL || '/bin/sh', arg: '-c' };
|
|
636
|
-
}
|
|
637
|
-
|
|
638
694
|
/**
|
|
639
695
|
* Run a shell command as a fresh one-shot process (no state carried to the
|
|
640
696
|
* next call). Never rejects: spawn failures, a stalled child, a non-zero
|
|
@@ -646,7 +702,18 @@ function execOneShot({ command, cwd, timeout, maxBuffer } = {}) {
|
|
|
646
702
|
return new Promise((resolve) => {
|
|
647
703
|
const limit = Math.min(Number(maxBuffer) || EXEC_MAX_BUFFER, EXEC_MAX_BUFFER);
|
|
648
704
|
const ms = Math.min(Number(timeout) || EXEC_TIMEOUT_DEFAULT, EXEC_TIMEOUT_CAP);
|
|
649
|
-
|
|
705
|
+
// Shell to run `exec` in: cmd.exe on Windows, a PROBED POSIX sh/bash
|
|
706
|
+
// elsewhere. The choice, the platform seam that makes its win32 half
|
|
707
|
+
// testable on Linux and the fish/csh/nu refusal all live in
|
|
708
|
+
// client/platform.js + shell.js (Phase 30.1/30.3) — there is no second copy
|
|
709
|
+
// of that decision here, and an unverifiable shell is REPORTED rather than
|
|
710
|
+
// used.
|
|
711
|
+
const spec = shells.oneShotShellSpec();
|
|
712
|
+
if (!spec.ok) {
|
|
713
|
+
resolve(fail(spec.error));
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
const { cmd, arg } = spec;
|
|
650
717
|
|
|
651
718
|
let child;
|
|
652
719
|
try {
|
|
@@ -758,7 +825,83 @@ function exec({ command, cwd, timeout, maxBuffer } = {}, ctx = {}) {
|
|
|
758
825
|
return execOneShot({ command, cwd, timeout, maxBuffer });
|
|
759
826
|
}
|
|
760
827
|
|
|
761
|
-
|
|
828
|
+
// ── hooks / installHooks ────────────────────────────────────────────────────
|
|
829
|
+
//
|
|
830
|
+
// The hook layer is SHARED with the CLI (`client/hooks.js`, the same file
|
|
831
|
+
// `aegiscode /hooks` reads and `agent-gate.mjs install-hooks` installs), loaded
|
|
832
|
+
// exactly like the other cross-host modules: the repo-relative path first,
|
|
833
|
+
// then the flattened staged copy inside the app dir. Two implementations of
|
|
834
|
+
// "which settings files count" is how the GUI and the terminal end up
|
|
835
|
+
// describing one machine differently — which is what this replaced.
|
|
836
|
+
//
|
|
837
|
+
// Before this, the desktop had NO hook surface at all: the app could open a
|
|
838
|
+
// guarded tree and never mention that the git-side half of the same lock was
|
|
839
|
+
// not installed, so a fresh clone committed with no gate and nothing said so.
|
|
840
|
+
let hooksLib = null;
|
|
841
|
+
try {
|
|
842
|
+
hooksLib = require('../../../client/hooks.js');
|
|
843
|
+
} catch {
|
|
844
|
+
try { hooksLib = require('../../vendor/hooks.js'); } catch { hooksLib = null; }
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
const HOOKS_LIB_MISSING =
|
|
848
|
+
'the shared hook module could not be loaded (tried client/hooks.js beside the app and '
|
|
849
|
+
+ 'vendor/hooks.js inside it) — run scripts/predist.mjs before packaging.';
|
|
850
|
+
|
|
851
|
+
function hooksListing(config) {
|
|
852
|
+
const lines = [];
|
|
853
|
+
const hooks = config && config.hooks ? config.hooks : {};
|
|
854
|
+
for (const [event, matchers] of Object.entries(hooks)) {
|
|
855
|
+
lines.push(`${event} (${matchers.length})`);
|
|
856
|
+
for (const matcher of matchers) {
|
|
857
|
+
if (!matcher) continue;
|
|
858
|
+
lines.push(` - ${matcher.name || '(unnamed)'}`);
|
|
859
|
+
const m = matcher.matcher;
|
|
860
|
+
if (m && m.tools) lines.push(` tools: ${m.tools}`);
|
|
861
|
+
if (m && m.paths) lines.push(` paths: ${m.paths}`);
|
|
862
|
+
if (m && m.commands) lines.push(` commands: ${m.commands}`);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return lines.length ? lines.join('\n') : '(no hooks declared in any settings file)';
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/** Read-only: hook config + whether this repo's guard hooks are installed. */
|
|
869
|
+
function hooks({ sub, cwd } = {}) {
|
|
870
|
+
if (!hooksLib) return fail(HOOKS_LIB_MISSING);
|
|
871
|
+
try {
|
|
872
|
+
const opts = { cwd: cwd || process.cwd() };
|
|
873
|
+
const config = hooksLib.readHookConfig(opts);
|
|
874
|
+
if (String(sub || 'status').toLowerCase() === 'list') return ok(hooksListing(config));
|
|
875
|
+
const stats = hooksLib.hookStats(config.hooks);
|
|
876
|
+
return ok(hooksLib.hooksSummary({ ...opts, config, stats }));
|
|
877
|
+
} catch (e) {
|
|
878
|
+
return fail(e && e.message ? e.message : String(e));
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/** Mutating: install the repo's guard hooks (core.hooksPath -> .githooks/). */
|
|
883
|
+
function installHooks({ cwd, dry_run } = {}) {
|
|
884
|
+
if (!hooksLib) return fail(HOOKS_LIB_MISSING);
|
|
885
|
+
let res;
|
|
886
|
+
try {
|
|
887
|
+
res = hooksLib.installRepoHooks({ cwd: cwd || process.cwd(), dryRun: Boolean(dry_run) });
|
|
888
|
+
} catch (e) {
|
|
889
|
+
return fail(e && e.message ? e.message : String(e));
|
|
890
|
+
}
|
|
891
|
+
const plan = res.actions.length ? `\n ${res.actions.join('\n ')}` : '';
|
|
892
|
+
if (!res.ok) return fail(`${res.error}${plan}`);
|
|
893
|
+
if (dry_run) {
|
|
894
|
+
return ok(`would install the guard hooks in ${res.status.repo}${plan || '\n (already installed — nothing to do)'}`
|
|
895
|
+
+ (res.status.installed ? '' : '\n re-run without dry_run to apply'));
|
|
896
|
+
}
|
|
897
|
+
if (!res.changed) {
|
|
898
|
+
return ok(`guard hooks already installed in ${res.status.repo}: core.hooksPath = .githooks\n ${res.status.execNote}`);
|
|
899
|
+
}
|
|
900
|
+
return ok(`guard hooks installed in ${res.status.repo}\n core.hooksPath = .githooks (verified by reading it back)`
|
|
901
|
+
+ `${plan}\n ${res.status.execNote}\n a commit and a push in this tree are now gated.`);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
const EXECUTORS = { readFile, writeFile, editFile, listDir, glob, grep, exec, hooks, installHooks };
|
|
762
905
|
|
|
763
906
|
/** True when `name` is a tool this layer can run (task is excluded — see SUBAGENT_TOOL). */
|
|
764
907
|
function isTool(name) {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
const fs = require('node:fs');
|
|
19
19
|
const path = require('node:path');
|
|
20
|
+
const { execFileSync } = require('node:child_process');
|
|
20
21
|
|
|
21
22
|
// The local-model transport. Required for ONE function: `remoteRefusal`, the
|
|
22
23
|
// fail-closed check that keeps a non-local base URL out of the `local` row. The
|
|
@@ -172,6 +173,40 @@ function maskKey(key) {
|
|
|
172
173
|
return `${key.slice(0, 9)}\u2026${key.slice(-4)}`;
|
|
173
174
|
}
|
|
174
175
|
|
|
176
|
+
const IS_WIN32 = process.platform === 'win32';
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Restrict the settings file to the current user. POSIX enforces 0600 at the
|
|
180
|
+
* kernel; Windows ignores POSIX modes entirely, so an equivalent ACL is applied
|
|
181
|
+
* via icacls (inheritance removed, only the current user granted full control).
|
|
182
|
+
* A failure is reported — never silently swallowed — because a credential file
|
|
183
|
+
* that did not get restricted must not look like it did.
|
|
184
|
+
*/
|
|
185
|
+
function restrictFile(file) {
|
|
186
|
+
if (IS_WIN32) {
|
|
187
|
+
const user = process.env.USERNAME || process.env.USER || process.env.USERDOMAIN;
|
|
188
|
+
if (!user) {
|
|
189
|
+
console.error(
|
|
190
|
+
`[settings] cannot restrict ${file}: no current user to grant (USERNAME unset)`
|
|
191
|
+
);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
execFileSync('icacls', [file, '/inheritance:r', '/grant:r', `${user}:(F)`], {
|
|
196
|
+
stdio: 'ignore',
|
|
197
|
+
});
|
|
198
|
+
} catch (err) {
|
|
199
|
+
console.error(`[settings] failed to restrict ACL on ${file}: ${err.message}`);
|
|
200
|
+
}
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
fs.chmodSync(file, 0o600);
|
|
205
|
+
} catch (err) {
|
|
206
|
+
console.error(`[settings] failed to chmod ${file} to 0600: ${err.message}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
175
210
|
function createSettingsStore({ dir, safeStorage } = {}) {
|
|
176
211
|
if (!dir) throw new Error('createSettingsStore requires a storage dir');
|
|
177
212
|
const file = path.join(dir, SETTINGS_FILE);
|
|
@@ -219,7 +254,7 @@ function createSettingsStore({ dir, safeStorage } = {}) {
|
|
|
219
254
|
// base64 is all the protection there is — file mode is the real control).
|
|
220
255
|
fs.writeFileSync(tmp, JSON.stringify(data, null, 2), { mode: 0o600 });
|
|
221
256
|
fs.renameSync(tmp, file);
|
|
222
|
-
|
|
257
|
+
restrictFile(file);
|
|
223
258
|
}
|
|
224
259
|
|
|
225
260
|
/** Provider CRUD must never touch a reserved (AEGIS-key) namespace. */
|
|
@@ -213,6 +213,36 @@ const RATES = {
|
|
|
213
213
|
input: 1.32, output: 3.96, cacheRead: 0.044, cacheWrite: 1.32,
|
|
214
214
|
offPeak: { input: 0.66, output: 1.98, cacheRead: 0.022, cacheWrite: 0.66 },
|
|
215
215
|
},
|
|
216
|
+
|
|
217
|
+
// The three rows below back the BYOK additions in client/byok-catalog.js —
|
|
218
|
+
// without a row here each would resolve to RATE_BASIS.DEFAULT, the same
|
|
219
|
+
// "priced at Sonnet's $3/$15 and nobody can tell" hole this file exists to
|
|
220
|
+
// close for DeepSeek and Haiku. None of the three publish a cache-WRITE
|
|
221
|
+
// premium (unlike Anthropic's 1.25x): all three bill a cache write as
|
|
222
|
+
// ordinary input, so cacheWrite repeats the input rate, the same convention
|
|
223
|
+
// the DeepSeek rows above use for the same reason.
|
|
224
|
+
|
|
225
|
+
// Grok 4.7 (api.x.ai/v1, flagship since 2026-09-21): $2.00/$6.00 per M,
|
|
226
|
+
// $0.50 cached input, standard (<200k token) tier. xAI doubles every rate
|
|
227
|
+
// above a 200k-token prompt, a prompt-SIZE threshold this table has no field
|
|
228
|
+
// for (the only tiering this schema models is DeepSeek's time-of-day
|
|
229
|
+
// peak/offPeak) — left at the standard tier rather than inventing one, so a
|
|
230
|
+
// long-context Grok turn under-reports rather than carrying a fabricated
|
|
231
|
+
// split.
|
|
232
|
+
'grok-4.7': { input: 2.00, output: 6.00, cacheRead: 0.50, cacheWrite: 2.00 },
|
|
233
|
+
|
|
234
|
+
// Gemini 3.8 Flash (ai.google.dev, GA 2026-09-02): $0.75/$3.75 per M,
|
|
235
|
+
// $0.075 cached input — the introductory rate published through
|
|
236
|
+
// 2026-12-31 (scheduled to rise to $1.50/$7.50 on 2027-01-01, not modeled
|
|
237
|
+
// here for the same reason the Grok long-context tier above is not: no
|
|
238
|
+
// field in this table carries a future-dated rate change).
|
|
239
|
+
'gemini-3.8-flash': { input: 0.75, output: 3.75, cacheRead: 0.075, cacheWrite: 0.75 },
|
|
240
|
+
|
|
241
|
+
// GPT-5.5 (api.openai.com/v1, released 2026-04-23): $5.00/$30.00 per M,
|
|
242
|
+
// $0.50 cached input, standard (<272k token) tier. Like Grok above, OpenAI
|
|
243
|
+
// doubles input and 1.5x's output past that prompt size; left at the
|
|
244
|
+
// standard tier for the same reason.
|
|
245
|
+
'gpt-5.5': { input: 5.00, output: 30.00, cacheRead: 0.50, cacheWrite: 5.00 },
|
|
216
246
|
};
|
|
217
247
|
|
|
218
248
|
/**
|
|
@@ -95,8 +95,18 @@ import crypto from 'node:crypto';
|
|
|
95
95
|
import fs from 'node:fs';
|
|
96
96
|
import os from 'node:os';
|
|
97
97
|
import path from 'node:path';
|
|
98
|
+
import { createRequire } from 'node:module';
|
|
98
99
|
import { fileURLToPath } from 'node:url';
|
|
99
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Load a CommonJS sibling (client/hooks.js) from this ES module. `createRequire`
|
|
103
|
+
* rather than a plain `import` so the caller can try/catch it synchronously and
|
|
104
|
+
* keep its own behaviour when the file is absent — a bare tools/ copy is a
|
|
105
|
+
* supported layout, and it must fail loudly rather than silently do nothing.
|
|
106
|
+
*/
|
|
107
|
+
const require_ = createRequire(import.meta.url);
|
|
108
|
+
function requireClient(spec) { return require_(spec); }
|
|
109
|
+
|
|
100
110
|
export const GATE_VERSION = 1;
|
|
101
111
|
export const KEY_DOMAIN = 'aegiscode-agent-gate-v1';
|
|
102
112
|
export const MACHINE_DOMAIN = 'aegiscode-machine-v1';
|
|
@@ -249,10 +259,27 @@ const WRITEISH_BASH = [
|
|
|
249
259
|
/(^|[^<])>>?\s*\S/, // > file, >> file
|
|
250
260
|
/\btee\b/, /\bsed\s+-i/, /\btruncate\b/, /\bdd\b/,
|
|
251
261
|
/\b(rm|mv|cp|install|touch|mkdir|rmdir|chmod|chown|ln)\b/,
|
|
252
|
-
/\b(patch|applypatch)\b/, /\
|
|
262
|
+
/\b(patch|applypatch)\b/, /\bperl\s+-i\b/,
|
|
253
263
|
/\bgit\s+(checkout|restore|reset|clean|stash|apply|revert|cherry-pick|merge|rebase)\b/,
|
|
254
264
|
/\bnpm\s+(install|ci|uninstall|update)\b/, /\byarn\s+(add|remove)\b/, /\bpip[0-9.]*\s+install\b/,
|
|
255
265
|
/\bAEGIS_GATE_SKIP\b/,
|
|
266
|
+
|
|
267
|
+
// `find` is a writer the moment it mutates: -delete, -exec/-execdir, and the
|
|
268
|
+
// -fprint/-fls family all write without ever containing `rm` or a redirect.
|
|
269
|
+
// Found by probing this gate keylessly on 2026-10-02 (`find <gated-tree>
|
|
270
|
+
// -name guard.json -delete` was reported as a read). Kept in step with
|
|
271
|
+
// aegiscodex-dev/src/repoguard.js, which carries the same list.
|
|
272
|
+
/\bfind\b[^|;]*\s-(delete|exec|execdir|fprint|fprint0|fls)\b/,
|
|
273
|
+
/\bxargs\b/,
|
|
274
|
+
|
|
275
|
+
// An inline-eval interpreter is an opaque program: `node -e`, `python -c`,
|
|
276
|
+
// `perl -e`, `sh -c` can write anywhere without naming a path in the command
|
|
277
|
+
// text. The old python rule looked for a literal `open(` and so missed
|
|
278
|
+
// `open(String.fromCharCode(...))`; the interpreter itself is the honest
|
|
279
|
+
// marker, and path-less write-ish commands fall back to cwd (fail-closed).
|
|
280
|
+
// `node --test` is deliberately NOT a hit.
|
|
281
|
+
/\b(python[0-9.]*|perl)\s+-c\b/, /\b(python[0-9.]*|perl)\s+-e\b/,
|
|
282
|
+
/\bnode\b[^|;]*\s(?:-e|--eval)\b/, /\b(sh|bash|zsh|dash)\s+-c\b/,
|
|
256
283
|
];
|
|
257
284
|
|
|
258
285
|
/** Path-shaped tokens in a command line. Deliberately over-eager: see bashTargets. */
|
|
@@ -697,7 +724,11 @@ function wireHook(root) {
|
|
|
697
724
|
fs.mkdirSync(hooksDir, { recursive: true });
|
|
698
725
|
const lib = path.join(hooksDir, 'lib-gate.sh');
|
|
699
726
|
fs.copyFileSync(src, lib);
|
|
700
|
-
|
|
727
|
+
// The exec bit means something only where git reads it. On win32 chmod is not
|
|
728
|
+
// enforced, so a chmodSync there is a silent no-op that READS as protection;
|
|
729
|
+
// git for Windows runs hooks with its bundled sh, so the bit is not needed.
|
|
730
|
+
const execBit = process.platform !== 'win32';
|
|
731
|
+
if (execBit) fs.chmodSync(lib, 0o755);
|
|
701
732
|
|
|
702
733
|
const hook = path.join(hooksDir, 'pre-commit');
|
|
703
734
|
let text = fs.existsSync(hook)
|
|
@@ -713,8 +744,8 @@ function wireHook(root) {
|
|
|
713
744
|
text = lines.join('\n');
|
|
714
745
|
}
|
|
715
746
|
fs.writeFileSync(hook, text, 'utf8');
|
|
716
|
-
fs.chmodSync(hook, 0o755);
|
|
717
|
-
return { lib, hook, already };
|
|
747
|
+
if (execBit) fs.chmodSync(hook, 0o755);
|
|
748
|
+
return { lib, hook, already, execBit };
|
|
718
749
|
}
|
|
719
750
|
|
|
720
751
|
function cmdInit({ flags }) {
|
|
@@ -780,7 +811,23 @@ function cmdInit({ flags }) {
|
|
|
780
811
|
: ' NO machine bound (--no-bind): any machine holding the key file opens this gate');
|
|
781
812
|
if (hooks) console.error(`✓ vendored ${hooks.lib}${hooks.already ? ' (gate section already present)' : ` and inserted the gate section into ${hooks.hook}`}`);
|
|
782
813
|
else console.error(' hooks NOT wired — pass --hooks to vendor lib-gate.sh and wire pre-commit');
|
|
783
|
-
|
|
814
|
+
// `--hooks` was the user asking for hooks. Ending on "now run this yourself"
|
|
815
|
+
// left a fresh tree with the files present and the hooks still not installed —
|
|
816
|
+
// the documented state in which NO guard runs. So the install happens here,
|
|
817
|
+
// where the request was made, and it is verified rather than assumed.
|
|
818
|
+
if (hooks) {
|
|
819
|
+
let hooksLib = null;
|
|
820
|
+
try { hooksLib = requireClient('../client/hooks.js'); } catch { hooksLib = null; }
|
|
821
|
+
if (hooksLib) {
|
|
822
|
+
const res = hooksLib.installRepoHooks({ cwd: root });
|
|
823
|
+
if (!res.ok) console.error(`✗ agent-gate: the hooks were vendored but NOT installed — ${res.error}`);
|
|
824
|
+
else if (!res.changed) console.error(`✓ guard hooks already installed (core.hooksPath = .githooks)`);
|
|
825
|
+
else console.error(`✓ installed: core.hooksPath = .githooks (read back to verify)\n ${res.actions.join('\n ')}`);
|
|
826
|
+
} else {
|
|
827
|
+
console.error(` finish: git -C ${root} config core.hooksPath .githooks`);
|
|
828
|
+
console.error(' (client/hooks.js is missing from this copy, so the install could not be done or verified here)');
|
|
829
|
+
}
|
|
830
|
+
}
|
|
784
831
|
console.error(` verify: agent-gate.mjs status --cwd ${root} (expect ALLOW)`);
|
|
785
832
|
console.error(' prove: AEGIS_AGENT_KEY=wrong agent-gate.mjs check --cwd … (expect exit 3, not 0)');
|
|
786
833
|
return EXIT.ALLOW;
|
|
@@ -998,18 +1045,56 @@ function cmdImportKey({ flags, rest }) {
|
|
|
998
1045
|
}
|
|
999
1046
|
|
|
1000
1047
|
function cmdInstallHooks({ flags }) {
|
|
1001
|
-
const root = flags.cwd || process.cwd();
|
|
1002
|
-
const
|
|
1003
|
-
|
|
1004
|
-
|
|
1048
|
+
const root = path.resolve(flags.cwd || process.cwd());
|
|
1049
|
+
const dryRun = Boolean(flags['dry-run'] || flags.dryRun);
|
|
1050
|
+
// The install itself lives in the SHARED module (client/hooks.js), the same
|
|
1051
|
+
// one the CLI /hooks and the desktop hooks tool call, so "installed" means
|
|
1052
|
+
// one thing on every host. Loaded through createRequire because this file is
|
|
1053
|
+
// ESM and that module is CJS. A build without the client tree (a bare
|
|
1054
|
+
// tools/ copy) falls back to the old describe-only behaviour below rather
|
|
1055
|
+
// than pretending the install happened.
|
|
1056
|
+
let hooksLib = null;
|
|
1057
|
+
try { hooksLib = requireClient('../client/hooks.js'); } catch { hooksLib = null; }
|
|
1058
|
+
|
|
1059
|
+
if (!hooksLib) {
|
|
1060
|
+
const hooksDir = path.join(root, '.githooks');
|
|
1061
|
+
if (!fs.existsSync(path.join(hooksDir, 'pre-commit'))) {
|
|
1062
|
+
console.error(`✗ agent-gate: no .githooks/pre-commit under ${root}`);
|
|
1063
|
+
return EXIT.CONFIG;
|
|
1064
|
+
}
|
|
1065
|
+
if (process.platform !== 'win32') {
|
|
1066
|
+
for (const name of ['pre-commit', 'pre-push']) {
|
|
1067
|
+
const p = path.join(hooksDir, name);
|
|
1068
|
+
if (fs.existsSync(p)) fs.chmodSync(p, 0o755);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
console.error('✗ agent-gate: client/hooks.js is missing, so this copy cannot install the hooks itself.');
|
|
1072
|
+
console.error(` run: git -C ${root} config core.hooksPath .githooks`);
|
|
1073
|
+
console.error(' (the shared installer is what verifies the write; restore client/hooks.js to get it)');
|
|
1074
|
+
return EXIT.CONFIG;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
const res = hooksLib.installRepoHooks({ cwd: root, dryRun });
|
|
1078
|
+
if (!res.ok) {
|
|
1079
|
+
console.error(`✗ agent-gate: ${res.error}`);
|
|
1080
|
+
if (res.actions.length) console.error(` ${dryRun ? 'would run' : 'ran'}:\n ${res.actions.join('\n ')}`);
|
|
1005
1081
|
return EXIT.CONFIG;
|
|
1006
1082
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1083
|
+
if (dryRun) {
|
|
1084
|
+
console.error(` would install the guard hooks in ${res.status.repo}:`);
|
|
1085
|
+
for (const a of res.actions) console.error(` ${a}`);
|
|
1086
|
+
if (res.status.installed) console.error(' (core.hooksPath is already .githooks — nothing to change)');
|
|
1087
|
+
return EXIT.ALLOW;
|
|
1088
|
+
}
|
|
1089
|
+
if (!res.changed) {
|
|
1090
|
+
console.error(`= agent-gate: guard hooks already installed in ${res.status.repo} (core.hooksPath = .githooks)`);
|
|
1091
|
+
} else {
|
|
1092
|
+
console.error(`✓ agent-gate: installed the guard hooks in ${res.status.repo} — core.hooksPath = .githooks (read back to verify)`);
|
|
1093
|
+
for (const a of res.actions) console.error(` ${a}`);
|
|
1010
1094
|
}
|
|
1011
|
-
console.error(`
|
|
1012
|
-
console.error(
|
|
1095
|
+
console.error(` present: ${res.status.present.join(', ') || '(none)'}${res.status.missing.length ? ` · missing: ${res.status.missing.join(', ')}` : ''}`);
|
|
1096
|
+
console.error(` ${res.status.execNote}`);
|
|
1097
|
+
console.error(` verify: node tools/invariant-lock.mjs status (the hooks run it)`);
|
|
1013
1098
|
return EXIT.ALLOW;
|
|
1014
1099
|
}
|
|
1015
1100
|
|