@semiont/content 0.5.5 → 0.5.7

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/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![npm downloads](https://img.shields.io/npm/dm/@semiont/content.svg)](https://www.npmjs.com/package/@semiont/content)
7
7
  [![License](https://img.shields.io/npm/l/@semiont/content.svg)](https://github.com/The-AI-Alliance/semiont/blob/main/LICENSE)
8
8
 
9
- Content-addressed storage using SHA-256 checksums with automatic deduplication and W3C compliance.
9
+ Working-tree storage for project resources, with optional git staging, plus PDF text-layer extraction.
10
10
 
11
11
  ## Installation
12
12
 
@@ -16,230 +16,115 @@ npm install @semiont/content
16
16
 
17
17
  ## Architecture Context
18
18
 
19
- **Infrastructure Ownership**: In production applications, the representation store is **created and managed by [@semiont/make-meaning](../make-meaning/)'s `startMakeMeaning()` function**, which serves as the single orchestration point for all infrastructure components (EventStore, GraphDB, RepStore, InferenceClient, JobQueue, Workers).
19
+ **Infrastructure Ownership**: In production applications, the working tree store is **created and managed by [@semiont/make-meaning](../make-meaning/)'s `startMakeMeaning()` function**, which serves as the single orchestration point for all infrastructure components. Backend code accesses it as `knowledgeBase.content`.
20
20
 
21
- The quick start example below shows direct instantiation for **testing, CLI tools, or content management scripts**. For backend integration, access the representation store through the `makeMeaning` context object.
21
+ The quick start example below shows direct instantiation for **testing, CLI tools, or content management scripts**.
22
22
 
23
23
  ## Quick Start
24
24
 
25
25
  ```typescript
26
- import { FilesystemRepresentationStore } from '@semiont/content';
26
+ import { WorkingTreeStore, deriveStorageUri } from '@semiont/content';
27
+ import { SemiontProject } from '@semiont/core/node';
27
28
 
28
- const store = new FilesystemRepresentationStore({
29
- basePath: '/path/to/storage'
30
- });
29
+ const project = new SemiontProject('/path/to/project');
30
+ const store = new WorkingTreeStore(project);
31
31
 
32
- // Store content - checksum becomes the address
33
- const content = Buffer.from('Hello, World!');
34
- const stored = await store.store(content, {
35
- mediaType: 'text/plain',
36
- language: 'en',
37
- rel: 'original'
38
- });
32
+ // Derive a stable file:// URI from a resource name
33
+ const uri = deriveStorageUri('My Document', 'text/markdown');
34
+ // => "file://my-document.md"
39
35
 
40
- console.log(stored.checksum); // sha256:abc123...
36
+ // Write content to the working tree (API/GUI/AI path)
37
+ const stored = await store.store(Buffer.from('# My Document\n'), uri);
38
+ console.log(stored.checksum); // SHA-256 hex of the content
39
+ console.log(stored.byteSize); // 14
41
40
 
42
- // Retrieve by checksum
43
- const retrieved = await store.retrieve(stored.checksum, 'text/plain');
44
- console.log(retrieved.toString()); // "Hello, World!"
41
+ // Register a file that is already on disk (CLI path)
42
+ const registered = await store.register('file://docs/overview.md');
45
43
 
46
- // Same content = same checksum (deduplication)
47
- const duplicate = await store.store(content, {
48
- mediaType: 'text/plain',
49
- rel: 'copy'
50
- });
44
+ // Read content back by URI
45
+ const content = await store.retrieve(uri);
46
+ console.log(content.toString()); // "# My Document\n"
51
47
 
52
- console.log(duplicate.checksum === stored.checksum); // true
48
+ // Move and remove files
49
+ await store.move(uri, 'file://docs/my-document.md');
50
+ await store.remove('file://docs/my-document.md');
53
51
  ```
54
52
 
55
- ## Features
53
+ ## Working Tree Storage
56
54
 
57
- - 🔐 **Content-Addressed** - SHA-256 checksum as identifier
58
- - 🎯 **Automatic Deduplication** - Identical content stored once
59
- - 🗂️ **Smart Sharding** - 65,536 directories for scalability
60
- - 📊 **W3C Compliant** - Full representation metadata support
61
- - 🏷️ **MIME Type Support** - 80+ types with proper extensions
62
- - 🌍 **Multilingual** - Language and encoding metadata
63
-
64
- ## Documentation
65
-
66
- - [API Reference](./docs/API.md) - Complete API documentation
67
- - [Architecture](./docs/ARCHITECTURE.md) - Design principles
68
- - [Patterns](./docs/PATTERNS.md) - Usage patterns and best practices
69
-
70
- ## Examples
71
-
72
- - [Basic Example](./examples/basic.ts) - Storage and retrieval
73
- - [Deduplication](./examples/deduplication.ts) - Content addressing benefits
74
- - [Binary Content](./examples/binary.ts) - Images and documents
75
-
76
- ## Storage Architecture
77
-
78
- ### Content Addressing
79
-
80
- Every piece of content is addressed by its SHA-256 checksum:
81
-
82
- ```typescript
83
- const checksum = calculateChecksum(content);
84
- // sha256:5aaa0b72c1f4d8e7a9f2c8b3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3
85
- ```
86
-
87
- ### Storage Path Structure
88
-
89
- In a semiont project, `basePath` is the project root (the directory containing
90
- `.semiont/`). The `representations/` directory is committed to version control —
91
- it is the durable content store for the project.
55
+ The working tree (project root) is the source of truth for file content. Resources are identified by their `file://` URI, which is stable across content changes; moves are tracked by events.
92
56
 
93
57
  ```
94
- my-project/ basePath (project root)
95
- └── representations/
96
- └── {mediaType}/ # URL-encoded MIME type
97
- └── {ab}/ # First 2 hex chars of checksum
98
- └── {cd}/ # Next 2 hex chars (65,536 shards)
99
- └── rep-{checksum}.{ext}
58
+ my-project/ ← project root
59
+ ├── .semiont/ ← project config and event log
60
+ └── docs/
61
+ └── overview.md ← storageUri "file://docs/overview.md"
100
62
  ```
101
63
 
102
- Example paths:
103
- ```
104
- representations/text~1plain/5a/aa/rep-5aaa0b72...abc.txt
105
- representations/image~1png/ff/12/rep-ff123456...def.png
106
- representations/application~1json/ab/cd/rep-abcd1234...123.json
107
- ```
64
+ There are two write paths:
108
65
 
109
- ### Deduplication
66
+ - **`store(content, storageUri)`** — write bytes to disk. Used when the file does not yet exist and the caller provides content (API/GUI/AI path).
67
+ - **`register(storageUri, expectedChecksum?)`** — read an existing file and record its metadata (CLI path). If `expectedChecksum` is provided and does not match, throws `ChecksumMismatchError`.
110
68
 
111
- Content-addressed storage provides automatic deduplication:
69
+ Both return the same metadata:
112
70
 
113
71
  ```typescript
114
- // Store same content 100 times
115
- for (let i = 0; i < 100; i++) {
116
- await store.store(identicalContent, metadata);
72
+ interface StoredResource {
73
+ storageUri: string; // file:// URI (e.g. "file://docs/overview.md")
74
+ checksum: string; // SHA-256 hex of content
75
+ byteSize: number; // Size in bytes
76
+ created: string; // ISO 8601 timestamp
117
77
  }
118
- // Result: Only ONE file on disk
119
78
  ```
120
79
 
121
- ## API Overview
80
+ ### Git Integration
122
81
 
123
- ### FilesystemRepresentationStore
82
+ When the project has `[git] sync = true` in `.semiont/config`, the store keeps the git index up to date automatically:
124
83
 
125
- ```typescript
126
- const store = new FilesystemRepresentationStore({
127
- basePath: '/data/storage' // Root storage directory
128
- });
129
- ```
84
+ - `store()` / `register()` run `git add`
85
+ - `move()` runs `git mv`
86
+ - `remove()` runs `git rm` (or `git rm --cached` with `keepFile: true`)
130
87
 
131
- ### Store Content
88
+ Every method accepts `{ noGit: true }` to skip staging for a single call. Without git sync, the store falls back to plain filesystem operations.
132
89
 
133
- ```typescript
134
- const stored = await store.store(
135
- content: Buffer,
136
- metadata: {
137
- mediaType: string; // Required: MIME type
138
- filename?: string; // Optional: Original filename
139
- encoding?: string; // Optional: Character encoding
140
- language?: string; // Optional: ISO language code
141
- rel?: string; // Optional: Relationship type
142
- }
143
- ): Promise<StoredRepresentation>
144
- ```
90
+ ## PDF Text-Layer Extraction
145
91
 
146
- ### Retrieve Content
92
+ For native (non-scanned) PDFs, `extractPdfTextLayer()` extracts positioned text using [pdfjs-dist](https://www.npmjs.com/package/pdfjs-dist). It returns `null` for scanned/image-only PDFs.
147
93
 
148
94
  ```typescript
149
- const buffer = await store.retrieve(
150
- checksum: string, // SHA-256 checksum
151
- mediaType: string // MIME type for path lookup
152
- ): Promise<Buffer>
153
- ```
95
+ import { extractPdfTextLayer, locate } from '@semiont/content';
154
96
 
155
- ### Types
97
+ const layer = await extractPdfTextLayer(pdfBytes);
98
+ if (layer) {
99
+ console.log(layer.text); // Full extracted text
100
+ console.log(layer.pages.length); // Page dimensions in PDF points
156
101
 
157
- ```typescript
158
- interface StoredRepresentation {
159
- '@id': string; // Content URI
160
- checksum: string; // SHA-256 hex (64 chars)
161
- byteSize: number; // Content size in bytes
162
- mediaType: string; // MIME type
163
- created: string; // ISO 8601 timestamp
164
- language?: string; // ISO language code
165
- encoding?: string; // Character encoding
166
- rel?: string; // Relationship type
102
+ // Find bounding rectangles for a span of the text (one per line)
103
+ const rects = locate(layer, 120, 178);
104
+ // => PdfCoordinate[] in PDF point space (origin: bottom-left)
167
105
  }
168
106
  ```
169
107
 
170
- ## Supported MIME Types
171
-
172
- The package includes 80+ MIME type mappings:
108
+ Coordinates are in PDF point space, originating from the bottom-left of the page. The Y-flip to canvas pixels happens downstream in the browser; the server has no canvas. The `PdfCoordinate` geometry type lives in `@semiont/core` alongside the viewrect FragmentSelector codec.
173
109
 
174
- | Type | Extensions | Example |
175
- |------|-----------|---------|
176
- | Text | `.txt`, `.md`, `.html`, `.csv` | `text/plain` → `.txt` |
177
- | Documents | `.pdf`, `.doc`, `.docx` | `application/pdf` → `.pdf` |
178
- | Images | `.png`, `.jpg`, `.gif`, `.webp` | `image/png` → `.png` |
179
- | Audio | `.mp3`, `.wav`, `.ogg` | `audio/mpeg` → `.mp3` |
180
- | Video | `.mp4`, `.webm`, `.mov` | `video/mp4` → `.mp4` |
181
- | Code | `.js`, `.ts`, `.py`, `.java` | `text/javascript` → `.js` |
182
- | Data | `.json`, `.xml`, `.yaml` | `application/json` → `.json` |
183
-
184
- Unknown types default to `.dat` extension.
185
-
186
- ## W3C Compliance
187
-
188
- Full support for W3C representation metadata:
110
+ ## Utilities
189
111
 
190
112
  ```typescript
191
- const stored = await store.store(content, {
192
- mediaType: 'text/html',
193
- language: 'en-US',
194
- encoding: 'UTF-8',
195
- rel: 'original'
196
- });
197
-
198
- // W3C-compliant metadata
199
- {
200
- "@id": "urn:sha256:abc123...",
201
- "@type": "Representation",
202
- "checksum": "sha256:abc123...",
203
- "mediaType": "text/html",
204
- "language": "en-US",
205
- "encoding": "UTF-8",
206
- "rel": "original",
207
- "byteSize": 1234,
208
- "created": "2024-01-01T00:00:00Z"
209
- }
113
+ import {
114
+ calculateChecksum, // SHA-256 hex of a string or Buffer
115
+ verifyChecksum, // Compare content against an expected checksum
116
+ deriveStorageUri, // ("My Doc", "text/markdown") → "file://my-doc.md"
117
+ } from '@semiont/content';
210
118
  ```
211
119
 
212
- ## Performance
120
+ `deriveStorageUri` takes a `SupportedMediaType`; the media-type registry —
121
+ which types are admitted, their extensions, and their capabilities — lives in
122
+ [@semiont/core](../core/)'s `media-types.ts`. See [docs/mime-types.md](./docs/mime-types.md).
213
123
 
214
- - **SHA-256 Calculation**: ~500 MB/s on modern CPUs
215
- - **Write Performance**: Limited by filesystem (typically ~100 MB/s)
216
- - **Read Performance**: O(1) direct path lookup
217
- - **Sharding**: 65,536 directories prevent filesystem bottlenecks
218
- - **Deduplication**: 100% space savings for duplicate content
219
-
220
- ## Best Practices
221
-
222
- 1. **Use Buffers**: Always pass content as Buffer for binary safety
223
- 2. **Specify MIME Types**: Required for proper file extensions
224
- 3. **Add Language Metadata**: Important for multilingual content
225
- 4. **Handle Missing Content**: Check existence before retrieval
226
- 5. **Monitor Storage**: Track disk usage and shard distribution
227
-
228
- ## Error Handling
124
+ ## Documentation
229
125
 
230
- ```typescript
231
- try {
232
- const retrieved = await store.retrieve(checksum, mediaType);
233
- } catch (error) {
234
- if (error.code === 'ENOENT') {
235
- // Content not found
236
- } else if (error.code === 'EACCES') {
237
- // Permission denied
238
- } else {
239
- // Other filesystem error
240
- }
241
- }
242
- ```
126
+ - [API Reference](./docs/API.md) - Complete API documentation
127
+ - [Architecture](./docs/architecture.md) - Design principles
243
128
 
244
129
  ## Development
245
130
 
@@ -259,4 +144,4 @@ npm run typecheck
259
144
 
260
145
  ## License
261
146
 
262
- Apache-2.0
147
+ Apache-2.0
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SemiontProject } from '@semiont/core/node';
2
- import { Logger } from '@semiont/core';
2
+ import { Logger, SupportedMediaType, PdfCoordinate } from '@semiont/core';
3
3
 
4
4
  /**
5
5
  * WorkingTreeStore - Manages files in the project working tree
@@ -129,37 +129,24 @@ declare class ChecksumMismatchError extends Error {
129
129
  }
130
130
 
131
131
  /**
132
- * MIME Type to File Extension Mapping
132
+ * Storage URI Derivation
133
133
  *
134
- * Maps common MIME types to their standard file extensions.
135
- * Used by RepresentationStore to save files with proper extensions.
134
+ * Builds the file:// URI a resource lives at in the working tree from its
135
+ * name and validated media type. Extensions come from the media-type
136
+ * registry in @semiont/core; formats are validated upstream at the
137
+ * create/yield boundary, so the lookup is strict — no fallback.
136
138
  */
139
+
137
140
  /**
138
- * Get file extension for a MIME type
139
- *
140
- * @param mediaType - MIME type (e.g., "text/markdown")
141
- * @returns File extension with leading dot (e.g., ".md") or ".dat" if unknown
141
+ * Derive a file:// storage URI from a resource name and media type.
142
142
  *
143
- * @example
144
- * getExtensionForMimeType('text/markdown') // => '.md'
145
- * getExtensionForMimeType('image/png') // => '.png'
146
- * getExtensionForMimeType('unknown/type') // => '.dat'
147
- */
148
- declare function getExtensionForMimeType(mediaType: string): string;
149
- /**
150
- * Derive a file:// storage URI from a resource name and MIME type.
143
+ * The name is lowercased, runs of non-alphanumeric characters collapse to
144
+ * single hyphens, and leading/trailing hyphens are stripped.
151
145
  *
152
146
  * @example
153
147
  * deriveStorageUri("My Document", "text/markdown") // => "file://my-document.md"
154
148
  */
155
- declare function deriveStorageUri(name: string, format: string): string;
156
- /**
157
- * Check if a MIME type has a known extension mapping
158
- *
159
- * @param mediaType - MIME type to check
160
- * @returns true if extension is known, false if would fallback to .dat
161
- */
162
- declare function hasKnownExtension(mediaType: string): boolean;
149
+ declare function deriveStorageUri(name: string, format: SupportedMediaType): string;
163
150
 
164
151
  /**
165
152
  * Checksum utilities for content verification
@@ -178,5 +165,70 @@ declare function calculateChecksum(content: string | Buffer): string;
178
165
  */
179
166
  declare function verifyChecksum(content: string | Buffer, checksum: string): boolean;
180
167
 
181
- export { ChecksumMismatchError, WorkingTreeStore, calculateChecksum, deriveStorageUri, getExtensionForMimeType, hasKnownExtension, verifyChecksum };
182
- export type { StoredResource };
168
+ /**
169
+ * PDF Text Layer Types
170
+ *
171
+ * Represents the extracted text layer from a native PDF, including per-run (word-level)
172
+ * geometry in PDF point coordinates originating from the bottom-left of the page
173
+ * (Y increases upward). The Y-flip to canvas pixels happens downstream in the
174
+ * browser; the server has no canvas.
175
+ *
176
+ * `PdfCoordinate` — the geometry `locate()` emits — lives in `@semiont/core`
177
+ * alongside the viewrect FragmentSelector codec.
178
+ */
179
+ /**
180
+ * A single text item (one text run, roughly a word) from the PDF text layer.
181
+ * Character offsets refer to positions in `PdfTextLayer.text`.
182
+ */
183
+ interface PdfTextItem {
184
+ start: number;
185
+ end: number;
186
+ page: number;
187
+ x: number;
188
+ y: number;
189
+ width: number;
190
+ height: number;
191
+ }
192
+ /** Page dimensions in PDF points */
193
+ interface PdfPageInfo {
194
+ pageNumber: number;
195
+ widthPt: number;
196
+ heightPt: number;
197
+ }
198
+ /**
199
+ * The full extracted text layer for a PDF.
200
+ * `text` is the reading-order concatenation across all pages.
201
+ * Each `item` is one text run carrying its character range into `text` plus PDF-point geometry.
202
+ */
203
+ interface PdfTextLayer {
204
+ pages: PdfPageInfo[];
205
+ text: string;
206
+ items: PdfTextItem[];
207
+ }
208
+
209
+ /**
210
+ * PDF Text Layer Extraction
211
+ *
212
+ * Extracts positioned text from native, non-scanned PDFs using pdfjs-dist.
213
+ * Returns null for scanned/image-only PDFs (no text items).
214
+ *
215
+ * Coordinates are in PDF point space, originating from the bottom-left.
216
+ * The Y-flip to canvas pixels happens downstream.
217
+ */
218
+
219
+ declare function extractPdfTextLayer(bytes: Uint8Array | Buffer): Promise<PdfTextLayer | null>;
220
+
221
+ /**
222
+ * Locates bounding rectangles for a span of text in a PdfTextLayer
223
+ * (single-line or multi-line).
224
+ *
225
+ * Finds all overlapping items [start, end), groups them by page and line,
226
+ * and records one bounding rectangle per line as a PdfCoordinate.
227
+ *
228
+ * Returns array of PdfCoordinate, one per line of text covered by the span.
229
+ * Returns empty array if no items overlap the span.
230
+ */
231
+ declare function locate(layer: PdfTextLayer, start: number, end: number): PdfCoordinate[];
232
+
233
+ export { ChecksumMismatchError, WorkingTreeStore, calculateChecksum, deriveStorageUri, extractPdfTextLayer, locate, verifyChecksum };
234
+ export type { PdfPageInfo, PdfTextItem, PdfTextLayer, StoredResource };
package/dist/index.js CHANGED
@@ -190,105 +190,122 @@ The file on disk differs from the recorded checksum. Has it been modified since
190
190
  this.actual = actual;
191
191
  this.name = "ChecksumMismatchError";
192
192
  }
193
+ storageUri;
194
+ expected;
195
+ actual;
193
196
  };
194
197
 
195
- // src/mime-extensions.ts
196
- var MIME_TO_EXTENSION = {
197
- // Text formats
198
- "text/plain": ".txt",
199
- "text/markdown": ".md",
200
- "text/html": ".html",
201
- "text/css": ".css",
202
- "text/csv": ".csv",
203
- "text/xml": ".xml",
204
- // Application formats - structured data
205
- "application/json": ".json",
206
- "application/xml": ".xml",
207
- "application/yaml": ".yaml",
208
- "application/x-yaml": ".yaml",
209
- // Application formats - documents
210
- "application/pdf": ".pdf",
211
- "application/msword": ".doc",
212
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx",
213
- "application/vnd.ms-excel": ".xls",
214
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ".xlsx",
215
- "application/vnd.ms-powerpoint": ".ppt",
216
- "application/vnd.openxmlformats-officedocument.presentationml.presentation": ".pptx",
217
- // Application formats - archives
218
- "application/zip": ".zip",
219
- "application/gzip": ".gz",
220
- "application/x-tar": ".tar",
221
- "application/x-7z-compressed": ".7z",
222
- // Application formats - executables/binaries
223
- "application/octet-stream": ".bin",
224
- "application/wasm": ".wasm",
225
- // Image formats
226
- "image/png": ".png",
227
- "image/jpeg": ".jpg",
228
- "image/gif": ".gif",
229
- "image/webp": ".webp",
230
- "image/svg+xml": ".svg",
231
- "image/bmp": ".bmp",
232
- "image/tiff": ".tiff",
233
- "image/x-icon": ".ico",
234
- // Audio formats
235
- "audio/mpeg": ".mp3",
236
- "audio/wav": ".wav",
237
- "audio/ogg": ".ogg",
238
- "audio/webm": ".webm",
239
- "audio/aac": ".aac",
240
- "audio/flac": ".flac",
241
- // Video formats
242
- "video/mp4": ".mp4",
243
- "video/mpeg": ".mpeg",
244
- "video/webm": ".webm",
245
- "video/ogg": ".ogv",
246
- "video/quicktime": ".mov",
247
- "video/x-msvideo": ".avi",
248
- // Programming languages
249
- "text/javascript": ".js",
250
- "application/javascript": ".js",
251
- "text/x-typescript": ".ts",
252
- "application/typescript": ".ts",
253
- "text/x-python": ".py",
254
- "text/x-java": ".java",
255
- "text/x-c": ".c",
256
- "text/x-c++": ".cpp",
257
- "text/x-csharp": ".cs",
258
- "text/x-go": ".go",
259
- "text/x-rust": ".rs",
260
- "text/x-ruby": ".rb",
261
- "text/x-php": ".php",
262
- "text/x-swift": ".swift",
263
- "text/x-kotlin": ".kt",
264
- "text/x-shell": ".sh",
265
- // Font formats
266
- "font/woff": ".woff",
267
- "font/woff2": ".woff2",
268
- "font/ttf": ".ttf",
269
- "font/otf": ".otf"
270
- };
271
- function getExtensionForMimeType(mediaType) {
272
- const normalized = mediaType.toLowerCase().split(";")[0].trim();
273
- const extension = MIME_TO_EXTENSION[normalized];
274
- return extension || ".dat";
275
- }
198
+ // src/storage-uri.ts
199
+ import { MEDIA_TYPES } from "@semiont/core";
276
200
  function deriveStorageUri(name, format) {
277
201
  const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
278
- const ext = getExtensionForMimeType(format);
279
- return `file://${slug}${ext}`;
202
+ return `file://${slug}${MEDIA_TYPES[format].extension}`;
203
+ }
204
+
205
+ // src/extract-pdf-text-layer.ts
206
+ import * as pdfjs from "pdfjs-dist/legacy/build/pdf.mjs";
207
+ async function extractPdfTextLayer(bytes) {
208
+ const doc = await pdfjs.getDocument({ data: bytes }).promise;
209
+ try {
210
+ const pages = [];
211
+ const items = [];
212
+ let text = "";
213
+ let hasAnyTextItems = false;
214
+ for (let pageNum = 1; pageNum <= doc.numPages; pageNum++) {
215
+ const page = await doc.getPage(pageNum);
216
+ const viewport = page.getViewport({ scale: 1 });
217
+ const content = await page.getTextContent();
218
+ pages.push({
219
+ pageNumber: pageNum,
220
+ widthPt: viewport.width,
221
+ heightPt: viewport.height
222
+ });
223
+ for (const item of content.items) {
224
+ if (!("str" in item)) continue;
225
+ if (item.str.trim()) {
226
+ hasAnyTextItems = true;
227
+ const start = text.length;
228
+ text += item.str;
229
+ const end = text.length;
230
+ const [, , , , x, y] = item.transform;
231
+ items.push({
232
+ start,
233
+ end,
234
+ page: pageNum,
235
+ x,
236
+ y,
237
+ width: item.width,
238
+ height: item.height
239
+ });
240
+ text += item.hasEOL ? "\n" : " ";
241
+ } else if (item.hasEOL) {
242
+ text += "\n";
243
+ }
244
+ }
245
+ text += "\n";
246
+ }
247
+ if (!hasAnyTextItems) return null;
248
+ return { pages, text, items };
249
+ } finally {
250
+ await doc.destroy();
251
+ }
252
+ }
253
+
254
+ // src/locate.ts
255
+ var SAME_LINE_THRESHOLD_PT = 2;
256
+ function locate(layer, start, end) {
257
+ const overlap = layer.items.filter(
258
+ (item) => item.start < end && item.end > start
259
+ );
260
+ if (overlap.length === 0) return [];
261
+ const pages = groupItemsByPage(overlap);
262
+ const rects = [];
263
+ for (const [page, pageItems] of pages) {
264
+ const lines = groupItemsByLine(pageItems, SAME_LINE_THRESHOLD_PT);
265
+ for (const lineItems of lines) {
266
+ const x = Math.min(...lineItems.map((i) => i.x));
267
+ const right = Math.max(...lineItems.map((i) => i.x + i.width));
268
+ const y = Math.min(...lineItems.map((i) => i.y));
269
+ const top = Math.max(...lineItems.map((i) => i.y + i.height));
270
+ rects.push({ page, x, y, width: right - x, height: top - y });
271
+ }
272
+ }
273
+ return rects;
280
274
  }
281
- function hasKnownExtension(mediaType) {
282
- const normalized = mediaType.toLowerCase().split(";")[0].trim();
283
- return normalized in MIME_TO_EXTENSION;
275
+ function groupItemsByPage(items) {
276
+ const map = /* @__PURE__ */ new Map();
277
+ for (const item of items) {
278
+ const existing = map.get(item.page);
279
+ if (existing) {
280
+ existing.push(item);
281
+ } else {
282
+ map.set(item.page, [item]);
283
+ }
284
+ }
285
+ return map;
286
+ }
287
+ function groupItemsByLine(items, sameLineThreshold) {
288
+ const sorted = [...items].sort((a, b) => b.y - a.y || a.x - b.x);
289
+ const lines = [];
290
+ let currentLine = [];
291
+ for (const item of sorted) {
292
+ if (currentLine.length === 0 || Math.abs(item.y - currentLine[0].y) <= sameLineThreshold) {
293
+ currentLine.push(item);
294
+ } else {
295
+ lines.push(currentLine);
296
+ currentLine = [item];
297
+ }
298
+ }
299
+ if (currentLine.length > 0) lines.push(currentLine);
300
+ return lines;
284
301
  }
285
302
  export {
286
303
  ChecksumMismatchError,
287
304
  WorkingTreeStore,
288
305
  calculateChecksum,
289
306
  deriveStorageUri,
290
- getExtensionForMimeType,
291
- hasKnownExtension,
307
+ extractPdfTextLayer,
308
+ locate,
292
309
  verifyChecksum
293
310
  };
294
311
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/working-tree-store.ts","../src/checksum.ts","../src/mime-extensions.ts"],"sourcesContent":["/**\n * WorkingTreeStore - Manages files in the project working tree\n *\n * Unlike the old content-addressed RepresentationStore, this store treats\n * the working tree (project root) as the source of truth for file content.\n * Resources are identified by their file:// URI, which is stable across\n * content changes and moves (tracked by events).\n *\n * Two write paths:\n * - store(content, storageUri): Write bytes to disk (API/GUI/AI path).\n * Used when the file does not yet exist and the caller provides content.\n * - register(storageUri, expectedChecksum?): Read an existing file and\n * return its metadata (CLI path). The file is already on disk; we just\n * verify and record it. If expectedChecksum is provided, throws on mismatch.\n *\n * Storage layout:\n * {projectRoot}/{path-from-uri}\n *\n * For example, storageUri \"file://docs/overview.md\" resolves to\n * {projectRoot}/docs/overview.md\n */\n\nimport { promises as fs } from 'fs';\nimport { execFileSync } from 'child_process';\nimport path from 'path';\nimport type { SemiontProject } from '@semiont/core/node';\nimport type { Logger } from '@semiont/core';\nimport { calculateChecksum, verifyChecksum } from './checksum';\n\n/**\n * Result of store() or register()\n */\nexport interface StoredResource {\n storageUri: string; // file:// URI (e.g. \"file://docs/overview.md\")\n checksum: string; // SHA-256 hex of content\n byteSize: number; // Size in bytes\n created: string; // ISO 8601 timestamp\n}\n\n/**\n * Manages files in the project working tree\n */\nexport class WorkingTreeStore {\n private projectRoot: string;\n private gitSync: boolean;\n private logger?: Logger;\n\n constructor(project: SemiontProject, logger?: Logger) {\n this.projectRoot = project.root;\n this.gitSync = project.gitSync;\n this.logger = logger;\n }\n\n private shouldRunGit(noGit?: boolean): boolean {\n return this.gitSync && !noGit;\n }\n\n /**\n * Write content to disk at the location indicated by storageUri.\n *\n * API/GUI/AI path: caller provides bytes; file may not yet exist.\n *\n * @param content - Raw bytes to write\n * @param storageUri - file:// URI (e.g. \"file://docs/overview.md\")\n * @returns Stored resource metadata\n */\n async store(content: Buffer, storageUri: string, options?: { noGit?: boolean }): Promise<StoredResource> {\n const filePath = this.resolveUri(storageUri);\n const checksum = calculateChecksum(content);\n\n this.logger?.debug('Storing resource', { storageUri, byteSize: content.length });\n\n await fs.mkdir(path.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, content);\n\n if (this.shouldRunGit(options?.noGit)) {\n execFileSync('git', ['add', filePath], { cwd: this.projectRoot });\n }\n\n this.logger?.info('Resource stored', { storageUri, checksum, byteSize: content.length });\n\n return {\n storageUri,\n checksum,\n byteSize: content.length,\n created: new Date().toISOString(),\n };\n }\n\n /**\n * Read an existing file and return its metadata.\n *\n * CLI path: the file is already on disk. We read it to compute the checksum.\n * If expectedChecksum is provided, throws ChecksumMismatchError on mismatch.\n *\n * @param storageUri - file:// URI (e.g. \"file://docs/overview.md\")\n * @param expectedChecksum - Optional SHA-256 to verify against\n * @returns Stored resource metadata\n * @throws ChecksumMismatchError if expectedChecksum is provided and does not match\n * @throws Error if file does not exist\n */\n async register(storageUri: string, expectedChecksum?: string, options?: { noGit?: boolean }): Promise<StoredResource> {\n const filePath = this.resolveUri(storageUri);\n\n this.logger?.debug('Registering resource', { storageUri });\n\n const content = await fs.readFile(filePath);\n const checksum = calculateChecksum(content);\n\n if (expectedChecksum !== undefined && !verifyChecksum(content, expectedChecksum)) {\n throw new ChecksumMismatchError(storageUri, expectedChecksum, checksum);\n }\n\n if (this.shouldRunGit(options?.noGit)) {\n execFileSync('git', ['add', filePath], { cwd: this.projectRoot });\n }\n\n this.logger?.info('Resource registered', { storageUri, checksum, byteSize: content.length });\n\n return {\n storageUri,\n checksum,\n byteSize: content.length,\n created: new Date().toISOString(),\n };\n }\n\n /**\n * Read file content by URI.\n *\n * @param storageUri - file:// URI\n * @returns Raw bytes\n */\n async retrieve(storageUri: string): Promise<Buffer> {\n const filePath = this.resolveUri(storageUri);\n try {\n return await fs.readFile(filePath);\n } catch (error: any) {\n if (error.code === 'ENOENT') {\n throw new Error(`Resource not found: ${storageUri}`);\n }\n throw error;\n }\n }\n\n /**\n * Move a file from one URI to another.\n *\n * If .git/ exists in the project root and noGit is not set, runs `git mv`.\n * Otherwise (no .git/ or noGit: true), runs fs.rename.\n *\n * @param fromUri - Current file:// URI\n * @param toUri - New file:// URI\n * @param options.noGit - Skip git mv even if .git/ is present\n */\n async move(fromUri: string, toUri: string, options?: { noGit?: boolean }): Promise<void> {\n const fromPath = this.resolveUri(fromUri);\n const toPath = this.resolveUri(toUri);\n\n this.logger?.debug('Moving resource', { fromUri, toUri });\n\n await fs.mkdir(path.dirname(toPath), { recursive: true });\n\n if (this.shouldRunGit(options?.noGit)) {\n // git mv handles both the filesystem rename and the index update\n execFileSync('git', ['mv', fromPath, toPath], { cwd: this.projectRoot });\n } else {\n await fs.rename(fromPath, toPath);\n }\n\n this.logger?.info('Resource moved', { fromUri, toUri });\n }\n\n /**\n * Remove a file from the working tree.\n *\n * If .git/ exists and noGit is not set:\n * - keepFile false (default): runs `git rm` (removes from index and disk)\n * - keepFile true: runs `git rm --cached` (removes from index only, file stays on disk)\n * If no .git/ or noGit: true:\n * - keepFile false: runs fs.unlink\n * - keepFile true: no-op on filesystem\n *\n * @param storageUri - file:// URI\n * @param options.noGit - Skip git rm even if .git/ is present\n * @param options.keepFile - Remove from git index only; leave file on disk\n */\n async remove(storageUri: string, options?: { noGit?: boolean; keepFile?: boolean }): Promise<void> {\n const filePath = this.resolveUri(storageUri);\n const keepFile = options?.keepFile ?? false;\n\n this.logger?.debug('Removing resource', { storageUri, keepFile });\n\n const useGit = this.shouldRunGit(options?.noGit);\n\n if (useGit) {\n const gitArgs = keepFile\n ? ['rm', '--cached', filePath]\n : ['rm', filePath];\n execFileSync('git', gitArgs, { cwd: this.projectRoot });\n this.logger?.info('Resource removed', { storageUri, keepFile, git: true });\n return;\n }\n\n if (keepFile) {\n this.logger?.info('Resource removed from index (file kept on disk)', { storageUri });\n return;\n }\n\n try {\n await fs.unlink(filePath);\n this.logger?.info('Resource removed', { storageUri });\n } catch (error: any) {\n if (error.code === 'ENOENT') {\n this.logger?.warn('Resource file already absent', { storageUri });\n return;\n }\n throw error;\n }\n }\n\n /**\n * Convert a file:// URI to an absolute filesystem path.\n *\n * \"file://docs/overview.md\" → \"{projectRoot}/docs/overview.md\"\n *\n * @param storageUri - file:// URI\n * @returns Absolute path\n */\n resolveUri(storageUri: string): string {\n if (!storageUri.startsWith('file://')) {\n throw new Error(`Invalid storage URI (must start with file://): ${storageUri}`);\n }\n const relativePath = storageUri.slice('file://'.length);\n return path.join(this.projectRoot, relativePath);\n }\n}\n\n/**\n * Thrown when a registered file's checksum does not match the expected value.\n * This indicates the file on disk differs from what was recorded (e.g. modified\n * after staging, or wrong file path provided).\n */\nexport class ChecksumMismatchError extends Error {\n constructor(\n readonly storageUri: string,\n readonly expected: string,\n readonly actual: string,\n ) {\n super(\n `Checksum mismatch for ${storageUri}: expected ${expected.slice(0, 8)}... but got ${actual.slice(0, 8)}...\\n` +\n `The file on disk differs from the recorded checksum. Has it been modified since staging?`\n );\n this.name = 'ChecksumMismatchError';\n }\n}\n","/**\n * Checksum utilities for content verification\n */\n\nimport { createHash } from 'crypto';\n\n/**\n * Calculate SHA-256 checksum of content\n * @param content The content to hash\n * @returns Hex-encoded SHA-256 hash\n */\nexport function calculateChecksum(content: string | Buffer): string {\n const hash = createHash('sha256');\n hash.update(content);\n return hash.digest('hex');\n}\n\n/**\n * Verify content against a checksum\n * @param content The content to verify\n * @param checksum The expected checksum\n * @returns True if content matches checksum\n */\nexport function verifyChecksum(content: string | Buffer, checksum: string): boolean {\n return calculateChecksum(content) === checksum;\n}\n","/**\n * MIME Type to File Extension Mapping\n *\n * Maps common MIME types to their standard file extensions.\n * Used by RepresentationStore to save files with proper extensions.\n */\n\n/**\n * Comprehensive MIME type to extension mapping\n */\nconst MIME_TO_EXTENSION: Record<string, string> = {\n // Text formats\n 'text/plain': '.txt',\n 'text/markdown': '.md',\n 'text/html': '.html',\n 'text/css': '.css',\n 'text/csv': '.csv',\n 'text/xml': '.xml',\n\n // Application formats - structured data\n 'application/json': '.json',\n 'application/xml': '.xml',\n 'application/yaml': '.yaml',\n 'application/x-yaml': '.yaml',\n\n // Application formats - documents\n 'application/pdf': '.pdf',\n 'application/msword': '.doc',\n 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': '.docx',\n 'application/vnd.ms-excel': '.xls',\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': '.xlsx',\n 'application/vnd.ms-powerpoint': '.ppt',\n 'application/vnd.openxmlformats-officedocument.presentationml.presentation': '.pptx',\n\n // Application formats - archives\n 'application/zip': '.zip',\n 'application/gzip': '.gz',\n 'application/x-tar': '.tar',\n 'application/x-7z-compressed': '.7z',\n\n // Application formats - executables/binaries\n 'application/octet-stream': '.bin',\n 'application/wasm': '.wasm',\n\n // Image formats\n 'image/png': '.png',\n 'image/jpeg': '.jpg',\n 'image/gif': '.gif',\n 'image/webp': '.webp',\n 'image/svg+xml': '.svg',\n 'image/bmp': '.bmp',\n 'image/tiff': '.tiff',\n 'image/x-icon': '.ico',\n\n // Audio formats\n 'audio/mpeg': '.mp3',\n 'audio/wav': '.wav',\n 'audio/ogg': '.ogg',\n 'audio/webm': '.webm',\n 'audio/aac': '.aac',\n 'audio/flac': '.flac',\n\n // Video formats\n 'video/mp4': '.mp4',\n 'video/mpeg': '.mpeg',\n 'video/webm': '.webm',\n 'video/ogg': '.ogv',\n 'video/quicktime': '.mov',\n 'video/x-msvideo': '.avi',\n\n // Programming languages\n 'text/javascript': '.js',\n 'application/javascript': '.js',\n 'text/x-typescript': '.ts',\n 'application/typescript': '.ts',\n 'text/x-python': '.py',\n 'text/x-java': '.java',\n 'text/x-c': '.c',\n 'text/x-c++': '.cpp',\n 'text/x-csharp': '.cs',\n 'text/x-go': '.go',\n 'text/x-rust': '.rs',\n 'text/x-ruby': '.rb',\n 'text/x-php': '.php',\n 'text/x-swift': '.swift',\n 'text/x-kotlin': '.kt',\n 'text/x-shell': '.sh',\n\n // Font formats\n 'font/woff': '.woff',\n 'font/woff2': '.woff2',\n 'font/ttf': '.ttf',\n 'font/otf': '.otf',\n};\n\n/**\n * Get file extension for a MIME type\n *\n * @param mediaType - MIME type (e.g., \"text/markdown\")\n * @returns File extension with leading dot (e.g., \".md\") or \".dat\" if unknown\n *\n * @example\n * getExtensionForMimeType('text/markdown') // => '.md'\n * getExtensionForMimeType('image/png') // => '.png'\n * getExtensionForMimeType('unknown/type') // => '.dat'\n */\nexport function getExtensionForMimeType(mediaType: string): string {\n // Normalize MIME type (lowercase, remove parameters)\n const normalized = mediaType.toLowerCase().split(';')[0]!.trim();\n\n // Look up in mapping\n const extension = MIME_TO_EXTENSION[normalized];\n\n // Return mapped extension or fallback to .dat\n return extension || '.dat';\n}\n\n/**\n * Derive a file:// storage URI from a resource name and MIME type.\n *\n * @example\n * deriveStorageUri(\"My Document\", \"text/markdown\") // => \"file://my-document.md\"\n */\nexport function deriveStorageUri(name: string, format: string): string {\n const slug = name\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-|-$/g, '');\n const ext = getExtensionForMimeType(format);\n return `file://${slug}${ext}`;\n}\n\n/**\n * Check if a MIME type has a known extension mapping\n *\n * @param mediaType - MIME type to check\n * @returns true if extension is known, false if would fallback to .dat\n */\nexport function hasKnownExtension(mediaType: string): boolean {\n const normalized = mediaType.toLowerCase().split(';')[0]!.trim();\n return normalized in MIME_TO_EXTENSION;\n}\n"],"mappings":";AAsBA,SAAS,YAAY,UAAU;AAC/B,SAAS,oBAAoB;AAC7B,OAAO,UAAU;;;ACpBjB,SAAS,kBAAkB;AAOpB,SAAS,kBAAkB,SAAkC;AAClE,QAAM,OAAO,WAAW,QAAQ;AAChC,OAAK,OAAO,OAAO;AACnB,SAAO,KAAK,OAAO,KAAK;AAC1B;AAQO,SAAS,eAAe,SAA0B,UAA2B;AAClF,SAAO,kBAAkB,OAAO,MAAM;AACxC;;;ADiBO,IAAM,mBAAN,MAAuB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,SAAyB,QAAiB;AACpD,SAAK,cAAc,QAAQ;AAC3B,SAAK,UAAU,QAAQ;AACvB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEQ,aAAa,OAA0B;AAC7C,WAAO,KAAK,WAAW,CAAC;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,MAAM,SAAiB,YAAoB,SAAwD;AACvG,UAAM,WAAW,KAAK,WAAW,UAAU;AAC3C,UAAM,WAAW,kBAAkB,OAAO;AAE1C,SAAK,QAAQ,MAAM,oBAAoB,EAAE,YAAY,UAAU,QAAQ,OAAO,CAAC;AAE/E,UAAM,GAAG,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AAC1D,UAAM,GAAG,UAAU,UAAU,OAAO;AAEpC,QAAI,KAAK,aAAa,SAAS,KAAK,GAAG;AACrC,mBAAa,OAAO,CAAC,OAAO,QAAQ,GAAG,EAAE,KAAK,KAAK,YAAY,CAAC;AAAA,IAClE;AAEA,SAAK,QAAQ,KAAK,mBAAmB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"sources":["../src/working-tree-store.ts","../src/checksum.ts","../src/storage-uri.ts","../src/extract-pdf-text-layer.ts","../src/locate.ts"],"sourcesContent":["/**\n * WorkingTreeStore - Manages files in the project working tree\n *\n * Unlike the old content-addressed RepresentationStore, this store treats\n * the working tree (project root) as the source of truth for file content.\n * Resources are identified by their file:// URI, which is stable across\n * content changes and moves (tracked by events).\n *\n * Two write paths:\n * - store(content, storageUri): Write bytes to disk (API/GUI/AI path).\n * Used when the file does not yet exist and the caller provides content.\n * - register(storageUri, expectedChecksum?): Read an existing file and\n * return its metadata (CLI path). The file is already on disk; we just\n * verify and record it. If expectedChecksum is provided, throws on mismatch.\n *\n * Storage layout:\n * {projectRoot}/{path-from-uri}\n *\n * For example, storageUri \"file://docs/overview.md\" resolves to\n * {projectRoot}/docs/overview.md\n */\n\nimport { promises as fs } from 'fs';\nimport { execFileSync } from 'child_process';\nimport path from 'path';\nimport type { SemiontProject } from '@semiont/core/node';\nimport type { Logger } from '@semiont/core';\nimport { calculateChecksum, verifyChecksum } from './checksum';\n\n/**\n * Result of store() or register()\n */\nexport interface StoredResource {\n storageUri: string; // file:// URI (e.g. \"file://docs/overview.md\")\n checksum: string; // SHA-256 hex of content\n byteSize: number; // Size in bytes\n created: string; // ISO 8601 timestamp\n}\n\n/**\n * Manages files in the project working tree\n */\nexport class WorkingTreeStore {\n private projectRoot: string;\n private gitSync: boolean;\n private logger?: Logger;\n\n constructor(project: SemiontProject, logger?: Logger) {\n this.projectRoot = project.root;\n this.gitSync = project.gitSync;\n this.logger = logger;\n }\n\n private shouldRunGit(noGit?: boolean): boolean {\n return this.gitSync && !noGit;\n }\n\n /**\n * Write content to disk at the location indicated by storageUri.\n *\n * API/GUI/AI path: caller provides bytes; file may not yet exist.\n *\n * @param content - Raw bytes to write\n * @param storageUri - file:// URI (e.g. \"file://docs/overview.md\")\n * @returns Stored resource metadata\n */\n async store(content: Buffer, storageUri: string, options?: { noGit?: boolean }): Promise<StoredResource> {\n const filePath = this.resolveUri(storageUri);\n const checksum = calculateChecksum(content);\n\n this.logger?.debug('Storing resource', { storageUri, byteSize: content.length });\n\n await fs.mkdir(path.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, content);\n\n if (this.shouldRunGit(options?.noGit)) {\n execFileSync('git', ['add', filePath], { cwd: this.projectRoot });\n }\n\n this.logger?.info('Resource stored', { storageUri, checksum, byteSize: content.length });\n\n return {\n storageUri,\n checksum,\n byteSize: content.length,\n created: new Date().toISOString(),\n };\n }\n\n /**\n * Read an existing file and return its metadata.\n *\n * CLI path: the file is already on disk. We read it to compute the checksum.\n * If expectedChecksum is provided, throws ChecksumMismatchError on mismatch.\n *\n * @param storageUri - file:// URI (e.g. \"file://docs/overview.md\")\n * @param expectedChecksum - Optional SHA-256 to verify against\n * @returns Stored resource metadata\n * @throws ChecksumMismatchError if expectedChecksum is provided and does not match\n * @throws Error if file does not exist\n */\n async register(storageUri: string, expectedChecksum?: string, options?: { noGit?: boolean }): Promise<StoredResource> {\n const filePath = this.resolveUri(storageUri);\n\n this.logger?.debug('Registering resource', { storageUri });\n\n const content = await fs.readFile(filePath);\n const checksum = calculateChecksum(content);\n\n if (expectedChecksum !== undefined && !verifyChecksum(content, expectedChecksum)) {\n throw new ChecksumMismatchError(storageUri, expectedChecksum, checksum);\n }\n\n if (this.shouldRunGit(options?.noGit)) {\n execFileSync('git', ['add', filePath], { cwd: this.projectRoot });\n }\n\n this.logger?.info('Resource registered', { storageUri, checksum, byteSize: content.length });\n\n return {\n storageUri,\n checksum,\n byteSize: content.length,\n created: new Date().toISOString(),\n };\n }\n\n /**\n * Read file content by URI.\n *\n * @param storageUri - file:// URI\n * @returns Raw bytes\n */\n async retrieve(storageUri: string): Promise<Buffer> {\n const filePath = this.resolveUri(storageUri);\n try {\n return await fs.readFile(filePath);\n } catch (error: any) {\n if (error.code === 'ENOENT') {\n throw new Error(`Resource not found: ${storageUri}`);\n }\n throw error;\n }\n }\n\n /**\n * Move a file from one URI to another.\n *\n * If .git/ exists in the project root and noGit is not set, runs `git mv`.\n * Otherwise (no .git/ or noGit: true), runs fs.rename.\n *\n * @param fromUri - Current file:// URI\n * @param toUri - New file:// URI\n * @param options.noGit - Skip git mv even if .git/ is present\n */\n async move(fromUri: string, toUri: string, options?: { noGit?: boolean }): Promise<void> {\n const fromPath = this.resolveUri(fromUri);\n const toPath = this.resolveUri(toUri);\n\n this.logger?.debug('Moving resource', { fromUri, toUri });\n\n await fs.mkdir(path.dirname(toPath), { recursive: true });\n\n if (this.shouldRunGit(options?.noGit)) {\n // git mv handles both the filesystem rename and the index update\n execFileSync('git', ['mv', fromPath, toPath], { cwd: this.projectRoot });\n } else {\n await fs.rename(fromPath, toPath);\n }\n\n this.logger?.info('Resource moved', { fromUri, toUri });\n }\n\n /**\n * Remove a file from the working tree.\n *\n * If .git/ exists and noGit is not set:\n * - keepFile false (default): runs `git rm` (removes from index and disk)\n * - keepFile true: runs `git rm --cached` (removes from index only, file stays on disk)\n * If no .git/ or noGit: true:\n * - keepFile false: runs fs.unlink\n * - keepFile true: no-op on filesystem\n *\n * @param storageUri - file:// URI\n * @param options.noGit - Skip git rm even if .git/ is present\n * @param options.keepFile - Remove from git index only; leave file on disk\n */\n async remove(storageUri: string, options?: { noGit?: boolean; keepFile?: boolean }): Promise<void> {\n const filePath = this.resolveUri(storageUri);\n const keepFile = options?.keepFile ?? false;\n\n this.logger?.debug('Removing resource', { storageUri, keepFile });\n\n const useGit = this.shouldRunGit(options?.noGit);\n\n if (useGit) {\n const gitArgs = keepFile\n ? ['rm', '--cached', filePath]\n : ['rm', filePath];\n execFileSync('git', gitArgs, { cwd: this.projectRoot });\n this.logger?.info('Resource removed', { storageUri, keepFile, git: true });\n return;\n }\n\n if (keepFile) {\n this.logger?.info('Resource removed from index (file kept on disk)', { storageUri });\n return;\n }\n\n try {\n await fs.unlink(filePath);\n this.logger?.info('Resource removed', { storageUri });\n } catch (error: any) {\n if (error.code === 'ENOENT') {\n this.logger?.warn('Resource file already absent', { storageUri });\n return;\n }\n throw error;\n }\n }\n\n /**\n * Convert a file:// URI to an absolute filesystem path.\n *\n * \"file://docs/overview.md\" → \"{projectRoot}/docs/overview.md\"\n *\n * @param storageUri - file:// URI\n * @returns Absolute path\n */\n resolveUri(storageUri: string): string {\n if (!storageUri.startsWith('file://')) {\n throw new Error(`Invalid storage URI (must start with file://): ${storageUri}`);\n }\n const relativePath = storageUri.slice('file://'.length);\n return path.join(this.projectRoot, relativePath);\n }\n}\n\n/**\n * Thrown when a registered file's checksum does not match the expected value.\n * This indicates the file on disk differs from what was recorded (e.g. modified\n * after staging, or wrong file path provided).\n */\nexport class ChecksumMismatchError extends Error {\n constructor(\n readonly storageUri: string,\n readonly expected: string,\n readonly actual: string,\n ) {\n super(\n `Checksum mismatch for ${storageUri}: expected ${expected.slice(0, 8)}... but got ${actual.slice(0, 8)}...\\n` +\n `The file on disk differs from the recorded checksum. Has it been modified since staging?`\n );\n this.name = 'ChecksumMismatchError';\n }\n}\n","/**\n * Checksum utilities for content verification\n */\n\nimport { createHash } from 'crypto';\n\n/**\n * Calculate SHA-256 checksum of content\n * @param content The content to hash\n * @returns Hex-encoded SHA-256 hash\n */\nexport function calculateChecksum(content: string | Buffer): string {\n const hash = createHash('sha256');\n hash.update(content);\n return hash.digest('hex');\n}\n\n/**\n * Verify content against a checksum\n * @param content The content to verify\n * @param checksum The expected checksum\n * @returns True if content matches checksum\n */\nexport function verifyChecksum(content: string | Buffer, checksum: string): boolean {\n return calculateChecksum(content) === checksum;\n}\n","/**\n * Storage URI Derivation\n *\n * Builds the file:// URI a resource lives at in the working tree from its\n * name and validated media type. Extensions come from the media-type\n * registry in @semiont/core; formats are validated upstream at the\n * create/yield boundary, so the lookup is strict — no fallback.\n */\n\nimport { MEDIA_TYPES, type SupportedMediaType } from '@semiont/core';\n\n/**\n * Derive a file:// storage URI from a resource name and media type.\n *\n * The name is lowercased, runs of non-alphanumeric characters collapse to\n * single hyphens, and leading/trailing hyphens are stripped.\n *\n * @example\n * deriveStorageUri(\"My Document\", \"text/markdown\") // => \"file://my-document.md\"\n */\nexport function deriveStorageUri(name: string, format: SupportedMediaType): string {\n const slug = name\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-|-$/g, '');\n return `file://${slug}${MEDIA_TYPES[format].extension}`;\n}\n","/**\n * PDF Text Layer Extraction\n *\n * Extracts positioned text from native, non-scanned PDFs using pdfjs-dist.\n * Returns null for scanned/image-only PDFs (no text items).\n *\n * Coordinates are in PDF point space, originating from the bottom-left.\n * The Y-flip to canvas pixels happens downstream.\n */\n\nimport * as pdfjs from 'pdfjs-dist/legacy/build/pdf.mjs';\nimport type { PdfTextLayer, PdfPageInfo, PdfTextItem } from './pdf-text-layer';\n\nexport async function extractPdfTextLayer(\n bytes: Uint8Array | Buffer\n): Promise<PdfTextLayer | null> {\n // pdf.js v5 removed the isEvalSupported option; this path only calls\n // getTextContent (no rendering / no PDF functions).\n const doc = await pdfjs.getDocument({ data: bytes }).promise;\n\n try {\n const pages: PdfPageInfo[] = [];\n const items: PdfTextItem[] = [];\n let text = '';\n let hasAnyTextItems = false;\n\n for (let pageNum = 1; pageNum <= doc.numPages; pageNum++) {\n const page = await doc.getPage(pageNum);\n const viewport = page.getViewport({ scale: 1.0 });\n const content = await page.getTextContent(); // all text items on the page\n\n pages.push({\n pageNumber: pageNum,\n widthPt: viewport.width,\n heightPt: viewport.height,\n });\n\n for (const item of content.items) {\n if (!('str' in item)) continue; // skip marked-content items (no text)\n\n if (item.str.trim()) {\n hasAnyTextItems = true;\n const start = text.length;\n text += item.str;\n const end = text.length; // range covers only this run's own chars\n\n const [, , , , x, y] = item.transform as number[];\n\n items.push({\n start,\n end,\n page: pageNum,\n x,\n y,\n width: item.width,\n height: item.height,\n });\n\n // Separator AFTER recording the run, so its [start, end) never\n // includes it. pdf.js flags the last run on a line with hasEOL —\n // newline there, space between words otherwise, so reading-order\n // lines don't glue (e.g. \"textsecond\").\n text += item.hasEOL ? '\\n' : ' ';\n } else if (item.hasEOL) {\n // Standalone end-of-line marker (empty/whitespace str): keep the\n // line break without letting whitespace-only runs add stray spaces.\n text += '\\n';\n }\n }\n\n text += '\\n'; // page break\n }\n\n if (!hasAnyTextItems) return null;\n\n return { pages, text, items };\n } finally {\n // Release the pdf.js document — Phase 2 runs this in a long-lived worker pool.\n await doc.destroy();\n }\n}\n","import type { PdfCoordinate } from '@semiont/core';\nimport type { PdfTextLayer, PdfTextItem } from './pdf-text-layer';\n\n/**\n * Items whose baseline Y is within this many PDF points are treated as being on\n * the same line. Tuned for ~12pt body text; revisit for documents with large or\n * variable font sizes (Phase 4 / #738).\n */\nconst SAME_LINE_THRESHOLD_PT = 2;\n\n/**\n * Locates bounding rectangles for a span of text in a PdfTextLayer\n * (single-line or multi-line).\n * \n * Finds all overlapping items [start, end), groups them by page and line,\n * and records one bounding rectangle per line as a PdfCoordinate.\n * \n * Returns array of PdfCoordinate, one per line of text covered by the span.\n * Returns empty array if no items overlap the span.\n */\nexport function locate(\n layer: PdfTextLayer,\n start: number,\n end: number\n): PdfCoordinate[] {\n const overlap: PdfTextItem[] = layer.items.filter(\n item => item.start < end && item.end > start\n );\n if (overlap.length === 0) return [];\n\n const pages: Map<number, PdfTextItem[]> = groupItemsByPage(overlap);\n const rects: PdfCoordinate[] = [];\n\n // for each page, group items into lines and compute one rectangle per line\n for (const [page, pageItems] of pages) {\n const lines = groupItemsByLine(pageItems, SAME_LINE_THRESHOLD_PT);\n // Compute one bounding rectangle per line and add it to rects\n for (const lineItems of lines) {\n const x = Math.min(...lineItems.map(i => i.x));\n const right = Math.max(...lineItems.map(i => i.x + i.width));\n const y = Math.min(...lineItems.map(i => i.y));\n const top = Math.max(...lineItems.map(i => i.y + i.height));\n rects.push({page, x, y, width: right - x, height: top - y});\n }\n }\n return rects;\n}\n\nfunction groupItemsByPage(items: PdfTextItem[]): Map<number, PdfTextItem[]> {\n const map = new Map<number, PdfTextItem[]>();\n for (const item of items) {\n const existing = map.get(item.page);\n if (existing) {\n existing.push(item);\n } else {\n map.set(item.page, [item]);\n }\n }\n return map;\n}\n\n\n/**\n * Sorts text items into lines when their y coordinates are\n * within `sameLineThreshold` points of each other.\n * Sorted top-to-bottom (descending y in PDF space), then left-to-right.\n * \n * Returns 2D array: \n * Outer array = list of lines\n * Inner array = list of items on that line\n*/\nfunction groupItemsByLine(items: PdfTextItem[], sameLineThreshold: number): PdfTextItem[][] {\n // Sort top-to-bottom by y; if y is equal, sort left-to-right by x\n const sorted = [...items].sort((a, b) => b.y - a.y || a.x - b.x);\n const lines: PdfTextItem[][] = [];\n let currentLine: PdfTextItem[] = [];\n\n for (const item of sorted) {\n if (currentLine.length === 0 || Math.abs(item.y - currentLine[0].y) <= sameLineThreshold) {\n currentLine.push(item);\n } else {\n lines.push(currentLine);\n currentLine = [item];\n }\n }\n if (currentLine.length > 0) lines.push(currentLine);\n return lines;\n}\n"],"mappings":";AAsBA,SAAS,YAAY,UAAU;AAC/B,SAAS,oBAAoB;AAC7B,OAAO,UAAU;;;ACpBjB,SAAS,kBAAkB;AAOpB,SAAS,kBAAkB,SAAkC;AAClE,QAAM,OAAO,WAAW,QAAQ;AAChC,OAAK,OAAO,OAAO;AACnB,SAAO,KAAK,OAAO,KAAK;AAC1B;AAQO,SAAS,eAAe,SAA0B,UAA2B;AAClF,SAAO,kBAAkB,OAAO,MAAM;AACxC;;;ADiBO,IAAM,mBAAN,MAAuB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,SAAyB,QAAiB;AACpD,SAAK,cAAc,QAAQ;AAC3B,SAAK,UAAU,QAAQ;AACvB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEQ,aAAa,OAA0B;AAC7C,WAAO,KAAK,WAAW,CAAC;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,MAAM,SAAiB,YAAoB,SAAwD;AACvG,UAAM,WAAW,KAAK,WAAW,UAAU;AAC3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AM,QAAyB,CAAC;AAChC,MAAI,cAA6B,CAAC;AAElC,aAAW,QAAQ,QAAQ;AACvB,QAAI,YAAY,WAAW,KAAK,KAAK,IAAI,KAAK,IAAI,YAAY,CAAC,EAAE,CAAC,KAAK,mBAAmB;AACtF,kBAAY,KAAK,IAAI;AAAA,IACzB,OAAO;AACH,YAAM,KAAK,WAAW;AACtB,oBAAc,CAAC,IAAI;AAAA,IACvB;AAAA,EACJ;AACA,MAAI,YAAY,SAAS,EAAG,OAAM,KAAK,WAAW;AAClD,SAAO;AACX;","names":[]}
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@semiont/content",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
+ "engines": {
5
+ "node": ">=24.0.0"
6
+ },
4
7
  "type": "module",
5
- "description": "Content-addressed storage for resource representations",
8
+ "description": "Working-tree storage for project resources and PDF text-layer extraction",
6
9
  "main": "./dist/index.js",
7
10
  "types": "./dist/index.d.ts",
8
11
  "exports": {
@@ -24,21 +27,24 @@
24
27
  "test:coverage": "vitest run --coverage"
25
28
  },
26
29
  "dependencies": {
27
- "@semiont/core": "*"
30
+ "@semiont/core": "*",
31
+ "pdfjs-dist": "^5.7.284"
28
32
  },
29
33
  "devDependencies": {
30
- "@vitest/coverage-v8": "^4.1.0",
31
- "rollup": "^4.60.3",
34
+ "@vitest/coverage-v8": "^4.1.8",
35
+ "pdf-lib": "^1.17.1",
36
+ "rollup": "^4.61.0",
32
37
  "rollup-plugin-dts": "^6.4.1",
33
38
  "tsup": "^8.0.1",
34
- "typescript": "^6.0.2"
39
+ "typescript": "^6.0.2",
40
+ "vitest": "^4.1.8"
35
41
  },
36
42
  "keywords": [
37
43
  "content",
38
44
  "storage",
39
- "representation",
40
- "content-addressed",
41
- "deduplication",
45
+ "working-tree",
46
+ "checksum",
47
+ "pdf",
42
48
  "semiont"
43
49
  ],
44
50
  "author": "The AI Alliance",