@faces-sh/cli 0.0.0-stage → 1.0.1

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 (290) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +158 -2
  3. package/bin/dev.js +5 -0
  4. package/bin/run.js +5 -0
  5. package/dist/base.d.ts +26 -0
  6. package/dist/base.js +181 -0
  7. package/dist/benchmark.d.ts +21 -0
  8. package/dist/benchmark.js +95 -0
  9. package/dist/billing.d.ts +17 -0
  10. package/dist/billing.js +101 -0
  11. package/dist/catalog.d.ts +35 -0
  12. package/dist/catalog.js +242 -0
  13. package/dist/client.d.ts +98 -0
  14. package/dist/client.js +590 -0
  15. package/dist/commands/account/preferences.d.ts +20 -0
  16. package/dist/commands/account/preferences.js +190 -0
  17. package/dist/commands/account/state.d.ts +11 -0
  18. package/dist/commands/account/state.js +24 -0
  19. package/dist/commands/auth/connect.d.ts +17 -0
  20. package/dist/commands/auth/connect.js +190 -0
  21. package/dist/commands/auth/connections.d.ts +12 -0
  22. package/dist/commands/auth/connections.js +40 -0
  23. package/dist/commands/auth/disconnect.d.ts +15 -0
  24. package/dist/commands/auth/disconnect.js +49 -0
  25. package/dist/commands/auth/login.d.ts +13 -0
  26. package/dist/commands/auth/login.js +42 -0
  27. package/dist/commands/auth/logout.d.ts +11 -0
  28. package/dist/commands/auth/logout.js +14 -0
  29. package/dist/commands/auth/refresh.d.ts +11 -0
  30. package/dist/commands/auth/refresh.js +30 -0
  31. package/dist/commands/auth/register.d.ts +15 -0
  32. package/dist/commands/auth/register.js +98 -0
  33. package/dist/commands/auth/whoami.d.ts +11 -0
  34. package/dist/commands/auth/whoami.js +108 -0
  35. package/dist/commands/benchmark/get.d.ts +16 -0
  36. package/dist/commands/benchmark/get.js +42 -0
  37. package/dist/commands/benchmark/list.d.ts +13 -0
  38. package/dist/commands/benchmark/list.js +47 -0
  39. package/dist/commands/benchmark/start.d.ts +22 -0
  40. package/dist/commands/benchmark/start.js +80 -0
  41. package/dist/commands/billing/balance.d.ts +11 -0
  42. package/dist/commands/billing/balance.js +27 -0
  43. package/dist/commands/billing/card/default.d.ts +15 -0
  44. package/dist/commands/billing/card/default.js +33 -0
  45. package/dist/commands/billing/card/remove.d.ts +16 -0
  46. package/dist/commands/billing/card/remove.js +41 -0
  47. package/dist/commands/billing/card-setup.d.ts +13 -0
  48. package/dist/commands/billing/card-setup.js +41 -0
  49. package/dist/commands/billing/cards.d.ts +11 -0
  50. package/dist/commands/billing/cards.js +34 -0
  51. package/dist/commands/billing/llm-costs.d.ts +14 -0
  52. package/dist/commands/billing/llm-costs.js +95 -0
  53. package/dist/commands/billing/subscription/activate.d.ts +14 -0
  54. package/dist/commands/billing/subscription/activate.js +91 -0
  55. package/dist/commands/billing/subscription/cancel.d.ts +12 -0
  56. package/dist/commands/billing/subscription/cancel.js +54 -0
  57. package/dist/commands/billing/subscription/index.d.ts +11 -0
  58. package/dist/commands/billing/subscription/index.js +46 -0
  59. package/dist/commands/billing/subscription/plan.d.ts +16 -0
  60. package/dist/commands/billing/subscription/plan.js +86 -0
  61. package/dist/commands/billing/topup.d.ts +16 -0
  62. package/dist/commands/billing/topup.js +60 -0
  63. package/dist/commands/billing/usage.d.ts +15 -0
  64. package/dist/commands/billing/usage.js +68 -0
  65. package/dist/commands/catalog/backup.d.ts +11 -0
  66. package/dist/commands/catalog/backup.js +169 -0
  67. package/dist/commands/catalog/doctor.d.ts +14 -0
  68. package/dist/commands/catalog/doctor.js +303 -0
  69. package/dist/commands/catalog/list.d.ts +11 -0
  70. package/dist/commands/catalog/list.js +39 -0
  71. package/dist/commands/catalog/restore.d.ts +17 -0
  72. package/dist/commands/catalog/restore.js +259 -0
  73. package/dist/commands/causes.d.ts +27 -0
  74. package/dist/commands/causes.js +135 -0
  75. package/dist/commands/chat/chat.d.ts +42 -0
  76. package/dist/commands/chat/chat.js +363 -0
  77. package/dist/commands/chat/messages.d.ts +26 -0
  78. package/dist/commands/chat/messages.js +139 -0
  79. package/dist/commands/chat/responses.d.ts +27 -0
  80. package/dist/commands/chat/responses.js +150 -0
  81. package/dist/commands/chat/thread.d.ts +43 -0
  82. package/dist/commands/chat/thread.js +458 -0
  83. package/dist/commands/compile/all.d.ts +14 -0
  84. package/dist/commands/compile/all.js +186 -0
  85. package/dist/commands/compile/doc/create.d.ts +19 -0
  86. package/dist/commands/compile/doc/create.js +58 -0
  87. package/dist/commands/compile/doc/delete.d.ts +15 -0
  88. package/dist/commands/compile/doc/delete.js +33 -0
  89. package/dist/commands/compile/doc/edit.d.ts +19 -0
  90. package/dist/commands/compile/doc/edit.js +59 -0
  91. package/dist/commands/compile/doc/get.d.ts +15 -0
  92. package/dist/commands/compile/doc/get.js +43 -0
  93. package/dist/commands/compile/doc/index.d.ts +24 -0
  94. package/dist/commands/compile/doc/index.js +211 -0
  95. package/dist/commands/compile/doc/list.d.ts +15 -0
  96. package/dist/commands/compile/doc/list.js +46 -0
  97. package/dist/commands/compile/doc/make.d.ts +17 -0
  98. package/dist/commands/compile/doc/make.js +95 -0
  99. package/dist/commands/compile/doc/pause.d.ts +17 -0
  100. package/dist/commands/compile/doc/pause.js +74 -0
  101. package/dist/commands/compile/doc/reset.d.ts +15 -0
  102. package/dist/commands/compile/doc/reset.js +33 -0
  103. package/dist/commands/compile/import.d.ts +20 -0
  104. package/dist/commands/compile/import.js +138 -0
  105. package/dist/commands/compile/stats.d.ts +11 -0
  106. package/dist/commands/compile/stats.js +75 -0
  107. package/dist/commands/compile/status.d.ts +17 -0
  108. package/dist/commands/compile/status.js +110 -0
  109. package/dist/commands/compile/thread/create.d.ts +16 -0
  110. package/dist/commands/compile/thread/create.js +42 -0
  111. package/dist/commands/compile/thread/delete.d.ts +15 -0
  112. package/dist/commands/compile/thread/delete.js +33 -0
  113. package/dist/commands/compile/thread/edit.d.ts +19 -0
  114. package/dist/commands/compile/thread/edit.js +120 -0
  115. package/dist/commands/compile/thread/get.d.ts +15 -0
  116. package/dist/commands/compile/thread/get.js +48 -0
  117. package/dist/commands/compile/thread/list.d.ts +14 -0
  118. package/dist/commands/compile/thread/list.js +38 -0
  119. package/dist/commands/compile/thread/make.d.ts +17 -0
  120. package/dist/commands/compile/thread/make.js +87 -0
  121. package/dist/commands/compile/thread/message.d.ts +16 -0
  122. package/dist/commands/compile/thread/message.js +43 -0
  123. package/dist/commands/compile/thread/pause.d.ts +17 -0
  124. package/dist/commands/compile/thread/pause.js +75 -0
  125. package/dist/commands/compile/thread/replace.d.ts +27 -0
  126. package/dist/commands/compile/thread/replace.js +114 -0
  127. package/dist/commands/compile/thread/reset.d.ts +15 -0
  128. package/dist/commands/compile/thread/reset.js +33 -0
  129. package/dist/commands/compile/upload.d.ts +21 -0
  130. package/dist/commands/compile/upload.js +162 -0
  131. package/dist/commands/config/clear.d.ts +12 -0
  132. package/dist/commands/config/clear.js +17 -0
  133. package/dist/commands/config/set.d.ts +15 -0
  134. package/dist/commands/config/set.js +43 -0
  135. package/dist/commands/config/show.d.ts +11 -0
  136. package/dist/commands/config/show.js +19 -0
  137. package/dist/commands/decide.d.ts +35 -0
  138. package/dist/commands/decide.js +242 -0
  139. package/dist/commands/face/attributes.d.ts +11 -0
  140. package/dist/commands/face/attributes.js +44 -0
  141. package/dist/commands/face/avatar/delete.d.ts +15 -0
  142. package/dist/commands/face/avatar/delete.js +38 -0
  143. package/dist/commands/face/avatar/get.d.ts +20 -0
  144. package/dist/commands/face/avatar/get.js +100 -0
  145. package/dist/commands/face/avatar/list.d.ts +14 -0
  146. package/dist/commands/face/avatar/list.js +56 -0
  147. package/dist/commands/face/avatar/make.d.ts +16 -0
  148. package/dist/commands/face/avatar/make.js +64 -0
  149. package/dist/commands/face/avatar/upload.d.ts +15 -0
  150. package/dist/commands/face/avatar/upload.js +67 -0
  151. package/dist/commands/face/create.d.ts +23 -0
  152. package/dist/commands/face/create.js +122 -0
  153. package/dist/commands/face/delete.d.ts +15 -0
  154. package/dist/commands/face/delete.js +39 -0
  155. package/dist/commands/face/diff.d.ts +12 -0
  156. package/dist/commands/face/diff.js +50 -0
  157. package/dist/commands/face/edit.d.ts +25 -0
  158. package/dist/commands/face/edit.js +155 -0
  159. package/dist/commands/face/get.d.ts +16 -0
  160. package/dist/commands/face/get.js +145 -0
  161. package/dist/commands/face/groups.d.ts +15 -0
  162. package/dist/commands/face/groups.js +34 -0
  163. package/dist/commands/face/list.d.ts +23 -0
  164. package/dist/commands/face/list.js +168 -0
  165. package/dist/commands/face/lock.d.ts +15 -0
  166. package/dist/commands/face/lock.js +35 -0
  167. package/dist/commands/face/neighbors.d.ts +16 -0
  168. package/dist/commands/face/neighbors.js +63 -0
  169. package/dist/commands/face/publish.d.ts +16 -0
  170. package/dist/commands/face/publish.js +43 -0
  171. package/dist/commands/face/share.d.ts +22 -0
  172. package/dist/commands/face/share.js +104 -0
  173. package/dist/commands/face/sources.d.ts +21 -0
  174. package/dist/commands/face/sources.js +169 -0
  175. package/dist/commands/face/stats.d.ts +12 -0
  176. package/dist/commands/face/stats.js +46 -0
  177. package/dist/commands/face/tag/add.d.ts +15 -0
  178. package/dist/commands/face/tag/add.js +40 -0
  179. package/dist/commands/face/tag/all.d.ts +11 -0
  180. package/dist/commands/face/tag/all.js +31 -0
  181. package/dist/commands/face/tag/list.d.ts +14 -0
  182. package/dist/commands/face/tag/list.js +36 -0
  183. package/dist/commands/face/tag/remove.d.ts +16 -0
  184. package/dist/commands/face/tag/remove.js +44 -0
  185. package/dist/commands/face/tag/set.d.ts +15 -0
  186. package/dist/commands/face/tag/set.js +40 -0
  187. package/dist/commands/face/unlock.d.ts +15 -0
  188. package/dist/commands/face/unlock.js +35 -0
  189. package/dist/commands/face/unpublish.d.ts +14 -0
  190. package/dist/commands/face/unpublish.js +32 -0
  191. package/dist/commands/face/unshare.d.ts +18 -0
  192. package/dist/commands/face/unshare.js +66 -0
  193. package/dist/commands/fidelity/get.d.ts +15 -0
  194. package/dist/commands/fidelity/get.js +42 -0
  195. package/dist/commands/fidelity/pick.d.ts +19 -0
  196. package/dist/commands/fidelity/pick.js +70 -0
  197. package/dist/commands/fidelity/run.d.ts +20 -0
  198. package/dist/commands/fidelity/run.js +99 -0
  199. package/dist/commands/fidelity/save-thread.d.ts +15 -0
  200. package/dist/commands/fidelity/save-thread.js +35 -0
  201. package/dist/commands/fidelity/start.d.ts +17 -0
  202. package/dist/commands/fidelity/start.js +56 -0
  203. package/dist/commands/fidelity/turn.d.ts +17 -0
  204. package/dist/commands/fidelity/turn.js +48 -0
  205. package/dist/commands/group/add.d.ts +16 -0
  206. package/dist/commands/group/add.js +83 -0
  207. package/dist/commands/group/create.d.ts +16 -0
  208. package/dist/commands/group/create.js +68 -0
  209. package/dist/commands/group/delete.d.ts +15 -0
  210. package/dist/commands/group/delete.js +39 -0
  211. package/dist/commands/group/edit.d.ts +18 -0
  212. package/dist/commands/group/edit.js +75 -0
  213. package/dist/commands/group/get.d.ts +14 -0
  214. package/dist/commands/group/get.js +29 -0
  215. package/dist/commands/group/list.d.ts +11 -0
  216. package/dist/commands/group/list.js +39 -0
  217. package/dist/commands/group/members.d.ts +15 -0
  218. package/dist/commands/group/members.js +68 -0
  219. package/dist/commands/group/remove.d.ts +15 -0
  220. package/dist/commands/group/remove.js +55 -0
  221. package/dist/commands/group/tag/add.d.ts +15 -0
  222. package/dist/commands/group/tag/add.js +30 -0
  223. package/dist/commands/group/tag/list.d.ts +14 -0
  224. package/dist/commands/group/tag/list.js +36 -0
  225. package/dist/commands/group/tag/remove.d.ts +15 -0
  226. package/dist/commands/group/tag/remove.js +30 -0
  227. package/dist/commands/group/tag/set.d.ts +15 -0
  228. package/dist/commands/group/tag/set.js +30 -0
  229. package/dist/commands/keys/create.d.ts +17 -0
  230. package/dist/commands/keys/create.js +72 -0
  231. package/dist/commands/keys/list.d.ts +11 -0
  232. package/dist/commands/keys/list.js +24 -0
  233. package/dist/commands/keys/revoke.d.ts +15 -0
  234. package/dist/commands/keys/revoke.js +49 -0
  235. package/dist/commands/keys/update.d.ts +17 -0
  236. package/dist/commands/keys/update.js +41 -0
  237. package/dist/commands/models/list.d.ts +15 -0
  238. package/dist/commands/models/list.js +98 -0
  239. package/dist/commands/session/close.d.ts +16 -0
  240. package/dist/commands/session/close.js +36 -0
  241. package/dist/commands/session/compact.d.ts +15 -0
  242. package/dist/commands/session/compact.js +58 -0
  243. package/dist/commands/session/create.d.ts +15 -0
  244. package/dist/commands/session/create.js +45 -0
  245. package/dist/commands/session/get.d.ts +15 -0
  246. package/dist/commands/session/get.js +34 -0
  247. package/dist/commands/style/delete.d.ts +19 -0
  248. package/dist/commands/style/delete.js +94 -0
  249. package/dist/commands/style/make.d.ts +28 -0
  250. package/dist/commands/style/make.js +298 -0
  251. package/dist/commands/style/revert.d.ts +17 -0
  252. package/dist/commands/style/revert.js +66 -0
  253. package/dist/commands/style/status.d.ts +20 -0
  254. package/dist/commands/style/status.js +109 -0
  255. package/dist/commands/style/upload.d.ts +19 -0
  256. package/dist/commands/style/upload.js +100 -0
  257. package/dist/commands/style/versions.d.ts +15 -0
  258. package/dist/commands/style/versions.js +104 -0
  259. package/dist/commands/user/follow.d.ts +14 -0
  260. package/dist/commands/user/follow.js +38 -0
  261. package/dist/commands/user/followers.d.ts +14 -0
  262. package/dist/commands/user/followers.js +50 -0
  263. package/dist/commands/user/following.d.ts +14 -0
  264. package/dist/commands/user/following.js +50 -0
  265. package/dist/commands/user/get.d.ts +14 -0
  266. package/dist/commands/user/get.js +49 -0
  267. package/dist/commands/user/unfollow.d.ts +14 -0
  268. package/dist/commands/user/unfollow.js +38 -0
  269. package/dist/config.d.ts +32 -0
  270. package/dist/config.js +139 -0
  271. package/dist/decisions.d.ts +42 -0
  272. package/dist/decisions.js +262 -0
  273. package/dist/fidelity.d.ts +50 -0
  274. package/dist/fidelity.js +92 -0
  275. package/dist/group-catalog.d.ts +22 -0
  276. package/dist/group-catalog.js +133 -0
  277. package/dist/paths.d.ts +1 -0
  278. package/dist/paths.js +8 -0
  279. package/dist/poll.d.ts +26 -0
  280. package/dist/poll.js +75 -0
  281. package/dist/routing.d.ts +15 -0
  282. package/dist/routing.js +135 -0
  283. package/dist/session.d.ts +14 -0
  284. package/dist/session.js +18 -0
  285. package/dist/style.d.ts +46 -0
  286. package/dist/style.js +285 -0
  287. package/dist/utils.d.ts +149 -0
  288. package/dist/utils.js +865 -0
  289. package/oclif.manifest.json +11070 -0
  290. package/package.json +127 -4
@@ -0,0 +1,242 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { loadConfig } from './config.js';
5
+ import { MAX_FRONTMATTER_VALUE, quoteYaml, unquoteYaml } from './utils.js';
6
+ import { childPath } from './paths.js';
7
+ export const CATALOG_DIR = path.join(os.homedir(), '.faces', 'catalog');
8
+ export const CATALOG_INDEX = path.join(os.homedir(), '.faces', 'catalog.json');
9
+ function serializeFrontmatter(fm) {
10
+ const lines = ['---'];
11
+ lines.push(`name: ${quoteYaml(fm.name)}`);
12
+ if (fm.description)
13
+ lines.push(`description: ${quoteYaml(fm.description)}`);
14
+ lines.push(`alias: ${quoteYaml(fm.alias)}`);
15
+ if (fm.default_model)
16
+ lines.push(`default_model: ${quoteYaml(fm.default_model)}`);
17
+ if (fm.formula)
18
+ lines.push(`formula: ${quoteYaml(fm.formula)}`);
19
+ if (fm.attributes && Object.keys(fm.attributes).length > 0) {
20
+ lines.push('attributes:');
21
+ for (const [k, v] of Object.entries(fm.attributes)) {
22
+ lines.push(` ${k}: ${quoteYaml(String(v))}`);
23
+ }
24
+ }
25
+ if (fm.tags && fm.tags.length > 0) {
26
+ lines.push(`tags: [${fm.tags.join(', ')}]`);
27
+ }
28
+ if (fm.compiled_tokens !== undefined) {
29
+ lines.push(`compiled_tokens: ${fm.compiled_tokens}`);
30
+ }
31
+ for (const line of fm.extraLines ?? [])
32
+ lines.push(line);
33
+ lines.push('---');
34
+ return lines.join('\n');
35
+ }
36
+ function parseFrontmatter(content) {
37
+ const block = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
38
+ let match = content.match(block);
39
+ if (!match)
40
+ return { frontmatter: null, body: content, extraKeys: {}, partial: {} };
41
+ const fm = {};
42
+ const extraKeys = {};
43
+ const extraLines = [];
44
+ const attributes = {};
45
+ const knownKeys = new Set(['name', 'description', 'alias', 'attributes', 'tags', 'default_model', 'formula', 'component_counts', 'compiled_tokens', 'profile_token_count']);
46
+ let rest = content;
47
+ while (match) {
48
+ let section = null;
49
+ for (const line of match[1].split('\n')) {
50
+ if (/^\s/.test(line) && line.trim()) {
51
+ if (section === 'attributes') {
52
+ const colonIdx = line.indexOf(':');
53
+ if (colonIdx > 0) {
54
+ const k = line.slice(0, colonIdx).trim();
55
+ if (!(k in attributes))
56
+ attributes[k] = unquoteYaml(line.slice(colonIdx + 1));
57
+ }
58
+ }
59
+ else if (section === 'extra') {
60
+ extraLines.push(line);
61
+ }
62
+ continue;
63
+ }
64
+ section = null;
65
+ const colonIdx = line.indexOf(':');
66
+ if (colonIdx < 0)
67
+ continue;
68
+ const key = line.slice(0, colonIdx).trim();
69
+ const val = unquoteYaml(line.slice(colonIdx + 1));
70
+ const seen = fm[key] !== undefined;
71
+ if (key === 'attributes')
72
+ section = 'attributes';
73
+ else if (!knownKeys.has(key)) {
74
+ if (key in extraKeys)
75
+ continue;
76
+ extraKeys[key] = val;
77
+ extraLines.push(line);
78
+ section = 'extra';
79
+ }
80
+ else if (seen)
81
+ continue;
82
+ else if (key === 'name')
83
+ fm.name = val;
84
+ else if (key === 'description')
85
+ fm.description = val;
86
+ else if (key === 'alias')
87
+ fm.alias = val;
88
+ else if (key === 'default_model')
89
+ fm.default_model = val;
90
+ else if (key === 'formula')
91
+ fm.formula = val;
92
+ else if (key === 'tags') {
93
+ const inner = val.replace(/^\[/, '').replace(/\]$/, '');
94
+ fm.tags = inner ? inner.split(',').map(s => s.trim()).filter(Boolean) : [];
95
+ }
96
+ else if (key === 'compiled_tokens')
97
+ fm.compiled_tokens = Number(val) || 0;
98
+ }
99
+ rest = rest.slice(match[0].length);
100
+ match = rest.match(block);
101
+ }
102
+ if (Object.keys(attributes).length > 0)
103
+ fm.attributes = attributes;
104
+ if (extraLines.length > 0)
105
+ fm.extraLines = extraLines;
106
+ if (!fm.name || !fm.alias)
107
+ return { frontmatter: null, body: rest, extraKeys, partial: fm };
108
+ return { frontmatter: fm, body: rest, extraKeys, partial: fm };
109
+ }
110
+ const DEFAULT_BODY = '\n## Notes\n\n';
111
+ export class CatalogService {
112
+ isEnabled() {
113
+ const cfg = loadConfig();
114
+ return cfg.catalog !== 'false';
115
+ }
116
+ writeFace(faceData, description) {
117
+ if (!this.isEnabled())
118
+ return;
119
+ try {
120
+ const alias = faceData.alias;
121
+ const dir = childPath(CATALOG_DIR, alias);
122
+ fs.mkdirSync(dir, { recursive: true });
123
+ const filePath = path.join(dir, 'FACE.md');
124
+ let existingBody = DEFAULT_BODY;
125
+ let existingDescription;
126
+ let existingExtraLines = [];
127
+ if (fs.existsSync(filePath)) {
128
+ const existing = fs.readFileSync(filePath, 'utf8');
129
+ const parsed = parseFrontmatter(existing);
130
+ if (parsed.body.trim())
131
+ existingBody = parsed.body;
132
+ if (parsed.partial.description)
133
+ existingDescription = parsed.partial.description;
134
+ existingExtraLines = parsed.partial.extraLines ?? [];
135
+ }
136
+ const fm = {
137
+ name: faceData.name,
138
+ alias,
139
+ };
140
+ if (description) {
141
+ fm.description = description;
142
+ }
143
+ else if (faceData.description) {
144
+ fm.description = faceData.description;
145
+ }
146
+ else if (existingDescription) {
147
+ if (existingDescription.length > MAX_FRONTMATTER_VALUE) {
148
+ process.stderr.write(`warn: discarded a ${existingDescription.length}-character description on '${alias}': ` +
149
+ 'too large to be real. It will be restored from the server on the next sync.\n');
150
+ }
151
+ else {
152
+ fm.description = existingDescription;
153
+ }
154
+ }
155
+ if (faceData.default_model)
156
+ fm.default_model = faceData.default_model;
157
+ if (faceData.formula)
158
+ fm.formula = faceData.formula;
159
+ if (faceData.basic_facts && Object.keys(faceData.basic_facts).length > 0) {
160
+ const attrs = {};
161
+ for (const [k, v] of Object.entries(faceData.basic_facts)) {
162
+ attrs[k] = typeof v === 'object' && v !== null && 'value' in v ? v.value : String(v);
163
+ }
164
+ fm.attributes = attrs;
165
+ }
166
+ if (faceData.tags && faceData.tags.length > 0)
167
+ fm.tags = faceData.tags;
168
+ if (typeof faceData.compile_tokens_synced === 'number')
169
+ fm.compiled_tokens = faceData.compile_tokens_synced;
170
+ else
171
+ fm.compiled_tokens = 0;
172
+ if (existingExtraLines.length > 0)
173
+ fm.extraLines = existingExtraLines;
174
+ const content = serializeFrontmatter(fm) + '\n' + existingBody;
175
+ fs.writeFileSync(filePath, content);
176
+ this.rebuildIndex();
177
+ }
178
+ catch (err) {
179
+ const msg = err instanceof Error ? err.message : String(err);
180
+ process.stderr.write(`warn: catalog write failed: ${msg}\n`);
181
+ }
182
+ }
183
+ deleteFace(alias) {
184
+ if (!this.isEnabled())
185
+ return;
186
+ try {
187
+ const dir = childPath(CATALOG_DIR, alias);
188
+ fs.rmSync(dir, { recursive: true, force: true });
189
+ this.rebuildIndex();
190
+ }
191
+ catch (err) {
192
+ const msg = err instanceof Error ? err.message : String(err);
193
+ process.stderr.write(`warn: catalog delete failed: ${msg}\n`);
194
+ }
195
+ }
196
+ updateTags(alias, tags) {
197
+ if (!this.isEnabled())
198
+ return;
199
+ try {
200
+ const filePath = path.join(childPath(CATALOG_DIR, alias), 'FACE.md');
201
+ if (!fs.existsSync(filePath))
202
+ return;
203
+ const content = fs.readFileSync(filePath, 'utf8');
204
+ const parsed = parseFrontmatter(content);
205
+ if (!parsed.frontmatter)
206
+ return;
207
+ parsed.frontmatter.tags = tags;
208
+ const newContent = serializeFrontmatter(parsed.frontmatter) + '\n' + parsed.body;
209
+ fs.writeFileSync(filePath, newContent);
210
+ this.rebuildIndex();
211
+ }
212
+ catch (err) {
213
+ const msg = err instanceof Error ? err.message : String(err);
214
+ process.stderr.write(`warn: catalog tag update failed: ${msg}\n`);
215
+ }
216
+ }
217
+ rebuildIndex() {
218
+ if (!this.isEnabled())
219
+ return;
220
+ try {
221
+ fs.mkdirSync(CATALOG_DIR, { recursive: true });
222
+ const entries = [];
223
+ const dirs = fs.readdirSync(CATALOG_DIR, { withFileTypes: true });
224
+ for (const dirent of dirs) {
225
+ if (!dirent.isDirectory())
226
+ continue;
227
+ const faceMdPath = path.join(childPath(CATALOG_DIR, dirent.name), 'FACE.md');
228
+ if (!fs.existsSync(faceMdPath))
229
+ continue;
230
+ const content = fs.readFileSync(faceMdPath, 'utf8');
231
+ const { frontmatter } = parseFrontmatter(content);
232
+ if (frontmatter)
233
+ entries.push(frontmatter);
234
+ }
235
+ fs.writeFileSync(CATALOG_INDEX, JSON.stringify(entries, null, 2));
236
+ }
237
+ catch (err) {
238
+ const msg = err instanceof Error ? err.message : String(err);
239
+ process.stderr.write(`warn: catalog index rebuild failed: ${msg}\n`);
240
+ }
241
+ }
242
+ }
@@ -0,0 +1,98 @@
1
+ export declare const CLI_VERSION: string | undefined;
2
+ export declare function outOfDateHint(latest?: string | null): string;
3
+ export declare function compareVersions(a: string, b: string): number;
4
+ export declare function latestCliVersion(): Promise<string | null>;
5
+ export declare function missingFieldsNote(data: unknown, fields: string[]): string | undefined;
6
+ export declare function looksOutOfDate(status: number, message: string): boolean;
7
+ export declare class FacesAPIError extends Error {
8
+ statusCode: number;
9
+ errorCode?: string;
10
+ fallbackAvailable?: boolean;
11
+ details?: Record<string, unknown>;
12
+ retryAfter?: number;
13
+ retryable?: boolean;
14
+ constructor(statusCode: number, message: string, opts?: {
15
+ errorCode?: string;
16
+ fallbackAvailable?: boolean;
17
+ details?: Record<string, unknown>;
18
+ retryAfter?: number;
19
+ retryable?: boolean;
20
+ });
21
+ }
22
+ export declare function refusalGuidance(status: number, errorCode: string | undefined, message: string): string | undefined;
23
+ export declare function readableDetail(detail: unknown): string | undefined;
24
+ export declare function parseRetryAfter(raw: string | null | undefined): number | undefined;
25
+ export declare const MAX_RATE_LIMIT_WAIT_S = 60;
26
+ export declare function rateLimitWait(retryAfter: number | undefined, body: string): number | undefined;
27
+ export interface ResponseWithHeaders<T = unknown> {
28
+ data: T;
29
+ headers: Record<string, string>;
30
+ }
31
+ export declare class FacesClient {
32
+ private baseUrl;
33
+ lastError?: FacesAPIError;
34
+ private withheld?;
35
+ private keySaved;
36
+ private token?;
37
+ private apiKey?;
38
+ constructor(baseUrl: string, token?: string, apiKey?: string, withheld?: string, keySaved?: boolean);
39
+ private url;
40
+ authHeader(requireJwt?: boolean): Record<string, string>;
41
+ private wrapNetworkError;
42
+ private send;
43
+ private parseError;
44
+ get(path: string, opts?: {
45
+ requireJwt?: boolean;
46
+ params?: Record<string, string>;
47
+ optionalAuth?: boolean;
48
+ }): Promise<unknown>;
49
+ getAll(path: string, opts?: {
50
+ requireJwt?: boolean;
51
+ pageSize?: number;
52
+ maxPages?: number;
53
+ }): Promise<{
54
+ data: Array<Record<string, unknown>>;
55
+ pages: number;
56
+ truncated: boolean;
57
+ envelope: Record<string, unknown>;
58
+ }>;
59
+ post(path: string, opts?: {
60
+ requireJwt?: boolean;
61
+ body?: unknown;
62
+ }): Promise<unknown>;
63
+ postWithHeaders(path: string, opts?: {
64
+ requireJwt?: boolean;
65
+ body?: unknown;
66
+ }): Promise<ResponseWithHeaders>;
67
+ postNoAuth(path: string, body: unknown): Promise<unknown>;
68
+ put(path: string, opts?: {
69
+ requireJwt?: boolean;
70
+ body?: unknown;
71
+ }): Promise<unknown>;
72
+ patch(path: string, opts?: {
73
+ requireJwt?: boolean;
74
+ body?: unknown;
75
+ }): Promise<unknown>;
76
+ delete(path: string, opts?: {
77
+ requireJwt?: boolean;
78
+ }): Promise<unknown>;
79
+ getBinary(path: string, opts?: {
80
+ requireJwt?: boolean;
81
+ }): Promise<{
82
+ bytes: Uint8Array;
83
+ contentType: string;
84
+ headers: Record<string, string>;
85
+ }>;
86
+ putForm(path: string, formData: FormData, opts?: {
87
+ requireJwt?: boolean;
88
+ }): Promise<unknown>;
89
+ postForm(path: string, formData: FormData, opts?: {
90
+ requireJwt?: boolean;
91
+ }): Promise<unknown>;
92
+ stream(path: string, body: unknown, opts?: {
93
+ requireJwt?: boolean;
94
+ onHeaders?: (headers: Record<string, string>) => void;
95
+ }): AsyncGenerator<string>;
96
+ }
97
+ export declare function streamErrorOf(data: string): FacesAPIError | undefined;
98
+ export declare function heldChatError(data: unknown): FacesAPIError | undefined;