@forwardimpact/model 0.2.0 → 0.4.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/lib/agent.js CHANGED
@@ -177,21 +177,25 @@ function findAgentBehaviour(agentBehaviours, id) {
177
177
  }
178
178
 
179
179
  /**
180
- * Build working style section from emphasized behaviours
181
- * Includes workflow patterns when available
180
+ * @typedef {Object} WorkingStyleEntry
181
+ * @property {string} title - Section title (e.g. "Own the outcome end-to-end")
182
+ * @property {string} content - Working style content (markdown)
183
+ */
184
+
185
+ /**
186
+ * Build working style entries from emphasized behaviours
187
+ * Returns structured data for template iteration
182
188
  * @param {Array} derivedBehaviours - Behaviours sorted by maturity (highest first)
183
189
  * @param {Array} agentBehaviours - Agent behaviour definitions with principles
184
190
  * @param {number} topN - Number of top behaviours to include
185
- * @returns {string} Working style markdown section
191
+ * @returns {WorkingStyleEntry[]} Array of working style entries
186
192
  */
187
193
  function buildWorkingStyleFromBehaviours(
188
194
  derivedBehaviours,
189
195
  agentBehaviours,
190
196
  topN = 3,
191
197
  ) {
192
- const sections = [];
193
- sections.push("## Working Style");
194
- sections.push("");
198
+ const entries = [];
195
199
 
196
200
  // Get top N behaviours by maturity
197
201
  const topBehaviours = derivedBehaviours.slice(0, topN);
@@ -207,22 +211,16 @@ function buildWorkingStyleFromBehaviours(
207
211
 
208
212
  // Use title as section header
209
213
  const title = agentBehaviour.title || derived.behaviourName;
210
- sections.push(`### ${title}`);
211
- sections.push("");
212
-
213
- // Include workingStyle if available (structured guidance)
214
- if (agentBehaviour.workingStyle) {
215
- sections.push(agentBehaviour.workingStyle.trim());
216
- sections.push("");
217
- } else if (agentBehaviour.principles) {
218
- // Fall back to principles
219
- const principles = agentBehaviour.principles.trim();
220
- sections.push(principles);
221
- sections.push("");
222
- }
214
+
215
+ // Include workingStyle if available, otherwise fall back to principles
216
+ const content = agentBehaviour.workingStyle
217
+ ? agentBehaviour.workingStyle.trim()
218
+ : agentBehaviour.principles.trim();
219
+
220
+ entries.push({ title, content });
223
221
  }
224
222
 
225
- return sections.join("\n");
223
+ return entries;
226
224
  }
227
225
 
228
226
  /**
@@ -308,8 +306,7 @@ function estimateBodyDataLength(bodyData) {
308
306
  "stageDescription",
309
307
  "identity",
310
308
  "priority",
311
- "delegation",
312
- "operationalContext",
309
+ "roleContext",
313
310
  "workingStyle",
314
311
  "beforeHandoff",
315
312
  ];
@@ -326,11 +323,6 @@ function estimateBodyDataLength(bodyData) {
326
323
  skill.name.length + skill.dirname.length + skill.useWhen.length + 50;
327
324
  }
328
325
  }
329
- if (bodyData.beforeMakingChanges) {
330
- for (const item of bodyData.beforeMakingChanges) {
331
- length += item.text.length + 5; // +5 for "1. " prefix
332
- }
333
- }
334
326
  if (bodyData.constraints) {
335
327
  for (const c of bodyData.constraints) {
336
328
  length += c.length + 2; // +2 for "- " prefix
@@ -496,6 +488,7 @@ function getChecklistStage(stageId) {
496
488
  * @param {Array} params.agentBehaviours - Agent behaviour definitions
497
489
  * @param {Array} params.skills - All skill definitions (for agent section lookup)
498
490
  * @param {string} params.checklistMarkdown - Pre-formatted checklist markdown
491
+ * @param {Array<{id: string, name: string, description: string}>} [params.agentIndex] - List of all available agents
499
492
  * @returns {Object} Structured profile body data
500
493
  */
501
494
  function buildStageProfileBodyData({
@@ -509,6 +502,7 @@ function buildStageProfileBodyData({
509
502
  agentBehaviours,
510
503
  skills,
511
504
  checklistMarkdown,
505
+ agentIndex,
512
506
  }) {
513
507
  const name = `${humanDiscipline.specialization || humanDiscipline.name} - ${humanTrack.name}`;
514
508
  const stageName = stage.name.charAt(0).toUpperCase() + stage.name.slice(1);
@@ -523,20 +517,6 @@ function buildStageProfileBodyData({
523
517
  ? substituteTemplateVars(rawPriority, humanDiscipline)
524
518
  : null;
525
519
 
526
- // Build beforeMakingChanges list - prefer track, fall back to discipline
527
- const rawSteps =
528
- agentTrack.beforeMakingChanges || agentDiscipline.beforeMakingChanges || [];
529
- const beforeMakingChanges = rawSteps.map((text, i) => ({
530
- index: i + 1,
531
- text: substituteTemplateVars(text, humanDiscipline),
532
- }));
533
-
534
- // Delegation (from discipline only, optional)
535
- const rawDelegation = agentDiscipline.delegation;
536
- const delegation = rawDelegation
537
- ? substituteTemplateVars(rawDelegation, humanDiscipline)
538
- : null;
539
-
540
520
  // Build skill index from derived skills with agent sections
541
521
  const skillIndex = derivedSkills
542
522
  .map((derived) => {
@@ -550,11 +530,11 @@ function buildStageProfileBodyData({
550
530
  })
551
531
  .filter(Boolean);
552
532
 
553
- // Operational Context - use track's roleContext (shared with human job descriptions)
554
- const operationalContext = humanTrack.roleContext.trim();
533
+ // Role Context - use track's roleContext (shared with human job descriptions)
534
+ const roleContext = humanTrack.roleContext.trim();
555
535
 
556
- // Working Style from derived behaviours (still markdown for now)
557
- const workingStyle = buildWorkingStyleFromBehaviours(
536
+ // Working styles from derived behaviours (structured for template iteration)
537
+ const workingStyles = buildWorkingStyleFromBehaviours(
558
538
  derivedBehaviours,
559
539
  agentBehaviours,
560
540
  3,
@@ -567,18 +547,26 @@ function buildStageProfileBodyData({
567
547
  ...(agentTrack.constraints || []),
568
548
  ];
569
549
 
550
+ // Filter agent index to only include agents with same track and stage (different disciplines)
551
+ // Agent IDs follow pattern: {discipline-abbrev}-{track-id-kebab}-{stage-id}
552
+ const trackSuffix = `-${toKebabCase(humanTrack.id)}-${stage.id}`;
553
+ const currentAgentId = `${getDisciplineAbbreviation(humanDiscipline.id)}${trackSuffix}`;
554
+ const filteredAgentIndex = (agentIndex || []).filter(
555
+ (agent) => agent.id.endsWith(trackSuffix) && agent.id !== currentAgentId,
556
+ );
557
+
570
558
  return {
571
559
  title: `${name} - ${stageName} Agent`,
572
560
  stageDescription: stage.description,
573
561
  identity: identity.trim(),
574
562
  priority: priority ? priority.trim() : null,
575
563
  skillIndex,
576
- beforeMakingChanges,
577
- delegation: delegation ? delegation.trim() : null,
578
- operationalContext,
579
- workingStyle,
564
+ roleContext,
565
+ workingStyles,
580
566
  beforeHandoff: checklistMarkdown || null,
581
567
  constraints,
568
+ agentIndex: filteredAgentIndex,
569
+ hasAgentIndex: filteredAgentIndex.length > 0,
582
570
  };
583
571
  }
584
572
 
@@ -681,6 +669,7 @@ export function deriveStageAgent({
681
669
  * @param {Object} params.agentTrack - Agent track definition
682
670
  * @param {Array} params.capabilities - Capabilities with checklists
683
671
  * @param {Array} params.stages - All stages (for handoff entry criteria)
672
+ * @param {Array<{id: string, name: string, description: string}>} [params.agentIndex] - List of all available agents
684
673
  * @returns {Object} Profile with frontmatter, bodyData, and filename
685
674
  */
686
675
  export function generateStageAgentProfile({
@@ -695,6 +684,7 @@ export function generateStageAgentProfile({
695
684
  agentTrack,
696
685
  capabilities,
697
686
  stages,
687
+ agentIndex,
698
688
  }) {
699
689
  // Derive the complete agent
700
690
  const agent = deriveStageAgent({
@@ -716,10 +706,8 @@ export function generateStageAgentProfile({
716
706
  const fullName = `${abbrev}-${toKebabCase(track.id)}-${stage.id}`;
717
707
  const filename = `${fullName}.agent.md`;
718
708
 
719
- // Build description
720
- const disciplineDesc = discipline.description.trim().split("\n")[0];
721
- const stageDesc = stage.description.split(" - ")[0]; // Just the short part
722
- const description = `${stageDesc} agent for ${discipline.specialization || discipline.name} on ${track.name} track. ${disciplineDesc}`;
709
+ // Build description using shared helper
710
+ const description = buildAgentDescription(discipline, track, stage);
723
711
 
724
712
  // Format checklist as markdown
725
713
  const checklistMarkdown = formatChecklistMarkdown(agent.checklist);
@@ -736,6 +724,7 @@ export function generateStageAgentProfile({
736
724
  agentBehaviours,
737
725
  skills,
738
726
  checklistMarkdown,
727
+ agentIndex,
739
728
  });
740
729
 
741
730
  // Build frontmatter
@@ -752,3 +741,71 @@ export function generateStageAgentProfile({
752
741
  filename,
753
742
  };
754
743
  }
744
+
745
+ /**
746
+ * Build an agent description from discipline, track, and stage
747
+ * Uses stage.summary for third-person metadata description
748
+ * @param {Object} discipline - Human discipline definition
749
+ * @param {Object} track - Human track definition
750
+ * @param {Object} stage - Stage definition with summary field
751
+ * @returns {string} Agent description
752
+ */
753
+ function buildAgentDescription(discipline, track, stage) {
754
+ const disciplineDesc = discipline.description.trim().split("\n")[0];
755
+ const stageSummary = stage.summary || stage.name;
756
+ return `${stageSummary} agent for ${discipline.specialization || discipline.name} on ${track.name} track. ${disciplineDesc}`;
757
+ }
758
+
759
+ /**
760
+ * Build a list of all available agents in the system
761
+ * Enumerates all valid discipline × track × stage combinations
762
+ * Returns id, name, and description for each agent
763
+ * @param {Object} params - Parameters
764
+ * @param {Array} params.disciplines - Human discipline definitions
765
+ * @param {Array} params.tracks - Human track definitions
766
+ * @param {Array} params.stages - Stage definitions
767
+ * @param {Array} params.agentDisciplines - Agent discipline definitions (to filter valid combinations)
768
+ * @param {Array} params.agentTracks - Agent track definitions (to filter valid combinations)
769
+ * @returns {Array<{id: string, name: string, description: string}>} List of all agents
770
+ */
771
+ export function buildAgentIndex({
772
+ disciplines,
773
+ tracks,
774
+ stages,
775
+ agentDisciplines,
776
+ agentTracks,
777
+ }) {
778
+ const agents = [];
779
+
780
+ // Build lookup sets for valid agent combinations
781
+ const agentDisciplineIds = new Set(agentDisciplines.map((d) => d.id));
782
+ const agentTrackIds = new Set(agentTracks.map((t) => t.id));
783
+
784
+ for (const discipline of disciplines) {
785
+ // Skip disciplines without agent definitions
786
+ if (!agentDisciplineIds.has(discipline.id)) continue;
787
+
788
+ for (const track of tracks) {
789
+ // Skip tracks without agent definitions
790
+ if (!agentTrackIds.has(track.id)) continue;
791
+
792
+ // Build base name (matches filename pattern)
793
+ const abbrev = getDisciplineAbbreviation(discipline.id);
794
+ const baseName = `${abbrev}-${toKebabCase(track.id)}`;
795
+
796
+ for (const stage of stages) {
797
+ const id = `${baseName}-${stage.id}`;
798
+ const fullName = `${discipline.specialization || discipline.name} - ${track.name} - ${stage.name.charAt(0).toUpperCase() + stage.name.slice(1)} Agent`;
799
+ const description = buildAgentDescription(discipline, track, stage);
800
+
801
+ agents.push({
802
+ id,
803
+ name: fullName,
804
+ description,
805
+ });
806
+ }
807
+ }
808
+ }
809
+
810
+ return agents;
811
+ }
package/lib/index.js CHANGED
@@ -102,11 +102,15 @@ export {
102
102
  deriveHandoffs,
103
103
  deriveStageAgent,
104
104
  generateStageAgentProfile,
105
+ buildAgentIndex,
105
106
  } from "./agent.js";
106
107
 
107
108
  // Checklists
108
109
  export { deriveChecklist, formatChecklistMarkdown } from "./checklist.js";
109
110
 
111
+ // Toolkit
112
+ export { deriveToolkit } from "./toolkit.js";
113
+
110
114
  // Profile filtering (for agents)
111
115
  export {
112
116
  getPositiveTrackCapabilities,
package/lib/job.js CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  getDisciplineSkillIds,
13
13
  } from "./derivation.js";
14
14
  import { deriveChecklist } from "./checklist.js";
15
+ import { deriveToolkit } from "./toolkit.js";
15
16
  import { getOrCreateJob } from "./job-cache.js";
16
17
 
17
18
  /**
@@ -28,6 +29,7 @@ import { getOrCreateJob } from "./job-cache.js";
28
29
  * @property {Array} behaviourProfile
29
30
  * @property {Array} derivedResponsibilities
30
31
  * @property {Array} driverCoverage
32
+ * @property {Array} toolkit - De-duplicated tools from skills
31
33
  * @property {Object} checklists - Handoff checklists keyed by handoff type
32
34
  */
33
35
 
@@ -85,6 +87,12 @@ export function prepareJobDetail({
85
87
  }
86
88
  }
87
89
 
90
+ // Derive toolkit from skill matrix
91
+ const toolkit = deriveToolkit({
92
+ skillMatrix: job.skillMatrix,
93
+ skills,
94
+ });
95
+
88
96
  return {
89
97
  title: job.title,
90
98
  disciplineId: discipline.id,
@@ -98,6 +106,8 @@ export function prepareJobDetail({
98
106
  skillMatrix: job.skillMatrix,
99
107
  behaviourProfile: job.behaviourProfile,
100
108
  derivedResponsibilities: job.derivedResponsibilities || [],
109
+ // Derived toolkit
110
+ toolkit,
101
111
  // Transformed driver coverage for display
102
112
  driverCoverage: driverCoverage.map((d) => ({
103
113
  id: d.driverId,
package/lib/toolkit.js ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Toolkit Derivation Functions
3
+ *
4
+ * Derives a de-duplicated list of tools from a skill matrix by looking up
5
+ * toolReferences from skill definitions. Only skills at the highest derived
6
+ * level contribute tools, ensuring focused toolkits for both jobs and agents.
7
+ */
8
+
9
+ import { filterByHighestLevel } from "./profile.js";
10
+
11
+ /**
12
+ * @typedef {Object} ToolkitEntry
13
+ * @property {string} name - Tool name
14
+ * @property {string} description - Tool description
15
+ * @property {string} [url] - Tool documentation URL
16
+ * @property {string} [simpleIcon] - Simple Icons slug for the tool icon
17
+ * @property {string[]} skillIds - IDs of skills that reference this tool
18
+ */
19
+
20
+ /**
21
+ * Derive a de-duplicated toolkit from a skill matrix
22
+ *
23
+ * Extracts tools from skills at the highest derived level, de-duplicates by name,
24
+ * and collects which skills reference each tool. This keeps toolkits focused on
25
+ * the engineer's core competencies for both jobs and agents.
26
+ *
27
+ * @param {Object} params
28
+ * @param {Array<{skillId: string, level: string}>} params.skillMatrix - Skill matrix with skill IDs and levels
29
+ * @param {Array} params.skills - All skill definitions with toolReferences
30
+ * @returns {ToolkitEntry[]} De-duplicated toolkit sorted by name
31
+ */
32
+ export function deriveToolkit({ skillMatrix, skills }) {
33
+ // Filter to highest level skills only
34
+ const sourceMatrix = filterByHighestLevel(skillMatrix);
35
+
36
+ // Build skill lookup map for O(1) access
37
+ const skillMap = new Map(skills.map((s) => [s.id, s]));
38
+
39
+ // Tool map for de-duplication: name -> ToolkitEntry
40
+ const toolMap = new Map();
41
+
42
+ for (const entry of sourceMatrix) {
43
+ const skill = skillMap.get(entry.skillId);
44
+ if (!skill?.toolReferences) continue;
45
+
46
+ for (const tool of skill.toolReferences) {
47
+ const existing = toolMap.get(tool.name);
48
+ if (existing) {
49
+ // Add skill ID if not already present
50
+ if (!existing.skillIds.includes(skill.id)) {
51
+ existing.skillIds.push(skill.id);
52
+ }
53
+ // Prefer first occurrence's metadata, but fill in missing values
54
+ if (!existing.url && tool.url) {
55
+ existing.url = tool.url;
56
+ }
57
+ if (!existing.simpleIcon && tool.simpleIcon) {
58
+ existing.simpleIcon = tool.simpleIcon;
59
+ }
60
+ } else {
61
+ toolMap.set(tool.name, {
62
+ name: tool.name,
63
+ description: tool.description,
64
+ url: tool.url,
65
+ simpleIcon: tool.simpleIcon,
66
+ skillIds: [skill.id],
67
+ });
68
+ }
69
+ }
70
+ }
71
+
72
+ // Sort by name and return
73
+ return Array.from(toolMap.values()).sort((a, b) =>
74
+ a.name.localeCompare(b.name),
75
+ );
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forwardimpact/model",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Derivation engine for roles, skills, and AI agent profiles",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -28,7 +28,7 @@
28
28
  "./progression": "./lib/progression.js"
29
29
  },
30
30
  "dependencies": {
31
- "@forwardimpact/schema": "^0.2.0"
31
+ "@forwardimpact/schema": "^0.4.0"
32
32
  },
33
33
  "engines": {
34
34
  "node": ">=18.0.0"