k0ntext 3.3.1 → 3.6.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 +225 -26
- package/dist/agents/cleanup-agent.d.ts.map +1 -1
- package/dist/agents/cleanup-agent.js +18 -6
- package/dist/agents/cleanup-agent.js.map +1 -1
- package/dist/agents/drift-agent.d.ts +7 -0
- package/dist/agents/drift-agent.d.ts.map +1 -1
- package/dist/agents/drift-agent.js +29 -8
- package/dist/agents/drift-agent.js.map +1 -1
- package/dist/cli/commands/cleanup.d.ts.map +1 -1
- package/dist/cli/commands/cleanup.js +8 -1
- package/dist/cli/commands/cleanup.js.map +1 -1
- package/dist/cli/commands/drift-detect.d.ts.map +1 -1
- package/dist/cli/commands/drift-detect.js +21 -1
- package/dist/cli/commands/drift-detect.js.map +1 -1
- package/dist/cli/commands/embeddings-refresh.d.ts +11 -0
- package/dist/cli/commands/embeddings-refresh.d.ts.map +1 -0
- package/dist/cli/commands/embeddings-refresh.js +114 -0
- package/dist/cli/commands/embeddings-refresh.js.map +1 -0
- package/dist/cli/commands/migrate.d.ts +11 -0
- package/dist/cli/commands/migrate.d.ts.map +1 -0
- package/dist/cli/commands/migrate.js +195 -0
- package/dist/cli/commands/migrate.js.map +1 -0
- package/dist/cli/commands/restore.d.ts +12 -0
- package/dist/cli/commands/restore.d.ts.map +1 -0
- package/dist/cli/commands/restore.js +261 -0
- package/dist/cli/commands/restore.js.map +1 -0
- package/dist/cli/commands/sync-templates.d.ts +15 -0
- package/dist/cli/commands/sync-templates.d.ts.map +1 -0
- package/dist/cli/commands/sync-templates.js +181 -0
- package/dist/cli/commands/sync-templates.js.map +1 -0
- package/dist/cli/commands/version-check.d.ts +12 -0
- package/dist/cli/commands/version-check.d.ts.map +1 -0
- package/dist/cli/commands/version-check.js +133 -0
- package/dist/cli/commands/version-check.js.map +1 -0
- package/dist/cli/generate.d.ts +5 -0
- package/dist/cli/generate.d.ts.map +1 -1
- package/dist/cli/generate.js +80 -16
- package/dist/cli/generate.js.map +1 -1
- package/dist/cli/index.js +215 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/repl/index.d.ts +1 -0
- package/dist/cli/repl/index.d.ts.map +1 -1
- package/dist/cli/repl/index.js +18 -6
- package/dist/cli/repl/index.js.map +1 -1
- package/dist/cli/utils/backup-manager.d.ts +94 -0
- package/dist/cli/utils/backup-manager.d.ts.map +1 -0
- package/dist/cli/utils/backup-manager.js +230 -0
- package/dist/cli/utils/backup-manager.js.map +1 -0
- package/dist/cli/utils/db-backup-manager.d.ts +55 -0
- package/dist/cli/utils/db-backup-manager.d.ts.map +1 -0
- package/dist/cli/utils/db-backup-manager.js +115 -0
- package/dist/cli/utils/db-backup-manager.js.map +1 -0
- package/dist/cli/utils/file-detector.d.ts +87 -0
- package/dist/cli/utils/file-detector.d.ts.map +1 -0
- package/dist/cli/utils/file-detector.js +131 -0
- package/dist/cli/utils/file-detector.js.map +1 -0
- package/dist/cli/utils/index.d.ts +9 -0
- package/dist/cli/utils/index.d.ts.map +1 -0
- package/dist/cli/utils/index.js +9 -0
- package/dist/cli/utils/index.js.map +1 -0
- package/dist/cli/utils/modification-prompt.d.ts +41 -0
- package/dist/cli/utils/modification-prompt.d.ts.map +1 -0
- package/dist/cli/utils/modification-prompt.js +84 -0
- package/dist/cli/utils/modification-prompt.js.map +1 -0
- package/dist/cli/version/checker.d.ts +47 -0
- package/dist/cli/version/checker.d.ts.map +1 -0
- package/dist/cli/version/checker.js +143 -0
- package/dist/cli/version/checker.js.map +1 -0
- package/dist/cli/version/comparator.d.ts +46 -0
- package/dist/cli/version/comparator.d.ts.map +1 -0
- package/dist/cli/version/comparator.js +99 -0
- package/dist/cli/version/comparator.js.map +1 -0
- package/dist/cli/version/index.d.ts +11 -0
- package/dist/cli/version/index.d.ts.map +1 -0
- package/dist/cli/version/index.js +11 -0
- package/dist/cli/version/index.js.map +1 -0
- package/dist/cli/version/parser.d.ts +38 -0
- package/dist/cli/version/parser.d.ts.map +1 -0
- package/dist/cli/version/parser.js +90 -0
- package/dist/cli/version/parser.js.map +1 -0
- package/dist/cli/version/prompt.d.ts +40 -0
- package/dist/cli/version/prompt.d.ts.map +1 -0
- package/dist/cli/version/prompt.js +162 -0
- package/dist/cli/version/prompt.js.map +1 -0
- package/dist/cli/version/types.d.ts +89 -0
- package/dist/cli/version/types.d.ts.map +1 -0
- package/dist/cli/version/types.js +7 -0
- package/dist/cli/version/types.js.map +1 -0
- package/dist/db/client.d.ts +79 -4
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +207 -12
- package/dist/db/client.js.map +1 -1
- package/dist/db/migrations/files/0014_add_schema_migrations_table.d.ts +14 -0
- package/dist/db/migrations/files/0014_add_schema_migrations_table.d.ts.map +1 -0
- package/dist/db/migrations/files/0014_add_schema_migrations_table.js +25 -0
- package/dist/db/migrations/files/0014_add_schema_migrations_table.js.map +1 -0
- package/dist/db/migrations/index.d.ts +9 -0
- package/dist/db/migrations/index.d.ts.map +1 -0
- package/dist/db/migrations/index.js +9 -0
- package/dist/db/migrations/index.js.map +1 -0
- package/dist/db/migrations/loader.d.ts +27 -0
- package/dist/db/migrations/loader.d.ts.map +1 -0
- package/dist/db/migrations/loader.js +106 -0
- package/dist/db/migrations/loader.js.map +1 -0
- package/dist/db/migrations/runner.d.ts +56 -0
- package/dist/db/migrations/runner.d.ts.map +1 -0
- package/dist/db/migrations/runner.js +266 -0
- package/dist/db/migrations/runner.js.map +1 -0
- package/dist/db/migrations/types.d.ts +71 -0
- package/dist/db/migrations/types.d.ts.map +1 -0
- package/dist/db/migrations/types.js +7 -0
- package/dist/db/migrations/types.js.map +1 -0
- package/dist/db/schema.d.ts +41 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +77 -2
- package/dist/db/schema.js.map +1 -1
- package/dist/mcp.js +2 -2
- package/dist/mcp.js.map +1 -1
- package/dist/template-engine/data-transformer.d.ts +17 -0
- package/dist/template-engine/data-transformer.d.ts.map +1 -0
- package/dist/template-engine/data-transformer.js +343 -0
- package/dist/template-engine/data-transformer.js.map +1 -0
- package/dist/template-engine/engine.d.ts +74 -0
- package/dist/template-engine/engine.d.ts.map +1 -0
- package/dist/template-engine/engine.js +183 -0
- package/dist/template-engine/engine.js.map +1 -0
- package/dist/template-engine/helpers.d.ts +81 -0
- package/dist/template-engine/helpers.d.ts.map +1 -0
- package/dist/template-engine/helpers.js +153 -0
- package/dist/template-engine/helpers.js.map +1 -0
- package/dist/template-engine/index.d.ts +10 -0
- package/dist/template-engine/index.d.ts.map +1 -0
- package/dist/template-engine/index.js +10 -0
- package/dist/template-engine/index.js.map +1 -0
- package/dist/template-engine/types.d.ts +147 -0
- package/dist/template-engine/types.d.ts.map +1 -0
- package/dist/template-engine/types.js +7 -0
- package/dist/template-engine/types.js.map +1 -0
- package/dist/template-sync/comparator.d.ts +138 -0
- package/dist/template-sync/comparator.d.ts.map +1 -0
- package/dist/template-sync/comparator.js +353 -0
- package/dist/template-sync/comparator.js.map +1 -0
- package/dist/template-sync/conflict-resolver.d.ts +112 -0
- package/dist/template-sync/conflict-resolver.d.ts.map +1 -0
- package/dist/template-sync/conflict-resolver.js +328 -0
- package/dist/template-sync/conflict-resolver.js.map +1 -0
- package/dist/template-sync/engine.d.ts +93 -0
- package/dist/template-sync/engine.d.ts.map +1 -0
- package/dist/template-sync/engine.js +350 -0
- package/dist/template-sync/engine.js.map +1 -0
- package/dist/template-sync/hasher.d.ts +67 -0
- package/dist/template-sync/hasher.d.ts.map +1 -0
- package/dist/template-sync/hasher.js +94 -0
- package/dist/template-sync/hasher.js.map +1 -0
- package/dist/template-sync/index.d.ts +20 -0
- package/dist/template-sync/index.d.ts.map +1 -0
- package/dist/template-sync/index.js +14 -0
- package/dist/template-sync/index.js.map +1 -0
- package/dist/template-sync/manifest.d.ts +131 -0
- package/dist/template-sync/manifest.d.ts.map +1 -0
- package/dist/template-sync/manifest.js +309 -0
- package/dist/template-sync/manifest.js.map +1 -0
- package/dist/template-sync/merger.d.ts +125 -0
- package/dist/template-sync/merger.d.ts.map +1 -0
- package/dist/template-sync/merger.js +371 -0
- package/dist/template-sync/merger.js.map +1 -0
- package/dist/template-sync/scanner.d.ts +106 -0
- package/dist/template-sync/scanner.d.ts.map +1 -0
- package/dist/template-sync/scanner.js +196 -0
- package/dist/template-sync/scanner.js.map +1 -0
- package/dist/template-sync/types.d.ts +199 -0
- package/dist/template-sync/types.d.ts.map +1 -0
- package/dist/template-sync/types.js +30 -0
- package/dist/template-sync/types.js.map +1 -0
- package/package.json +2 -1
- package/src/agents/cleanup-agent.ts +21 -6
- package/src/agents/drift-agent.ts +31 -8
- package/src/cli/commands/cleanup.ts +9 -1
- package/src/cli/commands/drift-detect.ts +24 -1
- package/src/cli/commands/embeddings-refresh.ts +135 -0
- package/src/cli/commands/migrate.ts +231 -0
- package/src/cli/commands/restore.ts +318 -0
- package/src/cli/commands/sync-templates.ts +210 -0
- package/src/cli/commands/version-check.ts +158 -0
- package/src/cli/generate.ts +99 -17
- package/src/cli/index.ts +246 -1
- package/src/cli/repl/index.ts +16 -6
- package/src/cli/utils/backup-manager.ts +275 -0
- package/src/cli/utils/db-backup-manager.ts +146 -0
- package/src/cli/utils/file-detector.ts +181 -0
- package/src/cli/utils/index.ts +9 -0
- package/src/cli/utils/modification-prompt.ts +112 -0
- package/src/cli/version/checker.ts +172 -0
- package/src/cli/version/comparator.ts +106 -0
- package/src/cli/version/index.ts +11 -0
- package/src/cli/version/parser.ts +101 -0
- package/src/cli/version/prompt.ts +208 -0
- package/src/cli/version/types.ts +95 -0
- package/src/db/client.ts +285 -18
- package/src/db/migrations/files/0014_add_schema_migrations_table.sql +19 -0
- package/src/db/migrations/files/0014_add_schema_migrations_table.ts +30 -0
- package/src/db/migrations/index.ts +9 -0
- package/src/db/migrations/loader.ts +129 -0
- package/src/db/migrations/runner.ts +316 -0
- package/src/db/migrations/types.ts +71 -0
- package/src/db/schema.ts +109 -2
- package/src/mcp.ts +2 -2
- package/src/template-engine/data-transformer.ts +367 -0
- package/src/template-engine/engine.ts +213 -0
- package/src/template-engine/helpers.ts +163 -0
- package/src/template-engine/index.ts +10 -0
- package/src/template-engine/types.ts +158 -0
- package/src/template-sync/comparator.ts +452 -0
- package/src/template-sync/conflict-resolver.ts +401 -0
- package/src/template-sync/engine.ts +417 -0
- package/src/template-sync/hasher.ts +104 -0
- package/src/template-sync/index.ts +60 -0
- package/src/template-sync/manifest.ts +358 -0
- package/src/template-sync/merger.ts +454 -0
- package/src/template-sync/scanner.ts +254 -0
- package/src/template-sync/types.ts +247 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../src/template-sync/scanner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAgB7C;;GAEG;AACH,MAAM,wBAAwB,GAAG;IAC/B,cAAc;IACd,MAAM;IACN,WAAW;IACX,OAAO;IACP,wBAAwB;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,eAAe;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,aAAa,CACxB,QAAgB,EAChB,iBAAmC,gBAAgB,EACnD,kBAA4B,wBAAwB;QAEpD,MAAM,OAAO,GAAmB,EAAE,CAAC;QAEnC,KAAK,MAAM,MAAM,IAAI,cAAc,EAAE,CAAC;YACpC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC5C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;YAC3E,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AG,IAAI,GAAG,EAAkB,CAAC;QAEzC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACpD,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,cAAc,CAAC,KAAqB,EAAE,MAAc;QACzD,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/E,CAAC;CACF"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Sync Types
|
|
3
|
+
*
|
|
4
|
+
* All type definitions for the template sync system.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Template file metadata
|
|
8
|
+
*/
|
|
9
|
+
export interface TemplateFile {
|
|
10
|
+
/** Relative path from .claude/ or templates/base/.claude/ */
|
|
11
|
+
relativePath: string;
|
|
12
|
+
/** Content hash (SHA-256, 16 chars) */
|
|
13
|
+
hash: string;
|
|
14
|
+
/** File size in bytes */
|
|
15
|
+
size: number;
|
|
16
|
+
/** Last modified time */
|
|
17
|
+
mtime: Date;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Template manifest structure (stored in DB and .claude/.k0ntext-manifest.json)
|
|
21
|
+
*/
|
|
22
|
+
export interface TemplateManifest {
|
|
23
|
+
/** k0ntext version that generated this manifest */
|
|
24
|
+
k0ntextVersion: string;
|
|
25
|
+
/** Template source version */
|
|
26
|
+
templateVersion: string;
|
|
27
|
+
/** Timestamp when manifest was created */
|
|
28
|
+
createdAt: string;
|
|
29
|
+
/** Timestamp when manifest was last updated */
|
|
30
|
+
updatedAt?: string;
|
|
31
|
+
/** All tracked template files keyed by relative path */
|
|
32
|
+
files: Record<string, TemplateFileEntry>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Single file entry in manifest
|
|
36
|
+
*/
|
|
37
|
+
export interface TemplateFileEntry {
|
|
38
|
+
/** Content hash */
|
|
39
|
+
hash: string;
|
|
40
|
+
/** Template version when file was last updated */
|
|
41
|
+
templateVersion: string;
|
|
42
|
+
/** Whether user has modified this file */
|
|
43
|
+
userModified: boolean;
|
|
44
|
+
/** Last sync timestamp */
|
|
45
|
+
lastSyncedAt?: string;
|
|
46
|
+
/** Original template hash (before user modification) */
|
|
47
|
+
originalHash?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Comparison result for a single file
|
|
51
|
+
*/
|
|
52
|
+
export interface FileComparison {
|
|
53
|
+
/** Relative path from .claude/ */
|
|
54
|
+
path: string;
|
|
55
|
+
/** Current state */
|
|
56
|
+
state: FileState;
|
|
57
|
+
/** Template hash (from package) */
|
|
58
|
+
templateHash: string;
|
|
59
|
+
/** Local hash (from .claude/) */
|
|
60
|
+
localHash: string;
|
|
61
|
+
/** Whether user has modified (from manifest) */
|
|
62
|
+
userModified: boolean;
|
|
63
|
+
/** Original template hash (if user modified) */
|
|
64
|
+
originalHash?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* File state after comparison
|
|
68
|
+
*/
|
|
69
|
+
export type FileState = 'identical' | 'safe-update' | 'conflict' | 'new' | 'deleted' | 'user-only';
|
|
70
|
+
/**
|
|
71
|
+
* Sync operation result
|
|
72
|
+
*/
|
|
73
|
+
export interface SyncResult {
|
|
74
|
+
/** Total files processed */
|
|
75
|
+
total: number;
|
|
76
|
+
/** Files updated (safe merge) */
|
|
77
|
+
updated: number;
|
|
78
|
+
/** Files skipped (user modified/conflict) */
|
|
79
|
+
skipped: string[];
|
|
80
|
+
/** New files created */
|
|
81
|
+
created: number;
|
|
82
|
+
/** Files in conflict requiring resolution */
|
|
83
|
+
conflicts: FileComparison[];
|
|
84
|
+
/** User-only files (deleted from template) */
|
|
85
|
+
userOnly: string[];
|
|
86
|
+
/** Duration in milliseconds */
|
|
87
|
+
durationMs: number;
|
|
88
|
+
/** Whether this was a dry run */
|
|
89
|
+
dryRun?: boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Sync options
|
|
93
|
+
*/
|
|
94
|
+
export interface SyncOptions {
|
|
95
|
+
/** Dry run - don't make changes */
|
|
96
|
+
dryRun?: boolean;
|
|
97
|
+
/** Force update all files (skip prompts, overwrite user modifications) */
|
|
98
|
+
force?: boolean;
|
|
99
|
+
/** Specific subdirectories to sync */
|
|
100
|
+
subdirectories?: TemplateSubdir[];
|
|
101
|
+
/** Verbose output */
|
|
102
|
+
verbose?: boolean;
|
|
103
|
+
/** Whether to archive removed files */
|
|
104
|
+
archiveRemoved?: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Template subdirectories (synced from package)
|
|
108
|
+
*/
|
|
109
|
+
export type TemplateSubdir = 'commands' | 'agents' | 'schemas' | 'standards' | 'tools' | 'automation';
|
|
110
|
+
/**
|
|
111
|
+
* Excluded subdirectories (user-specific, not synced)
|
|
112
|
+
*/
|
|
113
|
+
export type ExcludedSubdir = 'context' | 'indexes';
|
|
114
|
+
/**
|
|
115
|
+
* Template source configuration
|
|
116
|
+
*/
|
|
117
|
+
export interface TemplateSource {
|
|
118
|
+
/** Root path to templates (e.g., templates/base/.claude/) */
|
|
119
|
+
rootPath: string;
|
|
120
|
+
/** Subdirectories to sync */
|
|
121
|
+
subdirectories: TemplateSubdir[];
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Merge result for a single file
|
|
125
|
+
*/
|
|
126
|
+
export interface MergeResult {
|
|
127
|
+
/** File path */
|
|
128
|
+
path: string;
|
|
129
|
+
/** Whether merge was successful */
|
|
130
|
+
success: boolean;
|
|
131
|
+
/** Merge method used */
|
|
132
|
+
method: MergeMethod;
|
|
133
|
+
/** Diff if available */
|
|
134
|
+
diff?: string;
|
|
135
|
+
/** Error message if failed */
|
|
136
|
+
error?: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Merge method used
|
|
140
|
+
*/
|
|
141
|
+
export type MergeMethod = 'auto-safe' | 'auto-create' | 'overwrite' | 'skip' | 'conflict';
|
|
142
|
+
/**
|
|
143
|
+
* Resolution choice for conflicts
|
|
144
|
+
*/
|
|
145
|
+
export type ResolutionChoice = 'skip' | 'overwrite' | 'keep-local' | 'show-diff';
|
|
146
|
+
/**
|
|
147
|
+
* Resolution result for a single conflict
|
|
148
|
+
*/
|
|
149
|
+
export interface ResolutionResult {
|
|
150
|
+
/** File path */
|
|
151
|
+
path: string;
|
|
152
|
+
/** User's choice */
|
|
153
|
+
choice: ResolutionChoice;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Archive result for removed files
|
|
157
|
+
*/
|
|
158
|
+
export interface ArchiveResult {
|
|
159
|
+
/** Files that were archived */
|
|
160
|
+
archived: string[];
|
|
161
|
+
/** Archive path */
|
|
162
|
+
archivePath: string;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Template file record from database
|
|
166
|
+
*/
|
|
167
|
+
export interface TemplateFileRecord {
|
|
168
|
+
id: string;
|
|
169
|
+
relativePath: string;
|
|
170
|
+
templateHash: string;
|
|
171
|
+
templateVersion: string;
|
|
172
|
+
userModified: boolean;
|
|
173
|
+
lastSyncedAt?: string;
|
|
174
|
+
syncedAt: string;
|
|
175
|
+
metadata?: Record<string, unknown>;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Template manifest record from database
|
|
179
|
+
*/
|
|
180
|
+
export interface TemplateManifestRecord {
|
|
181
|
+
id: string;
|
|
182
|
+
k0ntextVersion: string;
|
|
183
|
+
templateVersion: string;
|
|
184
|
+
manifest: string;
|
|
185
|
+
createdAt: string;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* All template subdirectories
|
|
189
|
+
*/
|
|
190
|
+
export declare const TEMPLATE_SUBDIRS: TemplateSubdir[];
|
|
191
|
+
/**
|
|
192
|
+
* All excluded subdirectories
|
|
193
|
+
*/
|
|
194
|
+
export declare const EXCLUDED_SUBDIRS: ExcludedSubdir[];
|
|
195
|
+
/**
|
|
196
|
+
* Default sync options
|
|
197
|
+
*/
|
|
198
|
+
export declare const DEFAULT_SYNC_OPTIONS: SyncOptions;
|
|
199
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/template-sync/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC;IACrB,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,KAAK,EAAE,IAAI,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,cAAc,EAAE,MAAM,CAAC;IACvB,8BAA8B;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,eAAe,EAAE,MAAM,CAAC;IACxB,0CAA0C;IAC1C,YAA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,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,cAAc,EAO5C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,cAAc,EAA2B,CAAC;AAEzE;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAKlC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Sync Types
|
|
3
|
+
*
|
|
4
|
+
* All type definitions for the template sync system.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* All template subdirectories
|
|
8
|
+
*/
|
|
9
|
+
export const TEMPLATE_SUBDIRS = [
|
|
10
|
+
'commands',
|
|
11
|
+
'agents',
|
|
12
|
+
'schemas',
|
|
13
|
+
'standards',
|
|
14
|
+
'tools',
|
|
15
|
+
'automation'
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* All excluded subdirectories
|
|
19
|
+
*/
|
|
20
|
+
export const EXCLUDED_SUBDIRS = ['context', 'indexes'];
|
|
21
|
+
/**
|
|
22
|
+
* Default sync options
|
|
23
|
+
*/
|
|
24
|
+
export const DEFAULT_SYNC_OPTIONS = {
|
|
25
|
+
dryRun: false,
|
|
26
|
+
force: false,
|
|
27
|
+
verbose: false,
|
|
28
|
+
archiveRemoved: true
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/template-sync/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAyNH;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAqB;IAChD,UAAU;IACV,QAAQ;IACR,SAAS;IACT,WAAW;IACX,OAAO;IACP,YAAY;CACb,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAqB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAgB;IAC/C,MAAM,EAAE,KAAK;IACb,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,KAAK;IACd,cAAc,EAAE,IAAI;CACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "k0ntext",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "Unified AI Context Engineering - Intelligent context for Claude, Copilot, Cline, and more with OpenRouter-powered initialization",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
"chalk": "^5.3.0",
|
|
78
78
|
"commander": "^11.1.0",
|
|
79
79
|
"glob": "^10.5.0",
|
|
80
|
+
"handlebars": "^4.7.8",
|
|
80
81
|
"ora": "^8.0.1",
|
|
81
82
|
"sqlite-vec": "^0.1.3",
|
|
82
83
|
"sqlite-vec-windows-x64": "^0.1.7-alpha.2",
|
|
@@ -54,19 +54,27 @@ export class CleanupAgent {
|
|
|
54
54
|
const cwd = options.cwd || this.config.cwd;
|
|
55
55
|
const entries = fs.readdirSync(cwd, { withFileTypes: true });
|
|
56
56
|
|
|
57
|
-
const
|
|
57
|
+
const allToolFolders = entries
|
|
58
58
|
.filter(e => e.isDirectory() && e.name.startsWith('.'))
|
|
59
|
-
.filter(e => this.KNOWN_TOOL_FOLDERS.includes(e.name))
|
|
60
|
-
|
|
59
|
+
.filter(e => this.KNOWN_TOOL_FOLDERS.includes(e.name));
|
|
60
|
+
|
|
61
|
+
// Separate folders to remove vs folders to keep
|
|
62
|
+
const keepList = [
|
|
63
|
+
...(options.keep || []),
|
|
64
|
+
...this.config.defaultKeep
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const foldersToRemove = allToolFolders.filter(e => !keepList.includes(e.name));
|
|
68
|
+
const foldersToKeep = allToolFolders.filter(e => keepList.includes(e.name));
|
|
61
69
|
|
|
62
70
|
const results: CleanupResult = {
|
|
63
|
-
scanned:
|
|
71
|
+
scanned: allToolFolders.length,
|
|
64
72
|
removed: [],
|
|
65
|
-
kept:
|
|
73
|
+
kept: foldersToKeep.map(f => f.name),
|
|
66
74
|
errors: [],
|
|
67
75
|
};
|
|
68
76
|
|
|
69
|
-
for (const folder of
|
|
77
|
+
for (const folder of foldersToRemove) {
|
|
70
78
|
try {
|
|
71
79
|
const folderPath = path.join(cwd, folder.name);
|
|
72
80
|
|
|
@@ -83,6 +91,13 @@ export class CleanupAgent {
|
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
93
|
|
|
94
|
+
// Log kept folders in verbose mode
|
|
95
|
+
if ((options.verbose || this.config.verbose) && foldersToKeep.length > 0) {
|
|
96
|
+
for (const folder of foldersToKeep) {
|
|
97
|
+
console.log(`Kept: ${folder.name} (preserved)`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
86
101
|
return results;
|
|
87
102
|
}
|
|
88
103
|
|
|
@@ -43,6 +43,10 @@ export interface DriftResult {
|
|
|
43
43
|
filesChecked: number;
|
|
44
44
|
/** Time taken in milliseconds */
|
|
45
45
|
duration: number;
|
|
46
|
+
/** Files that failed due to authentication errors */
|
|
47
|
+
authFailures?: string[];
|
|
48
|
+
/** Files that failed due to other errors */
|
|
49
|
+
errors?: Array<{ file: string; error: string }>;
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
/**
|
|
@@ -131,6 +135,8 @@ export class DriftAgent {
|
|
|
131
135
|
const startTime = Date.now();
|
|
132
136
|
const drifts: DriftIssue[] = [];
|
|
133
137
|
let fixed = 0;
|
|
138
|
+
const authFailures: string[] = [];
|
|
139
|
+
const errors: Array<{ file: string; error: string }> = [];
|
|
134
140
|
|
|
135
141
|
// Get list of files to check
|
|
136
142
|
const filesToCheck = options.paths
|
|
@@ -147,14 +153,29 @@ export class DriftAgent {
|
|
|
147
153
|
|
|
148
154
|
// Analyze each file for drift
|
|
149
155
|
for (const relativePath of filesToProcess) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
try {
|
|
157
|
+
const drift = await this.checkFileForDrift(relativePath, sourceFiles);
|
|
158
|
+
if (drift) {
|
|
159
|
+
drifts.push(drift);
|
|
160
|
+
|
|
161
|
+
if (options.autoFix && drift.suggestion) {
|
|
162
|
+
const didFix = await this.fixDrift(relativePath, drift);
|
|
163
|
+
if (didFix) fixed++;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} catch (error) {
|
|
167
|
+
// Check for authentication errors
|
|
168
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
169
|
+
if (errorMessage.includes('401') ||
|
|
170
|
+
errorMessage.includes('Authentication') ||
|
|
171
|
+
errorMessage.includes('Unauthorized') ||
|
|
172
|
+
errorMessage.includes('API key')) {
|
|
173
|
+
authFailures.push(relativePath);
|
|
174
|
+
} else {
|
|
175
|
+
errors.push({ file: relativePath, error: errorMessage });
|
|
157
176
|
}
|
|
177
|
+
// Log error but continue
|
|
178
|
+
console.error(`Failed to analyze ${relativePath}: ${errorMessage}`);
|
|
158
179
|
}
|
|
159
180
|
}
|
|
160
181
|
|
|
@@ -162,7 +183,9 @@ export class DriftAgent {
|
|
|
162
183
|
drifts,
|
|
163
184
|
fixed,
|
|
164
185
|
filesChecked: filesToProcess.length,
|
|
165
|
-
duration: Date.now() - startTime
|
|
186
|
+
duration: Date.now() - startTime,
|
|
187
|
+
authFailures,
|
|
188
|
+
errors
|
|
166
189
|
};
|
|
167
190
|
}
|
|
168
191
|
|
|
@@ -98,7 +98,15 @@ Respond with JSON:
|
|
|
98
98
|
|
|
99
99
|
console.log(chalk.bold(`\nCleanup complete:`));
|
|
100
100
|
console.log(` Scanned: ${chalk.cyan(result.scanned.toString())} tool folders`);
|
|
101
|
-
|
|
101
|
+
|
|
102
|
+
// Use different messaging for dry-run
|
|
103
|
+
if (options.dryRun) {
|
|
104
|
+
const wouldRemoveCount = result.removed.filter(r => r.includes('(dry-run)')).length;
|
|
105
|
+
console.log(` Would remove: ${chalk.cyan(wouldRemoveCount.toString())}`);
|
|
106
|
+
} else {
|
|
107
|
+
console.log(` Removed: ${chalk.cyan(result.removed.length.toString())}`);
|
|
108
|
+
}
|
|
109
|
+
|
|
102
110
|
console.log(` Kept: ${chalk.cyan(result.kept.length.toString())}`);
|
|
103
111
|
|
|
104
112
|
if (result.errors.length > 0) {
|
|
@@ -53,7 +53,30 @@ export const driftDetectCommand = new Command('drift-detect')
|
|
|
53
53
|
console.log(`Duration: ${chalk.dim(`${result.duration}ms`)}`);
|
|
54
54
|
console.log(`Drifts found: ${result.drifts.length > 0 ? chalk.red(result.drifts.length.toString()) : chalk.green('0')}`);
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
// Show auth failures if any
|
|
57
|
+
if (result.authFailures && result.authFailures.length > 0) {
|
|
58
|
+
console.log(chalk.red(`Authentication failures: ${result.authFailures.length}`));
|
|
59
|
+
console.log(chalk.dim(` ${result.authFailures.slice(0, 5).join(', ')}${result.authFailures.length > 5 ? '...' : ''}`));
|
|
60
|
+
console.log(chalk.yellow(`\n⚠ Check your OPENROUTER_API_KEY`));
|
|
61
|
+
|
|
62
|
+
// Exit with error if all files failed auth
|
|
63
|
+
if (result.authFailures.length === result.filesChecked) {
|
|
64
|
+
console.log(chalk.red('\n✖ All files failed authentication. Cannot detect drift.'));
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Show other errors if any
|
|
70
|
+
if (result.errors && result.errors.length > 0) {
|
|
71
|
+
console.log(chalk.yellow(`Other errors: ${result.errors.length}`));
|
|
72
|
+
if (options.verbose) {
|
|
73
|
+
for (const err of result.errors.slice(0, 3)) {
|
|
74
|
+
console.log(chalk.dim(` ${err.file}: ${err.error.substring(0, 60)}...`));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (result.drifts.length === 0 && (!result.authFailures || result.authFailures.length === 0)) {
|
|
57
80
|
console.log(chalk.green('\n✓ No drift detected!'));
|
|
58
81
|
agent.close();
|
|
59
82
|
return;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embeddings Refresh Command
|
|
3
|
+
*
|
|
4
|
+
* Regenerate embeddings with optional dimension validation.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Command } from 'commander';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
import ora from 'ora';
|
|
10
|
+
import { confirm } from '@inquirer/prompts';
|
|
11
|
+
import { createIntelligentAnalyzer } from '../../analyzer/intelligent-analyzer.js';
|
|
12
|
+
import { hasOpenRouterKey } from '../../embeddings/openrouter.js';
|
|
13
|
+
import { DatabaseClient } from '../../db/client.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Embeddings refresh command
|
|
17
|
+
*/
|
|
18
|
+
export const embeddingsRefreshCommand = new Command('embeddings:refresh')
|
|
19
|
+
.description('Regenerate embeddings for all indexed content')
|
|
20
|
+
.option('--force', 'Force refresh even if dimensions change')
|
|
21
|
+
.option('--batch-size <n>', 'Process in batches', '50')
|
|
22
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
23
|
+
.action(async (options) => {
|
|
24
|
+
const spinner = ora();
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
// Check for OpenRouter API key
|
|
28
|
+
if (!hasOpenRouterKey()) {
|
|
29
|
+
spinner.fail('OPENROUTER_API_KEY not found');
|
|
30
|
+
console.log(chalk.yellow(' Set OPENROUTER_API_KEY for embeddings generation'));
|
|
31
|
+
console.log(chalk.dim(' Get your key at: https://openrouter.ai/keys\n'));
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const db = await DatabaseClient.create(process.cwd());
|
|
36
|
+
const analyzer = createIntelligentAnalyzer(process.cwd());
|
|
37
|
+
|
|
38
|
+
spinner.start('Checking embeddings status...');
|
|
39
|
+
|
|
40
|
+
const rawDb = db.getRawDb();
|
|
41
|
+
|
|
42
|
+
// Check if embeddings table exists and has data
|
|
43
|
+
const tableExists = rawDb.prepare(`
|
|
44
|
+
SELECT name FROM sqlite_master WHERE type='table' AND name='embeddings'
|
|
45
|
+
`).get() as { name: string } | undefined;
|
|
46
|
+
|
|
47
|
+
let currentDimension = 0;
|
|
48
|
+
if (tableExists) {
|
|
49
|
+
const embedding = rawDb.prepare('SELECT embedding FROM embeddings LIMIT 1').get() as { embedding: Buffer } | undefined;
|
|
50
|
+
if (embedding) {
|
|
51
|
+
currentDimension = embedding.embedding.length / 4; // Float32Array
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const expectedDimension = 1536; // OpenRouter text-embedding-3-small
|
|
56
|
+
|
|
57
|
+
if (currentDimension > 0 && currentDimension !== expectedDimension && !options.force) {
|
|
58
|
+
spinner.fail('Embedding dimension mismatch');
|
|
59
|
+
console.log(chalk.red(` Current: ${currentDimension}, Expected: ${expectedDimension}`));
|
|
60
|
+
console.log(chalk.dim('\nUse --force to override (requires full re-index)\n'));
|
|
61
|
+
db.close();
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Get all items
|
|
66
|
+
spinner.text = 'Fetching items...';
|
|
67
|
+
const items = db.getAllItems();
|
|
68
|
+
|
|
69
|
+
if (items.length === 0) {
|
|
70
|
+
spinner.succeed('No items to index');
|
|
71
|
+
db.close();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
spinner.stop();
|
|
76
|
+
|
|
77
|
+
console.log('');
|
|
78
|
+
console.log(chalk.bold('Embeddings Refresh:'));
|
|
79
|
+
console.log(` Items to process: ${chalk.cyan(items.length.toString())}`);
|
|
80
|
+
console.log(` Batch size: ${chalk.cyan(options.batchSize)}`);
|
|
81
|
+
console.log('');
|
|
82
|
+
|
|
83
|
+
const confirmed = await confirm({
|
|
84
|
+
message: 'Refresh all embeddings?',
|
|
85
|
+
default: true
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (!confirmed) {
|
|
89
|
+
console.log(chalk.dim('\nRefresh cancelled.\n'));
|
|
90
|
+
db.close();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
spinner.start('Refreshing embeddings...');
|
|
95
|
+
|
|
96
|
+
// Process in batches
|
|
97
|
+
const batchSize = parseInt(options.batchSize, 10);
|
|
98
|
+
let processed = 0;
|
|
99
|
+
|
|
100
|
+
for (let i = 0; i < items.length; i += batchSize) {
|
|
101
|
+
const batch = items.slice(i, i + batchSize);
|
|
102
|
+
const batchNum = Math.floor(i / batchSize) + 1;
|
|
103
|
+
const totalBatches = Math.ceil(items.length / batchSize);
|
|
104
|
+
|
|
105
|
+
for (const item of batch) {
|
|
106
|
+
if (options.verbose) {
|
|
107
|
+
spinner.stop();
|
|
108
|
+
console.log(chalk.dim(` Embedding: ${item.name}`));
|
|
109
|
+
spinner.start();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Generate and store embedding
|
|
113
|
+
try {
|
|
114
|
+
const embedding = await analyzer.embedText(item.content);
|
|
115
|
+
db.storeEmbedding(item.id, embedding);
|
|
116
|
+
processed++;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if (options.verbose) {
|
|
119
|
+
console.log(chalk.yellow(` Warning: Failed to embed ${item.name}`));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
spinner.text = `Processing batch ${batchNum}/${totalBatches} (${processed}/${items.length})...`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
spinner.succeed(chalk.green(`Refreshed ${processed} embeddings`));
|
|
128
|
+
db.close();
|
|
129
|
+
|
|
130
|
+
} catch (error) {
|
|
131
|
+
spinner.fail('Embedding refresh failed');
|
|
132
|
+
console.error(chalk.red(`\nError: ${error instanceof Error ? error.message : error}`));
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
});
|