@agentproto/corpus 0.1.0-alpha.1 → 0.1.0-alpha.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/chunk-3P23OX5X.mjs +93 -0
- package/dist/chunk-3P23OX5X.mjs.map +1 -0
- package/dist/fs.port-BHzctsoT.d.ts +60 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +3 -82
- package/dist/index.mjs.map +1 -1
- package/dist/ports/index.d.ts +3 -60
- package/dist/report/index.d.ts +526 -0
- package/dist/report/index.mjs +633 -0
- package/dist/report/index.mjs.map +1 -0
- package/package.json +10 -5
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import matter from 'gray-matter';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @agentproto/corpus v0.1.0-alpha
|
|
6
|
+
* Composition of AIP-10/12/18/9/15/41 — autonomous knowledge-improvement kit.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var REFINED_KIND_SCHEMA = z.enum([
|
|
10
|
+
"principle",
|
|
11
|
+
"pattern",
|
|
12
|
+
"critique",
|
|
13
|
+
"summary",
|
|
14
|
+
"example"
|
|
15
|
+
]);
|
|
16
|
+
function isRefinedKind(value) {
|
|
17
|
+
return REFINED_KIND_SCHEMA.safeParse(value).success;
|
|
18
|
+
}
|
|
19
|
+
var ENTRY_FRONTMATTER = z.object({
|
|
20
|
+
schema: z.string().optional().catch(void 0),
|
|
21
|
+
slug: z.string().optional().catch(void 0),
|
|
22
|
+
kind: z.string().optional().catch(void 0),
|
|
23
|
+
title: z.string().optional().catch(void 0),
|
|
24
|
+
sources: z.array(z.string()).optional().catch(void 0),
|
|
25
|
+
confidence: z.number().optional().catch(void 0),
|
|
26
|
+
tags: z.array(z.string()).optional().catch(void 0),
|
|
27
|
+
metadata: z.object({
|
|
28
|
+
corpus: z.object({
|
|
29
|
+
access: z.string().optional().catch(void 0),
|
|
30
|
+
status: z.string().optional().catch(void 0),
|
|
31
|
+
// Resolved provenance written at promote time — the origins this
|
|
32
|
+
// entry was distilled from, so a recall can cite the real source.
|
|
33
|
+
source_refs: z.array(
|
|
34
|
+
z.object({
|
|
35
|
+
id: z.string(),
|
|
36
|
+
url: z.string().optional().catch(void 0),
|
|
37
|
+
title: z.string().optional().catch(void 0),
|
|
38
|
+
authority: z.string().optional().catch(void 0),
|
|
39
|
+
language: z.string().optional().catch(void 0)
|
|
40
|
+
}).loose()
|
|
41
|
+
).optional().catch(void 0)
|
|
42
|
+
}).loose().optional().catch(void 0)
|
|
43
|
+
}).loose().optional().catch(void 0)
|
|
44
|
+
}).loose();
|
|
45
|
+
async function resolveKnowledge(opts) {
|
|
46
|
+
const { fs, query, allowedAccess } = opts;
|
|
47
|
+
const wantTags = new Set((query.tags ?? []).map((t) => t.toLowerCase()));
|
|
48
|
+
const wantKinds = query.kinds ? new Set(query.kinds) : null;
|
|
49
|
+
let rels;
|
|
50
|
+
try {
|
|
51
|
+
rels = await fs.walk("entries");
|
|
52
|
+
} catch {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
const hits = [];
|
|
56
|
+
for (const rel of rels) {
|
|
57
|
+
if (!rel.endsWith(".md")) continue;
|
|
58
|
+
const path = `entries/${rel}`;
|
|
59
|
+
let parsed;
|
|
60
|
+
try {
|
|
61
|
+
parsed = matter(await fs.readFile(path));
|
|
62
|
+
} catch {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const fm = ENTRY_FRONTMATTER.parse(parsed.data);
|
|
66
|
+
if (fm.schema !== "knowledge.entry/v1") continue;
|
|
67
|
+
if (fm.metadata?.corpus?.status === "archived") continue;
|
|
68
|
+
const kind = fm.kind ?? "";
|
|
69
|
+
if (wantKinds && !(isRefinedKind(kind) && wantKinds.has(kind))) continue;
|
|
70
|
+
const tags = fm.tags ?? [];
|
|
71
|
+
if (wantTags.size > 0 && !tags.some((t) => wantTags.has(t.toLowerCase()))) continue;
|
|
72
|
+
const access = fm.metadata?.corpus?.access;
|
|
73
|
+
if (allowedAccess && access && !allowedAccess.has(access)) continue;
|
|
74
|
+
hits.push({
|
|
75
|
+
slug: fm.slug ?? path,
|
|
76
|
+
kind,
|
|
77
|
+
title: fm.title ?? "",
|
|
78
|
+
body: parsed.content.trim(),
|
|
79
|
+
sources: fm.sources ?? [],
|
|
80
|
+
...fm.metadata?.corpus?.source_refs ? { sourceRefs: fm.metadata.corpus.source_refs } : {},
|
|
81
|
+
confidence: fm.confidence ?? 0,
|
|
82
|
+
tags,
|
|
83
|
+
...access ? { access } : {},
|
|
84
|
+
path
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
hits.sort((a, b) => b.confidence - a.confidence);
|
|
88
|
+
return query.maxResults !== void 0 ? hits.slice(0, query.maxResults) : hits;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { REFINED_KIND_SCHEMA, isRefinedKind, resolveKnowledge };
|
|
92
|
+
//# sourceMappingURL=chunk-3P23OX5X.mjs.map
|
|
93
|
+
//# sourceMappingURL=chunk-3P23OX5X.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/distill/types.ts","../src/knowledge/resolve.ts"],"names":["z"],"mappings":";;;;;;;;AAgBO,IAAM,mBAAA,GAAsB,EAAE,IAAA,CAAK;AAAA,EACxC,WAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA;AACF,CAAC;AAKM,SAAS,cAAc,KAAA,EAAsC;AAClE,EAAA,OAAO,mBAAA,CAAoB,SAAA,CAAU,KAAK,CAAA,CAAE,OAAA;AAC9C;ACNA,IAAM,iBAAA,GAAoBA,EACvB,MAAA,CAAO;AAAA,EACN,QAAQA,CAAAA,CAAE,MAAA,GAAS,QAAA,EAAS,CAAE,MAAM,MAAS,CAAA;AAAA,EAC7C,MAAMA,CAAAA,CAAE,MAAA,GAAS,QAAA,EAAS,CA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ACH;AAEA,EAAA,IAAA,CAAK,KAAK,CAAC,CAAA,EAAG,MAAM,CAAA,CAAE,UAAA,GAAa,EAAE,UAAU,CAAA;AAC/C,EAAA,OAAO,KAAA,CAAM,eAAe,MAAA,GAAY,IAAA,CAAK,MAAM,CAAA,EAAG,KAAA,CAAM,UAAU,CAAA,GAAI,IAAA;AAC5E","file":"chunk-3P23OX5X.mjs","sourcesContent":["/**\n * Distill — raw source → refined knowledge entries (the KNOWLEDGE layer).\n *\n * The \"simple mode\": no graph engine. A refined entry is just an AIP-10\n * `knowledge.entry/v1` markdown file whose `sources: [<id>]` frontmatter\n * IS the `derivedFrom` provenance edge. The filesystem refs ARE the graph;\n * a graph engine (mind-graph / gbrain) is an optional index added later.\n *\n * The kit owns the contract + the runner (what to write, where, with what\n * provenance). The LLM that actually extracts insights is an injected\n * `DistillPort` — host-supplied (Claude/OpenAI), so the kit stays pure.\n */\n\nimport { z } from \"zod\"\n\n/** Generic AIP-10 refined kinds — NOT domain-specific. */\nexport const REFINED_KIND_SCHEMA = z.enum([\n \"principle\",\n \"pattern\",\n \"critique\",\n \"summary\",\n \"example\",\n])\n\nexport type RefinedKind = z.infer<typeof REFINED_KIND_SCHEMA>\n\n/** Runtime guard — narrows an untyped value to RefinedKind without a cast. */\nexport function isRefinedKind(value: unknown): value is RefinedKind {\n return REFINED_KIND_SCHEMA.safeParse(value).success\n}\n\nexport interface DistilledItem {\n readonly kind: RefinedKind\n readonly title: string\n /** The refined insight, markdown. Self-contained, not a quote dump. */\n readonly body: string\n /** 0–1 model confidence. */\n readonly confidence?: number\n readonly tags?: readonly string[]\n}\n\nexport interface DistillInput {\n readonly title: string\n readonly body: string\n readonly tags?: readonly string[]\n /** Hint for the kinds worth extracting (e.g. only principles). */\n readonly kinds?: readonly RefinedKind[]\n}\n\n/**\n * The LLM boundary. Given a raw source, return refined items. Injected by\n * the host (corpus-cli `AnthropicDistiller`, a Guilde operator, …) so the\n * kit takes no model dependency.\n */\nexport interface DistillPort {\n distill(input: DistillInput): Promise<readonly DistilledItem[]>\n}\n","/**\n * resolveKnowledge — the `knowledge:` binding resolver (KNOWLEDGE→SKILL link).\n *\n * Filesystem-first: a skill's binding (`{ tags, kinds }`) is resolved against\n * the refined `entries/**/*.md` on disk — no graph engine. Returns the\n * matching refined entries (with their `sources:` provenance), filtered by the\n * caller's access scope so an operator never sees knowledge above its clearance.\n *\n * A graph engine (mind-graph / gbrain) can later replace this scan with\n * traversal/activation behind the SAME signature — the binding contract is stable.\n */\n\nimport matter from \"gray-matter\"\nimport { z } from \"zod\"\nimport type { FsPort } from \"../ports/fs.port.js\"\nimport { isRefinedKind, type RefinedKind } from \"../distill/types.js\"\n\n/**\n * Lenient zod view of an AIP-10 entry's frontmatter. Every field `.catch`es to\n * undefined so a malformed value degrades gracefully (the entry is still\n * parsed, the bad field is simply absent) — matching the previous defensive\n * hand-narrowing, but typed and cast-free.\n */\nconst ENTRY_FRONTMATTER = z\n .object({\n schema: z.string().optional().catch(undefined),\n slug: z.string().optional().catch(undefined),\n kind: z.string().optional().catch(undefined),\n title: z.string().optional().catch(undefined),\n sources: z.array(z.string()).optional().catch(undefined),\n confidence: z.number().optional().catch(undefined),\n tags: z.array(z.string()).optional().catch(undefined),\n metadata: z\n .object({\n corpus: z\n .object({\n access: z.string().optional().catch(undefined),\n status: z.string().optional().catch(undefined),\n // Resolved provenance written at promote time — the origins this\n // entry was distilled from, so a recall can cite the real source.\n source_refs: z\n .array(\n z\n .object({\n id: z.string(),\n url: z.string().optional().catch(undefined),\n title: z.string().optional().catch(undefined),\n authority: z.string().optional().catch(undefined),\n language: z.string().optional().catch(undefined),\n })\n .loose()\n )\n .optional()\n .catch(undefined),\n })\n .loose()\n .optional()\n .catch(undefined),\n })\n .loose()\n .optional()\n .catch(undefined),\n })\n .loose()\n\nexport interface CorpusEntryQuery {\n /** Match entries sharing ANY of these tags. Empty/absent = no tag filter. */\n readonly tags?: readonly string[]\n /** Restrict to these refined kinds. Empty/absent = all kinds. */\n readonly kinds?: readonly RefinedKind[]\n /** Cap results (highest-confidence first). */\n readonly maxResults?: number\n}\n\n/** A resolved origin an entry was distilled from (id + where to find it). */\nexport interface SourceRef {\n readonly id: string\n readonly url?: string\n readonly title?: string\n readonly authority?: string\n readonly language?: string\n}\n\nexport interface ResolvedEntry {\n readonly slug: string\n readonly kind: string\n readonly title: string\n readonly body: string\n /** Provenance — the raw source ids this entry was derived from. */\n readonly sources: readonly string[]\n /** Resolved provenance — id + url + title for each source, when available. */\n readonly sourceRefs?: readonly SourceRef[]\n readonly confidence: number\n readonly tags: readonly string[]\n readonly access?: string\n readonly path: string\n}\n\nexport interface ResolveKnowledgeOptions {\n readonly fs: FsPort\n readonly query: CorpusEntryQuery\n /**\n * Access scopes the caller (operator) is cleared for. An entry passes if it\n * has no access (public) or its access ∈ this set. Omit = no access filter.\n */\n readonly allowedAccess?: ReadonlySet<string>\n}\n\nexport async function resolveKnowledge(\n opts: ResolveKnowledgeOptions\n): Promise<readonly ResolvedEntry[]> {\n const { fs, query, allowedAccess } = opts\n const wantTags = new Set((query.tags ?? []).map(t => t.toLowerCase()))\n const wantKinds = query.kinds ? new Set(query.kinds) : null\n\n let rels: readonly string[]\n try {\n rels = await fs.walk(\"entries\")\n } catch {\n return []\n }\n\n const hits: ResolvedEntry[] = []\n for (const rel of rels) {\n if (!rel.endsWith(\".md\")) continue\n // `walk(\"entries\")` yields paths relative to the entries/ dir; readFile\n // resolves against the workspace root, so re-prefix.\n const path = `entries/${rel}`\n let parsed\n try {\n parsed = matter(await fs.readFile(path))\n } catch {\n continue\n }\n const fm = ENTRY_FRONTMATTER.parse(parsed.data)\n if (fm.schema !== \"knowledge.entry/v1\") continue\n\n // Tombstone: a guild disables a pack entry by shadowing it (same path) with\n // status \"archived\". Filtered here so the overlaid archived entry hides the\n // pack's. Absent/active = shown — only an explicit archive subtracts.\n if (fm.metadata?.corpus?.status === \"archived\") continue\n\n const kind = fm.kind ?? \"\"\n if (wantKinds && !(isRefinedKind(kind) && wantKinds.has(kind))) continue\n\n const tags = fm.tags ?? []\n if (wantTags.size > 0 && !tags.some(t => wantTags.has(t.toLowerCase()))) continue\n\n const access = fm.metadata?.corpus?.access\n if (allowedAccess && access && !allowedAccess.has(access)) continue\n\n hits.push({\n slug: fm.slug ?? path,\n kind,\n title: fm.title ?? \"\",\n body: parsed.content.trim(),\n sources: fm.sources ?? [],\n ...(fm.metadata?.corpus?.source_refs\n ? { sourceRefs: fm.metadata.corpus.source_refs }\n : {}),\n confidence: fm.confidence ?? 0,\n tags,\n ...(access ? { access } : {}),\n path,\n })\n }\n\n hits.sort((a, b) => b.confidence - a.confidence)\n return query.maxResults !== undefined ? hits.slice(0, query.maxResults) : hits\n}\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FsPort — filesystem boundary the corpus kit consumes.
|
|
3
|
+
*
|
|
4
|
+
* Structural interface, NOT a nominal one — any object exposing this
|
|
5
|
+
* shape satisfies it. Matches the existing Guilde `WorkspaceFsLike`
|
|
6
|
+
* convention (projects/guilde/packages/core/src/services/role-source/
|
|
7
|
+
* workspace.ts:38-47) so cloud and local topologies share the same
|
|
8
|
+
* minimal contract.
|
|
9
|
+
*
|
|
10
|
+
* Paths are relative to the workspace root (no leading slash). The
|
|
11
|
+
* concrete implementation (MastraFilesystem in cloud, local-fs in CLI,
|
|
12
|
+
* mcp-filesystem for hybrid topologies) does the resolution.
|
|
13
|
+
*/
|
|
14
|
+
interface FsStat {
|
|
15
|
+
readonly kind: "file" | "directory";
|
|
16
|
+
readonly bytes?: number;
|
|
17
|
+
readonly modifiedAt?: Date;
|
|
18
|
+
}
|
|
19
|
+
interface FsPort {
|
|
20
|
+
/** True if a file or directory exists at `path`. */
|
|
21
|
+
exists(path: string): Promise<boolean>;
|
|
22
|
+
/** Read a file as UTF-8 text. Throws on missing path. */
|
|
23
|
+
readFile(path: string): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Write a file atomically — caller assumes content is persisted on
|
|
26
|
+
* resolve. Implementations are expected to write to a temp file +
|
|
27
|
+
* rename so partial writes never become visible.
|
|
28
|
+
*/
|
|
29
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Append to a file. MUST be atomic against concurrent appends to the
|
|
32
|
+
* same path — used by the event emitter for _log.md. If the file
|
|
33
|
+
* does not exist, create it.
|
|
34
|
+
*/
|
|
35
|
+
appendFile(path: string, content: string): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* List immediate children of a directory. Returns names only (NOT
|
|
38
|
+
* full paths). Throws if `path` is not a directory.
|
|
39
|
+
*/
|
|
40
|
+
readdir(path: string): Promise<readonly string[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Recursive directory listing — returns workspace-relative paths of
|
|
43
|
+
* every file under `path`. Skips directories starting with `.`.
|
|
44
|
+
*/
|
|
45
|
+
walk(path: string): Promise<readonly string[]>;
|
|
46
|
+
/** File metadata. Returns null if the path doesn't exist. */
|
|
47
|
+
stat(path: string): Promise<FsStat | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Acquire a cross-process advisory lock on `path`. Used by the
|
|
50
|
+
* writer for atomic multi-file transactions (entry write + _index
|
|
51
|
+
* regen + _log append). Implementations MAY no-op for single-process
|
|
52
|
+
* topologies (local CLI), but cloud hosts MUST enforce real locking.
|
|
53
|
+
*/
|
|
54
|
+
lock(path: string): Promise<FsLockHandle>;
|
|
55
|
+
}
|
|
56
|
+
interface FsLockHandle {
|
|
57
|
+
release(): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type { FsPort as F, FsStat as a, FsLockHandle as b };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClockPort, IdentityPort, FetcherPort, EvalRubricPort, EvalContextPort, EvaluatorPort } from './ports/index.js';
|
|
2
2
|
export { CallerIdentity, EvalInputPort, EvalResultPort, FetchedSource, FetchedSourceKind, systemClock } from './ports/index.js';
|
|
3
|
+
import { F as FsPort, a as FsStat, b as FsLockHandle } from './fs.port-BHzctsoT.js';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
import { Registry } from '@agentproto/registry';
|
|
5
6
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { systemClock } from './chunk-KYX2DTEH.mjs';
|
|
2
|
+
import { REFINED_KIND_SCHEMA, resolveKnowledge } from './chunk-3P23OX5X.mjs';
|
|
3
|
+
export { REFINED_KIND_SCHEMA, isRefinedKind, resolveKnowledge } from './chunk-3P23OX5X.mjs';
|
|
2
4
|
import { CandidatesSidecar } from './chunk-UPX26MYH.mjs';
|
|
3
5
|
export { CandidatesSidecar, SidecarDuplicateError, SidecarNotFoundError } from './chunk-UPX26MYH.mjs';
|
|
4
6
|
import matter from 'gray-matter';
|
|
@@ -1054,16 +1056,6 @@ function sanitizeTag(raw) {
|
|
|
1054
1056
|
const t = raw.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").replace(/-{2,}/g, "-");
|
|
1055
1057
|
return /^[a-z][a-z0-9-]*$/.test(t) ? t : null;
|
|
1056
1058
|
}
|
|
1057
|
-
var REFINED_KIND_SCHEMA = z.enum([
|
|
1058
|
-
"principle",
|
|
1059
|
-
"pattern",
|
|
1060
|
-
"critique",
|
|
1061
|
-
"summary",
|
|
1062
|
-
"example"
|
|
1063
|
-
]);
|
|
1064
|
-
function isRefinedKind(value) {
|
|
1065
|
-
return REFINED_KIND_SCHEMA.safeParse(value).success;
|
|
1066
|
-
}
|
|
1067
1059
|
var DISTILLED_ITEM = z.object({
|
|
1068
1060
|
kind: REFINED_KIND_SCHEMA,
|
|
1069
1061
|
title: z.string(),
|
|
@@ -1282,77 +1274,6 @@ async function enumerateWindowRefs(source, distilled) {
|
|
|
1282
1274
|
}
|
|
1283
1275
|
return refs;
|
|
1284
1276
|
}
|
|
1285
|
-
var ENTRY_FRONTMATTER = z.object({
|
|
1286
|
-
schema: z.string().optional().catch(void 0),
|
|
1287
|
-
slug: z.string().optional().catch(void 0),
|
|
1288
|
-
kind: z.string().optional().catch(void 0),
|
|
1289
|
-
title: z.string().optional().catch(void 0),
|
|
1290
|
-
sources: z.array(z.string()).optional().catch(void 0),
|
|
1291
|
-
confidence: z.number().optional().catch(void 0),
|
|
1292
|
-
tags: z.array(z.string()).optional().catch(void 0),
|
|
1293
|
-
metadata: z.object({
|
|
1294
|
-
corpus: z.object({
|
|
1295
|
-
access: z.string().optional().catch(void 0),
|
|
1296
|
-
status: z.string().optional().catch(void 0),
|
|
1297
|
-
// Resolved provenance written at promote time — the origins this
|
|
1298
|
-
// entry was distilled from, so a recall can cite the real source.
|
|
1299
|
-
source_refs: z.array(
|
|
1300
|
-
z.object({
|
|
1301
|
-
id: z.string(),
|
|
1302
|
-
url: z.string().optional().catch(void 0),
|
|
1303
|
-
title: z.string().optional().catch(void 0),
|
|
1304
|
-
authority: z.string().optional().catch(void 0),
|
|
1305
|
-
language: z.string().optional().catch(void 0)
|
|
1306
|
-
}).loose()
|
|
1307
|
-
).optional().catch(void 0)
|
|
1308
|
-
}).loose().optional().catch(void 0)
|
|
1309
|
-
}).loose().optional().catch(void 0)
|
|
1310
|
-
}).loose();
|
|
1311
|
-
async function resolveKnowledge(opts) {
|
|
1312
|
-
const { fs, query, allowedAccess } = opts;
|
|
1313
|
-
const wantTags = new Set((query.tags ?? []).map((t) => t.toLowerCase()));
|
|
1314
|
-
const wantKinds = query.kinds ? new Set(query.kinds) : null;
|
|
1315
|
-
let rels;
|
|
1316
|
-
try {
|
|
1317
|
-
rels = await fs.walk("entries");
|
|
1318
|
-
} catch {
|
|
1319
|
-
return [];
|
|
1320
|
-
}
|
|
1321
|
-
const hits = [];
|
|
1322
|
-
for (const rel of rels) {
|
|
1323
|
-
if (!rel.endsWith(".md")) continue;
|
|
1324
|
-
const path = `entries/${rel}`;
|
|
1325
|
-
let parsed;
|
|
1326
|
-
try {
|
|
1327
|
-
parsed = matter(await fs.readFile(path));
|
|
1328
|
-
} catch {
|
|
1329
|
-
continue;
|
|
1330
|
-
}
|
|
1331
|
-
const fm = ENTRY_FRONTMATTER.parse(parsed.data);
|
|
1332
|
-
if (fm.schema !== "knowledge.entry/v1") continue;
|
|
1333
|
-
if (fm.metadata?.corpus?.status === "archived") continue;
|
|
1334
|
-
const kind = fm.kind ?? "";
|
|
1335
|
-
if (wantKinds && !(isRefinedKind(kind) && wantKinds.has(kind))) continue;
|
|
1336
|
-
const tags = fm.tags ?? [];
|
|
1337
|
-
if (wantTags.size > 0 && !tags.some((t) => wantTags.has(t.toLowerCase()))) continue;
|
|
1338
|
-
const access = fm.metadata?.corpus?.access;
|
|
1339
|
-
if (allowedAccess && access && !allowedAccess.has(access)) continue;
|
|
1340
|
-
hits.push({
|
|
1341
|
-
slug: fm.slug ?? path,
|
|
1342
|
-
kind,
|
|
1343
|
-
title: fm.title ?? "",
|
|
1344
|
-
body: parsed.content.trim(),
|
|
1345
|
-
sources: fm.sources ?? [],
|
|
1346
|
-
...fm.metadata?.corpus?.source_refs ? { sourceRefs: fm.metadata.corpus.source_refs } : {},
|
|
1347
|
-
confidence: fm.confidence ?? 0,
|
|
1348
|
-
tags,
|
|
1349
|
-
...access ? { access } : {},
|
|
1350
|
-
path
|
|
1351
|
-
});
|
|
1352
|
-
}
|
|
1353
|
-
hits.sort((a, b) => b.confidence - a.confidence);
|
|
1354
|
-
return query.maxResults !== void 0 ? hits.slice(0, query.maxResults) : hits;
|
|
1355
|
-
}
|
|
1356
1277
|
|
|
1357
1278
|
// src/knowledge/overlay-fs.ts
|
|
1358
1279
|
var WHITEOUT_SUFFIX = ".whiteout";
|
|
@@ -3375,6 +3296,6 @@ function joinPath5(a, b) {
|
|
|
3375
3296
|
var SPEC_NAME = "agentcorpus/v1";
|
|
3376
3297
|
var SPEC_VERSION = "0.1.0-alpha";
|
|
3377
3298
|
|
|
3378
|
-
export { ANY_REF, ClaudeDistiller, ConversationImporter, CorpusEventEmitter, CorpusIndexer, CorpusLinter, CorpusPromoter, CorpusValidator, CorpusVersionConflictError, CorpusWorkspaceReader, CorpusWorkspaceWriter, DEFAULT_TRANSITIONS, DistillRunner, EMPTY_SELECTOR, IllegalPlaybookTransitionError, IllegalTransitionError, ImporterRunner, KbMigrationImporter, LocalFilesImporter, MemFs, OperatorOverlayResolver, OverlayFs, PlaybookEvaluator, PlaybookLifecycle, PlaybookNotFoundError, PlaybookRegistry, PromoteRejectedError,
|
|
3299
|
+
export { ANY_REF, ClaudeDistiller, ConversationImporter, CorpusEventEmitter, CorpusIndexer, CorpusLinter, CorpusPromoter, CorpusValidator, CorpusVersionConflictError, CorpusWorkspaceReader, CorpusWorkspaceWriter, DEFAULT_TRANSITIONS, DistillRunner, EMPTY_SELECTOR, IllegalPlaybookTransitionError, IllegalTransitionError, ImporterRunner, KbMigrationImporter, LocalFilesImporter, MemFs, OperatorOverlayResolver, OverlayFs, PlaybookEvaluator, PlaybookLifecycle, PlaybookNotFoundError, PlaybookRegistry, PromoteRejectedError, ReadOnlyFs, ReviewerTrackRecord, SPEC_NAME, SPEC_VERSION, StackResolver, SyncRunner, WELL_KNOWN_AXES, WHITEOUT_SUFFIX, WebImporter, aggregateReviewerScores, appendAttestation, assertTransition, buildDistillPrompt, buildOverlayFromStack, canTransition, capabilityAxis, chunkText, compileLegacyPlaybookBinding, computeReviewerCalibration, createAxisRegistry, createDistillRegistry, enumerateWindowRefs, evaluateAccess, evaluateCapability, evaluateGate, extractAutoPromoteConfig, flattenPackRefs, identityAxis, isEmptySelector, isEntrySlug, isSourceSlug, makeAttestation, matchAttachmentRefs, matchAttachments, matchesLanguageFilter, matchesSelector, normalizeLanguageTag, parseItems, parseSelectorFrontmatter, parseWindowRef, partitionStackRefs, pearsonCorrelation, positionAxis, prefixedRefNormalizer, readAccessModes, readAccessSpec, readAttestations, readEntryLanguage, readOperatorLocale, readWorkspaceDefaultLanguage, renderOverlays, resolveLanguageFilter, roleAxis, runDistill, scanDistilledSourceIds, slugify, transitionGraphFromCollection, uniqueSlug, windowRef, windowSlug };
|
|
3379
3300
|
//# sourceMappingURL=index.mjs.map
|
|
3380
3301
|
//# sourceMappingURL=index.mjs.map
|