@skrr-ai/cli 0.1.207 → 0.1.209

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 (168) hide show
  1. package/dist/commands/agent/message/no-reply.js +1 -1
  2. package/dist/commands/agent/message/react.d.ts +23 -0
  3. package/dist/commands/agent/message/react.js +125 -0
  4. package/dist/commands/agent/message/resolve.d.ts +31 -0
  5. package/dist/commands/agent/message/resolve.js +111 -0
  6. package/dist/commands/agent/message/retract.js +1 -1
  7. package/dist/commands/agent/message/send.d.ts +25 -6
  8. package/dist/commands/agent/message/send.js +135 -30
  9. package/dist/commands/agent/request/list.d.ts +15 -0
  10. package/dist/commands/agent/request/list.js +82 -0
  11. package/dist/commands/agent/request/send.d.ts +18 -0
  12. package/dist/commands/agent/request/send.js +56 -0
  13. package/dist/commands/agents/access/approve.d.ts +17 -0
  14. package/dist/commands/agents/access/approve.js +94 -0
  15. package/dist/commands/agents/access/deny.d.ts +10 -0
  16. package/dist/commands/agents/access/deny.js +36 -0
  17. package/dist/commands/agents/access/list.d.ts +10 -0
  18. package/dist/commands/agents/access/list.js +55 -0
  19. package/dist/commands/agents/access/reach.d.ts +13 -0
  20. package/dist/commands/agents/access/reach.js +53 -0
  21. package/dist/commands/agents/access/revoke.d.ts +13 -0
  22. package/dist/commands/agents/access/revoke.js +50 -0
  23. package/dist/commands/agents/always-on/recovery-review.d.ts +5 -0
  24. package/dist/commands/agents/always-on/recovery-review.js +16 -0
  25. package/dist/commands/agents/chat.d.ts +8 -0
  26. package/dist/commands/agents/chat.js +369 -90
  27. package/dist/commands/agents/import.d.ts +15 -1
  28. package/dist/commands/agents/import.js +212 -24
  29. package/dist/commands/agents/intuitions/accept.d.ts +0 -1
  30. package/dist/commands/agents/intuitions/accept.js +22 -7
  31. package/dist/commands/agents/intuitions/generate.d.ts +0 -1
  32. package/dist/commands/agents/intuitions/generate.js +4 -16
  33. package/dist/commands/agents/intuitions/list.js +9 -3
  34. package/dist/commands/agents/intuitions/resume.d.ts +11 -0
  35. package/dist/commands/agents/intuitions/resume.js +37 -0
  36. package/dist/commands/agents/manager/status.js +7 -6
  37. package/dist/commands/agents/not-for-task.d.ts +24 -0
  38. package/dist/commands/agents/not-for-task.js +60 -0
  39. package/dist/commands/agents/schedule-overview.d.ts +20 -0
  40. package/dist/commands/agents/schedule-overview.js +35 -2
  41. package/dist/commands/agents/shared-memory.d.ts +24 -0
  42. package/dist/commands/agents/shared-memory.js +67 -0
  43. package/dist/commands/agents/stop.d.ts +23 -0
  44. package/dist/commands/agents/stop.js +61 -0
  45. package/dist/commands/agents/update.d.ts +7 -0
  46. package/dist/commands/agents/update.js +45 -2
  47. package/dist/commands/agents/visibility.d.ts +1 -0
  48. package/dist/commands/agents/visibility.js +14 -0
  49. package/dist/commands/code/migrate.js +3 -1
  50. package/dist/commands/convos/messages.js +5 -0
  51. package/dist/commands/convos/transcript.js +2 -2
  52. package/dist/commands/daemon/logs.d.ts +3 -1
  53. package/dist/commands/daemon/logs.js +6 -2
  54. package/dist/commands/duties/advance-next.js +16 -7
  55. package/dist/commands/duties/preflight.js +17 -13
  56. package/dist/commands/followups/show.js +9 -0
  57. package/dist/commands/followups/watch-pr.d.ts +27 -0
  58. package/dist/commands/followups/watch-pr.js +124 -0
  59. package/dist/commands/harnesses/evaluations/evidence.js +2 -2
  60. package/dist/commands/harnesses/evaluations/grant.js +1 -1
  61. package/dist/commands/harnesses/evaluations/revoke.js +1 -1
  62. package/dist/commands/harnesses/evaluations/show.js +1 -1
  63. package/dist/commands/harnesses/rollouts/grant.js +1 -1
  64. package/dist/commands/harnesses/rollouts/revoke.js +1 -1
  65. package/dist/commands/machines/hosted/identity-evaluations/revoke.js +1 -1
  66. package/dist/commands/machines/hosted/identity-evaluations/show.js +1 -1
  67. package/dist/commands/memory/consolidation/index.d.ts +20 -0
  68. package/dist/commands/memory/consolidation/index.js +78 -0
  69. package/dist/commands/memory/consolidation/resume.d.ts +14 -0
  70. package/dist/commands/memory/consolidation/resume.js +46 -0
  71. package/dist/commands/memory/consolidation/undo.d.ts +18 -0
  72. package/dist/commands/memory/consolidation/undo.js +61 -0
  73. package/dist/commands/messages/list.js +9 -1
  74. package/dist/commands/slack/mutes.d.ts +10 -0
  75. package/dist/commands/slack/mutes.js +62 -0
  76. package/dist/commands/slack/unmute.d.ts +12 -0
  77. package/dist/commands/slack/unmute.js +44 -0
  78. package/dist/commands/tasks/actionability.js +10 -0
  79. package/dist/commands/tasks/ask.d.ts +50 -0
  80. package/dist/commands/tasks/ask.js +190 -0
  81. package/dist/commands/tasks/bulk-update.js +12 -0
  82. package/dist/commands/tasks/handover.js +14 -0
  83. package/dist/commands/tasks/input/answer.js +8 -2
  84. package/dist/commands/tasks/input/show.d.ts +26 -0
  85. package/dist/commands/tasks/input/show.js +185 -17
  86. package/dist/commands/tasks/list.d.ts +8 -0
  87. package/dist/commands/tasks/list.js +50 -9
  88. package/dist/commands/tasks/move.d.ts +3 -0
  89. package/dist/commands/tasks/move.js +71 -1
  90. package/dist/commands/tasks/result/show.js +19 -7
  91. package/dist/commands/tasks/result/submit.js +3 -0
  92. package/dist/commands/tasks/runs.d.ts +4 -1
  93. package/dist/commands/tasks/runs.js +22 -3
  94. package/dist/commands/tasks/show.d.ts +4 -3
  95. package/dist/commands/tasks/show.js +40 -7
  96. package/dist/commands/tasks/start.js +35 -16
  97. package/dist/commands/tasks/update.d.ts +1 -0
  98. package/dist/commands/tasks/update.js +55 -1
  99. package/dist/commands/tasks/updates/add.js +3 -0
  100. package/dist/commands/tasks/wait.d.ts +20 -0
  101. package/dist/commands/tasks/wait.js +103 -2
  102. package/dist/generated/agent-guides.json +892 -183
  103. package/dist/generated/managed-instruction-guides.json +1 -1
  104. package/dist/lib/agent-access-command.d.ts +19 -0
  105. package/dist/lib/agent-access-command.js +44 -0
  106. package/dist/lib/agent-access.d.ts +18 -0
  107. package/dist/lib/agent-access.js +48 -0
  108. package/dist/lib/agent-import/apply.d.ts +50 -0
  109. package/dist/lib/agent-import/apply.js +85 -0
  110. package/dist/lib/agent-import/plan.d.ts +132 -0
  111. package/dist/lib/agent-import/plan.js +504 -0
  112. package/dist/lib/agent-import/reader.d.ts +94 -0
  113. package/dist/lib/agent-import/reader.js +326 -0
  114. package/dist/lib/agent-import/schedule.d.ts +46 -0
  115. package/dist/lib/agent-import/schedule.js +220 -0
  116. package/dist/lib/agent-import/sources.d.ts +124 -0
  117. package/dist/lib/agent-import/sources.js +797 -0
  118. package/dist/lib/chat-stop.d.ts +17 -0
  119. package/dist/lib/chat-stop.js +70 -0
  120. package/dist/lib/cloud-reply.d.ts +21 -0
  121. package/dist/lib/cloud-reply.js +52 -0
  122. package/dist/lib/duties.js +24 -4
  123. package/dist/lib/duty-ledgers.js +19 -2
  124. package/dist/lib/file-mime.js +8 -0
  125. package/dist/lib/followups.d.ts +61 -0
  126. package/dist/lib/followups.js +39 -0
  127. package/dist/lib/handover-interview.d.ts +18 -0
  128. package/dist/lib/handover-interview.js +53 -0
  129. package/dist/lib/inbound-messages.d.ts +156 -0
  130. package/dist/lib/inbound-messages.js +375 -0
  131. package/dist/lib/input-queue.js +2 -1
  132. package/dist/lib/intuition-look.d.ts +10 -0
  133. package/dist/lib/intuition-look.js +64 -0
  134. package/dist/lib/message-intent.d.ts +18 -2
  135. package/dist/lib/message-intent.js +23 -1
  136. package/dist/lib/preflight-copy.d.ts +16 -1
  137. package/dist/lib/preflight-copy.js +33 -1
  138. package/dist/lib/record-output.d.ts +1 -1
  139. package/dist/lib/record-output.js +2 -0
  140. package/dist/lib/skill-import.d.ts +19 -0
  141. package/dist/lib/skill-import.js +34 -0
  142. package/dist/lib/slack-thread-mutes.d.ts +25 -0
  143. package/dist/lib/slack-thread-mutes.js +12 -0
  144. package/dist/lib/task-carriers.d.ts +18 -0
  145. package/dist/lib/task-carriers.js +43 -0
  146. package/dist/lib/task-extras.d.ts +5 -0
  147. package/dist/lib/task-extras.js +5 -0
  148. package/dist/lib/task-operations.d.ts +2 -0
  149. package/dist/lib/task-operations.js +28 -4
  150. package/dist/lib/task-preflight.js +1 -0
  151. package/dist/lib/task-recurrence-summary.d.ts +15 -0
  152. package/dist/lib/task-recurrence-summary.js +22 -0
  153. package/dist/lib/task-review-notice.d.ts +21 -0
  154. package/dist/lib/task-review-notice.js +46 -0
  155. package/dist/lib/task-version.d.ts +53 -0
  156. package/dist/lib/task-version.js +89 -0
  157. package/dist/lib/task-write-attribution.d.ts +7 -0
  158. package/dist/lib/task-write-attribution.js +14 -0
  159. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/credentialEnvelopeBridge.js +6 -1
  160. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/turnPacing.d.ts +75 -0
  161. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/turnPacing.js +124 -0
  162. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/credentialEnvelopeBridge.js +45 -15
  163. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/turnPacing.d.ts +75 -0
  164. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/turnPacing.js +141 -0
  165. package/dist/node_modules/@skrr-ai/auth-core/package.json +11 -1
  166. package/dist/node_modules/@skrr-ai/data-provider/index.js +13492 -12505
  167. package/oclif.manifest.json +2090 -132
  168. package/package.json +9 -2
@@ -0,0 +1,326 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SourceReader = exports.IMPORT_REFUSAL_REASONS = exports.READ_MAX_BYTES = void 0;
7
+ exports.neverReadReason = neverReadReason;
8
+ exports.displayPath = displayPath;
9
+ /**
10
+ * The ONE way `skrr agents import` reads another app's bot folder.
11
+ *
12
+ * Everything the importer learns about an OpenClaw, Hermes or Orca bot passes through a
13
+ * `SourceReader`, and nothing it learns leaves this machine except through it. That is the whole
14
+ * safety argument, so the rules live here and nowhere else:
15
+ *
16
+ * 1. **Never read a key or login file.** A file or folder whose NAME says it holds keys, logins or
17
+ * chat history is refused before it is opened (`neverReadReason`): `.env*`, `auth.json`,
18
+ * `auth-profiles*`, `openclaw.json` (and its older names), `config.yaml`, key and database
19
+ * files, anything named `*secret*`, `*token*`, `*credential*` or `*password*`, and anything
20
+ * under `credentials/`, `devices/`, `identity/`, `sessions/`, `vault/`, `mcp-tokens/`, `logs/`,
21
+ * `sandboxes/`, `codex-home/`, `.git/` or `node_modules/`. The list is the one Orca's importer
22
+ * keeps for the same three apps (`bot-import-read-refusal.ts`), plus OpenClaw's
23
+ * `memory/.dreams/`. A link is judged by its own name AND by where it leads, so
24
+ * `notes.md -> ../.env` is still a `.env`.
25
+ * 2. **Never leave the folder.** The folder is resolved to its real path first; every file is
26
+ * resolved again and refused when its real path is outside, which is how a symlink to
27
+ * `~/.ssh/id_ed25519` or `/etc` is NOT followed. The file is then opened with `O_NOFOLLOW`, so
28
+ * a link swapped in after the check is refused by the kernel rather than read.
29
+ * 3. **Leave out every line that looks like it holds a secret.** Text is filtered line by line
30
+ * with `splitSecretLines` from `@skrr-ai/data-provider`: the same detector Memory holds every
31
+ * write to (`MemoryContentPolicy`), so the importer can never let through a shape Memory would
32
+ * flag, nor drift from it. A JSON file (cron jobs) is parsed whole IN THIS PROCESS, and only the
33
+ * fields the importer uses are kept, each filtered the same way (`field`).
34
+ * 4. **Small, plain text only.** A file over `READ_MAX_BYTES`, with a NUL byte, or not valid UTF-8
35
+ * is refused: none of the files an importer wants look like that, and a database or a binary
36
+ * that does is exactly what must not be sent anywhere.
37
+ *
38
+ * Every refusal and every line left out is recorded with its reason, and the plan shows them: an
39
+ * importer that silently skipped things would be indistinguishable from one that silently took them.
40
+ */
41
+ const node_fs_1 = require("node:fs");
42
+ const promises_1 = require("node:fs/promises");
43
+ const node_os_1 = __importDefault(require("node:os"));
44
+ const node_path_1 = __importDefault(require("node:path"));
45
+ const data_provider_1 = require("@skrr-ai/data-provider");
46
+ /** Bigger than any persona, memory or skill file; smaller than any database or log worth refusing. */
47
+ exports.READ_MAX_BYTES = 512 * 1024;
48
+ /** Names that hold keys, logins or chat history in OpenClaw, Hermes and Orca. Never opened. */
49
+ const NEVER_READ_NAME = /^(\.env.*|auth\.json|(openclaw|clawdbot|moltbot)\.json|config\.ya?ml|auth-profiles.*|.*\.(pem|key|p12|pfx|keychain|keychain-db|kdbx|sqlite|sqlite3|db|db-wal|db-shm)|.*(secret|token|credential|password).*)$/i;
50
+ /** Folders that hold keys, logins, devices, chat history or other people's code. Never entered. */
51
+ const NEVER_READ_FOLDER = /^(credentials|devices|identity|sessions|vault|mcp-tokens|logs|sandboxes|codex-home|\.git|node_modules|\.ssh|\.gnupg)$/i;
52
+ /** OpenClaw's memory dreaming workspace: machine scratch, not notes. */
53
+ const NEVER_READ_SUBPATH = /(^|\/)memory\/\.dreams(\/|$)/i;
54
+ exports.IMPORT_REFUSAL_REASONS = Object.freeze({
55
+ key_or_login_folder: 'It is in a folder that holds keys, logins or chat history; never read',
56
+ key_or_login_file: 'Its name says it may hold keys or logins; never read',
57
+ app_scratch: 'It is the app’s own scratch space, not notes; never read',
58
+ link_outside_folder: 'It links outside the folder being imported; not followed',
59
+ not_a_file: 'It is not a regular file',
60
+ too_large: `It is larger than ${exports.READ_MAX_BYTES / 1024} KB`,
61
+ not_text: 'It is not plain text',
62
+ unreadable: 'It could not be read',
63
+ // The importer's own limits on a skill's files (`sources.ts`, `readSkillFiles`), recorded here so
64
+ // the plan reports them the way it reports every other file that does not travel.
65
+ skill_too_deep: 'It is nested deeper in the skill folder than an imported skill carries',
66
+ skill_too_many_files: 'The skill already carries as many files as an imported skill can',
67
+ skill_full: `The skill has no room left for it (a skill holds at most ${data_provider_1.SKILL_LIMITS.CONTENT_MAX_LENGTH / 1024} KB of text)`,
68
+ });
69
+ /** Why `rel` (a path inside the source folder, `/`-separated) may never be read, or null. */
70
+ function neverReadReason(rel) {
71
+ const parts = rel.split(/[\\/]+/).filter(Boolean);
72
+ const name = parts[parts.length - 1] ?? '';
73
+ if (parts.some((part) => NEVER_READ_FOLDER.test(part)))
74
+ return 'key_or_login_folder';
75
+ if (NEVER_READ_SUBPATH.test(parts.join('/')))
76
+ return 'app_scratch';
77
+ return NEVER_READ_NAME.test(name) ? 'key_or_login_file' : null;
78
+ }
79
+ /** `/Users/me/.openclaw` -> `~/.openclaw`; a path outside home is shown as it is. */
80
+ function displayPath(abs) {
81
+ const home = node_os_1.default.homedir();
82
+ if (home && (abs === home || abs.startsWith(home + node_path_1.default.sep))) {
83
+ return `~${abs.slice(home.length).split(node_path_1.default.sep).join('/')}`;
84
+ }
85
+ return abs;
86
+ }
87
+ function isInside(root, candidate) {
88
+ const relative = node_path_1.default.relative(root, candidate);
89
+ return relative === '' || (!relative.startsWith('..') && !node_path_1.default.isAbsolute(relative));
90
+ }
91
+ function toRel(root, abs) {
92
+ return node_path_1.default.relative(root, abs).split(node_path_1.default.sep).join('/');
93
+ }
94
+ const FATAL_UTF8 = new TextDecoder('utf-8', { fatal: true });
95
+ // O_NOFOLLOW is POSIX; Windows has no symlink-following open to refuse, and the real-path check
96
+ // above still holds there.
97
+ const OPEN_FLAGS = node_fs_1.constants.O_RDONLY | (node_fs_1.constants.O_NOFOLLOW ?? 0);
98
+ class SourceReader {
99
+ root;
100
+ prefix;
101
+ refused;
102
+ leftOut;
103
+ constructor(
104
+ /** The source folder's real path. */
105
+ root,
106
+ /** Where this reader sits inside the folder the import was opened on, for messages. */
107
+ prefix,
108
+ /** One record for the whole import: a refusal inside a workspace is a refusal of the import. */
109
+ refused, leftOut) {
110
+ this.root = root;
111
+ this.prefix = prefix;
112
+ this.refused = refused;
113
+ this.leftOut = leftOut;
114
+ }
115
+ /** Open a source folder. Throws when it is not a folder. */
116
+ static async open(folder) {
117
+ const root = await (0, promises_1.realpath)(node_path_1.default.resolve(folder));
118
+ if (!(await (0, promises_1.stat)(root)).isDirectory()) {
119
+ throw new Error(`${folder} is not a folder`);
120
+ }
121
+ return new SourceReader(root, '', [], []);
122
+ }
123
+ /** The folder as a person reads it: `~/.openclaw`. */
124
+ get display() {
125
+ return displayPath(this.root);
126
+ }
127
+ /**
128
+ * A reader for a folder inside this one, sharing its records, or null when that is not a folder
129
+ * here. It is confined to the sub-folder: a link from it to elsewhere in this folder is not followed.
130
+ */
131
+ async sub(rel) {
132
+ const resolved = await this.resolve(rel, { record: true });
133
+ if (!resolved || resolved.kind !== 'dir')
134
+ return null;
135
+ return new SourceReader(resolved.real, this.join(rel), this.refused, this.leftOut);
136
+ }
137
+ /** `rel` as the plan names it: relative to the folder the import was opened on. */
138
+ join(rel) {
139
+ const clean = rel
140
+ .split(/[\\/]+/)
141
+ .filter(Boolean)
142
+ .join('/');
143
+ return this.prefix ? (clean ? `${this.prefix}/${clean}` : this.prefix) : clean;
144
+ }
145
+ /**
146
+ * Record that `rel` does not travel, for a reason the caller decided (a limit of its own). The
147
+ * plan shows it beside the reader's own refusals.
148
+ */
149
+ record(rel, reason) {
150
+ this.refuse(rel, reason);
151
+ }
152
+ refuse(rel, reason) {
153
+ const from = this.join(rel);
154
+ if (!this.refused.some((entry) => entry.from === from))
155
+ this.refused.push({ from, reason });
156
+ return null;
157
+ }
158
+ /**
159
+ * Where `rel` really is, or null (missing, or refused and recorded when `record`). Judges the
160
+ * path's own name and its real path's name, and refuses a real path outside the folder.
161
+ */
162
+ async resolve(rel, { record }) {
163
+ const abs = node_path_1.default.resolve(this.root, rel);
164
+ if (!isInside(this.root, abs))
165
+ return record ? this.refuse(rel, 'link_outside_folder') : null;
166
+ const ownReason = neverReadReason(toRel(this.root, abs));
167
+ if (ownReason)
168
+ return record ? this.refuse(rel, ownReason) : null;
169
+ let real;
170
+ try {
171
+ real = await (0, promises_1.realpath)(abs);
172
+ }
173
+ catch (err) {
174
+ if (err.code === 'ENOENT') {
175
+ // A dangling link is a link to somewhere that is not here; say so rather than "missing".
176
+ const link = await (0, promises_1.lstat)(abs).catch(() => null);
177
+ return link?.isSymbolicLink() && record ? this.refuse(rel, 'link_outside_folder') : null;
178
+ }
179
+ return record ? this.refuse(rel, 'unreadable') : null;
180
+ }
181
+ if (!isInside(this.root, real))
182
+ return record ? this.refuse(rel, 'link_outside_folder') : null;
183
+ const realReason = neverReadReason(toRel(this.root, real));
184
+ if (realReason)
185
+ return record ? this.refuse(rel, realReason) : null;
186
+ const info = await (0, promises_1.stat)(real).catch(() => null);
187
+ if (!info)
188
+ return record ? this.refuse(rel, 'unreadable') : null;
189
+ return { real, kind: info.isDirectory() ? 'dir' : info.isFile() ? 'file' : 'other' };
190
+ }
191
+ /** Whether `rel` exists, without reading it or recording anything. Never-read names may be tested. */
192
+ async has(rel, kind) {
193
+ const abs = node_path_1.default.resolve(this.root, rel);
194
+ if (!isInside(this.root, abs))
195
+ return false;
196
+ const info = await (0, promises_1.lstat)(abs).catch(() => null);
197
+ if (!info)
198
+ return false;
199
+ if (!kind)
200
+ return true;
201
+ if (info.isSymbolicLink()) {
202
+ const real = await (0, promises_1.realpath)(abs).catch(() => null);
203
+ if (!real || !isInside(this.root, real))
204
+ return false;
205
+ const target = await (0, promises_1.stat)(real).catch(() => null);
206
+ return kind === 'dir' ? Boolean(target?.isDirectory()) : Boolean(target?.isFile());
207
+ }
208
+ return kind === 'dir' ? info.isDirectory() : info.isFile();
209
+ }
210
+ /**
211
+ * A folder's files and folders, sorted by name. Each entry that may not be read is recorded as
212
+ * refused and left out of the list; a link is listed by what it leads to, and only when that is
213
+ * inside the folder.
214
+ */
215
+ async list(rel = '') {
216
+ const dir = await this.resolve(rel, { record: true });
217
+ if (!dir || dir.kind !== 'dir')
218
+ return [];
219
+ let names;
220
+ try {
221
+ names = (await (0, promises_1.readdir)(dir.real)).sort((a, b) => a.localeCompare(b));
222
+ }
223
+ catch {
224
+ this.refuse(rel, 'unreadable');
225
+ return [];
226
+ }
227
+ const out = [];
228
+ for (const name of names) {
229
+ const childRel = rel ? `${rel}/${name}` : name;
230
+ const child = await this.resolve(childRel, { record: true });
231
+ if (!child)
232
+ continue;
233
+ if (child.kind === 'other') {
234
+ this.refuse(childRel, 'not_a_file');
235
+ continue;
236
+ }
237
+ out.push({ name, rel: childRel, kind: child.kind });
238
+ }
239
+ return out;
240
+ }
241
+ /** A file's bytes as text, or null (missing, or refused and recorded). No secret filtering. */
242
+ async readRaw(rel) {
243
+ const resolved = await this.resolve(rel, { record: true });
244
+ if (!resolved)
245
+ return null;
246
+ if (resolved.kind !== 'file')
247
+ return this.refuse(rel, 'not_a_file');
248
+ let handle;
249
+ try {
250
+ handle = await (0, promises_1.open)(resolved.real, OPEN_FLAGS);
251
+ }
252
+ catch (err) {
253
+ const code = err.code;
254
+ return this.refuse(rel, code === 'ELOOP' ? 'link_outside_folder' : 'unreadable');
255
+ }
256
+ try {
257
+ const info = await handle.stat();
258
+ if (!info.isFile())
259
+ return this.refuse(rel, 'not_a_file');
260
+ if (info.size > exports.READ_MAX_BYTES)
261
+ return this.refuse(rel, 'too_large');
262
+ const buffer = Buffer.alloc(info.size);
263
+ const { bytesRead } = await handle.read(buffer, 0, info.size, 0);
264
+ const bytes = buffer.subarray(0, bytesRead);
265
+ if (bytes.includes(0))
266
+ return this.refuse(rel, 'not_text');
267
+ try {
268
+ return FATAL_UTF8.decode(bytes).replace(/^/, '');
269
+ }
270
+ catch {
271
+ return this.refuse(rel, 'not_text');
272
+ }
273
+ }
274
+ catch {
275
+ return this.refuse(rel, 'unreadable');
276
+ }
277
+ finally {
278
+ await handle.close().catch(() => undefined);
279
+ }
280
+ }
281
+ /** A text file's kept lines, each with its original line number; secret-looking lines left out. */
282
+ async readLines(rel) {
283
+ const raw = await this.readRaw(rel);
284
+ if (raw === null)
285
+ return null;
286
+ const { lines, leftOut } = (0, data_provider_1.splitSecretLines)(raw);
287
+ const from = this.join(rel);
288
+ for (const entry of leftOut)
289
+ this.leftOut.push({ from, line: entry.line, kind: entry.kind });
290
+ return lines;
291
+ }
292
+ /** A text file with every secret-looking line left out, or null. */
293
+ async readText(rel) {
294
+ const lines = await this.readLines(rel);
295
+ return lines === null ? null : lines.map((entry) => entry.text).join('\n');
296
+ }
297
+ /**
298
+ * A JSON file, parsed in this process and returned whole: the caller keeps only the fields it
299
+ * needs and passes each string through `field`. Null when missing, refused or not JSON.
300
+ */
301
+ async readJson(rel) {
302
+ const raw = await this.readRaw(rel);
303
+ if (raw === null)
304
+ return null;
305
+ try {
306
+ return JSON.parse(raw);
307
+ }
308
+ catch {
309
+ return this.refuse(rel, 'not_text');
310
+ }
311
+ }
312
+ /** One string taken from a JSON file, with its secret-looking lines left out ('' when not a string). */
313
+ field(value, rel, field) {
314
+ if (typeof value !== 'string' || !value)
315
+ return '';
316
+ const { lines, leftOut } = (0, data_provider_1.splitSecretLines)(value);
317
+ const from = this.join(rel);
318
+ for (const entry of leftOut)
319
+ this.leftOut.push({ from, field, kind: entry.kind });
320
+ return lines
321
+ .map((entry) => entry.text)
322
+ .join('\n')
323
+ .trim();
324
+ }
325
+ }
326
+ exports.SourceReader = SourceReader;
@@ -0,0 +1,46 @@
1
+ declare const DAY_KEYS: readonly ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
2
+ type DayKey = (typeof DAY_KEYS)[number];
3
+ /** The saved schedule a Duty manifest carries (`DutyPortableSavedCadence`). */
4
+ export type ImportedSavedCadence = {
5
+ mode: 'interval';
6
+ intervalMs: number;
7
+ activeHours?: {
8
+ start: string;
9
+ end: string;
10
+ };
11
+ daysOfWeek?: DayKey[];
12
+ timezone?: string;
13
+ } | {
14
+ mode: 'daily';
15
+ times: string[];
16
+ daysOfWeek?: DayKey[];
17
+ timezone?: string;
18
+ };
19
+ export type ScheduleReading = {
20
+ /** The schedule as the old app had it, for the plan and the Duty's description. */
21
+ original: string;
22
+ /** What it becomes here, or null when a Duty cadence cannot carry it exactly. */
23
+ savedCadence: ImportedSavedCadence | null;
24
+ /** Plain words for `savedCadence`, or why there is none. */
25
+ summary: string;
26
+ /** The time zone was not in the job and is this computer's. */
27
+ timezoneAssumed?: boolean;
28
+ /** A single run at one time, which a Duty has no saved form for. */
29
+ oneOff?: boolean;
30
+ };
31
+ /** This computer's zone: the one an app's scheduler on it used when a job named none. */
32
+ export declare function localTimezone(): string;
33
+ /**
34
+ * A five-field cron pattern as a Duty cadence, or null when no cadence says the same thing. Daily
35
+ * `times` (at most six) and an interval within a window of hours are what a cadence can say; a day
36
+ * of the month or a month cannot be said at all.
37
+ */
38
+ export declare function cadenceFromCron(expr: string): ImportedSavedCadence | null;
39
+ /**
40
+ * Read one job's schedule. `fallbackTimezone` is the zone the old app's scheduler used when the job
41
+ * named none: this computer's.
42
+ */
43
+ export declare function readImportedSchedule(raw: unknown, { fallbackTimezone }?: {
44
+ fallbackTimezone?: string;
45
+ }): ScheduleReading;
46
+ export {};
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.localTimezone = localTimezone;
4
+ exports.cadenceFromCron = cadenceFromCron;
5
+ exports.readImportedSchedule = readImportedSchedule;
6
+ /**
7
+ * Another app's schedule, read as a Duty's saved schedule.
8
+ *
9
+ * An imported schedule never runs on its own: the Duty lands as a draft with a MANUAL cadence and
10
+ * the schedule saved beside it, inactive (`savedCadence`, manifest version 2), until its owner
11
+ * restores it with `skrr duties update <id> --restore-saved-cadence` and turns the Duty on. This
12
+ * module only decides what that saved schedule is, and it refuses to guess: a schedule a Duty
13
+ * cadence cannot carry EXACTLY (a day of the month, a month, a one-off time, a shape it does not
14
+ * know) is reported in words and the Duty arrives with no saved schedule, so nobody discovers months
15
+ * later that "every weekday at 9" became "every 24 hours".
16
+ *
17
+ * Shapes read, from the apps' own job files:
18
+ * - OpenClaw `cron/jobs.json`: `{ kind: 'cron', expr, tz }`, `{ kind: 'every', everyMs }`,
19
+ * `{ kind: 'at', at }`.
20
+ * - Hermes `cron/jobs.json`: `{ kind: 'cron', expr }`, `{ kind: 'interval', minutes }`,
21
+ * `{ kind: 'once', run_at }`, each with a `display` string; or a plain string
22
+ * (`0 9 * * *`, `every 30m`).
23
+ */
24
+ const task_recurrence_summary_1 = require("../task-recurrence-summary");
25
+ const duties_1 = require("../duties");
26
+ const DAY_KEYS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
27
+ const DUTY_CADENCE_MAX_TIMES = 6;
28
+ const CRON_SHAPE_RE = /^\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+\s*$/;
29
+ const ISO_INSTANT_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/;
30
+ const EVERY_PREFIX_RE = /^every\s+/i;
31
+ const pad = (n) => String(n).padStart(2, '0');
32
+ function validTimezone(value) {
33
+ if (typeof value !== 'string' || !value.trim())
34
+ return null;
35
+ try {
36
+ new Intl.DateTimeFormat('en-US', { timeZone: value.trim() });
37
+ return value.trim();
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ }
43
+ /** This computer's zone: the one an app's scheduler on it used when a job named none. */
44
+ function localTimezone() {
45
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
46
+ }
47
+ function describeInterval(ms) {
48
+ const minutes = Math.round(ms / 60_000);
49
+ if (minutes % 1440 === 0)
50
+ return `every ${minutes / 1440} day${minutes === 1440 ? '' : 's'}`;
51
+ if (minutes % 60 === 0)
52
+ return `every ${minutes / 60} hour${minutes === 60 ? '' : 's'}`;
53
+ return `every ${minutes} minute${minutes === 1 ? '' : 's'}`;
54
+ }
55
+ function describeDays(days) {
56
+ if (!days)
57
+ return '';
58
+ const key = days.join(',');
59
+ if (key === 'mon,tue,wed,thu,fri')
60
+ return ', Monday to Friday';
61
+ if (key === 'sat,sun')
62
+ return ', at weekends';
63
+ return `, on ${days.join(', ')}`;
64
+ }
65
+ function summarize(cadence) {
66
+ const zone = cadence.timezone ? ` (${cadence.timezone})` : '';
67
+ if (cadence.mode === 'daily') {
68
+ return `daily at ${cadence.times.join(', ')}${describeDays(cadence.daysOfWeek)}${zone}`;
69
+ }
70
+ const hours = cadence.activeHours
71
+ ? `, between ${cadence.activeHours.start} and ${cadence.activeHours.end}`
72
+ : '';
73
+ return `${describeInterval(cadence.intervalMs)}${hours}${describeDays(cadence.daysOfWeek)}${zone}`;
74
+ }
75
+ function interval(ms) {
76
+ if (!Number.isFinite(ms) || ms < duties_1.MIN_DUTY_INTERVAL_MS || ms > duties_1.MAX_DUTY_INTERVAL_MS)
77
+ return null;
78
+ return { mode: 'interval', intervalMs: Math.round(ms) };
79
+ }
80
+ /** Evenly spaced from the field's start (0,15,30,45 -> 15), or null. */
81
+ function evenStep(values, size) {
82
+ if (values.length < 2 || values[0] !== 0)
83
+ return null;
84
+ const step = values[1] - values[0];
85
+ if (size % step !== 0 || values.length !== size / step)
86
+ return null;
87
+ return values.every((value, index) => value === index * step) ? step : null;
88
+ }
89
+ /** Consecutive hours (9..17) -> the window 09:00 to 18:00, or null (wrapping or gapped). */
90
+ function hourWindow(hours) {
91
+ if (hours.length === 0 || hours.length === 24)
92
+ return null;
93
+ const last = hours[hours.length - 1];
94
+ if (last >= 23 || hours.some((hour, index) => index > 0 && hour !== hours[index - 1] + 1)) {
95
+ return null;
96
+ }
97
+ return { start: `${pad(hours[0])}:00`, end: `${pad(last + 1)}:00` };
98
+ }
99
+ /**
100
+ * A five-field cron pattern as a Duty cadence, or null when no cadence says the same thing. Daily
101
+ * `times` (at most six) and an interval within a window of hours are what a cadence can say; a day
102
+ * of the month or a month cannot be said at all.
103
+ */
104
+ function cadenceFromCron(expr) {
105
+ const fields = (0, task_recurrence_summary_1.readCronFields)(expr);
106
+ if (!fields || fields.daysOfMonth !== '*' || fields.months !== '*')
107
+ return null;
108
+ const days = fields.daysOfWeek === '*' || fields.daysOfWeek.length === 7
109
+ ? undefined
110
+ : [...new Set(fields.daysOfWeek)]
111
+ .sort((a, b) => ((a + 6) % 7) - ((b + 6) % 7))
112
+ .map((d) => DAY_KEYS[d]);
113
+ const withDays = (cadence) => days ? { ...cadence, daysOfWeek: days } : cadence;
114
+ const { minutes, hours } = fields;
115
+ // One minute at up to six hours: daily times.
116
+ if (minutes.length === 1 && hours.length <= DUTY_CADENCE_MAX_TIMES) {
117
+ return withDays({
118
+ mode: 'daily',
119
+ times: hours.map((hour) => `${pad(hour)}:${pad(minutes[0])}`),
120
+ });
121
+ }
122
+ // Every N minutes (or every minute), all day or within a window of whole hours.
123
+ const minuteStep = minutes.length === 60 ? 1 : evenStep(minutes, 60);
124
+ if (minuteStep) {
125
+ const base = interval(minuteStep * 60_000);
126
+ if (!base)
127
+ return null;
128
+ if (hours.length === 24)
129
+ return withDays(base);
130
+ const window = hourWindow(hours);
131
+ return window ? withDays({ ...base, activeHours: window }) : null;
132
+ }
133
+ // One minute of every N hours, from midnight: an interval of N hours. (An interval has no
134
+ // phase, so ":30 past" and ":00" both read as "every N hours".)
135
+ if (minutes.length === 1) {
136
+ const hourStep = hours.length === 24 ? 1 : evenStep(hours, 24);
137
+ const base = hourStep ? interval(hourStep * 3_600_000) : null;
138
+ return base ? withDays(base) : null;
139
+ }
140
+ return null;
141
+ }
142
+ function text(value) {
143
+ return typeof value === 'string' ? value.trim() : '';
144
+ }
145
+ /**
146
+ * Read one job's schedule. `fallbackTimezone` is the zone the old app's scheduler used when the job
147
+ * named none: this computer's.
148
+ */
149
+ function readImportedSchedule(raw, { fallbackTimezone = localTimezone() } = {}) {
150
+ const object = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : null;
151
+ const kind = text(object?.kind).toLowerCase();
152
+ const display = text(object?.display) || text(object?.schedule_display);
153
+ const zoneOf = () => validTimezone(object?.tz) ?? validTimezone(object?.timezone);
154
+ const cronExpr = kind === 'cron' ? text(object?.expr) || text(object?.cron) || text(object?.expression) : '';
155
+ const asString = typeof raw === 'string' ? raw.trim() : '';
156
+ const expr = cronExpr || (CRON_SHAPE_RE.test(asString) ? asString : '');
157
+ if (expr) {
158
+ const zone = zoneOf();
159
+ const timezone = zone ?? fallbackTimezone;
160
+ const original = `${expr}${zone ? ` (${zone})` : ''}`;
161
+ const cadence = cadenceFromCron(expr);
162
+ if (!cadence) {
163
+ return {
164
+ original,
165
+ savedCadence: null,
166
+ summary: `no saved schedule: a Duty cannot run "${expr}" exactly; choose a cadence when you turn it on`,
167
+ };
168
+ }
169
+ const saved = { ...cadence, timezone };
170
+ return {
171
+ original,
172
+ savedCadence: saved,
173
+ summary: summarize(saved),
174
+ ...(zone ? {} : { timezoneAssumed: true }),
175
+ };
176
+ }
177
+ const everyMs = kind === 'every'
178
+ ? Number(object?.everyMs)
179
+ : kind === 'interval'
180
+ ? Number(object?.minutes) * 60_000 ||
181
+ Number(object?.everyMs) ||
182
+ Number(object?.seconds) * 1000
183
+ : Number.NaN;
184
+ let intervalMs = everyMs;
185
+ // Only "every 30m" repeats: in Hermes a bare "30m" is ONE run, thirty minutes after it was set.
186
+ if (!Number.isFinite(intervalMs) && EVERY_PREFIX_RE.test(asString)) {
187
+ try {
188
+ intervalMs = (0, duties_1.parseIntervalToMs)(asString.replace(EVERY_PREFIX_RE, ''));
189
+ }
190
+ catch {
191
+ intervalMs = Number.NaN;
192
+ }
193
+ }
194
+ if (Number.isFinite(intervalMs)) {
195
+ const original = display || (asString ? asString : describeInterval(intervalMs));
196
+ const cadence = interval(intervalMs);
197
+ if (!cadence) {
198
+ return {
199
+ original,
200
+ savedCadence: null,
201
+ summary: 'no saved schedule: a Duty checks at most once a minute and at least once a year',
202
+ };
203
+ }
204
+ return { original, savedCadence: cadence, summary: summarize(cadence) };
205
+ }
206
+ if (kind === 'at' || kind === 'once' || ISO_INSTANT_RE.test(asString)) {
207
+ const when = text(object?.at) || text(object?.run_at) || text(object?.runAt) || asString;
208
+ return {
209
+ original: display || (when ? `once, at ${when}` : 'once'),
210
+ savedCadence: null,
211
+ summary: 'no saved schedule: it was a single run, which a Duty does not save',
212
+ oneOff: true,
213
+ };
214
+ }
215
+ return {
216
+ original: display || (asString ? asString : kind ? `a "${kind}" schedule` : 'no schedule'),
217
+ savedCadence: null,
218
+ summary: 'no saved schedule: this import cannot read that schedule; choose a cadence when you turn it on',
219
+ };
220
+ }