@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.
Files changed (230) hide show
  1. package/LICENSE +204 -0
  2. package/README.md +399 -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-O24ISPOI.js +43 -0
  16. package/dist/bundle/chunk-2A3YPENI.js +31 -0
  17. package/dist/bundle/chunk-6BDIFKF5.js +222 -0
  18. package/dist/bundle/chunk-7O7XM37N.js +2 -0
  19. package/dist/bundle/chunk-AYHZY24E.js +120 -0
  20. package/dist/bundle/chunk-CKBTMZUX.js +72 -0
  21. package/dist/bundle/chunk-FGXUH3XL.js +416 -0
  22. package/dist/bundle/chunk-I5JQBRRC.js +807 -0
  23. package/dist/bundle/chunk-RKVAWMZT.js +38 -0
  24. package/dist/bundle/chunk-SCDNOUUR.js +395 -0
  25. package/dist/bundle/chunk-T7TG4JKR.js +312 -0
  26. package/dist/bundle/chunk-XBUCXQKT.js +51 -0
  27. package/dist/bundle/entry-EW5A7FYV.js +64 -0
  28. package/dist/bundle/failure-HMELJ3K5.js +19 -0
  29. package/dist/bundle/from-memo-F7NTUXAR.js +314 -0
  30. package/dist/bundle/program-7XWGFN4H.js +14994 -0
  31. package/dist/bundle/server-T7RVBNRW.js +303 -0
  32. package/dist/bundle/update-JZDS7B6L.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,314 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ replaceMemoSkill
5
+ } from "./chunk-RKVAWMZT.js";
6
+ import {
7
+ applyAuto,
8
+ autoState,
9
+ unitDir
10
+ } from "./chunk-6BDIFKF5.js";
11
+ import "./chunk-7O7XM37N.js";
12
+ import "./chunk-FGXUH3XL.js";
13
+ import "./chunk-T7TG4JKR.js";
14
+ import "./chunk-I5JQBRRC.js";
15
+ import {
16
+ APP,
17
+ __name
18
+ } from "./chunk-SCDNOUUR.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
+ };