@faces-sh/cli 1.2.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 (53) hide show
  1. package/README.md +51 -33
  2. package/dist/chat-command.d.ts +2 -0
  3. package/dist/chat.d.ts +2 -0
  4. package/dist/choices.d.ts +9 -0
  5. package/dist/choices.js +17 -1
  6. package/dist/client.d.ts +8 -0
  7. package/dist/client.js +37 -0
  8. package/dist/commands/chat/chat.d.ts +2 -0
  9. package/dist/commands/chat/messages.d.ts +2 -0
  10. package/dist/commands/chat/responses.d.ts +2 -0
  11. package/dist/commands/chat/thread.d.ts +2 -0
  12. package/dist/commands/choices.d.ts +3 -0
  13. package/dist/commands/choices.js +36 -0
  14. package/dist/commands/conversation/add.d.ts +2 -0
  15. package/dist/commands/conversation/add.js +5 -2
  16. package/dist/commands/conversation/create.d.ts +2 -0
  17. package/dist/commands/conversation/create.js +4 -2
  18. package/dist/commands/decide.d.ts +31 -0
  19. package/dist/commands/decide.js +84 -4
  20. package/dist/commands/face/list.d.ts +2 -0
  21. package/dist/commands/face/list.js +23 -1
  22. package/dist/commands/premise/add.d.ts +30 -0
  23. package/dist/commands/premise/add.js +86 -0
  24. package/dist/commands/premise/choices.d.ts +21 -0
  25. package/dist/commands/premise/choices.js +68 -0
  26. package/dist/commands/premise/claim.d.ts +20 -0
  27. package/dist/commands/premise/claim.js +38 -0
  28. package/dist/commands/premise/decide.d.ts +18 -0
  29. package/dist/commands/premise/decide.js +36 -0
  30. package/dist/commands/premise/delete.d.ts +17 -0
  31. package/dist/commands/premise/delete.js +17 -0
  32. package/dist/commands/premise/edit.d.ts +28 -0
  33. package/dist/commands/premise/edit.js +51 -0
  34. package/dist/commands/premise/get.d.ts +22 -0
  35. package/dist/commands/premise/get.js +37 -0
  36. package/dist/commands/premise/refine.d.ts +20 -0
  37. package/dist/commands/premise/refine.js +80 -0
  38. package/dist/commands/state/create.d.ts +13 -2
  39. package/dist/commands/state/create.js +55 -2
  40. package/dist/commands/state/get.d.ts +19 -2
  41. package/dist/commands/state/get.js +30 -2
  42. package/dist/commands/state/use.d.ts +16 -0
  43. package/dist/commands/state/use.js +25 -0
  44. package/dist/conversation.d.ts +30 -3
  45. package/dist/conversation.js +202 -18
  46. package/dist/foreman.d.ts +47 -0
  47. package/dist/foreman.js +115 -0
  48. package/dist/refine.d.ts +106 -0
  49. package/dist/refine.js +601 -0
  50. package/dist/synopsis.d.ts +49 -0
  51. package/dist/synopsis.js +43 -0
  52. package/oclif.manifest.json +1415 -109
  53. package/package.json +5 -2
@@ -5,6 +5,22 @@ import { conversationFields, conversationTurnFlags, MAX_DEPENDS_ON, parseDepends
5
5
  import { DECISION_MODELS, decisionModels, DECISION_FORMATS, fromOpenAIAnswers, toOpenAIDecision, questionsProblem, MAX_WARM_UP_WAIT_S, QUESTION_TYPES, decisionLines, heldDecisionError, readStateFlags, readQuestionFlags, warmUpWait, } from '../decisions.js';
6
6
  import { compileHint, sayWarmUp, SESSION_FLAG_DESCRIPTION, COMPACTION_FLAG_DESCRIPTION } from '../utils.js';
7
7
  import { modelProblem, parseModel } from '../model.js';
8
+ export function weighLines(data) {
9
+ const w = data.weigh ?? {};
10
+ if (!w.written)
11
+ return [`Nothing was written: ${w.reason ?? 'the decision gave no weights'}.`];
12
+ const lines = [`${w.premise ?? '?'}: its ${w.kind ?? '?'} edges, weighed by ${w.decision ?? 'the decision'}`];
13
+ for (const e of w.edges ?? []) {
14
+ const p = typeof e.p === 'number' ? e.p : 0;
15
+ const pruned = (w.pruned ?? []).includes(e.id ?? '') ? ' pruned' : '';
16
+ lines.push(` ${String(Math.round(p * 100) / 100).padEnd(5)} ${e.id ?? '?'}${pruned}`);
17
+ }
18
+ if ((w.pruned ?? []).length > 0) {
19
+ lines.push('', `Pruned (set invalidated): the alternatives outside ${w.cutoff ?? 0.85} of the probability.`);
20
+ }
21
+ lines.push(`side node: ${w.side_node ?? '-'}`);
22
+ return lines;
23
+ }
8
24
  const OPENAI_FORMAT_ONLY = ['gpt-6-luna'];
9
25
  export default class Decide extends BaseCommand {
10
26
  static description = 'Ask what a face would decide. Describe a situation, ask typed questions about it, and get back numbers, ' +
@@ -24,6 +40,7 @@ export default class Decide extends BaseCommand {
24
40
  '--level yields --level hedges --level firm',
25
41
  '<%= config.bin %> <%= command.id %> "(@alice | @bob):maestro-1/jev-latest" --state-file situation.json --questions-file questions.json --json',
26
42
  '<%= config.bin %> <%= command.id %> @alice:maestro-1/gpt-6-luna --state-file situation.txt --questions-file questions.json',
43
+ '<%= config.bin %> <%= command.id %> @alice:maestro-1/jev-latest --conversation fs_STATE_ID --weigh "handle bad input"',
27
44
  ];
28
45
  static flags = {
29
46
  ...BaseCommand.baseFlags,
@@ -76,10 +93,29 @@ export default class Decide extends BaseCommand {
76
93
  }),
77
94
  ...conversationTurnFlags(),
78
95
  'depends-on': Flags.string({
79
- description: 'In a state (--conversation), what this decision rests on, comma separated: premise keys and decision ids ' +
80
- `already in the state or set with --premise, at most ${MAX_DEPENDS_ON}. The decision is shown those, and is ` +
96
+ description: 'In a state (--conversation), what this decision rests on, comma separated: premise keys, decision ids and ' +
97
+ 'option ids (opt_..., or cho_... for all of a choices list, from faces choices --state-id) ' +
98
+ `already in the state or set with --premise, at most ${MAX_DEPENDS_ON} (a key that holds a comma goes in ` +
99
+ 'double quotes: \'"x, y",dec_1\'). The decision is shown those, and is ' +
81
100
  'invalidated when one of them is. Left out, it rests on every premise in force.',
82
101
  }),
102
+ weigh: Flags.string({
103
+ description: 'In a state (--conversation): weigh the edges of this premise. The face decides between the premises it rests ' +
104
+ 'on (one kind at a time, --weigh-kind), and each probability is written onto its edge with the decision that ' +
105
+ 'set it. For or edges, the alternatives outside --cutoff are set invalidated, with the reason. No --question: ' +
106
+ 'the question is the premise and its children. Sent in OpenAI\'s format.',
107
+ exclusive: ['question', 'questions-file', 'depends-on'],
108
+ }),
109
+ 'weigh-kind': Flags.string({
110
+ description: 'With --weigh, when the premise rests on both kinds: which edges to weigh, or or and.',
111
+ options: ['or', 'and'],
112
+ dependsOn: ['weigh'],
113
+ }),
114
+ cutoff: Flags.string({
115
+ description: 'With --weigh: the probability mass to keep, above 0 and at most 1 (default 0.85). The likeliest or ' +
116
+ 'alternatives are kept until they reach it; the rest are pruned. and children are never pruned.',
117
+ dependsOn: ['weigh'],
118
+ }),
83
119
  session: Flags.string({ description: SESSION_FLAG_DESCRIPTION }),
84
120
  compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION }),
85
121
  format: Flags.string({
@@ -126,7 +162,9 @@ export default class Decide extends BaseCommand {
126
162
  catch (err) {
127
163
  this.error(err instanceof Error ? err.message : String(err));
128
164
  }
129
- const state = this.readState(flags);
165
+ if (flags.weigh !== undefined)
166
+ return this.weigh(client, flags, name, downstream, json, turn);
167
+ const state = flags.conversation && !flags.state && !flags['state-file'] ? undefined : this.readState(flags);
130
168
  const questions = this.readQuestions(flags);
131
169
  if (!questions)
132
170
  this.error('Ask at least one question, with --question or --questions-file.');
@@ -146,7 +184,7 @@ export default class Decide extends BaseCommand {
146
184
  flags.format = 'openai';
147
185
  }
148
186
  const model = `${name.upstream}/${downstream}`;
149
- let body = { model, state, questions };
187
+ let body = state === undefined ? { model, questions } : { model, state, questions };
150
188
  if (flags.format === 'openai') {
151
189
  try {
152
190
  body = toOpenAIDecision(model, state, questions);
@@ -211,6 +249,48 @@ export default class Decide extends BaseCommand {
211
249
  }
212
250
  }
213
251
  }
252
+ async weigh(client, flags, name, downstream, json, turn) {
253
+ const sid = flags.conversation ?? flags.session;
254
+ if (!sid)
255
+ this.error('--weigh weighs a premise of a state: add --conversation <id> (from faces state:create).');
256
+ const premise = (flags.weigh ?? '').trim();
257
+ if (!premise)
258
+ this.error('--weigh is empty: name the premise whose edges to weigh.');
259
+ const weigh = { premise };
260
+ if (flags['weigh-kind'])
261
+ weigh.kind = flags['weigh-kind'];
262
+ if (flags.cutoff !== undefined) {
263
+ const c = Number(flags.cutoff);
264
+ if (!Number.isFinite(c) || c <= 0 || c > 1)
265
+ this.error(`--cutoff is a number above 0 and at most 1 (got '${flags.cutoff}').`);
266
+ weigh.cutoff = c;
267
+ }
268
+ this.models = await decisionModels(client);
269
+ const match = this.models.find((m) => m.toLowerCase() === downstream.toLowerCase());
270
+ if (!match)
271
+ this.error(`'${downstream}' is not a decision model. The decision models are: ${this.models.join(', ')}.`);
272
+ const body = { model: `${name.upstream}/${match}`, conversation: sid, weigh, ...turn };
273
+ if (flags.state !== undefined || flags['state-file'] !== undefined) {
274
+ const st = this.readState(flags);
275
+ body.input = typeof st === 'string' ? st : JSON.stringify(st);
276
+ }
277
+ if (!json)
278
+ process.stderr.write(`Weighing ${premise} with ${name.faces}. Decision model: ${match}. This usually takes 10 to 20 seconds.\n`);
279
+ let data;
280
+ try {
281
+ data = (await this.ask(client, body, flags.retry, json, '/v1/decisions'));
282
+ }
283
+ catch (err) {
284
+ if (err instanceof FacesAPIError)
285
+ this.error(this.explain(err, name.faces, match));
286
+ throw err;
287
+ }
288
+ if (json)
289
+ return data;
290
+ for (const line of weighLines(data))
291
+ this.log(line);
292
+ return data;
293
+ }
214
294
  readState(flags) {
215
295
  return readStateFlags(flags, (m) => this.error(m));
216
296
  }
@@ -14,6 +14,8 @@ export default class FaceList extends BaseCommand {
14
14
  sort: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
15
  order: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
16
  search: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ for: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ limit: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
19
  'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
20
  token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
21
  'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -2,6 +2,7 @@ import { Flags } from '@oclif/core';
2
2
  import { BaseCommand } from '../../base.js';
3
3
  import { FacesAPIError } from '../../client.js';
4
4
  import { renameFaceFields, faceStyles, readablePatternError } from '../../utils.js';
5
+ const FOR_LIMIT = 10;
5
6
  const SYSTEM_OWNER = 'head';
6
7
  export default class FaceList extends BaseCommand {
7
8
  static description = 'List faces. By default lists owned faces, newest first; use --public to include published faces ' +
@@ -38,6 +39,14 @@ export default class FaceList extends BaseCommand {
38
39
  search: Flags.string({
39
40
  description: 'Only faces whose alias, name or description matches this text',
40
41
  }),
42
+ for: Flags.string({
43
+ description: 'A task, in plain words: ranks the faces by how well their "use me for" line fits it, best first, each with ' +
44
+ 'its fit from 0 to 1. It ranks and never filters. Shows the best 10 unless --limit says otherwise.',
45
+ }),
46
+ limit: Flags.integer({
47
+ description: `The most faces to show, best first with --for; 0 shows all. Default: ${FOR_LIMIT} with --for, all without.`,
48
+ min: 0,
49
+ }),
41
50
  };
42
51
  async run() {
43
52
  const { flags } = await this.parse(FaceList);
@@ -76,6 +85,8 @@ export default class FaceList extends BaseCommand {
76
85
  parts.push(`order=${encodeURIComponent(flags.order)}`);
77
86
  if (flags.search)
78
87
  parts.push(`q=${encodeURIComponent(flags.search)}`);
88
+ if (flags.for)
89
+ parts.push(`for=${encodeURIComponent(flags.for)}`);
79
90
  if (includePublished)
80
91
  parts.push('include_published=true');
81
92
  if (flags.shared)
@@ -115,6 +126,12 @@ export default class FaceList extends BaseCommand {
115
126
  const block = new Set(notFromUsers);
116
127
  faces = faces.filter(f => f.owned_by == null || !block.has(f.owned_by));
117
128
  }
129
+ const limit = flags.limit ?? (flags.for ? FOR_LIMIT : 0);
130
+ const more = limit > 0 ? Math.max(0, faces.length - limit) : 0;
131
+ if (more > 0)
132
+ faces = faces.slice(0, limit);
133
+ if (more > 0 && data && typeof data === 'object' && !Array.isArray(data))
134
+ data.more = more;
118
135
  if (data.data !== undefined)
119
136
  data.data = faces;
120
137
  else
@@ -155,9 +172,14 @@ export default class FaceList extends BaseCommand {
155
172
  if (f.read_only)
156
173
  suffix += ' [read only]';
157
174
  const spec = f.specialty ? ` (${f.specialty})` : '';
158
- this.log(`${handle(f).padEnd(handleWidth)} ${f.name.padEnd(nameWidth)}${spec}${suffix}`.trimEnd());
175
+ const fit = typeof f.fit === 'number' ? `${f.fit.toFixed(2)} ` : '';
176
+ this.log(`${fit}${handle(f).padEnd(handleWidth)} ${f.name.padEnd(nameWidth)}${spec}${suffix}`.trimEnd());
159
177
  }
160
178
  }
179
+ if (more > 0) {
180
+ this.log('');
181
+ this.log(`${more} more face${more === 1 ? '' : 's'} ${flags.for ? 'fit less well' : 'not shown'}. --limit N shows the first N; --limit 0 shows all.`);
182
+ }
161
183
  if (truncated) {
162
184
  this.log('');
163
185
  this.log('This list is incomplete: the server had more faces than could be read in one go.');
@@ -0,0 +1,30 @@
1
+ import { ReplyCommand } from '../../foreman.js';
2
+ export default class PremiseAdd extends ReplyCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ key: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ value: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ and: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ or: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ on: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ role: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ status: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ origin: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ description: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ said: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ await: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ jsonl: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ as: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
+ 'state-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
22
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
23
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
24
+ };
25
+ static args: {
26
+ key: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
27
+ value: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
28
+ };
29
+ run(): Promise<unknown>;
30
+ }
@@ -0,0 +1,86 @@
1
+ import fs from 'node:fs';
2
+ import { Args, Flags } from '@oclif/core';
3
+ import { BaseCommand } from '../../base.js';
4
+ import { ReplyCommand, asFlag, compact, keyList, premiseValue, stateIdFlag } from '../../foreman.js';
5
+ export default class PremiseAdd extends ReplyCommand {
6
+ static description = 'Add a premise to the state; fails if the key exists (premise:edit changes one). --and: a sub-goal of that ' +
7
+ 'parent (it needs all its AND children). --or: a candidate for it (one proved candidate settles it). --on: ' +
8
+ 'inputs it reads (support, not refinement). No --role is a fact, a leaf. Free.';
9
+ static examples = [
10
+ '<%= config.bin %> <%= command.id %> "the dinner is planned" "A dinner party for six" --role goal --said "Plan a dinner party for six."',
11
+ '<%= config.bin %> <%= command.id %> "the guests" "Six, one vegan" --and "the dinner is planned" --origin human',
12
+ '<%= config.bin %> <%= command.id %> "each guest can eat each dish" "Pass if ..." --role test --and "the dinner is planned" --on "the menu,the guests"',
13
+ '<%= config.bin %> <%= command.id %> --jsonl premises.jsonl',
14
+ ];
15
+ static flags = {
16
+ ...BaseCommand.baseFlags,
17
+ ...stateIdFlag,
18
+ ...asFlag,
19
+ key: Flags.string({ description: 'The premise key (instead of the first argument).' }),
20
+ value: Flags.string({ description: 'Its value (instead of the second argument): JSON when it is JSON, text otherwise.' }),
21
+ and: Flags.string({ description: 'The parent it is a sub-goal of (AND).', exclusive: ['or'] }),
22
+ or: Flags.string({ description: 'The parent it is a candidate for (OR).', exclusive: ['and'] }),
23
+ on: Flags.string({ description: 'Inputs it reads: premise keys, comma separated (repeatable). A key holding a comma goes in double quotes.', multiple: true }),
24
+ role: Flags.string({ description: 'goal or test. None: a fact, a leaf.', options: ['goal', 'test'] }),
25
+ status: Flags.string({ description: 'stated, verified, assumed, unresolved or invalidated.' }),
26
+ origin: Flags.string({ description: 'Who it comes from: human, agent, tool or web. Default: human with --said, else agent.' }),
27
+ description: Flags.string({ description: 'What the premise is, in a line.' }),
28
+ said: Flags.string({ description: 'The human\'s words it comes from, as they said them (stored once, linked).' }),
29
+ await: Flags.string({ description: 'What it waits on: human, environment, a test\'s key, or none.' }),
30
+ jsonl: Flags.string({ description: 'Add many: a file (or - for stdin) with one JSON object per line, each with the fields above (key, value, and, or, on, role, status, origin, description, said, await, as); on is a JSON array of keys or a comma list.' }),
31
+ };
32
+ static args = {
33
+ key: Args.string({ description: 'The premise key: plain text, 1 to 120 characters.', required: false }),
34
+ value: Args.string({ description: 'Its value: JSON when it is JSON, text otherwise.', required: false }),
35
+ };
36
+ async run() {
37
+ const { args, flags } = await this.parse(PremiseAdd);
38
+ const client = this.makeClient(flags);
39
+ const p = this.statePath(this.stateId(flags), '/premises');
40
+ if (flags.jsonl) {
41
+ const raw = flags.jsonl === '-' ? fs.readFileSync(0, 'utf8') : fs.readFileSync(flags.jsonl, 'utf8');
42
+ const lines = raw.split('\n').map((l) => l.trim()).filter(Boolean);
43
+ const out = [];
44
+ for (const [i, line] of lines.entries()) {
45
+ let body;
46
+ try {
47
+ body = JSON.parse(line);
48
+ }
49
+ catch {
50
+ this.error(`--jsonl line ${i + 1} is not JSON: ${line.slice(0, 80)}`);
51
+ }
52
+ if (typeof body.on === 'string') {
53
+ try {
54
+ body.on = keyList([body.on], `--jsonl line ${i + 1}: on`) ?? [];
55
+ }
56
+ catch (err) {
57
+ this.error(err instanceof Error ? err.message : String(err));
58
+ }
59
+ }
60
+ if (i > 0 && !this.jsonEnabled())
61
+ this.log('');
62
+ out.push(await this.reply(client, 'POST', p, { body }));
63
+ if (process.exitCode)
64
+ break;
65
+ }
66
+ return out;
67
+ }
68
+ const key = flags.key ?? args.key;
69
+ const rawValue = flags.value ?? (flags.key === undefined ? args.value : args.key);
70
+ const body = compact({
71
+ key,
72
+ value: rawValue === undefined ? undefined : premiseValue(rawValue),
73
+ and: flags.and,
74
+ or: flags.or,
75
+ on: keyList(flags.on, '--on'),
76
+ role: flags.role,
77
+ status: flags.status,
78
+ origin: flags.origin,
79
+ description: flags.description,
80
+ said: flags.said,
81
+ await: flags.await,
82
+ as: flags.as,
83
+ });
84
+ return this.reply(client, 'POST', p, { body });
85
+ }
86
+ }
@@ -0,0 +1,21 @@
1
+ import { ReplyCommand } from '../../foreman.js';
2
+ export default class PremiseChoices extends ReplyCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ question: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ max: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ rank: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
+ face: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
10
+ as: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'state-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
+ };
17
+ static args: {
18
+ key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
19
+ };
20
+ run(): Promise<unknown>;
21
+ }
@@ -0,0 +1,68 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ import { ReplyCommand, asFlag, faceFlag, faceRef, stateIdFlag } from '../../foreman.js';
5
+ import { Loop, named, rank, stripOptions } from '../../refine.js';
6
+ export default class PremiseChoices extends ReplyCommand {
7
+ static description = 'Propose candidates (OR children) for a premise: the face is shown the premise and its inputs, not what ' +
8
+ 'already refines it. With no --question the face asks its own first. Each candidate goes through the ' +
9
+ 'duplicate check. A test or the human\'s fact has no candidates. Billed per call.';
10
+ static examples = [
11
+ '<%= config.bin %> <%= command.id %> "the menu" --face @home-cook',
12
+ '<%= config.bin %> <%= command.id %> "the menu" --face @home-cook --question "Which three menus suit these guests?"',
13
+ ];
14
+ static flags = {
15
+ ...BaseCommand.baseFlags,
16
+ ...stateIdFlag,
17
+ ...asFlag,
18
+ ...faceFlag,
19
+ question: Flags.string({ description: 'The question the candidates answer. Default: the face asks its own.' }),
20
+ max: Flags.integer({ description: 'At most this many candidates (default 8).', min: 1, max: 32 }),
21
+ rank: Flags.boolean({ description: 'Then rank them (premise:decide).', default: false }),
22
+ };
23
+ static args = { key: Args.string({ description: 'The premise the candidates are for.', required: true }) };
24
+ async run() {
25
+ const { args, flags } = await this.parse(PremiseChoices);
26
+ const client = this.makeClient(flags);
27
+ const id = this.stateId(flags);
28
+ const out = [];
29
+ const L = new Loop(client, id, faceRef(flags.face), flags.as, (l) => out.push(l));
30
+ try {
31
+ const n = (await L.premises())[args.key];
32
+ if (!n)
33
+ throw new FacesAPIError(404, `no premise "${args.key}" in this state`);
34
+ if (n.role === 'test')
35
+ throw new FacesAPIError(422, `"${args.key}" is a test: a test has no alternatives; it is settled by its status`);
36
+ if (n.role === null && n.origin === 'human')
37
+ throw new FacesAPIError(422, `"${args.key}" is the human's word, an axiom: it has no alternatives`);
38
+ if (n.op === 'and')
39
+ throw new FacesAPIError(422, `"${args.key}" is an AND premise: a premise has one operator, so it takes no OR child`);
40
+ let q = flags.question;
41
+ if (!q) {
42
+ q = await L.ownQuestion(args.key);
43
+ out.push(`The face asked: ${q}`);
44
+ }
45
+ const opts = stripOptions(await L.propose(args.key, named(q), flags.max));
46
+ const w = await L.write(args.key, 'or', opts);
47
+ if (w.new.length || w.matched.length)
48
+ await L.edit(args.key, { refinement: 'complete', refined_by: 'choices' });
49
+ out.push(`Wrote ${w.new.length} candidate(s) under "${args.key}"${w.new.length ? ': ' + w.new.map((k) => `"${k}"`).join(', ') : ''}.` +
50
+ (w.matched.length ? ` ${w.matched.length} matched one already there: ${w.matched.map((k) => `"${k}"`).join(', ')}.` : ''));
51
+ if (flags.rank)
52
+ out.push(...(await rank(L, args.key)));
53
+ }
54
+ catch (err) {
55
+ if (err instanceof FacesAPIError) {
56
+ process.exitCode = 1;
57
+ process.stderr.write([...out, `Stopped (${err.statusCode}): ${err.message}`].join('\n') + '\n');
58
+ return { error: { status: err.statusCode, message: err.message }, calls: L.calls };
59
+ }
60
+ throw err;
61
+ }
62
+ const got = await client.stateReply('GET', this.statePath(id, '/premise'), { params: { key: args.key } });
63
+ const text = [...out, `${L.calls} billed call(s).`, '', String(got.data.text ?? '')].join('\n');
64
+ if (!this.jsonEnabled())
65
+ this.log(text);
66
+ return { result: out, calls: L.calls, usage: L.usage, text };
67
+ }
68
+ }
@@ -0,0 +1,20 @@
1
+ import { ReplyCommand } from '../../foreman.js';
2
+ export default class PremiseClaim extends ReplyCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ release: import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
+ session: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ ttl: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ 'state-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ };
15
+ static args: {
16
+ key: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
17
+ who: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
18
+ };
19
+ run(): Promise<unknown>;
20
+ }
@@ -0,0 +1,38 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { ReplyCommand, compact, stateIdFlag } from '../../foreman.js';
4
+ export default class PremiseClaim extends ReplyCommand {
5
+ static description = 'Claim a premise\'s branch (it and everything AND/OR under it, never its inputs) for 30 minutes, or --ttl ' +
6
+ 'seconds; a write into it by anyone but <who> (their --as) is refused. Claiming it again renews it. --release ' +
7
+ 'releases the claims on it. The session-end hook releases the session\'s claims. Free.';
8
+ static examples = [
9
+ '<%= config.bin %> <%= command.id %> "the menu" builder-A',
10
+ '<%= config.bin %> <%= command.id %> "the menu" --release',
11
+ '<%= config.bin %> <%= command.id %> --release --session "$FACES_SESSION"',
12
+ ];
13
+ static flags = {
14
+ ...BaseCommand.baseFlags,
15
+ ...stateIdFlag,
16
+ release: Flags.boolean({ description: 'Release the claims on it (only <who>\'s, when given).', default: false }),
17
+ session: Flags.string({ description: 'With --release and no key: release every claim this session took (what the session-end hook runs).', dependsOn: ['release'] }),
18
+ ttl: Flags.integer({ description: 'How long it holds, in seconds (default 1800, at most 86400).', min: 1, max: 86400 }),
19
+ };
20
+ static args = {
21
+ key: Args.string({ description: 'The premise.', required: false }),
22
+ who: Args.string({ description: 'Who claims it: the name their writes carry as --as.', required: false }),
23
+ };
24
+ async run() {
25
+ const { args, flags } = await this.parse(PremiseClaim);
26
+ const client = this.makeClient(flags);
27
+ const id = this.stateId(flags);
28
+ if (flags.release && flags.session && !args.key)
29
+ return this.reply(client, 'POST', this.statePath(id, '/release-session'), { body: { session: flags.session } });
30
+ if (!args.key)
31
+ this.error('Name the premise: faces premise:claim "<key>" <who>');
32
+ if (flags.release)
33
+ return this.reply(client, 'POST', this.statePath(id, '/release'), { body: compact({ key: args.key, agent: args.who }) });
34
+ if (!args.who)
35
+ this.error('Name who claims it: faces premise:claim "<key>" <who>');
36
+ return this.reply(client, 'POST', this.statePath(id, '/claim'), { body: compact({ key: args.key, agent: args.who, ttl_seconds: flags.ttl }) });
37
+ }
38
+ }
@@ -0,0 +1,18 @@
1
+ import { ReplyCommand } from '../../foreman.js';
2
+ export default class PremiseDecide extends ReplyCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ face: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
7
+ as: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ 'state-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ };
14
+ static args: {
15
+ key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
16
+ };
17
+ run(): Promise<unknown>;
18
+ }
@@ -0,0 +1,36 @@
1
+ import { Args } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ import { ReplyCommand, asFlag, faceFlag, faceRef, stateIdFlag } from '../../foreman.js';
5
+ import { Loop, rank } from '../../refine.js';
6
+ export default class PremiseDecide extends ReplyCommand {
7
+ static description = 'Rank a premise\'s candidates: a decision writes each one\'s p, which says which to try first. It never ' +
8
+ 'chooses or prunes: the top one is next to try, and its tests settle it; only a failed test run on a ' +
9
+ 'candidate, or the human, refutes one. Billed per call.';
10
+ static examples = ['<%= config.bin %> <%= command.id %> "the menu" --face @home-cook'];
11
+ static flags = { ...BaseCommand.baseFlags, ...stateIdFlag, ...asFlag, ...faceFlag };
12
+ static args = { key: Args.string({ description: 'The OR premise whose candidates to rank.', required: true }) };
13
+ async run() {
14
+ const { args, flags } = await this.parse(PremiseDecide);
15
+ const client = this.makeClient(flags);
16
+ const id = this.stateId(flags);
17
+ const L = new Loop(client, id, faceRef(flags.face), flags.as);
18
+ let out;
19
+ try {
20
+ out = await rank(L, args.key);
21
+ }
22
+ catch (err) {
23
+ if (err instanceof FacesAPIError) {
24
+ process.exitCode = 1;
25
+ process.stderr.write(`Stopped (${err.statusCode}): ${err.message}\n`);
26
+ return { error: { status: err.statusCode, message: err.message }, calls: L.calls };
27
+ }
28
+ throw err;
29
+ }
30
+ const got = await client.stateReply('GET', this.statePath(id, '/premise'), { params: { key: args.key } });
31
+ const text = [...out, `${L.calls} billed call(s).`, '', String(got.data.text ?? '')].join('\n');
32
+ if (!this.jsonEnabled())
33
+ this.log(text);
34
+ return { result: out, calls: L.calls, usage: L.usage, text };
35
+ }
36
+ }
@@ -0,0 +1,17 @@
1
+ import { ReplyCommand } from '../../foreman.js';
2
+ export default class PremiseDelete extends ReplyCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ as: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ 'state-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ };
13
+ static args: {
14
+ key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
15
+ };
16
+ run(): Promise<unknown>;
17
+ }
@@ -0,0 +1,17 @@
1
+ import { Args } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { ReplyCommand, asFlag, stateIdFlag } from '../../foreman.js';
4
+ export default class PremiseDelete extends ReplyCommand {
5
+ static description = 'Remove a premise and its edges. Its history keeps it; no status changes, nothing cascades. Free.';
6
+ static examples = ['<%= config.bin %> <%= command.id %> "the old menu"'];
7
+ static flags = { ...BaseCommand.baseFlags, ...stateIdFlag, ...asFlag };
8
+ static args = { key: Args.string({ description: 'The premise to remove.', required: true }) };
9
+ async run() {
10
+ const { args, flags } = await this.parse(PremiseDelete);
11
+ const client = this.makeClient(flags);
12
+ const params = { key: args.key };
13
+ if (flags.as)
14
+ params.as = flags.as;
15
+ return this.reply(client, 'DELETE', this.statePath(this.stateId(flags), '/premises'), { params });
16
+ }
17
+ }
@@ -0,0 +1,28 @@
1
+ import { ReplyCommand } from '../../foreman.js';
2
+ export default class PremiseEdit extends ReplyCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ value: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ key: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ status: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ description: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ await: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ tested: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ evidence: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ note: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ on: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ refinement: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ said: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ as: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ 'state-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
22
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
23
+ };
24
+ static args: {
25
+ key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
26
+ };
27
+ run(): Promise<unknown>;
28
+ }