@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.
Files changed (230) hide show
  1. package/LICENSE +204 -0
  2. package/README.md +400 -2
  3. package/THIRD_PARTY_NOTICES +2 -0
  4. package/contracts/wirecat.json +4612 -0
  5. package/dist/actions/actions.js +269 -0
  6. package/dist/actions/command.js +102 -0
  7. package/dist/agents/command.js +17 -0
  8. package/dist/agents/log.js +23 -0
  9. package/dist/answer.js +100 -0
  10. package/dist/answers/command.js +128 -0
  11. package/dist/app.js +15 -0
  12. package/dist/author.js +109 -0
  13. package/dist/bin/wcat-wirecat.js +40 -0
  14. package/dist/bots/command.js +175 -0
  15. package/dist/bundle/auto-YETGUQ2J.js +43 -0
  16. package/dist/bundle/chunk-3ME37WWB.js +31 -0
  17. package/dist/bundle/chunk-4WI3FO7T.js +395 -0
  18. package/dist/bundle/chunk-7O7XM37N.js +2 -0
  19. package/dist/bundle/chunk-DWQQRBQV.js +51 -0
  20. package/dist/bundle/chunk-FOWR5KJS.js +72 -0
  21. package/dist/bundle/chunk-GGRL6DTE.js +120 -0
  22. package/dist/bundle/chunk-KNFSW562.js +312 -0
  23. package/dist/bundle/chunk-KPJVVFQF.js +416 -0
  24. package/dist/bundle/chunk-WMPDRWVF.js +222 -0
  25. package/dist/bundle/chunk-X5OK73GU.js +807 -0
  26. package/dist/bundle/chunk-ZC4PRE6C.js +38 -0
  27. package/dist/bundle/entry-S4DSYEAY.js +64 -0
  28. package/dist/bundle/failure-FALOD7QW.js +19 -0
  29. package/dist/bundle/from-memo-XVOLSUOM.js +314 -0
  30. package/dist/bundle/program-XSZSINBU.js +14994 -0
  31. package/dist/bundle/server-GQ4NZUDL.js +303 -0
  32. package/dist/bundle/update-2EH5KHTV.js +22 -0
  33. package/dist/bundle/wcat-wirecat.js +83 -0
  34. package/dist/config-command.js +39 -0
  35. package/dist/config-issues.js +15 -0
  36. package/dist/config.js +187 -0
  37. package/dist/context/command.js +162 -0
  38. package/dist/context/context.js +197 -0
  39. package/dist/contract-overrides/commands.js +81 -0
  40. package/dist/contract-overrides/mcp.js +241 -0
  41. package/dist/contract-overrides/meetings.js +344 -0
  42. package/dist/contract-overrides/search.js +508 -0
  43. package/dist/contract-overrides/skill.js +85 -0
  44. package/dist/contract-overrides.js +7 -0
  45. package/dist/digest/backfill.js +175 -0
  46. package/dist/digest/brief.js +189 -0
  47. package/dist/digest/catch-up-record.js +30 -0
  48. package/dist/digest/catch-up.js +86 -0
  49. package/dist/digest/command.js +110 -0
  50. package/dist/digest/digest-commands.js +327 -0
  51. package/dist/digest/digest.js +560 -0
  52. package/dist/digest/digests.js +213 -0
  53. package/dist/digest/history.js +202 -0
  54. package/dist/digest/input.js +30 -0
  55. package/dist/digest/known.js +28 -0
  56. package/dist/digest/sources.js +155 -0
  57. package/dist/digest/sync-health.js +158 -0
  58. package/dist/digest/task-proposals.js +67 -0
  59. package/dist/digest/tasks.js +145 -0
  60. package/dist/digest/text.js +49 -0
  61. package/dist/discovery/command.js +107 -0
  62. package/dist/doctor/command.js +167 -0
  63. package/dist/documents/command.js +107 -0
  64. package/dist/domain-lists/command.js +13 -0
  65. package/dist/events/command.js +35 -0
  66. package/dist/events/events.js +196 -0
  67. package/dist/examples.js +609 -0
  68. package/dist/facts/command.js +100 -0
  69. package/dist/facts/fact.js +54 -0
  70. package/dist/facts/facts.js +15 -0
  71. package/dist/failure.js +58 -0
  72. package/dist/finance/command.js +121 -0
  73. package/dist/finance/contracts-command.js +109 -0
  74. package/dist/finance/deal-text.js +34 -0
  75. package/dist/finance/deals-command.js +346 -0
  76. package/dist/finance/finance.js +129 -0
  77. package/dist/finance/lines-command.js +70 -0
  78. package/dist/finance/orders-command.js +94 -0
  79. package/dist/finance/products-command.js +98 -0
  80. package/dist/finance/subscriptions-command.js +152 -0
  81. package/dist/finance/transactions-command.js +136 -0
  82. package/dist/finance/wallets-command.js +105 -0
  83. package/dist/finance/written.js +36 -0
  84. package/dist/findings/command.js +102 -0
  85. package/dist/findings-input.js +23 -0
  86. package/dist/identity.js +20 -0
  87. package/dist/install/postinstall.js +47 -0
  88. package/dist/json-fields.js +48 -0
  89. package/dist/knowledge/business-text.js +19 -0
  90. package/dist/knowledge/command.js +435 -0
  91. package/dist/knowledge/document-context.js +33 -0
  92. package/dist/knowledge/key-documents.js +120 -0
  93. package/dist/knowledge/list-queries.js +20 -0
  94. package/dist/knowledge/meeting-projects-command.js +61 -0
  95. package/dist/knowledge/messenger-sync.js +253 -0
  96. package/dist/knowledge/money-text.js +16 -0
  97. package/dist/knowledge/notes-about.js +81 -0
  98. package/dist/knowledge/organization-delete-command.js +44 -0
  99. package/dist/knowledge/organization-text.js +27 -0
  100. package/dist/knowledge/project-actions-command.js +130 -0
  101. package/dist/knowledge/project-actions.js +104 -0
  102. package/dist/knowledge/project-activity-command.js +70 -0
  103. package/dist/knowledge/project-context.js +101 -0
  104. package/dist/knowledge/project-findings.js +41 -0
  105. package/dist/knowledge/project-gather-command.js +100 -0
  106. package/dist/knowledge/project-status-command.js +129 -0
  107. package/dist/knowledge/project-transfer-command.js +58 -0
  108. package/dist/knowledge/project-transfer.js +107 -0
  109. package/dist/knowledge/relationships-scan.js +116 -0
  110. package/dist/knowledge/relationships.js +115 -0
  111. package/dist/knowledge/roles-command.js +67 -0
  112. package/dist/mail/command.js +20 -0
  113. package/dist/mail/findings-command.js +143 -0
  114. package/dist/mail/findings-duplicates.js +159 -0
  115. package/dist/mail/messages-command.js +77 -0
  116. package/dist/mail/review-command.js +59 -0
  117. package/dist/mail/subscriptions-command.js +84 -0
  118. package/dist/mcp/catalogue.js +159 -0
  119. package/dist/mcp/command.js +125 -0
  120. package/dist/mcp/granted.js +18 -0
  121. package/dist/mcp/permissions.js +61 -0
  122. package/dist/mcp/server.js +128 -0
  123. package/dist/meetings/command.js +31 -0
  124. package/dist/meetings/list-command.js +59 -0
  125. package/dist/meetings/preparation-command.js +42 -0
  126. package/dist/meetings/preparation-text.js +44 -0
  127. package/dist/meetings/preparation.js +50 -0
  128. package/dist/meetings/read.js +32 -0
  129. package/dist/memories/command.js +105 -0
  130. package/dist/memories/memories.js +17 -0
  131. package/dist/memories/memory.js +89 -0
  132. package/dist/memories/sources.js +111 -0
  133. package/dist/mentions/command.js +91 -0
  134. package/dist/migrate/check.js +48 -0
  135. package/dist/migrate/from-memo.js +345 -0
  136. package/dist/migrate/skill.js +35 -0
  137. package/dist/models/command.js +19 -0
  138. package/dist/options.js +35 -0
  139. package/dist/output.js +17 -0
  140. package/dist/page.js +14 -0
  141. package/dist/people/command.js +144 -0
  142. package/dist/people/delete-command.js +53 -0
  143. package/dist/people/doubts-command.js +81 -0
  144. package/dist/people/identities-command.js +188 -0
  145. package/dist/people/identity.js +42 -0
  146. package/dist/people/owner.js +14 -0
  147. package/dist/people/proposal-rows.js +70 -0
  148. package/dist/people/proposals-command.js +248 -0
  149. package/dist/people/review-context.js +108 -0
  150. package/dist/people/subject.js +19 -0
  151. package/dist/program.js +875 -0
  152. package/dist/read-only.js +51 -0
  153. package/dist/reasons.js +368 -0
  154. package/dist/records/import.js +135 -0
  155. package/dist/records/input.js +210 -0
  156. package/dist/records/mapping.js +80 -0
  157. package/dist/records/record-commands.js +125 -0
  158. package/dist/records/sources.js +73 -0
  159. package/dist/refs.js +28 -0
  160. package/dist/review/command.js +171 -0
  161. package/dist/review/kinds.js +44 -0
  162. package/dist/review/review.js +299 -0
  163. package/dist/review/status.js +93 -0
  164. package/dist/rows.js +219 -0
  165. package/dist/run/auto.js +237 -0
  166. package/dist/run/entry.js +62 -0
  167. package/dist/run/files.js +51 -0
  168. package/dist/run/import.js +253 -0
  169. package/dist/run/lock.js +20 -0
  170. package/dist/save-help.js +3 -0
  171. package/dist/schedule/command.js +58 -0
  172. package/dist/schedule/mail-triage-input.js +152 -0
  173. package/dist/schedule/task-triage-input.js +152 -0
  174. package/dist/search/answers.js +176 -0
  175. package/dist/search/command.js +257 -0
  176. package/dist/search/denied.js +9 -0
  177. package/dist/search/embed.js +126 -0
  178. package/dist/search/hits.js +4 -0
  179. package/dist/search/lane-gates.js +76 -0
  180. package/dist/search/notes-text.js +18 -0
  181. package/dist/search/people.js +88 -0
  182. package/dist/search/search.js +306 -0
  183. package/dist/show/command.js +179 -0
  184. package/dist/store/crm-viewer.js +102 -0
  185. package/dist/store/group.js +112 -0
  186. package/dist/store/groups-command.js +136 -0
  187. package/dist/store/guard.js +94 -0
  188. package/dist/store/held.js +21 -0
  189. package/dist/store/info-command.js +37 -0
  190. package/dist/store/scope.js +53 -0
  191. package/dist/store/source-list.js +222 -0
  192. package/dist/store/source-target.js +28 -0
  193. package/dist/tags/command.js +176 -0
  194. package/dist/tasks/command.js +174 -0
  195. package/dist/tasks/context.js +74 -0
  196. package/dist/tasks/list.js +199 -0
  197. package/dist/tasks/proposal-duplicates.js +70 -0
  198. package/dist/tasks/relations-command.js +28 -0
  199. package/dist/tasks/shared.js +105 -0
  200. package/dist/tasks/tasks.js +197 -0
  201. package/dist/templates/command.js +18 -0
  202. package/dist/terminal.js +23 -0
  203. package/dist/update.js +35 -0
  204. package/dist/version.js +2 -0
  205. package/dist/vocabulary/command.js +103 -0
  206. package/dist/vocabulary/inspect.js +23 -0
  207. package/dist/vocabulary/inspection.js +18 -0
  208. package/dist/vocabulary/list.js +18 -0
  209. package/dist/vocabulary/project.js +19 -0
  210. package/dist/wcat.js +3 -0
  211. package/install/postinstall.mjs +9 -0
  212. package/package.json +89 -4
  213. package/scenarios/decision-trail.md +21 -0
  214. package/scenarios/person-brief.md +35 -0
  215. package/scenarios/prepare-meeting.md +17 -0
  216. package/scenarios/project-state.md +26 -0
  217. package/scenarios/set-up.md +18 -0
  218. package/scenarios/start-the-day.md +19 -0
  219. package/skills/mail-triage/SKILL.md +208 -0
  220. package/skills/morning-digest/SKILL.md +147 -0
  221. package/skills/task-triage/SKILL.md +79 -0
  222. package/skills/wcat/SKILL.md +65 -0
  223. package/skills/wcat/topics/mail.md +32 -0
  224. package/skills/wcat/topics/mcp.md +22 -0
  225. package/skills/wcat/topics/meetings.md +37 -0
  226. package/skills/wcat/topics/money.md +52 -0
  227. package/skills/wcat/topics/projects.md +54 -0
  228. package/skills/wcat/topics/proposals.md +113 -0
  229. package/skills/wcat/topics/search.md +85 -0
  230. package/skills/wcat/topics/vocabulary.md +8 -0
@@ -0,0 +1,38 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ APP,
5
+ __name
6
+ } from "./chunk-4WI3FO7T.js";
7
+
8
+ // dist/migrate/skill.js
9
+ import { readFileSync, rmSync } from "node:fs";
10
+ import { dirname, join } from "node:path";
11
+ import { installSkill, skillPath, skillVersion } from "@wirecat/cli-base/skill";
12
+ var OLD_SKILL_NAME = /^name:\s*["']?cli-memo["']?\s*$/m;
13
+ var memoSkills = /* @__PURE__ */ __name((env) => ["claude", "agents"].map((target) => ({ target, folder: dirname(skillPath(target, "cli-memo", env)) })).filter(({ folder }) => {
14
+ try {
15
+ const text = readFileSync(join(folder, "SKILL.md"), "utf8");
16
+ return OLD_SKILL_NAME.test(text) && skillVersion(text) !== void 0;
17
+ } catch {
18
+ return false;
19
+ }
20
+ }), "memoSkills");
21
+ var removeMemoSkills = /* @__PURE__ */ __name((env) => {
22
+ const found = memoSkills(env);
23
+ for (const { folder } of found)
24
+ rmSync(folder, { recursive: true, force: true });
25
+ return found.map(({ target }) => target);
26
+ }, "removeMemoSkills");
27
+ var SKILL = new URL("../../skills/wcat/SKILL.md", new URL("../migrate/skill.js", import.meta.url).href);
28
+ var replaceMemoSkill = /* @__PURE__ */ __name((env, skill = SKILL) => {
29
+ const found = memoSkills(env);
30
+ if (found.length > 0)
31
+ installSkill(APP, skill, { env, targets: found.map(({ target }) => target) });
32
+ return removeMemoSkills(env);
33
+ }, "replaceMemoSkill");
34
+
35
+ export {
36
+ removeMemoSkills,
37
+ replaceMemoSkill
38
+ };
@@ -0,0 +1,64 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ interactiveOf
5
+ } from "./chunk-3ME37WWB.js";
6
+ import {
7
+ APP,
8
+ __name
9
+ } from "./chunk-4WI3FO7T.js";
10
+
11
+ // dist/run/entry.js
12
+ import { errorObjectOf, exitCodeOfError, processStreams, renderError } from "@wirecat/cli-base";
13
+ var memoEntry = /* @__PURE__ */ __name((io) => {
14
+ const programs = /* @__PURE__ */ new WeakMap();
15
+ let failure;
16
+ return {
17
+ app: APP,
18
+ sqlite: true,
19
+ interactive: interactiveOf,
20
+ reasons: APP.errors.reasons,
21
+ ...io === void 0 ? {} : { io },
22
+ run: /* @__PURE__ */ __name(async (entry) => {
23
+ failure = await import("./failure-FALOD7QW.js");
24
+ const { createProgram, liftGroup, refuseJoinedPath } = await import("./program-XSZSINBU.js");
25
+ const { autoNotice, followInstall } = await import("./auto-YETGUQ2J.js");
26
+ const lifting = createProgram({ signal: entry.signal });
27
+ programs.set(entry, lifting);
28
+ const { group, rest: args } = await liftGroup(lifting, entry.args, entry.env);
29
+ const program = group === void 0 ? lifting : createProgram({ signal: entry.signal, group });
30
+ programs.set(entry, program);
31
+ if (args[0] !== "jobs") {
32
+ const notice2 = autoNotice(entry.env);
33
+ if (notice2)
34
+ processStreams.diagnostic(notice2);
35
+ }
36
+ const { updateNotice } = await import("./update-2EH5KHTV.js");
37
+ const notice = updateNotice(args);
38
+ program.hook("preAction", (_root, command) => entry.atStart(command));
39
+ failure.throwParseFailures(program);
40
+ refuseJoinedPath(program, args);
41
+ await program.parseAsync(args, { from: "user" });
42
+ await followInstall(entry.env).catch(() => void 0);
43
+ const line = await notice;
44
+ if (line && !process.exitCode)
45
+ processStreams.diagnostic(line);
46
+ return void 0;
47
+ }, "run"),
48
+ fail: /* @__PURE__ */ __name((error, entry) => {
49
+ if (failure)
50
+ return failure.reportFailure(error, {
51
+ args: entry.args,
52
+ program: programs.get(entry),
53
+ streams: processStreams,
54
+ tty: entry.tty
55
+ });
56
+ const object = errorObjectOf(error);
57
+ processStreams.diagnostic(renderError(object, { cli: APP.command, interactive: interactiveOf(entry.args, entry.tty) }));
58
+ return exitCodeOfError(object);
59
+ }, "fail")
60
+ };
61
+ }, "memoEntry");
62
+ export {
63
+ memoEntry
64
+ };
@@ -0,0 +1,19 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ errorObject,
5
+ mcpFailure,
6
+ recognisable,
7
+ reportFailure,
8
+ throwParseFailures
9
+ } from "./chunk-FOWR5KJS.js";
10
+ import "./chunk-X5OK73GU.js";
11
+ import "./chunk-3ME37WWB.js";
12
+ import "./chunk-4WI3FO7T.js";
13
+ export {
14
+ errorObject,
15
+ mcpFailure,
16
+ recognisable,
17
+ reportFailure,
18
+ throwParseFailures
19
+ };
@@ -0,0 +1,314 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ replaceMemoSkill
5
+ } from "./chunk-ZC4PRE6C.js";
6
+ import {
7
+ applyAuto,
8
+ autoState,
9
+ unitDir
10
+ } from "./chunk-WMPDRWVF.js";
11
+ import "./chunk-7O7XM37N.js";
12
+ import "./chunk-KPJVVFQF.js";
13
+ import "./chunk-KNFSW562.js";
14
+ import "./chunk-X5OK73GU.js";
15
+ import {
16
+ APP,
17
+ __name
18
+ } from "./chunk-4WI3FO7T.js";
19
+
20
+ // dist/migrate/from-memo.js
21
+ import { closeSync, cpSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmdirSync, rmSync, statSync, writeFileSync } from "node:fs";
22
+ import { dirname, join } from "node:path";
23
+ import { isMovedRun, resolvePaths, systemKeyring } from "@wirecat/cli-base";
24
+ import { pauseSchedule, readSchedule, thisMachine, writeSchedule } from "@wirecat/cli-core";
25
+ var OLD_APP = { ...APP, command: "memo", appName: "cli-memo", envPrefix: "MEMO" };
26
+ var OLD_JOBS_UNIT = "memo-import";
27
+ var NEW_PREFIX = `${APP.envPrefix}_`;
28
+ var OLD_PREFIX = `${OLD_APP.envPrefix}_`;
29
+ var MARKER = "migrated-from-memo.json";
30
+ var PENDING_SCHEDULES = "migrating-schedules.json";
31
+ var LOCK_STALE_MS = 5 * 6e4;
32
+ var FIXED_ACCOUNTS = [
33
+ "embeddings:openai",
34
+ "embeddings:anthropic",
35
+ "embeddings:endpoint:openai",
36
+ "embeddings:endpoint:anthropic",
37
+ // A key the owner stored by hand under the provider's own name, which cli-core still reads.
38
+ "openai",
39
+ "anthropic",
40
+ "registries:cas"
41
+ ];
42
+ var isEmptyDir = /* @__PURE__ */ __name((path) => {
43
+ try {
44
+ return statSync(path).isDirectory() && readdirSync(path).length === 0;
45
+ } catch {
46
+ return false;
47
+ }
48
+ }, "isEmptyDir");
49
+ var readJson = /* @__PURE__ */ __name((path) => {
50
+ try {
51
+ return JSON.parse(readFileSync(path, "utf8"));
52
+ } catch {
53
+ return void 0;
54
+ }
55
+ }, "readJson");
56
+ var moveFolder = /* @__PURE__ */ __name((from, to) => {
57
+ mkdirSync(dirname(to), { recursive: true });
58
+ try {
59
+ renameSync(from, to);
60
+ } catch (error) {
61
+ if (error.code !== "EXDEV")
62
+ throw error;
63
+ const partial = `${to}.moving`;
64
+ rmSync(partial, { recursive: true, force: true });
65
+ cpSync(from, partial, { recursive: true, preserveTimestamps: true, verbatimSymlinks: true });
66
+ renameSync(partial, to);
67
+ rmSync(from, { recursive: true, force: true });
68
+ }
69
+ try {
70
+ if (isEmptyDir(dirname(from)) && dirname(from).endsWith(OLD_APP.appName))
71
+ rmdirSync(dirname(from));
72
+ } catch {
73
+ }
74
+ }, "moveFolder");
75
+ var KINDS = ["config", "state", "cache"];
76
+ var moveFolders = /* @__PURE__ */ __name((old, now) => {
77
+ const kept = [];
78
+ for (const kind of KINDS) {
79
+ if (!existsSync(old[kind]))
80
+ continue;
81
+ if (existsSync(now[kind]) && !isEmptyDir(now[kind])) {
82
+ kept.push(kind);
83
+ continue;
84
+ }
85
+ if (isEmptyDir(now[kind]))
86
+ rmdirSync(now[kind]);
87
+ moveFolder(old[kind], now[kind]);
88
+ }
89
+ return kept;
90
+ }, "moveFolders");
91
+ var moveHttpTokens = /* @__PURE__ */ __name((state) => {
92
+ for (const ending of [".json", ".lock"]) {
93
+ const from = join(state, "mcp-http", `memo${ending}`);
94
+ const to = join(state, "mcp-http", `wcat${ending}`);
95
+ if (existsSync(from) && !existsSync(to))
96
+ renameSync(from, to);
97
+ }
98
+ }, "moveHttpTokens");
99
+ var endpointKey = /* @__PURE__ */ __name((url) => {
100
+ try {
101
+ const host = new URL(url).host;
102
+ return ["openai", "anthropic"].includes(host) ? `endpoint:${host}` : host;
103
+ } catch {
104
+ return void 0;
105
+ }
106
+ }, "endpointKey");
107
+ var addressesIn = /* @__PURE__ */ __name((value) => {
108
+ if (typeof value === "string")
109
+ return /^https?:\/\//.test(value) ? [value] : [];
110
+ if (Array.isArray(value))
111
+ return value.flatMap(addressesIn);
112
+ if (value && typeof value === "object")
113
+ return Object.values(value).flatMap(addressesIn);
114
+ return [];
115
+ }, "addressesIn");
116
+ var keyringAccounts = /* @__PURE__ */ __name((settingsFiles) => [
117
+ .../* @__PURE__ */ new Set([
118
+ ...FIXED_ACCOUNTS,
119
+ ...settingsFiles.flatMap((file) => addressesIn(readJson(file))).flatMap((url) => {
120
+ const key = endpointKey(url);
121
+ return key ? [`embeddings:${key}`] : [];
122
+ })
123
+ ])
124
+ ], "keyringAccounts");
125
+ var moveKeyring = /* @__PURE__ */ __name((keyring, accounts) => {
126
+ let failed = false;
127
+ for (const account of accounts) {
128
+ let secret;
129
+ try {
130
+ secret = keyring.get(OLD_APP.appName, account);
131
+ } catch {
132
+ return failed ? "retry" : "done";
133
+ }
134
+ if (secret === null)
135
+ continue;
136
+ try {
137
+ const present = keyring.get(APP.appName, account);
138
+ if (present !== null && present !== secret)
139
+ continue;
140
+ if (present === null)
141
+ keyring.set(APP.appName, account, secret);
142
+ if (keyring.get(APP.appName, account) !== secret) {
143
+ failed = true;
144
+ continue;
145
+ }
146
+ keyring.delete(OLD_APP.appName, account);
147
+ } catch {
148
+ failed = true;
149
+ }
150
+ }
151
+ return failed ? "retry" : "done";
152
+ }, "moveKeyring");
153
+ var renamedVariables = /* @__PURE__ */ __name((variables) => Object.fromEntries(Object.entries(variables).map(([name, value]) => [
154
+ name.startsWith(OLD_PREFIX) ? `${NEW_PREFIX}${name.slice(OLD_PREFIX.length)}` : name,
155
+ value
156
+ ])), "renamedVariables");
157
+ var PROMPT_COMMAND = /\bmemo (?=(?:actions|answers|commands|context|digest|facts|guide|mail|meetings|memories|messages|organizations|people|projects|reminders|review|schedule|search|show|skill|sync|tags|tasks|templates)\b)/g;
158
+ var renamedPrompt = /* @__PURE__ */ __name((prompt) => prompt.replace(/\bmemo mail findings\b/g, "wcat review findings").replace(/\bmemo mail review\b/g, "wcat review mail").replace(PROMPT_COMMAND, "wcat "), "renamedPrompt");
159
+ var renamedArgv = /* @__PURE__ */ __name(({ kind, argv }) => {
160
+ if (kind === "agent")
161
+ return argv.map((word) => renamedPrompt(word).replace(/^Bash\(memo([: ])/, "Bash(wcat$1"));
162
+ if (argv[0] !== "mail")
163
+ return argv;
164
+ if (argv[1] === "findings")
165
+ return ["review", "findings", ...argv.slice(2)];
166
+ if (argv[1] === "review")
167
+ return ["review", "mail", ...argv.slice(2)];
168
+ return argv;
169
+ }, "renamedArgv");
170
+ var renamedSchedule = /* @__PURE__ */ __name((schedule) => {
171
+ const argv = renamedArgv(schedule);
172
+ return {
173
+ ...schedule,
174
+ argv,
175
+ environment: renamedVariables(schedule.environment),
176
+ ...schedule.agent ? { agent: { ...schedule.agent, prompt: renamedPrompt(schedule.agent.prompt) } } : {}
177
+ };
178
+ }, "renamedSchedule");
179
+ var listSchedules = /* @__PURE__ */ __name((state) => {
180
+ const dir = join(state, "schedules");
181
+ if (!existsSync(dir))
182
+ return [];
183
+ return readdirSync(dir).map((name) => join(dir, name, "schedule.json")).filter((file) => existsSync(file)).map((file) => readSchedule(file));
184
+ }, "listSchedules");
185
+ var holdSchedules = /* @__PURE__ */ __name(async (site, state) => {
186
+ if (existsSync(join(state, PENDING_SCHEDULES)))
187
+ return;
188
+ const schedules = listSchedules(state);
189
+ if (schedules.length === 0)
190
+ return;
191
+ writeFileSync(join(state, PENDING_SCHEDULES), `${JSON.stringify(schedules, null, 2)}
192
+ `, { mode: 384 });
193
+ for (const schedule of schedules) {
194
+ const profile = schedule.environment[`${OLD_PREFIX}PROFILE`] ?? "";
195
+ await pauseSchedule({ app: OLD_APP, system: site.system, env: site.env, profile }, schedule.name, true);
196
+ }
197
+ }, "holdSchedules");
198
+ var restoreSchedules = /* @__PURE__ */ __name(async (site, state, warn) => {
199
+ const pending = join(state, PENDING_SCHEDULES);
200
+ const schedules = readJson(pending);
201
+ if (schedules === void 0)
202
+ return;
203
+ for (const schedule of schedules.map(renamedSchedule)) {
204
+ const profile = schedule.environment[`${NEW_PREFIX}PROFILE`] ?? "";
205
+ try {
206
+ await writeSchedule({ app: APP, system: site.system, env: site.env, profile }, schedule);
207
+ } catch (error) {
208
+ warn(`wcat: schedule ${schedule.name} is not on a timer: ${error.message}; run wcat schedule resume ${schedule.name}`);
209
+ }
210
+ }
211
+ rmSync(pending, { force: true });
212
+ }, "restoreSchedules");
213
+ var unitEnvironment = /* @__PURE__ */ __name((text) => {
214
+ const line = /^Environment=(.*)$/m.exec(text)?.[1] ?? "";
215
+ return Object.fromEntries([...line.matchAll(/"((?:[^"\\]|\\.)*)"/g)].map((match) => {
216
+ const pair = (match[1] ?? "").replace(/\\(["\\])/g, "$1");
217
+ return [pair.slice(0, pair.indexOf("=")), pair.slice(pair.indexOf("=") + 1)];
218
+ }));
219
+ }, "unitEnvironment");
220
+ var moveJobsTimer = /* @__PURE__ */ __name(async (env, configFile) => {
221
+ const raw = readJson(configFile);
222
+ if (raw?.auto?.places && Object.keys(raw.auto.places).some((name) => name.startsWith(OLD_PREFIX))) {
223
+ raw.auto.places = renamedVariables(raw.auto.places);
224
+ writeFileSync(configFile, `${JSON.stringify(raw, null, 2)}
225
+ `);
226
+ }
227
+ const oldService = join(unitDir(env), `${OLD_JOBS_UNIT}.service`);
228
+ if (!existsSync(oldService) && !existsSync(join(unitDir(env), `${OLD_JOBS_UNIT}.timer`)))
229
+ return;
230
+ const saved = existsSync(oldService) ? unitEnvironment(readFileSync(oldService, "utf8")) : {};
231
+ const state = autoState(raw ?? {});
232
+ await applyAuto(env, { ...state, enabled: false }, OLD_JOBS_UNIT);
233
+ if (state.enabled)
234
+ await applyAuto(env, state, void 0, saved.PATH ?? env.PATH);
235
+ }, "moveJobsTimer");
236
+ var lock = /* @__PURE__ */ __name((path) => {
237
+ mkdirSync(dirname(path), { recursive: true });
238
+ try {
239
+ closeSync(openSync(path, "wx"));
240
+ } catch {
241
+ try {
242
+ if (Date.now() - statSync(path).mtimeMs < LOCK_STALE_MS)
243
+ return void 0;
244
+ rmSync(path, { force: true });
245
+ closeSync(openSync(path, "wx"));
246
+ } catch {
247
+ return void 0;
248
+ }
249
+ }
250
+ return () => rmSync(path, { force: true });
251
+ }, "lock");
252
+ var migrateFromMemo = /* @__PURE__ */ __name(async ({ env, platform = process.platform, home, keyring = systemKeyring, system, warn = /* @__PURE__ */ __name(() => void 0, "warn") }) => {
253
+ const moved = isMovedRun({ appName: APP.appName, prefix: APP.envPrefix, env, platform, home }) || isMovedRun({ appName: OLD_APP.appName, prefix: OLD_APP.envPrefix, env, platform, home });
254
+ if (moved)
255
+ return "moved-run";
256
+ const now = resolvePaths({ appName: APP.appName, prefix: APP.envPrefix, env, platform });
257
+ const old = resolvePaths({ appName: OLD_APP.appName, prefix: OLD_APP.envPrefix, env, platform });
258
+ const markerPath = join(now.state, MARKER);
259
+ const before = existsSync(markerPath) ? readJson(markerPath) : void 0;
260
+ if (before && before.keyring === "done")
261
+ return "done-before";
262
+ const unlock = lock(`${now.state}.migrating`);
263
+ if (!unlock)
264
+ return "busy";
265
+ try {
266
+ const accounts = /* @__PURE__ */ __name(() => keyringAccounts([
267
+ join(now.config, "config.json"),
268
+ join(resolvePaths({ appName: "WireCat", prefix: "WIRECAT", env, platform }).config, "config.json")
269
+ ]), "accounts");
270
+ if (before) {
271
+ const keys2 = moveKeyring(keyring, accounts());
272
+ writeFileSync(markerPath, `${JSON.stringify({ ...before, keyring: keys2 })}
273
+ `);
274
+ return "keyring-retried";
275
+ }
276
+ const site = { env, system: system ?? thisMachine() };
277
+ const stateMoves = existsSync(old.state) && (!existsSync(now.state) || isEmptyDir(now.state));
278
+ if (stateMoves)
279
+ await holdSchedules(site, old.state);
280
+ const tasksOf = /* @__PURE__ */ __name((appName, prefix) => resolvePaths({ appName, prefix, env, platform }), "tasksOf");
281
+ const tasks = [tasksOf("cli-memo-tasks", "MEMO_TASKS"), tasksOf("wcat-tasks", "WCAT_TASKS")];
282
+ for (const [from, to] of [[old, now], tasks]) {
283
+ const kept = moveFolders(from, to);
284
+ if (kept.length > 0)
285
+ warn(`wcat: memo's ${kept.join(", ")} folder stayed where it was, because wcat's already holds files; wcat uses its own (${kept.map((kind) => to[kind]).join(", ")})`);
286
+ }
287
+ moveHttpTokens(now.state);
288
+ await restoreSchedules(site, now.state, warn);
289
+ if (platform === "linux")
290
+ await moveJobsTimer(env, join(now.config, "config.json")).catch((error) => warn(`wcat: memo's sync timer was not replaced: ${error.message}; run wcat jobs start`));
291
+ try {
292
+ replaceMemoSkill(env);
293
+ } catch (error) {
294
+ warn(`wcat: memo's agent skill was not replaced: ${error.message}; run wcat skill install`);
295
+ }
296
+ const keys = moveKeyring(keyring, accounts());
297
+ mkdirSync(now.state, { recursive: true });
298
+ writeFileSync(markerPath, `${JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString(), keyring: keys })}
299
+ `);
300
+ return "migrated";
301
+ } finally {
302
+ unlock();
303
+ }
304
+ }, "migrateFromMemo");
305
+ export {
306
+ MARKER,
307
+ OLD_APP,
308
+ keyringAccounts,
309
+ migrateFromMemo,
310
+ moveFolders,
311
+ moveKeyring,
312
+ renamedPrompt,
313
+ renamedSchedule
314
+ };