@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.
- package/README.md +106 -54
- package/dist/billing.js +11 -8
- package/dist/chat-command.d.ts +33 -0
- package/dist/chat-command.js +110 -0
- package/dist/chat.d.ts +49 -0
- package/dist/chat.js +157 -0
- package/dist/choices.d.ts +11 -5
- package/dist/choices.js +26 -9
- package/dist/client.d.ts +8 -0
- package/dist/client.js +37 -0
- package/dist/commands/billing/llm-costs.js +9 -5
- package/dist/commands/billing/subscription/index.js +1 -1
- package/dist/commands/catalog/doctor.js +2 -2
- package/dist/commands/{causes.d.ts → chat/chat.d.ts} +14 -14
- package/dist/commands/chat/chat.js +31 -0
- package/dist/commands/chat/messages.d.ts +32 -0
- package/dist/commands/chat/messages.js +21 -0
- package/dist/commands/chat/responses.d.ts +32 -0
- package/dist/commands/chat/responses.js +22 -0
- package/dist/commands/chat/thread.d.ts +40 -0
- package/dist/commands/chat/thread.js +238 -0
- package/dist/commands/choices.d.ts +4 -2
- package/dist/commands/choices.js +56 -15
- package/dist/commands/conversation/add.d.ts +2 -0
- package/dist/commands/conversation/add.js +5 -2
- package/dist/commands/conversation/compact.js +13 -16
- package/dist/commands/conversation/create.d.ts +2 -0
- package/dist/commands/conversation/create.js +14 -11
- package/dist/commands/decide.d.ts +32 -4
- package/dist/commands/decide.js +135 -83
- package/dist/commands/face/get.js +1 -1
- package/dist/commands/face/list.d.ts +2 -0
- package/dist/commands/face/list.js +23 -1
- package/dist/commands/fidelity/pick.js +2 -2
- package/dist/commands/fidelity/run.d.ts +20 -0
- package/dist/commands/fidelity/run.js +99 -0
- package/dist/commands/fidelity/start.d.ts +17 -0
- package/dist/commands/fidelity/start.js +56 -0
- package/dist/commands/fidelity/turn.d.ts +17 -0
- package/dist/commands/fidelity/turn.js +48 -0
- package/dist/commands/group/add.js +1 -1
- package/dist/commands/media/list.d.ts +12 -0
- package/dist/commands/media/list.js +35 -0
- package/dist/commands/models/list.js +13 -6
- package/dist/commands/premise/add.d.ts +30 -0
- package/dist/commands/premise/add.js +86 -0
- package/dist/commands/premise/choices.d.ts +21 -0
- package/dist/commands/premise/choices.js +68 -0
- package/dist/commands/premise/claim.d.ts +20 -0
- package/dist/commands/premise/claim.js +38 -0
- package/dist/commands/premise/decide.d.ts +18 -0
- package/dist/commands/premise/decide.js +36 -0
- package/dist/commands/premise/delete.d.ts +17 -0
- package/dist/commands/premise/delete.js +17 -0
- package/dist/commands/premise/edit.d.ts +28 -0
- package/dist/commands/premise/edit.js +51 -0
- package/dist/commands/premise/get.d.ts +22 -0
- package/dist/commands/premise/get.js +37 -0
- package/dist/commands/premise/refine.d.ts +20 -0
- package/dist/commands/premise/refine.js +80 -0
- package/dist/commands/session/compact.js +5 -8
- package/dist/commands/session/create.js +9 -8
- package/dist/commands/state/create.d.ts +13 -2
- package/dist/commands/state/create.js +55 -2
- package/dist/commands/state/get.d.ts +19 -2
- package/dist/commands/state/get.js +30 -2
- package/dist/commands/state/use.d.ts +16 -0
- package/dist/commands/state/use.js +25 -0
- package/dist/commands/style/make.js +1 -1
- package/dist/commands/style/upload.js +1 -1
- package/dist/conversation.d.ts +30 -3
- package/dist/conversation.js +202 -18
- package/dist/decisions.d.ts +0 -5
- package/dist/decisions.js +0 -18
- package/dist/fidelity.js +3 -3
- package/dist/foreman.d.ts +47 -0
- package/dist/foreman.js +115 -0
- package/dist/media.d.ts +8 -0
- package/dist/media.js +12 -0
- package/dist/model.d.ts +11 -0
- package/dist/model.js +53 -0
- package/dist/refine.d.ts +106 -0
- package/dist/refine.js +601 -0
- package/dist/routing.d.ts +1 -4
- package/dist/routing.js +4 -40
- package/dist/synopsis.d.ts +49 -0
- package/dist/synopsis.js +43 -0
- package/dist/utils.d.ts +1 -25
- package/dist/utils.js +10 -108
- package/oclif.manifest.json +3939 -1835
- package/package.json +10 -4
- package/dist/commands/causes.js +0 -146
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { BaseCommand } from '../../base.js';
|
|
7
|
+
import { FacesAPIError } from '../../client.js';
|
|
8
|
+
import { conversationFields, conversationTurnFlags } from '../../conversation.js';
|
|
9
|
+
import { MODEL_ARG_DESCRIPTION, chatModelProblem, chatPayload, sendChat } from '../../chat.js';
|
|
10
|
+
import { parseModel } from '../../model.js';
|
|
11
|
+
import { resolveEndpoint } from '../../routing.js';
|
|
12
|
+
import { COMPACTION_FLAG_DESCRIPTION, SESSION_FLAG_DESCRIPTION, STREAM_FLAG_DESCRIPTION, parseTemperature } from '../../utils.js';
|
|
13
|
+
import { chatRefusal } from '../../chat-command.js';
|
|
14
|
+
const THREADS_DIR = path.join(os.homedir(), '.faces', 'threads');
|
|
15
|
+
function newThreadId() {
|
|
16
|
+
return 't_' + crypto.randomBytes(6).toString('hex');
|
|
17
|
+
}
|
|
18
|
+
function threadPath(id) {
|
|
19
|
+
if (!/^[A-Za-z0-9_-]+$/.test(id))
|
|
20
|
+
throw new Error(`"${id}" is not a thread id. List them with: faces chat:thread --list`);
|
|
21
|
+
return path.join(THREADS_DIR, `${id}.json`);
|
|
22
|
+
}
|
|
23
|
+
function loadThread(id) {
|
|
24
|
+
const p = threadPath(id);
|
|
25
|
+
if (!fs.existsSync(p))
|
|
26
|
+
return null;
|
|
27
|
+
return JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
28
|
+
}
|
|
29
|
+
function saveThread(t) {
|
|
30
|
+
if (!fs.existsSync(THREADS_DIR))
|
|
31
|
+
fs.mkdirSync(THREADS_DIR, { recursive: true, mode: 0o700 });
|
|
32
|
+
t.updated_at = new Date().toISOString();
|
|
33
|
+
fs.writeFileSync(threadPath(t.id), JSON.stringify(t, null, 2), { mode: 0o600 });
|
|
34
|
+
}
|
|
35
|
+
function listThreads() {
|
|
36
|
+
if (!fs.existsSync(THREADS_DIR))
|
|
37
|
+
return [];
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const f of fs.readdirSync(THREADS_DIR)) {
|
|
40
|
+
if (!f.endsWith('.json'))
|
|
41
|
+
continue;
|
|
42
|
+
try {
|
|
43
|
+
out.push(JSON.parse(fs.readFileSync(path.join(THREADS_DIR, f), 'utf8')));
|
|
44
|
+
}
|
|
45
|
+
catch { }
|
|
46
|
+
}
|
|
47
|
+
out.sort((a, b) => (b.updated_at ?? '').localeCompare(a.updated_at ?? ''));
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
export default class ChatThread extends BaseCommand {
|
|
51
|
+
static description = 'A multi-turn chat with a face, kept under ~/.faces/threads/<id>.json. Start one with the model ' +
|
|
52
|
+
'(@alice:maestro-1/gpt-5.4) and a message, then go on with --id. The whole thread is sent each turn, ' +
|
|
53
|
+
'unless the turn is in a state (--conversation), which holds the history: then only the new message goes.';
|
|
54
|
+
static examples = [
|
|
55
|
+
'<%= config.bin %> <%= command.id %> @socrates:maestro-1/gpt-5.4 -m "What is justice?"',
|
|
56
|
+
'<%= config.bin %> <%= command.id %> --id t_abc123 -m "Say more about that"',
|
|
57
|
+
'<%= config.bin %> <%= command.id %> --list',
|
|
58
|
+
'<%= config.bin %> <%= command.id %> --id t_abc123 --show',
|
|
59
|
+
'<%= config.bin %> <%= command.id %> --id t_abc123 --delete',
|
|
60
|
+
];
|
|
61
|
+
static flags = {
|
|
62
|
+
...BaseCommand.baseFlags,
|
|
63
|
+
id: Flags.string({ description: 'Go on with a saved thread, by id.' }),
|
|
64
|
+
message: Flags.string({ char: 'm', description: 'Your message.' }),
|
|
65
|
+
file: Flags.string({ description: 'Read the message from a file.' }),
|
|
66
|
+
system: Flags.string({ description: 'System prompt (only when starting a thread).' }),
|
|
67
|
+
'max-tokens': Flags.integer({ description: 'The most tokens the reply may take (at least 1).', min: 1 }),
|
|
68
|
+
temperature: Flags.string({ description: 'Temperature (0.0-2.0).' }),
|
|
69
|
+
stream: Flags.boolean({ description: STREAM_FLAG_DESCRIPTION, default: true, allowNo: true }),
|
|
70
|
+
...conversationTurnFlags({ suffix: 'For this turn only. Only the new message is sent: the state holds the rest.' }),
|
|
71
|
+
session: Flags.string({ description: `${SESSION_FLAG_DESCRIPTION} For this turn only.` }),
|
|
72
|
+
compaction: Flags.string({ description: `${COMPACTION_FLAG_DESCRIPTION} For this turn only.` }),
|
|
73
|
+
'oauth-only': Flags.boolean({ description: 'On a linked ChatGPT plan, run there or fail: never fall back to credits.', default: false }),
|
|
74
|
+
list: Flags.boolean({ description: 'List saved threads.', default: false }),
|
|
75
|
+
show: Flags.boolean({ description: 'Show a thread (needs --id).', default: false }),
|
|
76
|
+
delete: Flags.boolean({ description: 'Delete a thread (needs --id).', default: false }),
|
|
77
|
+
yes: Flags.boolean({ description: 'Skip the confirmation for --delete.', default: false }),
|
|
78
|
+
};
|
|
79
|
+
static args = {
|
|
80
|
+
model: Args.string({ description: `${MODEL_ARG_DESCRIPTION} Needed to start a thread; a saved thread keeps its own.`, required: false }),
|
|
81
|
+
};
|
|
82
|
+
async run() {
|
|
83
|
+
const { args, flags } = await this.parse(ChatThread);
|
|
84
|
+
if (flags.list)
|
|
85
|
+
return this.handleList();
|
|
86
|
+
if (flags.delete)
|
|
87
|
+
return this.handleDelete(flags.id, flags.yes);
|
|
88
|
+
if (flags.show)
|
|
89
|
+
return this.handleShow(flags.id);
|
|
90
|
+
let message;
|
|
91
|
+
if (flags.file) {
|
|
92
|
+
if (!fs.existsSync(flags.file))
|
|
93
|
+
this.error(`File not found: ${flags.file}`);
|
|
94
|
+
message = fs.readFileSync(flags.file, 'utf8');
|
|
95
|
+
}
|
|
96
|
+
else if (flags.message) {
|
|
97
|
+
message = flags.message;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
this.error('Provide --message/-m or --file.');
|
|
101
|
+
}
|
|
102
|
+
let turn;
|
|
103
|
+
try {
|
|
104
|
+
turn = conversationFields(flags);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
this.error(err instanceof Error ? err.message : String(err));
|
|
108
|
+
}
|
|
109
|
+
const newOnly = Boolean(flags.conversation || flags.session);
|
|
110
|
+
let thread;
|
|
111
|
+
if (flags.id) {
|
|
112
|
+
let existing;
|
|
113
|
+
try {
|
|
114
|
+
existing = loadThread(flags.id);
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
this.error(err instanceof Error ? err.message : String(err));
|
|
118
|
+
}
|
|
119
|
+
if (!existing)
|
|
120
|
+
this.error(`Thread not found: ${flags.id}`);
|
|
121
|
+
thread = existing;
|
|
122
|
+
if (args.model && args.model.trim() !== thread.model)
|
|
123
|
+
this.warn(`A thread keeps its model; going on with ${thread.model}.`);
|
|
124
|
+
if (flags.system)
|
|
125
|
+
this.warn('--system is ignored when going on with a thread.');
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
if (!args.model)
|
|
129
|
+
this.error('Name the model to start a thread (e.g. faces chat:thread @socrates:maestro-1/gpt-5.4 -m "..."), or --id to go on with one.');
|
|
130
|
+
const now = new Date().toISOString();
|
|
131
|
+
thread = { id: newThreadId(), model: args.model.trim(), system: flags.system, created_at: now, updated_at: now, messages: [] };
|
|
132
|
+
}
|
|
133
|
+
const problem = chatModelProblem(thread.model);
|
|
134
|
+
if (problem)
|
|
135
|
+
this.error(`${problem}\nThis thread was saved with the old form; start a new one with the new model.`);
|
|
136
|
+
const client = this.makeClient(flags);
|
|
137
|
+
if (!thread.endpoint)
|
|
138
|
+
thread.endpoint = (await resolveEndpoint(client, parseModel(thread.model).downstream)).endpoint;
|
|
139
|
+
const endpoint = thread.endpoint;
|
|
140
|
+
thread.messages.push({ role: 'user', content: message, ts: new Date().toISOString() });
|
|
141
|
+
const sent = newOnly ? thread.messages.slice(-1) : thread.messages;
|
|
142
|
+
const json = this.jsonEnabled();
|
|
143
|
+
let payload;
|
|
144
|
+
try {
|
|
145
|
+
payload = chatPayload(endpoint, thread.model, sent.map((m) => ({ role: m.role, content: m.content })), {
|
|
146
|
+
system: thread.system,
|
|
147
|
+
maxTokens: flags['max-tokens'],
|
|
148
|
+
temperature: flags.temperature === undefined ? undefined : parseTemperature(flags.temperature, (m) => this.error(m)),
|
|
149
|
+
stream: flags.stream && !json,
|
|
150
|
+
oauthOnly: flags['oauth-only'],
|
|
151
|
+
session: flags.session,
|
|
152
|
+
compaction: flags.compaction,
|
|
153
|
+
turn,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
this.error(err instanceof Error ? err.message : String(err));
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const res = await sendChat(client, endpoint, payload, (d) => process.stdout.write(d), json);
|
|
161
|
+
if (!res.text)
|
|
162
|
+
this.error('No answer came back. Run it again with --no-stream to see what the server said.');
|
|
163
|
+
thread.messages.push({ role: 'assistant', content: res.text, ts: new Date().toISOString() });
|
|
164
|
+
saveThread(thread);
|
|
165
|
+
if (json)
|
|
166
|
+
return { thread_id: thread.id, model: thread.model, endpoint, assistant: res.text, turns: thread.messages.length };
|
|
167
|
+
if (payload.stream)
|
|
168
|
+
process.stdout.write('\n');
|
|
169
|
+
else
|
|
170
|
+
this.log(res.text);
|
|
171
|
+
this.log(`\n[thread ${thread.id} · ${thread.messages.length} turns]`);
|
|
172
|
+
return { thread_id: thread.id, assistant: res.text };
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
if (err instanceof FacesAPIError)
|
|
176
|
+
this.error(await chatRefusal(err, thread.model, endpoint, false, client));
|
|
177
|
+
throw err;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
handleList() {
|
|
181
|
+
const threads = listThreads();
|
|
182
|
+
if (this.jsonEnabled()) {
|
|
183
|
+
return threads.map((t) => ({ id: t.id, model: t.model, turns: t.messages.length, created_at: t.created_at, updated_at: t.updated_at }));
|
|
184
|
+
}
|
|
185
|
+
if (threads.length === 0) {
|
|
186
|
+
this.log('(no threads)');
|
|
187
|
+
return {};
|
|
188
|
+
}
|
|
189
|
+
for (const t of threads) {
|
|
190
|
+
const last = t.messages.at(-1);
|
|
191
|
+
this.log(`${t.id} ${t.model} (${t.messages.length} turns, updated ${t.updated_at})`);
|
|
192
|
+
if (last)
|
|
193
|
+
this.log(` ${last.role}: ${last.content.slice(0, 60).replace(/\s+/g, ' ')}${last.content.length > 60 ? '…' : ''}`);
|
|
194
|
+
}
|
|
195
|
+
return {};
|
|
196
|
+
}
|
|
197
|
+
async handleDelete(id, yes) {
|
|
198
|
+
if (!id)
|
|
199
|
+
this.error('--delete needs --id <thread-id>');
|
|
200
|
+
let p;
|
|
201
|
+
try {
|
|
202
|
+
p = threadPath(id);
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
this.error(err instanceof Error ? err.message : String(err));
|
|
206
|
+
}
|
|
207
|
+
if (!fs.existsSync(p))
|
|
208
|
+
this.error(`Thread not found: ${id}`);
|
|
209
|
+
await this.confirmOrRefuse(`Delete thread ${id} and its history?`, yes);
|
|
210
|
+
fs.unlinkSync(p);
|
|
211
|
+
if (!this.jsonEnabled())
|
|
212
|
+
this.log(`Deleted thread ${id}`);
|
|
213
|
+
return { deleted: id };
|
|
214
|
+
}
|
|
215
|
+
handleShow(id) {
|
|
216
|
+
if (!id)
|
|
217
|
+
this.error('--show needs --id <thread-id>');
|
|
218
|
+
let t;
|
|
219
|
+
try {
|
|
220
|
+
t = loadThread(id);
|
|
221
|
+
}
|
|
222
|
+
catch (err) {
|
|
223
|
+
this.error(err instanceof Error ? err.message : String(err));
|
|
224
|
+
}
|
|
225
|
+
if (!t)
|
|
226
|
+
this.error(`Thread not found: ${id}`);
|
|
227
|
+
if (this.jsonEnabled())
|
|
228
|
+
return t;
|
|
229
|
+
this.log(`Thread ${t.id} (${t.model})`);
|
|
230
|
+
this.log(`Created: ${t.created_at}`);
|
|
231
|
+
this.log(`Updated: ${t.updated_at}`);
|
|
232
|
+
if (t.system)
|
|
233
|
+
this.log(`---\nsystem: ${t.system}`);
|
|
234
|
+
for (const m of t.messages)
|
|
235
|
+
this.log(`---\n${m.role} [${m.ts}]:\n${m.content}`);
|
|
236
|
+
return t;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -7,7 +7,9 @@ export default class Choices extends BaseCommand {
|
|
|
7
7
|
state: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
8
|
'state-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
9
|
'state-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
-
|
|
10
|
+
'depends-on': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
into: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
kind: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
13
|
'max-choices': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
14
|
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
15
|
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -15,7 +17,7 @@ export default class Choices extends BaseCommand {
|
|
|
15
17
|
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
16
18
|
};
|
|
17
19
|
static args: {
|
|
18
|
-
|
|
20
|
+
model: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
19
21
|
};
|
|
20
22
|
run(): Promise<unknown>;
|
|
21
23
|
}
|
package/dist/commands/choices.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
2
|
import { BaseCommand } from '../base.js';
|
|
3
3
|
import { FacesAPIError } from '../client.js';
|
|
4
|
-
import {
|
|
4
|
+
import { CHOICES_PATH, MAX_CHOICES, choicesHint, choicesLines } from '../choices.js';
|
|
5
|
+
import { modelProblem } from '../model.js';
|
|
5
6
|
import { heldDecisionError, readStateFlags } from '../decisions.js';
|
|
6
7
|
import { retryOnceOnWarmUp, sayWarmUp } from '../utils.js';
|
|
8
|
+
import { MAX_DEPENDS_ON, parseDependsOn } from '../conversation.js';
|
|
7
9
|
export default class Choices extends BaseCommand {
|
|
8
|
-
static description = 'Ask a face what it would do (POST /v1/choices).
|
|
10
|
+
static description = 'Ask a face what it would do (POST /v1/choices). Name the upstream model, a face and its maestro: ' +
|
|
11
|
+
'@alice:maestro-1, @dana~alice:maestro-1 for a face shared with you, or a composite such as ' +
|
|
12
|
+
'"(@alice | @bob):maestro-1". maestro-1-flash answers sooner and costs 10 times more. ' +
|
|
13
|
+
'Describe the situation with --state (prose, at most ' +
|
|
9
14
|
'3,000 tokens) or --state-id (a state from faces state:create), ask with --question, and the face proposes ' +
|
|
10
15
|
'the options it would weigh, strongest first. Leave --question out and it proposes the question it would ask. ' +
|
|
11
|
-
'Billed on the tokens it processes (see faces models:list --kind
|
|
16
|
+
'Billed on the tokens it processes (see faces models:list --kind upstream). Takes about 10 to 30 seconds.';
|
|
12
17
|
static examples = [
|
|
13
|
-
'<%= config.bin %> <%= command.id %> alice --state "A startup offers me a lead role at a lower salary." --question "Should I take the offer?"',
|
|
14
|
-
'<%= config.bin %> <%= command.id %> head:
|
|
15
|
-
'<%= config.bin %> <%= command.id %> alice --state-id fs_STATE_ID --question "What should the shop do?" --max-choices 3',
|
|
16
|
-
'<%= config.bin %> <%= command.id %>
|
|
18
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1 --state "A startup offers me a lead role at a lower salary." --question "Should I take the offer?"',
|
|
19
|
+
'<%= config.bin %> <%= command.id %> @head~socrates:maestro-1 --state "A chain bakery opened across the street."',
|
|
20
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1 --state-id fs_STATE_ID --question "What should the shop do?" --max-choices 3',
|
|
21
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1 --state-id fs_STATE_ID --question "How do we get there?" --depends-on goal,budget',
|
|
22
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1 --state-id fs_STATE_ID --question "What does \'handle bad input\' mean here?" --into "handle bad input" --kind or',
|
|
23
|
+
'<%= config.bin %> <%= command.id %> "(@alice | @bob):maestro-1-flash" --state-file situation.txt -q "What next?" --json',
|
|
17
24
|
];
|
|
18
25
|
static flags = {
|
|
19
26
|
...BaseCommand.baseFlags,
|
|
@@ -24,12 +31,30 @@ export default class Choices extends BaseCommand {
|
|
|
24
31
|
description: 'A state (from faces state:create) as the situation. With --state, the prose is an addendum for this call only: ' +
|
|
25
32
|
'read with the state, never saved to it. Write anything that should persist with faces state:add --premise.',
|
|
26
33
|
}),
|
|
27
|
-
|
|
34
|
+
'depends-on': Flags.string({
|
|
35
|
+
description: 'With --state-id, what these options rest on, comma separated: premise keys, decision ids, option ids (opt_...) ' +
|
|
36
|
+
`and choices ids (cho_...) in the state, at most ${MAX_DEPENDS_ON}. The face is shown each of them, and the ` +
|
|
37
|
+
'premises each directly depends on, in full. The options written into the state record it.',
|
|
38
|
+
dependsOn: ['state-id'],
|
|
39
|
+
}),
|
|
40
|
+
into: Flags.string({
|
|
41
|
+
description: 'With --state-id and --question: the premise these options are for. Each option is written into the state ' +
|
|
42
|
+
'as a premise of its own (assumed, proposed by the face), and the premise rests on each through an edge of ' +
|
|
43
|
+
'--kind. Weigh them next with faces decide --weigh <premise>.',
|
|
44
|
+
dependsOn: ['state-id', 'question'],
|
|
45
|
+
}),
|
|
46
|
+
kind: Flags.string({
|
|
47
|
+
description: 'With --into: or (the default) when the options are alternatives, readings of an ambiguity or ways to do ' +
|
|
48
|
+
'it, one of which holds; and when they are facets that must all hold.',
|
|
49
|
+
options: ['or', 'and'],
|
|
50
|
+
dependsOn: ['into'],
|
|
51
|
+
}),
|
|
28
52
|
'max-choices': Flags.integer({ description: `The most options to return, 1 to ${MAX_CHOICES}. Default 8.`, min: 1, max: MAX_CHOICES }),
|
|
29
53
|
};
|
|
30
54
|
static args = {
|
|
31
|
-
|
|
32
|
-
description: 'The
|
|
55
|
+
model: Args.string({
|
|
56
|
+
description: 'The upstream model: @<face>:<maestro>, e.g. @alice:maestro-1. Another account\'s face is @owner~face; ' +
|
|
57
|
+
'a composite is "(@a | @b):maestro-1" (operators | & - ^). No model after it: on choices the upstream model answers.',
|
|
33
58
|
required: true,
|
|
34
59
|
}),
|
|
35
60
|
};
|
|
@@ -37,10 +62,11 @@ export default class Choices extends BaseCommand {
|
|
|
37
62
|
const { args, flags } = await this.parse(Choices);
|
|
38
63
|
const client = this.makeClient(flags);
|
|
39
64
|
const json = this.jsonEnabled();
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
65
|
+
const model = args.model.trim();
|
|
66
|
+
const problem = modelProblem(model, 'upstream');
|
|
67
|
+
if (problem)
|
|
68
|
+
this.error(problem);
|
|
69
|
+
const body = { model };
|
|
44
70
|
const fail = (m) => this.error(m);
|
|
45
71
|
if (flags.state !== undefined || flags['state-file'] !== undefined) {
|
|
46
72
|
const state = readStateFlags(flags, fail);
|
|
@@ -58,8 +84,23 @@ export default class Choices extends BaseCommand {
|
|
|
58
84
|
this.error('--question is empty. Leave it out to have the face propose the question.');
|
|
59
85
|
body.instructions = flags.question;
|
|
60
86
|
}
|
|
87
|
+
if (flags['depends-on'] !== undefined) {
|
|
88
|
+
try {
|
|
89
|
+
body.depends_on = parseDependsOn(flags['depends-on']);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
this.error(err instanceof Error ? err.message : String(err));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
61
95
|
if (flags['max-choices'] !== undefined)
|
|
62
96
|
body.max_choices = flags['max-choices'];
|
|
97
|
+
if (flags.into !== undefined) {
|
|
98
|
+
if (flags.into.trim() === '')
|
|
99
|
+
this.error('--into is empty: name a premise key of the state.');
|
|
100
|
+
body.into = flags.into.trim();
|
|
101
|
+
if (flags.kind)
|
|
102
|
+
body.kind = flags.kind;
|
|
103
|
+
}
|
|
63
104
|
let data;
|
|
64
105
|
try {
|
|
65
106
|
data = (await retryOnceOnWarmUp(async () => {
|
|
@@ -72,7 +113,7 @@ export default class Choices extends BaseCommand {
|
|
|
72
113
|
}
|
|
73
114
|
catch (err) {
|
|
74
115
|
if (err instanceof FacesAPIError) {
|
|
75
|
-
const hint = choicesHint(err.statusCode, err.message,
|
|
116
|
+
const hint = choicesHint(err.statusCode, err.message, model);
|
|
76
117
|
this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
|
|
77
118
|
}
|
|
78
119
|
throw err;
|
|
@@ -8,6 +8,8 @@ export default class ConversationAdd extends BaseCommand {
|
|
|
8
8
|
'premise-description': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
9
|
'premise-status': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
10
|
'premise-depends-on': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'premise-role': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
'premise-origin': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
13
|
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
14
|
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
15
|
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
2
|
import { BaseCommand } from '../../base.js';
|
|
3
3
|
import { FacesAPIError } from '../../client.js';
|
|
4
|
-
import { CONVERSATIONS_PATH, MAX_CONVERSATION_ITEMS, PREMISE_DESCRIPTION_FLAG_DESCRIPTION, PREMISE_DEPENDS_ON_FLAG_DESCRIPTION, PREMISE_FLAG_DESCRIPTION, PREMISE_STATUS_FLAG_DESCRIPTION, clientItems, conversationHint, itemLines, parsePremises, premiseLines, staleDecisionLines, statusChangeLines, } from '../../conversation.js';
|
|
4
|
+
import { CONVERSATIONS_PATH, MAX_CONVERSATION_ITEMS, PREMISE_DESCRIPTION_FLAG_DESCRIPTION, PREMISE_DEPENDS_ON_FLAG_DESCRIPTION, PREMISE_ORIGIN_FLAG_DESCRIPTION, PREMISE_ROLE_FLAG_DESCRIPTION, PREMISE_FLAG_DESCRIPTION, PREMISE_STATUS_FLAG_DESCRIPTION, clientItems, conversationHint, itemLines, parsePremises, premiseLines, staleDecisionLines, statusChangeLines, } from '../../conversation.js';
|
|
5
5
|
import { seg } from '../../utils.js';
|
|
6
6
|
export default class ConversationAdd extends BaseCommand {
|
|
7
7
|
static description = 'Add your own premises and messages to a state, without a face answering. Premises go in first, then ' +
|
|
@@ -14,6 +14,7 @@ export default class ConversationAdd extends BaseCommand {
|
|
|
14
14
|
'<%= config.bin %> <%= command.id %> fs_STATE_ID --premise rent_rises="no rise" --premise-status rent_rises=invalidated',
|
|
15
15
|
'<%= config.bin %> <%= command.id %> fs_STATE_ID --premise can_afford=false --premise-description can_afford="we can carry the rent" --premise-depends-on can_afford=rent_rises',
|
|
16
16
|
'<%= config.bin %> <%= command.id %> fs_STATE_ID --premise budget_usd=50000 --premise-description budget_usd="the most we can spend this year"',
|
|
17
|
+
'<%= config.bin %> <%= command.id %> fs_STATE_ID --premise ship_by=friday --premise-description ship_by="when we want it shipped" --premise-role ship_by=wanted --premise-origin ship_by=human',
|
|
17
18
|
'<%= config.bin %> <%= command.id %> fs_STATE_ID -m "The vendor sent their audit report."',
|
|
18
19
|
];
|
|
19
20
|
static flags = {
|
|
@@ -23,6 +24,8 @@ export default class ConversationAdd extends BaseCommand {
|
|
|
23
24
|
'premise-description': Flags.string({ description: PREMISE_DESCRIPTION_FLAG_DESCRIPTION, multiple: true }),
|
|
24
25
|
'premise-status': Flags.string({ description: PREMISE_STATUS_FLAG_DESCRIPTION, multiple: true }),
|
|
25
26
|
'premise-depends-on': Flags.string({ description: PREMISE_DEPENDS_ON_FLAG_DESCRIPTION, multiple: true }),
|
|
27
|
+
'premise-role': Flags.string({ description: PREMISE_ROLE_FLAG_DESCRIPTION, multiple: true }),
|
|
28
|
+
'premise-origin': Flags.string({ description: PREMISE_ORIGIN_FLAG_DESCRIPTION, multiple: true }),
|
|
26
29
|
};
|
|
27
30
|
static args = {
|
|
28
31
|
conversation_id: Args.string({ description: 'State id (from state:create)', required: true }),
|
|
@@ -32,7 +35,7 @@ export default class ConversationAdd extends BaseCommand {
|
|
|
32
35
|
const client = this.makeClient(flags);
|
|
33
36
|
let items;
|
|
34
37
|
try {
|
|
35
|
-
items = clientItems(flags.message, parsePremises(flags.premise, flags['premise-description'], flags['premise-status'], flags['premise-depends-on']));
|
|
38
|
+
items = clientItems(flags.message, parsePremises(flags.premise, flags['premise-description'], flags['premise-status'], flags['premise-depends-on'], flags['premise-role'], flags['premise-origin']));
|
|
36
39
|
}
|
|
37
40
|
catch (err) {
|
|
38
41
|
this.error(err instanceof Error ? err.message : String(err));
|
|
@@ -4,15 +4,15 @@ import { FacesAPIError } from '../../client.js';
|
|
|
4
4
|
import { heldDecisionError } from '../../decisions.js';
|
|
5
5
|
import { CONVERSATIONS_PATH, conversationHint } from '../../conversation.js';
|
|
6
6
|
import { retryOnceOnWarmUp, sayWarmUp, seg } from '../../utils.js';
|
|
7
|
+
import { asFace as faceAlone } from '../../model.js';
|
|
7
8
|
export default class ConversationCompact extends BaseCommand {
|
|
8
|
-
static description = 'Compact a state:
|
|
9
|
-
'
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'not charged. A compaction expires 30 days after it is written.';
|
|
9
|
+
static description = 'Compact a state: one face\'s position over the state, kept on the server under a compaction id. ' +
|
|
10
|
+
'Pass that id with --compaction on a later request with the same face. A state that takes any face ' +
|
|
11
|
+
'needs the face named. Billed on the tokens it reads and writes; on Connect and Pro it counts against ' +
|
|
12
|
+
'the plan\'s allowance. A failed compaction is not charged. A compaction expires 30 days after it is written.';
|
|
13
13
|
static examples = [
|
|
14
14
|
'<%= config.bin %> <%= command.id %> fs_STATE_ID',
|
|
15
|
-
'<%= config.bin %> <%= command.id %> fs_STATE_ID alice --json',
|
|
15
|
+
'<%= config.bin %> <%= command.id %> fs_STATE_ID @alice --json',
|
|
16
16
|
];
|
|
17
17
|
static flags = {
|
|
18
18
|
...BaseCommand.baseFlags,
|
|
@@ -20,8 +20,8 @@ export default class ConversationCompact extends BaseCommand {
|
|
|
20
20
|
static args = {
|
|
21
21
|
conversation_id: Args.string({ description: 'State id (from state:create)', required: true }),
|
|
22
22
|
face: Args.string({
|
|
23
|
-
description: 'The face to compact,
|
|
24
|
-
'state opened with one face compacts that face.',
|
|
23
|
+
description: 'The face to compact, as @face (or @owner~face), with no model after it. Needed when the state ' +
|
|
24
|
+
'takes any face; a state opened with one face compacts that face.',
|
|
25
25
|
required: false,
|
|
26
26
|
}),
|
|
27
27
|
};
|
|
@@ -29,9 +29,9 @@ export default class ConversationCompact extends BaseCommand {
|
|
|
29
29
|
const { args, flags } = await this.parse(ConversationCompact);
|
|
30
30
|
const client = this.makeClient(flags);
|
|
31
31
|
const json = this.jsonEnabled();
|
|
32
|
-
const face = args.face
|
|
33
|
-
if (face
|
|
34
|
-
this.error(`Compact a face alone,
|
|
32
|
+
const face = args.face === undefined ? undefined : faceAlone(args.face);
|
|
33
|
+
if (face && /[:/]/.test(face))
|
|
34
|
+
this.error(`Compact a face alone, with no maestro or model: ${face.split(/[:/]/)[0]}`);
|
|
35
35
|
let data;
|
|
36
36
|
try {
|
|
37
37
|
data = (await retryOnceOnWarmUp(async () => {
|
|
@@ -45,7 +45,7 @@ export default class ConversationCompact extends BaseCommand {
|
|
|
45
45
|
catch (err) {
|
|
46
46
|
if (err instanceof FacesAPIError) {
|
|
47
47
|
if (err.statusCode === 422 && !face && /takes any face/.test(err.message)) {
|
|
48
|
-
this.error(`HTTP ${err.statusCode}: ${err.message}\nName the face: faces state:compact ${args.conversation_id}
|
|
48
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}\nName the face: faces state:compact ${args.conversation_id} @<face>`);
|
|
49
49
|
}
|
|
50
50
|
const hint = conversationHint(err);
|
|
51
51
|
this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
|
|
@@ -53,16 +53,13 @@ export default class ConversationCompact extends BaseCommand {
|
|
|
53
53
|
throw err;
|
|
54
54
|
}
|
|
55
55
|
if (!json) {
|
|
56
|
-
if (typeof data.cause === 'string')
|
|
57
|
-
this.log(data.cause);
|
|
58
|
-
this.log('');
|
|
59
56
|
this.log(`compaction: ${data.compaction_id ?? '-'}`);
|
|
60
57
|
if (data.turns !== undefined)
|
|
61
58
|
this.log(`turns: ${data.turns}`);
|
|
62
59
|
if (data.expires_at)
|
|
63
60
|
this.log(`expires: ${data.expires_at}`);
|
|
64
61
|
if (data.compaction_id)
|
|
65
|
-
this.log(`\nUse it with: faces
|
|
62
|
+
this.log(`\nUse it with: faces chat:chat ${face ?? '@<face>'}:maestro-1/<model> --compaction ${data.compaction_id} -m "..."`);
|
|
66
63
|
}
|
|
67
64
|
return data;
|
|
68
65
|
}
|
|
@@ -9,6 +9,8 @@ export default class ConversationCreate extends BaseCommand {
|
|
|
9
9
|
'premise-description': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
10
|
'premise-status': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
11
|
'premise-depends-on': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
'premise-role': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
'premise-origin': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
14
|
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
15
|
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
16
|
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
2
|
import { BaseCommand } from '../../base.js';
|
|
3
3
|
import { FacesAPIError } from '../../client.js';
|
|
4
|
-
import { CONVERSATIONS_PATH, MAX_CONVERSATION_ITEMS, PREMISE_DESCRIPTION_FLAG_DESCRIPTION, PREMISE_DEPENDS_ON_FLAG_DESCRIPTION, PREMISE_FLAG_DESCRIPTION, PREMISE_STATUS_FLAG_DESCRIPTION, clientItems, conversationHint, conversationLines, parsePremises, } from '../../conversation.js';
|
|
4
|
+
import { CONVERSATIONS_PATH, MAX_CONVERSATION_ITEMS, PREMISE_DESCRIPTION_FLAG_DESCRIPTION, PREMISE_DEPENDS_ON_FLAG_DESCRIPTION, PREMISE_ORIGIN_FLAG_DESCRIPTION, PREMISE_ROLE_FLAG_DESCRIPTION, PREMISE_FLAG_DESCRIPTION, PREMISE_STATUS_FLAG_DESCRIPTION, clientItems, conversationHint, conversationLines, parsePremises, } from '../../conversation.js';
|
|
5
|
+
import { asFace as faceAlone } from '../../model.js';
|
|
5
6
|
export default class ConversationCreate extends BaseCommand {
|
|
6
7
|
static description = 'Start a state (formerly a conversation). The server keeps the situation your agent builds: premises ' +
|
|
7
8
|
'(named facts, each with a status and what it depends on), the decisions faces made, and your messages. ' +
|
|
8
|
-
'Ask a face about it with faces choices --state-id, or pass its id with --conversation on
|
|
9
|
+
'Ask a face about it with faces choices --state-id, or pass its id with --conversation on chat or decide ' +
|
|
9
10
|
'and send only what is new. Name a face and the state takes that face only; leave it out and it takes any ' +
|
|
10
11
|
'of your faces. Opening one is free. A state expires 30 days after it was last used.';
|
|
11
12
|
static examples = [
|
|
12
|
-
'<%= config.bin %> <%= command.id %> alice',
|
|
13
|
+
'<%= config.bin %> <%= command.id %> @alice',
|
|
13
14
|
'<%= config.bin %> <%= command.id %>',
|
|
14
15
|
'<%= config.bin %> <%= command.id %> --no-causes-visible --json',
|
|
15
|
-
'<%= config.bin %> <%= command.id %> alice --premise budget_usd=50000 --premise-description budget_usd="the most we can spend this year"',
|
|
16
|
+
'<%= config.bin %> <%= command.id %> @alice --premise budget_usd=50000 --premise-description budget_usd="the most we can spend this year"',
|
|
16
17
|
];
|
|
17
18
|
static flags = {
|
|
18
19
|
...BaseCommand.baseFlags,
|
|
@@ -27,23 +28,25 @@ export default class ConversationCreate extends BaseCommand {
|
|
|
27
28
|
'premise-description': Flags.string({ description: PREMISE_DESCRIPTION_FLAG_DESCRIPTION, multiple: true }),
|
|
28
29
|
'premise-status': Flags.string({ description: PREMISE_STATUS_FLAG_DESCRIPTION, multiple: true }),
|
|
29
30
|
'premise-depends-on': Flags.string({ description: PREMISE_DEPENDS_ON_FLAG_DESCRIPTION, multiple: true }),
|
|
31
|
+
'premise-role': Flags.string({ description: PREMISE_ROLE_FLAG_DESCRIPTION, multiple: true }),
|
|
32
|
+
'premise-origin': Flags.string({ description: PREMISE_ORIGIN_FLAG_DESCRIPTION, multiple: true }),
|
|
30
33
|
};
|
|
31
34
|
static args = {
|
|
32
35
|
face: Args.string({
|
|
33
|
-
description: 'The face alone:
|
|
34
|
-
'for a state that takes any of your faces.',
|
|
36
|
+
description: 'The face alone: @alice, @owner~alice, or a composite such as "(@a | @b)". No maestro or model. ' +
|
|
37
|
+
'Leave it out for a state that takes any of your faces.',
|
|
35
38
|
required: false,
|
|
36
39
|
}),
|
|
37
40
|
};
|
|
38
41
|
async run() {
|
|
39
42
|
const { args, flags } = await this.parse(ConversationCreate);
|
|
40
43
|
const client = this.makeClient(flags);
|
|
41
|
-
const face = args.face
|
|
42
|
-
if (face
|
|
43
|
-
this.error(`A state is with a face alone: ${face.
|
|
44
|
+
const face = args.face === undefined ? undefined : faceAlone(args.face);
|
|
45
|
+
if (face && /[:/]/.test(face))
|
|
46
|
+
this.error(`A state is with a face alone, with no maestro or model: ${face.split(/[:/]/)[0]}`);
|
|
44
47
|
let items;
|
|
45
48
|
try {
|
|
46
|
-
items = clientItems(flags.message, parsePremises(flags.premise, flags['premise-description'], flags['premise-status'], flags['premise-depends-on']));
|
|
49
|
+
items = clientItems(flags.message, parsePremises(flags.premise, flags['premise-description'], flags['premise-status'], flags['premise-depends-on'], flags['premise-role'], flags['premise-origin']));
|
|
47
50
|
}
|
|
48
51
|
catch (err) {
|
|
49
52
|
this.error(err instanceof Error ? err.message : String(err));
|
|
@@ -71,7 +74,7 @@ export default class ConversationCreate extends BaseCommand {
|
|
|
71
74
|
for (const line of conversationLines(data))
|
|
72
75
|
this.log(line);
|
|
73
76
|
if (data.id)
|
|
74
|
-
this.log(`\nAsk a face about it with: faces choices ${face ?? '
|
|
77
|
+
this.log(`\nAsk a face about it with: faces choices ${face ?? '@<face>'}:maestro-1 --state-id ${data.id} --question "..."`);
|
|
75
78
|
}
|
|
76
79
|
return data;
|
|
77
80
|
}
|