@invictus-group-ai/hooks 0.5.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/LICENSE +21 -0
- package/README.md +130 -0
- package/dist/bin.d.ts +11 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +37 -0
- package/dist/bin.js.map +1 -0
- package/dist/engine.d.ts +53 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +182 -0
- package/dist/engine.js.map +1 -0
- package/dist/git/post-commit.d.ts +43 -0
- package/dist/git/post-commit.d.ts.map +1 -0
- package/dist/git/post-commit.js +166 -0
- package/dist/git/post-commit.js.map +1 -0
- package/dist/git/pre-push.d.ts +43 -0
- package/dist/git/pre-push.d.ts.map +1 -0
- package/dist/git/pre-push.js +102 -0
- package/dist/git/pre-push.js.map +1 -0
- package/dist/git/prepare-commit-msg.d.ts +97 -0
- package/dist/git/prepare-commit-msg.d.ts.map +1 -0
- package/dist/git/prepare-commit-msg.js +623 -0
- package/dist/git/prepare-commit-msg.js.map +1 -0
- package/dist/git-activate.d.ts +25 -0
- package/dist/git-activate.d.ts.map +1 -0
- package/dist/git-activate.js +75 -0
- package/dist/git-activate.js.map +1 -0
- package/dist/hooks/db-guard.d.ts +31 -0
- package/dist/hooks/db-guard.d.ts.map +1 -0
- package/dist/hooks/db-guard.js +290 -0
- package/dist/hooks/db-guard.js.map +1 -0
- package/dist/hooks/index.d.ts +16 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +24 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/journal-nudge.d.ts +14 -0
- package/dist/hooks/journal-nudge.d.ts.map +1 -0
- package/dist/hooks/journal-nudge.js +60 -0
- package/dist/hooks/journal-nudge.js.map +1 -0
- package/dist/hooks/loc-recorder.d.ts +79 -0
- package/dist/hooks/loc-recorder.d.ts.map +1 -0
- package/dist/hooks/loc-recorder.js +183 -0
- package/dist/hooks/loc-recorder.js.map +1 -0
- package/dist/hooks/metrics-capture.d.ts +34 -0
- package/dist/hooks/metrics-capture.d.ts.map +1 -0
- package/dist/hooks/metrics-capture.js +275 -0
- package/dist/hooks/metrics-capture.js.map +1 -0
- package/dist/hooks/secret-guard.d.ts +19 -0
- package/dist/hooks/secret-guard.d.ts.map +1 -0
- package/dist/hooks/secret-guard.js +163 -0
- package/dist/hooks/secret-guard.js.map +1 -0
- package/dist/hooks/session-boot.d.ts +17 -0
- package/dist/hooks/session-boot.d.ts.map +1 -0
- package/dist/hooks/session-boot.js +123 -0
- package/dist/hooks/session-boot.js.map +1 -0
- package/dist/hooks/stop-gate.d.ts +17 -0
- package/dist/hooks/stop-gate.d.ts.map +1 -0
- package/dist/hooks/stop-gate.js +97 -0
- package/dist/hooks/stop-gate.js.map +1 -0
- package/dist/hooks/typecheck-on-edit.d.ts +18 -0
- package/dist/hooks/typecheck-on-edit.d.ts.map +1 -0
- package/dist/hooks/typecheck-on-edit.js +110 -0
- package/dist/hooks/typecheck-on-edit.js.map +1 -0
- package/dist/i18n/en.d.ts +45 -0
- package/dist/i18n/en.d.ts.map +1 -0
- package/dist/i18n/en.js +53 -0
- package/dist/i18n/en.js.map +1 -0
- package/dist/i18n/index.d.ts +35 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +56 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/pt-BR.d.ts +12 -0
- package/dist/i18n/pt-BR.d.ts.map +1 -0
- package/dist/i18n/pt-BR.js +50 -0
- package/dist/i18n/pt-BR.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/kit-cli.d.ts +36 -0
- package/dist/kit-cli.d.ts.map +1 -0
- package/dist/kit-cli.js +68 -0
- package/dist/kit-cli.js.map +1 -0
- package/dist/metrics-schema.d.ts +215 -0
- package/dist/metrics-schema.d.ts.map +1 -0
- package/dist/metrics-schema.js +83 -0
- package/dist/metrics-schema.js.map +1 -0
- package/dist/shared.d.ts +81 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +276 -0
- package/dist/shared.js.map +1 -0
- package/githooks/prepare-commit-msg +30 -0
- package/githooks/prepare-commit-msg.cmd +16 -0
- package/package.json +71 -0
- package/settings-template.json +97 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* secret-guard — PreToolUse on Bash | Write | Edit | MultiEdit.
|
|
3
|
+
*
|
|
4
|
+
* Scans EVERY writable field of the tool call: `command`, `content`,
|
|
5
|
+
* `new_string`, and `edits[].new_string` (the legacy kit's secret scanner
|
|
6
|
+
* missed Edit payloads entirely — that hole must never recur).
|
|
7
|
+
*
|
|
8
|
+
* Findings block with exit 2; matches are REDACTED in the block message
|
|
9
|
+
* (first 4 chars + length — never the secret itself). Allowlist:
|
|
10
|
+
* `.invictus/secretsignore` — one regex (or literal substring) per line,
|
|
11
|
+
* `#` comments; a candidate matching any line is suppressed.
|
|
12
|
+
*
|
|
13
|
+
* Deliberately NOT skipped: lines containing `$VAR` references — the legacy
|
|
14
|
+
* scanner skipped any line with an uppercase var on it, so a real key next
|
|
15
|
+
* to `$URL` sailed through (audit §1, defect b).
|
|
16
|
+
*/
|
|
17
|
+
import { readFileSync } from 'node:fs';
|
|
18
|
+
import { basename, join } from 'node:path';
|
|
19
|
+
import { HOOK_EXIT } from '@invictus-group-ai/core';
|
|
20
|
+
import { translatorFor } from '../i18n/index.js';
|
|
21
|
+
const PATTERNS = [
|
|
22
|
+
{ name: 'anthropic-api-key', re: /\bsk-ant-[A-Za-z0-9_-]{20,}/g },
|
|
23
|
+
{ name: 'openai-api-key', re: /\bsk-(?!ant-)(?:proj-|svcacct-)?[A-Za-z0-9_-]{20,}/g },
|
|
24
|
+
{ name: 'aws-access-key-id', re: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g },
|
|
25
|
+
{
|
|
26
|
+
name: 'aws-secret-access-key',
|
|
27
|
+
re: /aws_secret_access_key\s*[=:]\s*["']?([A-Za-z0-9/+=]{40})/gi,
|
|
28
|
+
valueGroup: 1,
|
|
29
|
+
},
|
|
30
|
+
{ name: 'github-token', re: /\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36,}\b/g },
|
|
31
|
+
{ name: 'github-fine-grained-pat', re: /\bgithub_pat_[A-Za-z0-9_]{22,}\b/g },
|
|
32
|
+
{ name: 'slack-token', re: /\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g },
|
|
33
|
+
{ name: 'stripe-live-key', re: /\b(?:sk|rk)_live_[A-Za-z0-9]{16,}\b/g },
|
|
34
|
+
{ name: 'google-api-key', re: /\bAIza[0-9A-Za-z_-]{35}\b/g },
|
|
35
|
+
{
|
|
36
|
+
name: 'private-key-block',
|
|
37
|
+
re: /-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY(?: BLOCK)?-----/g,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'jwt',
|
|
41
|
+
re: /\beyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'generic-credential-assignment',
|
|
45
|
+
re: /(?:password|passwd|secret|api[_-]?key|access[_-]?token|auth[_-]?token|client[_-]?secret)["']?\s*[=:]\s*["']([^"'\s]{8,})["']/gi,
|
|
46
|
+
valueGroup: 1,
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
/** Masked/templated values that are clearly not live secrets. */
|
|
50
|
+
function isPlaceholder(value) {
|
|
51
|
+
if (/^[$<{]/.test(value))
|
|
52
|
+
return true; // $VAR, ${VAR}, <token>, {{token}}
|
|
53
|
+
if (/[xX*•]{6,}|\.{3,}/.test(value))
|
|
54
|
+
return true; // masked
|
|
55
|
+
if (/(?:example|placeholder|dummy|redacted|changeme|your[_-])/i.test(value))
|
|
56
|
+
return true;
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
function loadAllowlist(projectDir) {
|
|
60
|
+
let raw;
|
|
61
|
+
try {
|
|
62
|
+
raw = readFileSync(join(projectDir, '.invictus', 'secretsignore'), 'utf8');
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
return raw
|
|
68
|
+
.split('\n')
|
|
69
|
+
.map((l) => l.trim())
|
|
70
|
+
.filter((l) => l !== '' && !l.startsWith('#'))
|
|
71
|
+
.map((line) => {
|
|
72
|
+
try {
|
|
73
|
+
return { raw: line, re: new RegExp(line) };
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return { raw: line, re: null };
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function isAllowlisted(rules, candidate, patternName) {
|
|
81
|
+
return rules.some((rule) => {
|
|
82
|
+
if (rule.raw === patternName)
|
|
83
|
+
return true;
|
|
84
|
+
if (rule.re)
|
|
85
|
+
return rule.re.test(candidate);
|
|
86
|
+
return candidate.includes(rule.raw);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function redact(secret) {
|
|
90
|
+
return `${secret.slice(0, 4)}…(redacted, ${secret.length} chars)`;
|
|
91
|
+
}
|
|
92
|
+
function scanText(field, text, rules, findings) {
|
|
93
|
+
for (const pattern of PATTERNS) {
|
|
94
|
+
pattern.re.lastIndex = 0;
|
|
95
|
+
for (const match of text.matchAll(pattern.re)) {
|
|
96
|
+
const full = match[0];
|
|
97
|
+
const value = pattern.valueGroup !== undefined ? (match[pattern.valueGroup] ?? full) : full;
|
|
98
|
+
if (isPlaceholder(value))
|
|
99
|
+
continue;
|
|
100
|
+
if (isAllowlisted(rules, full, pattern.name))
|
|
101
|
+
continue;
|
|
102
|
+
findings.push({ pattern: pattern.name, field, redacted: redact(full) });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** Writing to a .env* file is the taught workflow for secrets — never block it. */
|
|
107
|
+
function isDotEnvWrite(input) {
|
|
108
|
+
if (input.tool_name === 'Bash')
|
|
109
|
+
return false;
|
|
110
|
+
const filePath = input.tool_input?.file_path;
|
|
111
|
+
if (typeof filePath !== 'string')
|
|
112
|
+
return false;
|
|
113
|
+
return /^\.env(?:\.[A-Za-z0-9._-]+)?$/.test(basename(filePath));
|
|
114
|
+
}
|
|
115
|
+
export const secretGuard = {
|
|
116
|
+
name: 'secret-guard',
|
|
117
|
+
events: ['PreToolUse'],
|
|
118
|
+
timeoutMs: 5000,
|
|
119
|
+
run(input, ctx) {
|
|
120
|
+
const toolInput = input.tool_input ?? {};
|
|
121
|
+
if (isDotEnvWrite(input))
|
|
122
|
+
return { mode: 'exit', exitCode: HOOK_EXIT.SUCCESS };
|
|
123
|
+
const fields = [];
|
|
124
|
+
if (typeof toolInput.command === 'string')
|
|
125
|
+
fields.push({ field: 'command', text: toolInput.command });
|
|
126
|
+
if (typeof toolInput.content === 'string')
|
|
127
|
+
fields.push({ field: 'content', text: toolInput.content });
|
|
128
|
+
if (typeof toolInput.new_string === 'string')
|
|
129
|
+
fields.push({ field: 'new_string', text: toolInput.new_string });
|
|
130
|
+
if (Array.isArray(toolInput.edits)) {
|
|
131
|
+
toolInput.edits.forEach((edit, i) => {
|
|
132
|
+
if (edit && typeof edit === 'object') {
|
|
133
|
+
const ns = edit.new_string;
|
|
134
|
+
if (typeof ns === 'string')
|
|
135
|
+
fields.push({ field: `edits[${i}].new_string`, text: ns });
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (fields.length === 0)
|
|
140
|
+
return { mode: 'exit', exitCode: HOOK_EXIT.SUCCESS };
|
|
141
|
+
const rules = loadAllowlist(ctx.projectDir);
|
|
142
|
+
const findings = [];
|
|
143
|
+
for (const { field, text } of fields)
|
|
144
|
+
scanText(field, text, rules, findings);
|
|
145
|
+
if (findings.length === 0)
|
|
146
|
+
return { mode: 'exit', exitCode: HOOK_EXIT.SUCCESS };
|
|
147
|
+
// Block message in the client's render language (manifest.language.render,
|
|
148
|
+
// pt-BR fallback — D-003). Pattern/field names and the redacted value are
|
|
149
|
+
// machine tokens passed as params.
|
|
150
|
+
const t = translatorFor(ctx.projectDir, ctx.env);
|
|
151
|
+
const lines = [
|
|
152
|
+
t('secretGuard.blocked', { tool: input.tool_name ?? 'tool' }),
|
|
153
|
+
...findings.slice(0, 10).map((f) => t('secretGuard.finding', { pattern: f.pattern, field: f.field, redacted: f.redacted })),
|
|
154
|
+
findings.length > 10 ? t('secretGuard.more', { n: findings.length - 10 }) : null,
|
|
155
|
+
'',
|
|
156
|
+
t('secretGuard.never'),
|
|
157
|
+
t('secretGuard.instead'),
|
|
158
|
+
t('secretGuard.falsePositive'),
|
|
159
|
+
].filter((l) => l !== null);
|
|
160
|
+
return { mode: 'exit', exitCode: HOOK_EXIT.BLOCK, stderr: lines.join('\n') + '\n' };
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
//# sourceMappingURL=secret-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-guard.js","sourceRoot":"","sources":["../../src/hooks/secret-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AASjD,MAAM,QAAQ,GAAoB;IAChC,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,EAAE,8BAA8B,EAAE;IACjE,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,qDAAqD,EAAE;IACrF,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,EAAE,gCAA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AAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC;IACtF,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* session-boot — SessionStart.
|
|
3
|
+
*
|
|
4
|
+
* Context injection done right: CLEAN MARKDOWN on STDOUT (SessionStart is
|
|
5
|
+
* one of the two events where stdout enters model context), ≤60 lines, and
|
|
6
|
+
* strictly no ANSI — the legacy kit printed its "context" to stderr with
|
|
7
|
+
* box art and injected nothing (audit §1, hook 10).
|
|
8
|
+
*
|
|
9
|
+
* Content: journal head (MEMORY.md + latest daily entry), git summary,
|
|
10
|
+
* open TODO checkboxes. Everything is optional; an empty repo still boots.
|
|
11
|
+
*
|
|
12
|
+
* Also activates the kit's git hooks in this clone (git-activate.ts): neither
|
|
13
|
+
* `core.hooksPath` nor a lost executable bit travels with `git clone`.
|
|
14
|
+
*/
|
|
15
|
+
import type { HookModule } from '../engine.js';
|
|
16
|
+
export declare const sessionBoot: HookModule;
|
|
17
|
+
//# sourceMappingURL=session-boot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-boot.d.ts","sourceRoot":"","sources":["../../src/hooks/session-boot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,cAAc,CAAC;AA6D5D,eAAO,MAAM,WAAW,EAAE,UAwDzB,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* session-boot — SessionStart.
|
|
3
|
+
*
|
|
4
|
+
* Context injection done right: CLEAN MARKDOWN on STDOUT (SessionStart is
|
|
5
|
+
* one of the two events where stdout enters model context), ≤60 lines, and
|
|
6
|
+
* strictly no ANSI — the legacy kit printed its "context" to stderr with
|
|
7
|
+
* box art and injected nothing (audit §1, hook 10).
|
|
8
|
+
*
|
|
9
|
+
* Content: journal head (MEMORY.md + latest daily entry), git summary,
|
|
10
|
+
* open TODO checkboxes. Everything is optional; an empty repo still boots.
|
|
11
|
+
*
|
|
12
|
+
* Also activates the kit's git hooks in this clone (git-activate.ts): neither
|
|
13
|
+
* `core.hooksPath` nor a lost executable bit travels with `git clone`.
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync } from 'node:fs';
|
|
16
|
+
import { basename, join } from 'node:path';
|
|
17
|
+
import { HOOK_EXIT } from '@invictus-group-ai/core';
|
|
18
|
+
import { activateGitHooks } from '../git-activate.js';
|
|
19
|
+
import { translatorFor } from '../i18n/index.js';
|
|
20
|
+
import { startBackgroundSync } from '../kit-cli.js';
|
|
21
|
+
import { gitOutput, journalDir, latestDailyJournalPath, stripAnsi } from '../shared.js';
|
|
22
|
+
const MAX_LINES = 60;
|
|
23
|
+
function headOfFile(path, maxLines) {
|
|
24
|
+
try {
|
|
25
|
+
return readFileSync(path, 'utf8')
|
|
26
|
+
.split('\n')
|
|
27
|
+
.slice(0, maxLines)
|
|
28
|
+
.map((l) => l.trimEnd());
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function collectTodos(paths, cap) {
|
|
35
|
+
const todos = [];
|
|
36
|
+
for (const path of paths) {
|
|
37
|
+
let text;
|
|
38
|
+
try {
|
|
39
|
+
text = readFileSync(path, 'utf8');
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
for (const line of text.split('\n')) {
|
|
45
|
+
if (/^\s*[-*]\s+\[ \]/.test(line)) {
|
|
46
|
+
todos.push(line.trim());
|
|
47
|
+
if (todos.length >= cap)
|
|
48
|
+
return todos;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return todos;
|
|
53
|
+
}
|
|
54
|
+
function gitSummary(projectDir, t) {
|
|
55
|
+
const branch = gitOutput(['rev-parse', '--abbrev-ref', 'HEAD'], projectDir);
|
|
56
|
+
if (branch === null)
|
|
57
|
+
return [];
|
|
58
|
+
const lines = [t('sessionBoot.branch', { branch })];
|
|
59
|
+
const porcelain = gitOutput(['status', '--porcelain'], projectDir);
|
|
60
|
+
if (porcelain !== null) {
|
|
61
|
+
const entries = porcelain === '' ? [] : porcelain.split('\n');
|
|
62
|
+
const staged = entries.filter((l) => l[0] !== ' ' && l[0] !== '?').length;
|
|
63
|
+
const unstaged = entries.filter((l) => l[1] && l[1] !== ' ' && l[0] !== '?').length;
|
|
64
|
+
const untracked = entries.filter((l) => l.startsWith('??')).length;
|
|
65
|
+
lines.push(t('sessionBoot.workingTree', { staged, modified: unstaged, untracked }));
|
|
66
|
+
}
|
|
67
|
+
const log = gitOutput(['log', '-5', '--oneline', '--no-decorate'], projectDir);
|
|
68
|
+
if (log) {
|
|
69
|
+
lines.push(t('sessionBoot.recentCommits'));
|
|
70
|
+
for (const commit of log.split('\n'))
|
|
71
|
+
lines.push(` - ${commit}`);
|
|
72
|
+
}
|
|
73
|
+
return lines;
|
|
74
|
+
}
|
|
75
|
+
export const sessionBoot = {
|
|
76
|
+
name: 'session-boot',
|
|
77
|
+
events: ['SessionStart'],
|
|
78
|
+
timeoutMs: 8000,
|
|
79
|
+
run(input, ctx) {
|
|
80
|
+
// Send pending metrics without making the session wait for the network
|
|
81
|
+
// (detached, throttled, silent). The push stays the guaranteed path.
|
|
82
|
+
startBackgroundSync(ctx.projectDir, ctx.env);
|
|
83
|
+
// Headers in the client's render language (manifest.language.render,
|
|
84
|
+
// pt-BR fallback — D-003); journal/git/TODO content passes through as-is.
|
|
85
|
+
const t = translatorFor(ctx.projectDir, ctx.env);
|
|
86
|
+
const out = [t('sessionBoot.title'), ''];
|
|
87
|
+
const memoryPath = join(journalDir(ctx.projectDir), 'MEMORY.md');
|
|
88
|
+
const memoryHead = headOfFile(memoryPath, 12);
|
|
89
|
+
if (memoryHead.length > 0) {
|
|
90
|
+
out.push(t('sessionBoot.memory'), ...memoryHead, '');
|
|
91
|
+
}
|
|
92
|
+
const daily = latestDailyJournalPath(ctx.projectDir);
|
|
93
|
+
if (daily) {
|
|
94
|
+
const dailyHead = headOfFile(daily, 14);
|
|
95
|
+
if (dailyHead.length > 0) {
|
|
96
|
+
out.push(t('sessionBoot.journal', { file: basename(daily) }), ...dailyHead, '');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Before the git summary, so a repaired mode shows up in the counts.
|
|
100
|
+
const activation = activateGitHooks(ctx.projectDir);
|
|
101
|
+
const git = gitSummary(ctx.projectDir, t);
|
|
102
|
+
if (activation.hooksPathSet || activation.chmodded.length > 0) {
|
|
103
|
+
git.push(t('sessionBoot.githooksActivated'));
|
|
104
|
+
}
|
|
105
|
+
if (git.length > 0) {
|
|
106
|
+
out.push(t('sessionBoot.git'), ...git, '');
|
|
107
|
+
}
|
|
108
|
+
const todoSources = [join(ctx.projectDir, 'CLAUDE.md'), ...(daily ? [daily] : [])];
|
|
109
|
+
const todos = collectTodos(todoSources, 8);
|
|
110
|
+
if (todos.length > 0) {
|
|
111
|
+
out.push(t('sessionBoot.todos'), ...todos, '');
|
|
112
|
+
}
|
|
113
|
+
if (out.length <= 2) {
|
|
114
|
+
out.push(t('sessionBoot.empty'), '');
|
|
115
|
+
}
|
|
116
|
+
let lines = out.map((l) => stripAnsi(l));
|
|
117
|
+
if (lines.length > MAX_LINES) {
|
|
118
|
+
lines = [...lines.slice(0, MAX_LINES - 1), '…'];
|
|
119
|
+
}
|
|
120
|
+
return { mode: 'exit', exitCode: HOOK_EXIT.SUCCESS, stdout: lines.join('\n') + '\n' };
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
//# sourceMappingURL=session-boot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-boot.js","sourceRoot":"","sources":["../../src/hooks/session-boot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,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AE,CAAC,CAAC,CAAC;QAC3C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YACpB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,EAAE,EAAE,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,IAAI,KAAK,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;YAC7B,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC;IACxF,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* stop-gate — Stop. The ONLY hook allowed on the Stop event (§7).
|
|
3
|
+
*
|
|
4
|
+
* Stop fires after EVERY assistant reply, not at session end — the legacy
|
|
5
|
+
* kit hung five hooks off it and two of them could block Claude forever
|
|
6
|
+
* because nothing checked `stop_hook_active` (audit defects #1 and #2).
|
|
7
|
+
*
|
|
8
|
+
* Contract here:
|
|
9
|
+
* 1. FIRST: `stop_hook_active` → exit 0, unconditionally (no infinite loop).
|
|
10
|
+
* 2. Single check: commits were made this session AND the journal has no
|
|
11
|
+
* entry since the last commit → block ONCE (exit 2, reason on stderr).
|
|
12
|
+
* A per-session marker file guarantees the ONCE.
|
|
13
|
+
* 3. Anything unreadable → fail open (exit 0).
|
|
14
|
+
*/
|
|
15
|
+
import type { HookModule } from '../engine.js';
|
|
16
|
+
export declare const stopGate: HookModule;
|
|
17
|
+
//# sourceMappingURL=stop-gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop-gate.d.ts","sourceRoot":"","sources":["../../src/hooks/stop-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,cAAc,CAAC;AAuC5D,eAAO,MAAM,QAAQ,EAAE,UA8CtB,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* stop-gate — Stop. The ONLY hook allowed on the Stop event (§7).
|
|
3
|
+
*
|
|
4
|
+
* Stop fires after EVERY assistant reply, not at session end — the legacy
|
|
5
|
+
* kit hung five hooks off it and two of them could block Claude forever
|
|
6
|
+
* because nothing checked `stop_hook_active` (audit defects #1 and #2).
|
|
7
|
+
*
|
|
8
|
+
* Contract here:
|
|
9
|
+
* 1. FIRST: `stop_hook_active` → exit 0, unconditionally (no infinite loop).
|
|
10
|
+
* 2. Single check: commits were made this session AND the journal has no
|
|
11
|
+
* entry since the last commit → block ONCE (exit 2, reason on stderr).
|
|
12
|
+
* A per-session marker file guarantees the ONCE.
|
|
13
|
+
* 3. Anything unreadable → fail open (exit 0).
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync, statSync, writeFileSync } from 'node:fs';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import { HOOK_EXIT } from '@invictus-group-ai/core';
|
|
18
|
+
import { translatorFor } from '../i18n/index.js';
|
|
19
|
+
import { ensureDir, gitOutput, latestJournalMtimeMs, readFirstLine, shortHash8, } from '../shared.js';
|
|
20
|
+
const ALLOW = { mode: 'exit', exitCode: HOOK_EXIT.SUCCESS };
|
|
21
|
+
/** Session start (epoch seconds): first transcript timestamp, else file times. */
|
|
22
|
+
function sessionStartSec(transcriptPath) {
|
|
23
|
+
const firstLine = readFirstLine(transcriptPath);
|
|
24
|
+
if (firstLine !== null) {
|
|
25
|
+
try {
|
|
26
|
+
const parsed = JSON.parse(firstLine);
|
|
27
|
+
if (typeof parsed.timestamp === 'string') {
|
|
28
|
+
const ts = Date.parse(parsed.timestamp);
|
|
29
|
+
if (Number.isFinite(ts))
|
|
30
|
+
return Math.floor(ts / 1000);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
/* fall through to stat */
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const st = statSync(transcriptPath);
|
|
39
|
+
const ms = st.birthtimeMs > 0 ? st.birthtimeMs : st.mtimeMs;
|
|
40
|
+
return Math.floor(ms / 1000);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function markerPath(projectDir, sessionId) {
|
|
47
|
+
return join(projectDir, '.invictus', 'local', 'stop-gate', `${shortHash8(sessionId)}.blocked`);
|
|
48
|
+
}
|
|
49
|
+
export const stopGate = {
|
|
50
|
+
name: 'stop-gate',
|
|
51
|
+
events: ['Stop'],
|
|
52
|
+
timeoutMs: 8000,
|
|
53
|
+
run(input, ctx) {
|
|
54
|
+
// (1) MUST be the first check — prevents the infinite Stop-block loop.
|
|
55
|
+
if (input.stop_hook_active === true)
|
|
56
|
+
return ALLOW;
|
|
57
|
+
// (2) Block at most once per session.
|
|
58
|
+
const marker = markerPath(ctx.projectDir, input.session_id);
|
|
59
|
+
if (existsSync(marker))
|
|
60
|
+
return ALLOW;
|
|
61
|
+
const startedSec = sessionStartSec(input.transcript_path);
|
|
62
|
+
if (startedSec === null)
|
|
63
|
+
return ALLOW;
|
|
64
|
+
const lastCommitRaw = gitOutput(['log', '-1', '--format=%ct'], ctx.projectDir);
|
|
65
|
+
if (lastCommitRaw === null || lastCommitRaw === '')
|
|
66
|
+
return ALLOW; // no repo / no commits
|
|
67
|
+
const lastCommitSec = Number.parseInt(lastCommitRaw, 10);
|
|
68
|
+
if (!Number.isFinite(lastCommitSec))
|
|
69
|
+
return ALLOW;
|
|
70
|
+
if (lastCommitSec < startedSec)
|
|
71
|
+
return ALLOW; // no commits this session
|
|
72
|
+
const journalMs = latestJournalMtimeMs(ctx.projectDir);
|
|
73
|
+
if (journalMs !== null && journalMs / 1000 >= lastCommitSec)
|
|
74
|
+
return ALLOW; // journaled already
|
|
75
|
+
// Record the marker BEFORE blocking so a crash can never block twice.
|
|
76
|
+
if (ensureDir(join(ctx.projectDir, '.invictus', 'local', 'stop-gate'))) {
|
|
77
|
+
try {
|
|
78
|
+
writeFileSync(marker, `${Math.floor(Date.now() / 1000)}\n`, 'utf8');
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return ALLOW; // cannot guarantee "once" — fail open instead of risking a loop
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return ALLOW;
|
|
86
|
+
}
|
|
87
|
+
// Localized block reason (manifest.language.render, pt-BR fallback); the
|
|
88
|
+
// instruction to run the invi-journal skill keeps identical meaning.
|
|
89
|
+
const t = translatorFor(ctx.projectDir, ctx.env);
|
|
90
|
+
return {
|
|
91
|
+
mode: 'exit',
|
|
92
|
+
exitCode: HOOK_EXIT.BLOCK,
|
|
93
|
+
stderr: t('stopGate.blocked') + '\n',
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=stop-gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop-gate.js","sourceRoot":"","sources":["../../src/hooks/stop-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,I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AAK,IAAI,IAAI,SAAS,GAAG,IAAI,IAAI,aAAa;YAAE,OAAO,KAAK,CAAC,CAAC,oBAAoB;QAE/F,sEAAsE;QACtE,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC;YACvE,IAAI,CAAC;gBACH,aAAa,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACtE,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAC,CAAC,gEAAgE;YAChF,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAC;QACf,CAAC;QAED,yEAAyE;QACzE,qEAAqE;QACrE,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QACjD,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,SAAS,CAAC,KAAK;YACzB,MAAM,EAAE,CAAC,CAAC,kBAAkB,CAAC,GAAG,IAAI;SACrC,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* typecheck-on-edit — PostToolUse on Write | Edit | MultiEdit for .ts/.tsx.
|
|
3
|
+
*
|
|
4
|
+
* Runs a PROJECT-SCOPED `tsc --noEmit -p <nearest tsconfig.json>` — never
|
|
5
|
+
* `tsc <file>`, which ignores tsconfig (path aliases, JSX config) and was
|
|
6
|
+
* the legacy kit's false-positive machine (audit §1, hook 04).
|
|
7
|
+
*
|
|
8
|
+
* Warn-only: type errors surface via exit 2 (stderr reaches the agent on
|
|
9
|
+
* PostToolUse); they never undo the edit. Off by default — enabled when the
|
|
10
|
+
* manifest lists this hook in `hooks[]` (the per-stack toggle set at init),
|
|
11
|
+
* or forced with INVICTUS_TYPECHECK=1 / disabled with INVICTUS_TYPECHECK=0.
|
|
12
|
+
*
|
|
13
|
+
* Fail-open: missing tsconfig, missing tsc binary, or a tsc timeout all
|
|
14
|
+
* exit 0 silently.
|
|
15
|
+
*/
|
|
16
|
+
import type { HookModule } from '../engine.js';
|
|
17
|
+
export declare const typecheckOnEdit: HookModule;
|
|
18
|
+
//# sourceMappingURL=typecheck-on-edit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typecheck-on-edit.d.ts","sourceRoot":"","sources":["../../src/hooks/typecheck-on-edit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,cAAc,CAAC;AAkD5D,eAAO,MAAM,eAAe,EAAE,UAgD7B,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* typecheck-on-edit — PostToolUse on Write | Edit | MultiEdit for .ts/.tsx.
|
|
3
|
+
*
|
|
4
|
+
* Runs a PROJECT-SCOPED `tsc --noEmit -p <nearest tsconfig.json>` — never
|
|
5
|
+
* `tsc <file>`, which ignores tsconfig (path aliases, JSX config) and was
|
|
6
|
+
* the legacy kit's false-positive machine (audit §1, hook 04).
|
|
7
|
+
*
|
|
8
|
+
* Warn-only: type errors surface via exit 2 (stderr reaches the agent on
|
|
9
|
+
* PostToolUse); they never undo the edit. Off by default — enabled when the
|
|
10
|
+
* manifest lists this hook in `hooks[]` (the per-stack toggle set at init),
|
|
11
|
+
* or forced with INVICTUS_TYPECHECK=1 / disabled with INVICTUS_TYPECHECK=0.
|
|
12
|
+
*
|
|
13
|
+
* Fail-open: missing tsconfig, missing tsc binary, or a tsc timeout all
|
|
14
|
+
* exit 0 silently.
|
|
15
|
+
*/
|
|
16
|
+
import { execFileSync } from 'node:child_process';
|
|
17
|
+
import { dirname, join, relative } from 'node:path';
|
|
18
|
+
import { HOOK_EXIT } from '@invictus-group-ai/core';
|
|
19
|
+
import { translatorFor } from '../i18n/index.js';
|
|
20
|
+
import { findUp, readManifestSafe } from '../shared.js';
|
|
21
|
+
const TS_FILE_RE = /\.(?:ts|tsx|mts|cts)$/;
|
|
22
|
+
const DECLARATION_RE = /\.d\.(?:ts|mts|cts)$/;
|
|
23
|
+
const MAX_REPORTED_LINES = 30;
|
|
24
|
+
function isEnabled(ctx) {
|
|
25
|
+
const flag = ctx.env.INVICTUS_TYPECHECK;
|
|
26
|
+
if (flag === '0' || flag === 'false')
|
|
27
|
+
return false;
|
|
28
|
+
if (flag === '1' || flag === 'true')
|
|
29
|
+
return true;
|
|
30
|
+
const manifest = readManifestSafe(ctx.projectDir);
|
|
31
|
+
return manifest?.hooks.includes('typecheck-on-edit') ?? false;
|
|
32
|
+
}
|
|
33
|
+
function resolveTsc(tsconfigDir, ctx) {
|
|
34
|
+
const fromEnv = ctx.env.INVICTUS_TSC;
|
|
35
|
+
if (typeof fromEnv === 'string' && fromEnv.length > 0)
|
|
36
|
+
return fromEnv;
|
|
37
|
+
const binName = process.platform === 'win32' ? 'tsc.cmd' : 'tsc';
|
|
38
|
+
return findUp(join('node_modules', '.bin', binName), tsconfigDir, ctx.projectDir);
|
|
39
|
+
}
|
|
40
|
+
function runTsc(tsc, tsconfigPath, cwd, timeoutMs) {
|
|
41
|
+
try {
|
|
42
|
+
execFileSync(tsc, ['--noEmit', '-p', tsconfigPath], {
|
|
43
|
+
cwd,
|
|
44
|
+
encoding: 'utf8',
|
|
45
|
+
timeout: timeoutMs,
|
|
46
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
47
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
48
|
+
shell: process.platform === 'win32',
|
|
49
|
+
});
|
|
50
|
+
return { ok: true, output: '' };
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
const e = err;
|
|
54
|
+
if (e.code === 'ENOENT' || e.code === 'ETIMEDOUT' || e.killed) {
|
|
55
|
+
return null; // cannot judge — fail open
|
|
56
|
+
}
|
|
57
|
+
const output = `${e.stdout ?? ''}\n${e.stderr ?? ''}`.trim();
|
|
58
|
+
if (output === '')
|
|
59
|
+
return null; // crashed without diagnostics — fail open
|
|
60
|
+
return { ok: false, output };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export const typecheckOnEdit = {
|
|
64
|
+
name: 'typecheck-on-edit',
|
|
65
|
+
events: ['PostToolUse'],
|
|
66
|
+
timeoutMs: 90_000,
|
|
67
|
+
run(input, ctx) {
|
|
68
|
+
const ok = { mode: 'exit', exitCode: HOOK_EXIT.SUCCESS };
|
|
69
|
+
if (!['Write', 'Edit', 'MultiEdit'].includes(input.tool_name ?? ''))
|
|
70
|
+
return ok;
|
|
71
|
+
const filePath = input.tool_input?.file_path;
|
|
72
|
+
if (typeof filePath !== 'string')
|
|
73
|
+
return ok;
|
|
74
|
+
if (!TS_FILE_RE.test(filePath) || DECLARATION_RE.test(filePath))
|
|
75
|
+
return ok;
|
|
76
|
+
if (!isEnabled(ctx))
|
|
77
|
+
return ok;
|
|
78
|
+
const tsconfigPath = findUp('tsconfig.json', dirname(filePath), ctx.projectDir);
|
|
79
|
+
if (!tsconfigPath)
|
|
80
|
+
return ok;
|
|
81
|
+
const tsconfigDir = dirname(tsconfigPath);
|
|
82
|
+
const tsc = resolveTsc(tsconfigDir, ctx);
|
|
83
|
+
if (!tsc)
|
|
84
|
+
return ok;
|
|
85
|
+
const rawTimeout = Number.parseInt(ctx.env.INVICTUS_TSC_TIMEOUT_MS ?? '', 10);
|
|
86
|
+
const timeoutMs = Number.isFinite(rawTimeout) && rawTimeout > 0 ? rawTimeout : 60_000;
|
|
87
|
+
const result = runTsc(tsc, tsconfigPath, tsconfigDir, timeoutMs);
|
|
88
|
+
if (result === null || result.ok)
|
|
89
|
+
return ok;
|
|
90
|
+
const allLines = result.output.split('\n').filter((l) => l.trim() !== '');
|
|
91
|
+
const editedRel = relative(tsconfigDir, filePath);
|
|
92
|
+
const mine = allLines.filter((l) => l.includes(editedRel) || l.includes(filePath));
|
|
93
|
+
const others = allLines.filter((l) => !mine.includes(l));
|
|
94
|
+
const reported = [...mine.slice(0, 20), ...others.slice(0, MAX_REPORTED_LINES - Math.min(mine.length, 20))];
|
|
95
|
+
// Header/footer localized (manifest.language.render, pt-BR fallback);
|
|
96
|
+
// the tsc diagnostic lines are compiler output and pass through verbatim.
|
|
97
|
+
const t = translatorFor(ctx.projectDir, ctx.env);
|
|
98
|
+
const message = [
|
|
99
|
+
t('typecheck.header', {
|
|
100
|
+
file: editedRel,
|
|
101
|
+
tsconfig: relative(ctx.projectDir, tsconfigPath) || 'tsconfig.json',
|
|
102
|
+
}),
|
|
103
|
+
...reported,
|
|
104
|
+
allLines.length > reported.length ? t('typecheck.omitted', { n: allLines.length - reported.length }) : null,
|
|
105
|
+
t('typecheck.warnOnly'),
|
|
106
|
+
].filter((l) => l !== null);
|
|
107
|
+
return { mode: 'exit', exitCode: HOOK_EXIT.BLOCK, stderr: message.join('\n') + '\n' };
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=typecheck-on-edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typecheck-on-edit.js","sourceRoot":"","sources":["../../src/hooks/typecheck-on-edit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAExD,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAC3C,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAC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,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EN hook-message catalog — the CANONICAL source (D-003, ARCHITECTURE §9).
|
|
3
|
+
* Same catalog pattern as packages/kit/src/i18n: `MessageKey` is derived from
|
|
4
|
+
* this object, and pt-BR.ts is typed `Record<MessageKey, string>`, so a
|
|
5
|
+
* missing or extra translation FAILS THE BUILD (`tsc` runs before every test).
|
|
6
|
+
*
|
|
7
|
+
* TRANSLATION CONTRACT: the parts the agent must OBEY (workflow instructions
|
|
8
|
+
* like "write the migration to db/migrations/…", "run the invi-journal
|
|
9
|
+
* skill") keep IDENTICAL MEANING across languages — translate, never
|
|
10
|
+
* paraphrase. Machine tokens (paths, file names, skill names, `-- UP` /
|
|
11
|
+
* `-- DOWN`, `$VAR`, pattern/field names) are never translated.
|
|
12
|
+
*/
|
|
13
|
+
export declare const en: {
|
|
14
|
+
readonly 'secretGuard.blocked': "Invictus secret-guard blocked this {tool} call: possible secret(s) detected.";
|
|
15
|
+
readonly 'secretGuard.finding': " - {pattern} in {field}: {redacted}";
|
|
16
|
+
readonly 'secretGuard.more': " … and {n} more";
|
|
17
|
+
readonly 'secretGuard.never': "Never write live credentials into code, commands, or tracked files.";
|
|
18
|
+
readonly 'secretGuard.instead': "Instead: put the value in a git-ignored .env file (or the environment) and reference it as $VAR / process.env.VAR.";
|
|
19
|
+
readonly 'secretGuard.falsePositive': "False positive? Add a matching regex line to .invictus/secretsignore and retry.";
|
|
20
|
+
readonly 'dbGuard.blocked': "Invictus db-guard blocked a direct database write:";
|
|
21
|
+
readonly 'dbGuard.reason': " - {reason}";
|
|
22
|
+
readonly 'dbGuard.workflowIntro': "Database mutations are the human's responsibility. Use the migration-file workflow instead:";
|
|
23
|
+
readonly 'dbGuard.step1': " 1. Write the SQL/DDL to a new file: db/migrations/<YYYYMMDDHHMMSS>_<short_description>.sql";
|
|
24
|
+
readonly 'dbGuard.step2': " 2. Include both sections: \"-- UP\" (the change) and \"-- DOWN\" (the rollback).";
|
|
25
|
+
readonly 'dbGuard.step3': " 3. Tell the user the migration file is ready for review — a human applies it.";
|
|
26
|
+
readonly 'dbGuard.readOnly': "Read-only commands (SELECT, EXPLAIN, \\d, --dry-run, status) are allowed.";
|
|
27
|
+
readonly 'typecheck.header': "Invictus typecheck-on-edit: tsc reports errors after editing {file} (project: {tsconfig}).";
|
|
28
|
+
readonly 'typecheck.omitted': "… {n} more line(s) omitted.";
|
|
29
|
+
readonly 'typecheck.warnOnly': "This is a warning — the edit was applied. Fix the type errors before moving on.";
|
|
30
|
+
readonly 'stopGate.blocked': string;
|
|
31
|
+
readonly 'journalNudge.context': string;
|
|
32
|
+
readonly 'sessionBoot.title': "## Invictus session context";
|
|
33
|
+
readonly 'sessionBoot.memory': "### Memory (journal/MEMORY.md)";
|
|
34
|
+
readonly 'sessionBoot.journal': "### Journal — {file}";
|
|
35
|
+
readonly 'sessionBoot.git': "### Git";
|
|
36
|
+
readonly 'sessionBoot.branch': "- Branch: `{branch}`";
|
|
37
|
+
readonly 'sessionBoot.workingTree': "- Working tree: {staged} staged, {modified} modified, {untracked} untracked";
|
|
38
|
+
readonly 'sessionBoot.recentCommits': "- Recent commits:";
|
|
39
|
+
readonly 'sessionBoot.todos': "### Open TODOs";
|
|
40
|
+
readonly 'sessionBoot.empty': "_No journal, git history, or TODOs found yet — fresh workspace._";
|
|
41
|
+
readonly 'sessionBoot.githooksActivated': "- Git hooks activated in this clone (core.hooksPath → .githooks, executable bit). If `git status` shows a mode change under .githooks/, commit it: later clones then come up active.";
|
|
42
|
+
};
|
|
43
|
+
/** Union of every catalog key — a translation missing one fails the build. */
|
|
44
|
+
export type MessageKey = keyof typeof en;
|
|
45
|
+
//# sourceMappingURL=en.d.ts.map
|