@getengram/cli 0.6.0 → 0.7.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 (208) hide show
  1. package/LICENSE +112 -0
  2. package/README.md +1 -1
  3. package/dist/commands/auth.d.ts.map +1 -1
  4. package/dist/commands/auth.js +38 -11
  5. package/dist/commands/auth.js.map +1 -1
  6. package/dist/commands/conversations.d.ts.map +1 -1
  7. package/dist/commands/conversations.js +8 -2
  8. package/dist/commands/conversations.js.map +1 -1
  9. package/dist/commands/exclude.d.ts.map +1 -1
  10. package/dist/commands/exclude.js +73 -21
  11. package/dist/commands/exclude.js.map +1 -1
  12. package/dist/commands/import.d.ts +30 -3
  13. package/dist/commands/import.d.ts.map +1 -1
  14. package/dist/commands/import.js +374 -45
  15. package/dist/commands/import.js.map +1 -1
  16. package/dist/commands/login.d.ts.map +1 -1
  17. package/dist/commands/login.js +144 -29
  18. package/dist/commands/login.js.map +1 -1
  19. package/dist/commands/search.js +2 -2
  20. package/dist/commands/search.js.map +1 -1
  21. package/dist/commands/status.d.ts +16 -0
  22. package/dist/commands/status.d.ts.map +1 -0
  23. package/dist/commands/status.js +51 -0
  24. package/dist/commands/status.js.map +1 -0
  25. package/dist/commands/store.d.ts.map +1 -1
  26. package/dist/commands/store.js +19 -3
  27. package/dist/commands/store.js.map +1 -1
  28. package/dist/commands/upgrade.d.ts +24 -0
  29. package/dist/commands/upgrade.d.ts.map +1 -1
  30. package/dist/commands/upgrade.js +64 -15
  31. package/dist/commands/upgrade.js.map +1 -1
  32. package/dist/commands/usage.d.ts +44 -0
  33. package/dist/commands/usage.d.ts.map +1 -1
  34. package/dist/commands/usage.js +79 -19
  35. package/dist/commands/usage.js.map +1 -1
  36. package/dist/commands/vault.d.ts +11 -2
  37. package/dist/commands/vault.d.ts.map +1 -1
  38. package/dist/commands/vault.js +372 -53
  39. package/dist/commands/vault.js.map +1 -1
  40. package/dist/config-file.d.ts +74 -0
  41. package/dist/config-file.d.ts.map +1 -0
  42. package/dist/config-file.js +152 -0
  43. package/dist/config-file.js.map +1 -0
  44. package/dist/config-guard.d.ts +96 -0
  45. package/dist/config-guard.d.ts.map +1 -0
  46. package/dist/config-guard.js +184 -0
  47. package/dist/config-guard.js.map +1 -0
  48. package/dist/config.d.ts +48 -4
  49. package/dist/config.d.ts.map +1 -1
  50. package/dist/config.js +101 -12
  51. package/dist/config.js.map +1 -1
  52. package/dist/daemon/as-root.d.ts +46 -0
  53. package/dist/daemon/as-root.d.ts.map +1 -0
  54. package/dist/daemon/as-root.js +64 -0
  55. package/dist/daemon/as-root.js.map +1 -0
  56. package/dist/daemon/backoff.d.ts +26 -0
  57. package/dist/daemon/backoff.d.ts.map +1 -0
  58. package/dist/daemon/backoff.js +37 -0
  59. package/dist/daemon/backoff.js.map +1 -0
  60. package/dist/daemon/codex-parser.d.ts +38 -4
  61. package/dist/daemon/codex-parser.d.ts.map +1 -1
  62. package/dist/daemon/codex-parser.js +111 -23
  63. package/dist/daemon/codex-parser.js.map +1 -1
  64. package/dist/daemon/command-path.d.ts +13 -0
  65. package/dist/daemon/command-path.d.ts.map +1 -0
  66. package/dist/daemon/command-path.js +35 -0
  67. package/dist/daemon/command-path.js.map +1 -0
  68. package/dist/daemon/commands.d.ts +153 -3
  69. package/dist/daemon/commands.d.ts.map +1 -1
  70. package/dist/daemon/commands.js +2775 -235
  71. package/dist/daemon/commands.js.map +1 -1
  72. package/dist/daemon/db.d.ts +255 -27
  73. package/dist/daemon/db.d.ts.map +1 -1
  74. package/dist/daemon/db.js +749 -53
  75. package/dist/daemon/db.js.map +1 -1
  76. package/dist/daemon/exclusions.d.ts +23 -3
  77. package/dist/daemon/exclusions.d.ts.map +1 -1
  78. package/dist/daemon/exclusions.js +91 -21
  79. package/dist/daemon/exclusions.js.map +1 -1
  80. package/dist/daemon/homebrew.d.ts +26 -0
  81. package/dist/daemon/homebrew.d.ts.map +1 -0
  82. package/dist/daemon/homebrew.js +43 -0
  83. package/dist/daemon/homebrew.js.map +1 -0
  84. package/dist/daemon/instance.d.ts +427 -0
  85. package/dist/daemon/instance.d.ts.map +1 -0
  86. package/dist/daemon/instance.js +1201 -0
  87. package/dist/daemon/instance.js.map +1 -0
  88. package/dist/daemon/key-source.d.ts +41 -0
  89. package/dist/daemon/key-source.d.ts.map +1 -0
  90. package/dist/daemon/key-source.js +89 -0
  91. package/dist/daemon/key-source.js.map +1 -0
  92. package/dist/daemon/launch.d.ts +56 -0
  93. package/dist/daemon/launch.d.ts.map +1 -0
  94. package/dist/daemon/launch.js +153 -0
  95. package/dist/daemon/launch.js.map +1 -0
  96. package/dist/daemon/launchd.d.ts +215 -0
  97. package/dist/daemon/launchd.d.ts.map +1 -0
  98. package/dist/daemon/launchd.js +527 -0
  99. package/dist/daemon/launchd.js.map +1 -0
  100. package/dist/daemon/login-start.d.ts +2 -0
  101. package/dist/daemon/login-start.d.ts.map +1 -0
  102. package/dist/daemon/login-start.js +25 -0
  103. package/dist/daemon/login-start.js.map +1 -0
  104. package/dist/daemon/ownership.d.ts +123 -0
  105. package/dist/daemon/ownership.d.ts.map +1 -0
  106. package/dist/daemon/ownership.js +245 -0
  107. package/dist/daemon/ownership.js.map +1 -0
  108. package/dist/daemon/package-runner.d.ts +28 -0
  109. package/dist/daemon/package-runner.d.ts.map +1 -0
  110. package/dist/daemon/package-runner.js +113 -0
  111. package/dist/daemon/package-runner.js.map +1 -0
  112. package/dist/daemon/parser.d.ts +50 -5
  113. package/dist/daemon/parser.d.ts.map +1 -1
  114. package/dist/daemon/parser.js +224 -47
  115. package/dist/daemon/parser.js.map +1 -1
  116. package/dist/daemon/powershell.d.ts +25 -0
  117. package/dist/daemon/powershell.d.ts.map +1 -0
  118. package/dist/daemon/powershell.js +30 -0
  119. package/dist/daemon/powershell.js.map +1 -0
  120. package/dist/daemon/preflight.d.ts +0 -17
  121. package/dist/daemon/preflight.d.ts.map +1 -1
  122. package/dist/daemon/preflight.js +32 -6
  123. package/dist/daemon/preflight.js.map +1 -1
  124. package/dist/daemon/prune.d.ts +101 -0
  125. package/dist/daemon/prune.d.ts.map +1 -0
  126. package/dist/daemon/prune.js +287 -0
  127. package/dist/daemon/prune.js.map +1 -0
  128. package/dist/daemon/queue-error.d.ts +47 -0
  129. package/dist/daemon/queue-error.d.ts.map +1 -0
  130. package/dist/daemon/queue-error.js +59 -0
  131. package/dist/daemon/queue-error.js.map +1 -0
  132. package/dist/daemon/root-daemon.d.ts +60 -0
  133. package/dist/daemon/root-daemon.d.ts.map +1 -0
  134. package/dist/daemon/root-daemon.js +86 -0
  135. package/dist/daemon/root-daemon.js.map +1 -0
  136. package/dist/daemon/scoop.d.ts +52 -0
  137. package/dist/daemon/scoop.d.ts.map +1 -0
  138. package/dist/daemon/scoop.js +84 -0
  139. package/dist/daemon/scoop.js.map +1 -0
  140. package/dist/daemon/scrubber.d.ts +456 -0
  141. package/dist/daemon/scrubber.d.ts.map +1 -0
  142. package/dist/daemon/scrubber.js +994 -0
  143. package/dist/daemon/scrubber.js.map +1 -0
  144. package/dist/daemon/status.d.ts +306 -11
  145. package/dist/daemon/status.d.ts.map +1 -1
  146. package/dist/daemon/status.js +568 -43
  147. package/dist/daemon/status.js.map +1 -1
  148. package/dist/daemon/supervise.d.ts +78 -0
  149. package/dist/daemon/supervise.d.ts.map +1 -0
  150. package/dist/daemon/supervise.js +121 -0
  151. package/dist/daemon/supervise.js.map +1 -0
  152. package/dist/daemon/supervisor.d.ts +18 -0
  153. package/dist/daemon/supervisor.d.ts.map +1 -0
  154. package/dist/daemon/supervisor.js +56 -0
  155. package/dist/daemon/supervisor.js.map +1 -0
  156. package/dist/daemon/syncer.d.ts +382 -21
  157. package/dist/daemon/syncer.d.ts.map +1 -1
  158. package/dist/daemon/syncer.js +1448 -178
  159. package/dist/daemon/syncer.js.map +1 -1
  160. package/dist/daemon/systemd.d.ts +109 -0
  161. package/dist/daemon/systemd.d.ts.map +1 -0
  162. package/dist/daemon/systemd.js +363 -0
  163. package/dist/daemon/systemd.js.map +1 -0
  164. package/dist/daemon/types.d.ts +58 -6
  165. package/dist/daemon/types.d.ts.map +1 -1
  166. package/dist/daemon/vault-changed.d.ts +29 -0
  167. package/dist/daemon/vault-changed.d.ts.map +1 -0
  168. package/dist/daemon/vault-changed.js +47 -0
  169. package/dist/daemon/vault-changed.js.map +1 -0
  170. package/dist/daemon/vault-key-missing.d.ts +70 -0
  171. package/dist/daemon/vault-key-missing.d.ts.map +1 -0
  172. package/dist/daemon/vault-key-missing.js +125 -0
  173. package/dist/daemon/vault-key-missing.js.map +1 -0
  174. package/dist/daemon/watcher.d.ts +87 -4
  175. package/dist/daemon/watcher.d.ts.map +1 -1
  176. package/dist/daemon/watcher.js +286 -36
  177. package/dist/daemon/watcher.js.map +1 -1
  178. package/dist/daemon/worker-main.js +363 -51
  179. package/dist/daemon/worker-main.js.map +1 -1
  180. package/dist/daemon/worker.js +19 -1
  181. package/dist/daemon/worker.js.map +1 -1
  182. package/dist/import-resume.d.ts +163 -0
  183. package/dist/import-resume.d.ts.map +1 -0
  184. package/dist/import-resume.js +267 -0
  185. package/dist/import-resume.js.map +1 -0
  186. package/dist/index.js +242 -33
  187. package/dist/index.js.map +1 -1
  188. package/dist/message-bounds.d.ts +52 -0
  189. package/dist/message-bounds.d.ts.map +1 -0
  190. package/dist/message-bounds.js +157 -0
  191. package/dist/message-bounds.js.map +1 -0
  192. package/dist/output.d.ts +14 -0
  193. package/dist/output.d.ts.map +1 -1
  194. package/dist/output.js +33 -5
  195. package/dist/output.js.map +1 -1
  196. package/dist/private-files.d.ts +126 -0
  197. package/dist/private-files.d.ts.map +1 -0
  198. package/dist/private-files.js +372 -0
  199. package/dist/private-files.js.map +1 -0
  200. package/dist/server-url.d.ts +31 -0
  201. package/dist/server-url.d.ts.map +1 -0
  202. package/dist/server-url.js +47 -0
  203. package/dist/server-url.js.map +1 -0
  204. package/dist/vault-key.d.ts +122 -0
  205. package/dist/vault-key.d.ts.map +1 -0
  206. package/dist/vault-key.js +273 -0
  207. package/dist/vault-key.js.map +1 -0
  208. package/package.json +11 -12
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Message bodies bounded the way Engram bounds them before it stores them
3
+ * (engram#750): base64 file payloads become a short note, then the text is
4
+ * clipped to MAX_MESSAGE_CONTENT_CHARS with a visible marker.
5
+ *
6
+ * Engram does this to every message it receives (engram#386), so doing it
7
+ * here first stores the same text, with one exception that only ever
8
+ * stores less: an encoded run glued to the next word by "_" or "-" is left
9
+ * alone, but when the clip cuts it the run ends at the cut, and Engram's
10
+ * own pass then replaces it with a note. What doing it here changes is
11
+ * what travels and waits. A screenshot in a tool result was queued in
12
+ * daemon.db and uploaded as megabytes of base64, only to be replaced by a
13
+ * note on arrival, and one message past the server's 8 MB request limit
14
+ * was refused on every try.
15
+ *
16
+ * This is a copy of the worker's code, not an import: the worker's lives in
17
+ * @getengram/shared and apps/mcp-server, which are never published, and the
18
+ * CLI depends only on @getengram/sdk. A test runs both copies over the same
19
+ * inputs and fails the moment they differ, so change them together:
20
+ * apps/mcp-server/src/services/binary-payloads.ts stripBinaryPayloads
21
+ * apps/mcp-server/src/services/tier.ts boundContent
22
+ * packages/shared/src/constants.ts MAX_MESSAGE_CONTENT_CHARS
23
+ */
24
+ /** Engram's per-message clip, in characters. */
25
+ export const MAX_MESSAGE_CONTENT_CHARS = 100_000;
26
+ /**
27
+ * What Engram appends to a clipped body. Spelled out rather than built with
28
+ * toLocaleString(), which follows the user's locale ("100.000" in German);
29
+ * the worker's always reads "100,000".
30
+ */
31
+ export const TRUNCATION_MARKER = "\n\n…[truncated: message exceeded 100,000 characters]";
32
+ /**
33
+ * Bound one message body exactly as Engram's append does: file payloads
34
+ * replaced with a note, then the text clipped with a visible marker. A body
35
+ * with nothing to bound comes back unchanged (the same string).
36
+ */
37
+ export function boundContent(content) {
38
+ const text = stripBinaryPayloads(content);
39
+ if (text.length <= MAX_MESSAGE_CONTENT_CHARS)
40
+ return text;
41
+ return text.slice(0, MAX_MESSAGE_CONTENT_CHARS) + TRUNCATION_MARKER;
42
+ }
43
+ // ---------------------------------------------------------------------------
44
+ // From here on, a copy of apps/mcp-server/src/services/binary-payloads.ts.
45
+ // ---------------------------------------------------------------------------
46
+ /** The redactor's floor for a base64 token; shorter runs are never touched. */
47
+ const MIN_RUN_CHARS = 40;
48
+ /**
49
+ * A run with no file signature is replaced only past this length (about
50
+ * 1.5 KB decoded). Below it a run may be a key or token, and Engram's
51
+ * redactor decides; nothing this long is a credential anyone types or pastes.
52
+ */
53
+ export const GENERIC_MIN_CHARS = 2048;
54
+ /** 16 base64 characters decode to 12 bytes — enough for every signature. */
55
+ const SNIFF_CHARS = 16;
56
+ // A base64 run that stands alone: it starts after a character outside the
57
+ // alphabet (or after a JSON escape such as \n, so an encoded line break is
58
+ // a boundary, not part of the run) and is not glued to a neighbour by "_"
59
+ // or "-". Same alphabet and padding as the redactor's BASE64_TOKEN.
60
+ const BASE64_RUN = /(?:(?<![A-Za-z0-9+/_\\-])|(?<=\\[nrt]))[A-Za-z0-9+/]{40,}={0,2}(?![A-Za-z0-9+/_-])/g;
61
+ // data:[<type>/<subtype>][;<param>]…;base64,<payload>
62
+ const DATA_URL = /data:(?:([a-z0-9.+-]{1,64})\/([a-z0-9.+-]{1,64}))?(?:;[a-z0-9.+=_-]{1,100}){0,4};base64,([A-Za-z0-9+/]{40,}={0,2})(?![A-Za-z0-9+/_-])/gi;
63
+ const GENERIC = { kind: "base64 data" };
64
+ const IMAGE_FORMATS = new Map([
65
+ ["png", "PNG"],
66
+ ["jpeg", "JPEG"],
67
+ ["jpg", "JPEG"],
68
+ ["pjpeg", "JPEG"],
69
+ ["gif", "GIF"],
70
+ ["webp", "WebP"],
71
+ ["svg+xml", "SVG"],
72
+ ["bmp", "BMP"],
73
+ ["avif", "AVIF"],
74
+ ["heic", "HEIC"],
75
+ ["heif", "HEIF"],
76
+ ["tiff", "TIFF"],
77
+ ["x-icon", "ICO"],
78
+ ["vnd.microsoft.icon", "ICO"],
79
+ ]);
80
+ /** The file type from the first decoded bytes, or null when unrecognised. */
81
+ function sniff(run) {
82
+ let head;
83
+ try {
84
+ head = atob(run.slice(0, SNIFF_CHARS));
85
+ }
86
+ catch {
87
+ return null;
88
+ }
89
+ if (head.startsWith("\xFF\xD8\xFF"))
90
+ return { kind: "image", format: "JPEG" };
91
+ if (head.startsWith("\x89PNG\r\n\x1A\n"))
92
+ return { kind: "image", format: "PNG" };
93
+ if (head.startsWith("GIF87a") || head.startsWith("GIF89a")) {
94
+ return { kind: "image", format: "GIF" };
95
+ }
96
+ if (head.startsWith("RIFF") && head.slice(8, 12) === "WEBP") {
97
+ return { kind: "image", format: "WebP" };
98
+ }
99
+ if (head.startsWith("%PDF-"))
100
+ return { kind: "PDF" };
101
+ return null;
102
+ }
103
+ /** What a data: URL's declared media type says it is. */
104
+ function fromMediaType(type, subtype) {
105
+ if (!type || !subtype)
106
+ return null;
107
+ const t = type.toLowerCase();
108
+ const s = subtype.toLowerCase();
109
+ if (t === "image")
110
+ return { kind: "image", format: IMAGE_FORMATS.get(s) };
111
+ if (t === "application" && s === "pdf")
112
+ return { kind: "PDF" };
113
+ if (t === "audio" || t === "video" || t === "font")
114
+ return { kind: t };
115
+ return null;
116
+ }
117
+ /**
118
+ * Real encoded files mix upper case, lower case and digits; a long run of
119
+ * one repeated character or a single-case word is something else.
120
+ */
121
+ function looksEncoded(run) {
122
+ return /[a-z]/.test(run) && /[A-Z]/.test(run) && /[0-9]/.test(run);
123
+ }
124
+ function decodedBytes(payload) {
125
+ const pad = payload.endsWith("==") ? 2 : payload.endsWith("=") ? 1 : 0;
126
+ return Math.floor(((payload.length - pad) * 3) / 4);
127
+ }
128
+ /** Same scale as the "[image attached: …]" note (daemon/parser.ts). */
129
+ function formatSize(bytes) {
130
+ if (bytes >= 1_048_576)
131
+ return `${(bytes / 1_048_576).toFixed(1)} MB`;
132
+ if (bytes >= 1024)
133
+ return `${Math.round(bytes / 1024)} KB`;
134
+ return `${bytes} B`;
135
+ }
136
+ function note(payload, encoded) {
137
+ const format = payload.format ? `${payload.format}, ` : "";
138
+ return `[${payload.kind} not stored: ${format}${formatSize(decodedBytes(encoded))}]`;
139
+ }
140
+ /**
141
+ * Replace every base64 file payload in `text` with a short note saying
142
+ * what it was and how big: "[image not stored: PNG, 312 KB]". The note has
143
+ * no quotes or backslashes, so a JSON tool result stays valid JSON. Runs
144
+ * that could be a credential are left exactly as they were, for Engram's
145
+ * redactor. Text with no payload comes back unchanged (the same string).
146
+ */
147
+ export function stripBinaryPayloads(text) {
148
+ if (text.length < MIN_RUN_CHARS)
149
+ return text;
150
+ return text
151
+ .replace(DATA_URL, (_url, type, subtype, payload) => note(sniff(payload) ?? fromMediaType(type, subtype) ?? GENERIC, payload))
152
+ .replace(BASE64_RUN, (run) => {
153
+ const found = sniff(run) ?? (run.length >= GENERIC_MIN_CHARS && looksEncoded(run) ? GENERIC : null);
154
+ return found ? note(found, run) : run;
155
+ });
156
+ }
157
+ //# sourceMappingURL=message-bounds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-bounds.js","sourceRoot":"","sources":["../src/message-bounds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,gDAAgD;AAChD,MAAM,CAAC,MAAM,yBAAyB,GAAG,OAAO,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,uDAAuD,CAAC;AAEzF;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,MAAM,IAAI,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAC1C,IAAI,IAAI,CAAC,MAAM,IAAI,yBAAyB;QAAE,OAAO,IAAI,CAAC;IAC1D,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,yBAAyB,CAAC,GAAG,iBAAiB,CAAC;AACtE,CAAC;AAED,8EAA8E;AAC9E,2EAA2E;AAC3E,8EAA8E;AAE9E,+EAA+E;AAC/E,MAAM,aAAa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OAAO,CAAC,CAAC,GAAG,CAAC;AACvF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,IAAI,IAAI,CAAC,MAAM,GAAG,aAAa;QAAE,OAAO,IAAI,CAAC;IAC7C,OAAO,IAAI;SACR,OAAO,CACN,QAAQ,EACR,CAAC,IAAI,EAAE,IAAwB,EAAE,OAA2B,EAAE,OAAe,EAAE,EAAE,CAC/E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,OAAO,EAAE,OAAO,CAAC,CAC3E;SACA,OAAO,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE;QAC3B,MAAM,KAAK,GACT,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,iBAAiB,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACxF,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACxC,CAAC,CAAC,CAAC;AACP,CAAC"}
package/dist/output.d.ts CHANGED
@@ -1,9 +1,23 @@
1
1
  /** Formatting helpers for CLI output */
2
2
  export declare function json(data: unknown): void;
3
3
  export declare function table(rows: Record<string, unknown>[], columns: string[]): void;
4
+ /**
5
+ * Whether what the CLI prints gets colors (engram#628): only when stdout
6
+ * and stderr are both terminals, since a colored string can go to either.
7
+ * Pipes, files and CI logs used to get the raw escape codes. NO_COLOR set
8
+ * to anything but "" turns colors off (https://no-color.org), and so does
9
+ * a terminal that can't show them (TERM=dumb).
10
+ */
11
+ export declare function colorEnabled(): boolean;
4
12
  export declare function dim(text: string): string;
5
13
  export declare function bold(text: string): string;
6
14
  export declare function green(text: string): string;
7
15
  export declare function red(text: string): string;
8
16
  export declare function cyan(text: string): string;
17
+ /**
18
+ * A count and its noun, singular for exactly one (engram#628): "1 message",
19
+ * "0 messages", "1,234 messages". `many` is for a noun that doesn't just
20
+ * add an "s" ("copy", "copies").
21
+ */
22
+ export declare function plural(count: number, one: string, many?: string): string;
9
23
  //# sourceMappingURL=output.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,wCAAwC;AAExC,wBAAgB,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAExC;AAED,wBAAgB,KAAK,CACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC/B,OAAO,EAAE,MAAM,EAAE,GAChB,IAAI,CA4BN;AAED,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExC;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExC;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzC"}
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,wCAAwC;AAExC,wBAAgB,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAExC;AAED,wBAAgB,KAAK,CACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC/B,OAAO,EAAE,MAAM,EAAE,GAChB,IAAI,CA4BN;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAItC;AAMD,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExC;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExC;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,SAAY,GAAG,MAAM,CAK3E"}
package/dist/output.js CHANGED
@@ -23,19 +23,47 @@ export function table(rows, columns) {
23
23
  console.log(line);
24
24
  }
25
25
  }
26
+ /**
27
+ * Whether what the CLI prints gets colors (engram#628): only when stdout
28
+ * and stderr are both terminals, since a colored string can go to either.
29
+ * Pipes, files and CI logs used to get the raw escape codes. NO_COLOR set
30
+ * to anything but "" turns colors off (https://no-color.org), and so does
31
+ * a terminal that can't show them (TERM=dumb).
32
+ */
33
+ export function colorEnabled() {
34
+ if (process.env.NO_COLOR)
35
+ return false;
36
+ if (process.env.TERM === "dumb")
37
+ return false;
38
+ return Boolean(process.stdout.isTTY && process.stderr.isTTY);
39
+ }
40
+ function paint(code, text) {
41
+ return colorEnabled() ? `\x1b[${code}m${text}\x1b[0m` : text;
42
+ }
26
43
  export function dim(text) {
27
- return `\x1b[2m${text}\x1b[0m`;
44
+ return paint("2", text);
28
45
  }
29
46
  export function bold(text) {
30
- return `\x1b[1m${text}\x1b[0m`;
47
+ return paint("1", text);
31
48
  }
32
49
  export function green(text) {
33
- return `\x1b[32m${text}\x1b[0m`;
50
+ return paint("32", text);
34
51
  }
35
52
  export function red(text) {
36
- return `\x1b[31m${text}\x1b[0m`;
53
+ return paint("31", text);
37
54
  }
38
55
  export function cyan(text) {
39
- return `\x1b[36m${text}\x1b[0m`;
56
+ return paint("36", text);
57
+ }
58
+ /**
59
+ * A count and its noun, singular for exactly one (engram#628): "1 message",
60
+ * "0 messages", "1,234 messages". `many` is for a noun that doesn't just
61
+ * add an "s" ("copy", "copies").
62
+ */
63
+ export function plural(count, one, many = `${one}s`) {
64
+ // A count that isn't a number after all is printed as it is, as the
65
+ // template strings this replaced did, instead of throwing.
66
+ const shown = Number.isFinite(count) ? count.toLocaleString("en-US") : String(count);
67
+ return `${shown} ${count === 1 ? one : many}`;
40
68
  }
41
69
  //# sourceMappingURL=output.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,wCAAwC;AAExC,MAAM,UAAU,IAAI,CAAC,IAAa;IAChC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,KAAK,CACnB,IAA+B,EAC/B,OAAiB;IAEjB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACxB,OAAO;IACT,CAAC;IAED,0BAA0B;IAC1B,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACjC,IAAI,CAAC,GAAG,CACN,GAAG,CAAC,MAAM,EACV,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAChD,CACF,CAAC;IAEF,SAAS;IACT,MAAM,MAAM,GAAG,OAAO;SACnB,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SACpD,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG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,CAAC,KAAK,CAAC,CAAC;IACrF,OAAO,GAAG,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAChD,CAAC"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * ~/.engram holds the API key, the vault key, and the daemon's queue of
3
+ * captured transcript text. On macOS and Linux it is the user's alone
4
+ * (engram#627): the directory is 0700 and the files in it 0600, as Claude
5
+ * Code keeps the transcripts themselves. It used to get the defaults, 0755
6
+ * and 0644 under the usual umask, so other accounts on the machine could
7
+ * read the daemon's copy of transcripts they couldn't read at the source.
8
+ *
9
+ * Windows is left alone: files under the user profile inherit its ACL,
10
+ * which is private already. Writes there are still atomic.
11
+ *
12
+ * IMPORTANT: Node built-ins only. launch.ts uses this module, and the
13
+ * Windows sign-in entry runs launch.ts before the daemon's native-module
14
+ * preflight (see launch.ts).
15
+ */
16
+ export declare const PRIVATE_DIR_MODE = 448;
17
+ export declare const PRIVATE_FILE_MODE = 384;
18
+ /**
19
+ * Make sure `dir` exists and is private: created 0700, or, when it is
20
+ * already there and the user's own, its group and other bits cleared, so an
21
+ * install from before engram#627 is covered too. Returns what was done.
22
+ *
23
+ * Only for a directory that is Engram's alone (~/.engram), never one that
24
+ * other things share.
25
+ */
26
+ export declare function ensurePrivateDirSync(dir: string): "created" | "changed" | "private" | "not-ours";
27
+ /**
28
+ * Clear the group and other bits of the file at `path` when it is the
29
+ * user's own. Best effort, and never throws: a mode that can't be changed
30
+ * (a filesystem without them) mustn't stop capture.
31
+ *
32
+ * Path-based on purpose. Opening and closing a SQLite database file here
33
+ * would drop the locks this process holds on it through SQLite.
34
+ */
35
+ export declare function restrictSync(path: string): "changed" | "private" | "missing" | "not-ours" | "failed";
36
+ /**
37
+ * Create an empty file at `path`, 0600, unless something is there already.
38
+ * For daemon.db: SQLite gives its -wal and -shm files the database file's
39
+ * mode, and treats an empty file as an empty database.
40
+ */
41
+ export declare function createPrivateFileSync(path: string): void;
42
+ export interface PrivateWriteOptions {
43
+ /**
44
+ * Flush the new content to disk before it replaces the old (default).
45
+ * status.json, rewritten every few seconds and of no use after a power
46
+ * cut, skips it.
47
+ */
48
+ durable?: boolean;
49
+ }
50
+ /**
51
+ * Replace `file` with `data` in one step (engram#627): `data` goes to a
52
+ * 0600 temp file beside it, which is then renamed over the old one. A
53
+ * reader sees the old content or the new, never part of either, and a
54
+ * crash or a full disk in the middle leaves the old file whole.
55
+ * config.json used to be rewritten in place, so a write cut short left it
56
+ * truncated and lost the API key and baseUrl.
57
+ *
58
+ * A symlink is written through, to the file it points at. A file this
59
+ * process couldn't have written in place isn't replaced either (EACCES,
60
+ * as an in-place write would have thrown): the rename needs only the
61
+ * directory's permission.
62
+ */
63
+ export declare function writePrivateFileSync(file: string, data: string, options?: PrivateWriteOptions): void;
64
+ /**
65
+ * Throw what writePrivateFileSync(file, …) would for a file, or a folder,
66
+ * this process can't write, but write nothing (engram#717). For a command
67
+ * that does what can't be undone before it saves: `engram login` makes a
68
+ * new API key, and a save that then fails loses it. A full disk is found
69
+ * only by writing.
70
+ */
71
+ export declare function checkWritableSync(file: string): void;
72
+ export interface SmallFile {
73
+ data: Buffer;
74
+ /**
75
+ * Which write of the file this is: its device, inode, modification time
76
+ * and size. writePrivateFileSync writes a new file every time, so a new
77
+ * write almost always differs from the last; a file system can give the
78
+ * new file the old one's inode, and the same time when its clock is
79
+ * coarse.
80
+ */
81
+ stamp: string;
82
+ }
83
+ /**
84
+ * A small file read without waiting: null when there is none, it can't be
85
+ * read, or it isn't a regular file of at most `maxBytes`. It is opened
86
+ * without blocking and checked before it is read: a FIFO put in its place
87
+ * would otherwise hang the reader. BigInt fstat: a plain stat fills the
88
+ * buffer Node's module loader reads (see lstatSocketPath in
89
+ * daemon/instance.ts).
90
+ */
91
+ export declare function readSmallFileSync(file: string, maxBytes: number): SmallFile | null;
92
+ /**
93
+ * How old a leftover temp file must be before it is removed. A write in
94
+ * progress, such as the CLI saving config.json as the daemon starts, has
95
+ * its temp file for a few milliseconds.
96
+ */
97
+ export declare const STALE_TEMP_MS: number;
98
+ export interface PrivateDirReport {
99
+ dir: "created" | "changed" | "private" | "not-ours";
100
+ /** Files whose group and other bits were cleared. */
101
+ changed: string[];
102
+ /** Files left as they were: another user's, or the change failed. */
103
+ skipped: string[];
104
+ /** Temp files of config.json, status.json, daemon.pid, daemon.stop and vault-changed that a write cut short left behind. */
105
+ removed: string[];
106
+ /**
107
+ * Why `dir` couldn't be listed ("EACCES"), when it couldn't: its files
108
+ * were then left as they are (engram#723).
109
+ */
110
+ unlisted?: string;
111
+ }
112
+ /**
113
+ * At the daemon's start (engram#627): `dir` made private, and every
114
+ * regular file directly in it set to 0600, so an install from before this
115
+ * fix is covered as well as a new one. Symlinks and subdirectories are left
116
+ * alone, so nothing outside `dir` changes. Temp files that an interrupted
117
+ * write of config.json, status.json, daemon.pid, daemon.stop or
118
+ * vault-changed left behind are removed once they are STALE_TEMP_MS old.
119
+ *
120
+ * Throws only when `dir` can't be created or looked at. One that can't be
121
+ * listed, as a `chmod u-r` leaves it, has its files left as they are, and
122
+ * `unlisted` says why (engram#723): the daemon needs to open its files, not
123
+ * to list them, so that is no reason for it not to start.
124
+ */
125
+ export declare function makeDirPrivateSync(dir: string, now?: number): PrivateDirReport;
126
+ //# sourceMappingURL=private-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-files.d.ts","sourceRoot":"","sources":["../src/private-files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA0BH,eAAO,MAAM,gBAAgB,MAAQ,CAAC;AACtC,eAAO,MAAM,iBAAiB,MAAQ,CAAC;AAuCvC;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,CAYhG;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,G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