@primusclaw/personal-agent 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -752,7 +752,8 @@ var PERSONAL_ONLY_COMMANDS = [
752
752
  "agents",
753
753
  "agent",
754
754
  "lang",
755
- "approvals"
755
+ "approvals",
756
+ "skills"
756
757
  ];
757
758
  var ARGUMENT_COMMANDS = ["feedback"];
758
759
  function within(list2, name) {
@@ -4270,6 +4271,112 @@ var receiptText = defineCatalog({
4270
4271
  }
4271
4272
  });
4272
4273
 
4274
+ // packages/core/src/locales/skills.ts
4275
+ var skillText = defineCatalog({
4276
+ en: {
4277
+ savedTitle: (p) => `Saved as your skill: ${p.name} v${String(p.version)}`,
4278
+ updatedTitle: (p) => `Skill updated: ${p.name} v${String(p.version)}`,
4279
+ deletedTitle: (p) => `Skill deleted: ${p.name}`,
4280
+ disabledTitle: (p) => `Skill turned off: ${p.name}`,
4281
+ enabledTitle: (p) => `Skill turned on: ${p.name}`,
4282
+ draftTitle: (p) => `Save this as a skill? ${p.name}`,
4283
+ whenToUse: "When to use",
4284
+ files: "Files",
4285
+ manual: "Used only when you name it.",
4286
+ autoNote: "Related requests will use it from now on.",
4287
+ draftNote: "Nothing is saved until you press Save.",
4288
+ undo: "Undo",
4289
+ edit: "Edit",
4290
+ save: "Save",
4291
+ discard: "Discard",
4292
+ editTitle: (p) => `Edit skill: ${p.name}`,
4293
+ editDescription: "When to use it",
4294
+ editContent: "SKILL.md",
4295
+ editSave: "Save changes",
4296
+ editTooLong: (p) => `${p.name} is too long to edit on a card. Tell me in the chat what to change.`,
4297
+ undoneDeleted: (p) => `Undone: ${p.name} is deleted again.`,
4298
+ undoneVersion: (p) => `Undone: ${p.name} is back to its earlier text (now v${String(p.version)}).`,
4299
+ undoneRestored: (p) => `Undone: ${p.name} is back.`,
4300
+ undoneEnabled: (p) => `Undone: ${p.name} is on again.`,
4301
+ undoneDisabled: (p) => `Undone: ${p.name} is off again.`,
4302
+ undoExpired: "This can no longer be undone: a change can be undone for a day.",
4303
+ undoChanged: (p) => `Not undone: ${p.name} has changed since. Use /skills to see it now.`,
4304
+ undoDone: "This was undone already.",
4305
+ undoFull: "Not undone: your skills are full. Delete one first, then press Undo again.",
4306
+ gone: "This card is no longer active.",
4307
+ failed: "That did not go through. Press it again in a moment.",
4308
+ refused: (p) => `Not saved: ${p.why}`,
4309
+ unavailable: "Personal skills are not available on this Claw.",
4310
+ noSkills: "You have no personal skills yet. Ask me to save a way of working as a skill, for example: save this as a skill.",
4311
+ listTitle: (p) => `Your skills (${String(p.n)})`,
4312
+ listLine: (p) => `- **${p.name}** v${String(p.version)}${p.state}: ${p.description}`,
4313
+ stateOff: " (off)",
4314
+ stateManual: " (only when named)",
4315
+ listHint: "/skills show <name>, /skills disable <name>, /skills enable <name>, /skills delete <name>",
4316
+ showHead: (p) => `**${p.name}** v${String(p.version)}${p.state}`,
4317
+ showFiles: (p) => `Files: ${p.files}`,
4318
+ notFound: (p) => `You have no skill named ${p.name}. /skills lists yours.`,
4319
+ already: (p) => `${p.name} is ${p.on} already.`,
4320
+ on: "on",
4321
+ off: "off",
4322
+ usage: "Use /skills, /skills show <name>, /skills disable <name>, /skills enable <name> or /skills delete <name>.",
4323
+ couldNotRead: "Your skills could not be read just now. Try again in a moment.",
4324
+ draftSaved: (p) => `Saved as your skill: ${p.name} v${String(p.version)}.`,
4325
+ draftDiscarded: "Discarded: nothing was saved."
4326
+ },
4327
+ zh: {
4328
+ savedTitle: (p) => `\u5DF2\u5B58\u4E3A\u4F60\u7684\u6280\u80FD\uFF1A${p.name} v${String(p.version)}`,
4329
+ updatedTitle: (p) => `\u6280\u80FD\u5DF2\u66F4\u65B0\uFF1A${p.name} v${String(p.version)}`,
4330
+ deletedTitle: (p) => `\u6280\u80FD\u5DF2\u5220\u9664\uFF1A${p.name}`,
4331
+ disabledTitle: (p) => `\u6280\u80FD\u5DF2\u505C\u7528\uFF1A${p.name}`,
4332
+ enabledTitle: (p) => `\u6280\u80FD\u5DF2\u542F\u7528\uFF1A${p.name}`,
4333
+ draftTitle: (p) => `\u8981\u5B58\u6210\u6280\u80FD\u5417\uFF1F${p.name}`,
4334
+ whenToUse: "\u4EC0\u4E48\u65F6\u5019\u7528",
4335
+ files: "\u9644\u5E26\u6587\u4EF6",
4336
+ manual: "\u53EA\u5728\u4F60\u70B9\u540D\u65F6\u4F7F\u7528\u3002",
4337
+ autoNote: "\u4EE5\u540E\u76F8\u5173\u7684\u8BF7\u6C42\u4F1A\u81EA\u52A8\u7528\u5230\u5B83\u3002",
4338
+ draftNote: "\u70B9\u300C\u4FDD\u5B58\u300D\u4E4B\u524D\u4EC0\u4E48\u90FD\u4E0D\u4F1A\u4FDD\u5B58\u3002",
4339
+ undo: "\u64A4\u9500",
4340
+ edit: "\u4FEE\u6539",
4341
+ save: "\u4FDD\u5B58",
4342
+ discard: "\u653E\u5F03",
4343
+ editTitle: (p) => `\u4FEE\u6539\u6280\u80FD\uFF1A${p.name}`,
4344
+ editDescription: "\u4EC0\u4E48\u65F6\u5019\u7528",
4345
+ editContent: "SKILL.md",
4346
+ editSave: "\u4FDD\u5B58\u4FEE\u6539",
4347
+ editTooLong: (p) => `${p.name} \u592A\u957F\uFF0C\u6CA1\u6CD5\u5728\u5361\u7247\u4E0A\u4FEE\u6539\u3002\u76F4\u63A5\u5728\u804A\u5929\u91CC\u544A\u8BC9\u6211\u8981\u6539\u4EC0\u4E48\u3002`,
4348
+ undoneDeleted: (p) => `\u5DF2\u64A4\u9500\uFF1A${p.name} \u5DF2\u5220\u9664\u3002`,
4349
+ undoneVersion: (p) => `\u5DF2\u64A4\u9500\uFF1A${p.name} \u56DE\u5230\u4E86\u4E4B\u524D\u7684\u5185\u5BB9\uFF08\u73B0\u5728\u662F v${String(p.version)}\uFF09\u3002`,
4350
+ undoneRestored: (p) => `\u5DF2\u64A4\u9500\uFF1A${p.name} \u5DF2\u6062\u590D\u3002`,
4351
+ undoneEnabled: (p) => `\u5DF2\u64A4\u9500\uFF1A${p.name} \u5DF2\u91CD\u65B0\u542F\u7528\u3002`,
4352
+ undoneDisabled: (p) => `\u5DF2\u64A4\u9500\uFF1A${p.name} \u5DF2\u91CD\u65B0\u505C\u7528\u3002`,
4353
+ undoExpired: "\u5DF2\u7ECF\u4E0D\u80FD\u64A4\u9500\u4E86\uFF1A\u6539\u52A8\u53EA\u80FD\u5728\u4E00\u5929\u5185\u64A4\u9500\u3002",
4354
+ undoChanged: (p) => `\u6CA1\u6709\u64A4\u9500\uFF1A${p.name} \u4E4B\u540E\u53C8\u6539\u8FC7\u4E86\u3002\u7528 /skills \u770B\u770B\u5B83\u73B0\u5728\u7684\u6837\u5B50\u3002`,
4355
+ undoDone: "\u8FD9\u4E2A\u6539\u52A8\u5DF2\u7ECF\u64A4\u9500\u8FC7\u4E86\u3002",
4356
+ undoFull: "\u6CA1\u6709\u64A4\u9500\uFF1A\u4F60\u7684\u6280\u80FD\u5DF2\u7ECF\u6EE1\u4E86\u3002\u5148\u5220\u6389\u4E00\u4E2A\uFF0C\u518D\u70B9\u300C\u64A4\u9500\u300D\u3002",
4357
+ gone: "\u8FD9\u5F20\u5361\u7247\u5DF2\u7ECF\u5931\u6548\u4E86\u3002",
4358
+ failed: "\u6CA1\u6709\u6210\u529F\uFF0C\u8FC7\u4E00\u4F1A\u513F\u518D\u70B9\u4E00\u6B21\u3002",
4359
+ refused: (p) => `\u6CA1\u6709\u4FDD\u5B58\uFF1A${p.why}`,
4360
+ unavailable: "\u8FD9\u4E2A Claw \u4E0A\u8FD8\u6CA1\u6709\u4E2A\u4EBA\u6280\u80FD\u3002",
4361
+ noSkills: "\u4F60\u8FD8\u6CA1\u6709\u4E2A\u4EBA\u6280\u80FD\u3002\u53EF\u4EE5\u8BA9\u6211\u628A\u4E00\u79CD\u505A\u6CD5\u5B58\u6210\u6280\u80FD\uFF0C\u6BD4\u5982\u8BF4\uFF1A\u628A\u8FD9\u4E2A\u5B58\u6210\u6280\u80FD\u3002",
4362
+ listTitle: (p) => `\u4F60\u7684\u6280\u80FD\uFF08${String(p.n)} \u4E2A\uFF09`,
4363
+ listLine: (p) => `- **${p.name}** v${String(p.version)}${p.state}\uFF1A${p.description}`,
4364
+ stateOff: "\uFF08\u5DF2\u505C\u7528\uFF09",
4365
+ stateManual: "\uFF08\u53EA\u5728\u70B9\u540D\u65F6\u7528\uFF09",
4366
+ listHint: "/skills show <\u540D\u5B57>\u3001/skills disable <\u540D\u5B57>\u3001/skills enable <\u540D\u5B57>\u3001/skills delete <\u540D\u5B57>",
4367
+ showHead: (p) => `**${p.name}** v${String(p.version)}${p.state}`,
4368
+ showFiles: (p) => `\u9644\u5E26\u6587\u4EF6\uFF1A${p.files}`,
4369
+ notFound: (p) => `\u4F60\u6CA1\u6709\u53EB ${p.name} \u7684\u6280\u80FD\u3002\u7528 /skills \u770B\u770B\u4F60\u6709\u54EA\u4E9B\u3002`,
4370
+ already: (p) => `${p.name} \u5DF2\u7ECF\u662F${p.on}\u7684\u4E86\u3002`,
4371
+ on: "\u542F\u7528",
4372
+ off: "\u505C\u7528",
4373
+ usage: "\u7528\u6CD5\uFF1A/skills\u3001/skills show <\u540D\u5B57>\u3001/skills disable <\u540D\u5B57>\u3001/skills enable <\u540D\u5B57>\u3001/skills delete <\u540D\u5B57>\u3002",
4374
+ couldNotRead: "\u6682\u65F6\u8BFB\u4E0D\u5230\u4F60\u7684\u6280\u80FD\uFF0C\u8FC7\u4E00\u4F1A\u513F\u518D\u8BD5\u3002",
4375
+ draftSaved: (p) => `\u5DF2\u5B58\u4E3A\u4F60\u7684\u6280\u80FD\uFF1A${p.name} v${String(p.version)}\u3002`,
4376
+ draftDiscarded: "\u5DF2\u653E\u5F03\uFF0C\u4EC0\u4E48\u90FD\u6CA1\u6709\u4FDD\u5B58\u3002"
4377
+ }
4378
+ });
4379
+
4273
4380
  // packages/core/src/locales/proactive-lines.ts
4274
4381
  var releaseLines = {
4275
4382
  olderSaid: (p) => `${String(p.n)} earlier messages from your assistant are not shown here. Send /board to see where your tasks stand.`,
@@ -6796,7 +6903,7 @@ var LiveView = class {
6796
6903
  const plan = planText(this.todos, this.lang);
6797
6904
  const budget = LIVE_MAX_CHARS - (plan ? cpLength(plan) + 2 : 0);
6798
6905
  let body = "";
6799
- let clipped = false;
6906
+ let clipped2 = false;
6800
6907
  for (const paragraph of this.paragraphs().reverse()) {
6801
6908
  const joined = body ? `${paragraph}
6802
6909
 
@@ -6805,15 +6912,15 @@ ${body}` : paragraph;
6805
6912
  body = joined;
6806
6913
  continue;
6807
6914
  }
6808
- clipped = true;
6915
+ clipped2 = true;
6809
6916
  if (!body) body = pyLstrip(cpSlice(paragraph, -budget));
6810
6917
  break;
6811
6918
  }
6812
- if (clipped) body = `...
6919
+ if (clipped2) body = `...
6813
6920
 
6814
6921
  ${body}`;
6815
6922
  if (body.split("```").length % 2 === 0) {
6816
- body = clipped ? `\`\`\`
6923
+ body = clipped2 ? `\`\`\`
6817
6924
  ${body}` : `${body}
6818
6925
  \`\`\``;
6819
6926
  }
@@ -10836,7 +10943,8 @@ var SETTINGS_ENTRIES = [
10836
10943
  sayZh: "\u4F60\u8BB0\u5F97\u6211\u4EC0\u4E48",
10837
10944
  sayEn: "what do you remember about me",
10838
10945
  reaches: "memory",
10839
- covers: ["command:memory"],
10946
+ // (`/skills`: the personal skills the person saved, the other thing Claw keeps of theirs; listed, turned off or on, deleted)
10947
+ covers: ["command:memory", "command:skills"],
10840
10948
  action: true
10841
10949
  }),
10842
10950
  capability({
@@ -16406,12 +16514,26 @@ function triggerDone(create2, out, lang) {
16406
16514
  const next = localTime(trigger["next_fire_at"], tz);
16407
16515
  return t4.scheduled({ name: or(trigger["name"], ""), schedule: or(trigger["schedule"], ""), tz, next });
16408
16516
  }
16517
+ function skillSaveOutcome(status, out, lang) {
16518
+ const t4 = assistantActionText.in(lang);
16519
+ const s = skillText.in(lang);
16520
+ const result = fields(out["result"]);
16521
+ if (status === "done" && truthy2(out["answered_now"])) {
16522
+ const version = typeof result["version"] === "number" ? result["version"] : 1;
16523
+ return s.draftSaved({ name: or(result["name"], ""), version });
16524
+ }
16525
+ if (status === "done") return t4.alreadyAnswered;
16526
+ if (status === "denied") return s.draftDiscarded;
16527
+ if (status === "expired") return t4.expired;
16528
+ return s.refused({ why: or(result["message"], or(result["error"], status)) });
16529
+ }
16409
16530
  function confirmOutcome(kind, out, lang) {
16410
16531
  const t4 = assistantActionText.in(lang);
16411
16532
  const status = or(out["status"], "");
16412
16533
  const create2 = kind === "trigger_create";
16413
16534
  if (kind === "devenv_send") return devenvSendOutcome(status, out, lang);
16414
16535
  if (kind === "devenv_hide") return devenvHideOutcome(status, out, lang);
16536
+ if (kind === "skill_save") return skillSaveOutcome(status, out, lang);
16415
16537
  const comment = kind === "github_comment" ? commentOutcome(out, lang) : void 0;
16416
16538
  if (comment !== void 0) return comment;
16417
16539
  if (status === "done" && truthy2(out["answered_now"])) return triggerDone(create2, out, lang);
@@ -16433,6 +16555,13 @@ async function finish(click, edited, said2) {
16433
16555
  await click.conversation.send(line2);
16434
16556
  }
16435
16557
 
16558
+ // packages/core/src/skills/views.ts
16559
+ var SKILL_UNDO_KIND = "skill_undo";
16560
+ var SKILL_VERB = "assistant_skill";
16561
+ var SKILL_EDIT_DESCRIPTION = "skill_description";
16562
+ var SKILL_EDIT_CONTENT = "skill_content";
16563
+ var SKILL_EDIT_MAX = 6e3;
16564
+
16436
16565
  // packages/core/src/assistant/actions.ts
16437
16566
  var REVIEW_HANDOFF = "review_for_other";
16438
16567
  function record(value) {
@@ -16520,7 +16649,7 @@ var AssistantActions = class {
16520
16649
  const data = click.action.data;
16521
16650
  const card = store.assistantButtons.getConfirmCard(pyStr(data["card"]));
16522
16651
  const op = data["op"];
16523
- if (op !== "allow" && op !== "deny" || card === null || card.userId !== click.sender.id) {
16652
+ if (op !== "allow" && op !== "deny" || card === null || card.userId !== click.sender.id || card.kind === SKILL_UNDO_KIND) {
16524
16653
  await finish(click, t.confirmGone);
16525
16654
  return;
16526
16655
  }
@@ -17659,7 +17788,8 @@ var CONFIRM_KINDS = [
17659
17788
  "trigger_cancel",
17660
17789
  "devenv_send",
17661
17790
  "github_comment",
17662
- "devenv_hide"
17791
+ "devenv_hide",
17792
+ "skill_save"
17663
17793
  ];
17664
17794
  var ASSISTANT_SUGGESTED_REPLIES = {
17665
17795
  zh: [
@@ -17719,6 +17849,37 @@ function suggestedRepliesOf(event, text8, styleOn, lang, max = SUGGESTIONS_MAX)
17719
17849
  if (replies.length) return replies.slice(0, max);
17720
17850
  return [...ASSISTANT_SUGGESTED_REPLIES[lang ?? pickLang2(text8)]];
17721
17851
  }
17852
+ var SKILL_CARD_KINDS = ["saved", "deleted", "disabled", "enabled", "draft"];
17853
+ var SKILL_DESCRIPTION_MAX = 300;
17854
+ var SKILL_PREVIEW_MAX = 1500;
17855
+ var SKILL_FILES_MAX = 20;
17856
+ var SKILL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/;
17857
+ var CHANGE_ID = /^[A-Za-z0-9-]{1,64}$/;
17858
+ function clipped(value, max) {
17859
+ const all = Array.from(field2(value));
17860
+ return all.length > max ? `${all.slice(0, max - 1).join("")}\u2026` : all.join("");
17861
+ }
17862
+ function skillCardOf(event) {
17863
+ const card = record2(event["skill_card"]);
17864
+ if (event["type"] !== "assistant.say" || card === void 0) return void 0;
17865
+ const kind = SKILL_CARD_KINDS.find((k) => k === card["kind"]);
17866
+ const name = typeof card["name"] === "string" ? card["name"] : "";
17867
+ if (kind === void 0 || !SKILL_NAME.test(name)) return void 0;
17868
+ const version = typeof card["version"] === "number" && Number.isSafeInteger(card["version"]) ? card["version"] : null;
17869
+ const changeId = typeof card["change_id"] === "string" && CHANGE_ID.test(card["change_id"]) ? card["change_id"] : "";
17870
+ const files = (Array.isArray(card["files"]) ? card["files"] : []).map((f) => record2(f)?.["path"]).filter((p) => typeof p === "string" && p !== "" && cpLength(p) <= 200 && !p.includes("\n")).slice(0, SKILL_FILES_MAX);
17871
+ return {
17872
+ kind,
17873
+ name,
17874
+ version,
17875
+ created: card["created"] === true,
17876
+ description: pySplit(clipped(card["description"], SKILL_DESCRIPTION_MAX)).join(" "),
17877
+ manual: card["invocation"] === "manual",
17878
+ files,
17879
+ preview: clipped(card["preview"], SKILL_PREVIEW_MAX),
17880
+ changeId
17881
+ };
17882
+ }
17722
17883
  var CHOICE_OPTIONS_MIN = 2;
17723
17884
  var CHOICE_OPTIONS_MAX = 10;
17724
17885
  var CHOICE_OPTION_MAX = 80;
@@ -17887,10 +18048,33 @@ ${text8}`;
17887
18048
  const inCard = said2.inCard ? said2.text : "";
17888
18049
  if (item?.canAccept)
17889
18050
  return { message: this.workCard(userId, item, said2.text, inCard, said2.lang), holdsWords: said2.inCard };
18051
+ const skill = item === null ? this.skillCard(userId, event, said2.text, said2.lang) : void 0;
18052
+ if (skill !== void 0) return { message: skill, holdsWords: true };
17890
18053
  const asked3 = item === null ? this.askCard(userId, event, inCard, said2.lang) : void 0;
17891
18054
  if (asked3 !== void 0) return { message: asked3, holdsWords: said2.inCard };
17892
18055
  return this.choiceCard(userId, event, inCard, said2.lang, said2.inCard);
17893
18056
  }
18057
+ /**
18058
+ * A personal skill the message is about (`skill_card`), recorded first: a draft is its held write (Save and Discard answer it as
18059
+ * any held write is answered); anything done already records the change its Undo takes back. Undefined for none, and for a draft
18060
+ * without its held write (it is then the plain held write's card).
18061
+ */
18062
+ skillCard(userId, event, text8, lang) {
18063
+ const skill = skillCardOf(event);
18064
+ if (skill === void 0) return void 0;
18065
+ const buttons2 = this.deps.store.assistantButtons;
18066
+ if (skill.kind === "draft") {
18067
+ const held = confirmWriteOf(event);
18068
+ if (held === void 0 || held.kind !== "skill_save") return void 0;
18069
+ const cardId2 = buttons2.addConfirmCard(userId, held.confirmationId, held.kind, held.allowLabel);
18070
+ return view3(
18071
+ { name: "skillCard", model: { skill, cardId: cardId2, allowLabel: held.allowLabel, note: "", ended: false, lang } },
18072
+ text8
18073
+ );
18074
+ }
18075
+ const cardId = skill.changeId ? buttons2.addConfirmCard(userId, skill.changeId, SKILL_UNDO_KIND, skill.name) : "";
18076
+ return view3({ name: "skillCard", model: { skill, cardId, allowLabel: "", note: "", ended: false, lang } }, text8);
18077
+ }
17894
18078
  /** A write Claw holds for the person (Allow, Deny) or a command put to them (Run, Cancel), recorded first; undefined for none. */
17895
18079
  askCard(userId, event, inCard, lang) {
17896
18080
  const held = confirmWriteOf(event);
@@ -18351,6 +18535,281 @@ var WorkCardClicks = class {
18351
18535
  }
18352
18536
  };
18353
18537
 
18538
+ // packages/core/src/skills/card.ts
18539
+ var PREVIEW_LINES = 30;
18540
+ var PREVIEW_CHARS = 1500;
18541
+ function preview(content) {
18542
+ const lines = content.split(/\r?\n/u).slice(0, PREVIEW_LINES).join("\n");
18543
+ const all = Array.from(lines);
18544
+ return all.length > PREVIEW_CHARS ? `${all.slice(0, PREVIEW_CHARS - 1).join("")}\u2026` : lines;
18545
+ }
18546
+ function skillCardOfSkill(skill, kind, changeId) {
18547
+ return {
18548
+ kind,
18549
+ name: skill.name,
18550
+ version: skill.version,
18551
+ created: false,
18552
+ description: skill.description,
18553
+ manual: skill.invocation === "manual",
18554
+ files: (skill.fileList ?? []).map((f) => f.path),
18555
+ preview: kind === "deleted" || skill.content === void 0 ? "" : preview(skill.content),
18556
+ changeId
18557
+ };
18558
+ }
18559
+
18560
+ // packages/core/src/skills/clicks.ts
18561
+ function refusalReason(error) {
18562
+ try {
18563
+ const body = JSON.parse(error.detail);
18564
+ if (typeof body === "object" && body !== null) {
18565
+ const reason = body["reason"];
18566
+ return typeof reason === "string" ? reason : "";
18567
+ }
18568
+ } catch {
18569
+ }
18570
+ return "";
18571
+ }
18572
+ function refusalWords(error) {
18573
+ try {
18574
+ const body = JSON.parse(error.detail);
18575
+ const said2 = typeof body === "object" && body !== null ? body["error"] : void 0;
18576
+ if (typeof said2 === "string" && said2) return said2;
18577
+ } catch {
18578
+ }
18579
+ return `HTTP ${String(error.status)}`;
18580
+ }
18581
+ var SkillCardClicks = class {
18582
+ constructor(deps) {
18583
+ this.deps = deps;
18584
+ }
18585
+ deps;
18586
+ verbs = [SKILL_VERB];
18587
+ async withCredential(click, credential2) {
18588
+ const data = click.action.data;
18589
+ const op = pyStr(data["op"]);
18590
+ const card = this.deps.store.assistantButtons.getConfirmCard(pyStr(data["card"]));
18591
+ const lang = click.lang();
18592
+ const t4 = skillText.in(lang);
18593
+ if (card === null || card.userId !== click.sender.id || card.kind !== SKILL_UNDO_KIND || op !== "undo" && op !== "edit" && op !== "save_edit") {
18594
+ await finish(click, t4.gone);
18595
+ return;
18596
+ }
18597
+ if (card.state !== "open") {
18598
+ await finish(click, op === "undo" ? t4.undoDone : t4.gone);
18599
+ return;
18600
+ }
18601
+ if (op === "undo") await this.undo(click, card, credential2, lang);
18602
+ else if (op === "edit") await this.edit(click, card, credential2, lang);
18603
+ else await this.saveEdit(click, card, credential2, lang);
18604
+ }
18605
+ async undo(click, card, credential2, lang) {
18606
+ const t4 = skillText.in(lang);
18607
+ const buttons2 = this.deps.store.assistantButtons;
18608
+ if (!buttons2.moveConfirmCard(card.cardId, "busy", { onlyFrom: "open" })) {
18609
+ await finish(click, t4.undoDone);
18610
+ return;
18611
+ }
18612
+ let undone;
18613
+ try {
18614
+ undone = await this.deps.skills.undo(credential2, card.confirmationId);
18615
+ } catch (error) {
18616
+ if (!clawFailure3(error)) throw error;
18617
+ this.deps.logger.warn("a skill's change could not be undone", { error: errorName(error) });
18618
+ if (error instanceof ClawError && error.status < 500) {
18619
+ buttons2.moveConfirmCard(card.cardId, "done");
18620
+ await finish(click, this.undoRefused(error, card.label, lang));
18621
+ return;
18622
+ }
18623
+ buttons2.moveConfirmCard(card.cardId, "open", { onlyFrom: "busy" });
18624
+ await click.settle(t4.failed, { announce: false });
18625
+ return;
18626
+ }
18627
+ buttons2.moveConfirmCard(card.cardId, "done");
18628
+ const name = undone.name || card.label;
18629
+ const said2 = undone.undone === "deleted" ? t4.undoneDeleted({ name }) : undone.undone === "restored_version" ? t4.undoneVersion({ name, version: undone.version ?? 0 }) : undone.undone === "enabled" ? t4.undoneEnabled({ name }) : undone.undone === "disabled" ? t4.undoneDisabled({ name }) : t4.undoneRestored({ name });
18630
+ await finish(click, said2);
18631
+ }
18632
+ undoRefused(error, name, lang) {
18633
+ const t4 = skillText.in(lang);
18634
+ const reason = refusalReason(error);
18635
+ if (error.status === 410 || reason === "expired") return t4.undoExpired;
18636
+ if (reason === "undone") return t4.undoDone;
18637
+ if (reason === "changed") return t4.undoChanged({ name });
18638
+ if (reason === "full") return t4.undoFull;
18639
+ return t4.gone;
18640
+ }
18641
+ async edit(click, card, credential2, lang) {
18642
+ const t4 = skillText.in(lang);
18643
+ let skill;
18644
+ try {
18645
+ skill = await this.deps.skills.show(credential2, card.label);
18646
+ } catch (error) {
18647
+ if (!clawFailure3(error)) throw error;
18648
+ await finish(
18649
+ click,
18650
+ error instanceof ClawError && error.status === 404 ? t4.notFound({ name: card.label }) : t4.couldNotRead
18651
+ );
18652
+ return;
18653
+ }
18654
+ if (cpLength(skill.content) > SKILL_EDIT_MAX) {
18655
+ await finish(click, t4.editTooLong({ name: skill.name }));
18656
+ return;
18657
+ }
18658
+ const model = {
18659
+ cardId: card.cardId,
18660
+ name: skill.name,
18661
+ description: skill.description,
18662
+ content: skill.content,
18663
+ note: "",
18664
+ lang
18665
+ };
18666
+ await click.settle(viewMessage2({ name: "skillEdit", model }), { announce: false });
18667
+ }
18668
+ async saveEdit(click, card, credential2, lang) {
18669
+ const t4 = skillText.in(lang);
18670
+ const buttons2 = this.deps.store.assistantButtons;
18671
+ const content = pyStr(click.action.data[SKILL_EDIT_CONTENT]);
18672
+ const description = pyStr(click.action.data[SKILL_EDIT_DESCRIPTION]).trim();
18673
+ const again = (note) => click.settle(
18674
+ viewMessage2({
18675
+ name: "skillEdit",
18676
+ model: { cardId: card.cardId, name: card.label, description, content, note, lang }
18677
+ }),
18678
+ { announce: false }
18679
+ );
18680
+ if (!content.trim()) {
18681
+ await again(t4.refused({ why: "SKILL.md" }));
18682
+ return;
18683
+ }
18684
+ if (!buttons2.moveConfirmCard(card.cardId, "busy", { onlyFrom: "open" })) {
18685
+ await finish(click, t4.gone);
18686
+ return;
18687
+ }
18688
+ let change;
18689
+ try {
18690
+ change = await this.deps.skills.update(credential2, card.label, { content, description });
18691
+ } catch (error) {
18692
+ if (!clawFailure3(error)) throw error;
18693
+ buttons2.moveConfirmCard(card.cardId, "open", { onlyFrom: "busy" });
18694
+ this.deps.logger.warn("a skill could not be saved from its card", { error: errorName(error) });
18695
+ await again(
18696
+ error instanceof ClawError && error.status < 500 ? t4.refused({ why: refusalWords(error) }) : t4.failed
18697
+ );
18698
+ return;
18699
+ }
18700
+ buttons2.moveConfirmCard(card.cardId, "done");
18701
+ let shown3;
18702
+ try {
18703
+ shown3 = await this.deps.skills.show(credential2, card.label);
18704
+ } catch (error) {
18705
+ if (!clawFailure3(error)) throw error;
18706
+ await finish(click, t4.updatedTitle({ name: card.label, version: change.version ?? 0 }));
18707
+ return;
18708
+ }
18709
+ const next = change.changeId ? buttons2.addConfirmCard(click.sender.id, change.changeId, SKILL_UNDO_KIND, card.label) : "";
18710
+ const skill = skillCardOfSkill(shown3, "saved", change.changeId);
18711
+ const model = { skill, cardId: next, allowLabel: "", note: "", ended: false, lang };
18712
+ await click.settle(viewMessage2({ name: "skillCard", model }), {
18713
+ fallback: t4.updatedTitle({ name: shown3.name, version: shown3.version })
18714
+ });
18715
+ }
18716
+ };
18717
+
18718
+ // packages/core/src/skills/command.ts
18719
+ var SHOW_MAX = 3500;
18720
+ var SkillsCommand = class {
18721
+ constructor(deps) {
18722
+ this.deps = deps;
18723
+ }
18724
+ deps;
18725
+ name = "skills";
18726
+ async run(route, args) {
18727
+ const lang = route.lang();
18728
+ const t4 = skillText.in(lang);
18729
+ const words3 = pySplit(args);
18730
+ const verb = (words3[0] ?? "").toLowerCase();
18731
+ const name = words3[1] ?? "";
18732
+ const say3 = (text8) => route.conversation.send(textMessage(text8));
18733
+ try {
18734
+ await this.dispatch(route, verb, words3.length, name, lang);
18735
+ } catch (error) {
18736
+ if (!clawFailure3(error)) throw error;
18737
+ this.deps.logger.info("a /skills command could not be carried out", { error: errorName(error) });
18738
+ if (error instanceof ClawError && error.status === 404)
18739
+ await say3(verb === "" || verb === "list" ? t4.unavailable : t4.notFound({ name }));
18740
+ else await say3(t4.couldNotRead);
18741
+ }
18742
+ return true;
18743
+ }
18744
+ async dispatch(route, verb, count5, name, lang) {
18745
+ if (verb === "" || verb === "list" && count5 === 1) return this.list(route, lang);
18746
+ if (verb === "show" && count5 === 2) return this.show(route, name, lang);
18747
+ if ((verb === "disable" || verb === "enable" || verb === "delete") && count5 === 2)
18748
+ return this.act(route, verb, name, lang);
18749
+ await route.conversation.send(textMessage(skillText.in(lang).usage));
18750
+ }
18751
+ state(s, lang) {
18752
+ const t4 = skillText.in(lang);
18753
+ return `${s.enabled ? "" : t4.stateOff}${s.invocation === "manual" ? t4.stateManual : ""}`;
18754
+ }
18755
+ async list(route, lang) {
18756
+ const t4 = skillText.in(lang);
18757
+ const skills = await this.deps.skills.list(route.credential);
18758
+ if (!skills.length) {
18759
+ await route.conversation.send(textMessage(t4.noSkills));
18760
+ return;
18761
+ }
18762
+ const lines = skills.map(
18763
+ (s) => t4.listLine({
18764
+ name: s.name,
18765
+ version: s.version,
18766
+ description: s.description.replace(/\s+/gu, " "),
18767
+ state: this.state(s, lang)
18768
+ })
18769
+ );
18770
+ await route.conversation.send(
18771
+ richMessage([`**${t4.listTitle({ n: skills.length })}**`, ...lines, "", t4.listHint].join("\n"))
18772
+ );
18773
+ }
18774
+ async show(route, name, lang) {
18775
+ const t4 = skillText.in(lang);
18776
+ const s = await this.deps.skills.show(route.credential, name);
18777
+ const chars = Array.from(s.content);
18778
+ const body = chars.length > SHOW_MAX ? `${chars.slice(0, SHOW_MAX).join("")}
18779
+ \u2026` : s.content;
18780
+ const parts2 = [
18781
+ t4.showHead({ name: s.name, version: s.version, state: this.state(s, lang) }),
18782
+ s.description,
18783
+ "```",
18784
+ body,
18785
+ "```"
18786
+ ];
18787
+ if (s.fileList.length) parts2.push(t4.showFiles({ files: s.fileList.map((f) => f.path).join(", ") }));
18788
+ await route.conversation.send(richMessage(parts2.join("\n")));
18789
+ }
18790
+ async act(route, act, name, lang) {
18791
+ const t4 = skillText.in(lang);
18792
+ const { skills, store } = this.deps;
18793
+ const before = (await skills.list(route.credential)).find((s) => s.name === name);
18794
+ if (before === void 0) {
18795
+ await route.conversation.send(textMessage(t4.notFound({ name })));
18796
+ return;
18797
+ }
18798
+ const change = act === "delete" ? await skills.remove(route.credential, name) : await skills.setEnabled(route.credential, name, act === "enable");
18799
+ if (!change.changed) {
18800
+ await route.conversation.send(textMessage(t4.already({ name, on: act === "enable" ? t4.on : t4.off })));
18801
+ return;
18802
+ }
18803
+ const kind = act === "delete" ? "deleted" : act === "enable" ? "enabled" : "disabled";
18804
+ const cardId = change.changeId ? store.assistantButtons.addConfirmCard(route.sender.id, change.changeId, SKILL_UNDO_KIND, name) : "";
18805
+ const skill = skillCardOfSkill(before, kind, change.changeId);
18806
+ const title = kind === "deleted" ? t4.deletedTitle({ name }) : kind === "enabled" ? t4.enabledTitle({ name }) : t4.disabledTitle({ name });
18807
+ await route.conversation.send(
18808
+ viewMessage2({ name: "skillCard", model: { skill, cardId, allowLabel: "", note: "", ended: false, lang } }, title)
18809
+ );
18810
+ }
18811
+ };
18812
+
18354
18813
  // packages/core/src/text/neutral.ts
18355
18814
  function isControl(ch) {
18356
18815
  const code3 = ch.codePointAt(0) ?? 0;
@@ -27165,7 +27624,7 @@ var RUNNING_MARK2 = "\u23F3";
27165
27624
  var STYLE_CHARS = /[*_`~]/g;
27166
27625
  function boundedBody(paragraphs, budget) {
27167
27626
  let body = "";
27168
- let clipped = false;
27627
+ let clipped2 = false;
27169
27628
  for (let i = paragraphs.length - 1; i >= 0; i -= 1) {
27170
27629
  const paragraph = paragraphs[i] ?? "";
27171
27630
  const joined = body ? `${paragraph}
@@ -27175,14 +27634,14 @@ ${body}` : paragraph;
27175
27634
  body = joined;
27176
27635
  continue;
27177
27636
  }
27178
- clipped = true;
27637
+ clipped2 = true;
27179
27638
  if (!body) body = pyLstrip(cpSlice(paragraph, -budget));
27180
27639
  break;
27181
27640
  }
27182
- if (clipped) body = `...
27641
+ if (clipped2) body = `...
27183
27642
 
27184
27643
  ${body}`;
27185
- if (body.split("```").length % 2 === 0) body = clipped ? `\`\`\`
27644
+ if (body.split("```").length % 2 === 0) body = clipped2 ? `\`\`\`
27186
27645
  ${body}` : `${body}
27187
27646
  \`\`\``;
27188
27647
  return body;
@@ -27281,8 +27740,8 @@ var RemoteLiveView = class {
27281
27740
  return pyStrip(inertAnswer(splitErrorTail(masked2(block.text)).kept));
27282
27741
  case "thought": {
27283
27742
  const flat2 = inertAnswer(squashSpaces(masked2(block.text).replace(STYLE_CHARS, " ")));
27284
- const clipped = cpLength(flat2) <= THOUGHT_MAX ? flat2 : "\u2026" + pyLstrip(cpSlice(flat2, -(THOUGHT_MAX - 1)));
27285
- return pyStrip(clipped) ? `_\u{1F4AD} ${pyStrip(clipped)}_` : "";
27743
+ const clipped2 = cpLength(flat2) <= THOUGHT_MAX ? flat2 : "\u2026" + pyLstrip(cpSlice(flat2, -(THOUGHT_MAX - 1)));
27744
+ return pyStrip(clipped2) ? `_\u{1F4AD} ${pyStrip(clipped2)}_` : "";
27286
27745
  }
27287
27746
  case "failed":
27288
27747
  return remoteText.in(this.lang).stepFailed({ title: neutral2(block.text, TOOL_TITLE_MAX) });
@@ -33646,6 +34105,11 @@ export {
33646
34105
  SENSITIVE_OPERATION_NAMES,
33647
34106
  SESSION_HISTORY_KEEP,
33648
34107
  SESSION_LIST,
34108
+ SKILL_EDIT_CONTENT,
34109
+ SKILL_EDIT_DESCRIPTION,
34110
+ SKILL_EDIT_MAX,
34111
+ SKILL_UNDO_KIND,
34112
+ SKILL_VERB,
33649
34113
  STATS_INTERVAL_SECONDS,
33650
34114
  SUMMARY_MAX2 as SUMMARY_MAX,
33651
34115
  SURFACE_CHANNEL,
@@ -33653,6 +34117,8 @@ export {
33653
34117
  SayPlanner,
33654
34118
  SecretsUnavailable,
33655
34119
  SecurityLog,
34120
+ SkillCardClicks,
34121
+ SkillsCommand,
33656
34122
  SseFrames,
33657
34123
  Subscriptions as SubscriptionKeeper,
33658
34124
  TAG,
@@ -34004,6 +34470,7 @@ export {
34004
34470
  showButton,
34005
34471
  shown,
34006
34472
  silentLogger,
34473
+ skillText,
34007
34474
  slug,
34008
34475
  sortedCp,
34009
34476
  splitErrorTail,
@@ -6,6 +6,8 @@ export declare function localTime(at: unknown, zone: string): string;
6
6
  export declare function commentOutcome(out: Fields, lang: Lang): string | undefined;
7
7
  /** What came of a press on an instruction card (`devenv_send`): sent, as which item, or why not. */
8
8
  export declare function devenvSendOutcome(status: string, out: Fields, lang: Lang): string;
9
+ /** What came of Save or Discard on a drafted skill's card: saved (which version), discarded, or why not. */
10
+ export declare function skillSaveOutcome(status: string, out: Fields, lang: Lang): string;
9
11
  /** What came of a press on a held write's card of `kind`, in one line: Claw's answer said plainly. */
10
12
  export declare function confirmOutcome(kind: string, out: Fields, lang: Lang): string;
11
13
  export {};
@@ -13,7 +13,7 @@ export declare const SUGGESTED_REPLY_MAX = 30;
13
13
  /** The suggested replies kept under a message when the channel's own limit is not given (`SurfaceCaps.suggestionsMax`). */
14
14
  export declare const SUGGESTIONS_MAX = 3;
15
15
  /** The writes Claw holds for the person that this worker draws as a card. */
16
- export declare const CONFIRM_KINDS: readonly ["trigger_create", "trigger_cancel", "devenv_send", "github_comment", "devenv_hide"];
16
+ export declare const CONFIRM_KINDS: readonly ["trigger_create", "trigger_cancel", "devenv_send", "github_comment", "devenv_hide", "skill_save"];
17
17
  /** The default replies under what the assistant said: (what the button says, what it sends). */
18
18
  export declare const ASSISTANT_SUGGESTED_REPLIES: Readonly<Record<Lang, readonly SuggestedReply[]>>;
19
19
  type Event = Readonly<Record<string, unknown>>;
@@ -42,6 +42,33 @@ export declare function confirmWriteOf(event: Event): ConfirmWrite | undefined;
42
42
  * language (`lang`; without it, the language of `text`).
43
43
  */
44
44
  export declare function suggestedRepliesOf(event: Event, text: string, styleOn: boolean, lang?: Lang, max?: number): SuggestedReply[];
45
+ /** What a skill's card is about (`skill_card.kind`): done already, or a draft to save. */
46
+ export declare const SKILL_CARD_KINDS: readonly ["saved", "deleted", "disabled", "enabled", "draft"];
47
+ /** Code points of a skill's description on its card (Claw sends at most 300). */
48
+ export declare const SKILL_DESCRIPTION_MAX = 300;
49
+ /** Code points of the start of SKILL.md a card shows (Claw sends at most 1500). */
50
+ export declare const SKILL_PREVIEW_MAX = 1500;
51
+ /** The files a skill's card lists (Claw keeps at most 20). */
52
+ export declare const SKILL_FILES_MAX = 20;
53
+ /** One of the person's personal skills as an `assistant.say` shows it (`skill_card`). */
54
+ export interface SkillCardEvent {
55
+ readonly kind: (typeof SKILL_CARD_KINDS)[number];
56
+ readonly name: string;
57
+ readonly version: number | null;
58
+ /** `saved`: a new skill (true) or a new version of one (false). */
59
+ readonly created: boolean;
60
+ readonly description: string;
61
+ readonly manual: boolean;
62
+ readonly files: readonly string[];
63
+ readonly preview: string;
64
+ /** What Undo takes back ("" none). */
65
+ readonly changeId: string;
66
+ }
67
+ /**
68
+ * The skill an `assistant.say` is about (`skill_card`); undefined when it carries none this worker draws. Read whole or not at all:
69
+ * a name that is not one, or a kind it does not know, and there is no card (the words still say it).
70
+ */
71
+ export declare function skillCardOf(event: Event): SkillCardEvent | undefined;
45
72
  /** The fewest options a choice card shows (Claw sends from 2). */
46
73
  export declare const CHOICE_OPTIONS_MIN = 2;
47
74
  /** The most options a choice card shows (Claw sends at most 10). */
@@ -6,8 +6,9 @@
6
6
  * cites as [n], and the replies to tap under the last of its messages when no card follows.
7
7
  * - When the event's item holds a result that waits, a card with Accept and Stop; when it holds a write for the person, a card
8
8
  * that lets it through or not; when it puts a command to the person, a card with Run and Cancel; when it puts a choice to the
9
- * person, a card with the options and Send (each recorded first, so its buttons mean something). A card holds the words only
10
- * when they are short and not shown already.
9
+ * person, a card with the options and Send; when it is about one of the person's skills, the skill's card with Undo and Edit,
10
+ * or a draft's with Save and Discard (each recorded first, so its buttons mean something). A card holds the words only when they
11
+ * are short and not shown already; a skill's card always does.
11
12
  * - Then a card for each file the item's worker delivered, with Claw's own download link.
12
13
  *
13
14
  * Every word of this worker's own is in the person's language, never in that of what was said.
@@ -58,6 +59,12 @@ export declare class SayPlanner {
58
59
  * to the person; undefined for none. `holdsWords`: the card shows the words, which are then not said apart.
59
60
  */
60
61
  private card;
62
+ /**
63
+ * A personal skill the message is about (`skill_card`), recorded first: a draft is its held write (Save and Discard answer it as
64
+ * any held write is answered); anything done already records the change its Undo takes back. Undefined for none, and for a draft
65
+ * without its held write (it is then the plain held write's card).
66
+ */
67
+ private skillCard;
61
68
  /** A write Claw holds for the person (Allow, Deny) or a command put to them (Run, Cancel), recorded first; undefined for none. */
62
69
  private askCard;
63
70
  /**
@@ -6,7 +6,7 @@
6
6
  export declare const COMMANDS: readonly ["help", "new", "stop", "unlink", "whoami", "resume", "memory", "sessions"];
7
7
  /** The only commands a group chat accepts. */
8
8
  export declare const GROUP_COMMANDS: readonly ["help", "new", "stop", "whoami", "feedback"];
9
- export declare const PERSONAL_ONLY_COMMANDS: readonly ["link", "unlink", "resume", "timezone", "quiet", "pause", "brief", "repo", "sessions", "agents", "agent", "lang", "approvals"];
9
+ export declare const PERSONAL_ONLY_COMMANDS: readonly ["link", "unlink", "resume", "timezone", "quiet", "pause", "brief", "repo", "sessions", "agents", "agent", "lang", "approvals", "skills"];
10
10
  /**
11
11
  * `/feedback [TEXT]` takes an argument, so it is read with `commandArgs`, never `parseCommand`; it is listed here (not in
12
12
  * COMMANDS) only so that a group chat accepts it and an unknown `/word` is still plain text.
@@ -59,6 +59,8 @@ export * from "./approvals/index.js";
59
59
  export * from "./assistant/index.js";
60
60
  export * from "./assistant/work-items.js";
61
61
  export type * from "./assistant/views.js";
62
+ export * from "./skills/index.js";
63
+ export type { SkillCardEvent } from "./assistant/events.js";
62
64
  export * from "./direct-chat/index.js";
63
65
  export * from "./proactive/index.js";
64
66
  export * from "./proactive/views.js";
@@ -12,5 +12,6 @@ export * from "./assistant-chat.js";
12
12
  export * from "./assistant-devenv-hide.js";
13
13
  export * from "./assistant-work-clicks.js";
14
14
  export * from "./assistant.js";
15
+ export * from "./skills.js";
15
16
  export * from "./proactive-lines.js";
16
17
  export * from "./proactive.js";
@@ -0,0 +1,105 @@
1
+ export declare const skillText: import("./catalog.js").Catalog<{
2
+ savedTitle: (p: {
3
+ name: string;
4
+ version: number;
5
+ }) => string;
6
+ updatedTitle: (p: {
7
+ name: string;
8
+ version: number;
9
+ }) => string;
10
+ deletedTitle: (p: {
11
+ name: string;
12
+ }) => string;
13
+ disabledTitle: (p: {
14
+ name: string;
15
+ }) => string;
16
+ enabledTitle: (p: {
17
+ name: string;
18
+ }) => string;
19
+ draftTitle: (p: {
20
+ name: string;
21
+ }) => string;
22
+ whenToUse: string;
23
+ files: string;
24
+ manual: string;
25
+ autoNote: string;
26
+ draftNote: string;
27
+ undo: string;
28
+ edit: string;
29
+ save: string;
30
+ discard: string;
31
+ editTitle: (p: {
32
+ name: string;
33
+ }) => string;
34
+ editDescription: string;
35
+ editContent: string;
36
+ editSave: string;
37
+ editTooLong: (p: {
38
+ name: string;
39
+ }) => string;
40
+ undoneDeleted: (p: {
41
+ name: string;
42
+ }) => string;
43
+ undoneVersion: (p: {
44
+ name: string;
45
+ version: number;
46
+ }) => string;
47
+ undoneRestored: (p: {
48
+ name: string;
49
+ }) => string;
50
+ undoneEnabled: (p: {
51
+ name: string;
52
+ }) => string;
53
+ undoneDisabled: (p: {
54
+ name: string;
55
+ }) => string;
56
+ undoExpired: string;
57
+ undoChanged: (p: {
58
+ name: string;
59
+ }) => string;
60
+ undoDone: string;
61
+ undoFull: string;
62
+ gone: string;
63
+ failed: string;
64
+ refused: (p: {
65
+ why: string;
66
+ }) => string;
67
+ unavailable: string;
68
+ noSkills: string;
69
+ listTitle: (p: {
70
+ n: number;
71
+ }) => string;
72
+ listLine: (p: {
73
+ name: string;
74
+ version: number;
75
+ description: string;
76
+ state: string;
77
+ }) => string;
78
+ stateOff: string;
79
+ stateManual: string;
80
+ listHint: string;
81
+ showHead: (p: {
82
+ name: string;
83
+ version: number;
84
+ state: string;
85
+ }) => string;
86
+ showFiles: (p: {
87
+ files: string;
88
+ }) => string;
89
+ notFound: (p: {
90
+ name: string;
91
+ }) => string;
92
+ already: (p: {
93
+ name: string;
94
+ on: string;
95
+ }) => string;
96
+ on: string;
97
+ off: string;
98
+ usage: string;
99
+ couldNotRead: string;
100
+ draftSaved: (p: {
101
+ name: string;
102
+ version: number;
103
+ }) => string;
104
+ draftDiscarded: string;
105
+ }>;
@@ -1,11 +1,13 @@
1
1
  import type { ClawAssistantPort } from "./assistant.js";
2
2
  import type { ClawRemoteAgentsPort } from "./remote-agents.js";
3
3
  import type { ClawSessionsPort } from "./sessions.js";
4
+ import type { ClawSkillsPort } from "./skills.js";
4
5
  import type { ClawMergeConfirmationsPort, ClawNotificationsPort, ClawSettingsPort, ClawTriggersPort } from "./settings.js";
5
6
  import type { ClawWorkItemsPort } from "./work-items.js";
6
7
  export type * from "./assistant.js";
7
8
  export type * from "./remote-agents.js";
8
9
  export type * from "./sessions.js";
10
+ export type * from "./skills.js";
9
11
  export type * from "./settings.js";
10
12
  export type * from "./work-items.js";
11
13
  /**
@@ -25,4 +27,6 @@ export interface ClawPort {
25
27
  readonly triggers: ClawTriggersPort;
26
28
  readonly mergeConfirmations: ClawMergeConfirmationsPort;
27
29
  readonly remoteAgents: ClawRemoteAgentsPort;
30
+ /** The person's personal skills: `/skills`, and the buttons of a skill's card. */
31
+ readonly skills: ClawSkillsPort;
28
32
  }
@@ -0,0 +1,52 @@
1
+ import type { ClawCredential } from "../../claw/credential.js";
2
+ /** One of the person's personal skills as `/skills` lists it: the current version of each name, turned off ones included. */
3
+ export interface ClawSkillEntry {
4
+ readonly name: string;
5
+ readonly version: number;
6
+ readonly description: string;
7
+ readonly enabled: boolean;
8
+ /** `manual`: used only when the person names it. */
9
+ readonly invocation: "auto" | "manual";
10
+ /** Imported from someone else. */
11
+ readonly imported: boolean;
12
+ /** When a turn last read it (ISO), or "" never. */
13
+ readonly lastUsedAt: string;
14
+ readonly files: number;
15
+ }
16
+ /** One skill whole: SKILL.md and its files. */
17
+ export interface ClawSkill extends ClawSkillEntry {
18
+ readonly content: string;
19
+ readonly fileList: readonly {
20
+ readonly path: string;
21
+ readonly sizeBytes: number;
22
+ }[];
23
+ }
24
+ /** A change Claw made that the person can take back (`change_id`), and until when (ISO, "" not said). */
25
+ export interface ClawSkillChange {
26
+ readonly version: number | null;
27
+ readonly changed: boolean;
28
+ readonly changeId: string;
29
+ readonly undoExpiresAt: string;
30
+ }
31
+ /** What an undo did: `deleted`, `restored_version`, `restored`, `enabled` or `disabled`. */
32
+ export interface ClawSkillUndone {
33
+ readonly undone: string;
34
+ readonly name: string;
35
+ readonly version: number | null;
36
+ }
37
+ /**
38
+ * The person's personal skills (`/v1/users/me/skills`, `/v1/users/me/skill-changes`), always as that person. ClawError(404): no such
39
+ * skill, change or route (a Claw without them); ClawError(409/410): the change cannot be undone (`reason`, in the error's text).
40
+ */
41
+ export interface ClawSkillsPort {
42
+ list(key: ClawCredential): Promise<ClawSkillEntry[]>;
43
+ show(key: ClawCredential, name: string): Promise<ClawSkill>;
44
+ setEnabled(key: ClawCredential, name: string, enabled: boolean): Promise<ClawSkillChange>;
45
+ remove(key: ClawCredential, name: string): Promise<ClawSkillChange>;
46
+ /** Saves new text (and description) for one of the person's skills as its next version. */
47
+ update(key: ClawCredential, name: string, skill: {
48
+ readonly content: string;
49
+ readonly description: string;
50
+ }): Promise<ClawSkillChange>;
51
+ undo(key: ClawCredential, changeId: string): Promise<ClawSkillUndone>;
52
+ }
@@ -62,12 +62,55 @@ export interface AssistantConfirmWrite {
62
62
  confirmation_id: string;
63
63
  /** The short id the person may type back. */
64
64
  ref: string;
65
- /** `devenv_send`: an instruction for an agent on the person's own machine (`assistant/devenv-tools.ts`). */
66
- kind: "trigger_create" | "trigger_cancel" | "github_comment" | "devenv_send" | "devenv_hide";
65
+ /**
66
+ * `devenv_send`: an instruction for an agent on the person's own machine (`assistant/devenv-tools.ts`). `skill_save`: a personal skill
67
+ * the assistant drafted on its own, saved only when the person lets it through (`assistant/skill-writes.ts`); its message carries
68
+ * `skill_card` with what would be saved.
69
+ */
70
+ kind: "trigger_create" | "trigger_cancel" | "github_comment" | "devenv_send" | "devenv_hide" | "skill_save";
67
71
  /** What the button that lets it through says, in the language of the text. */
68
72
  allow_label: string;
69
73
  expires_at: string;
70
74
  }
75
+ /**
76
+ * A personal skill as a message shows it (`assistant/skill-writes.ts`): what was just saved, changed, turned off or deleted at the
77
+ * person's request, or what the assistant drafted for them to confirm. The message's text says the same in words, for a channel that
78
+ * draws no card. Everything here is the person's own skill, so it goes only to their own conversation, never a group's.
79
+ *
80
+ * - `saved` (a skill created, or a new version of one), `deleted`, `disabled`, `enabled`: done already. `change_id` is what an Undo
81
+ * button takes back, `POST /v1/users/me/skill-changes/{change_id}/undo` made as the person, until `undo_expires_at`: a created skill
82
+ * is deleted again, an update goes back to the version before, a delete is restored, a turn off or on is turned back. An Edit
83
+ * button changes the skill as it is now (`GET` then `PUT /v1/users/me/skills/{name}`).
84
+ * - `draft`: nothing is saved yet. The message also carries `confirm_write` (kind `skill_save`); its two buttons are Save (`allow`)
85
+ * and Discard (`deny`) on that confirmation.
86
+ */
87
+ export interface AssistantSkillCard {
88
+ kind: "saved" | "deleted" | "disabled" | "enabled" | "draft";
89
+ name: string;
90
+ /** The version now (for `draft`, the version a save would make; null when not known). */
91
+ version: number | null;
92
+ /** `saved`: true for a new skill (or one brought back), false for a new version of one the person had. */
93
+ created?: boolean;
94
+ /** When to use it, in the person's words: what decides whether it is used without being named. */
95
+ description: string;
96
+ /** `manual`: used only when the person names it. */
97
+ invocation: "auto" | "manual";
98
+ files: Array<{
99
+ path: string;
100
+ size_bytes: number;
101
+ }>;
102
+ /** The first lines of SKILL.md (at most 30 lines and 1500 characters), for the card to show; empty for `deleted`. */
103
+ preview: string;
104
+ change_id?: string;
105
+ undo_expires_at?: string;
106
+ /** `draft`: the confirmation its Save and Discard answer, the same as `confirm_write.confirmation_id`. */
107
+ confirmation_id?: string;
108
+ /**
109
+ * `draft` shown where the user has no assistant (a session event of the chat a worker saved from): no confirmation, the draft itself,
110
+ * saved with `POST /v1/users/me/skill-drafts/{draft_id}/confirm` and dropped with `DELETE` on the same path.
111
+ */
112
+ draft_id?: string;
113
+ }
71
114
  /**
72
115
  * A file a work item's worker delivered (`deliver_file`, `deliver_text`), or one the router wrote (`deliver_text`), for a channel to
73
116
  * offer as a download. The download is Claw's own link, `GET /v1/sessions/{session_id}/deliveries/{id}`, which answers only the
@@ -179,6 +222,8 @@ export interface AssistantSayPayload extends AssistantEventBase {
179
222
  */
180
223
  choices?: AssistantSayChoice;
181
224
  confirm_write?: AssistantConfirmWrite;
225
+ /** A personal skill the message is about (`AssistantSkillCard`); present only with `CLAW_USER_SKILLS_ENABLED`. */
226
+ skill_card?: AssistantSkillCard;
182
227
  /** Files the user gets with the message (a worker's deliveries, `deliveries.ts`): one download each. */
183
228
  files?: AssistantFile[];
184
229
  /** Present on a development environment session's own message: which session, and which of its three kinds of news. */
@@ -0,0 +1,4 @@
1
+ import type { SkillCardEvent } from "../assistant/events.js";
2
+ import type { ClawSkill, ClawSkillEntry } from "../ports/claw/skills.js";
3
+ /** A skill Claw answered, as a card shows it (`kind`, and the change its Undo takes back, "" none). */
4
+ export declare function skillCardOfSkill(skill: ClawSkillEntry & Partial<Pick<ClawSkill, "content" | "fileList">>, kind: SkillCardEvent["kind"], changeId: string): SkillCardEvent;
@@ -0,0 +1,24 @@
1
+ import { ClawError } from "../claw/errors.js";
2
+ import type { ClawSkillsPort } from "../ports/claw/skills.js";
3
+ import type { ClickHandler, ClickRoute } from "../ports/routing.js";
4
+ import type { Logger } from "../ports/logger.js";
5
+ import type { StorePort } from "../ports/store/index.js";
6
+ export interface SkillClickDeps {
7
+ readonly store: Pick<StorePort, "assistantButtons">;
8
+ readonly skills: ClawSkillsPort;
9
+ readonly logger: Logger;
10
+ }
11
+ /** Why Claw refused (the `reason` of its answer), or "". */
12
+ export declare function refusalReason(error: ClawError): string;
13
+ /** Claw's own words for a refusal (its `error`), or the status. */
14
+ export declare function refusalWords(error: ClawError): string;
15
+ export declare class SkillCardClicks implements ClickHandler {
16
+ private readonly deps;
17
+ readonly verbs: readonly ["assistant_skill"];
18
+ constructor(deps: SkillClickDeps);
19
+ withCredential(click: ClickRoute, credential: string): Promise<void>;
20
+ private undo;
21
+ private undoRefused;
22
+ private edit;
23
+ private saveEdit;
24
+ }
@@ -0,0 +1,22 @@
1
+ import type { ClawSkillsPort } from "../ports/claw/skills.js";
2
+ import type { Logger } from "../ports/logger.js";
3
+ import type { CommandHandler, CommandRoute } from "../ports/routing.js";
4
+ import type { StorePort } from "../ports/store/index.js";
5
+ export interface SkillsCommandDeps {
6
+ readonly store: Pick<StorePort, "assistantButtons">;
7
+ readonly skills: ClawSkillsPort;
8
+ readonly logger: Logger;
9
+ }
10
+ /** The longest SKILL.md `/skills show` says whole (code points); a longer one is cut, with a note. */
11
+ export declare const SHOW_MAX = 3500;
12
+ export declare class SkillsCommand implements CommandHandler {
13
+ private readonly deps;
14
+ readonly name = "skills";
15
+ constructor(deps: SkillsCommandDeps);
16
+ run(route: CommandRoute, args: string): Promise<boolean>;
17
+ private dispatch;
18
+ private state;
19
+ private list;
20
+ private show;
21
+ private act;
22
+ }
@@ -0,0 +1,5 @@
1
+ /** The person's personal skills in the chat: `/skills`, and the buttons of a skill's card. */
2
+ export { SkillCardClicks, type SkillClickDeps } from "./clicks.js";
3
+ export { SkillsCommand, type SkillsCommandDeps } from "./command.js";
4
+ export { SKILL_EDIT_CONTENT, SKILL_EDIT_DESCRIPTION, SKILL_EDIT_MAX, SKILL_UNDO_KIND, SKILL_VERB } from "./views.js";
5
+ export type { SkillCardModel, SkillEditModel } from "./views.js";
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The cards of the person's personal skills. What they say is `skillText`'s; a surface draws them. Their buttons carry only the id of
3
+ * the card this worker recorded (`assistant_confirm_cards`): what a press means is read from the record, never from the click.
4
+ */
5
+ import type { SkillCardEvent } from "../assistant/events.js";
6
+ /** The kind a skill card's record has: its Undo takes back the change it names (`confirmationId`, the change's id); `label` is the skill's name. */
7
+ export declare const SKILL_UNDO_KIND = "skill_undo";
8
+ /** The verb of the Undo, Edit and Save changes buttons (a draft's Save and Discard are the held write's own, `assistant_confirm`). */
9
+ export declare const SKILL_VERB = "assistant_skill";
10
+ /** The ids of the edit card's inputs. */
11
+ export declare const SKILL_EDIT_DESCRIPTION = "skill_description";
12
+ export declare const SKILL_EDIT_CONTENT = "skill_content";
13
+ /** The longest SKILL.md edited on a card (code points): a longer one is changed by telling the assistant. */
14
+ export declare const SKILL_EDIT_MAX = 6000;
15
+ /** A skill as its card shows it: what was saved, changed, turned off or deleted (with Undo and Edit), or a draft (Save, Discard). */
16
+ export interface SkillCardModel {
17
+ readonly skill: SkillCardEvent;
18
+ /** The card's record ("" none: no buttons). A draft's is its held write; any other's is its change, for Undo and Edit. */
19
+ readonly cardId: string;
20
+ /** A draft's Save, in Claw's word ("" for the catalog's). */
21
+ readonly allowLabel: string;
22
+ /** One line under it ("" none): what came of a press, or why to press again. */
23
+ readonly note: string;
24
+ /** Its buttons are gone: answered already. */
25
+ readonly ended: boolean;
26
+ readonly lang: "zh" | "en";
27
+ }
28
+ /** A skill's text and description to change, with Save changes. */
29
+ export interface SkillEditModel {
30
+ readonly cardId: string;
31
+ readonly name: string;
32
+ readonly description: string;
33
+ readonly content: string;
34
+ /** One line above Save changes ("" none): why the last Save did not go through. */
35
+ readonly note: string;
36
+ readonly lang: "zh" | "en";
37
+ }
38
+ declare module "../ports/surface.js" {
39
+ interface ViewMap {
40
+ skillCard: SkillCardModel;
41
+ skillEdit: SkillEditModel;
42
+ }
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primusclaw/personal-agent",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "The personal agent's channel-neutral core: domain logic, ports and plugin interfaces.",
5
5
  "license": "MIT",
6
6
  "repository": {