@hasna/snapshots 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.
Files changed (55) hide show
  1. package/LICENSE +130 -0
  2. package/README.md +90 -0
  3. package/dist/agent/index.d.ts +3 -0
  4. package/dist/agent/index.d.ts.map +1 -0
  5. package/dist/agent/index.js +12 -0
  6. package/dist/agent/index.js.map +1 -0
  7. package/dist/capture/index.d.ts +3 -0
  8. package/dist/capture/index.d.ts.map +1 -0
  9. package/dist/capture/index.js +267 -0
  10. package/dist/capture/index.js.map +1 -0
  11. package/dist/cli/index.d.ts +3 -0
  12. package/dist/cli/index.d.ts.map +1 -0
  13. package/dist/cli/index.js +195 -0
  14. package/dist/cli/index.js.map +1 -0
  15. package/dist/index.d.ts +8 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +8 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/mcp/index.d.ts +3 -0
  20. package/dist/mcp/index.d.ts.map +1 -0
  21. package/dist/mcp/index.js +116 -0
  22. package/dist/mcp/index.js.map +1 -0
  23. package/dist/policy.d.ts +5 -0
  24. package/dist/policy.d.ts.map +1 -0
  25. package/dist/policy.js +38 -0
  26. package/dist/policy.js.map +1 -0
  27. package/dist/restore.d.ts +4 -0
  28. package/dist/restore.d.ts.map +1 -0
  29. package/dist/restore.js +157 -0
  30. package/dist/restore.js.map +1 -0
  31. package/dist/runtime.d.ts +38 -0
  32. package/dist/runtime.d.ts.map +1 -0
  33. package/dist/runtime.js +91 -0
  34. package/dist/runtime.js.map +1 -0
  35. package/dist/server/index.d.ts +3 -0
  36. package/dist/server/index.d.ts.map +1 -0
  37. package/dist/server/index.js +51 -0
  38. package/dist/server/index.js.map +1 -0
  39. package/dist/service.d.ts +16 -0
  40. package/dist/service.d.ts.map +1 -0
  41. package/dist/service.js +84 -0
  42. package/dist/service.js.map +1 -0
  43. package/dist/storage.d.ts +25 -0
  44. package/dist/storage.d.ts.map +1 -0
  45. package/dist/storage.js +215 -0
  46. package/dist/storage.js.map +1 -0
  47. package/dist/types.d.ts +90 -0
  48. package/dist/types.d.ts.map +1 -0
  49. package/dist/types.js +2 -0
  50. package/dist/types.js.map +1 -0
  51. package/dist/util.d.ts +26 -0
  52. package/dist/util.d.ts.map +1 -0
  53. package/dist/util.js +113 -0
  54. package/dist/util.js.map +1 -0
  55. package/package.json +78 -0
package/dist/util.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { JsonValue } from "./types.js";
2
+ export declare function nowIso(): string;
3
+ export declare function defaultDataDir(): string;
4
+ export declare function defaultDbPath(): string;
5
+ export declare function ensureParentDir(path: string): void;
6
+ export declare function ensureDir(path: string): void;
7
+ export declare function sha256(input: string): string;
8
+ export declare function stableJson(value: JsonValue): string;
9
+ export declare function sortJson(value: JsonValue): JsonValue;
10
+ export declare function safeParseJson(text: string): JsonValue | undefined;
11
+ export declare function commandExists(command: string): boolean;
12
+ export interface CommandResult {
13
+ ok: boolean;
14
+ status: number | null;
15
+ stdout: string;
16
+ stderr: string;
17
+ error?: string;
18
+ }
19
+ export declare function runCommand(command: string, args?: string[], timeoutMs?: number): CommandResult;
20
+ export declare function runJsonCommand(command: string, args?: string[], timeoutMs?: number): JsonValue | undefined;
21
+ export declare function redactText(input: string): string;
22
+ export declare function redactJson(value: JsonValue): JsonValue;
23
+ export declare function shellQuote(value: string): string;
24
+ export declare function slugPart(value: string): string;
25
+ export declare function fileExists(path: string | undefined): path is string;
26
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,YAAY,CAAC;AAExD,wBAAgB,MAAM,IAAI,MAAM,CAE/B;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wBAAgB,eAAe,CAAC,IAAI,E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createHash } from "node:crypto";
2
+ import { existsSync, mkdirSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ import { homedir } from "node:os";
5
+ import { spawnSync } from "node:child_process";
6
+ export function nowIso() {
7
+ return new Date().toISOString();
8
+ }
9
+ export function defaultDataDir() {
10
+ return process.env.HASNA_SNAPSHOTS_DIR ?? join(homedir(), ".hasna", "snapshots");
11
+ }
12
+ export function defaultDbPath() {
13
+ return process.env.HASNA_SNAPSHOTS_DB_PATH ?? join(defaultDataDir(), "snapshots.sqlite");
14
+ }
15
+ export function ensureParentDir(path) {
16
+ mkdirSync(dirname(path), { recursive: true });
17
+ }
18
+ export function ensureDir(path) {
19
+ mkdirSync(path, { recursive: true });
20
+ }
21
+ export function sha256(input) {
22
+ return createHash("sha256").update(input).digest("hex");
23
+ }
24
+ export function stableJson(value) {
25
+ return JSON.stringify(sortJson(value));
26
+ }
27
+ export function sortJson(value) {
28
+ if (Array.isArray(value)) {
29
+ return value.map(sortJson);
30
+ }
31
+ if (value && typeof value === "object") {
32
+ const sorted = {};
33
+ for (const key of Object.keys(value).sort()) {
34
+ sorted[key] = sortJson(value[key]);
35
+ }
36
+ return sorted;
37
+ }
38
+ return value;
39
+ }
40
+ export function safeParseJson(text) {
41
+ try {
42
+ return JSON.parse(text);
43
+ }
44
+ catch {
45
+ return undefined;
46
+ }
47
+ }
48
+ export function commandExists(command) {
49
+ const result = spawnSync("sh", ["-lc", `command -v ${shellQuote(command)}`], {
50
+ encoding: "utf8",
51
+ stdio: ["ignore", "pipe", "pipe"],
52
+ timeout: 2_000
53
+ });
54
+ return result.status === 0;
55
+ }
56
+ export function runCommand(command, args = [], timeoutMs = 5_000) {
57
+ const result = spawnSync(command, args, {
58
+ encoding: "utf8",
59
+ stdio: ["ignore", "pipe", "pipe"],
60
+ timeout: timeoutMs
61
+ });
62
+ return {
63
+ ok: result.status === 0,
64
+ status: result.status,
65
+ stdout: result.stdout ?? "",
66
+ stderr: result.stderr ?? "",
67
+ error: result.error?.message
68
+ };
69
+ }
70
+ export function runJsonCommand(command, args = [], timeoutMs = 5_000) {
71
+ const result = runCommand(command, args, timeoutMs);
72
+ if (!result.ok)
73
+ return undefined;
74
+ return safeParseJson(result.stdout);
75
+ }
76
+ export function redactText(input) {
77
+ return input
78
+ .replace(/([A-Za-z_]*(?:TOKEN|SECRET|KEY|PASSWORD|PASS|COOKIE)[A-Za-z_]*=)[^\s]+/gi, "$1[redacted]")
79
+ .replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi, "$1[redacted]")
80
+ .replace(/(https?:\/\/[^:\s/]+:)[^@\s/]+(@)/gi, "$1[redacted]$2");
81
+ }
82
+ export function redactJson(value) {
83
+ if (Array.isArray(value)) {
84
+ return value.map(redactJson);
85
+ }
86
+ if (value && typeof value === "object") {
87
+ const redacted = {};
88
+ for (const [key, child] of Object.entries(value)) {
89
+ if (/token|secret|key|password|pass|cookie/i.test(key)) {
90
+ redacted[key] = "[redacted]";
91
+ }
92
+ else {
93
+ redacted[key] = redactJson(child);
94
+ }
95
+ }
96
+ return redacted;
97
+ }
98
+ if (typeof value === "string") {
99
+ return redactText(value);
100
+ }
101
+ return value;
102
+ }
103
+ export function shellQuote(value) {
104
+ return `'${value.replaceAll("'", "'\\''")}'`;
105
+ }
106
+ export function slugPart(value) {
107
+ const slug = value.trim().toLowerCase().replace(/[^a-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "");
108
+ return slug || sha256(value).slice(0, 12);
109
+ }
110
+ export function fileExists(path) {
111
+ return Boolean(path && existsSync(path));
112
+ }
113
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CA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AAC;IAClB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC/F,OAAO,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAwB;IACjD,OAAO,OAAO,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@hasna/snapshots",
3
+ "version": "0.1.0",
4
+ "description": "Runtime snapshot and restore layer for Hasna local open-source developer environments.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "snapshots": "dist/cli/index.js",
10
+ "snapshots-agent": "dist/agent/index.js",
11
+ "snapshots-mcp": "dist/mcp/index.js",
12
+ "snapshots-serve": "dist/server/index.js"
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ },
19
+ "./storage": {
20
+ "types": "./dist/storage.d.ts",
21
+ "import": "./dist/storage.js"
22
+ },
23
+ "./policy": {
24
+ "types": "./dist/policy.d.ts",
25
+ "import": "./dist/policy.js"
26
+ },
27
+ "./restore": {
28
+ "types": "./dist/restore.d.ts",
29
+ "import": "./dist/restore.js"
30
+ },
31
+ "./capture": {
32
+ "types": "./dist/capture/index.d.ts",
33
+ "import": "./dist/capture/index.js"
34
+ },
35
+ "./service": {
36
+ "types": "./dist/service.d.ts",
37
+ "import": "./dist/service.js"
38
+ }
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "README.md",
43
+ "LICENSE"
44
+ ],
45
+ "scripts": {
46
+ "build": "bunx tsc -p tsconfig.json",
47
+ "typecheck": "bunx tsc --noEmit",
48
+ "test": "bun test",
49
+ "verify:release": "bun run typecheck && bun test && bun run build",
50
+ "prepublishOnly": "bun run verify:release",
51
+ "postinstall": "mkdir -p $HOME/.hasna/snapshots/{exports,logs,plans} 2>/dev/null || true"
52
+ },
53
+ "keywords": [
54
+ "snapshots",
55
+ "restore",
56
+ "developer-tools",
57
+ "mcp",
58
+ "cli",
59
+ "hasna"
60
+ ],
61
+ "publishConfig": {
62
+ "registry": "https://registry.npmjs.org/",
63
+ "access": "public"
64
+ },
65
+ "repository": {
66
+ "type": "git",
67
+ "url": "git+https://github.com/hasna/snapshots.git"
68
+ },
69
+ "engines": {
70
+ "bun": ">=1.0.0"
71
+ },
72
+ "author": "Andrei Hasna <andrei@hasna.com>",
73
+ "license": "Apache-2.0",
74
+ "devDependencies": {
75
+ "@types/bun": "^1.3.14",
76
+ "typescript": "^5.9.3"
77
+ }
78
+ }