@guyghost/swarm-dao-core 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/dist/commands/index.d.ts +2 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +2 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/registry.d.ts +46 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +352 -0
- package/dist/commands/registry.js.map +1 -0
- package/dist/control/gates.d.ts.map +1 -1
- package/dist/control/gates.js +17 -0
- package/dist/control/gates.js.map +1 -1
- package/dist/delivery/dependencies.d.ts.map +1 -1
- package/dist/delivery/dependencies.js +15 -7
- package/dist/delivery/dependencies.js.map +1 -1
- package/dist/delivery/execution.d.ts.map +1 -1
- package/dist/delivery/execution.js +7 -5
- package/dist/delivery/execution.js.map +1 -1
- package/dist/governance/agents.d.ts +2 -0
- package/dist/governance/agents.d.ts.map +1 -1
- package/dist/governance/agents.js +49 -12
- package/dist/governance/agents.js.map +1 -1
- package/dist/governance/delegation.machine.d.ts +316 -0
- package/dist/governance/delegation.machine.d.ts.map +1 -0
- package/dist/governance/delegation.machine.js +387 -0
- package/dist/governance/delegation.machine.js.map +1 -0
- package/dist/governance/delegation.utils.d.ts +55 -0
- package/dist/governance/delegation.utils.d.ts.map +1 -0
- package/dist/governance/delegation.utils.js +157 -0
- package/dist/governance/delegation.utils.js.map +1 -0
- package/dist/governance/index.d.ts +2 -0
- package/dist/governance/index.d.ts.map +1 -1
- package/dist/governance/index.js +2 -0
- package/dist/governance/index.js.map +1 -1
- package/dist/governance/lifecycle.d.ts +0 -6
- package/dist/governance/lifecycle.d.ts.map +1 -1
- package/dist/governance/lifecycle.js +7 -31
- package/dist/governance/lifecycle.js.map +1 -1
- package/dist/governance/proposal.machine.d.ts +65 -81
- package/dist/governance/proposal.machine.d.ts.map +1 -1
- package/dist/governance/proposal.machine.js +160 -357
- package/dist/governance/proposal.machine.js.map +1 -1
- package/dist/governance/proposal.utils.d.ts +19 -165
- package/dist/governance/proposal.utils.d.ts.map +1 -1
- package/dist/governance/proposal.utils.js +49 -119
- package/dist/governance/proposal.utils.js.map +1 -1
- package/dist/governance/scoring.d.ts.map +1 -1
- package/dist/governance/scoring.js +36 -16
- package/dist/governance/scoring.js.map +1 -1
- package/dist/host-tools/github-config.d.ts +7 -0
- package/dist/host-tools/github-config.d.ts.map +1 -0
- package/dist/host-tools/github-config.js +33 -0
- package/dist/host-tools/github-config.js.map +1 -0
- package/dist/host-tools/handlers.d.ts +87 -0
- package/dist/host-tools/handlers.d.ts.map +1 -0
- package/dist/host-tools/handlers.js +556 -0
- package/dist/host-tools/handlers.js.map +1 -0
- package/dist/host-tools/index.d.ts +5 -0
- package/dist/host-tools/index.d.ts.map +1 -0
- package/dist/host-tools/index.js +5 -0
- package/dist/host-tools/index.js.map +1 -0
- package/dist/host-tools/messages.d.ts +12 -0
- package/dist/host-tools/messages.d.ts.map +1 -0
- package/dist/host-tools/messages.js +34 -0
- package/dist/host-tools/messages.js.map +1 -0
- package/dist/host-tools/utils.d.ts +3 -0
- package/dist/host-tools/utils.d.ts.map +1 -0
- package/dist/host-tools/utils.js +29 -0
- package/dist/host-tools/utils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/http.d.ts +12 -1
- package/dist/integrations/http.d.ts.map +1 -1
- package/dist/integrations/http.js +114 -17
- package/dist/integrations/http.js.map +1 -1
- package/dist/intelligence/delegation.d.ts +40 -0
- package/dist/intelligence/delegation.d.ts.map +1 -0
- package/dist/intelligence/delegation.js +162 -0
- package/dist/intelligence/delegation.js.map +1 -0
- package/dist/intelligence/index.d.ts +1 -0
- package/dist/intelligence/index.d.ts.map +1 -1
- package/dist/intelligence/index.js +1 -0
- package/dist/intelligence/index.js.map +1 -1
- package/dist/intelligence/model.d.ts +28 -2
- package/dist/intelligence/model.d.ts.map +1 -1
- package/dist/intelligence/model.js +36 -3
- package/dist/intelligence/model.js.map +1 -1
- package/dist/intelligence/swarm.d.ts +13 -2
- package/dist/intelligence/swarm.d.ts.map +1 -1
- package/dist/intelligence/swarm.js +97 -50
- package/dist/intelligence/swarm.js.map +1 -1
- package/dist/persistence.d.ts +2 -6
- package/dist/persistence.d.ts.map +1 -1
- package/dist/persistence.js +109 -123
- package/dist/persistence.js.map +1 -1
- package/dist/types/index.d.ts +70 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { buildDaoCommandHelp } from "../commands/registry.js";
|
|
2
|
+
export const DAO_ONBOARDING_MESSAGE = [
|
|
3
|
+
"# DAO not initialized",
|
|
4
|
+
"",
|
|
5
|
+
"1. Run `dao_setup` to create the default governance agents.",
|
|
6
|
+
"2. Run `dao_help` to see the full workflow and available commands.",
|
|
7
|
+
'3. Start your first proposal with `dao_propose title="..." type="product-feature" description="..."`.',
|
|
8
|
+
].join("\n");
|
|
9
|
+
export function buildDaoHelpMessage(options = {}) {
|
|
10
|
+
const manualDeliberation = options.manualDeliberation ?? true;
|
|
11
|
+
const controlTool = options.controlTool ?? "dao_control";
|
|
12
|
+
const deliberationSteps = manualDeliberation
|
|
13
|
+
? [
|
|
14
|
+
"3. `dao_deliberate proposalId=1`",
|
|
15
|
+
"4. Spawn sub-agents via your host's task/agent tool using the dispatch plan",
|
|
16
|
+
"5. `dao_record_outputs proposalId=1 outputs='[...]'`",
|
|
17
|
+
`6. \`${controlTool} proposalId=1\``,
|
|
18
|
+
"7. `dao_execute proposalId=1`",
|
|
19
|
+
]
|
|
20
|
+
: ["3. `dao_deliberate proposalId=1`", `4. \`${controlTool} proposalId=1\``, "5. `dao_execute proposalId=1`"];
|
|
21
|
+
const flow = [
|
|
22
|
+
"# DAO Help",
|
|
23
|
+
"",
|
|
24
|
+
"Recommended flow:",
|
|
25
|
+
"1. `dao_setup`",
|
|
26
|
+
'2. `dao_propose title="..." type="product-feature" description="..."`',
|
|
27
|
+
...deliberationSteps,
|
|
28
|
+
];
|
|
29
|
+
if (options.hideCatalogue)
|
|
30
|
+
return flow.join("\n");
|
|
31
|
+
const catalogue = buildDaoCommandHelp({ host: options.host, title: "Full command reference" });
|
|
32
|
+
return `${flow.join("\n")}\n\n${catalogue}`;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/host-tools/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAuB,MAAM,yBAAyB,CAAC;AAEnF,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,uBAAuB;IACvB,EAAE;IACF,6DAA6D;IAC7D,oEAAoE;IACpE,uGAAuG;CACxG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAWb,MAAM,UAAU,mBAAmB,CAAC,UAAsC,EAAE;IAC1E,MAAM,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,IAAI,IAAI,CAAC;IAC9D,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,aAAa,CAAC;IAEzD,MAAM,iBAAiB,GAAG,kBAAkB;QAC1C,CAAC,CAAC;YACE,kCAAkC;YAClC,6EAA6E;YAC7E,sDAAsD;YACtD,QAAQ,WAAW,iBAAiB;YACpC,+BAA+B;SAChC;QACH,CAAC,CAAC,CAAC,kCAAkC,EAAE,QAAQ,WAAW,iBAAiB,EAAE,+BAA+B,CAAC,CAAC;IAEhH,MAAM,IAAI,GAAG;QACX,YAAY;QACZ,EAAE;QACF,mBAAmB;QACnB,gBAAgB;QAChB,uEAAuE;QACvE,GAAG,iBAAiB;KACrB,CAAC;IAEF,IAAI,OAAO,CAAC,aAAa;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAElD,MAAM,SAAS,GAAG,mBAAmB,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,wBAAwB,EAAE,CAAC,CAAC;IAC/F,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,SAAS,EAAE,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/host-tools/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAczE;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,CASlE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const FORBIDDEN_JSON_KEYS = new Set(["__proto__", "prototype", "constructor"]);
|
|
2
|
+
export function assertSafeJsonValue(value, context) {
|
|
3
|
+
if (Array.isArray(value)) {
|
|
4
|
+
for (const item of value) {
|
|
5
|
+
assertSafeJsonValue(item, context);
|
|
6
|
+
}
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (typeof value !== "object" || value === null)
|
|
10
|
+
return;
|
|
11
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
12
|
+
if (FORBIDDEN_JSON_KEYS.has(key)) {
|
|
13
|
+
throw new Error(`Unsafe key "${key}" in ${context}`);
|
|
14
|
+
}
|
|
15
|
+
assertSafeJsonValue(nested, context);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function parseSafeJson(input, context) {
|
|
19
|
+
let parsed;
|
|
20
|
+
try {
|
|
21
|
+
parsed = JSON.parse(input);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new Error(`Invalid JSON in ${context}: ${error instanceof Error ? error.message : String(error)}`);
|
|
25
|
+
}
|
|
26
|
+
assertSafeJsonValue(parsed, context);
|
|
27
|
+
return parsed;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/host-tools/utils.ts"],"names":[],"mappings":"AAAA,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC;AAE/E,MAAM,UAAU,mBAAmB,CAAC,KAAc,EAAE,OAAe;IACjE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,mBAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACrC,CAAC;QACD,OAAO;IACT,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO;IACxD,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,IAAI,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,eAAe,GAAG,QAAQ,OAAO,EAAE,CAAC,CAAC;QACvD,CAAC;QACD,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAI,KAAa,EAAE,OAAe;IAC7D,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,mBAAmB,OAAO,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC3G,CAAC;IACD,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,MAAW,CAAC;AACrB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export * from "./agents/index.js";
|
|
2
|
+
export * from "./commands/index.js";
|
|
2
3
|
export * from "./config.js";
|
|
3
4
|
export * from "./control/index.js";
|
|
4
5
|
export * from "./delivery/index.js";
|
|
5
6
|
export * from "./governance/index.js";
|
|
6
7
|
export * from "./health-score.js";
|
|
8
|
+
export * from "./host-tools/index.js";
|
|
7
9
|
export * from "./integrations/index.js";
|
|
8
10
|
export * from "./intelligence/index.js";
|
|
9
11
|
export * from "./intelligence/roundtable.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,mBAAmB,CAAC;AAElC,cAAc,aAAa,CAAC;AAE5B,cAAc,oBAAoB,CAAC;AAEnC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,mBAAmB,CAAC;AAElC,cAAc,yBAAyB,CAAC;AAExC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAE7C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,mBAAmB,CAAC;AAElC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,aAAa,CAAC;AAE5B,cAAc,oBAAoB,CAAC;AAEnC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,mBAAmB,CAAC;AAElC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,yBAAyB,CAAC;AAExC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAE7C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// ============================================================
|
|
4
4
|
// Agents
|
|
5
5
|
export * from "./agents/index.js";
|
|
6
|
+
// Commands registry (`/dao` surface — source of truth for every adapter)
|
|
7
|
+
export * from "./commands/index.js";
|
|
6
8
|
// Configuration
|
|
7
9
|
export * from "./config.js";
|
|
8
10
|
// Control (L4)
|
|
@@ -13,6 +15,8 @@ export * from "./delivery/index.js";
|
|
|
13
15
|
export * from "./governance/index.js";
|
|
14
16
|
// Health Score
|
|
15
17
|
export * from "./health-score.js";
|
|
18
|
+
// Host tool handlers (shared across adapters)
|
|
19
|
+
export * from "./host-tools/index.js";
|
|
16
20
|
// Integrations
|
|
17
21
|
export * from "./integrations/index.js";
|
|
18
22
|
// Intelligence (L2)
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,8BAA8B;AAC9B,+DAA+D;AAE/D,SAAS;AACT,cAAc,mBAAmB,CAAC;AAClC,gBAAgB;AAChB,cAAc,aAAa,CAAC;AAC5B,eAAe;AACf,cAAc,oBAAoB,CAAC;AACnC,gBAAgB;AAChB,cAAc,qBAAqB,CAAC;AACpC,kBAAkB;AAClB,cAAc,uBAAuB,CAAC;AACtC,eAAe;AACf,cAAc,mBAAmB,CAAC;AAClC,eAAe;AACf,cAAc,yBAAyB,CAAC;AACxC,oBAAoB;AACpB,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,gBAAgB;AAChB,cAAc,0BAA0B,CAAC;AACzC,cAAc;AACd,cAAc,kBAAkB,CAAC;AACjC,QAAQ;AACR,cAAc,kBAAkB,CAAC;AACjC,QAAQ;AACR,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,8BAA8B;AAC9B,+DAA+D;AAE/D,SAAS;AACT,cAAc,mBAAmB,CAAC;AAClC,yEAAyE;AACzE,cAAc,qBAAqB,CAAC;AACpC,gBAAgB;AAChB,cAAc,aAAa,CAAC;AAC5B,eAAe;AACf,cAAc,oBAAoB,CAAC;AACnC,gBAAgB;AAChB,cAAc,qBAAqB,CAAC;AACpC,kBAAkB;AAClB,cAAc,uBAAuB,CAAC;AACtC,eAAe;AACf,cAAc,mBAAmB,CAAC;AAClC,8CAA8C;AAC9C,cAAc,uBAAuB,CAAC;AACtC,eAAe;AACf,cAAc,yBAAyB,CAAC;AACxC,oBAAoB;AACpB,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,gBAAgB;AAChB,cAAc,0BAA0B,CAAC;AACzC,cAAc;AACd,cAAc,kBAAkB,CAAC;AACjC,QAAQ;AACR,cAAc,kBAAkB,CAAC;AACjC,QAAQ;AACR,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
|
@@ -4,13 +4,24 @@ interface JsonRequestOptions {
|
|
|
4
4
|
body?: string;
|
|
5
5
|
timeoutMs?: number;
|
|
6
6
|
allowStatuses?: number[];
|
|
7
|
+
maxAttempts?: number;
|
|
8
|
+
_fetch?: FetchImplementation;
|
|
7
9
|
}
|
|
8
10
|
export declare class HttpRequestError extends Error {
|
|
9
11
|
readonly status: number;
|
|
10
12
|
readonly url: string;
|
|
11
13
|
constructor(message: string, status: number, url: string);
|
|
12
14
|
}
|
|
13
|
-
|
|
15
|
+
interface HttpResponseLike {
|
|
16
|
+
ok: boolean;
|
|
17
|
+
status: number;
|
|
18
|
+
text(): Promise<string>;
|
|
19
|
+
headers: {
|
|
20
|
+
get(name: string): string | null;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
type FetchImplementation = (url: string, init?: RequestInit) => Promise<HttpResponseLike>;
|
|
24
|
+
export declare function requestJson<T>(url: string, { timeoutMs, allowStatuses, maxAttempts, _fetch, ...options }?: JsonRequestOptions): Promise<{
|
|
14
25
|
status: number;
|
|
15
26
|
data: T | null;
|
|
16
27
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/integrations/http.ts"],"names":[],"mappings":"AAAA,UAAU,kBAAkB;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/integrations/http.ts"],"names":[],"mappings":"AAAA,UAAU,kBAAkB;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IAKrB,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B;AAED,qBAAa,gBAAiB,SAAQ,KAAK;aAGvB,MAAM,EAAE,MAAM;aACd,GAAG,EAAE,MAAM;gBAF3B,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM;CAK9B;AA4DD,UAAU,gBAAgB;IACxB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,EAAE;QAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CAC/C;AAED,KAAK,mBAAmB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAoE1F,wBAAsB,WAAW,CAAC,CAAC,EACjC,GAAG,EAAE,MAAM,EACX,EAAE,SAAkB,EAAE,aAAkB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAE,kBAAuB,GACnG,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAA;CAAE,CAAC,CA8C7C"}
|
|
@@ -11,11 +11,58 @@ export class HttpRequestError extends Error {
|
|
|
11
11
|
function truncate(text, maxLength) {
|
|
12
12
|
return text.length > maxLength ? `${text.slice(0, maxLength)}...` : text;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
// HTTP keep-alive (connection reuse) is handled automatically by the Bun fetch
|
|
15
|
+
// runtime, which pools and reuses TCP connections by default. There is no
|
|
16
|
+
// standard, dependency-free fetch option to toggle this in Bun (the `dispatcher`
|
|
17
|
+
// option is undici/Node-specific and unavailable here), so we rely on the runtime
|
|
18
|
+
// and focus this change on idempotency-aware retry with backoff.
|
|
19
|
+
// Backoff tuning. `Retry-After` is honoured but capped so retries stay fast.
|
|
20
|
+
const MAX_RETRY_AFTER_MS = 5_000;
|
|
21
|
+
const BACKOFF_BASE_MS = 200;
|
|
22
|
+
const BACKOFF_CAP_MS = 1_000;
|
|
23
|
+
const SNIPPET_MAX_LENGTH = 300;
|
|
24
|
+
function isRetryableStatus(status) {
|
|
25
|
+
return status === 429 || (status >= 500 && status <= 599);
|
|
26
|
+
}
|
|
27
|
+
function isIdempotentMethod(method) {
|
|
28
|
+
return method === "GET" || method === "HEAD" || method === "OPTIONS" || method === "PUT" || method === "DELETE";
|
|
29
|
+
}
|
|
30
|
+
function parseRetryAfter(value) {
|
|
31
|
+
if (!value)
|
|
32
|
+
return null;
|
|
33
|
+
const trimmed = value.trim();
|
|
34
|
+
// Delta-seconds (non-negative integer).
|
|
35
|
+
if (/^\d+$/.test(trimmed)) {
|
|
36
|
+
const seconds = Number.parseInt(trimmed, 10);
|
|
37
|
+
return Math.min(seconds * 1000, MAX_RETRY_AFTER_MS);
|
|
38
|
+
}
|
|
39
|
+
// HTTP-date.
|
|
40
|
+
const dateMs = Date.parse(trimmed);
|
|
41
|
+
if (!Number.isNaN(dateMs)) {
|
|
42
|
+
return Math.min(Math.max(0, dateMs - Date.now()), MAX_RETRY_AFTER_MS);
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
// Exponential backoff with full jitter. `attempt` is 1-based.
|
|
47
|
+
function exponentialBackoff(attempt) {
|
|
48
|
+
const capped = Math.min(BACKOFF_BASE_MS * 2 ** (attempt - 1), BACKOFF_CAP_MS);
|
|
49
|
+
return Math.floor(Math.random() * capped);
|
|
50
|
+
}
|
|
51
|
+
function sleep(ms) {
|
|
52
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
53
|
+
}
|
|
54
|
+
function snippetFrom(text) {
|
|
55
|
+
const trimmed = text.trim();
|
|
56
|
+
return trimmed ? ` - ${truncate(trimmed, SNIPPET_MAX_LENGTH)}` : "";
|
|
57
|
+
}
|
|
58
|
+
// Runs a single fetch attempt. `timeoutMs` is the PER-ATTEMPT timeout: each
|
|
59
|
+
// attempt owns its own AbortController, so a single attempt's observable
|
|
60
|
+
// behaviour matches the pre-retry implementation exactly.
|
|
61
|
+
async function performAttempt(url, options, allowStatuses, timeoutMs, fetchImpl) {
|
|
15
62
|
const controller = new AbortController();
|
|
16
63
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
17
64
|
try {
|
|
18
|
-
const response = await
|
|
65
|
+
const response = await fetchImpl(url, {
|
|
19
66
|
method: options.method,
|
|
20
67
|
headers: options.headers,
|
|
21
68
|
body: options.body,
|
|
@@ -23,30 +70,80 @@ export async function requestJson(url, { timeoutMs = 15_000, allowStatuses = [],
|
|
|
23
70
|
});
|
|
24
71
|
const text = typeof response.text === "function" ? await response.text() : "";
|
|
25
72
|
const isAllowedFailure = allowStatuses.includes(response.status);
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
73
|
+
if (response.ok || isAllowedFailure) {
|
|
74
|
+
if (!text.trim()) {
|
|
75
|
+
return { kind: "success", status: response.status, data: null };
|
|
76
|
+
}
|
|
77
|
+
let data;
|
|
78
|
+
try {
|
|
79
|
+
data = JSON.parse(text);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return {
|
|
83
|
+
kind: "json-error",
|
|
84
|
+
error: new Error(`Invalid JSON response from ${url}: ${error instanceof Error ? error.message : String(error)}`),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return { kind: "success", status: response.status, data };
|
|
36
88
|
}
|
|
37
|
-
|
|
38
|
-
|
|
89
|
+
if (isRetryableStatus(response.status)) {
|
|
90
|
+
let retryAfterMs = null;
|
|
91
|
+
try {
|
|
92
|
+
retryAfterMs = parseRetryAfter(response.headers.get("retry-after"));
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
retryAfterMs = null;
|
|
96
|
+
}
|
|
97
|
+
return { kind: "retryable-status", status: response.status, text, retryAfterMs };
|
|
39
98
|
}
|
|
40
|
-
return { status: response.status,
|
|
99
|
+
return { kind: "non-retryable-status", status: response.status, text };
|
|
41
100
|
}
|
|
42
101
|
catch (error) {
|
|
43
102
|
if (error instanceof Error && error.name === "AbortError") {
|
|
44
|
-
|
|
103
|
+
return { kind: "abort" };
|
|
45
104
|
}
|
|
46
|
-
|
|
105
|
+
return { kind: "network-error", error };
|
|
47
106
|
}
|
|
48
107
|
finally {
|
|
49
108
|
clearTimeout(timeout);
|
|
50
109
|
}
|
|
51
110
|
}
|
|
111
|
+
export async function requestJson(url, { timeoutMs = 15_000, allowStatuses = [], maxAttempts, _fetch, ...options } = {}) {
|
|
112
|
+
const fetchImpl = _fetch ?? globalThis.fetch;
|
|
113
|
+
const method = options.method?.toUpperCase() ?? "GET";
|
|
114
|
+
const defaultAttempts = isIdempotentMethod(method) ? 3 : 1;
|
|
115
|
+
const attempts = Math.max(1, Math.trunc(maxAttempts ?? defaultAttempts));
|
|
116
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
117
|
+
const isLastAttempt = attempt === attempts;
|
|
118
|
+
const outcome = await performAttempt(url, options, allowStatuses, timeoutMs, fetchImpl);
|
|
119
|
+
switch (outcome.kind) {
|
|
120
|
+
case "success":
|
|
121
|
+
return { status: outcome.status, data: outcome.data };
|
|
122
|
+
case "json-error":
|
|
123
|
+
throw outcome.error;
|
|
124
|
+
case "non-retryable-status":
|
|
125
|
+
throw new HttpRequestError(`HTTP ${outcome.status} for ${url}${snippetFrom(outcome.text)}`, outcome.status, url);
|
|
126
|
+
case "retryable-status":
|
|
127
|
+
if (isLastAttempt) {
|
|
128
|
+
throw new HttpRequestError(`HTTP ${outcome.status} for ${url}${snippetFrom(outcome.text)}`, outcome.status, url);
|
|
129
|
+
}
|
|
130
|
+
await sleep(outcome.retryAfterMs ?? exponentialBackoff(attempt));
|
|
131
|
+
break;
|
|
132
|
+
case "abort":
|
|
133
|
+
if (isLastAttempt) {
|
|
134
|
+
throw new Error(`Request timed out after ${timeoutMs}ms for ${url}`);
|
|
135
|
+
}
|
|
136
|
+
await sleep(exponentialBackoff(attempt));
|
|
137
|
+
break;
|
|
138
|
+
case "network-error":
|
|
139
|
+
if (isLastAttempt) {
|
|
140
|
+
throw outcome.error;
|
|
141
|
+
}
|
|
142
|
+
await sleep(exponentialBackoff(attempt));
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Unreachable: the loop always returns or throws on the final attempt.
|
|
147
|
+
throw new Error(`requestJson: exhausted all attempts for ${url}`);
|
|
148
|
+
}
|
|
52
149
|
//# sourceMappingURL=http.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/integrations/http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/integrations/http.ts"],"names":[],"mappings":"AAcA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAGvB;IACA;IAHlB,YACE,OAAe,EACC,MAAc,EACd,GAAW;QAE3B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,WAAM,GAAN,MAAM,CAAQ;QACd,QAAG,GAAH,GAAG,CAAQ;QAG3B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,SAAiB;IAC/C,OAAO,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC3E,CAAC;AAED,+EAA+E;AAC/E,0EAA0E;AAC1E,iFAAiF;AACjF,kFAAkF;AAClF,iEAAiE;AAEjE,6EAA6E;AAC7E,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACjC,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,MAAM,kBAAkB,GA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;gBACf,MAAM,OAAO,CAAC,KAAK,CAAC;YACtB,KAAK,sBAAsB;gBACzB,MAAM,IAAI,gBAAgB,CACxB,QAAQ,OAAO,CAAC,MAAM,QAAQ,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAC/D,OAAO,CAAC,MAAM,EACd,GAAG,CACJ,CAAC;YACJ,KAAK,kBAAkB;gBACrB,IAAI,aAAa,EAAE,CAAC;oBAClB,MAAM,IAAI,gBAAgB,CACxB,QAAQ,OAAO,CAAC,MAAM,QAAQ,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAC/D,OAAO,CAAC,MAAM,EACd,GAAG,CACJ,CAAC;gBACJ,CAAC;gBACD,MAAM,KAAK,CAAC,OAAO,CAAC,YAAY,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;gBACjE,MAAM;YACR,KAAK,OAAO;gBACV,IAAI,aAAa,EAAE,CAAC;oBAClB,MAAM,IAAI,KAAK,CAAC,2BAA2B,SAAS,UAAU,GAAG,EAAE,CAAC,CAAC;gBACvE,CAAC;gBACD,MAAM,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;gBACzC,MAAM;YACR,KAAK,eAAe;gBAClB,IAAI,aAAa,EAAE,CAAC;oBAClB,MAAM,OAAO,CAAC,KAAK,CAAC;gBACtB,CAAC;gBACD,MAAM,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;gBACzC,MAAM;QACV,CAAC;IACH,CAAC;IACD,uEAAuE;IACvE,MAAM,IAAI,KAAK,CAAC,2CAA2C,GAAG,EAAE,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type DelegationSignal } from "../governance/delegation.machine.js";
|
|
2
|
+
import { type DelegationCoordinatorState, type DelegationRequestState } from "../governance/delegation.utils.js";
|
|
3
|
+
import type { AgentOutput, DAOAgent, DAOConfig, HostAdapter, Proposal } from "../types/index.js";
|
|
4
|
+
import { type ModelResolutionContext } from "./model.js";
|
|
5
|
+
export interface DelegationResult {
|
|
6
|
+
/** Parent content with folded child reasoning appended (INV-6: votes untouched). */
|
|
7
|
+
foldedContent: string;
|
|
8
|
+
/** Every coordinator created for this parent (for the registry / cascade). */
|
|
9
|
+
coordinators: DelegationCoordinatorState[];
|
|
10
|
+
/** Every request created for this parent (for audit). */
|
|
11
|
+
requests: DelegationRequestState[];
|
|
12
|
+
/** True when at least one request reached `delegated`. */
|
|
13
|
+
delegated: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Run all declared delegations for a parent agent after it has produced an
|
|
17
|
+
* output. Returns the (possibly folded) parent content and the live machine
|
|
18
|
+
* states. No-op when delegation is disabled, the agent declares no delegates,
|
|
19
|
+
* or the parent emitted no recognizable signal.
|
|
20
|
+
*/
|
|
21
|
+
export declare function runDelegations(params: {
|
|
22
|
+
parent: DAOAgent;
|
|
23
|
+
parentOutput: AgentOutput;
|
|
24
|
+
proposal: Proposal;
|
|
25
|
+
adapter: HostAdapter;
|
|
26
|
+
config: DAOConfig;
|
|
27
|
+
parentModelContext: ModelResolutionContext;
|
|
28
|
+
onCoordinatorCreated?: (coordinator: DelegationCoordinatorState) => void;
|
|
29
|
+
}): Promise<DelegationResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Append the child's investigation under a `## Delegated Facets` section.
|
|
32
|
+
* Pure. The parent's `## Vote` section is never touched (INV-6).
|
|
33
|
+
*/
|
|
34
|
+
export declare function foldChildIntoParent(parentContent: string, signal: DelegationSignal, childOutput: AgentOutput): string;
|
|
35
|
+
/**
|
|
36
|
+
* Drain/cancel cascade (B3). Emit DRAIN to each coordinator, then CANCEL to
|
|
37
|
+
* every non-terminal request. Idempotent: terminal states ignore events.
|
|
38
|
+
*/
|
|
39
|
+
export declare function drainDelegations(coordinators: DelegationCoordinatorState[], requests: DelegationRequestState[]): void;
|
|
40
|
+
//# sourceMapp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AAE,QAAQ,EAAE,sBAAsB,EAAE,GAAG,IAAI,CAgBrH"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// Swarm DAO Core — Delegation Orchestrator (DFI thin slice)
|
|
3
|
+
// ------------------------------------------------------------
|
|
4
|
+
// I/O layer ONLY. Drives the two delegation machines through their events.
|
|
5
|
+
// Owns: parse parent LLM signal, evaluate the pure gate, spawn child via
|
|
6
|
+
// `HostAdapter.spawnAgent`, fold child reasoning into the parent output, and
|
|
7
|
+
// run the drain/cancel cascade. Emits NO decision the machines do not
|
|
8
|
+
// authorize (INV-3). Child outputs fold into parent REASONING only — never
|
|
9
|
+
// into votes (INV-6, enforced structurally: weight 0, separate section).
|
|
10
|
+
//
|
|
11
|
+
// Fold integrity (B2): the request machine commits to a fold hash on
|
|
12
|
+
// CHILD_REPORTED (FNV-1a over the child output content) and the orchestrator
|
|
13
|
+
// must echo the identical hash on FOLD_COMPLETE. This binds the fold ack to
|
|
14
|
+
// the observed child report. A request cannot leave `reported` otherwise.
|
|
15
|
+
// ============================================================
|
|
16
|
+
import { buildChildAgent, computeMergedFoldHash, evaluateDelegationGate, extractDelegationSignals, normalizeFacet, } from "../governance/delegation.machine.js";
|
|
17
|
+
import { createCoordinatorState, createRequestState, dispatchCoordinatorEvent, dispatchDelegationEvent, profileFor, registeredArchetypes, } from "../governance/delegation.utils.js";
|
|
18
|
+
import { buildChildModelResolutionContext, resolveAgentModel } from "./model.js";
|
|
19
|
+
/**
|
|
20
|
+
* Run all declared delegations for a parent agent after it has produced an
|
|
21
|
+
* output. Returns the (possibly folded) parent content and the live machine
|
|
22
|
+
* states. No-op when delegation is disabled, the agent declares no delegates,
|
|
23
|
+
* or the parent emitted no recognizable signal.
|
|
24
|
+
*/
|
|
25
|
+
export async function runDelegations(params) {
|
|
26
|
+
const { parent, parentOutput, proposal, adapter, config, parentModelContext } = params;
|
|
27
|
+
const content = parentOutput.content ?? "";
|
|
28
|
+
const coordinators = [];
|
|
29
|
+
const requests = [];
|
|
30
|
+
const delegation = config.delegation;
|
|
31
|
+
const declared = parent.delegates ?? [];
|
|
32
|
+
const signals = delegation?.enabled === true && declared.length > 0 ? extractDelegationSignals(content) : [];
|
|
33
|
+
if (signals.length === 0) {
|
|
34
|
+
return { foldedContent: content, coordinators, requests, delegated: false };
|
|
35
|
+
}
|
|
36
|
+
const coordinator = createCoordinatorState(parent, config);
|
|
37
|
+
coordinators.push(coordinator);
|
|
38
|
+
params.onCoordinatorCreated?.(coordinator);
|
|
39
|
+
const archetypes = registeredArchetypes(config);
|
|
40
|
+
const parentResolvedModel = resolveAgentModel(parent, parentModelContext);
|
|
41
|
+
let counter = 0;
|
|
42
|
+
let delegated = false;
|
|
43
|
+
let foldedContent = content;
|
|
44
|
+
for (const signal of signals) {
|
|
45
|
+
const requestId = `${parent.id}:${normalizeFacet(signal.facet)}:${counter++}`;
|
|
46
|
+
const arrived = dispatchCoordinatorEvent(coordinator, {
|
|
47
|
+
type: "REQUEST_ARRIVED",
|
|
48
|
+
requestId,
|
|
49
|
+
facet: signal.facet,
|
|
50
|
+
archetype: signal.archetype,
|
|
51
|
+
});
|
|
52
|
+
if (!arrived.ok || arrived.ack?.accepted === false) {
|
|
53
|
+
// Coordinator-level refusal (budget / disabled / depth). Record a blocked
|
|
54
|
+
// request for audit; no child is spawned (INV-2, W4).
|
|
55
|
+
const req = createRequestState(requestId, coordinator, signal.facet, signal.archetype);
|
|
56
|
+
requests.push(req);
|
|
57
|
+
dispatchDelegationEvent(req, {
|
|
58
|
+
type: "GATE_DECIDED",
|
|
59
|
+
ok: false,
|
|
60
|
+
reasons: [arrived.ok ? (arrived.ack?.reason ?? "rejected by coordinator") : arrived.error],
|
|
61
|
+
});
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const req = createRequestState(requestId, coordinator, signal.facet, signal.archetype);
|
|
65
|
+
requests.push(req);
|
|
66
|
+
// Per-request gate (pure). Single authority for facet/archetype/depth.
|
|
67
|
+
const gate = evaluateDelegationGate({
|
|
68
|
+
facet: signal.facet,
|
|
69
|
+
archetype: signal.archetype,
|
|
70
|
+
parentDepth: coordinator.parentDepth,
|
|
71
|
+
maxDepth: delegation?.maxDepth ?? 0,
|
|
72
|
+
declared,
|
|
73
|
+
registeredArchetypes: archetypes,
|
|
74
|
+
});
|
|
75
|
+
dispatchDelegationEvent(req, { type: "GATE_DECIDED", ok: gate.ok, reasons: gate.reasons });
|
|
76
|
+
if (!gate.ok) {
|
|
77
|
+
// Resolve the coordinator slot we consumed: a blocked request is terminal.
|
|
78
|
+
dispatchCoordinatorEvent(coordinator, { type: "REQUEST_RESOLVED", requestId, terminalStatus: "blocked" });
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
dispatchDelegationEvent(req, {
|
|
82
|
+
type: "SPAWN_ACKED",
|
|
83
|
+
childAgentId: `${parent.id}:delegate:${normalizeFacet(signal.facet)}`,
|
|
84
|
+
});
|
|
85
|
+
const spec = declared.find((d) => normalizeFacet(d.facet) === normalizeFacet(signal.facet));
|
|
86
|
+
const childAgent = buildChildAgent(parent, spec ?? { facet: signal.facet, archetype: signal.archetype });
|
|
87
|
+
const profile = profileFor(config, signal.archetype);
|
|
88
|
+
const childModel = resolveAgentModel(childAgent, buildChildModelResolutionContext(config.defaultModel, {
|
|
89
|
+
parentAgentModel: parentResolvedModel,
|
|
90
|
+
profile,
|
|
91
|
+
parentSessionModel: parentModelContext.parentSessionModel,
|
|
92
|
+
hostDefaultModel: parentModelContext.hostDefaultModel,
|
|
93
|
+
}));
|
|
94
|
+
try {
|
|
95
|
+
const childOutput = await adapter.spawnAgent({
|
|
96
|
+
agent: childAgent,
|
|
97
|
+
proposal,
|
|
98
|
+
systemPrompt: profile?.promptId ? `[prompt:${profile.promptId}]` : childAgent.systemPrompt,
|
|
99
|
+
model: childModel,
|
|
100
|
+
timeoutMs: delegation?.foldTimeoutMs,
|
|
101
|
+
});
|
|
102
|
+
if (childOutput.error) {
|
|
103
|
+
dispatchDelegationEvent(req, { type: "CHILD_FAILED", error: childOutput.error });
|
|
104
|
+
dispatchCoordinatorEvent(coordinator, { type: "REQUEST_RESOLVED", requestId, terminalStatus: "failed" });
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
dispatchDelegationEvent(req, { type: "CHILD_REPORTED", output: childOutput });
|
|
108
|
+
// Fold: merge child reasoning into the parent's content (INV-6).
|
|
109
|
+
foldedContent = foldChildIntoParent(foldedContent, signal, childOutput);
|
|
110
|
+
// Echo the machine's commitment hash to acknowledge the fold (B2).
|
|
111
|
+
dispatchDelegationEvent(req, {
|
|
112
|
+
type: "FOLD_COMPLETE",
|
|
113
|
+
foldedInto: parent.id,
|
|
114
|
+
mergedAgentOutputHash: computeMergedFoldHash(childOutput.content ?? ""),
|
|
115
|
+
});
|
|
116
|
+
delegated = true;
|
|
117
|
+
dispatchCoordinatorEvent(coordinator, { type: "REQUEST_RESOLVED", requestId, terminalStatus: "delegated" });
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
const message = err instanceof Error ? err.message : "spawn failed";
|
|
121
|
+
dispatchDelegationEvent(req, { type: "SPAWN_FAILED", error: message });
|
|
122
|
+
dispatchCoordinatorEvent(coordinator, { type: "REQUEST_RESOLVED", requestId, terminalStatus: "failed" });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return { foldedContent, coordinators, requests, delegated };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Append the child's investigation under a `## Delegated Facets` section.
|
|
129
|
+
* Pure. The parent's `## Vote` section is never touched (INV-6).
|
|
130
|
+
*/
|
|
131
|
+
export function foldChildIntoParent(parentContent, signal, childOutput) {
|
|
132
|
+
const childBlock = [
|
|
133
|
+
"",
|
|
134
|
+
"## Delegated Facets",
|
|
135
|
+
`### facet: ${signal.facet} | archetype: ${signal.archetype}`,
|
|
136
|
+
childOutput.content?.trim() ?? "_(no output)_",
|
|
137
|
+
"",
|
|
138
|
+
].join("\n");
|
|
139
|
+
return `${parentContent.replace(/\n*$/, "")}\n${childBlock}`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Drain/cancel cascade (B3). Emit DRAIN to each coordinator, then CANCEL to
|
|
143
|
+
* every non-terminal request. Idempotent: terminal states ignore events.
|
|
144
|
+
*/
|
|
145
|
+
export function drainDelegations(coordinators, requests) {
|
|
146
|
+
for (const c of coordinators) {
|
|
147
|
+
dispatchCoordinatorEvent(c, { type: "DRAIN", reason: "proposal-terminal" });
|
|
148
|
+
}
|
|
149
|
+
const byParent = new Map(coordinators.map((c) => [c.parentAgentId, c]));
|
|
150
|
+
for (const r of requests) {
|
|
151
|
+
dispatchDelegationEvent(r, { type: "CANCEL", reason: "proposal-terminal" });
|
|
152
|
+
const owner = byParent.get(r.parentAgentId) ?? coordinators[0];
|
|
153
|
+
if (owner) {
|
|
154
|
+
dispatchCoordinatorEvent(owner, {
|
|
155
|
+
type: "REQUEST_RESOLVED",
|
|
156
|
+
requestId: r.requestId,
|
|
157
|
+
terminalStatus: "cancelled",
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=delegation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegation.js","sourceRoot":"","sources":["../../src/intelligence/delegation.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,4DAA4D;AAC5D,+DAA+D;AAC/D,2EAA2E;AAC3E,yEAAyE;AACzE,6EAA6E;AAC7E,sEAAsE;AACtE,2EAA2E;AAC3E,yEAAyE;AACzE,EAAE;AACF,qEAAqE;AACrE,6EAA6E;AAC7E,4EAA4E;AAC5E,0EAA0E;AAC1E,+DAA+D;AAE/D,OAAO,EACL,eAAe,EACf,qBAAqB,EAErB,sBAAsB,EACtB,wBAAwB,EACxB,cAAc,GACf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,sBAAsB,EACtB,kBAAkB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EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACxE,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,uBAAuB,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC;QAC5E,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;QAC/D,IAAI,KAAK,EAAE,CAAC;YACV,wBAAwB,CAAC,KAAK,EAAE;gBAC9B,IAAI,EAAE,kBAAkB;gBACxB,SAAS,EAAE,CAAC,CAAC,SAAS;gBACtB,cAAc,EAAE,WAAW;aAC5B,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/intelligence/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/intelligence/index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/intelligence/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/intelligence/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
|
@@ -1,16 +1,42 @@
|
|
|
1
|
-
import type { DAOAgent } from "../types/index.js";
|
|
1
|
+
import type { DAOAgent, DelegationProfileEntry } from "../types/index.js";
|
|
2
2
|
export interface ModelResolutionContext {
|
|
3
|
+
/** Model set on a parent agent (delegation inheritance). */
|
|
4
|
+
parentAgentModel?: string;
|
|
5
|
+
/** Model declared by the delegation profile for the child's archetype. */
|
|
6
|
+
profileDefaultModel?: string;
|
|
3
7
|
parentSessionModel?: string;
|
|
4
8
|
configDefaultModel: string;
|
|
5
9
|
hostDefaultModel?: string;
|
|
6
10
|
}
|
|
7
11
|
/**
|
|
8
12
|
* Resolve the model for a DAO agent using the inheritance chain:
|
|
9
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* agent.model
|
|
15
|
+
* → profile.defaultModel (delegation profile, child archetype)
|
|
16
|
+
* → parentAgent.resolvedModel (delegation parent — default behaviour)
|
|
17
|
+
* → parentSessionModel
|
|
18
|
+
* → config.defaultModel
|
|
19
|
+
* → host default
|
|
20
|
+
*
|
|
21
|
+
* For a delegated child, `agent.model` carries the child's `DelegationSpec.model`
|
|
22
|
+
* (where `"inherit"` / omitted ⇒ fall through to the parent). The chain is
|
|
23
|
+
* strictly additive: every layer may only refine, never branch.
|
|
10
24
|
*/
|
|
11
25
|
export declare function resolveAgentModel(agent: DAOAgent, ctx: ModelResolutionContext): string;
|
|
12
26
|
export declare function describeModelResolution(agent: DAOAgent, resolved: string, ctx: ModelResolutionContext): string;
|
|
13
27
|
export declare function buildModelResolutionContext(configDefaultModel: string, options?: {
|
|
28
|
+
parentAgentModel?: string;
|
|
29
|
+
parentSessionModel?: string;
|
|
30
|
+
hostDefaultModel?: string;
|
|
31
|
+
}): ModelResolutionContext;
|
|
32
|
+
/**
|
|
33
|
+
* Build a resolution context for a delegated child. `profileDefaultModel` is
|
|
34
|
+
* sourced from the DAO's delegation profile for the child's archetype; the
|
|
35
|
+
* parent agent's resolved model is the default the child inherits.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildChildModelResolutionContext(configDefaultModel: string, options: {
|
|
38
|
+
parentAgentModel: string;
|
|
39
|
+
profile?: DelegationProfileEntry;
|
|
14
40
|
parentSessionModel?: string;
|
|
15
41
|
hostDefaultModel?: string;
|
|
16
42
|
}): ModelResolutionContext;
|