sinapse-ai 7.7.4 → 7.7.5
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/.codex/delegation-matrix.json +512 -0
- package/.codex/handoff-packet.schema.json +148 -0
- package/.codex/scripts/resolve-codex-delegation.js +205 -0
- package/.codex/tasks/route-sinapse-request.md +7 -5
- package/.sinapse-ai/data/entity-registry.yaml +783 -755
- package/.sinapse-ai/data/registry-update-log.jsonl +3 -0
- package/.sinapse-ai/infrastructure/scripts/validate-codex-delegation.js +292 -0
- package/.sinapse-ai/infrastructure/scripts/validate-codex-sync.js +3 -0
- package/.sinapse-ai/install-manifest.yaml +11 -7
- package/package.json +4 -1
- package/packages/installer/tests/unit/artifact-copy-pipeline/artifact-copy-pipeline.test.js +7 -2
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
const PROJECT_ROOT = path.resolve(__dirname, '..', '..');
|
|
8
|
+
const MATRIX_PATH = path.join('.codex', 'delegation-matrix.json');
|
|
9
|
+
|
|
10
|
+
function loadDelegationMatrix(projectRoot = PROJECT_ROOT) {
|
|
11
|
+
const matrixPath = path.join(projectRoot, MATRIX_PATH);
|
|
12
|
+
const raw = fs.readFileSync(matrixPath, 'utf8');
|
|
13
|
+
return JSON.parse(raw);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function normalizeRouteInput(value) {
|
|
17
|
+
return String(value || '')
|
|
18
|
+
.trim()
|
|
19
|
+
.replace(/^[@*]/, '')
|
|
20
|
+
.toLowerCase();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function normalizeActorInput(value) {
|
|
24
|
+
return String(value || '')
|
|
25
|
+
.trim()
|
|
26
|
+
.replace(/^@/, '')
|
|
27
|
+
.toLowerCase();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function collectRouteAliases(routeId, routeSpec) {
|
|
31
|
+
return [routeId, ...(routeSpec.aliases || [])]
|
|
32
|
+
.map((alias) => normalizeRouteInput(alias))
|
|
33
|
+
.filter(Boolean);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function resolveDelegationRoute(routeInput, projectRoot = PROJECT_ROOT, matrix = loadDelegationMatrix(projectRoot)) {
|
|
37
|
+
const normalized = normalizeRouteInput(routeInput);
|
|
38
|
+
const matches = Object.entries(matrix.routes || {}).filter(([routeId, routeSpec]) =>
|
|
39
|
+
collectRouteAliases(routeId, routeSpec).includes(normalized),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (matches.length > 1) {
|
|
43
|
+
throw new Error(`Ambiguous Codex delegation route "${routeInput}"`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (matches.length === 0) {
|
|
47
|
+
throw new Error(`Unknown Codex delegation route "${routeInput}"`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const [routeId, routeSpec] = matches[0];
|
|
51
|
+
return { routeId, routeSpec };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function resolveRouteRecord(routeInput, projectRoot = PROJECT_ROOT, matrix = loadDelegationMatrix(projectRoot)) {
|
|
55
|
+
if (
|
|
56
|
+
routeInput &&
|
|
57
|
+
typeof routeInput === 'object' &&
|
|
58
|
+
typeof routeInput.routeId === 'string' &&
|
|
59
|
+
routeInput.routeSpec &&
|
|
60
|
+
typeof routeInput.routeSpec === 'object'
|
|
61
|
+
) {
|
|
62
|
+
return routeInput;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return resolveDelegationRoute(routeInput, projectRoot, matrix);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function routeMentionsSource(routeSpec, sourceInput) {
|
|
69
|
+
const normalizedSource = normalizeActorInput(sourceInput);
|
|
70
|
+
if (!normalizedSource) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (normalizeActorInput(routeSpec.owner) === normalizedSource) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (routeSpec.delegationChain || []).some(
|
|
79
|
+
(step) =>
|
|
80
|
+
normalizeActorInput(step.from) === normalizedSource ||
|
|
81
|
+
normalizeActorInput(step.to) === normalizedSource,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function buildHandoffPacket(routeInput, projectRoot = PROJECT_ROOT, matrix = loadDelegationMatrix(projectRoot)) {
|
|
86
|
+
const { routeId, routeSpec } = resolveRouteRecord(routeInput, projectRoot, matrix);
|
|
87
|
+
const nextStep = routeSpec.delegationChain?.[0] || null;
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
routeId,
|
|
91
|
+
mission: routeSpec.mission,
|
|
92
|
+
phase: matrix.phase || 'W5 / Delegation Matrix Parity',
|
|
93
|
+
owner: routeSpec.owner,
|
|
94
|
+
classification: routeSpec.classification,
|
|
95
|
+
summary: routeSpec.summary || '',
|
|
96
|
+
inputs: routeSpec.inputs || [],
|
|
97
|
+
outputs: routeSpec.outputs || [],
|
|
98
|
+
validators: routeSpec.validators || [],
|
|
99
|
+
sharedSurfaceRisk: routeSpec.sharedSurfaceRisk || 'low',
|
|
100
|
+
nextHandoff: {
|
|
101
|
+
to: nextStep?.to || routeSpec.owner,
|
|
102
|
+
artifact: routeSpec.outputs?.[0] || 'handoff-packet',
|
|
103
|
+
},
|
|
104
|
+
delegationChain: routeSpec.delegationChain || [],
|
|
105
|
+
resources: routeSpec.resources || [],
|
|
106
|
+
notes: routeSpec.notes || [],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function resolveCodexDelegation(routeInput, projectRoot = PROJECT_ROOT, options = {}) {
|
|
111
|
+
const matrix = options.matrix || loadDelegationMatrix(projectRoot);
|
|
112
|
+
const { routeId, routeSpec } = resolveDelegationRoute(routeInput, projectRoot, matrix);
|
|
113
|
+
|
|
114
|
+
if (options.source && !routeMentionsSource(routeSpec, options.source)) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
`Codex delegation route "${routeId}" is not available from source "${options.source}"`,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
routeId,
|
|
122
|
+
owner: routeSpec.owner,
|
|
123
|
+
requestType: routeSpec.requestType,
|
|
124
|
+
classification: routeSpec.classification,
|
|
125
|
+
mission: routeSpec.mission,
|
|
126
|
+
summary: routeSpec.summary || '',
|
|
127
|
+
inputs: routeSpec.inputs || [],
|
|
128
|
+
outputs: routeSpec.outputs || [],
|
|
129
|
+
validators: routeSpec.validators || [],
|
|
130
|
+
sharedSurfaceRisk: routeSpec.sharedSurfaceRisk || 'low',
|
|
131
|
+
resources: routeSpec.resources || [],
|
|
132
|
+
delegationChain: routeSpec.delegationChain || [],
|
|
133
|
+
handoffPacket: buildHandoffPacket({ routeId, routeSpec }, projectRoot, matrix),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function parseArgs(argv = process.argv.slice(2)) {
|
|
138
|
+
const flags = new Set(argv.filter((arg) => arg.startsWith('--')));
|
|
139
|
+
const args = argv.filter((arg) => !arg.startsWith('--'));
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
source: args.length > 1 ? args[0] : null,
|
|
143
|
+
route: args.length > 1 ? args[1] : args[0],
|
|
144
|
+
json: flags.has('--json'),
|
|
145
|
+
packet: flags.has('--packet'),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function formatHumanResult(result) {
|
|
150
|
+
const nextHandoff = result.handoffPacket?.nextHandoff?.to || 'n/a';
|
|
151
|
+
const delegationPath = (result.delegationChain || [])
|
|
152
|
+
.map((step) => `${step.from} -> ${step.to}`)
|
|
153
|
+
.join(' | ');
|
|
154
|
+
|
|
155
|
+
return [
|
|
156
|
+
`Route: ${result.routeId}`,
|
|
157
|
+
`Owner: ${result.owner}`,
|
|
158
|
+
`Request Type: ${result.requestType}`,
|
|
159
|
+
`Classification: ${result.classification}`,
|
|
160
|
+
`Next Handoff: ${nextHandoff}`,
|
|
161
|
+
`Delegation Chain: ${delegationPath || 'n/a'}`,
|
|
162
|
+
].join('\n');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function main() {
|
|
166
|
+
const args = parseArgs();
|
|
167
|
+
if (!args.route) {
|
|
168
|
+
console.error(
|
|
169
|
+
'Usage: node .codex/scripts/resolve-codex-delegation.js <route> [--json] [--packet]\n' +
|
|
170
|
+
' or: node .codex/scripts/resolve-codex-delegation.js <source-agent> <route> [--json] [--packet]',
|
|
171
|
+
);
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
const result = resolveCodexDelegation(args.route, PROJECT_ROOT, {
|
|
177
|
+
source: args.source,
|
|
178
|
+
});
|
|
179
|
+
const payload = args.packet ? result.handoffPacket : result;
|
|
180
|
+
|
|
181
|
+
if (args.json || args.packet) {
|
|
182
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
183
|
+
} else {
|
|
184
|
+
console.log(formatHumanResult(result));
|
|
185
|
+
}
|
|
186
|
+
} catch (error) {
|
|
187
|
+
console.error(error.message);
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (require.main === module) {
|
|
193
|
+
main();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
module.exports = {
|
|
197
|
+
MATRIX_PATH,
|
|
198
|
+
loadDelegationMatrix,
|
|
199
|
+
normalizeRouteInput,
|
|
200
|
+
resolveDelegationRoute,
|
|
201
|
+
buildHandoffPacket,
|
|
202
|
+
resolveCodexDelegation,
|
|
203
|
+
parseArgs,
|
|
204
|
+
formatHumanResult,
|
|
205
|
+
};
|
|
@@ -11,19 +11,21 @@ Diagnose a request and choose the smallest correct Codex routing path.
|
|
|
11
11
|
## Steps
|
|
12
12
|
|
|
13
13
|
1. Read `.codex/catalog.json`.
|
|
14
|
-
2.
|
|
14
|
+
2. Read `.codex/delegation-matrix.json`.
|
|
15
|
+
3. Classify the request as one of:
|
|
15
16
|
- simple + single-domain
|
|
16
17
|
- complex + single-domain
|
|
17
18
|
- complex + multi-domain
|
|
18
19
|
- framework/development workflow
|
|
19
|
-
|
|
20
|
+
4. Prefer the smallest correct path:
|
|
20
21
|
- simple + single-domain -> relevant `*-orqx` or validated framework agent
|
|
21
22
|
- complex + single-domain -> relevant `*-orqx`
|
|
22
23
|
- complex + multi-domain -> `sinapse-orqx` orchestration plan
|
|
23
24
|
- framework/development workflow -> `sinapse-pm`, `sinapse-po`, `sinapse-sm`, `sinapse-dev`, or `sinapse-qa`
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
5. When the request matches an approved handoff route, resolve it through `.codex/delegation-matrix.json`.
|
|
26
|
+
6. If the request depends on a starred command, resolve it through `.codex/command-registry.json`.
|
|
27
|
+
7. Only recommend direct specialist routing from `.codex/agents` when the delegation matrix marks it as `exploratory`.
|
|
28
|
+
8. Return the recommended route with rationale, classification, and next action.
|
|
27
29
|
|
|
28
30
|
## Output Contract
|
|
29
31
|
|