@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
package/dist/rows.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { rowShapeOf, rowsOfEntity } from "@wirecat/cli-core";
|
|
2
|
+
const sender = { field: ["sender_is_me", "sender_name"], tag: "me" };
|
|
3
|
+
const fact = {
|
|
4
|
+
columns: [
|
|
5
|
+
{ field: "ref" },
|
|
6
|
+
{ field: "kind" },
|
|
7
|
+
{ field: "status" },
|
|
8
|
+
{ field: "subject_name" },
|
|
9
|
+
{ field: "project_name" },
|
|
10
|
+
{ field: ["occurred_at", "created_at"], as: "day" },
|
|
11
|
+
],
|
|
12
|
+
text: ["text"],
|
|
13
|
+
};
|
|
14
|
+
/** An order or an invoice, with a row per line under it. */
|
|
15
|
+
const LINED = {
|
|
16
|
+
columns: [{ field: "ref" }, { field: "title" }, { field: "status" }, { field: "review" }],
|
|
17
|
+
sections: { lines: "memo_money_line" },
|
|
18
|
+
};
|
|
19
|
+
/** A proposal as `review` lists it. */
|
|
20
|
+
export const PROPOSAL_ROW = {
|
|
21
|
+
columns: [
|
|
22
|
+
{ field: "id" },
|
|
23
|
+
{ field: "kind" },
|
|
24
|
+
{ field: "title" },
|
|
25
|
+
{ field: "score" },
|
|
26
|
+
{ field: "proposer" },
|
|
27
|
+
{ field: "created_at", as: "day" },
|
|
28
|
+
],
|
|
29
|
+
text: ["reason"],
|
|
30
|
+
};
|
|
31
|
+
/** A `review confirm` or `reject` answer: a line per proposal decided, then one per proposal refused. */
|
|
32
|
+
const DECISIONS = {
|
|
33
|
+
columns: [],
|
|
34
|
+
sections: { decided: "memo_decided", refused: "memo_refused" },
|
|
35
|
+
oneLine: true,
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* wcat's rows by command path. Most of wcat's answers are cli-core's shared entities (note, memory, task, hit), whose
|
|
39
|
+
* rows cli-core will not take from an app, so wcat keys its own by the command that answers them.
|
|
40
|
+
*/
|
|
41
|
+
export const ROWS = {
|
|
42
|
+
"search all": {
|
|
43
|
+
columns: [{ field: "ref" }, { field: "kind" }, { field: "timestamp", as: "time" }, { field: "title" }, sender],
|
|
44
|
+
text: ["excerpt"],
|
|
45
|
+
},
|
|
46
|
+
"search notes": {
|
|
47
|
+
columns: [{ field: "ref" }, { field: "updated_at", as: "day" }, { field: ["title", "path"] }],
|
|
48
|
+
text: ["excerpt"],
|
|
49
|
+
},
|
|
50
|
+
"search memories": fact,
|
|
51
|
+
"search people": { columns: [{ field: "ref" }, { field: "name" }] },
|
|
52
|
+
"notes list": {
|
|
53
|
+
columns: [
|
|
54
|
+
{ field: "ref" },
|
|
55
|
+
{ field: "updated_at", as: "day" },
|
|
56
|
+
{ field: "source" },
|
|
57
|
+
{ field: ["title", "path"] },
|
|
58
|
+
{ field: "via" },
|
|
59
|
+
],
|
|
60
|
+
text: ["text"],
|
|
61
|
+
},
|
|
62
|
+
"facts list": fact,
|
|
63
|
+
"invoices list": {
|
|
64
|
+
columns: [{ field: "ref" }, { field: "project_name" }, { field: ["issue_date", "created_at"], as: "day" }],
|
|
65
|
+
text: ["title"],
|
|
66
|
+
},
|
|
67
|
+
"payments list": {
|
|
68
|
+
columns: [{ field: "ref" }, { field: "project_name" }, { field: "date", as: "day" }],
|
|
69
|
+
text: ["title"],
|
|
70
|
+
},
|
|
71
|
+
"deals list": {
|
|
72
|
+
columns: [{ field: "ref" }, { field: "project_name" }, { field: "close_date", as: "day" }],
|
|
73
|
+
text: ["summary"],
|
|
74
|
+
},
|
|
75
|
+
"leads list": {
|
|
76
|
+
columns: [{ field: "ref" }, { field: "project_name" }, { field: "created_at", as: "day" }],
|
|
77
|
+
text: ["summary"],
|
|
78
|
+
},
|
|
79
|
+
"memories list": fact,
|
|
80
|
+
"people list": {
|
|
81
|
+
columns: [
|
|
82
|
+
{ field: "ref" },
|
|
83
|
+
{ field: "display_name" },
|
|
84
|
+
{ field: "contact" },
|
|
85
|
+
{ field: "owner", tag: "owner" },
|
|
86
|
+
{ field: "messages_from", as: "count", tag: "messages" },
|
|
87
|
+
{ field: "tasks", as: "count", tag: "tasks" },
|
|
88
|
+
{ field: "kind_signals" },
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
"people check": {
|
|
92
|
+
columns: [
|
|
93
|
+
{ field: "ref" },
|
|
94
|
+
{ field: "display_name" },
|
|
95
|
+
{ field: "contact" },
|
|
96
|
+
{ field: "kind" },
|
|
97
|
+
{ field: "same_name", tag: "same name" },
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
"events list": {
|
|
101
|
+
columns: [
|
|
102
|
+
{ field: "ref" },
|
|
103
|
+
{ field: ["starts_at", "ends_at"], as: "time" },
|
|
104
|
+
{ field: "event_type" },
|
|
105
|
+
{ field: "in" },
|
|
106
|
+
{ field: "title" },
|
|
107
|
+
],
|
|
108
|
+
text: ["description"],
|
|
109
|
+
},
|
|
110
|
+
"organizations list": { columns: [{ field: "ref" }, { field: "name" }, { field: "kind" }] },
|
|
111
|
+
"projects list": { columns: [{ field: "ref" }, { field: "key" }, { field: "name" }, { field: "kind" }] },
|
|
112
|
+
"relationships list": {
|
|
113
|
+
columns: [
|
|
114
|
+
{ field: "id" },
|
|
115
|
+
{ field: "from" },
|
|
116
|
+
{ field: "kind" },
|
|
117
|
+
{ field: "to" },
|
|
118
|
+
{ field: "role" },
|
|
119
|
+
{ field: "purpose" },
|
|
120
|
+
{ field: "confirmed", tag: "confirmed" },
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
"tasks list": {
|
|
124
|
+
columns: [
|
|
125
|
+
{ field: ["key", "ref", "id"] },
|
|
126
|
+
{ field: "state" },
|
|
127
|
+
{ field: "kind" },
|
|
128
|
+
{ field: "priority_label" },
|
|
129
|
+
{ field: "project_key" },
|
|
130
|
+
{ field: "due_at", as: "day" },
|
|
131
|
+
{ field: "source" },
|
|
132
|
+
],
|
|
133
|
+
text: ["title", "message.text"],
|
|
134
|
+
},
|
|
135
|
+
"messages show": {
|
|
136
|
+
columns: [
|
|
137
|
+
{ field: "ref" },
|
|
138
|
+
{ field: ["timestamp", "date"], as: "time" },
|
|
139
|
+
{ field: "chat_title" },
|
|
140
|
+
{ field: ["from", "sender_is_me", "sender_name"], tag: "me" },
|
|
141
|
+
{ field: "subject" },
|
|
142
|
+
{ field: "attachments", as: "files" },
|
|
143
|
+
],
|
|
144
|
+
text: ["text", "excerpt"],
|
|
145
|
+
},
|
|
146
|
+
"projects evidence": {
|
|
147
|
+
columns: [{ field: "project_ref" }],
|
|
148
|
+
sections: { items: "memo_evidence_item", people: "memo_evidence_person", linked_chats: "linked_chat" },
|
|
149
|
+
},
|
|
150
|
+
show: {
|
|
151
|
+
columns: [{ field: "ref" }, { field: "kind" }, { field: "state" }, { field: "title" }, { field: "open.line" }],
|
|
152
|
+
},
|
|
153
|
+
"wallets list": {
|
|
154
|
+
columns: [{ field: "ref" }, { field: "title" }, { field: "balance.amount" }, { field: "balance.currency" }],
|
|
155
|
+
},
|
|
156
|
+
"review show": { ...PROPOSAL_ROW, oneLine: true },
|
|
157
|
+
"review confirm": DECISIONS,
|
|
158
|
+
"review reject": DECISIONS,
|
|
159
|
+
"orders show": LINED,
|
|
160
|
+
"orders lines add": LINED,
|
|
161
|
+
"orders lines remove": LINED,
|
|
162
|
+
"invoices show": LINED,
|
|
163
|
+
"invoices lines add": LINED,
|
|
164
|
+
"invoices lines remove": LINED,
|
|
165
|
+
};
|
|
166
|
+
/** Rows for the lists inside an item answer, by the entity its row's `sections` names. */
|
|
167
|
+
const SECTION_ROWS = {
|
|
168
|
+
memo_evidence_item: {
|
|
169
|
+
columns: [{ field: "ref" }, { field: "context" }, { field: "kind" }, { field: "title" }],
|
|
170
|
+
text: ["text"],
|
|
171
|
+
},
|
|
172
|
+
memo_finance: {
|
|
173
|
+
columns: [
|
|
174
|
+
{ field: "direction" },
|
|
175
|
+
{ field: "currency" },
|
|
176
|
+
{ field: "billed" },
|
|
177
|
+
{ field: "paid" },
|
|
178
|
+
{ field: "owed" },
|
|
179
|
+
{ field: "invoices", as: "count", tag: "invoices" },
|
|
180
|
+
{ field: "payments", as: "count", tag: "payments" },
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
memo_deal: {
|
|
184
|
+
columns: [
|
|
185
|
+
{ field: "ref" },
|
|
186
|
+
{ field: "stage" },
|
|
187
|
+
{ field: "amount" },
|
|
188
|
+
{ field: "currency" },
|
|
189
|
+
{ field: "close_date", as: "day" },
|
|
190
|
+
],
|
|
191
|
+
text: ["title"],
|
|
192
|
+
},
|
|
193
|
+
memo_money_line: {
|
|
194
|
+
columns: [
|
|
195
|
+
{ field: "position" },
|
|
196
|
+
{ field: "quantity" },
|
|
197
|
+
{ field: "unit_price" },
|
|
198
|
+
{ field: "amount" },
|
|
199
|
+
{ field: "product" },
|
|
200
|
+
],
|
|
201
|
+
text: ["description"],
|
|
202
|
+
},
|
|
203
|
+
memo_decided: { columns: [{ field: "id" }, { field: "status" }, { field: "kind" }] },
|
|
204
|
+
memo_refused: { columns: [{ field: "id" }, { field: "code" }, { field: "reason" }], text: ["message"] },
|
|
205
|
+
memo_evidence_person: {
|
|
206
|
+
columns: [{ field: "person" }, { field: "name" }, { field: "items", as: "count", tag: "items" }],
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
const shared = rowsOfEntity();
|
|
210
|
+
export const sectionRowOf = (entity) => SECTION_ROWS[entity] ?? shared(entity);
|
|
211
|
+
const pathOf = (command) => {
|
|
212
|
+
const words = [];
|
|
213
|
+
for (let at = command; at?.parent; at = at.parent)
|
|
214
|
+
words.unshift(at.name());
|
|
215
|
+
return words.join(" ");
|
|
216
|
+
};
|
|
217
|
+
/** The row a wcat answer is drawn with: wcat's for this command, else cli-core's for its entity, else the generic one. */
|
|
218
|
+
export const rowOf = (command) => (command && ROWS[pathOf(command)]) || rowShapeOf(command);
|
|
219
|
+
//# sourceMappingURL=rows.js.map
|
package/dist/run/auto.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { CliError, resolvePaths } from "@wirecat/cli-base";
|
|
7
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
8
|
+
import { installerOf } from "@wirecat/cli-base/update";
|
|
9
|
+
import { failingNotice, LOCAL_READ, LOCAL_WRITE, recordRun } from "@wirecat/cli-core";
|
|
10
|
+
import { InvalidArgumentError } from "commander";
|
|
11
|
+
import { answers, itemAnswer } from "../answer.js";
|
|
12
|
+
import { loadConfig, updateConfig } from "../config.js";
|
|
13
|
+
export const DEFAULT_EVERY = "5m";
|
|
14
|
+
export const UNIT = "wcat-import";
|
|
15
|
+
const lastRunPath = (env) => join(resolvePaths({ appName: "wcat", prefix: "WCAT", env }).state, "auto", "last.json");
|
|
16
|
+
export const lastAutoRun = (env) => {
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(readFileSync(lastRunPath(env), "utf8"));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/** Only the timer's own runs count: a sync started by hand is watched by whoever started it. */
|
|
25
|
+
export const recordAutoRun = (env, at, reason) => {
|
|
26
|
+
if (env.WCAT_AUTO !== "1")
|
|
27
|
+
return;
|
|
28
|
+
recordRun(lastRunPath(env), {
|
|
29
|
+
at: new Date(at).toISOString(),
|
|
30
|
+
exitCode: reason === undefined ? 0 : 1,
|
|
31
|
+
output: `journalctl --user -u ${UNIT}.service`,
|
|
32
|
+
...(reason === undefined ? {} : { reason }),
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export const autoNotice = (env) => env.WCAT_AUTO === "1"
|
|
36
|
+
? undefined
|
|
37
|
+
: failingNotice("wcat", [{ job: "sync", last: lastAutoRun(env) }], "wcat jobs status");
|
|
38
|
+
/** `5m`, `90s`, `1h` → systemd's `5min`, `90s`, `1h`; under a minute is refused. */
|
|
39
|
+
export const interval = (value) => {
|
|
40
|
+
const match = /^(\d+)(s|m|h)$/.exec(value.trim());
|
|
41
|
+
const seconds = match === null ? 0 : Number(match[1]) * { s: 1, m: 60, h: 3600 }[match[2]];
|
|
42
|
+
if (seconds < 60)
|
|
43
|
+
throw new InvalidArgumentError("an interval of a minute or more, like 5m, 90s or 1h");
|
|
44
|
+
return value.trim();
|
|
45
|
+
};
|
|
46
|
+
const systemdSpan = (every) => every.replace(/m$/, "min");
|
|
47
|
+
export const unitDir = (env) => join(env.XDG_CONFIG_HOME ?? join(env.HOME ?? homedir(), ".config"), "systemd", "user");
|
|
48
|
+
const quote = (arg) => `"${arg.replace(/(["\\])/g, "\\$1")}"`;
|
|
49
|
+
const wcatBin = () => resolve(dirname(fileURLToPath(import.meta.url)), "../bin/wcat-wirecat.js");
|
|
50
|
+
/** The variables that move wcat's folders and the store; the timer runs with the ones set at `wcat jobs start`. */
|
|
51
|
+
export const PLACE_VARIABLES = [
|
|
52
|
+
"WCAT_CONFIG_DIR",
|
|
53
|
+
"WCAT_STATE_DIR",
|
|
54
|
+
"WCAT_CACHE_DIR",
|
|
55
|
+
"MESSAGING_STORE",
|
|
56
|
+
"WIRECAT_STATE_DIR",
|
|
57
|
+
];
|
|
58
|
+
export const placesOf = (env) => Object.fromEntries(PLACE_VARIABLES.flatMap((name) => (env[name] ? [[name, env[name]]] : [])));
|
|
59
|
+
const execStart = () => `ExecStart=${[process.execPath, wcatBin(), "sync"].map(quote).join(" ")}`;
|
|
60
|
+
export const serviceUnit = (env, places = {}) => [
|
|
61
|
+
"[Unit]",
|
|
62
|
+
"Description=wcat: sync notes into the shared store and embed stored mail",
|
|
63
|
+
"",
|
|
64
|
+
"[Service]",
|
|
65
|
+
"Type=oneshot",
|
|
66
|
+
execStart(),
|
|
67
|
+
// The programs wcat calls are found on the PATH wcat was set up with.
|
|
68
|
+
`Environment=${[`PATH=${env.PATH ?? ""}`, ...Object.entries(places).map(([name, value]) => `${name}=${value}`)]
|
|
69
|
+
.map(quote)
|
|
70
|
+
.join(" ")} WCAT_AUTO=1`,
|
|
71
|
+
"Nice=10",
|
|
72
|
+
"",
|
|
73
|
+
].join("\n");
|
|
74
|
+
export const timerUnit = (every) => [
|
|
75
|
+
"[Unit]",
|
|
76
|
+
`Description=wcat: sync notes and embed stored mail every ${every}`,
|
|
77
|
+
"",
|
|
78
|
+
"[Timer]",
|
|
79
|
+
"OnActiveSec=1min",
|
|
80
|
+
// From when a sync ends: counted from its start, a sync longer than the interval left no next run.
|
|
81
|
+
`OnUnitInactiveSec=${systemdSpan(every)}`,
|
|
82
|
+
"AccuracySec=30s",
|
|
83
|
+
"",
|
|
84
|
+
"[Install]",
|
|
85
|
+
"WantedBy=timers.target",
|
|
86
|
+
"",
|
|
87
|
+
].join("\n");
|
|
88
|
+
const systemctl = (env) => (...args) => new Promise((done, fail) => execFile(env.WCAT_SYSTEMCTL ?? "systemctl", ["--user", ...args], { env }, (error, stdout, stderr) => error === null
|
|
89
|
+
? done(stdout)
|
|
90
|
+
: fail(new CliError("provider_error", `systemctl ${args.join(" ")}: ${stderr.trim() || error.message}`, {
|
|
91
|
+
reason: "auto.systemctl-failed",
|
|
92
|
+
}))));
|
|
93
|
+
export const autoState = (config) => ({
|
|
94
|
+
enabled: config.auto?.enabled ?? false,
|
|
95
|
+
every: config.auto?.every ?? DEFAULT_EVERY,
|
|
96
|
+
places: config.auto?.places ?? {},
|
|
97
|
+
});
|
|
98
|
+
/**
|
|
99
|
+
* Makes the timer match the config: on with its interval, or gone. The config is the one source, so a
|
|
100
|
+
* hand edit of `auto` takes effect at the next timer run, which calls this first.
|
|
101
|
+
*/
|
|
102
|
+
export const applyAuto = async (env, state, unit = UNIT, path = env.PATH) => {
|
|
103
|
+
const run = systemctl(env);
|
|
104
|
+
const dir = unitDir(env);
|
|
105
|
+
const timerPath = join(dir, `${unit}.timer`);
|
|
106
|
+
const servicePath = join(dir, `${unit}.service`);
|
|
107
|
+
if (!state.enabled) {
|
|
108
|
+
if (!existsSync(timerPath) && !existsSync(servicePath))
|
|
109
|
+
return;
|
|
110
|
+
await run("disable", "--now", `${unit}.timer`).catch(() => "");
|
|
111
|
+
rmSync(timerPath, { force: true });
|
|
112
|
+
rmSync(servicePath, { force: true });
|
|
113
|
+
await run("daemon-reload");
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const wanted = {
|
|
117
|
+
[servicePath]: serviceUnit({ ...env, PATH: path }, state.places),
|
|
118
|
+
[timerPath]: timerUnit(state.every),
|
|
119
|
+
};
|
|
120
|
+
const stale = Object.entries(wanted).filter(([path, text]) => !existsSync(path) || readFileSync(path, "utf8") !== text);
|
|
121
|
+
if (stale.length === 0)
|
|
122
|
+
return;
|
|
123
|
+
mkdirSync(dir, { recursive: true });
|
|
124
|
+
for (const [path, text] of stale)
|
|
125
|
+
writeFileSync(path, text);
|
|
126
|
+
await run("daemon-reload");
|
|
127
|
+
await run("enable", "--now", `${unit}.timer`);
|
|
128
|
+
// A timer already running keeps its old interval until restarted.
|
|
129
|
+
if (stale.some(([path]) => path === timerPath))
|
|
130
|
+
await run("restart", `${unit}.timer`);
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Where a global install of npm, pnpm or Bun keeps its packages. A wcat in any other node_modules belongs to a
|
|
134
|
+
* project or a tool's private folder, which can be deleted at any time.
|
|
135
|
+
*/
|
|
136
|
+
export const globalRoots = (env, execPath = process.execPath) => {
|
|
137
|
+
const home = env.HOME ?? homedir();
|
|
138
|
+
const bin = dirname(execPath);
|
|
139
|
+
const npmPrefix = env.npm_config_prefix ?? env.NPM_CONFIG_PREFIX;
|
|
140
|
+
return [
|
|
141
|
+
resolve(bin, "..", "lib", "node_modules"),
|
|
142
|
+
resolve(bin, "node_modules"),
|
|
143
|
+
...(npmPrefix ? [resolve(npmPrefix, "lib", "node_modules"), resolve(npmPrefix, "node_modules")] : []),
|
|
144
|
+
"/usr/lib/node_modules",
|
|
145
|
+
"/usr/local/lib/node_modules",
|
|
146
|
+
resolve(env.PNPM_HOME ?? join(home, ".local", "share", "pnpm"), "global"),
|
|
147
|
+
resolve(env.BUN_INSTALL ?? join(home, ".bun"), "install", "global"),
|
|
148
|
+
];
|
|
149
|
+
};
|
|
150
|
+
const isGlobal = (scriptPath, roots) => roots.some((root) => scriptPath.startsWith(`${root}/`) || scriptPath.startsWith(`${root}\\`));
|
|
151
|
+
/**
|
|
152
|
+
* The timer runs the wcat that last ran here: after `nvm use` and an install under the new Node, the
|
|
153
|
+
* first wcat command points the unit at it, so removing the old Node does not leave the timer broken.
|
|
154
|
+
* Only a global install moves it: a checkout, `npx` or another tool's private install would point it at a
|
|
155
|
+
* folder that goes away.
|
|
156
|
+
*
|
|
157
|
+
* Any command runs this, a read too, from any caller's environment. So it changes the program line only, keeps the
|
|
158
|
+
* PATH the timer was set up with, and never enables, starts or restarts the timer: one stopped by hand stays stopped.
|
|
159
|
+
*/
|
|
160
|
+
export const followInstall = async (env, scriptPath, roots = globalRoots(env)) => {
|
|
161
|
+
if (env.WCAT_AUTO === "1")
|
|
162
|
+
return;
|
|
163
|
+
scriptPath ??= realpathSync(wcatBin());
|
|
164
|
+
if (!["npm", "pnpm", "bun"].includes(installerOf(scriptPath)))
|
|
165
|
+
return;
|
|
166
|
+
if (!isGlobal(scriptPath, roots))
|
|
167
|
+
return;
|
|
168
|
+
if (!autoState(loadConfig(env)).enabled)
|
|
169
|
+
return;
|
|
170
|
+
const servicePath = join(unitDir(env), `${UNIT}.service`);
|
|
171
|
+
if (!existsSync(servicePath))
|
|
172
|
+
return;
|
|
173
|
+
const current = readFileSync(servicePath, "utf8");
|
|
174
|
+
const moved = current.replace(/^ExecStart=.*$/m, execStart());
|
|
175
|
+
if (moved === current)
|
|
176
|
+
return;
|
|
177
|
+
writeFileSync(servicePath, moved);
|
|
178
|
+
await systemctl(env)("daemon-reload");
|
|
179
|
+
};
|
|
180
|
+
const failingOf = (last) => last && last.exitCode !== 0
|
|
181
|
+
? { since: last.failingSince ?? last.at, runs: last.failures ?? 1, reason: last.reason ?? null, log: last.output }
|
|
182
|
+
: null;
|
|
183
|
+
export const autoCommand = (program, streams, env) => {
|
|
184
|
+
const run = systemctl(env);
|
|
185
|
+
const { print } = answers(program, streams, env);
|
|
186
|
+
const auto = program.command("jobs").description("run wcat sync on a systemd user timer, set in the config");
|
|
187
|
+
annotate(auto.command("start"), { effects: LOCAL_WRITE })
|
|
188
|
+
.description("sync every --every (default auto.every, else 5m), starting a minute from now")
|
|
189
|
+
.option("--every <duration>", "how often: 5m, 90s, 1h — a minute or more", interval)
|
|
190
|
+
.action(async (options) => {
|
|
191
|
+
const config = updateConfig((current) => ({
|
|
192
|
+
...current,
|
|
193
|
+
auto: { enabled: true, every: options.every ?? autoState(current).every, places: placesOf(env) },
|
|
194
|
+
}), env);
|
|
195
|
+
await applyAuto(env, autoState(config));
|
|
196
|
+
streams.data(`wcat sync runs every ${autoState(config).every}.\n`);
|
|
197
|
+
});
|
|
198
|
+
annotate(auto.command("stop"), { effects: LOCAL_WRITE })
|
|
199
|
+
.description("stop syncing on a timer and remove the timer")
|
|
200
|
+
.action(async () => {
|
|
201
|
+
const config = updateConfig((current) => ({ ...current, auto: { ...current.auto, enabled: false } }), env);
|
|
202
|
+
await applyAuto(env, autoState(config));
|
|
203
|
+
streams.data("wcat sync no longer runs on a timer.\n");
|
|
204
|
+
});
|
|
205
|
+
annotate(auto.command("status"), { effects: LOCAL_READ })
|
|
206
|
+
.description("whether the timer is on, its interval, its next run and how the last one ended")
|
|
207
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
208
|
+
.action(async (options) => {
|
|
209
|
+
const state = autoState(loadConfig(env));
|
|
210
|
+
const show = async (unit, properties) => Object.fromEntries((await run("show", unit, "--property", properties).catch(() => ""))
|
|
211
|
+
.split("\n")
|
|
212
|
+
.filter(Boolean)
|
|
213
|
+
.map((line) => [line.slice(0, line.indexOf("=")), line.slice(line.indexOf("=") + 1)]));
|
|
214
|
+
const timer = await show(`${UNIT}.timer`, "ActiveState");
|
|
215
|
+
const service = await show(`${UNIT}.service`, "Result");
|
|
216
|
+
// list-timers gives wall-clock times for every kind of timer; `show` leaves them empty for these.
|
|
217
|
+
const listed = JSON.parse((await run("list-timers", `${UNIT}.timer`, "--output=json").catch(() => "[]")) || "[]")[0];
|
|
218
|
+
const when = (micros) => typeof micros === "number" && micros > 0 ? new Date(micros / 1000).toISOString() : null;
|
|
219
|
+
const status = {
|
|
220
|
+
...state,
|
|
221
|
+
timer: timer.ActiveState ?? "unknown",
|
|
222
|
+
next: when(listed?.next),
|
|
223
|
+
last: when(listed?.last),
|
|
224
|
+
lastResult: service.Result || null,
|
|
225
|
+
failing: failingOf(lastAutoRun(env)),
|
|
226
|
+
};
|
|
227
|
+
print(options.json, itemAnswer(status), `${status.enabled ? `on, every ${status.every}` : "off"} — timer ${status.timer}` +
|
|
228
|
+
(status.next ? `, next ${status.next}` : "") +
|
|
229
|
+
(status.last ? `, last ${status.last} (${status.lastResult ?? "?"})` : "") +
|
|
230
|
+
(status.failing
|
|
231
|
+
? `\nfailing since ${status.failing.since} (${status.failing.runs} runs)` +
|
|
232
|
+
(status.failing.reason ? `: ${status.failing.reason}` : "") +
|
|
233
|
+
`\nthe full message: ${status.failing.log}`
|
|
234
|
+
: ""));
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
//# sourceMappingURL=auto.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { errorObjectOf, exitCodeOfError, processStreams, renderError } from "@wirecat/cli-base";
|
|
2
|
+
import { APP } from "../app.js";
|
|
3
|
+
import { interactiveOf } from "../terminal.js";
|
|
4
|
+
/**
|
|
5
|
+
* wcat as `startCli` runs it. Under `commands --serve` several requests run at once, so each keeps its own program:
|
|
6
|
+
* commander holds parsed options on the command, and a shared one answered every request with the last one's options.
|
|
7
|
+
*/
|
|
8
|
+
export const memoEntry = (io) => {
|
|
9
|
+
const programs = new WeakMap();
|
|
10
|
+
let failure;
|
|
11
|
+
return {
|
|
12
|
+
app: APP,
|
|
13
|
+
sqlite: true,
|
|
14
|
+
interactive: interactiveOf,
|
|
15
|
+
reasons: APP.errors.reasons,
|
|
16
|
+
...(io === undefined ? {} : { io }),
|
|
17
|
+
run: async (entry) => {
|
|
18
|
+
// failure.js loads cli-core's whole command tree, which a bare --version never needs.
|
|
19
|
+
failure = await import("../failure.js");
|
|
20
|
+
// A static import would load the store's SQLite before startCli could swap it.
|
|
21
|
+
const { createProgram, liftGroup, refuseJoinedPath } = await import("../program.js");
|
|
22
|
+
const { autoNotice, followInstall } = await import("./auto.js");
|
|
23
|
+
const lifting = createProgram({ signal: entry.signal });
|
|
24
|
+
programs.set(entry, lifting);
|
|
25
|
+
const { group, rest: args } = await liftGroup(lifting, entry.args, entry.env);
|
|
26
|
+
const program = group === undefined ? lifting : createProgram({ signal: entry.signal, group });
|
|
27
|
+
programs.set(entry, program);
|
|
28
|
+
// `wcat jobs status` says it in full; everywhere else one line, until a timer run passes again.
|
|
29
|
+
if (args[0] !== "jobs") {
|
|
30
|
+
const notice = autoNotice(entry.env);
|
|
31
|
+
if (notice)
|
|
32
|
+
processStreams.diagnostic(notice);
|
|
33
|
+
}
|
|
34
|
+
const { updateNotice } = await import("../update.js");
|
|
35
|
+
const notice = updateNotice(args);
|
|
36
|
+
program.hook("preAction", (_root, command) => entry.atStart(command));
|
|
37
|
+
failure.throwParseFailures(program);
|
|
38
|
+
refuseJoinedPath(program, args);
|
|
39
|
+
await program.parseAsync(args, { from: "user" });
|
|
40
|
+
// After the command, so a broken systemctl never stands between the owner and the answer.
|
|
41
|
+
await followInstall(entry.env).catch(() => undefined);
|
|
42
|
+
const line = await notice;
|
|
43
|
+
if (line && !process.exitCode)
|
|
44
|
+
processStreams.diagnostic(line);
|
|
45
|
+
return undefined;
|
|
46
|
+
},
|
|
47
|
+
fail: (error, entry) => {
|
|
48
|
+
if (failure)
|
|
49
|
+
return failure.reportFailure(error, {
|
|
50
|
+
args: entry.args,
|
|
51
|
+
program: programs.get(entry),
|
|
52
|
+
streams: processStreams,
|
|
53
|
+
tty: entry.tty,
|
|
54
|
+
});
|
|
55
|
+
// Before run loaded failure.js: the SQLite swap, or the import itself.
|
|
56
|
+
const object = errorObjectOf(error);
|
|
57
|
+
processStreams.diagnostic(renderError(object, { cli: APP.command, interactive: interactiveOf(entry.args, entry.tty) }));
|
|
58
|
+
return exitCodeOfError(object);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=entry.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { findOnPath } from "@wirecat/cli-base/wcat";
|
|
3
|
+
export const FILES_PROGRAM = "wcat-files";
|
|
4
|
+
const failure = (reasonId, reason, code = "internal_error") => ({
|
|
5
|
+
ran: true,
|
|
6
|
+
notes: [],
|
|
7
|
+
failed: [{ source: "notes", code, reasonId, reason }],
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Notes belong to the files CLI now, so `wcat sync` runs `wcat-files sync --json` when it is on PATH and reports its
|
|
11
|
+
* folders as its own. Its stderr goes to ours, so its progress lines still show.
|
|
12
|
+
*/
|
|
13
|
+
export const filesSync = (env, { embed, signal, platform = process.platform }) => {
|
|
14
|
+
const [program] = findOnPath(FILES_PROGRAM, { env, platform });
|
|
15
|
+
if (program === undefined)
|
|
16
|
+
return Promise.resolve({ ran: false });
|
|
17
|
+
const args = ["sync", "--json", ...(embed ? [] : ["--no-embed"])];
|
|
18
|
+
return new Promise((done) => {
|
|
19
|
+
const child = execFile(program, args, {
|
|
20
|
+
env,
|
|
21
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
22
|
+
// A .cmd needs a shell on Windows; every argument here is a fixed word.
|
|
23
|
+
shell: platform === "win32" && /\.(cmd|bat)$/i.test(program),
|
|
24
|
+
...(signal ? { signal } : {}),
|
|
25
|
+
}, (error, stdout) => {
|
|
26
|
+
let answer;
|
|
27
|
+
try {
|
|
28
|
+
answer = JSON.parse(stdout);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
done(failure("files.sync-failed", `files sync failed: ${error?.message.split("\n")[0] ?? "no answer"}`));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (answer.item === undefined) {
|
|
35
|
+
const reason = answer.error?.message ?? "files sync answered no item";
|
|
36
|
+
done(failure(answer.error?.reason ?? "files.sync-failed", reason, answer.error?.code ?? "internal_error"));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const { notes = [], notesEmbedded, enrichment, failed = [] } = answer.item;
|
|
40
|
+
done({
|
|
41
|
+
ran: true,
|
|
42
|
+
notes,
|
|
43
|
+
...(notesEmbedded ? { notesEmbedded } : {}),
|
|
44
|
+
...(enrichment ? { enrichment } : {}),
|
|
45
|
+
failed,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
child.stderr?.pipe(process.stderr);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=files.js.map
|