@isparling/engram-cli 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/LICENSE +187 -0
- package/README.md +41 -0
- package/bin/engram +14 -0
- package/package.json +32 -0
- package/release/engram-release.ts +1493 -0
- package/src/atomicWrite.ts +80 -0
- package/src/candidate.ts +229 -0
- package/src/classify.ts +275 -0
- package/src/cli.ts +709 -0
- package/src/contentHash.ts +54 -0
- package/src/deepFreeze.ts +13 -0
- package/src/diff.ts +81 -0
- package/src/guardedRetrieval.ts +128 -0
- package/src/guardedRetrievalInternal.ts +321 -0
- package/src/knowledgeRecord.ts +256 -0
- package/src/knowledgeRetrieval.ts +564 -0
- package/src/knowledgeRollup.ts +479 -0
- package/src/knowledgeTransaction.ts +683 -0
- package/src/knowledgeTypes.ts +249 -0
- package/src/knowledgeValidation.ts +269 -0
- package/src/markdownRecord.ts +265 -0
- package/src/packLoader.ts +188 -0
- package/src/packTypes.ts +12 -0
- package/src/presentation.ts +673 -0
- package/src/qmdConfigGuard.ts +245 -0
- package/src/qmdRunner.ts +392 -0
- package/src/realPath.ts +47 -0
- package/src/spaceBinding.ts +37 -0
- package/src/spaceRegistry.ts +1139 -0
- package/src/submit.ts +228 -0
- package/src/symlinkGuard.ts +71 -0
- package/src/transactionLock.ts +188 -0
- package/src/types.ts +38 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// The minimal effective binding used by Markdown and qmd operations. The
|
|
2
|
+
// durable manifest/registry layer resolves this shape in spaceRegistry.ts;
|
|
3
|
+
// knowledge-facing CLI commands never accept these paths directly.
|
|
4
|
+
|
|
5
|
+
import { join, resolve, sep } from "node:path";
|
|
6
|
+
import { err, ok, type Result } from "./types.ts";
|
|
7
|
+
|
|
8
|
+
export type SpaceBinding = {
|
|
9
|
+
recordsRoot: string;
|
|
10
|
+
qmdConfigDir: string;
|
|
11
|
+
qmdCacheHome: string;
|
|
12
|
+
qmdCollectionName: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const RECORD_ID_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Resolves a candidate's target_id to an absolute file path inside the
|
|
19
|
+
* bound records root. Rejects anything that is not a bare kebab-case id
|
|
20
|
+
* (no path separators, no "..") and, as defense in depth, rejects any
|
|
21
|
+
* resolved path that does not stay under the bound root.
|
|
22
|
+
*/
|
|
23
|
+
export function resolveRecordPath(binding: SpaceBinding, recordId: string): Result<string> {
|
|
24
|
+
if (!RECORD_ID_PATTERN.test(recordId)) {
|
|
25
|
+
return err([`invalid record id: ${JSON.stringify(recordId)} (must match ${RECORD_ID_PATTERN})`]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const candidatePath = join(binding.recordsRoot, `${recordId}.md`);
|
|
29
|
+
const resolvedRoot = resolve(binding.recordsRoot) + sep;
|
|
30
|
+
const resolvedPath = resolve(candidatePath);
|
|
31
|
+
|
|
32
|
+
if (!resolvedPath.startsWith(resolvedRoot)) {
|
|
33
|
+
return err([`record id resolves outside the bound records root: ${JSON.stringify(recordId)}`]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return ok(resolvedPath);
|
|
37
|
+
}
|