@aragon-agent/cli 0.6.78 → 0.6.79
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/README.md +89 -21
- package/dist/agent/controller.d.ts +36 -0
- package/dist/agent/controller.js +108 -0
- package/dist/agent/system-prompt.d.ts +10 -0
- package/dist/agent/system-prompt.js +6 -0
- package/dist/app/App.js +108 -27
- package/dist/app/index-console.d.ts +59 -0
- package/dist/app/index-console.js +99 -0
- package/dist/cli.js +80 -4
- package/dist/commands/builtins.js +4 -2
- package/dist/commands/catalog.js +7 -1
- package/dist/commands/index-build.js +10 -1
- package/dist/commands/index-command.d.ts +43 -0
- package/dist/commands/index-command.js +244 -0
- package/dist/commands/index-copy.d.ts +50 -0
- package/dist/commands/index-copy.js +82 -0
- package/dist/commands/kit-command.d.ts +10 -0
- package/dist/commands/kit-command.js +8 -2
- package/dist/commands/kits-command.d.ts +35 -0
- package/dist/commands/kits-command.js +137 -0
- package/dist/commands/registry.d.ts +10 -0
- package/dist/compaction/memory-agent.js +61 -0
- package/dist/config/env.d.ts +30 -0
- package/dist/config/env.js +47 -0
- package/dist/config/launch-notice.d.ts +61 -0
- package/dist/config/launch-notice.js +138 -0
- package/dist/config/load.d.ts +20 -0
- package/dist/config/load.js +72 -2
- package/dist/diagnostics/info.d.ts +28 -0
- package/dist/diagnostics/info.js +41 -0
- package/dist/exec/cli-commands.d.ts +24 -0
- package/dist/exec/cli-commands.js +48 -1
- package/dist/exec/index.js +9 -0
- package/dist/exec/options.d.ts +12 -0
- package/dist/host/index-build.d.ts +38 -7
- package/dist/host/index-build.js +74 -20
- package/dist/indexer/commit.d.ts +77 -0
- package/dist/indexer/commit.js +145 -0
- package/dist/indexer/discover.d.ts +50 -0
- package/dist/indexer/discover.js +147 -0
- package/dist/indexer/engine.d.ts +51 -0
- package/dist/indexer/engine.js +477 -0
- package/dist/indexer/errors.d.ts +62 -0
- package/dist/indexer/errors.js +86 -0
- package/dist/indexer/finalize.d.ts +30 -0
- package/dist/indexer/finalize.js +19 -0
- package/dist/indexer/fingerprint.d.ts +41 -0
- package/dist/indexer/fingerprint.js +49 -0
- package/dist/indexer/ignore.d.ts +59 -0
- package/dist/indexer/ignore.js +140 -0
- package/dist/indexer/index.d.ts +21 -0
- package/dist/indexer/index.js +21 -0
- package/dist/indexer/l0.d.ts +55 -0
- package/dist/indexer/l0.js +168 -0
- package/dist/indexer/limits.d.ts +75 -0
- package/dist/indexer/limits.js +106 -0
- package/dist/indexer/link.d.ts +68 -0
- package/dist/indexer/link.js +220 -0
- package/dist/indexer/lock.d.ts +115 -0
- package/dist/indexer/lock.js +270 -0
- package/dist/indexer/parse.d.ts +68 -0
- package/dist/indexer/parse.js +163 -0
- package/dist/indexer/paths.d.ts +99 -0
- package/dist/indexer/paths.js +198 -0
- package/dist/indexer/plan.d.ts +48 -0
- package/dist/indexer/plan.js +80 -0
- package/dist/indexer/rank.d.ts +42 -0
- package/dist/indexer/rank.js +125 -0
- package/dist/indexer/read/cache.d.ts +28 -0
- package/dist/indexer/read/cache.js +54 -0
- package/dist/indexer/read/query.d.ts +48 -0
- package/dist/indexer/read/query.js +361 -0
- package/dist/indexer/scanner/extract.d.ts +36 -0
- package/dist/indexer/scanner/extract.js +134 -0
- package/dist/indexer/scanner/mask.d.ts +44 -0
- package/dist/indexer/scanner/mask.js +198 -0
- package/dist/indexer/scanner/py-extract.d.ts +29 -0
- package/dist/indexer/scanner/py-extract.js +164 -0
- package/dist/indexer/scanner/refs.d.ts +31 -0
- package/dist/indexer/scanner/refs.js +116 -0
- package/dist/indexer/scanner/ts-extract.d.ts +39 -0
- package/dist/indexer/scanner/ts-extract.js +277 -0
- package/dist/indexer/store.d.ts +88 -0
- package/dist/indexer/store.js +309 -0
- package/dist/indexer/tools.d.ts +120 -0
- package/dist/indexer/tools.js +132 -0
- package/dist/indexer/types.d.ts +225 -0
- package/dist/indexer/types.js +44 -0
- package/dist/indexer/wiring.d.ts +45 -0
- package/dist/indexer/wiring.js +42 -0
- package/dist/tools/index.d.ts +16 -2
- package/dist/tools/index.js +23 -0
- package/package.json +3 -3
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `code_query` tool definition (spec 7.3).
|
|
3
|
+
*
|
|
4
|
+
* ONE TOOL WITH AN `op` ENUM, NOT SIX TOOLS. Six separate tools would cost ~400
|
|
5
|
+
* tokens of tool list in every single turn; one tool with an enum costs ~60. That
|
|
6
|
+
* is the whole argument, and it is measurable, which is why it survived review.
|
|
7
|
+
*
|
|
8
|
+
* READ-ONLY BY CONSTRUCTION: the tool is absent from `CALLER_GATED_TOOLS` (which
|
|
9
|
+
* is `MUTATING_TOOLS` plus `skill_create`) and absent from
|
|
10
|
+
* `PLAN_MODE_BLOCKED_TOOLS`. Nothing new is needed to let it run in plan mode or
|
|
11
|
+
* in a read-only governance seat - it simply is not on the blocklist.
|
|
12
|
+
*
|
|
13
|
+
* ASCII ONLY: inside the glyph scanner's scope.
|
|
14
|
+
*/
|
|
15
|
+
import { type AgentTool } from '@aragon-agent/core';
|
|
16
|
+
/** Tool name, exported so the registry, the docs truth set and tests quote one constant. */
|
|
17
|
+
export declare const CODE_QUERY_TOOL_NAME = "code_query";
|
|
18
|
+
/**
|
|
19
|
+
* The description handed to the model. Kept short on purpose: it is paid for on
|
|
20
|
+
* every request, and the operations are self-describing.
|
|
21
|
+
*/
|
|
22
|
+
export declare const CODE_QUERY_DESCRIPTION = "Query the project's AST index: map areas, outline a file, find symbols, show references, impact of a change. Prefer over grep when you need structure. Read-only.";
|
|
23
|
+
/** The six operations, in the order the description lists them. */
|
|
24
|
+
export declare const CODE_QUERY_OPS: readonly ["map", "outline", "find", "symbol", "refs", "impact"];
|
|
25
|
+
/**
|
|
26
|
+
* JSON-schema parameters. `op` is the only required field: every other field is
|
|
27
|
+
* optional and validated by the query layer, so a malformed call still produces
|
|
28
|
+
* an actionable sentence instead of a schema error the model cannot fix.
|
|
29
|
+
*/
|
|
30
|
+
export declare const CODE_QUERY_PARAMETERS: {
|
|
31
|
+
readonly type: "object";
|
|
32
|
+
readonly properties: {
|
|
33
|
+
readonly op: {
|
|
34
|
+
readonly type: "string";
|
|
35
|
+
readonly enum: readonly ["map", "outline", "find", "symbol", "refs", "impact"];
|
|
36
|
+
readonly description: "Operation to run.";
|
|
37
|
+
};
|
|
38
|
+
readonly path: {
|
|
39
|
+
readonly type: "string";
|
|
40
|
+
readonly description: "File or directory for map / outline / impact.";
|
|
41
|
+
};
|
|
42
|
+
readonly query: {
|
|
43
|
+
readonly type: "string";
|
|
44
|
+
readonly description: "Substring for find (matches simple and qualified names).";
|
|
45
|
+
};
|
|
46
|
+
readonly symbol: {
|
|
47
|
+
readonly type: "string";
|
|
48
|
+
readonly description: "Symbol name for symbol / refs.";
|
|
49
|
+
};
|
|
50
|
+
readonly target: {
|
|
51
|
+
readonly type: "string";
|
|
52
|
+
readonly description: "Change target (path or symbol) for impact.";
|
|
53
|
+
};
|
|
54
|
+
readonly kind: {
|
|
55
|
+
readonly type: "string";
|
|
56
|
+
readonly description: "Optional symbol kind filter for find (class, function, method, ...).";
|
|
57
|
+
};
|
|
58
|
+
readonly limit: {
|
|
59
|
+
readonly type: "integer";
|
|
60
|
+
readonly minimum: 1;
|
|
61
|
+
readonly maximum: 100;
|
|
62
|
+
readonly description: "Page size, 1-100 (default 20).";
|
|
63
|
+
};
|
|
64
|
+
readonly cursor: {
|
|
65
|
+
readonly type: "string";
|
|
66
|
+
readonly description: "Opaque page cursor returned by a previous answer.";
|
|
67
|
+
};
|
|
68
|
+
readonly depth: {
|
|
69
|
+
readonly type: "integer";
|
|
70
|
+
readonly minimum: 1;
|
|
71
|
+
readonly maximum: 4;
|
|
72
|
+
readonly description: "Graph depth for map / impact, 1-4 (default 2).";
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
readonly required: readonly ["op"];
|
|
76
|
+
readonly additionalProperties: false;
|
|
77
|
+
};
|
|
78
|
+
/** The subset of the repo's tool shape this module needs; avoids importing the registry. */
|
|
79
|
+
export interface CodeQueryToolSpec {
|
|
80
|
+
/** Tool name. */
|
|
81
|
+
readonly name: string;
|
|
82
|
+
/** One-line description shown to the model. */
|
|
83
|
+
readonly description: string;
|
|
84
|
+
/** JSON schema for the arguments. */
|
|
85
|
+
readonly parameters: typeof CODE_QUERY_PARAMETERS;
|
|
86
|
+
/** True for every tool that cannot write; the registry uses it for read-only seats. */
|
|
87
|
+
readonly readOnly: true;
|
|
88
|
+
/** Token budget the answer is capped to, surfaced for the tool budget check. */
|
|
89
|
+
readonly maxTokens: number;
|
|
90
|
+
}
|
|
91
|
+
/** The tool spec, ready to register. */
|
|
92
|
+
export declare const CODE_QUERY_TOOL: CodeQueryToolSpec;
|
|
93
|
+
/** What the executable tool needs from the session that owns it. */
|
|
94
|
+
export interface CodeQueryToolDeps {
|
|
95
|
+
/** Session working directory; the ROOT is discovered from it, exactly as the engine does. */
|
|
96
|
+
readonly getCwd: () => string;
|
|
97
|
+
/** Live master switch. `/index off` must disable the tool in a session already running. */
|
|
98
|
+
readonly isEnabled?: () => boolean;
|
|
99
|
+
/** Sink for the `index.query` record (spec 5.13). Never receives file contents. */
|
|
100
|
+
readonly log?: (event: string, fields?: Record<string, unknown>) => void;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Build the executable `code_query` tool.
|
|
104
|
+
*
|
|
105
|
+
* WHY THIS EXISTS ALONGSIDE `CODE_QUERY_TOOL`: the constant above is the SPEC (name,
|
|
106
|
+
* description, schema) that the docs truth set and the tests compare against; this
|
|
107
|
+
* function is the thing the model actually calls. Without it the whole "the index
|
|
108
|
+
* reaches the model" half of the feature is a definition nobody executes - a tool
|
|
109
|
+
* that appears in `HOST_TOOL_NAMES` and in the docs page while being absent from the
|
|
110
|
+
* tool array the model is given.
|
|
111
|
+
*
|
|
112
|
+
* READ-ONLY BY CONSTRUCTION: no `recordChange`, no filesystem write, no child process.
|
|
113
|
+
* Every answer is a string produced by `runQuery`, which is itself total - an unbuilt
|
|
114
|
+
* index, an illegal `op` and an empty match all come back as actionable text.
|
|
115
|
+
*
|
|
116
|
+
* THE ROOT IS DISCOVERED, NOT THE CWD. In a monorepo the artifact lives at the git
|
|
117
|
+
* root, and reading `<cwd>/.claude-index/ast` would answer "not built" over a complete
|
|
118
|
+
* index (the same defect `/index clean` had).
|
|
119
|
+
*/
|
|
120
|
+
export declare function createCodeQueryTool(deps: CodeQueryToolDeps): AgentTool;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `code_query` tool definition (spec 7.3).
|
|
3
|
+
*
|
|
4
|
+
* ONE TOOL WITH AN `op` ENUM, NOT SIX TOOLS. Six separate tools would cost ~400
|
|
5
|
+
* tokens of tool list in every single turn; one tool with an enum costs ~60. That
|
|
6
|
+
* is the whole argument, and it is measurable, which is why it survived review.
|
|
7
|
+
*
|
|
8
|
+
* READ-ONLY BY CONSTRUCTION: the tool is absent from `CALLER_GATED_TOOLS` (which
|
|
9
|
+
* is `MUTATING_TOOLS` plus `skill_create`) and absent from
|
|
10
|
+
* `PLAN_MODE_BLOCKED_TOOLS`. Nothing new is needed to let it run in plan mode or
|
|
11
|
+
* in a read-only governance seat - it simply is not on the blocklist.
|
|
12
|
+
*
|
|
13
|
+
* ASCII ONLY: inside the glyph scanner's scope.
|
|
14
|
+
*/
|
|
15
|
+
import { defineTool, textResult } from '@aragon-agent/core';
|
|
16
|
+
import { QUERY_LIMIT_DEFAULT, QUERY_LIMIT_MAX, QUERY_LIMIT_MIN, QUERY_DEPTH_DEFAULT, QUERY_DEPTH_MAX, QUERY_DEPTH_MIN, QUERY_TOKEN_BUDGET } from './limits.js';
|
|
17
|
+
import { discoverRoot, indexPathsFor } from './paths.js';
|
|
18
|
+
import { runQuery } from './read/query.js';
|
|
19
|
+
/** Tool name, exported so the registry, the docs truth set and tests quote one constant. */
|
|
20
|
+
export const CODE_QUERY_TOOL_NAME = 'code_query';
|
|
21
|
+
/**
|
|
22
|
+
* The description handed to the model. Kept short on purpose: it is paid for on
|
|
23
|
+
* every request, and the operations are self-describing.
|
|
24
|
+
*/
|
|
25
|
+
export const CODE_QUERY_DESCRIPTION = "Query the project's AST index: map areas, outline a file, find symbols, show references, impact of a change. Prefer over grep when you need structure. Read-only.";
|
|
26
|
+
/** The six operations, in the order the description lists them. */
|
|
27
|
+
export const CODE_QUERY_OPS = ['map', 'outline', 'find', 'symbol', 'refs', 'impact'];
|
|
28
|
+
/**
|
|
29
|
+
* JSON-schema parameters. `op` is the only required field: every other field is
|
|
30
|
+
* optional and validated by the query layer, so a malformed call still produces
|
|
31
|
+
* an actionable sentence instead of a schema error the model cannot fix.
|
|
32
|
+
*/
|
|
33
|
+
export const CODE_QUERY_PARAMETERS = {
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {
|
|
36
|
+
op: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
enum: [...CODE_QUERY_OPS],
|
|
39
|
+
description: 'Operation to run.',
|
|
40
|
+
},
|
|
41
|
+
path: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
description: 'File or directory for map / outline / impact.',
|
|
44
|
+
},
|
|
45
|
+
query: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
description: 'Substring for find (matches simple and qualified names).',
|
|
48
|
+
},
|
|
49
|
+
symbol: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'Symbol name for symbol / refs.',
|
|
52
|
+
},
|
|
53
|
+
target: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: 'Change target (path or symbol) for impact.',
|
|
56
|
+
},
|
|
57
|
+
kind: {
|
|
58
|
+
type: 'string',
|
|
59
|
+
description: 'Optional symbol kind filter for find (class, function, method, ...).',
|
|
60
|
+
},
|
|
61
|
+
limit: {
|
|
62
|
+
type: 'integer',
|
|
63
|
+
minimum: QUERY_LIMIT_MIN,
|
|
64
|
+
maximum: QUERY_LIMIT_MAX,
|
|
65
|
+
description: `Page size, ${QUERY_LIMIT_MIN}-${QUERY_LIMIT_MAX} (default ${QUERY_LIMIT_DEFAULT}).`,
|
|
66
|
+
},
|
|
67
|
+
cursor: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
description: 'Opaque page cursor returned by a previous answer.',
|
|
70
|
+
},
|
|
71
|
+
depth: {
|
|
72
|
+
type: 'integer',
|
|
73
|
+
minimum: QUERY_DEPTH_MIN,
|
|
74
|
+
maximum: QUERY_DEPTH_MAX,
|
|
75
|
+
description: `Graph depth for map / impact, ${QUERY_DEPTH_MIN}-${QUERY_DEPTH_MAX} (default ${QUERY_DEPTH_DEFAULT}).`,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
required: ['op'],
|
|
79
|
+
additionalProperties: false,
|
|
80
|
+
};
|
|
81
|
+
/** The tool spec, ready to register. */
|
|
82
|
+
export const CODE_QUERY_TOOL = {
|
|
83
|
+
name: CODE_QUERY_TOOL_NAME,
|
|
84
|
+
description: CODE_QUERY_DESCRIPTION,
|
|
85
|
+
parameters: CODE_QUERY_PARAMETERS,
|
|
86
|
+
readOnly: true,
|
|
87
|
+
maxTokens: QUERY_TOKEN_BUDGET,
|
|
88
|
+
};
|
|
89
|
+
/** Sentence for the disabled case: actionable, and it names the switch (spec 7.5). */
|
|
90
|
+
const DISABLED_SENTENCE = 'The project index is off, so code_query has nothing to answer from. Run /index on to enable it.';
|
|
91
|
+
/**
|
|
92
|
+
* Build the executable `code_query` tool.
|
|
93
|
+
*
|
|
94
|
+
* WHY THIS EXISTS ALONGSIDE `CODE_QUERY_TOOL`: the constant above is the SPEC (name,
|
|
95
|
+
* description, schema) that the docs truth set and the tests compare against; this
|
|
96
|
+
* function is the thing the model actually calls. Without it the whole "the index
|
|
97
|
+
* reaches the model" half of the feature is a definition nobody executes - a tool
|
|
98
|
+
* that appears in `HOST_TOOL_NAMES` and in the docs page while being absent from the
|
|
99
|
+
* tool array the model is given.
|
|
100
|
+
*
|
|
101
|
+
* READ-ONLY BY CONSTRUCTION: no `recordChange`, no filesystem write, no child process.
|
|
102
|
+
* Every answer is a string produced by `runQuery`, which is itself total - an unbuilt
|
|
103
|
+
* index, an illegal `op` and an empty match all come back as actionable text.
|
|
104
|
+
*
|
|
105
|
+
* THE ROOT IS DISCOVERED, NOT THE CWD. In a monorepo the artifact lives at the git
|
|
106
|
+
* root, and reading `<cwd>/.claude-index/ast` would answer "not built" over a complete
|
|
107
|
+
* index (the same defect `/index clean` had).
|
|
108
|
+
*/
|
|
109
|
+
export function createCodeQueryTool(deps) {
|
|
110
|
+
return defineTool({
|
|
111
|
+
name: CODE_QUERY_TOOL_NAME,
|
|
112
|
+
label: 'Query code structure',
|
|
113
|
+
description: CODE_QUERY_DESCRIPTION,
|
|
114
|
+
// A MUTABLE COPY, not the constant itself: `CODE_QUERY_PARAMETERS` is `as const` so the
|
|
115
|
+
// docs truth set can compare it literally, and `JSONSchema7` requires mutable arrays.
|
|
116
|
+
// Copying here keeps the published constant readonly and the registered schema legal.
|
|
117
|
+
parameters: JSON.parse(JSON.stringify(CODE_QUERY_PARAMETERS)),
|
|
118
|
+
async execute(_toolCallId, params) {
|
|
119
|
+
if (deps.isEnabled && !deps.isEnabled())
|
|
120
|
+
return textResult(DISABLED_SENTENCE);
|
|
121
|
+
const request = params;
|
|
122
|
+
const root = discoverRoot(deps.getCwd()).root;
|
|
123
|
+
const answer = runQuery({ paths: indexPathsFor(root), root, request });
|
|
124
|
+
deps.log?.('index.query', {
|
|
125
|
+
op: String(request.op),
|
|
126
|
+
tokens: answer.tokens,
|
|
127
|
+
truncated: answer.truncated,
|
|
128
|
+
});
|
|
129
|
+
return textResult(answer.text);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disk and in-memory shapes for the deterministic index (spec 8.1 / 8.2).
|
|
3
|
+
*
|
|
4
|
+
* Field names on disk are short (`p`, `f`, `n`, `k`) on purpose: at a few
|
|
5
|
+
* thousand files the compaction saves a measurable share of the artifact, and
|
|
6
|
+
* every field carries a JSDoc here so readability lives next to the shape
|
|
7
|
+
* instead of in the key. The short keys are a STORAGE FORMAT - renaming one is
|
|
8
|
+
* a schema break, which is why `INDEX_SCHEMA_VERSION` moves with it.
|
|
9
|
+
*
|
|
10
|
+
* ASCII ONLY: `indexer/**` is inside the glyph scanner's scan scope.
|
|
11
|
+
*/
|
|
12
|
+
/** Bumped whenever a row shape changes incompatibly. Readers treat unknown values as "rebuild". */
|
|
13
|
+
export declare const INDEX_SCHEMA_VERSION = 1;
|
|
14
|
+
/** Engine identity recorded in `meta.json`, so a future engine can refuse old artifacts. */
|
|
15
|
+
export declare const INDEX_ENGINE_ID = "aragon-index/1";
|
|
16
|
+
/** Languages the current tier-1 scanner understands. */
|
|
17
|
+
export type IndexLang = 'ts' | 'tsx' | 'js' | 'jsx' | 'mjs' | 'cjs' | 'py' | 'other';
|
|
18
|
+
/** How one file came out of the parser. `partial` means "some symbols, syntax beyond the scanner". */
|
|
19
|
+
export type FileStatus = 'ok' | 'partial' | 'timeout' | 'large' | 'error';
|
|
20
|
+
/** How a reference was resolved during LINK (spec 5.3 stage 5). */
|
|
21
|
+
export type Resolution = 'local' | 'import' | 'this' | 'name' | 'none';
|
|
22
|
+
/**
|
|
23
|
+
* Kind words. BYTE-IDENTICAL to the web scanner's `SYMBOL_KINDS`
|
|
24
|
+
* (`apps/web/src/lib/project-index/kinds.ts`), enforced by
|
|
25
|
+
* `scripts/check-index-vocabulary.mjs` under `npm run test:tooling` (spec 5.8 / AC-23).
|
|
26
|
+
*
|
|
27
|
+
* THE WEB LIST WINS when the two disagree, and it did: the design claimed the vocabularies
|
|
28
|
+
* were already identical, while the cli draft carried `const` / `module` / `decorator` /
|
|
29
|
+
* `unknown` and the web list carries `constant` / `enum_member` / `constructor` / `field`.
|
|
30
|
+
* The browser side is bound to SQLite `CHECK` constraints and to rows already on disk, so it
|
|
31
|
+
* is the authority; this list and the scanner's emissions were corrected to match (see
|
|
32
|
+
* `## 实施过程发现的方案缺陷` in the design). Order is the UI's display order on both sides.
|
|
33
|
+
*/
|
|
34
|
+
export declare const SYMBOL_KINDS: readonly ["class", "interface", "type", "enum", "enum_member", "function", "method", "constructor", "property", "field", "variable", "constant", "namespace"];
|
|
35
|
+
/** Reference kinds. BYTE-IDENTICAL to the web scanner's `REF_KINDS`, same order, same gate. */
|
|
36
|
+
export declare const REF_KINDS: readonly ["call", "new", "type", "extends", "implements", "decorator", "jsx"];
|
|
37
|
+
/** One entry of `SYMBOL_KINDS`. */
|
|
38
|
+
export type SymbolKind = (typeof SYMBOL_KINDS)[number];
|
|
39
|
+
/** One entry of `REF_KINDS`. */
|
|
40
|
+
export type RefKind = (typeof REF_KINDS)[number];
|
|
41
|
+
/** A symbol row as written to `symbols.jsonl`. */
|
|
42
|
+
export interface SymbolRow {
|
|
43
|
+
/** Repo-relative file path. */
|
|
44
|
+
readonly f: string;
|
|
45
|
+
/** Simple name. */
|
|
46
|
+
readonly n: string;
|
|
47
|
+
/** Qualified name, unique inside the file (`Class.method`, `Class#2`). */
|
|
48
|
+
readonly q: string;
|
|
49
|
+
/** Kind word from `SYMBOL_KINDS`. */
|
|
50
|
+
readonly k: SymbolKind;
|
|
51
|
+
/** First line, 1-based. */
|
|
52
|
+
readonly ln: number;
|
|
53
|
+
/** Last line, 1-based, never below `ln`. */
|
|
54
|
+
readonly el: number;
|
|
55
|
+
/** True when exported. */
|
|
56
|
+
readonly x: boolean;
|
|
57
|
+
/** Visibility modifier when the language has one. */
|
|
58
|
+
readonly v?: string;
|
|
59
|
+
/** Single-line signature, truncated by the scanner. */
|
|
60
|
+
readonly sg?: string;
|
|
61
|
+
/** Parent qualified name, when the symbol lives inside another. */
|
|
62
|
+
readonly pa?: string;
|
|
63
|
+
/** Number of files that reference this symbol after LINK. */
|
|
64
|
+
readonly fl: number;
|
|
65
|
+
/** PageRank score in the file graph, 0..1. */
|
|
66
|
+
readonly r: number;
|
|
67
|
+
}
|
|
68
|
+
/** A reference row as written to `refs.jsonl`. */
|
|
69
|
+
export interface RefRow {
|
|
70
|
+
/** Repo-relative file path holding the reference. */
|
|
71
|
+
readonly f: string;
|
|
72
|
+
/** Line of the reference, 1-based. */
|
|
73
|
+
readonly ln: number;
|
|
74
|
+
/** Kind word from `REF_KINDS`. */
|
|
75
|
+
readonly fk: RefKind;
|
|
76
|
+
/** Referenced name. */
|
|
77
|
+
readonly n: string;
|
|
78
|
+
/** Resolved target as `path#qualifiedName`, or '' when unresolved. */
|
|
79
|
+
readonly t: string;
|
|
80
|
+
/** How it was resolved. */
|
|
81
|
+
readonly rs: Resolution;
|
|
82
|
+
}
|
|
83
|
+
/** One imported name inside an import statement. */
|
|
84
|
+
export interface ImportedName {
|
|
85
|
+
/** Name as imported. */
|
|
86
|
+
readonly i: string;
|
|
87
|
+
/** Local binding (differs for `as`). */
|
|
88
|
+
readonly l: string;
|
|
89
|
+
}
|
|
90
|
+
/** An import row as written to `imports.jsonl`. */
|
|
91
|
+
export interface ImportRow {
|
|
92
|
+
/** Repo-relative file path holding the import. */
|
|
93
|
+
readonly f: string;
|
|
94
|
+
/** Line of the import, 1-based. */
|
|
95
|
+
readonly ln: number;
|
|
96
|
+
/** Module specifier exactly as written. */
|
|
97
|
+
readonly sp: string;
|
|
98
|
+
/** `static` | `dynamic` | `require` | `py`. */
|
|
99
|
+
readonly k: 'static' | 'dynamic' | 'require' | 'py';
|
|
100
|
+
/** Resolved target path inside the repo, when the specifier points at one. */
|
|
101
|
+
readonly tp?: string;
|
|
102
|
+
/** Imported names; empty for a bare `import x`. */
|
|
103
|
+
readonly nm: readonly ImportedName[];
|
|
104
|
+
}
|
|
105
|
+
/** One row of `files.jsonl`. */
|
|
106
|
+
export interface FileRow {
|
|
107
|
+
/** Repo-relative path. */
|
|
108
|
+
readonly p: string;
|
|
109
|
+
/** Language bucket. */
|
|
110
|
+
readonly l: IndexLang;
|
|
111
|
+
/** Byte size. */
|
|
112
|
+
readonly b: number;
|
|
113
|
+
/** Content hash, `sha1:<hex>`. */
|
|
114
|
+
readonly h: string;
|
|
115
|
+
/** Line count. */
|
|
116
|
+
readonly n: number;
|
|
117
|
+
/** Parse status. */
|
|
118
|
+
readonly s: FileStatus;
|
|
119
|
+
/** Parse duration in milliseconds. */
|
|
120
|
+
readonly ms: number;
|
|
121
|
+
/** Symbol count in this file. */
|
|
122
|
+
readonly sy: number;
|
|
123
|
+
/** Reference count in this file. */
|
|
124
|
+
readonly rf: number;
|
|
125
|
+
/** Import count in this file. */
|
|
126
|
+
readonly im: number;
|
|
127
|
+
}
|
|
128
|
+
/** A node of `graph.json`. */
|
|
129
|
+
export interface GraphNode {
|
|
130
|
+
/** Repo-relative path. */
|
|
131
|
+
readonly id: string;
|
|
132
|
+
/** PageRank score. */
|
|
133
|
+
readonly rank: number;
|
|
134
|
+
/** Area label, i.e. the top two path segments. */
|
|
135
|
+
readonly area: string;
|
|
136
|
+
}
|
|
137
|
+
/** An edge of `graph.json`. */
|
|
138
|
+
export interface GraphEdge {
|
|
139
|
+
/** Importer path. */
|
|
140
|
+
readonly from: string;
|
|
141
|
+
/** Imported path. */
|
|
142
|
+
readonly to: string;
|
|
143
|
+
/** Edge weight (number of import statements between the two). */
|
|
144
|
+
readonly w: number;
|
|
145
|
+
}
|
|
146
|
+
/** `graph.json` as a whole. */
|
|
147
|
+
export interface FileGraph {
|
|
148
|
+
readonly nodes: readonly GraphNode[];
|
|
149
|
+
readonly edges: readonly GraphEdge[];
|
|
150
|
+
}
|
|
151
|
+
/** Counters recorded in `meta.json`. */
|
|
152
|
+
export interface IndexCounts {
|
|
153
|
+
readonly files: number;
|
|
154
|
+
readonly symbols: number;
|
|
155
|
+
readonly refs: number;
|
|
156
|
+
readonly imports: number;
|
|
157
|
+
}
|
|
158
|
+
/** Resolution histogram recorded in `meta.json`, so `/index status` needs no table scan. */
|
|
159
|
+
export type ResolutionHistogram = Readonly<Record<Resolution, number>>;
|
|
160
|
+
/** Failure histogram recorded in `meta.json`. */
|
|
161
|
+
export type FailureHistogram = Readonly<Record<'timeout' | 'large' | 'error' | 'partial', number>>;
|
|
162
|
+
/** `meta.json`. `gitHead` is frozen at build time: the L0 block may read it, never live HEAD. */
|
|
163
|
+
export interface IndexMeta {
|
|
164
|
+
readonly schemaVersion: number;
|
|
165
|
+
readonly generation: number;
|
|
166
|
+
readonly engine: string;
|
|
167
|
+
readonly builtAt: string;
|
|
168
|
+
readonly root: string;
|
|
169
|
+
readonly gitHead: string | null;
|
|
170
|
+
readonly gitHeadDirty: boolean;
|
|
171
|
+
readonly counts: IndexCounts;
|
|
172
|
+
readonly languages: Readonly<Record<string, number>>;
|
|
173
|
+
readonly resolved: ResolutionHistogram;
|
|
174
|
+
readonly durationMs: number;
|
|
175
|
+
readonly failures: FailureHistogram;
|
|
176
|
+
/** True only when the file set AND the git head were both unchanged (spec 13.4). */
|
|
177
|
+
readonly unchanged: boolean;
|
|
178
|
+
/** Files re-parsed in this generation. */
|
|
179
|
+
readonly reparsed: number;
|
|
180
|
+
/** Files carried over from the previous generation unchanged. */
|
|
181
|
+
readonly reused: number;
|
|
182
|
+
}
|
|
183
|
+
/** The `current` pointer file. Small enough that `rename` is the whole commit. */
|
|
184
|
+
export interface CurrentPointer {
|
|
185
|
+
readonly generation: number;
|
|
186
|
+
readonly schemaVersion: number;
|
|
187
|
+
}
|
|
188
|
+
/** Per-file parse result (stage 3 output, pure data, never written as-is). */
|
|
189
|
+
export interface FileFacts {
|
|
190
|
+
/** Repo-relative path. */
|
|
191
|
+
readonly path: string;
|
|
192
|
+
/** Language bucket. */
|
|
193
|
+
readonly lang: IndexLang;
|
|
194
|
+
/** Byte size on disk. */
|
|
195
|
+
readonly bytes: number;
|
|
196
|
+
/** Content hash, `sha1:<hex>`. */
|
|
197
|
+
readonly sha1: string;
|
|
198
|
+
/** Line count. */
|
|
199
|
+
readonly lines: number;
|
|
200
|
+
/** Parse status. */
|
|
201
|
+
readonly status: FileStatus;
|
|
202
|
+
/** Parse duration in milliseconds. */
|
|
203
|
+
readonly parseMs: number;
|
|
204
|
+
/** Symbols found. */
|
|
205
|
+
readonly symbols: readonly SymbolRow[];
|
|
206
|
+
/** References found (unresolved; LINK fills `t`/`rs`). */
|
|
207
|
+
readonly refs: readonly Omit<RefRow, 't' | 'rs'>[];
|
|
208
|
+
/** Imports found. */
|
|
209
|
+
readonly imports: readonly ImportRow[];
|
|
210
|
+
}
|
|
211
|
+
/** Everything stage 4 writes for one generation, held in memory before COMMIT. */
|
|
212
|
+
export interface GenerationPayload {
|
|
213
|
+
/** Files table. */
|
|
214
|
+
readonly files: readonly FileRow[];
|
|
215
|
+
/** Symbols table. */
|
|
216
|
+
readonly symbols: readonly SymbolRow[];
|
|
217
|
+
/** References table. */
|
|
218
|
+
readonly refs: readonly RefRow[];
|
|
219
|
+
/** Imports table. */
|
|
220
|
+
readonly imports: readonly ImportRow[];
|
|
221
|
+
/** File graph. */
|
|
222
|
+
readonly graph: FileGraph;
|
|
223
|
+
/** Meta without the fields FINALIZE fills in. */
|
|
224
|
+
readonly meta: IndexMeta;
|
|
225
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disk and in-memory shapes for the deterministic index (spec 8.1 / 8.2).
|
|
3
|
+
*
|
|
4
|
+
* Field names on disk are short (`p`, `f`, `n`, `k`) on purpose: at a few
|
|
5
|
+
* thousand files the compaction saves a measurable share of the artifact, and
|
|
6
|
+
* every field carries a JSDoc here so readability lives next to the shape
|
|
7
|
+
* instead of in the key. The short keys are a STORAGE FORMAT - renaming one is
|
|
8
|
+
* a schema break, which is why `INDEX_SCHEMA_VERSION` moves with it.
|
|
9
|
+
*
|
|
10
|
+
* ASCII ONLY: `indexer/**` is inside the glyph scanner's scan scope.
|
|
11
|
+
*/
|
|
12
|
+
/** Bumped whenever a row shape changes incompatibly. Readers treat unknown values as "rebuild". */
|
|
13
|
+
export const INDEX_SCHEMA_VERSION = 1;
|
|
14
|
+
/** Engine identity recorded in `meta.json`, so a future engine can refuse old artifacts. */
|
|
15
|
+
export const INDEX_ENGINE_ID = 'aragon-index/1';
|
|
16
|
+
/**
|
|
17
|
+
* Kind words. BYTE-IDENTICAL to the web scanner's `SYMBOL_KINDS`
|
|
18
|
+
* (`apps/web/src/lib/project-index/kinds.ts`), enforced by
|
|
19
|
+
* `scripts/check-index-vocabulary.mjs` under `npm run test:tooling` (spec 5.8 / AC-23).
|
|
20
|
+
*
|
|
21
|
+
* THE WEB LIST WINS when the two disagree, and it did: the design claimed the vocabularies
|
|
22
|
+
* were already identical, while the cli draft carried `const` / `module` / `decorator` /
|
|
23
|
+
* `unknown` and the web list carries `constant` / `enum_member` / `constructor` / `field`.
|
|
24
|
+
* The browser side is bound to SQLite `CHECK` constraints and to rows already on disk, so it
|
|
25
|
+
* is the authority; this list and the scanner's emissions were corrected to match (see
|
|
26
|
+
* `## 实施过程发现的方案缺陷` in the design). Order is the UI's display order on both sides.
|
|
27
|
+
*/
|
|
28
|
+
export const SYMBOL_KINDS = [
|
|
29
|
+
'class',
|
|
30
|
+
'interface',
|
|
31
|
+
'type',
|
|
32
|
+
'enum',
|
|
33
|
+
'enum_member',
|
|
34
|
+
'function',
|
|
35
|
+
'method',
|
|
36
|
+
'constructor',
|
|
37
|
+
'property',
|
|
38
|
+
'field',
|
|
39
|
+
'variable',
|
|
40
|
+
'constant',
|
|
41
|
+
'namespace',
|
|
42
|
+
];
|
|
43
|
+
/** Reference kinds. BYTE-IDENTICAL to the web scanner's `REF_KINDS`, same order, same gate. */
|
|
44
|
+
export const REF_KINDS = ['call', 'new', 'type', 'extends', 'implements', 'decorator', 'jsx'];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composition root for the index engine (`createIndexer`), shared by the TUI key
|
|
3
|
+
* handler, the `/index` command family and the host bridge (spec 6.3).
|
|
4
|
+
*
|
|
5
|
+
* WHY A SEPARATE MODULE: the three entry points must agree on config, root, logger
|
|
6
|
+
* and limits. If each built its own engine, the panel could build into one root
|
|
7
|
+
* while `/index status` read another - and nothing would report the mismatch. One
|
|
8
|
+
* factory means one answer per question.
|
|
9
|
+
*
|
|
10
|
+
* The factory is deliberately synchronous and cheap: it only resolves the root and
|
|
11
|
+
* clamps config. Nothing touches the disk until `build()` or `status()` is called,
|
|
12
|
+
* so opening the panel cannot fail because of a filesystem problem.
|
|
13
|
+
*
|
|
14
|
+
* ASCII ONLY: inside the glyph scanner's scope.
|
|
15
|
+
*/
|
|
16
|
+
import { type IndexConfig } from '@aragon-agent/tui/model/index-build/config';
|
|
17
|
+
import { type IndexEngine } from './engine.js';
|
|
18
|
+
/** What a caller can override; everything else comes from config. */
|
|
19
|
+
export interface CreateIndexerOptions {
|
|
20
|
+
/** Working directory (the key handler passes the session cwd, the host passes its own). */
|
|
21
|
+
readonly cwd: string;
|
|
22
|
+
/** Raw persisted config, already shape-checked by the tui layer but re-clamped here. */
|
|
23
|
+
readonly config?: Partial<IndexConfig>;
|
|
24
|
+
/** Structured log sink; the CLI passes `getLogger('cli')`, the TUI its port. */
|
|
25
|
+
readonly log?: (event: string, fields?: Record<string, unknown>) => void;
|
|
26
|
+
/** Clock override for tests. */
|
|
27
|
+
readonly now?: () => number;
|
|
28
|
+
/** Generation override for tests that must write a fixed generation number. */
|
|
29
|
+
readonly generationOverride?: number;
|
|
30
|
+
}
|
|
31
|
+
/** The engine plus the config it resolved, so callers do not re-clamp. */
|
|
32
|
+
export interface Indexer {
|
|
33
|
+
/** The engine port. */
|
|
34
|
+
readonly engine: IndexEngine;
|
|
35
|
+
/** Effective config after clamping. */
|
|
36
|
+
readonly config: IndexConfig;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Build the engine for one workspace.
|
|
40
|
+
*
|
|
41
|
+
* The config is clamped twice by design (spec 8.3): once when it was read from
|
|
42
|
+
* disk, and once here, because a caller can pass a hand-built object and a
|
|
43
|
+
* temperature typo must not reach the parser.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createIndexer(options: CreateIndexerOptions): Indexer;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composition root for the index engine (`createIndexer`), shared by the TUI key
|
|
3
|
+
* handler, the `/index` command family and the host bridge (spec 6.3).
|
|
4
|
+
*
|
|
5
|
+
* WHY A SEPARATE MODULE: the three entry points must agree on config, root, logger
|
|
6
|
+
* and limits. If each built its own engine, the panel could build into one root
|
|
7
|
+
* while `/index status` read another - and nothing would report the mismatch. One
|
|
8
|
+
* factory means one answer per question.
|
|
9
|
+
*
|
|
10
|
+
* The factory is deliberately synchronous and cheap: it only resolves the root and
|
|
11
|
+
* clamps config. Nothing touches the disk until `build()` or `status()` is called,
|
|
12
|
+
* so opening the panel cannot fail because of a filesystem problem.
|
|
13
|
+
*
|
|
14
|
+
* ASCII ONLY: inside the glyph scanner's scope.
|
|
15
|
+
*/
|
|
16
|
+
import { DEFAULT_INDEX_CONFIG, clampIndexConfig } from '@aragon-agent/tui/model/index-build/config';
|
|
17
|
+
import { createIndexEngine } from './engine.js';
|
|
18
|
+
import { clampIndexLimits } from './limits.js';
|
|
19
|
+
/**
|
|
20
|
+
* Build the engine for one workspace.
|
|
21
|
+
*
|
|
22
|
+
* The config is clamped twice by design (spec 8.3): once when it was read from
|
|
23
|
+
* disk, and once here, because a caller can pass a hand-built object and a
|
|
24
|
+
* temperature typo must not reach the parser.
|
|
25
|
+
*/
|
|
26
|
+
export function createIndexer(options) {
|
|
27
|
+
const config = clampIndexConfig(options.config, DEFAULT_INDEX_CONFIG);
|
|
28
|
+
const engine = createIndexEngine({
|
|
29
|
+
cwd: options.cwd,
|
|
30
|
+
enabled: config.enabled,
|
|
31
|
+
exclude: config.exclude,
|
|
32
|
+
limits: clampIndexLimits({
|
|
33
|
+
maxFileBytes: config.maxFileBytes,
|
|
34
|
+
maxFiles: config.maxFiles,
|
|
35
|
+
keepGenerations: config.keepGenerations,
|
|
36
|
+
}),
|
|
37
|
+
log: options.log,
|
|
38
|
+
now: options.now,
|
|
39
|
+
generationOverride: options.generationOverride,
|
|
40
|
+
});
|
|
41
|
+
return { engine, config };
|
|
42
|
+
}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -253,6 +253,20 @@ export interface BuiltinToolsOptions {
|
|
|
253
253
|
* identity (I-20). The tools are appended RAW - never wrapped by `geneHints` below.
|
|
254
254
|
*/
|
|
255
255
|
geneTools?: AgentTool[];
|
|
256
|
+
/**
|
|
257
|
+
* `code_query`, appended verbatim (tui-ctrl-i-ast-index 7.3).
|
|
258
|
+
*
|
|
259
|
+
* THROUGH THE FACTORY FOR THE REASON `geneTools` RECORDS: `tools.test.ts::C7` asserts
|
|
260
|
+
* `HOST_TOOL_NAMES` equals what this factory PRODUCES, so appending in `AgentController`
|
|
261
|
+
* afterwards would turn that test red with a message about two lists of names.
|
|
262
|
+
*
|
|
263
|
+
* READ-ONLY BY CONSTRUCTION, and that is why `code_query` is absent from
|
|
264
|
+
* `PLAN_MODE_BLOCKED_TOOLS` and from `CALLER_GATED_TOOLS`: it runs inside the plan gate,
|
|
265
|
+
* inside a read-only governance seat and in strict mode without any new exemption. SPREAD
|
|
266
|
+
* CONDITIONALLY: with the index off the options bag has no such key and the array is the
|
|
267
|
+
* one built before this feature existed (AC-14's prompt equivalence rests on the same rule).
|
|
268
|
+
*/
|
|
269
|
+
indexTools?: AgentTool[];
|
|
256
270
|
/**
|
|
257
271
|
* The stage-hint engine (gene-bank 9.4). When present, the built-in tools and the skill, process
|
|
258
272
|
* and job tools are decorated so a first-use / failure / retry lookup can append a hint to
|
|
@@ -463,7 +477,7 @@ export declare function gatedToolTimeouts(toolTimeoutMs: number, decisionBudgetM
|
|
|
463
477
|
* is the whole of what this mechanism is worth, and saying so plainly beats
|
|
464
478
|
* implying it covers more.
|
|
465
479
|
*/
|
|
466
|
-
export declare const SKILL_TOOL_FLOOR: readonly ["read_file", "list_dir", "glob", "grep", "skill", "skill_find", "ask_user", "submit_plan", "task", "todo_write", "bash_output", "job_wait", "job_list", "memory_search", "memory_read", "gene_search", "gene_read", "gene_feedback", "team_status", "team_message", "team_pause", "team_resume", "team_stop", "team_spawn", "team_collect"];
|
|
480
|
+
export declare const SKILL_TOOL_FLOOR: readonly ["read_file", "list_dir", "glob", "grep", "skill", "skill_find", "ask_user", "submit_plan", "task", "todo_write", "bash_output", "job_wait", "job_list", "code_query", "memory_search", "memory_read", "gene_search", "gene_read", "gene_feedback", "team_status", "team_message", "team_pause", "team_resume", "team_stop", "team_spawn", "team_collect"];
|
|
467
481
|
/**
|
|
468
482
|
* The five tools plan mode refuses: exactly the complement of `SKILL_TOOL_FLOOR`
|
|
469
483
|
* within `HOST_TOOL_NAMES` — "the five that change something", the set this file
|
|
@@ -496,7 +510,7 @@ export declare const PLAN_MODE_BLOCKED_TOOLS: ReadonlySet<string>;
|
|
|
496
510
|
* declaration MEANS, and that reading must not change with how the CLI was
|
|
497
511
|
* started.
|
|
498
512
|
*/
|
|
499
|
-
export declare const HOST_TOOL_NAMES: readonly ["read_file", "write_file", "edit_file", "list_dir", "glob", "grep", "bash", "skill", "skill_find", "skill_install", "skill_create", "ask_user", "submit_plan", "todo_write", "bash_output", "bash_kill", "job_wait", "job_list", "memory_search", "memory_read", "memory_write", "memory_batch", "gene_search", "gene_read", "gene_feedback", "gene_run", "submit_result", "task", "team_status", "team_message", "team_pause", "team_resume", "team_stop", "team_spawn", "team_collect"];
|
|
513
|
+
export declare const HOST_TOOL_NAMES: readonly ["read_file", "write_file", "edit_file", "list_dir", "glob", "grep", "bash", "skill", "skill_find", "skill_install", "skill_create", "ask_user", "submit_plan", "todo_write", "bash_output", "bash_kill", "job_wait", "job_list", "code_query", "memory_search", "memory_read", "memory_write", "memory_batch", "gene_search", "gene_read", "gene_feedback", "gene_run", "submit_result", "task", "team_status", "team_message", "team_pause", "team_resume", "team_stop", "team_spawn", "team_collect"];
|
|
500
514
|
/**
|
|
501
515
|
* The three memory tools, as one constant (agent-memory 7.1).
|
|
502
516
|
*
|