@wirecat/cli-core 0.665.0 → 0.667.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +82 -0
- package/dist/calendar/cli/conference.d.ts +3 -0
- package/dist/calendar/cli/conference.js +7 -0
- package/dist/calendar/cli/index.d.ts +1 -0
- package/dist/calendar/cli/index.js +4 -2
- package/dist/calendar/mcp/index.d.ts +62 -12
- package/dist/calendar/mcp/index.js +6 -0
- package/dist/calendar/testing/writer-contract.js +1 -0
- package/dist/calendar/testing/writer.d.ts +3 -0
- package/dist/calendar/testing/writer.js +9 -1
- package/dist/calendar/writer.d.ts +13 -0
- package/dist/calendar/writes.d.ts +3 -0
- package/dist/calendar/writes.js +21 -1
- package/dist/cli/documents/catalog.d.ts +87 -0
- package/dist/cli/documents/catalog.js +246 -0
- package/dist/cli/documents/documents.d.ts +32 -0
- package/dist/cli/documents/documents.js +76 -0
- package/dist/cli/documents/folders.d.ts +22 -0
- package/dist/cli/documents/folders.js +45 -0
- package/dist/cli/documents/index.d.ts +36 -0
- package/dist/cli/documents/index.js +32 -0
- package/dist/cli/documents/knowledge.d.ts +36 -0
- package/dist/cli/documents/knowledge.js +235 -0
- package/dist/cli/documents/mirrors.d.ts +46 -0
- package/dist/cli/documents/mirrors.js +198 -0
- package/dist/cli/documents/queries.d.ts +120 -0
- package/dist/cli/documents/queries.js +156 -0
- package/dist/cli/documents/search.d.ts +25 -0
- package/dist/cli/documents/search.js +34 -0
- package/dist/cli/documents/sync.d.ts +31 -0
- package/dist/cli/documents/sync.js +41 -0
- package/dist/cli/documents/testing/commands-contract.d.ts +35 -0
- package/dist/cli/documents/testing/commands-contract.js +205 -0
- package/dist/cli/documents/testing/index.d.ts +3 -0
- package/dist/cli/documents/testing/index.js +3 -0
- package/dist/cli/documents/testing/source-contract.d.ts +18 -0
- package/dist/cli/documents/testing/source-contract.js +112 -0
- package/dist/cli/documents/testing/source.d.ts +13 -0
- package/dist/cli/documents/testing/source.js +67 -0
- package/dist/cli/documents/words.d.ts +87 -0
- package/dist/cli/documents/words.js +79 -0
- package/dist/domain/providers.js +2 -1
- package/dist/entities/index.d.ts +6 -0
- package/dist/errors/reasons.js +16 -2
- package/dist/meetings/answers.d.ts +10 -0
- package/dist/meetings/answers.js +24 -1
- package/dist/meetings/cli/index.js +3 -2
- package/dist/meetings/cli/management.d.ts +1 -1
- package/dist/meetings/cli/management.js +67 -25
- package/dist/meetings/export.d.ts +2 -0
- package/dist/meetings/export.js +1 -0
- package/dist/meetings/index.d.ts +1 -1
- package/dist/meetings/index.js +1 -1
- package/dist/meetings/meeting-management.d.ts +68 -3
- package/dist/meetings/meeting-management.js +134 -17
- package/dist/meetings/read-answers.d.ts +1 -0
- package/dist/meetings/read-answers.js +1 -0
- package/dist/meetings/reads.d.ts +29 -2
- package/dist/meetings/reads.js +3 -2
- package/dist/meetings/result-items.d.ts +3 -0
- package/dist/meetings/result-items.js +9 -1
- package/dist/meetings/testing/management-contract.js +27 -5
- package/package.json +9 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { parseLucene, queryError, queryFieldsOf, validateQuery, } from "@wirecat/cli-base/query";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
import { FACT_STATUSES, FACT_TYPES, MEMORY_KINDS, MEMORY_SCOPES, MEMORY_STATUSES } from "../../domain/knowledge.js";
|
|
4
|
+
import { note } from "../../entities/note.js";
|
|
5
|
+
import { answerEntity } from "../answer-entity.js";
|
|
6
|
+
import { LIST_QUERY_GUIDE, nativeField, queryTerms, termField, typedQuery, withQuery, } from "../list-query.js";
|
|
7
|
+
const registry = (entity, schema, native, examples) => ({
|
|
8
|
+
entity,
|
|
9
|
+
backend: "native",
|
|
10
|
+
fields: queryFieldsOf(schema, { native, examples }).map((field) => field.native ? { ...field, operators: ["term", "phrase"] } : field),
|
|
11
|
+
});
|
|
12
|
+
export const folderRow = v.strictObject({ id: v.string() });
|
|
13
|
+
export const mirrorRow = v.strictObject({ id: v.string(), path: v.string(), folder: v.string() });
|
|
14
|
+
export const tagRow = v.strictObject({ tag: v.string() });
|
|
15
|
+
export const linkRow = v.looseObject({
|
|
16
|
+
id: v.string(),
|
|
17
|
+
from: v.string(),
|
|
18
|
+
to: v.nullable(v.string()),
|
|
19
|
+
kind: v.string(),
|
|
20
|
+
role: v.nullable(v.string()),
|
|
21
|
+
confirmed: v.boolean(),
|
|
22
|
+
origin: v.picklist(["file", "owner", "suggested", "message"]),
|
|
23
|
+
});
|
|
24
|
+
/** Who a document names, in every documents CLI: the provider's id of the account, the provider, and the person. */
|
|
25
|
+
export const IDENTITY_ROLES = ["owner", "last-editor"];
|
|
26
|
+
export const identityRow = v.looseObject({
|
|
27
|
+
remote_id: v.nullable(v.string()),
|
|
28
|
+
provider: v.string(),
|
|
29
|
+
role: v.picklist(IDENTITY_ROLES),
|
|
30
|
+
person: v.nullable(v.record(v.string(), v.unknown())),
|
|
31
|
+
});
|
|
32
|
+
/** The list queries of the shared documents commands: the same entities in every documents CLI. */
|
|
33
|
+
export const documentQueries = () => {
|
|
34
|
+
return {
|
|
35
|
+
folders: registry("selected_folder", folderRow, ["id"], { id: "id:FOLDER_ID" }),
|
|
36
|
+
mirrors: registry("mirror", mirrorRow, ["id", "path", "folder"], {
|
|
37
|
+
id: "id:example",
|
|
38
|
+
path: 'path:"/example/notes"',
|
|
39
|
+
folder: "folder:FOLDER_ID",
|
|
40
|
+
}),
|
|
41
|
+
tags: registry("document_tag", tagRow, ["tag"], { tag: "tag:budget" }),
|
|
42
|
+
notes: registry("note", note, ["text"], { text: "text:review" }),
|
|
43
|
+
links: registry("document_relationship", linkRow, ["id", "role", "origin", "confirmed"], {
|
|
44
|
+
id: "id:1",
|
|
45
|
+
role: "role:reviewer",
|
|
46
|
+
origin: "origin:owner",
|
|
47
|
+
confirmed: "confirmed:true",
|
|
48
|
+
}),
|
|
49
|
+
identities: registry("document_identity", identityRow, ["remote_id", "role"], {
|
|
50
|
+
remote_id: "remote_id:example",
|
|
51
|
+
role: "role:owner",
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export const bindQuery = (command, query, schema) => answerEntity(withQuery(command, query), query.entity, schema);
|
|
56
|
+
export const termsOf = (words, query, command) => Object.fromEntries(queryTerms(words, query, command));
|
|
57
|
+
export const FACT_QUERY = {
|
|
58
|
+
entity: "fact",
|
|
59
|
+
backend: "native",
|
|
60
|
+
fields: [
|
|
61
|
+
termField("kind", "enum", "kind:decision", { values: FACT_TYPES }),
|
|
62
|
+
termField("status", "enum", "status:proposed", { values: FACT_STATUSES }),
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
export const MEMORY_QUERY = {
|
|
66
|
+
entity: "memory",
|
|
67
|
+
backend: "native",
|
|
68
|
+
fields: [
|
|
69
|
+
termField("kind", "enum", "kind:preference", { values: MEMORY_KINDS }),
|
|
70
|
+
termField("status", "enum", "status:proposed", { values: MEMORY_STATUSES }),
|
|
71
|
+
termField("scope", "enum", "scope:work", { values: MEMORY_SCOPES }),
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
export const MEMORY_SEARCH_QUERY = {
|
|
75
|
+
entity: "memory",
|
|
76
|
+
backend: "native",
|
|
77
|
+
fields: [
|
|
78
|
+
nativeField({
|
|
79
|
+
name: "text",
|
|
80
|
+
type: "txt",
|
|
81
|
+
operators: ["term", "phrase"],
|
|
82
|
+
example: "text:reviews",
|
|
83
|
+
relation: "words of the memory; a bare word means the same",
|
|
84
|
+
}),
|
|
85
|
+
termField("scope", "enum", "scope:work", { values: MEMORY_SCOPES }),
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
/** A fact as cli-core's `fact` entity. */
|
|
89
|
+
export const factItem = ({ type, statement, source, confirmedBy, ...fact }) => ({
|
|
90
|
+
ref: fact.ref,
|
|
91
|
+
id: fact.id,
|
|
92
|
+
kind: type,
|
|
93
|
+
text: statement,
|
|
94
|
+
status: fact.status,
|
|
95
|
+
project: fact.project,
|
|
96
|
+
subject: fact.subject,
|
|
97
|
+
occurred_at: fact.occurredAt,
|
|
98
|
+
supersedes: fact.supersedes,
|
|
99
|
+
author: fact.author,
|
|
100
|
+
model: fact.model,
|
|
101
|
+
confirmed_by: confirmedBy,
|
|
102
|
+
scope: fact.scope,
|
|
103
|
+
origin: source,
|
|
104
|
+
evidence: fact.evidence,
|
|
105
|
+
created_at: fact.createdAt,
|
|
106
|
+
updated_at: fact.updatedAt,
|
|
107
|
+
});
|
|
108
|
+
/** A memory as cli-core's `memory` entity. */
|
|
109
|
+
export const memoryItem = ({ body, ...memory }) => ({
|
|
110
|
+
ref: memory.ref,
|
|
111
|
+
id: memory.id,
|
|
112
|
+
kind: memory.kind,
|
|
113
|
+
text: body,
|
|
114
|
+
subject: memory.subject,
|
|
115
|
+
author: memory.author,
|
|
116
|
+
model: memory.model,
|
|
117
|
+
confidence: memory.confidence,
|
|
118
|
+
status: memory.status,
|
|
119
|
+
scope: memory.scope,
|
|
120
|
+
supersedes: memory.supersedes,
|
|
121
|
+
evidence: memory.evidence,
|
|
122
|
+
last_verified_at: memory.lastVerifiedAt,
|
|
123
|
+
created_at: memory.createdAt,
|
|
124
|
+
updated_at: memory.updatedAt,
|
|
125
|
+
});
|
|
126
|
+
/**
|
|
127
|
+
* `memories search`'s words and its `scope:` term: the store searches the words and filters the scope in one
|
|
128
|
+
* query. Bare words are text, so they may repeat; everything is joined by AND.
|
|
129
|
+
*/
|
|
130
|
+
export const memorySearch = (words) => {
|
|
131
|
+
const command = "memories search";
|
|
132
|
+
const context = { command, guide: LIST_QUERY_GUIDE };
|
|
133
|
+
const ast = validateQuery(parseLucene(typedQuery(words), { defaultField: "text", ...context }), MEMORY_SEARCH_QUERY, context);
|
|
134
|
+
const text = [];
|
|
135
|
+
let scope;
|
|
136
|
+
const add = (node) => {
|
|
137
|
+
if (node.kind === "boolean") {
|
|
138
|
+
for (const clause of node.clauses) {
|
|
139
|
+
if (clause.occur !== "must")
|
|
140
|
+
queryError("query.unsupported-placement", clause.node.span, "this search joins its terms by AND", context);
|
|
141
|
+
add(clause.node);
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (node.field === "text")
|
|
146
|
+
text.push(node.value);
|
|
147
|
+
else if (scope !== undefined)
|
|
148
|
+
queryError("query.unsupported-placement", node.span, "scope only once here", context);
|
|
149
|
+
else
|
|
150
|
+
scope = node.value.toLowerCase();
|
|
151
|
+
};
|
|
152
|
+
add(ast.root);
|
|
153
|
+
if (text.length === 0)
|
|
154
|
+
queryError("query.missing-value", ast.root.span, "say which words to look for beside scope:", context);
|
|
155
|
+
return { text: text.join(" "), ...(scope === undefined ? {} : { scope }) };
|
|
156
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { type Body } from "../envelope.js";
|
|
3
|
+
import { type DocumentWords } from "./words.js";
|
|
4
|
+
export interface DocumentSearchOptions {
|
|
5
|
+
limit: number;
|
|
6
|
+
offset: number;
|
|
7
|
+
exact: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface DocumentSearchCommands {
|
|
10
|
+
words: DocumentWords;
|
|
11
|
+
output(body: Body): void;
|
|
12
|
+
/** Searches the selected profile's imported documents, by meaning too when they are indexed. */
|
|
13
|
+
search(query: string, options: DocumentSearchOptions): Promise<object>;
|
|
14
|
+
/**
|
|
15
|
+
* What the selected profile has imported. An empty answer over an empty import reads to an agent as "no such
|
|
16
|
+
* document", so the answer then says what to run.
|
|
17
|
+
*/
|
|
18
|
+
imported(): {
|
|
19
|
+
profile: string;
|
|
20
|
+
chosen: boolean;
|
|
21
|
+
documents: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** `search` over the selected profile's imported documents; a documents CLI has no messenger `search` group. */
|
|
25
|
+
export declare const addDocumentSearchCommand: (program: Command, helpers: DocumentSearchCommands) => Command;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { annotate, sharedCommand } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { honoursDryRun } from "../dry-run-guard.js";
|
|
3
|
+
import { LOCAL_READ } from "../effects.js";
|
|
4
|
+
import { itemOf } from "../envelope.js";
|
|
5
|
+
import { examples, positive, wordsOf } from "./words.js";
|
|
6
|
+
const notImported = (app, { profile, chosen, documents }) => {
|
|
7
|
+
if (documents > 0)
|
|
8
|
+
return undefined;
|
|
9
|
+
return !chosen
|
|
10
|
+
? `profile ${profile} has no folders selected, so nothing is imported to search — ` +
|
|
11
|
+
`${app} ${profile} folders add FOLDER_ID, then ${app} ${profile} sync`
|
|
12
|
+
: `profile ${profile} has imported no documents yet — ${app} ${profile} sync`;
|
|
13
|
+
};
|
|
14
|
+
const addDocumentSearchCommandDefinition = (program, helpers) => {
|
|
15
|
+
const wording = wordsOf(helpers.words);
|
|
16
|
+
const { prefix } = wording;
|
|
17
|
+
return examples(annotate(program.command("search"), { effects: LOCAL_READ })
|
|
18
|
+
.argument("<query>", "words to look for, and fields such as tag: and date: that every hit must match")
|
|
19
|
+
.description("search imported documents by words, and by meaning when indexed"), [`${prefix} search budget`, `${prefix} search "quarterly plan" --exact --limit 5`])
|
|
20
|
+
.option("--limit <n>", "how many results to return", positive, 20)
|
|
21
|
+
.option("--page <n>", "which page to return", positive, 1)
|
|
22
|
+
.option("--exact", "match the words exactly: no word forms, no meaning")
|
|
23
|
+
.action(async (query, { page, ...args }) => {
|
|
24
|
+
const result = await helpers.search(query, {
|
|
25
|
+
...args,
|
|
26
|
+
offset: (page - 1) * args.limit,
|
|
27
|
+
exact: args.exact ?? false,
|
|
28
|
+
});
|
|
29
|
+
const hint = notImported(wording.app, helpers.imported());
|
|
30
|
+
helpers.output(itemOf(hint ? { ...result, not_imported: hint } : result));
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
/** `search` over the selected profile's imported documents; a documents CLI has no messenger `search` group. */
|
|
34
|
+
export const addDocumentSearchCommand = honoursDryRun(sharedCommand(addDocumentSearchCommandDefinition));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { type Body } from "../envelope.js";
|
|
3
|
+
import { type DocumentWords } from "./words.js";
|
|
4
|
+
export interface DocumentSyncArgs {
|
|
5
|
+
limit: number;
|
|
6
|
+
rescan?: boolean;
|
|
7
|
+
/** Also index pending text for meaning search, with a model already downloaded. */
|
|
8
|
+
embed?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface DocumentSyncCommands {
|
|
11
|
+
words: DocumentWords;
|
|
12
|
+
output(body: Body): void;
|
|
13
|
+
/** Writes a line for the person, not the answer. */
|
|
14
|
+
diagnostic(text: string): void;
|
|
15
|
+
/** The selected profile, as `sync again` names it. */
|
|
16
|
+
profile(): string;
|
|
17
|
+
/** The most entries one sync reads under the chosen folders, as `sync --help` says. */
|
|
18
|
+
maxEntries: number;
|
|
19
|
+
/**
|
|
20
|
+
* Syncs the selected profile into the shared store under the lock the CLI's writes take. `errors` are the failed
|
|
21
|
+
* operations still pending; `pending` counts every operation left for the next sync.
|
|
22
|
+
*/
|
|
23
|
+
sync(args: DocumentSyncArgs): Promise<{
|
|
24
|
+
errors: unknown[];
|
|
25
|
+
pending: number;
|
|
26
|
+
}>;
|
|
27
|
+
/** What `status` answers: the last sync, imported documents and pending work, from local files only. */
|
|
28
|
+
status(): object | Promise<object>;
|
|
29
|
+
}
|
|
30
|
+
/** `sync` into the shared store and `status` of the local copy, for the selected profile. */
|
|
31
|
+
export declare const addDocumentSyncCommands: (program: Command, helpers: DocumentSyncCommands) => Command[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate, sharedCommand } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { honoursDryRun } from "../dry-run-guard.js";
|
|
4
|
+
import { FETCH, LOCAL_READ } from "../effects.js";
|
|
5
|
+
import { itemOf } from "../envelope.js";
|
|
6
|
+
import { examples, positive, wordsOf } from "./words.js";
|
|
7
|
+
const addDocumentSyncCommandsDefinition = (program, helpers) => {
|
|
8
|
+
const { output } = helpers;
|
|
9
|
+
const wording = wordsOf(helpers.words);
|
|
10
|
+
const { prefix, text } = wording;
|
|
11
|
+
const sync = examples(annotate(program.command("sync"), { effects: FETCH })
|
|
12
|
+
.summary("import what changed in the chosen folders, and finish an unfinished sync")
|
|
13
|
+
.description("import what changed in the chosen folders, and finish an unfinished sync; " +
|
|
14
|
+
`one sync reads at most ${helpers.maxEntries} entries under the chosen folders, and as many changes`), [`${prefix} sync`, `${prefix} sync --rescan --limit 500`])
|
|
15
|
+
.option("--limit <n>", text.syncLimit, positive, 200)
|
|
16
|
+
.option("--rescan", "read every chosen folder again instead of only what changed")
|
|
17
|
+
.option("--embed", "also index pending text for meaning search, with a model already downloaded")
|
|
18
|
+
.action(async (args) => {
|
|
19
|
+
const result = await helpers.sync(args);
|
|
20
|
+
output(itemOf(result, {
|
|
21
|
+
meta: result.errors.length
|
|
22
|
+
? {
|
|
23
|
+
complete: false,
|
|
24
|
+
issues: [{ code: "provider_error", reason: "sync.partial", source: wording.source }],
|
|
25
|
+
}
|
|
26
|
+
: {},
|
|
27
|
+
}));
|
|
28
|
+
if (result.errors.length || result.pending)
|
|
29
|
+
helpers.diagnostic(`${result.pending} source operations remain; run ${wording.app} ${helpers.profile()} sync again\n`);
|
|
30
|
+
if (result.errors.length)
|
|
31
|
+
throw new CliError("provider_error", "sync completed partially; failed operations remain pending", {
|
|
32
|
+
reason: "sync.partial",
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
const status = examples(annotate(program.command("status"), { effects: LOCAL_READ }).description("show the last sync, imported documents and pending work"), [`${prefix} status`]).action(async () => {
|
|
36
|
+
output(itemOf(await helpers.status()));
|
|
37
|
+
});
|
|
38
|
+
return [sync, status];
|
|
39
|
+
};
|
|
40
|
+
/** `sync` into the shared store and `status` of the local copy, for the selected profile. */
|
|
41
|
+
export const addDocumentSyncCommands = honoursDryRun(sharedCommand(addDocumentSyncCommandsDefinition));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { ContractCase } from "../../../meetings/index.js";
|
|
3
|
+
import type { DocumentWords } from "../words.js";
|
|
4
|
+
/** The CLI's commands over its own fakes, with a fresh store and a fresh provider for each case. */
|
|
5
|
+
export interface DocumentCommandsFixture {
|
|
6
|
+
/** The CLI's whole command tree, as `run` builds it. */
|
|
7
|
+
program: Command;
|
|
8
|
+
words: DocumentWords;
|
|
9
|
+
/**
|
|
10
|
+
* Runs one command against the fakes, the words after the profile (`["tags", "list", "a"]`), with the profile chosen
|
|
11
|
+
* and `--json` added by the CLI. Answers the exit code and what it printed as data.
|
|
12
|
+
*/
|
|
13
|
+
run(argv: string[]): Promise<{
|
|
14
|
+
exit: number;
|
|
15
|
+
stdout: string;
|
|
16
|
+
}>;
|
|
17
|
+
/** A document the fake provider holds, by an id `documents show` takes once `sync` imported it. */
|
|
18
|
+
document: string;
|
|
19
|
+
/** A word of that document's text, which `search` finds. */
|
|
20
|
+
word: string;
|
|
21
|
+
/** The CLI mounts `mirrors`. */
|
|
22
|
+
mirrors?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** Every path the shared builders add, as `<group> <command>`. */
|
|
25
|
+
export declare const SHARED_DOCUMENT_PATHS: readonly ["folders add", "folders list", "folders remove", "sync", "status", "documents list", "documents show", "documents export", "documents context", "search", "catalog import", "catalog show", "catalog list", "catalog search", "catalog tree", "catalog tags list", "catalog tags add", "catalog tags remove", "tags list", "tags add", "tags remove", "relationships list", "relationships add", "relationships remove", "notes add", "notes list", "notes show", "notes edit", "notes remove", "memories add", "memories list", "memories show", "memories confirm", "memories stale", "memories search", "memories extract", "facts add", "facts list", "facts show", "facts confirm", "facts reverse", "identities list", "identities link"];
|
|
26
|
+
export declare const SHARED_MIRROR_PATHS: readonly ["mirrors add", "mirrors list", "mirrors remove", "mirrors status", "mirrors sync", "mirrors watch"];
|
|
27
|
+
type Effect = {
|
|
28
|
+
remote: "none" | "read" | "write";
|
|
29
|
+
local: "none" | "read" | "write";
|
|
30
|
+
};
|
|
31
|
+
/** What each shared path reads and writes: the MCP server offers or holds back a tool by it. */
|
|
32
|
+
export declare const SHARED_EFFECTS: Record<(typeof SHARED_DOCUMENT_PATHS)[number] | (typeof SHARED_MIRROR_PATHS)[number], Effect>;
|
|
33
|
+
/** What every documents CLI's shared commands are and answer: run each case in the CLI's tests. */
|
|
34
|
+
export declare const documentCommandsContract: (make: () => DocumentCommandsFixture | Promise<DocumentCommandsFixture>) => ContractCase[];
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { hasSharedContract, metaOf, sharedContractOverrides } from "@wirecat/cli-base/commands";
|
|
3
|
+
/** Every path the shared builders add, as `<group> <command>`. */
|
|
4
|
+
export const SHARED_DOCUMENT_PATHS = [
|
|
5
|
+
"folders add",
|
|
6
|
+
"folders list",
|
|
7
|
+
"folders remove",
|
|
8
|
+
"sync",
|
|
9
|
+
"status",
|
|
10
|
+
"documents list",
|
|
11
|
+
"documents show",
|
|
12
|
+
"documents export",
|
|
13
|
+
"documents context",
|
|
14
|
+
"search",
|
|
15
|
+
"catalog import",
|
|
16
|
+
"catalog show",
|
|
17
|
+
"catalog list",
|
|
18
|
+
"catalog search",
|
|
19
|
+
"catalog tree",
|
|
20
|
+
"catalog tags list",
|
|
21
|
+
"catalog tags add",
|
|
22
|
+
"catalog tags remove",
|
|
23
|
+
"tags list",
|
|
24
|
+
"tags add",
|
|
25
|
+
"tags remove",
|
|
26
|
+
"relationships list",
|
|
27
|
+
"relationships add",
|
|
28
|
+
"relationships remove",
|
|
29
|
+
"notes add",
|
|
30
|
+
"notes list",
|
|
31
|
+
"notes show",
|
|
32
|
+
"notes edit",
|
|
33
|
+
"notes remove",
|
|
34
|
+
"memories add",
|
|
35
|
+
"memories list",
|
|
36
|
+
"memories show",
|
|
37
|
+
"memories confirm",
|
|
38
|
+
"memories stale",
|
|
39
|
+
"memories search",
|
|
40
|
+
"memories extract",
|
|
41
|
+
"facts add",
|
|
42
|
+
"facts list",
|
|
43
|
+
"facts show",
|
|
44
|
+
"facts confirm",
|
|
45
|
+
"facts reverse",
|
|
46
|
+
"identities list",
|
|
47
|
+
"identities link",
|
|
48
|
+
];
|
|
49
|
+
export const SHARED_MIRROR_PATHS = [
|
|
50
|
+
"mirrors add",
|
|
51
|
+
"mirrors list",
|
|
52
|
+
"mirrors remove",
|
|
53
|
+
"mirrors status",
|
|
54
|
+
"mirrors sync",
|
|
55
|
+
"mirrors watch",
|
|
56
|
+
];
|
|
57
|
+
const READ = { remote: "none", local: "read" };
|
|
58
|
+
const WRITE = { remote: "none", local: "write" };
|
|
59
|
+
const FETCH = { remote: "read", local: "write" };
|
|
60
|
+
const PUSH = { remote: "write", local: "write" };
|
|
61
|
+
/** What each shared path reads and writes: the MCP server offers or holds back a tool by it. */
|
|
62
|
+
export const SHARED_EFFECTS = {
|
|
63
|
+
"folders add": FETCH,
|
|
64
|
+
"folders list": READ,
|
|
65
|
+
"folders remove": WRITE,
|
|
66
|
+
sync: FETCH,
|
|
67
|
+
status: READ,
|
|
68
|
+
"documents list": READ,
|
|
69
|
+
"documents show": READ,
|
|
70
|
+
"documents export": WRITE,
|
|
71
|
+
"documents context": READ,
|
|
72
|
+
search: READ,
|
|
73
|
+
"catalog import": WRITE,
|
|
74
|
+
"catalog show": READ,
|
|
75
|
+
"catalog list": READ,
|
|
76
|
+
"catalog search": READ,
|
|
77
|
+
"catalog tree": READ,
|
|
78
|
+
"catalog tags list": READ,
|
|
79
|
+
"catalog tags add": WRITE,
|
|
80
|
+
"catalog tags remove": WRITE,
|
|
81
|
+
"tags list": READ,
|
|
82
|
+
"tags add": WRITE,
|
|
83
|
+
"tags remove": WRITE,
|
|
84
|
+
"relationships list": READ,
|
|
85
|
+
"relationships add": WRITE,
|
|
86
|
+
"relationships remove": WRITE,
|
|
87
|
+
"notes add": WRITE,
|
|
88
|
+
"notes list": READ,
|
|
89
|
+
"notes show": READ,
|
|
90
|
+
"notes edit": WRITE,
|
|
91
|
+
"notes remove": WRITE,
|
|
92
|
+
"memories add": WRITE,
|
|
93
|
+
"memories list": READ,
|
|
94
|
+
"memories show": READ,
|
|
95
|
+
"memories confirm": WRITE,
|
|
96
|
+
"memories stale": WRITE,
|
|
97
|
+
"memories search": READ,
|
|
98
|
+
"memories extract": PUSH,
|
|
99
|
+
"facts add": WRITE,
|
|
100
|
+
"facts list": READ,
|
|
101
|
+
"facts show": READ,
|
|
102
|
+
"facts confirm": WRITE,
|
|
103
|
+
"facts reverse": WRITE,
|
|
104
|
+
"identities list": READ,
|
|
105
|
+
"identities link": WRITE,
|
|
106
|
+
"mirrors add": FETCH,
|
|
107
|
+
"mirrors list": READ,
|
|
108
|
+
"mirrors remove": WRITE,
|
|
109
|
+
"mirrors status": READ,
|
|
110
|
+
"mirrors sync": PUSH,
|
|
111
|
+
"mirrors watch": PUSH,
|
|
112
|
+
};
|
|
113
|
+
const find = (program, path) => {
|
|
114
|
+
let at = program;
|
|
115
|
+
for (const name of path.split(" "))
|
|
116
|
+
at = at?.commands.find((command) => command.name() === name);
|
|
117
|
+
return at;
|
|
118
|
+
};
|
|
119
|
+
const json = (stdout) => {
|
|
120
|
+
const lines = stdout.trim().split("\n");
|
|
121
|
+
try {
|
|
122
|
+
return JSON.parse(stdout);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return lines.map((line) => JSON.parse(line));
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const ok = async (fixture, argv) => {
|
|
129
|
+
const answer = await fixture.run(argv);
|
|
130
|
+
assert.equal(answer.exit, 0, `${argv.join(" ")} exits 0`);
|
|
131
|
+
return json(answer.stdout);
|
|
132
|
+
};
|
|
133
|
+
/** Every value under `key` anywhere in an answer, so a check does not depend on one CLI's envelope. */
|
|
134
|
+
const valuesOf = (value, key) => {
|
|
135
|
+
if (Array.isArray(value))
|
|
136
|
+
return value.flatMap((one) => valuesOf(one, key));
|
|
137
|
+
if (typeof value !== "object" || value === null)
|
|
138
|
+
return [];
|
|
139
|
+
return Object.entries(value).flatMap(([name, one]) => [...(name === key ? [one] : []), ...valuesOf(one, key)]);
|
|
140
|
+
};
|
|
141
|
+
const items = (answer) => (Array.isArray(answer.items) ? answer.items : []);
|
|
142
|
+
/** What every documents CLI's shared commands are and answer: run each case in the CLI's tests. */
|
|
143
|
+
export const documentCommandsContract = (make) => [
|
|
144
|
+
{
|
|
145
|
+
name: "tree: every shared path is there, still cli-core's, and says what it reads and writes",
|
|
146
|
+
async run() {
|
|
147
|
+
const fixture = await make();
|
|
148
|
+
const paths = [...SHARED_DOCUMENT_PATHS, ...(fixture.mirrors ? SHARED_MIRROR_PATHS : [])];
|
|
149
|
+
for (const path of paths) {
|
|
150
|
+
const command = find(fixture.program, path);
|
|
151
|
+
assert.ok(command, `${path} is mounted`);
|
|
152
|
+
assert.ok(hasSharedContract(command), `${path} is the shared definition`);
|
|
153
|
+
const { remote, local } = metaOf(command).effects ?? {};
|
|
154
|
+
assert.deepEqual({ remote, local }, SHARED_EFFECTS[path], `${path} reads and writes what cli-core says`);
|
|
155
|
+
}
|
|
156
|
+
const name = fixture.program.name();
|
|
157
|
+
const overridden = sharedContractOverrides(fixture.program)
|
|
158
|
+
.map((override) => (override.command[0] === name ? override.command.slice(1) : override.command).join(" "))
|
|
159
|
+
.filter((path) => paths.some((shared) => shared === path || shared.startsWith(`${path} `) || path.startsWith(`${shared} `)));
|
|
160
|
+
assert.deepEqual(overridden, [], "the CLI overrides no shared contract");
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: "words: the remote side is the CLI's word in --keep and in identities link",
|
|
165
|
+
async run() {
|
|
166
|
+
const fixture = await make();
|
|
167
|
+
const link = find(fixture.program, "identities link");
|
|
168
|
+
assert.ok(link?.registeredArguments.some((argument) => argument.name() === `${fixture.words.remote}-id`), `identities link takes <${fixture.words.remote}-id>`);
|
|
169
|
+
if (!fixture.mirrors)
|
|
170
|
+
return;
|
|
171
|
+
const keep = find(fixture.program, "mirrors sync")?.options.find((option) => option.long === "--keep");
|
|
172
|
+
assert.deepEqual(keep?.argChoices, ["local", fixture.words.remote, "both"]);
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: "sync, then documents list, documents show, status and search answer the imported document",
|
|
177
|
+
async run() {
|
|
178
|
+
const fixture = await make();
|
|
179
|
+
await ok(fixture, ["sync"]);
|
|
180
|
+
const listed = items(await ok(fixture, ["documents", "list"])).map((item) => item.id);
|
|
181
|
+
assert.ok(listed.includes(fixture.document), `documents list answers ${fixture.document} by its id`);
|
|
182
|
+
const shown = await ok(fixture, ["documents", "show", fixture.document]);
|
|
183
|
+
assert.ok(valuesOf(shown, "id").includes(fixture.document), `documents show answers ${fixture.document}`);
|
|
184
|
+
assert.ok(valuesOf(shown, "text").some((text) => typeof text === "string" && text.includes(fixture.word)), `documents show gives the text with "${fixture.word}"`);
|
|
185
|
+
await ok(fixture, ["status"]);
|
|
186
|
+
const found = await ok(fixture, ["search", fixture.word]);
|
|
187
|
+
assert.ok(valuesOf(found, "id").includes(fixture.document), `search "${fixture.word}" finds ${fixture.document}`);
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: "tags and notes: what is added to a document is listed on it, and a removed tag is gone",
|
|
192
|
+
async run() {
|
|
193
|
+
const fixture = await make();
|
|
194
|
+
await ok(fixture, ["sync"]);
|
|
195
|
+
await ok(fixture, ["tags", "add", fixture.document, "contract-tag"]);
|
|
196
|
+
const tags = async () => items(await ok(fixture, ["tags", "list", fixture.document])).map((item) => item.tag);
|
|
197
|
+
assert.deepEqual(await tags(), ["contract-tag"]);
|
|
198
|
+
await ok(fixture, ["tags", "remove", fixture.document, "contract-tag"]);
|
|
199
|
+
assert.deepEqual(await tags(), []);
|
|
200
|
+
await ok(fixture, ["notes", "add", fixture.document, "check the contract numbers"]);
|
|
201
|
+
const notes = items(await ok(fixture, ["notes", "list", fixture.document])).map((item) => item.text);
|
|
202
|
+
assert.deepEqual(notes, ["check the contract numbers"]);
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { type DocumentCommandsFixture, documentCommandsContract, SHARED_DOCUMENT_PATHS, SHARED_MIRROR_PATHS, } from "./commands-contract.js";
|
|
2
|
+
export { FAKE_FOLDER, type FakeDocumentSource, fakeDocumentSource, fakeFile } from "./source.js";
|
|
3
|
+
export { type DocumentSourceFixture, documentSourceContract } from "./source-contract.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DocumentSource, SourceFile } from "../../../documents.js";
|
|
2
|
+
import type { ContractCase } from "../../../meetings/index.js";
|
|
3
|
+
/** One adapter over recorded or faked responses, fresh for each case. */
|
|
4
|
+
export interface DocumentSourceFixture<M extends SourceFile = SourceFile> {
|
|
5
|
+
source: DocumentSource<M>;
|
|
6
|
+
/** A folder the account can read, with at least one file somewhere below it. */
|
|
7
|
+
root: string;
|
|
8
|
+
/** The provider's folder test, as the CLI passes it to `syncDocuments`. */
|
|
9
|
+
isFolder(file: M): boolean;
|
|
10
|
+
/** A folder that is also a document (a page with sub-pages), as the CLI passes it to `syncDocuments`. */
|
|
11
|
+
isDocument?(file: M): boolean;
|
|
12
|
+
/** Makes a change on the provider's side (a new or edited file) for the change feed to list; absent skips that check. */
|
|
13
|
+
change?(): Promise<void>;
|
|
14
|
+
/** An id the provider does not know; absent skips that case. */
|
|
15
|
+
missing?: string;
|
|
16
|
+
}
|
|
17
|
+
/** What every documents adapter answers, whatever the provider: run each case in the adapter's tests. */
|
|
18
|
+
export declare const documentSourceContract: <M extends SourceFile>(make: () => DocumentSourceFixture<M> | Promise<DocumentSourceFixture<M>>) => ContractCase[];
|