@faces-sh/cli 1.1.0 → 1.3.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 (92) hide show
  1. package/README.md +106 -54
  2. package/dist/billing.js +11 -8
  3. package/dist/chat-command.d.ts +33 -0
  4. package/dist/chat-command.js +110 -0
  5. package/dist/chat.d.ts +49 -0
  6. package/dist/chat.js +157 -0
  7. package/dist/choices.d.ts +11 -5
  8. package/dist/choices.js +26 -9
  9. package/dist/client.d.ts +8 -0
  10. package/dist/client.js +37 -0
  11. package/dist/commands/billing/llm-costs.js +9 -5
  12. package/dist/commands/billing/subscription/index.js +1 -1
  13. package/dist/commands/catalog/doctor.js +2 -2
  14. package/dist/commands/{causes.d.ts → chat/chat.d.ts} +14 -14
  15. package/dist/commands/chat/chat.js +31 -0
  16. package/dist/commands/chat/messages.d.ts +32 -0
  17. package/dist/commands/chat/messages.js +21 -0
  18. package/dist/commands/chat/responses.d.ts +32 -0
  19. package/dist/commands/chat/responses.js +22 -0
  20. package/dist/commands/chat/thread.d.ts +40 -0
  21. package/dist/commands/chat/thread.js +238 -0
  22. package/dist/commands/choices.d.ts +4 -2
  23. package/dist/commands/choices.js +56 -15
  24. package/dist/commands/conversation/add.d.ts +2 -0
  25. package/dist/commands/conversation/add.js +5 -2
  26. package/dist/commands/conversation/compact.js +13 -16
  27. package/dist/commands/conversation/create.d.ts +2 -0
  28. package/dist/commands/conversation/create.js +14 -11
  29. package/dist/commands/decide.d.ts +32 -4
  30. package/dist/commands/decide.js +135 -83
  31. package/dist/commands/face/get.js +1 -1
  32. package/dist/commands/face/list.d.ts +2 -0
  33. package/dist/commands/face/list.js +23 -1
  34. package/dist/commands/fidelity/pick.js +2 -2
  35. package/dist/commands/fidelity/run.d.ts +20 -0
  36. package/dist/commands/fidelity/run.js +99 -0
  37. package/dist/commands/fidelity/start.d.ts +17 -0
  38. package/dist/commands/fidelity/start.js +56 -0
  39. package/dist/commands/fidelity/turn.d.ts +17 -0
  40. package/dist/commands/fidelity/turn.js +48 -0
  41. package/dist/commands/group/add.js +1 -1
  42. package/dist/commands/media/list.d.ts +12 -0
  43. package/dist/commands/media/list.js +35 -0
  44. package/dist/commands/models/list.js +13 -6
  45. package/dist/commands/premise/add.d.ts +30 -0
  46. package/dist/commands/premise/add.js +86 -0
  47. package/dist/commands/premise/choices.d.ts +21 -0
  48. package/dist/commands/premise/choices.js +68 -0
  49. package/dist/commands/premise/claim.d.ts +20 -0
  50. package/dist/commands/premise/claim.js +38 -0
  51. package/dist/commands/premise/decide.d.ts +18 -0
  52. package/dist/commands/premise/decide.js +36 -0
  53. package/dist/commands/premise/delete.d.ts +17 -0
  54. package/dist/commands/premise/delete.js +17 -0
  55. package/dist/commands/premise/edit.d.ts +28 -0
  56. package/dist/commands/premise/edit.js +51 -0
  57. package/dist/commands/premise/get.d.ts +22 -0
  58. package/dist/commands/premise/get.js +37 -0
  59. package/dist/commands/premise/refine.d.ts +20 -0
  60. package/dist/commands/premise/refine.js +80 -0
  61. package/dist/commands/session/compact.js +5 -8
  62. package/dist/commands/session/create.js +9 -8
  63. package/dist/commands/state/create.d.ts +13 -2
  64. package/dist/commands/state/create.js +55 -2
  65. package/dist/commands/state/get.d.ts +19 -2
  66. package/dist/commands/state/get.js +30 -2
  67. package/dist/commands/state/use.d.ts +16 -0
  68. package/dist/commands/state/use.js +25 -0
  69. package/dist/commands/style/make.js +1 -1
  70. package/dist/commands/style/upload.js +1 -1
  71. package/dist/conversation.d.ts +30 -3
  72. package/dist/conversation.js +202 -18
  73. package/dist/decisions.d.ts +0 -5
  74. package/dist/decisions.js +0 -18
  75. package/dist/fidelity.js +3 -3
  76. package/dist/foreman.d.ts +47 -0
  77. package/dist/foreman.js +115 -0
  78. package/dist/media.d.ts +8 -0
  79. package/dist/media.js +12 -0
  80. package/dist/model.d.ts +11 -0
  81. package/dist/model.js +53 -0
  82. package/dist/refine.d.ts +106 -0
  83. package/dist/refine.js +601 -0
  84. package/dist/routing.d.ts +1 -4
  85. package/dist/routing.js +4 -40
  86. package/dist/synopsis.d.ts +49 -0
  87. package/dist/synopsis.js +43 -0
  88. package/dist/utils.d.ts +1 -25
  89. package/dist/utils.js +10 -108
  90. package/oclif.manifest.json +3939 -1835
  91. package/package.json +10 -4
  92. package/dist/commands/causes.js +0 -146
@@ -1,13 +1,19 @@
1
1
  import { Flags } from '@oclif/core';
2
2
  export const CONVERSATIONS_PATH = '/v1/states';
3
3
  export const MAX_CONVERSATION_ITEMS = 20;
4
- const PREMISE_KEY = /^[A-Za-z0-9_-]{1,64}$/;
4
+ export const MAX_KEY_CHARS = 120;
5
+ const KEY_REFUSED = /[\u0000-\u001f\u007f-\u009f\u2028\u2029\u202a-\u202e\u2066-\u2069]/;
5
6
  export const PREMISE_STATUSES = ['stated', 'verified', 'assumed', 'unresolved', 'invalidated'];
7
+ export const PREMISE_ROLES = ['goal', 'test'];
8
+ export const EDGE_KINDS = ['and', 'or'];
9
+ export const PREMISE_ORIGINS = ['human', 'agent', 'tool', 'web'];
6
10
  export const MAX_DEPENDS_ON = 200;
7
11
  export const CONVERSATION_FLAG_DESCRIPTION = 'Add this turn to a state, by id (from faces state:create). Send only what is new: ' +
8
12
  'the state so far is read before it. A state opened with one face takes only that face.';
9
13
  export const PREMISE_FLAG_DESCRIPTION = 'A premise, as key=value (repeatable): a named fact the face\'s answers depend on, kept on the ' +
10
- 'state. The key is 1 to 64 letters, digits, _ or -. The value is read as JSON when it is JSON ' +
14
+ 'state. The key is plain text, 1 to 120 characters, split from the value at the first =: ' +
15
+ '--premise \'everyone can eat=yes\'. A key that holds = goes in double quotes: --premise \'"a=b"=yes\'. ' +
16
+ 'The value is read as JSON when it is JSON ' +
11
17
  '(50000, true, null, ["a","b"], {"max":3}) and as text otherwise, so plan=annual is the text "annual". ' +
12
18
  'Quote it to keep a number as text: --premise \'code="007"\'. A newer value of a key replaces it from ' +
13
19
  'then on. A key used for the first time needs --premise-description.';
@@ -17,9 +23,20 @@ export const PREMISE_DESCRIPTION_FLAG_DESCRIPTION = 'What a --premise means, in
17
23
  export const PREMISE_STATUS_FLAG_DESCRIPTION = `A --premise's status, as key=status (repeatable, one per key): ${PREMISE_STATUSES.join(', ')}. ` +
18
24
  'Left out, a new premise is stated. An invalidated premise invalidates everything that depends on it; ' +
19
25
  'set it to another status to restore them.';
20
- export const PREMISE_DEPENDS_ON_FLAG_DESCRIPTION = 'What a --premise rests on, as key=a,b (repeatable, one per key): premise keys and decision ids already in ' +
21
- `the state or set in the same request, at most ${MAX_DEPENDS_ON}. key= with nothing after it clears it; ` +
26
+ export const PREMISE_DEPENDS_ON_FLAG_DESCRIPTION = 'What a --premise rests on, as key=a,b (repeatable, one per key): premise keys, decision ids and option ids ' +
27
+ '(opt_..., or cho_... for all of a choices list, from faces choices --state-id) already in ' +
28
+ `the state or set in the same request, at most ${MAX_DEPENDS_ON}, comma separated (a key that holds a comma ` +
29
+ 'goes in double quotes: key=\'"x, y",b\'). key rests on each: each must hold for it to hold. Weigh an entry ' +
30
+ 'with :and or :or, then a weight from 0 to 1, then @ and the decision that set it: ' +
31
+ 'task=a,b:or:0.7,c:and:0.5@dec_x. An and entry is a child that must hold (its weight is importance); the or ' +
32
+ 'entries are alternatives, one of which holds (their weights are probabilities and sum to 1). A plain entry is ' +
33
+ 'an and with no weight. key= with nothing after it clears it; ' +
22
34
  'left out, a newer value keeps what the key rested on before.';
35
+ export const PREMISE_ROLE_FLAG_DESCRIPTION = `A --premise's role, as key=role (repeatable, one per key): ${PREMISE_ROLES.join(' or ')}. wanted marks a goal, ` +
36
+ 'the outcome the state is working toward (the work is done when every goal is achieved); test marks a check ' +
37
+ 'that must pass. key= with nothing after it clears it; left out, a newer value keeps the role the key had.';
38
+ export const PREMISE_ORIGIN_FLAG_DESCRIPTION = `Who set a --premise, as key=origin (repeatable, one per key): ${PREMISE_ORIGINS.join(', ')}. key= with ` +
39
+ 'nothing after it clears it; left out, a newer value keeps the origin the key had.';
23
40
  export const CAUSES_VISIBLE_TURN_FLAG_DESCRIPTION = 'Whether the face reads the other faces\' causes on this turn, in a conversation with several faces. ' +
24
41
  'Leave it out to follow the state (see faces state:create --no-causes-visible).';
25
42
  export function conversationTurnFlags(opts = {}) {
@@ -31,6 +48,8 @@ export function conversationTurnFlags(opts = {}) {
31
48
  'premise-description': Flags.string({ description: d(PREMISE_DESCRIPTION_FLAG_DESCRIPTION), multiple: true, dependsOn: ['premise'], exclusive }),
32
49
  'premise-status': Flags.string({ description: d(PREMISE_STATUS_FLAG_DESCRIPTION), multiple: true, dependsOn: ['premise'], exclusive }),
33
50
  'premise-depends-on': Flags.string({ description: d(PREMISE_DEPENDS_ON_FLAG_DESCRIPTION), multiple: true, dependsOn: ['premise'], exclusive }),
51
+ 'premise-role': Flags.string({ description: d(PREMISE_ROLE_FLAG_DESCRIPTION), multiple: true, dependsOn: ['premise'], exclusive }),
52
+ 'premise-origin': Flags.string({ description: d(PREMISE_ORIGIN_FLAG_DESCRIPTION), multiple: true, dependsOn: ['premise'], exclusive }),
34
53
  'causes-visible': Flags.boolean({ description: d(`${CAUSES_VISIBLE_TURN_FLAG_DESCRIPTION} Needs --conversation.`), allowNo: true, exclusive }),
35
54
  };
36
55
  }
@@ -53,11 +72,15 @@ export function conversationHint(err) {
53
72
  return 'A state expires 30 days after it was last used, and a closed one cannot be used. ' +
54
73
  'Start another with: faces state:create';
55
74
  }
56
- const fresh = err.statusCode === 422 ? /premise '([A-Za-z0-9_-]{1,64})' is new/.exec(err.message) : null;
57
- if (fresh)
58
- return `Say what it means: --premise-description ${fresh[1]}="what it means, in plain words"`;
75
+ const fresh = err.statusCode === 422 ? /premise ('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*") is new/.exec(err.message) : null;
76
+ if (fresh) {
77
+ const key = unrepr(fresh[1]);
78
+ if (/^[A-Za-z0-9_-]+$/.test(key))
79
+ return `Say what it means: --premise-description ${key}="what it means, in plain words"`;
80
+ return `Say what it means: --premise-description ${shellWord(`${keyArg(key)}=what it means, in plain words`)}`;
81
+ }
59
82
  if (err.statusCode === 422 && /depends_on` names no premise or decision/.test(err.message)) {
60
- return 'Name premise keys and decision ids already in the state (faces state:items <id>), or premises set in the same request.';
83
+ return 'Name premise keys, decision ids and option ids already in the state (faces state:items <id>), or premises set in the same request.';
61
84
  }
62
85
  return undefined;
63
86
  }
@@ -74,17 +97,55 @@ export function premiseValue(raw) {
74
97
  return raw;
75
98
  }
76
99
  }
100
+ function quotedHead(raw) {
101
+ const s = raw.trimStart();
102
+ if (!s.startsWith('"'))
103
+ return undefined;
104
+ for (let i = 1; i < s.length; i++) {
105
+ if (s[i] === '\\') {
106
+ i++;
107
+ continue;
108
+ }
109
+ if (s[i] === '"') {
110
+ try {
111
+ return [JSON.parse(s.slice(0, i + 1)), s.slice(i + 1)];
112
+ }
113
+ catch {
114
+ return undefined;
115
+ }
116
+ }
117
+ }
118
+ return undefined;
119
+ }
77
120
  function splitPair(raw, flag, shape) {
121
+ const q = quotedHead(raw);
122
+ if (q) {
123
+ const rest = q[1].trimStart();
124
+ if (!rest.startsWith('='))
125
+ throw new Error(`${flag} takes ${shape}; after a quoted key comes = (got '${raw}').`);
126
+ return [q[0].trim(), rest.slice(1)];
127
+ }
78
128
  const i = raw.indexOf('=');
79
129
  if (i <= 0)
80
130
  throw new Error(`${flag} takes ${shape} (got '${raw}').`);
81
131
  return [raw.slice(0, i).trim(), raw.slice(i + 1)];
82
132
  }
83
133
  function checkKey(key, flag) {
84
- if (!PREMISE_KEY.test(key))
85
- throw new Error(`${flag}: a premise key is 1 to 64 letters, digits, _ or - (got '${key}').`);
134
+ const n = [...key].length;
135
+ if (n < 1 || n > MAX_KEY_CHARS || KEY_REFUSED.test(key)) {
136
+ throw new Error(`${flag}: a premise key is plain text of 1 to ${MAX_KEY_CHARS} characters on one line, with no control characters (got ${JSON.stringify(key)}).`);
137
+ }
138
+ }
139
+ export function keyArg(key) {
140
+ return /[=,]/.test(key) || key.startsWith('"') ? JSON.stringify(key) : key;
141
+ }
142
+ function shellWord(text) {
143
+ return /^[A-Za-z0-9_@%+=:,./-]+$/.test(text) ? text : `'${text.replace(/'/g, "'\\''")}'`;
86
144
  }
87
- export function parsePremises(premises = [], descriptions = [], statuses = [], dependsOn = []) {
145
+ function unrepr(q) {
146
+ return q.slice(1, -1).replace(/\\(.)/g, '$1');
147
+ }
148
+ export function parsePremises(premises = [], descriptions = [], statuses = [], dependsOn = [], roles = [], origins = []) {
88
149
  const out = [];
89
150
  const seen = new Map();
90
151
  for (const raw of premises) {
@@ -135,16 +196,131 @@ export function parsePremises(premises = [], descriptions = [], statuses = [], d
135
196
  throw new Error(`--premise-depends-on names '${key}', which no --premise sets. Add --premise ${key}=<value>.`);
136
197
  if (linked.has(key))
137
198
  throw new Error(`--premise-depends-on sets '${key}' twice. List everything it rests on once, comma separated.`);
138
- const deps = parseDependsOn(text, '--premise-depends-on');
139
- if (deps.includes(key))
199
+ const deps = parseWeightedDependsOn(text, '--premise-depends-on');
200
+ if (deps.some((d) => entryId(d) === key))
140
201
  throw new Error(`--premise-depends-on: premise '${key}' cannot depend on itself.`);
141
202
  linked.add(key);
142
203
  p.depends_on = deps;
143
204
  }
205
+ setOneOf(seen, roles, '--premise-role', 'role', PREMISE_ROLES);
206
+ setOneOf(seen, origins, '--premise-origin', 'origin', PREMISE_ORIGINS);
144
207
  return out;
145
208
  }
209
+ function setOneOf(seen, raws, flag, field, allowed) {
210
+ const done = new Set();
211
+ for (const raw of raws) {
212
+ const [key, text] = splitPair(raw, flag, `key=${field}`);
213
+ checkKey(key, flag);
214
+ const p = seen.get(key);
215
+ if (!p)
216
+ throw new Error(`${flag} names '${key}', which no --premise sets. Add --premise ${key}=<value>.`);
217
+ if (done.has(key))
218
+ throw new Error(`${flag} sets '${key}' twice. Give one ${field} per key.`);
219
+ const v = text.trim().toLowerCase();
220
+ if (v !== '' && !allowed.includes(v)) {
221
+ throw new Error(`${flag} for '${key}' is ${allowed.length === 1 ? allowed[0] : `one of ${allowed.join(', ')}`}, or ${key}= to clear it (got '${text}').`);
222
+ }
223
+ done.add(key);
224
+ p[field] = v === '' ? null : v;
225
+ }
226
+ }
146
227
  export function parseDependsOn(raw, flag = '--depends-on') {
147
- const out = [...new Set(raw.split(',').map((x) => x.trim()).filter(Boolean))];
228
+ const names = [];
229
+ let s = raw;
230
+ for (;;) {
231
+ s = s.trimStart();
232
+ if (s === '')
233
+ break;
234
+ const q = quotedHead(s);
235
+ if (q) {
236
+ names.push(q[0]);
237
+ s = q[1].trimStart();
238
+ if (s !== '' && !s.startsWith(','))
239
+ throw new Error(`${flag}: after a quoted key comes a comma or the end (got '${raw}').`);
240
+ s = s.slice(1);
241
+ continue;
242
+ }
243
+ const i = s.indexOf(',');
244
+ names.push((i < 0 ? s : s.slice(0, i)).trim());
245
+ if (i < 0)
246
+ break;
247
+ s = s.slice(i + 1);
248
+ }
249
+ const out = [...new Set(names.map((x) => x.trim()).filter(Boolean))];
250
+ if (out.length > MAX_DEPENDS_ON)
251
+ throw new Error(`${flag} names at most ${MAX_DEPENDS_ON} premises and decisions (got ${out.length}).`);
252
+ return out;
253
+ }
254
+ export function entryId(d) {
255
+ return typeof d === 'string' ? d : d.id;
256
+ }
257
+ export function entryText(d) {
258
+ if (typeof d === 'string')
259
+ return keyArg(d);
260
+ const p = typeof d.p === 'number' ? ` ${Math.round(d.p * 100) / 100}` : '';
261
+ return `${keyArg(d.id)} (${d.kind}${p}${d.decision ? ` by ${d.decision}` : ''})`;
262
+ }
263
+ const EDGE_SUFFIX = /^(?::(and|or)(?::([^:@,]*))?)?(?:@(dec_[A-Za-z0-9_-]+))?$/;
264
+ const UNQUOTED_ENTRY = /^(.*?)((?::(?:and|or)(?::[^:@,]*)?)?(?:@dec_[A-Za-z0-9_-]+)?)$/;
265
+ function edgeOf(id, suffix, flag, raw) {
266
+ const m = EDGE_SUFFIX.exec(suffix);
267
+ if (!m)
268
+ throw new Error(`${flag}: '${suffix}' after '${id}' is not :and or :or, then :p, then @dec_... (got '${raw}').`);
269
+ const [, kind, p, decision] = m;
270
+ if (!kind && !decision)
271
+ return id;
272
+ if (!kind)
273
+ throw new Error(`${flag}: give '${id}' a kind before its decision, :and or :or (as ${id}:or:0.7@${decision}).`);
274
+ const out = { id, kind };
275
+ if (p !== undefined) {
276
+ const n = Number(p);
277
+ if (p.trim() === '' || !Number.isFinite(n) || n < 0 || n > 1)
278
+ throw new Error(`${flag}: the weight of '${id}' is a number from 0 to 1 (got '${p}').`);
279
+ out.p = n;
280
+ }
281
+ if (decision)
282
+ out.decision = decision;
283
+ return out;
284
+ }
285
+ export function parseWeightedDependsOn(raw, flag = '--premise-depends-on') {
286
+ const out = [];
287
+ let s = raw;
288
+ for (;;) {
289
+ s = s.trimStart();
290
+ if (s === '')
291
+ break;
292
+ const q = quotedHead(s);
293
+ let entry;
294
+ if (q) {
295
+ const rest = q[1];
296
+ const i = rest.indexOf(',');
297
+ entry = edgeOf(q[0], (i < 0 ? rest : rest.slice(0, i)).trim(), flag, raw);
298
+ if (i < 0)
299
+ s = '';
300
+ else
301
+ s = rest.slice(i + 1);
302
+ }
303
+ else {
304
+ const i = s.indexOf(',');
305
+ const tok = (i < 0 ? s : s.slice(0, i)).trim();
306
+ const m = UNQUOTED_ENTRY.exec(tok);
307
+ if (m[1].trim() === '')
308
+ throw new Error(`${flag}: an entry needs an id before its weight (got '${tok}').`);
309
+ entry = edgeOf(m[1].trim(), m[2], flag, raw);
310
+ if (i < 0)
311
+ s = '';
312
+ else
313
+ s = s.slice(i + 1);
314
+ }
315
+ const id = entryId(entry);
316
+ const was = out.findIndex((d) => entryId(d) === id);
317
+ if (was >= 0) {
318
+ if (typeof entry !== 'string' || typeof out[was] !== 'string')
319
+ throw new Error(`${flag} names '${id}' twice. Give each entry once.`);
320
+ continue;
321
+ }
322
+ out.push(entry);
323
+ }
148
324
  if (out.length > MAX_DEPENDS_ON)
149
325
  throw new Error(`${flag} names at most ${MAX_DEPENDS_ON} premises and decisions (got ${out.length}).`);
150
326
  return out;
@@ -154,7 +330,7 @@ export function conversationFields(flags) {
154
330
  if (flags.conversation && flags.session && flags.conversation !== flags.session) {
155
331
  throw new Error('--session is the old name for --conversation: pass one of them, not two different ids.');
156
332
  }
157
- const premises = parsePremises(flags.premise, flags['premise-description'], flags['premise-status'], flags['premise-depends-on']);
333
+ const premises = parsePremises(flags.premise, flags['premise-description'], flags['premise-status'], flags['premise-depends-on'], flags['premise-role'], flags['premise-origin']);
158
334
  const inConversation = Boolean(flags.conversation || flags.session);
159
335
  if (!inConversation && (premises.length > 0 || flags['causes-visible'] !== undefined)) {
160
336
  throw new Error('Premises and --causes-visible belong to a state: add --conversation <id> (from faces state:create).');
@@ -184,7 +360,15 @@ function statusNote(p) {
184
360
  if (p.because)
185
361
  parts.push(`because ${p.because}`);
186
362
  if (p.depends_on && p.depends_on.length > 0)
187
- parts.push(`rests on ${p.depends_on.join(', ')}`);
363
+ parts.push(`rests on ${p.depends_on.map(entryText).join(', ')}`);
364
+ if (p.role)
365
+ parts.push(p.role);
366
+ if (p.origin)
367
+ parts.push(`from ${p.origin}`);
368
+ if (p.face)
369
+ parts.push(`proposed by @${p.face}`);
370
+ if (p.reason)
371
+ parts.push(p.reason);
188
372
  return parts.length > 0 ? ` [${parts.join('; ')}]` : '';
189
373
  }
190
374
  export function statusChangeLines(changes) {
@@ -203,7 +387,7 @@ export function premiseLines(premises) {
203
387
  return ['premises: none'];
204
388
  const lines = ['premises:'];
205
389
  for (const [key, p] of entries) {
206
- lines.push(` ${key} = ${shownValue(p?.value)}${statusNote(p)}${p?.description ? ` (${p.description})` : ''}`);
390
+ lines.push(` ${keyArg(key)} = ${shownValue(p?.value)}${statusNote(p)}${p?.description ? ` (${p.description})` : ''}`);
207
391
  }
208
392
  return lines;
209
393
  }
@@ -272,7 +456,7 @@ export function itemLines(items) {
272
456
  if (call?.name === 'premise') {
273
457
  const key = String(parsed(call.arguments).key ?? '?');
274
458
  const desc = typeof out.description === 'string' && out.description ? ` (${out.description})` : '';
275
- lines.push(`${head}premise ${key} = ${shownValue(out.value)}${desc}`);
459
+ lines.push(`${head}premise ${keyArg(key)} = ${shownValue(out.value)}${desc}`);
276
460
  }
277
461
  else if (call?.name === 'decision') {
278
462
  const who = String(it.face ?? call.face ?? 'face');
@@ -22,11 +22,6 @@ export declare function parseDecisionOption(raw: string): {
22
22
  export declare function decisionLines(answers: Record<string, unknown>, barWidth?: number): string[];
23
23
  export declare const MAX_WARM_UP_WAIT_S = 300;
24
24
  export declare function warmUpWait(status: number, retryAfter: number | undefined, waitedS: number): number | undefined;
25
- export interface DecisionCauses {
26
- cause?: string;
27
- causes?: Record<string, unknown>;
28
- }
29
- export declare function causeLines(data: DecisionCauses, questionIds: string[]): string[];
30
25
  export declare function heldDecisionError(data: unknown): FacesAPIError | undefined;
31
26
  export declare function readStateFlags(flags: {
32
27
  state?: string;
package/dist/decisions.js CHANGED
@@ -158,24 +158,6 @@ export function warmUpWait(status, retryAfter, waitedS) {
158
158
  return undefined;
159
159
  return retryAfter;
160
160
  }
161
- export function causeLines(data, questionIds) {
162
- const cause = typeof data.cause === 'string' ? data.cause : '';
163
- const per = questionIds.map((id) => {
164
- const c = data.causes?.[id];
165
- return [id, typeof c === 'string' && c !== '' ? c : cause];
166
- });
167
- if (per.length === 0 || per.every(([, c]) => c === cause))
168
- return cause ? [cause] : [];
169
- const lines = [];
170
- for (const [id, c] of per) {
171
- if (!c)
172
- continue;
173
- if (lines.length > 0)
174
- lines.push('');
175
- lines.push(`${id}:`, c);
176
- }
177
- return lines;
178
- }
179
161
  export function heldDecisionError(data) {
180
162
  if (!data || typeof data !== 'object')
181
163
  return undefined;
package/dist/fidelity.js CHANGED
@@ -23,7 +23,7 @@ export function nextStep(run) {
23
23
  }
24
24
  return run.next.awaiting === 'choice'
25
25
  ? `Pick the answer that sounds more like the person: faces fidelity:pick ${id} a|b [--correction "..."]`
26
- : `Turn ${run.next.turn} waits for a message, and new turns are retired with chat.`;
26
+ : `Send turn ${run.next.turn}'s message: faces fidelity:turn ${id} -m "..."`;
27
27
  }
28
28
  export function runLines(run) {
29
29
  const total = run.turns_total ?? FIDELITY_TURNS;
@@ -73,7 +73,7 @@ export function fidelityHint(err, on = {}) {
73
73
  case 'fidelity_choice_pending':
74
74
  return `Pick one first: faces fidelity:pick ${id} a|b`;
75
75
  case 'fidelity_run_finished':
76
- return `Read the score: faces fidelity:get ${id}.`;
76
+ return `Read the score: faces fidelity:get ${id}. Start another with faces fidelity:start ${on.alias ?? '<alias>'}.`;
77
77
  case 'fidelity_run_open':
78
78
  return `See where it stands: faces fidelity:get ${id}`;
79
79
  case 'fidelity_unknown_model':
@@ -81,7 +81,7 @@ export function fidelityHint(err, on = {}) {
81
81
  case 'fidelity_nothing_compiled':
82
82
  return `Add a source with: faces compile:upload ${on.alias ?? '<alias>'} --file <file>`;
83
83
  case 'fidelity_run_not_found':
84
- return 'Check the run id.';
84
+ return 'Run ids are printed by faces fidelity:start.';
85
85
  default:
86
86
  return undefined;
87
87
  }
@@ -0,0 +1,47 @@
1
+ import { BaseCommand } from './base.js';
2
+ import { FacesClient } from './client.js';
3
+ import { premiseValue } from './conversation.js';
4
+ export declare const STATE_DIR = ".faces";
5
+ export declare const STATE_FILE = "state";
6
+ export declare const STATE_LOCAL_FILE = "state.local";
7
+ export declare function findStateFile(from?: string): {
8
+ file: string;
9
+ id: string;
10
+ } | undefined;
11
+ export declare function writeStateFile(id: string, local?: boolean, dir?: string): string;
12
+ export declare function keyList(raw: string[] | undefined, flag: string): string[] | undefined;
13
+ export { premiseValue };
14
+ export declare const stateIdFlag: {
15
+ 'state-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ };
17
+ export declare const asFlag: {
18
+ as: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
+ };
20
+ export declare abstract class ReplyCommand extends BaseCommand {
21
+ protected stateId(flags: {
22
+ 'state-id'?: string;
23
+ }, positional?: string): string;
24
+ protected statePath(id: string, route: string): string;
25
+ protected reply(client: FacesClient, method: 'GET' | 'POST' | 'PATCH' | 'DELETE', p: string, opts?: {
26
+ body?: Record<string, unknown>;
27
+ params?: Record<string, string>;
28
+ }): Promise<Record<string, unknown>>;
29
+ protected show(got: {
30
+ status: number;
31
+ ok: boolean;
32
+ data: Record<string, unknown>;
33
+ }): Record<string, unknown>;
34
+ }
35
+ export declare function compact(body: Record<string, unknown>): Record<string, unknown>;
36
+ export declare const formatFlags: {
37
+ problog: import("@oclif/core/interfaces").BooleanFlag<boolean>;
38
+ dot: import("@oclif/core/interfaces").BooleanFlag<boolean>;
39
+ };
40
+ export declare function formatOf(flags: {
41
+ problog?: boolean;
42
+ dot?: boolean;
43
+ }, json: boolean): string;
44
+ export declare const faceFlag: {
45
+ face: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
46
+ };
47
+ export declare function faceRef(face: string): string;
@@ -0,0 +1,115 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { Flags } from '@oclif/core';
4
+ import { BaseCommand } from './base.js';
5
+ import { FacesAPIError } from './client.js';
6
+ import { CONVERSATIONS_PATH, parseDependsOn, premiseValue } from './conversation.js';
7
+ import { seg } from './utils.js';
8
+ export const STATE_DIR = '.faces';
9
+ export const STATE_FILE = 'state';
10
+ export const STATE_LOCAL_FILE = 'state.local';
11
+ export function findStateFile(from = process.cwd()) {
12
+ let dir = path.resolve(from);
13
+ for (;;) {
14
+ for (const name of [STATE_LOCAL_FILE, STATE_FILE]) {
15
+ const file = path.join(dir, STATE_DIR, name);
16
+ try {
17
+ const id = fs.readFileSync(file, 'utf8').trim().split(/\s+/)[0];
18
+ if (id)
19
+ return { file, id };
20
+ }
21
+ catch {
22
+ }
23
+ }
24
+ const up = path.dirname(dir);
25
+ if (up === dir)
26
+ return undefined;
27
+ dir = up;
28
+ }
29
+ }
30
+ export function writeStateFile(id, local = false, dir = process.cwd()) {
31
+ const d = path.join(dir, STATE_DIR);
32
+ fs.mkdirSync(d, { recursive: true });
33
+ const file = path.join(d, local ? STATE_LOCAL_FILE : STATE_FILE);
34
+ fs.writeFileSync(file, id + '\n');
35
+ return file;
36
+ }
37
+ export function keyList(raw, flag) {
38
+ if (!raw || raw.length === 0)
39
+ return undefined;
40
+ const out = [];
41
+ for (const r of raw)
42
+ out.push(...parseDependsOn(r, flag));
43
+ return [...new Set(out)];
44
+ }
45
+ export { premiseValue };
46
+ export const stateIdFlag = {
47
+ 'state-id': Flags.string({
48
+ description: 'The state (fs_...). Default: FACES_STATE_ID, else .faces/state.local or .faces/state here or above.',
49
+ env: 'FACES_STATE_ID',
50
+ }),
51
+ };
52
+ export const asFlag = {
53
+ as: Flags.string({ description: 'Who writes: your name, as a claim names it. A write into a branch another has claimed is refused (409) unless it is theirs.' }),
54
+ };
55
+ export class ReplyCommand extends BaseCommand {
56
+ stateId(flags, positional) {
57
+ const id = positional || flags['state-id'] || findStateFile()?.id;
58
+ if (!id) {
59
+ this.error('No state here: no --state-id, no FACES_STATE_ID and no .faces/state in this directory or above. ' +
60
+ 'faces state:create --use makes one; faces state:use <id> uses one of yours.');
61
+ }
62
+ return id;
63
+ }
64
+ statePath(id, route) {
65
+ return `${CONVERSATIONS_PATH}/${seg(id)}${route}`;
66
+ }
67
+ async reply(client, method, p, opts = {}) {
68
+ let got;
69
+ try {
70
+ got = await client.stateReply(method, p, opts);
71
+ }
72
+ catch (err) {
73
+ if (err instanceof FacesAPIError)
74
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
75
+ throw err;
76
+ }
77
+ return this.show(got);
78
+ }
79
+ show(got) {
80
+ const { data } = got;
81
+ if (!got.ok)
82
+ process.exitCode = 1;
83
+ if (this.jsonEnabled())
84
+ return got.ok ? data : { ...data, error: { message: data.error, status: got.status } };
85
+ const text = typeof data.text === 'string' ? data.text : JSON.stringify(data);
86
+ if (got.ok)
87
+ this.log(text);
88
+ else
89
+ process.stderr.write(text + '\n');
90
+ return data;
91
+ }
92
+ }
93
+ export function compact(body) {
94
+ return Object.fromEntries(Object.entries(body).filter(([, v]) => v !== undefined));
95
+ }
96
+ export const formatFlags = {
97
+ problog: Flags.boolean({ description: 'The proof as runnable ProbLog.', default: false, exclusive: ['dot'] }),
98
+ dot: Flags.boolean({ description: 'The proof as Graphviz dot.', default: false, exclusive: ['problog'] }),
99
+ };
100
+ export function formatOf(flags, json) {
101
+ if (json)
102
+ return 'json';
103
+ if (flags.problog)
104
+ return 'problog';
105
+ if (flags.dot)
106
+ return 'dot';
107
+ return 'text';
108
+ }
109
+ export const faceFlag = {
110
+ face: Flags.string({ description: 'The face that does it: @alias (faces face:list --for "<the task>" ranks them).', required: true }),
111
+ };
112
+ export function faceRef(face) {
113
+ const f = face.trim();
114
+ return f.startsWith('@') || f.startsWith('(') ? f : '@' + f;
115
+ }
@@ -0,0 +1,8 @@
1
+ export declare const MEDIA_PATH = "/v1/media";
2
+ export interface Medium {
3
+ name?: string;
4
+ description?: string;
5
+ subcategories?: string[];
6
+ }
7
+ export declare function mediaOf(raw: unknown): Medium[];
8
+ export declare function mediaLines(media: Medium[]): string[];
package/dist/media.js ADDED
@@ -0,0 +1,12 @@
1
+ import { table } from './utils.js';
2
+ export const MEDIA_PATH = '/v1/media';
3
+ export function mediaOf(raw) {
4
+ const data = Array.isArray(raw) ? raw : (raw?.data ?? []);
5
+ return Array.isArray(data) ? data : [];
6
+ }
7
+ export function mediaLines(media) {
8
+ if (media.length === 0)
9
+ return ['No media.'];
10
+ const rows = media.map((m) => [String(m.name ?? ''), String(m.description ?? ''), (m.subcategories ?? []).join(', ')]);
11
+ return table(['MEDIUM', 'DESCRIPTION', 'COVERS'], rows);
12
+ }
@@ -0,0 +1,11 @@
1
+ export declare const MAESTROS: readonly ["maestro-1", "maestro-1-flash"];
2
+ export declare const DEFAULT_MAESTRO: "maestro-1";
3
+ export interface ModelName {
4
+ upstream?: string;
5
+ faces?: string;
6
+ maestro?: string;
7
+ downstream?: string;
8
+ }
9
+ export declare function parseModel(raw: string): ModelName;
10
+ export declare function asFace(face: string): string;
11
+ export declare function modelProblem(raw: string, needs: 'upstream' | 'both', example?: string): string | undefined;
package/dist/model.js ADDED
@@ -0,0 +1,53 @@
1
+ export const MAESTROS = ['maestro-1', 'maestro-1-flash'];
2
+ export const DEFAULT_MAESTRO = MAESTROS[0];
3
+ const MAESTRO_END = /:\s*(maestro-[^\s:/()@|&^~]*)\s*$/i;
4
+ export function parseModel(raw) {
5
+ const s = raw.trim();
6
+ const slash = s.indexOf('/');
7
+ const prefix = slash >= 0 ? s.slice(0, slash) : s;
8
+ const m = MAESTRO_END.exec(prefix);
9
+ if (!m || !/^[@(]/.test(prefix.trim()))
10
+ return { downstream: s || undefined };
11
+ const faces = prefix.slice(0, m.index).trim();
12
+ return {
13
+ upstream: `${faces}:${m[1]}`,
14
+ faces,
15
+ maestro: m[1],
16
+ downstream: slash >= 0 ? s.slice(slash + 1).trim() || undefined : undefined,
17
+ };
18
+ }
19
+ export function asFace(face) {
20
+ const f = face.trim();
21
+ return /^[@(]/.test(f) ? f : `@${f}`;
22
+ }
23
+ export function modelProblem(raw, needs, example = 'gpt-5.4') {
24
+ const s = raw.trim();
25
+ if (!s)
26
+ return 'Name the model: @<face>:maestro-1' + (needs === 'both' ? `/<model>, e.g. @alice:maestro-1/${example}` : ', e.g. @alice:maestro-1');
27
+ const p = parseModel(s);
28
+ if (!p.upstream) {
29
+ const at = s.indexOf('@');
30
+ if (at > 0 && !s.startsWith('(')) {
31
+ const face = s.slice(0, at);
32
+ const down = s.slice(at + 1);
33
+ return `face@model is gone: write ${asFace(face)}:${DEFAULT_MAESTRO}${needs === 'both' ? `/${down}` : ''}`;
34
+ }
35
+ if (/^[@(]/.test(s)) {
36
+ const faces = s.split('/')[0].trim();
37
+ const rest = s.includes('/') ? s.slice(s.indexOf('/') + 1) : needs === 'both' ? '<model>' : '';
38
+ return `Name the maestro after the face: ${faces}:${DEFAULT_MAESTRO}${rest ? `/${rest}` : ''}`;
39
+ }
40
+ if (/^[a-z0-9][a-z0-9~:-]*$/i.test(s) && !/^maestro-/i.test(s) && needs === 'upstream') {
41
+ return `Write the face as ${asFace(s.replace(':', '~'))}:${DEFAULT_MAESTRO}`;
42
+ }
43
+ if (needs === 'both' && /^[a-z0-9][a-z0-9-]*$/i.test(s)) {
44
+ return `Add a face: @<face>:${DEFAULT_MAESTRO}/${s}, or, if ${s} is a face, @${s}:${DEFAULT_MAESTRO}/<model>`;
45
+ }
46
+ return `Add a face: @<face>:${DEFAULT_MAESTRO}${needs === 'both' ? `/${s}` : ''}`;
47
+ }
48
+ if (needs === 'upstream' && p.downstream)
49
+ return `faces choices takes the upstream model alone, with no model after it: ${p.upstream}`;
50
+ if (needs === 'both' && !p.downstream)
51
+ return `Name the model that answers after the maestro: ${p.upstream}/<model>, e.g. ${p.upstream}/${example}`;
52
+ return undefined;
53
+ }