@skrr-ai/cli 0.1.207 → 0.1.208
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/dist/commands/agent/message/resolve.d.ts +31 -0
- package/dist/commands/agent/message/resolve.js +111 -0
- package/dist/commands/agent/message/send.d.ts +17 -5
- package/dist/commands/agent/message/send.js +77 -26
- package/dist/commands/agent/request/list.d.ts +15 -0
- package/dist/commands/agent/request/list.js +82 -0
- package/dist/commands/agent/request/send.d.ts +18 -0
- package/dist/commands/agent/request/send.js +56 -0
- package/dist/commands/agents/access/approve.d.ts +17 -0
- package/dist/commands/agents/access/approve.js +94 -0
- package/dist/commands/agents/access/deny.d.ts +10 -0
- package/dist/commands/agents/access/deny.js +36 -0
- package/dist/commands/agents/access/list.d.ts +10 -0
- package/dist/commands/agents/access/list.js +53 -0
- package/dist/commands/agents/access/reach.d.ts +13 -0
- package/dist/commands/agents/access/reach.js +53 -0
- package/dist/commands/agents/access/revoke.d.ts +13 -0
- package/dist/commands/agents/access/revoke.js +50 -0
- package/dist/commands/agents/import.d.ts +15 -1
- package/dist/commands/agents/import.js +211 -23
- package/dist/commands/agents/intuitions/accept.d.ts +0 -1
- package/dist/commands/agents/intuitions/accept.js +22 -7
- package/dist/commands/agents/intuitions/generate.d.ts +0 -1
- package/dist/commands/agents/intuitions/generate.js +4 -16
- package/dist/commands/agents/intuitions/list.js +9 -3
- package/dist/commands/agents/intuitions/resume.d.ts +11 -0
- package/dist/commands/agents/intuitions/resume.js +37 -0
- package/dist/commands/agents/shared-memory.d.ts +24 -0
- package/dist/commands/agents/shared-memory.js +67 -0
- package/dist/commands/agents/visibility.d.ts +1 -0
- package/dist/commands/agents/visibility.js +14 -0
- package/dist/commands/code/migrate.js +3 -1
- package/dist/commands/duties/advance-next.js +15 -6
- package/dist/commands/followups/show.js +9 -0
- package/dist/commands/followups/watch-pr.d.ts +27 -0
- package/dist/commands/followups/watch-pr.js +123 -0
- package/dist/commands/memory/consolidation/index.d.ts +20 -0
- package/dist/commands/memory/consolidation/index.js +78 -0
- package/dist/commands/memory/consolidation/resume.d.ts +14 -0
- package/dist/commands/memory/consolidation/resume.js +46 -0
- package/dist/commands/memory/consolidation/undo.d.ts +18 -0
- package/dist/commands/memory/consolidation/undo.js +60 -0
- package/dist/commands/slack/mutes.d.ts +10 -0
- package/dist/commands/slack/mutes.js +62 -0
- package/dist/commands/slack/unmute.d.ts +12 -0
- package/dist/commands/slack/unmute.js +44 -0
- package/dist/commands/tasks/actionability.js +9 -0
- package/dist/commands/tasks/ask.d.ts +50 -0
- package/dist/commands/tasks/ask.js +190 -0
- package/dist/commands/tasks/handover.js +14 -0
- package/dist/commands/tasks/input/answer.js +8 -2
- package/dist/commands/tasks/input/show.d.ts +26 -0
- package/dist/commands/tasks/input/show.js +185 -17
- package/dist/commands/tasks/move.d.ts +11 -0
- package/dist/commands/tasks/move.js +82 -1
- package/dist/commands/tasks/result/submit.js +3 -0
- package/dist/commands/tasks/runs.d.ts +4 -1
- package/dist/commands/tasks/runs.js +22 -3
- package/dist/commands/tasks/show.js +22 -1
- package/dist/commands/tasks/update.d.ts +1 -0
- package/dist/commands/tasks/update.js +52 -1
- package/dist/commands/tasks/updates/add.js +3 -0
- package/dist/commands/tasks/wait.d.ts +20 -0
- package/dist/commands/tasks/wait.js +102 -1
- package/dist/generated/agent-guides.json +501 -92
- package/dist/generated/managed-instruction-guides.json +1 -1
- package/dist/lib/agent-access-command.d.ts +19 -0
- package/dist/lib/agent-access-command.js +44 -0
- package/dist/lib/agent-access.d.ts +18 -0
- package/dist/lib/agent-access.js +48 -0
- package/dist/lib/agent-import/apply.d.ts +50 -0
- package/dist/lib/agent-import/apply.js +85 -0
- package/dist/lib/agent-import/plan.d.ts +132 -0
- package/dist/lib/agent-import/plan.js +504 -0
- package/dist/lib/agent-import/reader.d.ts +94 -0
- package/dist/lib/agent-import/reader.js +326 -0
- package/dist/lib/agent-import/schedule.d.ts +46 -0
- package/dist/lib/agent-import/schedule.js +220 -0
- package/dist/lib/agent-import/sources.d.ts +124 -0
- package/dist/lib/agent-import/sources.js +797 -0
- package/dist/lib/followups.d.ts +61 -0
- package/dist/lib/followups.js +39 -0
- package/dist/lib/handover-interview.d.ts +18 -0
- package/dist/lib/handover-interview.js +53 -0
- package/dist/lib/input-queue.js +2 -1
- package/dist/lib/intuition-look.d.ts +10 -0
- package/dist/lib/intuition-look.js +64 -0
- package/dist/lib/record-output.d.ts +1 -1
- package/dist/lib/record-output.js +2 -0
- package/dist/lib/skill-import.d.ts +19 -0
- package/dist/lib/skill-import.js +34 -0
- package/dist/lib/slack-thread-mutes.d.ts +25 -0
- package/dist/lib/slack-thread-mutes.js +12 -0
- package/dist/lib/task-carriers.d.ts +18 -0
- package/dist/lib/task-carriers.js +43 -0
- package/dist/lib/task-extras.d.ts +5 -0
- package/dist/lib/task-extras.js +5 -0
- package/dist/lib/task-recurrence-summary.d.ts +15 -0
- package/dist/lib/task-recurrence-summary.js +22 -0
- package/dist/lib/task-version.d.ts +44 -0
- package/dist/lib/task-version.js +73 -0
- package/dist/lib/task-write-attribution.d.ts +7 -0
- package/dist/lib/task-write-attribution.js +14 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/turnPacing.d.ts +75 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/turnPacing.js +124 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/turnPacing.d.ts +75 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/turnPacing.js +141 -0
- package/dist/node_modules/@skrr-ai/auth-core/package.json +10 -0
- package/dist/node_modules/@skrr-ai/data-provider/index.js +13323 -12577
- package/oclif.manifest.json +1787 -107
- package/package.json +5 -2
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SECRET_KIND_WORDS = exports.IMPORT_PLAN_GROUP_TITLES = exports.IMPORT_PLAN_GROUPS = exports.IMPORT_REASON_PREFIX = exports.DUTY_DIRECTIVE_MAX_CHARS = exports.MEMORY_CLAIM_MAX_CHARS = exports.PERSONA_FILE_MAX_CHARS = void 0;
|
|
4
|
+
exports.loadImportTarget = loadImportTarget;
|
|
5
|
+
exports.memoryImportKey = memoryImportKey;
|
|
6
|
+
exports.dutyImportKey = dutyImportKey;
|
|
7
|
+
exports.buildImportPlan = buildImportPlan;
|
|
8
|
+
exports.planWrites = planWrites;
|
|
9
|
+
exports.planForOutput = planForOutput;
|
|
10
|
+
exports.renderImportPlan = renderImportPlan;
|
|
11
|
+
/**
|
|
12
|
+
* What importing a bot would do to one Skrr agent, decided before anything is written.
|
|
13
|
+
*
|
|
14
|
+
* The plan is the product: a person moving a bot sees, item by item, what comes over as it is, what
|
|
15
|
+
* comes over changed, what is already here, what this agent already has its own version of (kept),
|
|
16
|
+
* and what stays behind and why — including every file that was never read and every line left out
|
|
17
|
+
* because it looked like a secret. `skrr agents import` writes nothing until the person says yes to
|
|
18
|
+
* exactly this list (`--yes` when there is nobody to ask).
|
|
19
|
+
*
|
|
20
|
+
* Where each kind of thing goes, and why there:
|
|
21
|
+
* - **Persona** files go through the persona file endpoint (`PUT /api/bootstrap/:fileType`, the
|
|
22
|
+
* service `bootstrap_update_file` writes through), so the layer each file belongs to, its version
|
|
23
|
+
* and its history are the same as for any other edit. The history entry's reason names the source,
|
|
24
|
+
* which is how a re-import tells "our earlier import, untouched since" (update it) from "changed
|
|
25
|
+
* here" (keep it, unless `--replace-persona`).
|
|
26
|
+
* - **Notes** (MEMORY.md, daily notes, Hermes memories, the old runtime's AGENTS.md) become Memory
|
|
27
|
+
* PROPOSALS with `import` evidence naming the source file. Nothing becomes a remembered fact until
|
|
28
|
+
* the person accepts it, and once accepted it reaches a prompt the way every Memory does: fenced
|
|
29
|
+
* as untrusted data. The old bot's notes are notes, not orders.
|
|
30
|
+
* - **Skills** are created through the same conversion as `skrr agents import <SKILL.md>`.
|
|
31
|
+
* - **Schedules** (cron jobs, the OpenClaw heartbeat) become DRAFT Duties through the Duty manifest
|
|
32
|
+
* import, which only ever creates drafts. The schedule is saved beside the Duty, not running, so
|
|
33
|
+
* nothing imported runs on its own: the person restores the schedule and turns the Duty on.
|
|
34
|
+
*
|
|
35
|
+
* Re-importing is idempotent by construction, not by checking: a proposal carries a key derived
|
|
36
|
+
* from its source and words (the server replays a repeated key), a Duty carries an `externalKey`
|
|
37
|
+
* (unique per agent), a skill and a persona file are compared with what the agent holds.
|
|
38
|
+
*/
|
|
39
|
+
const node_crypto_1 = require("node:crypto");
|
|
40
|
+
const data_provider_1 = require("@skrr-ai/data-provider");
|
|
41
|
+
const skill_import_1 = require("../skill-import");
|
|
42
|
+
const reader_1 = require("./reader");
|
|
43
|
+
const sources_1 = require("./sources");
|
|
44
|
+
/** The persona endpoint's limit (`BootstrapController`). */
|
|
45
|
+
exports.PERSONA_FILE_MAX_CHARS = 20_000;
|
|
46
|
+
/** The Memory proposal limit (`WorkspaceService.validateMemoryInput`). */
|
|
47
|
+
exports.MEMORY_CLAIM_MAX_CHARS = 50_000;
|
|
48
|
+
const MEMORY_TITLE_MAX_CHARS = 240;
|
|
49
|
+
const DUTY_TITLE_MAX_CHARS = 200;
|
|
50
|
+
/**
|
|
51
|
+
* What `POST /api/duties/import` accepts (`api/server/services/Duties/dutyTextLimits.js`). The server
|
|
52
|
+
* refuses longer text rather than cutting it, and so does the plan: an instruction cut short is a
|
|
53
|
+
* different instruction.
|
|
54
|
+
*/
|
|
55
|
+
exports.DUTY_DIRECTIVE_MAX_CHARS = 8_000;
|
|
56
|
+
const DUTY_DESCRIPTION_MAX_CHARS = 5_000;
|
|
57
|
+
/** How sure an imported note is: another app's record, not something this agent saw. */
|
|
58
|
+
const IMPORTED_NOTE_CONFIDENCE = 0.6;
|
|
59
|
+
/** Every persona edit the importer makes starts with this, so a re-import can find its own. */
|
|
60
|
+
exports.IMPORT_REASON_PREFIX = 'Imported from ';
|
|
61
|
+
const PROPOSAL_STATUSES = ['proposed', 'accepted', 'merged', 'rejected'];
|
|
62
|
+
exports.IMPORT_PLAN_GROUPS = ['comes', 'changed', 'already', 'kept', 'stays'];
|
|
63
|
+
exports.IMPORT_PLAN_GROUP_TITLES = Object.freeze({
|
|
64
|
+
comes: 'Comes over',
|
|
65
|
+
changed: 'Comes over, changed',
|
|
66
|
+
already: 'Already here',
|
|
67
|
+
kept: 'Kept as it is here',
|
|
68
|
+
stays: 'Stays behind',
|
|
69
|
+
});
|
|
70
|
+
const GROUP_MARKS = Object.freeze({
|
|
71
|
+
comes: '+',
|
|
72
|
+
changed: '~',
|
|
73
|
+
already: '=',
|
|
74
|
+
kept: '!',
|
|
75
|
+
stays: '-',
|
|
76
|
+
});
|
|
77
|
+
/** What a left-out line looked like, in words. Never the line. */
|
|
78
|
+
exports.SECRET_KIND_WORDS = Object.freeze({
|
|
79
|
+
private_key: 'a private key',
|
|
80
|
+
key_block: 'a key block',
|
|
81
|
+
aws_access_key: 'an AWS key',
|
|
82
|
+
github_token: 'a GitHub token',
|
|
83
|
+
slack_token: 'a Slack token',
|
|
84
|
+
bearer_token: 'a bearer token',
|
|
85
|
+
jwt: 'a signed token',
|
|
86
|
+
credential_assignment: 'a password or key',
|
|
87
|
+
url_credentials: 'an address with a password in it',
|
|
88
|
+
provider_api_key: 'an API key',
|
|
89
|
+
google_api_key: 'a Google API key',
|
|
90
|
+
gitlab_token: 'a GitLab token',
|
|
91
|
+
npm_token: 'an npm token',
|
|
92
|
+
stripe_secret_key: 'a Stripe key',
|
|
93
|
+
telegram_bot_token: 'a Telegram bot token',
|
|
94
|
+
url_secret_param: 'an address carrying a key',
|
|
95
|
+
env_credential: 'a key in an environment variable',
|
|
96
|
+
credential_phrase: 'a password or key',
|
|
97
|
+
});
|
|
98
|
+
const DUTY_PAGE_LIMIT = 100;
|
|
99
|
+
const DUTY_PAGES_MAX = 20;
|
|
100
|
+
/** Read what `agentId` already holds. Any failure is the caller's: a plan on a partial read could overwrite. */
|
|
101
|
+
async function loadImportTarget(agentId, readers, personaFiles) {
|
|
102
|
+
const bootstrap = await readers.getBootstrap(agentId);
|
|
103
|
+
const personaHistory = {};
|
|
104
|
+
for (const fileType of personaFiles) {
|
|
105
|
+
const { history = [] } = await readers.getBootstrapHistory(agentId, { fileType, limit: 50 });
|
|
106
|
+
personaHistory[fileType] = history
|
|
107
|
+
.filter((entry) => !entry.fileType || entry.fileType === fileType)
|
|
108
|
+
.sort((a, b) => String(b.changedAt ?? '').localeCompare(String(a.changedAt ?? '')));
|
|
109
|
+
}
|
|
110
|
+
const skills = (await readers.getSkillsByAgent(agentId)).data ?? [];
|
|
111
|
+
const importedProposals = new Map();
|
|
112
|
+
for (const status of PROPOSAL_STATUSES) {
|
|
113
|
+
const { proposals = [] } = await readers.listProposals(agentId, status);
|
|
114
|
+
for (const proposal of proposals) {
|
|
115
|
+
for (const evidence of Array.isArray(proposal.evidence) ? proposal.evidence : []) {
|
|
116
|
+
const key = evidence?.metadata?.importKey;
|
|
117
|
+
if (typeof key === 'string')
|
|
118
|
+
importedProposals.set(key, proposal.status ?? status);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const importedDuties = new Map();
|
|
123
|
+
let cursor;
|
|
124
|
+
for (let page = 0; page < DUTY_PAGES_MAX; page += 1) {
|
|
125
|
+
const response = await readers.listDuties({
|
|
126
|
+
agentId,
|
|
127
|
+
limit: DUTY_PAGE_LIMIT,
|
|
128
|
+
...(cursor ? { cursor } : {}),
|
|
129
|
+
});
|
|
130
|
+
for (const duty of response.data ?? []) {
|
|
131
|
+
if (duty.externalKey?.startsWith('import:'))
|
|
132
|
+
importedDuties.set(duty.externalKey, { id: duty.id, status: duty.status });
|
|
133
|
+
}
|
|
134
|
+
if (!response.has_more || !response.next_cursor)
|
|
135
|
+
break;
|
|
136
|
+
cursor = response.next_cursor;
|
|
137
|
+
}
|
|
138
|
+
return { agentId, bootstrap, personaHistory, skills, importedProposals, importedDuties };
|
|
139
|
+
}
|
|
140
|
+
function sha(value) {
|
|
141
|
+
return (0, node_crypto_1.createHash)('sha256').update(value).digest('hex');
|
|
142
|
+
}
|
|
143
|
+
function slug(value, max = 60) {
|
|
144
|
+
const out = value
|
|
145
|
+
.toLowerCase()
|
|
146
|
+
.replace(/[^a-z0-9._-]+/g, '-')
|
|
147
|
+
.replace(/^-+|-+$/g, '')
|
|
148
|
+
.slice(0, max);
|
|
149
|
+
return out || sha(value).slice(0, 12);
|
|
150
|
+
}
|
|
151
|
+
function clip(text, max) {
|
|
152
|
+
return text.length <= max ? text : `${text.slice(0, max - 1).trimEnd()}…`;
|
|
153
|
+
}
|
|
154
|
+
function where(source, from) {
|
|
155
|
+
return from ? `${source.folder}/${from}` : source.folder;
|
|
156
|
+
}
|
|
157
|
+
/** The proposal key: one note, from one file of one bot, in these words. */
|
|
158
|
+
function memoryImportKey(source, from, claim) {
|
|
159
|
+
return `import:${source.app}:${sha([source.app, source.sourceAgent, from, claim].join('\0')).slice(0, 40)}`;
|
|
160
|
+
}
|
|
161
|
+
/** The Duty key: one job of one bot. Stable across re-imports even when the job's words change. */
|
|
162
|
+
function dutyImportKey(source, sourceId) {
|
|
163
|
+
return `import:${source.app}:${slug(source.sourceAgent)}:${slug(sourceId, 120)}`;
|
|
164
|
+
}
|
|
165
|
+
function dutyDescription(source, job, appLabel) {
|
|
166
|
+
const ran = job.origin === 'heartbeat' ? 'There it was checked' : 'There it ran';
|
|
167
|
+
const parts = [
|
|
168
|
+
`Imported from ${appLabel} (${where(source, job.from)}${job.origin === 'cron' ? `, job "${job.sourceId}"` : ''}). ${ran} ${job.schedule.original}${job.deliveredTo ? ` and sent its results to ${job.deliveredTo}` : ''}.${job.wasOff ? ' It was switched off there.' : ''}`,
|
|
169
|
+
'It arrives as a draft and never runs on its own.',
|
|
170
|
+
job.schedule.savedCadence
|
|
171
|
+
? `Its schedule is saved but not running: ${job.schedule.summary}. When the old one is off, restore it with \`skrr duties update <id> --restore-saved-cadence\` and turn this Duty on with \`skrr duties resume <id>\`.`
|
|
172
|
+
: `It has ${job.schedule.summary}. Set a cadence with \`skrr duties update <id>\` and turn it on with \`skrr duties resume <id>\`.`,
|
|
173
|
+
];
|
|
174
|
+
return parts.join('\n\n');
|
|
175
|
+
}
|
|
176
|
+
function dutyManifest(source, job, appLabel, externalKey) {
|
|
177
|
+
const savedCadence = job.schedule.savedCadence;
|
|
178
|
+
return {
|
|
179
|
+
manifestKind: 'oversky.duty.manifest',
|
|
180
|
+
manifestVersion: savedCadence ? 2 : 1,
|
|
181
|
+
externalKey,
|
|
182
|
+
externalVersion: 1,
|
|
183
|
+
body: {
|
|
184
|
+
title: clip(job.origin === 'heartbeat' ? `${job.name} (from ${appLabel})` : job.name, DUTY_TITLE_MAX_CHARS),
|
|
185
|
+
description: clip(dutyDescription(source, job, appLabel), DUTY_DESCRIPTION_MAX_CHARS),
|
|
186
|
+
agentDirective: job.instruction,
|
|
187
|
+
kind: 'maintain',
|
|
188
|
+
target: {
|
|
189
|
+
outcome: job.origin === 'heartbeat'
|
|
190
|
+
? `The heartbeat checklist ${source.name} kept in ${appLabel} is worked through, and anything that needs the owner is raised.`
|
|
191
|
+
: `"${clip(job.name, 120)}" is carried out on its schedule, as ${source.name} did it in ${appLabel}.`,
|
|
192
|
+
},
|
|
193
|
+
cadence: { mode: 'manual' },
|
|
194
|
+
...(savedCadence ? { savedCadence } : {}),
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function personaItem(source, file, target, { replacePersona }) {
|
|
199
|
+
const fileName = sources_1.IMPORT_PERSONA_FILE_NAMES[file.fileType];
|
|
200
|
+
const base = {
|
|
201
|
+
area: 'persona',
|
|
202
|
+
what: `Persona ${fileName}`,
|
|
203
|
+
from: file.from,
|
|
204
|
+
to: `this agent's ${fileName}`,
|
|
205
|
+
};
|
|
206
|
+
if (file.content.length > exports.PERSONA_FILE_MAX_CHARS) {
|
|
207
|
+
return {
|
|
208
|
+
...base,
|
|
209
|
+
group: 'stays',
|
|
210
|
+
why: `It is longer than the ${exports.PERSONA_FILE_MAX_CHARS.toLocaleString('en-US')} characters a persona file holds.`,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const action = {
|
|
214
|
+
kind: 'persona',
|
|
215
|
+
fileType: file.fileType,
|
|
216
|
+
content: file.content,
|
|
217
|
+
reason: `${exports.IMPORT_REASON_PREFIX}${sources_1.AGENT_IMPORT_APP_LABELS[source.app]}: ${where(source, file.from)}`,
|
|
218
|
+
};
|
|
219
|
+
if (!target)
|
|
220
|
+
return { ...base, group: 'comes', action };
|
|
221
|
+
const current = target.bootstrap[file.fileType];
|
|
222
|
+
const currentContent = (current?.content ?? '').trim();
|
|
223
|
+
if (currentContent === file.content.trim())
|
|
224
|
+
return { ...base, group: 'already' };
|
|
225
|
+
const last = target.personaHistory[file.fileType]?.[0];
|
|
226
|
+
const untouchedImport = Boolean(last?.reason?.startsWith(exports.IMPORT_REASON_PREFIX)) &&
|
|
227
|
+
(last?.newContent ?? '').trim() === currentContent;
|
|
228
|
+
if (!currentContent || !current?.updatedBy || current.updatedBy === 'system') {
|
|
229
|
+
return { ...base, group: 'comes', why: 'It replaces the starting template.', action };
|
|
230
|
+
}
|
|
231
|
+
if (untouchedImport) {
|
|
232
|
+
return {
|
|
233
|
+
...base,
|
|
234
|
+
group: 'changed',
|
|
235
|
+
why: `It changed in ${sources_1.AGENT_IMPORT_APP_LABELS[source.app]} since the last import, and nobody has edited it here since.`,
|
|
236
|
+
action,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (replacePersona) {
|
|
240
|
+
return {
|
|
241
|
+
...base,
|
|
242
|
+
group: 'changed',
|
|
243
|
+
why: 'It replaces the version written here, as --replace-persona asks. The old one stays in the file’s history.',
|
|
244
|
+
action,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
...base,
|
|
249
|
+
group: 'kept',
|
|
250
|
+
why: `This agent's ${fileName} was written here, so it is kept. Re-run with --replace-persona to replace it (the old one stays in its history).`,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function scheduleItem(source, job, target) {
|
|
254
|
+
const appLabel = sources_1.AGENT_IMPORT_APP_LABELS[source.app];
|
|
255
|
+
const base = { area: 'duty', what: `Duty "${clip(job.name, 80)}"`, from: job.from };
|
|
256
|
+
if (job.schedule.oneOff) {
|
|
257
|
+
return {
|
|
258
|
+
...base,
|
|
259
|
+
group: 'stays',
|
|
260
|
+
why: `It was a single run (${job.schedule.original}); a Duty is a standing responsibility.`,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
if (job.instruction.length > exports.DUTY_DIRECTIVE_MAX_CHARS) {
|
|
264
|
+
return {
|
|
265
|
+
...base,
|
|
266
|
+
group: 'stays',
|
|
267
|
+
why: `Its instruction is longer than the ${exports.DUTY_DIRECTIVE_MAX_CHARS.toLocaleString('en-US')} characters a Duty holds. Shorten it there, or write the Duty here.`,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
const externalKey = dutyImportKey(source, job.sourceId);
|
|
271
|
+
const existing = target?.importedDuties.get(externalKey);
|
|
272
|
+
if (existing) {
|
|
273
|
+
return {
|
|
274
|
+
...base,
|
|
275
|
+
group: 'already',
|
|
276
|
+
why: `Imported before as Duty ${existing.id} (${existing.status}); a re-import does not change it.`,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
const notes = [
|
|
280
|
+
job.schedule.savedCadence
|
|
281
|
+
? `Its schedule is saved, not running: ${job.schedule.summary}.${job.schedule.timezoneAssumed ? ' The job named no time zone, so it is this computer’s.' : ''}`
|
|
282
|
+
: `${job.schedule.summary.replace(/^no saved schedule: /, 'No saved schedule: ')}.`,
|
|
283
|
+
job.deliveredTo
|
|
284
|
+
? `Its results went to ${job.deliveredTo}; a Duty reports to you in ${data_provider_1.BRAND.displayName}.`
|
|
285
|
+
: '',
|
|
286
|
+
job.wasOff ? `It was switched off in ${appLabel}.` : '',
|
|
287
|
+
].filter(Boolean);
|
|
288
|
+
return {
|
|
289
|
+
...base,
|
|
290
|
+
group: 'comes',
|
|
291
|
+
to: 'a draft Duty (it never runs until you turn it on)',
|
|
292
|
+
why: notes.join(' '),
|
|
293
|
+
action: {
|
|
294
|
+
kind: 'duty',
|
|
295
|
+
externalKey,
|
|
296
|
+
manifest: dutyManifest(source, job, appLabel, externalKey),
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/** Decide every item. `target` null makes a plan with nothing to compare against. */
|
|
301
|
+
function buildImportPlan(source, target, options = {}) {
|
|
302
|
+
const appLabel = sources_1.AGENT_IMPORT_APP_LABELS[source.app];
|
|
303
|
+
const items = [];
|
|
304
|
+
for (const file of source.persona) {
|
|
305
|
+
items.push(personaItem(source, file, target, { replacePersona: options.replacePersona === true }));
|
|
306
|
+
}
|
|
307
|
+
const seenKeys = new Set();
|
|
308
|
+
for (const note of source.memories) {
|
|
309
|
+
const base = {
|
|
310
|
+
area: 'memory',
|
|
311
|
+
what: clip(note.title, 80),
|
|
312
|
+
from: note.from,
|
|
313
|
+
line: note.line,
|
|
314
|
+
};
|
|
315
|
+
if (note.claim.length > exports.MEMORY_CLAIM_MAX_CHARS) {
|
|
316
|
+
items.push({
|
|
317
|
+
...base,
|
|
318
|
+
group: 'stays',
|
|
319
|
+
why: `It is longer than the ${exports.MEMORY_CLAIM_MAX_CHARS.toLocaleString('en-US')} characters a Memory proposal holds.`,
|
|
320
|
+
});
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
const key = memoryImportKey(source, note.from, note.claim);
|
|
324
|
+
if (seenKeys.has(key))
|
|
325
|
+
continue;
|
|
326
|
+
seenKeys.add(key);
|
|
327
|
+
const status = target?.importedProposals.get(key);
|
|
328
|
+
if (status) {
|
|
329
|
+
items.push({
|
|
330
|
+
...base,
|
|
331
|
+
group: 'already',
|
|
332
|
+
why: status === 'rejected'
|
|
333
|
+
? 'You turned this proposal down before; it is not proposed again.'
|
|
334
|
+
: status === 'proposed'
|
|
335
|
+
? 'Proposed by an earlier import, waiting for your review.'
|
|
336
|
+
: 'Accepted into Memory from an earlier import.',
|
|
337
|
+
});
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
items.push({
|
|
341
|
+
...base,
|
|
342
|
+
group: 'comes',
|
|
343
|
+
to: 'a Memory proposal (you review it before it becomes Memory)',
|
|
344
|
+
action: {
|
|
345
|
+
kind: 'memory',
|
|
346
|
+
input: {
|
|
347
|
+
path: note.path,
|
|
348
|
+
claim: note.claim,
|
|
349
|
+
title: clip(note.title, MEMORY_TITLE_MAX_CHARS),
|
|
350
|
+
memoryKind: note.memoryKind,
|
|
351
|
+
confidence: IMPORTED_NOTE_CONFIDENCE,
|
|
352
|
+
evidence: [
|
|
353
|
+
{
|
|
354
|
+
sourceKind: 'import',
|
|
355
|
+
sourceRef: `${source.app}:${where(source, note.from)}`,
|
|
356
|
+
metadata: {
|
|
357
|
+
importKey: key,
|
|
358
|
+
app: source.app,
|
|
359
|
+
sourceAgent: source.sourceAgent,
|
|
360
|
+
path: where(source, note.from),
|
|
361
|
+
...(note.line ? { line: note.line } : {}),
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
],
|
|
365
|
+
idempotencyKey: key,
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
for (const candidate of source.skills) {
|
|
371
|
+
const stored = (0, skill_import_1.storedSkillName)(candidate.skill.name);
|
|
372
|
+
const base = { area: 'skill', what: `Skill "${stored}"`, from: candidate.from };
|
|
373
|
+
const existing = target?.skills.find((skill) => (0, skill_import_1.storedSkillName)(skill.name) === stored);
|
|
374
|
+
if (existing) {
|
|
375
|
+
items.push((existing.content ?? '').trim() === candidate.skill.content.trim()
|
|
376
|
+
? { ...base, group: 'already' }
|
|
377
|
+
: {
|
|
378
|
+
...base,
|
|
379
|
+
group: 'kept',
|
|
380
|
+
why: 'This agent already has a skill by that name, and it differs; it is kept.',
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
const dropped = candidate.dropped.map((drop) => `"${drop.key}" is left out (${data_provider_1.CLAUDE_CODE_IMPORT_DROP_REASONS[drop.reason]}).`);
|
|
385
|
+
const files = candidate.files.map((file) => file.path);
|
|
386
|
+
items.push({
|
|
387
|
+
...base,
|
|
388
|
+
group: dropped.length ? 'changed' : 'comes',
|
|
389
|
+
to: files.length
|
|
390
|
+
? `a skill on this agent, with ${files.length} ${files.length === 1 ? 'file' : 'files'} beside it (${clip(files.join(', '), 80)})`
|
|
391
|
+
: 'a skill on this agent',
|
|
392
|
+
...(dropped.length ? { why: dropped.join(' ') } : {}),
|
|
393
|
+
action: { kind: 'skill', skill: candidate.skill },
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
// A file beside SKILL.md that does not travel is in the reader's record, by path and reason,
|
|
397
|
+
// and is listed below with every other file that stays behind.
|
|
398
|
+
}
|
|
399
|
+
for (const job of source.schedules)
|
|
400
|
+
items.push(scheduleItem(source, job, target));
|
|
401
|
+
const explained = new Set(source.stays.map((entry) => entry.from).filter(Boolean));
|
|
402
|
+
for (const entry of source.stays) {
|
|
403
|
+
items.push({
|
|
404
|
+
group: 'stays',
|
|
405
|
+
area: 'source',
|
|
406
|
+
what: entry.what,
|
|
407
|
+
from: entry.from,
|
|
408
|
+
why: entry.why,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
for (const refusal of source.reader.refused) {
|
|
412
|
+
if (explained.has(refusal.from) || explained.has(`${refusal.from}/`))
|
|
413
|
+
continue;
|
|
414
|
+
items.push({
|
|
415
|
+
group: 'stays',
|
|
416
|
+
area: 'file',
|
|
417
|
+
what: refusal.from,
|
|
418
|
+
from: refusal.from,
|
|
419
|
+
why: `${reader_1.IMPORT_REFUSAL_REASONS[refusal.reason]}.`,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
items.push(...leftOutItems(source.reader.leftOut));
|
|
423
|
+
return {
|
|
424
|
+
app: source.app,
|
|
425
|
+
appLabel,
|
|
426
|
+
folder: source.folder,
|
|
427
|
+
sourceAgent: source.sourceAgent,
|
|
428
|
+
name: source.name,
|
|
429
|
+
agentId: target?.agentId ?? null,
|
|
430
|
+
items,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
/** One "stays" line per file: how many lines were left out, where, and what they looked like. */
|
|
434
|
+
function leftOutItems(leftOut) {
|
|
435
|
+
const byFile = new Map();
|
|
436
|
+
for (const entry of leftOut)
|
|
437
|
+
byFile.set(entry.from, [...(byFile.get(entry.from) ?? []), entry]);
|
|
438
|
+
return [...byFile.entries()].map(([from, entries]) => {
|
|
439
|
+
const places = entries
|
|
440
|
+
.map((entry) => (entry.line ? `line ${entry.line}` : entry.field))
|
|
441
|
+
.filter(Boolean);
|
|
442
|
+
const kinds = [...new Set(entries.map((entry) => exports.SECRET_KIND_WORDS[entry.kind]))];
|
|
443
|
+
const count = entries.length;
|
|
444
|
+
return {
|
|
445
|
+
group: 'stays',
|
|
446
|
+
area: 'secret',
|
|
447
|
+
what: `${count} ${count === 1 ? 'line' : 'lines'} of ${from} (${clip(places.join(', '), 60)})`,
|
|
448
|
+
from,
|
|
449
|
+
why: `Left out: ${count === 1 ? 'it' : 'they'} looked like ${kinds.join(', ')}. Nothing that looks like a key or password travels; sign in again here instead.`,
|
|
450
|
+
};
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
/** Whether the plan has anything to write. */
|
|
454
|
+
function planWrites(plan) {
|
|
455
|
+
return plan.items.filter((item) => item.action && (item.group === 'comes' || item.group === 'changed'));
|
|
456
|
+
}
|
|
457
|
+
/** The plan as JSON output: every item, without the content it would write. */
|
|
458
|
+
function planForOutput(plan) {
|
|
459
|
+
return {
|
|
460
|
+
source: { app: plan.app, folder: plan.folder, sourceAgent: plan.sourceAgent, name: plan.name },
|
|
461
|
+
agentId: plan.agentId,
|
|
462
|
+
items: plan.items.map(({ action: _action, ...item }) => item),
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
/** The plan in words, grouped, memory notes from one file folded into one line. */
|
|
466
|
+
function renderImportPlan(plan) {
|
|
467
|
+
const lines = [];
|
|
468
|
+
lines.push(`Import from ${plan.appLabel}: ${plan.name} (${plan.sourceAgent === plan.name ? '' : `"${plan.sourceAgent}", `}${plan.folder})`);
|
|
469
|
+
lines.push(plan.agentId
|
|
470
|
+
? `Into agent ${plan.agentId}`
|
|
471
|
+
: 'No agent chosen yet: nothing is compared or written.');
|
|
472
|
+
for (const group of exports.IMPORT_PLAN_GROUPS) {
|
|
473
|
+
const items = plan.items.filter((item) => item.group === group);
|
|
474
|
+
if (!items.length)
|
|
475
|
+
continue;
|
|
476
|
+
lines.push('', exports.IMPORT_PLAN_GROUP_TITLES[group]);
|
|
477
|
+
const mark = GROUP_MARKS[group];
|
|
478
|
+
const notes = new Map();
|
|
479
|
+
for (const item of items) {
|
|
480
|
+
if (item.area === 'memory') {
|
|
481
|
+
const key = `${item.from}\0${item.why ?? ''}`;
|
|
482
|
+
notes.set(key, [...(notes.get(key) ?? []), item]);
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
lines.push(` ${mark} ${item.what}${item.from && !item.what.includes(item.from) ? ` (${item.from})` : ''}`);
|
|
486
|
+
if (item.to && (group === 'comes' || group === 'changed'))
|
|
487
|
+
lines.push(` becomes ${item.to}`);
|
|
488
|
+
if (item.why)
|
|
489
|
+
lines.push(` ${item.why}`);
|
|
490
|
+
}
|
|
491
|
+
for (const folded of notes.values()) {
|
|
492
|
+
const first = folded[0];
|
|
493
|
+
const count = folded.length;
|
|
494
|
+
const titles = folded.slice(0, 3).map((item) => `"${clip(item.what, 40)}"`);
|
|
495
|
+
const more = count > 3 ? ` and ${count - 3} more` : '';
|
|
496
|
+
lines.push(` ${mark} ${count} ${count === 1 ? 'note' : 'notes'} from ${first.from}: ${titles.join(', ')}${more}`);
|
|
497
|
+
if (group === 'comes' || group === 'changed')
|
|
498
|
+
lines.push(' each becomes a Memory proposal; you review it before it becomes Memory');
|
|
499
|
+
if (first.why)
|
|
500
|
+
lines.push(` ${first.why}`);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return lines;
|
|
504
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type SecretLineKind } from '@skrr-ai/data-provider';
|
|
2
|
+
/** Bigger than any persona, memory or skill file; smaller than any database or log worth refusing. */
|
|
3
|
+
export declare const READ_MAX_BYTES: number;
|
|
4
|
+
export declare const IMPORT_REFUSAL_REASONS: Readonly<{
|
|
5
|
+
readonly key_or_login_folder: "It is in a folder that holds keys, logins or chat history; never read";
|
|
6
|
+
readonly key_or_login_file: "Its name says it may hold keys or logins; never read";
|
|
7
|
+
readonly app_scratch: "It is the app’s own scratch space, not notes; never read";
|
|
8
|
+
readonly link_outside_folder: "It links outside the folder being imported; not followed";
|
|
9
|
+
readonly not_a_file: "It is not a regular file";
|
|
10
|
+
readonly too_large: "It is larger than 512 KB";
|
|
11
|
+
readonly not_text: "It is not plain text";
|
|
12
|
+
readonly unreadable: "It could not be read";
|
|
13
|
+
readonly skill_too_deep: "It is nested deeper in the skill folder than an imported skill carries";
|
|
14
|
+
readonly skill_too_many_files: "The skill already carries as many files as an imported skill can";
|
|
15
|
+
readonly skill_full: `The skill has no room left for it (a skill holds at most ${number} KB of text)`;
|
|
16
|
+
}>;
|
|
17
|
+
export type ImportRefusalReason = keyof typeof IMPORT_REFUSAL_REASONS;
|
|
18
|
+
/** A file or folder the reader would not read, by its path inside the source folder. */
|
|
19
|
+
export type ImportRefusal = {
|
|
20
|
+
from: string;
|
|
21
|
+
reason: ImportRefusalReason;
|
|
22
|
+
};
|
|
23
|
+
/** A line (or a JSON field) the reader left out. Never the text itself. */
|
|
24
|
+
export type ImportLeftOut = {
|
|
25
|
+
from: string;
|
|
26
|
+
line?: number;
|
|
27
|
+
field?: string;
|
|
28
|
+
kind: SecretLineKind;
|
|
29
|
+
};
|
|
30
|
+
export type SourceEntry = {
|
|
31
|
+
name: string;
|
|
32
|
+
rel: string;
|
|
33
|
+
kind: 'file' | 'dir';
|
|
34
|
+
};
|
|
35
|
+
/** Why `rel` (a path inside the source folder, `/`-separated) may never be read, or null. */
|
|
36
|
+
export declare function neverReadReason(rel: string): ImportRefusalReason | null;
|
|
37
|
+
/** `/Users/me/.openclaw` -> `~/.openclaw`; a path outside home is shown as it is. */
|
|
38
|
+
export declare function displayPath(abs: string): string;
|
|
39
|
+
export declare class SourceReader {
|
|
40
|
+
/** The source folder's real path. */
|
|
41
|
+
readonly root: string;
|
|
42
|
+
/** Where this reader sits inside the folder the import was opened on, for messages. */
|
|
43
|
+
private readonly prefix;
|
|
44
|
+
/** One record for the whole import: a refusal inside a workspace is a refusal of the import. */
|
|
45
|
+
readonly refused: ImportRefusal[];
|
|
46
|
+
readonly leftOut: ImportLeftOut[];
|
|
47
|
+
private constructor();
|
|
48
|
+
/** Open a source folder. Throws when it is not a folder. */
|
|
49
|
+
static open(folder: string): Promise<SourceReader>;
|
|
50
|
+
/** The folder as a person reads it: `~/.openclaw`. */
|
|
51
|
+
get display(): string;
|
|
52
|
+
/**
|
|
53
|
+
* A reader for a folder inside this one, sharing its records, or null when that is not a folder
|
|
54
|
+
* here. It is confined to the sub-folder: a link from it to elsewhere in this folder is not followed.
|
|
55
|
+
*/
|
|
56
|
+
sub(rel: string): Promise<SourceReader | null>;
|
|
57
|
+
/** `rel` as the plan names it: relative to the folder the import was opened on. */
|
|
58
|
+
join(rel: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Record that `rel` does not travel, for a reason the caller decided (a limit of its own). The
|
|
61
|
+
* plan shows it beside the reader's own refusals.
|
|
62
|
+
*/
|
|
63
|
+
record(rel: string, reason: ImportRefusalReason): void;
|
|
64
|
+
private refuse;
|
|
65
|
+
/**
|
|
66
|
+
* Where `rel` really is, or null (missing, or refused and recorded when `record`). Judges the
|
|
67
|
+
* path's own name and its real path's name, and refuses a real path outside the folder.
|
|
68
|
+
*/
|
|
69
|
+
private resolve;
|
|
70
|
+
/** Whether `rel` exists, without reading it or recording anything. Never-read names may be tested. */
|
|
71
|
+
has(rel: string, kind?: 'file' | 'dir'): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* A folder's files and folders, sorted by name. Each entry that may not be read is recorded as
|
|
74
|
+
* refused and left out of the list; a link is listed by what it leads to, and only when that is
|
|
75
|
+
* inside the folder.
|
|
76
|
+
*/
|
|
77
|
+
list(rel?: string): Promise<SourceEntry[]>;
|
|
78
|
+
/** A file's bytes as text, or null (missing, or refused and recorded). No secret filtering. */
|
|
79
|
+
private readRaw;
|
|
80
|
+
/** A text file's kept lines, each with its original line number; secret-looking lines left out. */
|
|
81
|
+
readLines(rel: string): Promise<Array<{
|
|
82
|
+
line: number;
|
|
83
|
+
text: string;
|
|
84
|
+
}> | null>;
|
|
85
|
+
/** A text file with every secret-looking line left out, or null. */
|
|
86
|
+
readText(rel: string): Promise<string | null>;
|
|
87
|
+
/**
|
|
88
|
+
* A JSON file, parsed in this process and returned whole: the caller keeps only the fields it
|
|
89
|
+
* needs and passes each string through `field`. Null when missing, refused or not JSON.
|
|
90
|
+
*/
|
|
91
|
+
readJson(rel: string): Promise<unknown>;
|
|
92
|
+
/** One string taken from a JSON file, with its secret-looking lines left out ('' when not a string). */
|
|
93
|
+
field(value: unknown, rel: string, field: string): string;
|
|
94
|
+
}
|