@kognai/orchestrator-core 0.2.2 → 0.2.3
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/dist/lib/sovereign-agent-factory.d.ts +21 -0
- package/dist/lib/sovereign-agent-factory.js +63 -0
- package/dist/lib/v2-decomposition-gate.types.d.ts +80 -0
- package/dist/lib/v2-decomposition-gate.types.js +2 -0
- package/dist/lib/v2-decomposition-gate.types.test.d.ts +0 -0
- package/dist/lib/v2-decomposition-gate.types.test.js +3 -0
- package/package.json +1 -1
|
@@ -136,6 +136,27 @@ export declare function spawnCitizen(req: SpawnRequest, opts?: {
|
|
|
136
136
|
decision: SpawnDecision;
|
|
137
137
|
citizen?: CitizenRecord;
|
|
138
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* TICKET-334e — backfill an initial ACP for every citizen in the registry that
|
|
141
|
+
* has no entry in acp/trust-scores.json yet. These are pre-SAF citizens that were
|
|
142
|
+
* born scoreless (minted via bare mintCitizen before the canonical issuer seeded
|
|
143
|
+
* ACP at birth — see TICKET-334b). The router PASS-THROUGHs unscored agents, so
|
|
144
|
+
* this gives them a real routing profile instead of an implicit bypass.
|
|
145
|
+
*
|
|
146
|
+
* Classification reuses the SAF path (classifyRequest → initialAcp) keyed on the
|
|
147
|
+
* citizen's owner lineage + agent_name, so a backfilled score is identical to the
|
|
148
|
+
* one the same agent would receive if spawned today. Idempotent: writeInitialAcp
|
|
149
|
+
* skips any agent_name that already has a score, so re-running only fills gaps.
|
|
150
|
+
*/
|
|
151
|
+
export declare function backfillAcpForRegistry(): {
|
|
152
|
+
scanned: number;
|
|
153
|
+
seeded: {
|
|
154
|
+
agent_name: string;
|
|
155
|
+
classification: SpawnClass;
|
|
156
|
+
score: number;
|
|
157
|
+
}[];
|
|
158
|
+
skipped: number;
|
|
159
|
+
};
|
|
139
160
|
/**
|
|
140
161
|
* Emergency bypass — Founder only. Overrides all gates including health and
|
|
141
162
|
* constitutional conditional findings. Logs prominently to KSL.
|
|
@@ -24,6 +24,7 @@ exports.issueSpawnDecision = issueSpawnDecision;
|
|
|
24
24
|
exports.sovereignSpawn = sovereignSpawn;
|
|
25
25
|
exports.deriveOwner = deriveOwner;
|
|
26
26
|
exports.spawnCitizen = spawnCitizen;
|
|
27
|
+
exports.backfillAcpForRegistry = backfillAcpForRegistry;
|
|
27
28
|
exports.founderEmergencySpawn = founderEmergencySpawn;
|
|
28
29
|
exports.getSpawnRegistry = getSpawnRegistry;
|
|
29
30
|
exports.batchSpawn = batchSpawn;
|
|
@@ -353,6 +354,68 @@ function spawnCitizen(req, opts = {}) {
|
|
|
353
354
|
writeInitialAcp(citizen.agent_name, decision.initial_acp_score);
|
|
354
355
|
return { decision, citizen };
|
|
355
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* TICKET-334e — derive the constitutional requester DID for an EXISTING citizen
|
|
359
|
+
* from its owner lineage, so classifyRequest() sorts it the same way a fresh
|
|
360
|
+
* spawn from that owner would (external → EXTERNAL sub-floor; everything else by
|
|
361
|
+
* role). Mirrors the DID shapes deriveOwner() reads.
|
|
362
|
+
*/
|
|
363
|
+
function requesterDidForCitizen(c) {
|
|
364
|
+
const id = c.owner_id || c.company || 'kognai';
|
|
365
|
+
switch (c.owner_kind) {
|
|
366
|
+
case 'external': return `did:external:${id}:${c.agent_name}`;
|
|
367
|
+
case 'user': return `did:kognai:citizen:${id}`;
|
|
368
|
+
case 'scs': return `did:kognai:scs:${id}:${c.agent_name}`;
|
|
369
|
+
default: return `did:kognai:${id}`; // company / legacy
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/** Read the agent_name keys already present in acp/trust-scores.json. */
|
|
373
|
+
function readAcpScoreKeys() {
|
|
374
|
+
try {
|
|
375
|
+
const { readFileSync } = require('fs');
|
|
376
|
+
const { join } = require('path');
|
|
377
|
+
const acpPath = join((0, engine_paths_1.resolveEnginePaths)().root, 'acp', 'trust-scores.json');
|
|
378
|
+
const data = JSON.parse(readFileSync(acpPath, 'utf-8'));
|
|
379
|
+
return new Set(Object.keys(data?.scores ?? {}));
|
|
380
|
+
}
|
|
381
|
+
catch {
|
|
382
|
+
return new Set();
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* TICKET-334e — backfill an initial ACP for every citizen in the registry that
|
|
387
|
+
* has no entry in acp/trust-scores.json yet. These are pre-SAF citizens that were
|
|
388
|
+
* born scoreless (minted via bare mintCitizen before the canonical issuer seeded
|
|
389
|
+
* ACP at birth — see TICKET-334b). The router PASS-THROUGHs unscored agents, so
|
|
390
|
+
* this gives them a real routing profile instead of an implicit bypass.
|
|
391
|
+
*
|
|
392
|
+
* Classification reuses the SAF path (classifyRequest → initialAcp) keyed on the
|
|
393
|
+
* citizen's owner lineage + agent_name, so a backfilled score is identical to the
|
|
394
|
+
* one the same agent would receive if spawned today. Idempotent: writeInitialAcp
|
|
395
|
+
* skips any agent_name that already has a score, so re-running only fills gaps.
|
|
396
|
+
*/
|
|
397
|
+
function backfillAcpForRegistry() {
|
|
398
|
+
const reg = (0, citizenship_1.readRegistry)();
|
|
399
|
+
const alreadyScored = readAcpScoreKeys();
|
|
400
|
+
const seeded = [];
|
|
401
|
+
let skipped = 0;
|
|
402
|
+
for (const c of reg.citizens) {
|
|
403
|
+
if (!c.agent_name || alreadyScored.has(c.agent_name)) {
|
|
404
|
+
skipped++;
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
const classification = classifyRequest({
|
|
408
|
+
requester_did: requesterDidForCitizen(c),
|
|
409
|
+
requested_role: c.agent_name,
|
|
410
|
+
requested_capabilities: [],
|
|
411
|
+
purpose: `TICKET-334e ACP backfill for pre-SAF citizen ${c.agent_name}`,
|
|
412
|
+
});
|
|
413
|
+
const score = initialAcp(classification);
|
|
414
|
+
writeInitialAcp(c.agent_name, score);
|
|
415
|
+
seeded.push({ agent_name: c.agent_name, classification, score });
|
|
416
|
+
}
|
|
417
|
+
return { scanned: reg.citizens.length, seeded, skipped };
|
|
418
|
+
}
|
|
356
419
|
/**
|
|
357
420
|
* Emergency bypass — Founder only. Overrides all gates including health and
|
|
358
421
|
* constitutional conditional findings. Logs prominently to KSL.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the task kind for decomposition gate scoring.
|
|
3
|
+
* @category DecompositionGate
|
|
4
|
+
*/
|
|
5
|
+
export type TaskKind = 'MODIFY' | 'CREATE';
|
|
6
|
+
/**
|
|
7
|
+
* Represents an edit point in the task context.
|
|
8
|
+
* @property kind - The type of edit (e.g., 'import', 'function_body')
|
|
9
|
+
* @property location - The file path or symbol where the edit occurs
|
|
10
|
+
* @property description - Optional description of the edit
|
|
11
|
+
* @category DecompositionGate
|
|
12
|
+
*/
|
|
13
|
+
export interface EditPoint {
|
|
14
|
+
kind: 'import' | 'guard' | 'function_body' | 'export';
|
|
15
|
+
location: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Complexity score for a task before decomposition.
|
|
20
|
+
* @property editPointCount - Total number of edit points
|
|
21
|
+
* @property editPoints - Array of edit points
|
|
22
|
+
* @property estimatedLines - Estimated number of lines to modify
|
|
23
|
+
* @property taskKind - The kind of task (MODIFY or CREATE)
|
|
24
|
+
* @category DecompositionGate
|
|
25
|
+
*/
|
|
26
|
+
export interface ComplexityScore {
|
|
27
|
+
editPointCount: number;
|
|
28
|
+
editPoints: EditPoint[];
|
|
29
|
+
estimatedLines: number;
|
|
30
|
+
taskKind: TaskKind;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Decision outcome from the decomposition gate.
|
|
34
|
+
* @property accepted - Whether the task is accepted for decomposition
|
|
35
|
+
* @property reason - Reason for acceptance or rejection
|
|
36
|
+
* @property score - Complexity score of the task
|
|
37
|
+
* @property redecomposeFeedback - Optional feedback for redecomposing the task (if rejected)
|
|
38
|
+
* @category DecompositionGate
|
|
39
|
+
*/
|
|
40
|
+
export interface GateDecision {
|
|
41
|
+
accepted: boolean;
|
|
42
|
+
reason: string;
|
|
43
|
+
score: ComplexityScore;
|
|
44
|
+
redecomposeFeedback?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Mode of the decomposition gate.
|
|
48
|
+
* @property shadow - Logs only (no hard rejection)
|
|
49
|
+
* @property enforce - Hard rejects tasks that exceed complexity limits
|
|
50
|
+
* @category DecompositionGate
|
|
51
|
+
*/
|
|
52
|
+
export type GateMode = 'shadow' | 'enforce';
|
|
53
|
+
/**
|
|
54
|
+
* Configuration for the decomposition gate.
|
|
55
|
+
* @property mode - Operation mode (shadow or enforce)
|
|
56
|
+
* @property maxEditPointsModify - Maximum edit points for modify tasks (default: 1)
|
|
57
|
+
* @property maxLinesCreate - Maximum lines for create tasks (default: 200)
|
|
58
|
+
* @category DecompositionGate
|
|
59
|
+
*/
|
|
60
|
+
export interface GateConfig {
|
|
61
|
+
mode: GateMode;
|
|
62
|
+
maxEditPointsModify: number;
|
|
63
|
+
maxLinesCreate: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Input for the decomposition gate scoring.
|
|
67
|
+
* @property id - Unique identifier for the task
|
|
68
|
+
* @property taskKind - The kind of task (MODIFY or CREATE)
|
|
69
|
+
* @property description - Description of the task
|
|
70
|
+
* @property targetFiles - List of target files for the task
|
|
71
|
+
* @property estimatedLines - Estimated number of lines (optional)
|
|
72
|
+
* @category DecompositionGate
|
|
73
|
+
*/
|
|
74
|
+
export interface TicketInput {
|
|
75
|
+
id: string;
|
|
76
|
+
taskKind: TaskKind;
|
|
77
|
+
description: string;
|
|
78
|
+
targetFiles: string[];
|
|
79
|
+
estimatedLines?: number;
|
|
80
|
+
}
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kognai/orchestrator-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Kognai sovereign orchestrator — core engine (template-agnostic). Shared by all products (Kognai/coding, Voxight/market-intel, Invoica/fin-compliance); each supplies only its template. Replaces per-repo forks of orchestrate-agents-v2 / sprint-runner / lib.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "SkinGem",
|