@wirecat/cli-core 0.695.0 → 0.697.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 (66) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/cli/bot/api-http.d.ts +1 -1
  3. package/dist/cli/bot/api-http.js +77 -5
  4. package/dist/cli/bot/api-input.d.ts +5 -0
  5. package/dist/cli/bot/api-input.js +55 -0
  6. package/dist/cli/bot/api.d.ts +2 -0
  7. package/dist/cli/bot/api.js +22 -4
  8. package/dist/cli/index.d.ts +3 -3
  9. package/dist/cli/index.js +3 -3
  10. package/dist/cli/messenger/store-maintenance-command.js +3 -2
  11. package/dist/cli/profile-token.d.ts +10 -2
  12. package/dist/cli/profile-token.js +19 -3
  13. package/dist/cli/service-api-call.d.ts +2 -0
  14. package/dist/cli/service-api-call.js +1 -1
  15. package/dist/cli/service-api-manifest.d.ts +9 -3
  16. package/dist/cli/service-api-manifest.js +70 -11
  17. package/dist/cli/service-api.d.ts +5 -0
  18. package/dist/cli/service-api.js +13 -6
  19. package/dist/cli/token-session.d.ts +27 -1
  20. package/dist/cli/token-session.js +52 -13
  21. package/dist/crm/manifest/manifest.d.ts +2 -0
  22. package/dist/crm/manifest/manifest.js +2 -1
  23. package/dist/crm/manifest/map.d.ts +2 -1
  24. package/dist/crm/manifest/map.js +2 -1
  25. package/dist/domain/tracker.d.ts +100 -0
  26. package/dist/domain/tracker.js +28 -0
  27. package/dist/errors/reasons.js +1 -0
  28. package/dist/manifest/index.d.ts +9 -5
  29. package/dist/manifest/index.js +18 -7
  30. package/dist/store/exports.d.ts +1 -0
  31. package/dist/store/exports.js +1 -0
  32. package/dist/store/recover.js +2 -0
  33. package/dist/store/sqlite/account-purge.js +1 -0
  34. package/dist/store/sqlite/crm-files.d.ts +3 -0
  35. package/dist/store/sqlite/crm-files.js +2 -2
  36. package/dist/store/sqlite/manifest.js +2 -0
  37. package/dist/store/sqlite/migrations.generated.js +17 -0
  38. package/dist/store/sqlite/schema.d.ts +252 -0
  39. package/dist/store/sqlite/schema.js +28 -0
  40. package/dist/store/sqlite/tracker.d.ts +82 -0
  41. package/dist/store/sqlite/tracker.js +210 -0
  42. package/dist/store/store.d.ts +3 -0
  43. package/dist/store/store.js +5 -0
  44. package/dist/tracker/cli/index.d.ts +24 -0
  45. package/dist/tracker/cli/index.js +279 -0
  46. package/dist/tracker/index.d.ts +8 -0
  47. package/dist/tracker/index.js +7 -0
  48. package/dist/tracker/manifest/manifest.d.ts +76 -0
  49. package/dist/tracker/manifest/manifest.js +139 -0
  50. package/dist/tracker/manifest/map.d.ts +10 -0
  51. package/dist/tracker/manifest/map.js +86 -0
  52. package/dist/tracker/manifest/source.d.ts +18 -0
  53. package/dist/tracker/manifest/source.js +174 -0
  54. package/dist/tracker/source.d.ts +55 -0
  55. package/dist/tracker/source.js +1 -0
  56. package/dist/tracker/sync.d.ts +60 -0
  57. package/dist/tracker/sync.js +254 -0
  58. package/dist/tracker/tasks.d.ts +18 -0
  59. package/dist/tracker/tasks.js +29 -0
  60. package/dist/tracker/testing/index.d.ts +2 -0
  61. package/dist/tracker/testing/index.js +2 -0
  62. package/dist/tracker/testing/source-contract.d.ts +46 -0
  63. package/dist/tracker/testing/source-contract.js +246 -0
  64. package/dist/tracker/testing/source.d.ts +31 -0
  65. package/dist/tracker/testing/source.js +141 -0
  66. package/package.json +12 -4
package/CHANGELOG.md CHANGED
@@ -5,6 +5,66 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
5
5
  minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
6
6
  shape of this file.
7
7
 
8
+ ## 0.697.0 — 17.11.2026
9
+
10
+ ### Added
11
+
12
+ - **The `api` group and `serviceApiCall` send a GraphQL operation** of a manifest that cli-base 0.115.0 generates
13
+ from a schema. Each call is one POST of the document `graphqlDocument` builds, never sent again on a redirect.
14
+ The variables are `--body` as one object with each flag over it, read by its schema: digits as written, `true` or
15
+ `false`, JSON for an input object. A variable the operation does not declare, or a required one left out, is
16
+ refused before anything is sent. The flags of a GraphQL operation are its body and stay out of the run's files.
17
+ - **`errors[]` is a failure even at HTTP 200.** A CLI's own `failure` names it first; else its `extensions.code`
18
+ does, repeated only when it is a plain constant, never the service's message. A write is `outcome_unknown` unless
19
+ the code says nothing ran and no data came back. The answer is `data.<field>`; `--all` pages by `pageInfo`.
20
+ - **`ApiCommandInput.selection`** gives a source a deeper selection than the generated one. `api list` and the run
21
+ record name a GraphQL operation as `POST` `query/issues`.
22
+ - **A tracker CLI can be described as data: `trackerSourceFromManifest`.** A `TrackerManifest` names, for each kind,
23
+ the list, changes and ids operations of the generated API and maps our fields to paths in a row, in the CRM
24
+ manifest's rule language. Over GraphQL each call may send its own selection, and `parseTrackerManifest` refuses a
25
+ map path the selection leaves out. `wirecat.config` takes `category: "tracker"` with its `source`, and
26
+ `spec.kind: "graphql"`. See [Trackers](docs/dev/TRACKER.md#a-tracker-described-as-data).
27
+ - **Issue trackers get their own category: `@wirecat/cli-core/tracker`.** A tracker CLI writes one `TrackerSource`
28
+ and gets the copy in the shared store (store version 70: `tracker_items` and the word index `tracker_item_words`),
29
+ `syncTracker` (changes by cursor, deletions by a daily id pass, a run budget that resumes where it stopped),
30
+ `addTrackerCommands` (`sync`, `issues list|show|search|task`, and `projects`, `teams`, `users`, `states`, `labels`
31
+ lists), and `/tracker/testing` with `trackerSourceContract` and `fakeTrackerSource`. `issues task` makes an issue
32
+ the owner's task by a link, copying only its key. See [Trackers](docs/dev/TRACKER.md).
33
+
34
+ ### Changed — may break callers
35
+
36
+ - **cli-core needs `@wirecat/cli-base` 0.115.0 or later**, whose manifest has the `graphql` binding.
37
+
38
+ ## 0.696.0 — 17.11.2026
39
+
40
+ ### Added
41
+
42
+ - **A service that signs in with a user name and a password, as WordPress's application passwords, gets the same
43
+ `session` group.** `tokenSessionCommand` takes `login: { page? }`: `session start --login <name>` asks only the
44
+ password hidden, shows where to make one first, and keeps `<name>:<password>` in the profile's entry;
45
+ `<PREFIX>_TOKEN` holds the same pair. A manifest whose scheme is `http` `basic` now signs each call with it, where
46
+ the `api` group refused that scheme; a token without a user name is refused before anything is sent, and a spec
47
+ that also offers a bearer or a key sends that. A name with a colon is refused, since Basic splits there. cli-base's
48
+ `fakeApi`, and so `crmManifestFake`, does not take Basic yet.
49
+ - **One CLI can serve a service that runs on each owner's own site, a profile per site.** `tokenSessionCommand` takes
50
+ `site: { example }`: `session start --site blog.example.com` checks the token on that site and keeps the site in
51
+ the token's own keyring entry, written and forgotten with it, so a token only goes to the site it signed in to.
52
+ `session status` shows the site. `<PREFIX>_TOKEN` needs `<PREFIX>_TOKEN_SITE` beside it. `serviceApiCommand` takes
53
+ `serverVariables`, read when a call is sent, so `api list` and `api show` work before sign-in; give it
54
+ `signedInSite(app, resolveSettings)`, and give `serviceApiCall` that function's value for the command. Build the
55
+ fetch per run with the site's host in `hostFetch`. A site is https only, a host with a port or a path, never a user
56
+ name, query or fragment. A free variable inside a host (`{subdomain}.example.com`) takes one name only.
57
+ - **`ProfileTokenStore.write` takes named secrets to keep in the same write, and `readWith` reads the token and one
58
+ named secret from the same place:** both from the environment, or both from the profile's entry.
59
+
60
+ ### Fixed
61
+
62
+ - **A generated `api` command no longer demands a required parameter that the spec gives a default.** Notion's
63
+ page-markdown calls stopped with `required option '--notion-version <value>' not specified`, though its spec says
64
+ `Notion-Version` defaults to `2026-03-11`. Such a flag is now optional, shows its default in `--help`, and the call
65
+ sends the default when the flag is left out; a value given on the command line wins. A required parameter with no
66
+ default is still required. This covers the Bot API group too.
67
+
8
68
  ## 0.695.0 — 17.11.2026
9
69
 
10
70
  ### Added
@@ -1,5 +1,5 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
- import type { ManifestOperation } from "@wirecat/cli-base/codegen";
2
+ import { type ManifestOperation } from "@wirecat/cli-base/codegen";
3
3
  import { type FetchLike } from "@wirecat/cli-base/http";
4
4
  import type { Command } from "commander";
5
5
  import type { ApiCommandInput } from "./api.js";
@@ -1,9 +1,10 @@
1
1
  import { CliError, wallClock } from "@wirecat/cli-base";
2
+ import { graphqlDocument } from "@wirecat/cli-base/codegen";
2
3
  import { providerWaitMs, readJsonResponse, statusToCode } from "@wirecat/cli-base/http";
3
4
  import { providerRequest } from "../command-runs.js";
4
5
  import { outputFor } from "../context.js";
5
6
  import { itemOf, renderAnswer } from "../envelope.js";
6
- import { parseApiJson, sendsBytes } from "./api-input.js";
7
+ import { apiJson, graphqlVariables, parseApiJson, sendsBytes } from "./api-input.js";
7
8
  const LARGEST_ANSWER = 16 * 1024 * 1024;
8
9
  /** `new URL` folds a `.` or `..` segment into its parent, so such an id would reach another endpoint. */
9
10
  const segment = (name, value) => {
@@ -21,12 +22,14 @@ export const unsendableBody = (operation) => {
21
22
  /** One generated HTTP operation and its flags as the request they stand for; nothing is sent. */
22
23
  export const httpApiRequest = (operation, input, baseUrl) => {
23
24
  const { binding } = operation;
24
- if (binding.kind !== "http")
25
+ if (binding.kind !== "http" && binding.kind !== "graphql")
25
26
  throw new CliError("configuration_error", `${operation.command} is not an HTTP operation`);
26
27
  if (unsendableBody(operation))
27
28
  throw new CliError("validation_error", `${operation.command} sends ${operation.request?.contentType}, which the generated command cannot send; nothing was sent`, { sent: false });
28
29
  if (operation.response?.sensitive)
29
30
  throw new CliError("validation_error", `${operation.command} answers with a credential, which the generated command never prints; nothing was sent`, { sent: false });
31
+ if (binding.kind === "graphql")
32
+ return graphqlRequest(operation, binding, input, baseUrl);
30
33
  if (Object.keys(input.fields).length > 0)
31
34
  throw new CliError("configuration_error", `${operation.command} has body fields as flags, which HTTP cannot send`);
32
35
  if (!/^\/(?!\/)/.test(binding.path))
@@ -58,8 +61,70 @@ export const httpApiRequest = (operation, input, baseUrl) => {
58
61
  headers.set("content-type", "application/json");
59
62
  return { method: binding.method, url, headers, ...(body === undefined ? {} : { body }) };
60
63
  };
64
+ /** One GraphQL operation as a POST of its one document to the endpoint, with its variables. */
65
+ const graphqlRequest = (operation, binding, input, baseUrl) => {
66
+ const variables = graphqlVariables(operation, input.body, input.fields);
67
+ const headers = new Headers(input.headers);
68
+ headers.set("accept", "application/json");
69
+ headers.set("content-type", "application/json");
70
+ const query = graphqlDocument(binding, input.selection);
71
+ // A 307 or 308 would send the variables again, to wherever it points.
72
+ return { method: "POST", url: new URL(baseUrl), headers, body: apiJson({ query, variables }), redirect: "error" };
73
+ };
61
74
  /** `/v1/pages/{page_id}` → `/v1/pages/:page_id`: the run record keeps the template, never an id. */
62
75
  const templateOf = (path) => path.replace(/\{([^}]+)\}/g, ":$1");
76
+ /** What the run record names a request by: the path template, or a GraphQL operation's root field. */
77
+ const endpointOf = (operation) => operation.binding.kind === "http"
78
+ ? templateOf(operation.binding.path)
79
+ : operation.binding.kind === "graphql"
80
+ ? `${operation.binding.operation}/${operation.binding.field}`
81
+ : "";
82
+ // Common GraphQL server codes (Apollo's names) as the CLI's; any other is the provider's.
83
+ const GRAPHQL_CODES = {
84
+ UNAUTHENTICATED: "authentication_error",
85
+ AUTHENTICATION_ERROR: "authentication_error",
86
+ FORBIDDEN: "permission_error",
87
+ RATELIMITED: "rate_limited",
88
+ BAD_USER_INPUT: "validation_error",
89
+ GRAPHQL_VALIDATION_FAILED: "validation_error",
90
+ INVALID_INPUT: "validation_error",
91
+ };
92
+ // A refusal of these kinds means the service did nothing, so a write that got one is not in doubt.
93
+ const NOTHING_RAN = new Set(["authentication_error", "permission_error", "rate_limited", "validation_error"]);
94
+ /**
95
+ * A GraphQL answer comes with HTTP 200 even when it failed: `errors[]` is the failure, named by the CLI's own
96
+ * `failure`, else by its first `extensions.code`, never by the service's message (WC-SECR-6). A write that failed in
97
+ * any other way, or answered data too, may have landed (WC-LIFE-9). Otherwise the answer is `data.<field>`.
98
+ */
99
+ const graphqlAnswer = (options, operation, answer) => {
100
+ const { binding } = operation;
101
+ if (binding.kind !== "graphql")
102
+ return answer;
103
+ const { data, errors } = (answer ?? {});
104
+ if (Array.isArray(errors) && errors.length > 0) {
105
+ const own = options.failure?.(200, answer, operation);
106
+ if (own)
107
+ throw own;
108
+ const raw = errors[0]?.extensions?.code;
109
+ // The code is the service's text too: only a plain constant is repeated.
110
+ const code = typeof raw === "string" && /^[A-Z][A-Z0-9_]{0,40}$/.test(raw) ? raw : undefined;
111
+ const known = (code && GRAPHQL_CODES[code]) || "provider_error";
112
+ const writes = operation.effect !== "read";
113
+ if (writes && (!NOTHING_RAN.has(known) || data?.[binding.field] != null))
114
+ return outcomeUnknown(options.service);
115
+ throw new CliError(known, `${options.service} refused ${operation.command}${code ? ` (${code})` : ""}`, {
116
+ retryable: known === "rate_limited",
117
+ });
118
+ }
119
+ if (!data || !(binding.field in data))
120
+ throw new CliError("invalid_response", `${options.service} answered ${operation.command} without data.${binding.field}`);
121
+ return data[binding.field];
122
+ };
123
+ const outcomeUnknown = (service) => {
124
+ throw new CliError("outcome_unknown", `${service} did not confirm a write; check it before repeating the write`, {
125
+ retryable: false,
126
+ });
127
+ };
63
128
  const answerOf = async (response, maxBytes) => {
64
129
  if (response.status === 204 || !response.body || response.headers.get("content-length") === "0")
65
130
  return {};
@@ -71,7 +136,7 @@ const answerOf = async (response, maxBytes) => {
71
136
  */
72
137
  export const httpApiSend = (options) => async (command, operation, request) => {
73
138
  const writes = operation.effect !== "read";
74
- const template = templateOf(operation.binding.kind === "http" ? operation.binding.path : "");
139
+ const template = endpointOf(operation);
75
140
  const end = providerRequest(`${request.method} ${template}`, undefined, {
76
141
  method: request.method,
77
142
  endpointTemplate: template,
@@ -109,8 +174,15 @@ export const httpApiSend = (options) => async (command, operation, request) => {
109
174
  end({ status, error: failed });
110
175
  throw failed;
111
176
  }
112
- end({ status });
113
- return answer;
177
+ try {
178
+ const result = graphqlAnswer(options, operation, answer);
179
+ end({ status });
180
+ return result;
181
+ }
182
+ catch (error) {
183
+ end({ status, error });
184
+ throw error;
185
+ }
114
186
  };
115
187
  /**
116
188
  * The `execute` of `generatedApiCommand` for any OpenAPI CLI: fills the path, adds the query, sends the JSON body
@@ -15,3 +15,8 @@ export declare const checkApiBody: (operation: ManifestOperation, text: string |
15
15
  export declare const parseApiJson: (text: string) => unknown;
16
16
  export declare const apiJson: (value: unknown) => string;
17
17
  export declare const apiPlainJson: (value: unknown) => unknown;
18
+ /**
19
+ * A GraphQL operation's variables: the body's (`--body`, all of them as one object) with each flag over it, read by
20
+ * the variable's schema. A name the operation does not declare, or a required one left out, is refused unsent.
21
+ */
22
+ export declare const graphqlVariables: (operation: ManifestOperation, body: string | undefined, fields: Readonly<Record<string, string>>) => Record<string, unknown>;
@@ -118,3 +118,58 @@ const finite = (key, value) => {
118
118
  };
119
119
  export const apiJson = (value) => stringify(value, finite) ?? "null";
120
120
  export const apiPlainJson = (value) => JSON.parse(stringify(value, (key, inner) => isLosslessNumber(inner) && !isSafeNumber(inner.value) ? inner.toString() : finite(key, inner)) ?? "null");
121
+ /** A JSON object with no lossless number at its top: what a GraphQL body of variables must be. */
122
+ const isVariables = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && !isLosslessNumber(value);
123
+ /**
124
+ * A GraphQL operation's variables: the body's (`--body`, all of them as one object) with each flag over it, read by
125
+ * the variable's schema. A name the operation does not declare, or a required one left out, is refused unsent.
126
+ */
127
+ export const graphqlVariables = (operation, body, fields) => {
128
+ const { binding } = operation;
129
+ if (binding.kind !== "graphql")
130
+ throw new CliError("configuration_error", `${operation.command} is not a GraphQL operation`);
131
+ const given = body?.trim() ? parseApiJson(body) : {};
132
+ if (!isVariables(given))
133
+ throw new CliError("validation_error", `${operation.command} takes its variables as one JSON object`, {
134
+ sent: false,
135
+ });
136
+ const variables = { ...given };
137
+ for (const [name, raw] of Object.entries(fields)) {
138
+ const schema = operation.parameters.find((one) => one.in === "body" && one.name === name)?.schema;
139
+ variables[name] = flagValue(operation, name, raw, schema?.type);
140
+ }
141
+ const unknown = Object.keys(variables).filter((name) => !(name in binding.variables));
142
+ if (unknown.length > 0)
143
+ throw new CliError("validation_error", `${operation.command} has no variable ${unknown.join(", ")}`, {
144
+ sent: false,
145
+ });
146
+ const missing = Object.entries(binding.variables)
147
+ .filter(([name, type]) => type.endsWith("!") && variables[name] == null)
148
+ .map(([name]) => `--${apiFlagOf(name)}`);
149
+ if (missing.length > 0)
150
+ throw new CliError("validation_error", `${operation.command} needs ${missing.join(", ")}`, { sent: false });
151
+ return variables;
152
+ };
153
+ const DECIMAL = /^-?\d+(\.\d+)?$/;
154
+ const flagValue = (operation, name, raw, type) => {
155
+ const flag = `--${apiFlagOf(name)} of ${operation.command}`;
156
+ if (type === "integer" || type === "number") {
157
+ // Number() would take 0x10 and 1e1, and round a long id; the digits go as written.
158
+ if (!(type === "integer" ? DIGITS : DECIMAL).test(raw.trim()))
159
+ throw new CliError("validation_error", `${flag} takes ${type === "integer" ? "a whole number" : "a number"}`, {
160
+ sent: false,
161
+ });
162
+ return new LosslessNumber(raw.trim());
163
+ }
164
+ if (type === "boolean") {
165
+ if (raw !== "true" && raw !== "false")
166
+ throw new CliError("validation_error", `${flag} takes true or false`, { sent: false });
167
+ return raw === "true";
168
+ }
169
+ if (type === "object" || type === "array" || type === "unknown")
170
+ return parseApiJson(raw);
171
+ // An input object or a list given as JSON; an enum's value, behind a ref too, is a bare word.
172
+ if (type === "ref" && /^\s*[{["]/.test(raw))
173
+ return parseApiJson(raw);
174
+ return raw;
175
+ };
@@ -10,6 +10,8 @@ export interface ApiCommandInput {
10
10
  bytes?: Uint8Array<ArrayBuffer>;
11
11
  bodySource?: "argument" | "stdin" | "file";
12
12
  tokenProfile?: string;
13
+ /** A GraphQL operation's selection in place of its default, for a source that needs more than one level. */
14
+ selection?: string;
13
15
  }
14
16
  export interface ApiCommands {
15
17
  operations: readonly ManifestOperation[];
@@ -3,14 +3,17 @@ import { annotate } from "@wirecat/cli-base/commands";
3
3
  import { Command, Option } from "commander";
4
4
  import { secretInput } from "../../runs/run-context.js";
5
5
  import { REMOTE_READ, REMOTE_WRITE } from "../effects.js";
6
- import { apiFlagOf, apiOptionKey, readApiBody, readApiBytes, sendsBytes } from "./api-input.js";
6
+ import { apiFlagOf, apiJson, apiOptionKey, graphqlVariables, readApiBody, readApiBytes, sendsBytes, } from "./api-input.js";
7
+ const scalarOf = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : undefined;
7
8
  export const generatedApiCommand = (api) => {
8
9
  const group = new Command("api").description(api.description ?? "every operation of the official Bot API, generated from its schema");
9
10
  group.option("--store-token <profile>", "keep a returned authentication token only in this bot profile's OS keyring; never print it");
10
11
  for (const operation of api.operations) {
11
12
  const binding = operation.binding.kind === "http"
12
13
  ? `${operation.binding.method} ${operation.binding.path}`
13
- : operation.binding.name;
14
+ : operation.binding.kind === "graphql"
15
+ ? `${operation.binding.operation} ${operation.binding.field}`
16
+ : operation.binding.name;
14
17
  const command = annotate(new Command(operation.command), {
15
18
  effects: operation.effect === "read" ? REMOTE_READ : REMOTE_WRITE,
16
19
  }).description(`${operation.summary ?? operation.id} — ${operation.effect} (${binding})`);
@@ -18,7 +21,18 @@ export const generatedApiCommand = (api) => {
18
21
  if (parameter.sensitive)
19
22
  continue;
20
23
  const option = new Option(`--${apiFlagOf(parameter.name)} <value>`, parameter.description?.split("\n")[0] ?? parameter.name);
21
- command.addOption(parameter.required && parameter.in !== "body" ? option.makeOptionMandatory() : option);
24
+ // A GraphQL flag is the request body, which never reaches the run's files (SEC-196).
25
+ if (operation.binding.kind === "graphql" && parameter.in === "body")
26
+ secretInput(option);
27
+ if (parameter.required && parameter.in !== "body") {
28
+ // A required parameter the spec gives a default (Notion's `Notion-Version`) is sent with it, never asked for.
29
+ const fallback = scalarOf(parameter.schema.default);
30
+ if (fallback === undefined)
31
+ option.makeOptionMandatory();
32
+ else
33
+ option.default(fallback);
34
+ }
35
+ command.addOption(option);
22
36
  }
23
37
  if (operation.request && sendsBytes(operation)) {
24
38
  command.option("--body-file <path>", `the file to upload, sent as ${operation.request.contentType}; - is stdin`);
@@ -76,7 +90,11 @@ export const generatedApiCommand = (api) => {
76
90
  input.bodySource = options.body === "-" ? "stdin" : "argument";
77
91
  else if (options.bodyFile !== undefined)
78
92
  input.bodySource = options.bodyFile === "-" ? "stdin" : "file";
79
- const body = operation.binding.kind === "rpc" ? text : api.checkBody ? api.checkBody(operation, text) : text;
93
+ // A GraphQL body is all the variables: the flags join it here, so the schema check sees what is sent.
94
+ const given = operation.binding.kind === "graphql" ? apiJson(graphqlVariables(operation, text, input.fields)) : text;
95
+ if (operation.binding.kind === "graphql")
96
+ input.fields = {};
97
+ const body = operation.binding.kind === "rpc" ? text : api.checkBody ? api.checkBody(operation, given) : given;
80
98
  if (body !== undefined)
81
99
  input.body = body;
82
100
  await api.execute(this, operation, input);
@@ -118,7 +118,7 @@ export { readMeetingProjectCandidates } from "./meeting-project-candidates-read.
118
118
  export { meetingResultItem } from "./meeting-results.js";
119
119
  export { type MeetingSeriesInventoryReader, readMeetingSeriesInventory } from "./meeting-series-inventory-read.js";
120
120
  export { addMeetingTagsCommand, type MeetingTagsCommandDeps } from "./meeting-tags-command.js";
121
- export { accountFileFor, profilesHere, recalledAccount, rememberAccount } from "./messenger/accounts.js";
121
+ export { accountFileFor, profilesHere, recalledAccount, rememberAccount, } from "./messenger/accounts.js";
122
122
  export { terminalAsker } from "./messenger/ask.js";
123
123
  export type { CompletionOptions } from "./messenger/complete-command.js";
124
124
  export { type ConnectOptions, connectFor, type Messenger, type MessengerContext, messengerContext, type ProfileState, type ReadConnection, type StoredMessages, } from "./messenger/context.js";
@@ -155,7 +155,7 @@ export { type AgentScheduleSpec, agentSchedule, backfillScheduleRun, pauseSchedu
155
155
  export { deniedKinds, deniedKindsOf, type LeftOut, type SearchedKind } from "./search-left-out.js";
156
156
  export { type BodyPermission, type ServiceApiOptions, type ServiceApiPermissionsInput, serviceApiKeys, serviceApiOperations, serviceApiPermissions, } from "./service-api.js";
157
157
  export { type ServiceApiCall, type ServiceApiCallOptions, serviceApiCall } from "./service-api-call.js";
158
- export { manifestBaseUrl, type ServiceApiManifest, signRequest } from "./service-api-manifest.js";
158
+ export { manifestBaseUrl, type ServiceApiManifest, signRequest, siteValue } from "./service-api-manifest.js";
159
159
  export { type DeclaredSetting, type SettingRow, settingRows, withSettingDefaults } from "./setting-defaults.js";
160
160
  export { type Config, type Configuration, count, first, flag, fromFile, type GlobalFlags, NONE_NAMED, namedProfile, type ProfileKind, plain, type ResolveOptions, type Settings, type SettingsExtension, type SettingsExtensionContext, type Source, settingsFor, } from "./settings.js";
161
161
  export { type PermissionAnswer, readSetupAnswers, type SetupAnswers, setupPermissionCeiling } from "./setup-answers.js";
@@ -167,5 +167,5 @@ export { type StoreInfo, sharedStoreCommand, storeInfo, storeInfoCommand } from
167
167
  export { type RecoveryCheck, type RecoveryRun, recoveryNotes, storeRecoverCommand, storeRecoveryCheck, storeRecoveryRun, } from "./store-recover.js";
168
168
  export { changeStoreSetting, isStoreSetting, STORE_SETTINGS, storeSettings } from "./store-settings.js";
169
169
  export type { TemplatesOptions } from "./templates-command.js";
170
- export { type TokenSessionOptions, tokenSessionCommand } from "./token-session.js";
170
+ export { signedInSite, type TokenSessionOptions, tokenSessionCommand } from "./token-session.js";
171
171
  export { restartServers, type UpgradeContext } from "./upgrade-command.js";
package/dist/cli/index.js CHANGED
@@ -109,7 +109,7 @@ export { readMeetingProjectCandidates } from "./meeting-project-candidates-read.
109
109
  export { meetingResultItem } from "./meeting-results.js";
110
110
  export { readMeetingSeriesInventory } from "./meeting-series-inventory-read.js";
111
111
  export { addMeetingTagsCommand } from "./meeting-tags-command.js";
112
- export { accountFileFor, profilesHere, recalledAccount, rememberAccount } from "./messenger/accounts.js";
112
+ export { accountFileFor, profilesHere, recalledAccount, rememberAccount, } from "./messenger/accounts.js";
113
113
  export { terminalAsker } from "./messenger/ask.js";
114
114
  export { connectFor, messengerContext, } from "./messenger/context.js";
115
115
  export { DOCTOR_DEEP_OPTION, damageNotes } from "./messenger/doctor-command.js";
@@ -144,7 +144,7 @@ export { agentSchedule, backfillScheduleRun, pauseSchedule, removeSchedule, runS
144
144
  export { deniedKinds, deniedKindsOf } from "./search-left-out.js";
145
145
  export { serviceApiKeys, serviceApiOperations, serviceApiPermissions, } from "./service-api.js";
146
146
  export { serviceApiCall } from "./service-api-call.js";
147
- export { manifestBaseUrl, signRequest } from "./service-api-manifest.js";
147
+ export { manifestBaseUrl, signRequest, siteValue } from "./service-api-manifest.js";
148
148
  export { settingRows, withSettingDefaults } from "./setting-defaults.js";
149
149
  export { count, first, flag, fromFile, NONE_NAMED, namedProfile, plain, settingsFor, } from "./settings.js";
150
150
  export { readSetupAnswers, setupPermissionCeiling } from "./setup-answers.js";
@@ -155,5 +155,5 @@ export { runnable, withSafety } from "./steps.js";
155
155
  export { sharedStoreCommand, storeInfo, storeInfoCommand } from "./store-info.js";
156
156
  export { recoveryNotes, storeRecoverCommand, storeRecoveryCheck, storeRecoveryRun, } from "./store-recover.js";
157
157
  export { changeStoreSetting, isStoreSetting, STORE_SETTINGS, storeSettings } from "./store-settings.js";
158
- export { tokenSessionCommand } from "./token-session.js";
158
+ export { signedInSite, tokenSessionCommand } from "./token-session.js";
159
159
  export { restartServers } from "./upgrade-command.js";
@@ -16,7 +16,7 @@ import { migrate } from "../../store/migrations.js";
16
16
  import { openCache } from "../../store/open.js";
17
17
  import { storePath } from "../../store/path.js";
18
18
  import { deleteCopy, repairStore } from "../../store/repair.js";
19
- import { drainNoteIndex, dropAllUnusedVectors, fillSearchIndex, fillStems, involvementStoreOver, noteIndexState, openSqlite, openStore, orphanPointers, pendingNormalization, resetAttachmentWords, resetCrmFileWords, resetNoteIndex, resetSearchIndex, resetStems, rollBack, searchIndexState, stemmerCache, stemsState, vectorIndexCounts, } from "../../store/store.js";
19
+ import { drainNoteIndex, dropAllUnusedVectors, fillSearchIndex, fillStems, involvementStoreOver, noteIndexState, openSqlite, openStore, orphanPointers, pendingNormalization, resetAttachmentWords, resetCrmFileWords, resetNoteIndex, resetSearchIndex, resetStems, resetTrackerItemWords, rollBack, searchIndexState, stemmerCache, stemsState, vectorIndexCounts, } from "../../store/store.js";
20
20
  import { environmentOf, outputFor } from "../context.js";
21
21
  import { destroysNothing, grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "../effects.js";
22
22
  import { itemOf, renderAnswer, snakeKeys } from "../envelope.js";
@@ -327,6 +327,7 @@ const inspect = (path) => reading(path, (database) => {
327
327
  ...(stems ? [["message_stems", indexIntegrity(database, "message_stems", 0)]] : []),
328
328
  ...(schema.version > 0 ? [["attachment_words", indexIntegrity(database, "attachment_words", 0)]] : []),
329
329
  ...(schema.version >= 68 ? [["crm_file_words", indexIntegrity(database, "crm_file_words", 0)]] : []),
330
+ ...(schema.version >= 70 ? [["tracker_item_words", indexIntegrity(database, "tracker_item_words", 0)]] : []),
330
331
  ]);
331
332
  const size = bytesOf(path) + bytesOf(`${path}-wal`);
332
333
  const { bavail, bsize } = statfsSync(dirname(path));
@@ -531,7 +532,7 @@ const reindexCommand = (owner) => destroysNothing(annotate(new Command("rebuild"
531
532
  throw new CliError("validation_error", `the store is behind this build — \`${lineOf(this, "store migrate")}\` first`);
532
533
  }
533
534
  resetSearchIndex(database);
534
- const fileTexts = resetAttachmentWords(database) + resetCrmFileWords(database);
535
+ const fileTexts = resetAttachmentWords(database) + resetCrmFileWords(database) + resetTrackerItemWords(database);
535
536
  const words = buildWordIndex(database, (note) => renderer.note(note));
536
537
  return {
537
538
  path,
@@ -24,8 +24,16 @@ export declare class ProfileTokenStore {
24
24
  readonly variable: string;
25
25
  constructor({ app, env, keyring, warn }: ProfileTokenStoreOptions);
26
26
  read(profile: string): StoredCredential | undefined;
27
- /** The token; the profile's named secrets stay as they were. */
28
- write(profile: string, token: string, storage?: TokenStorage): CredentialSource;
27
+ /** The token, and `secrets` beside it in the same write; the profile's other named secrets stay as they were. */
28
+ write(profile: string, token: string, storage?: TokenStorage, secrets?: Readonly<Record<string, string>>): CredentialSource;
29
+ /**
30
+ * The token and one named secret from the same place, never one of each: `<PREFIX>_TOKEN` with
31
+ * `<PREFIX>_TOKEN_<NAME>`, or the profile's entry. A site kept beside a token so stays the token's own.
32
+ */
33
+ readWith(profile: string, name: string): {
34
+ token: StoredCredential;
35
+ secret: string | undefined;
36
+ } | undefined;
29
37
  /** The token and every named secret: the whole entry, as `session end` wants. */
30
38
  remove(profile: string): CredentialSource[];
31
39
  /** A named secret: `<PREFIX>_TOKEN_<NAME>`, then the profile's entry. */
@@ -79,9 +79,25 @@ export class ProfileTokenStore {
79
79
  const { token } = unpack(found.secret);
80
80
  return token === undefined ? undefined : { secret: token, source: found.source };
81
81
  }
82
- /** The token; the profile's named secrets stay as they were. */
83
- write(profile, token, storage = "keyring") {
84
- return this.#put(profile, { ...this.#heldUnlessUnreachable(profile), token }, storage);
82
+ /** The token, and `secrets` beside it in the same write; the profile's other named secrets stay as they were. */
83
+ write(profile, token, storage = "keyring", secrets = {}) {
84
+ for (const name of Object.keys(secrets))
85
+ checkName(name);
86
+ const held = this.#heldUnlessUnreachable(profile);
87
+ return this.#put(profile, { ...held, token, secrets: { ...held.secrets, ...secrets } }, storage);
88
+ }
89
+ /**
90
+ * The token and one named secret from the same place, never one of each: `<PREFIX>_TOKEN` with
91
+ * `<PREFIX>_TOKEN_<NAME>`, or the profile's entry. A site kept beside a token so stays the token's own.
92
+ */
93
+ readWith(profile, name) {
94
+ checkName(name);
95
+ const token = this.read(profile);
96
+ if (!token)
97
+ return undefined;
98
+ if (token.source === "environment")
99
+ return { token, secret: this.#options.env?.[this.secretVariable(name)] || undefined };
100
+ return { token, secret: this.#held(profile).secrets[name] };
85
101
  }
86
102
  /** The token and every named secret: the whole entry, as `session end` wants. */
87
103
  remove(profile) {
@@ -15,6 +15,8 @@ export interface ServiceApiCallOptions {
15
15
  token?: () => string | Promise<string>;
16
16
  /** In place of the manifest's first server. */
17
17
  baseUrl?: string;
18
+ /** The values of the server's free variables, such as `{ site }` from the profile's sign-in (`recalledSite`). */
19
+ serverVariables?: Readonly<Record<string, string>>;
18
20
  /** Headers beside the sign-in, such as the API version. */
19
21
  headers?: (operation: ManifestOperation) => Record<string, string>;
20
22
  failure?: HttpApiSendOptions["failure"];
@@ -10,7 +10,7 @@ const NO_COMMAND = new Command("source");
10
10
  * sends reads only; a write goes through the `api` group, where the profile's guard asks.
11
11
  */
12
12
  export const serviceApiCall = (options) => {
13
- const baseUrl = manifestBaseUrl(options.manifest, options.baseUrl);
13
+ const baseUrl = manifestBaseUrl(options.manifest, options.baseUrl, options.serverVariables);
14
14
  const operations = new Map(options.manifest.operations.map((one) => [one.id, one]));
15
15
  const send = httpApiSend({ service: options.service, fetch: () => options.fetch, failure: options.failure });
16
16
  return async (id, input) => {
@@ -8,10 +8,16 @@ export interface ServiceApiManifest {
8
8
  security?: readonly SecurityRequirement[];
9
9
  }
10
10
  /**
11
- * The first server the spec names. A variable is filled with its default only when its `enum` lists the choices: a
12
- * free one (`{subdomain}`) names the owner's own host, which the default would send the token past.
11
+ * The first server the spec names. A variable is filled from `variables` first, such as the site a profile signed in
12
+ * to; else with its default, only when its `enum` lists the choices: a free one (`{site}`) names the owner's own host,
13
+ * which the default would send the token past.
13
14
  */
14
- export declare const manifestBaseUrl: (manifest: ServiceApiManifest, given?: string) => string;
15
+ export declare const manifestBaseUrl: (manifest: ServiceApiManifest, given?: string, variables?: Readonly<Record<string, string>>) => string;
16
+ /**
17
+ * The site an owner types, as a server's free variable takes it: a host with a port or a path if any, from
18
+ * `blog.example.com` or `https://blog.example.com/`. Only https: an `http://` address is refused, not rewritten.
19
+ */
20
+ export declare const siteValue: (raw: string) => string;
15
21
  /**
16
22
  * Signs one request for its operation. Set the final URL first: a key in the query goes into it. Anything but the
17
23
  * standard sign-in header, or a key in the query, never follows a redirect, even to the same host: another host would