@wirecat/cli-core 0.623.0 → 0.625.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 (47) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/dist/background/backfill.d.ts +1 -1
  3. package/dist/background/backfill.js +1 -1
  4. package/dist/background/daily-archive-timer.d.ts +1 -1
  5. package/dist/background/report/stored-templates.d.ts +21 -3
  6. package/dist/background/report/stored-templates.js +34 -6
  7. package/dist/background/schedules.d.ts +10 -20
  8. package/dist/background/schedules.js +8 -162
  9. package/dist/background/timers.d.ts +19 -0
  10. package/dist/background/timers.js +175 -0
  11. package/dist/background/when.d.ts +28 -7
  12. package/dist/background/when.js +55 -11
  13. package/dist/calendar/prepare.d.ts +14 -0
  14. package/dist/cli/app-doctor-command.js +2 -1
  15. package/dist/cli/envelope.d.ts +28 -0
  16. package/dist/cli/index.d.ts +3 -2
  17. package/dist/cli/index.js +3 -2
  18. package/dist/cli/schedule/schedule-command.d.ts +100 -3
  19. package/dist/cli/schedule/schedule-command.js +276 -118
  20. package/dist/cli/templates-command.js +45 -20
  21. package/dist/domain/display-names.d.ts +5 -2
  22. package/dist/domain/display-names.js +13 -4
  23. package/dist/domain/person-kinds.d.ts +9 -0
  24. package/dist/domain/person-kinds.js +67 -0
  25. package/dist/domain/records-table.d.ts +61 -0
  26. package/dist/domain/records-table.js +382 -0
  27. package/dist/entities/index.d.ts +2 -1
  28. package/dist/entities/list-results.d.ts +2 -0
  29. package/dist/entities/list-results.js +2 -0
  30. package/dist/entities/template.d.ts +1 -1
  31. package/dist/entities/template.js +1 -1
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.js +1 -0
  34. package/dist/mcp/surface.js +23 -2
  35. package/dist/meetings/mcp/index.d.ts +15 -15
  36. package/dist/services/index.d.ts +1 -1
  37. package/dist/services/index.js +1 -1
  38. package/dist/services/metadata.d.ts +1 -1
  39. package/dist/services/search-harder.d.ts +6 -1
  40. package/dist/services/search-harder.js +9 -2
  41. package/dist/store/index.d.ts +2 -1
  42. package/dist/store/index.js +2 -0
  43. package/dist/store/people.d.ts +4 -3
  44. package/dist/store/sqlite/people-list.d.ts +23 -8
  45. package/dist/store/sqlite/people-list.js +189 -65
  46. package/package.json +2 -2
  47. package/parity.json +29 -0
@@ -0,0 +1,382 @@
1
+ import { RECORD_TYPES } from "./record-types.js";
2
+ import { pointerOf, RECORDS_SCHEMA_VERSION, } from "./records.js";
3
+ /** The types a table can carry: an SMS and a call come from a phone's own export, never from a hand-made sheet. */
4
+ export const TABLE_RECORD_TYPES = Object.keys(RECORD_TYPES).filter((type) => !RECORD_TYPES[type].importOnly);
5
+ export class TableError extends Error {
6
+ errors;
7
+ constructor(errors) {
8
+ super(errors.map((e) => e.message).join("; "));
9
+ this.errors = errors;
10
+ }
11
+ }
12
+ const LIST_SEPARATOR = "|";
13
+ const BOM = "";
14
+ const specOf = (type) => RECORD_TYPES[type];
15
+ const typesOf = (schema) => schema.type === undefined ? [] : typeof schema.type === "string" ? [schema.type] : [...schema.type];
16
+ const shapeOf = (schema) => {
17
+ const types = typesOf(schema);
18
+ if (types.includes("integer"))
19
+ return "integer";
20
+ if (types.includes("boolean"))
21
+ return "boolean";
22
+ if (types.includes("array"))
23
+ return "list";
24
+ if (schema.pattern?.includes("T[0-9]{2}"))
25
+ return "instant";
26
+ if (schema.pattern?.startsWith("^[0-9]{4}-"))
27
+ return "day";
28
+ if (schema.pattern?.includes("[A-Za-z]{3}"))
29
+ return "currency";
30
+ if (schema.pattern?.includes("(\\.[0-9]"))
31
+ return "decimal";
32
+ return "text";
33
+ };
34
+ const valuesOf = (schema) => schema.enum?.filter((v) => v !== null);
35
+ const flat = (schema) => {
36
+ const types = typesOf(schema);
37
+ return !types.includes("object") && !(types.includes("array") && schema.items?.type === "object");
38
+ };
39
+ const fieldColumn = (name, schema, required, kind) => {
40
+ const values = valuesOf(schema);
41
+ const shape = shapeOf(schema);
42
+ return {
43
+ name,
44
+ kind,
45
+ required,
46
+ shape,
47
+ description: schema.description ?? "",
48
+ ...(values ? { values } : {}),
49
+ ...(shape === "list" ? { many: true } : {}),
50
+ };
51
+ };
52
+ const roleColumn = (name, role) => ({
53
+ name,
54
+ kind: "role",
55
+ required: role.required === true,
56
+ shape: "text",
57
+ description: role.targets.length === 1
58
+ ? `The ${role.targets[0]}'s external id`
59
+ : `<type>:<external id>, the type one of ${role.targets.join(", ")}`,
60
+ targets: role.targets,
61
+ ...(role.many ? { many: true } : {}),
62
+ });
63
+ /** A type's columns: the external id, its flat fields, one per role, then one per key of each list of items. */
64
+ export const recordColumns = (type) => {
65
+ const spec = specOf(type);
66
+ if (!spec || spec.importOnly)
67
+ return [];
68
+ const fields = spec.fields.properties ?? {};
69
+ const required = spec.fields.required ?? [];
70
+ const lists = Object.entries(fields).filter(([, schema]) => !flat(schema));
71
+ return [
72
+ { name: "external_id", kind: "id", required: true, shape: "text", description: "Its id in your system" },
73
+ ...Object.entries(fields)
74
+ .filter(([, schema]) => flat(schema))
75
+ .map(([name, schema]) => fieldColumn(name, schema, required.includes(name), "field")),
76
+ ...Object.entries(spec.roles)
77
+ .filter(([, role]) => !role.linked)
78
+ .map(([name, role]) => roleColumn(name, role)),
79
+ ...lists.flatMap(([list, schema]) => {
80
+ const item = schema.items ?? {};
81
+ const own = item.required ?? [];
82
+ return Object.entries(item.properties ?? {}).map(([key, s]) => fieldColumn(`${list}.${key}`, s, required.includes(list) && own.includes(key), "item"));
83
+ }),
84
+ ];
85
+ };
86
+ const csvCell = (value, separator) => /["\r\n]/.test(value) || value.includes(separator) ? `"${value.replaceAll('"', '""')}"` : value;
87
+ const example = (column) => {
88
+ if (column.values?.[0])
89
+ return column.values[0];
90
+ switch (column.shape) {
91
+ case "decimal":
92
+ return "100.00";
93
+ case "day":
94
+ return "2026-01-31";
95
+ case "instant":
96
+ return "2026-01-31T09:00:00Z";
97
+ case "currency":
98
+ return "EUR";
99
+ case "integer":
100
+ return 1;
101
+ case "boolean":
102
+ return true;
103
+ case "list":
104
+ return ["…"];
105
+ default:
106
+ return column.description || "…";
107
+ }
108
+ };
109
+ const exampleRef = (column) => ({
110
+ role: column.name,
111
+ type: column.targets?.[0] ?? "",
112
+ external_id: `${column.targets?.[0] ?? "record"}-1`,
113
+ });
114
+ /**
115
+ * A file to fill for a type. CSV is the header row alone, with a byte-order mark so Excel reads it as UTF-8; JSON is
116
+ * an envelope of one example record that names every field and role.
117
+ */
118
+ export const recordTemplate = (type, format, { source, separator = "," } = {}) => {
119
+ const columns = recordColumns(type);
120
+ if (columns.length === 0)
121
+ throw new TableError([unknownType(type)]);
122
+ if (format === "csv")
123
+ return `${BOM}${columns.map((c) => csvCell(c.name, separator)).join(separator)}\r\n`;
124
+ const fields = {};
125
+ for (const c of columns.filter((c) => c.kind === "field"))
126
+ fields[c.name] = example(c);
127
+ for (const c of columns.filter((c) => c.kind === "item")) {
128
+ const [list = "", key = ""] = c.name.split(".");
129
+ fields[list] ??= [{}];
130
+ const [first] = fields[list];
131
+ if (first)
132
+ first[key] = example(c);
133
+ }
134
+ const envelope = {
135
+ schema_version: RECORDS_SCHEMA_VERSION,
136
+ source: {
137
+ provider: source?.provider ?? "sheet",
138
+ account: source?.account ?? "main",
139
+ batch_id: source?.batch_id ?? "first-import",
140
+ },
141
+ records: [
142
+ {
143
+ key: `${type}-1`,
144
+ type,
145
+ external_id: `${type}-1`,
146
+ operation: "upsert",
147
+ fields,
148
+ relations: columns.filter((c) => c.kind === "role").map(exampleRef),
149
+ },
150
+ ],
151
+ };
152
+ return `${JSON.stringify(envelope, null, 2)}\n`;
153
+ };
154
+ /** RFC 4180 rows; a separator inside quotes, a doubled quote and a line break inside quotes are part of the cell. */
155
+ export const csvRows = (text, separator) => {
156
+ const rows = [];
157
+ let cells = [];
158
+ let cell = "";
159
+ let quoted = false;
160
+ let line = 1;
161
+ let start = 1;
162
+ const end = () => {
163
+ cells.push(cell);
164
+ cell = "";
165
+ };
166
+ for (let i = 0; i < text.length; i++) {
167
+ const c = text[i];
168
+ if (quoted) {
169
+ if (c === '"' && text[i + 1] === '"') {
170
+ cell += '"';
171
+ i++;
172
+ }
173
+ else if (c === '"')
174
+ quoted = false;
175
+ else {
176
+ if (c === "\n")
177
+ line++;
178
+ cell += c;
179
+ }
180
+ }
181
+ else if (c === '"' && cell === "")
182
+ quoted = true;
183
+ else if (c === separator)
184
+ end();
185
+ else if (c === "\n" || c === "\r") {
186
+ if (c === "\r" && text[i + 1] === "\n")
187
+ i++;
188
+ end();
189
+ rows.push({ cells, line: start });
190
+ cells = [];
191
+ line++;
192
+ start = line;
193
+ }
194
+ else
195
+ cell += c;
196
+ }
197
+ if (cell !== "" || cells.length > 0) {
198
+ end();
199
+ rows.push({ cells, line: start });
200
+ }
201
+ return rows.filter((r) => r.cells.some((c) => c.trim() !== ""));
202
+ };
203
+ /** The header's separator: Excel saves `;` where the decimal mark is a comma, as in Russian or Spanish. */
204
+ export const csvSeparator = (header) => {
205
+ const count = (s) => header.split(s).length - 1;
206
+ return [";", "\t", ","].reduce((best, s) => (count(s) > count(best) ? s : best), ",");
207
+ };
208
+ const DAY_DOTTED = /^(\d{1,2})[./](\d{1,2})[./](\d{4})$/;
209
+ /** What a spreadsheet writes, as the envelope reads it; anything it cannot read is left for the envelope to refuse. */
210
+ const normalized = (column, raw) => {
211
+ const value = raw.trim();
212
+ switch (column.shape) {
213
+ case "decimal": {
214
+ const plain = value.replace(/[\s  ]/g, "");
215
+ return /^\d+,\d+$/.test(plain) ? plain.replace(",", ".") : plain;
216
+ }
217
+ case "day": {
218
+ const dotted = DAY_DOTTED.exec(value);
219
+ return dotted ? `${dotted[3]}-${dotted[2]?.padStart(2, "0")}-${dotted[1]?.padStart(2, "0")}` : value;
220
+ }
221
+ case "currency":
222
+ return value.toUpperCase();
223
+ case "integer":
224
+ return /^-?\d+$/.test(value) ? Number(value) : value;
225
+ case "boolean":
226
+ return /^(true|yes|1|да|sí|si)$/i.test(value) ? true : /^(false|no|0|нет)$/i.test(value) ? false : value;
227
+ case "list":
228
+ return value
229
+ .split(LIST_SEPARATOR)
230
+ .map((v) => v.trim())
231
+ .filter(Boolean);
232
+ default:
233
+ return column.many
234
+ ? value
235
+ .split(LIST_SEPARATOR)
236
+ .map((v) => v.trim())
237
+ .filter(Boolean)
238
+ : value;
239
+ }
240
+ };
241
+ const unknownType = (type) => ({
242
+ pointer: "",
243
+ code: "record.type",
244
+ message: `no table for ${type}: use one of ${TABLE_RECORD_TYPES.join(", ")}`,
245
+ });
246
+ const relationsOf = (column, raw) => {
247
+ const targets = column.targets ?? [];
248
+ const values = column.many ? raw.split(LIST_SEPARATOR) : [raw];
249
+ const out = [];
250
+ for (const value of values.map((v) => v.trim()).filter(Boolean)) {
251
+ const at = value.indexOf(":");
252
+ const named = at > 0 ? value.slice(0, at) : "";
253
+ if (targets.length === 1 && !targets.includes(named)) {
254
+ out.push({ role: column.name, type: targets[0], external_id: value });
255
+ continue;
256
+ }
257
+ if (!targets.includes(named) || at === value.length - 1)
258
+ return {
259
+ pointer: "",
260
+ code: "record.invalid",
261
+ message: `${column.name} takes <type>:<external id>, the type one of ${targets.join(", ")}: not ${value}`,
262
+ };
263
+ out.push({ role: column.name, type: named, external_id: value.slice(at + 1) });
264
+ }
265
+ return out;
266
+ };
267
+ /**
268
+ * Reads a sheet of one type as an envelope. A row whose `external_id` an earlier row had continues that record: its
269
+ * item columns (`lines.amount`) add one item to the list, as an invoice exported a line a row does.
270
+ */
271
+ export const envelopeOfCsv = (text, { type, source, options }) => {
272
+ const columns = recordColumns(type);
273
+ if (columns.length === 0)
274
+ throw new TableError([unknownType(type)]);
275
+ const body = text.startsWith(BOM) ? text.slice(1) : text;
276
+ const separator = csvSeparator(body.slice(0, body.search(/\r?\n|$/)));
277
+ const [head, ...rows] = csvRows(body, separator);
278
+ if (!head)
279
+ throw new TableError([{ pointer: "", code: "envelope.invalid", message: "the file has no header row" }]);
280
+ const byName = new Map(columns.map((c) => [c.name, c]));
281
+ const header = head.cells.map((name) => name.trim());
282
+ const unknown = header.filter((name) => name !== "" && !byName.has(name));
283
+ if (unknown.length > 0)
284
+ throw new TableError([
285
+ {
286
+ pointer: "",
287
+ code: "envelope.invalid",
288
+ message: `columns ${type} has no field for: ${unknown.join(", ")}. Download the ${type} template for the list`,
289
+ place: { line: 1, column: unknown[0] },
290
+ },
291
+ ]);
292
+ if (!header.includes("external_id"))
293
+ throw new TableError([
294
+ { pointer: "", code: "envelope.invalid", message: "the header has no external_id column", place: { line: 1 } },
295
+ ]);
296
+ const records = [];
297
+ const indexById = new Map();
298
+ const places = new Map();
299
+ const errors = [];
300
+ for (const row of rows) {
301
+ const cell = (name) => row.cells[header.indexOf(name)] ?? "";
302
+ const id = cell("external_id").trim();
303
+ if (!id) {
304
+ errors.push({
305
+ pointer: "",
306
+ code: "record.invalid",
307
+ message: "a row has no external_id",
308
+ place: { line: row.line, column: "external_id" },
309
+ });
310
+ continue;
311
+ }
312
+ const known = indexById.get(id);
313
+ const index = known ?? records.length;
314
+ const record = records[index] ?? {
315
+ key: `${type}:${id}`,
316
+ type,
317
+ external_id: id,
318
+ operation: "upsert",
319
+ fields: {},
320
+ relations: [],
321
+ };
322
+ if (known === undefined) {
323
+ records.push(record);
324
+ indexById.set(id, index);
325
+ places.set(pointerOf("records", index), { line: row.line });
326
+ }
327
+ const fields = record.fields;
328
+ const item = {};
329
+ let list = "";
330
+ header.forEach((name, i) => {
331
+ const column = byName.get(name);
332
+ const raw = row.cells[i] ?? "";
333
+ if (!column || column.kind === "id" || raw.trim() === "")
334
+ return;
335
+ const at = { line: row.line, column: name };
336
+ if (column.kind === "field") {
337
+ fields[name] = normalized(column, raw);
338
+ places.set(pointerOf("records", index, "fields", name), at);
339
+ }
340
+ else if (column.kind === "role") {
341
+ const relations = relationsOf(column, raw);
342
+ if (!Array.isArray(relations)) {
343
+ errors.push({ ...relations, pointer: pointerOf("records", index, "relations"), key: record.key, place: at });
344
+ return;
345
+ }
346
+ record.relations = [...(record.relations ?? []).filter((r) => r.role !== name), ...relations];
347
+ places.set(pointerOf("records", index, "relations"), at);
348
+ }
349
+ else {
350
+ const [of = "", key = ""] = name.split(".");
351
+ list = of;
352
+ item[key] = normalized(column, raw);
353
+ }
354
+ });
355
+ if (list) {
356
+ fields[list] ??= [];
357
+ const items = fields[list];
358
+ places.set(pointerOf("records", index, "fields", list, items.length), { line: row.line });
359
+ items.push(item);
360
+ }
361
+ }
362
+ if (errors.length > 0)
363
+ throw new TableError(errors);
364
+ const envelope = {
365
+ schema_version: RECORDS_SCHEMA_VERSION,
366
+ source,
367
+ ...(options ? { options } : {}),
368
+ records,
369
+ };
370
+ return {
371
+ envelope,
372
+ placeOf(pointer) {
373
+ const item = /^\/records\/\d+\/fields\/([^/]+)\/\d+\/([^/]+)/.exec(pointer);
374
+ for (let at = pointer; at !== ""; at = at.slice(0, at.lastIndexOf("/"))) {
375
+ const place = places.get(at);
376
+ if (place)
377
+ return item && !place.column ? { ...place, column: `${item[1]}.${item[2]}` } : place;
378
+ }
379
+ return undefined;
380
+ },
381
+ };
382
+ };
@@ -4199,6 +4199,7 @@ export declare const ENTITIES: {
4199
4199
  readonly name: v.StringSchema<undefined>;
4200
4200
  readonly kind: v.PicklistSchema<["command", "agent"], undefined>;
4201
4201
  readonly when: v.StringSchema<undefined>;
4202
+ readonly paused: v.OptionalSchema<v.LiteralSchema<true, undefined>, undefined>;
4202
4203
  readonly notify: v.OptionalSchema<v.PicklistSchema<["always", "failures", "never"], undefined>, undefined>;
4203
4204
  readonly deliver_to: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
4204
4205
  readonly last: v.NullableSchema<v.StrictObjectSchema<{
@@ -11941,7 +11942,7 @@ export declare const ENTITIES: {
11941
11942
  readonly language: v.StringSchema<undefined>;
11942
11943
  readonly about: v.StringSchema<undefined>;
11943
11944
  readonly renders: v.BooleanSchema<undefined>;
11944
- readonly source: v.PicklistSchema<["stored", "default"], undefined>;
11945
+ readonly source: v.PicklistSchema<["stored", "inherited", "default"], undefined>;
11945
11946
  readonly updated_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
11946
11947
  readonly updated_by: v.NullableSchema<v.StringSchema<undefined>, undefined>;
11947
11948
  }, undefined>;
@@ -48,6 +48,8 @@ export declare const scheduledJob: v.StrictObjectSchema<{
48
48
  readonly name: v.StringSchema<undefined>;
49
49
  readonly kind: v.PicklistSchema<["command", "agent"], undefined>;
50
50
  readonly when: v.StringSchema<undefined>;
51
+ /** Kept without its timer: `schedule run` runs it, `schedule resume` puts it back on its timer. */
52
+ readonly paused: v.OptionalSchema<v.LiteralSchema<true, undefined>, undefined>;
51
53
  /** When a finished run shows a desktop notice: `always`, `failures` or `never`; the default is shown, not left out. */
52
54
  readonly notify: v.OptionalSchema<v.PicklistSchema<["always", "failures", "never"], undefined>, undefined>;
53
55
  /** Where a run's result is sent after it: `telegram-bot:<profile>/<chat>` or `email:<profile>/<address>`. */
@@ -32,6 +32,8 @@ export const scheduledJob = v.strictObject({
32
32
  name: text,
33
33
  kind: v.picklist(["command", "agent"]),
34
34
  when: text,
35
+ /** Kept without its timer: `schedule run` runs it, `schedule resume` puts it back on its timer. */
36
+ paused: v.optional(v.literal(true)),
35
37
  /** When a finished run shows a desktop notice: `always`, `failures` or `never`; the default is shown, not left out. */
36
38
  notify: v.optional(v.picklist(["always", "failures", "never"])),
37
39
  /** Where a run's result is sent after it: `telegram-bot:<profile>/<chat>` or `email:<profile>/<address>`. */
@@ -5,7 +5,7 @@ export declare const template: v.StrictObjectSchema<{
5
5
  readonly language: v.StringSchema<undefined>;
6
6
  readonly about: v.StringSchema<undefined>;
7
7
  readonly renders: v.BooleanSchema<undefined>;
8
- readonly source: v.PicklistSchema<["stored", "default"], undefined>;
8
+ readonly source: v.PicklistSchema<["stored", "inherited", "default"], undefined>;
9
9
  readonly updated_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
10
10
  readonly updated_by: v.NullableSchema<v.StringSchema<undefined>, undefined>;
11
11
  }, undefined>;
@@ -6,7 +6,7 @@ export const template = v.strictObject({
6
6
  language: text,
7
7
  about: text,
8
8
  renders: v.boolean(),
9
- source: v.picklist(["stored", "default"]),
9
+ source: v.picklist(["stored", "inherited", "default"]),
10
10
  updated_at: v.nullable(time),
11
11
  updated_by: v.nullable(text),
12
12
  });
package/dist/index.d.ts CHANGED
@@ -22,6 +22,7 @@ export type { RankingGraphEvidence, RankingGraphLink } from "./domain/rankings-g
22
22
  export type { RankingComponent, RankingInput, RankingMeasure, RankingOptions, RankingTarget, RankingWeights, ScorePreset, } from "./domain/rankings-options.js";
23
23
  export { rankingOptions } from "./domain/rankings-options.js";
24
24
  export { type EnvelopeOptions, type EnvelopeRecord, type EnvelopeSource, envelopeOfJsonl, envelopeOfText, type IngestError, RECORD_ENTITY_TYPES, RECORD_OPERATIONS, RECORDS_ENVELOPE_SCHEMA, RECORDS_SCHEMA_VERSION, type RecordEntityType, type RecordOperation, type RecordRelation, type RecordsEnvelope, } from "./domain/records.js";
25
+ export { type ColumnShape, envelopeOfCsv, recordColumns, recordTemplate, TABLE_RECORD_TYPES, type TableColumn, type TableEnvelope, TableError, type TablePlace, } from "./domain/records-table.js";
25
26
  export { canonicalReference, formatReference, looksLikeReference, parseReference, REF_KINDS, type Reference, type RefKindName, type RefKindSpec, } from "./domain/references.js";
26
27
  export { byEngagement, CONTRACT_ROLES, ENGAGEMENT_LEVELS, type Engagement, engagementRank, inverseOf, isUsable, ORGANIZATION_ROLES, PROJECT_ROLES, RELATION_KINDS, RELATIONS, type RelationKind, ROLE_LISTS, type RoleList, rolesOf, STANDINGS, type Standing, standingOf, usableLink, } from "./domain/relations.js";
27
28
  export { normalizeTag, TAG_TYPES, type TagType } from "./domain/tags.js";
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ export { countedPoll } from "./domain/polls.js";
17
17
  export { ADDED_ACCOUNT, ADDED_PROVIDER, CRM_OPENS, FOLDER_PROVIDERS, holdsKind, isFolderProvider, isKind, KINDS, kindIn, kindOf, kindsIn, PROVIDERS, providerNamed, providers, UNKNOWN_PROVIDER, useProviders, } from "./domain/providers.js";
18
18
  export { rankingOptions } from "./domain/rankings-options.js";
19
19
  export { envelopeOfJsonl, envelopeOfText, RECORD_ENTITY_TYPES, RECORD_OPERATIONS, RECORDS_ENVELOPE_SCHEMA, RECORDS_SCHEMA_VERSION, } from "./domain/records.js";
20
+ export { envelopeOfCsv, recordColumns, recordTemplate, TABLE_RECORD_TYPES, TableError, } from "./domain/records-table.js";
20
21
  export { canonicalReference, formatReference, looksLikeReference, parseReference, REF_KINDS, } from "./domain/references.js";
21
22
  export { byEngagement, CONTRACT_ROLES, ENGAGEMENT_LEVELS, engagementRank, inverseOf, isUsable, ORGANIZATION_ROLES, PROJECT_ROLES, RELATION_KINDS, RELATIONS, ROLE_LISTS, rolesOf, STANDINGS, standingOf, usableLink, } from "./domain/relations.js";
22
23
  export { normalizeTag, TAG_TYPES } from "./domain/tags.js";
@@ -9,6 +9,27 @@ import { agentArguments } from "./text.js";
9
9
  import { answered, commandOf, entryRunner, failed, inputOf, outputSchemaOf, READ, syncAllowedFor, UNTRUSTED, UNTRUSTED_NEUTRAL, WRITE, } from "./tool.js";
10
10
  const MATCHES = 8;
11
11
  const ANSWER = answerSchema();
12
+ // The listing shows an agent only what it acts on; the server still checks every answer against the full envelope,
13
+ // and tools_search gives each command's full answer. meta.ranking alone took 2,800 characters of every connect.
14
+ const agentAnswer = (prefix, writes) => {
15
+ const meta = v.pipe(v.looseObject({}), v.description(`run facts; ${prefix}_tools_search shows the full answer`));
16
+ const next = v.optional(v.pipe(v.array(v.looseObject({})), v.description("steps to run next: command and args")));
17
+ return v.looseObject(writes
18
+ ? { item: v.optional(v.unknown()), next, meta }
19
+ : {
20
+ items: v.optional(v.array(v.unknown())),
21
+ item: v.optional(v.unknown()),
22
+ page: v.optional(v.looseObject({ has_more: v.boolean() })),
23
+ next,
24
+ missing: v.optional(v.array(v.looseObject({ field: v.string(), why: v.string() }))),
25
+ meta,
26
+ });
27
+ };
28
+ const listedAs = (prefix, writes) => {
29
+ const checked = toStandardJsonSchema(ANSWER);
30
+ const shown = toStandardJsonSchema(agentAnswer(prefix, writes))["~standard"].jsonSchema;
31
+ return { "~standard": { ...checked["~standard"], jsonSchema: shown } };
32
+ };
12
33
  export const normal = (command) => command
13
34
  .trim()
14
35
  .toLowerCase()
@@ -152,7 +173,7 @@ isMessenger) => {
152
173
  arguments: v.optional(v.pipe(v.record(v.string(), v.unknown()), v.description("that command's arguments"))),
153
174
  });
154
175
  server.registerTool(`${prefix}_read`, {
155
- outputSchema: toStandardJsonSchema(ANSWER),
176
+ outputSchema: listedAs(prefix, false),
156
177
  title: "Run a reading command",
157
178
  description: `Run one command that only reads, with the arguments ${prefix}_tools_search showed. ${untrusted}`,
158
179
  inputSchema: toStandardJsonSchema(call),
@@ -160,7 +181,7 @@ isMessenger) => {
160
181
  }, runner(false));
161
182
  if (Object.values(commands).some((one) => one.writes))
162
183
  server.registerTool(`${prefix}_write`, {
163
- outputSchema: toStandardJsonSchema(ANSWER),
184
+ outputSchema: listedAs(prefix, true),
164
185
  title: "Run a writing command",
165
186
  description: `Run one command that changes something — ${messenger ? "sends, edits, deletes, joins" : "creates, edits, deletes"} — with the arguments ${prefix}_tools_search showed. ${untrusted}`,
166
187
  inputSchema: toStandardJsonSchema(call),