@oscharko-dev/keiko-contracts 0.2.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/dist/.tsbuildinfo +1 -0
- package/dist/bff-wire.d.ts +661 -0
- package/dist/bff-wire.d.ts.map +1 -0
- package/dist/bff-wire.js +102 -0
- package/dist/bug-investigation-events.d.ts +92 -0
- package/dist/bug-investigation-events.d.ts.map +1 -0
- package/dist/bug-investigation-events.js +18 -0
- package/dist/coding-context.d.ts +76 -0
- package/dist/coding-context.d.ts.map +1 -0
- package/dist/coding-context.js +158 -0
- package/dist/connected-context.d.ts +174 -0
- package/dist/connected-context.d.ts.map +1 -0
- package/dist/connected-context.js +636 -0
- package/dist/conversation-budget.d.ts +37 -0
- package/dist/conversation-budget.d.ts.map +1 -0
- package/dist/conversation-budget.js +97 -0
- package/dist/editor-agent.d.ts +131 -0
- package/dist/editor-agent.d.ts.map +1 -0
- package/dist/editor-agent.js +197 -0
- package/dist/editor-completion.d.ts +62 -0
- package/dist/editor-completion.d.ts.map +1 -0
- package/dist/editor-completion.js +147 -0
- package/dist/editor-dirty-close.d.ts +17 -0
- package/dist/editor-dirty-close.d.ts.map +1 -0
- package/dist/editor-dirty-close.js +8 -0
- package/dist/editor-hot-exit.d.ts +18 -0
- package/dist/editor-hot-exit.d.ts.map +1 -0
- package/dist/editor-hot-exit.js +42 -0
- package/dist/editor-inline-completion.d.ts +70 -0
- package/dist/editor-inline-completion.d.ts.map +1 -0
- package/dist/editor-inline-completion.js +215 -0
- package/dist/editor-layout.d.ts +105 -0
- package/dist/editor-layout.d.ts.map +1 -0
- package/dist/editor-layout.js +479 -0
- package/dist/editor-patch-apply.d.ts +77 -0
- package/dist/editor-patch-apply.d.ts.map +1 -0
- package/dist/editor-patch-apply.js +122 -0
- package/dist/editor-session.d.ts +31 -0
- package/dist/editor-session.d.ts.map +1 -0
- package/dist/editor-session.js +75 -0
- package/dist/editor-test-generation.d.ts +104 -0
- package/dist/editor-test-generation.d.ts.map +1 -0
- package/dist/editor-test-generation.js +211 -0
- package/dist/evaluations.d.ts +75 -0
- package/dist/evaluations.d.ts.map +1 -0
- package/dist/evaluations.js +16 -0
- package/dist/evidence.d.ts +297 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +9 -0
- package/dist/gateway.d.ts +129 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +66 -0
- package/dist/harness.d.ts +274 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/harness.js +38 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +83 -0
- package/dist/language-service.d.ts +145 -0
- package/dist/language-service.d.ts.map +1 -0
- package/dist/language-service.js +161 -0
- package/dist/local-knowledge-large-document-validation.d.ts +7 -0
- package/dist/local-knowledge-large-document-validation.d.ts.map +1 -0
- package/dist/local-knowledge-large-document-validation.js +161 -0
- package/dist/local-knowledge-large-document.d.ts +113 -0
- package/dist/local-knowledge-large-document.d.ts.map +1 -0
- package/dist/local-knowledge-large-document.js +142 -0
- package/dist/local-knowledge-paths.d.ts +3 -0
- package/dist/local-knowledge-paths.d.ts.map +1 -0
- package/dist/local-knowledge-paths.js +65 -0
- package/dist/local-knowledge-records.d.ts +190 -0
- package/dist/local-knowledge-records.d.ts.map +1 -0
- package/dist/local-knowledge-records.js +36 -0
- package/dist/local-knowledge-schema-validation.d.ts +19 -0
- package/dist/local-knowledge-schema-validation.d.ts.map +1 -0
- package/dist/local-knowledge-schema-validation.js +115 -0
- package/dist/local-knowledge-schema.d.ts +14 -0
- package/dist/local-knowledge-schema.d.ts.map +1 -0
- package/dist/local-knowledge-schema.js +715 -0
- package/dist/local-knowledge-validation.d.ts +20 -0
- package/dist/local-knowledge-validation.d.ts.map +1 -0
- package/dist/local-knowledge-validation.js +487 -0
- package/dist/local-knowledge.d.ts +158 -0
- package/dist/local-knowledge.d.ts.map +1 -0
- package/dist/local-knowledge.js +63 -0
- package/dist/memory-audit-events.d.ts +73 -0
- package/dist/memory-audit-events.d.ts.map +1 -0
- package/dist/memory-audit-events.js +44 -0
- package/dist/memory-audit-validation.d.ts +4 -0
- package/dist/memory-audit-validation.d.ts.map +1 -0
- package/dist/memory-audit-validation.js +151 -0
- package/dist/memory-barrel.d.ts +15 -0
- package/dist/memory-barrel.d.ts.map +1 -0
- package/dist/memory-barrel.js +20 -0
- package/dist/memory-internal.d.ts +26 -0
- package/dist/memory-internal.d.ts.map +1 -0
- package/dist/memory-internal.js +104 -0
- package/dist/memory-operations-validation.d.ts +12 -0
- package/dist/memory-operations-validation.d.ts.map +1 -0
- package/dist/memory-operations-validation.js +267 -0
- package/dist/memory-operations.d.ts +156 -0
- package/dist/memory-operations.d.ts.map +1 -0
- package/dist/memory-operations.js +29 -0
- package/dist/memory-record-validation.d.ts +10 -0
- package/dist/memory-record-validation.d.ts.map +1 -0
- package/dist/memory-record-validation.js +101 -0
- package/dist/memory-records.d.ts +66 -0
- package/dist/memory-records.d.ts.map +1 -0
- package/dist/memory-records.js +22 -0
- package/dist/memory-retrieval-validation.d.ts +6 -0
- package/dist/memory-retrieval-validation.d.ts.map +1 -0
- package/dist/memory-retrieval-validation.js +108 -0
- package/dist/memory-validation.d.ts +31 -0
- package/dist/memory-validation.d.ts.map +1 -0
- package/dist/memory-validation.js +318 -0
- package/dist/memory-workflow-port.d.ts +26 -0
- package/dist/memory-workflow-port.d.ts.map +1 -0
- package/dist/memory-workflow-port.js +13 -0
- package/dist/memory.d.ts +81 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +104 -0
- package/dist/prompt-enhancer-analyzer.d.ts +7 -0
- package/dist/prompt-enhancer-analyzer.d.ts.map +1 -0
- package/dist/prompt-enhancer-analyzer.js +745 -0
- package/dist/prompt-enhancer-bff.d.ts +67 -0
- package/dist/prompt-enhancer-bff.d.ts.map +1 -0
- package/dist/prompt-enhancer-bff.js +156 -0
- package/dist/prompt-enhancer-critic.d.ts +46 -0
- package/dist/prompt-enhancer-critic.d.ts.map +1 -0
- package/dist/prompt-enhancer-critic.js +35 -0
- package/dist/prompt-enhancer-grounding.d.ts +19 -0
- package/dist/prompt-enhancer-grounding.d.ts.map +1 -0
- package/dist/prompt-enhancer-grounding.js +235 -0
- package/dist/prompt-enhancer-safety.d.ts +66 -0
- package/dist/prompt-enhancer-safety.d.ts.map +1 -0
- package/dist/prompt-enhancer-safety.js +446 -0
- package/dist/prompt-enhancer-validation.d.ts +28 -0
- package/dist/prompt-enhancer-validation.d.ts.map +1 -0
- package/dist/prompt-enhancer-validation.js +931 -0
- package/dist/prompt-enhancer.d.ts +184 -0
- package/dist/prompt-enhancer.d.ts.map +1 -0
- package/dist/prompt-enhancer.js +350 -0
- package/dist/qualityIntelligence/assertNever.d.ts +2 -0
- package/dist/qualityIntelligence/assertNever.d.ts.map +1 -0
- package/dist/qualityIntelligence/assertNever.js +7 -0
- package/dist/qualityIntelligence/auditSummary.d.ts +25 -0
- package/dist/qualityIntelligence/auditSummary.d.ts.map +1 -0
- package/dist/qualityIntelligence/auditSummary.js +7 -0
- package/dist/qualityIntelligence/bffWire.d.ts +356 -0
- package/dist/qualityIntelligence/bffWire.d.ts.map +1 -0
- package/dist/qualityIntelligence/bffWire.js +22 -0
- package/dist/qualityIntelligence/coverageMap.d.ts +21 -0
- package/dist/qualityIntelligence/coverageMap.d.ts.map +1 -0
- package/dist/qualityIntelligence/coverageMap.js +29 -0
- package/dist/qualityIntelligence/editableRevision.d.ts +21 -0
- package/dist/qualityIntelligence/editableRevision.d.ts.map +1 -0
- package/dist/qualityIntelligence/editableRevision.js +8 -0
- package/dist/qualityIntelligence/evidenceAtom.d.ts +35 -0
- package/dist/qualityIntelligence/evidenceAtom.d.ts.map +1 -0
- package/dist/qualityIntelligence/evidenceAtom.js +29 -0
- package/dist/qualityIntelligence/exportBundle.d.ts +28 -0
- package/dist/qualityIntelligence/exportBundle.d.ts.map +1 -0
- package/dist/qualityIntelligence/exportBundle.js +46 -0
- package/dist/qualityIntelligence/handoffEnvelope.d.ts +23 -0
- package/dist/qualityIntelligence/handoffEnvelope.d.ts.map +1 -0
- package/dist/qualityIntelligence/handoffEnvelope.js +8 -0
- package/dist/qualityIntelligence/ids.d.ts +58 -0
- package/dist/qualityIntelligence/ids.d.ts.map +1 -0
- package/dist/qualityIntelligence/ids.js +93 -0
- package/dist/qualityIntelligence/index.d.ts +29 -0
- package/dist/qualityIntelligence/index.d.ts.map +1 -0
- package/dist/qualityIntelligence/index.js +20 -0
- package/dist/qualityIntelligence/reviewRecord.d.ts +19 -0
- package/dist/qualityIntelligence/reviewRecord.d.ts.map +1 -0
- package/dist/qualityIntelligence/reviewRecord.js +20 -0
- package/dist/qualityIntelligence/runPlanAndEvents.d.ts +84 -0
- package/dist/qualityIntelligence/runPlanAndEvents.d.ts.map +1 -0
- package/dist/qualityIntelligence/runPlanAndEvents.js +51 -0
- package/dist/qualityIntelligence/sourceEnvelope.d.ts +77 -0
- package/dist/qualityIntelligence/sourceEnvelope.d.ts.map +1 -0
- package/dist/qualityIntelligence/sourceEnvelope.js +118 -0
- package/dist/qualityIntelligence/testCaseCandidate.d.ts +21 -0
- package/dist/qualityIntelligence/testCaseCandidate.d.ts.map +1 -0
- package/dist/qualityIntelligence/testCaseCandidate.js +21 -0
- package/dist/qualityIntelligence/testQualityRubric.d.ts +17 -0
- package/dist/qualityIntelligence/testQualityRubric.d.ts.map +1 -0
- package/dist/qualityIntelligence/testQualityRubric.js +32 -0
- package/dist/qualityIntelligence/validationFinding.d.ts +48 -0
- package/dist/qualityIntelligence/validationFinding.d.ts.map +1 -0
- package/dist/qualityIntelligence/validationFinding.js +36 -0
- package/dist/relationships-validation.d.ts +13 -0
- package/dist/relationships-validation.d.ts.map +1 -0
- package/dist/relationships-validation.js +422 -0
- package/dist/relationships.d.ts +79 -0
- package/dist/relationships.d.ts.map +1 -0
- package/dist/relationships.js +307 -0
- package/dist/text-safety.d.ts +7 -0
- package/dist/text-safety.d.ts.map +1 -0
- package/dist/text-safety.js +58 -0
- package/dist/tools.d.ts +153 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +118 -0
- package/dist/unit-test-events.d.ts +87 -0
- package/dist/unit-test-events.d.ts.map +1 -0
- package/dist/unit-test-events.js +14 -0
- package/dist/verification-summary.d.ts +38 -0
- package/dist/verification-summary.d.ts.map +1 -0
- package/dist/verification-summary.js +5 -0
- package/dist/verification.d.ts +64 -0
- package/dist/verification.d.ts.map +1 -0
- package/dist/verification.js +13 -0
- package/dist/workflow-descriptor.d.ts +21 -0
- package/dist/workflow-descriptor.d.ts.map +1 -0
- package/dist/workflow-descriptor.js +8 -0
- package/dist/workflow-handoff.d.ts +69 -0
- package/dist/workflow-handoff.d.ts.map +1 -0
- package/dist/workflow-handoff.js +381 -0
- package/dist/workspace-descriptors.d.ts +21 -0
- package/dist/workspace-descriptors.d.ts.map +1 -0
- package/dist/workspace-descriptors.js +180 -0
- package/dist/workspace-ui.d.ts +119 -0
- package/dist/workspace-ui.d.ts.map +1 -0
- package/dist/workspace-ui.js +105 -0
- package/dist/workspace.d.ts +104 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +27 -0
- package/package.json +71 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Bounded large-document ingestion contracts for the Local Knowledge Connector
|
|
2
|
+
// (Epic #1160, Issue #1286). This module is PURE — no node:sqlite, no fs, no clock, no
|
|
3
|
+
// randomness, no crypto — so it stays in the leaf `keiko-contracts` package.
|
|
4
|
+
//
|
|
5
|
+
// The large-document path coexists with the existing full-buffer parser path. Small files
|
|
6
|
+
// keep their current behavior; large supported files are preflight-classified, bounded by an
|
|
7
|
+
// explicit multi-dimensional resource policy, extracted progressively (page-windowed),
|
|
8
|
+
// checkpointed durably so they can resume, and degraded to partial coverage with quality
|
|
9
|
+
// warnings rather than failing the indexing pipeline when an optional capability is missing.
|
|
10
|
+
//
|
|
11
|
+
// Every record carries explicit capsuleId + documentId lineage so a single global pool is
|
|
12
|
+
// unrepresentable (Foundry IQ invariant). The wire surface stays content-free: checkpoints
|
|
13
|
+
// carry hashes, cursors, and counts — never raw extracted text.
|
|
14
|
+
const MIB = 1024 * 1024;
|
|
15
|
+
const GIB = 1024 * MIB;
|
|
16
|
+
export const DEFAULT_LARGE_DOCUMENT_RESOURCE_POLICY = Object.freeze({
|
|
17
|
+
maxRawFileBytes: GIB,
|
|
18
|
+
maxExtractedTextBytes: 256 * MIB,
|
|
19
|
+
maxParserUnits: 200_000,
|
|
20
|
+
maxParserObjects: 25_000_000,
|
|
21
|
+
maxChunkCount: 2_000_000,
|
|
22
|
+
maxEmbeddingBatchCount: 100_000,
|
|
23
|
+
maxWallClockMs: 60 * 60 * 1000,
|
|
24
|
+
cancellationDeadlineMs: 15_000,
|
|
25
|
+
maxRetryCount: 3,
|
|
26
|
+
maxPersistedStorageGrowthBytes: 512 * MIB,
|
|
27
|
+
largeFileThresholdBytes: 64 * MIB,
|
|
28
|
+
extractionWindowPages: 16,
|
|
29
|
+
});
|
|
30
|
+
// Stable, order-fixed fingerprint persisted with each checkpoint. Any policy change yields a
|
|
31
|
+
// different fingerprint, which makes a resumed job refuse a checkpoint produced under
|
|
32
|
+
// different limits.
|
|
33
|
+
export function largeDocumentPolicyFingerprint(policy) {
|
|
34
|
+
return [
|
|
35
|
+
"ldp1",
|
|
36
|
+
policy.maxRawFileBytes,
|
|
37
|
+
policy.maxExtractedTextBytes,
|
|
38
|
+
policy.maxParserUnits,
|
|
39
|
+
policy.maxParserObjects,
|
|
40
|
+
policy.maxChunkCount,
|
|
41
|
+
policy.maxEmbeddingBatchCount,
|
|
42
|
+
policy.maxWallClockMs,
|
|
43
|
+
policy.cancellationDeadlineMs,
|
|
44
|
+
policy.maxRetryCount,
|
|
45
|
+
policy.maxPersistedStorageGrowthBytes,
|
|
46
|
+
policy.largeFileThresholdBytes,
|
|
47
|
+
policy.extractionWindowPages,
|
|
48
|
+
].join(":");
|
|
49
|
+
}
|
|
50
|
+
export const LARGE_DOCUMENT_EXTRACTION_STRATEGIES = [
|
|
51
|
+
"standard-buffer",
|
|
52
|
+
"progressive-pdf",
|
|
53
|
+
"unsupported",
|
|
54
|
+
"oversized",
|
|
55
|
+
];
|
|
56
|
+
export const EXTRACTION_PHASES = [
|
|
57
|
+
"preflight",
|
|
58
|
+
"extracting",
|
|
59
|
+
"extracted",
|
|
60
|
+
"chunking",
|
|
61
|
+
"chunked",
|
|
62
|
+
"embedding",
|
|
63
|
+
"embedded",
|
|
64
|
+
"complete",
|
|
65
|
+
"cancelled",
|
|
66
|
+
"failed",
|
|
67
|
+
];
|
|
68
|
+
// A phase is terminal when no further work will run for the document under the current job.
|
|
69
|
+
export const TERMINAL_EXTRACTION_PHASES = [
|
|
70
|
+
"complete",
|
|
71
|
+
"cancelled",
|
|
72
|
+
"failed",
|
|
73
|
+
];
|
|
74
|
+
export function isTerminalExtractionPhase(phase) {
|
|
75
|
+
return TERMINAL_EXTRACTION_PHASES.includes(phase);
|
|
76
|
+
}
|
|
77
|
+
export const COVERAGE_QUALITIES = [
|
|
78
|
+
"complete",
|
|
79
|
+
"text-only",
|
|
80
|
+
"partial",
|
|
81
|
+
"none",
|
|
82
|
+
];
|
|
83
|
+
export const EXTRACTION_CAPABILITY_STATUSES = [
|
|
84
|
+
"available",
|
|
85
|
+
"unavailable",
|
|
86
|
+
"degraded",
|
|
87
|
+
"failing",
|
|
88
|
+
];
|
|
89
|
+
export const DEFAULT_EXTRACTION_CAPABILITY_AVAILABILITY = Object.freeze({ ocr: "unavailable", multimodal: "unavailable" });
|
|
90
|
+
// A capability contributes useful coverage only when it is fully available. Degraded/failing
|
|
91
|
+
// capabilities are isolated as quality warnings.
|
|
92
|
+
export function capabilityContributesCoverage(status) {
|
|
93
|
+
return status === "available";
|
|
94
|
+
}
|
|
95
|
+
// ─── Content-free diagnostic codes for the large-document path ─────────────────
|
|
96
|
+
export const LARGE_DOCUMENT_DIAGNOSTIC_CODES = Object.freeze({
|
|
97
|
+
PARTIAL_COVERAGE: "PARTIAL_COVERAGE",
|
|
98
|
+
OCR_CAPABILITY_UNAVAILABLE: "OCR_CAPABILITY_UNAVAILABLE",
|
|
99
|
+
MULTIMODAL_CAPABILITY_UNAVAILABLE: "MULTIMODAL_CAPABILITY_UNAVAILABLE",
|
|
100
|
+
CONVERTER_UNAVAILABLE: "CONVERTER_UNAVAILABLE",
|
|
101
|
+
RESOURCE_POLICY_EXCEEDED: "RESOURCE_POLICY_EXCEEDED",
|
|
102
|
+
CHECKPOINT_INCOMPATIBLE: "CHECKPOINT_INCOMPATIBLE",
|
|
103
|
+
EXTRACTION_RESUMED: "EXTRACTION_RESUMED",
|
|
104
|
+
EXTRACTION_PROGRESS: "EXTRACTION_PROGRESS",
|
|
105
|
+
});
|
|
106
|
+
export const CHECKPOINT_INCOMPATIBILITY_REASONS = [
|
|
107
|
+
"source-hash",
|
|
108
|
+
"parser-version",
|
|
109
|
+
"resource-policy",
|
|
110
|
+
"chunking-strategy",
|
|
111
|
+
"embedding-identity",
|
|
112
|
+
];
|
|
113
|
+
function sameEmbeddingIdentity(a, b) {
|
|
114
|
+
return (a.provider === b.provider &&
|
|
115
|
+
a.modelId === b.modelId &&
|
|
116
|
+
a.vectorDimensions === b.vectorDimensions &&
|
|
117
|
+
a.vectorMetric === b.vectorMetric &&
|
|
118
|
+
(a.modelRevision ?? "") === (b.modelRevision ?? ""));
|
|
119
|
+
}
|
|
120
|
+
// Pure comparison. A resumed job continues only when this returns `{ compatible: true }`;
|
|
121
|
+
// otherwise the job restarts from scratch and emits a CHECKPOINT_INCOMPATIBLE diagnostic.
|
|
122
|
+
export function checkpointCompatibility(stored, current) {
|
|
123
|
+
const reasons = [];
|
|
124
|
+
if (stored.sourceContentHash !== current.sourceContentHash)
|
|
125
|
+
reasons.push("source-hash");
|
|
126
|
+
if (stored.parserVersion !== current.parserVersion)
|
|
127
|
+
reasons.push("parser-version");
|
|
128
|
+
if (stored.policyFingerprint !== current.policyFingerprint)
|
|
129
|
+
reasons.push("resource-policy");
|
|
130
|
+
if (stored.chunkingStrategyVersion !== current.chunkingStrategyVersion) {
|
|
131
|
+
reasons.push("chunking-strategy");
|
|
132
|
+
}
|
|
133
|
+
if (!sameEmbeddingIdentity(stored.embeddingIdentity, current.embeddingIdentity)) {
|
|
134
|
+
reasons.push("embedding-identity");
|
|
135
|
+
}
|
|
136
|
+
return reasons.length === 0 ? { compatible: true } : { compatible: false, reasons };
|
|
137
|
+
}
|
|
138
|
+
export const LARGE_DOCUMENT_RESUME_CHOICES = [
|
|
139
|
+
"resume",
|
|
140
|
+
"restart",
|
|
141
|
+
"abandon",
|
|
142
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-knowledge-paths.d.ts","sourceRoot":"","sources":["../src/local-knowledge-paths.ts"],"names":[],"mappings":"AAoCA,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAiBrD;AAKD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAW5D"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Pure path-safety helpers for the Local Knowledge Connector validators (Epic #189,
|
|
2
|
+
// Issue #191). Extracted from `local-knowledge-validation.ts` to keep each file under the
|
|
3
|
+
// 400-LOC budget and to give downstream packages a single import target when they need to
|
|
4
|
+
// re-use the safe-path predicates at their own trust boundaries.
|
|
5
|
+
//
|
|
6
|
+
// Producers may pass either a workspace-relative path or an absolute path; the validator
|
|
7
|
+
// only rejects the most dangerous shapes: traversal segments, tilde expansion (which the
|
|
8
|
+
// shell would resolve to $HOME), NUL bytes, Windows-style drive letters and UNC prefixes,
|
|
9
|
+
// and the literal filesystem root markers. These helpers NEVER touch the filesystem.
|
|
10
|
+
const WINDOWS_DRIVE_RE = /^[A-Za-z]:/;
|
|
11
|
+
const ROOT_MARKERS = new Set(["/", "\\", "~", "."]);
|
|
12
|
+
function hasTraversalSegment(path) {
|
|
13
|
+
const normalized = path.replace(/\\/g, "/");
|
|
14
|
+
for (const segment of normalized.split("/")) {
|
|
15
|
+
if (segment === "..") {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
function isObviouslyUnsafeAbsoluteScope(path) {
|
|
22
|
+
if (path === "/" || path === "\\") {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (path.startsWith("~")) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (path.startsWith("\\\\")) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return WINDOWS_DRIVE_RE.test(path) && path.length <= 3;
|
|
32
|
+
}
|
|
33
|
+
export function isSafeScopePath(path) {
|
|
34
|
+
if (path.length === 0) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (path.includes("\0")) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (ROOT_MARKERS.has(path)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (path.startsWith("~")) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (isObviouslyUnsafeAbsoluteScope(path)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return !hasTraversalSegment(path);
|
|
50
|
+
}
|
|
51
|
+
// Storage references live under Keiko's runtime-state directory and MUST stay relative.
|
|
52
|
+
// We refuse anything starting with `/`, `\`, a Windows drive prefix, a tilde, or anything
|
|
53
|
+
// containing `..` or NUL.
|
|
54
|
+
export function isSafeStorageReference(path) {
|
|
55
|
+
if (path.length === 0 || path.includes("\0")) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (path.startsWith("/") || path.startsWith("\\") || path.startsWith("~")) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (WINDOWS_DRIVE_RE.test(path)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return !hasTraversalSegment(path);
|
|
65
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { CapsuleLifecycleState, ChunkId, DocumentId, EmbeddingModelIdentity, KnowledgeCapsuleId, KnowledgeSourceId, ParserIdentity, VectorId } from "./local-knowledge.js";
|
|
2
|
+
export type DocumentStatus = "pending" | "extracted" | "skipped" | "failed" | "unsupported";
|
|
3
|
+
export declare const DOCUMENT_STATUSES: readonly DocumentStatus[];
|
|
4
|
+
export interface DocumentRecord {
|
|
5
|
+
readonly id: DocumentId;
|
|
6
|
+
readonly capsuleId: KnowledgeCapsuleId;
|
|
7
|
+
readonly sourceId: KnowledgeSourceId;
|
|
8
|
+
readonly documentPath: string;
|
|
9
|
+
readonly sizeBytes: number;
|
|
10
|
+
readonly mediaType: string;
|
|
11
|
+
readonly contentHash: string;
|
|
12
|
+
readonly parser: ParserIdentity;
|
|
13
|
+
readonly lastExtractedAt: number;
|
|
14
|
+
readonly status: DocumentStatus;
|
|
15
|
+
readonly safeDisplayName: string;
|
|
16
|
+
}
|
|
17
|
+
export interface PageBoundingBox {
|
|
18
|
+
readonly x: number;
|
|
19
|
+
readonly y: number;
|
|
20
|
+
readonly w: number;
|
|
21
|
+
readonly h: number;
|
|
22
|
+
}
|
|
23
|
+
export interface PageRecord {
|
|
24
|
+
readonly documentId: DocumentId;
|
|
25
|
+
readonly pageNumber: number;
|
|
26
|
+
readonly pageLabel?: string;
|
|
27
|
+
readonly characterStart: number;
|
|
28
|
+
readonly characterEnd: number;
|
|
29
|
+
readonly boundingBox?: PageBoundingBox;
|
|
30
|
+
}
|
|
31
|
+
export interface SectionRecord {
|
|
32
|
+
readonly documentId: DocumentId;
|
|
33
|
+
readonly sectionPath: readonly string[];
|
|
34
|
+
readonly characterStart: number;
|
|
35
|
+
readonly characterEnd: number;
|
|
36
|
+
}
|
|
37
|
+
export type ParsedUnit = {
|
|
38
|
+
readonly kind: "page";
|
|
39
|
+
readonly documentId: DocumentId;
|
|
40
|
+
readonly pageNumber: number;
|
|
41
|
+
readonly pageLabel?: string;
|
|
42
|
+
readonly characterStart: number;
|
|
43
|
+
readonly characterEnd: number;
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: "section";
|
|
46
|
+
readonly documentId: DocumentId;
|
|
47
|
+
readonly sectionPath: readonly string[];
|
|
48
|
+
readonly characterStart: number;
|
|
49
|
+
readonly characterEnd: number;
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: "json-path";
|
|
52
|
+
readonly documentId: DocumentId;
|
|
53
|
+
readonly jsonPointer: string;
|
|
54
|
+
readonly characterStart: number;
|
|
55
|
+
readonly characterEnd: number;
|
|
56
|
+
} | {
|
|
57
|
+
readonly kind: "csv-row";
|
|
58
|
+
readonly documentId: DocumentId;
|
|
59
|
+
readonly tableName: string;
|
|
60
|
+
readonly rowIndex: number;
|
|
61
|
+
readonly characterStart: number;
|
|
62
|
+
readonly characterEnd: number;
|
|
63
|
+
} | {
|
|
64
|
+
readonly kind: "html-block";
|
|
65
|
+
readonly documentId: DocumentId;
|
|
66
|
+
readonly headingPath?: readonly string[];
|
|
67
|
+
readonly characterStart: number;
|
|
68
|
+
readonly characterEnd: number;
|
|
69
|
+
} | {
|
|
70
|
+
readonly kind: "unsupported-media";
|
|
71
|
+
readonly documentId: DocumentId;
|
|
72
|
+
readonly reason: string;
|
|
73
|
+
};
|
|
74
|
+
export type ParsedUnitKind = ParsedUnit["kind"];
|
|
75
|
+
export declare const PARSED_UNIT_KINDS: readonly ParsedUnitKind[];
|
|
76
|
+
export interface ChunkRecord {
|
|
77
|
+
readonly id: ChunkId;
|
|
78
|
+
readonly capsuleId: KnowledgeCapsuleId;
|
|
79
|
+
readonly sourceId: KnowledgeSourceId;
|
|
80
|
+
readonly documentId: DocumentId;
|
|
81
|
+
readonly parsedUnit: ParsedUnit;
|
|
82
|
+
readonly orderIndex: number;
|
|
83
|
+
readonly tokenCount: number;
|
|
84
|
+
readonly safeExcerptHash: string;
|
|
85
|
+
}
|
|
86
|
+
export interface VectorRecord {
|
|
87
|
+
readonly id: VectorId;
|
|
88
|
+
readonly chunkId: ChunkId;
|
|
89
|
+
readonly capsuleId: KnowledgeCapsuleId;
|
|
90
|
+
readonly sourceId: KnowledgeSourceId;
|
|
91
|
+
readonly documentId: DocumentId;
|
|
92
|
+
readonly embeddingIdentity: EmbeddingModelIdentity;
|
|
93
|
+
readonly vectorDimensions: number;
|
|
94
|
+
readonly storageReference: string;
|
|
95
|
+
readonly createdAt: number;
|
|
96
|
+
}
|
|
97
|
+
export interface CitationReference {
|
|
98
|
+
readonly documentId: DocumentId;
|
|
99
|
+
readonly capsuleId: KnowledgeCapsuleId;
|
|
100
|
+
readonly sourceId: KnowledgeSourceId;
|
|
101
|
+
readonly chunkId: ChunkId;
|
|
102
|
+
readonly pageNumber?: number;
|
|
103
|
+
readonly pageLabel?: string;
|
|
104
|
+
readonly sectionPath?: readonly string[];
|
|
105
|
+
readonly jsonPointer?: string;
|
|
106
|
+
readonly tableName?: string;
|
|
107
|
+
readonly rowIndex?: number;
|
|
108
|
+
readonly characterStart?: number;
|
|
109
|
+
readonly characterEnd?: number;
|
|
110
|
+
readonly safeDisplayName: string;
|
|
111
|
+
}
|
|
112
|
+
export interface RetrievalReference {
|
|
113
|
+
readonly chunkId: ChunkId;
|
|
114
|
+
readonly capsuleId: KnowledgeCapsuleId;
|
|
115
|
+
readonly score: number;
|
|
116
|
+
readonly citation: CitationReference;
|
|
117
|
+
}
|
|
118
|
+
export type ParserDiagnosticSeverity = "info" | "warning" | "error";
|
|
119
|
+
export declare const PARSER_DIAGNOSTIC_SEVERITIES: readonly ParserDiagnosticSeverity[];
|
|
120
|
+
export interface ParserDiagnostic {
|
|
121
|
+
readonly severity: ParserDiagnosticSeverity;
|
|
122
|
+
readonly code: string;
|
|
123
|
+
readonly message: string;
|
|
124
|
+
readonly documentId?: DocumentId;
|
|
125
|
+
readonly pageNumber?: number;
|
|
126
|
+
}
|
|
127
|
+
export interface ParserResult {
|
|
128
|
+
readonly documentId: DocumentId;
|
|
129
|
+
readonly parser: ParserIdentity;
|
|
130
|
+
readonly pages: readonly PageRecord[];
|
|
131
|
+
readonly sections: readonly SectionRecord[];
|
|
132
|
+
readonly units: readonly ParsedUnit[];
|
|
133
|
+
readonly diagnostics: readonly ParserDiagnostic[];
|
|
134
|
+
readonly extractedAt: number;
|
|
135
|
+
}
|
|
136
|
+
export type IndexingJobStatus = "queued" | "running" | "succeeded" | "failed" | "cancelled";
|
|
137
|
+
export declare const INDEXING_JOB_STATUSES: readonly IndexingJobStatus[];
|
|
138
|
+
export type CapsuleReindexMode = "changed-files" | "repair-failed" | "resume";
|
|
139
|
+
export declare const CAPSULE_REINDEX_MODES: readonly CapsuleReindexMode[];
|
|
140
|
+
export interface CapsuleReindexRequest {
|
|
141
|
+
readonly capsuleId: KnowledgeCapsuleId;
|
|
142
|
+
readonly mode?: CapsuleReindexMode;
|
|
143
|
+
readonly force?: boolean;
|
|
144
|
+
}
|
|
145
|
+
export interface IndexingJobError {
|
|
146
|
+
readonly code: string;
|
|
147
|
+
readonly message: string;
|
|
148
|
+
}
|
|
149
|
+
export interface IndexingJobRecord {
|
|
150
|
+
readonly id: string;
|
|
151
|
+
readonly capsuleId: KnowledgeCapsuleId;
|
|
152
|
+
readonly sourceIds: readonly KnowledgeSourceId[];
|
|
153
|
+
readonly startedAt: number;
|
|
154
|
+
readonly finishedAt?: number;
|
|
155
|
+
readonly status: IndexingJobStatus;
|
|
156
|
+
readonly totalDocuments: number;
|
|
157
|
+
readonly processedDocuments: number;
|
|
158
|
+
readonly failedDocuments: number;
|
|
159
|
+
readonly skippedDocuments: number;
|
|
160
|
+
readonly lastError?: IndexingJobError;
|
|
161
|
+
readonly largeDocumentCount?: number;
|
|
162
|
+
readonly partialCoverageDocuments?: number;
|
|
163
|
+
readonly resumableDocuments?: number;
|
|
164
|
+
}
|
|
165
|
+
export interface CapsuleHealth {
|
|
166
|
+
readonly capsuleId: KnowledgeCapsuleId;
|
|
167
|
+
readonly sourceIds: readonly KnowledgeSourceId[];
|
|
168
|
+
readonly lifecycleState: CapsuleLifecycleState;
|
|
169
|
+
readonly storageSizeBytes: number;
|
|
170
|
+
readonly documentCount: number;
|
|
171
|
+
readonly chunkCount: number;
|
|
172
|
+
readonly vectorCount: number;
|
|
173
|
+
readonly lastIndexedAt?: number;
|
|
174
|
+
readonly embeddingIdentity: EmbeddingModelIdentity;
|
|
175
|
+
readonly vectorCompatible: boolean;
|
|
176
|
+
readonly failedDocuments: number;
|
|
177
|
+
readonly skippedDocuments: number;
|
|
178
|
+
readonly unsupportedDocuments: number;
|
|
179
|
+
readonly unsupportedGuidance: readonly string[];
|
|
180
|
+
readonly staleReasons: readonly string[];
|
|
181
|
+
readonly partialCoverageDocuments?: number;
|
|
182
|
+
readonly qualityWarnings?: readonly string[];
|
|
183
|
+
readonly resumableDocuments?: number;
|
|
184
|
+
}
|
|
185
|
+
export interface CapsuleDeleteRequest {
|
|
186
|
+
readonly capsuleId: KnowledgeCapsuleId;
|
|
187
|
+
readonly deleteIndex: boolean;
|
|
188
|
+
readonly deleteSources: false;
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=local-knowledge-records.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-knowledge-records.d.ts","sourceRoot":"","sources":["../src/local-knowledge-records.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,qBAAqB,EACrB,OAAO,EACP,UAAU,EACV,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACT,MAAM,sBAAsB,CAAC;AAG9B,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,CAAC;AAE5F,eAAO,MAAM,iBAAiB,EAAE,SAAS,cAAc,EAM7C,CAAC;AAEX,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,UAAU,CAAC;IACxB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AAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CACtC;AAMD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC;IACvC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC;CAC/B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Document-derived record contracts for the Local Knowledge Connector (Epic #189, Issue
|
|
2
|
+
// #191). Split from `local-knowledge.ts` to keep each file under the 400-LOC budget. Every
|
|
3
|
+
// record carries explicit capsuleId + sourceId + documentId lineage where applicable so a
|
|
4
|
+
// single global knowledge pool is unrepresentable (Foundry IQ invariant).
|
|
5
|
+
export const DOCUMENT_STATUSES = [
|
|
6
|
+
"pending",
|
|
7
|
+
"extracted",
|
|
8
|
+
"skipped",
|
|
9
|
+
"failed",
|
|
10
|
+
"unsupported",
|
|
11
|
+
];
|
|
12
|
+
export const PARSED_UNIT_KINDS = [
|
|
13
|
+
"page",
|
|
14
|
+
"section",
|
|
15
|
+
"json-path",
|
|
16
|
+
"csv-row",
|
|
17
|
+
"html-block",
|
|
18
|
+
"unsupported-media",
|
|
19
|
+
];
|
|
20
|
+
export const PARSER_DIAGNOSTIC_SEVERITIES = [
|
|
21
|
+
"info",
|
|
22
|
+
"warning",
|
|
23
|
+
"error",
|
|
24
|
+
];
|
|
25
|
+
export const INDEXING_JOB_STATUSES = [
|
|
26
|
+
"queued",
|
|
27
|
+
"running",
|
|
28
|
+
"succeeded",
|
|
29
|
+
"failed",
|
|
30
|
+
"cancelled",
|
|
31
|
+
];
|
|
32
|
+
export const CAPSULE_REINDEX_MODES = [
|
|
33
|
+
"changed-files",
|
|
34
|
+
"repair-failed",
|
|
35
|
+
"resume",
|
|
36
|
+
];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { LocalKnowledgeValidation } from "./local-knowledge-validation.js";
|
|
2
|
+
export interface CapsuleRowShape {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly displayName: string;
|
|
5
|
+
readonly vectorDimensions: number;
|
|
6
|
+
readonly vectorMetric: string;
|
|
7
|
+
readonly embeddingModelProvider: string;
|
|
8
|
+
readonly embeddingModelId: string;
|
|
9
|
+
readonly lifecycleState: string;
|
|
10
|
+
readonly storageReference: string;
|
|
11
|
+
readonly createdAt: number;
|
|
12
|
+
readonly updatedAt: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function validateCapsuleRowShape(input: unknown): LocalKnowledgeValidation<CapsuleRowShape>;
|
|
15
|
+
export interface RedactPathOptions {
|
|
16
|
+
readonly homePrefix?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function redactPathInDiagnostic(rawPath: string, options?: RedactPathOptions): string;
|
|
19
|
+
//# sourceMappingURL=local-knowledge-schema-validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-knowledge-schema-validation.d.ts","sourceRoot":"","sources":["../src/local-knowledge-schema-validation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAOhF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;IACxC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AA4CD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,wBAAwB,CAAC,eAAe,CAAC,CAYjG;AA4DD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAQD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAU/F"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Pure helpers for the Local Knowledge Connector persistent schema (Epic #189, Issue
|
|
2
|
+
// #265). Split out from `local-knowledge-schema.ts` to keep both files under the 400-LOC
|
|
3
|
+
// budget. No `node:sqlite`, no fs, no clock — these helpers only inspect or rewrite
|
|
4
|
+
// strings the runtime (#193) reads from disk or surfaces to diagnostics.
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function isNonEmptyString(value) {
|
|
9
|
+
return typeof value === "string" && value.length > 0;
|
|
10
|
+
}
|
|
11
|
+
function isFinitePositiveInt(value) {
|
|
12
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
13
|
+
}
|
|
14
|
+
function isFiniteNonNegative(value) {
|
|
15
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
16
|
+
}
|
|
17
|
+
const NON_EMPTY_STRING_FIELDS = [
|
|
18
|
+
["id", isNonEmptyString, "must be a non-empty string"],
|
|
19
|
+
["displayName", isNonEmptyString, "must be a non-empty string"],
|
|
20
|
+
["vectorMetric", isNonEmptyString, "must be a non-empty string"],
|
|
21
|
+
["embeddingModelProvider", isNonEmptyString, "must be a non-empty string"],
|
|
22
|
+
["embeddingModelId", isNonEmptyString, "must be a non-empty string"],
|
|
23
|
+
["lifecycleState", isNonEmptyString, "must be a non-empty string"],
|
|
24
|
+
["storageReference", isNonEmptyString, "must be a non-empty string"],
|
|
25
|
+
];
|
|
26
|
+
const ROW_FIELD_CHECKS = [
|
|
27
|
+
...NON_EMPTY_STRING_FIELDS,
|
|
28
|
+
["vectorDimensions", isFinitePositiveInt, "must be a positive integer"],
|
|
29
|
+
["createdAt", isFiniteNonNegative, "must be a finite non-negative number"],
|
|
30
|
+
["updatedAt", isFiniteNonNegative, "must be a finite non-negative number"],
|
|
31
|
+
];
|
|
32
|
+
export function validateCapsuleRowShape(input) {
|
|
33
|
+
if (!isRecord(input)) {
|
|
34
|
+
return { ok: false, errors: ["capsuleRow must be an object"] };
|
|
35
|
+
}
|
|
36
|
+
const errors = [];
|
|
37
|
+
for (const [field, guard, errorSuffix] of ROW_FIELD_CHECKS) {
|
|
38
|
+
if (!guard(input[field])) {
|
|
39
|
+
errors.push(`capsuleRow.${field} ${errorSuffix}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (errors.length > 0)
|
|
43
|
+
return { ok: false, errors };
|
|
44
|
+
return { ok: true, value: input };
|
|
45
|
+
}
|
|
46
|
+
// ─── Diagnostic path redaction ───────────────────────────────────────────────────
|
|
47
|
+
// Used by parser-diagnostic and indexing-job error construction so raw filesystem paths
|
|
48
|
+
// cannot land in audit logs or UI surfaces. Pure: reads no environment, no fs, no clock.
|
|
49
|
+
// The HOME prefix is supplied by the caller (the runtime in #193 resolves it once at
|
|
50
|
+
// boot) so this helper stays deterministic and trivially testable.
|
|
51
|
+
const REDACTED_MAX_CHARS = 1024;
|
|
52
|
+
// Matches the ASCII control range; control chars in filenames are pathological and must
|
|
53
|
+
// not flow into UI strings unredacted. Disable the lint rule because the regex IS the
|
|
54
|
+
// gate.
|
|
55
|
+
// eslint-disable-next-line no-control-regex
|
|
56
|
+
const CONTROL_RE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g;
|
|
57
|
+
function stripControls(value) {
|
|
58
|
+
return value.replace(CONTROL_RE, "");
|
|
59
|
+
}
|
|
60
|
+
function normalizeSeparators(value) {
|
|
61
|
+
return value.replace(/\\/g, "/");
|
|
62
|
+
}
|
|
63
|
+
function trimTrailingSlashes(value) {
|
|
64
|
+
let end = value.length;
|
|
65
|
+
while (end > 0 && value.charCodeAt(end - 1) === 47) {
|
|
66
|
+
end -= 1;
|
|
67
|
+
}
|
|
68
|
+
return end === value.length ? value : value.slice(0, end);
|
|
69
|
+
}
|
|
70
|
+
function truncateAtNul(value) {
|
|
71
|
+
const nulAt = value.indexOf("\0");
|
|
72
|
+
return nulAt === -1 ? value : value.slice(0, nulAt);
|
|
73
|
+
}
|
|
74
|
+
function replaceHomePrefix(value, homePrefix) {
|
|
75
|
+
// Normalize the homePrefix to forward-slash form first so the comparison succeeds whether
|
|
76
|
+
// the caller supplies `/Users/foo`, `C:\\Users\\foo`, or any mix. Strip trailing slashes so
|
|
77
|
+
// callers can pass either form. The empty-prefix gate short-circuits a caller-supplied "/".
|
|
78
|
+
const normalizedPrefix = trimTrailingSlashes(normalizeSeparators(homePrefix));
|
|
79
|
+
if (normalizedPrefix.length === 0)
|
|
80
|
+
return value;
|
|
81
|
+
if (value === normalizedPrefix)
|
|
82
|
+
return "~";
|
|
83
|
+
// Match the prefix followed by a separator; prevents `/Users/foobar` being misread as
|
|
84
|
+
// `/Users/foo` + `bar`.
|
|
85
|
+
if (value.startsWith(`${normalizedPrefix}/`)) {
|
|
86
|
+
return `~${value.slice(normalizedPrefix.length)}`;
|
|
87
|
+
}
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
const WINDOWS_DRIVE_RE = /^[A-Za-z]:\/(.*)$/;
|
|
91
|
+
function replaceDrivePrefix(value) {
|
|
92
|
+
const match = WINDOWS_DRIVE_RE.exec(value);
|
|
93
|
+
if (match === null)
|
|
94
|
+
return value;
|
|
95
|
+
return `<drive>/${match[1] ?? ""}`;
|
|
96
|
+
}
|
|
97
|
+
// Public boundary helper. Order matters: separator normalisation runs BEFORE home-prefix
|
|
98
|
+
// rewriting so a Windows-style homePrefix (e.g. `C:\\Users\\foo`) compares cleanly against a
|
|
99
|
+
// Windows-style input. Drive-letter masking runs LAST so it only applies to inputs that did
|
|
100
|
+
// NOT match the user's home (otherwise a Windows home like `C:\\Users\\victim\\docs` would
|
|
101
|
+
// be rewritten to `<drive>/Users/victim/docs` and the home-prefix could never match — the
|
|
102
|
+
// #265 Copilot finding). Each step is idempotent so repeated calls return the same string.
|
|
103
|
+
export function redactPathInDiagnostic(rawPath, options = {}) {
|
|
104
|
+
if (typeof rawPath !== "string")
|
|
105
|
+
return "";
|
|
106
|
+
const homePrefix = options.homePrefix ?? "";
|
|
107
|
+
const afterNul = truncateAtNul(rawPath);
|
|
108
|
+
const noControls = stripControls(afterNul);
|
|
109
|
+
const normalized = normalizeSeparators(noControls);
|
|
110
|
+
const homeRewritten = replaceHomePrefix(normalized, homePrefix);
|
|
111
|
+
const driveRewritten = replaceDrivePrefix(homeRewritten);
|
|
112
|
+
if (driveRewritten.length <= REDACTED_MAX_CHARS)
|
|
113
|
+
return driveRewritten;
|
|
114
|
+
return `${driveRewritten.slice(0, REDACTED_MAX_CHARS)}…`;
|
|
115
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const LOCAL_KNOWLEDGE_DB_SCHEMA_VERSION: 13;
|
|
2
|
+
export declare const KNOWLEDGE_CAPSULE_DDL: readonly string[];
|
|
3
|
+
export declare const KNOWLEDGE_CAPSULE_INDEXES: readonly string[];
|
|
4
|
+
export declare const DELETE_CAPSULE_SQL: "DELETE FROM capsules WHERE id = :capsule_id;";
|
|
5
|
+
export interface KnowledgeCapsuleMigration {
|
|
6
|
+
readonly version: number;
|
|
7
|
+
readonly reason: string;
|
|
8
|
+
readonly up: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export declare const KNOWLEDGE_CAPSULE_MIGRATIONS: readonly KnowledgeCapsuleMigration[];
|
|
11
|
+
export declare const KNOWLEDGE_CAPSULE_V1_TABLES: readonly string[];
|
|
12
|
+
export declare const KNOWLEDGE_CAPSULE_TABLES: readonly string[];
|
|
13
|
+
export declare const KNOWLEDGE_CAPSULE_INDEX_NAMES: readonly string[];
|
|
14
|
+
//# sourceMappingURL=local-knowledge-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-knowledge-schema.d.ts","sourceRoot":"","sources":["../src/local-knowledge-schema.ts"],"names":[],"mappings":"AA+BA,eAAO,MAAM,iCAAiC,EAAG,EAAW,CAAC;AA2a7D,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAoBzC,CAAC;AAGX,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EA2B7C,CAAC;AAIX,eAAO,MAAM,kBAAkB,EAAG,8CAAuD,CAAC;AAM1F,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,EAAE,SAAS,MAAM,EAAE,CAAC;CAChC;AAoHD,eAAO,MAAM,4BAA4B,EAAE,SAAS,yBAAyB,EAkGnE,CAAC;AASX,eAAO,MAAM,2BAA2B,EAAE,SAAS,MAAM,EAa/C,CAAC;AAEX,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAQ5C,CAAC;AAEX,eAAO,MAAM,6BAA6B,EAAE,SAAS,MAAM,EA2BjD,CAAC"}
|