@wirecat/cli-core 0.696.0 → 0.698.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 (70) hide show
  1. package/CHANGELOG.md +93 -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 +12 -3
  8. package/dist/cli/documents/folders.d.ts +2 -0
  9. package/dist/cli/documents/library.d.ts +2 -0
  10. package/dist/cli/documents/library.js +5 -1
  11. package/dist/cli/documents/queries.d.ts +4 -0
  12. package/dist/cli/documents/queries.js +7 -1
  13. package/dist/cli/messenger/mcp-command.js +53 -4
  14. package/dist/cli/messenger/store-maintenance-command.js +3 -2
  15. package/dist/cli/schedule/schedule-command.js +9 -4
  16. package/dist/cli/service-api-manifest.js +25 -18
  17. package/dist/cli/service-api.js +6 -2
  18. package/dist/conversations/link.d.ts +5 -2
  19. package/dist/conversations/link.js +27 -9
  20. package/dist/crm/manifest/manifest.d.ts +2 -0
  21. package/dist/crm/manifest/manifest.js +2 -1
  22. package/dist/crm/manifest/map.d.ts +7 -2
  23. package/dist/crm/manifest/map.js +16 -9
  24. package/dist/crm/testing/manifest-fake.js +31 -2
  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 +17 -5
  29. package/dist/manifest/index.js +26 -8
  30. package/dist/mcp/all-profiles.d.ts +9 -0
  31. package/dist/mcp/all-profiles.js +56 -14
  32. package/dist/ports/wirecat-tools.js +7 -0
  33. package/dist/store/exports.d.ts +1 -0
  34. package/dist/store/exports.js +1 -0
  35. package/dist/store/recover.js +2 -0
  36. package/dist/store/sqlite/account-purge.js +1 -0
  37. package/dist/store/sqlite/batches.js +5 -2
  38. package/dist/store/sqlite/crm-files.d.ts +3 -0
  39. package/dist/store/sqlite/crm-files.js +2 -2
  40. package/dist/store/sqlite/manifest.js +2 -0
  41. package/dist/store/sqlite/migrations.generated.js +17 -0
  42. package/dist/store/sqlite/schema.d.ts +252 -0
  43. package/dist/store/sqlite/schema.js +28 -0
  44. package/dist/store/sqlite/tracker.d.ts +82 -0
  45. package/dist/store/sqlite/tracker.js +210 -0
  46. package/dist/store/store.d.ts +3 -0
  47. package/dist/store/store.js +5 -0
  48. package/dist/tracker/cli/index.d.ts +24 -0
  49. package/dist/tracker/cli/index.js +292 -0
  50. package/dist/tracker/index.d.ts +8 -0
  51. package/dist/tracker/index.js +7 -0
  52. package/dist/tracker/manifest/manifest.d.ts +76 -0
  53. package/dist/tracker/manifest/manifest.js +139 -0
  54. package/dist/tracker/manifest/map.d.ts +10 -0
  55. package/dist/tracker/manifest/map.js +86 -0
  56. package/dist/tracker/manifest/source.d.ts +18 -0
  57. package/dist/tracker/manifest/source.js +174 -0
  58. package/dist/tracker/source.d.ts +55 -0
  59. package/dist/tracker/source.js +1 -0
  60. package/dist/tracker/sync.d.ts +60 -0
  61. package/dist/tracker/sync.js +254 -0
  62. package/dist/tracker/tasks.d.ts +18 -0
  63. package/dist/tracker/tasks.js +29 -0
  64. package/dist/tracker/testing/index.d.ts +2 -0
  65. package/dist/tracker/testing/index.js +2 -0
  66. package/dist/tracker/testing/source-contract.d.ts +46 -0
  67. package/dist/tracker/testing/source-contract.js +246 -0
  68. package/dist/tracker/testing/source.d.ts +31 -0
  69. package/dist/tracker/testing/source.js +141 -0
  70. package/package.json +12 -4
@@ -67,18 +67,19 @@ const serverValue = (name, value, code = "configuration_error") => {
67
67
  * none: its security, its own or else the document's, is absent, as in a spec that says nothing about sign-in, or
68
68
  * empty (`[]`, `[{}]`). An optional sign-in (`[{}, { oauth: [] }]`) still sends the token.
69
69
  */
70
- // cli-base reads no basic scheme yet; the token of one is `<user>:<password>`, as `session start --login` keeps it.
71
- const basicPlace = (scheme) => scheme.type === "http" && /^basic$/i.test(scheme.scheme ?? "")
72
- ? {
73
- in: "header",
74
- name: "authorization",
75
- value: (token) => {
76
- if (!token.includes(":"))
77
- throw new CliError("authentication_error", "this service signs in with a user name and a password: run session start --login <name>");
78
- return `Basic ${Buffer.from(token).toString("base64")}`;
79
- },
80
- }
81
- : undefined;
70
+ const isBasic = (scheme) => scheme.type === "http" && /^basic$/i.test(scheme.scheme ?? "");
71
+ // Told apart by the scheme, not by signInPlace: a newer cli-base signs Basic and an older one does not, and
72
+ // either may be installed. Neither refuses a token without a user name. The token is `<user>:<password>`, as
73
+ // `session start --login` keeps it.
74
+ const BASIC = {
75
+ in: "header",
76
+ name: "authorization",
77
+ value: (token) => {
78
+ if (!token.includes(":"))
79
+ throw new CliError("authentication_error", "this service signs in with a user name and a password: run session start --login <name>");
80
+ return `Basic ${Buffer.from(token).toString("base64")}`;
81
+ },
82
+ };
82
83
  const authOf = (manifest, operation) => {
83
84
  const requirements = signInRequirements(operation, manifest.security);
84
85
  if (!requirements)
@@ -86,8 +87,11 @@ const authOf = (manifest, operation) => {
86
87
  const names = requirements.flatMap((one) => Object.keys(one));
87
88
  const sendable = names.flatMap((name) => {
88
89
  const scheme = manifest.securitySchemes?.[name];
89
- const place = scheme && (signInPlace(scheme) ?? basicPlace(scheme));
90
- return place ? [{ place, basic: !signInPlace(scheme) }] : [];
90
+ if (!scheme)
91
+ return [];
92
+ const basic = isBasic(scheme);
93
+ const place = basic ? BASIC : signInPlace(scheme);
94
+ return place ? [{ place, basic }] : [];
91
95
  });
92
96
  // Basic only when nothing else is offered: it needs a user name a token sign-in does not keep.
93
97
  const auth = (sendable.find((one) => one.place.in === "header" && !one.basic) ??
@@ -126,14 +130,17 @@ const numberOf = (value) => {
126
130
  };
127
131
  export const parameterValue = (input, parameter) => parameter.in === "query"
128
132
  ? input.query[parameter.name]
129
- : input.body === undefined
130
- ? undefined
131
- : parseApiJson(input.body)?.[parameter.name];
133
+ : (input.fields[parameter.name] ??
134
+ (input.body === undefined
135
+ ? undefined
136
+ : parseApiJson(input.body)?.[parameter.name]));
132
137
  export const withValue = (input, parameter, value) => {
133
138
  if (parameter.in === "query")
134
139
  return { ...input, query: { ...input.query, [parameter.name]: String(value) } };
135
140
  const body = input.body === undefined ? {} : parseApiJson(input.body);
136
- return { ...input, body: apiJson({ ...body, [parameter.name]: value }) };
141
+ // A flag of the same name would stand over the body, and every page would ask for the first.
142
+ const { [parameter.name]: _, ...fields } = input.fields;
143
+ return { ...input, fields, body: apiJson({ ...body, [parameter.name]: value }) };
137
144
  };
138
145
  /** Reads one answer by the manifest's pagination: where its items are and what the next request is. */
139
146
  export const nextPage = (pagination, input, answer) => {
@@ -83,8 +83,12 @@ export const serviceApiPermissions = (input) => {
83
83
  };
84
84
  const rowOf = (operation) => ({
85
85
  command: operation.command,
86
- method: operation.binding.kind === "http" ? operation.binding.method : "",
87
- path: operation.binding.kind === "http" ? operation.binding.path : "",
86
+ method: operation.binding.kind === "http" ? operation.binding.method : operation.binding.kind === "graphql" ? "POST" : "",
87
+ path: operation.binding.kind === "http"
88
+ ? operation.binding.path
89
+ : operation.binding.kind === "graphql"
90
+ ? `${operation.binding.operation} ${operation.binding.field}`
91
+ : "",
88
92
  effect: operation.effect,
89
93
  summary: operation.summary ?? "",
90
94
  });
@@ -1,6 +1,9 @@
1
1
  import type { Id, Message } from "../domain/models.js";
2
- /** 5: a message longer than a chunk is split into overlapping pieces, so builds before it are outdated. */
3
- export declare const RULES_VERSION = 5;
2
+ /**
3
+ * 5: a message longer than a chunk is split into overlapping pieces. 6: a message's parent is always in its own
4
+ * topic or thread, so a forum's topics are no longer one conversation. Builds before the current version are outdated.
5
+ */
6
+ export declare const RULES_VERSION = 6;
4
7
  /** How far back a rule looks, in messages: 97% of reply parents sat within 50 in a measured group. */
5
8
  export declare const LOOK_BACK = 50;
6
9
  export type LinkInput = Pick<Message, "id" | "senderId" | "text" | "timestamp" | "replyToId" | "threadId" | "mentions"> & Partial<Pick<Message, "senderName">>;
@@ -1,5 +1,8 @@
1
- /** 5: a message longer than a chunk is split into overlapping pieces, so builds before it are outdated. */
2
- export const RULES_VERSION = 5;
1
+ /**
2
+ * 5: a message longer than a chunk is split into overlapping pieces. 6: a message's parent is always in its own
3
+ * topic or thread, so a forum's topics are no longer one conversation. Builds before the current version are outdated.
4
+ */
5
+ export const RULES_VERSION = 6;
3
6
  /** How far back a rule looks, in messages: 97% of reply parents sat within 50 in a measured group. */
4
7
  export const LOOK_BACK = 50;
5
8
  // Tuned on the IRC dev split (bench/disentangle/sweep.ts); wider windows gained nothing.
@@ -13,32 +16,46 @@ export const linkMessages = (messages, { handles = new Map(), answers = new Map(
13
16
  const links = [];
14
17
  const parents = new Map();
15
18
  const conversationOf = new Map();
19
+ const held = new Map();
16
20
  const conversations = [];
17
21
  const window = [];
18
22
  for (const message of messages) {
19
23
  check?.();
20
24
  const found = [
21
- ...replyLink(message, conversationOf),
25
+ ...replyLink(message, held),
22
26
  ...mentionLinks(message, window, handles),
23
27
  ...sameSenderLink(message, window),
24
28
  ];
25
29
  links.push(...found);
26
- const parent = choose(found, answers, message.id, conversationOf);
30
+ const parent = choose(found, answers, message, held);
27
31
  parents.set(message.id, parent);
28
32
  const conversation = parent === null ? conversations.length : conversationOf.get(parent);
29
33
  if (conversation === conversations.length)
30
34
  conversations.push([]);
31
35
  conversations[conversation]?.push(message.id);
32
36
  conversationOf.set(message.id, conversation);
37
+ held.set(message.id, { threadId: message.threadId, text: message.text.trim() !== "" });
33
38
  window.push(message);
34
39
  if (window.length > LOOK_BACK)
35
40
  window.shift();
36
41
  }
37
42
  return { links, parents, conversations };
38
43
  };
39
- const replyLink = (message, held) => message.replyToId !== undefined && held.has(message.replyToId)
44
+ const replyLink = (message, held) => message.replyToId !== undefined && inThread(held, message.replyToId, message)
40
45
  ? [link(message, message.replyToId, "provider", "reply", 1, "reply")]
41
46
  : [];
47
+ /**
48
+ * Whether `id` may be the message's parent: a message of the same topic or thread, or the thread's own first
49
+ * message when it says something, as a WhatsApp community post its comments answer. A Telegram forum topic starts
50
+ * with an empty service message every message of the topic replies to: linked, it chained the whole topic, and
51
+ * through those first messages' sender every topic, into one conversation.
52
+ */
53
+ const inThread = (held, id, message) => {
54
+ const parent = held.get(id);
55
+ if (!parent)
56
+ return false;
57
+ return parent.threadId === message.threadId || (id === message.threadId && parent.text);
58
+ };
42
59
  const mentionLinks = (message, window, handles) => {
43
60
  const links = [];
44
61
  const people = new Set([...mentioned(message.text, handles)].flatMap((handle) => handles.get(handle) ?? []));
@@ -74,15 +91,16 @@ const mentioned = (text, handles) => {
74
91
  return found;
75
92
  };
76
93
  /** The messenger's reply first, then the most confident rule; on a tie, the one found first. */
77
- const choose = (links, answers, id, held) => {
94
+ const choose = (links, answers, message, held) => {
78
95
  const provider = links.find((one) => one.source === "provider");
79
96
  if (provider)
80
97
  return provider.parentId;
81
- // An answer naming a message this chat no longer holds, or a later one, leaves the choice to the rules.
82
- const answer = answers.get(id);
98
+ // An answer naming a message this chat no longer holds, a later one or one in another topic leaves the choice
99
+ // to the rules.
100
+ const answer = answers.get(message.id);
83
101
  if (answer === null)
84
102
  return null;
85
- if (answer !== undefined && held.has(answer))
103
+ if (answer !== undefined && inThread(held, answer, message))
86
104
  return answer;
87
105
  let best;
88
106
  for (const one of links)
@@ -1,3 +1,4 @@
1
+ import * as v from "valibot";
1
2
  import type { ServiceApiCall } from "../../cli/service-api-call.js";
2
3
  import type { ServiceApiManifest } from "../../cli/service-api-manifest.js";
3
4
  import { type CrmKind, type CrmRecords } from "../../domain/crm.js";
@@ -188,6 +189,7 @@ export interface CrmManifestHooks {
188
189
  /** Adds or replaces source methods (`self`, `activities`, a live `list`); `base` is what the manifest built. */
189
190
  extend?: (base: CrmSource) => Partial<CrmSource>;
190
191
  }
192
+ export declare const crmRuleSchema: v.GenericSchema<CrmRule>;
191
193
  /**
192
194
  * The manifest checked against its shape and the generated API: each operation exists, a list pages or says where its
193
195
  * rows are, a change call places `{since}`, a deal or lead kind has pipelines. Every error names where it is.
@@ -6,7 +6,7 @@ import { editDistance } from "../../search/correct.js";
6
6
  import { FIELDS } from "./map.js";
7
7
  const path = v.pipe(v.string(), v.regex(/^[^.\s]+(\.[^.\s]+)*$/, "a dotted path such as properties.name"));
8
8
  const paths = v.pipe(v.array(path), v.minLength(1));
9
- const rule = v.union([
9
+ export const crmRuleSchema = v.union([
10
10
  path,
11
11
  v.strictObject({ first: paths }),
12
12
  v.strictObject({ join: paths }),
@@ -18,6 +18,7 @@ const rule = v.union([
18
18
  v.strictObject({ value: v.unknown() }),
19
19
  v.function(),
20
20
  ], "a path, one of first, join, all, path, each, value, or a function");
21
+ const rule = crmRuleSchema;
21
22
  const call = v.strictObject({
22
23
  operation: v.pipe(v.string(), v.minLength(1)),
23
24
  path: v.optional(v.record(v.string(), v.string())),
@@ -1,10 +1,14 @@
1
1
  import type { CrmField, CrmKind, CrmRecords } from "../../domain/crm.js";
2
- import { type CrmRaw, id, text } from "../values.js";
2
+ import { type CrmRaw, id, number, text } from "../values.js";
3
3
  import type { CrmRule } from "./manifest.js";
4
4
  /** The service sent nothing at this path: the field is left out, so the stored copy keeps what it held. */
5
5
  export declare const MISSING: unique symbol;
6
6
  type Read = unknown | typeof MISSING;
7
- /** A dotted path; a number steps into a list (`results.0.id`), and `.` is the value itself. */
7
+ /**
8
+ * A dotted path; a number steps into a list (`results.0.id`), and `.` is the value itself. Past the end of a list the
9
+ * service sent, or under a `null` it sent, is "none" (`null`), not "not sent": a cleared value must clear the copy,
10
+ * as Attio's `values.job_title.0.value` on an empty list.
11
+ */
8
12
  export declare const at: (value: unknown, path: string) => unknown;
9
13
  export declare const evaluate: (rule: CrmRule, raw: CrmRaw) => Read;
10
14
  /** A time as epoch ms: ISO, epoch seconds, or epoch ms as digits in a string (HubSpot sends both forms). */
@@ -18,6 +22,7 @@ declare const CONVERT: {
18
22
  epoch: typeof epochOf;
19
23
  day: typeof dayOf;
20
24
  bool: typeof yes;
25
+ number: typeof number;
21
26
  texts: (value: unknown) => string[];
22
27
  ids: (value: unknown) => string[];
23
28
  status: (value: unknown) => string | null;
@@ -1,17 +1,23 @@
1
1
  import { DEAL_STATUSES } from "../../domain/deals.js";
2
- import { amountOf, crmValuesOf, epoch, fullName, id, isRaw, text } from "../values.js";
2
+ import { amountOf, crmValuesOf, epoch, fullName, id, isRaw, number, text } from "../values.js";
3
3
  /** The service sent nothing at this path: the field is left out, so the stored copy keeps what it held. */
4
4
  export const MISSING = Symbol("missing");
5
- /** A dotted path; a number steps into a list (`results.0.id`), and `.` is the value itself. */
5
+ /**
6
+ * A dotted path; a number steps into a list (`results.0.id`), and `.` is the value itself. Past the end of a list the
7
+ * service sent, or under a `null` it sent, is "none" (`null`), not "not sent": a cleared value must clear the copy,
8
+ * as Attio's `values.job_title.0.value` on an empty list.
9
+ */
6
10
  export const at = (value, path) => path === "."
7
11
  ? value
8
- : path.split(".").reduce((inner, key) =>
9
- // Past the end of a list the service sent is "none", not "not sent": a removed link must leave the copy.
10
- Array.isArray(inner) && /^\d+$/.test(key)
11
- ? (inner[Number(key)] ?? null)
12
- : isRaw(inner)
13
- ? inner[key]
14
- : undefined, value);
12
+ : path
13
+ .split(".")
14
+ .reduce((inner, key) => inner === null
15
+ ? null
16
+ : Array.isArray(inner) && /^\d+$/.test(key)
17
+ ? (inner[Number(key)] ?? null)
18
+ : isRaw(inner)
19
+ ? inner[key]
20
+ : undefined, value);
15
21
  const read = (raw, path) => {
16
22
  const found = at(raw, path);
17
23
  return found === undefined ? MISSING : found;
@@ -86,6 +92,7 @@ const CONVERT = {
86
92
  epoch: epochOf,
87
93
  day: dayOf,
88
94
  bool: yes,
95
+ number,
89
96
  texts: (value) => unique(listOf(value).map(text)),
90
97
  ids: (value) => linksOf(value).map(({ externalId }) => externalId),
91
98
  status: (value) => {
@@ -119,6 +119,33 @@ export const crmManifestFake = (input, options) => {
119
119
  return undefined;
120
120
  return ["string", "unknown"].includes(type) ? String(value) : undefined;
121
121
  };
122
+ /**
123
+ * The schema with each union on the way to `keys` cut to the branch that has the rest of the path: a sample of the
124
+ * first branch of Attio's seventeen value types would carry another type's fields, and the strict fake refuses it.
125
+ */
126
+ const narrowed = (node, keys) => {
127
+ if (keys.length === 0)
128
+ return node;
129
+ const found = resolve(node, definitions);
130
+ const [key, ...rest] = keys;
131
+ const fits = (one) => "node" in walk(one, keys.join("."), definitions);
132
+ switch (found.type) {
133
+ case "union": {
134
+ const branch = found.of.find(fits);
135
+ return branch ? narrowed(branch, keys) : node;
136
+ }
137
+ case "allOf":
138
+ return { ...found, of: found.of.map((one) => (fits(one) ? narrowed(one, keys) : one)) };
139
+ case "array":
140
+ return /^\d+$/.test(key) ? { ...found, items: narrowed(found.items, rest) } : node;
141
+ case "object": {
142
+ const inner = found.properties[key] ?? found.additionalProperties;
143
+ return inner ? { ...found, properties: { ...found.properties, [key]: narrowed(inner, rest) } } : node;
144
+ }
145
+ default:
146
+ return node;
147
+ }
148
+ };
122
149
  /** The object a dotted path ends in, with its last key and schema: what is missing is built from the schema's sample. */
123
150
  const parentOf = (row, path, node) => {
124
151
  const keys = path.split(".");
@@ -128,7 +155,7 @@ export const crmManifestFake = (input, options) => {
128
155
  for (const [place, one] of keys.entries()) {
129
156
  const inner = schema === undefined ? undefined : (step(schema, one, definitions) ?? undefined);
130
157
  if (typeof here[one] !== "object" || here[one] === null) {
131
- const made = sample(inner);
158
+ const made = sample(inner && narrowed(inner, [...keys.slice(place + 1), key]));
132
159
  here[one] = typeof made === "object" && made !== null ? made : /^\d+$/.test(keys[place + 1] ?? key) ? [] : {};
133
160
  }
134
161
  here = here[one];
@@ -168,7 +195,9 @@ export const crmManifestFake = (input, options) => {
168
195
  }
169
196
  };
170
197
  const rowOf = (node, rules, types, n, given) => {
171
- const made = sample(node);
198
+ // Sampled already cut to the branches the rules write into, so a list the first sample holds has the right type.
199
+ const paths = Object.values(rules).flatMap((rule) => pathOf(rule) ?? []);
200
+ const made = sample(node && paths.reduce((cut, path) => narrowed(cut, path.split(".")), node));
172
201
  const row = isRaw(made) ? made : {};
173
202
  for (const [field, rule] of Object.entries(rules)) {
174
203
  const path = pathOf(rule);
@@ -0,0 +1,100 @@
1
+ /**
2
+ * What an issue tracker holds that the store copies (Linear, and any tracker after it): its teams, users, workflow
3
+ * states, labels, projects, issues and the comments on them. Teams, users, states and labels come before the
4
+ * projects and issues that name them.
5
+ */
6
+ export declare const TRACKER_KINDS: readonly ["team", "user", "state", "label", "project", "issue", "comment"];
7
+ export type TrackerKind = (typeof TRACKER_KINDS)[number];
8
+ /** Where an issue in a state stands in its work, whatever the team named the state. */
9
+ export declare const STATE_TYPES: readonly ["triage", "backlog", "unstarted", "started", "completed", "canceled"];
10
+ export type StateType = (typeof STATE_TYPES)[number];
11
+ /**
12
+ * Every record has the tracker's id. A field left out means the tracker did not say, and the store keeps what it
13
+ * held; `null` means the tracker said there is none. Times are epoch milliseconds.
14
+ */
15
+ interface TrackerRecord {
16
+ externalId: string;
17
+ createdAt?: number | null;
18
+ updatedAt?: number | null;
19
+ /** The tracker archived it: it still exists, and a read that asks for archived rows lists it. */
20
+ archivedAt?: number | null;
21
+ }
22
+ export interface TrackerTeam extends TrackerRecord {
23
+ name: string;
24
+ /** The short key an issue's key starts with: `ENG`. */
25
+ key?: string | null;
26
+ }
27
+ export interface TrackerUser extends TrackerRecord {
28
+ name: string;
29
+ /** How the store joins the user to a person it already knows: by this exact address. */
30
+ email?: string | null;
31
+ active?: boolean | null;
32
+ }
33
+ export interface TrackerState extends TrackerRecord {
34
+ name: string;
35
+ type: StateType;
36
+ team?: string | null;
37
+ /** Any numbers; the order they give is the board's. */
38
+ position?: number | null;
39
+ }
40
+ export interface TrackerLabel extends TrackerRecord {
41
+ name: string;
42
+ team?: string | null;
43
+ }
44
+ export interface TrackerProject extends TrackerRecord {
45
+ name: string;
46
+ description?: string | null;
47
+ /** The tracker's own word for where the project stands: `planned`, `started`. */
48
+ status?: string | null;
49
+ /** A user's id. */
50
+ lead?: string | null;
51
+ teams?: string[];
52
+ /** `YYYY-MM-DD`. */
53
+ targetDate?: string | null;
54
+ url?: string | null;
55
+ }
56
+ export interface TrackerIssue extends TrackerRecord {
57
+ title: string;
58
+ /** The readable key people say: `ENG-12`. */
59
+ key?: string | null;
60
+ description?: string | null;
61
+ state?: string | null;
62
+ team?: string | null;
63
+ project?: string | null;
64
+ /** Users' ids. */
65
+ assignee?: string | null;
66
+ creator?: string | null;
67
+ labels?: string[];
68
+ /** The issue this one is a part of. */
69
+ parent?: string | null;
70
+ /** 0 is none, then 1 the most urgent: Linear's scale, which a tracker with another one maps onto. */
71
+ priority?: number | null;
72
+ /** `YYYY-MM-DD`. */
73
+ dueDate?: string | null;
74
+ completedAt?: number | null;
75
+ canceledAt?: number | null;
76
+ url?: string | null;
77
+ }
78
+ export interface TrackerComment extends TrackerRecord {
79
+ issue: string;
80
+ body: string;
81
+ /** A user's id; none when an integration wrote it. */
82
+ author?: string | null;
83
+ url?: string | null;
84
+ }
85
+ export interface TrackerRecords {
86
+ team: TrackerTeam;
87
+ user: TrackerUser;
88
+ state: TrackerState;
89
+ label: TrackerLabel;
90
+ project: TrackerProject;
91
+ issue: TrackerIssue;
92
+ comment: TrackerComment;
93
+ }
94
+ /** The record's title in lists and search: an issue's title, a comment's start, anything else's name. */
95
+ export declare const trackerTitleOf: <K extends TrackerKind>(kind: K, record: TrackerRecords[K]) => string;
96
+ /** The record's text that search reads beside its title: a description or a comment's body. */
97
+ export declare const trackerBodyOf: <K extends TrackerKind>(kind: K, record: TrackerRecords[K]) => string | null | undefined;
98
+ /** The record its row hangs under: a comment's issue, a state's or a label's team. */
99
+ export declare const trackerParentOf: <K extends TrackerKind>(kind: K, record: TrackerRecords[K]) => string | null | undefined;
100
+ export {};
@@ -0,0 +1,28 @@
1
+ /**
2
+ * What an issue tracker holds that the store copies (Linear, and any tracker after it): its teams, users, workflow
3
+ * states, labels, projects, issues and the comments on them. Teams, users, states and labels come before the
4
+ * projects and issues that name them.
5
+ */
6
+ export const TRACKER_KINDS = ["team", "user", "state", "label", "project", "issue", "comment"];
7
+ /** Where an issue in a state stands in its work, whatever the team named the state. */
8
+ export const STATE_TYPES = ["triage", "backlog", "unstarted", "started", "completed", "canceled"];
9
+ /** The record's title in lists and search: an issue's title, a comment's start, anything else's name. */
10
+ export const trackerTitleOf = (kind, record) => kind === "issue"
11
+ ? record.title
12
+ : kind === "comment"
13
+ ? record.body.split("\n")[0]?.slice(0, 120) || "(comment)"
14
+ : record.name;
15
+ /** The record's text that search reads beside its title: a description or a comment's body. */
16
+ export const trackerBodyOf = (kind, record) => kind === "comment"
17
+ ? record.body
18
+ : kind === "issue" || kind === "project"
19
+ ? record.description
20
+ : null;
21
+ /** The record its row hangs under: a comment's issue, a state's or a label's team. */
22
+ export const trackerParentOf = (kind, record) => kind === "comment"
23
+ ? record.issue
24
+ : kind === "state" || kind === "label"
25
+ ? record.team
26
+ : kind === "issue"
27
+ ? record.team
28
+ : null;
@@ -487,6 +487,7 @@ const OTHERS = [
487
487
  validation("crm.owner-unknown", "owner: names no CRM user: me without a known sign-in user, or not a user id"),
488
488
  validation("crm.write-unsupported", "the CRM does not take this write, or does not recognise a repeated one"),
489
489
  validation("crm.unlisted-held", "a list of every id would mark most of a kind deleted; nothing was, until --rescan"),
490
+ validation("tracker.unlisted-held", "a tracker's id list would mark too much deleted, or the sign-in read only part; nothing was, until --rescan"),
490
491
  validation("crm.narrowing-held", "the default scope mine would mark most of a kind's stored rows deleted; none is, until the owner sets the scope"),
491
492
  validation("crm.unassigned-dropped", "the CRM does not let this sign-in choose a user in unassigned; that user's deals are not copied"),
492
493
  validation("crm.not-reported", "the CRM did not list users or departments; what they would say is unknown, nothing withdrawn"),
@@ -1,5 +1,8 @@
1
1
  import type { CrmManifest } from "../crm/manifest/manifest.js";
2
2
  import type { OAuthProvider } from "../oauth/provider.js";
3
+ import type { TrackerManifest } from "../tracker/manifest/manifest.js";
4
+ /** A dotted path into an answer, as the source manifest reads it: `auth.verify`'s `id`, `name` and `active`. */
5
+ export { at as valueAt } from "../crm/manifest/map.js";
3
6
  /**
4
7
  * The operation that answers whose the token is, and where its answer holds the account's id (and a name to show):
5
8
  * `{ operation: "getV2Self", id: "workspace_id", name: "workspace_name" }`. `session start` checks a token with it.
@@ -8,6 +11,12 @@ export interface CliVerify {
8
11
  operation: string;
9
12
  id: string;
10
13
  name?: string;
14
+ /**
15
+ * Where the answer says the token still works, for a service that answers a dead token with success: Attio's
16
+ * `GET /v2/self` gives 200 `{ "active": false }` to an unknown, revoked or deleted token. Anything but `true` there is
17
+ * a refused sign-in.
18
+ */
19
+ active?: string;
11
20
  }
12
21
  export type CliAuth = {
13
22
  preset: "none";
@@ -29,7 +38,7 @@ export type CliAuth = {
29
38
  /** The provider sends a new refresh token on each refresh; the spec cannot say so. */
30
39
  rotating?: boolean;
31
40
  };
32
- export declare const CLI_CATEGORIES: readonly ["messenger", "mail", "notes", "files", "meetings", "calendar", "crm", "other"];
41
+ export declare const CLI_CATEGORIES: readonly ["messenger", "mail", "notes", "files", "meetings", "calendar", "crm", "tracker", "other"];
33
42
  export type CliCategory = (typeof CLI_CATEGORIES)[number];
34
43
  /** One file, `wirecat.config.ts`, that `new --from-config` builds a CLI from. */
35
44
  export interface CliConfig {
@@ -47,21 +56,24 @@ export interface CliConfig {
47
56
  };
48
57
  /** `from`: the https URL the description is published at. */
49
58
  spec: {
50
- kind: "openapi" | "swagger";
59
+ kind: "openapi" | "swagger" | "graphql";
51
60
  from: string;
52
61
  };
53
62
  auth: CliAuth;
54
63
  /** cli-template's `--category`; `other` is any API outside them. */
55
64
  category: CliCategory;
56
- /** The CRM source; checked against the generated API by `parseCrmManifest` once the api group exists. */
57
- source?: CrmManifest;
65
+ /**
66
+ * A crm or tracker CLI's source; checked against the generated API by `parseCrmManifest` or `parseTrackerManifest`
67
+ * once the api group exists.
68
+ */
69
+ source?: CrmManifest | TrackerManifest;
58
70
  /** The module of named hooks, relative to the config: `./src/hooks.ts`. */
59
71
  hooks?: string;
60
72
  }
61
73
  /** Types the config in the editor; it returns what it is given. */
62
74
  export declare const defineCli: (config: CliConfig) => CliConfig;
63
75
  /**
64
- * The config checked against its shape; every error names where it is. A CRM CLI needs its source. `source` comes back
76
+ * The config checked against its shape; every error names where it is. A crm or tracker CLI needs its source. `source` comes back
65
77
  * unchecked: `parseCrmManifest` checks it against the generated API.
66
78
  */
67
79
  export declare const parseCliConfig: (input: unknown) => CliConfig;
@@ -1,6 +1,18 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import * as v from "valibot";
3
- export const CLI_CATEGORIES = ["messenger", "mail", "notes", "files", "meetings", "calendar", "crm", "other"];
3
+ /** A dotted path into an answer, as the source manifest reads it: `auth.verify`'s `id`, `name` and `active`. */
4
+ export { at as valueAt } from "../crm/manifest/map.js";
5
+ export const CLI_CATEGORIES = [
6
+ "messenger",
7
+ "mail",
8
+ "notes",
9
+ "files",
10
+ "meetings",
11
+ "calendar",
12
+ "crm",
13
+ "tracker",
14
+ "other",
15
+ ];
4
16
  /** Types the config in the editor; it returns what it is given. */
5
17
  export const defineCli = (config) => config;
6
18
  const word = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/, "lower-case letters and digits, words joined by one dash"));
@@ -37,7 +49,12 @@ const httpsUrl = v.pipe(v.string(), v.check((text) => !/\s/.test(text), "an http
37
49
  // A token handed back in the fragment (OAuth's implicit flow) would be committed too; a description needs none.
38
50
  v.check((text) => !urlOf(text)?.hash, "an https URL without a #fragment"));
39
51
  const dotPath = v.pipe(v.string(), v.regex(/^[^.\s]+(\.[^.\s]+)*$/, "a dot path into the answer, such as data.id"));
40
- const verify = v.optional(v.strictObject({ operation: v.pipe(v.string(), v.minLength(1)), id: dotPath, name: v.optional(dotPath) }));
52
+ const verify = v.optional(v.strictObject({
53
+ operation: v.pipe(v.string(), v.minLength(1)),
54
+ id: dotPath,
55
+ name: v.optional(dotPath),
56
+ active: v.optional(dotPath),
57
+ }));
41
58
  const schema = v.strictObject({
42
59
  identity: v.strictObject({
43
60
  command: word,
@@ -47,7 +64,7 @@ const schema = v.strictObject({
47
64
  owner: v.pipe(v.string(), v.regex(/^[A-Za-z0-9](?:-?[A-Za-z0-9]){0,38}$/, "a GitHub owner")),
48
65
  }),
49
66
  spec: v.strictObject({
50
- kind: v.picklist(["openapi", "swagger"]),
67
+ kind: v.picklist(["openapi", "swagger", "graphql"]),
51
68
  from: httpsUrl,
52
69
  }),
53
70
  auth: v.variant("preset", [
@@ -72,7 +89,7 @@ const schema = v.strictObject({
72
89
  hooks: v.optional(v.pipe(v.string(), v.regex(/^\.\/([^\s]*\/)?[^/\s.][^/\s]*\.[cm]?[jt]s$/, "a module in the project, such as ./src/hooks.ts"), v.check((text) => !/\.d\.[cm]?ts$/.test(text), "a module, not a .d.ts declaration file"), v.check((text) => !text.split(/[\\/]/).includes(".."), "a module in the project, without .."))),
73
90
  });
74
91
  /**
75
- * The config checked against its shape; every error names where it is. A CRM CLI needs its source. `source` comes back
92
+ * The config checked against its shape; every error names where it is. A crm or tracker CLI needs its source. `source` comes back
76
93
  * unchecked: `parseCrmManifest` checks it against the generated API.
77
94
  */
78
95
  export const parseCliConfig = (input) => {
@@ -94,12 +111,13 @@ export const parseCliConfig = (input) => {
94
111
  // Typed, not cast: a field CliConfig needs that the schema lacks or types otherwise fails to compile (not the reverse).
95
112
  const output = parsed.output;
96
113
  const config = output;
97
- if (config.category !== "crm" && config.source)
98
- throw new CliError("configuration_error", "wirecat.config: source: only a crm CLI reads a source yet", {
114
+ const sourced = config.category === "crm" || config.category === "tracker";
115
+ if (!sourced && config.source)
116
+ throw new CliError("configuration_error", "wirecat.config: source: only a crm or tracker CLI reads a source yet", {
99
117
  reason: "manifest.invalid",
100
118
  });
101
- if (config.category === "crm" && !config.source)
102
- throw new CliError("configuration_error", "wirecat.config: source: a crm CLI needs its source", {
119
+ if (sourced && !config.source)
120
+ throw new CliError("configuration_error", `wirecat.config: source: a ${config.category} CLI needs its source`, {
103
121
  reason: "manifest.invalid",
104
122
  });
105
123
  return config;
@@ -21,6 +21,10 @@ export interface AllProfilesOptions {
21
21
  /** How to sign a profile in, for the refusal of a call it cannot serve yet. */
22
22
  signIn?: (profile: string) => string;
23
23
  child: (profile: string) => ChildSpec;
24
+ /** The tools a profile's server would list, for a session that starts before any profile exists. */
25
+ catalogue?: () => Promise<readonly Tool[]>;
26
+ /** How to set up the first profile: every call of a session with no profile is refused with it. */
27
+ setup?: string;
24
28
  instructions: string;
25
29
  idleMs?: number;
26
30
  /** A child's stderr, line by line; never this process's stdout, which carries the protocol. */
@@ -44,6 +48,11 @@ export declare const allProfilesServer: (options: AllProfilesOptions) => {
44
48
  build: () => McpServer;
45
49
  close: () => Promise<void>;
46
50
  };
51
+ /**
52
+ * What a server answers to `tools/list`, asked in this process: the list for a session with no profile, which has no
53
+ * profile's server to ask.
54
+ */
55
+ export declare const listedTools: (server: McpServer) => Promise<Tool[]>;
47
56
  /** Over stdin and stdout until the client closes stdin or the process is told to stop; then the children close. */
48
57
  export declare const serveAllProfilesOverStdio: (options: AllProfilesOptions, io?: {
49
58
  stdin?: Readable;