@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
@@ -0,0 +1,56 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ import { fidelityError, fidelityPost, nextStep } from '../../fidelity.js';
5
+ import { seg, usd } from '../../utils.js';
6
+ export default class FidelityStart extends BaseCommand {
7
+ static description = 'Start a fidelity run on a face you own: ten blind turns, scored out of 10. Each turn you send a ' +
8
+ 'message, read two answers labelled a and b (one is the face, one a competitor model given the ' +
9
+ 'face\'s own writing), and pick the one that sounds more like the person, accepting it or correcting ' +
10
+ 'it. The picks must be the person\'s own: an agent shows both answers and passes on the choice it is ' +
11
+ 'given, never its own. The score is saved on the face, and a new run replaces it. On Connect or Pro ' +
12
+ 'with ChatGPT linked, answers from Codex-eligible models run on the ChatGPT plan; the rest, and grading ' +
13
+ 'a correction, is paid from credits. To play it in the terminal, use faces fidelity:run.';
14
+ static examples = [
15
+ '<%= config.bin %> <%= command.id %> alice',
16
+ '<%= config.bin %> <%= command.id %> alice --competitor <model>',
17
+ ];
18
+ static flags = {
19
+ ...BaseCommand.baseFlags,
20
+ competitor: Flags.string({
21
+ description: 'The chat model the face is compared with (default: the cheapest Codex-eligible chat model)',
22
+ }),
23
+ model: Flags.string({ description: 'The model the face answers on (default: its own default model)' }),
24
+ };
25
+ static args = {
26
+ alias: Args.string({ description: 'Alias of a face you own', required: true }),
27
+ };
28
+ async run() {
29
+ const { args, flags } = await this.parse(FidelityStart);
30
+ const client = this.makeClient(flags);
31
+ const body = {};
32
+ if (flags.competitor)
33
+ body.competitor = flags.competitor;
34
+ if (flags.model)
35
+ body.model = flags.model;
36
+ let run;
37
+ try {
38
+ run = (await fidelityPost(client, `/v1/faces/${seg(args.alias)}/fidelity`, body));
39
+ }
40
+ catch (err) {
41
+ if (err instanceof FacesAPIError)
42
+ this.error(fidelityError(err, { alias: args.alias }));
43
+ throw err;
44
+ }
45
+ if (this.jsonEnabled())
46
+ return run;
47
+ this.log(`run: ${run.run_id}`);
48
+ this.log(`face: ${run.alias ?? args.alias}`);
49
+ this.log(`competitor: ${run.competitor ?? '-'}`);
50
+ if (run.estimated_usd !== undefined)
51
+ this.log(`up to: ${usd(run.estimated_usd)} from credits`);
52
+ this.log('');
53
+ this.log(nextStep(run) ?? '');
54
+ return run;
55
+ }
56
+ }
@@ -0,0 +1,17 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class FidelityTurn extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ message: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ file: 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
+ run_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
15
+ };
16
+ run(): Promise<unknown>;
17
+ }
@@ -0,0 +1,48 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import fs from 'node:fs';
3
+ import { BaseCommand } from '../../base.js';
4
+ import { FacesAPIError } from '../../client.js';
5
+ import { answerLines, fidelityError, fidelityPost } from '../../fidelity.js';
6
+ import { seg } from '../../utils.js';
7
+ export default class FidelityTurn extends BaseCommand {
8
+ static description = 'Send the next turn\'s message on a fidelity run. Prints two answers, a and b, in random order, with ' +
9
+ 'nothing saying which is the face. Pick one with faces fidelity:pick before the next turn.';
10
+ static examples = ['<%= config.bin %> <%= command.id %> <run> -m "How was the trip?"'];
11
+ static flags = {
12
+ ...BaseCommand.baseFlags,
13
+ message: Flags.string({ char: 'm', description: 'Your message for this turn', exclusive: ['file'] }),
14
+ file: Flags.string({ description: 'Read the message from a file' }),
15
+ };
16
+ static args = {
17
+ run_id: Args.string({ description: 'Fidelity run id, from faces fidelity:start', required: true }),
18
+ };
19
+ async run() {
20
+ const { args, flags } = await this.parse(FidelityTurn);
21
+ const client = this.makeClient(flags);
22
+ let message = flags.message;
23
+ if (flags.file) {
24
+ if (!fs.existsSync(flags.file))
25
+ this.error(`File not found: ${flags.file}`);
26
+ message = fs.readFileSync(flags.file, 'utf8');
27
+ }
28
+ if (!message?.trim())
29
+ this.error('Give the message with -m "..." or --file <path>.');
30
+ let data;
31
+ try {
32
+ data = await fidelityPost(client, `/v1/fidelity/${seg(args.run_id)}/turns`, { message });
33
+ }
34
+ catch (err) {
35
+ if (err instanceof FacesAPIError)
36
+ this.error(fidelityError(err, { run: args.run_id }));
37
+ throw err;
38
+ }
39
+ if (this.jsonEnabled())
40
+ return data;
41
+ const turn = Number(data.turn);
42
+ for (const line of answerLines(turn, (data.answers ?? {})))
43
+ this.log(line);
44
+ this.log('');
45
+ this.log(`Pick one: faces fidelity:pick ${args.run_id} a|b [--correction "what they would have said"]`);
46
+ return data;
47
+ }
48
+ }
@@ -5,7 +5,7 @@ import { GroupCatalogService } from '../../group-catalog.js';
5
5
  import { resolveFace, seg } from '../../utils.js';
6
6
  export default class GroupAdd extends BaseCommand {
7
7
  static description = 'Add face(s) to a group. Any face this account can reach may join: your own, a published one, or one ' +
8
- 'shared with you. Name someone else\'s as owner:alias, the same address chat uses.';
8
+ 'shared with you. Name someone else\'s as owner:alias.';
9
9
  static flags = {
10
10
  ...BaseCommand.baseFlags,
11
11
  face: Flags.string({ description: 'Face alias to add (repeatable)', multiple: true, required: true }),
@@ -0,0 +1,12 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class MediaList extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
+ };
11
+ run(): Promise<unknown>;
12
+ }
@@ -0,0 +1,35 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ import { FacesAPIError } from '../../client.js';
3
+ import { MEDIA_PATH, mediaLines, mediaOf } from '../../media.js';
4
+ export default class MediaList extends BaseCommand {
5
+ static description = 'List the media (GET /v1/media): the kinds of writing a source can be, each with its description and ' +
6
+ 'the subcategories it covers. A document declares one when it is compiled (--medium), styles are built ' +
7
+ 'one per medium, and chat chooses one for each request. Send the name exactly: a subcategory such as ' +
8
+ 'keynote is not a medium (it is a speech). No login needed.';
9
+ static examples = [
10
+ '<%= config.bin %> <%= command.id %>',
11
+ '<%= config.bin %> <%= command.id %> --json',
12
+ ];
13
+ static flags = {
14
+ ...BaseCommand.baseFlags,
15
+ };
16
+ async run() {
17
+ const { flags } = await this.parse(MediaList);
18
+ const client = this.makeClient(flags);
19
+ let raw;
20
+ try {
21
+ raw = await client.get(MEDIA_PATH, { optionalAuth: true });
22
+ }
23
+ catch (err) {
24
+ if (err instanceof FacesAPIError)
25
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
26
+ throw err;
27
+ }
28
+ const data = mediaOf(raw);
29
+ if (this.jsonEnabled())
30
+ return { object: 'list', data };
31
+ for (const line of mediaLines(data))
32
+ this.log(line);
33
+ return { object: 'list', data };
34
+ }
35
+ }
@@ -2,24 +2,26 @@ import { Flags } from '@oclif/core';
2
2
  import { BaseCommand } from '../../base.js';
3
3
  import { FacesAPIError } from '../../client.js';
4
4
  import { table } from '../../utils.js';
5
- const KINDS = ['choices', 'decision', 'cause', 'compile', 'chat', 'image', 'transcription'];
5
+ const KINDS = ['upstream', 'chat', 'decision', 'compile', 'image', 'transcription'];
6
6
  export default class ModelsList extends BaseCommand {
7
7
  static description = 'List the models you can name, once each, with their kind, endpoint and price (GET /v1/models). ' +
8
- 'Without --kind only chat models are listed; --kind choices lists the models faces choices runs on. ' +
8
+ 'Upstream models are ours, the maestros, written after a face: @alice:maestro-1. Downstream models write ' +
9
+ 'the answer, after the /: @alice:maestro-1/gpt-5.4. Each is priced on its own. Without --kind the maestros ' +
10
+ 'and the chat models are listed; --kind decision lists the models faces decide answers on. ' +
9
11
  'CHATGPT marks the Codex-eligible models, which can run on a linked ChatGPT plan (style builds, interviews). ' +
10
12
  'Prices are per million tokens. No login needed.';
11
13
  static examples = [
12
14
  '<%= config.bin %> <%= command.id %>',
13
- '<%= config.bin %> <%= command.id %> --kind choices',
15
+ '<%= config.bin %> <%= command.id %> --kind upstream',
14
16
  '<%= config.bin %> <%= command.id %> --kind decision',
15
- '<%= config.bin %> <%= command.id %> --kind cause,compile',
17
+ '<%= config.bin %> <%= command.id %> --kind upstream,compile',
16
18
  '<%= config.bin %> <%= command.id %> --kind all --json',
17
19
  '<%= config.bin %> <%= command.id %> --provider anthropic',
18
20
  ];
19
21
  static flags = {
20
22
  ...BaseCommand.baseFlags,
21
23
  kind: Flags.string({
22
- description: `One kind or a comma-separated list: ${KINDS.join(', ')}; or all. Default: chat.`,
24
+ description: `One kind or a comma-separated list: ${KINDS.join(', ')}; or all. Default: upstream and chat.`,
23
25
  }),
24
26
  provider: Flags.string({ description: 'Only models from this lab (e.g. openai, anthropic, qwen)' }),
25
27
  chatgpt: Flags.boolean({
@@ -84,7 +86,12 @@ export default class ModelsList extends BaseCommand {
84
86
  if (m.token_basis === 'source')
85
87
  notes.push(`${m.id}: priced per million source tokens compiled.`);
86
88
  if (m.token_basis === 'processed')
87
- notes.push(`${m.id}: priced on the tokens each call processes, as its usage reports them.`);
89
+ notes.push(`${m.id}: on /v1/choices, priced on the tokens each call processes, as its usage reports them.`);
90
+ const st = m.steering;
91
+ if (st && typeof st === 'object' && typeof st.input_cost_per_million_tokens === 'number') {
92
+ notes.push(`${m.id}: steering a face over a downstream model (chat, decide) costs $${st.input_cost_per_million_tokens} per million ` +
93
+ `input tokens plus $${st.cost_per_call_usd} a call, with no output charge; the downstream model is billed at its listed price plus the markup.`);
94
+ }
88
95
  const inc = m.included_tokens_per_month;
89
96
  if (inc && typeof inc === 'object') {
90
97
  const plans = Object.entries(inc).filter(([, n]) => typeof n === 'number' && n > 0).map(([p, n]) => `${p[0].toUpperCase()}${p.slice(1)} ${n.toLocaleString('en-US')}`);
@@ -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
+ }