@shrkcrft/knowledge 0.1.0-alpha.14 → 0.1.0-alpha.15

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.
@@ -1 +1 @@
1
- {"version":3,"file":"action-hints-formatter.d.ts","sourceRoot":"","sources":["../../src/format/action-hints-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAGlC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC/B;AAkBD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,SAAS,eAAe,EAAE,GAClC,sBAAsB,CAyCxB;AAED,MAAM,WAAW,wBAAwB;IACvC,sEAAsE;IACtE,KAAK,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC;IACrB,wEAAwE;IACxE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,sBAAsB,EAC7B,OAAO,GAAE,wBAA6B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ACnC,KAAK,EAAE,sBAAsB,EAC7B,OAAO,GAAE,wBAA6B,GACrC,MAAM,CA2DR;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,eAAe,EACtB,OAAO,GAAE,wBAA6B,GACrC,MAAM,CAGR;AAED,mFAAmF;AACnF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,sBAAsB,GAAG,MAAM,CAE3E"}
@@ -1,6 +1,9 @@
1
1
  import { priorityWeight } from "../model/knowledge-priority.js";
2
2
  function dedupePush(out, items, key) {
3
- if (!items)
3
+ // Defensive: an entry may author an object-array hint (commands / mcpTools)
4
+ // as a scalar by mistake. Iterating a non-array here would walk string chars
5
+ // and produce garbage keys, so anything that isn't an array is ignored.
6
+ if (!Array.isArray(items))
4
7
  return;
5
8
  const seen = new Set(out.map(key));
6
9
  for (const item of items) {
@@ -11,8 +14,24 @@ function dedupePush(out, items, key) {
11
14
  }
12
15
  }
13
16
  }
17
+ /**
18
+ * Coerce an authored hint value into a string array. A common authoring typo
19
+ * is to write a single-value field as a scalar (`preferredFlow: 'x'`) instead
20
+ * of an array (`preferredFlow: ['x']`). A scalar string has `.length` but no
21
+ * `.map`, which previously crashed the formatter (`preferredFlow.map is not a
22
+ * function`) and took down the whole `shrk context` entrypoint. Normalizing
23
+ * here preserves the authored content while guaranteeing the all-array contract
24
+ * of `IAggregatedActionHints`.
25
+ */
26
+ function toHintStrings(value) {
27
+ if (Array.isArray(value))
28
+ return value.filter((v) => typeof v === 'string');
29
+ if (typeof value === 'string' && value.trim().length > 0)
30
+ return [value];
31
+ return [];
32
+ }
14
33
  function dedupeStrings(out, items) {
15
- dedupePush(out, items, (s) => s);
34
+ dedupePush(out, toHintStrings(items), (s) => s);
16
35
  }
17
36
  /**
18
37
  * Combine actionHints from a list of relevant entries into a single bundle.
@@ -41,8 +60,9 @@ export function aggregateActionHints(entries) {
41
60
  continue;
42
61
  dedupePush(out.commands, h.commands, (c) => c.command);
43
62
  dedupePush(out.mcpTools, h.mcpTools, (m) => m.tool);
44
- if (!out.preferredFlow.length && h.preferredFlow?.length) {
45
- out.preferredFlow = h.preferredFlow;
63
+ const flow = toHintStrings(h.preferredFlow);
64
+ if (!out.preferredFlow.length && flow.length) {
65
+ out.preferredFlow = flow;
46
66
  out.preferredFlowSourceId = entry.id;
47
67
  }
48
68
  dedupeStrings(out.forbiddenActions, h.forbiddenActions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shrkcrft/knowledge",
3
- "version": "0.1.0-alpha.14",
3
+ "version": "0.1.0-alpha.15",
4
4
  "description": "SharkCraft structured knowledge model: typed entries, index, search, loaders (TS + markdown), validation.",
5
5
  "license": "MIT",
6
6
  "author": "SharkCraft contributors",
@@ -44,7 +44,7 @@
44
44
  "typecheck": "tsc --noEmit -p tsconfig.json"
45
45
  },
46
46
  "dependencies": {
47
- "@shrkcrft/core": "^0.1.0-alpha.14"
47
+ "@shrkcrft/core": "^0.1.0-alpha.15"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"