@claude-flow/cli 3.6.23 → 3.6.25

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 (62) hide show
  1. package/.claude/helpers/github-safe.js +64 -49
  2. package/.claude/helpers/statusline.cjs +11 -13
  3. package/.claude/helpers/statusline.js +11 -6
  4. package/README.md +8 -2
  5. package/bin/cli.js +21 -0
  6. package/bin/mcp-server.js +16 -0
  7. package/dist/src/commands/appliance.d.ts.map +1 -1
  8. package/dist/src/commands/appliance.js +8 -10
  9. package/dist/src/commands/appliance.js.map +1 -1
  10. package/dist/src/commands/guidance.d.ts.map +1 -1
  11. package/dist/src/commands/guidance.js +1 -5
  12. package/dist/src/commands/guidance.js.map +1 -1
  13. package/dist/src/commands/performance.d.ts.map +1 -1
  14. package/dist/src/commands/performance.js +3 -3
  15. package/dist/src/commands/performance.js.map +1 -1
  16. package/dist/src/commands/process.d.ts.map +1 -1
  17. package/dist/src/commands/process.js +6 -7
  18. package/dist/src/commands/process.js.map +1 -1
  19. package/dist/src/commands/verify.d.ts.map +1 -1
  20. package/dist/src/commands/verify.js +24 -3
  21. package/dist/src/commands/verify.js.map +1 -1
  22. package/dist/src/encryption/vault.d.ts +94 -0
  23. package/dist/src/encryption/vault.d.ts.map +1 -0
  24. package/dist/src/encryption/vault.js +172 -0
  25. package/dist/src/encryption/vault.js.map +1 -0
  26. package/dist/src/fs-secure.d.ts +67 -0
  27. package/dist/src/fs-secure.d.ts.map +1 -0
  28. package/dist/src/fs-secure.js +74 -0
  29. package/dist/src/fs-secure.js.map +1 -0
  30. package/dist/src/mcp-tools/github-tools.d.ts.map +1 -1
  31. package/dist/src/mcp-tools/github-tools.js +122 -31
  32. package/dist/src/mcp-tools/github-tools.js.map +1 -1
  33. package/dist/src/mcp-tools/hooks-tools.js +2 -2
  34. package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
  35. package/dist/src/mcp-tools/memory-tools.d.ts.map +1 -1
  36. package/dist/src/mcp-tools/memory-tools.js +7 -12
  37. package/dist/src/mcp-tools/memory-tools.js.map +1 -1
  38. package/dist/src/mcp-tools/session-tools.d.ts.map +1 -1
  39. package/dist/src/mcp-tools/session-tools.js +24 -12
  40. package/dist/src/mcp-tools/session-tools.js.map +1 -1
  41. package/dist/src/mcp-tools/terminal-tools.d.ts.map +1 -1
  42. package/dist/src/mcp-tools/terminal-tools.js +22 -7
  43. package/dist/src/mcp-tools/terminal-tools.js.map +1 -1
  44. package/dist/src/mcp-tools/validate-input.d.ts +12 -0
  45. package/dist/src/mcp-tools/validate-input.d.ts.map +1 -1
  46. package/dist/src/mcp-tools/validate-input.js +56 -0
  47. package/dist/src/mcp-tools/validate-input.js.map +1 -1
  48. package/dist/src/memory/memory-bridge.d.ts.map +1 -1
  49. package/dist/src/memory/memory-bridge.js +33 -3
  50. package/dist/src/memory/memory-bridge.js.map +1 -1
  51. package/dist/src/memory/memory-initializer.d.ts.map +1 -1
  52. package/dist/src/memory/memory-initializer.js +17 -16
  53. package/dist/src/memory/memory-initializer.js.map +1 -1
  54. package/dist/src/transfer/ipfs/upload.d.ts.map +1 -1
  55. package/dist/src/transfer/ipfs/upload.js +2 -0
  56. package/dist/src/transfer/ipfs/upload.js.map +1 -1
  57. package/dist/src/update/executor.d.ts +1 -0
  58. package/dist/src/update/executor.d.ts.map +1 -1
  59. package/dist/src/update/executor.js +43 -7
  60. package/dist/src/update/executor.js.map +1 -1
  61. package/dist/tsconfig.tsbuildinfo +1 -1
  62. package/package.json +1 -1
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Encryption-at-rest vault primitives (ADR-096 Phase 1).
3
+ *
4
+ * Goal: provide deterministic encrypt/decrypt of arbitrary Buffers with a
5
+ * symmetric key, using a magic-byte format so readers of older plaintext
6
+ * stores can detect-then-pass-through during the migration window.
7
+ *
8
+ * Phase 1 deliberately ships only the cipher primitives + the env-var key
9
+ * source. Keychain (keytar) and interactive passphrase resolution land in
10
+ * a follow-up iteration so the blast radius of this commit is limited to
11
+ * a single self-contained module with no native dependencies.
12
+ *
13
+ * Wire format (output of encryptBuffer):
14
+ *
15
+ * +---------+-----------+----------------+--------+
16
+ * | magic 4 | iv 12 | ciphertext N | tag 16 |
17
+ * +---------+-----------+----------------+--------+
18
+ * "RFE1" random AES-256-GCM GCM
19
+ *
20
+ * The magic distinguishes encrypted blobs from plaintext during the
21
+ * incremental migration: readers call isEncryptedBlob() and either
22
+ * decryptBuffer() or treat the bytes as plaintext, so existing
23
+ * .claude-flow/sessions/*.json files keep working unchanged.
24
+ */
25
+ /** ASCII "RFE1" — Ruflo File Encrypted v1. 4 bytes. */
26
+ export declare const MAGIC: Buffer<ArrayBuffer>;
27
+ /**
28
+ * True when at-rest encryption should be applied to writes.
29
+ *
30
+ * Truthy values: "1", "true", "yes", "on" (case-insensitive). Anything else
31
+ * — including unset — keeps the legacy plaintext path. This is the gate
32
+ * that lets the 1865-test baseline keep passing unchanged while users opt
33
+ * into encryption.
34
+ */
35
+ export declare function isEncryptionEnabled(): boolean;
36
+ /**
37
+ * Resolve a 32-byte encryption key from CLAUDE_FLOW_ENCRYPTION_KEY.
38
+ *
39
+ * Phase 1 supports only the env-var source; keychain and passphrase
40
+ * resolution are deferred to a follow-up iteration (see ADR-096). When
41
+ * encryption is enabled but no key resolves, this throws with a clear
42
+ * message rather than silently falling back to plaintext (fail-closed).
43
+ *
44
+ * Accepted encodings (auto-detected by length):
45
+ * - 64-char hex (32 bytes)
46
+ * - 44-char base64 (32 bytes + padding)
47
+ * - exactly 32 raw bytes (rare; for callers that pre-decode)
48
+ *
49
+ * Anything else is rejected — we'd rather fail loudly than encrypt with a
50
+ * truncated key.
51
+ */
52
+ export declare function getKey(): Buffer;
53
+ /**
54
+ * Decode a key string. Exposed for testing and for the future passphrase
55
+ * resolver, which will scrypt-derive a Buffer and hand it back through here
56
+ * to share the same length-check.
57
+ */
58
+ export declare function decodeKey(raw: string): Buffer;
59
+ /**
60
+ * Encrypt a plaintext Buffer with AES-256-GCM. Returns the wire-format
61
+ * blob: magic(4) || iv(12) || ciphertext(N) || tag(16).
62
+ *
63
+ * The IV is freshly randomized per call. Reusing a (key, iv) pair under
64
+ * GCM is catastrophic — every call MUST produce a different IV. Node's
65
+ * randomBytes is csprng-backed so this is automatic; the function takes
66
+ * no IV input deliberately.
67
+ */
68
+ export declare function encryptBuffer(plaintext: Buffer, key: Buffer): Buffer;
69
+ /**
70
+ * Decrypt a wire-format blob. Verifies the magic byte (sanity), parses
71
+ * iv + ciphertext + tag, runs AES-256-GCM decrypt, and lets the GCM
72
+ * auth tag fail loudly on tamper (Node throws "Unsupported state or
73
+ * unable to authenticate data" — we let that propagate).
74
+ *
75
+ * Pre-condition: caller has already determined this is an encrypted
76
+ * blob via isEncryptedBlob(). decryptBuffer throws on bad magic so a
77
+ * mistaken plaintext blob still fails loudly rather than producing
78
+ * garbage.
79
+ */
80
+ export declare function decryptBuffer(blob: Buffer, key: Buffer): Buffer;
81
+ /**
82
+ * Magic-byte sniff. True iff the blob starts with the RFE1 magic AND is
83
+ * long enough to be a valid encrypted blob. Used by readers during the
84
+ * incremental migration: legacy plaintext files return false and flow
85
+ * through the existing read path unchanged.
86
+ *
87
+ * Note: this is a heuristic. A plaintext file that happens to start with
88
+ * "RFE1" would be misdetected — we accept that vanishingly small risk
89
+ * because (a) the four bytes 0x52,0x46,0x45,0x31 are an unusual prefix
90
+ * for JSON (`{`, `[`) or SQLite (`SQLite format 3`), and (b) decryption
91
+ * will then fail with a clear error rather than silently corrupt.
92
+ */
93
+ export declare function isEncryptedBlob(blob: Buffer): boolean;
94
+ //# sourceMappingURL=vault.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../../../src/encryption/vault.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAWH,uDAAuD;AACvD,eAAO,MAAM,KAAK,qBAAwC,CAAC;AAa3D;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAK7C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAU/B;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAc7C;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAYpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CA2B/D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIrD"}
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Encryption-at-rest vault primitives (ADR-096 Phase 1).
3
+ *
4
+ * Goal: provide deterministic encrypt/decrypt of arbitrary Buffers with a
5
+ * symmetric key, using a magic-byte format so readers of older plaintext
6
+ * stores can detect-then-pass-through during the migration window.
7
+ *
8
+ * Phase 1 deliberately ships only the cipher primitives + the env-var key
9
+ * source. Keychain (keytar) and interactive passphrase resolution land in
10
+ * a follow-up iteration so the blast radius of this commit is limited to
11
+ * a single self-contained module with no native dependencies.
12
+ *
13
+ * Wire format (output of encryptBuffer):
14
+ *
15
+ * +---------+-----------+----------------+--------+
16
+ * | magic 4 | iv 12 | ciphertext N | tag 16 |
17
+ * +---------+-----------+----------------+--------+
18
+ * "RFE1" random AES-256-GCM GCM
19
+ *
20
+ * The magic distinguishes encrypted blobs from plaintext during the
21
+ * incremental migration: readers call isEncryptedBlob() and either
22
+ * decryptBuffer() or treat the bytes as plaintext, so existing
23
+ * .claude-flow/sessions/*.json files keep working unchanged.
24
+ */
25
+ import { createCipheriv, createDecipheriv, randomBytes, timingSafeEqual, } from 'node:crypto';
26
+ // ── Constants ────────────────────────────────────────────────────────────────
27
+ /** ASCII "RFE1" — Ruflo File Encrypted v1. 4 bytes. */
28
+ export const MAGIC = Buffer.from([0x52, 0x46, 0x45, 0x31]); // "RFE1"
29
+ const MAGIC_LEN = MAGIC.length; // 4
30
+ const IV_LEN = 12; // GCM-recommended nonce size
31
+ const TAG_LEN = 16; // GCM auth tag
32
+ const KEY_LEN = 32; // AES-256
33
+ const ALG = 'aes-256-gcm';
34
+ const MIN_BLOB_LEN = MAGIC_LEN + IV_LEN + TAG_LEN; // empty plaintext still has these
35
+ const ENV_ENABLE_FLAG = 'CLAUDE_FLOW_ENCRYPT_AT_REST';
36
+ const ENV_KEY_VAR = 'CLAUDE_FLOW_ENCRYPTION_KEY';
37
+ // ── Public API ───────────────────────────────────────────────────────────────
38
+ /**
39
+ * True when at-rest encryption should be applied to writes.
40
+ *
41
+ * Truthy values: "1", "true", "yes", "on" (case-insensitive). Anything else
42
+ * — including unset — keeps the legacy plaintext path. This is the gate
43
+ * that lets the 1865-test baseline keep passing unchanged while users opt
44
+ * into encryption.
45
+ */
46
+ export function isEncryptionEnabled() {
47
+ const v = process.env[ENV_ENABLE_FLAG];
48
+ if (typeof v !== 'string')
49
+ return false;
50
+ const norm = v.trim().toLowerCase();
51
+ return norm === '1' || norm === 'true' || norm === 'yes' || norm === 'on';
52
+ }
53
+ /**
54
+ * Resolve a 32-byte encryption key from CLAUDE_FLOW_ENCRYPTION_KEY.
55
+ *
56
+ * Phase 1 supports only the env-var source; keychain and passphrase
57
+ * resolution are deferred to a follow-up iteration (see ADR-096). When
58
+ * encryption is enabled but no key resolves, this throws with a clear
59
+ * message rather than silently falling back to plaintext (fail-closed).
60
+ *
61
+ * Accepted encodings (auto-detected by length):
62
+ * - 64-char hex (32 bytes)
63
+ * - 44-char base64 (32 bytes + padding)
64
+ * - exactly 32 raw bytes (rare; for callers that pre-decode)
65
+ *
66
+ * Anything else is rejected — we'd rather fail loudly than encrypt with a
67
+ * truncated key.
68
+ */
69
+ export function getKey() {
70
+ const raw = process.env[ENV_KEY_VAR];
71
+ if (!raw) {
72
+ throw new Error(`${ENV_ENABLE_FLAG} is set but ${ENV_KEY_VAR} is not. ` +
73
+ `Provide a 32-byte key as 64-char hex or 44-char base64. ` +
74
+ `See ADR-096 for keychain/passphrase support (coming in a follow-up).`);
75
+ }
76
+ return decodeKey(raw);
77
+ }
78
+ /**
79
+ * Decode a key string. Exposed for testing and for the future passphrase
80
+ * resolver, which will scrypt-derive a Buffer and hand it back through here
81
+ * to share the same length-check.
82
+ */
83
+ export function decodeKey(raw) {
84
+ const trimmed = raw.trim();
85
+ // Hex first — strict 64 chars [0-9a-fA-F]
86
+ if (/^[0-9a-fA-F]{64}$/.test(trimmed)) {
87
+ return Buffer.from(trimmed, 'hex');
88
+ }
89
+ // Base64 — accept padded 44-char or unpadded 43-char forms
90
+ if (/^[A-Za-z0-9+/]{43}=?$/.test(trimmed)) {
91
+ const buf = Buffer.from(trimmed, 'base64');
92
+ if (buf.length === KEY_LEN)
93
+ return buf;
94
+ }
95
+ throw new Error(`Invalid ${ENV_KEY_VAR}: expected 32-byte key as 64-char hex or 44-char base64`);
96
+ }
97
+ /**
98
+ * Encrypt a plaintext Buffer with AES-256-GCM. Returns the wire-format
99
+ * blob: magic(4) || iv(12) || ciphertext(N) || tag(16).
100
+ *
101
+ * The IV is freshly randomized per call. Reusing a (key, iv) pair under
102
+ * GCM is catastrophic — every call MUST produce a different IV. Node's
103
+ * randomBytes is csprng-backed so this is automatic; the function takes
104
+ * no IV input deliberately.
105
+ */
106
+ export function encryptBuffer(plaintext, key) {
107
+ if (!Buffer.isBuffer(plaintext)) {
108
+ throw new TypeError('encryptBuffer: plaintext must be a Buffer');
109
+ }
110
+ if (!Buffer.isBuffer(key) || key.length !== KEY_LEN) {
111
+ throw new TypeError(`encryptBuffer: key must be a ${KEY_LEN}-byte Buffer`);
112
+ }
113
+ const iv = randomBytes(IV_LEN);
114
+ const cipher = createCipheriv(ALG, key, iv);
115
+ const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
116
+ const tag = cipher.getAuthTag();
117
+ return Buffer.concat([MAGIC, iv, ciphertext, tag]);
118
+ }
119
+ /**
120
+ * Decrypt a wire-format blob. Verifies the magic byte (sanity), parses
121
+ * iv + ciphertext + tag, runs AES-256-GCM decrypt, and lets the GCM
122
+ * auth tag fail loudly on tamper (Node throws "Unsupported state or
123
+ * unable to authenticate data" — we let that propagate).
124
+ *
125
+ * Pre-condition: caller has already determined this is an encrypted
126
+ * blob via isEncryptedBlob(). decryptBuffer throws on bad magic so a
127
+ * mistaken plaintext blob still fails loudly rather than producing
128
+ * garbage.
129
+ */
130
+ export function decryptBuffer(blob, key) {
131
+ if (!Buffer.isBuffer(blob)) {
132
+ throw new TypeError('decryptBuffer: blob must be a Buffer');
133
+ }
134
+ if (!Buffer.isBuffer(key) || key.length !== KEY_LEN) {
135
+ throw new TypeError(`decryptBuffer: key must be a ${KEY_LEN}-byte Buffer`);
136
+ }
137
+ if (blob.length < MIN_BLOB_LEN) {
138
+ throw new Error(`decryptBuffer: blob too short (${blob.length}B; need >= ${MIN_BLOB_LEN}B)`);
139
+ }
140
+ const magic = blob.subarray(0, MAGIC_LEN);
141
+ // timingSafeEqual to avoid an oracle on the magic bytes specifically;
142
+ // not strictly required (the magic isn't secret) but cheap and correct.
143
+ if (!timingSafeEqual(magic, MAGIC)) {
144
+ throw new Error('decryptBuffer: bad magic — blob is not Ruflo-encrypted (RFE1)');
145
+ }
146
+ const iv = blob.subarray(MAGIC_LEN, MAGIC_LEN + IV_LEN);
147
+ const tag = blob.subarray(blob.length - TAG_LEN);
148
+ const ciphertext = blob.subarray(MAGIC_LEN + IV_LEN, blob.length - TAG_LEN);
149
+ const decipher = createDecipheriv(ALG, key, iv);
150
+ decipher.setAuthTag(tag);
151
+ return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
152
+ }
153
+ /**
154
+ * Magic-byte sniff. True iff the blob starts with the RFE1 magic AND is
155
+ * long enough to be a valid encrypted blob. Used by readers during the
156
+ * incremental migration: legacy plaintext files return false and flow
157
+ * through the existing read path unchanged.
158
+ *
159
+ * Note: this is a heuristic. A plaintext file that happens to start with
160
+ * "RFE1" would be misdetected — we accept that vanishingly small risk
161
+ * because (a) the four bytes 0x52,0x46,0x45,0x31 are an unusual prefix
162
+ * for JSON (`{`, `[`) or SQLite (`SQLite format 3`), and (b) decryption
163
+ * will then fail with a clear error rather than silently corrupt.
164
+ */
165
+ export function isEncryptedBlob(blob) {
166
+ if (!Buffer.isBuffer(blob))
167
+ return false;
168
+ if (blob.length < MIN_BLOB_LEN)
169
+ return false;
170
+ return timingSafeEqual(blob.subarray(0, MAGIC_LEN), MAGIC);
171
+ }
172
+ //# sourceMappingURL=vault.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault.js","sourceRoot":"","sources":["../../../src/encryption/vault.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,eAAe,GAChB,MAAM,aAAa,CAAC;AAErB,gFAAgF;AAEhF,uDAAuD;AACvD,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;AACrE,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI;AACpC,MAAM,MAAM,GAAG,EAAE,CAAC,CAAc,6BAA6B;AAC7D,MAAM,OAAO,GAAG,EAAE,CAAC,CAAa,eAAe;AAC/C,MAAM,OAAO,GAAG,EAAE,CAAC,CAAa,UAAU;AAC1C,MAAM,GAAG,GAAG,aAAsB,CAAC;AACnC,MAAM,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,kCAAkC;AAErF,MAAM,eAAe,GAAG,6BAA6B,CAAC;AACtD,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAEjD,gFAAgF;AAEhF;;;;;;;GAOG;AACH,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CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Restricted-permission file helpers.
3
+ *
4
+ * audit_1776853149979: session/memory/terminal stores were written with the
5
+ * process umask, which on most macOS/Linux setups leaves them world-readable
6
+ * (mode 0644). They contain conversation snapshots, agent prompts, and
7
+ * terminal command history — anyone else on the host can read them.
8
+ *
9
+ * These helpers write atomically and force mode 0600 (files) / 0700 (dirs).
10
+ * chmod fails silently on Windows, where POSIX modes don't apply — that's
11
+ * fine, the OS-level ACL surface there is different.
12
+ *
13
+ * ADR-096 Phase 2: optional opt-in encryption-at-rest. When the caller
14
+ * passes `encrypt: true` AND the env-gated vault is enabled, payloads are
15
+ * AES-256-GCM-encrypted before hitting disk. Reads use the magic-byte
16
+ * sniff so legacy plaintext files keep working unchanged during the
17
+ * incremental migration.
18
+ */
19
+ /**
20
+ * Create a directory tree with mode 0700 (owner-only). No-op if exists.
21
+ * Uses recursive: true so missing parents are created with the same mode.
22
+ */
23
+ export declare function mkdirRestricted(path: string): void;
24
+ /**
25
+ * Options for writeFileRestricted. Object form so we can grow the API
26
+ * without churning every call site.
27
+ */
28
+ export interface WriteOptions {
29
+ /** Buffer encoding when `data` is a string. Ignored for Buffer payloads. */
30
+ encoding?: BufferEncoding;
31
+ /**
32
+ * If true AND encryption is globally enabled (CLAUDE_FLOW_ENCRYPT_AT_REST),
33
+ * encrypt the payload with AES-256-GCM before writing. If encryption is
34
+ * NOT enabled, this flag is silently ignored — the legacy plaintext path
35
+ * runs unchanged. Default: false.
36
+ */
37
+ encrypt?: boolean;
38
+ }
39
+ /**
40
+ * Write a file and tighten its permissions to mode 0600 (owner read/write).
41
+ *
42
+ * Two call signatures, both supported (the legacy positional one keeps
43
+ * existing call sites working without churn):
44
+ *
45
+ * writeFileRestricted(path, data) // plaintext, utf-8
46
+ * writeFileRestricted(path, data, 'utf-8') // legacy: encoding only
47
+ * writeFileRestricted(path, data, { encrypt: true }) // opt-in encryption
48
+ */
49
+ export declare function writeFileRestricted(path: string, data: string | Buffer, optsOrEncoding?: BufferEncoding | WriteOptions): void;
50
+ /**
51
+ * Read a file and transparently decrypt if it carries the RFE1 magic.
52
+ *
53
+ * Returns a string when the caller asks for one (default utf-8). Returns
54
+ * a Buffer when `encoding` is null. This matches Node's readFileSync
55
+ * shape so the function is a near-drop-in replacement.
56
+ *
57
+ * Migration semantics:
58
+ * - If the file IS encrypted, decrypt and return.
59
+ * - If the file is NOT encrypted, return its raw bytes (string-decoded
60
+ * under `encoding` if requested).
61
+ *
62
+ * That means a reader can be migrated *first*, before its writer flips
63
+ * `encrypt: true`, without breaking on the legacy plaintext path.
64
+ */
65
+ export declare function readFileMaybeEncrypted(path: string, encoding?: BufferEncoding): string;
66
+ export declare function readFileMaybeEncrypted(path: string, encoding: null): Buffer;
67
+ //# sourceMappingURL=fs-secure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs-secure.d.ts","sourceRoot":"","sources":["../../src/fs-secure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAWH;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAElD;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,cAAc,GAAE,cAAc,GAAG,YAAsB,GACtD,IAAI,CA0BN;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,cAAc,GACxB,MAAM,CAAC;AACV,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,IAAI,GACb,MAAM,CAAC"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Restricted-permission file helpers.
3
+ *
4
+ * audit_1776853149979: session/memory/terminal stores were written with the
5
+ * process umask, which on most macOS/Linux setups leaves them world-readable
6
+ * (mode 0644). They contain conversation snapshots, agent prompts, and
7
+ * terminal command history — anyone else on the host can read them.
8
+ *
9
+ * These helpers write atomically and force mode 0600 (files) / 0700 (dirs).
10
+ * chmod fails silently on Windows, where POSIX modes don't apply — that's
11
+ * fine, the OS-level ACL surface there is different.
12
+ *
13
+ * ADR-096 Phase 2: optional opt-in encryption-at-rest. When the caller
14
+ * passes `encrypt: true` AND the env-gated vault is enabled, payloads are
15
+ * AES-256-GCM-encrypted before hitting disk. Reads use the magic-byte
16
+ * sniff so legacy plaintext files keep working unchanged during the
17
+ * incremental migration.
18
+ */
19
+ import { chmodSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
20
+ import { decryptBuffer, encryptBuffer, getKey, isEncryptedBlob, isEncryptionEnabled, } from './encryption/vault.js';
21
+ /**
22
+ * Create a directory tree with mode 0700 (owner-only). No-op if exists.
23
+ * Uses recursive: true so missing parents are created with the same mode.
24
+ */
25
+ export function mkdirRestricted(path) {
26
+ mkdirSync(path, { recursive: true, mode: 0o700 });
27
+ }
28
+ /**
29
+ * Write a file and tighten its permissions to mode 0600 (owner read/write).
30
+ *
31
+ * Two call signatures, both supported (the legacy positional one keeps
32
+ * existing call sites working without churn):
33
+ *
34
+ * writeFileRestricted(path, data) // plaintext, utf-8
35
+ * writeFileRestricted(path, data, 'utf-8') // legacy: encoding only
36
+ * writeFileRestricted(path, data, { encrypt: true }) // opt-in encryption
37
+ */
38
+ export function writeFileRestricted(path, data, optsOrEncoding = 'utf-8') {
39
+ const opts = typeof optsOrEncoding === 'string'
40
+ ? { encoding: optsOrEncoding }
41
+ : optsOrEncoding;
42
+ const encoding = opts.encoding ?? 'utf-8';
43
+ let payload = data;
44
+ if (opts.encrypt && isEncryptionEnabled()) {
45
+ const plaintext = Buffer.isBuffer(data) ? data : Buffer.from(data, encoding);
46
+ payload = encryptBuffer(plaintext, getKey());
47
+ }
48
+ // For encrypted payloads we always have a Buffer — pass through without an
49
+ // encoding so writeFileSync doesn't try to text-decode it.
50
+ if (Buffer.isBuffer(payload)) {
51
+ writeFileSync(path, payload);
52
+ }
53
+ else {
54
+ writeFileSync(path, payload, encoding);
55
+ }
56
+ try {
57
+ chmodSync(path, 0o600);
58
+ }
59
+ catch {
60
+ // Windows / FS without POSIX modes — silently skip.
61
+ }
62
+ }
63
+ export function readFileMaybeEncrypted(path, encoding = 'utf-8') {
64
+ const raw = readFileSync(path);
65
+ let plain;
66
+ if (isEncryptedBlob(raw)) {
67
+ plain = decryptBuffer(raw, getKey());
68
+ }
69
+ else {
70
+ plain = raw;
71
+ }
72
+ return encoding === null ? plain : plain.toString(encoding);
73
+ }
74
+ //# sourceMappingURL=fs-secure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs-secure.js","sourceRoot":"","sources":["../../src/fs-secure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EACL,aAAa,EACb,aAAa,EACb,MAAM,EACN,eAAe,EACf,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAE/B;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACpD,CAAC;AAkBD;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,IAAqB,EACrB,iBAAgD,OAAO;IAEvD,MAAM,IAAI,GACR,OAAO,cAAc,KAAK,QAAQ;QAChC,CAAC,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE;QAC9B,CAAC,CAAC,cAAc,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-1 +1 @@
1
- {"version":3,"file":"github-tools.d.ts","sourceRoot":"","sources":["../../../src/mcp-tools/github-tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,YAAY,CAAC;AA8EzD,eAAO,MAAM,WAAW,EAAE,OAAO,EAmbhC,CAAC"}
1
+ {"version":3,"file":"github-tools.d.ts","sourceRoot":"","sources":["../../../src/mcp-tools/github-tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,YAAY,CAAC;AAqIzD,eAAO,MAAM,WAAW,EAAE,OAAO,EAqdhC,CAAC"}