ctxtop 4.0.0 → 4.1.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/.antigravity-plugin/plugin.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHECKSUMS.sha256 +59 -42
- package/README.md +351 -330
- package/bin/ah-statusline.mjs +30 -0
- package/bin/ctxtop.mjs +330 -5
- package/config/default_flightcheck.json +19 -0
- package/config/modelCatalog.json +165 -0
- package/hooks/handlers/compact-lifecycle.mjs +323 -8
- package/hooks/handlers/config-change.mjs +402 -0
- package/hooks/handlers/hookIo.mjs +56 -0
- package/hooks/handlers/post-model-switch.mjs +111 -0
- package/hooks/handlers/post-tool-use.mjs +117 -16
- package/hooks/handlers/pre-model-switch.mjs +823 -24
- package/hooks/handlers/pre-tool-use.mjs +271 -4
- package/hooks/handlers/stop-gate.mjs +297 -11
- package/hooks/handlers/user-prompt-submit.mjs +224 -0
- package/hooks/hooks.json +50 -0
- package/hooks/post_tool_use.mjs +8 -0
- package/hooks/register.js +48 -9
- package/hooks/session_start.mjs +11 -1
- package/hooks/stop.mjs +11 -1
- package/package.json +11 -4
- package/packages/antigravity/package.json +1 -1
- package/packages/claude-code/package.json +1 -1
- package/packages/core/package.json +1 -1
- package/packages/engine-node/package.json +1 -1
- package/packages/mcp/package.json +1 -1
- package/packages/mcp/src/server.mjs +1 -1
- package/packages/pro/package.json +1 -1
- package/plugin.json +1 -1
- package/sidecars/horizon-daemon/server.mjs +38 -2
- package/skills/handoff/SKILL.md +8 -0
- package/src/adapters/antigravity/index.mjs +31 -1
- package/src/adapters/claude-code/index.mjs +40 -1
- package/src/cli/horizon_hud.mjs +254 -52
- package/src/config/modelCatalog.json +84 -0
- package/src/core/bucket_b_runtime.mjs +1200 -0
- package/src/core/constants.mjs +191 -4
- package/src/core/detectors_det01_to_16.mjs +54 -5
- package/src/core/doc_indexer.mjs +338 -0
- package/src/core/layer5_hygiene.mjs +118 -0
- package/src/core/parser.mjs +2 -1
- package/src/core/paths.mjs +3 -2
- package/src/core/rsl_clash_auditor.mjs +423 -0
- package/src/core/rsl_distiller.mjs +372 -0
- package/src/core/rsl_ledger.mjs +969 -0
- package/src/core/rsl_triage.mjs +909 -0
- package/src/core/session_auditor.mjs +658 -0
- package/src/core/shield_manager.mjs +1417 -0
- package/src/core/task_quota_router.mjs +1 -1
- package/src/core-isomorphic/coach/cacheGravityRouter.mjs +874 -47
- package/src/core-isomorphic/coach/resumeToolsetAuditor.mjs +321 -0
- package/src/core-isomorphic/coach/smartCompactAdvisor.mjs +305 -0
- package/src/core-isomorphic/coach/ttlWatchdog.mjs +13 -6
- package/src/core-isomorphic/config/anthropicModelCatalog.json +404 -1
- package/src/core-isomorphic/config/catalogLoader.mjs +546 -46
- package/src/core-isomorphic/config/horizonConfig.mjs +47 -1
- package/src/core-isomorphic/diagnostics/prompt_hygiene_governor.mjs +266 -0
- package/src/core-isomorphic/economics/cacheGravity.mjs +18 -0
- package/src/core-isomorphic/economics/cliffBreaker.mjs +98 -12
- package/src/core-isomorphic/economics/driftLatency.mjs +114 -0
- package/src/core-isomorphic/guards/bucketBAlphaBeta.mjs +860 -0
- package/src/core-isomorphic/guards/bucketBGamma.mjs +442 -0
- package/src/core-isomorphic/guards/bucketBHeuristics.mjs +37 -0
- package/src/core-isomorphic/guards/circuitBreakers.mjs +191 -191
- package/src/core-isomorphic/guards/det01_03_shell_secret.mjs +154 -5
- package/src/core-isomorphic/guards/det04_12_thrash_rot.mjs +103 -11
- package/src/core-isomorphic/guards/det13_20_mcp_scope.mjs +311 -1
- package/src/core-isomorphic/guards/docIndexCore.mjs +446 -0
- package/src/core-isomorphic/guards/losslessPostSanitizer.mjs +16 -0
- package/src/core-isomorphic/guards/slopsquatGate.mjs +551 -0
- package/src/core-isomorphic/index.js +1 -0
- package/src/core-isomorphic/telemetry/telemetryBridge.mjs +36 -12
- package/src/core-isomorphic/ui/horizonPanelHtml.mjs +293 -237
- package/src/core-isomorphic/ui/modViews.mjs +35 -9
- package/src/diagnostics/claudeHookCapabilities.mjs +396 -0
- package/src/diagnostics/doctorEngine.mjs +95 -3
- package/src/engine-node/db/probe.mjs +234 -2
- package/src/engine-node/index.mjs +3 -0
- package/src/engine-node/sensors/blindspots.mjs +13 -6
- package/src/hooks/antigravity_rsl_hook.mjs +250 -0
- package/src/hooks/claude_rsl_hook.mjs +288 -0
- package/src/hooks/post_invocation.mjs +196 -4
- package/src/hooks/pre_invocation.mjs +732 -22
- package/src/hooks/session_start.mjs +39 -1
- package/src/utils/modelSwitchTelemetry.mjs +308 -0
- package/src/utils/sessionCalibration.mjs +657 -0
- package/src/webview/horizon_panel.html +1325 -317
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @file src/core/doc_indexer.mjs
|
|
4
|
+
* Zero-Token Structural Document & Log Indexer (`< 20ms`, zero LLM calls).
|
|
5
|
+
*
|
|
6
|
+
* Exposes programmatic helpers (`resolveIndexPath`, `checkIndex`, `buildIndex`, `sliceFile`)
|
|
7
|
+
* and CLI flags:
|
|
8
|
+
* - `--check <file> [--cwd <dir>]` -> exits `0` (`FRESH`), `1` (`STALE`), or `2` (`MISSING`)
|
|
9
|
+
* - `--build <file> [--cwd <dir>]` -> writes cached `.index.md` under `.agents/cache/indices/`
|
|
10
|
+
* - `--slice <file> <start_line> <end_line>` -> prints 1-indexed line-numbered output
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import crypto from 'node:crypto';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import { atomicWriteFileSync } from './atomic_io.mjs';
|
|
18
|
+
import {
|
|
19
|
+
isForbiddenSkuPath,
|
|
20
|
+
compareIndexFreshness,
|
|
21
|
+
buildStructuralIndexMarkdown,
|
|
22
|
+
formatSlicedLines
|
|
23
|
+
} from '../core-isomorphic/guards/docIndexCore.mjs';
|
|
24
|
+
|
|
25
|
+
export { isForbiddenSkuPath, compareIndexFreshness, buildStructuralIndexMarkdown, formatSlicedLines };
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Computes canonical LF-normalized SHA-256 hex digest of text content.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} rawText
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
export function computeFileContentSha256(rawText = '') {
|
|
34
|
+
const normalized = String(rawText ?? '').replace(/\r\n/g, '\n');
|
|
35
|
+
return crypto.createHash('sha256').update(normalized, 'utf8').digest('hex');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Resolves the gitignored `.agents/cache/indices/<slug>_<hash>.index.md` target path
|
|
40
|
+
* so indexing never dirties `git status` alongside workspace source files.
|
|
41
|
+
* Callers may pass `options.indexPath` when indexing an already-gitignored temp/cache file.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} filePath
|
|
44
|
+
* @param {object} [options={}]
|
|
45
|
+
* @param {string} [options.cwd]
|
|
46
|
+
* @param {string} [options.indexPath]
|
|
47
|
+
* @returns {string}
|
|
48
|
+
*/
|
|
49
|
+
export function resolveIndexPath(filePath, options = {}) {
|
|
50
|
+
if (typeof options.indexPath === 'string' && options.indexPath.trim()) {
|
|
51
|
+
return path.resolve(options.indexPath.trim());
|
|
52
|
+
}
|
|
53
|
+
const baseCwd = path.resolve(options.cwd || process.cwd());
|
|
54
|
+
const absFile = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(baseCwd, filePath);
|
|
55
|
+
const relRaw = path.relative(baseCwd, absFile).replace(/\\/g, '/');
|
|
56
|
+
const isInsideWorkspace = !relRaw.startsWith('..') && !path.isAbsolute(relRaw);
|
|
57
|
+
|
|
58
|
+
// If the file itself already lives inside a gitignored cache/tmp folder, allow adjacent `.index.md`
|
|
59
|
+
if (
|
|
60
|
+
isInsideWorkspace &&
|
|
61
|
+
/^(?:\.agents\/(?:tmp|cache|telemetry)|\.claude\/cache)\//i.test(relRaw)
|
|
62
|
+
) {
|
|
63
|
+
return `${absFile}.index.md`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const keyBasis = isInsideWorkspace ? relRaw : absFile.replace(/\\/g, '/');
|
|
67
|
+
const pathHash = crypto.createHash('sha256').update(keyBasis, 'utf8').digest('hex').slice(0, 12);
|
|
68
|
+
const safeSlug = (isInsideWorkspace ? relRaw : path.basename(absFile))
|
|
69
|
+
.replace(/[^A-Za-z0-9._-]+/g, '_')
|
|
70
|
+
.replace(/^_+|_+$/g, '')
|
|
71
|
+
.slice(-72);
|
|
72
|
+
return path.join(baseCwd, '.agents', 'cache', 'indices', `${safeSlug}_${pathHash}.index.md`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isBlockedTargetPath(absFile, baseCwd) {
|
|
76
|
+
const rel = path.relative(baseCwd, absFile).replace(/\\/g, '/');
|
|
77
|
+
return isForbiddenSkuPath(absFile) || isForbiddenSkuPath(rel);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Checks whether `<file>`'s structural index is `FRESH` (`0`), `STALE` (`1`), or `MISSING` (`2`).
|
|
82
|
+
*
|
|
83
|
+
* @param {string} filePath
|
|
84
|
+
* @param {object} [options={}]
|
|
85
|
+
* @returns {{ code: 0 | 1 | 2, status: 'FRESH' | 'STALE' | 'MISSING' | 'SKIPPED', indexPath: string, sha256: string | null }}
|
|
86
|
+
*/
|
|
87
|
+
export function checkIndex(filePath, options = {}) {
|
|
88
|
+
const baseCwd = path.resolve(options.cwd || process.cwd());
|
|
89
|
+
const absFile = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(baseCwd, filePath);
|
|
90
|
+
const indexPath = resolveIndexPath(absFile, options);
|
|
91
|
+
|
|
92
|
+
if (isBlockedTargetPath(absFile, baseCwd)) {
|
|
93
|
+
return { code: 2, status: 'SKIPPED', indexPath, sha256: null };
|
|
94
|
+
}
|
|
95
|
+
if (!fs.existsSync(absFile) || !fs.statSync(absFile).isFile()) {
|
|
96
|
+
return { code: 2, status: 'MISSING', indexPath, sha256: null };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const rawText = fs.readFileSync(absFile, 'utf8');
|
|
100
|
+
const liveSha = computeFileContentSha256(rawText);
|
|
101
|
+
if (!fs.existsSync(indexPath)) {
|
|
102
|
+
return { code: 2, status: 'MISSING', indexPath, sha256: liveSha };
|
|
103
|
+
}
|
|
104
|
+
const indexMd = fs.readFileSync(indexPath, 'utf8');
|
|
105
|
+
const cmp = compareIndexFreshness(liveSha, indexMd);
|
|
106
|
+
return {
|
|
107
|
+
code: cmp.code,
|
|
108
|
+
status: cmp.status,
|
|
109
|
+
indexPath,
|
|
110
|
+
sha256: liveSha
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Builds or refreshes the zero-token `.index.md` structural map for `<file>`.
|
|
116
|
+
*
|
|
117
|
+
* @param {string} filePath
|
|
118
|
+
* @param {object} [options={}]
|
|
119
|
+
* @returns {{
|
|
120
|
+
* ok: boolean,
|
|
121
|
+
* skipped: boolean,
|
|
122
|
+
* reason?: string,
|
|
123
|
+
* refreshed?: boolean,
|
|
124
|
+
* indexPath: string,
|
|
125
|
+
* relIndexPath: string,
|
|
126
|
+
* sha256: string | null,
|
|
127
|
+
* totalLines: number,
|
|
128
|
+
* spanCount: number,
|
|
129
|
+
* usedFallback: boolean,
|
|
130
|
+
* indexTokens: number,
|
|
131
|
+
* markdown: string
|
|
132
|
+
* }}
|
|
133
|
+
*/
|
|
134
|
+
export function buildIndex(filePath, options = {}) {
|
|
135
|
+
const baseCwd = path.resolve(options.cwd || process.cwd());
|
|
136
|
+
const absFile = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(baseCwd, filePath);
|
|
137
|
+
const indexPath = resolveIndexPath(absFile, options);
|
|
138
|
+
const relIndexPath = path.relative(baseCwd, indexPath).replace(/\\/g, '/');
|
|
139
|
+
|
|
140
|
+
if (isBlockedTargetPath(absFile, baseCwd)) {
|
|
141
|
+
return {
|
|
142
|
+
ok: false,
|
|
143
|
+
skipped: true,
|
|
144
|
+
reason: 'SKU boundary: isolated directory excluded from ctxtop indexing',
|
|
145
|
+
indexPath,
|
|
146
|
+
relIndexPath,
|
|
147
|
+
sha256: null,
|
|
148
|
+
totalLines: 0,
|
|
149
|
+
spanCount: 0,
|
|
150
|
+
usedFallback: false,
|
|
151
|
+
indexTokens: 0,
|
|
152
|
+
markdown: ''
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!fs.existsSync(absFile) || !fs.statSync(absFile).isFile()) {
|
|
157
|
+
return {
|
|
158
|
+
ok: false,
|
|
159
|
+
skipped: true,
|
|
160
|
+
reason: `Target file not found: ${absFile}`,
|
|
161
|
+
indexPath,
|
|
162
|
+
relIndexPath,
|
|
163
|
+
sha256: null,
|
|
164
|
+
totalLines: 0,
|
|
165
|
+
spanCount: 0,
|
|
166
|
+
usedFallback: false,
|
|
167
|
+
indexTokens: 0,
|
|
168
|
+
markdown: ''
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const rawText = fs.readFileSync(absFile, 'utf8');
|
|
173
|
+
const liveSha = computeFileContentSha256(rawText);
|
|
174
|
+
|
|
175
|
+
if (!options.force && fs.existsSync(indexPath)) {
|
|
176
|
+
try {
|
|
177
|
+
const existingMd = fs.readFileSync(indexPath, 'utf8');
|
|
178
|
+
const cmp = compareIndexFreshness(liveSha, existingMd);
|
|
179
|
+
if (cmp.code === 0) {
|
|
180
|
+
const lineCount = rawText.length === 0 ? 0 : rawText.replace(/\r\n/g, '\n').split('\n').length;
|
|
181
|
+
return {
|
|
182
|
+
ok: true,
|
|
183
|
+
skipped: false,
|
|
184
|
+
refreshed: false,
|
|
185
|
+
indexPath,
|
|
186
|
+
relIndexPath,
|
|
187
|
+
sha256: liveSha,
|
|
188
|
+
totalLines: lineCount,
|
|
189
|
+
spanCount: Math.max(0, existingMd.split('\n').filter((l) => l.startsWith('| L')).length),
|
|
190
|
+
usedFallback: existingMd.includes('| Unstructured Span L'),
|
|
191
|
+
indexTokens: Math.max(1, Math.ceil(existingMd.length / 4)),
|
|
192
|
+
markdown: existingMd
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
} catch {
|
|
196
|
+
// Rebuild below
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const relDisplay = path.relative(baseCwd, absFile).replace(/\\/g, '/');
|
|
201
|
+
const displayPath = !relDisplay.startsWith('..') && !path.isAbsolute(relDisplay)
|
|
202
|
+
? relDisplay
|
|
203
|
+
: path.basename(absFile);
|
|
204
|
+
|
|
205
|
+
const built = buildStructuralIndexMarkdown({
|
|
206
|
+
filePath: absFile,
|
|
207
|
+
displayPath,
|
|
208
|
+
rawText,
|
|
209
|
+
sha256: liveSha
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
fs.mkdirSync(path.dirname(indexPath), { recursive: true });
|
|
213
|
+
atomicWriteFileSync(indexPath, built.markdown);
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
ok: true,
|
|
217
|
+
skipped: false,
|
|
218
|
+
refreshed: true,
|
|
219
|
+
indexPath,
|
|
220
|
+
relIndexPath,
|
|
221
|
+
sha256: built.sha256,
|
|
222
|
+
totalLines: built.totalLines,
|
|
223
|
+
spanCount: built.spanCount,
|
|
224
|
+
usedFallback: built.usedFallback,
|
|
225
|
+
indexTokens: built.indexTokens,
|
|
226
|
+
markdown: built.markdown
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Slices `<file>` between 1-indexed `startLine` and `endLine` inclusive across CRLF/LF.
|
|
232
|
+
*
|
|
233
|
+
* @param {string} filePath
|
|
234
|
+
* @param {number} startLine
|
|
235
|
+
* @param {number} endLine
|
|
236
|
+
* @param {object} [options={}]
|
|
237
|
+
* @returns {{ ok: boolean, skipped?: boolean, reason?: string, text: string, startLine: number, endLine: number, totalLines: number }}
|
|
238
|
+
*/
|
|
239
|
+
export function sliceFile(filePath, startLine, endLine, options = {}) {
|
|
240
|
+
const baseCwd = path.resolve(options.cwd || process.cwd());
|
|
241
|
+
const absFile = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(baseCwd, filePath);
|
|
242
|
+
if (isBlockedTargetPath(absFile, baseCwd)) {
|
|
243
|
+
return {
|
|
244
|
+
ok: false,
|
|
245
|
+
skipped: true,
|
|
246
|
+
reason: 'SKU boundary: isolated directory excluded from ctxtop slicing',
|
|
247
|
+
text: '',
|
|
248
|
+
startLine: 0,
|
|
249
|
+
endLine: 0,
|
|
250
|
+
totalLines: 0
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (!fs.existsSync(absFile) || !fs.statSync(absFile).isFile()) {
|
|
254
|
+
return {
|
|
255
|
+
ok: false,
|
|
256
|
+
reason: `File not found: ${absFile}`,
|
|
257
|
+
text: '',
|
|
258
|
+
startLine: 0,
|
|
259
|
+
endLine: 0,
|
|
260
|
+
totalLines: 0
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
const rawText = fs.readFileSync(absFile, 'utf8');
|
|
264
|
+
const sliced = formatSlicedLines(rawText, startLine, endLine);
|
|
265
|
+
return {
|
|
266
|
+
ok: true,
|
|
267
|
+
...sliced
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* CLI runner for `node src/core/doc_indexer.mjs <--check|--build|--slice> ...`.
|
|
273
|
+
*
|
|
274
|
+
* @param {string[]} [args=[]]
|
|
275
|
+
* @returns {{ exitCode: number, output: string }}
|
|
276
|
+
*/
|
|
277
|
+
export function runDocIndexerCli(args = process.argv.slice(2)) {
|
|
278
|
+
const cwdIdx = args.indexOf('--cwd');
|
|
279
|
+
const cwd = cwdIdx !== -1 && args[cwdIdx + 1] ? path.resolve(args[cwdIdx + 1]) : process.cwd();
|
|
280
|
+
const outIdx = args.indexOf('--index-path');
|
|
281
|
+
const indexPath = outIdx !== -1 && args[outIdx + 1] ? path.resolve(args[outIdx + 1]) : undefined;
|
|
282
|
+
const opts = { cwd, ...(indexPath ? { indexPath } : {}) };
|
|
283
|
+
|
|
284
|
+
const checkIdx = args.indexOf('--check');
|
|
285
|
+
if (checkIdx !== -1 && args[checkIdx + 1]) {
|
|
286
|
+
const res = checkIndex(args[checkIdx + 1], opts);
|
|
287
|
+
return {
|
|
288
|
+
exitCode: res.code,
|
|
289
|
+
output: `${res.status} (${res.indexPath})`
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const buildIdx = args.indexOf('--build');
|
|
294
|
+
if (buildIdx !== -1 && args[buildIdx + 1]) {
|
|
295
|
+
const res = buildIndex(args[buildIdx + 1], opts);
|
|
296
|
+
if (!res.ok) {
|
|
297
|
+
return {
|
|
298
|
+
exitCode: res.skipped ? 0 : 1,
|
|
299
|
+
output: res.reason || 'Skipped'
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
exitCode: 0,
|
|
304
|
+
output: `${res.indexPath} (${res.totalLines} lines, ${res.spanCount} spans)`
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const sliceIdx = args.indexOf('--slice');
|
|
309
|
+
if (sliceIdx !== -1 && args[sliceIdx + 1]) {
|
|
310
|
+
const target = args[sliceIdx + 1];
|
|
311
|
+
const start = Number(args[sliceIdx + 2] || 1);
|
|
312
|
+
const end = Number(args[sliceIdx + 3] || start + 149);
|
|
313
|
+
const res = sliceFile(target, start, end, opts);
|
|
314
|
+
if (!res.ok) {
|
|
315
|
+
return { exitCode: 1, output: res.reason || 'Slice failed' };
|
|
316
|
+
}
|
|
317
|
+
return { exitCode: 0, output: res.text };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return {
|
|
321
|
+
exitCode: 1,
|
|
322
|
+
output: 'Usage: doc_indexer.mjs <--check <file> | --build <file> | --slice <file> <start_line> <end_line>> [--cwd <dir>]'
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const isMain = (() => {
|
|
327
|
+
try {
|
|
328
|
+
return process.argv[1] && fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url));
|
|
329
|
+
} catch {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
})();
|
|
333
|
+
|
|
334
|
+
if (isMain) {
|
|
335
|
+
const res = runDocIndexerCli();
|
|
336
|
+
if (res.output) process.stdout.write(`${res.output}\n`);
|
|
337
|
+
process.exit(res.exitCode);
|
|
338
|
+
}
|
|
@@ -963,4 +963,122 @@ export function validateAntigravityHooksSchema(hooksConfig) {
|
|
|
963
963
|
};
|
|
964
964
|
}
|
|
965
965
|
|
|
966
|
+
/**
|
|
967
|
+
* Item A5 (#15): Audits Antigravity `.agents/rules/` markdown files (and `AGENTS.md`) for:
|
|
968
|
+
* 1. Invalid camelCase YAML frontmatter keys (`alwaysOn`, `modelDecision`, `globPattern`, `triggerType`)
|
|
969
|
+
* that are silently dropped by the Antigravity rule loader instead of `always_on`, `model_decision`, `glob`.
|
|
970
|
+
* 2. Cumulative always-on rule token budget exceeding `20,000` tokens.
|
|
971
|
+
* 3. Nested `.agents/rules/<subdir>/<file>.md` files when `.agents/rules.json` is absent.
|
|
972
|
+
*
|
|
973
|
+
* Strictly skips `packages/airlock/`.
|
|
974
|
+
*
|
|
975
|
+
* @param {object} [options={}]
|
|
976
|
+
*/
|
|
977
|
+
export function auditAntigravityRulesIntegrity(options = {}) {
|
|
978
|
+
const workspacePath = path.resolve(options.workspacePath || options.cwd || process.cwd());
|
|
979
|
+
const rulesDir = path.join(workspacePath, '.agents', 'rules');
|
|
980
|
+
const rulesJsonPath = path.join(workspacePath, '.agents', 'rules.json');
|
|
981
|
+
const hasRulesJson = fs.existsSync(rulesJsonPath);
|
|
982
|
+
|
|
983
|
+
const camelCaseFiles = [];
|
|
984
|
+
const nestedUnindexedFiles = [];
|
|
985
|
+
let alwaysOnTokens = 0;
|
|
986
|
+
|
|
987
|
+
const agentsMdPath = path.join(workspacePath, 'AGENTS.md');
|
|
988
|
+
if (fs.existsSync(agentsMdPath)) {
|
|
989
|
+
try {
|
|
990
|
+
const rawAgents = fs.readFileSync(agentsMdPath, 'utf8');
|
|
991
|
+
alwaysOnTokens += Math.ceil(rawAgents.length / 3.8);
|
|
992
|
+
} catch {
|
|
993
|
+
// Ignore unreadable AGENTS.md
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
const walkRules = (dir, relSubdir = '') => {
|
|
998
|
+
if (!fs.existsSync(dir)) return;
|
|
999
|
+
let entries = [];
|
|
1000
|
+
try {
|
|
1001
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
1002
|
+
} catch {
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
for (const entry of entries) {
|
|
1006
|
+
const fullPath = path.join(dir, entry.name);
|
|
1007
|
+
const relFromWorkspace = path.relative(workspacePath, fullPath).replace(/\\/g, '/');
|
|
1008
|
+
if (relFromWorkspace === 'packages/airlock' || relFromWorkspace.startsWith('packages/airlock/')) {
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
if (entry.isDirectory()) {
|
|
1012
|
+
walkRules(fullPath, relSubdir ? `${relSubdir}/${entry.name}` : entry.name);
|
|
1013
|
+
} else if (entry.isFile() && entry.name.endsWith('.md')) {
|
|
1014
|
+
if (relSubdir && !hasRulesJson) {
|
|
1015
|
+
nestedUnindexedFiles.push(relFromWorkspace);
|
|
1016
|
+
}
|
|
1017
|
+
try {
|
|
1018
|
+
const raw = fs.readFileSync(fullPath, 'utf8');
|
|
1019
|
+
const fmMatch = raw.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
1020
|
+
const fm = fmMatch ? fmMatch[1] : '';
|
|
1021
|
+
const badKeys = [];
|
|
1022
|
+
if (/^\s*alwaysOn\s*:/m.test(fm) || /\btrigger\s*:\s*alwaysOn\b/.test(fm)) {
|
|
1023
|
+
badKeys.push('alwaysOn -> trigger: always_on');
|
|
1024
|
+
}
|
|
1025
|
+
if (/^\s*modelDecision\s*:/m.test(fm) || /\btrigger\s*:\s*modelDecision\b/.test(fm)) {
|
|
1026
|
+
badKeys.push('modelDecision -> trigger: model_decision');
|
|
1027
|
+
}
|
|
1028
|
+
if (/^\s*globPattern\s*:/m.test(fm) || /\btrigger\s*:\s*globPattern\b/.test(fm)) {
|
|
1029
|
+
badKeys.push('globPattern -> trigger: glob + globs:');
|
|
1030
|
+
}
|
|
1031
|
+
if (badKeys.length > 0) {
|
|
1032
|
+
camelCaseFiles.push({ file: relFromWorkspace, fixes: badKeys });
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
const isAlwaysOn =
|
|
1036
|
+
!fmMatch ||
|
|
1037
|
+
/\btrigger\s*:\s*always_on\b/i.test(fm) ||
|
|
1038
|
+
/^\s*always_on\s*:\s*true\b/im.test(fm);
|
|
1039
|
+
if (isAlwaysOn) {
|
|
1040
|
+
alwaysOnTokens += Math.ceil(raw.length / 3.8);
|
|
1041
|
+
}
|
|
1042
|
+
} catch {
|
|
1043
|
+
// Ignore unreadable rule file
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
walkRules(rulesDir, '');
|
|
1050
|
+
|
|
1051
|
+
const issues = [];
|
|
1052
|
+
if (camelCaseFiles.length > 0) {
|
|
1053
|
+
const detail = camelCaseFiles
|
|
1054
|
+
.slice(0, 4)
|
|
1055
|
+
.map((c) => `${c.file} (${c.fixes.join(', ')})`)
|
|
1056
|
+
.join('; ');
|
|
1057
|
+
issues.push(`Silent camelCase frontmatter drop in ${detail}`);
|
|
1058
|
+
}
|
|
1059
|
+
if (nestedUnindexedFiles.length > 0) {
|
|
1060
|
+
issues.push(
|
|
1061
|
+
`Nested rule file(s) ignored without .agents/rules.json (${nestedUnindexedFiles.slice(0, 4).join(', ')})`
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
if (alwaysOnTokens > 20000) {
|
|
1065
|
+
issues.push(
|
|
1066
|
+
`Cumulative always-on rules consume ~${alwaysOnTokens.toLocaleString()} tokens (>20,000 token budget)`
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
return {
|
|
1071
|
+
valid: issues.length === 0,
|
|
1072
|
+
triggered: issues.length > 0,
|
|
1073
|
+
camelCaseFiles,
|
|
1074
|
+
nestedUnindexedFiles,
|
|
1075
|
+
alwaysOnTokens,
|
|
1076
|
+
issues,
|
|
1077
|
+
advisory:
|
|
1078
|
+
issues.length > 0
|
|
1079
|
+
? `[Highbeam Quota Shield — Antigravity Rule Validator (#15)] ${issues.join('. ')}.`
|
|
1080
|
+
: null
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
|
|
966
1084
|
|
package/src/core/parser.mjs
CHANGED
|
@@ -131,7 +131,8 @@ export function extractTurnEffortMetadata(entry) {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
const
|
|
134
|
+
const rawExplicit = entry.turnMetadata || entry.turn_metadata;
|
|
135
|
+
const explicitMeta = rawExplicit && typeof rawExplicit === 'object' ? rawExplicit : null;
|
|
135
136
|
const effort = explicitMeta?.effort || explicitMeta?.reasoningEffort || explicitMeta?.reasoning_effort ||
|
|
136
137
|
entry.effort || entry.reasoning_effort || entry.reasoningEffort || null;
|
|
137
138
|
const tier = explicitMeta?.tier || explicitMeta?.effortTier || entry.effortTier || entry.tier || null;
|
package/src/core/paths.mjs
CHANGED
|
@@ -113,8 +113,9 @@ export function isIgnorablePath(p) {
|
|
|
113
113
|
const raw = String(p).replace(/\\/g, '/');
|
|
114
114
|
const s = raw
|
|
115
115
|
.replace(/^[a-z]:\/users\/[^/]+\/appdata\/local\/temp\/[^/]+\//i, '')
|
|
116
|
-
.replace(/^\/(?:private\/)?
|
|
117
|
-
|
|
116
|
+
.replace(/^\/(?:private\/)?var\/folders\/[^/]+\/[^/]+\/[^/]+\/[^/]+\//i, '')
|
|
117
|
+
.replace(/^\/(?:private\/)?tmp\/(?:[^/]+\/)?/i, '');
|
|
118
|
+
if (/(?:^|\/)(?:src|lib|packages|app|bin|test|tests|scripts)\/.*\.(?:[mc]?[jt]sx?|py|rs|go|java|c|cpp|h|hpp|rb|php|swift|kt|vue|svelte|html|css)$/i.test(s)) {
|
|
118
119
|
return false;
|
|
119
120
|
}
|
|
120
121
|
if (/(^|\/)(package-lock\.json|yarn\.lock|pnpm-lock\.yaml|poetry\.lock|Cargo\.lock|Gemfile\.lock|composer\.lock|\.lock)$/i.test(s)) return true;
|