sinapse-ai 7.7.5 → 7.7.6
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/.claude/CLAUDE.md +1 -0
- package/.claude/rules/security-data-protection.md +184 -0
- package/.codex/delegation-matrix.json +364 -475
- package/.codex/handoff-packet.schema.json +13 -93
- package/.codex/scripts/resolve-codex-delegation-parity.js +205 -0
- package/.codex/scripts/resolve-codex-delegation.js +92 -121
- package/.codex/tasks/route-sinapse-request.md +2 -2
- package/.sinapse-ai/constitution.md +67 -1
- package/.sinapse-ai/core/doctor/checks/constitution-consistency.js +1 -0
- package/.sinapse-ai/core/health-check/checks/project/constitution-consistency.js +1 -0
- package/.sinapse-ai/data/entity-registry.yaml +757 -764
- package/.sinapse-ai/data/registry-update-log.jsonl +3 -0
- package/.sinapse-ai/infrastructure/scripts/validate-codex-delegation.js +5 -3
- package/.sinapse-ai/install-manifest.yaml +12 -12
- package/.sinapse-ai/product/templates/ide-rules/claude-rules.md +1 -0
- package/docs/codex-delegation-parity.md +115 -0
- package/docs/codex-parity-program.md +7 -0
- package/package.json +1 -1
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
3
|
-
"title": "Codex
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "Codex Handoff Packet",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"additionalProperties": false,
|
|
6
6
|
"required": [
|
|
7
7
|
"mission",
|
|
8
8
|
"phase",
|
|
9
9
|
"owner",
|
|
10
|
-
"classification",
|
|
11
10
|
"inputs",
|
|
12
11
|
"outputs",
|
|
13
12
|
"validators",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"delegationChain"
|
|
13
|
+
"shared-surface-risk",
|
|
14
|
+
"next-handoff"
|
|
17
15
|
],
|
|
18
16
|
"properties": {
|
|
19
|
-
"routeId": {
|
|
20
|
-
"type": "string",
|
|
21
|
-
"minLength": 1
|
|
22
|
-
},
|
|
23
17
|
"mission": {
|
|
24
18
|
"type": "string",
|
|
25
19
|
"minLength": 1
|
|
@@ -32,15 +26,9 @@
|
|
|
32
26
|
"type": "string",
|
|
33
27
|
"minLength": 1
|
|
34
28
|
},
|
|
35
|
-
"classification": {
|
|
36
|
-
"type": "string",
|
|
37
|
-
"enum": ["validator-backed", "codex-only-shim", "exploratory"]
|
|
38
|
-
},
|
|
39
|
-
"summary": {
|
|
40
|
-
"type": "string"
|
|
41
|
-
},
|
|
42
29
|
"inputs": {
|
|
43
30
|
"type": "array",
|
|
31
|
+
"minItems": 1,
|
|
44
32
|
"items": {
|
|
45
33
|
"type": "string",
|
|
46
34
|
"minLength": 1
|
|
@@ -48,6 +36,7 @@
|
|
|
48
36
|
},
|
|
49
37
|
"outputs": {
|
|
50
38
|
"type": "array",
|
|
39
|
+
"minItems": 1,
|
|
51
40
|
"items": {
|
|
52
41
|
"type": "string",
|
|
53
42
|
"minLength": 1
|
|
@@ -55,93 +44,24 @@
|
|
|
55
44
|
},
|
|
56
45
|
"validators": {
|
|
57
46
|
"type": "array",
|
|
47
|
+
"minItems": 1,
|
|
58
48
|
"items": {
|
|
59
49
|
"type": "string",
|
|
60
50
|
"minLength": 1
|
|
61
51
|
}
|
|
62
52
|
},
|
|
63
|
-
"
|
|
53
|
+
"shared-surface-risk": {
|
|
64
54
|
"type": "string",
|
|
65
|
-
"enum": ["
|
|
66
|
-
},
|
|
67
|
-
"nextHandoff": {
|
|
68
|
-
"type": "object",
|
|
69
|
-
"additionalProperties": false,
|
|
70
|
-
"required": ["to", "artifact"],
|
|
71
|
-
"properties": {
|
|
72
|
-
"to": {
|
|
73
|
-
"type": "string",
|
|
74
|
-
"minLength": 1
|
|
75
|
-
},
|
|
76
|
-
"artifact": {
|
|
77
|
-
"type": "string",
|
|
78
|
-
"minLength": 1
|
|
79
|
-
}
|
|
80
|
-
}
|
|
55
|
+
"enum": ["none", "codex-only", "shared-review-required"]
|
|
81
56
|
},
|
|
82
|
-
"
|
|
83
|
-
"type": "
|
|
84
|
-
"
|
|
85
|
-
"items": {
|
|
86
|
-
"type": "object",
|
|
87
|
-
"additionalProperties": false,
|
|
88
|
-
"required": ["from", "fromType", "to", "toType", "handoff", "reason"],
|
|
89
|
-
"properties": {
|
|
90
|
-
"from": {
|
|
91
|
-
"type": "string",
|
|
92
|
-
"minLength": 1
|
|
93
|
-
},
|
|
94
|
-
"fromType": {
|
|
95
|
-
"type": "string",
|
|
96
|
-
"enum": ["orqx", "framework-agent", "specialist"]
|
|
97
|
-
},
|
|
98
|
-
"to": {
|
|
99
|
-
"type": "string",
|
|
100
|
-
"minLength": 1
|
|
101
|
-
},
|
|
102
|
-
"toType": {
|
|
103
|
-
"type": "string",
|
|
104
|
-
"enum": ["orqx", "framework-agent", "specialist"]
|
|
105
|
-
},
|
|
106
|
-
"path": {
|
|
107
|
-
"type": "string",
|
|
108
|
-
"minLength": 1
|
|
109
|
-
},
|
|
110
|
-
"task": {
|
|
111
|
-
"type": "string",
|
|
112
|
-
"minLength": 1
|
|
113
|
-
},
|
|
114
|
-
"resolver": {
|
|
115
|
-
"type": "string",
|
|
116
|
-
"minLength": 1
|
|
117
|
-
},
|
|
118
|
-
"command": {
|
|
119
|
-
"type": "string",
|
|
120
|
-
"minLength": 1
|
|
121
|
-
},
|
|
122
|
-
"handoff": {
|
|
123
|
-
"type": "string",
|
|
124
|
-
"minLength": 1
|
|
125
|
-
},
|
|
126
|
-
"reason": {
|
|
127
|
-
"type": "string",
|
|
128
|
-
"minLength": 1
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
"resources": {
|
|
134
|
-
"type": "array",
|
|
135
|
-
"items": {
|
|
136
|
-
"type": "string",
|
|
137
|
-
"minLength": 1
|
|
138
|
-
}
|
|
57
|
+
"next-handoff": {
|
|
58
|
+
"type": "string",
|
|
59
|
+
"minLength": 1
|
|
139
60
|
},
|
|
140
61
|
"notes": {
|
|
141
62
|
"type": "array",
|
|
142
63
|
"items": {
|
|
143
|
-
"type": "string"
|
|
144
|
-
"minLength": 1
|
|
64
|
+
"type": "string"
|
|
145
65
|
}
|
|
146
66
|
}
|
|
147
67
|
}
|
|
@@ -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-parity.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-parity.js <route> [--json] [--packet]\n' +
|
|
170
|
+
' or: node .codex/scripts/resolve-codex-delegation-parity.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
|
+
};
|
|
@@ -5,181 +5,151 @@ const fs = require('fs');
|
|
|
5
5
|
const path = require('path');
|
|
6
6
|
|
|
7
7
|
const PROJECT_ROOT = path.resolve(__dirname, '..', '..');
|
|
8
|
-
const MATRIX_PATH = path.join('.codex', 'delegation-matrix.json');
|
|
9
8
|
|
|
10
9
|
function loadDelegationMatrix(projectRoot = PROJECT_ROOT) {
|
|
11
|
-
const matrixPath = path.join(projectRoot,
|
|
10
|
+
const matrixPath = path.join(projectRoot, '.codex', 'delegation-matrix.json');
|
|
12
11
|
const raw = fs.readFileSync(matrixPath, 'utf8');
|
|
13
12
|
return JSON.parse(raw);
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
function
|
|
17
|
-
return String(value || '')
|
|
18
|
-
.trim()
|
|
19
|
-
.replace(/^[@*]/, '')
|
|
20
|
-
.toLowerCase();
|
|
15
|
+
function normalizeAgentInput(value) {
|
|
16
|
+
return String(value || '').trim().replace(/^@/, '').toLowerCase();
|
|
21
17
|
}
|
|
22
18
|
|
|
23
|
-
function
|
|
24
|
-
return String(value || '')
|
|
25
|
-
.trim()
|
|
26
|
-
.replace(/^@/, '')
|
|
27
|
-
.toLowerCase();
|
|
19
|
+
function normalizeRouteInput(value) {
|
|
20
|
+
return String(value || '').trim().replace(/^\*/, '').toLowerCase();
|
|
28
21
|
}
|
|
29
22
|
|
|
30
|
-
function
|
|
23
|
+
function collectAliases(routeId, routeSpec) {
|
|
31
24
|
return [routeId, ...(routeSpec.aliases || [])]
|
|
32
25
|
.map((alias) => normalizeRouteInput(alias))
|
|
33
26
|
.filter(Boolean);
|
|
34
27
|
}
|
|
35
28
|
|
|
36
|
-
function
|
|
37
|
-
const normalized =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
function getSourceAgentConfig(matrix, agentInput) {
|
|
30
|
+
const normalized = normalizeAgentInput(agentInput);
|
|
31
|
+
|
|
32
|
+
if (['sinapse-orqx', 'imperator'].includes(normalized)) {
|
|
33
|
+
return {
|
|
34
|
+
sourceAgent: 'sinapse-orqx',
|
|
35
|
+
routes: {
|
|
36
|
+
...(matrix.masterRoutes || {}),
|
|
37
|
+
...(matrix.orqxRoutes || {}),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const matches = Object.entries(matrix.specialistRoutes || {})
|
|
43
|
+
.filter(([sourceAgentId, sourceSpec]) => {
|
|
44
|
+
const aliases = [sourceAgentId, ...(sourceSpec.aliases || [])]
|
|
45
|
+
.map((alias) => normalizeAgentInput(alias))
|
|
46
|
+
.filter(Boolean);
|
|
47
|
+
return aliases.includes(normalized);
|
|
48
|
+
});
|
|
41
49
|
|
|
42
50
|
if (matches.length > 1) {
|
|
43
|
-
throw new Error(`Ambiguous Codex delegation
|
|
51
|
+
throw new Error(`Ambiguous Codex delegation source "${agentInput}"`);
|
|
44
52
|
}
|
|
45
53
|
|
|
46
|
-
if (matches.length ===
|
|
47
|
-
|
|
54
|
+
if (matches.length === 1) {
|
|
55
|
+
return {
|
|
56
|
+
sourceAgent: matches[0][0],
|
|
57
|
+
routes: matches[0][1].routes || {},
|
|
58
|
+
};
|
|
48
59
|
}
|
|
49
60
|
|
|
50
|
-
|
|
51
|
-
return { routeId, routeSpec };
|
|
61
|
+
return null;
|
|
52
62
|
}
|
|
53
63
|
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
}
|
|
64
|
+
function resolveRoute(routes, routeInput) {
|
|
65
|
+
const normalized = normalizeRouteInput(routeInput);
|
|
66
|
+
const matches = Object.entries(routes || {})
|
|
67
|
+
.filter(([routeId, routeSpec]) => collectAliases(routeId, routeSpec).includes(normalized));
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (!normalizedSource) {
|
|
71
|
-
return true;
|
|
69
|
+
if (matches.length > 1) {
|
|
70
|
+
throw new Error(`Ambiguous Codex delegation route "${routeInput}"`);
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
if (
|
|
75
|
-
return
|
|
73
|
+
if (matches.length === 0) {
|
|
74
|
+
return null;
|
|
76
75
|
}
|
|
77
76
|
|
|
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
77
|
return {
|
|
90
|
-
routeId,
|
|
91
|
-
|
|
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 || [],
|
|
78
|
+
routeId: matches[0][0],
|
|
79
|
+
routeSpec: matches[0][1],
|
|
107
80
|
};
|
|
108
81
|
}
|
|
109
82
|
|
|
110
|
-
function resolveCodexDelegation(routeInput, projectRoot = PROJECT_ROOT
|
|
111
|
-
const matrix =
|
|
112
|
-
const
|
|
83
|
+
function resolveCodexDelegation(agentInput, routeInput, projectRoot = PROJECT_ROOT) {
|
|
84
|
+
const matrix = loadDelegationMatrix(projectRoot);
|
|
85
|
+
const source = getSourceAgentConfig(matrix, agentInput);
|
|
86
|
+
if (!source) {
|
|
87
|
+
throw new Error(`Unknown Codex delegation source "${agentInput}"`);
|
|
88
|
+
}
|
|
113
89
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
);
|
|
90
|
+
const route = resolveRoute(source.routes, routeInput);
|
|
91
|
+
if (!route) {
|
|
92
|
+
throw new Error(`Unknown Codex delegation route "${routeInput}" for source "${source.sourceAgent}"`);
|
|
118
93
|
}
|
|
119
94
|
|
|
120
95
|
return {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
validators: routeSpec.validators || [],
|
|
130
|
-
sharedSurfaceRisk: routeSpec.sharedSurfaceRisk || 'low',
|
|
131
|
-
resources: routeSpec.resources || [],
|
|
132
|
-
delegationChain: routeSpec.delegationChain || [],
|
|
133
|
-
handoffPacket: buildHandoffPacket({ routeId, routeSpec }, projectRoot, matrix),
|
|
96
|
+
sourceAgent: source.sourceAgent,
|
|
97
|
+
routeId: route.routeId,
|
|
98
|
+
classification: route.routeSpec.classification,
|
|
99
|
+
target: route.routeSpec.target,
|
|
100
|
+
handoff: route.routeSpec.handoff || null,
|
|
101
|
+
sourceDocs: route.routeSpec.sourceDocs || [],
|
|
102
|
+
handoffSchemaPath: matrix.handoffSchemaPath,
|
|
103
|
+
handoffTemplatePath: matrix.handoffTemplatePath,
|
|
134
104
|
};
|
|
135
105
|
}
|
|
136
106
|
|
|
137
107
|
function parseArgs(argv = process.argv.slice(2)) {
|
|
138
|
-
const flags = new Set(argv.filter((arg) => arg.startsWith('--')));
|
|
139
108
|
const args = argv.filter((arg) => !arg.startsWith('--'));
|
|
140
|
-
|
|
109
|
+
const flags = new Set(argv.filter((arg) => arg.startsWith('--')));
|
|
141
110
|
return {
|
|
142
|
-
|
|
143
|
-
route: args
|
|
111
|
+
agent: args[0],
|
|
112
|
+
route: args[1],
|
|
144
113
|
json: flags.has('--json'),
|
|
145
|
-
packet: flags.has('--packet'),
|
|
146
114
|
};
|
|
147
115
|
}
|
|
148
116
|
|
|
149
117
|
function formatHumanResult(result) {
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
.map((step) => `${step.from} -> ${step.to}`)
|
|
153
|
-
.join(' | ');
|
|
154
|
-
|
|
155
|
-
return [
|
|
118
|
+
const lines = [
|
|
119
|
+
`Source: ${result.sourceAgent}`,
|
|
156
120
|
`Route: ${result.routeId}`,
|
|
157
|
-
`Owner: ${result.owner}`,
|
|
158
|
-
`Request Type: ${result.requestType}`,
|
|
159
121
|
`Classification: ${result.classification}`,
|
|
160
|
-
`
|
|
161
|
-
`
|
|
162
|
-
]
|
|
122
|
+
`Target Type: ${result.target.type}`,
|
|
123
|
+
`Target Agent: ${result.target.agentId}`,
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
if (result.target.commandId) {
|
|
127
|
+
lines.push(`Target Command: ${result.target.commandId}`);
|
|
128
|
+
}
|
|
129
|
+
if (result.target.docPath) {
|
|
130
|
+
lines.push(`Target Doc: ${result.target.docPath}`);
|
|
131
|
+
}
|
|
132
|
+
if (result.target.taskPath) {
|
|
133
|
+
lines.push(`Target Task: ${result.target.taskPath}`);
|
|
134
|
+
}
|
|
135
|
+
if (result.handoff) {
|
|
136
|
+
lines.push(`Next Handoff: ${result.handoff.nextHandoff}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return lines.join('\n');
|
|
163
140
|
}
|
|
164
141
|
|
|
165
142
|
function main() {
|
|
166
143
|
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
|
-
);
|
|
144
|
+
if (!args.agent || !args.route) {
|
|
145
|
+
console.error('Usage: node .codex/scripts/resolve-codex-delegation.js <source-agent> <route> [--json]');
|
|
172
146
|
process.exit(1);
|
|
173
147
|
}
|
|
174
148
|
|
|
175
149
|
try {
|
|
176
|
-
const result = resolveCodexDelegation(args.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const payload = args.packet ? result.handoffPacket : result;
|
|
180
|
-
|
|
181
|
-
if (args.json || args.packet) {
|
|
182
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
150
|
+
const result = resolveCodexDelegation(args.agent, args.route);
|
|
151
|
+
if (args.json) {
|
|
152
|
+
console.log(JSON.stringify(result, null, 2));
|
|
183
153
|
} else {
|
|
184
154
|
console.log(formatHumanResult(result));
|
|
185
155
|
}
|
|
@@ -194,11 +164,12 @@ if (require.main === module) {
|
|
|
194
164
|
}
|
|
195
165
|
|
|
196
166
|
module.exports = {
|
|
197
|
-
MATRIX_PATH,
|
|
198
167
|
loadDelegationMatrix,
|
|
168
|
+
normalizeAgentInput,
|
|
199
169
|
normalizeRouteInput,
|
|
200
|
-
|
|
201
|
-
|
|
170
|
+
collectAliases,
|
|
171
|
+
getSourceAgentConfig,
|
|
172
|
+
resolveRoute,
|
|
202
173
|
resolveCodexDelegation,
|
|
203
174
|
parseArgs,
|
|
204
175
|
formatHumanResult,
|
|
@@ -11,7 +11,7 @@ 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. Read `.codex/delegation-
|
|
14
|
+
2. Read `.codex/delegation-parity.json`.
|
|
15
15
|
3. Classify the request as one of:
|
|
16
16
|
- simple + single-domain
|
|
17
17
|
- complex + single-domain
|
|
@@ -22,7 +22,7 @@ Diagnose a request and choose the smallest correct Codex routing path.
|
|
|
22
22
|
- complex + single-domain -> relevant `*-orqx`
|
|
23
23
|
- complex + multi-domain -> `sinapse-orqx` orchestration plan
|
|
24
24
|
- framework/development workflow -> `sinapse-pm`, `sinapse-po`, `sinapse-sm`, `sinapse-dev`, or `sinapse-qa`
|
|
25
|
-
5. When the request matches an approved handoff route, resolve it through `.codex/delegation-
|
|
25
|
+
5. When the request matches an approved handoff route, resolve it through `.codex/delegation-parity.json`.
|
|
26
26
|
6. If the request depends on a starred command, resolve it through `.codex/command-registry.json`.
|
|
27
27
|
7. Only recommend direct specialist routing from `.codex/agents` when the delegation matrix marks it as `exploratory`.
|
|
28
28
|
8. Return the recommended route with rationale, classification, and next action.
|