@deepseek-ai/dsh-experimental-webworker-packer 0.1.6-alpha.1

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.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Pack a Preview deployment from this repository: compose and lower the base
4
+ * image, then write each named fixture overlay and their manifest.
5
+ *
6
+ * Usage: dsh-pack-vfs-image --out <file> [--profile web] [--root /dsh]
7
+ * node --import tsx/esm src/bin.ts --out ../../apps/web/dist/preview/vfs-image.tar.gz
8
+ * @module @deepseek-ai/dsh-experimental-webworker-packer/src/bin
9
+ */
10
+ import { mkdirSync, writeFileSync } from 'node:fs';
11
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
12
+ import { fileURLToPath } from 'node:url';
13
+ import { PREVIEW_FIXTURE_MANIFEST_FILE, PREVIEW_FIXTURE_MANIFEST_VERSION, } from '@deepseek-ai/dsh-experimental-webworker-runtime';
14
+ import { packVfsImage, packVfsOverlay } from "./pack.js";
15
+ import { composeProfile, configTrees, describePack, indexWorkspacePackages, previewFixtures, } from "./repository.js";
16
+ /**
17
+ * Read one `--flag value` pair.
18
+ * @param name - Flag name without dashes.
19
+ * @param fallback - Value when the flag is absent.
20
+ * @returns The value.
21
+ * @throws When the flag is present with no value, because silently packing the
22
+ * default profile is worse than stopping.
23
+ */
24
+ function flag(name, fallback) {
25
+ const index = process.argv.indexOf(`--${name}`);
26
+ if (index === -1) {
27
+ if (fallback !== undefined)
28
+ return fallback;
29
+ throw new Error(`dsh-pack-vfs-image: --${name} is required`);
30
+ }
31
+ const value = process.argv[index + 1];
32
+ if (value === undefined || value.startsWith('--')) {
33
+ throw new Error(`dsh-pack-vfs-image: --${name} needs a value`);
34
+ }
35
+ return value;
36
+ }
37
+ const repoRoot = fileURLToPath(new URL('../../../../', import.meta.url));
38
+ const profile = flag('profile', 'web');
39
+ const out = flag('out');
40
+ const outputFile = isAbsolute(out) ? out : resolve(process.cwd(), out);
41
+ const result = packVfsImage({
42
+ config: composeProfile(repoRoot, profile),
43
+ profile,
44
+ root: flag('root', '/dsh'),
45
+ workspaces: indexWorkspacePackages(repoRoot),
46
+ resolveFrom: repoRoot,
47
+ configTrees: configTrees(repoRoot),
48
+ });
49
+ if (result.missing.length > 0) {
50
+ throw new Error(`vfs image: ${String(result.missing.length)} dependencies did not resolve; the image would be incomplete`);
51
+ }
52
+ mkdirSync(dirname(outputFile), { recursive: true });
53
+ writeFileSync(outputFile, result.image);
54
+ const fixtureDefinitions = previewFixtures(repoRoot);
55
+ const fixtureDirectory = join(dirname(outputFile), 'fixtures');
56
+ mkdirSync(fixtureDirectory, { recursive: true });
57
+ const fixtureLines = [];
58
+ const fixtures = fixtureDefinitions.map((fixture) => {
59
+ const packed = packVfsOverlay(fixture.trees);
60
+ const file = `fixtures/${fixture.id}.tar.gz`;
61
+ writeFileSync(join(dirname(outputFile), file), packed.image);
62
+ fixtureLines.push(` fixture overlay ${fixture.id} (${String(packed.image.byteLength)} B compressed)`);
63
+ return {
64
+ id: fixture.id,
65
+ label: fixture.label,
66
+ description: fixture.description,
67
+ overlays: [file],
68
+ };
69
+ });
70
+ const manifest = {
71
+ version: PREVIEW_FIXTURE_MANIFEST_VERSION,
72
+ defaultFixture: fixtures[0]?.id ?? null,
73
+ fixtures,
74
+ };
75
+ writeFileSync(join(dirname(outputFile), PREVIEW_FIXTURE_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
76
+ process.stdout.write([...describePack(result, repoRoot, outputFile), ...fixtureLines, ''].join('\n'));
77
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Build-time packer for the browser runtime's VFS image.
3
+ * @module @deepseek-ai/dsh-experimental-webworker-packer
4
+ */
5
+ export { WRAPPER_CONTRACT, type ImageFiles, type TransformOutcome, } from './transform-image.ts';
6
+ export { CONFIG_PATH, DEFAULT_ROOT, MANIFEST_PATH, packVfsImage, packVfsOverlay, type ConfigTree, type ImageTree, type PackOptions, type PackOverlayResult, type PackResult, } from './pack.ts';
7
+ export { composeProfile, configTrees, describePack, indexWorkspacePackages, previewFixtures, type PreviewFixture, } from './repository.ts';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,105 @@
1
+ import { type ImageFiles, type TransformOutcome } from './transform-image.ts';
2
+ export { DEFAULT_ROOT } from '@deepseek-ai/dsh-experimental-webworker-runtime';
3
+ /** Image path of the manifest; the layout contract's name, re-exported for callers. */
4
+ export declare const MANIFEST_PATH: string;
5
+ /** Image path of the composed profile; the layout contract's name, re-exported for callers. */
6
+ export declare const CONFIG_PATH: string;
7
+ /** One directory tree to copy into the image at a caller-selected mount. */
8
+ export interface ImageTree {
9
+ /** Image path to mount it at, relative to the virtual root. */
10
+ readonly mount: string;
11
+ /** Absolute source directory. */
12
+ readonly directory: string;
13
+ }
14
+ /** One configuration tree whose plugin rows may extend the package roster. */
15
+ export interface ConfigTree extends ImageTree {
16
+ /**
17
+ * Whether plugin names inside its `.yml` files join the materialization closure.
18
+ * An agent preset mounts plugins the base composition never lists, and creating a
19
+ * session fails if any of them is missing from the image.
20
+ */
21
+ readonly scanRoster?: boolean;
22
+ }
23
+ /** Everything the packer needs that it cannot know by itself. */
24
+ export interface PackOptions {
25
+ /** Composed profile, `!!js` intact, as the CLI's `--dump-default-config` produced it. */
26
+ readonly config: string;
27
+ /** Profile name, recorded in the manifest. */
28
+ readonly profile: string;
29
+ /** Virtual root the image mounts under; defaults to {@link DEFAULT_ROOT}. */
30
+ readonly root?: string;
31
+ /** Package name to absolute directory, for workspace and vendored packages. */
32
+ readonly workspaces: ReadonlyMap<string, string>;
33
+ /** Directory Node-style dependency resolution walks up from for the roster. */
34
+ readonly resolveFrom: string;
35
+ /** Config trees to copy in beside the composition. */
36
+ readonly configTrees?: readonly ConfigTree[];
37
+ /** Empty directories to create; defaults to `home/`, `workspace/`, `tmp/`. */
38
+ readonly emptyDirectories?: readonly string[];
39
+ /**
40
+ * Extra sweep roots: image specifiers requested by code outside the image.
41
+ * Defaults to the worker assembly's own entries.
42
+ */
43
+ readonly entries?: readonly string[];
44
+ }
45
+ /** What one pack produced, for the caller to report or assert on. */
46
+ export interface PackResult {
47
+ /** The gzip-compressed tar archive to write; the runtime inflates it at mount. */
48
+ readonly image: Uint8Array;
49
+ /** Every entry, before zipping; the manifest is already among them. */
50
+ readonly files: ImageFiles;
51
+ /** Package name to how many files it contributed, in materialization order. */
52
+ readonly packages: ReadonlyMap<string, number>;
53
+ /** How many of them came from the workspace rather than from `node_modules`. */
54
+ readonly workspacePackages: number;
55
+ /** Roster package names the closure started from. */
56
+ readonly roster: readonly string[];
57
+ /** Dependencies that did not resolve; a non-empty list means an incomplete image. */
58
+ readonly missing: readonly string[];
59
+ /** Executable scripts dropped from the image. */
60
+ readonly executables: readonly string[];
61
+ /** Page bundles left out of the transform; like every JavaScript entry they carry the trailing debugger name. */
62
+ readonly pageBundles: readonly string[];
63
+ /** JavaScript entries the image carries. */
64
+ readonly javascriptEntries: number;
65
+ /** JavaScript candidates no root reaches, dropped from the image. */
66
+ readonly droppedJavascriptEntries: number;
67
+ /** Third-party requests that resolve nowhere; loud at require time if hit. */
68
+ readonly unresolvedExternalRequests: readonly string[];
69
+ /** What the pack-time transform did. */
70
+ readonly transform: TransformOutcome;
71
+ /** Wrapper contract recorded in the manifest; every packed body meets it. */
72
+ readonly contract: string;
73
+ }
74
+ /** One deterministic data-overlay archive and its uncompressed entries. */
75
+ export interface PackOverlayResult {
76
+ /** Gzip-compressed ustar bytes consumed by the Worker host. */
77
+ readonly image: Uint8Array;
78
+ /** Every path in the overlay before compression. */
79
+ readonly files: ImageFiles;
80
+ }
81
+ /**
82
+ * Pack one VFS image.
83
+ *
84
+ * The manifest's claim is all-or-nothing: it names the one contract every packed body
85
+ * was emitted against. A module the transform cannot express therefore fails the pack
86
+ * rather than downgrading the image, because a mostly-transformed image boots into
87
+ * errors far from their cause.
88
+ * @param options - Composition, package index, and paths.
89
+ * @returns The compressed image plus what went into it.
90
+ * @throws When a config tree or workspace directory named in the options is missing,
91
+ * because a silently thinner image fails much later and much less clearly.
92
+ */
93
+ export declare function packVfsImage(options: PackOptions): PackResult;
94
+ /**
95
+ * Pack opaque data trees into one ordered VFS overlay.
96
+ *
97
+ * Overlay mounts are restricted to the runtime-owned data directories, so an
98
+ * overlay cannot replace configuration, the lowering manifest, or modules.
99
+ * Files bypass package excludes and module reachability processing; later
100
+ * trees replace earlier files at the same path.
101
+ * @param trees - Absolute source directories and their data-directory mounts.
102
+ * @returns Deterministic compressed archive plus its uncompressed entries.
103
+ */
104
+ export declare function packVfsOverlay(trees: readonly ImageTree[]): PackOverlayResult;
105
+ //# sourceMappingURL=pack.d.ts.map
@@ -0,0 +1,61 @@
1
+ import type { ConfigTree, ImageTree, PackResult } from './pack.ts';
2
+ /** One built-in Preview source and the trees packed into its overlay. */
3
+ export interface PreviewFixture {
4
+ /** URL/query-safe identifier. */
5
+ readonly id: string;
6
+ /** User-facing chooser label. */
7
+ readonly label: string;
8
+ /** User-facing chooser detail. */
9
+ readonly description: string;
10
+ /** Opaque trees packed into this fixture's overlay archive. */
11
+ readonly trees: readonly ImageTree[];
12
+ }
13
+ /**
14
+ * Index every workspace and vendored package by name.
15
+ * @param repoRoot - Absolute repository root.
16
+ * @returns Package name to absolute directory.
17
+ */
18
+ export declare function indexWorkspacePackages(repoRoot: string): Map<string, string>;
19
+ /**
20
+ * Compose one profile through the real CLI dump path, leaving `!!js`
21
+ * unevaluated. The dump runs against a throwaway Harness home and default
22
+ * layers only, so the image is the shipped profile: the machine's `$DSH_HOME`
23
+ * — its profile manifest with locally installed bundles, and its patch files —
24
+ * would otherwise leak this machine's plugins into the image and break the
25
+ * same-tree-same-bytes guarantee.
26
+ * @param repoRoot - Absolute repository root.
27
+ * @param profile - Profile name to compose.
28
+ * @returns The composed YAML.
29
+ */
30
+ export declare function composeProfile(repoRoot: string, profile: string): string;
31
+ /**
32
+ * Config trees the CLI package declares for deployment images
33
+ * (`dsh.configTrees` in its package.json): `path` is relative to the CLI
34
+ * package root, `mount` is the image path, `scanRoster` feeds the tree's yml
35
+ * plugin rows into the pack roster. The CLI owns its config layout; this
36
+ * reader follows the declaration instead of naming directories. A malformed
37
+ * declaration refuses the pack.
38
+ * @param repoRoot - Absolute repository root.
39
+ * @returns Trees with absolute source directories.
40
+ */
41
+ export declare function configTrees(repoRoot: string): ConfigTree[];
42
+ /**
43
+ * Built-in filesystem fixtures offered by the repository preview.
44
+ * Session and Workspace semantics remain opaque here; the owning runtime tests
45
+ * validate those files through their production readers.
46
+ * @param repoRoot - Absolute repository root.
47
+ * @returns Named chooser entries and their overlay trees.
48
+ */
49
+ export declare function previewFixtures(repoRoot: string): PreviewFixture[];
50
+ /**
51
+ * Render one pack as the lines a build log should carry.
52
+ *
53
+ * Refusals and unresolved dependencies are the two states a reader must not miss, so
54
+ * they are spelled out rather than counted.
55
+ * @param result - What the pack produced.
56
+ * @param repoRoot - Absolute repository root, for relative paths.
57
+ * @param outputFile - Where the image was written.
58
+ * @returns Lines to print.
59
+ */
60
+ export declare function describePack(result: PackResult, repoRoot: string, outputFile: string): string[];
61
+ //# sourceMappingURL=repository.d.ts.map
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Pack rule tables: the one place the image's include/exclude decisions live.
3
+ * Patterns are picomatch globs. Exclude patterns match tree-root-relative
4
+ * paths (so `src/**` drops only a root-level source tree), page-asset
5
+ * patterns match image paths. Traversal mechanics — nested `node_modules`
6
+ * flattening and dot-directory pruning — stay in the collector; these tables
7
+ * hold the judgement calls.
8
+ */
9
+ /**
10
+ * Paths dropped from every collected tree. Test trees, sourcemaps,
11
+ * declarations, and archives never resolve at runtime while dominating the
12
+ * byte count. Third-party `src/` directories remain eligible because package
13
+ * entrypoints may resolve to JavaScript there.
14
+ */
15
+ export declare const EXCLUDE: readonly string[];
16
+ /**
17
+ * Additional paths dropped from workspace and vendored packages only. Their
18
+ * runtime plane is built `lib/`; a workspace `dist/` is a page-asset tree the
19
+ * static deployment serves itself. External packages may place runtime code
20
+ * under either directory.
21
+ */
22
+ export declare const EXCLUDE_WORKSPACE: readonly string[];
23
+ /**
24
+ * Image paths that belong to the PAGE, not to the worker's loader.
25
+ *
26
+ * A package's `lib/client.js` is its browser bundle behind the `./client`
27
+ * export: the page's own module system evaluates it with its own wrapper,
28
+ * which has no ambient-store parameter. Transforming those bodies would
29
+ * inject calls the page cannot resolve, so they ship untransformed — their
30
+ * only change is the trailing debugger-name line every JavaScript entry
31
+ * gains — and the manifest's all-or-nothing claim stays true, because the
32
+ * worker loader never evaluates them (the tunnel serves them as bytes).
33
+ */
34
+ export declare const PAGE_ASSETS: readonly string[];
35
+ /**
36
+ * Image specifiers the worker assembly requires directly, beyond the composed
37
+ * roster: they are requested by worker-bundle code, so no image file
38
+ * references them and the reachability sweep must seed them as roots. Keep in
39
+ * step with the literal `require`/`resolve` calls in the runtime's
40
+ * `worker-host.ts`.
41
+ */
42
+ export declare const IMAGE_ENTRY_SEEDS: readonly string[];
43
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1,12 @@
1
+ /** Image entries, keyed by their path relative to the virtual root. */
2
+ export type ImageFiles = Record<string, Uint8Array>;
3
+ /** Wrapper contract the packed bodies are emitted against. */
4
+ export declare const WRAPPER_CONTRACT: string;
5
+ /** What one pack-time transform pass did. */
6
+ export interface TransformOutcome {
7
+ /** JavaScript entries visited. */
8
+ readonly visited: number;
9
+ /** How many changed; the rest were already in final form. */
10
+ readonly rewritten: number;
11
+ }
12
+ //# sourceMappingURL=transform-image.d.ts.map
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@deepseek-ai/dsh-experimental-webworker-packer",
3
+ "description": "Build-time packer for the browser runtime's base VFS image and ordered data-overlay archives",
4
+ "version": "0.1.6-alpha.1",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
11
+ "directory": "packages/experimental/webworker-packer"
12
+ },
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "types": "lib/types/index.d.ts",
16
+ "bin": {
17
+ "dsh-pack-vfs-image": "./bin.js"
18
+ },
19
+ "exports": {
20
+ ".": {
21
+ "types": "./lib/types/index.d.ts",
22
+ "default": "./lib/index.js"
23
+ },
24
+ "./src/*": "./src/*",
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "lib/index.js",
29
+ "lib/bin.js",
30
+ "bin.js",
31
+ "lib/repository-*.js",
32
+ "lib/types/**/*.d.ts"
33
+ ],
34
+ "license": "MIT",
35
+ "dependencies": {
36
+ "js-yaml": "^4.2.0",
37
+ "picomatch": "^4.0.4",
38
+ "@deepseek-ai/cordis-plugin-include": "^1.0.7",
39
+ "@deepseek-ai/dsh-experimental-webworker-runtime": "^0.1.6-alpha.1",
40
+ "@deepseek-ai/dsh-home-paths": "^0.1.6-alpha.1"
41
+ },
42
+ "devDependencies": {
43
+ "@types/js-yaml": "^4.0.9",
44
+ "@types/picomatch": "^3.0.2",
45
+ "@deepseek-ai/cordis": "^4.0.2"
46
+ },
47
+ "peerDependencies": {
48
+ "@deepseek-ai/cordis": "^4.0.2"
49
+ }
50
+ }