koneck 2.25.7 → 2.25.9

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.
@@ -0,0 +1,115 @@
1
+ import path from 'path';
2
+ /**
3
+ * The files and directories of a workspace, for the `@` reference picker.
4
+ *
5
+ * Ordering is the whole value here. A flat alphabetical list of every path buries `package.json`
6
+ * under a thousand entries from `dist/`, so entries are ranked by how close they are to the root
7
+ * and directories come first at each level — which is the order someone reaching for `@` is
8
+ * thinking in. What the repository already ignores is ignored here too, because a build output
9
+ * directory is not what anyone means to reference.
10
+ */
11
+ export async function listWorkspaceEntries(cwd, limit = 4000) {
12
+ const { globby } = await import('globby');
13
+ try {
14
+ const entries = await globby(['**/*'], {
15
+ cwd,
16
+ gitignore: true,
17
+ onlyFiles: false,
18
+ markDirectories: true,
19
+ dot: true,
20
+ followSymbolicLinks: false,
21
+ // Ignored even when untracked: these are never what an `@` reference means, and walking
22
+ // node_modules alone can take longer than the rest of the tree put together.
23
+ ignore: ['**/node_modules/**', '**/.git/**', '**/dist/**', '**/build/**', '**/.next/**'],
24
+ suppressErrors: true,
25
+ });
26
+ return rankEntries(entries).slice(0, limit);
27
+ }
28
+ catch {
29
+ return [];
30
+ }
31
+ }
32
+ /**
33
+ * Shallow before deep, directories before files, then alphabetical.
34
+ *
35
+ * Depth first because a reference is far more often to `src/engine.ts` than to something eight
36
+ * levels down, and a picker that has to be scrolled past the whole of `src/` to reach `README.md`
37
+ * is slower than typing the path by hand.
38
+ */
39
+ export function rankEntries(entries) {
40
+ return [...entries].sort((a, b) => {
41
+ const depthA = a.split('/').filter(Boolean).length;
42
+ const depthB = b.split('/').filter(Boolean).length;
43
+ if (depthA !== depthB)
44
+ return depthA - depthB;
45
+ const dirA = a.endsWith('/') ? 0 : 1;
46
+ const dirB = b.endsWith('/') ? 0 : 1;
47
+ if (dirA !== dirB)
48
+ return dirA - dirB;
49
+ return a.localeCompare(b);
50
+ });
51
+ }
52
+ /**
53
+ * Scores a path against what has been typed, or null when it does not match.
54
+ *
55
+ * Matching is a subsequence over the whole path, so `egt` finds `src/engine.ts`, but a hit in the
56
+ * file name beats one spread across directories — typing `chat` should offer `ink-chat.tsx` before
57
+ * `chat/old/notes.md`. Lower is better.
58
+ */
59
+ export function scoreEntry(entry, query) {
60
+ if (query === '')
61
+ return 0;
62
+ const hay = entry.toLowerCase();
63
+ const needle = query.toLowerCase();
64
+ const base = path.posix.basename(entry.replace(/\/$/, '')).toLowerCase();
65
+ const inBase = base.indexOf(needle);
66
+ if (inBase !== -1)
67
+ return inBase; // best: a literal hit in the name
68
+ const direct = hay.indexOf(needle);
69
+ if (direct !== -1)
70
+ return 100 + direct; // next: literal, but in the path
71
+ // Last: the characters appear in order somewhere. Spread is the penalty, so a tight run wins.
72
+ let i = 0, first = -1, last = -1;
73
+ for (let k = 0; k < hay.length && i < needle.length; k++) {
74
+ if (hay[k] === needle[i]) {
75
+ if (first === -1)
76
+ first = k;
77
+ last = k;
78
+ i++;
79
+ }
80
+ }
81
+ return i === needle.length ? 1000 + (last - first) : null;
82
+ }
83
+ /** The best matches for a query, in the order they should be offered. */
84
+ export function filterEntries(entries, query, limit = 200) {
85
+ if (query === '')
86
+ return entries.slice(0, limit);
87
+ const scored = [];
88
+ for (const entry of entries) {
89
+ const score = scoreEntry(entry, query);
90
+ if (score !== null)
91
+ scored.push({ entry, score });
92
+ }
93
+ scored.sort((a, b) => (a.score - b.score) || a.entry.length - b.entry.length);
94
+ return scored.slice(0, limit).map(s => s.entry);
95
+ }
96
+ /**
97
+ * Where an `@` reference being typed begins, or -1 if the caret is not in one.
98
+ *
99
+ * The `@` only opens a reference at a word boundary, so an email address or a decorator in pasted
100
+ * code does not trigger the picker. A space ends it, since paths shown here never contain one.
101
+ */
102
+ export function activeReference(draft, caret) {
103
+ const upto = draft.slice(0, caret);
104
+ const at = upto.lastIndexOf('@');
105
+ if (at === -1)
106
+ return null;
107
+ const before = at === 0 ? '' : upto[at - 1];
108
+ if (before !== '' && !/\s/.test(before))
109
+ return null;
110
+ const query = upto.slice(at + 1);
111
+ if (/\s/.test(query))
112
+ return null;
113
+ return { start: at, query };
114
+ }
115
+ //# sourceMappingURL=workspace-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace-files.js","sourceRoot":"","sources":["../src/workspace-files.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,GAAW,EAAE,KAAK,GAAG,IAAI;IAClE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,CAAC,MAAM,CAAC,EAAE;YACrC,GAAG;YACH,SAAS,EAAE,IAAI;YACf,SAAS,EAAE,KAAK;YAChB,eAAe,EAAE,IAAI;YACrB,GAAG,EAAE,IAAI;YACT,mBAAmB,EAAE,KAAK;YAC1B,wFAAwF;YACxF,6EAA6E;YAC7E,MAAM,EAAE,CAAC,oBAAoB,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,CAAC;YACxF,cAAc,EAAE,IAAI;SACrB,CAAC,CAAC;QACH,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,OAA0B;IACpD,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAChC,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;QACnD,MAAM,MAAM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CAAC,MAAM,CAAC,CAAC;IAC9E,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,KAAa;IAC1D,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACnC,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,EAAE,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3B,MAAM,MAAM,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAE,CAAC;IAC7C,IAAI,MAAM,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IACrD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACjC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAClC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AAC9B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koneck",
3
- "version": "2.25.7",
3
+ "version": "2.25.9",
4
4
  "description": "Kinetically Orchestrated Neural Execution Engine for Code",
5
5
  "type": "module",
6
6
  "bin": {
@@ -54,6 +54,7 @@
54
54
  "openai": "^4.67.0",
55
55
  "ora": "^8.1.0",
56
56
  "react": "^18.3.1",
57
+ "string-width": "^7.2.0",
57
58
  "ts-morph": "^24.0.0"
58
59
  },
59
60
  "devDependencies": {