@chemx/starter-kit 26.9.21-8 → 26.9.23-1269
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/cli/audit/ast-visitors.js +10 -17
- package/cli/audit/autofix.js +17 -2
- package/cli/audit/clone-detector.js +64 -0
- package/cli/audit/clone-detector.spec.js +46 -0
- package/cli/audit/hook-shape-validator.js +312 -0
- package/cli/audit/prompts.js +1 -1
- package/cli/audit/reporter-clones.js +33 -0
- package/cli/audit/reporter-hotspot-graph.js +34 -0
- package/cli/audit/rules-registry.js +6 -1
- package/cli/audit/rules.js +10 -2
- package/cli/audit/rules.spec.js +129 -0
- package/cli/audit-stages.spec.js +30 -0
- package/cli/audit.js +12 -3
- package/cli/commands/cmd-audit.js +43 -3
- package/cli/commands/cmd-project.js +100 -0
- package/cli/commands/cmd-router.js +34 -2
- package/cli/commands-schema.js +14 -0
- package/cli/create.spec.js +2 -2
- package/cli/exploder.js +258 -0
- package/cli/exploder.spec.js +99 -0
- package/cli/generator-compact.spec.js +104 -0
- package/cli/generator-framework.spec.js +72 -0
- package/cli/generator-templates/archetypes/collection-archetypes.js +9 -9
- package/cli/generator-templates/archetypes/index.js +34 -4
- package/cli/generator-templates/archetypes/input-archetypes.js +2 -2
- package/cli/generator-templates/archetypes/layout-archetypes.js +2 -2
- package/cli/generator-templates/archetypes/minimal-archetypes.js +131 -0
- package/cli/generator-templates/archetypes/status-archetypes.js +4 -4
- package/cli/generator-templates/archetypes/vector-matcher.js +50 -0
- package/cli/generator-templates/archetypes/vector-matcher.spec.js +25 -0
- package/cli/generator-templates/compact.js +130 -0
- package/cli/generator-templates/controller-converters.js +93 -0
- package/cli/generator-templates/controller.js +2 -64
- package/cli/generator-templates/react.js +1 -1
- package/cli/generator-templates/svelte.js +1 -1
- package/cli/generator-templates/types.js +2 -2
- package/cli/generator-templates/vue.js +1 -1
- package/cli/generator-templates.js +1 -0
- package/cli/generator-templates.spec.js +6 -1
- package/cli/generator.js +94 -7
- package/cli/help.js +1 -1
- package/cli/index.js +21 -8
- package/cli/installer-templates.js +1 -1
- package/cli/mcp/antigravity.js +3 -2
- package/cli/mcp/installer.js +7 -7
- package/cli/mcp/installer.spec.js +3 -3
- package/cli/mcp/manifests.js +3 -2
- package/cli/mcp/prompts.js +1 -1
- package/cli/mcp/server.js +2 -0
- package/cli/mcp/tools-audit.js +95 -0
- package/cli/mcp/tools-generate.js +62 -0
- package/cli/mcp/tools-patch.js +72 -0
- package/cli/mcp/tools-patterns.js +71 -0
- package/cli/mcp/tools-project.js +75 -0
- package/cli/mcp/tools-project.spec.js +51 -0
- package/cli/mcp/tools-q-modes.js +69 -0
- package/cli/mcp/tools-q.js +58 -0
- package/cli/mcp/tools-read.js +69 -0
- package/cli/mcp/tools-search-util.js +35 -0
- package/cli/mcp/tools-search.js +15 -294
- package/cli/mcp/tools-team-feed.js +57 -0
- package/cli/mcp/tools-team-locks.js +63 -0
- package/cli/mcp/tools-team-mailbox.js +32 -0
- package/cli/mcp/tools-team-tasks.js +84 -0
- package/cli/mcp/tools-team.js +37 -183
- package/cli/mcp/tools-verify.js +47 -0
- package/cli/mcp/tools-write.js +33 -0
- package/cli/mcp/tools.js +72 -376
- package/cli/mutators.js +10 -23
- package/cli/pillars-schema.js +3 -3
- package/cli/project-detector.js +47 -0
- package/cli/reader-shorthand.spec.js +60 -0
- package/cli/reader.js +67 -24
- package/cli/search-bulletproof.spec.js +104 -0
- package/cli/search-db.js +33 -5
- package/cli/search-queries-hotspot-graph.js +65 -0
- package/cli/search-queries-hotspot-graph.spec.js +66 -0
- package/cli/search-queries-similar.js +84 -0
- package/cli/search-queries-similar.spec.js +43 -0
- package/cli/search-schema.js +30 -10
- package/cli/search.js +9 -2
- package/cli/team/index.js +9 -0
- package/cli/team/team-commands.js +104 -64
- package/cli/team/team-concurrency-stress.spec.js +95 -0
- package/cli/team/team-db-mailbox.js +86 -0
- package/cli/team/team-db-task-helpers.js +30 -28
- package/cli/team/team-db-tasks.js +13 -5
- package/cli/team/team-flags.js +69 -0
- package/cli/team/team-format.js +87 -46
- package/cli/team/team-mailbox-empirical.spec.js +191 -0
- package/cli/team/team-mailbox.spec.js +93 -0
- package/cli/team/team-memory.js +84 -0
- package/cli/team/team-memory.spec.js +74 -0
- package/cli/team/team-projects-coordinator.js +100 -0
- package/cli/team/team-projects-format.js +45 -0
- package/cli/team/team-projects-memory.js +70 -0
- package/cli/team/team-projects.js +94 -0
- package/cli/team/team-projects.spec.js +116 -0
- package/cli/team/team-schema-memory.js +25 -0
- package/cli/team/team-schema-projects.js +50 -0
- package/cli/team/team-schema.js +33 -14
- package/cli/team/team-tasks-hierarchy.spec.js +80 -0
- package/cli/team/team-tokens.js +95 -0
- package/cli/team/team-triage.js +159 -12
- package/cli/team/team-verification-gate.spec.js +253 -0
- package/cli/team/team.spec.js +1 -1
- package/cli/trend.js +84 -0
- package/cli/trend.spec.js +51 -0
- package/cli/ui-actions-tasks.js +13 -5
- package/cli/ui-actions.js +10 -2
- package/cli/ui-client-api.js +2 -2
- package/cli/ui-client-script.js +12 -15
- package/cli/ui-e2e-verification.spec.js +13 -3
- package/cli/ui-filetree.spec.js +5 -5
- package/cli/ui-handlers.js +10 -2
- package/cli/ui-html.js +26 -34
- package/cli/ui-index.html +905 -0
- package/cli/ui-kanban.spec.js +12 -12
- package/cli/ui-server.js +7 -0
- package/cli/ui-sse.js +57 -0
- package/cli/ui-sse.spec.js +74 -0
- package/cli/ui-styles.js +195 -81
- package/cli/ui-template-kanban.js +15 -1
- package/cli/ui-vbulletin.spec.js +12 -13
- package/cli/ui.spec.js +12 -5
- package/cli/verify.js +19 -8
- package/package.json +3 -1
- package/scripts/check-framework-generation.mjs +195 -0
- package/scripts/pre-commit.sh +2 -7
- package/scripts/publish-both.mjs +4 -0
package/cli/mcp/tools-search.js
CHANGED
|
@@ -1,294 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import { toColumnar } from '../columnar.js';
|
|
17
|
-
import { handleCheckCommand } from '../search-commands.js';
|
|
18
|
-
|
|
19
|
-
const PROJECT_ROOT = path.resolve(path.dirname(new URL(import.meta.url).pathname), '../..');
|
|
20
|
-
|
|
21
|
-
export const resolveTargetCwd = (cwd) => {
|
|
22
|
-
const hasCwd = Boolean(cwd);
|
|
23
|
-
const isUserHome = cwd === '/home/xopher';
|
|
24
|
-
const hasPackageJson = hasCwd && fs.existsSync(path.resolve(cwd, 'package.json'));
|
|
25
|
-
const isValidProjectCwd = hasCwd && !isUserHome && hasPackageJson;
|
|
26
|
-
if (!isValidProjectCwd) {
|
|
27
|
-
return PROJECT_ROOT;
|
|
28
|
-
}
|
|
29
|
-
return cwd;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const handleChemxQ = (args = {}, cwd = process.cwd()) => {
|
|
33
|
-
const targetCwd = resolveTargetCwd(args.cwd || cwd);
|
|
34
|
-
const query = args.query || args.symbol;
|
|
35
|
-
if (!query) {
|
|
36
|
-
throw new Error('chemx_q requires "query" or "symbol" argument.');
|
|
37
|
-
}
|
|
38
|
-
const db = openIndexDb(targetCwd);
|
|
39
|
-
if (!db) {
|
|
40
|
-
syncSearchIndex('src', targetCwd);
|
|
41
|
-
}
|
|
42
|
-
const activeDb = openIndexDb(targetCwd);
|
|
43
|
-
if (!activeDb) {
|
|
44
|
-
throw new Error('Unable to initialize Chemical X AST search index database.');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const isConnectionLookup = Boolean(args.connections || args.symbol);
|
|
48
|
-
if (args.blastRadius || args.impact) {
|
|
49
|
-
const blast = calculateBlastRadius(activeDb, query, { maxDepth: args.maxDepth || 5 });
|
|
50
|
-
const allConsumers = [...blast.directConsumers, ...blast.transitiveConsumers];
|
|
51
|
-
const colData = toColumnar(allConsumers, ['path', 'tier', 'depth']);
|
|
52
|
-
return {
|
|
53
|
-
target: blast.target,
|
|
54
|
-
seed: blast.seedPath,
|
|
55
|
-
count: blast.totalImpactCount,
|
|
56
|
-
depth: blast.depth,
|
|
57
|
-
tiers: blast.tiers,
|
|
58
|
-
format: 'columnar',
|
|
59
|
-
cols: colData.cols,
|
|
60
|
-
rows: colData.rows,
|
|
61
|
-
tests: blast.impactedTests.map((t) => t.path || t)
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (args.semantic) {
|
|
66
|
-
const results = querySemanticIndex(activeDb, query, { limit: args.limit || 20, tier: args.tier });
|
|
67
|
-
const colData = toColumnar(results, ['filePath', 'targetType', 'targetName', 'tier', 'similarity']);
|
|
68
|
-
return {
|
|
69
|
-
query,
|
|
70
|
-
mode: 'semantic',
|
|
71
|
-
count: results.length,
|
|
72
|
-
format: 'columnar',
|
|
73
|
-
cols: colData.cols,
|
|
74
|
-
rows: colData.rows
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (args.hybrid) {
|
|
79
|
-
const results = queryHybridIndex(activeDb, query, { limit: args.limit || 20 });
|
|
80
|
-
const colData = toColumnar(results, ['filePath', 'name', 'tier', 'score', 'ftsRank', 'vecRank']);
|
|
81
|
-
return {
|
|
82
|
-
query,
|
|
83
|
-
mode: 'hybrid (BM25 + Vector RRF)',
|
|
84
|
-
count: results.length,
|
|
85
|
-
format: 'columnar',
|
|
86
|
-
cols: colData.cols,
|
|
87
|
-
rows: colData.rows
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (isConnectionLookup) {
|
|
92
|
-
const symDef = findSymbolDefinition(activeDb, query);
|
|
93
|
-
const symRefs = findSymbolReferences(activeDb, query);
|
|
94
|
-
if (symDef) {
|
|
95
|
-
const deps = findFileDependencies(activeDb, symDef.filePath);
|
|
96
|
-
const blast = calculateBlastRadius(activeDb, symDef.name);
|
|
97
|
-
return {
|
|
98
|
-
symbol: symDef.name,
|
|
99
|
-
kind: symDef.kind,
|
|
100
|
-
filePath: symDef.filePath,
|
|
101
|
-
lines: `${symDef.startLine}-${symDef.endLine}`,
|
|
102
|
-
signature: symDef.signature,
|
|
103
|
-
dependencies: deps.map((d) => `${d.sourceModule}: ${d.importedSymbol}`),
|
|
104
|
-
consumers: symRefs.map((r) => `${r.importerPath}:${r.line}`),
|
|
105
|
-
blastRadius: {
|
|
106
|
-
totalImpactCount: blast.totalImpactCount,
|
|
107
|
-
impactedTests: blast.impactedTests.map((t) => t.path)
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
const deps = findFileDependencies(activeDb, query);
|
|
112
|
-
const dependents = findFileDependents(activeDb, query);
|
|
113
|
-
const hasFileConnections = deps.length > 0 || dependents.length > 0;
|
|
114
|
-
if (hasFileConnections) {
|
|
115
|
-
const blast = calculateBlastRadius(activeDb, query);
|
|
116
|
-
return {
|
|
117
|
-
file: query,
|
|
118
|
-
dependencies: deps.map((d) => `${d.sourceModule}: ${d.importedSymbol}`),
|
|
119
|
-
dependents: dependents.map((d) => `${d.importerPath}:${d.line}`),
|
|
120
|
-
blastRadius: {
|
|
121
|
-
totalImpactCount: blast.totalImpactCount,
|
|
122
|
-
impactedTests: blast.impactedTests.map((t) => t.path)
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const limit = typeof args.limit === 'number' ? args.limit : 20;
|
|
129
|
-
const results = queryIndex(activeDb, {
|
|
130
|
-
query,
|
|
131
|
-
tier: args.tier || 'all',
|
|
132
|
-
limit
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
if (args.columnar) {
|
|
136
|
-
return toColumnar(results, ['path', 'tier', 'lines', 'symbols', 'props', 'hooks'], {
|
|
137
|
-
symbols: (r) => (r.symbols || []).map((s) => s.name),
|
|
138
|
-
props: (r) => (r.props || []).map((p) => p.name),
|
|
139
|
-
hooks: (r) => r.hooks || []
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (args.inspect) {
|
|
144
|
-
return results.map((r) => ({
|
|
145
|
-
path: r.path,
|
|
146
|
-
tier: r.tier,
|
|
147
|
-
lines: r.lines,
|
|
148
|
-
symbols: (r.symbols || []).map((s) => s.name),
|
|
149
|
-
props: (r.props || []).map((p) => p.name),
|
|
150
|
-
hooks: r.hooks || []
|
|
151
|
-
}));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const lines = results.map((r) => {
|
|
155
|
-
const mainSym = (r.symbols || []).find((s) => s.isExport)?.name || '';
|
|
156
|
-
const symPart = mainSym ? ` (${mainSym})` : '';
|
|
157
|
-
const hasHooks = Boolean(r.hooks && r.hooks.length > 0);
|
|
158
|
-
const hookPart = hasHooks ? ` [${r.hooks.slice(0, 2).join(',')}]` : '';
|
|
159
|
-
return `[${r.tier.toUpperCase()}] ${r.path}:${r.lines}L${symPart}${hookPart}`;
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
const hasLines = lines.length > 0;
|
|
163
|
-
return hasLines ? lines.join('\n') : `No matching capsules or symbols for "${query}"`;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export const handleChemxRead = (args = {}, cwd = process.cwd()) => {
|
|
167
|
-
if (!args.path) {
|
|
168
|
-
throw new Error('chemx_read requires "path" argument.');
|
|
169
|
-
}
|
|
170
|
-
const targetCwd = resolveTargetCwd(args.cwd || cwd);
|
|
171
|
-
const targetPath = path.isAbsolute(args.path) ? args.path : path.resolve(targetCwd, args.path);
|
|
172
|
-
const res = readTokenOptimized(targetPath, {
|
|
173
|
-
outline: args.outline,
|
|
174
|
-
symbol: args.symbol,
|
|
175
|
-
stripComments: args.stripComments !== false,
|
|
176
|
-
compact: args.compact !== false,
|
|
177
|
-
startLine: args.startLine,
|
|
178
|
-
endLine: args.endLine
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
let connectionCard = '';
|
|
182
|
-
if (args.connections) {
|
|
183
|
-
const db = openIndexDb(targetCwd);
|
|
184
|
-
if (db) {
|
|
185
|
-
const blast = calculateBlastRadius(db, args.symbol || targetPath);
|
|
186
|
-
if (args.symbol) {
|
|
187
|
-
const refs = findSymbolReferences(db, args.symbol);
|
|
188
|
-
connectionCard = `\n// Connections for ${args.symbol}: referenced by ${refs.length} file(s) [${refs.slice(0, 3).map((r) => path.basename(r.importerPath)).join(', ')}]. Blast Radius: ${blast.totalImpactCount} affected file(s) across ${blast.depth} hops (${blast.impactedTests.length} tests).`;
|
|
189
|
-
} else {
|
|
190
|
-
const deps = findFileDependencies(db, targetPath);
|
|
191
|
-
const dependents = findFileDependents(db, targetPath);
|
|
192
|
-
connectionCard = `\n// File Connections: imports ${deps.length} symbol(s), imported by ${dependents.length} file(s). Blast Radius: ${blast.totalImpactCount} affected file(s) across ${blast.depth} hops (${blast.impactedTests.length} tests).`;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const header = `// ${res.file} (${res.lineCount || res.totalLines} lines, ~${res.tokensEst} tokens)${connectionCard}\n`;
|
|
198
|
-
return header + res.content;
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const isSevereViolation = (v) => {
|
|
202
|
-
const isCritical = v.severity === 'CRITICAL';
|
|
203
|
-
const isHigh = v.severity === 'HIGH';
|
|
204
|
-
return isCritical || isHigh;
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const formatPatchWarnings = (result) => {
|
|
208
|
-
const warnings = [];
|
|
209
|
-
|
|
210
|
-
// Stage 1: Atomic Concept Declarations
|
|
211
|
-
const hasLineBudget = Boolean(result.lineBudget);
|
|
212
|
-
const isBudgetExceeded = hasLineBudget && !result.lineBudget.passed;
|
|
213
|
-
|
|
214
|
-
// Stage 2: Clean Conditionals
|
|
215
|
-
if (isBudgetExceeded) {
|
|
216
|
-
warnings.push(`[Directive 1.A] ${result.lineBudget.warning}`);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const violations = result.violations || [];
|
|
220
|
-
for (const v of violations) {
|
|
221
|
-
const isSevere = isSevereViolation(v);
|
|
222
|
-
if (isSevere) {
|
|
223
|
-
warnings.push(`[${v.severity} - ${v.rule}] Line ${v.line}: ${v.hazard} -> ${v.directive || ''}`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const hasWarnings = warnings.length > 0;
|
|
228
|
-
return hasWarnings ? warnings : undefined;
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
export const handleChemxPatch = (args = {}, cwd = process.cwd()) => {
|
|
232
|
-
// Stage 1: Atomic Concept Declarations
|
|
233
|
-
const hasPath = Boolean(args.path);
|
|
234
|
-
const hasTargetContent = args.targetContent !== undefined;
|
|
235
|
-
const hasReplacementContent = args.replacementContent !== undefined;
|
|
236
|
-
|
|
237
|
-
// Stage 2: Unified Decision Variable
|
|
238
|
-
const hasRequiredArgs = hasPath && hasTargetContent && hasReplacementContent;
|
|
239
|
-
|
|
240
|
-
// Stage 3: Early-Return Guard Clause
|
|
241
|
-
if (!hasRequiredArgs) {
|
|
242
|
-
throw new Error('chemx_patch requires "path", "targetContent", and "replacementContent" arguments.');
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const targetPath = path.isAbsolute(args.path) ? args.path : path.resolve(cwd, args.path);
|
|
246
|
-
const result = patchFile(targetPath, {
|
|
247
|
-
targetContent: args.targetContent,
|
|
248
|
-
replacementContent: args.replacementContent,
|
|
249
|
-
allowMultiple: Boolean(args.allowMultiple),
|
|
250
|
-
cwd
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
return {
|
|
254
|
-
...result,
|
|
255
|
-
warnings: formatPatchWarnings(result)
|
|
256
|
-
};
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
export const handleChemxCheck = (args = {}, cwd = process.cwd()) => {
|
|
260
|
-
if (args.path === 'RESTART_MCP') {
|
|
261
|
-
setTimeout(() => process.exit(0), 50);
|
|
262
|
-
return { restarting: true };
|
|
263
|
-
}
|
|
264
|
-
if (!args.path) {
|
|
265
|
-
throw new Error('chemx_check requires "path" argument.');
|
|
266
|
-
}
|
|
267
|
-
const targetPath = path.isAbsolute(args.path) ? args.path : path.resolve(cwd, args.path);
|
|
268
|
-
return handleCheckCommand(targetPath, { isJson: true, isCli: false });
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
export const handleChemxWrite = (args = {}, cwd = process.cwd()) => {
|
|
272
|
-
// Stage 1: Atomic Concept Declarations
|
|
273
|
-
const hasPath = Boolean(args.path);
|
|
274
|
-
const hasContent = args.content !== undefined;
|
|
275
|
-
|
|
276
|
-
// Stage 2: Unified Decision Variable
|
|
277
|
-
const hasRequiredArgs = hasPath && hasContent;
|
|
278
|
-
|
|
279
|
-
// Stage 3: Early-Return Guard Clause
|
|
280
|
-
if (!hasRequiredArgs) {
|
|
281
|
-
throw new Error('chemx_write requires "path" and "content" arguments.');
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const targetPath = path.isAbsolute(args.path) ? args.path : path.resolve(cwd, args.path);
|
|
285
|
-
const result = writeFile(targetPath, {
|
|
286
|
-
content: args.content,
|
|
287
|
-
cwd
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
return {
|
|
291
|
-
...result,
|
|
292
|
-
warnings: formatPatchWarnings(result)
|
|
293
|
-
};
|
|
294
|
-
};
|
|
1
|
+
export {
|
|
2
|
+
PROJECT_ROOT,
|
|
3
|
+
EXT_LANG_MAP,
|
|
4
|
+
resolveTargetCwd
|
|
5
|
+
} from './tools-search-util.js';
|
|
6
|
+
|
|
7
|
+
export { handleChemxQ } from './tools-q.js';
|
|
8
|
+
export { handleChemxRead } from './tools-read.js';
|
|
9
|
+
export {
|
|
10
|
+
isSevereViolation,
|
|
11
|
+
formatPatchWarnings,
|
|
12
|
+
handleChemxPatch,
|
|
13
|
+
handleChemxCheck
|
|
14
|
+
} from './tools-patch.js';
|
|
15
|
+
export { handleChemxWrite } from './tools-write.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { openIndexDb } from '../search-db.js';
|
|
2
|
+
import { toColumnar } from '../columnar.js';
|
|
3
|
+
import {
|
|
4
|
+
getSwarmStatus,
|
|
5
|
+
queryFeed,
|
|
6
|
+
postFeedEvent,
|
|
7
|
+
registerAgent
|
|
8
|
+
} from '../team/team-db.js';
|
|
9
|
+
import { formatSwarmStatusCard } from '../team/team-format.js';
|
|
10
|
+
|
|
11
|
+
export const handleChemxTeamStatus = async (args = {}, cwd = process.cwd()) => {
|
|
12
|
+
const db = openIndexDb(cwd);
|
|
13
|
+
if (!db) return { error: 'sqlite_unavailable' };
|
|
14
|
+
const status = getSwarmStatus(db);
|
|
15
|
+
return {
|
|
16
|
+
agents: status.agents,
|
|
17
|
+
tasks: status.tasks,
|
|
18
|
+
locks: {
|
|
19
|
+
active: status.locks.active,
|
|
20
|
+
waiting: status.locks.waiting,
|
|
21
|
+
leases: toColumnar(status.locks.leases, ['file_path', 'locked_by', 'expires_at'])
|
|
22
|
+
},
|
|
23
|
+
tokens: status.tokens,
|
|
24
|
+
blockedTasks: toColumnar(status.blockedTasks, ['id', 'title', 'assigned_agent_id', 'blocked_reason']),
|
|
25
|
+
recentFeed: toColumnar(status.recentFeed, ['id', 'timestamp', 'author_id', 'event_type', 'message']),
|
|
26
|
+
card: formatSwarmStatusCard(status)
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const handleChemxTeamFeed = async (args = {}, cwd = process.cwd()) => {
|
|
31
|
+
const db = openIndexDb(cwd);
|
|
32
|
+
if (!db) return { error: 'sqlite_unavailable' };
|
|
33
|
+
const events = queryFeed(db, {
|
|
34
|
+
since_id: args.sinceId,
|
|
35
|
+
thread_id: args.threadId,
|
|
36
|
+
task_id: args.taskId,
|
|
37
|
+
agent_id: args.agentId,
|
|
38
|
+
limit: args.limit
|
|
39
|
+
});
|
|
40
|
+
return toColumnar(events, ['id', 'timestamp', 'author_id', 'recipient_id', 'event_type', 'file_path', 'message']);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const handleChemxTeamPost = async (args = {}, cwd = process.cwd()) => {
|
|
44
|
+
const db = openIndexDb(cwd);
|
|
45
|
+
if (!db) return { error: 'sqlite_unavailable' };
|
|
46
|
+
const authorHandle = args.authorId || '@agent';
|
|
47
|
+
registerAgent(db, { id: authorHandle, role: 'contributor' });
|
|
48
|
+
return postFeedEvent(db, {
|
|
49
|
+
message: args.message,
|
|
50
|
+
author_id: authorHandle,
|
|
51
|
+
recipient_id: args.recipientId,
|
|
52
|
+
thread_id: args.threadId,
|
|
53
|
+
task_id: args.taskId,
|
|
54
|
+
file_path: args.filePath,
|
|
55
|
+
event_type: args.eventType
|
|
56
|
+
});
|
|
57
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { openIndexDb } from '../search-db.js';
|
|
2
|
+
import { toColumnar } from '../columnar.js';
|
|
3
|
+
import {
|
|
4
|
+
requestFileLock,
|
|
5
|
+
releaseFileLock,
|
|
6
|
+
getFileLockStatus
|
|
7
|
+
} from '../team/team-db.js';
|
|
8
|
+
import { handleError } from '../errors/index.js';
|
|
9
|
+
|
|
10
|
+
export const handleChemxTeamLock = async (args = {}, cwd = process.cwd()) => {
|
|
11
|
+
const db = openIndexDb(cwd);
|
|
12
|
+
if (!db) return { error: 'sqlite_unavailable' };
|
|
13
|
+
const action = args.action || 'status';
|
|
14
|
+
|
|
15
|
+
if (action === 'acquire') {
|
|
16
|
+
return requestFileLock(db, args.filePath, args.agentId, {
|
|
17
|
+
purpose: args.purpose,
|
|
18
|
+
ttlMs: args.ttlMs
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (action === 'release') {
|
|
22
|
+
return releaseFileLock(db, args.filePath, args.agentId);
|
|
23
|
+
}
|
|
24
|
+
if (action === 'status') {
|
|
25
|
+
const status = getFileLockStatus(db, args.filePath);
|
|
26
|
+
return {
|
|
27
|
+
lease: status.lease,
|
|
28
|
+
waiters: toColumnar(status.waiters, ['id', 'agent_id', 'priority', 'status', 'requested_at'])
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return { error: `Unknown lock action: ${action}` };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const handleChemxReportIssue = async (args = {}, cwd = process.cwd()) => {
|
|
35
|
+
const errorObj = new Error(args.error || 'Unknown error');
|
|
36
|
+
if (args.stack) errorObj.stack = args.stack;
|
|
37
|
+
|
|
38
|
+
const result = await handleError(errorObj, {
|
|
39
|
+
cwd,
|
|
40
|
+
command: args.command,
|
|
41
|
+
repo: args.repo,
|
|
42
|
+
autoPost: Boolean(args.autoPost),
|
|
43
|
+
labels: args.labels,
|
|
44
|
+
silent: true,
|
|
45
|
+
context: args.context,
|
|
46
|
+
skipFileWrite: true
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
success: true,
|
|
51
|
+
issue: {
|
|
52
|
+
title: result.issue.title,
|
|
53
|
+
body: result.issue.body,
|
|
54
|
+
webUrl: result.issue.webUrl,
|
|
55
|
+
targetRepo: result.issue.targetRepo,
|
|
56
|
+
labels: result.issue.labels
|
|
57
|
+
},
|
|
58
|
+
published: result.publishResult.success,
|
|
59
|
+
publishedUrl: result.publishResult.url,
|
|
60
|
+
issueNumber: result.publishResult.issueNumber,
|
|
61
|
+
savedPath: result.savedPath || null
|
|
62
|
+
};
|
|
63
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { openIndexDb } from '../search-db.js';
|
|
2
|
+
import { getAgentMailbox, sendDirectMessage } from '../team/team-db-mailbox.js';
|
|
3
|
+
|
|
4
|
+
export const handleChemxTeamInbox = async (args = {}, cwd = process.cwd()) => {
|
|
5
|
+
const db = openIndexDb(cwd);
|
|
6
|
+
if (!db) return { error: 'sqlite_unavailable' };
|
|
7
|
+
const agentId = args.agentId || args.agent || args.as || '@agent';
|
|
8
|
+
return getAgentMailbox(db, agentId, {
|
|
9
|
+
since: args.since || args.sinceId,
|
|
10
|
+
limit: args.limit,
|
|
11
|
+
markRead: Boolean(args.markRead)
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const handleChemxTeamDm = async (args = {}, cwd = process.cwd()) => {
|
|
16
|
+
const db = openIndexDb(cwd);
|
|
17
|
+
if (!db) return { error: 'sqlite_unavailable' };
|
|
18
|
+
const authorId = args.authorId || args.as || '@agent';
|
|
19
|
+
const recipientId = args.recipientId || args.to || args.recipient;
|
|
20
|
+
const hasRecipient = Boolean(recipientId);
|
|
21
|
+
const hasMessage = Boolean(args.message);
|
|
22
|
+
const canSend = hasRecipient && hasMessage;
|
|
23
|
+
if (!canSend) return { error: 'recipientId and message required' };
|
|
24
|
+
return sendDirectMessage(db, {
|
|
25
|
+
author_id: authorId,
|
|
26
|
+
recipient_id: recipientId,
|
|
27
|
+
message: args.message,
|
|
28
|
+
task_id: args.taskId || args.task,
|
|
29
|
+
thread_id: args.threadId || args.thread,
|
|
30
|
+
metadata: args.metadata || {}
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { openIndexDb } from '../search-db.js';
|
|
2
|
+
import { toColumnar } from '../columnar.js';
|
|
3
|
+
import {
|
|
4
|
+
listTasks,
|
|
5
|
+
createTask,
|
|
6
|
+
claimTask,
|
|
7
|
+
updateTaskStatus,
|
|
8
|
+
registerAgent,
|
|
9
|
+
postFeedEvent
|
|
10
|
+
} from '../team/team-db.js';
|
|
11
|
+
import { completeTaskWithAudit, autoGenerateTasksFromAudit } from '../team/team-triage.js';
|
|
12
|
+
import { formatTaskListCard } from '../team/team-format.js';
|
|
13
|
+
|
|
14
|
+
export const handleChemxTeamTask = async (args = {}, cwd = process.cwd()) => {
|
|
15
|
+
const db = openIndexDb(cwd);
|
|
16
|
+
if (!db) return { error: 'sqlite_unavailable' };
|
|
17
|
+
const action = args.action || 'list';
|
|
18
|
+
|
|
19
|
+
if (action === 'list') {
|
|
20
|
+
const parentId = args.parentId !== undefined ? args.parentId : args.parent;
|
|
21
|
+
const tasks = listTasks(db, { status: args.status, assigned_agent_id: args.agentId, parentId });
|
|
22
|
+
const col = toColumnar(tasks, ['id', 'title', 'tier', 'status', 'priority', 'assigned_agent_id', 'target_path', 'parent_id']);
|
|
23
|
+
return { ...col, total: tasks.length, card: formatTaskListCard(tasks) };
|
|
24
|
+
}
|
|
25
|
+
if (action === 'create' || action === 'add') {
|
|
26
|
+
const authorHandle = args.agentId || '@agent';
|
|
27
|
+
registerAgent(db, { id: authorHandle, role: 'contributor' });
|
|
28
|
+
if (args.assignedAgentId) {
|
|
29
|
+
registerAgent(db, { id: args.assignedAgentId, role: 'executor' });
|
|
30
|
+
}
|
|
31
|
+
const parentId = args.parentId !== undefined ? args.parentId : args.parent;
|
|
32
|
+
const task = createTask(db, {
|
|
33
|
+
title: args.title,
|
|
34
|
+
target_path: args.targetPath,
|
|
35
|
+
tier: args.tier || 'molecule',
|
|
36
|
+
priority: args.priority || 2,
|
|
37
|
+
assigned_agent_id: args.assignedAgentId || null,
|
|
38
|
+
parent_id: parentId ?? null
|
|
39
|
+
});
|
|
40
|
+
if (task) {
|
|
41
|
+
postFeedEvent(db, {
|
|
42
|
+
author_id: authorHandle,
|
|
43
|
+
task_id: task.id,
|
|
44
|
+
event_type: 'task_created',
|
|
45
|
+
message: `Created task #${task.id}: ${task.title}`
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return task;
|
|
49
|
+
}
|
|
50
|
+
if (action === 'claim') {
|
|
51
|
+
const agentHandle = args.agentId || '@agent';
|
|
52
|
+
registerAgent(db, { id: agentHandle, role: 'executor' });
|
|
53
|
+
return claimTask(db, args.taskId, agentHandle);
|
|
54
|
+
}
|
|
55
|
+
if (action === 'done' || action === 'complete') {
|
|
56
|
+
const agentHandle = args.agentId || '@agent';
|
|
57
|
+
registerAgent(db, { id: agentHandle, role: 'executor' });
|
|
58
|
+
return completeTaskWithAudit(db, args.taskId, agentHandle, { cwd, force: args.force, noTargetConfirm: args.noTargetConfirm, tokens: args.tokens });
|
|
59
|
+
}
|
|
60
|
+
if (action === 'block') {
|
|
61
|
+
return updateTaskStatus(db, args.taskId, 'blocked', { blockedReason: args.blockedReason || 'Blocked' });
|
|
62
|
+
}
|
|
63
|
+
if (action === 'update') {
|
|
64
|
+
const targetStatus = args.status || 'in_progress';
|
|
65
|
+
const agentHandle = args.agentId || '@agent';
|
|
66
|
+
registerAgent(db, { id: agentHandle, role: 'executor' });
|
|
67
|
+
if (targetStatus === 'done' || targetStatus === 'completed') {
|
|
68
|
+
return completeTaskWithAudit(db, args.taskId, agentHandle, { cwd, force: args.force, noTargetConfirm: args.noTargetConfirm, tokens: args.tokens });
|
|
69
|
+
}
|
|
70
|
+
return updateTaskStatus(db, args.taskId, targetStatus, { blockedReason: args.blockedReason || '' });
|
|
71
|
+
}
|
|
72
|
+
if (action === 'set-target' || action === 'target') {
|
|
73
|
+
const hasTaskId = Boolean(args.taskId);
|
|
74
|
+
const hasTargetPath = Boolean(args.targetPath);
|
|
75
|
+
const canSet = hasTaskId && hasTargetPath;
|
|
76
|
+
if (!canSet) return { error: 'taskId and targetPath required' };
|
|
77
|
+
db.prepare('UPDATE agent_tasks SET target_path = ?, updated_at = ? WHERE id = ?').run(args.targetPath, Date.now(), Number(args.taskId));
|
|
78
|
+
return db.prepare('SELECT * FROM agent_tasks WHERE id = ?').get(Number(args.taskId));
|
|
79
|
+
}
|
|
80
|
+
if (action === 'triage') {
|
|
81
|
+
return autoGenerateTasksFromAudit(db, { cwd, maxTasks: args.maxTasks || 10 });
|
|
82
|
+
}
|
|
83
|
+
return { error: `Unknown task action: ${action}` };
|
|
84
|
+
};
|