@nusoft/nuos-build-catalogue 0.10.0 → 0.10.2
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/dist/cli.d.ts +13 -0
- package/dist/cli.js +491 -0
- package/dist/commands/create.d.ts +70 -0
- package/dist/commands/create.js +341 -0
- package/dist/commands/format.d.ts +19 -0
- package/dist/commands/format.js +89 -0
- package/dist/commands/handlers.d.ts +35 -0
- package/dist/commands/handlers.js +132 -0
- package/dist/commands/init.d.ts +41 -0
- package/dist/commands/init.js +289 -0
- package/dist/commands/prompt.d.ts +44 -0
- package/dist/commands/prompt.js +100 -0
- package/dist/commands/write.d.ts +39 -0
- package/dist/commands/write.js +247 -0
- package/dist/embedder/ollama.d.ts +54 -0
- package/dist/embedder/ollama.js +164 -0
- package/dist/embedder/openai.d.ts +21 -0
- package/dist/embedder/openai.js +56 -0
- package/dist/embedder/select.d.ts +9 -0
- package/dist/embedder/select.js +27 -0
- package/dist/embedder/stub.d.ts +15 -0
- package/dist/embedder/stub.js +40 -0
- package/dist/embedder/types.d.ts +21 -0
- package/dist/embedder/types.js +6 -0
- package/dist/embedder/vertex.d.ts +41 -0
- package/dist/embedder/vertex.js +94 -0
- package/dist/indexer/chunk.d.ts +20 -0
- package/dist/indexer/chunk.js +196 -0
- package/dist/indexer/crawl.d.ts +20 -0
- package/dist/indexer/crawl.js +66 -0
- package/dist/indexer/metadata.d.ts +21 -0
- package/dist/indexer/metadata.js +126 -0
- package/dist/indexer/upsert.d.ts +26 -0
- package/dist/indexer/upsert.js +152 -0
- package/dist/migrate/parsers.d.ts +17 -0
- package/dist/migrate/parsers.js +123 -0
- package/dist/migrate/run.d.ts +22 -0
- package/dist/migrate/run.js +142 -0
- package/dist/migrate/store.d.ts +20 -0
- package/dist/migrate/store.js +52 -0
- package/dist/migrate/types.d.ts +57 -0
- package/dist/migrate/types.js +13 -0
- package/dist/regenerate/check.d.ts +11 -0
- package/dist/regenerate/check.js +97 -0
- package/dist/regenerate/diff.d.ts +18 -0
- package/dist/regenerate/diff.js +38 -0
- package/dist/regenerate/types.d.ts +52 -0
- package/dist/regenerate/types.js +14 -0
- package/dist/runtime/ac-parse.d.ts +63 -0
- package/dist/runtime/ac-parse.js +196 -0
- package/dist/runtime/markdown-edit.d.ts +53 -0
- package/dist/runtime/markdown-edit.js +101 -0
- package/dist/runtime/markdown-render.d.ts +27 -0
- package/dist/runtime/markdown-render.js +209 -0
- package/dist/runtime/mis-adapter.d.ts +35 -0
- package/dist/runtime/mis-adapter.js +364 -0
- package/dist/runtime/runtime.d.ts +20 -0
- package/dist/runtime/runtime.js +39 -0
- package/dist/search/format.d.ts +6 -0
- package/dist/search/format.js +23 -0
- package/dist/search/query.d.ts +29 -0
- package/dist/search/query.js +71 -0
- package/dist/store/open.d.ts +14 -0
- package/dist/store/open.js +16 -0
- package/package.json +3 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output formatter — human-readable table or JSON.
|
|
3
|
+
*/
|
|
4
|
+
export function formatHumanReadable(hits) {
|
|
5
|
+
if (hits.length === 0)
|
|
6
|
+
return '(no results)';
|
|
7
|
+
return hits
|
|
8
|
+
.map((h, i) => {
|
|
9
|
+
const idTag = h.idInKind ? ` ${h.idInKind}` : '';
|
|
10
|
+
const status = h.status ? ` [${h.status}]` : '';
|
|
11
|
+
const heading = h.headings ? ` › ${h.headings}` : '';
|
|
12
|
+
const lines = h.startLine ? `:${h.startLine}-${h.endLine}` : '';
|
|
13
|
+
return [
|
|
14
|
+
`${(i + 1).toString().padStart(2)}. ${h.path}${lines}`,
|
|
15
|
+
` ${h.fileKind}${idTag}${status}${heading} (score ${h.score.toFixed(4)})`,
|
|
16
|
+
` ${h.snippet}`,
|
|
17
|
+
].join('\n');
|
|
18
|
+
})
|
|
19
|
+
.join('\n\n');
|
|
20
|
+
}
|
|
21
|
+
export function formatJson(hits) {
|
|
22
|
+
return JSON.stringify({ hits }, null, 2);
|
|
23
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search — embed the query, call NuVector.searchKnowledge, format results.
|
|
3
|
+
*/
|
|
4
|
+
import type { NuVector } from '@nusoft/nuvector';
|
|
5
|
+
import type { Embedder } from '../embedder/types.js';
|
|
6
|
+
export interface SearchOptions {
|
|
7
|
+
query: string;
|
|
8
|
+
limit?: number;
|
|
9
|
+
kind?: string;
|
|
10
|
+
status?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SearchHit {
|
|
13
|
+
chunkId: string;
|
|
14
|
+
path: string;
|
|
15
|
+
fileKind: string;
|
|
16
|
+
idInKind: string;
|
|
17
|
+
status: string;
|
|
18
|
+
date: string;
|
|
19
|
+
headings: string;
|
|
20
|
+
startLine: number;
|
|
21
|
+
endLine: number;
|
|
22
|
+
score: number;
|
|
23
|
+
snippet: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function runSearch(store: NuVector, embedder: Embedder, options: SearchOptions): Promise<{
|
|
26
|
+
hits: SearchHit[];
|
|
27
|
+
embedMs: number;
|
|
28
|
+
searchMs: number;
|
|
29
|
+
}>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search — embed the query, call NuVector.searchKnowledge, format results.
|
|
3
|
+
*/
|
|
4
|
+
import { TENANT } from '../store/open.js';
|
|
5
|
+
export async function runSearch(store, embedder, options) {
|
|
6
|
+
const limit = options.limit ?? 10;
|
|
7
|
+
const t1 = Date.now();
|
|
8
|
+
const [queryEmbedding] = await embedder.embed([options.query]);
|
|
9
|
+
const embedMs = Date.now() - t1;
|
|
10
|
+
const t2 = Date.now();
|
|
11
|
+
// Use retrieveContext (not searchKnowledge — that's the NuWiki four-layer
|
|
12
|
+
// entry point and only returns Layer 1 article summaries). For arbitrary
|
|
13
|
+
// document chunks like the catalogue indexer's, retrieveContext + kind
|
|
14
|
+
// filter is the correct method.
|
|
15
|
+
const result = await store.retrieveContext({
|
|
16
|
+
embedding: queryEmbedding,
|
|
17
|
+
tenant: TENANT,
|
|
18
|
+
topK: Math.max(limit * 3, 30),
|
|
19
|
+
filters: { kind: 'document_chunk' },
|
|
20
|
+
});
|
|
21
|
+
const searchMs = Date.now() - t2;
|
|
22
|
+
const items = (result?.items ?? []);
|
|
23
|
+
let hits = items.map((it) => {
|
|
24
|
+
const meta = it.metadata ?? {};
|
|
25
|
+
return {
|
|
26
|
+
chunkId: String(it.ref ?? ''),
|
|
27
|
+
path: String(meta.path ?? ''),
|
|
28
|
+
fileKind: String(meta.file_kind ?? ''),
|
|
29
|
+
idInKind: String(meta.id_in_kind ?? ''),
|
|
30
|
+
status: String(meta.status ?? ''),
|
|
31
|
+
date: String(meta.date ?? ''),
|
|
32
|
+
headings: String(meta.headings ?? ''),
|
|
33
|
+
startLine: Number(meta.start_line ?? 0),
|
|
34
|
+
endLine: Number(meta.end_line ?? 0),
|
|
35
|
+
score: Number(it.score ?? 0),
|
|
36
|
+
snippet: makeSnippet(String(it.text ?? it.summary ?? ''), options.query),
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
if (options.kind) {
|
|
40
|
+
hits = hits.filter((h) => h.fileKind === options.kind);
|
|
41
|
+
}
|
|
42
|
+
if (options.status) {
|
|
43
|
+
hits = hits.filter((h) => h.status.toLowerCase().includes(options.status.toLowerCase()));
|
|
44
|
+
}
|
|
45
|
+
return { hits: hits.slice(0, limit), embedMs, searchMs };
|
|
46
|
+
}
|
|
47
|
+
function makeSnippet(text, query) {
|
|
48
|
+
const flat = text.replace(/\s+/g, ' ').trim();
|
|
49
|
+
if (flat.length <= 200)
|
|
50
|
+
return flat;
|
|
51
|
+
const tokens = query
|
|
52
|
+
.toLowerCase()
|
|
53
|
+
.split(/\s+/u)
|
|
54
|
+
.filter((t) => t.length > 2);
|
|
55
|
+
let bestIdx = -1;
|
|
56
|
+
for (const tok of tokens) {
|
|
57
|
+
const idx = flat.toLowerCase().indexOf(tok);
|
|
58
|
+
if (idx >= 0) {
|
|
59
|
+
bestIdx = idx;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (bestIdx === -1) {
|
|
64
|
+
return flat.slice(0, 200) + '…';
|
|
65
|
+
}
|
|
66
|
+
const start = Math.max(0, bestIdx - 60);
|
|
67
|
+
const end = Math.min(flat.length, bestIdx + 140);
|
|
68
|
+
const prefix = start > 0 ? '…' : '';
|
|
69
|
+
const suffix = end < flat.length ? '…' : '';
|
|
70
|
+
return prefix + flat.slice(start, end) + suffix;
|
|
71
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NuVector store factory — opens the file-backed store at the configured
|
|
3
|
+
* location, creating it if missing. The verification gate (scripts/
|
|
4
|
+
* verify-persistence.ts) confirmed file-backed persistence works in
|
|
5
|
+
* @nusoft/nuvector@0.1.0; see WU 110 notes for the verdict and known
|
|
6
|
+
* API quirks.
|
|
7
|
+
*/
|
|
8
|
+
import { NuVector } from '@nusoft/nuvector';
|
|
9
|
+
export declare const TENANT = "nuos_build_catalogue";
|
|
10
|
+
export interface StoreConfig {
|
|
11
|
+
storagePath: string;
|
|
12
|
+
dimensions: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function openStore(config: StoreConfig): Promise<NuVector>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NuVector store factory — opens the file-backed store at the configured
|
|
3
|
+
* location, creating it if missing. The verification gate (scripts/
|
|
4
|
+
* verify-persistence.ts) confirmed file-backed persistence works in
|
|
5
|
+
* @nusoft/nuvector@0.1.0; see WU 110 notes for the verdict and known
|
|
6
|
+
* API quirks.
|
|
7
|
+
*/
|
|
8
|
+
import { NuVector } from '@nusoft/nuvector';
|
|
9
|
+
export const TENANT = 'nuos_build_catalogue';
|
|
10
|
+
export async function openStore(config) {
|
|
11
|
+
return NuVector.open({
|
|
12
|
+
storage: config.storagePath,
|
|
13
|
+
dimensions: config.dimensions,
|
|
14
|
+
tenant: TENANT,
|
|
15
|
+
});
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nusoft/nuos-build-catalogue",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "NuOS build-catalogue tooling: semantic search (WU 110) + migration runner that lifts markdown artefacts into JSON-backed workflow records (WU 111, Phase G).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"access": "restricted"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "tsc",
|
|
19
|
+
"build": "rm -rf dist && tsc && chmod +x dist/cli.js",
|
|
20
|
+
"prepublishOnly": "npm run build",
|
|
20
21
|
"verify-storage": "tsx scripts/verify-persistence.ts",
|
|
21
22
|
"test": "tsx --test tests/chunk.test.ts tests/metadata.test.ts tests/crawl.test.ts tests/migrate.test.ts tests/commands-read.test.ts tests/regenerate.test.ts tests/commands-write.test.ts tests/ac-parse.test.ts tests/create.test.ts tests/init.test.ts",
|
|
22
23
|
"typecheck": "tsc --noEmit",
|