@wirecat/wirecat 0.0.0-stage → 1.1.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 +399 -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-O24ISPOI.js +43 -0
- package/dist/bundle/chunk-2A3YPENI.js +31 -0
- package/dist/bundle/chunk-6BDIFKF5.js +222 -0
- package/dist/bundle/chunk-7O7XM37N.js +2 -0
- package/dist/bundle/chunk-AYHZY24E.js +120 -0
- package/dist/bundle/chunk-CKBTMZUX.js +72 -0
- package/dist/bundle/chunk-FGXUH3XL.js +416 -0
- package/dist/bundle/chunk-I5JQBRRC.js +807 -0
- package/dist/bundle/chunk-RKVAWMZT.js +38 -0
- package/dist/bundle/chunk-SCDNOUUR.js +395 -0
- package/dist/bundle/chunk-T7TG4JKR.js +312 -0
- package/dist/bundle/chunk-XBUCXQKT.js +51 -0
- package/dist/bundle/entry-EW5A7FYV.js +64 -0
- package/dist/bundle/failure-HMELJ3K5.js +19 -0
- package/dist/bundle/from-memo-F7NTUXAR.js +314 -0
- package/dist/bundle/program-7XWGFN4H.js +14994 -0
- package/dist/bundle/server-T7RVBNRW.js +303 -0
- package/dist/bundle/update-JZDS7B6L.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,98 @@
|
|
|
1
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { CATALOG_KINDS, LOCAL_READ, LOCAL_WRITE, queryTerms, termField, withQuery, } from "@wirecat/cli-core";
|
|
3
|
+
import { answers, itemAnswer } from "../answer.js";
|
|
4
|
+
import { authorOf } from "../author.js";
|
|
5
|
+
import { positive } from "../options.js";
|
|
6
|
+
import { pageOf } from "../page.js";
|
|
7
|
+
import { withSources } from "../records/sources.js";
|
|
8
|
+
import { today } from "./finance.js";
|
|
9
|
+
import { given, json, onOff, optionalChoice } from "./written.js";
|
|
10
|
+
export const PRODUCT_QUERY = {
|
|
11
|
+
entity: "product",
|
|
12
|
+
backend: "native",
|
|
13
|
+
fields: [
|
|
14
|
+
termField("kind", "enum", "kind:service", { values: CATALOG_KINDS }),
|
|
15
|
+
termField("supplier", "ref", 'supplier:"organization:3"'),
|
|
16
|
+
termField("archived", "bool", "archived:true"),
|
|
17
|
+
termField("name", "kw", 'name:"Bike rental"'),
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
export const listProducts = async (store, words, limit) => {
|
|
21
|
+
const terms = queryTerms(words, PRODUCT_QUERY, "products list");
|
|
22
|
+
const filter = given({
|
|
23
|
+
kind: terms.get("kind"),
|
|
24
|
+
supplier: terms.get("supplier"),
|
|
25
|
+
archived: terms.has("archived") ? terms.get("archived") === "true" : undefined,
|
|
26
|
+
name: terms.get("name"),
|
|
27
|
+
});
|
|
28
|
+
return pageOf("products list", limit, (most) => store.products.list({ ...filter, limit: most }));
|
|
29
|
+
};
|
|
30
|
+
/** `wcat products`: what the owner sells or buys, written directly by anyone, as it feeds no total. */
|
|
31
|
+
export const productCommands = (program, streams, env) => {
|
|
32
|
+
const { run } = answers(program, streams, env);
|
|
33
|
+
const products = program
|
|
34
|
+
.command("products")
|
|
35
|
+
.description("goods and services you sell or buy, with their prices; a line that names one copies its price, so a later " +
|
|
36
|
+
"price change leaves the line as it was")
|
|
37
|
+
.summary("goods and services you sell or buy, with their prices");
|
|
38
|
+
withQuery(json(annotate(products.command("list"), { effects: LOCAL_READ })).description("products and services, by name; archived:true lists those no longer sold"), PRODUCT_QUERY)
|
|
39
|
+
.option("--limit <n>", "most products, up to 500", positive, 100)
|
|
40
|
+
.action((words, { json, limit }) => run(json, (store) => listProducts(store, words, limit)));
|
|
41
|
+
json(annotate(products.command("show"), { effects: LOCAL_READ, output: { entity: "product" } }))
|
|
42
|
+
.description("one product or service with its price, unit, supplier and stock code")
|
|
43
|
+
.argument("<product>", "product:<id>")
|
|
44
|
+
.action((ref, options, command) => run(options.json, async (store) => itemAnswer(await withSources(command, store, await store.products.get(ref)))));
|
|
45
|
+
json(annotate(products.command("add"), {
|
|
46
|
+
effects: LOCAL_WRITE,
|
|
47
|
+
output: { entity: "product" },
|
|
48
|
+
literal_after_dashes: true,
|
|
49
|
+
})
|
|
50
|
+
.option("--kind <kind>", `${CATALOG_KINDS.join(" or ")}; product when left out`)
|
|
51
|
+
.option("--unit <text>", "what one of it is counted in, such as hour or month")
|
|
52
|
+
.option("--sku <code>", "the stock code the seller gives it")
|
|
53
|
+
.option("--supplier <party>", "who supplies it, when not you: person:<uid> or organization:<id>")
|
|
54
|
+
.option("--description <text>", "what it is, in a sentence"))
|
|
55
|
+
.description("add a product or service you sell or buy; anyone adds one directly, as a price feeds no total")
|
|
56
|
+
.summary("add a product or service")
|
|
57
|
+
.argument("<name>", "its name, as an invoice or order line prints it")
|
|
58
|
+
.argument("[amount]", "the price of one unit, a decimal such as 10000.00")
|
|
59
|
+
.argument("[currency]", "ISO 4217, such as RUB; given with the amount")
|
|
60
|
+
.action((name, amount, currency, options) => run(options.json, async (store) => itemAnswer(await store.products.add({
|
|
61
|
+
by: authorOf(env),
|
|
62
|
+
name,
|
|
63
|
+
...given({
|
|
64
|
+
kind: optionalChoice(options.kind, CATALOG_KINDS, "--kind"),
|
|
65
|
+
unitPrice: amount,
|
|
66
|
+
currency,
|
|
67
|
+
unit: options.unit,
|
|
68
|
+
sku: options.sku,
|
|
69
|
+
supplier: options.supplier,
|
|
70
|
+
description: options.description,
|
|
71
|
+
}),
|
|
72
|
+
}))));
|
|
73
|
+
json(annotate(products.command("update"), { effects: LOCAL_WRITE, output: { entity: "product" } })
|
|
74
|
+
.option("--amount <decimal>", "the new price of one unit, such as 12000.00; give --currency with it")
|
|
75
|
+
.option("--currency <code>", "an ISO 4217 code, such as RUB")
|
|
76
|
+
.option("--title <title>", "its new name")
|
|
77
|
+
.option("--unit <text>", "what one of it is counted in, such as hour or month")
|
|
78
|
+
.option("--description <text>", "what it is, in a sentence")
|
|
79
|
+
.option("--archived <on|off>", "on: no longer sold, and lines and subscriptions keep pointing at it; off: sold again"))
|
|
80
|
+
.description("change a product's price, name, unit or description, or archive it; lines already written keep theirs")
|
|
81
|
+
.summary("change or archive a product")
|
|
82
|
+
.argument("<product>", "product:<id>")
|
|
83
|
+
.action((ref, options) => run(options.json, async (store) => {
|
|
84
|
+
const archived = onOff(options.archived, "--archived");
|
|
85
|
+
return itemAnswer(await store.products.update(ref, {
|
|
86
|
+
by: authorOf(env),
|
|
87
|
+
...given({
|
|
88
|
+
name: options.title,
|
|
89
|
+
unitPrice: options.amount,
|
|
90
|
+
currency: options.currency,
|
|
91
|
+
unit: options.unit,
|
|
92
|
+
description: options.description,
|
|
93
|
+
archivedDate: archived === undefined ? undefined : archived ? today() : null,
|
|
94
|
+
}),
|
|
95
|
+
}));
|
|
96
|
+
}));
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=products-command.js.map
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { FINANCE_REVIEWS, INVOICE_DIRECTIONS, LOCAL_READ, LOCAL_WRITE, queryTerms, SUBSCRIPTION_STATUSES, termField, withQuery, } from "@wirecat/cli-core";
|
|
3
|
+
import { answers, itemAnswer } from "../answer.js";
|
|
4
|
+
import { byOption, whoRuns } from "../author.js";
|
|
5
|
+
import { positive } from "../options.js";
|
|
6
|
+
import { pageOf } from "../page.js";
|
|
7
|
+
import { withSources } from "../records/sources.js";
|
|
8
|
+
import { canonicalProject } from "../vocabulary/project.js";
|
|
9
|
+
import { dayOf, today } from "./finance.js";
|
|
10
|
+
import { choice, given, json, needed, optionalChoice, PROPOSES, writeMeta, writtenBy } from "./written.js";
|
|
11
|
+
export const SUBSCRIPTION_QUERY = {
|
|
12
|
+
entity: "subscription",
|
|
13
|
+
backend: "native",
|
|
14
|
+
fields: [
|
|
15
|
+
termField("status", "enum", "status:active", { values: SUBSCRIPTION_STATUSES }),
|
|
16
|
+
termField("direction", "enum", "direction:payable", { values: INVOICE_DIRECTIONS }),
|
|
17
|
+
termField("supplier", "ref", 'supplier:"organization:3"'),
|
|
18
|
+
termField("customer", "ref", 'customer:"organization:3"'),
|
|
19
|
+
termField("project", "kw", "project:PMED"),
|
|
20
|
+
termField("review", "enum", "review:proposed", { values: FINANCE_REVIEWS }),
|
|
21
|
+
termField("renews", "time", "renews:2026-12-01"),
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
export const listSubscriptions = async (store, words, limit) => {
|
|
25
|
+
const terms = queryTerms(words, SUBSCRIPTION_QUERY, "subscriptions list");
|
|
26
|
+
const project = terms.get("project");
|
|
27
|
+
const filter = given({
|
|
28
|
+
status: terms.get("status"),
|
|
29
|
+
direction: terms.get("direction"),
|
|
30
|
+
supplier: terms.get("supplier"),
|
|
31
|
+
customer: terms.get("customer"),
|
|
32
|
+
review: terms.get("review"),
|
|
33
|
+
renewsBy: dayOf(terms.get("renews")),
|
|
34
|
+
project: project === undefined ? undefined : await canonicalProject(store, project),
|
|
35
|
+
});
|
|
36
|
+
return pageOf("subscriptions list", limit, (most) => store.subscriptions.list({ ...filter, limit: most }));
|
|
37
|
+
};
|
|
38
|
+
const parts = (command) => command
|
|
39
|
+
.option("--status <state>", `${SUBSCRIPTION_STATUSES.join(", ")}; trial needs --trial-end-date`)
|
|
40
|
+
.option("--supplier <party>", "who supplies it: person:<uid> or organization:<id>; you, when you bill it")
|
|
41
|
+
.option("--customer <party>", "who receives it and pays for it: person:<uid> or organization:<id>; you, when you pay")
|
|
42
|
+
.option("--product <product>", "the product or service it is for: product:<id>")
|
|
43
|
+
.option("--contract <contract>", "the contract it runs under: contract:<id>")
|
|
44
|
+
.option("--period <count-unit>", "how often it is charged: a count and a unit, such as 1-month or 1-year")
|
|
45
|
+
.option("--start-date <date>", "the first day it runs, YYYY-MM-DD")
|
|
46
|
+
.option("--trial-end-date <date>", "the day its free trial ends, YYYY-MM-DD");
|
|
47
|
+
const fieldsOf = (options) => given({
|
|
48
|
+
status: optionalChoice(options.status, SUBSCRIPTION_STATUSES, "--status"),
|
|
49
|
+
supplier: options.supplier,
|
|
50
|
+
customer: options.customer,
|
|
51
|
+
product: options.product,
|
|
52
|
+
contract: options.contract,
|
|
53
|
+
every: options.period,
|
|
54
|
+
startDate: dayOf(options.startDate),
|
|
55
|
+
trialEndDate: dayOf(options.trialEndDate),
|
|
56
|
+
endDate: dayOf(options.endDate),
|
|
57
|
+
});
|
|
58
|
+
/** `wcat subscriptions`: what the owner bills or pays on a schedule, and its price history. */
|
|
59
|
+
export const subscriptionCommands = (program, streams, env) => {
|
|
60
|
+
const { run } = answers(program, streams, env);
|
|
61
|
+
const subscriptions = program
|
|
62
|
+
.command("subscriptions")
|
|
63
|
+
.description("subscriptions you bill or pay: who supplies it, who pays, how often, and every price it had; a price is " +
|
|
64
|
+
"never changed, a new one is added")
|
|
65
|
+
.summary("subscriptions you bill or pay, and their prices");
|
|
66
|
+
withQuery(json(annotate(subscriptions.command("list"), { effects: LOCAL_READ })).description("subscriptions, newest first; renews:2026-12-01 lists those that renew by then"), SUBSCRIPTION_QUERY)
|
|
67
|
+
.option("--limit <n>", "most subscriptions, up to 500", positive, 100)
|
|
68
|
+
.action((words, { json, limit }) => run(json, (store) => listSubscriptions(store, words, limit)));
|
|
69
|
+
json(annotate(subscriptions.command("show"), { effects: LOCAL_READ, output: { entity: "subscription" } }))
|
|
70
|
+
.description("one subscription with its parties, dates, current price and every price it had")
|
|
71
|
+
.argument("<subscription>", "subscription:<id>")
|
|
72
|
+
.action((ref, options, command) => run(options.json, async (store) => itemAnswer(await withSources(command, store, await store.subscriptions.get(ref)))));
|
|
73
|
+
json(writeMeta(parts(annotate(subscriptions.command("add"), {
|
|
74
|
+
effects: LOCAL_WRITE,
|
|
75
|
+
output: { entity: "subscription" },
|
|
76
|
+
literal_after_dashes: true,
|
|
77
|
+
})).option("--kind <kind>", "receivable (you bill it) or payable (you pay it)")))
|
|
78
|
+
.description(`record a subscription and its first price; ${PROPOSES}`)
|
|
79
|
+
.summary("record a subscription; an agent's waits for your review")
|
|
80
|
+
.argument("<name>", "what it is, such as Hosting")
|
|
81
|
+
.argument("<amount>", "its price for one period, a decimal such as 990.00")
|
|
82
|
+
.argument("<currency>", "ISO 4217, such as RUB")
|
|
83
|
+
.action(async (name, amount, currency, options, command) => {
|
|
84
|
+
const by = await whoRuns(command, env, {
|
|
85
|
+
asOwner: options.asOwner,
|
|
86
|
+
question: "record this subscription as yours?",
|
|
87
|
+
});
|
|
88
|
+
await run(options.json, async (store) => {
|
|
89
|
+
const startDate = dayOf(options.startDate) ?? today();
|
|
90
|
+
return itemAnswer(await store.subscriptions.add({
|
|
91
|
+
...(await writtenBy(store, by, options)),
|
|
92
|
+
...fieldsOf(options),
|
|
93
|
+
name,
|
|
94
|
+
direction: choice(options.kind, INVOICE_DIRECTIONS, "--kind"),
|
|
95
|
+
every: needed(options.period, "--period", "how often it is charged, such as 1-month"),
|
|
96
|
+
startDate,
|
|
97
|
+
prices: [{ amount, currency, effectiveFrom: startDate }],
|
|
98
|
+
}));
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
json(byOption(parts(annotate(subscriptions.command("update"), { effects: LOCAL_WRITE, output: { entity: "subscription" } }))
|
|
102
|
+
.option("--title <title>", "its new name")
|
|
103
|
+
.option("--end-date <date>", "the last day it runs, YYYY-MM-DD")))
|
|
104
|
+
.description("change a subscription's status, schedule, dates or parties; pause it with --status paused. You change any, an " +
|
|
105
|
+
"agent only one it proposed that is still proposed. A new price is subscriptions prices add")
|
|
106
|
+
.summary("change a subscription")
|
|
107
|
+
.argument("<subscription>", "subscription:<id>")
|
|
108
|
+
.action(async (ref, options, command) => {
|
|
109
|
+
const by = await whoRuns(command, env, { asOwner: options.asOwner, question: `change ${ref} as yours?` });
|
|
110
|
+
await run(options.json, async (store) => itemAnswer(await store.subscriptions.update(ref, { by, ...fieldsOf(options), ...given({ name: options.title }) })));
|
|
111
|
+
});
|
|
112
|
+
json(byOption(annotate(subscriptions.command("cancel"), { effects: LOCAL_WRITE, output: { entity: "subscription" } }).option("--occurred-time <time>", "the day it was cancelled, such as 2026-11-01; today when left out")))
|
|
113
|
+
.description("mark a subscription cancelled on a day; it stays, with its prices")
|
|
114
|
+
.summary("cancel a subscription")
|
|
115
|
+
.argument("<subscription>", "subscription:<id>")
|
|
116
|
+
.action(async (ref, options, command) => {
|
|
117
|
+
const by = await whoRuns(command, env, { asOwner: options.asOwner, question: `cancel ${ref} as yours?` });
|
|
118
|
+
await run(options.json, async (store) => itemAnswer(await store.subscriptions.update(ref, {
|
|
119
|
+
by,
|
|
120
|
+
status: "cancelled",
|
|
121
|
+
cancelledDate: dayOf(options.occurredTime) ?? today(),
|
|
122
|
+
})));
|
|
123
|
+
});
|
|
124
|
+
const prices = subscriptions
|
|
125
|
+
.command("prices")
|
|
126
|
+
.description("the prices a subscription had, each from a day on; one is never changed, a new one is added")
|
|
127
|
+
.summary("a subscription's prices");
|
|
128
|
+
json(byOption(annotate(prices.command("add"), { effects: LOCAL_WRITE, output: { entity: "subscription_price" } })
|
|
129
|
+
.option("--start-date <date>", "the first day the price holds, YYYY-MM-DD; the subscription's start when left out")
|
|
130
|
+
.option("--reason <text>", "why an agent proposes it, for the owner who decides")))
|
|
131
|
+
.description(`add a price from a day on; the earlier ones stay as they were. ${PROPOSES}, and the subscription stays as it is`)
|
|
132
|
+
.summary("add a subscription's new price")
|
|
133
|
+
.argument("<subscription>", "subscription:<id>")
|
|
134
|
+
.argument("<amount>", "the price for one period, a decimal such as 1190.00")
|
|
135
|
+
.argument("<currency>", "ISO 4217, such as RUB")
|
|
136
|
+
.action(async (ref, amount, currency, options, command) => {
|
|
137
|
+
const by = await whoRuns(command, env, {
|
|
138
|
+
asOwner: options.asOwner,
|
|
139
|
+
question: `add a price to ${ref} as yours?`,
|
|
140
|
+
});
|
|
141
|
+
await run(options.json, async (store) => itemAnswer(await store.subscriptions.addPrice(ref, {
|
|
142
|
+
by,
|
|
143
|
+
amount,
|
|
144
|
+
currency,
|
|
145
|
+
...given({
|
|
146
|
+
effectiveFrom: dayOf(options.startDate),
|
|
147
|
+
reason: by === "owner" ? undefined : options.reason,
|
|
148
|
+
}),
|
|
149
|
+
})));
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=subscriptions-command.js.map
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { FINANCE_REVIEWS, LOCAL_READ, LOCAL_WRITE, MONEY_DIRECTIONS, queryTerms, TRANSACTION_STATUSES, termField, withQuery, } from "@wirecat/cli-core";
|
|
3
|
+
import { answers, itemAnswer } from "../answer.js";
|
|
4
|
+
import { byOption, whoRuns } from "../author.js";
|
|
5
|
+
import { positive } from "../options.js";
|
|
6
|
+
import { pageOf } from "../page.js";
|
|
7
|
+
import { withSources } from "../records/sources.js";
|
|
8
|
+
import { canonicalProject } from "../vocabulary/project.js";
|
|
9
|
+
import { dayOf, today } from "./finance.js";
|
|
10
|
+
import { choice, given, json, optionalChoice, PROPOSES, writeMeta, writtenBy } from "./written.js";
|
|
11
|
+
export const TRANSACTION_QUERY = {
|
|
12
|
+
entity: "transaction",
|
|
13
|
+
backend: "native",
|
|
14
|
+
fields: [
|
|
15
|
+
termField("wallet", "ref", 'wallet:"wallet:2"'),
|
|
16
|
+
termField("direction", "enum", "direction:out", { values: MONEY_DIRECTIONS }),
|
|
17
|
+
termField("status", "enum", "status:pending", { values: TRANSACTION_STATUSES }),
|
|
18
|
+
termField("category", "kw", "category:Rent"),
|
|
19
|
+
termField("project", "kw", "project:PMED"),
|
|
20
|
+
termField("review", "enum", "review:proposed", { values: FINANCE_REVIEWS }),
|
|
21
|
+
termField("uncategorized", "bool", "uncategorized:true"),
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
export const listTransactions = async (store, words, limit) => {
|
|
25
|
+
const terms = queryTerms(words, TRANSACTION_QUERY, "transactions list");
|
|
26
|
+
const project = terms.get("project");
|
|
27
|
+
const filter = given({
|
|
28
|
+
wallet: terms.get("wallet"),
|
|
29
|
+
direction: terms.get("direction"),
|
|
30
|
+
status: terms.get("status"),
|
|
31
|
+
category: terms.get("category"),
|
|
32
|
+
review: terms.get("review"),
|
|
33
|
+
uncategorized: terms.has("uncategorized") ? terms.get("uncategorized") === "true" : undefined,
|
|
34
|
+
project: project === undefined ? undefined : await canonicalProject(store, project),
|
|
35
|
+
});
|
|
36
|
+
return pageOf("transactions list", limit, (most) => store.transactions.list({ ...filter, limit: most }));
|
|
37
|
+
};
|
|
38
|
+
const STATUS_HELP = `${TRANSACTION_STATUSES.join(" or ")}; only a booked one counts in a balance`;
|
|
39
|
+
/** `wcat transactions`: what a bank statement says moved, and the categories it is split into. */
|
|
40
|
+
export const transactionCommands = (program, streams, env) => {
|
|
41
|
+
const { run } = answers(program, streams, env);
|
|
42
|
+
const transactions = program
|
|
43
|
+
.command("transactions")
|
|
44
|
+
.description("money a wallet's statement shows moving in or out, the payment it settles, and the categories it is split into")
|
|
45
|
+
.summary("money moving in or out of your wallets");
|
|
46
|
+
withQuery(json(annotate(transactions.command("list"), { effects: LOCAL_READ })).description("transactions, newest first; uncategorized:true lists those not fully split into categories"), TRANSACTION_QUERY)
|
|
47
|
+
.summary("transactions, newest first")
|
|
48
|
+
.option("--limit <n>", "most transactions, up to 500", positive, 100)
|
|
49
|
+
.action((words, { json, limit }) => run(json, (store) => listTransactions(store, words, limit)));
|
|
50
|
+
json(annotate(transactions.command("show"), { effects: LOCAL_READ, output: { entity: "transaction" } }))
|
|
51
|
+
.description("one transaction with its wallet, payment, splits and what is not categorized")
|
|
52
|
+
.argument("<transaction>", "transaction:<id>")
|
|
53
|
+
.action((ref, options, command) => run(options.json, async (store) => itemAnswer(await withSources(command, store, await store.transactions.get(ref)))));
|
|
54
|
+
json(writeMeta(annotate(transactions.command("add"), {
|
|
55
|
+
effects: LOCAL_WRITE,
|
|
56
|
+
output: { entity: "transaction" },
|
|
57
|
+
literal_after_dashes: true,
|
|
58
|
+
})
|
|
59
|
+
.option("--kind <kind>", "in (money came in) or out (money went out)")
|
|
60
|
+
.option("--occurred-time <time>", "the day the statement shows, such as 2026-11-01; today when left out")
|
|
61
|
+
.option("--description <text>", "what the statement says, as it says it")
|
|
62
|
+
.option("--status <state>", `${STATUS_HELP}; booked when left out`)
|
|
63
|
+
.option("--payment <payment>", "the payment it settles, same amount, currency and direction: payment:<id>")))
|
|
64
|
+
.description(`record what a wallet's statement shows moved, in the wallet's currency; ${PROPOSES}`)
|
|
65
|
+
.summary("record a transaction; an agent's waits for your review")
|
|
66
|
+
.argument("<wallet>", "wallet:<id>")
|
|
67
|
+
.argument("<amount>", "a decimal above 0, such as 500.00")
|
|
68
|
+
.action(async (wallet, amount, options, command) => {
|
|
69
|
+
const by = await whoRuns(command, env, {
|
|
70
|
+
asOwner: options.asOwner,
|
|
71
|
+
question: "record this transaction as yours?",
|
|
72
|
+
});
|
|
73
|
+
await run(options.json, async (store) => itemAnswer(await store.transactions.add({
|
|
74
|
+
...(await writtenBy(store, by, options)),
|
|
75
|
+
wallet,
|
|
76
|
+
amount,
|
|
77
|
+
direction: choice(options.kind, MONEY_DIRECTIONS, "--kind"),
|
|
78
|
+
statementDate: dayOf(options.occurredTime) ?? today(),
|
|
79
|
+
...given({
|
|
80
|
+
status: optionalChoice(options.status, TRANSACTION_STATUSES, "--status"),
|
|
81
|
+
description: options.description,
|
|
82
|
+
payment: options.payment,
|
|
83
|
+
}),
|
|
84
|
+
})));
|
|
85
|
+
});
|
|
86
|
+
json(byOption(annotate(transactions.command("update"), { effects: LOCAL_WRITE, output: { entity: "transaction" } })
|
|
87
|
+
.option("--status <state>", STATUS_HELP)
|
|
88
|
+
.option("--payment <payment>", "the payment it settles, same amount, currency and direction: payment:<id>")
|
|
89
|
+
.option("--description <text>", "what the statement says, as it says it")))
|
|
90
|
+
.description("book a pending transaction, link it to the payment it settles, or fix its text; you change any, an agent only " +
|
|
91
|
+
"one it proposed that is still proposed")
|
|
92
|
+
.summary("book a transaction or link it to its payment")
|
|
93
|
+
.argument("<transaction>", "transaction:<id>")
|
|
94
|
+
.action(async (ref, options, command) => {
|
|
95
|
+
const by = await whoRuns(command, env, { asOwner: options.asOwner, question: `change ${ref} as yours?` });
|
|
96
|
+
await run(options.json, async (store) => itemAnswer(await store.transactions.update(ref, {
|
|
97
|
+
by,
|
|
98
|
+
...given({
|
|
99
|
+
status: optionalChoice(options.status, TRANSACTION_STATUSES, "--status"),
|
|
100
|
+
payment: options.payment,
|
|
101
|
+
description: options.description,
|
|
102
|
+
}),
|
|
103
|
+
})));
|
|
104
|
+
});
|
|
105
|
+
const splits = transactions
|
|
106
|
+
.command("splits")
|
|
107
|
+
.description("the categories a transaction's amount is split into; together never more than the amount, the rest is " +
|
|
108
|
+
"uncategorized")
|
|
109
|
+
.summary("a transaction's categories");
|
|
110
|
+
const WHO = "you split any transaction; an agent only one it proposed that is still proposed";
|
|
111
|
+
json(byOption(annotate(splits.command("add"), { effects: LOCAL_WRITE, output: { entity: "transaction" } }).option("--project <project>", "the project this part belongs to: its key or project:<id>")))
|
|
112
|
+
.description(`put part of a transaction's amount under a category; ${WHO}`)
|
|
113
|
+
.summary("put part of a transaction under a category")
|
|
114
|
+
.argument("<transaction>", "transaction:<id>")
|
|
115
|
+
.argument("<amount>", "a decimal above 0, such as 120.00")
|
|
116
|
+
.argument("<category...>", "the category, in a word or a few, such as Rent")
|
|
117
|
+
.action(async (ref, amount, words, options, command) => {
|
|
118
|
+
const by = await whoRuns(command, env, { asOwner: options.asOwner, question: `split ${ref} as yours?` });
|
|
119
|
+
await run(options.json, async (store) => itemAnswer(await store.transactions.addSplit(ref, {
|
|
120
|
+
by,
|
|
121
|
+
amount,
|
|
122
|
+
category: words.join(" "),
|
|
123
|
+
...(options.project === undefined ? {} : { project: await canonicalProject(store, options.project) }),
|
|
124
|
+
})));
|
|
125
|
+
});
|
|
126
|
+
json(byOption(annotate(splits.command("remove"), { effects: LOCAL_WRITE, output: { entity: "transaction" } })))
|
|
127
|
+
.description(`take a split off a transaction; its amount is uncategorized again. ${WHO}`)
|
|
128
|
+
.summary("take a split off a transaction")
|
|
129
|
+
.argument("<transaction>", "transaction:<id>")
|
|
130
|
+
.argument("<position>", "the split's position, from 1, as transactions show lists it", positive)
|
|
131
|
+
.action(async (ref, position, options, command) => {
|
|
132
|
+
const by = await whoRuns(command, env, { asOwner: options.asOwner, question: `change ${ref}'s splits as yours?` });
|
|
133
|
+
await run(options.json, async (store) => itemAnswer(await store.transactions.removeSplit(ref, { position, by })));
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=transactions-command.js.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { LOCAL_READ, LOCAL_WRITE, queryTerms, termField, WALLET_KINDS, withQuery, } from "@wirecat/cli-core";
|
|
3
|
+
import { answers, itemAnswer } from "../answer.js";
|
|
4
|
+
import { authorOf, byOption, whoRuns } from "../author.js";
|
|
5
|
+
import { positive } from "../options.js";
|
|
6
|
+
import { pageOf } from "../page.js";
|
|
7
|
+
import { sourceAccounts, withSources } from "../records/sources.js";
|
|
8
|
+
import { dayOf } from "./finance.js";
|
|
9
|
+
import { given, json, optionalChoice } from "./written.js";
|
|
10
|
+
export const WALLET_QUERY = {
|
|
11
|
+
entity: "wallet",
|
|
12
|
+
backend: "native",
|
|
13
|
+
fields: [
|
|
14
|
+
termField("kind", "enum", "kind:card", { values: WALLET_KINDS }),
|
|
15
|
+
termField("currency", "kw", "currency:RUB"),
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
export const listWallets = async (store, words, limit) => {
|
|
19
|
+
const terms = queryTerms(words, WALLET_QUERY, "wallets list");
|
|
20
|
+
const filter = given({
|
|
21
|
+
kind: terms.get("kind"),
|
|
22
|
+
currency: terms.get("currency"),
|
|
23
|
+
});
|
|
24
|
+
return pageOf("wallets list", limit, (most) => store.wallets.list({ ...filter, limit: most }));
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* An imported wallet's opening balance as its source record gives it: only the owner sets the wallet's own, so until
|
|
28
|
+
* then `wallets show` prints the source's beside it.
|
|
29
|
+
*/
|
|
30
|
+
const sourceSays = async (store, wallet) => {
|
|
31
|
+
if (wallet.openingBalance !== null)
|
|
32
|
+
return null;
|
|
33
|
+
for (const { provider, account } of await sourceAccounts(store, wallet)) {
|
|
34
|
+
const { items: [record], } = await store.records.list({ provider, account, entity: wallet.ref, limit: 1 });
|
|
35
|
+
const { opening_balance: balance, opening_date: date } = record?.fields ?? {};
|
|
36
|
+
if (record && typeof balance === "string")
|
|
37
|
+
return {
|
|
38
|
+
openingBalance: balance,
|
|
39
|
+
openingDate: typeof date === "string" ? date : null,
|
|
40
|
+
record: `${record.type}:${record.externalId}`,
|
|
41
|
+
account: `${provider}:${account}`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
/** `wcat wallets`: where the owner's money is, with a balance computed from its confirmed, booked transactions. */
|
|
47
|
+
export const walletCommands = (program, streams, env) => {
|
|
48
|
+
const { run } = answers(program, streams, env);
|
|
49
|
+
const wallets = program
|
|
50
|
+
.command("wallets")
|
|
51
|
+
.description("bank accounts, cards and cash you keep money in, one currency each; a balance is the opening balance plus " +
|
|
52
|
+
"confirmed, booked transactions, computed each time")
|
|
53
|
+
.summary("bank accounts, cards and cash, with their balances");
|
|
54
|
+
withQuery(json(annotate(wallets.command("list"), { effects: LOCAL_READ })).description("wallets with their balances today; kind:card lists the cards"), WALLET_QUERY)
|
|
55
|
+
.option("--limit <n>", "most wallets, up to 500", positive, 100)
|
|
56
|
+
.action((words, { json, limit }) => run(json, (store) => listWallets(store, words, limit)));
|
|
57
|
+
json(annotate(wallets.command("show"), { effects: LOCAL_READ, output: { entity: "wallet" } }).option("--until-time <time>", "the balance up to and including this day, such as 2026-10-31; today when left out"))
|
|
58
|
+
.description("one wallet with its balance, and beside it what is pending or proposed and not counted yet; for an imported " +
|
|
59
|
+
"wallet whose opening balance you have not set, source_says gives the one its source sent")
|
|
60
|
+
.summary("one wallet with its balance and what is pending")
|
|
61
|
+
.argument("<wallet>", "wallet:<id>")
|
|
62
|
+
.action((ref, options, command) => run(options.json, async (store) => {
|
|
63
|
+
const until = dayOf(options.untilTime);
|
|
64
|
+
const wallet = await store.wallets.get(ref, until === undefined ? {} : { until });
|
|
65
|
+
return itemAnswer(await withSources(command, store, { ...wallet, sourceSays: await sourceSays(store, wallet) }));
|
|
66
|
+
}));
|
|
67
|
+
json(annotate(wallets.command("add"), { effects: LOCAL_WRITE, output: { entity: "wallet" }, literal_after_dashes: true })
|
|
68
|
+
.option("--kind <kind>", `${WALLET_KINDS.join(", ")}; bank when left out`)
|
|
69
|
+
.option("--institution <text>", "the bank or other company that holds it, by name"))
|
|
70
|
+
.description("add a wallet in one currency; anyone adds one directly, and only you set its opening balance, with wallets update")
|
|
71
|
+
.summary("add a bank account, card or cash wallet")
|
|
72
|
+
.argument("<name>", "what you call it, such as 'Main card'")
|
|
73
|
+
.argument("<currency>", "ISO 4217, such as RUB; a bank account in two currencies is two wallets")
|
|
74
|
+
.action((name, currency, options) => run(options.json, async (store) => itemAnswer(await store.wallets.add({
|
|
75
|
+
by: authorOf(env),
|
|
76
|
+
name,
|
|
77
|
+
currency,
|
|
78
|
+
...given({
|
|
79
|
+
kind: optionalChoice(options.kind, WALLET_KINDS, "--kind"),
|
|
80
|
+
institution: options.institution,
|
|
81
|
+
}),
|
|
82
|
+
}))));
|
|
83
|
+
json(byOption(annotate(wallets.command("update"), { effects: LOCAL_WRITE, output: { entity: "wallet" } })
|
|
84
|
+
.option("--title <title>", "its new name")
|
|
85
|
+
.option("--institution <text>", "the bank or other company that holds it, by name")
|
|
86
|
+
.option("--opening-balance <decimal>", "what it held on --opening-date, such as 1500.50; only you set it")
|
|
87
|
+
.option("--opening-date <date>", "the day of the opening balance, YYYY-MM-DD")))
|
|
88
|
+
.description("rename a wallet, or set the opening balance its balance counts from; the opening balance is yours alone, an " +
|
|
89
|
+
"agent is refused")
|
|
90
|
+
.summary("rename a wallet or set its opening balance")
|
|
91
|
+
.argument("<wallet>", "wallet:<id>")
|
|
92
|
+
.action(async (ref, options, command) => {
|
|
93
|
+
const by = await whoRuns(command, env, { asOwner: options.asOwner, question: `change ${ref} as yours?` });
|
|
94
|
+
await run(options.json, async (store) => itemAnswer(await store.wallets.update(ref, {
|
|
95
|
+
by,
|
|
96
|
+
...given({
|
|
97
|
+
name: options.title,
|
|
98
|
+
institution: options.institution,
|
|
99
|
+
openingBalance: options.openingBalance,
|
|
100
|
+
openingDate: dayOf(options.openingDate),
|
|
101
|
+
}),
|
|
102
|
+
})));
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=wallets-command.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { byOption } from "../author.js";
|
|
3
|
+
import { jsonOption } from "../options.js";
|
|
4
|
+
import { canonicalProject } from "../vocabulary/project.js";
|
|
5
|
+
export const json = (command) => jsonOption(command);
|
|
6
|
+
export const PROPOSES = "yours is confirmed at once; an agent's waits as proposed for you in wcat review";
|
|
7
|
+
export const choice = (value, allowed, flag) => {
|
|
8
|
+
if (value === undefined || !allowed.includes(value))
|
|
9
|
+
throw new CliError("validation_error", `${flag} is one of ${allowed.join(", ")}`, { param: flag });
|
|
10
|
+
return value;
|
|
11
|
+
};
|
|
12
|
+
export const needed = (value, flag, what) => {
|
|
13
|
+
if (value === undefined || value.trim() === "")
|
|
14
|
+
throw new CliError("validation_error", `name ${what}: ${flag}`, { param: flag });
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
17
|
+
export const optionalChoice = (value, allowed, flag) => (value === undefined ? undefined : choice(value, allowed, flag));
|
|
18
|
+
/** `--auto-renew on`, `--archived off`: the vocabulary's on|off values. */
|
|
19
|
+
export const onOff = (value, flag) => value === undefined ? undefined : choice(value, ["on", "off"], flag) === "on";
|
|
20
|
+
/** The parts every finance write shares: who writes it, its project, and an agent's reason. */
|
|
21
|
+
export const writtenBy = async (store, by, options) => ({
|
|
22
|
+
by,
|
|
23
|
+
...(options.project === undefined ? {} : { project: await canonicalProject(store, options.project) }),
|
|
24
|
+
...(by !== "owner" && options.reason !== undefined ? { reason: options.reason } : {}),
|
|
25
|
+
...(options.evidence === undefined ? {} : { evidence: options.evidence }),
|
|
26
|
+
});
|
|
27
|
+
export const party = (command, what) => command
|
|
28
|
+
.option("--person <uid>", `the person ${what}: person:<id>`)
|
|
29
|
+
.option("--organization <organization>", `the organization ${what}: organization:<id>`);
|
|
30
|
+
export const writeMeta = (command) => byOption(command
|
|
31
|
+
.option("--project <project>", "the project it belongs to: its key or project:<id>")
|
|
32
|
+
.option("--reason <text>", "why an agent proposes it, for the owner who decides")
|
|
33
|
+
.option("--evidence <ref...>", "what shows it, up to 8: msg:, note:, document: or another reference"));
|
|
34
|
+
/** Leaves out what the caller did not give, so an update changes only the named fields. */
|
|
35
|
+
export const given = (fields) => Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== undefined));
|
|
36
|
+
//# sourceMappingURL=written.js.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { environmentOf, LOCAL_READ, LOCAL_WRITE, parseMeetingFindingsJson, proposesOnly, queryTerms, termField, withQuery, } from "@wirecat/cli-core";
|
|
4
|
+
import { answers, itemAnswer, listAnswer } from "../answer.js";
|
|
5
|
+
import { byOption, whoRuns } from "../author.js";
|
|
6
|
+
import { FINDINGS_INPUT_HELP, readFindingsInput } from "../findings-input.js";
|
|
7
|
+
import { mcpOwnerAllowed } from "../mcp/permissions.js";
|
|
8
|
+
import { positive } from "../options.js";
|
|
9
|
+
import { accountName, MEETING_ACCOUNT_HELP, MEETING_WRITE_HELP, sourceOptions, theAccount, writeAccount, writeOptions, } from "../store/source-list.js";
|
|
10
|
+
import { withoutTaskDuplicates } from "../tasks/proposal-duplicates.js";
|
|
11
|
+
const FINDINGS_QUERY = {
|
|
12
|
+
entity: "meeting_findings",
|
|
13
|
+
backend: "native",
|
|
14
|
+
fields: [termField("status", "enum", "status:proposed", { values: ["proposed", "reviewed"] })],
|
|
15
|
+
};
|
|
16
|
+
export const findingsCommand = (program, streams, env) => {
|
|
17
|
+
const group = program
|
|
18
|
+
.command("meetings")
|
|
19
|
+
.description("stored meeting evidence and reviewed findings")
|
|
20
|
+
.command("actions")
|
|
21
|
+
.description("cited meeting facts and project tasks waiting for owner review");
|
|
22
|
+
const { run } = answers(program, streams, env);
|
|
23
|
+
const warn = (text) => streams.diagnostic(text);
|
|
24
|
+
const scope = (store, given) => theAccount(store, env, given, warn);
|
|
25
|
+
const acting = (store, given) => writeAccount(store, env, given, warn);
|
|
26
|
+
const options = (command) => sourceOptions(command, MEETING_ACCOUNT_HELP).option("--json", "print JSON; --json=id,status keeps only those fields");
|
|
27
|
+
const writes = (command) => writeOptions(command, MEETING_WRITE_HELP).option("--json", "print JSON; --json=id,status keeps only those fields");
|
|
28
|
+
writes(proposesOnly(annotate(group.command("add"), { effects: LOCAL_WRITE, output: { entity: "meeting_findings" } })))
|
|
29
|
+
.description("stage cited findings; facts and tasks wait for owner confirmation")
|
|
30
|
+
.argument("<file>", FINDINGS_INPUT_HELP)
|
|
31
|
+
.addHelpText("after", "\nInput: schema_version 1, key, extractor, findings. Every finding names id, kind, project and evidence (reference and fingerprint). Facts name type and statement; tasks name type, title, reason and commitment (explicit or inferred). At most 16 findings, each with 1–8 exact cues from Zoom evidence. Optional due_at is a real ISO timestamp with timezone and requires due_evidence; optional assignee is a person reference and requires assignee_evidence. Both support lists cite this finding's cue references.\n")
|
|
32
|
+
.action(async (file, given) => {
|
|
33
|
+
const text = await readFindingsInput(file, environmentOf(program).stdin ?? process.stdin);
|
|
34
|
+
const input = parseMeetingFindingsJson(text);
|
|
35
|
+
const author = await whoRuns(program, env, { question: "" });
|
|
36
|
+
const agent = author === "owner" ? { bot: "wcat-findings" } : author;
|
|
37
|
+
await run(given.json, async (store) => {
|
|
38
|
+
const { input: kept, duplicates } = await withoutTaskDuplicates(store, env, input);
|
|
39
|
+
const noted = duplicates.length ? { duplicates } : {};
|
|
40
|
+
if (kept.findings.length === 0)
|
|
41
|
+
return itemAnswer({ staged: false, findings: 0, ...noted });
|
|
42
|
+
return itemAnswer({ ...(await store.meetingFindings.stage(await acting(store, given), kept, agent)), ...noted });
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
options(annotate(group.command("show"), { effects: LOCAL_READ, output: { entity: "meeting_findings" } }))
|
|
46
|
+
.description("one findings preview, prior decisions and its review receipt")
|
|
47
|
+
.argument("<id>", "stored findings batch ID")
|
|
48
|
+
.action((id, given) => run(given.json, async (store) => itemAnswer(await store.meetingFindings.get(await scope(store, given), id))));
|
|
49
|
+
withQuery(options(annotate(group.command("list"), { effects: LOCAL_READ, output: { entity: "meeting_findings" } })), FINDINGS_QUERY)
|
|
50
|
+
.description("findings batches in one meeting account, newest first")
|
|
51
|
+
.option("--limit <n>", "batches per page, at most 50", positive, 20)
|
|
52
|
+
.option("--page <n>", "which page, from 1", positive, 1)
|
|
53
|
+
.action((words, given) => run(given.json, async (store) => {
|
|
54
|
+
const status = queryTerms(words, FINDINGS_QUERY, "meetings actions list").get("status");
|
|
55
|
+
const key = await scope(store, given);
|
|
56
|
+
const found = await store.meetingFindings.list(key, {
|
|
57
|
+
limit: given.limit,
|
|
58
|
+
offset: (given.page - 1) * given.limit,
|
|
59
|
+
...(status === undefined ? {} : { status }),
|
|
60
|
+
});
|
|
61
|
+
return listAnswer("meetings actions list", {
|
|
62
|
+
items: found.items,
|
|
63
|
+
limit: given.limit,
|
|
64
|
+
page: given.page,
|
|
65
|
+
has_more: found.hasMore,
|
|
66
|
+
args: { query: words.join(" "), source: accountName(key), limit: given.limit },
|
|
67
|
+
});
|
|
68
|
+
}));
|
|
69
|
+
for (const name of ["confirm", "reject"]) {
|
|
70
|
+
const command = writes(annotate(group.command(name), { effects: LOCAL_WRITE, output: { entity: "meeting_findings" } }))
|
|
71
|
+
.description(name === "confirm"
|
|
72
|
+
? "owner only: create selected findings and reject the other new candidates"
|
|
73
|
+
: "owner only: reject every new candidate in this batch")
|
|
74
|
+
.argument("<id>", "stored findings batch ID")
|
|
75
|
+
.requiredOption("--fingerprint <hash>", "the exact fingerprint shown in the preview");
|
|
76
|
+
byOption(command);
|
|
77
|
+
const review = async (id, given, accept) => {
|
|
78
|
+
const key = `meetings.actions.${name}`;
|
|
79
|
+
const who = await whoRuns(command, env, { asOwner: given.asOwner, question: `${name} batch ${id} as you?` });
|
|
80
|
+
// A saved permission is the owner's standing answer; the agent still decides as itself, never its own batch.
|
|
81
|
+
const by = who === "owner"
|
|
82
|
+
? who
|
|
83
|
+
: mcpOwnerAllowed(env, key)
|
|
84
|
+
? { bot: who.bot, reason: `the owner allows ${key}` }
|
|
85
|
+
: undefined;
|
|
86
|
+
if (by === undefined)
|
|
87
|
+
throw new CliError("validation_error", "findings confirmation and rejection belong to the owner; agents must leave proposals for review");
|
|
88
|
+
return run(given.json, async (store) => itemAnswer(await store.meetingFindings.review(await acting(store, given), id, {
|
|
89
|
+
fingerprint: given.fingerprint,
|
|
90
|
+
accept,
|
|
91
|
+
by,
|
|
92
|
+
})));
|
|
93
|
+
};
|
|
94
|
+
if (name === "confirm")
|
|
95
|
+
command
|
|
96
|
+
.argument("<ids...>", "candidate IDs to accept; other new candidates are rejected")
|
|
97
|
+
.action((id, ids, given) => review(id, given, ids));
|
|
98
|
+
else
|
|
99
|
+
command.action((id, given) => review(id, given, []));
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=command.js.map
|