@plurnk/plurnk-contracts 8.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/SPEC.md +10 -24
  2. package/dist/schema/DaemonNotificationEnvelope.json +555 -0
  3. package/dist/schema/McpServerDefinition.json +1 -1
  4. package/dist/schema/PlurnkStatement.json +24 -0
  5. package/dist/schema/ProposalProjection.json +0 -4
  6. package/dist/src/Application.d.ts +22 -1
  7. package/dist/src/Application.d.ts.map +1 -1
  8. package/dist/src/Application.js +480 -15
  9. package/dist/src/Application.js.map +1 -1
  10. package/dist/src/ApplicationNotifications.d.ts +59 -19
  11. package/dist/src/ApplicationNotifications.d.ts.map +1 -1
  12. package/dist/src/ApplicationNotifications.js +40 -7
  13. package/dist/src/ApplicationNotifications.js.map +1 -1
  14. package/dist/src/ApplicationPort.d.ts +26 -7
  15. package/dist/src/ApplicationPort.d.ts.map +1 -1
  16. package/dist/src/ApplicationPort.js.map +1 -1
  17. package/dist/src/LogRow.d.ts +1 -1
  18. package/dist/src/LogRow.js +1 -1
  19. package/dist/src/LogRow.js.map +1 -1
  20. package/dist/src/Validator.d.ts +3 -3
  21. package/dist/src/Validator.d.ts.map +1 -1
  22. package/dist/src/Validator.js +8 -16
  23. package/dist/src/Validator.js.map +1 -1
  24. package/dist/src/index.d.ts +2 -3
  25. package/dist/src/index.d.ts.map +1 -1
  26. package/dist/src/index.js +2 -3
  27. package/dist/src/index.js.map +1 -1
  28. package/dist/src/types.generated.d.ts +820 -636
  29. package/dist/src/types.generated.d.ts.map +1 -1
  30. package/dist/src/types.generated.js.map +1 -1
  31. package/dist/src/types.js +1 -1
  32. package/dist/src/types.js.map +1 -1
  33. package/package.json +2 -2
  34. package/dist/schema/ApplicationOperationEvent.json +0 -27
  35. package/dist/schema/CapabilityDescriptor.json +0 -28
  36. package/dist/schema/CapabilityPolicy.json +0 -22
  37. package/dist/schema/CapabilityProjection.json +0 -14
  38. package/dist/schema/CapabilitySelector.json +0 -29
  39. package/dist/src/CapabilityAdmission.d.ts +0 -11
  40. package/dist/src/CapabilityAdmission.d.ts.map +0 -1
  41. package/dist/src/CapabilityAdmission.js +0 -108
  42. package/dist/src/CapabilityAdmission.js.map +0 -1
@@ -18,7 +18,7 @@ export const formatServiceUpdateReport = (result) => {
18
18
  const verLine = `version: ${pkg}@${ver}${suffix} — to update packages, stop the daemon and run: ${upgradeCmd}`;
19
19
  return `${catLine}\n${verLine}`;
20
20
  };
21
- /** {§acp-action-binding} Parses a family command (`mcp`, `skills`, `personas`, `env`, `schedule`) into its action kind and parameters. */
21
+ /** {§acp-action-binding} Parses a family command (`mcp`, `skills`, `personas`, `members`, `env`, `schedule`) into its action kind and parameters. */
22
22
  export const parseFamilyCommand = (family, args) => {
23
23
  let scopePrefix = family === "env" ? "session" : "workspace";
24
24
  const filteredArgs = [];
@@ -39,7 +39,7 @@ export const parseFamilyCommand = (family, args) => {
39
39
  }
40
40
  const rawSub = filteredArgs[0] ?? "list";
41
41
  const sub = family === "env" && rawSub === "set"
42
- ? "add"
42
+ ? "replace"
43
43
  : family === "env" && rawSub === "unset"
44
44
  ? "remove"
45
45
  : rawSub;
@@ -101,7 +101,7 @@ export const parseFamilyCommand = (family, args) => {
101
101
  actionName,
102
102
  params: query.length === 0
103
103
  ? {}
104
- : family === "skills"
104
+ : family === "skills" || family === "personas"
105
105
  ? { source: query }
106
106
  : family === "schedule"
107
107
  ? { rule: query }
@@ -119,9 +119,54 @@ export const parseFamilyCommand = (family, args) => {
119
119
  };
120
120
  }
121
121
  if ((sub === "add" || sub === "replace") && family === "mcp") {
122
- const alias = rest[0] ?? "";
123
- const target = rest[1] ?? "";
124
- const extraArgs = rest.slice(2);
122
+ let urlFlag;
123
+ let commandFlag;
124
+ const argFlags = [];
125
+ const envObj = {};
126
+ const posArgs = [];
127
+ for (let i = 0; i < rest.length; i += 1) {
128
+ const tok = rest[i] ?? "";
129
+ if (tok === "--url" && rest[i + 1] !== undefined) {
130
+ urlFlag = rest[i + 1];
131
+ i += 1;
132
+ }
133
+ else if (tok.startsWith("--url=")) {
134
+ urlFlag = tok.slice("--url=".length);
135
+ }
136
+ else if (tok === "--command" && rest[i + 1] !== undefined) {
137
+ commandFlag = rest[i + 1];
138
+ i += 1;
139
+ }
140
+ else if (tok.startsWith("--command=")) {
141
+ commandFlag = tok.slice("--command=".length);
142
+ }
143
+ else if (tok === "--arg" && rest[i + 1] !== undefined) {
144
+ argFlags.push(rest[i + 1] ?? "");
145
+ i += 1;
146
+ }
147
+ else if (tok.startsWith("--arg=")) {
148
+ argFlags.push(tok.slice("--arg=".length));
149
+ }
150
+ else if (tok === "--env" && rest[i + 1] !== undefined) {
151
+ const pair = rest[i + 1] ?? "";
152
+ const eq = pair.indexOf("=");
153
+ if (eq > 0)
154
+ envObj[pair.slice(0, eq)] = pair.slice(eq + 1);
155
+ i += 1;
156
+ }
157
+ else if (tok.startsWith("--env=")) {
158
+ const pair = tok.slice("--env=".length);
159
+ const eq = pair.indexOf("=");
160
+ if (eq > 0)
161
+ envObj[pair.slice(0, eq)] = pair.slice(eq + 1);
162
+ }
163
+ else {
164
+ posArgs.push(tok);
165
+ }
166
+ }
167
+ const alias = posArgs[0] ?? "";
168
+ const target = urlFlag ?? commandFlag ?? posArgs[1] ?? "";
169
+ const extraArgs = argFlags.length > 0 ? argFlags : posArgs.slice(2);
125
170
  const params = /^https?:\/\//iu.test(target)
126
171
  ? { alias, type: "streamable-http", url: target }
127
172
  : {
@@ -129,6 +174,7 @@ export const parseFamilyCommand = (family, args) => {
129
174
  type: "stdio",
130
175
  command: target,
131
176
  ...(extraArgs.length > 0 ? { args: extraArgs } : {}),
177
+ ...(Object.keys(envObj).length > 0 ? { env: envObj } : {}),
132
178
  };
133
179
  return {
134
180
  scopePrefix,
@@ -139,8 +185,42 @@ export const parseFamilyCommand = (family, args) => {
139
185
  };
140
186
  }
141
187
  if (sub === "skills" && family === "mcp") {
142
- const server = rest[0] ?? "";
143
- const skill = rest[1];
188
+ let serverFlag;
189
+ let skillFlag;
190
+ let includeFiles;
191
+ let verify;
192
+ const posArgs = [];
193
+ for (let i = 0; i < rest.length; i += 1) {
194
+ const tok = rest[i] ?? "";
195
+ if ((tok === "--server" || tok === "--alias") && rest[i + 1] !== undefined) {
196
+ serverFlag = rest[i + 1];
197
+ i += 1;
198
+ }
199
+ else if (tok.startsWith("--server=")) {
200
+ serverFlag = tok.slice("--server=".length);
201
+ }
202
+ else if (tok.startsWith("--alias=")) {
203
+ serverFlag = tok.slice("--alias=".length);
204
+ }
205
+ else if (tok === "--skill" && rest[i + 1] !== undefined) {
206
+ skillFlag = rest[i + 1];
207
+ i += 1;
208
+ }
209
+ else if (tok.startsWith("--skill=")) {
210
+ skillFlag = tok.slice("--skill=".length);
211
+ }
212
+ else if (tok === "--include-files") {
213
+ includeFiles = true;
214
+ }
215
+ else if (tok === "--verify") {
216
+ verify = true;
217
+ }
218
+ else {
219
+ posArgs.push(tok);
220
+ }
221
+ }
222
+ const server = serverFlag ?? posArgs[0] ?? "";
223
+ const skill = skillFlag ?? (serverFlag !== undefined ? posArgs[0] : posArgs[1]);
144
224
  return {
145
225
  scopePrefix,
146
226
  sub,
@@ -149,6 +229,8 @@ export const parseFamilyCommand = (family, args) => {
149
229
  params: {
150
230
  server,
151
231
  ...(skill !== undefined && skill.length > 0 ? { skill } : {}),
232
+ ...(includeFiles === true ? { includeFiles: true } : {}),
233
+ ...(verify === true ? { verify: true } : {}),
152
234
  },
153
235
  };
154
236
  }
@@ -173,6 +255,74 @@ export const parseFamilyCommand = (family, args) => {
173
255
  };
174
256
  }
175
257
  if (sub === "complete" && family === "mcp") {
258
+ let serverFlag;
259
+ let promptFlag;
260
+ let uriFlag;
261
+ let nameFlag;
262
+ let valueFlag;
263
+ const posArgs = [];
264
+ for (let i = 0; i < rest.length; i += 1) {
265
+ const tok = rest[i] ?? "";
266
+ if ((tok === "--server" || tok === "--alias") && rest[i + 1] !== undefined) {
267
+ serverFlag = rest[i + 1];
268
+ i += 1;
269
+ }
270
+ else if (tok.startsWith("--server=")) {
271
+ serverFlag = tok.slice("--server=".length);
272
+ }
273
+ else if (tok.startsWith("--alias=")) {
274
+ serverFlag = tok.slice("--alias=".length);
275
+ }
276
+ else if (tok === "--prompt" && rest[i + 1] !== undefined) {
277
+ promptFlag = rest[i + 1];
278
+ i += 1;
279
+ }
280
+ else if (tok.startsWith("--prompt=")) {
281
+ promptFlag = tok.slice("--prompt=".length);
282
+ }
283
+ else if (tok === "--uri" && rest[i + 1] !== undefined) {
284
+ uriFlag = rest[i + 1];
285
+ i += 1;
286
+ }
287
+ else if (tok.startsWith("--uri=")) {
288
+ uriFlag = tok.slice("--uri=".length);
289
+ }
290
+ else if (tok === "--name" && rest[i + 1] !== undefined) {
291
+ nameFlag = rest[i + 1];
292
+ i += 1;
293
+ }
294
+ else if (tok.startsWith("--name=")) {
295
+ nameFlag = tok.slice("--name=".length);
296
+ }
297
+ else if (tok === "--value" && rest[i + 1] !== undefined) {
298
+ valueFlag = rest[i + 1];
299
+ i += 1;
300
+ }
301
+ else if (tok.startsWith("--value=")) {
302
+ valueFlag = tok.slice("--value=".length);
303
+ }
304
+ else {
305
+ posArgs.push(tok);
306
+ }
307
+ }
308
+ if (promptFlag !== undefined || uriFlag !== undefined || nameFlag !== undefined || valueFlag !== undefined || serverFlag !== undefined) {
309
+ const server = serverFlag ?? posArgs[0] ?? "";
310
+ const remPos = serverFlag !== undefined ? posArgs : posArgs.slice(1);
311
+ const ref = promptFlag !== undefined
312
+ ? { type: "ref/prompt", name: promptFlag }
313
+ : { type: "ref/resource", uri: uriFlag ?? "" };
314
+ const argument = {
315
+ name: nameFlag ?? remPos[0] ?? "",
316
+ value: valueFlag ?? remPos[1] ?? "",
317
+ };
318
+ return {
319
+ scopePrefix,
320
+ sub,
321
+ rest,
322
+ actionName: "workspace.mcp.complete",
323
+ params: { server, ref, argument },
324
+ };
325
+ }
176
326
  let server = "";
177
327
  let ref = { type: "ref/prompt", name: "" };
178
328
  let argTokens = [];
@@ -221,11 +371,19 @@ export const parseFamilyCommand = (family, args) => {
221
371
  };
222
372
  }
223
373
  if ((sub === "add" || sub === "replace") && family === "skills") {
374
+ let sourceFlag;
224
375
  let ref;
225
376
  const posArgs = [];
226
377
  for (let i = 0; i < rest.length; i += 1) {
227
378
  const tok = rest[i] ?? "";
228
- if (tok === "--ref" && rest[i + 1] !== undefined) {
379
+ if (tok === "--source" && rest[i + 1] !== undefined) {
380
+ sourceFlag = rest[i + 1];
381
+ i += 1;
382
+ }
383
+ else if (tok.startsWith("--source=")) {
384
+ sourceFlag = tok.slice("--source=".length);
385
+ }
386
+ else if (tok === "--ref" && rest[i + 1] !== undefined) {
229
387
  ref = rest[i + 1];
230
388
  i += 1;
231
389
  }
@@ -237,7 +395,7 @@ export const parseFamilyCommand = (family, args) => {
237
395
  }
238
396
  }
239
397
  const alias = posArgs[0] ?? "";
240
- const source = posArgs[1] ?? "";
398
+ const source = sourceFlag ?? posArgs[1] ?? "";
241
399
  return {
242
400
  scopePrefix,
243
401
  sub,
@@ -344,18 +502,126 @@ export const parseFamilyCommand = (family, args) => {
344
502
  params: { alias, value },
345
503
  };
346
504
  }
347
- if ((sub === "add" || sub === "replace") && family === "schedule") {
505
+ if (sub === "run" && family === "schedule") {
506
+ const alias = rest[0] ?? "";
507
+ return {
508
+ scopePrefix,
509
+ sub,
510
+ rest,
511
+ actionName: "workspace.schedule.run",
512
+ params: { alias },
513
+ };
514
+ }
515
+ if ((sub === "done" || sub === "reopen" || sub === "open") && family === "schedule") {
348
516
  const alias = rest[0] ?? "";
349
- const sessionArg = rest[1] ?? "";
350
- const rule = rest[2] ?? "";
351
- const prompt = rest.slice(3).join(" ");
517
+ const status = sub === "done" ? "done" : "open";
518
+ return {
519
+ scopePrefix,
520
+ sub: "status",
521
+ rest,
522
+ actionName: "workspace.schedule.status",
523
+ params: { alias, status },
524
+ };
525
+ }
526
+ if ((sub === "add" || sub === "replace") && family === "schedule") {
527
+ let ruleFlag;
528
+ let runFlag;
529
+ let targetFlag;
530
+ let promptFlag;
531
+ let personaFlag;
532
+ let catchupFlag;
533
+ const posArgs = [];
534
+ for (let i = 0; i < rest.length; i += 1) {
535
+ const tok = rest[i] ?? "";
536
+ if (tok === "--rule" && rest[i + 1] !== undefined) {
537
+ ruleFlag = rest[i + 1];
538
+ i += 1;
539
+ }
540
+ else if (tok.startsWith("--rule=")) {
541
+ ruleFlag = tok.slice("--rule=".length);
542
+ }
543
+ else if (tok === "--run" && rest[i + 1] !== undefined) {
544
+ runFlag = rest[i + 1];
545
+ i += 1;
546
+ }
547
+ else if (tok.startsWith("--run=")) {
548
+ runFlag = tok.slice("--run=".length);
549
+ }
550
+ else if (tok === "--target" && rest[i + 1] !== undefined) {
551
+ targetFlag = rest[i + 1];
552
+ i += 1;
553
+ }
554
+ else if (tok.startsWith("--target=")) {
555
+ targetFlag = tok.slice("--target=".length);
556
+ }
557
+ else if (tok === "--prompt" && rest[i + 1] !== undefined) {
558
+ promptFlag = rest[i + 1];
559
+ i += 1;
560
+ }
561
+ else if (tok.startsWith("--prompt=")) {
562
+ promptFlag = tok.slice("--prompt=".length);
563
+ }
564
+ else if (tok === "--persona" && rest[i + 1] !== undefined) {
565
+ personaFlag = rest[i + 1];
566
+ i += 1;
567
+ }
568
+ else if (tok.startsWith("--persona=")) {
569
+ personaFlag = tok.slice("--persona=".length);
570
+ }
571
+ else if (tok === "--catchup") {
572
+ catchupFlag = true;
573
+ }
574
+ else if (tok === "--no-catchup") {
575
+ catchupFlag = false;
576
+ }
577
+ else {
578
+ posArgs.push(tok);
579
+ }
580
+ }
581
+ const normalizeRuleArg = (raw) => raw === undefined || raw === "null" || raw === "none" ? null : raw;
582
+ if (runFlag !== undefined) {
583
+ const alias = posArgs[0] ?? "";
584
+ const rawRule = ruleFlag ?? posArgs[1];
585
+ const normalizedTarget = targetFlag === undefined
586
+ ? undefined
587
+ : targetFlag.startsWith("session://") ? targetFlag : `session://${targetFlag}`;
588
+ return {
589
+ scopePrefix,
590
+ sub,
591
+ rest,
592
+ actionName: `workspace.schedule.${sub}`,
593
+ params: {
594
+ alias,
595
+ rule: normalizeRuleArg(rawRule),
596
+ run: runFlag,
597
+ ...(normalizedTarget !== undefined ? { target: normalizedTarget } : {}),
598
+ ...(catchupFlag !== undefined ? { catchup: catchupFlag } : {}),
599
+ },
600
+ };
601
+ }
602
+ const alias = posArgs[0] ?? "";
603
+ const sessionArg = targetFlag ?? posArgs[1] ?? "";
604
+ const rawRule = ruleFlag ?? posArgs[2] ?? "";
605
+ const prompt = promptFlag !== undefined
606
+ ? promptFlag
607
+ : targetFlag !== undefined && ruleFlag !== undefined
608
+ ? posArgs.slice(1).join(" ")
609
+ : posArgs.slice(3).join(" ");
352
610
  const target = sessionArg.startsWith("session://") ? sessionArg : `session://${sessionArg}`;
611
+ const rule = rawRule === "null" || rawRule === "none" ? null : rawRule;
353
612
  return {
354
613
  scopePrefix,
355
614
  sub,
356
615
  rest,
357
616
  actionName: `workspace.schedule.${sub}`,
358
- params: { alias, rule, target, prompt },
617
+ params: {
618
+ alias,
619
+ rule,
620
+ target,
621
+ prompt,
622
+ ...(personaFlag !== undefined ? { persona: personaFlag } : {}),
623
+ ...(catchupFlag !== undefined ? { catchup: catchupFlag } : {}),
624
+ },
359
625
  };
360
626
  }
361
627
  return {
@@ -366,4 +632,203 @@ export const parseFamilyCommand = (family, args) => {
366
632
  params: rest.length > 0 ? { args: rest } : {},
367
633
  };
368
634
  };
635
+ /** {§acp-action-binding} Formats definition rows for `list` and multi-definition `members` mutations across CLI, ACP, and Web. */
636
+ export const formatFamilyRows = (family, result) => {
637
+ const definitions = Array.isArray(result.definitions)
638
+ ? result.definitions
639
+ : Array.isArray(result.items)
640
+ ? result.items
641
+ : [];
642
+ if (definitions.length === 0) {
643
+ return `${family}: none\n`;
644
+ }
645
+ const lines = [];
646
+ for (const item of definitions) {
647
+ if (!isRecord(item)) {
648
+ lines.push(String(item));
649
+ continue;
650
+ }
651
+ const alias = typeof item.alias === "string"
652
+ ? item.alias
653
+ : typeof item.name === "string"
654
+ ? item.name
655
+ : "";
656
+ const state = typeof item.state === "string" ? item.state : "active";
657
+ const def = isRecord(item.definition) ? item.definition : {};
658
+ const detail = isRecord(item.detail) ? item.detail : {};
659
+ const type = typeof def.type === "string" ? def.type : "";
660
+ const target = typeof def.command === "string"
661
+ ? def.command
662
+ : typeof def.url === "string"
663
+ ? def.url
664
+ : typeof def.source === "string"
665
+ ? def.source
666
+ : typeof def.value === "string"
667
+ ? def.value
668
+ : family === "schedule"
669
+ ? [
670
+ typeof detail.status === "string" ? `status=${detail.status}` : "",
671
+ typeof def.rule === "string" ? def.rule : def.rule === null ? "unscheduled" : "",
672
+ typeof def.target === "string"
673
+ ? def.target
674
+ : typeof def.run === "string"
675
+ ? "run"
676
+ : "",
677
+ ]
678
+ .filter((p) => p.length > 0)
679
+ .join(" ")
680
+ : family === "members"
681
+ ? [
682
+ typeof detail.effect === "string" ? detail.effect : "",
683
+ typeof detail.matched === "number" ? `matched=${String(detail.matched)}` : "",
684
+ ]
685
+ .filter((p) => p.length > 0)
686
+ .join(" ")
687
+ : typeof def.description === "string"
688
+ ? def.description
689
+ : "";
690
+ const extra = family === "personas"
691
+ ? [
692
+ typeof def.model === "string" && def.model.length > 0 ? `model=${def.model}` : "",
693
+ typeof def.effort === "string" && def.effort.length > 0 ? `effort=${def.effort}` : "",
694
+ ]
695
+ .filter((p) => p.length > 0)
696
+ .join(" ")
697
+ : "";
698
+ const prov = isRecord(item.provenance) ? item.provenance : {};
699
+ const source = typeof prov.source === "string" && prov.source.length > 0 ? `source=${prov.source}` : "";
700
+ const rowParts = [alias, state, type, target, extra, source].filter((p) => p.length > 0);
701
+ lines.push(rowParts.join(" "));
702
+ }
703
+ return `${lines.join("\n")}\n`;
704
+ };
705
+ /** {§acp-action-binding} Formats any family action result (`list`, `discover`, `add`, `replace`, `remove`, `enable`, `disable`, `skills`, `complete`, `oauth`, `run`, `status`) into structured human-readable text. */
706
+ export const formatFamilyResult = (family, actionName, params, result) => {
707
+ if (!isRecord(result)) {
708
+ return `Executed /${family}`;
709
+ }
710
+ if (actionName === "workspace.mcp.oauth.begin" || actionName === "workspace.mcp.oauth.complete") {
711
+ const alias = typeof result.alias === "string"
712
+ ? result.alias
713
+ : typeof params.alias === "string"
714
+ ? params.alias
715
+ : "";
716
+ if (isRecord(result.authorization) && typeof result.authorization.url === "string") {
717
+ return `${alias}: authorization required: ${result.authorization.url}`;
718
+ }
719
+ if (result.status === 202) {
720
+ return `${alias}: Sign-in accepted; tools awaiting activation.`;
721
+ }
722
+ if (result.status === 200) {
723
+ return `${alias} active`;
724
+ }
725
+ }
726
+ if (isRecord(result.completion) && Array.isArray(result.completion.values)) {
727
+ const values = result.completion.values.filter((v) => typeof v === "string");
728
+ return values.length === 0 ? `${family} complete: none` : values.join("\n");
729
+ }
730
+ if (actionName === "workspace.mcp.skills") {
731
+ if (result.found === false) {
732
+ return "mcp skills: none";
733
+ }
734
+ if (isRecord(result.skill) && typeof result.skill.name === "string") {
735
+ return `${result.skill.name} verified`;
736
+ }
737
+ if (Array.isArray(result.skills)) {
738
+ if (result.skills.length === 0)
739
+ return "mcp skills: none";
740
+ return result.skills
741
+ .map((item) => {
742
+ if (!isRecord(item))
743
+ return String(item);
744
+ const name = typeof item.name === "string" ? item.name : "";
745
+ const summary = typeof item.description === "string" && item.description.length > 0
746
+ ? ` ${item.description}`
747
+ : "";
748
+ return `${name}${summary}`;
749
+ })
750
+ .join("\n");
751
+ }
752
+ }
753
+ if (Array.isArray(result.candidates)) {
754
+ if (result.candidates.length === 0) {
755
+ return `${family} discover: none`;
756
+ }
757
+ return result.candidates
758
+ .map((item) => {
759
+ if (!isRecord(item))
760
+ return String(item);
761
+ const alias = typeof item.alias === "string" && item.alias.length > 0 ? item.alias : "";
762
+ const summary = typeof item.summary === "string" && item.summary.length > 0 ? item.summary : "";
763
+ return alias.length > 0 && summary.length > 0
764
+ ? `${alias} ${summary}`
765
+ : alias.length > 0
766
+ ? alias
767
+ : summary;
768
+ })
769
+ .join("\n");
770
+ }
771
+ if (result.removed === true && typeof result.alias === "string") {
772
+ return `${result.alias} removed`;
773
+ }
774
+ if (isRecord(result.definition) && typeof result.definition.alias === "string") {
775
+ return formatFamilyRows(family, { definitions: [result.definition] }).trimEnd();
776
+ }
777
+ if (Array.isArray(result.definitions) || Array.isArray(result.items)) {
778
+ return formatFamilyRows(family, result).trimEnd();
779
+ }
780
+ return `Executed /${family}`;
781
+ };
782
+ /** {§acp-action-binding} Expands `/learn [--scope project|plurnk] [instructions]` with folder-aware skill target resolution. */
783
+ export const expandLearnCommand = (rawLine, options) => {
784
+ const trimmed = rawLine.trim();
785
+ if (trimmed !== "/learn" && !trimmed.startsWith("/learn ")) {
786
+ return null;
787
+ }
788
+ const restText = trimmed.slice("/learn".length).trim();
789
+ const tokens = restText.length > 0 ? restText.split(/\s+/u) : [];
790
+ let explicitScope;
791
+ const instructionTokens = [];
792
+ for (let i = 0; i < tokens.length; i += 1) {
793
+ const tok = tokens[i] ?? "";
794
+ if (tok === "--scope") {
795
+ const next = tokens[i + 1];
796
+ if (next === undefined || next.startsWith("--")) {
797
+ return { ok: false, error: "Missing /learn --scope value: expected 'project' or 'plurnk'." };
798
+ }
799
+ explicitScope = next;
800
+ i += 1;
801
+ }
802
+ else if (tok.startsWith("--scope=")) {
803
+ explicitScope = tok.slice("--scope=".length);
804
+ }
805
+ else {
806
+ instructionTokens.push(tok);
807
+ }
808
+ }
809
+ if (explicitScope !== undefined && explicitScope !== "project" && explicitScope !== "plurnk") {
810
+ return {
811
+ ok: false,
812
+ error: `Invalid /learn scope '${explicitScope}': expected 'project' or 'plurnk'.`,
813
+ };
814
+ }
815
+ if (explicitScope === "project" && options?.projectRoot === null) {
816
+ return {
817
+ ok: false,
818
+ error: "This workspace has no project folder; use `/learn --scope plurnk` to save under $XDG_CONFIG_HOME/plurnk/skills.",
819
+ };
820
+ }
821
+ const scope = explicitScope ?? (options?.projectRoot === null ? "plurnk" : "project");
822
+ const targetPath = scope === "plurnk"
823
+ ? "${XDG_CONFIG_HOME:-~/.config}/plurnk/skills/<name>/SKILL.md"
824
+ : ".agents/skills/<name>/SKILL.md";
825
+ const instructions = instructionTokens.join(" ");
826
+ const basePrompt = `Distill reusable workflow, setup, or domain knowledge from this session into an Agent Skill at \`${targetPath}\` ` +
827
+ "(read `mcp:///plurnk/skills.json` first, write a concise `SKILL.md` with YAML frontmatter `name` and `description`, and verify discovery with the `skills` tool).";
828
+ return {
829
+ ok: true,
830
+ scope,
831
+ prompt: instructions.length > 0 ? `${basePrompt}\n\nFocus: ${instructions}` : basePrompt,
832
+ };
833
+ };
369
834
  //# sourceMappingURL=Application.js.map