@hasna/snapshots 0.1.2 → 0.1.3

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
@@ -43,6 +43,89 @@ HASNA_SNAPSHOTS_DIR=/path/to/data
43
43
  HASNA_SNAPSHOTS_DB_PATH=/path/to/snapshots.sqlite
44
44
  ```
45
45
 
46
+ ## SDK
47
+
48
+ The package exposes typed SDK exports from the root package and focused subpaths:
49
+
50
+ ```ts
51
+ import { SnapshotStore, captureAll, createRestorePlan } from "@hasna/snapshots";
52
+ import { planService } from "@hasna/snapshots/service";
53
+ ```
54
+
55
+ Capture and store a snapshot:
56
+
57
+ ```ts
58
+ import { SnapshotStore, captureAll } from "@hasna/snapshots";
59
+
60
+ const store = new SnapshotStore({ path: "/tmp/snapshots.sqlite" });
61
+ try {
62
+ const capture = await captureAll({
63
+ include: ["machine", "projects", "tmux"],
64
+ tmuxPaneTailLines: 0,
65
+ });
66
+
67
+ const snapshot = store.saveSnapshot(capture.resources, {
68
+ name: "before-upgrade",
69
+ diagnostics: capture.diagnostics,
70
+ sourceStatuses: capture.sourceStatuses,
71
+ });
72
+
73
+ console.log(snapshot.id, snapshot.resourceCount);
74
+ } finally {
75
+ store.close();
76
+ }
77
+ ```
78
+
79
+ Build a guarded restore plan without applying it:
80
+
81
+ ```ts
82
+ import { SnapshotStore, createRestorePlan } from "@hasna/snapshots";
83
+
84
+ const store = new SnapshotStore();
85
+ try {
86
+ const [snapshot] = store.listSnapshots(1);
87
+ if (!snapshot) throw new Error("No snapshots found");
88
+
89
+ const resources = store.getSnapshotResources(snapshot.id);
90
+ const policies = store.listPolicies();
91
+ const plan = createRestorePlan(snapshot, resources, policies, {
92
+ include: ["tmux-session:work"],
93
+ dependencyMode: "parents",
94
+ targetMode: "strict",
95
+ });
96
+
97
+ store.saveRestorePlan(plan);
98
+ console.log(plan.id, plan.summary, plan.autopilot);
99
+ } finally {
100
+ store.close();
101
+ }
102
+ ```
103
+
104
+ Service planning is SDK-only until callers explicitly write/apply the generated plan:
105
+
106
+ ```ts
107
+ import { planService } from "@hasna/snapshots/service";
108
+
109
+ const plan = planService({ intervalSeconds: 300 });
110
+ console.log(plan.kind, plan.path, plan.note);
111
+ ```
112
+
113
+ ### Interface Parity
114
+
115
+ | Workflow | CLI | SDK | MCP | HTTP server |
116
+ | --- | --- | --- | --- | --- |
117
+ | Capture snapshot | `snapshots capture`, `snapshots daemon once` | `captureAll`, `SnapshotStore.saveSnapshot` | `capture_snapshot` | `POST /snapshots` |
118
+ | List snapshots | `snapshots list` | `SnapshotStore.listSnapshots` | `list_snapshots` | `GET /snapshots` |
119
+ | Read snapshot/resources | `snapshots show`, `snapshots resources` | `SnapshotStore.getSnapshot`, `SnapshotStore.getSnapshotResources`, `SnapshotStore.listResources` | `get_snapshot` | `GET /snapshots/:id` |
120
+ | Plan restore | `snapshots plan`, `snapshots restore` without `--apply` | `createRestorePlan`, `SnapshotStore.saveRestorePlan` | `plan_restore` | not exposed |
121
+ | Apply restore | `snapshots restore --apply --yes` | `createRestorePlan(..., { apply: true, yes: true })` | intentionally not exposed | not exposed |
122
+ | Policy management | `snapshots policy list/set` | `SnapshotStore.listPolicies`, `SnapshotStore.upsertPolicy` | intentionally not exposed | not exposed |
123
+ | Service planning | `snapshots service plan/status/install` | `planService`, `serviceStatus`, `applyServicePlan` | intentionally not exposed | not exposed |
124
+
125
+ MCP intentionally exposes only capture, list, read, and plan tools. Restore
126
+ execution and service installation mutate local machine state, so they stay in
127
+ the CLI/SDK surfaces where callers must opt in explicitly.
128
+
46
129
  ## CLI
47
130
 
48
131
  ```sh
File without changes
package/dist/cli/index.js CHANGED
File without changes
package/dist/mcp/index.js CHANGED
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/snapshots",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Runtime snapshot and restore layer for Hasna local open-source developer environments.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -46,6 +46,7 @@
46
46
  "build": "bun x tsc -p tsconfig.json",
47
47
  "typecheck": "bun x tsc --noEmit",
48
48
  "test": "bun test",
49
+ "check": "bun run typecheck && bun test && bun run build",
49
50
  "verify:release": "bun run typecheck && bun test && bun run build",
50
51
  "prepublishOnly": "bun run verify:release",
51
52
  "postinstall": "mkdir -p $HOME/.hasna/snapshots/{exports,logs,plans} 2>/dev/null || true"