@use-aistack/cli 0.19.1 → 0.20.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
@@ -18906,7 +18906,7 @@ function apiEquivalentCost(modelKey, t, atMs) {
18906
18906
  }
18907
18907
 
18908
18908
  // src/version.ts
18909
- var CLI_VERSION = true ? "0.19.1" : "0.0.0-dev";
18909
+ var CLI_VERSION = true ? "0.20.0" : "0.0.0-dev";
18910
18910
 
18911
18911
  // src/api.ts
18912
18912
  var BASE_URL = process.env.AISTACK_URL || "https://aistack.to";
@@ -20638,6 +20638,7 @@ function createAggregate() {
20638
20638
  lastTs: null,
20639
20639
  toolCalls: /* @__PURE__ */ new Map(),
20640
20640
  skillCalls: /* @__PURE__ */ new Map(),
20641
+ skillTypedCalls: /* @__PURE__ */ new Map(),
20641
20642
  mcpServerCalls: /* @__PURE__ */ new Map(),
20642
20643
  mcpToolCalls: /* @__PURE__ */ new Map(),
20643
20644
  subagentCalls: /* @__PURE__ */ new Map(),
@@ -20653,6 +20654,10 @@ function createAggregate() {
20653
20654
  };
20654
20655
  }
20655
20656
  var bump = (m, k, n = 1) => m.set(k, (m.get(k) ?? 0) + n);
20657
+ function bumpTypedSkill(agg, name) {
20658
+ bump(agg.skillCalls, name);
20659
+ bump(agg.skillTypedCalls, name);
20660
+ }
20656
20661
  function emptyUsage() {
20657
20662
  return {
20658
20663
  input: 0,
@@ -20784,6 +20789,7 @@ function finalize(agg) {
20784
20789
  projects: agg.projectDirs.size,
20785
20790
  tools: byCount(agg.toolCalls),
20786
20791
  skills: byCount(agg.skillCalls),
20792
+ skillsTyped: new Map(agg.skillTypedCalls),
20787
20793
  mcpServers: byCount(agg.mcpServerCalls),
20788
20794
  subagents: byCount(agg.subagentCalls),
20789
20795
  slashCommands: byCount(agg.slashCommands),
@@ -22690,6 +22696,11 @@ function buildModels(rows, totalTokens, publishCost) {
22690
22696
  return model;
22691
22697
  });
22692
22698
  }
22699
+ var TYPED_SKILL_HARNESSES = /* @__PURE__ */ new Set([
22700
+ "claude-code",
22701
+ "codex",
22702
+ "opencode"
22703
+ ]);
22693
22704
  function buildPayload(input) {
22694
22705
  const {
22695
22706
  aggregate: agg,
@@ -22738,8 +22749,8 @@ function buildPayload(input) {
22738
22749
  );
22739
22750
  const skills = buildCategory(
22740
22751
  finalized.skills,
22741
- new Set(allowlist.skills),
22742
- optIns.skills,
22752
+ new Set(finalized.skills.map(([name]) => name)),
22753
+ [],
22743
22754
  observedCalls.skills
22744
22755
  );
22745
22756
  const subagents = buildCategory(
@@ -22783,7 +22794,10 @@ function buildPayload(input) {
22783
22794
  inventory: {
22784
22795
  builtinTools: builtins.atoms,
22785
22796
  mcpServers: mcp.atoms,
22786
- skills: skills.atoms,
22797
+ skills: TYPED_SKILL_HARNESSES.has(harnessName) ? skills.atoms.map((atom) => ({
22798
+ ...atom,
22799
+ typedCalls: finalized.skillsTyped.get(atom.name) ?? 0
22800
+ })) : skills.atoms,
22787
22801
  subagents: subagents.atoms,
22788
22802
  slashCommands: slash.atoms,
22789
22803
  withheld: {
@@ -23580,7 +23594,8 @@ function createAggregate2() {
23580
23594
  workflowSeenCalls: /* @__PURE__ */ new Set(),
23581
23595
  workflowSeenTurns: /* @__PURE__ */ new Set(),
23582
23596
  contextFirstCall: /* @__PURE__ */ new Map(),
23583
- workflowToolNames: /* @__PURE__ */ new Map()
23597
+ workflowToolNames: /* @__PURE__ */ new Map(),
23598
+ typedCommands: /* @__PURE__ */ new Map()
23584
23599
  });
23585
23600
  }
23586
23601
  function workflowSessionKey(rec) {
@@ -24020,6 +24035,7 @@ function toolResultBytes(content) {
24020
24035
  }
24021
24036
  return bytes;
24022
24037
  }
24038
+ var SKILL_BODY_PREFIX = "Base directory for this skill:";
24023
24039
  function ingestUser(agg, rec) {
24024
24040
  const msg = asObj(rec.message);
24025
24041
  if (!msg) return;
@@ -24033,10 +24049,34 @@ function ingestUser(agg, rec) {
24033
24049
  if (asStr(block.type) === "text") text += asStr(block.text) ?? "";
24034
24050
  }
24035
24051
  }
24052
+ if (rec.isMeta === true && !asStr(rec.sourceToolUseID) && text.startsWith(SKILL_BODY_PREFIX)) {
24053
+ ingestTypedSkill(agg, rec, text);
24054
+ return;
24055
+ }
24036
24056
  if (!text.includes("<command-name>")) return;
24057
+ const names = [];
24037
24058
  for (const match of text.matchAll(SLASH_RE)) {
24038
- bump(agg.slashCommands, cleanName(match[1]));
24059
+ const name = cleanName(match[1]);
24060
+ bump(agg.slashCommands, name);
24061
+ names.push(name);
24062
+ }
24063
+ const uuid = asStr(rec.uuid);
24064
+ if (uuid && names.length > 0) agg.typedCommands.set(uuid, names);
24065
+ }
24066
+ function ingestTypedSkill(agg, rec, text) {
24067
+ const parent = asStr(rec.parentUuid);
24068
+ const typed = parent ? agg.typedCommands.get(parent) : void 0;
24069
+ if (typed?.length === 1) {
24070
+ const name = typed[0];
24071
+ const left = (agg.slashCommands.get(name) ?? 0) - 1;
24072
+ if (left > 0) agg.slashCommands.set(name, left);
24073
+ else agg.slashCommands.delete(name);
24074
+ bumpTypedSkill(agg, name);
24075
+ return;
24039
24076
  }
24077
+ const dir = text.slice(SKILL_BODY_PREFIX.length).split("\n")[0].trim();
24078
+ const base = dir.split(/[\\/]/).filter(Boolean).pop();
24079
+ bumpTypedSkill(agg, base ? cleanName(base) : "(unnamed)");
24040
24080
  }
24041
24081
 
24042
24082
  // src/harness/claude/scan.ts
@@ -24222,7 +24262,8 @@ function createFileState() {
24222
24262
  metaTsMs: null,
24223
24263
  forked: false,
24224
24264
  sawResponse: false,
24225
- callNames: /* @__PURE__ */ new Map()
24265
+ callNames: /* @__PURE__ */ new Map(),
24266
+ turnSkills: /* @__PURE__ */ new Set()
24226
24267
  };
24227
24268
  }
24228
24269
  function genuineDelta(payload, state, tsMs) {
@@ -24291,9 +24332,10 @@ function ingestLine(agg, raw, state, sinceMs) {
24291
24332
  }
24292
24333
  noteActivity(agg, state, tsMs);
24293
24334
  noteProjectDay(agg, state.cwd ?? "(unknown)", tsMs);
24294
- if (type === "event_msg" && payload)
24335
+ if (type === "event_msg" && payload) {
24336
+ if (asStr(payload.type) === "task_started") state.turnSkills.clear();
24295
24337
  ingestEvent(agg, payload, state, tsMs, firstCall);
24296
- else if (type === "response_item" && payload)
24338
+ } else if (type === "response_item" && payload)
24297
24339
  ingestItem(agg, payload, state, tsMs);
24298
24340
  else if (type === "compacted" && tsMs !== null && state.sessionId) {
24299
24341
  agg.workflow.ingest({
@@ -24403,10 +24445,16 @@ function ingestItem(agg, payload, state, tsMs) {
24403
24445
  if (!name) return;
24404
24446
  const callId = asStr(payload.call_id) ?? asStr(payload.id);
24405
24447
  if (callId) state.callNames.set(callId, name);
24448
+ if (name !== "apply_patch" && (!callId || !agg.toolCallDedup.has(callId)))
24449
+ ingestSkillReads(agg, payload.arguments ?? payload.input, state);
24406
24450
  ingestCall(agg, name, callId);
24407
24451
  ingestWorkflowCall(agg, payload, name, callId, state, tsMs);
24408
24452
  return;
24409
24453
  }
24454
+ if (type === "message" && asStr(payload.role) === "user") {
24455
+ ingestSkillMention(agg, payload, state);
24456
+ return;
24457
+ }
24410
24458
  if (type === "local_shell_call") {
24411
24459
  const callId = asStr(payload.call_id) ?? asStr(payload.id);
24412
24460
  if (callId) state.callNames.set(callId, "local_shell");
@@ -24435,6 +24483,34 @@ function ingestItem(agg, payload, state, tsMs) {
24435
24483
  );
24436
24484
  }
24437
24485
  }
24486
+ var SKILL_READ_RE = /([A-Za-z0-9._:@-]+)[/\\]SKILL\.md\b/g;
24487
+ function ingestSkillReads(agg, args, state) {
24488
+ if (typeof args !== "string" || !args.includes("SKILL.md")) return;
24489
+ for (const match of args.matchAll(SKILL_READ_RE))
24490
+ countTurnSkill(agg, cleanName(match[1]), state);
24491
+ }
24492
+ var SKILL_MENTION_RE = /^<skill>\s*<name>([^<]{1,200})<\/name>/;
24493
+ function ingestSkillMention(agg, payload, state) {
24494
+ for (const rawBlock of asArr(payload.content)) {
24495
+ const text = asStr(asObj(rawBlock)?.text);
24496
+ const name = text ? SKILL_MENTION_RE.exec(text)?.[1] : void 0;
24497
+ if (!name) continue;
24498
+ const id = asStr(payload.id);
24499
+ if (id) {
24500
+ const key2 = `skill-mention:${id}`;
24501
+ if (agg.toolCallDedup.has(key2)) return;
24502
+ agg.toolCallDedup.add(key2);
24503
+ }
24504
+ countTurnSkill(agg, cleanName(name), state, true);
24505
+ return;
24506
+ }
24507
+ }
24508
+ function countTurnSkill(agg, name, state, typed = false) {
24509
+ if (state.turnSkills.has(name)) return;
24510
+ state.turnSkills.add(name);
24511
+ if (typed) bumpTypedSkill(agg, name);
24512
+ else bump(agg.skillCalls, name);
24513
+ }
24438
24514
  function ingestToolResult(agg, payload, state, tsMs) {
24439
24515
  if (tsMs === null || !state.sessionId) return;
24440
24516
  const callId = asStr(payload.call_id) ?? asStr(payload.id);
@@ -27343,6 +27419,16 @@ function noteConfiguredMcpServers2(agg, state, serverNames) {
27343
27419
  }
27344
27420
  state.mcpServers.sort((a, b) => b.length - a.length);
27345
27421
  }
27422
+ function ingestTypedSkill2(agg, row) {
27423
+ const id = asStr(row.id);
27424
+ const dir = asStr(row.skillDir)?.trim();
27425
+ if (!id || !dir) return;
27426
+ const key2 = `typed-skill:${id}`;
27427
+ if (agg.toolCallDedup.has(key2)) return;
27428
+ agg.toolCallDedup.add(key2);
27429
+ const base = dir.split(/[\\/]/).filter(Boolean).pop();
27430
+ if (base) bumpTypedSkill(agg, cleanName(base));
27431
+ }
27346
27432
 
27347
27433
  // src/harness/opencode/scan.ts
27348
27434
  import { readFileSync as readFileSync12 } from "node:fs";
@@ -27527,6 +27613,21 @@ function readDb(agg, state, open4, file, sinceMs) {
27527
27613
  messageId: r.message_id
27528
27614
  });
27529
27615
  }
27616
+ const typedSkills = db.prepare(
27617
+ `select id, substr(rest, 1, case when instr(rest, char(10)) > 0
27618
+ then instr(rest, char(10)) - 1 else 512 end) as skill_dir
27619
+ from (
27620
+ select p.id as id, substr(json_extract(p.data, '$.text'),
27621
+ instr(json_extract(p.data, '$.text'), 'Base directory for this skill: ') + 31) as rest
27622
+ from part p join message m on m.id = p.message_id
27623
+ where p.time_created >= ?
27624
+ and json_extract(p.data, '$.type') = 'text'
27625
+ and json_extract(m.data, '$.role') = 'user'
27626
+ and instr(json_extract(p.data, '$.text'), 'Base directory for this skill: ') > 0
27627
+ )`
27628
+ );
27629
+ for (const r of typedSkills.all(sinceMs))
27630
+ ingestTypedSkill2(agg, { id: r.id, skillDir: r.skill_dir });
27530
27631
  try {
27531
27632
  const v2parts = db.prepare(
27532
27633
  `select sm.id || ':' || je.key as id, sm.id as message_id,