@letterstory/cli 0.167.0 → 0.168.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/lib/cli.mjs +21 -26
- package/lib/client.mjs +6 -4
- package/lib/commands/admin.mjs +81 -100
- package/lib/commands/auth.mjs +34 -2
- package/lib/commands/insights.mjs +7 -2
- package/lib/commands/org.mjs +1 -1
- package/lib/commands/sim.mjs +84 -5
- package/lib/oauth.mjs +16 -2
- package/package.json +1 -1
package/lib/cli.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import { resolveDocumentFlags } from "./documents.mjs";
|
|
|
15
15
|
import { checkForUpdate } from "./update-check.mjs";
|
|
16
16
|
import {
|
|
17
17
|
cmdLogin,
|
|
18
|
+
cmdSignup,
|
|
18
19
|
cmdLogout,
|
|
19
20
|
cmdConfig,
|
|
20
21
|
cmdWhoami,
|
|
@@ -74,7 +75,7 @@ import {
|
|
|
74
75
|
} from "./commands.mjs";
|
|
75
76
|
|
|
76
77
|
// Matches cli/package.json; publish-cli.yml rewrites both to the published version.
|
|
77
|
-
export const VERSION = "0.
|
|
78
|
+
export const VERSION = "0.168.0";
|
|
78
79
|
|
|
79
80
|
/** The exit code for a gate refusal (CARD_REQUIRED, PAYMENT_FAILED, OUT_OF_TOKENS): 1 is a plain error. */
|
|
80
81
|
export const EXIT_PAYMENT_REQUIRED = 3;
|
|
@@ -158,11 +159,6 @@ export const BOOLEAN_FLAGS = new Set([
|
|
|
158
159
|
"enroll",
|
|
159
160
|
"unenroll",
|
|
160
161
|
"clean-slate",
|
|
161
|
-
// admin recipes list --tab --enabled-only, save --enable|--disable, import --retire-missing
|
|
162
|
-
"enabled-only",
|
|
163
|
-
"enable",
|
|
164
|
-
"disable",
|
|
165
|
-
"retire-missing",
|
|
166
162
|
// admin crm record-outcome --draft
|
|
167
163
|
"draft",
|
|
168
164
|
// admin crm reach-outs --fresh
|
|
@@ -430,6 +426,9 @@ Auth:
|
|
|
430
426
|
login [--url <url>] Sign in via your browser (default url: https://app.letterstory.com)
|
|
431
427
|
login --device [--url <url>] Sign in with one link, opened in any browser (for agents and remote shells)
|
|
432
428
|
login --key <ls_…> [--url <url>] Save a static API key instead (for CI/automation)
|
|
429
|
+
signup --email <work email> [--agent <name>] [--url <url>]
|
|
430
|
+
Sign someone up with no account yet: Letter emails them a link,
|
|
431
|
+
they confirm in a browser, and this saves the new account's session
|
|
433
432
|
logout Forget saved credentials (revokes an OAuth session, if any)
|
|
434
433
|
config Show the resolved url + credential source
|
|
435
434
|
|
|
@@ -888,28 +887,22 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
|
|
|
888
887
|
read-only SQL across every org; --sql prints
|
|
889
888
|
the queries behind the answer. Needs the
|
|
890
889
|
fleet:query capability on the staff key.
|
|
891
|
-
admin recipes list
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
vocab says what
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
writes nothing; --retire-missing retires every enabled
|
|
903
|
-
recipe of the file's tabs it leaves out. Exits 1 if any
|
|
904
|
-
row failed.
|
|
905
|
-
admin recipes save [<id>] [--file <recipe.json>] [--tab plan|build|fix] [--name …] [--look-at …] [--when-to-use …]
|
|
906
|
-
[--when-not-to-use …] [--example …] [--moves-json <json>] [--primitives a,b|none] [--outcomes a,b|none]
|
|
907
|
-
[--company-types a,b|none] [--enable|--disable] [--position n]
|
|
890
|
+
admin recipes list | show <id|name> | vocab | stats Recipes: Letter's one library of direction for
|
|
891
|
+
Letterpress on Plan, Build and Fix (/superadmin/recipes),
|
|
892
|
+
five fields each: name, recipe, when to use, when not to
|
|
893
|
+
use, weight. vocab says what each field means; stats how
|
|
894
|
+
each recipe's suggestions fare. Needs recipes:read.
|
|
895
|
+
admin recipes export [--out recipes.json] The library as a file import reads back.
|
|
896
|
+
admin recipes import <file> [--dry-run] Write a library in one call: each recipe matched by id,
|
|
897
|
+
else name, then changed or created. --dry-run writes
|
|
898
|
+
nothing. Exits 1 if any row failed.
|
|
899
|
+
admin recipes save [<id>] [--file <recipe.json>] [--name …] [--recipe …] [--when-to-use …]
|
|
900
|
+
[--when-not-to-use …] [--weight 1..10]
|
|
908
901
|
Create one (no id) or change one. Needs recipes:write.
|
|
909
|
-
admin recipes delete <id> --yes Delete for good
|
|
902
|
+
admin recipes delete <id> --yes Delete for good.
|
|
910
903
|
admin letterpress status [--customers] Letterpress as it runs now: per lens its mode, bar, recipes,
|
|
911
904
|
runs, model and prompt hash, how often the shadow agreed,
|
|
912
|
-
how runs grounded (
|
|
905
|
+
how runs grounded (a recipe / none). Needs recipes:read.
|
|
913
906
|
admin letterpress gaps [--customers] The gaps the numbers show, each with the one call that
|
|
914
907
|
addresses it, pre-filled. Needs recipes:read.
|
|
915
908
|
admin letterpress replay <run-id> A Build or Fix run through today's checks and settings, no
|
|
@@ -922,7 +915,7 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
|
|
|
922
915
|
judgement's weights per ask, each lens's bar and read
|
|
923
916
|
budget, each surface's ask and guidance, the dismissal
|
|
924
917
|
window. Needs recipes:read.
|
|
925
|
-
admin letterpress set <weights.<ask>.<reading>|lenses.<lens>.bar.<reading>|lenses.<lens>.bar|lenses.<lens>.research.turns|lenses.<lens>.research.ms|asks.<lens>.ask|asks.<lens>.guidance|dismissals.block_days> <value>
|
|
918
|
+
admin letterpress set <weights.<ask>.<reading>|lenses.<lens>.bar.<reading>|lenses.<lens>.bar|lenses.<lens>.research.turns|lenses.<lens>.research.ms|asks.<lens>.ask|asks.<lens>.guidance|dismissals.block_days|explore.ask|explore.research.turns|explore.every_days> <value>
|
|
926
919
|
Change one weight, one bar, or a lens's ask and guidance (the
|
|
927
920
|
opinions Letterpress chooses by, as staff's words); the version
|
|
928
921
|
bumps and the previous body is kept. Needs recipes:write.
|
|
@@ -1473,6 +1466,7 @@ Insights:
|
|
|
1473
1466
|
Measure → Reads: AI engines and people reading your sites, counted one way
|
|
1474
1467
|
insights questions [--period 14d|30d|90d] Measure → Questions: every question we ask, named / share / change / cited
|
|
1475
1468
|
insights pages [--period 14d|30d|90d] [--site own|phantoms|<key>] Measure → Pages: your pages AI answers cited, won questions first
|
|
1469
|
+
insights mentions [--site phantoms|<key>]... Measure → Pages → Naming you: which posts on your phantom sites name you
|
|
1476
1470
|
insights competitors [--period 14d|30d|90d] GEO → Competitors: share of mentions per brand, is it moving, by engine/question
|
|
1477
1471
|
insights question <key> [--period 14d|30d|90d] [--filter all|named_you|rival_not_you|no_one] [--limit n]
|
|
1478
1472
|
One By-question row: the wordings asked and the AI answers
|
|
@@ -1666,6 +1660,7 @@ then ~/.letterstory/config.json.`;
|
|
|
1666
1660
|
|
|
1667
1661
|
const CLIENT_COMMANDS = {
|
|
1668
1662
|
login: cmdLogin,
|
|
1663
|
+
signup: cmdSignup,
|
|
1669
1664
|
logout: cmdLogout,
|
|
1670
1665
|
config: cmdConfig,
|
|
1671
1666
|
whoami: cmdWhoami,
|
package/lib/client.mjs
CHANGED
|
@@ -127,8 +127,10 @@ export class LetterstoryClient {
|
|
|
127
127
|
// needs no prior initialize handshake. When authenticated via OAuth, a single
|
|
128
128
|
// 401 triggers one silent refresh-and-retry before giving up — a static key
|
|
129
129
|
// has no such recovery, since a rejected key is just wrong.
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
// `keyless`: a public tool (start_signup, finish_signup) is called with no credentials at all,
|
|
131
|
+
// by someone who has no account yet.
|
|
132
|
+
async rpc(method, params, { _retried = false, keyless = false } = {}) {
|
|
133
|
+
const authHeaders = keyless ? {} : this.authHeaders();
|
|
132
134
|
if (!authHeaders) {
|
|
133
135
|
throw new CliError(
|
|
134
136
|
`Not logged in. Run \`${this.bin} login\` (opens your browser) or \`${this.bin} login --key <ls_…>\`.`
|
|
@@ -255,8 +257,8 @@ export class LetterstoryClient {
|
|
|
255
257
|
// Invoke a tool and unwrap the MCP content envelope. A tool-level failure arrives
|
|
256
258
|
// as { isError: true, content:[{text}] } on HTTP 200 (e.g. a capability the key
|
|
257
259
|
// lacks, or a validation error) — surface that text as a CliError.
|
|
258
|
-
async callTool(name, args = {}) {
|
|
259
|
-
const result = await this.rpc("tools/call", { name, arguments: args });
|
|
260
|
+
async callTool(name, args = {}, { keyless = false } = {}) {
|
|
261
|
+
const result = await this.rpc("tools/call", { name, arguments: args }, { keyless });
|
|
260
262
|
const text = result?.content?.[0]?.text ?? "";
|
|
261
263
|
if (result?.isError)
|
|
262
264
|
throw new CliError(text || `Tool ${name} failed`, { code: result.structuredContent?.code ?? null });
|
package/lib/commands/admin.mjs
CHANGED
|
@@ -4932,58 +4932,23 @@ async function cmdAdminRepublish(ctx) {
|
|
|
4932
4932
|
|
|
4933
4933
|
const RECIPES = "/api/superadmin/recipes";
|
|
4934
4934
|
/** The fields a recipe file carries: what import_recipes reads back. */
|
|
4935
|
-
const RECIPE_FILE_FIELDS = [
|
|
4936
|
-
"id",
|
|
4937
|
-
"name",
|
|
4938
|
-
"tab",
|
|
4939
|
-
"outcomes",
|
|
4940
|
-
"company_types",
|
|
4941
|
-
"fits_when",
|
|
4942
|
-
"look_at",
|
|
4943
|
-
"when_to_use",
|
|
4944
|
-
"when_not_to_use",
|
|
4945
|
-
"example",
|
|
4946
|
-
"impact",
|
|
4947
|
-
"moves",
|
|
4948
|
-
"primitives",
|
|
4949
|
-
"enabled",
|
|
4950
|
-
"position",
|
|
4951
|
-
];
|
|
4935
|
+
const RECIPE_FILE_FIELDS = ["id", "name", "recipe", "when_to_use", "when_not_to_use", "weight"];
|
|
4952
4936
|
const RECIPES_USAGE =
|
|
4953
|
-
"Usage: admin recipes list
|
|
4937
|
+
"Usage: admin recipes list | show <id|name> | vocab | stats | export [--out <file>] | import <file> [--dry-run] | save [<id>] [--file <recipe.json>] [--name …] [--recipe …] [--when-to-use …] [--when-not-to-use …] [--weight 1..10] | delete <id> --yes";
|
|
4954
4938
|
|
|
4955
4939
|
const recipeForFile = (r) => Object.fromEntries(RECIPE_FILE_FIELDS.map((k) => [k, r[k]]));
|
|
4956
4940
|
|
|
4957
4941
|
function recipeLine(r) {
|
|
4958
|
-
|
|
4959
|
-
r.outcomes?.length ? `outcomes ${r.outcomes.join(",")}` : "every outcome",
|
|
4960
|
-
r.company_types?.length ? `kinds ${r.company_types.join(",")}` : "every kind",
|
|
4961
|
-
r.tab === "plan"
|
|
4962
|
-
? `${r.moves?.length ?? 0} moves · stands up ${r.primitives?.length ? r.primitives.join(",") : "nothing"}`
|
|
4963
|
-
: null,
|
|
4964
|
-
]
|
|
4965
|
-
.filter(Boolean)
|
|
4966
|
-
.join(" · ");
|
|
4967
|
-
return `${String(r.position).padStart(4)} ${r.enabled ? "on " : "off"} ${r.tab.padEnd(5)} ${r.name} v${r.version} [${scope}] ${r.id}`;
|
|
4942
|
+
return `${String(r.weight).padStart(2)}/10 ${r.name} ${r.id}`;
|
|
4968
4943
|
}
|
|
4969
4944
|
|
|
4970
4945
|
function recipeDetail(r) {
|
|
4971
4946
|
return [
|
|
4972
|
-
`${r.name}
|
|
4973
|
-
`
|
|
4974
|
-
`
|
|
4975
|
-
`
|
|
4976
|
-
|
|
4977
|
-
` look at: ${r.look_at || "—"}`,
|
|
4978
|
-
` when to use: ${r.when_to_use || "—"}`,
|
|
4979
|
-
` when not to use: ${r.when_not_to_use || "—"}`,
|
|
4980
|
-
` example: ${r.example || "—"}`,
|
|
4981
|
-
r.tab === "plan"
|
|
4982
|
-
? ` moves:\n${(r.moves ?? []).map((m) => ` ${m.id}${m.stage ? ` · ${m.stage}` : ""}${m.after?.length ? ` · after ${m.after.join(",")}` : ""}${m.recommend ? " · recommend" : ""}${m.keep ? " · keep" : ""}${m.optional ? " · optional" : ""}${m.required ? " · required" : ""}${m.why ? ` · "${m.why}"` : ""}`).join("\n")}`
|
|
4983
|
-
: null,
|
|
4984
|
-
]
|
|
4985
|
-
.filter(Boolean)
|
|
4986
|
-
.join("\n");
|
|
4947
|
+
`${r.name} weight ${r.weight}/10 ${r.id}`,
|
|
4948
|
+
` recipe: ${r.recipe || "—"}`,
|
|
4949
|
+
` when to use: ${r.when_to_use || "—"}`,
|
|
4950
|
+
` when not to use: ${r.when_not_to_use || "—"}`,
|
|
4951
|
+
].join("\n");
|
|
4987
4952
|
}
|
|
4988
4953
|
|
|
4989
4954
|
function readJson(path) {
|
|
@@ -5002,53 +4967,28 @@ function readRecipesFile(path) {
|
|
|
5002
4967
|
return recipes.map((r) => compact(recipeForFile(r)));
|
|
5003
4968
|
}
|
|
5004
4969
|
|
|
5005
|
-
/** A list flag for save: `a,b` (repeatable), `none` to clear it; a bare flag is a mistake. */
|
|
5006
|
-
function recipeListFlag(flags, name) {
|
|
5007
|
-
const v = flags[name];
|
|
5008
|
-
if (v === undefined) return undefined;
|
|
5009
|
-
if (v === true) throw new CliError(`--${name} needs a value: a,b or none`);
|
|
5010
|
-
return flagStr(v) === "none" ? [] : flagCsv(v);
|
|
5011
|
-
}
|
|
5012
|
-
|
|
5013
4970
|
/** The fields `admin recipes save` sets: one recipe from --file (or show --json's output), then flags over it. */
|
|
5014
4971
|
function recipeFromFlags(flags) {
|
|
5015
4972
|
const path = flagStr(flags.file);
|
|
5016
4973
|
const parsed = path ? readJson(path) : {};
|
|
5017
|
-
const base = parsed?.recipe
|
|
4974
|
+
const base = parsed?.recipe && typeof parsed.recipe === "object" ? parsed.recipe : parsed;
|
|
5018
4975
|
if (!base || typeof base !== "object" || Array.isArray(base) || Array.isArray(base.recipes)) {
|
|
5019
4976
|
throw new CliError("--file holds one recipe object; use admin recipes import for several");
|
|
5020
4977
|
}
|
|
5021
|
-
const movesFlag = flagStr(flags["moves-json"]);
|
|
5022
|
-
let moves;
|
|
5023
|
-
if (movesFlag !== undefined) {
|
|
5024
|
-
try {
|
|
5025
|
-
moves = JSON.parse(movesFlag);
|
|
5026
|
-
} catch (err) {
|
|
5027
|
-
throw new CliError(`--moves-json holds a JSON array of moves: ${err.message}`);
|
|
5028
|
-
}
|
|
5029
|
-
}
|
|
5030
4978
|
return compact({
|
|
5031
4979
|
...compact(recipeForFile(base)),
|
|
5032
4980
|
name: flagStr(flags.name),
|
|
5033
|
-
|
|
5034
|
-
look_at: flagStr(flags["look-at"]),
|
|
4981
|
+
recipe: flagStr(flags.recipe),
|
|
5035
4982
|
when_to_use: flagStr(flags["when-to-use"]),
|
|
5036
4983
|
when_not_to_use: flagStr(flags["when-not-to-use"]),
|
|
5037
|
-
|
|
5038
|
-
example: flagStr(flags.example),
|
|
5039
|
-
moves,
|
|
5040
|
-
primitives: recipeListFlag(flags, "primitives"),
|
|
5041
|
-
outcomes: recipeListFlag(flags, "outcomes"),
|
|
5042
|
-
company_types: recipeListFlag(flags, "company-types"),
|
|
5043
|
-
enabled: flagBool(flags.disable) ? false : flagBool(flags.enable) ? true : undefined,
|
|
5044
|
-
position: flagNum(flags.position),
|
|
4984
|
+
weight: flagNum(flags.weight),
|
|
5045
4985
|
});
|
|
5046
4986
|
}
|
|
5047
4987
|
|
|
5048
4988
|
const ENGINE = "/api/superadmin/engine-settings";
|
|
5049
4989
|
const LETTERPRESS = "/api/superadmin/letterpress";
|
|
5050
4990
|
const ENGINE_USAGE =
|
|
5051
|
-
"Usage: admin letterpress status | gaps | replay <run-id> | mark <run-id> <item-id> <right|weak|wrong|lead|clear> [--note …] | settings | set <weights.<ask>.<reading>|lenses.<lens>.bar.<reading>|lenses.<lens>.bar|lenses.<lens>.research.turns|lenses.<lens>.research.ms|asks.<lens>.ask|asks.<lens>.guidance|dismissals.block_days> <value>";
|
|
4991
|
+
"Usage: admin letterpress status | gaps | replay <run-id> | mark <run-id> <item-id> <right|weak|wrong|lead|clear> [--note …] | settings | set <weights.<ask>.<reading>|lenses.<lens>.bar.<reading>|lenses.<lens>.bar|lenses.<lens>.research.turns|lenses.<lens>.research.ms|asks.<lens>.ask|asks.<lens>.guidance|dismissals.block_days|explore.ask|explore.research.turns|explore.research.ms|explore.every_days> <value>";
|
|
5052
4992
|
|
|
5053
4993
|
/** One number of the settings from a dotted path and a value: the PUT body save_engine_settings reads. */
|
|
5054
4994
|
function engineSettingsPatch(path, value) {
|
|
@@ -5060,6 +5000,17 @@ function engineSettingsPatch(path, value) {
|
|
|
5060
5000
|
}
|
|
5061
5001
|
if (parts[0] === "asks" && (parts[2] === "ask" || parts[2] === "guidance") && parts.length === 3)
|
|
5062
5002
|
return { asks: { [parts[1]]: { [parts[2]]: String(value) } } };
|
|
5003
|
+
if (parts[0] === "explore" && parts[1] === "ask" && parts.length === 2) return { explore: { ask: String(value) } };
|
|
5004
|
+
if (parts[0] === "explore" && parts[1] === "research" && parts.length === 3) {
|
|
5005
|
+
const n = Number(value);
|
|
5006
|
+
if (!Number.isFinite(n)) throw new CliError(`${path}: a number`);
|
|
5007
|
+
return { explore: { research: { [parts[2]]: n } } };
|
|
5008
|
+
}
|
|
5009
|
+
if (parts[0] === "explore" && parts[1] === "every_days" && parts.length === 2) {
|
|
5010
|
+
const n = Number(value);
|
|
5011
|
+
if (!Number.isInteger(n)) throw new CliError(`${path}: a whole number of days`);
|
|
5012
|
+
return { explore: { every_days: n } };
|
|
5013
|
+
}
|
|
5063
5014
|
if (parts[0] === "dismissals" && parts[1] === "block_days" && parts.length === 2) {
|
|
5064
5015
|
const n = Number(value);
|
|
5065
5016
|
if (!Number.isInteger(n)) throw new CliError(`${path}: a whole number of days`);
|
|
@@ -5106,7 +5057,19 @@ function engineSettingsText(r) {
|
|
|
5106
5057
|
const dismissals = s.dismissals
|
|
5107
5058
|
? `a dismissal blocks for ${s.dismissals.block_days} days, then is dated history`
|
|
5108
5059
|
: null;
|
|
5109
|
-
|
|
5060
|
+
const explore = s.explore
|
|
5061
|
+
? `explore every ${s.explore.every_days} days, ${s.explore.research.turns} reads, ${Math.round(s.explore.research.ms / 1000)}s: ${s.explore.ask}`
|
|
5062
|
+
: null;
|
|
5063
|
+
return [
|
|
5064
|
+
head,
|
|
5065
|
+
...lenses,
|
|
5066
|
+
...(dismissals ? [dismissals] : []),
|
|
5067
|
+
...(explore ? [explore] : []),
|
|
5068
|
+
"",
|
|
5069
|
+
...weights,
|
|
5070
|
+
"",
|
|
5071
|
+
...asks,
|
|
5072
|
+
].join("\n");
|
|
5110
5073
|
}
|
|
5111
5074
|
|
|
5112
5075
|
/**
|
|
@@ -5130,7 +5093,7 @@ async function cmdAdminLetterpress(ctx) {
|
|
|
5130
5093
|
`Letterpress, last ${s.days} days (settings v${s.settings.version}${s.settings.defaults_only ? ", defaults" : ""}, questions v${s.judgement_version})`,
|
|
5131
5094
|
...s.lenses.map(
|
|
5132
5095
|
(l) =>
|
|
5133
|
-
`${l.lens.padEnd(6)} ${l.mode.padEnd(6)} ${String(l.runs).padStart(3)} runs recipes ${l.recipes
|
|
5096
|
+
`${l.lens.padEnd(6)} ${l.mode.padEnd(6)} ${String(l.runs).padStart(3)} runs recipes ${l.recipes} followed a recipe ${l.followed.recipe} / none ${l.followed.none}${l.shadow ? ` shadow: top same ${l.shadow.top_same}/${l.shadow.runs}, order same ${l.shadow.order_same}` : ""}${l.drift?.pairs ? ` drift ${l.drift.changed}/${l.drift.pairs}` : ""}${l.prompt_hash ? ` prompt ${l.prompt_hash}` : ""}${l.model ? ` ${l.model}` : ""}`
|
|
5134
5097
|
),
|
|
5135
5098
|
s.surfaces.length
|
|
5136
5099
|
? `asks from: ${s.surfaces.map((x) => `${x.surface} ${x.runs}`).join(", ")}`
|
|
@@ -5211,7 +5174,7 @@ async function cmdAdminLetterpress(ctx) {
|
|
|
5211
5174
|
|
|
5212
5175
|
/**
|
|
5213
5176
|
* `admin recipes …` — the recipes page (/superadmin/recipes) for an agent: Letter's one library
|
|
5214
|
-
* of direction for Letterpress on Plan, Build and Fix
|
|
5177
|
+
* of direction for Letterpress on Plan, Build and Fix, five fields each. The loop for building it out is
|
|
5215
5178
|
* `vocab` (what a recipe can say) → `export --out recipes.json` → edit → `import recipes.json
|
|
5216
5179
|
* --dry-run` → `import recipes.json`; `stats` says how each recipe's suggestions fare. Reads need
|
|
5217
5180
|
* recipes:read on the staff key, writes recipes:write; every write is recorded as the key holder's.
|
|
@@ -5219,9 +5182,7 @@ async function cmdAdminLetterpress(ctx) {
|
|
|
5219
5182
|
async function cmdAdminRecipes(ctx) {
|
|
5220
5183
|
const { flags, positionals, io } = ctx;
|
|
5221
5184
|
const sub = positionals[0];
|
|
5222
|
-
const
|
|
5223
|
-
const all = async () =>
|
|
5224
|
-
(await staffRequest(ctx, "GET", tab ? `${RECIPES}?tab=${encodeURIComponent(tab)}` : RECIPES)).recipes ?? [];
|
|
5185
|
+
const all = async () => (await staffRequest(ctx, "GET", RECIPES)).recipes ?? [];
|
|
5225
5186
|
switch (sub) {
|
|
5226
5187
|
case "stats": {
|
|
5227
5188
|
const result = await staffRequest(ctx, "GET", `${RECIPES}/stats`);
|
|
@@ -5230,7 +5191,7 @@ async function cmdAdminRecipes(ctx) {
|
|
|
5230
5191
|
? r.stats
|
|
5231
5192
|
.map(
|
|
5232
5193
|
(s) =>
|
|
5233
|
-
`${String(s.shown).padStart(5)} shown ${String(s.dismissed).padStart(4)} dismissed ${String(s.resolved ?? 0).padStart(4)} resolved ${String(s.built ?? 0).padStart(3)} built ${s.
|
|
5194
|
+
`${String(s.shown).padStart(5)} shown ${String(s.dismissed).padStart(4)} dismissed ${String(s.resolved ?? 0).padStart(4)} resolved ${String(s.built ?? 0).padStart(3)} built ${s.lens.padEnd(5)} ${s.recipe}${s.reasons.length ? `\n why: ${s.reasons.slice(0, 3).join(" · ")}` : ""}`
|
|
5234
5195
|
)
|
|
5235
5196
|
.join("\n")
|
|
5236
5197
|
: "No suggestions from the passes yet."
|
|
@@ -5238,7 +5199,7 @@ async function cmdAdminRecipes(ctx) {
|
|
|
5238
5199
|
return 0;
|
|
5239
5200
|
}
|
|
5240
5201
|
case "list": {
|
|
5241
|
-
const recipes =
|
|
5202
|
+
const recipes = await all();
|
|
5242
5203
|
printResult(io, flags, { recipes }, (r) =>
|
|
5243
5204
|
r.recipes.length ? r.recipes.map(recipeLine).join("\n") : "No recipes yet."
|
|
5244
5205
|
);
|
|
@@ -5257,23 +5218,11 @@ async function cmdAdminRecipes(ctx) {
|
|
|
5257
5218
|
[
|
|
5258
5219
|
...r.how_recipes_are_read.map((line) => `· ${line}`),
|
|
5259
5220
|
"",
|
|
5260
|
-
"
|
|
5261
|
-
...r.
|
|
5221
|
+
"Lenses (each reads the whole library):",
|
|
5222
|
+
...r.lenses.map((t) => ` ${t.id}: reads ${t.reads}`),
|
|
5262
5223
|
"",
|
|
5263
5224
|
"Fields:",
|
|
5264
5225
|
...r.fields.map((f) => ` ${f.name}: ${f.description}`),
|
|
5265
|
-
"",
|
|
5266
|
-
"A move's fields (plan):",
|
|
5267
|
-
...r.move_fields.map((f) => ` ${f.name}: ${f.description}`),
|
|
5268
|
-
"",
|
|
5269
|
-
`Actions a move may name: ${r.actions.join(", ")}`,
|
|
5270
|
-
`Evidence the moves can make a plan read: ${r.evidence.join(", ")}`,
|
|
5271
|
-
"",
|
|
5272
|
-
"Outcomes:",
|
|
5273
|
-
...r.outcomes.map((g) => ` ${g.id}${g.available ? "" : " (not available yet)"}: ${g.brief}`),
|
|
5274
|
-
"",
|
|
5275
|
-
`Company types: ${r.company_types.map((t) => `${t.id} (${t.label})`).join(", ")}`,
|
|
5276
|
-
`Primitives: ${r.primitives.map((p) => `${p.id} (${p.label})`).join(", ")}`,
|
|
5277
5226
|
].join("\n")
|
|
5278
5227
|
);
|
|
5279
5228
|
return 0;
|
|
@@ -5292,13 +5241,11 @@ async function cmdAdminRecipes(ctx) {
|
|
|
5292
5241
|
const result = await staffPost(ctx, `${RECIPES}/import`, {
|
|
5293
5242
|
recipes: readRecipesFile(path),
|
|
5294
5243
|
dry_run: flagBool(flags["dry-run"]),
|
|
5295
|
-
retire_missing: flagBool(flags["retire-missing"]),
|
|
5296
5244
|
});
|
|
5297
5245
|
const verb = {
|
|
5298
5246
|
create: "create",
|
|
5299
5247
|
update: "update",
|
|
5300
5248
|
unchanged: "same ",
|
|
5301
|
-
retire: "retire",
|
|
5302
5249
|
failed: "FAILED",
|
|
5303
5250
|
};
|
|
5304
5251
|
printResult(io, flags, result, (r) =>
|
|
@@ -5307,7 +5254,7 @@ async function cmdAdminRecipes(ctx) {
|
|
|
5307
5254
|
(row) =>
|
|
5308
5255
|
`${verb[row.action] ?? row.action} ${row.name}${row.changed.length && row.action !== "create" ? ` (${row.changed.join(", ")})` : ""}${row.error ? ` → ${row.error}` : ""}`
|
|
5309
5256
|
),
|
|
5310
|
-
`${r.dry_run ? "Would create" : "Created"} ${r.counts.created}, ${r.dry_run ? "update" : "updated"} ${r.counts.updated}
|
|
5257
|
+
`${r.dry_run ? "Would create" : "Created"} ${r.counts.created}, ${r.dry_run ? "update" : "updated"} ${r.counts.updated}; ${r.counts.unchanged} unchanged, ${r.counts.failed} failed.${r.dry_run ? " Nothing was written (--dry-run)." : ""}`,
|
|
5311
5258
|
].join("\n")
|
|
5312
5259
|
);
|
|
5313
5260
|
return result.counts?.failed ? 1 : 0;
|
|
@@ -5326,9 +5273,7 @@ async function cmdAdminRecipes(ctx) {
|
|
|
5326
5273
|
case "delete": {
|
|
5327
5274
|
const id = requirePositional(positionals, 1, "id");
|
|
5328
5275
|
if (!flagBool(flags.yes)) {
|
|
5329
|
-
io.error(
|
|
5330
|
-
`Re-run with --yes to delete for good: ${ctx.bin} admin recipes delete ${id} --yes (save --disable retires one and keeps it)`
|
|
5331
|
-
);
|
|
5276
|
+
io.error(`Re-run with --yes to delete for good: ${ctx.bin} admin recipes delete ${id} --yes`);
|
|
5332
5277
|
return 1;
|
|
5333
5278
|
}
|
|
5334
5279
|
const result = await staffRequest(ctx, "DELETE", `${RECIPES}/${encodeURIComponent(id)}`);
|
|
@@ -5351,6 +5296,8 @@ const LAGO_USAGE = `Usage: admin billing lago <command>
|
|
|
5351
5296
|
payments retry <lago-invoice-id> charge one failed invoice again now
|
|
5352
5297
|
payments run [--dry] one pass of the failed-payment loop now (--dry: report only)
|
|
5353
5298
|
signups [--status open|card_saved|provisioned|paid|abandoned|canceled] new paying orgs on their way onto Lago
|
|
5299
|
+
debt <org-id> what an org owes from an ended plan (it blocks the org's own re-signup)
|
|
5300
|
+
debt clear <org-id> --why "…" forgive it, kept with who and why, so the org can sign up again on its own
|
|
5354
5301
|
signups end <org-id> --why "…" end an org's signup in flight (not yet provisioned), so one on other terms can open
|
|
5355
5302
|
cap <org-id> <dollars|off> [--why "…"] set an account's monthly spend cap on overage (off: no cap)
|
|
5356
5303
|
cancel <org-id> --why "…" --yes end an account's Lago plan now (its plan fee refunded in its first month, once per org)
|
|
@@ -5671,6 +5618,40 @@ async function cmdAdminBilling(ctx) {
|
|
|
5671
5618
|
printResult(io, flags, result);
|
|
5672
5619
|
return 0;
|
|
5673
5620
|
}
|
|
5621
|
+
case "debt": {
|
|
5622
|
+
const usd = (cents) => `$${(cents / 100).toFixed(2)}`;
|
|
5623
|
+
if (positionals[2] === "clear") {
|
|
5624
|
+
const orgId = requirePositional(positionals, 3, "org-id");
|
|
5625
|
+
if (!flagStr(flags.why))
|
|
5626
|
+
throw new CliError('Say why: debt clear <org-id> --why "…" (it is kept with the account).');
|
|
5627
|
+
const result = await staffRequest(ctx, "POST", `${LAGO}/debt`, { orgId, why: flagStr(flags.why) });
|
|
5628
|
+
printResult(
|
|
5629
|
+
io,
|
|
5630
|
+
flags,
|
|
5631
|
+
result,
|
|
5632
|
+
(r) => `Debt cleared: ${usd(r.clearedCents)} forgiven. The org can sign up again on its own.`
|
|
5633
|
+
);
|
|
5634
|
+
return 0;
|
|
5635
|
+
}
|
|
5636
|
+
const orgId = requirePositional(positionals, 2, "org-id");
|
|
5637
|
+
const result = await staffRequest(ctx, "GET", `${LAGO}/debt?orgId=${encodeURIComponent(orgId)}`);
|
|
5638
|
+
printResult(io, flags, result, (r) =>
|
|
5639
|
+
[
|
|
5640
|
+
r.owedCents > 0
|
|
5641
|
+
? `Owes ${usd(r.owedCents)} from an earlier plan: its own re-signup is refused until staff clear it.`
|
|
5642
|
+
: "Owes nothing from an earlier plan.",
|
|
5643
|
+
...r.items.map(
|
|
5644
|
+
(i) => ` ${i.invoice ?? "first invoice (voided by its cancel)"} ${usd(i.cents)} ${i.state}`
|
|
5645
|
+
),
|
|
5646
|
+
...(r.cleared
|
|
5647
|
+
? [
|
|
5648
|
+
`Last cleared ${r.cleared.at.slice(0, 10)} by ${r.cleared.by}: ${usd(r.cleared.cents)} — ${r.cleared.reason}`,
|
|
5649
|
+
]
|
|
5650
|
+
: []),
|
|
5651
|
+
].join("\n")
|
|
5652
|
+
);
|
|
5653
|
+
return 0;
|
|
5654
|
+
}
|
|
5674
5655
|
case "changes": {
|
|
5675
5656
|
if (positionals[2] === "cancel") {
|
|
5676
5657
|
const orgId = requirePositional(positionals, 3, "org-id");
|
package/lib/commands/auth.mjs
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
// calling get_company_info, same probe `login` uses to verify a fresh key.
|
|
8
8
|
|
|
9
9
|
import { LetterstoryClient, resolveConfig, writeConfigFile, clearConfigFile, configPath } from "../client.mjs";
|
|
10
|
-
import { flagStr } from "./shared.mjs";
|
|
11
|
-
import { browserLogin, deviceLogin, revokeToken } from "../oauth.mjs";
|
|
10
|
+
import { argsFromFlags, flagStr } from "./shared.mjs";
|
|
11
|
+
import { browserLogin, deviceLogin, pollDeviceToken, revokeToken } from "../oauth.mjs";
|
|
12
12
|
|
|
13
13
|
export async function cmdLogin(ctx) {
|
|
14
14
|
const { flags, io } = ctx;
|
|
@@ -40,6 +40,11 @@ export async function cmdLogin(ctx) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const tokens = flags.device ? await deviceLogin({ url, io }) : await browserLogin({ url, io });
|
|
43
|
+
return saveSession({ tokens, url, flags, io });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// An OAuth session from /token, saved the way every login saves it, then checked with one call.
|
|
47
|
+
async function saveSession({ tokens, url, flags, io }) {
|
|
43
48
|
const oauth = {
|
|
44
49
|
access_token: tokens.access_token,
|
|
45
50
|
refresh_token: tokens.refresh_token,
|
|
@@ -60,6 +65,33 @@ export async function cmdLogin(ctx) {
|
|
|
60
65
|
return 0;
|
|
61
66
|
}
|
|
62
67
|
|
|
68
|
+
export const ARGS = {
|
|
69
|
+
start_signup: {
|
|
70
|
+
email: { flag: "email", required: true },
|
|
71
|
+
agent: "agent",
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// signup: an agent signs its user up (docs/architecture/agent-signup.md). No key: `start_signup`
|
|
76
|
+
// emails the person a link, they confirm in a browser, and this polls for the new account's token
|
|
77
|
+
// and saves it like `login --device`.
|
|
78
|
+
export async function cmdSignup(ctx) {
|
|
79
|
+
const { flags, io } = ctx;
|
|
80
|
+
const url = flagStr(flags.url) || resolveConfig({}).url;
|
|
81
|
+
const client = new LetterstoryClient({ url });
|
|
82
|
+
const start = await client.callTool("start_signup", argsFromFlags(ARGS.start_signup, flags), { keyless: true });
|
|
83
|
+
io.log(`Letter emailed ${start.email} a link to create their account.`);
|
|
84
|
+
io.log(`Ask them to open it and confirm. Code: ${start.user_code} (the page shows the same one)`);
|
|
85
|
+
io.log(`${start.free_tokens.note} The confirmation page shows what this account gets.`);
|
|
86
|
+
io.log("Waiting for them to confirm…");
|
|
87
|
+
const tokens = await pollDeviceToken({
|
|
88
|
+
base: url.replace(/\/+$/, ""),
|
|
89
|
+
start,
|
|
90
|
+
again: "Run `signup` again.",
|
|
91
|
+
});
|
|
92
|
+
return saveSession({ tokens, url, flags, io });
|
|
93
|
+
}
|
|
94
|
+
|
|
63
95
|
export async function cmdLogout(ctx) {
|
|
64
96
|
const { config, io } = ctx;
|
|
65
97
|
if (config.oauth?.access_token) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// network, single-post, and top-posts levels (ported from phantomstory-cli's
|
|
3
3
|
// insights.ts); plus Measure's Overview (`summary`), GEO → Competitors
|
|
4
4
|
// (`competitors`), AI Visibility Bank (`bank`) and phantom Page Access (`access`);
|
|
5
|
-
// Measure → Reads (`reads`), Questions (`questions`)
|
|
5
|
+
// Measure → Reads (`reads`), Questions (`questions`), Pages (`pages`) and the posts naming you (`mentions`), and the live feed of what
|
|
6
6
|
// is reading the phantom sites (`activity`) — the same reads the web app renders.
|
|
7
7
|
|
|
8
8
|
import { CliError } from "../client.mjs";
|
|
@@ -42,6 +42,9 @@ export const ARGS = {
|
|
|
42
42
|
period: { flag: "period", enum: PERIODS },
|
|
43
43
|
sites: { flag: "site", type: "list" },
|
|
44
44
|
},
|
|
45
|
+
list_site_mentions: {
|
|
46
|
+
sites: { flag: "site", type: "list" },
|
|
47
|
+
},
|
|
45
48
|
get_recent_activity: {
|
|
46
49
|
phantom_id: { flag: "phantom" },
|
|
47
50
|
limit: { flag: "limit", type: "num" },
|
|
@@ -82,11 +85,13 @@ export async function cmdInsights(ctx) {
|
|
|
82
85
|
return call(rest, "list_measure_questions");
|
|
83
86
|
case "pages":
|
|
84
87
|
return call(rest, "list_cited_pages");
|
|
88
|
+
case "mentions":
|
|
89
|
+
return call(rest, "list_site_mentions");
|
|
85
90
|
case "activity":
|
|
86
91
|
return call(rest, "get_recent_activity");
|
|
87
92
|
default:
|
|
88
93
|
throw new CliError(
|
|
89
|
-
`Unknown insights subcommand: ${sub ?? "(none)"}. Try: summary, reads, questions, pages, competitors, question, detection, activity, site, post, top, bank, access`
|
|
94
|
+
`Unknown insights subcommand: ${sub ?? "(none)"}. Try: summary, reads, questions, pages, mentions, competitors, question, detection, activity, site, post, top, bank, access`
|
|
90
95
|
);
|
|
91
96
|
}
|
|
92
97
|
}
|
package/lib/commands/org.mjs
CHANGED
|
@@ -225,7 +225,7 @@ export function billingAccountText(r) {
|
|
|
225
225
|
`Free tokens: ${Math.max(0, f.availableTokens)} left of ${f.grantedTokens} given (${f.usedTokens} used${f.heldTokens ? `, ${f.heldTokens} held by running work` : ""}).`,
|
|
226
226
|
...f.grants.map(
|
|
227
227
|
(g) =>
|
|
228
|
-
` +${g.tokens} ${g.source}${g.sourceKey !== g.source ? `: ${g.sourceKey}` : ""} ${g.createdAt.slice(0, 10)}`
|
|
228
|
+
` +${g.tokens} ${g.source}${g.sourceKey !== g.source ? `: ${g.sourceKey}` : ""}${g.channel === "agent" ? " (an agent signed you up)" : ""} ${g.createdAt.slice(0, 10)}`
|
|
229
229
|
),
|
|
230
230
|
f.cardRequired
|
|
231
231
|
? "No free tokens left: new work needs a card. An admin adds one in Settings → Billing."
|
package/lib/commands/sim.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// `sim` — Simulations from a terminal: a free, simulated copy of your API that agents can
|
|
2
2
|
// use, and what they did with it. Thin wrappers over the simulation tools (create_simulation,
|
|
3
3
|
// get_simulation, update_simulation, mint_simulation_key, list_simulation_sessions,
|
|
4
|
-
// get_simulation_session, get_simulation_report), the same lib functions the app calls.
|
|
4
|
+
// get_simulation_session, get_simulation_report, the runs tools), the same lib functions the app calls.
|
|
5
5
|
//
|
|
6
6
|
// letterstory sim create --name "Attio API" --spec-url https://api.attio.com/openapi/api
|
|
7
7
|
// letterstory sim show <id>
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
// letterstory sim limits <id> --daily-calls 5000 --daily-sessions 100
|
|
14
14
|
// letterstory sim runs-import --file /tmp/dr1/graded.json --tasks scripts/driven-runs/packs/letter-mcp/tasks.json --suite letter-mcp
|
|
15
15
|
// letterstory sim runs --live
|
|
16
|
-
// letterstory sim run <run-id>
|
|
16
|
+
// letterstory sim run <run-id> [--watch]
|
|
17
|
+
// letterstory sim run-start <simulation-id> --task "Find our open deals over $10k" [--truth "..."] [--watch]
|
|
18
|
+
// letterstory sim run-stop <run-id>
|
|
17
19
|
// letterstory sim report <id> --since 7d
|
|
18
20
|
// letterstory sim sessions <id>
|
|
19
21
|
// letterstory sim session <session-id>
|
|
@@ -108,6 +110,17 @@ export const ARGS = {
|
|
|
108
110
|
limit: { flag: "limit", type: "num" },
|
|
109
111
|
},
|
|
110
112
|
get_simulation_run: { run_id: { positional: 0, label: "run-id", required: true } },
|
|
113
|
+
start_simulation_run: {
|
|
114
|
+
simulation_id: simulationId,
|
|
115
|
+
task_prompt: "task",
|
|
116
|
+
truth: "truth",
|
|
117
|
+
task_key: "task-key",
|
|
118
|
+
suite: "suite",
|
|
119
|
+
model: "model",
|
|
120
|
+
budget_usd: { flag: "budget", type: "num" },
|
|
121
|
+
max_turns: { flag: "turns", type: "num" },
|
|
122
|
+
},
|
|
123
|
+
stop_simulation_run: { run_id: { positional: 0, label: "run-id", required: true } },
|
|
111
124
|
record_simulation_runs: {
|
|
112
125
|
simulation_id: "simulation",
|
|
113
126
|
suite: "suite",
|
|
@@ -213,9 +226,13 @@ export async function cmdSim(ctx) {
|
|
|
213
226
|
return simRun(rest);
|
|
214
227
|
case "runs-import":
|
|
215
228
|
return simRunsImport(rest);
|
|
229
|
+
case "run-start":
|
|
230
|
+
return simRunStart(rest);
|
|
231
|
+
case "run-stop":
|
|
232
|
+
return simRunStop(rest);
|
|
216
233
|
default:
|
|
217
234
|
throw new CliError(
|
|
218
|
-
"Usage: sim [list|create|show|rule|pause|resume|limits|seed|key|sessions|session|report|runs|run|runs-import]"
|
|
235
|
+
"Usage: sim [list|create|show|rule|pause|resume|limits|seed|key|sessions|session|report|runs|run|run-start|run-stop|runs-import]"
|
|
219
236
|
);
|
|
220
237
|
}
|
|
221
238
|
}
|
|
@@ -353,11 +370,19 @@ async function simRuns(ctx) {
|
|
|
353
370
|
return 0;
|
|
354
371
|
}
|
|
355
372
|
|
|
356
|
-
/** `sim run <run-id
|
|
373
|
+
/** `sim run <run-id> [--watch]`: one run in full, or followed live until it ends. */
|
|
357
374
|
async function simRun(ctx) {
|
|
358
|
-
|
|
375
|
+
refuseUnknownFlags(ctx, ARGS.get_simulation_run, ["watch"]);
|
|
376
|
+
if (ctx.flags.watch === true) return simWatch(ctx, flagStr(ctx.positionals[0]));
|
|
377
|
+
printRun(ctx, await call(ctx, "get_simulation_run"));
|
|
378
|
+
return 0;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function printRun(ctx, result) {
|
|
359
382
|
printResult(ctx.io, ctx.flags, result, ({ run: r }) =>
|
|
360
383
|
[
|
|
384
|
+
...(r.live ? [`Running (${r.phase ?? r.status}). Watch it: sim run ${r.id} --watch`] : []),
|
|
385
|
+
...(r.error ? [`Error: ${r.error}`] : []),
|
|
361
386
|
`${r.task_key} — ${r.agent}${r.model ? `:${r.model}` : ""}: ${r.verdict ?? "ungraded"}${r.cause && r.cause !== "none" ? ` (${r.cause})` : ""}, stopped: ${r.outcome ?? r.status}`,
|
|
362
387
|
`Task: ${r.task_prompt}`,
|
|
363
388
|
...(r.verdict_reason ? [`Why: ${r.verdict_reason}`] : []),
|
|
@@ -371,9 +396,63 @@ async function simRun(ctx) {
|
|
|
371
396
|
...(r.answer ? ["", "Answer:", r.answer] : []),
|
|
372
397
|
].join("\n")
|
|
373
398
|
);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** `sim run-start <simulation-id> --task "..." [--truth "..."] [--task-key <name>] [--budget 2] [--turns 40] [--watch]` */
|
|
402
|
+
async function simRunStart(ctx) {
|
|
403
|
+
refuseUnknownFlags(ctx, ARGS.start_simulation_run, ["watch"]);
|
|
404
|
+
const args = argsFromFlags(ARGS.start_simulation_run, ctx.flags, ctx.positionals);
|
|
405
|
+
if (!args.task_prompt)
|
|
406
|
+
throw new CliError(
|
|
407
|
+
'Usage: sim run-start <simulation-id> --task "what the agent should do" [--truth "the right answer"]'
|
|
408
|
+
);
|
|
409
|
+
const result = await ctx.client.callTool("start_simulation_run", args);
|
|
410
|
+
if (ctx.flags.watch === true) return simWatch(ctx, result.run.id);
|
|
411
|
+
printResult(
|
|
412
|
+
ctx.io,
|
|
413
|
+
ctx.flags,
|
|
414
|
+
result,
|
|
415
|
+
(r) => `Started run ${r.run.id}. Watch it: sim run ${r.run.id} --watch Stop it: sim run-stop ${r.run.id}`
|
|
416
|
+
);
|
|
417
|
+
return 0;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** `sim run-stop <run-id>`: what the agent did so far is kept. */
|
|
421
|
+
async function simRunStop(ctx) {
|
|
422
|
+
const result = await call(ctx, "stop_simulation_run");
|
|
423
|
+
printResult(ctx.io, ctx.flags, result, (r) =>
|
|
424
|
+
r.stopped
|
|
425
|
+
? `Stopped run ${r.run.id}. What it did so far is kept.`
|
|
426
|
+
: `Run ${r.run.id} had already ended (${r.run.outcome ?? r.run.status}).`
|
|
427
|
+
);
|
|
374
428
|
return 0;
|
|
375
429
|
}
|
|
376
430
|
|
|
431
|
+
const WATCH_MS = 3000;
|
|
432
|
+
|
|
433
|
+
/** Follow a run's feed until it ends, then print it in full. Ctrl-C stops watching, not the run. */
|
|
434
|
+
async function simWatch(ctx, runId) {
|
|
435
|
+
if (!runId) throw new CliError("Usage: sim run <run-id> --watch");
|
|
436
|
+
let shown = 0;
|
|
437
|
+
let phase = null;
|
|
438
|
+
for (;;) {
|
|
439
|
+
const result = await ctx.client.callTool("get_simulation_run", { run_id: runId });
|
|
440
|
+
const r = result.run;
|
|
441
|
+
if (r.live && r.phase !== phase) {
|
|
442
|
+
phase = r.phase;
|
|
443
|
+
ctx.io.log(`· ${phase ?? r.status}`);
|
|
444
|
+
}
|
|
445
|
+
for (const line of r.activity.slice(shown)) ctx.io.log(` ${line.kind.padEnd(5)} ${line.text}`);
|
|
446
|
+
shown = r.activity.length;
|
|
447
|
+
if (!r.live) {
|
|
448
|
+
ctx.io.log("");
|
|
449
|
+
printRun(ctx, result);
|
|
450
|
+
return 0;
|
|
451
|
+
}
|
|
452
|
+
await new Promise((resolve) => setTimeout(resolve, WATCH_MS));
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
377
456
|
/** `sim runs-import --file graded.json --tasks tasks.json [--suite <pack>] [--simulation <id>] [--target <url>]` */
|
|
378
457
|
async function simRunsImport(ctx) {
|
|
379
458
|
refuseUnknownFlags(ctx, ARGS.record_simulation_runs, ["file", "tasks", "target"]);
|
package/lib/oauth.mjs
CHANGED
|
@@ -216,8 +216,22 @@ export async function deviceLogin({
|
|
|
216
216
|
|
|
217
217
|
io.log(`Open this link, pick the organization and click Allow:\n ${start.verification_uri_complete}\n`);
|
|
218
218
|
io.log(`Code: ${start.user_code} (the page shows the same one)`);
|
|
219
|
+
io.log(
|
|
220
|
+
"No Letter account yet? Run `letterstory signup --email <work email>` instead: Letter emails a link to create one."
|
|
221
|
+
);
|
|
219
222
|
io.log("Waiting for approval…");
|
|
223
|
+
return pollDeviceToken({ base, start, fetchImpl, sleep, again: "Run `login --device` again." });
|
|
224
|
+
}
|
|
220
225
|
|
|
226
|
+
// The device-code poll (RFC 8628 §3.4-3.5), shared by `login --device` and `signup`: polls /token
|
|
227
|
+
// every `interval` seconds until the person approves (or confirms their signup) in a browser.
|
|
228
|
+
export async function pollDeviceToken({
|
|
229
|
+
base,
|
|
230
|
+
start,
|
|
231
|
+
fetchImpl = globalThis.fetch,
|
|
232
|
+
sleep = (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
233
|
+
again,
|
|
234
|
+
}) {
|
|
221
235
|
let intervalMs = (start.interval ?? 5) * 1000;
|
|
222
236
|
const deadline = Date.now() + (start.expires_in ?? 600) * 1000;
|
|
223
237
|
while (Date.now() < deadline) {
|
|
@@ -245,10 +259,10 @@ export async function deviceLogin({
|
|
|
245
259
|
continue;
|
|
246
260
|
}
|
|
247
261
|
if (error === "access_denied") throw new CliError("Sign-in was cancelled in the browser.");
|
|
248
|
-
if (error === "expired_token") throw new CliError(
|
|
262
|
+
if (error === "expired_token") throw new CliError(`The link expired. ${again}`);
|
|
249
263
|
throw new CliError(`Login failed: ${json?.error_description || error || `HTTP ${poll.status}`}`);
|
|
250
264
|
}
|
|
251
|
-
throw new CliError(
|
|
265
|
+
throw new CliError(`The link expired before it was approved. ${again}`);
|
|
252
266
|
}
|
|
253
267
|
|
|
254
268
|
export async function refreshAccessToken({ url, refreshToken, fetchImpl = globalThis.fetch }) {
|