@baselane/materialize 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2026 Mohammad Omar
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @baselane/materialize
2
+
3
+ Disk-reconcile and install engine (plan/apply/receipt/settings-merge/manifest-io/resolve/
4
+ install) shared by the [`baselane`](https://www.npmjs.com/package/baselane) CLI and the
5
+ baselane desktop agent.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @baselane/materialize
11
+ ```
12
+
13
+ Used as a library dependency of `baselane` — most users won't install it directly.
14
+
15
+ Docs: https://baselane.sh
@@ -0,0 +1,6 @@
1
+ import type { Bundle, Manifest, ReconcilePlan } from "./types.ts";
2
+ export declare const MANIFEST_NAME = ".baselane-manifest.json";
3
+ export declare function loadManifest(rootDir: string): Promise<Manifest>;
4
+ export declare function readCurrent(rootDir: string, paths: string[]): Promise<Record<string, string | null>>;
5
+ export declare function applyPlan(rootDir: string, bundle: Bundle, plan: ReconcilePlan): Promise<void>;
6
+ export declare function writeManifest(rootDir: string, bundle: Bundle): Promise<void>;
package/dist/fs-ops.js ADDED
@@ -0,0 +1,101 @@
1
+ import { lstat, mkdir, readFile, unlink, writeFile } from "node:fs/promises";
2
+ import { dirname, join, resolve, sep } from "node:path";
3
+ import { sha256 } from "./hash.js";
4
+ export const MANIFEST_NAME = ".baselane-manifest.json";
5
+ // Lexical containment only — symlink traversal is refused separately by assertNoSymlinkWithin on mutating ops.
6
+ function resolveInside(rootDir, path) {
7
+ const abs = resolve(rootDir, path);
8
+ const rootAbs = resolve(rootDir);
9
+ if (abs !== rootAbs && !abs.startsWith(rootAbs + sep)) {
10
+ throw new Error(`baselane: path "${path}" escapes target root`);
11
+ }
12
+ return abs;
13
+ }
14
+ async function assertNoSymlinkWithin(rootDir, relPath) {
15
+ const segments = relPath.split("/");
16
+ let current = resolve(rootDir);
17
+ for (const segment of segments) {
18
+ current = join(current, segment);
19
+ let stats;
20
+ try {
21
+ stats = await lstat(current);
22
+ }
23
+ catch (err) {
24
+ const code = err.code;
25
+ if (code === "ENOENT" || code === "ENOTDIR")
26
+ return; // remainder doesn't exist yet; mkdir creates real dirs
27
+ throw err;
28
+ }
29
+ if (stats.isSymbolicLink()) {
30
+ throw new Error(`baselane: path "${relPath}" traverses a symlink ("${segment}") — refusing`);
31
+ }
32
+ }
33
+ }
34
+ async function readIfExists(absPath) {
35
+ try {
36
+ return await readFile(absPath, "utf8");
37
+ }
38
+ catch (err) {
39
+ const code = err.code;
40
+ if (code === "ENOENT" || code === "ENOTDIR")
41
+ return null;
42
+ throw err;
43
+ }
44
+ }
45
+ export async function loadManifest(rootDir) {
46
+ const raw = await readIfExists(join(rootDir, MANIFEST_NAME));
47
+ if (raw === null)
48
+ return { version: 1, files: {} };
49
+ const parsed = JSON.parse(raw);
50
+ if (parsed.version !== 1 || typeof parsed.files !== "object" || parsed.files === null) {
51
+ throw new Error("baselane: malformed manifest");
52
+ }
53
+ return parsed;
54
+ }
55
+ export async function readCurrent(rootDir, paths) {
56
+ const state = {};
57
+ for (const path of paths) {
58
+ state[path] = await readIfExists(resolveInside(rootDir, path));
59
+ }
60
+ return state;
61
+ }
62
+ export async function applyPlan(rootDir, bundle, plan) {
63
+ // A file in plan.drifted was hand-edited since baselane last wrote it. It is also in
64
+ // plan.writes (its content differs from desired), so applyPlan is about to overwrite —
65
+ // revert — the local edit. Back the local version up to <path>.baselane-bak FIRST so a
66
+ // developer's edit is never silently lost (#3 data-loss critical: revert-without-backup).
67
+ const drifted = new Set(plan.drifted);
68
+ for (const path of plan.writes) {
69
+ await assertNoSymlinkWithin(rootDir, path);
70
+ const abs = resolveInside(rootDir, path);
71
+ const content = bundle.files[path];
72
+ if (content === undefined)
73
+ throw new Error(`baselane: write "${path}" not in bundle`);
74
+ if (drifted.has(path)) {
75
+ const local = await readFile(abs, "utf8").catch(() => null);
76
+ if (local !== null)
77
+ await writeFile(`${abs}.baselane-bak`, local, "utf8");
78
+ }
79
+ await mkdir(dirname(abs), { recursive: true });
80
+ await writeFile(abs, content, "utf8");
81
+ }
82
+ for (const path of plan.deletes) {
83
+ await assertNoSymlinkWithin(rootDir, path);
84
+ const abs = resolveInside(rootDir, path);
85
+ // Same rule as writes: a delete target that's drifted (hand-edited since baselane last wrote
86
+ // it) is about to lose that edit permanently. Back it up first.
87
+ if (drifted.has(path)) {
88
+ const local = await readFile(abs, "utf8").catch(() => null);
89
+ if (local !== null)
90
+ await writeFile(`${abs}.baselane-bak`, local, "utf8");
91
+ }
92
+ await unlink(abs);
93
+ }
94
+ }
95
+ export async function writeManifest(rootDir, bundle) {
96
+ const manifest = {
97
+ version: 1,
98
+ files: Object.fromEntries(Object.entries(bundle.files).map(([path, content]) => [path, sha256(content)])),
99
+ };
100
+ await writeFile(join(rootDir, MANIFEST_NAME), JSON.stringify(manifest, null, 2) + "\n", "utf8");
101
+ }
package/dist/hash.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function sha256(content: string): string;
package/dist/hash.js ADDED
@@ -0,0 +1,4 @@
1
+ import { createHash } from "node:crypto";
2
+ export function sha256(content) {
3
+ return createHash("sha256").update(content, "utf8").digest("hex");
4
+ }
@@ -0,0 +1,11 @@
1
+ export { sha256 } from "./hash.ts";
2
+ export { planReconcile } from "./plan.ts";
3
+ export { applyPlan, loadManifest, readCurrent, writeManifest, MANIFEST_NAME } from "./fs-ops.ts";
4
+ export { hasManagedHooks, mergeBaselaneHooks, SettingsParseError } from "./settings-merge.ts";
5
+ export type { Bundle, BundleOnboardingStep, Manifest, ReconcilePlan } from "./types.ts";
6
+ export { targetLocation, readManifestFile, readManifestWithFallback, writeManifestFile } from "./manifest-io.ts";
7
+ export type { TargetLocation } from "./manifest-io.ts";
8
+ export { resolveManifestPacks, fetchRegistryVersions, registryBaseFor, encodeSkillPin, decodeSkillPin, DEFAULT_REGISTRY } from "./resolve-packs.ts";
9
+ export type { ResolvedManifestPacks, RegistryVersionEntry } from "./resolve-packs.ts";
10
+ export { runInstall, installFromManifest } from "./install.ts";
11
+ export type { InstallOptions, InstallReport } from "./install.ts";
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { sha256 } from "./hash.js";
2
+ export { planReconcile } from "./plan.js";
3
+ export { applyPlan, loadManifest, readCurrent, writeManifest, MANIFEST_NAME } from "./fs-ops.js";
4
+ export { hasManagedHooks, mergeBaselaneHooks, SettingsParseError } from "./settings-merge.js";
5
+ export { targetLocation, readManifestFile, readManifestWithFallback, writeManifestFile } from "./manifest-io.js";
6
+ export { resolveManifestPacks, fetchRegistryVersions, registryBaseFor, encodeSkillPin, decodeSkillPin, DEFAULT_REGISTRY } from "./resolve-packs.js";
7
+ export { runInstall, installFromManifest } from "./install.js";
@@ -0,0 +1,35 @@
1
+ import { type HarnessManifest, type WorkflowPack } from "@baselane/packs";
2
+ import { type TargetLocation } from "./manifest-io.ts";
3
+ export interface InstallOptions {
4
+ source?: string;
5
+ global: boolean;
6
+ dir?: string;
7
+ homeDir?: string;
8
+ dryRun: boolean;
9
+ json: boolean;
10
+ token?: string;
11
+ fetchImpl?: typeof fetch;
12
+ registryBase?: string;
13
+ log?: (line: string) => void;
14
+ }
15
+ export interface InstallReport {
16
+ manifestPath: string;
17
+ targetDir: string;
18
+ packs: Record<string, string>;
19
+ writes: string[];
20
+ deletes: string[];
21
+ driftedBackedUp: string[];
22
+ unchanged: string[];
23
+ notes: string[];
24
+ dryRun: boolean;
25
+ }
26
+ export declare function installFromManifest(manifest: HarnessManifest, loc: TargetLocation, opts: {
27
+ dryRun: boolean;
28
+ token?: string;
29
+ fetchImpl?: typeof fetch;
30
+ registryBase?: string;
31
+ log?: (l: string) => void;
32
+ inlinePacks?: Record<string, WorkflowPack>;
33
+ priorReceipt?: Record<string, string>;
34
+ }, prior: HarnessManifest | null): Promise<InstallReport>;
35
+ export declare function runInstall(opts: InstallOptions): Promise<InstallReport>;
@@ -0,0 +1,115 @@
1
+ import { readFile, unlink, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { buildManifest, materializeHarness, ENTRY_FILES, LEGACY_MANIFEST_PATH, MANIFEST_PATH, } from "@baselane/packs";
4
+ import { parseInstallRef, resolveDefaultBranch } from "@baselane/distribute";
5
+ import { applyPlan, readCurrent } from "./fs-ops.js";
6
+ import { planReconcile } from "./plan.js";
7
+ import { mergeBaselaneHooks, SettingsParseError } from "./settings-merge.js";
8
+ import { readManifestWithFallback, targetLocation, writeManifestFile } from "./manifest-io.js";
9
+ import { DEFAULT_REGISTRY, encodeSkillPin, fetchRegistryVersions, resolveManifestPacks } from "./resolve-packs.js";
10
+ const MACHINE_SETTINGS_PATH = "settings.json";
11
+ export async function installFromManifest(manifest, loc, opts, prior) {
12
+ const log = opts.log ?? console.log;
13
+ const notes = [];
14
+ const { packs, resolutions } = await resolveManifestPacks(manifest, {
15
+ token: opts.token, fetchImpl: opts.fetchImpl, inlinePacks: opts.inlinePacks, registryBase: opts.registryBase,
16
+ onNotice: (m) => { notes.push(m); log(m); },
17
+ }).then((r) => { notes.push(...r.notes); r.notes.forEach(log); return r; });
18
+ const entryState = await readCurrent(loc.targetDir, [...ENTRY_FILES]);
19
+ const result = materializeHarness({ manifest, resolvedPacks: packs, currentFiles: entryState, resolutions });
20
+ const desired = { ...result.files };
21
+ let heldSettings = null;
22
+ if (loc.target.kind === "machine" && desired[MACHINE_SETTINGS_PATH] !== undefined) {
23
+ heldSettings = desired[MACHINE_SETTINGS_PATH];
24
+ delete desired[MACHINE_SETTINGS_PATH];
25
+ }
26
+ const bundle = { version: 1, files: desired };
27
+ const receipt = {
28
+ version: 1,
29
+ files: opts.priorReceipt ??
30
+ Object.fromEntries((prior?.materialized.vendored ?? [])
31
+ .filter((v) => v.sha256 !== null)
32
+ .map((v) => [v.path, v.sha256])),
33
+ };
34
+ const onDisk = await readCurrent(loc.targetDir, [...new Set([...Object.keys(desired), ...Object.keys(receipt.files)])]);
35
+ const plan = planReconcile(bundle, receipt, onDisk);
36
+ const report = {
37
+ manifestPath: loc.manifestPath, targetDir: loc.targetDir,
38
+ packs: manifest.packs,
39
+ writes: plan.writes, deletes: plan.deletes,
40
+ driftedBackedUp: plan.drifted.filter((p) => plan.writes.includes(p) || plan.deletes.includes(p)),
41
+ unchanged: plan.unchanged, notes, dryRun: opts.dryRun,
42
+ };
43
+ if (opts.dryRun)
44
+ return report;
45
+ await applyPlan(loc.targetDir, bundle, plan);
46
+ if (heldSettings !== null) {
47
+ const settingsPath = join(loc.targetDir, MACHINE_SETTINGS_PATH);
48
+ let current;
49
+ try {
50
+ current = await readFile(settingsPath, "utf8");
51
+ }
52
+ catch (err) {
53
+ const code = err.code;
54
+ if (code === "ENOENT" || code === "ENOTDIR")
55
+ current = null;
56
+ else
57
+ throw err; // e.g. EACCES — do NOT silently treat an unreadable file as absent (clobber risk)
58
+ }
59
+ try {
60
+ await writeFile(settingsPath, mergeBaselaneHooks(current, heldSettings), "utf8");
61
+ }
62
+ catch (err) {
63
+ if (err instanceof SettingsParseError) {
64
+ throw new Error(`install: ${settingsPath} is not valid JSON — fix or remove it, then re-run (refusing to overwrite)`);
65
+ }
66
+ throw err;
67
+ }
68
+ }
69
+ await writeManifestFile(loc.manifestPath, result.manifest);
70
+ return report;
71
+ }
72
+ export async function runInstall(opts) {
73
+ const log = opts.log ?? console.log;
74
+ const loc = targetLocation({ global: opts.global, dir: opts.dir, homeDir: opts.homeDir });
75
+ const { manifest: existing, legacyPath } = await readManifestWithFallback(loc);
76
+ const base = existing ?? buildManifest({ target: loc.target, packs: {} });
77
+ let manifest = base;
78
+ if (opts.source !== undefined) {
79
+ const parsed = parseInstallRef(opts.source);
80
+ if (parsed.kind === "git") {
81
+ manifest = { ...base, packs: { ...base.packs, [parsed.name]: parsed.ref } };
82
+ }
83
+ else if (parsed.kind === "registry") {
84
+ const registryBase = base.registry ?? opts.registryBase ?? DEFAULT_REGISTRY;
85
+ let version = parsed.version;
86
+ if (version === null) {
87
+ const versions = await fetchRegistryVersions(parsed.name, registryBase, { fetchImpl: opts.fetchImpl, onNotice: log });
88
+ if (versions.length === 0)
89
+ throw new Error(`install: "${parsed.name}" has no published versions at ${registryBase}`);
90
+ version = versions[0].version; // fetchRegistryVersions sorts semver-desc locally — index 0 is the true latest
91
+ }
92
+ manifest = { ...base, packs: { ...base.packs, [parsed.name]: version } };
93
+ }
94
+ else {
95
+ // "skill": owner/repo@skill — no explicit ref, so pin at the repo's default branch;
96
+ // the single-skill filter rides along in the pin (see encodeSkillPin's doc comment).
97
+ const label = `${parsed.owner}/${parsed.repo}`;
98
+ const branch = await resolveDefaultBranch(parsed.owner, parsed.repo, { token: opts.token, fetchImpl: opts.fetchImpl ?? fetch, label });
99
+ const gitName = `github:${parsed.owner}/${parsed.repo}`;
100
+ manifest = { ...base, packs: { ...base.packs, [gitName]: encodeSkillPin(branch, parsed.skill) } };
101
+ }
102
+ }
103
+ if (Object.keys(manifest.packs).length === 0 && opts.source === undefined && existing === null) {
104
+ throw new Error(`install: no ${loc.manifestPath} found and no source given — nothing to install`);
105
+ }
106
+ const report = await installFromManifest(manifest, loc, { dryRun: opts.dryRun, token: opts.token, fetchImpl: opts.fetchImpl, registryBase: opts.registryBase, log }, existing);
107
+ // Legacy .baselane/harness.json is superseded by the just-written root manifest — remove it
108
+ // only once the new one is confirmed on disk (dry-run never reaches here with legacyPath set
109
+ // as a real migration, since nothing was written).
110
+ if (legacyPath !== null && !opts.dryRun) {
111
+ await unlink(legacyPath);
112
+ log(`migrated manifest: ${LEGACY_MANIFEST_PATH} → ${MANIFEST_PATH}`);
113
+ }
114
+ return report;
115
+ }
@@ -0,0 +1,25 @@
1
+ import { type HarnessManifest } from "@baselane/packs";
2
+ export interface TargetLocation {
3
+ manifestPath: string;
4
+ targetDir: string;
5
+ target: {
6
+ kind: "repo" | "machine";
7
+ id: string;
8
+ };
9
+ }
10
+ export declare function targetLocation(opts: {
11
+ global: boolean;
12
+ dir?: string;
13
+ homeDir?: string;
14
+ }): TargetLocation;
15
+ export declare function readManifestFile(manifestPath: string): Promise<HarnessManifest | null>;
16
+ /** Reads a target's manifest, falling back to the pre-2026-07-16 `.baselane/harness.json`
17
+ * location for repo targets when the root manifest is absent. Machine targets never fall
18
+ * back — `loc.manifestPath` (`~/.baselane/harness.json`) is unchanged and has no legacy path.
19
+ * `legacyPath` is non-null only when the fallback was actually used, signaling callers that
20
+ * migrated on write (see `installFromManifest`). */
21
+ export declare function readManifestWithFallback(loc: TargetLocation): Promise<{
22
+ manifest: HarnessManifest | null;
23
+ legacyPath: string | null;
24
+ }>;
25
+ export declare function writeManifestFile(manifestPath: string, manifest: HarnessManifest): Promise<void>;
@@ -0,0 +1,69 @@
1
+ import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
2
+ import { randomBytes } from "node:crypto";
3
+ import { hostname, homedir } from "node:os";
4
+ import { basename, dirname, join, resolve } from "node:path";
5
+ import { LEGACY_MANIFEST_PATH, MANIFEST_PATH, validateManifest } from "@baselane/packs";
6
+ export function targetLocation(opts) {
7
+ if (opts.global) {
8
+ const home = opts.homeDir ?? homedir();
9
+ return {
10
+ manifestPath: join(home, ".baselane", "harness.json"),
11
+ targetDir: opts.dir ?? join(home, ".claude"),
12
+ target: { kind: "machine", id: hostname() },
13
+ };
14
+ }
15
+ const dir = resolve(opts.dir ?? ".");
16
+ return {
17
+ manifestPath: join(dir, MANIFEST_PATH),
18
+ targetDir: dir,
19
+ target: { kind: "repo", id: basename(dir) },
20
+ };
21
+ }
22
+ export async function readManifestFile(manifestPath) {
23
+ let raw;
24
+ try {
25
+ raw = await readFile(manifestPath, "utf8");
26
+ }
27
+ catch (err) {
28
+ const code = err.code;
29
+ if (code === "ENOENT" || code === "ENOTDIR")
30
+ return null;
31
+ throw err;
32
+ }
33
+ try {
34
+ return validateManifest(JSON.parse(raw));
35
+ }
36
+ catch (err) {
37
+ throw new Error(`harness.json at ${manifestPath} is invalid: ${err instanceof Error ? err.message : String(err)}`);
38
+ }
39
+ }
40
+ /** Reads a target's manifest, falling back to the pre-2026-07-16 `.baselane/harness.json`
41
+ * location for repo targets when the root manifest is absent. Machine targets never fall
42
+ * back — `loc.manifestPath` (`~/.baselane/harness.json`) is unchanged and has no legacy path.
43
+ * `legacyPath` is non-null only when the fallback was actually used, signaling callers that
44
+ * migrated on write (see `installFromManifest`). */
45
+ export async function readManifestWithFallback(loc) {
46
+ const root = await readManifestFile(loc.manifestPath);
47
+ if (root !== null)
48
+ return { manifest: root, legacyPath: null };
49
+ if (loc.target.kind !== "repo")
50
+ return { manifest: null, legacyPath: null };
51
+ const legacyPath = join(loc.targetDir, LEGACY_MANIFEST_PATH);
52
+ const legacy = await readManifestFile(legacyPath);
53
+ if (legacy === null)
54
+ return { manifest: null, legacyPath: null };
55
+ return { manifest: legacy, legacyPath };
56
+ }
57
+ export async function writeManifestFile(manifestPath, manifest) {
58
+ await mkdir(dirname(manifestPath), { recursive: true });
59
+ // Randomized suffix: two concurrent writers (e.g. install + agent sync) never collide on the same tmp path.
60
+ const tmp = `${manifestPath}.${randomBytes(6).toString("hex")}.tmp`;
61
+ await writeFile(tmp, JSON.stringify(manifest, null, 2) + "\n", "utf8");
62
+ try {
63
+ await rename(tmp, manifestPath);
64
+ }
65
+ catch (err) {
66
+ await unlink(tmp).catch(() => { }); // best-effort: don't leave the tmp file behind on a failed rename
67
+ throw err;
68
+ }
69
+ }
package/dist/plan.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { Bundle, Manifest, ReconcilePlan } from "./types.ts";
2
+ /**
3
+ * Pure desired-state diff. `onDisk` must cover every path in bundle.files ∪ manifest.files
4
+ * (null = absent). Paths outside that union are structurally unreachable here — the
5
+ * never-clobber guarantee starts in this signature.
6
+ */
7
+ export declare function planReconcile(bundle: Bundle, manifest: Manifest, onDisk: Record<string, string | null>): ReconcilePlan;
package/dist/plan.js ADDED
@@ -0,0 +1,34 @@
1
+ import { sha256 } from "./hash.js";
2
+ /**
3
+ * Pure desired-state diff. `onDisk` must cover every path in bundle.files ∪ manifest.files
4
+ * (null = absent). Paths outside that union are structurally unreachable here — the
5
+ * never-clobber guarantee starts in this signature.
6
+ */
7
+ export function planReconcile(bundle, manifest, onDisk) {
8
+ const writes = [];
9
+ const unchanged = [];
10
+ const drifted = [];
11
+ for (const [path, desired] of Object.entries(bundle.files)) {
12
+ const current = onDisk[path] ?? null;
13
+ if (current === desired)
14
+ unchanged.push(path);
15
+ else
16
+ writes.push(path);
17
+ }
18
+ const deletes = [];
19
+ for (const path of Object.keys(manifest.files)) {
20
+ if (!(path in bundle.files) && (onDisk[path] ?? null) !== null)
21
+ deletes.push(path);
22
+ }
23
+ for (const [path, managedHash] of Object.entries(manifest.files)) {
24
+ const current = onDisk[path] ?? null;
25
+ if (current !== null && sha256(current) !== managedHash)
26
+ drifted.push(path);
27
+ }
28
+ return {
29
+ writes: writes.sort(),
30
+ deletes: deletes.sort(),
31
+ drifted: drifted.sort(),
32
+ unchanged: unchanged.sort(),
33
+ };
34
+ }
@@ -0,0 +1,44 @@
1
+ import { type HarnessManifest, type Resolution, type WorkflowPack } from "@baselane/packs";
2
+ export interface ResolvedManifestPacks {
3
+ packs: Record<string, WorkflowPack>;
4
+ resolutions: Record<string, Resolution>;
5
+ notes: string[];
6
+ }
7
+ /** CLI default registry, overridden by `manifest.registry`, then a caller-supplied `registryBase`
8
+ * (the CLI reads `BASELANE_REGISTRY` and passes it through — env access stays out of this
9
+ * package, same as how `GITHUB_TOKEN` flows in as `opts.token`). Spec: RETURN DECISION 4. */
10
+ export declare const DEFAULT_REGISTRY = "https://registry.baselane.sh";
11
+ export declare function registryBaseFor(manifest: HarnessManifest, fallback?: string): string;
12
+ export interface RegistryVersionEntry {
13
+ version: string;
14
+ source: {
15
+ name: string;
16
+ ref: string;
17
+ sha: string;
18
+ };
19
+ packId: string;
20
+ publishedAt: string;
21
+ }
22
+ /** GET {registryBase}/registry/v1/packs/{name} — every entry validated against the registry's
23
+ * own publish-time shape (semver version, `github:` source, 40-hex lowercase sha); entries that
24
+ * fail are dropped (never written to a committed manifest pin), with a notice so a silently
25
+ * degraded registry response isn't invisible. The kept entries are sorted semver-desc locally —
26
+ * "latest" must never trust server-supplied order. */
27
+ export declare function fetchRegistryVersions(name: string, registryBase: string, ctx?: {
28
+ fetchImpl?: typeof fetch;
29
+ onNotice?: (m: string) => void;
30
+ }): Promise<RegistryVersionEntry[]>;
31
+ export declare function encodeSkillPin(ref: string, skill: string): string;
32
+ /** Exported for display code (e.g. formatting an install/update report) — the raw pin string
33
+ * contains a control character and must never be printed verbatim. */
34
+ export declare function decodeSkillPin(pin: string): {
35
+ ref: string;
36
+ onlySkill: string | undefined;
37
+ };
38
+ export declare function resolveManifestPacks(manifest: HarnessManifest, opts?: {
39
+ token?: string;
40
+ fetchImpl?: typeof fetch;
41
+ onNotice?: (m: string) => void;
42
+ inlinePacks?: Record<string, WorkflowPack>;
43
+ registryBase?: string;
44
+ }): Promise<ResolvedManifestPacks>;
@@ -0,0 +1,146 @@
1
+ import { packFromFileset, validatePack } from "@baselane/packs";
2
+ import { isGitSourceName, parseGitSourceName, resolveGitSource } from "@baselane/distribute";
3
+ /** CLI default registry, overridden by `manifest.registry`, then a caller-supplied `registryBase`
4
+ * (the CLI reads `BASELANE_REGISTRY` and passes it through — env access stays out of this
5
+ * package, same as how `GITHUB_TOKEN` flows in as `opts.token`). Spec: RETURN DECISION 4. */
6
+ export const DEFAULT_REGISTRY = "https://registry.baselane.sh";
7
+ export function registryBaseFor(manifest, fallback) {
8
+ return manifest.registry ?? fallback ?? DEFAULT_REGISTRY;
9
+ }
10
+ const VERSION_RE = /^\d+\.\d+\.\d+$/;
11
+ const SOURCE_NAME_RE = /^github:[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;
12
+ const SHA_RE = /^[0-9a-f]{40}$/;
13
+ /** 3-part numeric semver compare, descending ("1.10.0" sorts before "1.2.0"). Mirrors
14
+ * apps/portal/src/compliance.ts's compareVersions — inlined because packages can't import
15
+ * from apps/portal. ALL client-side "latest" resolution must go through this, never trust
16
+ * the order the registry response happened to arrive in. */
17
+ function compareVersionsDesc(a, b) {
18
+ const part = (v, i) => Number.parseInt(v.split(".")[i] ?? "0", 10);
19
+ for (let i = 0; i < 3; i++) {
20
+ const d = part(b, i) - part(a, i);
21
+ if (d !== 0)
22
+ return d;
23
+ }
24
+ return 0;
25
+ }
26
+ /** A registry is an untrusted network response, not a trusted local store — a malicious or
27
+ * buggy server could otherwise write a non-semver version, a non-github: source, or a
28
+ * malformed sha straight into a committed harness.json pin. Reject anything that doesn't
29
+ * match the exact shape the portal's own RegistryIndexRec validator enforces at publish time. */
30
+ function isValidRegistryVersionEntry(v) {
31
+ if (v === null || typeof v !== "object")
32
+ return false;
33
+ const r = v;
34
+ if (typeof r.version !== "string" || !VERSION_RE.test(r.version))
35
+ return false;
36
+ if (typeof r.packId !== "string" || r.packId.length === 0)
37
+ return false;
38
+ if (typeof r.publishedAt !== "string")
39
+ return false;
40
+ const source = r.source;
41
+ if (source === null || typeof source !== "object")
42
+ return false;
43
+ if (typeof source.name !== "string" || !SOURCE_NAME_RE.test(source.name))
44
+ return false;
45
+ if (typeof source.ref !== "string" || source.ref.length === 0)
46
+ return false;
47
+ if (typeof source.sha !== "string" || !SHA_RE.test(source.sha))
48
+ return false;
49
+ return true;
50
+ }
51
+ /** GET {registryBase}/registry/v1/packs/{name} — every entry validated against the registry's
52
+ * own publish-time shape (semver version, `github:` source, 40-hex lowercase sha); entries that
53
+ * fail are dropped (never written to a committed manifest pin), with a notice so a silently
54
+ * degraded registry response isn't invisible. The kept entries are sorted semver-desc locally —
55
+ * "latest" must never trust server-supplied order. */
56
+ export async function fetchRegistryVersions(name, registryBase, ctx = {}) {
57
+ const fetchImpl = ctx.fetchImpl ?? fetch;
58
+ let res;
59
+ try {
60
+ res = await fetchImpl(`${registryBase}/registry/v1/packs/${name}`);
61
+ }
62
+ catch (err) {
63
+ throw new Error(`registry: lookup for "${name}" at ${registryBase} failed: ${err instanceof Error ? err.message : String(err)}`);
64
+ }
65
+ if (res.status === 404)
66
+ throw new Error(`registry: pack "${name}" not found at ${registryBase}`);
67
+ if (!res.ok)
68
+ throw new Error(`registry: lookup for "${name}" at ${registryBase} failed with HTTP ${res.status}`);
69
+ const body = (await res.json());
70
+ if (!Array.isArray(body.versions))
71
+ throw new Error(`registry: malformed response for "${name}" at ${registryBase} (missing "versions")`);
72
+ const valid = body.versions.filter(isValidRegistryVersionEntry);
73
+ const dropped = body.versions.length - valid.length;
74
+ if (dropped > 0) {
75
+ ctx.onNotice?.(`registry: dropped ${dropped} malformed version entr${dropped === 1 ? "y" : "ies"} for "${name}" ` +
76
+ `at ${registryBase} (bad version/source/sha shape) — refusing to trust them`);
77
+ }
78
+ return valid.sort((a, b) => compareVersionsDesc(a.version, b.version));
79
+ }
80
+ /** The `owner/repo@skill` shorthand (no explicit ref) resolves to a `github:owner/repo` manifest
81
+ * entry pinned at the repo's default branch — but the single-skill filter it implies has nowhere
82
+ * else to live (manifest pins are plain ref strings, `Record<string,string>`; touching that shape
83
+ * ripples through validateManifest/buildManifest/materializeHarness for a one-slice feature).
84
+ * Instead the filter rides along inside the pin string itself, behind a control-character
85
+ * separator no real git ref name can contain (git refuses control chars in ref names) — so this
86
+ * is unambiguous and invisible to any pin that isn't skill-scoped. */
87
+ const SKILL_PIN_SEP = "";
88
+ export function encodeSkillPin(ref, skill) {
89
+ return `${ref}${SKILL_PIN_SEP}${skill}`;
90
+ }
91
+ /** Exported for display code (e.g. formatting an install/update report) — the raw pin string
92
+ * contains a control character and must never be printed verbatim. */
93
+ export function decodeSkillPin(pin) {
94
+ const at = pin.indexOf(SKILL_PIN_SEP);
95
+ if (at === -1)
96
+ return { ref: pin, onlySkill: undefined };
97
+ return { ref: pin.slice(0, at), onlySkill: pin.slice(at + 1) };
98
+ }
99
+ export async function resolveManifestPacks(manifest, opts = {}) {
100
+ const packs = {};
101
+ const resolutions = {};
102
+ const notes = [];
103
+ const registryBase = registryBaseFor(manifest, opts.registryBase);
104
+ for (const [name, pin] of Object.entries(manifest.packs)) {
105
+ const inline = opts.inlinePacks?.[name];
106
+ if (inline !== undefined) {
107
+ packs[name] = validatePack(inline);
108
+ continue;
109
+ }
110
+ if (isGitSourceName(name)) {
111
+ const { repo } = parseGitSourceName(name);
112
+ const { ref, onlySkill } = decodeSkillPin(pin);
113
+ const resolved = await resolveGitSource({ name, ref, token: opts.token, fetchImpl: opts.fetchImpl, onNotice: opts.onNotice });
114
+ const result = await packFromFileset(resolved.files, { repoName: repo, ref, sha: resolved.sha, onlySkill });
115
+ packs[name] = result.pack;
116
+ resolutions[name] = { ref: pin, sha: resolved.sha, packId: result.pack.id };
117
+ if (result.derived) {
118
+ notes.push(`derived pack from ${name}@${ref}: id "${result.pack.id}", ${(result.pack.skills ?? []).length} skill(s) (no pack.json found — ingested)`);
119
+ }
120
+ continue;
121
+ }
122
+ // Registry-scoped: `pin` is an exact version (manifest pins are always exact — RETURN
123
+ // DECISION 4). Look it up in the index, verify the resolved sha against what the index
124
+ // recorded at publish time (tamper evidence — a moved tag/branch or a compromised registry
125
+ // record must fail loudly, never resolve silently to different content), then ingest exactly
126
+ // like a git install.
127
+ const versions = await fetchRegistryVersions(name, registryBase, { fetchImpl: opts.fetchImpl, onNotice: opts.onNotice });
128
+ const match = versions.find((v) => v.version === pin);
129
+ if (!match) {
130
+ const available = versions.map((v) => v.version).join(", ") || "(none)";
131
+ throw new Error(`install: "${name}@${pin}" not found in registry ${registryBase} — available versions: ${available}`);
132
+ }
133
+ const resolved = await resolveGitSource({
134
+ name: match.source.name, ref: match.source.ref, token: opts.token, fetchImpl: opts.fetchImpl, onNotice: opts.onNotice,
135
+ });
136
+ if (resolved.sha !== match.source.sha) {
137
+ throw new Error(`install: "${name}@${pin}" tamper check failed — registry index says ${match.source.name}@${match.source.ref} ` +
138
+ `resolved to sha ${match.source.sha} at publish time, but it currently resolves to ${resolved.sha}`);
139
+ }
140
+ const { repo } = parseGitSourceName(match.source.name);
141
+ const result = await packFromFileset(resolved.files, { repoName: repo, ref: match.source.ref, sha: resolved.sha });
142
+ packs[name] = result.pack;
143
+ resolutions[name] = { ref: pin, sha: resolved.sha, packId: result.pack.id };
144
+ }
145
+ return { packs, resolutions, notes };
146
+ }
@@ -0,0 +1,18 @@
1
+ /** Thrown by mergeBaselaneHooks when existing settings are present but aren't a valid JSON
2
+ * object — the caller must bail on write rather than merge over an empty stand-in, or the
3
+ * developer's permissions/model/env/MCP config gets silently erased. */
4
+ export declare class SettingsParseError extends Error {
5
+ }
6
+ /**
7
+ * Whether an existing `~/.claude/settings.json` has any baselane-managed hook entries
8
+ * that a merge would need to prune. Lets callers skip merging (and rewriting) settings
9
+ * files we've never touched — e.g. a developer's hand-written settings with no baselane
10
+ * hooks in them at all.
11
+ */
12
+ export declare function hasManagedHooks(existingSettingsJson: string | null): boolean;
13
+ /**
14
+ * Merge this pack's hooks into a developer's existing `~/.claude/settings.json`.
15
+ * Every hook we own is tagged with a `BASELANE_MANAGED=1 ` command prefix so a later
16
+ * merge can find and replace our own prior entries without touching the developer's.
17
+ */
18
+ export declare function mergeBaselaneHooks(existingSettingsJson: string | null, packSettingsJson: string): string;
@@ -0,0 +1,69 @@
1
+ const BASELANE_PREFIX = "BASELANE_MANAGED=1 ";
2
+ /** Thrown by mergeBaselaneHooks when existing settings are present but aren't a valid JSON
3
+ * object — the caller must bail on write rather than merge over an empty stand-in, or the
4
+ * developer's permissions/model/env/MCP config gets silently erased. */
5
+ export class SettingsParseError extends Error {
6
+ }
7
+ function tryParseSettings(json) {
8
+ try {
9
+ const parsed = JSON.parse(json);
10
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
11
+ return null;
12
+ return parsed;
13
+ }
14
+ catch {
15
+ return null;
16
+ }
17
+ }
18
+ // Lenient: malformed input reads as "no settings at all". Only safe for read-only checks
19
+ // (e.g. "does this file already have managed hooks to prune?") — never for deciding what to
20
+ // WRITE. mergeBaselaneHooks below parses strictly and throws instead.
21
+ function parseSettings(json) {
22
+ if (json === null)
23
+ return {};
24
+ return tryParseSettings(json) ?? {};
25
+ }
26
+ function isBaselaneManaged(entry) {
27
+ return entry.hooks.some((h) => h.command.startsWith(BASELANE_PREFIX));
28
+ }
29
+ /**
30
+ * Whether an existing `~/.claude/settings.json` has any baselane-managed hook entries
31
+ * that a merge would need to prune. Lets callers skip merging (and rewriting) settings
32
+ * files we've never touched — e.g. a developer's hand-written settings with no baselane
33
+ * hooks in them at all.
34
+ */
35
+ export function hasManagedHooks(existingSettingsJson) {
36
+ const existing = parseSettings(existingSettingsJson);
37
+ const existingHooks = existing.hooks ?? {};
38
+ return Object.values(existingHooks).some((entries) => entries.some(isBaselaneManaged));
39
+ }
40
+ /**
41
+ * Merge this pack's hooks into a developer's existing `~/.claude/settings.json`.
42
+ * Every hook we own is tagged with a `BASELANE_MANAGED=1 ` command prefix so a later
43
+ * merge can find and replace our own prior entries without touching the developer's.
44
+ */
45
+ export function mergeBaselaneHooks(existingSettingsJson, packSettingsJson) {
46
+ let existing = {};
47
+ if (existingSettingsJson !== null) {
48
+ const parsed = tryParseSettings(existingSettingsJson);
49
+ if (parsed === null) {
50
+ throw new SettingsParseError("existing settings.json is not a valid JSON object — refusing to merge over it");
51
+ }
52
+ existing = parsed;
53
+ }
54
+ const pack = parseSettings(packSettingsJson);
55
+ const existingHooks = existing.hooks ?? {};
56
+ const packHooks = pack.hooks ?? {};
57
+ const events = [...new Set([...Object.keys(existingHooks), ...Object.keys(packHooks)])];
58
+ const mergedHooks = {};
59
+ for (const event of events) {
60
+ const kept = (existingHooks[event] ?? []).filter((entry) => !isBaselaneManaged(entry));
61
+ const ours = (packHooks[event] ?? []).map((entry) => ({
62
+ ...entry,
63
+ hooks: entry.hooks.map((h) => ({ ...h, command: BASELANE_PREFIX + h.command })),
64
+ }));
65
+ mergedHooks[event] = [...kept, ...ours];
66
+ }
67
+ const merged = { ...existing, hooks: mergedHooks };
68
+ return JSON.stringify(merged, null, 2) + "\n";
69
+ }
@@ -0,0 +1,34 @@
1
+ /** One onboarding step the portal wants surfaced to this device's developer (bundle version 2). */
2
+ export interface BundleOnboardingStep {
3
+ packId: string;
4
+ stepId: string;
5
+ title: string;
6
+ description: string;
7
+ command?: string;
8
+ }
9
+ /** Approved config bundle: target-relative POSIX path → file content. Version 2 adds informational
10
+ * metadata (the effective pack ids, whole-file collisions, and pending onboarding steps); the
11
+ * file-map contract is unchanged, so a version-1 bundle is a strict subset. */
12
+ export interface Bundle {
13
+ version: 1 | 2;
14
+ files: Record<string, string>;
15
+ packIds?: string[];
16
+ collisions?: string[];
17
+ onboarding?: BundleOnboardingStep[];
18
+ }
19
+ /** What baselane manages in the target dir: path → sha256 of the content we wrote. */
20
+ export interface Manifest {
21
+ version: 1;
22
+ files: Record<string, string>;
23
+ }
24
+ /** Result of planning a reconcile — pure data, no side effects. */
25
+ export interface ReconcilePlan {
26
+ /** Bundle paths whose on-disk content differs (or is absent): will be (over)written. */
27
+ writes: string[];
28
+ /** Paths in the manifest but not in the bundle and still on disk: will be removed. */
29
+ deletes: string[];
30
+ /** Managed paths whose on-disk content no longer matches the manifest hash (local edits). */
31
+ drifted: string[];
32
+ /** Bundle paths already byte-identical on disk. */
33
+ unchanged: string[];
34
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@baselane/materialize",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Disk-reconcile and install engine (plan/apply/receipt/settings-merge/manifest-io/resolve/install) shared by the baselane CLI and desktop agent.",
6
+ "main": "./dist/index.js",
7
+ "license": "Apache-2.0",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/mohammad0omar/baselane.sh.git",
11
+ "directory": "packages/materialize"
12
+ },
13
+ "homepage": "https://baselane.sh",
14
+ "files": [
15
+ "dist/",
16
+ "README.md"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "dependencies": {
22
+ "@baselane/packs": "0.1.0",
23
+ "@baselane/distribute": "0.1.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^24.0.0",
27
+ "typescript": "^5.9.0",
28
+ "vitest": "^2.0.0"
29
+ },
30
+ "scripts": {
31
+ "test": "vitest run",
32
+ "typecheck": "tsc --noEmit",
33
+ "build": "tsc -p tsconfig.build.json"
34
+ },
35
+ "types": "./dist/index.d.ts"
36
+ }