@forwardimpact/model 0.2.0 → 0.3.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 +108 -49
- package/lib/index.js +4 -0
- package/lib/job.js +10 -0
- package/lib/toolkit.js +69 -0
- package/package.json +2 -2
package/lib/agent.js
CHANGED
|
@@ -177,21 +177,25 @@ function findAgentBehaviour(agentBehaviours, id) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
/**
|
|
180
|
-
*
|
|
181
|
-
*
|
|
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 {
|
|
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
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
|
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
|
-
"
|
|
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
|
-
//
|
|
554
|
-
const
|
|
533
|
+
// Role Context - use track's roleContext (shared with human job descriptions)
|
|
534
|
+
const roleContext = humanTrack.roleContext.trim();
|
|
555
535
|
|
|
556
|
-
// Working
|
|
557
|
-
const
|
|
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
|
-
|
|
577
|
-
|
|
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({
|
|
@@ -736,6 +726,7 @@ export function generateStageAgentProfile({
|
|
|
736
726
|
agentBehaviours,
|
|
737
727
|
skills,
|
|
738
728
|
checklistMarkdown,
|
|
729
|
+
agentIndex,
|
|
739
730
|
});
|
|
740
731
|
|
|
741
732
|
// Build frontmatter
|
|
@@ -752,3 +743,71 @@ export function generateStageAgentProfile({
|
|
|
752
743
|
filename,
|
|
753
744
|
};
|
|
754
745
|
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Build an agent description from discipline, track, and stage
|
|
749
|
+
* Uses the same format as generateStageAgentProfile for consistency
|
|
750
|
+
* @param {Object} discipline - Human discipline definition
|
|
751
|
+
* @param {Object} track - Human track definition
|
|
752
|
+
* @param {Object} stage - Stage definition
|
|
753
|
+
* @returns {string} Agent description
|
|
754
|
+
*/
|
|
755
|
+
function buildAgentDescription(discipline, track, stage) {
|
|
756
|
+
const disciplineDesc = discipline.description.trim().split("\n")[0];
|
|
757
|
+
const stageDesc = stage.description.split(" - ")[0];
|
|
758
|
+
return `${stageDesc} agent for ${discipline.specialization || discipline.name} on ${track.name} track. ${disciplineDesc}`;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Build a list of all available agents in the system
|
|
763
|
+
* Enumerates all valid discipline × track × stage combinations
|
|
764
|
+
* Returns id, name, and description for each agent
|
|
765
|
+
* @param {Object} params - Parameters
|
|
766
|
+
* @param {Array} params.disciplines - Human discipline definitions
|
|
767
|
+
* @param {Array} params.tracks - Human track definitions
|
|
768
|
+
* @param {Array} params.stages - Stage definitions
|
|
769
|
+
* @param {Array} params.agentDisciplines - Agent discipline definitions (to filter valid combinations)
|
|
770
|
+
* @param {Array} params.agentTracks - Agent track definitions (to filter valid combinations)
|
|
771
|
+
* @returns {Array<{id: string, name: string, description: string}>} List of all agents
|
|
772
|
+
*/
|
|
773
|
+
export function buildAgentIndex({
|
|
774
|
+
disciplines,
|
|
775
|
+
tracks,
|
|
776
|
+
stages,
|
|
777
|
+
agentDisciplines,
|
|
778
|
+
agentTracks,
|
|
779
|
+
}) {
|
|
780
|
+
const agents = [];
|
|
781
|
+
|
|
782
|
+
// Build lookup sets for valid agent combinations
|
|
783
|
+
const agentDisciplineIds = new Set(agentDisciplines.map((d) => d.id));
|
|
784
|
+
const agentTrackIds = new Set(agentTracks.map((t) => t.id));
|
|
785
|
+
|
|
786
|
+
for (const discipline of disciplines) {
|
|
787
|
+
// Skip disciplines without agent definitions
|
|
788
|
+
if (!agentDisciplineIds.has(discipline.id)) continue;
|
|
789
|
+
|
|
790
|
+
for (const track of tracks) {
|
|
791
|
+
// Skip tracks without agent definitions
|
|
792
|
+
if (!agentTrackIds.has(track.id)) continue;
|
|
793
|
+
|
|
794
|
+
// Build base name (matches filename pattern)
|
|
795
|
+
const abbrev = getDisciplineAbbreviation(discipline.id);
|
|
796
|
+
const baseName = `${abbrev}-${toKebabCase(track.id)}`;
|
|
797
|
+
|
|
798
|
+
for (const stage of stages) {
|
|
799
|
+
const id = `${baseName}-${stage.id}`;
|
|
800
|
+
const fullName = `${discipline.specialization || discipline.name} - ${track.name} - ${stage.name.charAt(0).toUpperCase() + stage.name.slice(1)} Agent`;
|
|
801
|
+
const description = buildAgentDescription(discipline, track, stage);
|
|
802
|
+
|
|
803
|
+
agents.push({
|
|
804
|
+
id,
|
|
805
|
+
name: fullName,
|
|
806
|
+
description,
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
return agents;
|
|
813
|
+
}
|
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,69 @@
|
|
|
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.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {Object} ToolkitEntry
|
|
10
|
+
* @property {string} name - Tool name
|
|
11
|
+
* @property {string} description - Tool description
|
|
12
|
+
* @property {string} [url] - Tool documentation URL
|
|
13
|
+
* @property {string} [simpleIcon] - Simple Icons slug for the tool icon
|
|
14
|
+
* @property {string[]} skillIds - IDs of skills that reference this tool
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Derive a de-duplicated toolkit from a skill matrix
|
|
19
|
+
*
|
|
20
|
+
* Extracts all tools referenced by skills in the matrix, de-duplicates by name,
|
|
21
|
+
* and collects which skills reference each tool.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} params
|
|
24
|
+
* @param {Array<{skillId: string}>} params.skillMatrix - Skill matrix with skill IDs
|
|
25
|
+
* @param {Array} params.skills - All skill definitions with toolReferences
|
|
26
|
+
* @returns {ToolkitEntry[]} De-duplicated toolkit sorted by name
|
|
27
|
+
*/
|
|
28
|
+
export function deriveToolkit({ skillMatrix, skills }) {
|
|
29
|
+
// Build skill lookup map for O(1) access
|
|
30
|
+
const skillMap = new Map(skills.map((s) => [s.id, s]));
|
|
31
|
+
|
|
32
|
+
// Tool map for de-duplication: name -> ToolkitEntry
|
|
33
|
+
const toolMap = new Map();
|
|
34
|
+
|
|
35
|
+
for (const entry of skillMatrix) {
|
|
36
|
+
const skill = skillMap.get(entry.skillId);
|
|
37
|
+
if (!skill?.toolReferences) continue;
|
|
38
|
+
|
|
39
|
+
for (const tool of skill.toolReferences) {
|
|
40
|
+
const existing = toolMap.get(tool.name);
|
|
41
|
+
if (existing) {
|
|
42
|
+
// Add skill ID if not already present
|
|
43
|
+
if (!existing.skillIds.includes(skill.id)) {
|
|
44
|
+
existing.skillIds.push(skill.id);
|
|
45
|
+
}
|
|
46
|
+
// Prefer first occurrence's metadata, but fill in missing values
|
|
47
|
+
if (!existing.url && tool.url) {
|
|
48
|
+
existing.url = tool.url;
|
|
49
|
+
}
|
|
50
|
+
if (!existing.simpleIcon && tool.simpleIcon) {
|
|
51
|
+
existing.simpleIcon = tool.simpleIcon;
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
toolMap.set(tool.name, {
|
|
55
|
+
name: tool.name,
|
|
56
|
+
description: tool.description,
|
|
57
|
+
url: tool.url,
|
|
58
|
+
simpleIcon: tool.simpleIcon,
|
|
59
|
+
skillIds: [skill.id],
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Sort by name and return
|
|
66
|
+
return Array.from(toolMap.values()).sort((a, b) =>
|
|
67
|
+
a.name.localeCompare(b.name),
|
|
68
|
+
);
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forwardimpact/model",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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.
|
|
31
|
+
"@forwardimpact/schema": "^0.3.0"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=18.0.0"
|