@faces-sh/cli 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +64 -30
  2. package/dist/billing.js +11 -8
  3. package/dist/chat-command.d.ts +31 -0
  4. package/dist/chat-command.js +110 -0
  5. package/dist/chat.d.ts +47 -0
  6. package/dist/chat.js +157 -0
  7. package/dist/choices.d.ts +2 -5
  8. package/dist/choices.js +9 -8
  9. package/dist/commands/billing/llm-costs.js +9 -5
  10. package/dist/commands/billing/subscription/index.js +1 -1
  11. package/dist/commands/catalog/doctor.js +2 -2
  12. package/dist/commands/chat/chat.d.ts +31 -0
  13. package/dist/commands/chat/chat.js +31 -0
  14. package/dist/commands/chat/messages.d.ts +30 -0
  15. package/dist/commands/chat/messages.js +21 -0
  16. package/dist/commands/chat/responses.d.ts +30 -0
  17. package/dist/commands/chat/responses.js +22 -0
  18. package/dist/commands/{causes.d.ts → chat/thread.d.ts} +17 -12
  19. package/dist/commands/chat/thread.js +238 -0
  20. package/dist/commands/choices.d.ts +1 -2
  21. package/dist/commands/choices.js +20 -15
  22. package/dist/commands/conversation/compact.js +13 -16
  23. package/dist/commands/conversation/create.js +10 -9
  24. package/dist/commands/decide.d.ts +1 -4
  25. package/dist/commands/decide.js +53 -81
  26. package/dist/commands/face/get.js +1 -1
  27. package/dist/commands/fidelity/pick.js +2 -2
  28. package/dist/commands/fidelity/run.d.ts +20 -0
  29. package/dist/commands/fidelity/run.js +99 -0
  30. package/dist/commands/fidelity/start.d.ts +17 -0
  31. package/dist/commands/fidelity/start.js +56 -0
  32. package/dist/commands/fidelity/turn.d.ts +17 -0
  33. package/dist/commands/fidelity/turn.js +48 -0
  34. package/dist/commands/group/add.js +1 -1
  35. package/dist/commands/media/list.d.ts +12 -0
  36. package/dist/commands/media/list.js +35 -0
  37. package/dist/commands/models/list.js +13 -6
  38. package/dist/commands/session/compact.js +5 -8
  39. package/dist/commands/session/create.js +9 -8
  40. package/dist/commands/style/make.js +1 -1
  41. package/dist/commands/style/upload.js +1 -1
  42. package/dist/decisions.d.ts +0 -5
  43. package/dist/decisions.js +0 -18
  44. package/dist/fidelity.js +3 -3
  45. package/dist/media.d.ts +8 -0
  46. package/dist/media.js +12 -0
  47. package/dist/model.d.ts +11 -0
  48. package/dist/model.js +53 -0
  49. package/dist/routing.d.ts +1 -4
  50. package/dist/routing.js +4 -40
  51. package/dist/utils.d.ts +1 -25
  52. package/dist/utils.js +10 -108
  53. package/oclif.manifest.json +1616 -818
  54. package/package.json +6 -3
  55. package/dist/commands/causes.js +0 -146
package/dist/utils.js CHANGED
@@ -220,23 +220,6 @@ export function resolveProfileAddendum(text, file) {
220
220
  }
221
221
  return value;
222
222
  }
223
- export function resolveCause(text, file) {
224
- let value = text;
225
- if (file !== undefined) {
226
- if (!fs.existsSync(file))
227
- throw new Error(`File not found: ${file}`);
228
- value = fs.readFileSync(file, 'utf8');
229
- }
230
- return value !== undefined && value.trim() ? value : undefined;
231
- }
232
- export const CAUSE_FLAG_DESCRIPTION = 'Supply this turn\'s cause yourself, at most 30,000 tokens. The model answers on it in place of the ' +
233
- 'face\'s own, and no cause is charged. Needs a model named (alias@model). It comes back where a cause ' +
234
- 'normally does.';
235
- export const CAUSE_FILE_FLAG_DESCRIPTION = 'Read --cause from a file.';
236
- export function causeNeedsModel(face) {
237
- return (`--cause needs a model to answer on it: ${face}@<model>. A face named alone returns only its own ` +
238
- 'cause, so there is nothing to supply.');
239
- }
240
223
  export function flattenAttributes(facts) {
241
224
  const flat = {};
242
225
  for (const [k, v] of Object.entries(facts)) {
@@ -269,62 +252,6 @@ export function extractStreamDelta(parsed) {
269
252
  const choices = parsed.choices;
270
253
  return String(choices?.[0]?.delta?.content ?? '');
271
254
  }
272
- export function extractStreamReasoning(parsed) {
273
- if (parsed.type === 'content_block_delta') {
274
- if (parsed.index !== 0)
275
- return '';
276
- return String(parsed.delta?.thinking ?? '');
277
- }
278
- if (parsed.type === 'response.reasoning_summary_text.delta') {
279
- const item = parsed.item_id;
280
- if (typeof item === 'string' && !item.startsWith('rs_faces_'))
281
- return '';
282
- return String(parsed.delta ?? '');
283
- }
284
- const choices = parsed.choices;
285
- return String(choices?.[0]?.delta?.cause ?? '');
286
- }
287
- export const FACES_THINKING_SIGNATURE = 'faces-reasoning';
288
- export const FACES_REASONING_ITEM_PREFIX = 'rs_faces_';
289
- export function extractCause(body, endpoint) {
290
- if (endpoint === '/v1/messages') {
291
- const block = body.content?.find((b) => b.type === 'thinking' && b.signature === FACES_THINKING_SIGNATURE);
292
- return { text: block ? String(block.thinking ?? '') : '' };
293
- }
294
- if (endpoint === '/v1/responses') {
295
- const item = body.output?.find((o) => o.type === 'reasoning' && String(o.id ?? '').startsWith(FACES_REASONING_ITEM_PREFIX));
296
- if (!item)
297
- return { text: '' };
298
- const text = (item.summary ?? []).map((s) => String(s.text ?? '')).join('\n');
299
- return { text, id: String(item.id) };
300
- }
301
- const choices = body.choices;
302
- return { text: String(choices?.[0]?.message?.cause ?? '') };
303
- }
304
- export function extractReasoning(body, endpoint) {
305
- return extractCause(body, endpoint).text;
306
- }
307
- export const REASONING_FLAG_DESCRIPTION = 'Also show the face\'s cause: the principal why behind its response in this context. Printed to ' +
308
- 'stderr ahead of the reply, so the reply alone still goes to stdout.';
309
- export function reasoningHeading(face) {
310
- return `${face.replace(/@.*$/, '')}'s cause:`;
311
- }
312
- export function reasoningOnlyNote(face, llmFlag = true) {
313
- const bare = face.replace(/@.*$/, '');
314
- return `That is ${bare}'s cause alone: a face named without a model gives no reply. ` +
315
- `For one, name the model: ${bare}@<model>${llmFlag ? ', or add --llm <model>' : ''}.`;
316
- }
317
- export function writeReply(model, reasoning, text, showReasoning, note) {
318
- if (!text && reasoning) {
319
- process.stdout.write(`${reasoning}\n`);
320
- if (note)
321
- process.stderr.write(`\n${note}\n`);
322
- return;
323
- }
324
- if (showReasoning && reasoning)
325
- process.stderr.write(`${reasoningHeading(model)}\n${reasoning}\n\n`);
326
- process.stdout.write(`${text}\n`);
327
- }
328
255
  export const STREAM_FLAG_DESCRIPTION = 'Stream the reply as it is written (the default). --no-stream waits for the whole reply instead. ' +
329
256
  'Either way a face has up to 300s to answer; past that the request is stopped and can be asked again. ' +
330
257
  '--json is never streamed.';
@@ -386,14 +313,11 @@ export function compileHint(face, recompile, verb = 'answer') {
386
313
  `(list them with: faces face:sources ${face}). Asking again as it is will not help.`
387
314
  : `Give it a first source: faces compile:upload ${face} --file <file>. A saved composite needs one on each face in its formula.`;
388
315
  }
389
- export function faceRefusalHint(err, model, style) {
390
- const face = model.replace(/@[^@]*$/, '');
391
- if (style && (err.errorCode === 'style_medium_unavailable' || /has no (styles? yet|.* style)/i.test(err.message))) {
392
- return `Build one: faces style:make ${face} --all\nOr leave out --style to answer without a built style.`;
393
- }
394
- if (err.statusCode === 409) {
316
+ export function faceRefusalHint(err, model) {
317
+ const slash = model.indexOf('/');
318
+ const face = (slash >= 0 ? model.slice(0, slash) : model).replace(/:\s*maestro-[^:]*$/i, '').replace(/^@/, '').replace('~', ':');
319
+ if (err.statusCode === 409)
395
320
  return compileHint(face, !/nothing compiled/i.test(err.message));
396
- }
397
321
  if (err.statusCode === 404 && isMeAlias(face))
398
322
  return ME_MISSING;
399
323
  if (err.statusCode === 504)
@@ -409,51 +333,29 @@ export const MIN_MAX_OUTPUT_TOKENS = 16;
409
333
  export function isMaxTokensRenameError(message) {
410
334
  return /max_completion_tokens/.test(message) && /max_tokens/.test(message);
411
335
  }
412
- const MEDIUM_LIST = 'What sort of writing this is, spelled exactly: email, text message, social post, essay, ' +
413
- 'academic paper, blog post, legal document, thread reply, conversation, lecture, other. ' +
414
- 'Reach for lecture for sustained speech nobody interrupts (a talk, a sermon, a keynote), and ' +
415
- 'other for writing that is none of the named forms, read as prose with no form-specific ' +
416
- 'conventions assumed. Those descriptions are not accepted inputs: send the value itself.';
336
+ const MEDIUM_LIST = 'What sort of writing this is, spelled exactly as faces media:list names it: email, essay, speech, ' +
337
+ 'journal entry, script and the rest (25 in all). A subcategory such as keynote is not a medium: send ' +
338
+ 'the medium it belongs to (speech). other is for writing that is none of the named forms, read as ' +
339
+ 'prose with no form-specific conventions assumed.';
417
340
  export const DOCUMENT_VS_THREAD = 'A document is the face\'s own writing (an essay, letter, paper, book or poem), and every word ' +
418
341
  'in it is read as theirs. An interview, transcript or dialogue is a thread: upload it with ' +
419
342
  'faces compile:upload ALIAS --file FILE --kind thread --face-speaker NAME, so only the face\'s ' +
420
343
  'turns are used.';
421
- export const STYLE_FLAG_DESCRIPTION = 'Apply the style the face has built for this medium, one of: email, text message, social post, essay, ' +
422
- 'academic paper, blog post, legal document, thread reply, conversation, lecture, other. Leave it out and ' +
423
- 'no built style is applied. A face with no style in that medium is refused, naming the ones it has ' +
424
- '(see them with faces face:get). Needs a single face and a model. Adds roughly 2,000 to 3,500 input ' +
425
- 'tokens per request. Sets --medium too. Chat commands only: causes and decide do not use a style.';
426
- export const MEDIUM_FLAG_DESCRIPTION = 'What the reply is, so it is shaped for it: email, text message, social post, essay, academic paper, ' +
427
- 'blog post, legal document, thread reply, conversation, lecture, other. Needs no built style. Leave it ' +
428
- 'out and the medium is inferred from your message. With --style, leave it out or give the same medium.';
429
344
  export const SESSION_FLAG_DESCRIPTION = 'The old name for --conversation, still accepted: add this turn to a session (a conversation), by id ' +
430
345
  '(from faces session:create or conversation:create). The session must be with this face.';
431
346
  export const COMPACTION_FLAG_DESCRIPTION = 'Read a compaction, by id (from faces conversation:compact or session:compact), alongside the messages ' +
432
347
  'sent. It must be of this face.';
433
- export function chatExtras(flags) {
434
- const out = {};
435
- if (flags.style)
436
- out.style = flags.style;
437
- if (flags.medium)
438
- out.medium = flags.medium;
439
- if (flags.session)
440
- out.session = flags.session;
441
- if (flags.compaction)
442
- out.compaction = flags.compaction;
443
- return out;
444
- }
445
348
  export const MEDIUM_EDIT_DESCRIPTION = () => MEDIUM_LIST + ' Omit it to leave the medium as it is.';
446
349
  export const MEDIUM_REQUIRED_DESCRIPTION = MEDIUM_LIST +
447
350
  ' ' + DOCUMENT_VS_THREAD +
448
351
  ' A document cannot be saved without saying what it is, so this is required rather than ' +
449
352
  'optional. Here the spelling is held to exactly: case and surrounding spaces are forgiven and ' +
450
- 'nothing else is, so an unknown word is refused naming all eleven rather than being folded into ' +
353
+ 'nothing else is, so an unknown word is refused naming every medium rather than being folded into ' +
451
354
  'a near match. Do not guess one: a wrong medium is not flagged afterwards. If none of the ' +
452
355
  'named forms fit, that is what other is for. If one of them ' +
453
356
  'does fit and you simply have not been told which, ask.';
454
357
  export const MEDIUM_MISSING_MESSAGE = 'Say what this writing is with --medium: a document cannot be saved without one.\n' +
455
- 'One of: email, text message, social post, essay, academic paper, blog post, legal document, ' +
456
- 'thread reply, conversation, lecture, other.\n' +
358
+ 'One of the media faces media:list names (email, essay, speech, journal entry, script and the rest).\n' +
457
359
  '`other` is for writing that is none of those: it compiles, and is read as prose with no ' +
458
360
  'form-specific conventions assumed. It is the honest answer when nothing fits, and the wrong ' +
459
361
  'answer for a letter or a memo, which are forms with rules of their own.\n' +