@milo4jo/contextkit 0.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/README.md +181 -0
- package/dist/commands/index-cmd.d.ts +3 -0
- package/dist/commands/index-cmd.d.ts.map +1 -0
- package/dist/commands/index-cmd.js +111 -0
- package/dist/commands/index-cmd.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +56 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/select.d.ts +3 -0
- package/dist/commands/select.d.ts.map +1 -0
- package/dist/commands/select.js +64 -0
- package/dist/commands/select.js.map +1 -0
- package/dist/commands/source/add.d.ts +3 -0
- package/dist/commands/source/add.d.ts.map +1 -0
- package/dist/commands/source/add.js +87 -0
- package/dist/commands/source/add.js.map +1 -0
- package/dist/commands/source/index.d.ts +3 -0
- package/dist/commands/source/index.d.ts.map +1 -0
- package/dist/commands/source/index.js +14 -0
- package/dist/commands/source/index.js.map +1 -0
- package/dist/commands/source/list.d.ts +3 -0
- package/dist/commands/source/list.d.ts.map +1 -0
- package/dist/commands/source/list.js +46 -0
- package/dist/commands/source/list.js.map +1 -0
- package/dist/commands/source/remove.d.ts +3 -0
- package/dist/commands/source/remove.d.ts.map +1 -0
- package/dist/commands/source/remove.js +38 -0
- package/dist/commands/source/remove.js.map +1 -0
- package/dist/commands/source.d.ts +3 -0
- package/dist/commands/source.d.ts.map +1 -0
- package/dist/commands/source.js +153 -0
- package/dist/commands/source.js.map +1 -0
- package/dist/config/index.d.ts +38 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +100 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +21 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +5 -0
- package/dist/config/types.js.map +1 -0
- package/dist/db/index.d.ts +14 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +63 -0
- package/dist/db/index.js.map +1 -0
- package/dist/errors/index.d.ts +30 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +51 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/chunker.d.ts +44 -0
- package/dist/indexer/chunker.d.ts.map +1 -0
- package/dist/indexer/chunker.js +102 -0
- package/dist/indexer/chunker.js.map +1 -0
- package/dist/indexer/discovery.d.ts +34 -0
- package/dist/indexer/discovery.d.ts.map +1 -0
- package/dist/indexer/discovery.js +66 -0
- package/dist/indexer/discovery.js.map +1 -0
- package/dist/indexer/embeddings.d.ts +32 -0
- package/dist/indexer/embeddings.d.ts.map +1 -0
- package/dist/indexer/embeddings.js +85 -0
- package/dist/indexer/embeddings.js.map +1 -0
- package/dist/indexer/index.d.ts +37 -0
- package/dist/indexer/index.d.ts.map +1 -0
- package/dist/indexer/index.js +123 -0
- package/dist/indexer/index.js.map +1 -0
- package/dist/selector/budget.d.ts +26 -0
- package/dist/selector/budget.d.ts.map +1 -0
- package/dist/selector/budget.js +75 -0
- package/dist/selector/budget.js.map +1 -0
- package/dist/selector/formatter.d.ts +44 -0
- package/dist/selector/formatter.d.ts.map +1 -0
- package/dist/selector/formatter.js +114 -0
- package/dist/selector/formatter.js.map +1 -0
- package/dist/selector/index.d.ts +37 -0
- package/dist/selector/index.d.ts.map +1 -0
- package/dist/selector/index.js +67 -0
- package/dist/selector/index.js.map +1 -0
- package/dist/selector/scoring.d.ts +26 -0
- package/dist/selector/scoring.d.ts.map +1 -0
- package/dist/selector/scoring.js +113 -0
- package/dist/selector/scoring.js.map +1 -0
- package/dist/selector/search.d.ts +29 -0
- package/dist/selector/search.d.ts.map +1 -0
- package/dist/selector/search.js +48 -0
- package/dist/selector/search.js.map +1 -0
- package/dist/utils/cli.d.ts +20 -0
- package/dist/utils/cli.d.ts.map +1 -0
- package/dist/utils/cli.js +19 -0
- package/dist/utils/cli.js.map +1 -0
- package/dist/utils/format.d.ts +30 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +44 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/output.d.ts +42 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/output.js +62 -0
- package/dist/utils/output.js.map +1 -0
- package/dist/utils/prompts.d.ts +23 -0
- package/dist/utils/prompts.d.ts.map +1 -0
- package/dist/utils/prompts.js +46 -0
- package/dist/utils/prompts.js.map +1 -0
- package/dist/utils/streams.d.ts +40 -0
- package/dist/utils/streams.d.ts.map +1 -0
- package/dist/utils/streams.js +61 -0
- package/dist/utils/streams.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove.d.ts","sourceRoot":"","sources":["../../../src/commands/source/remove.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,eAAO,MAAM,aAAa,SAqCtB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { loadConfig, saveConfig, ensureInitialized } from '../../config/index.js';
|
|
3
|
+
import { writeSuccess, writeMessage } from '../../utils/streams.js';
|
|
4
|
+
import { formatCommand, formatHighlight } from '../../utils/format.js';
|
|
5
|
+
import { confirm, shouldSkipConfirm } from '../../utils/prompts.js';
|
|
6
|
+
import { SourceNotFoundError } from '../../errors/index.js';
|
|
7
|
+
export const removeCommand = new Command('remove')
|
|
8
|
+
.alias('rm')
|
|
9
|
+
.description('Remove a source')
|
|
10
|
+
.argument('<name>', 'Name of the source to remove')
|
|
11
|
+
.option('-y, --yes', 'Skip confirmation prompt')
|
|
12
|
+
.action(async (name, options) => {
|
|
13
|
+
ensureInitialized();
|
|
14
|
+
const config = loadConfig();
|
|
15
|
+
const index = config.sources.findIndex((s) => s.id === name);
|
|
16
|
+
if (index === -1) {
|
|
17
|
+
throw new SourceNotFoundError(name);
|
|
18
|
+
}
|
|
19
|
+
const source = config.sources[index];
|
|
20
|
+
// Confirm unless --yes is passed
|
|
21
|
+
if (!shouldSkipConfirm(options)) {
|
|
22
|
+
writeMessage('');
|
|
23
|
+
writeMessage(`This will remove '${formatHighlight(name)}' from indexing.`);
|
|
24
|
+
writeMessage(`Path: ${source.path}`);
|
|
25
|
+
writeMessage('');
|
|
26
|
+
const confirmed = await confirm('Are you sure?', true);
|
|
27
|
+
if (!confirmed) {
|
|
28
|
+
writeMessage('Cancelled.');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Remove source
|
|
33
|
+
config.sources.splice(index, 1);
|
|
34
|
+
saveConfig(config);
|
|
35
|
+
writeSuccess(`Removed source '${formatHighlight(name)}'`);
|
|
36
|
+
writeMessage(`Run ${formatCommand('contextkit index')} to update the index.`);
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=remove.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove.js","sourceRoot":"","sources":["../../../src/commands/source/remove.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC;KAC/C,KAAK,CAAC,IAAI,CAAC;KACX,WAAW,CAAC,iBAAiB,CAAC;KAC9B,QAAQ,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CAAC;AAChF,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/commands/source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,eAAO,MAAM,aAAa,SAKtB,CAAC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { existsSync, statSync } from 'fs';
|
|
3
|
+
import { resolve, relative, basename } from 'path';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import fg from 'fast-glob';
|
|
6
|
+
import { loadConfig, saveConfig, ensureInitialized } from '../config/index.js';
|
|
7
|
+
import { output } from '../utils/output.js';
|
|
8
|
+
export const sourceCommand = new Command('source')
|
|
9
|
+
.description('Manage sources')
|
|
10
|
+
.action(() => {
|
|
11
|
+
// Show subcommand help when no subcommand given
|
|
12
|
+
sourceCommand.help();
|
|
13
|
+
});
|
|
14
|
+
// source add
|
|
15
|
+
sourceCommand
|
|
16
|
+
.command('add <path>')
|
|
17
|
+
.description('Add a directory as a source')
|
|
18
|
+
.option('-n, --name <name>', 'Custom name for the source')
|
|
19
|
+
.option('-i, --include <patterns...>', 'Include patterns (glob)')
|
|
20
|
+
.option('-e, --exclude <patterns...>', 'Exclude patterns (glob)')
|
|
21
|
+
.action(async (path, options) => {
|
|
22
|
+
ensureInitialized();
|
|
23
|
+
const absolutePath = resolve(process.cwd(), path);
|
|
24
|
+
const relativePath = './' + relative(process.cwd(), absolutePath);
|
|
25
|
+
// Validate path exists
|
|
26
|
+
if (!existsSync(absolutePath)) {
|
|
27
|
+
output.error('Path not found');
|
|
28
|
+
// Try to suggest similar paths
|
|
29
|
+
const parent = resolve(absolutePath, '..');
|
|
30
|
+
if (existsSync(parent)) {
|
|
31
|
+
const entries = fg.sync(['*'], { cwd: parent, onlyDirectories: true });
|
|
32
|
+
const similar = entries.filter((e) => e.toLowerCase().includes(basename(path).toLowerCase()));
|
|
33
|
+
if (similar.length > 0) {
|
|
34
|
+
console.error(`Did you mean '${similar[0]}'?`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
// Validate it's a directory
|
|
40
|
+
if (!statSync(absolutePath).isDirectory()) {
|
|
41
|
+
output.error('Not a directory');
|
|
42
|
+
console.error(`'${path}' is a file, not a directory.`);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
// Load config
|
|
46
|
+
const config = loadConfig();
|
|
47
|
+
// Generate source ID
|
|
48
|
+
const sourceId = options.name || basename(absolutePath);
|
|
49
|
+
// Check for duplicates
|
|
50
|
+
const existing = config.sources.find((s) => s.id === sourceId);
|
|
51
|
+
if (existing) {
|
|
52
|
+
output.error('Source already exists');
|
|
53
|
+
console.error(`A source named '${sourceId}' already exists.`);
|
|
54
|
+
console.error(`Use a different name with ${chalk.cyan('--name')}`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
// Count files
|
|
58
|
+
const defaultInclude = ['**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx', '**/*.md', '**/*.json'];
|
|
59
|
+
const defaultExclude = ['**/node_modules/**', '**/dist/**', '**/.git/**'];
|
|
60
|
+
const include = options.include || defaultInclude;
|
|
61
|
+
const exclude = options.exclude || defaultExclude;
|
|
62
|
+
const files = fg.sync(include, {
|
|
63
|
+
cwd: absolutePath,
|
|
64
|
+
ignore: exclude,
|
|
65
|
+
onlyFiles: true,
|
|
66
|
+
});
|
|
67
|
+
// Create source entry
|
|
68
|
+
const source = {
|
|
69
|
+
id: sourceId,
|
|
70
|
+
path: relativePath,
|
|
71
|
+
patterns: {
|
|
72
|
+
include,
|
|
73
|
+
exclude,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
// Add to config
|
|
77
|
+
config.sources.push(source);
|
|
78
|
+
saveConfig(config);
|
|
79
|
+
// Output
|
|
80
|
+
output.success(`Added source '${chalk.cyan(sourceId)}'`);
|
|
81
|
+
console.log(` Path: ${relativePath}`);
|
|
82
|
+
console.log(` Files: ${files.length} (${getFileExtensions(files)})`);
|
|
83
|
+
console.log();
|
|
84
|
+
console.log(`Run ${chalk.cyan('contextkit index')} to index this source.`);
|
|
85
|
+
});
|
|
86
|
+
// source list
|
|
87
|
+
sourceCommand
|
|
88
|
+
.command('list')
|
|
89
|
+
.description('List configured sources')
|
|
90
|
+
.action(() => {
|
|
91
|
+
ensureInitialized();
|
|
92
|
+
const config = loadConfig();
|
|
93
|
+
const opts = sourceCommand.parent?.opts() || {};
|
|
94
|
+
if (config.sources.length === 0) {
|
|
95
|
+
if (opts.json) {
|
|
96
|
+
console.log(JSON.stringify({ sources: [] }));
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
console.log('No sources configured.');
|
|
100
|
+
console.log(`Add one with ${chalk.cyan('contextkit source add <path>')}`);
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (opts.json) {
|
|
105
|
+
console.log(JSON.stringify({ sources: config.sources }, null, 2));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (opts.plain) {
|
|
109
|
+
for (const source of config.sources) {
|
|
110
|
+
console.log(`${source.id}\t${source.path}`);
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// Table output
|
|
115
|
+
console.log();
|
|
116
|
+
console.log(chalk.bold('Sources:'));
|
|
117
|
+
console.log(` ${chalk.gray('NAME'.padEnd(15))} ${chalk.gray('PATH')}`);
|
|
118
|
+
for (const source of config.sources) {
|
|
119
|
+
console.log(` ${source.id.padEnd(15)} ${source.path}`);
|
|
120
|
+
}
|
|
121
|
+
console.log();
|
|
122
|
+
console.log(`Total: ${config.sources.length} source${config.sources.length === 1 ? '' : 's'}`);
|
|
123
|
+
});
|
|
124
|
+
// source remove
|
|
125
|
+
sourceCommand
|
|
126
|
+
.command('remove <name>')
|
|
127
|
+
.alias('rm')
|
|
128
|
+
.description('Remove a source')
|
|
129
|
+
.action((name) => {
|
|
130
|
+
ensureInitialized();
|
|
131
|
+
const config = loadConfig();
|
|
132
|
+
const index = config.sources.findIndex((s) => s.id === name);
|
|
133
|
+
if (index === -1) {
|
|
134
|
+
output.error('Source not found');
|
|
135
|
+
console.error(`No source named '${name}'.`);
|
|
136
|
+
console.error(`Run ${chalk.cyan('contextkit source list')} to see available sources.`);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
config.sources.splice(index, 1);
|
|
140
|
+
saveConfig(config);
|
|
141
|
+
output.success(`Removed source '${chalk.cyan(name)}'`);
|
|
142
|
+
console.log(`Run ${chalk.cyan('contextkit index')} to update the index.`);
|
|
143
|
+
});
|
|
144
|
+
function getFileExtensions(files) {
|
|
145
|
+
const exts = new Set();
|
|
146
|
+
for (const file of files) {
|
|
147
|
+
const ext = file.split('.').pop();
|
|
148
|
+
if (ext)
|
|
149
|
+
exts.add(ext);
|
|
150
|
+
}
|
|
151
|
+
return Array.from(exts).slice(0, 5).join(', ') + (exts.size > 5 ? '...' : '');
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../src/commands/source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACnD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,WAAW,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,o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AO,CAAC,mBAAmB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvD,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,CAAC;AAC5E,CAAC,CAAC,CAAC;AAEL,SAAS,iBAAiB,CAAC,KAAe;IACxC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QAClC,IAAI,GAAG;YAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Config } from './types.js';
|
|
2
|
+
export declare const CONFIG_FILE = "config.yaml";
|
|
3
|
+
export declare const INDEX_DB = "index.db";
|
|
4
|
+
export declare const CONTEXTKIT_DIR = ".contextkit";
|
|
5
|
+
/**
|
|
6
|
+
* Get the .contextkit directory path
|
|
7
|
+
*/
|
|
8
|
+
export declare function getContextKitDir(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Get the config file path
|
|
11
|
+
*/
|
|
12
|
+
export declare function getConfigPath(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Get the database file path
|
|
15
|
+
*/
|
|
16
|
+
export declare function getDbPath(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Check if ContextKit is initialized in the current directory
|
|
19
|
+
*/
|
|
20
|
+
export declare function isInitialized(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Ensure ContextKit is initialized, throw if not
|
|
23
|
+
*/
|
|
24
|
+
export declare function ensureInitialized(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Load the configuration file
|
|
27
|
+
*/
|
|
28
|
+
export declare function loadConfig(): Config;
|
|
29
|
+
/**
|
|
30
|
+
* Save the configuration file
|
|
31
|
+
*/
|
|
32
|
+
export declare function saveConfig(config: Config): void;
|
|
33
|
+
/**
|
|
34
|
+
* Get the default configuration as YAML string
|
|
35
|
+
*/
|
|
36
|
+
export declare function getDefaultConfig(): string;
|
|
37
|
+
export type { Config, Source, Settings } from './types.js';
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,QAAQ,aAAa,CAAC;AACnC,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAE5C;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAIxC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAgBnC;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAI/C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAiCzC;AAED,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { parse, stringify } from 'yaml';
|
|
4
|
+
import { NotInitializedError } from '../errors/index.js';
|
|
5
|
+
export const CONFIG_FILE = 'config.yaml';
|
|
6
|
+
export const INDEX_DB = 'index.db';
|
|
7
|
+
export const CONTEXTKIT_DIR = '.contextkit';
|
|
8
|
+
/**
|
|
9
|
+
* Get the .contextkit directory path
|
|
10
|
+
*/
|
|
11
|
+
export function getContextKitDir() {
|
|
12
|
+
return join(process.cwd(), CONTEXTKIT_DIR);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get the config file path
|
|
16
|
+
*/
|
|
17
|
+
export function getConfigPath() {
|
|
18
|
+
return join(getContextKitDir(), CONFIG_FILE);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get the database file path
|
|
22
|
+
*/
|
|
23
|
+
export function getDbPath() {
|
|
24
|
+
return join(getContextKitDir(), INDEX_DB);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check if ContextKit is initialized in the current directory
|
|
28
|
+
*/
|
|
29
|
+
export function isInitialized() {
|
|
30
|
+
return existsSync(getContextKitDir()) && existsSync(getConfigPath());
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Ensure ContextKit is initialized, throw if not
|
|
34
|
+
*/
|
|
35
|
+
export function ensureInitialized() {
|
|
36
|
+
if (!isInitialized()) {
|
|
37
|
+
throw new NotInitializedError();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Load the configuration file
|
|
42
|
+
*/
|
|
43
|
+
export function loadConfig() {
|
|
44
|
+
const configPath = getConfigPath();
|
|
45
|
+
if (!existsSync(configPath)) {
|
|
46
|
+
throw new Error(`Config file not found: ${configPath}`);
|
|
47
|
+
}
|
|
48
|
+
const content = readFileSync(configPath, 'utf-8');
|
|
49
|
+
const config = parse(content);
|
|
50
|
+
// Ensure sources array exists
|
|
51
|
+
if (!config.sources) {
|
|
52
|
+
config.sources = [];
|
|
53
|
+
}
|
|
54
|
+
return config;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Save the configuration file
|
|
58
|
+
*/
|
|
59
|
+
export function saveConfig(config) {
|
|
60
|
+
const configPath = getConfigPath();
|
|
61
|
+
const content = stringify(config, { lineWidth: 0 });
|
|
62
|
+
writeFileSync(configPath, content);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the default configuration as YAML string
|
|
66
|
+
*/
|
|
67
|
+
export function getDefaultConfig() {
|
|
68
|
+
const config = {
|
|
69
|
+
version: 1,
|
|
70
|
+
sources: [],
|
|
71
|
+
settings: {
|
|
72
|
+
chunk_size: 500,
|
|
73
|
+
chunk_overlap: 50,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
return `# ContextKit Configuration
|
|
77
|
+
# https://github.com/milo4jo/contextkit
|
|
78
|
+
|
|
79
|
+
version: ${config.version}
|
|
80
|
+
|
|
81
|
+
# Sources to index
|
|
82
|
+
sources: []
|
|
83
|
+
# Example:
|
|
84
|
+
# - id: src
|
|
85
|
+
# path: ./src
|
|
86
|
+
# patterns:
|
|
87
|
+
# include:
|
|
88
|
+
# - "**/*.ts"
|
|
89
|
+
# - "**/*.js"
|
|
90
|
+
# exclude:
|
|
91
|
+
# - "**/node_modules/**"
|
|
92
|
+
# - "**/*.test.ts"
|
|
93
|
+
|
|
94
|
+
# Chunking settings
|
|
95
|
+
settings:
|
|
96
|
+
chunk_size: ${config.settings.chunk_size}
|
|
97
|
+
chunk_overlap: ${config.settings.chunk_overlap}
|
|
98
|
+
`;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,E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Y,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAW,CAAC;IAExC,8BAA8B;IAC9B,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;IACtB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;IACpD,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,MAAM,GAAW;QACrB,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE;YACR,UAAU,EAAE,GAAG;YACf,aAAa,EAAE,EAAE;SAClB;KACF,CAAC;IAEF,OAAO;;;WAGE,MAAM,CAAC,OAAO;;;;;;;;;;;;;;;;;gBAiBT,MAAM,CAAC,QAAQ,CAAC,UAAU;mBACvB,MAAM,CAAC,QAAQ,CAAC,aAAa;CAC/C,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration types for ContextKit
|
|
3
|
+
*/
|
|
4
|
+
export interface Source {
|
|
5
|
+
id: string;
|
|
6
|
+
path: string;
|
|
7
|
+
patterns: {
|
|
8
|
+
include: string[];
|
|
9
|
+
exclude: string[];
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface Settings {
|
|
13
|
+
chunk_size: number;
|
|
14
|
+
chunk_overlap: number;
|
|
15
|
+
}
|
|
16
|
+
export interface Config {
|
|
17
|
+
version: number;
|
|
18
|
+
sources: Source[];
|
|
19
|
+
settings: Settings;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QACR,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;CACH;AAED,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,QAAQ,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
2
|
+
/**
|
|
3
|
+
* Initialize the database with schema
|
|
4
|
+
*/
|
|
5
|
+
export declare function initDatabase(dbPath: string): Database.Database;
|
|
6
|
+
/**
|
|
7
|
+
* Open the existing database
|
|
8
|
+
*/
|
|
9
|
+
export declare function openDatabase(): Database.Database;
|
|
10
|
+
/**
|
|
11
|
+
* Close the database connection
|
|
12
|
+
*/
|
|
13
|
+
export declare function closeDatabase(db: Database.Database): void;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAsCtC;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAU9D;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,QAAQ,CAAC,QAAQ,CAKhD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAEzD"}
|
package/dist/db/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
2
|
+
import { getDbPath } from '../config/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Database schema for ContextKit
|
|
5
|
+
*/
|
|
6
|
+
const SCHEMA = `
|
|
7
|
+
-- Sources table
|
|
8
|
+
CREATE TABLE IF NOT EXISTS sources (
|
|
9
|
+
id TEXT PRIMARY KEY,
|
|
10
|
+
path TEXT NOT NULL,
|
|
11
|
+
config JSON,
|
|
12
|
+
file_count INTEGER DEFAULT 0,
|
|
13
|
+
chunk_count INTEGER DEFAULT 0,
|
|
14
|
+
indexed_at TIMESTAMP
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
-- Ensure chunk_count column exists (migration)
|
|
18
|
+
-- SQLite doesn't support IF NOT EXISTS for columns, so we handle this in code
|
|
19
|
+
|
|
20
|
+
-- Chunks table
|
|
21
|
+
CREATE TABLE IF NOT EXISTS chunks (
|
|
22
|
+
id TEXT PRIMARY KEY,
|
|
23
|
+
source_id TEXT NOT NULL REFERENCES sources(id) ON DELETE CASCADE,
|
|
24
|
+
file_path TEXT NOT NULL,
|
|
25
|
+
content TEXT NOT NULL,
|
|
26
|
+
start_line INTEGER,
|
|
27
|
+
end_line INTEGER,
|
|
28
|
+
tokens INTEGER NOT NULL,
|
|
29
|
+
embedding BLOB,
|
|
30
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
-- Indexes for performance
|
|
34
|
+
CREATE INDEX IF NOT EXISTS idx_chunks_source ON chunks(source_id);
|
|
35
|
+
CREATE INDEX IF NOT EXISTS idx_chunks_file ON chunks(file_path);
|
|
36
|
+
`;
|
|
37
|
+
/**
|
|
38
|
+
* Initialize the database with schema
|
|
39
|
+
*/
|
|
40
|
+
export function initDatabase(dbPath) {
|
|
41
|
+
const db = new Database(dbPath);
|
|
42
|
+
// Enable foreign keys
|
|
43
|
+
db.pragma('foreign_keys = ON');
|
|
44
|
+
// Create schema
|
|
45
|
+
db.exec(SCHEMA);
|
|
46
|
+
return db;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Open the existing database
|
|
50
|
+
*/
|
|
51
|
+
export function openDatabase() {
|
|
52
|
+
const dbPath = getDbPath();
|
|
53
|
+
const db = new Database(dbPath);
|
|
54
|
+
db.pragma('foreign_keys = ON');
|
|
55
|
+
return db;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Close the database connection
|
|
59
|
+
*/
|
|
60
|
+
export function closeDatabase(db) {
|
|
61
|
+
db.close();
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Bd,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAEhC,sBAAsB;IACtB,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAE/B,gBAAgB;IAChB,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEhB,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChC,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAC/B,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,EAAqB;IACjD,EAAE,CAAC,KAAK,EAAE,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error classes for ContextKit
|
|
3
|
+
* Based on ARCHITECTURE.md specification
|
|
4
|
+
*/
|
|
5
|
+
export declare class ContextKitError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly recoverable: boolean;
|
|
8
|
+
constructor(message: string, code: string, recoverable?: boolean);
|
|
9
|
+
}
|
|
10
|
+
export declare class NotInitializedError extends ContextKitError {
|
|
11
|
+
readonly suggestion = "contextkit init";
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
14
|
+
export declare class SourceNotFoundError extends ContextKitError {
|
|
15
|
+
readonly suggestion = "contextkit source list";
|
|
16
|
+
constructor(name: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class PathNotFoundError extends ContextKitError {
|
|
19
|
+
constructor(path: string, suggestion?: string);
|
|
20
|
+
}
|
|
21
|
+
export declare class SourceExistsError extends ContextKitError {
|
|
22
|
+
constructor(name: string, existingPath?: string);
|
|
23
|
+
}
|
|
24
|
+
export declare class AlreadyInitializedError extends ContextKitError {
|
|
25
|
+
constructor();
|
|
26
|
+
}
|
|
27
|
+
export declare class InvalidUsageError extends ContextKitError {
|
|
28
|
+
constructor(message: string);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;gBAElB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,UAAQ;CAM/D;AAED,qBAAa,mBAAoB,SAAQ,eAAe;IACtD,QAAQ,CAAC,UAAU,qBAAqB;;CAQzC;AAED,qBAAa,mBAAoB,SAAQ,eAAe;IACtD,QAAQ,CAAC,UAAU,4BAA4B;gBAEnC,IAAI,EAAE,MAAM;CAMzB;AAED,qBAAa,iBAAkB,SAAQ,eAAe;gBACxC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAM9C;AAED,qBAAa,iBAAkB,SAAQ,eAAe;gBACxC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;CAOhD;AAED,qBAAa,uBAAwB,SAAQ,eAAe;;CAI3D;AAED,qBAAa,iBAAkB,SAAQ,eAAe;gBACxC,OAAO,EAAE,MAAM;CAG5B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error classes for ContextKit
|
|
3
|
+
* Based on ARCHITECTURE.md specification
|
|
4
|
+
*/
|
|
5
|
+
export class ContextKitError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
recoverable;
|
|
8
|
+
constructor(message, code, recoverable = false) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'ContextKitError';
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.recoverable = recoverable;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class NotInitializedError extends ContextKitError {
|
|
16
|
+
suggestion = 'contextkit init';
|
|
17
|
+
constructor() {
|
|
18
|
+
super('Not initialized. Run `contextkit init` to set up ContextKit in this directory.', 'NOT_INITIALIZED');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class SourceNotFoundError extends ContextKitError {
|
|
22
|
+
suggestion = 'contextkit source list';
|
|
23
|
+
constructor(name) {
|
|
24
|
+
super(`Source "${name}" not found. Run \`contextkit source list\` to see available sources.`, 'SOURCE_NOT_FOUND');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class PathNotFoundError extends ContextKitError {
|
|
28
|
+
constructor(path, suggestion) {
|
|
29
|
+
const msg = suggestion
|
|
30
|
+
? `Path "${path}" not found. Did you mean "${suggestion}"?`
|
|
31
|
+
: `Path "${path}" not found.`;
|
|
32
|
+
super(msg, 'PATH_NOT_FOUND');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class SourceExistsError extends ContextKitError {
|
|
36
|
+
constructor(name, existingPath) {
|
|
37
|
+
const hint = existingPath ? ` It points to "${existingPath}".` : '';
|
|
38
|
+
super(`Source "${name}" already exists.${hint} Use a different name or remove it first with \`contextkit source remove ${name}\`.`, 'SOURCE_EXISTS');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class AlreadyInitializedError extends ContextKitError {
|
|
42
|
+
constructor() {
|
|
43
|
+
super('Already initialized. Use --force to reinitialize.', 'ALREADY_INITIALIZED');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class InvalidUsageError extends ContextKitError {
|
|
47
|
+
constructor(message) {
|
|
48
|
+
super(message, 'INVALID_USAGE');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,IAAI,CAAS;IACb,WAAW,CAAU;IAE9B,YAAY,OAAe,EAAE,IAAY,EAAE,WAAW,GAAG,KAAK;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAA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