@wirecat/wirecat 0.0.0-stage → 1.0.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/LICENSE +204 -0
- package/README.md +400 -2
- package/THIRD_PARTY_NOTICES +2 -0
- package/contracts/wirecat.json +4612 -0
- package/dist/actions/actions.js +269 -0
- package/dist/actions/command.js +102 -0
- package/dist/agents/command.js +17 -0
- package/dist/agents/log.js +23 -0
- package/dist/answer.js +100 -0
- package/dist/answers/command.js +128 -0
- package/dist/app.js +15 -0
- package/dist/author.js +109 -0
- package/dist/bin/wcat-wirecat.js +40 -0
- package/dist/bots/command.js +175 -0
- package/dist/bundle/auto-YETGUQ2J.js +43 -0
- package/dist/bundle/chunk-3ME37WWB.js +31 -0
- package/dist/bundle/chunk-4WI3FO7T.js +395 -0
- package/dist/bundle/chunk-7O7XM37N.js +2 -0
- package/dist/bundle/chunk-DWQQRBQV.js +51 -0
- package/dist/bundle/chunk-FOWR5KJS.js +72 -0
- package/dist/bundle/chunk-GGRL6DTE.js +120 -0
- package/dist/bundle/chunk-KNFSW562.js +312 -0
- package/dist/bundle/chunk-KPJVVFQF.js +416 -0
- package/dist/bundle/chunk-WMPDRWVF.js +222 -0
- package/dist/bundle/chunk-X5OK73GU.js +807 -0
- package/dist/bundle/chunk-ZC4PRE6C.js +38 -0
- package/dist/bundle/entry-S4DSYEAY.js +64 -0
- package/dist/bundle/failure-FALOD7QW.js +19 -0
- package/dist/bundle/from-memo-XVOLSUOM.js +314 -0
- package/dist/bundle/program-XSZSINBU.js +14994 -0
- package/dist/bundle/server-GQ4NZUDL.js +303 -0
- package/dist/bundle/update-2EH5KHTV.js +22 -0
- package/dist/bundle/wcat-wirecat.js +83 -0
- package/dist/config-command.js +39 -0
- package/dist/config-issues.js +15 -0
- package/dist/config.js +187 -0
- package/dist/context/command.js +162 -0
- package/dist/context/context.js +197 -0
- package/dist/contract-overrides/commands.js +81 -0
- package/dist/contract-overrides/mcp.js +241 -0
- package/dist/contract-overrides/meetings.js +344 -0
- package/dist/contract-overrides/search.js +508 -0
- package/dist/contract-overrides/skill.js +85 -0
- package/dist/contract-overrides.js +7 -0
- package/dist/digest/backfill.js +175 -0
- package/dist/digest/brief.js +189 -0
- package/dist/digest/catch-up-record.js +30 -0
- package/dist/digest/catch-up.js +86 -0
- package/dist/digest/command.js +110 -0
- package/dist/digest/digest-commands.js +327 -0
- package/dist/digest/digest.js +560 -0
- package/dist/digest/digests.js +213 -0
- package/dist/digest/history.js +202 -0
- package/dist/digest/input.js +30 -0
- package/dist/digest/known.js +28 -0
- package/dist/digest/sources.js +155 -0
- package/dist/digest/sync-health.js +158 -0
- package/dist/digest/task-proposals.js +67 -0
- package/dist/digest/tasks.js +145 -0
- package/dist/digest/text.js +49 -0
- package/dist/discovery/command.js +107 -0
- package/dist/doctor/command.js +167 -0
- package/dist/documents/command.js +107 -0
- package/dist/domain-lists/command.js +13 -0
- package/dist/events/command.js +35 -0
- package/dist/events/events.js +196 -0
- package/dist/examples.js +609 -0
- package/dist/facts/command.js +100 -0
- package/dist/facts/fact.js +54 -0
- package/dist/facts/facts.js +15 -0
- package/dist/failure.js +58 -0
- package/dist/finance/command.js +121 -0
- package/dist/finance/contracts-command.js +109 -0
- package/dist/finance/deal-text.js +34 -0
- package/dist/finance/deals-command.js +346 -0
- package/dist/finance/finance.js +129 -0
- package/dist/finance/lines-command.js +70 -0
- package/dist/finance/orders-command.js +94 -0
- package/dist/finance/products-command.js +98 -0
- package/dist/finance/subscriptions-command.js +152 -0
- package/dist/finance/transactions-command.js +136 -0
- package/dist/finance/wallets-command.js +105 -0
- package/dist/finance/written.js +36 -0
- package/dist/findings/command.js +102 -0
- package/dist/findings-input.js +23 -0
- package/dist/identity.js +20 -0
- package/dist/install/postinstall.js +47 -0
- package/dist/json-fields.js +48 -0
- package/dist/knowledge/business-text.js +19 -0
- package/dist/knowledge/command.js +435 -0
- package/dist/knowledge/document-context.js +33 -0
- package/dist/knowledge/key-documents.js +120 -0
- package/dist/knowledge/list-queries.js +20 -0
- package/dist/knowledge/meeting-projects-command.js +61 -0
- package/dist/knowledge/messenger-sync.js +253 -0
- package/dist/knowledge/money-text.js +16 -0
- package/dist/knowledge/notes-about.js +81 -0
- package/dist/knowledge/organization-delete-command.js +44 -0
- package/dist/knowledge/organization-text.js +27 -0
- package/dist/knowledge/project-actions-command.js +130 -0
- package/dist/knowledge/project-actions.js +104 -0
- package/dist/knowledge/project-activity-command.js +70 -0
- package/dist/knowledge/project-context.js +101 -0
- package/dist/knowledge/project-findings.js +41 -0
- package/dist/knowledge/project-gather-command.js +100 -0
- package/dist/knowledge/project-status-command.js +129 -0
- package/dist/knowledge/project-transfer-command.js +58 -0
- package/dist/knowledge/project-transfer.js +107 -0
- package/dist/knowledge/relationships-scan.js +116 -0
- package/dist/knowledge/relationships.js +115 -0
- package/dist/knowledge/roles-command.js +67 -0
- package/dist/mail/command.js +20 -0
- package/dist/mail/findings-command.js +143 -0
- package/dist/mail/findings-duplicates.js +159 -0
- package/dist/mail/messages-command.js +77 -0
- package/dist/mail/review-command.js +59 -0
- package/dist/mail/subscriptions-command.js +84 -0
- package/dist/mcp/catalogue.js +159 -0
- package/dist/mcp/command.js +125 -0
- package/dist/mcp/granted.js +18 -0
- package/dist/mcp/permissions.js +61 -0
- package/dist/mcp/server.js +128 -0
- package/dist/meetings/command.js +31 -0
- package/dist/meetings/list-command.js +59 -0
- package/dist/meetings/preparation-command.js +42 -0
- package/dist/meetings/preparation-text.js +44 -0
- package/dist/meetings/preparation.js +50 -0
- package/dist/meetings/read.js +32 -0
- package/dist/memories/command.js +105 -0
- package/dist/memories/memories.js +17 -0
- package/dist/memories/memory.js +89 -0
- package/dist/memories/sources.js +111 -0
- package/dist/mentions/command.js +91 -0
- package/dist/migrate/check.js +48 -0
- package/dist/migrate/from-memo.js +345 -0
- package/dist/migrate/skill.js +35 -0
- package/dist/models/command.js +19 -0
- package/dist/options.js +35 -0
- package/dist/output.js +17 -0
- package/dist/page.js +14 -0
- package/dist/people/command.js +144 -0
- package/dist/people/delete-command.js +53 -0
- package/dist/people/doubts-command.js +81 -0
- package/dist/people/identities-command.js +188 -0
- package/dist/people/identity.js +42 -0
- package/dist/people/owner.js +14 -0
- package/dist/people/proposal-rows.js +70 -0
- package/dist/people/proposals-command.js +248 -0
- package/dist/people/review-context.js +108 -0
- package/dist/people/subject.js +19 -0
- package/dist/program.js +875 -0
- package/dist/read-only.js +51 -0
- package/dist/reasons.js +368 -0
- package/dist/records/import.js +135 -0
- package/dist/records/input.js +210 -0
- package/dist/records/mapping.js +80 -0
- package/dist/records/record-commands.js +125 -0
- package/dist/records/sources.js +73 -0
- package/dist/refs.js +28 -0
- package/dist/review/command.js +171 -0
- package/dist/review/kinds.js +44 -0
- package/dist/review/review.js +299 -0
- package/dist/review/status.js +93 -0
- package/dist/rows.js +219 -0
- package/dist/run/auto.js +237 -0
- package/dist/run/entry.js +62 -0
- package/dist/run/files.js +51 -0
- package/dist/run/import.js +253 -0
- package/dist/run/lock.js +20 -0
- package/dist/save-help.js +3 -0
- package/dist/schedule/command.js +58 -0
- package/dist/schedule/mail-triage-input.js +152 -0
- package/dist/schedule/task-triage-input.js +152 -0
- package/dist/search/answers.js +176 -0
- package/dist/search/command.js +257 -0
- package/dist/search/denied.js +9 -0
- package/dist/search/embed.js +126 -0
- package/dist/search/hits.js +4 -0
- package/dist/search/lane-gates.js +76 -0
- package/dist/search/notes-text.js +18 -0
- package/dist/search/people.js +88 -0
- package/dist/search/search.js +306 -0
- package/dist/show/command.js +179 -0
- package/dist/store/crm-viewer.js +102 -0
- package/dist/store/group.js +112 -0
- package/dist/store/groups-command.js +136 -0
- package/dist/store/guard.js +94 -0
- package/dist/store/held.js +21 -0
- package/dist/store/info-command.js +37 -0
- package/dist/store/scope.js +53 -0
- package/dist/store/source-list.js +222 -0
- package/dist/store/source-target.js +28 -0
- package/dist/tags/command.js +176 -0
- package/dist/tasks/command.js +174 -0
- package/dist/tasks/context.js +74 -0
- package/dist/tasks/list.js +199 -0
- package/dist/tasks/proposal-duplicates.js +70 -0
- package/dist/tasks/relations-command.js +28 -0
- package/dist/tasks/shared.js +105 -0
- package/dist/tasks/tasks.js +197 -0
- package/dist/templates/command.js +18 -0
- package/dist/terminal.js +23 -0
- package/dist/update.js +35 -0
- package/dist/version.js +2 -0
- package/dist/vocabulary/command.js +103 -0
- package/dist/vocabulary/inspect.js +23 -0
- package/dist/vocabulary/inspection.js +18 -0
- package/dist/vocabulary/list.js +18 -0
- package/dist/vocabulary/project.js +19 -0
- package/dist/wcat.js +3 -0
- package/install/postinstall.mjs +9 -0
- package/package.json +89 -4
- package/scenarios/decision-trail.md +21 -0
- package/scenarios/person-brief.md +35 -0
- package/scenarios/prepare-meeting.md +17 -0
- package/scenarios/project-state.md +26 -0
- package/scenarios/set-up.md +18 -0
- package/scenarios/start-the-day.md +19 -0
- package/skills/mail-triage/SKILL.md +208 -0
- package/skills/morning-digest/SKILL.md +147 -0
- package/skills/task-triage/SKILL.md +79 -0
- package/skills/wcat/SKILL.md +65 -0
- package/skills/wcat/topics/mail.md +32 -0
- package/skills/wcat/topics/mcp.md +22 -0
- package/skills/wcat/topics/meetings.md +37 -0
- package/skills/wcat/topics/money.md +52 -0
- package/skills/wcat/topics/projects.md +54 -0
- package/skills/wcat/topics/proposals.md +113 -0
- package/skills/wcat/topics/search.md +85 -0
- package/skills/wcat/topics/vocabulary.md +8 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate, annotateOption } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { answerEntity, groupLockOf, itemOf, LOCAL_READ, parseReference, projectCutoffTime, projectStatus, projectStatusAnswer, projectStatusRow, projectStatusSchema, projectStatusText, projectWindowOf, purposeList, STATUS_SIGNALS, } from "@wirecat/cli-core";
|
|
4
|
+
import { Option } from "commander";
|
|
5
|
+
import { withStore } from "../answer.js";
|
|
6
|
+
import { APP } from "../app.js";
|
|
7
|
+
import { dealsText, openDealsOf } from "../finance/deals-command.js";
|
|
8
|
+
import { financeOf, financeText } from "../finance/finance.js";
|
|
9
|
+
import { collect } from "../options.js";
|
|
10
|
+
import { groupScopeOf } from "../store/group.js";
|
|
11
|
+
import { chatRead, chatSync, syncProfileOf } from "./messenger-sync.js";
|
|
12
|
+
import { oldPurposeOption, PURPOSES_HELP, purposesAsked } from "./project-gather-command.js";
|
|
13
|
+
const withFinance = (row) => ({
|
|
14
|
+
...row,
|
|
15
|
+
sections: { ...row.sections, finance: "memo_finance", deals: "memo_deal" },
|
|
16
|
+
});
|
|
17
|
+
/** Chat titles the store knows better than the chat list did; one read per answer. */
|
|
18
|
+
const titled = async (store, found) => {
|
|
19
|
+
const summaries = await store.refs.summaries(found.chats.map((chat) => chat.ref));
|
|
20
|
+
return {
|
|
21
|
+
...found,
|
|
22
|
+
chats: found.chats.map((chat) => ({ ...chat, title: summaries.get(chat.ref)?.title ?? chat.title })),
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const linked = (chat) => {
|
|
26
|
+
const reference = parseReference(chat.ref);
|
|
27
|
+
if (reference.type !== "chat")
|
|
28
|
+
throw new Error(`${chat.ref} is not a chat reference`);
|
|
29
|
+
return { provider: reference.provider, account: reference.account, chat: reference.chat };
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The chats to read are in tg, max or wa, which wcat cannot run: a step names the command to type, with the profile
|
|
33
|
+
* signed in to that chat's account, or `<profile>` when there is none or more than one; `blocked` keeps why. It is a
|
|
34
|
+
* command step only while cli-core builds the answer, which keeps `line`; `asAction` hands it out as a user action.
|
|
35
|
+
*/
|
|
36
|
+
const outside = (blocked) => (step, found) => {
|
|
37
|
+
if (!found)
|
|
38
|
+
return null;
|
|
39
|
+
if (found.command === null)
|
|
40
|
+
blocked.add(found.why);
|
|
41
|
+
return {
|
|
42
|
+
kind: "command",
|
|
43
|
+
step,
|
|
44
|
+
command: "projects status",
|
|
45
|
+
args: {},
|
|
46
|
+
line: found.command ?? found.line,
|
|
47
|
+
why: "",
|
|
48
|
+
safe_to_auto_execute: true,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const asAction = (step) => step.kind === "command"
|
|
52
|
+
? { kind: "user_action", step: step.step, why: `${step.why}: ${step.line}`, safe_to_auto_execute: false }
|
|
53
|
+
: step;
|
|
54
|
+
export const projectStatusCommand = (projects, print, env) => answerEntity(annotate(projects.command("status"), { effects: LOCAL_READ, partial: true }), "project_status", projectStatusSchema, { row: withFinance(projectStatusRow(STATUS_SIGNALS)) })
|
|
55
|
+
.description("where a project stands, from the stored messages of every chat confirmed as the project's or its child " +
|
|
56
|
+
"projects', in every account those links name (meta.accounts lists them): the last message, who replies " +
|
|
57
|
+
"next, open questions both ways, promises, amounts found by words with their direction (only when the project " +
|
|
58
|
+
"has no confirmed invoice or payment), payments recorded, billed, paid and " +
|
|
59
|
+
"owed per currency from confirmed invoices and payments (finance), up to five open deals (deals), how long each " +
|
|
60
|
+
"--context-query has been quiet on their side, and how much of each chat is held. Amounts, directions and " +
|
|
61
|
+
"promises found by words are marked pattern: read the cited message before trusting one. Others' questions " +
|
|
62
|
+
"in a group with no role, and others' word-found promises in a group, are counted on the chat's row as " +
|
|
63
|
+
"unlisted, not listed. next names at most " +
|
|
64
|
+
"two chats to read, with the messenger command that reads them. No model call; nothing leaves this machine")
|
|
65
|
+
.summary("where a project stands: whose move, open asks, money, chats to read next")
|
|
66
|
+
.argument("<project>", "an existing project's id, project:<id>, key, exact name or alias")
|
|
67
|
+
.option("--since-time <time>", "how far back: days (60d, at most 730d) or a start date (2026-09-01)", "60d")
|
|
68
|
+
.option("--before-time <time>", "fixed exclusive end: ISO 8601 timestamp with UTC offset; days back count from it")
|
|
69
|
+
.option("--context-query <words>", "words that all appear in one text; reports their last mention per side. Repeat for another", collect, [])
|
|
70
|
+
.option("--sync-profile <tool=profile>", "the messenger profile the next steps name when several are signed in to a chat's account, such as " +
|
|
71
|
+
"max=default; repeat for another tool", syncProfileOf)
|
|
72
|
+
.option("--purposes <purposes>", PURPOSES_HELP, purposeList)
|
|
73
|
+
.addOption(oldPurposeOption())
|
|
74
|
+
.addOption(annotateOption(new Option("--compact", "one line per signal, chat and next step, for an agent"), { mcp: false }))
|
|
75
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
76
|
+
.action(async (project, options) => {
|
|
77
|
+
if (options.compact && options.json)
|
|
78
|
+
throw new CliError("validation_error", "--compact and --json ask for different output — pick one", {
|
|
79
|
+
reason: "output.conflict",
|
|
80
|
+
param: "--compact",
|
|
81
|
+
});
|
|
82
|
+
const chosen = options.syncProfile ?? {};
|
|
83
|
+
const { found, finance, open } = await withStore(env, async (store) => {
|
|
84
|
+
const scope = await groupScopeOf(store, env);
|
|
85
|
+
const status = await projectStatus(store, {
|
|
86
|
+
project,
|
|
87
|
+
...(scope === undefined ? {} : { accounts: scope.accounts }),
|
|
88
|
+
...projectWindowOf(options.sinceTime),
|
|
89
|
+
...(options.beforeTime === undefined ? {} : { asOf: projectCutoffTime(options.beforeTime) }),
|
|
90
|
+
contextQueries: options.contextQuery,
|
|
91
|
+
...purposesAsked(options),
|
|
92
|
+
});
|
|
93
|
+
const projects = [status.project.ref, ...status.children.map((child) => child.ref)];
|
|
94
|
+
const books = await financeOf(store, projects);
|
|
95
|
+
return { found: await titled(store, status), finance: books, open: await openDealsOf(store, projects) };
|
|
96
|
+
});
|
|
97
|
+
const blocked = new Set();
|
|
98
|
+
const step = outside(blocked);
|
|
99
|
+
const hints = {
|
|
100
|
+
sync: (chat, since) => step("messages.sync", chatSync(linked(chat), since, env, chosen)),
|
|
101
|
+
read: (chat, since) => step("messages.list", chatRead(linked(chat), since, env, chosen)),
|
|
102
|
+
line: (one) => (one.kind === "command" ? (one.line ?? one.command) : one.why),
|
|
103
|
+
};
|
|
104
|
+
// Under the lock an outside chat's ref would tell the agent that account and chat exist: only a count is said.
|
|
105
|
+
const lock = groupLockOf(APP, env);
|
|
106
|
+
const hidden = lock === undefined ? [] : found.outOfScope.filter(({ reason }) => reason === "other-account");
|
|
107
|
+
const shown = hidden.length
|
|
108
|
+
? { ...found, outOfScope: found.outOfScope.filter((one) => !hidden.includes(one)) }
|
|
109
|
+
: found;
|
|
110
|
+
const { item, next, missing, meta } = projectStatusAnswer(shown, hints);
|
|
111
|
+
const gaps = [
|
|
112
|
+
...missing,
|
|
113
|
+
...(hidden.length
|
|
114
|
+
? [{ field: "out_of_scope", why: `${hidden.length} of the project's chats are outside group ${lock}` }]
|
|
115
|
+
: []),
|
|
116
|
+
...(blocked.size ? [{ field: "next_command", why: [...blocked].join("; ") }] : []),
|
|
117
|
+
];
|
|
118
|
+
print(options.json, itemOf({
|
|
119
|
+
...item,
|
|
120
|
+
...(finance.length ? { finance } : {}),
|
|
121
|
+
...(open.deals.length ? { deals: open.deals } : {}),
|
|
122
|
+
...(open.more ? { deals_more: open.more } : {}),
|
|
123
|
+
}, {
|
|
124
|
+
...(next.length ? { next: next.map(asAction) } : {}),
|
|
125
|
+
...(gaps.length ? { missing: gaps } : {}),
|
|
126
|
+
meta,
|
|
127
|
+
}), [projectStatusText(shown, hints), ...financeText(finance), ...dealsText(open)].join("\n"), options.compact === true);
|
|
128
|
+
});
|
|
129
|
+
//# sourceMappingURL=project-status-command.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { LOCAL_READ, LOCAL_WRITE } from "@wirecat/cli-core";
|
|
3
|
+
import { answers, itemAnswer } from "../answer.js";
|
|
4
|
+
import { positive } from "../options.js";
|
|
5
|
+
import { annotationInputs, assertAnnotationRestoreOwner, exportAnnotations, previewAnnotations, restoreAnnotations, snapshotAnnotations, } from "./project-transfer.js";
|
|
6
|
+
export const projectTransferCommand = (projects, streams, env) => {
|
|
7
|
+
const group = projects
|
|
8
|
+
.command("annotations")
|
|
9
|
+
.description("selected project aliases, facts and generic links; not a full backup");
|
|
10
|
+
const { print } = answers(projects, streams, env);
|
|
11
|
+
annotate(group.command("show"), { effects: LOCAL_READ, output: { entity: "project_annotation_snapshot" } })
|
|
12
|
+
.description("read selected project annotations without creating a file; not a full backup")
|
|
13
|
+
.argument("<project>", "the project's id, key, exact name or alias")
|
|
14
|
+
.option("--max-read-bytes <bytes>", "source input byte budget, at most 4194304", positive)
|
|
15
|
+
.option("--json", "print the standard JSON answer")
|
|
16
|
+
.action(async (project, options) => print(options.json, itemAnswer(await snapshotAnnotations(env, project, options.maxReadBytes))));
|
|
17
|
+
annotate(group.command("export"), { effects: LOCAL_WRITE, output: { entity: "project_annotation_export" } })
|
|
18
|
+
.description("write selected annotations to a new private file, omitting source bodies")
|
|
19
|
+
.argument("<project>", "the project's id, key, exact name or alias")
|
|
20
|
+
.requiredOption("--output <file>", "new snapshot file; parent folder must exist and existing paths are refused")
|
|
21
|
+
.option("--max-read-bytes <bytes>", "source input byte budget, at most 4194304", positive)
|
|
22
|
+
.option("--json", "print JSON; --json=project,counts keeps only those fields")
|
|
23
|
+
.action(async (project, options) => print(options.json, itemAnswer(await exportAnnotations(env, project, options.output ?? "", options.maxReadBytes))));
|
|
24
|
+
for (const name of ["check", "restore"]) {
|
|
25
|
+
const command = annotate(group.command(name), {
|
|
26
|
+
effects: name === "check" ? LOCAL_READ : LOCAL_WRITE,
|
|
27
|
+
output: { entity: "project_annotation_transfer" },
|
|
28
|
+
})
|
|
29
|
+
.description(name === "check"
|
|
30
|
+
? "check bindings and conflicts in an existing target without restoring"
|
|
31
|
+
: "owner: restore selected annotations with the exact successful check fingerprint")
|
|
32
|
+
.argument("<file>", "version2 snapshot JSON file, at most 4194304 UTF-8 bytes")
|
|
33
|
+
.requiredOption("--target-store <file>", "explicit existing destination store; never created by preview")
|
|
34
|
+
.requiredOption("--project <project>", "explicit destination project:<id>; its key and name must match the snapshot")
|
|
35
|
+
.requiredOption("--bindings <file>", "JSON object mapping every external source reference and the project to explicit target references")
|
|
36
|
+
.option("--max-read-bytes <bytes>", "destination input byte budget, at most 4194304", positive)
|
|
37
|
+
.option("--json", name === "check"
|
|
38
|
+
? "print JSON; --json=ready,fingerprint keeps only those fields"
|
|
39
|
+
: "print JSON; --json=project,counts keeps only those fields");
|
|
40
|
+
if (name === "restore")
|
|
41
|
+
command.requiredOption("--fingerprint <hash>", "exact fingerprint returned by the successful target preview");
|
|
42
|
+
command.action(async (file, options) => {
|
|
43
|
+
if (name === "restore")
|
|
44
|
+
assertAnnotationRestoreOwner(env);
|
|
45
|
+
const input = {
|
|
46
|
+
...(await annotationInputs(file, options.bindings)),
|
|
47
|
+
target: options.targetStore,
|
|
48
|
+
project: options.project,
|
|
49
|
+
...(options.maxReadBytes === undefined ? {} : { maxReadBytes: options.maxReadBytes }),
|
|
50
|
+
};
|
|
51
|
+
const result = name === "check"
|
|
52
|
+
? await previewAnnotations(env, input)
|
|
53
|
+
: await restoreAnnotations(env, { ...input, fingerprint: options.fingerprint });
|
|
54
|
+
print(options.json, itemAnswer(result));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=project-transfer-command.js.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { lstat } from "node:fs/promises";
|
|
2
|
+
import { CliError } from "@wirecat/cli-base";
|
|
3
|
+
import { decodeProjectAnnotationSnapshot, openStore, PROJECT_ANNOTATIONS_MAX_BYTES, previewProjectAnnotationSnapshot, readBoundedUtf8File, snapshotProjectAnnotations, storePath, writeFileAtomic, } from "@wirecat/cli-core";
|
|
4
|
+
import * as v from "valibot";
|
|
5
|
+
import { authorOf } from "../author.js";
|
|
6
|
+
import { mcpOwnerAllowed } from "../mcp/permissions.js";
|
|
7
|
+
import { canonicalProject } from "../vocabulary/project.js";
|
|
8
|
+
export const snapshotAnnotations = async (env, project, maxReadBytes) => {
|
|
9
|
+
const source = storePath(env);
|
|
10
|
+
let reference = /^[1-9]\d*$/.test(project) ? `project:${project}` : project;
|
|
11
|
+
if (!reference.startsWith("project:")) {
|
|
12
|
+
const store = await openStore({ path: source, env, readOnly: true });
|
|
13
|
+
try {
|
|
14
|
+
reference = await canonicalProject(store, project, {
|
|
15
|
+
maxEntries: 1000,
|
|
16
|
+
maxReadBytes: Math.min(maxReadBytes ?? PROJECT_ANNOTATIONS_MAX_BYTES, PROJECT_ANNOTATIONS_MAX_BYTES),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
await store.close();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return snapshotProjectAnnotations({
|
|
24
|
+
source,
|
|
25
|
+
project: reference,
|
|
26
|
+
env,
|
|
27
|
+
...(maxReadBytes === undefined ? {} : { maxReadBytes }),
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
export const exportAnnotations = async (env, project, output, maxReadBytes) => {
|
|
31
|
+
try {
|
|
32
|
+
await lstat(output);
|
|
33
|
+
throw new CliError("validation_error", "snapshot output already exists; choose another path");
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (!(typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT"))
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
const result = await snapshotAnnotations(env, project, maxReadBytes);
|
|
40
|
+
try {
|
|
41
|
+
await writeFileAtomic(output, JSON.stringify(result.snapshot), { overwrite: false });
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "EEXIST")
|
|
45
|
+
throw new CliError("validation_error", "snapshot output already exists; choose another path");
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
output_file: output,
|
|
50
|
+
project: result.snapshot.project.ref,
|
|
51
|
+
manifest_fingerprint: result.fingerprint,
|
|
52
|
+
coverage: result.snapshot.coverage,
|
|
53
|
+
counts: {
|
|
54
|
+
aliases: result.snapshot.aliases.length,
|
|
55
|
+
facts: result.snapshot.facts.length,
|
|
56
|
+
links: result.snapshot.links.length,
|
|
57
|
+
},
|
|
58
|
+
read_bytes: result.read_bytes,
|
|
59
|
+
records: result.records,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export const annotationInputs = async (snapshotFile, bindingsFile) => {
|
|
63
|
+
const snapshot = await readBoundedUtf8File(snapshotFile, { maxBytes: PROJECT_ANNOTATIONS_MAX_BYTES });
|
|
64
|
+
decodeProjectAnnotationSnapshot(snapshot);
|
|
65
|
+
let bindings;
|
|
66
|
+
try {
|
|
67
|
+
bindings = JSON.parse(await readBoundedUtf8File(bindingsFile, { maxBytes: PROJECT_ANNOTATIONS_MAX_BYTES }));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (error instanceof SyntaxError)
|
|
71
|
+
throw new CliError("validation_error", "bindings file must contain a JSON object");
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
const checked = v.safeParse(v.record(v.string(), v.string()), bindings);
|
|
75
|
+
if (!checked.success)
|
|
76
|
+
throw new CliError("validation_error", "bindings must map source references to target reference strings");
|
|
77
|
+
return { snapshot, bindings: checked.output };
|
|
78
|
+
};
|
|
79
|
+
export const previewAnnotations = (env, input) => previewProjectAnnotationSnapshot({ ...input, env });
|
|
80
|
+
export const assertAnnotationRestoreOwner = (env) => {
|
|
81
|
+
if (authorOf(env) !== "owner" && !mcpOwnerAllowed(env, "projects.annotations.restore"))
|
|
82
|
+
throw new CliError("permission_error", "project annotation restore belongs to the owner; agents may export and preview");
|
|
83
|
+
};
|
|
84
|
+
export const restoreAnnotations = async (env, input) => {
|
|
85
|
+
assertAnnotationRestoreOwner(env);
|
|
86
|
+
const { fingerprint, ...options } = input;
|
|
87
|
+
const preview = await previewAnnotations(env, options);
|
|
88
|
+
if (!preview.ready || preview.fingerprint !== fingerprint)
|
|
89
|
+
throw new CliError("validation_error", "project annotation preview is stale or has conflicts; preview again");
|
|
90
|
+
const store = await openStore({ path: options.target, env });
|
|
91
|
+
try {
|
|
92
|
+
if (!store.projectAnnotations)
|
|
93
|
+
throw new CliError("configuration_error", "project annotation restore is unavailable");
|
|
94
|
+
const result = await store.projectAnnotations.restore({
|
|
95
|
+
snapshot: options.snapshot,
|
|
96
|
+
project: options.project,
|
|
97
|
+
bindings: options.bindings,
|
|
98
|
+
fingerprint,
|
|
99
|
+
...(options.maxReadBytes === undefined ? {} : { maxReadBytes: options.maxReadBytes }),
|
|
100
|
+
});
|
|
101
|
+
return { ...result, mappings: Object.entries(result.mappings).map(([source, target]) => ({ source, target })) };
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
await store.close();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=project-transfer.js.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { stepOf } from "@wirecat/cli-base/standards";
|
|
4
|
+
import { LOCAL_WRITE, projectWindowOf, scanProjectLinks, } from "@wirecat/cli-core";
|
|
5
|
+
import { itemAnswer, withStore } from "../answer.js";
|
|
6
|
+
import { positive } from "../options.js";
|
|
7
|
+
import { labelsFor } from "../review/review.js";
|
|
8
|
+
import { ACCOUNTS_HELP, accountName, namedAccounts } from "../store/source-list.js";
|
|
9
|
+
import { projectOf } from "./key-documents.js";
|
|
10
|
+
const DAY = 86_400_000;
|
|
11
|
+
const SCAN_STEP = {
|
|
12
|
+
id: "relationships.scan",
|
|
13
|
+
kind: "command",
|
|
14
|
+
command: "relationships scan",
|
|
15
|
+
args: [
|
|
16
|
+
{ name: "project", required: true },
|
|
17
|
+
{ name: "source", required: true },
|
|
18
|
+
],
|
|
19
|
+
why: "{count} confirmed chats: a scan lists the chats and people that look like the project's; --yes proposes them",
|
|
20
|
+
};
|
|
21
|
+
const confirmedChats = async (store, ref) => (await store.knowledge.relations(null, ref)).filter((one) => one.confirmed && one.kind === "member-of" && one.to === ref && one.from.startsWith("chat:")).length;
|
|
22
|
+
/** Offered while a project has fewer than two confirmed chats: below that its evidence reads mostly by name. */
|
|
23
|
+
export const scanStep = async (store, project, source) => {
|
|
24
|
+
const count = await confirmedChats(store, project.ref);
|
|
25
|
+
return count >= 2 ? [] : [stepOf(SCAN_STEP, { args: { project: project.key, source }, values: { count } })];
|
|
26
|
+
};
|
|
27
|
+
const projectsOf = async (store, reference) => {
|
|
28
|
+
if (reference === undefined)
|
|
29
|
+
return [null];
|
|
30
|
+
if (reference === "all")
|
|
31
|
+
return (await store.knowledge.projects()).map((one) => one.ref);
|
|
32
|
+
return [(await projectOf(store, reference)).ref];
|
|
33
|
+
};
|
|
34
|
+
/** The chats two or more proposed people write in, for `review list via:<chat>` to decide them together. */
|
|
35
|
+
const groupsOf = (proposals, label) => {
|
|
36
|
+
const people = new Map();
|
|
37
|
+
for (const one of proposals) {
|
|
38
|
+
const chat = one.evidence[0];
|
|
39
|
+
if (!one.from.startsWith("person:") || !chat?.startsWith("chat:"))
|
|
40
|
+
continue;
|
|
41
|
+
if (!one.signals.some((signal) => signal.scorer.startsWith("chat-senders@")))
|
|
42
|
+
continue;
|
|
43
|
+
people.set(chat, (people.get(chat) ?? 0) + 1);
|
|
44
|
+
}
|
|
45
|
+
return [...people]
|
|
46
|
+
.filter(([, count]) => count >= 2)
|
|
47
|
+
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
48
|
+
.map(([chat, count]) => ({ chat, title: label(chat), people: count, review: `wcat review list via:${chat}` }));
|
|
49
|
+
};
|
|
50
|
+
const scanned = async (store, scans, written) => {
|
|
51
|
+
const label = await labelsFor(store, scans.flatMap((scan) => [
|
|
52
|
+
scan.project,
|
|
53
|
+
...scan.proposals.flatMap((one) => [one.from, one.to, one.evidence[0] ?? null]),
|
|
54
|
+
]));
|
|
55
|
+
return {
|
|
56
|
+
written,
|
|
57
|
+
scans: scans.map((scan) => ({
|
|
58
|
+
project: scan.project,
|
|
59
|
+
title: label(scan.project),
|
|
60
|
+
proposals: scan.proposals.map((one) => ({
|
|
61
|
+
id: one.id,
|
|
62
|
+
state: one.state,
|
|
63
|
+
from: one.from,
|
|
64
|
+
to: one.to,
|
|
65
|
+
kind: one.kind,
|
|
66
|
+
title: `${label(one.from) ?? one.from} → ${label(one.to) ?? one.to}`,
|
|
67
|
+
score: one.score,
|
|
68
|
+
...(one.purpose ? { purpose: one.purpose } : {}),
|
|
69
|
+
signals: one.signals,
|
|
70
|
+
evidence: one.evidence,
|
|
71
|
+
})),
|
|
72
|
+
groups: written ? groupsOf(scan.proposals, label) : [],
|
|
73
|
+
skipped: scan.skipped,
|
|
74
|
+
})),
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
const scanText = ({ written, scans }) => [
|
|
78
|
+
written ? "Proposed for your review (wcat review):" : "Nothing written; --yes proposes these for your review:",
|
|
79
|
+
...scans.flatMap(({ project, title, proposals, groups, skipped }) => [
|
|
80
|
+
`${title ?? project ?? "people by shared mail domain"}: ${proposals.length} to propose; skipped ` +
|
|
81
|
+
`${skipped.confirmed} linked, ${skipped.rejected} rejected, ${skipped.belowThreshold} weak, ` +
|
|
82
|
+
`${skipped.overLimit} over the limit`,
|
|
83
|
+
...proposals.map((one) => ` ${one.score.toFixed(2)} ${one.title}${one.id === null ? "" : ` ${one.id}`} ${one.state}`),
|
|
84
|
+
...groups.map((one) => ` ${one.people} senders of ${one.title ?? one.chat}, to decide together: ${one.review}`),
|
|
85
|
+
]),
|
|
86
|
+
].join("\n");
|
|
87
|
+
export const relationshipsScanCommand = (relations, print, env, warn) => annotate(relations.command("scan"), { effects: LOCAL_WRITE })
|
|
88
|
+
.description("chats, mail threads and people that look like a project's, scored from the store: its name and aliases in " +
|
|
89
|
+
"titles and messages, the chats and threads of its members in every messenger, spreading from what it finds. " +
|
|
90
|
+
"With no project, people who share a company mail domain. Lists them and writes nothing; --yes writes them " +
|
|
91
|
+
"as proposals by wcat-scan for you to decide in wcat review. Never confirms, and never proposes again what " +
|
|
92
|
+
"you rejected")
|
|
93
|
+
.summary("propose chats and people for a project; nothing is written without --yes")
|
|
94
|
+
.argument("[project]", "a project's id, key, exact name or alias, or all; left out, people by mail domain")
|
|
95
|
+
.option("--source <accounts>", `where to look, or all: ${ACCOUNTS_HELP}`)
|
|
96
|
+
.option("--since-time <time>", "how far back messages count: days (90d, at most 730d) or a date", "90d")
|
|
97
|
+
.option("--limit <n>", "new proposals per project at most, up to 50", positive, 20)
|
|
98
|
+
.option("--yes", "write the proposals; without it nothing is written")
|
|
99
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
100
|
+
.action(async (project, options) => {
|
|
101
|
+
if (options.limit > 50)
|
|
102
|
+
throw new CliError("validation_error", "--limit is at most 50", { param: "limit" });
|
|
103
|
+
const window = projectWindowOf(options.sinceTime);
|
|
104
|
+
const since = new Date("days" in window ? Date.now() - window.days * DAY : window.after).toISOString();
|
|
105
|
+
const written = options.yes === true;
|
|
106
|
+
const { body, text } = await withStore(env, async (store) => {
|
|
107
|
+
const sources = await namedAccounts(store, env, options, warn);
|
|
108
|
+
const scans = [];
|
|
109
|
+
for (const one of await projectsOf(store, project))
|
|
110
|
+
scans.push(await scanProjectLinks(store, { project: one, sources, since, write: written, limit: options.limit }));
|
|
111
|
+
const answer = await scanned(store, scans, written);
|
|
112
|
+
return { body: itemAnswer(answer, { meta: { accounts: sources.map(accountName) } }), text: scanText(answer) };
|
|
113
|
+
});
|
|
114
|
+
print(options.json, body, text);
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=relationships-scan.js.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { byEngagement, queryTerms, RELATION_KINDS, STANDINGS, termField, } from "@wirecat/cli-core";
|
|
3
|
+
import { labelsFor, proposerName } from "../review/review.js";
|
|
4
|
+
import { crmViewersAll } from "../store/crm-viewer.js";
|
|
5
|
+
import { guardOf } from "../store/guard.js";
|
|
6
|
+
import { documentContext } from "./document-context.js";
|
|
7
|
+
export const RELATIONSHIP_QUERY = {
|
|
8
|
+
entity: "relationship",
|
|
9
|
+
backend: "native",
|
|
10
|
+
fields: [
|
|
11
|
+
termField("about", "ref", 'about:"person:5"', {
|
|
12
|
+
relation: "the person, organization, project, deal or lead at either end; each row says its direction",
|
|
13
|
+
}),
|
|
14
|
+
termField("from", "ref", 'from:"person:5"', { relation: "the end that belongs, reports or relates" }),
|
|
15
|
+
termField("to", "ref", 'to:"person:5"', { relation: "the end it belongs, reports or relates to" }),
|
|
16
|
+
termField("kind", "enum", "kind:reports-to", { values: RELATION_KINDS }),
|
|
17
|
+
termField("role", "kw", "role:decision-maker"),
|
|
18
|
+
termField("standing", "enum", "standing:reported", { values: STANDINGS }),
|
|
19
|
+
termField("confirmed", "enum", "confirmed:false", { values: ["true", "false"] }),
|
|
20
|
+
termField("at", "kw", "at:2026-10-01", { relation: "held at the start of that UTC day" }),
|
|
21
|
+
termField("include", "enum", "include:ended", { values: ["ended"] }),
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
const DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
25
|
+
/** `at:2026-10-01`: held at the start of that UTC day. */
|
|
26
|
+
const atOf = (day) => {
|
|
27
|
+
const at = Date.parse(`${day}T00:00:00Z`);
|
|
28
|
+
if (!DAY.test(day) || Number.isNaN(at))
|
|
29
|
+
throw new CliError("validation_error", `at: takes a day, such as at:2026-10-01 — not "${day}"`, {
|
|
30
|
+
reason: "input.invalid",
|
|
31
|
+
});
|
|
32
|
+
return at;
|
|
33
|
+
};
|
|
34
|
+
/** `relationships list`: cli-core filters and pages the links and the pending proposals together. */
|
|
35
|
+
export const listRelationships = async (store, env, words, { limit, page, accounts, deniedKinds } = { limit: 100, page: 1 }) => {
|
|
36
|
+
const terms = queryTerms(words, RELATIONSHIP_QUERY, "relationships list");
|
|
37
|
+
const confirmed = terms.get("confirmed");
|
|
38
|
+
const standing = (terms.get("standing") ??
|
|
39
|
+
(confirmed === "false" ? "proposed" : confirmed === "true" ? "confirmed" : undefined));
|
|
40
|
+
const at = terms.get("at");
|
|
41
|
+
const found = await store.knowledge.listRelations({
|
|
42
|
+
...(terms.has("kind") ? { kind: terms.get("kind") } : {}),
|
|
43
|
+
...(terms.has("role") ? { role: terms.get("role") } : {}),
|
|
44
|
+
...(terms.has("from") ? { from: terms.get("from") } : {}),
|
|
45
|
+
...(terms.has("to") ? { to: terms.get("to") } : {}),
|
|
46
|
+
...(terms.has("about") ? { about: terms.get("about") } : {}),
|
|
47
|
+
...(standing === undefined ? {} : { standing }),
|
|
48
|
+
...(at === undefined ? {} : { at: atOf(at) }),
|
|
49
|
+
...(terms.get("include") === "ended" ? { includeEnded: true } : {}),
|
|
50
|
+
...(accounts === undefined ? {} : { accounts }),
|
|
51
|
+
...(deniedKinds?.length ? { deniedKinds } : {}),
|
|
52
|
+
viewers: await crmViewersAll(store),
|
|
53
|
+
limit,
|
|
54
|
+
page,
|
|
55
|
+
});
|
|
56
|
+
// Under the lock a row whose end the group cannot show, a person only an outside account saw, is left out.
|
|
57
|
+
const guard = await guardOf(store, env);
|
|
58
|
+
const rows = [];
|
|
59
|
+
for (const one of found.items)
|
|
60
|
+
if (guard === undefined || ((await guard.visible(one.from)) && (await guard.visible(one.to))))
|
|
61
|
+
rows.push(one);
|
|
62
|
+
const label = await labelsFor(store, rows.flatMap((one) => [one.from, one.to]));
|
|
63
|
+
const documents = new Map();
|
|
64
|
+
const documentOf = (ref) => {
|
|
65
|
+
if (!ref.startsWith("document:"))
|
|
66
|
+
return undefined;
|
|
67
|
+
if (!documents.has(ref))
|
|
68
|
+
documents.set(ref, documentContext(store, ref));
|
|
69
|
+
return documents.get(ref);
|
|
70
|
+
};
|
|
71
|
+
const ends = async (one) => {
|
|
72
|
+
const [from, to] = await Promise.all([documentOf(one.from), documentOf(one.to)]);
|
|
73
|
+
return { ...(from === undefined ? {} : { fromDocument: from }), ...(to === undefined ? {} : { toDocument: to }) };
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
hasMore: found.hasMore,
|
|
77
|
+
limit,
|
|
78
|
+
page,
|
|
79
|
+
items: await Promise.all(byEngagement(rows).map(async (one) => ({
|
|
80
|
+
...one,
|
|
81
|
+
status: one.standing,
|
|
82
|
+
// Who proposed it is the review's to name; the list says it beside the proposal.
|
|
83
|
+
...(one.source === "proposal"
|
|
84
|
+
? { proposer: proposerName((await store.proposedActions.get(one.id)).proposedBy) }
|
|
85
|
+
: {}),
|
|
86
|
+
fromTitle: label(one.from),
|
|
87
|
+
toTitle: label(one.to),
|
|
88
|
+
...(await ends(one)),
|
|
89
|
+
}))),
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export const relationshipsText = (items) => items.length
|
|
93
|
+
? items
|
|
94
|
+
.map((one) => [
|
|
95
|
+
one.id,
|
|
96
|
+
`${one.fromTitle} → ${one.toTitle}`,
|
|
97
|
+
[
|
|
98
|
+
one.direction === "incoming" ? (one.inverse ?? one.kind) : one.kind,
|
|
99
|
+
one.role && `as ${one.role}${one.custom ? " (custom)" : ""}`,
|
|
100
|
+
"roleNote" in one && one.roleNote && `(${one.roleNote})`,
|
|
101
|
+
one.position && `(${one.position})`,
|
|
102
|
+
one.purpose && `for ${one.purpose}`,
|
|
103
|
+
"engagement" in one && one.engagement && `engagement ${one.engagement}`,
|
|
104
|
+
]
|
|
105
|
+
.filter(Boolean)
|
|
106
|
+
.join(" "),
|
|
107
|
+
"proposer" in one
|
|
108
|
+
? `proposed by ${one.proposer}`
|
|
109
|
+
: [one.standing, one.account && `by ${one.account}`].filter(Boolean).join(" "),
|
|
110
|
+
]
|
|
111
|
+
.filter(Boolean)
|
|
112
|
+
.join(" "))
|
|
113
|
+
.join("\n")
|
|
114
|
+
: "no relationships";
|
|
115
|
+
//# sourceMappingURL=relationships.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { LOCAL_READ, LOCAL_WRITE, queryTerms, ROLE_LISTS, termField, withQuery } from "@wirecat/cli-core";
|
|
4
|
+
import { listAnswer, withStore } from "../answer.js";
|
|
5
|
+
import { byOption, whoRuns } from "../author.js";
|
|
6
|
+
import { oneOf } from "../options.js";
|
|
7
|
+
const LISTS = Object.keys(ROLE_LISTS);
|
|
8
|
+
/** wcat's own entity: one role of one list. */
|
|
9
|
+
const ROLES_QUERY = {
|
|
10
|
+
entity: "relationship_role",
|
|
11
|
+
backend: "native",
|
|
12
|
+
fields: [termField("list", "enum", "list:organization", { values: LISTS })],
|
|
13
|
+
};
|
|
14
|
+
const LIST_HELP = "organization (roles in an organization), project, deal (a deal's or a lead's), contract (a party's) or related " +
|
|
15
|
+
"(what a person or an organization is to another)";
|
|
16
|
+
/** Role lists are the owner's settings, as the permissions are: an agent reads them and changes none. */
|
|
17
|
+
const ownerOnly = async (command, env, asOwner, question) => {
|
|
18
|
+
if ((await whoRuns(command, env, { asOwner, question })) !== "owner")
|
|
19
|
+
throw new CliError("permission_error", "only the owner changes the role lists; an agent uses the roles they hold", {
|
|
20
|
+
reason: "roles.owner-only",
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* `wcat relationships roles …`: which roles a relationship may take, built in and the owner's own (NEED-2405).
|
|
25
|
+
* cli-core keeps the lists and refuses a built-in's removal and an owner role still in use.
|
|
26
|
+
*/
|
|
27
|
+
export const relationshipRolesCommand = (relations, { print }, env) => {
|
|
28
|
+
const roles = relations.command("roles").description("the roles a relationship may take: built in and your own");
|
|
29
|
+
const rows = async (lists) => withStore(env, async (store) => (await Promise.all(lists.map(async (list) => (await store.knowledge.roles(list)).map((one) => ({ list, ...one }))))).flat());
|
|
30
|
+
const show = async (json, command, lists) => {
|
|
31
|
+
const items = await rows(lists);
|
|
32
|
+
print(json, listAnswer(command, { items, limit: Math.max(1, items.length), has_more: false }), items
|
|
33
|
+
.map(({ list, id, label, labels, builtIn }) => `${list} ${id}${(label ?? labels?.en) ? ` ${label ?? labels?.en}` : ""}${builtIn ? "" : " (yours)"}`)
|
|
34
|
+
.join("\n"));
|
|
35
|
+
};
|
|
36
|
+
withQuery(annotate(roles.command("list"), { effects: LOCAL_READ, output: { entity: "relationship_role" } }), ROLES_QUERY)
|
|
37
|
+
.description("the roles of every list, or of one with list:<name>; each built in (with labels in English, Russian and " +
|
|
38
|
+
"Spanish) or yours")
|
|
39
|
+
.summary("the roles a relationship may take")
|
|
40
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
41
|
+
.action((words, options) => {
|
|
42
|
+
const list = queryTerms(words, ROLES_QUERY, "relationships roles list").get("list");
|
|
43
|
+
return show(options.json, "relationships roles list", list === undefined ? LISTS : [list]);
|
|
44
|
+
});
|
|
45
|
+
byOption(annotate(roles.command("add"), { effects: LOCAL_WRITE, output: { entity: "relationship_role" } })
|
|
46
|
+
.description("add a role of your own to a list; relationships may then take it. Only you change the lists")
|
|
47
|
+
.summary("add a role of your own")
|
|
48
|
+
.argument("<list>", LIST_HELP, oneOf(LISTS))
|
|
49
|
+
.argument("<role>", "the role's id: lowercase letters, digits and -, such as board-member")
|
|
50
|
+
.option("--label <label>", "how it reads, such as 'Board member'")
|
|
51
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")).action(async (list, role, options, command) => {
|
|
52
|
+
await ownerOnly(command, env, options.asOwner, `add the ${list} role ${role} as you?`);
|
|
53
|
+
await withStore(env, (store) => store.knowledge.addRole(list, role, options.label));
|
|
54
|
+
await show(options.json, "relationships roles add", [list]);
|
|
55
|
+
});
|
|
56
|
+
byOption(annotate(roles.command("remove"), { effects: LOCAL_WRITE, output: { entity: "relationship_role" } })
|
|
57
|
+
.description("remove a role of your own; a built-in one stays, and one a relationship still holds is refused")
|
|
58
|
+
.summary("remove a role of your own")
|
|
59
|
+
.argument("<list>", LIST_HELP, oneOf(LISTS))
|
|
60
|
+
.argument("<role>", "the role's id")
|
|
61
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")).action(async (list, role, options, command) => {
|
|
62
|
+
await ownerOnly(command, env, options.asOwner, `remove the ${list} role ${role} as you?`);
|
|
63
|
+
await withStore(env, (store) => store.knowledge.removeRole(list, role));
|
|
64
|
+
await show(options.json, "relationships roles remove", [list]);
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=roles-command.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { mailFindingsCommand } from "./findings-command.js";
|
|
2
|
+
import { mailReviewCommands } from "./review-command.js";
|
|
3
|
+
import { mailSubscriptionsCommand } from "./subscriptions-command.js";
|
|
4
|
+
/**
|
|
5
|
+
* `review mail`, `review findings` and `review subscriptions`: the `mail` word is the mail CLI's in `wcat`, so wcat's
|
|
6
|
+
* mail reads sit in review.
|
|
7
|
+
*/
|
|
8
|
+
export const reviewMailCommands = (program, streams, env) => {
|
|
9
|
+
const named = (name) => {
|
|
10
|
+
const found = program.commands.find((command) => command.name() === name);
|
|
11
|
+
if (!found)
|
|
12
|
+
throw new Error(`wcat ${name} is mounted before wcat review mail`);
|
|
13
|
+
return found;
|
|
14
|
+
};
|
|
15
|
+
const review = named("review");
|
|
16
|
+
mailFindingsCommand(program, review, streams, env);
|
|
17
|
+
mailReviewCommands(review, named("messages"), env);
|
|
18
|
+
mailSubscriptionsCommand(review, program, streams, env);
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=command.js.map
|