@faces-sh/cli 1.0.2 → 1.1.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 (57) hide show
  1. package/README.md +71 -51
  2. package/dist/choices.d.ts +23 -0
  3. package/dist/choices.js +48 -0
  4. package/dist/commands/auth/connect.js +2 -2
  5. package/dist/commands/catalog/doctor.js +9 -68
  6. package/dist/commands/causes.d.ts +2 -0
  7. package/dist/commands/causes.js +2 -2
  8. package/dist/commands/{fidelity/run.d.ts → choices.d.ts} +9 -8
  9. package/dist/commands/choices.js +86 -0
  10. package/dist/commands/conversation/add.d.ts +2 -0
  11. package/dist/commands/conversation/add.js +21 -10
  12. package/dist/commands/conversation/close.js +5 -5
  13. package/dist/commands/conversation/compact.js +9 -9
  14. package/dist/commands/conversation/create.d.ts +2 -0
  15. package/dist/commands/conversation/create.js +14 -12
  16. package/dist/commands/conversation/get.js +4 -4
  17. package/dist/commands/conversation/items.js +19 -8
  18. package/dist/commands/decide.d.ts +3 -0
  19. package/dist/commands/decide.js +20 -3
  20. package/dist/commands/face/get.js +1 -1
  21. package/dist/commands/fidelity/pick.js +2 -2
  22. package/dist/commands/models/list.js +7 -3
  23. package/dist/commands/session/close.js +1 -1
  24. package/dist/commands/session/compact.js +2 -2
  25. package/dist/commands/session/create.js +2 -2
  26. package/dist/commands/session/get.js +1 -1
  27. package/dist/commands/state/add.d.ts +3 -0
  28. package/dist/commands/state/add.js +3 -0
  29. package/dist/commands/state/close.d.ts +3 -0
  30. package/dist/commands/state/close.js +3 -0
  31. package/dist/commands/state/compact.d.ts +3 -0
  32. package/dist/commands/state/compact.js +3 -0
  33. package/dist/commands/state/create.d.ts +3 -0
  34. package/dist/commands/state/create.js +3 -0
  35. package/dist/commands/state/get.d.ts +3 -0
  36. package/dist/commands/state/get.js +3 -0
  37. package/dist/commands/state/items.d.ts +3 -0
  38. package/dist/commands/state/items.js +3 -0
  39. package/dist/commands/style/make.js +2 -6
  40. package/dist/conversation.d.ts +27 -2
  41. package/dist/conversation.js +100 -16
  42. package/dist/fidelity.js +3 -3
  43. package/oclif.manifest.json +1100 -1493
  44. package/package.json +9 -9
  45. package/dist/commands/chat/chat.d.ts +0 -47
  46. package/dist/commands/chat/chat.js +0 -376
  47. package/dist/commands/chat/messages.d.ts +0 -30
  48. package/dist/commands/chat/messages.js +0 -148
  49. package/dist/commands/chat/responses.d.ts +0 -31
  50. package/dist/commands/chat/responses.js +0 -159
  51. package/dist/commands/chat/thread.d.ts +0 -50
  52. package/dist/commands/chat/thread.js +0 -472
  53. package/dist/commands/fidelity/run.js +0 -99
  54. package/dist/commands/fidelity/start.d.ts +0 -17
  55. package/dist/commands/fidelity/start.js +0 -56
  56. package/dist/commands/fidelity/turn.d.ts +0 -17
  57. package/dist/commands/fidelity/turn.js +0 -48
@@ -1,19 +1,27 @@
1
1
  import { Flags } from '@oclif/core';
2
- export const CONVERSATIONS_PATH = '/v1/conversations';
2
+ export const CONVERSATIONS_PATH = '/v1/states';
3
3
  export const MAX_CONVERSATION_ITEMS = 20;
4
4
  const PREMISE_KEY = /^[A-Za-z0-9_-]{1,64}$/;
5
- export const CONVERSATION_FLAG_DESCRIPTION = 'Add this turn to a conversation, by id (from faces conversation:create). Send only the new message: ' +
6
- 'the conversation so far is read before it. A conversation opened with one face takes only that face.';
5
+ export const PREMISE_STATUSES = ['stated', 'verified', 'assumed', 'unresolved', 'invalidated'];
6
+ export const MAX_DEPENDS_ON = 200;
7
+ export const CONVERSATION_FLAG_DESCRIPTION = 'Add this turn to a state, by id (from faces state:create). Send only what is new: ' +
8
+ 'the state so far is read before it. A state opened with one face takes only that face.';
7
9
  export const PREMISE_FLAG_DESCRIPTION = 'A premise, as key=value (repeatable): a named fact the face\'s answers depend on, kept on the ' +
8
- 'conversation. The key is 1 to 64 letters, digits, _ or -. The value is read as JSON when it is JSON ' +
10
+ 'state. The key is 1 to 64 letters, digits, _ or -. The value is read as JSON when it is JSON ' +
9
11
  '(50000, true, null, ["a","b"], {"max":3}) and as text otherwise, so plan=annual is the text "annual". ' +
10
12
  'Quote it to keep a number as text: --premise \'code="007"\'. A newer value of a key replaces it from ' +
11
13
  'then on. A key used for the first time needs --premise-description.';
12
14
  export const PREMISE_DESCRIPTION_FLAG_DESCRIPTION = 'What a --premise means, in plain words, as key="text" (repeatable, one per key), e.g. ' +
13
15
  '--premise-description budget_usd="the most we can spend this year". Required the first time a key is ' +
14
- 'used in a conversation, and kept after that.';
16
+ 'used in a state, and kept after that.';
17
+ export const PREMISE_STATUS_FLAG_DESCRIPTION = `A --premise's status, as key=status (repeatable, one per key): ${PREMISE_STATUSES.join(', ')}. ` +
18
+ 'Left out, a new premise is stated. An invalidated premise invalidates everything that depends on it; ' +
19
+ '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; ` +
22
+ 'left out, a newer value keeps what the key rested on before.';
15
23
  export const CAUSES_VISIBLE_TURN_FLAG_DESCRIPTION = 'Whether the face reads the other faces\' causes on this turn, in a conversation with several faces. ' +
16
- 'Leave it out to follow the conversation (see faces conversation:create --no-causes-visible).';
24
+ 'Leave it out to follow the state (see faces state:create --no-causes-visible).';
17
25
  export function conversationTurnFlags(opts = {}) {
18
26
  const d = (text) => (opts.suffix ? `${text} ${opts.suffix}` : text);
19
27
  const exclusive = opts.exclusive;
@@ -21,13 +29,15 @@ export function conversationTurnFlags(opts = {}) {
21
29
  conversation: Flags.string({ description: d(CONVERSATION_FLAG_DESCRIPTION), exclusive }),
22
30
  premise: Flags.string({ description: d(`${PREMISE_FLAG_DESCRIPTION} Needs --conversation.`), multiple: true, exclusive }),
23
31
  'premise-description': Flags.string({ description: d(PREMISE_DESCRIPTION_FLAG_DESCRIPTION), multiple: true, dependsOn: ['premise'], exclusive }),
32
+ 'premise-status': Flags.string({ description: d(PREMISE_STATUS_FLAG_DESCRIPTION), multiple: true, dependsOn: ['premise'], exclusive }),
33
+ 'premise-depends-on': Flags.string({ description: d(PREMISE_DEPENDS_ON_FLAG_DESCRIPTION), multiple: true, dependsOn: ['premise'], exclusive }),
24
34
  'causes-visible': Flags.boolean({ description: d(`${CAUSES_VISIBLE_TURN_FLAG_DESCRIPTION} Needs --conversation.`), allowNo: true, exclusive }),
25
35
  };
26
36
  }
27
37
  export function conversationLines(c) {
28
38
  const pairs = [
29
- ['conversation', c.id],
30
- ['face', c.model ?? (c.object === 'conversation' ? 'any of your faces' : undefined)],
39
+ ['state', c.id],
40
+ ['face', c.model ?? (c.object === 'conversation' || c.object === 'state' ? 'any of your faces' : undefined)],
31
41
  ['status', c.status],
32
42
  ['turns', c.turns],
33
43
  ['items', c.items],
@@ -40,12 +50,15 @@ export function conversationLines(c) {
40
50
  }
41
51
  export function conversationHint(err) {
42
52
  if (err.statusCode === 404) {
43
- return 'A conversation expires 30 days after it was last used, and a closed one cannot be used. ' +
44
- 'Start another with: faces conversation:create';
53
+ return 'A state expires 30 days after it was last used, and a closed one cannot be used. ' +
54
+ 'Start another with: faces state:create';
45
55
  }
46
56
  const fresh = err.statusCode === 422 ? /premise '([A-Za-z0-9_-]{1,64})' is new/.exec(err.message) : null;
47
57
  if (fresh)
48
58
  return `Say what it means: --premise-description ${fresh[1]}="what it means, in plain words"`;
59
+ 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.';
61
+ }
49
62
  return undefined;
50
63
  }
51
64
  export function premiseValue(raw) {
@@ -71,7 +84,7 @@ function checkKey(key, flag) {
71
84
  if (!PREMISE_KEY.test(key))
72
85
  throw new Error(`${flag}: a premise key is 1 to 64 letters, digits, _ or - (got '${key}').`);
73
86
  }
74
- export function parsePremises(premises = [], descriptions = []) {
87
+ export function parsePremises(premises = [], descriptions = [], statuses = [], dependsOn = []) {
75
88
  const out = [];
76
89
  const seen = new Map();
77
90
  for (const raw of premises) {
@@ -97,6 +110,43 @@ export function parsePremises(premises = [], descriptions = []) {
97
110
  described.add(key);
98
111
  p.description = text.trim();
99
112
  }
113
+ const statused = new Set();
114
+ for (const raw of statuses) {
115
+ const [key, text] = splitPair(raw, '--premise-status', 'key=status');
116
+ checkKey(key, '--premise-status');
117
+ const p = seen.get(key);
118
+ if (!p)
119
+ throw new Error(`--premise-status names '${key}', which no --premise sets. Add --premise ${key}=<value>.`);
120
+ if (statused.has(key))
121
+ throw new Error(`--premise-status sets '${key}' twice. Give one status per key.`);
122
+ const status = text.trim().toLowerCase();
123
+ if (!PREMISE_STATUSES.includes(status)) {
124
+ throw new Error(`--premise-status for '${key}' is one of ${PREMISE_STATUSES.join(', ')} (got '${text}').`);
125
+ }
126
+ statused.add(key);
127
+ p.status = status;
128
+ }
129
+ const linked = new Set();
130
+ for (const raw of dependsOn) {
131
+ const [key, text] = splitPair(raw, '--premise-depends-on', 'key=a,b');
132
+ checkKey(key, '--premise-depends-on');
133
+ const p = seen.get(key);
134
+ if (!p)
135
+ throw new Error(`--premise-depends-on names '${key}', which no --premise sets. Add --premise ${key}=<value>.`);
136
+ if (linked.has(key))
137
+ 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))
140
+ throw new Error(`--premise-depends-on: premise '${key}' cannot depend on itself.`);
141
+ linked.add(key);
142
+ p.depends_on = deps;
143
+ }
144
+ return out;
145
+ }
146
+ export function parseDependsOn(raw, flag = '--depends-on') {
147
+ const out = [...new Set(raw.split(',').map((x) => x.trim()).filter(Boolean))];
148
+ if (out.length > MAX_DEPENDS_ON)
149
+ throw new Error(`${flag} names at most ${MAX_DEPENDS_ON} premises and decisions (got ${out.length}).`);
100
150
  return out;
101
151
  }
102
152
  export function conversationFields(flags) {
@@ -104,10 +154,10 @@ export function conversationFields(flags) {
104
154
  if (flags.conversation && flags.session && flags.conversation !== flags.session) {
105
155
  throw new Error('--session is the old name for --conversation: pass one of them, not two different ids.');
106
156
  }
107
- const premises = parsePremises(flags.premise, flags['premise-description']);
157
+ const premises = parsePremises(flags.premise, flags['premise-description'], flags['premise-status'], flags['premise-depends-on']);
108
158
  const inConversation = Boolean(flags.conversation || flags.session);
109
159
  if (!inConversation && (premises.length > 0 || flags['causes-visible'] !== undefined)) {
110
- throw new Error('Premises and --causes-visible belong to a conversation: add --conversation <id> (from faces conversation:create).');
160
+ throw new Error('Premises and --causes-visible belong to a state: add --conversation <id> (from faces state:create).');
111
161
  }
112
162
  if (flags.conversation)
113
163
  out.conversation = flags.conversation;
@@ -123,13 +173,37 @@ export function clientItems(messages = [], premises = []) {
123
173
  export function shownValue(v) {
124
174
  return v === undefined ? '-' : JSON.stringify(v);
125
175
  }
176
+ function statusNote(p) {
177
+ if (!p)
178
+ return '';
179
+ const parts = [];
180
+ if (p.status && p.status !== 'stated')
181
+ parts.push(p.status);
182
+ if (p.asserted_status)
183
+ parts.push(`set ${p.asserted_status}`);
184
+ if (p.because)
185
+ parts.push(`because ${p.because}`);
186
+ if (p.depends_on && p.depends_on.length > 0)
187
+ parts.push(`rests on ${p.depends_on.join(', ')}`);
188
+ return parts.length > 0 ? ` [${parts.join('; ')}]` : '';
189
+ }
190
+ export function statusChangeLines(changes) {
191
+ if (!changes || changes.length === 0)
192
+ return [];
193
+ const lines = [`${changes.length === 1 ? '1 status changed' : `${changes.length} statuses changed`}:`];
194
+ for (const c of changes) {
195
+ const what = c.kind === 'decision' ? `decision ${c.id ?? '?'}` : `premise ${c.key ?? '?'}`;
196
+ lines.push(` ${what}: ${c.from ?? '-'} -> ${c.to ?? '-'}${c.because ? ` (because ${c.because})` : ''}`);
197
+ }
198
+ return lines;
199
+ }
126
200
  export function premiseLines(premises) {
127
201
  const entries = Object.entries(premises ?? {});
128
202
  if (entries.length === 0)
129
203
  return ['premises: none'];
130
204
  const lines = ['premises:'];
131
205
  for (const [key, p] of entries) {
132
- lines.push(` ${key} = ${shownValue(p?.value)}${p?.description ? ` (${p.description})` : ''}`);
206
+ lines.push(` ${key} = ${shownValue(p?.value)}${statusNote(p)}${p?.description ? ` (${p.description})` : ''}`);
133
207
  }
134
208
  return lines;
135
209
  }
@@ -157,7 +231,7 @@ function parsed(raw) {
157
231
  }
158
232
  }
159
233
  function questionText(q) {
160
- return String(q.instructions ?? q.question ?? q.id ?? '?');
234
+ return String(q.instructions ?? q.question ?? q.name ?? q.id ?? '?');
161
235
  }
162
236
  function choiceOf(out) {
163
237
  if (out.choice !== undefined && out.choice !== null)
@@ -182,6 +256,16 @@ export function itemLines(items) {
182
256
  calls.set(String(it.call_id ?? ''), it);
183
257
  continue;
184
258
  }
259
+ if (it.type === 'decision') {
260
+ const answer = (it.answer && typeof it.answer === 'object' ? it.answer : {});
261
+ const question = (it.question && typeof it.question === 'object' ? it.question : {});
262
+ const result = answer.result === undefined || answer.result === null ? '-' : String(answer.result);
263
+ const status = it.status === 'invalidated' ? ` [invalidated${it.because ? `, because ${String(it.because)}` : ''}]` : '';
264
+ lines.push(`${head}${String(it.face ?? 'face')}${it.model ? ` (${it.model})` : ''} decided: ${questionText(question)} -> ${result}${status}`);
265
+ if (typeof it.cause === 'string' && it.cause)
266
+ lines.push(`${pad}cause: ${it.cause}`);
267
+ continue;
268
+ }
185
269
  if (it.type === 'function_call_output') {
186
270
  const call = calls.get(String(it.call_id ?? ''));
187
271
  const out = parsed(it.output);
@@ -228,7 +312,7 @@ export function staleDecisionLines(stale) {
228
312
  for (const d of stale) {
229
313
  const q = d.question ? questionText(d.question) : '?';
230
314
  const choice = d.choice === undefined || d.choice === null ? '-' : String(d.choice);
231
- lines.push(` ${d.face ?? 'face'}: ${q} -> ${choice}${d.call_id ? ` [${d.call_id}]` : ''}`);
315
+ lines.push(` ${d.face ?? 'face'}: ${q} -> ${choice}${d.call_id ? ` [${d.call_id}]` : ''}${d.via ? `, through ${d.via}` : ''}`);
232
316
  for (const [key, c] of Object.entries(d.changed ?? {})) {
233
317
  lines.push(` ${key}: was ${shownValue(c?.was)}, now ${shownValue(c?.now)}`);
234
318
  }
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
- : `Send turn ${run.next.turn}'s message: faces fidelity:turn ${id} -m "..."`;
26
+ : `Turn ${run.next.turn} waits for a message, and new turns are retired with chat.`;
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}. Start another with faces fidelity:start ${on.alias ?? '<alias>'}.`;
76
+ return `Read the score: faces fidelity:get ${id}.`;
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 'Run ids are printed by faces fidelity:start.';
84
+ return 'Check the run id.';
85
85
  default:
86
86
  return undefined;
87
87
  }