@wirecat/cli-core 0.723.0 → 0.725.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 (59) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/cli/documents/file-conflicts.d.ts +7 -2
  3. package/dist/cli/documents/file-conflicts.js +5 -4
  4. package/dist/cli/documents/file-edit.js +4 -4
  5. package/dist/cli/documents/history.js +2 -2
  6. package/dist/cli/documents/index.d.ts +1 -1
  7. package/dist/cli/documents/words.d.ts +1 -1
  8. package/dist/cli/messenger/search-answers.js +4 -0
  9. package/dist/cli/search-left-out.d.ts +1 -0
  10. package/dist/cli/search-left-out.js +1 -0
  11. package/dist/content/writes.d.ts +3 -9
  12. package/dist/content/writes.js +3 -13
  13. package/dist/crm/manifest/writer.js +1 -1
  14. package/dist/crm/testing/manifest-fake.js +2 -2
  15. package/dist/crm/writes.d.ts +4 -13
  16. package/dist/crm/writes.js +2 -9
  17. package/dist/domain/providers.d.ts +1 -1
  18. package/dist/domain/providers.js +4 -1
  19. package/dist/entities/hit.d.ts +3 -2
  20. package/dist/entities/hit.js +5 -1
  21. package/dist/entities/index.d.ts +1 -1
  22. package/dist/errors/reasons.js +27 -1
  23. package/dist/office/docx.js +10 -10
  24. package/dist/office/xlsx.js +17 -17
  25. package/dist/search/account-list.js +1 -0
  26. package/dist/sends/profile-writes.d.ts +22 -0
  27. package/dist/sends/profile-writes.js +20 -0
  28. package/dist/services/metadata.d.ts +1 -1
  29. package/dist/services/search-all.d.ts +7 -3
  30. package/dist/services/search-all.js +51 -1
  31. package/dist/tracker/cli/index.d.ts +10 -1
  32. package/dist/tracker/cli/index.js +20 -1
  33. package/dist/tracker/cli/writes.d.ts +27 -0
  34. package/dist/tracker/cli/writes.js +74 -0
  35. package/dist/tracker/index.d.ts +5 -2
  36. package/dist/tracker/index.js +5 -2
  37. package/dist/tracker/manifest/manifest.d.ts +25 -0
  38. package/dist/tracker/manifest/manifest.js +59 -8
  39. package/dist/tracker/manifest/source.d.ts +10 -1
  40. package/dist/tracker/manifest/source.js +12 -9
  41. package/dist/tracker/manifest/writer.d.ts +20 -0
  42. package/dist/tracker/manifest/writer.js +72 -0
  43. package/dist/tracker/sync.d.ts +5 -0
  44. package/dist/tracker/sync.js +12 -0
  45. package/dist/tracker/testing/index.d.ts +3 -1
  46. package/dist/tracker/testing/index.js +3 -1
  47. package/dist/tracker/testing/manifest-fake.d.ts +2 -0
  48. package/dist/tracker/testing/manifest-fake.js +123 -41
  49. package/dist/tracker/testing/manifest-writes.d.ts +16 -0
  50. package/dist/tracker/testing/manifest-writes.js +70 -0
  51. package/dist/tracker/testing/source.d.ts +9 -1
  52. package/dist/tracker/testing/source.js +63 -0
  53. package/dist/tracker/testing/write-contract.d.ts +20 -0
  54. package/dist/tracker/testing/write-contract.js +94 -0
  55. package/dist/tracker/writer.d.ts +57 -0
  56. package/dist/tracker/writer.js +25 -0
  57. package/dist/tracker/writes.d.ts +53 -0
  58. package/dist/tracker/writes.js +226 -0
  59. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -5,6 +5,76 @@ 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.725.0 — 23.11.2026
9
+
10
+ ### Added
11
+
12
+ - **`search all` finds a tracker's issues, projects and comments.** A new lane, `tracker`, reads every tracker
13
+ account's copy by the words of titles and text, as `issues search` does, beside messages, mail, notes and the rest.
14
+ Hits are `issue` (titled with the key, `ENG-12 Fix login`), `project` and `issue_comment`, with ref
15
+ `tracker:<provider>/<account>/<kind>/<id>`, their title and excerpt untrusted. A provider kind `tracker` joins the
16
+ registry, and `linear` is seeded as one. A CLI that gates `search all` lanes by list keys gates issues and comments
17
+ by `issues.list` and projects by `projects.list`: memo needs that gate in the bump that brings this lane
18
+ ([TRACKER.md](docs/dev/TRACKER.md#search-all)).
19
+
20
+ ### Changed — may break callers
21
+
22
+ - **`mirrors conflicts resolve` runs inside the app's run.** `FileConflictCommands.connect(command, mirror, body)` now
23
+ takes the body and runs it inside the app's run, so a resolve is bounded by `--timeout`, kept by `--record` under its
24
+ own name, and its requests land in that run. Before, `connect` answered the connection and the resolve ran outside
25
+ any run. A CLI that mounts `fileConflictsCommand` wraps `body(connection)` in its own run, as its `mirrors sync`
26
+ does; `FileConflictConnection` is the type it hands over (#3230).
27
+ - **The Office edit refusals keep their own reason, spelled like every other reason.** `office.formula_cell` and the
28
+ other `office.*` reasons were not registered, so the CLI and MCP showed `input.invalid` in their place, and the
29
+ registry refuses an underscore. They are registered now and use hyphens: `office.formula-cell`,
30
+ `office.wrong-format`, `office.invalid-cell`, `office.no-sheet` and the rest
31
+ ([Editing Office files](docs/office.md)). Code that compared `details.reason` with the old spelling compares
32
+ with the new one.
33
+
34
+ ### Fixed
35
+
36
+ - **The shared `changes` command passes the command lint.** With cli-base 0.129.0 or later, whose vocabulary has the
37
+ view `changes` and the flags `--since <time>` and `--event <events>`, and the `--until <time>` cli-core 0.724.0
38
+ takes, a documents CLI needs no lint override or audit difference for it. cli-core's own command lint now mounts
39
+ `documents history` and `changes`, so a new finding fails here first (#3229).
40
+ - **`crmManifestFake` keeps a written value at a place whose schema lists the values it takes.** It dropped every
41
+ value there and kept its sample, the list's first: a deal written in EUR read back in ARS from Attio's real
42
+ `currency_code`, so `crmManifestWriteContract` failed on Attio's own API description.
43
+
44
+ ## 0.724.0 — 23.11.2026
45
+
46
+ ### Added
47
+
48
+ - **CRM writes described by a source manifest.** `writes.<kind>` names a service's create, update and remove calls
49
+ and how each of our fields is sent (`to`, `each`, `list`, `number`, `decimals`, `implied`, a fixed currency,
50
+ `clear`), so a CRM CLI built from `wirecat.config.ts` gets `deals create|update|move|close|delete` and
51
+ `people create|update` with no writer of its own. A field with no rule, and a `--field` code the service does not
52
+ define, are refused before anything is sent. `crmManifestWrites` builds
53
+ `CrmRun.writes` over the CLI's fetch and token, and each write also checks its operation's `api` keys;
54
+ `crmManifestWriteCapabilities` and `crmManifestWriteKeys` give `addCrmCommands` and `crmAlsoChecks` the same.
55
+ `crmManifestWriteContract` runs `crmWriteContract` against `crmManifestFake`, which now answers writes, with
56
+ `loseNextAnswer()` and `requests()` ([CRM.md](docs/dev/CRM.md#writes-from-a-manifest)).
57
+ - **`crmSourceFromManifest` reads one record of any kind**: `record(kind, id)` by the entity's `get`, as a writer's
58
+ read-back.
59
+ - **attio in "Works with".** `WIRECAT_TOOLS` lists `attio` (`@wirecat/attio-cli`) beside the other CRM CLIs.
60
+ - **A tracker CLI creates, changes and comments on issues with its own commands.** `addTrackerCommands({ writes })`
61
+ mounts `issues create`, `issues update <issue>` and `issues comment <issue>`: a team, state, label, project or user
62
+ is named by its id or by a name only one row of the copy has (a label among the issue's team's and the workspace's),
63
+ an empty value clears a field, and a reference the copy does not hold is refused before anything is sent. Each write
64
+ passes the profile's guard on `issues.create`, `issues.update` or `issues.comment`, is journaled with the
65
+ `operation_id` it answers, previews under `--dry-run`, and stores the tracker's answer as a sync does, so
66
+ `issues show` has it at once. An `--assignee` other than the sign-in's own user also checks `issues.assign-others`,
67
+ denied by default as `crm.assign-others` is. A manifest's `writes` section maps each write to a mutation (Linear's
68
+ `issueCreate`, `issueUpdate`, `commentCreate`); `trackerWriterFromManifest` sends it through `serviceApiWriter`, so
69
+ the operation's own `api.*` key still applies. `trackerWriteContract` and `trackerManifestWriteContract` check a
70
+ writer, over a fake that answers the mutations strictly by the schema ([TRACKER.md](docs/dev/TRACKER.md#writes)).
71
+
72
+ ### Fixed
73
+
74
+ - **`changes` takes `--since <time>` and `--until <time>`**, the vocabulary's value name, where it said `<when>`. With
75
+ cli-base 0.129.0, which adds the `changes` view, `--since` and `--event`, the shared history commands pass
76
+ `cli-dev lint` in a documents CLI with no override. The flags take the same values as before.
77
+
8
78
  ## 0.723.0 — 23.11.2026
9
79
 
10
80
  ### Added
@@ -15,9 +15,14 @@ export interface FileConflictCommands {
15
15
  pathOf(mirror: Mirror, input: string): string;
16
16
  stateOf(command: Command, mirror: Mirror): FileMirrorStatePort;
17
17
  versionsOf(command: Command, mirror: Mirror): FileVersions;
18
- /** The remote signed in for the mirror's account, the write guard and the mirrors' sync lock. */
19
- connect(command: Command, mirror: Mirror): Promise<Pick<FileConflictResolveOptions, "target" | "principal" | "guard" | "operationId" | "lock" | "signal">>;
18
+ /**
19
+ * Runs `body` inside the app's run (its `--timeout`, run record and request log) with the remote signed in for the
20
+ * mirror's account, the write guard and the mirrors' sync lock; answers what `body` answered.
21
+ */
22
+ connect<T>(command: Command, mirror: Mirror, body: (connection: FileConflictConnection) => Promise<T>): Promise<T>;
20
23
  }
24
+ /** What `connect` hands `mirrors conflicts resolve`. */
25
+ export type FileConflictConnection = Pick<FileConflictResolveOptions, "target" | "principal" | "guard" | "operationId" | "lock" | "signal">;
21
26
  /**
22
27
  * `mirrors conflicts list|show|resolve` for a file mirror: the conflicts the last sync left, each with its three
23
28
  * versions and the line merge that failed, and a resolution that writes one final content to both sides.
@@ -86,16 +86,17 @@ export const fileConflictsCommand = (helpers) => {
86
86
  });
87
87
  const mirror = one(this, id);
88
88
  const keep = (args.keep === remote ? "remote" : args.keep);
89
- const resolved = await resolveFileConflict({
90
- ...(await helpers.connect(this, mirror)),
89
+ const path = helpers.pathOf(mirror, input);
90
+ const resolved = await helpers.connect(this, mirror, (connection) => resolveFileConflict({
91
+ ...connection,
91
92
  root: mirror.path,
92
93
  folder: mirror.folder,
93
- path: helpers.pathOf(mirror, input),
94
+ path,
94
95
  state: helpers.stateOf(this, mirror),
95
96
  versions: helpers.versionsOf(this, mirror),
96
97
  remote,
97
98
  choice: keep ? { keep } : { file: file },
98
- });
99
+ }));
99
100
  const resolution = resolved.resolution === "remote" ? remote : resolved.resolution;
100
101
  helpers.output(this, itemOf(snakeKeys({ id, ...resolved, resolution })));
101
102
  }));
@@ -59,7 +59,7 @@ const columnName = (column) => {
59
59
  const cornerOf = (address) => {
60
60
  const match = ADDRESS.exec(address.toUpperCase());
61
61
  if (!match)
62
- throw new CliError("validation_error", `${address} is not a cell like B7`, { reason: "office.invalid_cell" });
62
+ throw new CliError("validation_error", `${address} is not a cell like B7`, { reason: "office.invalid-cell" });
63
63
  const letters = match[1];
64
64
  return {
65
65
  column: [...letters].reduce((sum, letter) => sum * 26 + letter.charCodeAt(0) - 64, 0),
@@ -201,7 +201,7 @@ const addFileEditCommandsDefinition = (files, helpers) => {
201
201
  const wanted = sheetRangeOf(range);
202
202
  if (wanted.range === undefined)
203
203
  throw new CliError("validation_error", `${range} names no cell; give one like Sheet1!B2`, {
204
- reason: "office.invalid_cell",
204
+ reason: "office.invalid-cell",
205
205
  });
206
206
  cellEditsOf("", wanted.range, values);
207
207
  await editInPlace(this, "sheets", input, args.expectedFingerprint, async (bytes) => {
@@ -209,7 +209,7 @@ const addFileEditCommandsDefinition = (files, helpers) => {
209
209
  if (sheet === undefined) {
210
210
  const names = (await readXlsxCells(bytes, { range: "A1" })).map((one) => one.name);
211
211
  if (names.length !== 1)
212
- throw new CliError("validation_error", `the workbook has ${names.length} sheets (${names.map((name) => `"${name}"`).join(", ")}); name one, like ${names[0] ?? "Sheet1"}!${wanted.range}`, { reason: "office.no_sheet" });
212
+ throw new CliError("validation_error", `the workbook has ${names.length} sheets (${names.map((name) => `"${name}"`).join(", ")}); name one, like ${names[0] ?? "Sheet1"}!${wanted.range}`, { reason: "office.no-sheet" });
213
213
  sheet = names[0];
214
214
  }
215
215
  try {
@@ -228,7 +228,7 @@ const addFileEditCommandsDefinition = (files, helpers) => {
228
228
  };
229
229
  }
230
230
  catch (error) {
231
- if (isCliError(error) && error.details?.reason === "office.formula_cell")
231
+ if (isCliError(error) && error.details?.reason === "office.formula-cell")
232
232
  throw new CliError("validation_error", error.message.replace("pass overwriteFormulas", "pass --replace"), error.details);
233
233
  throw error;
234
234
  }
@@ -55,8 +55,8 @@ const addDocumentHistoryCommandsDefinition = (program, helpers) => {
55
55
  helpers.output(itemOf(await history.versions(ref)));
56
56
  }));
57
57
  return examples(annotate(program.command("changes"), { effects: LOCAL_READ }).description("list the documents the sync added, changed, removed or brought back, newest first"), [`${prefix} changes`, `${prefix} changes --since 7d --event deleted,unavailable`])
58
- .option("--since <when>", "from this time: an ISO 8601 time, today, yesterday, or 30m, 2h, 1d ago", "1d")
59
- .option("--until <when>", "up to this time, in the same forms")
58
+ .option("--since <time>", "from this time: an ISO 8601 time, today, yesterday, or 30m, 2h, 1d ago", "1d")
59
+ .option("--until <time>", "up to this time, in the same forms")
60
60
  .option(`--event <events>`, `only these, comma separated: ${DOCUMENT_EVENTS.join(", ")}`, eventList)
61
61
  .option("--limit <n>", "how many changes to return", positive, 50)
62
62
  .option("--page <n>", "which page to return", positive, 1)
@@ -10,7 +10,7 @@ import { type DocumentSyncCommands } from "./sync.js";
10
10
  import type { DocumentWords } from "./words.js";
11
11
  export { addDocumentCatalogCommands, CATALOG_FIELDS, type CatalogTree, type CatalogTreeSource, catalogId, catalogOutput, catalogSource, catalogTree, type DocumentCatalog, type DocumentCatalogCommands, type DocumentCatalogStores, } from "./catalog.js";
12
12
  export { addLocalDocumentCommands, type ImportedDocument, type LocalDocumentCommands } from "./documents.js";
13
- export { type FileConflictCommands, fileConflictsCommand } from "./file-conflicts.js";
13
+ export { type FileConflictCommands, type FileConflictConnection, fileConflictsCommand } from "./file-conflicts.js";
14
14
  export { addFileEditCommands, type FileEditCommands } from "./file-edit.js";
15
15
  export { addFileUpdateCommand, type FileUpdateCommands, type FileUpdatePort } from "./file-update.js";
16
16
  export { addDocumentFolderCommands, type DocumentFolderCommands } from "./folders.js";
@@ -58,8 +58,8 @@ export interface CopyAge {
58
58
  }
59
59
  export declare const ageOf: (lastSync: string | undefined, now?: number) => CopyAge;
60
60
  export declare const staleCopy: (provider: string, lastSync: string | undefined, now?: number) => {
61
- next?: undefined;
62
61
  missing?: undefined;
62
+ next?: undefined;
63
63
  meta?: undefined;
64
64
  } | {
65
65
  missing: {
@@ -297,6 +297,10 @@ const ALL_HIT_UNTRUSTED = {
297
297
  lead: ["title", "excerpt"],
298
298
  // A client's file: its name and every word of it are someone else's.
299
299
  crm_file: ["title", "excerpt"],
300
+ // Written by the tracker's users, the owner's colleagues or anyone a public issue lets in.
301
+ issue: ["title", "excerpt"],
302
+ project: ["title", "excerpt"],
303
+ issue_comment: ["title", "excerpt"],
300
304
  ...BUSINESS_UNTRUSTED,
301
305
  };
302
306
  export const allHitItem = (item) => item.kind === "meeting"
@@ -12,6 +12,7 @@ declare const LIST_KEYS: {
12
12
  readonly events: "events.list";
13
13
  readonly meetings: "meetings.list";
14
14
  readonly crm_file: "files.list";
15
+ readonly tracker: "issues.list";
15
16
  };
16
17
  export type SearchedKind = keyof typeof LIST_KEYS;
17
18
  export interface LeftOut<K extends SearchedKind> {
@@ -13,6 +13,7 @@ const LIST_KEYS = {
13
13
  events: "events.list",
14
14
  meetings: "meetings.list",
15
15
  crm_file: "files.list",
16
+ tracker: "issues.list",
16
17
  };
17
18
  /**
18
19
  * The kinds whose list `permissions` deny, for a CLI with levels of its own, such as memo's: `by` names who denies in
@@ -1,19 +1,13 @@
1
1
  import type { ContentPost } from "../domain/content.js";
2
- import type { AppIdentity } from "../ports/app.js";
3
- import type { Warn } from "../runs/events.js";
4
- import { type Asker, type GuardSettings } from "../sends/guard.js";
2
+ import type { Asker } from "../sends/guard.js";
3
+ import { type ProfileWrites } from "../sends/profile-writes.js";
5
4
  import type { MessageStore } from "../store/store.js";
6
5
  import type { AccountKey } from "../store/types.js";
7
6
  import type { ContentSource } from "./source.js";
8
7
  import { type ContentDraft, type ContentFields, type ContentWriter } from "./writer.js";
9
8
  /** What a CLI hands the content writes for one profile. */
10
- export interface ContentWrites {
9
+ export interface ContentWrites extends ProfileWrites {
11
10
  writer: ContentWriter;
12
- app: AppIdentity;
13
- /** The profile's levels, read on every write so a config change applies at once. */
14
- settings: () => Omit<GuardSettings, "sendsPerHour"> & Partial<Pick<GuardSettings, "sendsPerHour">>;
15
- env?: NodeJS.ProcessEnv;
16
- warn?: Warn;
17
11
  }
18
12
  export interface ContentWriteContext {
19
13
  store: MessageStore;
@@ -1,24 +1,14 @@
1
1
  import { CliError, isCliError } from "@wirecat/cli-base";
2
- import { guardFor } from "../sends/guard.js";
3
2
  import { guardedWrite } from "../sends/guarded.js";
4
- import { keyedGuard } from "../sends/keyed-guard.js";
5
- import { DEFAULT_PERMISSIONS, levelFor } from "../sends/permissions.js";
3
+ import { askedKeys, profileWriteGuard } from "../sends/profile-writes.js";
6
4
  import { newOperationId } from "../sends/send-id.js";
7
5
  import { CONTENT_WRITE_DEFAULTS, contentConflict, POSTS_DELETE_FORCE_KEY, POSTS_PUBLISH_KEY, } from "./writer.js";
8
6
  const PUBLIC = new Set(["published", "scheduled"]);
9
- const guardOf = (context, extra) => {
10
- const settings = context.writes.settings();
11
- const defaults = { ...DEFAULT_PERMISSIONS, ...CONTENT_WRITE_DEFAULTS, ...settings.permissionDefaults };
12
- return keyedGuard((ask) => guardFor(context.writes.app, { ...settings, sendsPerHour: Number.MAX_SAFE_INTEGER, permissionDefaults: defaults }, context.writes.warn ?? (() => { }), context.writes.env, ask), context.ask, (key) => levelFor(settings.permissions, key, defaults).level, extra);
13
- };
7
+ const guardOf = (context, extra) => profileWriteGuard(context.writes, context.ask, CONTENT_WRITE_DEFAULTS, extra);
14
8
  /** Checked and journaled once; a lost answer is `outcome_unknown`, and the owner syncs before writing again. */
15
9
  const written = async (context, key, extra, operationId, act) => {
16
10
  try {
17
- // The keys the owner was asked about here (an `ask` level) need not be asked again by a writer's own call; a key
18
- // allowed here was asked about by nobody, so it confirms nothing.
19
- const settings = context.writes.settings();
20
- const defaults = { ...DEFAULT_PERMISSIONS, ...CONTENT_WRITE_DEFAULTS, ...settings.permissionDefaults };
21
- const asked = [key, ...extra].filter((one) => levelFor(settings.permissions, one, defaults).level === "ask");
11
+ const asked = askedKeys(context.writes, CONTENT_WRITE_DEFAULTS, [key, ...extra]);
22
12
  return await guardedWrite(guardOf(context, extra), { chatId: null, kind: "edit", key, operationId }, () => act(asked));
23
13
  }
24
14
  catch (error) {
@@ -51,7 +51,6 @@ export const crmManifestWriteKeys = (input, api, bodyPermissions) => {
51
51
  };
52
52
  };
53
53
  const refused = (message, param) => new CliError("validation_error", message, { reason: "crm.record-field", sent: false, ...(param ? { param } : {}) });
54
- /** A merge of the entries rules that share a key give: each object's keys beside the others'. */
55
54
  /** Our fields that write one key of the service together, by that key: Attio's name and its parts. */
56
55
  const sharedOf = (one) => {
57
56
  const by = new Map();
@@ -60,6 +59,7 @@ const sharedOf = (one) => {
60
59
  by.set(rule.to, [...(by.get(rule.to) ?? []), field]);
61
60
  return [...by.values()].filter((fields) => fields.length > 1);
62
61
  };
62
+ /** A merge of the entries rules that share a key give: each object's keys beside the others'. */
63
63
  const merged = (entries, list) => {
64
64
  const given = entries.filter((one) => one !== CLEAR);
65
65
  if (given.length === 0)
@@ -79,7 +79,7 @@ const givenOf = (spec, values) => {
79
79
  .map(String);
80
80
  if (list)
81
81
  given[name] = field === "people" ? found.map((one) => ({ externalId: one, role: "contact" })) : found;
82
- // A key several rules write together is replaced whole: a part it leaves out is gone.
82
+ // One value replaces the field whole, so a part of a key several rules share that the write leaves out is gone.
83
83
  else
84
84
  given[name] = found[0] ?? null;
85
85
  }
@@ -162,7 +162,7 @@ export const crmManifestFake = (input, options) => {
162
162
  if (type === "integer" || type === "number")
163
163
  return Number.isFinite(Number(value)) ? Number(value) : undefined;
164
164
  if (type === "string" && found?.type === "string" && found.enum)
165
- return undefined;
165
+ return found.enum.includes(String(value)) ? String(value) : undefined;
166
166
  return ["string", "unknown"].includes(type) ? String(value) : undefined;
167
167
  };
168
168
  /**
@@ -1,28 +1,19 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import type { CrmField, CrmKind, CrmOrganization, CrmPerson } from "../domain/crm.js";
3
3
  import type { DealKind } from "../domain/deals.js";
4
- import type { AppIdentity } from "../ports/app.js";
5
- import type { Warn } from "../runs/events.js";
6
- import { type Asker, type GuardSettings } from "../sends/guard.js";
7
- import { type PermissionKey } from "../sends/permissions.js";
4
+ import type { Asker } from "../sends/guard.js";
5
+ import type { PermissionKey } from "../sends/permissions.js";
6
+ import { type ProfileWrites } from "../sends/profile-writes.js";
8
7
  import type { Deal, PipelineOptions, PipelineReport } from "../store/sqlite/deals.js";
9
8
  import type { MessageStore } from "../store/store.js";
10
9
  import type { AccountKey } from "../store/types.js";
11
10
  import type { CrmSource } from "./source.js";
12
11
  import { type CrmVerb, type CrmWriter } from "./writer.js";
13
12
  /** What a CLI hands the CRM writes for one profile. */
14
- export interface CrmWrites {
13
+ export interface CrmWrites extends ProfileWrites {
15
14
  writer: CrmWriter;
16
- app: AppIdentity;
17
- /**
18
- * The profile's levels, read on every write so a config change applies at once. A CRM limits its own rate, so
19
- * `sendsPerHour` is not read: the guard is there for the levels and the journal.
20
- */
21
- settings: () => Omit<GuardSettings, "sendsPerHour"> & Partial<Pick<GuardSettings, "sendsPerHour">>;
22
15
  /** The CRM user the sign-in acts as. An owner other than it checks `crm.assign-others`; left out, every owner does. */
23
16
  self?: string;
24
- env?: NodeJS.ProcessEnv;
25
- warn?: Warn;
26
17
  /**
27
18
  * The CLI's own keys a write also checks, such as Bitrix24's `api.crm.deal.update`; pass the same function to
28
19
  * `crmAlsoChecks` so `--dry-run` names them.
@@ -2,10 +2,8 @@ import { CliError, isCliError } from "@wirecat/cli-base";
2
2
  import { currencyOf, minorUnits } from "../domain/money.js";
3
3
  import { e164Of } from "../domain/phones.js";
4
4
  import { foldName } from "../resolve.js";
5
- import { guardFor } from "../sends/guard.js";
6
5
  import { guardedWrite } from "../sends/guarded.js";
7
- import { keyedGuard } from "../sends/keyed-guard.js";
8
- import { DEFAULT_PERMISSIONS, levelFor } from "../sends/permissions.js";
6
+ import { profileWriteGuard } from "../sends/profile-writes.js";
9
7
  import { newOperationId } from "../sends/send-id.js";
10
8
  import { foreignContacts } from "./foreign-contacts.js";
11
9
  import { CRM_ASSIGN_OTHERS_KEY, CRM_WRITE_DEFAULTS, } from "./writer.js";
@@ -250,12 +248,7 @@ const keysOf = (context, kind, verb, { stage, owner }) => {
250
248
  extra.push(CRM_ASSIGN_OTHERS_KEY);
251
249
  return { key: keyOf(kind, verb), extra: [...extra, ...(context.writes.alsoChecks?.(kind, verb) ?? [])] };
252
250
  };
253
- /** The profile's guard over the write's own key and the keys its fields imply (`keyedGuard`). */
254
- const guardOf = (context, extra) => {
255
- const settings = context.writes.settings();
256
- const defaults = { ...DEFAULT_PERMISSIONS, ...CRM_WRITE_DEFAULTS, ...settings.permissionDefaults };
257
- return keyedGuard((ask) => guardFor(context.writes.app, { ...settings, sendsPerHour: Number.MAX_SAFE_INTEGER, permissionDefaults: defaults }, context.writes.warn ?? (() => { }), context.writes.env, ask), context.ask, (key) => levelFor(settings.permissions, key, defaults).level, extra);
258
- };
251
+ const guardOf = (context, extra) => profileWriteGuard(context.writes, context.ask, CRM_WRITE_DEFAULTS, extra);
259
252
  /** Sends the write once, never again: a lost answer is `outcome_unknown`, with what the owner may do about it. */
260
253
  const written = async (context, { key, extra }, operationId, act) => {
261
254
  try {
@@ -1,7 +1,7 @@
1
1
  import type { Provider } from "./models.js";
2
2
  import { type RefKindName } from "./references.js";
3
3
  /** What a search reads; the same names `--only`, `searched` and `skipped` use. */
4
- export declare const KINDS: readonly ["messages", "mail", "notes", "documents", "meetings", "events", "crm"];
4
+ export declare const KINDS: readonly ["messages", "mail", "notes", "documents", "meetings", "events", "crm", "tracker"];
5
5
  export type Kind = (typeof KINDS)[number];
6
6
  export interface ProviderEntry {
7
7
  name: Provider;
@@ -1,7 +1,7 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { REF_KINDS } from "./references.js";
3
3
  /** What a search reads; the same names `--only`, `searched` and `skipped` use. */
4
- export const KINDS = ["messages", "mail", "notes", "documents", "meetings", "events", "crm"];
4
+ export const KINDS = ["messages", "mail", "notes", "documents", "meetings", "events", "crm", "tracker"];
5
5
  const MESSENGER_OPENS = { chat: "messages list", message: "messages show", contact: "contacts show" };
6
6
  /** What a CRM CLI's entry gives as `opens`: the read commands `addCrmCommands` mounts. */
7
7
  export const CRM_OPENS = { deal: "deals show", lead: "leads show", pipeline: "pipelines show" };
@@ -22,6 +22,8 @@ export const PROVIDERS = [
22
22
  // Google Meet has no tool of its own: its meetings are gcal's, since every meeting is on the calendar.
23
23
  { name: "google-meet", kind: "meetings", aliases: [], command: "gcal" },
24
24
  { name: "google-drive", kind: "documents", aliases: [] },
25
+ // Seeded: linear-cli registers no entry, and without one its accounts would count as a messenger's.
26
+ { name: "linear", kind: "tracker", aliases: [], command: "linear" },
25
27
  // Its meetings come from the notes Telemost mails (`keeper@telemost.yandex.ru`), read by a mail rule.
26
28
  { name: "telemost", kind: "meetings", aliases: [] },
27
29
  // A phone export's records: its SMS and its calls in the one account the import names.
@@ -41,6 +43,7 @@ const LABELS = {
41
43
  added: "added by hand",
42
44
  email: "mail",
43
45
  telemost: "Telemost",
46
+ linear: "Linear",
44
47
  };
45
48
  /** How a text names a provider to a person: `MAX`, not `max`. */
46
49
  export const providerLabel = (provider) => LABELS[provider] ?? provider;
@@ -1,10 +1,11 @@
1
1
  import * as v from "valibot";
2
2
  /**
3
3
  * One result of `search all`: a message, a mail, a note, a calendar event, a meeting passage, a deal, a lead, the text
4
- * of a downloaded CRM file, or an invoice, payment, order, contract, subscription, product or wallet.
4
+ * of a downloaded CRM file, a tracker's issue, project or issue comment, or an invoice, payment, order, contract,
5
+ * subscription, product or wallet.
5
6
  */
6
7
  export declare const hit: v.StrictObjectSchema<{
7
- readonly kind: v.PicklistSchema<["message", "mail", "note", "document", "event", "meeting", "deal", "lead", "crm_file", "invoice", "payment", "order", "contract", "subscription", "product", "wallet"], undefined>;
8
+ readonly kind: v.PicklistSchema<["message", "mail", "note", "document", "event", "meeting", "deal", "lead", "crm_file", "issue", "project", "issue_comment", "invoice", "payment", "order", "contract", "subscription", "product", "wallet"], undefined>;
8
9
  readonly ref: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>;
9
10
  readonly provider: v.StringSchema<undefined>;
10
11
  readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -4,7 +4,8 @@ import { hitFile } from "./attachment.js";
4
4
  import { count, reference, text, time, untrusted } from "./fields.js";
5
5
  /**
6
6
  * One result of `search all`: a message, a mail, a note, a calendar event, a meeting passage, a deal, a lead, the text
7
- * of a downloaded CRM file, or an invoice, payment, order, contract, subscription, product or wallet.
7
+ * of a downloaded CRM file, a tracker's issue, project or issue comment, or an invoice, payment, order, contract,
8
+ * subscription, product or wallet.
8
9
  */
9
10
  export const hit = v.strictObject({
10
11
  kind: v.picklist([
@@ -17,6 +18,9 @@ export const hit = v.strictObject({
17
18
  "deal",
18
19
  "lead",
19
20
  "crm_file",
21
+ "issue",
22
+ "project",
23
+ "issue_comment",
20
24
  ...BUSINESS_KINDS,
21
25
  ]),
22
26
  ref: reference,
@@ -4326,7 +4326,7 @@ export declare const ENTITIES: {
4326
4326
  readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
4327
4327
  }, undefined>;
4328
4328
  readonly hit: v.StrictObjectSchema<{
4329
- readonly kind: v.PicklistSchema<["message", "mail", "note", "document", "event", "meeting", "deal", "lead", "crm_file", "invoice", "payment", "order", "contract", "subscription", "product", "wallet"], undefined>;
4329
+ readonly kind: v.PicklistSchema<["message", "mail", "note", "document", "event", "meeting", "deal", "lead", "crm_file", "issue", "project", "issue_comment", "invoice", "payment", "order", "contract", "subscription", "product", "wallet"], undefined>;
4330
4330
  readonly ref: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>;
4331
4331
  readonly provider: v.StringSchema<undefined>;
4332
4332
  readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -123,6 +123,27 @@ const SQL = [
123
123
  ["db.timeout", "timeout", "the database server did not answer in time"],
124
124
  ["db.failed", "provider_error", "the database server failed the query"],
125
125
  ];
126
+ /** In-place Office edits (`./office`, `files sheets|documents update`); the names are documented in office.md. */
127
+ const OFFICE = [
128
+ ["office.wrong-format", "the file is not the Office format the command edits, or its parts cannot be read"],
129
+ ["office.invalid-cell", "a cell is not an address like B7"],
130
+ ["office.invalid-value", "a cell value cannot be written: a number must be finite"],
131
+ ["office.no-sheet", "the workbook has no such sheet, or several when none is named"],
132
+ ["office.duplicate-edit", "the same cell or paragraph is changed twice in one call"],
133
+ ["office.formula-cell", "the cell holds a formula; --replace writes the value over it"],
134
+ ["office.shared-formula", "the cell holds a formula other cells share; replacing it would break theirs"],
135
+ ["office.array-formula", "the cell is part of an array formula; change it in Excel"],
136
+ ["office.rich-value", "the cell holds a picture or a linked data type, which the editor does not replace"],
137
+ ["office.table-header", "the cell is a table's header or total, whose part repeats the text; change it in Excel"],
138
+ ["office.implicit-rows", "the sheet has rows without numbers, so a row cannot be added"],
139
+ ["office.implicit-cells", "the row has cells without addresses, so a cell cannot be added"],
140
+ ["office.no-paragraph", "the document has no paragraph at that index"],
141
+ ["office.unsafe-paragraph", "the paragraph cannot be edited safely; documents show gives the reason"],
142
+ ["office.tracked-change", "the paragraph holds a tracked change"],
143
+ ["office.section-break", "the paragraph ends a section; deleting it would merge two sections"],
144
+ ["office.bookmark", "the paragraph holds a bookmark a cross-reference may point at"],
145
+ ["office.last-paragraph", "the delete would leave the document or a table cell without a paragraph"],
146
+ ].map(([reason, message]) => validation(reason, message));
126
147
  const OTHERS = [
127
148
  validation("doctor.report-exists", "the report's file exists; a problem report never overwrites a file"),
128
149
  validation("usage.unknown-command", "no command by this name; the CLI's help lists them"),
@@ -540,6 +561,11 @@ const OTHERS = [
540
561
  validation("crm.write-unsupported", "the CRM does not take this write, or does not recognise a repeated one"),
541
562
  validation("crm.unlisted-held", "a list of every id would mark most of a kind deleted; nothing was, until --rescan"),
542
563
  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"),
564
+ validation("tracker.write-unsupported", "the tracker does not take this write, or does not recognise a repeated one"),
565
+ validation("tracker.field", "a field of an issue or a comment the tracker's write does not take as given"),
566
+ validation("tracker.reference", "a team, state, label, project or user no single row of the copy has by that name"),
567
+ validation("tracker.team-required", "a new issue needs its team: name one, or sync a copy that holds one"),
568
+ ["tracker.no-record", "invalid_response", "the tracker answered a write with no record and no error; sync and look"],
543
569
  validation("content.unlisted-held", "a content id list would mark too much deleted, the sign-in read only part, or the site moved; nothing was"),
544
570
  validation("content.conflict", "the post changed at the source since the last sync; sync, then write again"),
545
571
  validation("content.lossy-body", "the post's text holds blocks or embeds Markdown does not keep; --replace-body"),
@@ -764,7 +790,7 @@ const DETAILED = {
764
790
  export const REASONS = defineReasons([
765
791
  ...QUERY_REASONS,
766
792
  ...INPUT_FIELD_REASONS,
767
- ...[...QUERY, ...SIGN_IN, ...PROVIDER_API, ...SFTP, ...SQL, ...OTHERS].map(([reason, code, message]) => ({
793
+ ...[...QUERY, ...SIGN_IN, ...PROVIDER_API, ...SFTP, ...SQL, ...OFFICE, ...OTHERS].map(([reason, code, message]) => ({
768
794
  reason,
769
795
  code,
770
796
  message,
@@ -66,10 +66,10 @@ class Document {
66
66
  const root = this.part.root;
67
67
  this.ns = root.ns;
68
68
  if (root.local !== "document" || !WORD_NAMESPACES.includes(this.ns))
69
- throw refuse("the file is not a Word document", "office.wrong_format");
69
+ throw refuse("the file is not a Word document", "office.wrong-format");
70
70
  const body = childrenOf(root, this.ns, "body")[0];
71
71
  if (!body)
72
- throw refuse("the document has no body", "office.wrong_format");
72
+ throw refuse("the document has no body", "office.wrong-format");
73
73
  this.walk(body, "body", false);
74
74
  const styles = pack.related(this.part.path, "styles");
75
75
  if (styles && pack.has(styles[1].path)) {
@@ -208,7 +208,7 @@ class Document {
208
208
  if (!properties)
209
209
  return "";
210
210
  if (hasTracked(properties))
211
- throw refuse("the paragraph to copy the style from holds a tracked change", "office.tracked_change");
211
+ throw refuse("the paragraph to copy the style from holds a tracked change", "office.tracked-change");
212
212
  let raw = this.raw(properties);
213
213
  for (const section of childrenOf(properties, this.ns, "sectPr").reverse())
214
214
  raw = raw.slice(0, section.start - properties.start) + raw.slice(section.end - properties.start);
@@ -253,18 +253,18 @@ export const editDocxParagraphs = async (bytes, edits) => {
253
253
  const infos = document.paragraphs();
254
254
  const check = (index, what) => {
255
255
  if (!Number.isInteger(index) || index < 0 || index >= found.length)
256
- throw refuse(`${what} ${index} does not exist; the document has ${found.length} paragraphs`, "office.no_paragraph");
256
+ throw refuse(`${what} ${index} does not exist; the document has ${found.length} paragraphs`, "office.no-paragraph");
257
257
  return found[index];
258
258
  };
259
259
  const editable = (index, action) => {
260
260
  const info = infos[index];
261
261
  if (!info.editable)
262
- throw refuse(`paragraph ${index} cannot be ${action}: ${info.reason}`, "office.unsafe_paragraph");
262
+ throw refuse(`paragraph ${index} cannot be ${action}: ${info.reason}`, "office.unsafe-paragraph");
263
263
  };
264
264
  const touched = new Set();
265
265
  const once = (index) => {
266
266
  if (touched.has(index))
267
- throw refuse(`paragraph ${index} is changed twice in one call`, "office.duplicate_edit");
267
+ throw refuse(`paragraph ${index} is changed twice in one call`, "office.duplicate-edit");
268
268
  touched.add(index);
269
269
  };
270
270
  const splices = [];
@@ -281,7 +281,7 @@ export const editDocxParagraphs = async (bytes, edits) => {
281
281
  editable(edit.delete, "deleted");
282
282
  const properties = childrenOf(target.element, document.ns, "pPr")[0];
283
283
  if (properties && childrenOf(properties, document.ns, "sectPr").length)
284
- throw refuse(`paragraph ${edit.delete} ends a section; deleting it would merge two sections`, "office.section_break");
284
+ throw refuse(`paragraph ${edit.delete} ends a section; deleting it would merge two sections`, "office.section-break");
285
285
  if (target.element.children.some((child) => MARKERS.has(child.local)))
286
286
  throw refuse(`paragraph ${edit.delete} holds a bookmark that a cross-reference may point at`, "office.bookmark");
287
287
  splices.push({ start: target.element.start, end: target.element.end, text: "" });
@@ -307,10 +307,10 @@ export const editDocxParagraphs = async (bytes, edits) => {
307
307
  if (edit.insertAfter !== -1)
308
308
  check(edit.insertAfter, "paragraph");
309
309
  if (!found.length)
310
- throw refuse("the document has no paragraph to insert next to", "office.no_paragraph");
310
+ throw refuse("the document has no paragraph to insert next to", "office.no-paragraph");
311
311
  const neighbour = found[Math.max(0, edit.insertAfter)];
312
312
  if (neighbour.lockedControl)
313
- throw refuse(`paragraph ${edit.insertAfter} sits in a locked content control`, "office.unsafe_paragraph");
313
+ throw refuse(`paragraph ${edit.insertAfter} sits in a locked content control`, "office.unsafe-paragraph");
314
314
  const source = check(edit.styleFrom ?? Math.max(0, edit.insertAfter), "styleFrom paragraph").element;
315
315
  const element = neighbour.element;
316
316
  const text = normalized(edit.text);
@@ -332,7 +332,7 @@ export const editDocxParagraphs = async (bytes, edits) => {
332
332
  const remaining = blocks.filter((block) => !deleted.includes(found.findIndex((entry) => entry.element === block)));
333
333
  const addsAtEnd = found.some((entry, index) => insertedAfter.has(index) && entry.element === blocks.at(-1));
334
334
  if (!addsAtEnd && remaining.at(-1)?.local !== "p")
335
- throw refuse(`${container.local === "tc" ? "a table cell" : "the document"} must end with a paragraph; this delete would leave it without one`, "office.last_paragraph");
335
+ throw refuse(`${container.local === "tc" ? "a table cell" : "the document"} must end with a paragraph; this delete would leave it without one`, "office.last-paragraph");
336
336
  }
337
337
  if (!edits.length)
338
338
  return { bytes: bytes.slice(), replaced, inserted, deleted, collapsed };