@guyghost/swarm-dao-core 0.1.4 → 0.2.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/config.d.ts.map +1 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/control/gates.js +4 -4
- package/dist/control/gates.js.map +1 -1
- package/dist/delivery/artefacts.d.ts.map +1 -1
- package/dist/delivery/artefacts.js +4 -3
- package/dist/delivery/artefacts.js.map +1 -1
- package/dist/delivery/dry-run.d.ts.map +1 -1
- package/dist/delivery/dry-run.js +14 -17
- package/dist/delivery/dry-run.js.map +1 -1
- package/dist/delivery/plans.d.ts.map +1 -1
- package/dist/delivery/plans.js +19 -7
- package/dist/delivery/plans.js.map +1 -1
- package/dist/governance/agents.d.ts +4 -0
- package/dist/governance/agents.d.ts.map +1 -1
- package/dist/governance/agents.js +86 -1
- package/dist/governance/agents.js.map +1 -1
- 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.js +5 -5
- package/dist/governance/lifecycle.js.map +1 -1
- package/dist/governance/proposal.machine.d.ts +131 -0
- package/dist/governance/proposal.machine.d.ts.map +1 -0
- package/dist/governance/proposal.machine.js +378 -0
- package/dist/governance/proposal.machine.js.map +1 -0
- package/dist/governance/proposal.utils.d.ts +166 -0
- package/dist/governance/proposal.utils.d.ts.map +1 -0
- package/dist/governance/proposal.utils.js +126 -0
- package/dist/governance/proposal.utils.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/bitbucket.d.ts.map +1 -1
- package/dist/integrations/bitbucket.js +9 -2
- package/dist/integrations/bitbucket.js.map +1 -1
- package/dist/integrations/github.d.ts.map +1 -1
- package/dist/integrations/github.js +9 -2
- package/dist/integrations/github.js.map +1 -1
- package/dist/integrations/gitlab.d.ts.map +1 -1
- package/dist/integrations/gitlab.js +9 -2
- package/dist/integrations/gitlab.js.map +1 -1
- 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 +17 -0
- package/dist/intelligence/model.d.ts.map +1 -0
- package/dist/intelligence/model.js +41 -0
- package/dist/intelligence/model.js.map +1 -0
- package/dist/intelligence/roundtable.d.ts +2 -1
- package/dist/intelligence/roundtable.d.ts.map +1 -1
- package/dist/intelligence/roundtable.js +5 -3
- package/dist/intelligence/roundtable.js.map +1 -1
- package/dist/intelligence/swarm.d.ts +9 -3
- package/dist/intelligence/swarm.d.ts.map +1 -1
- package/dist/intelligence/swarm.js +24 -12
- package/dist/intelligence/swarm.js.map +1 -1
- package/dist/observability/index.d.ts +1 -0
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +1 -0
- package/dist/observability/index.js.map +1 -1
- package/dist/observability/logging.d.ts +14 -0
- package/dist/observability/logging.d.ts.map +1 -0
- package/dist/observability/logging.js +38 -0
- package/dist/observability/logging.js.map +1 -0
- package/dist/persistence.d.ts.map +1 -1
- package/dist/persistence.js +70 -40
- package/dist/persistence.js.map +1 -1
- package/dist/types/index.d.ts +11 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +24 -22
- package/dist/types/index.js.map +1 -1
- package/dist/utils/host.js +2 -2
- package/dist/utils/host.js.map +1 -1
- package/dist/utils/security.d.ts +7 -0
- package/dist/utils/security.d.ts.map +1 -0
- package/dist/utils/security.js +32 -0
- package/dist/utils/security.js.map +1 -0
- package/package.json +8 -3
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// ============================================================
|
|
2
2
|
// Swarm DAO Core — Round Table (Agents suggest proposals)
|
|
3
3
|
// ============================================================
|
|
4
|
-
import { PROPOSAL_TYPES } from "../types/index.js";
|
|
4
|
+
import { PROPOSAL_TYPE, PROPOSAL_TYPES } from "../types/index.js";
|
|
5
|
+
import { resolveAgentModel } from "./model.js";
|
|
5
6
|
const SUGGESTION_PROMPT = `You are participating in a DAO Round Table.
|
|
6
7
|
|
|
7
8
|
Your task: suggest ONE concrete proposal that would improve the project.
|
|
@@ -15,7 +16,7 @@ Output format:
|
|
|
15
16
|
**Description:** [2-3 sentences describing what and why]
|
|
16
17
|
|
|
17
18
|
Be specific. Reference actual files, patterns, or problems if you can.`;
|
|
18
|
-
export async function runRoundTable(adapter, agents, maxConcurrent) {
|
|
19
|
+
export async function runRoundTable(adapter, agents, maxConcurrent, modelContext) {
|
|
19
20
|
const suggestions = [];
|
|
20
21
|
// Process in batches
|
|
21
22
|
for (let i = 0; i < agents.length; i += maxConcurrent) {
|
|
@@ -27,7 +28,7 @@ export async function runRoundTable(adapter, agents, maxConcurrent) {
|
|
|
27
28
|
proposal: {
|
|
28
29
|
id: 0,
|
|
29
30
|
title: "Round Table Suggestions",
|
|
30
|
-
type:
|
|
31
|
+
type: PROPOSAL_TYPE.GOVERNANCE_CHANGE,
|
|
31
32
|
description: "Agents suggest proposals",
|
|
32
33
|
proposedBy: "system",
|
|
33
34
|
status: "open",
|
|
@@ -36,6 +37,7 @@ export async function runRoundTable(adapter, agents, maxConcurrent) {
|
|
|
36
37
|
createdAt: new Date().toISOString(),
|
|
37
38
|
},
|
|
38
39
|
systemPrompt: `${agent.systemPrompt}\n\n${SUGGESTION_PROMPT}`,
|
|
40
|
+
model: resolveAgentModel(agent, modelContext),
|
|
39
41
|
timeoutMs: 60_000,
|
|
40
42
|
});
|
|
41
43
|
const parsed = parseSuggestion(output.content);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roundtable.js","sourceRoot":"","sources":["../../src/intelligence/roundtable.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,0DAA0D;AAC1D,+DAA+D;AAG/D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAm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M,EAAE,IAAI,IAAI,CAAC;QAC1C,MAAM,IAAI,oBAAoB,CAAC,CAAC,MAAM,EAAE,WAAW,IAAI,CAAC;QACxD,IAAI,CAAC,CAAC,UAAU,IAAI,cAAc,EAAE,CAAC;YACnC,MAAM,IAAI,0BAA0B,CAAC,CAAC,UAAU,IAAI,CAAC;QACvD,CAAC;QACD,MAAM,IAAI,IAAI,CAAC;IACjB,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,2BAA2B,CAAC;QACtC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,CAAC,SAAS,4BAA4B,CAAC;QACzD,CAAC;QACD,MAAM,IAAI,IAAI,CAAC;IACjB,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,aAAa,CAAC;QACxB,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AgentOutput, DAOAgent, HostAdapter, Proposal } from "../types/index.js";
|
|
2
|
+
import { type ModelResolutionContext } from "./model.js";
|
|
2
3
|
export interface SwarmProgressUpdate {
|
|
3
4
|
agentId: string;
|
|
4
5
|
agentName: string;
|
|
@@ -10,18 +11,23 @@ export interface DispatchInstruction {
|
|
|
10
11
|
agentId: string;
|
|
11
12
|
agentName: string;
|
|
12
13
|
prompt: string;
|
|
13
|
-
model
|
|
14
|
+
model: string;
|
|
15
|
+
modelDescription: string;
|
|
14
16
|
timeoutMs: number;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Build dispatch instructions for each agent.
|
|
18
20
|
* Host adapters use these to spawn sub-agents.
|
|
19
21
|
*/
|
|
20
|
-
export declare function buildDispatchInstructions(proposal: Proposal, agents: DAOAgent[]): DispatchInstruction[];
|
|
22
|
+
export declare function buildDispatchInstructions(proposal: Proposal, agents: DAOAgent[], modelContext: ModelResolutionContext): DispatchInstruction[];
|
|
21
23
|
export declare function formatDispatchPlan(proposal: Proposal, instructions: DispatchInstruction[]): string;
|
|
24
|
+
export declare function createDispatchModelContext(configDefaultModel: string, adapter: HostAdapter, options?: {
|
|
25
|
+
hostDefaultModel?: string;
|
|
26
|
+
parentSessionModel?: string;
|
|
27
|
+
}): ModelResolutionContext;
|
|
22
28
|
/**
|
|
23
29
|
* Dispatch swarm via a host adapter.
|
|
24
30
|
* This is the host-agnostic version — adapters implement the actual spawning.
|
|
25
31
|
*/
|
|
26
|
-
export declare function dispatchSwarm(proposal: Proposal, agents: DAOAgent[], adapter: HostAdapter, maxConcurrent: number, onUpdate?: (update: SwarmProgressUpdate) => void): Promise<AgentOutput[]>;
|
|
32
|
+
export declare function dispatchSwarm(proposal: Proposal, agents: DAOAgent[], adapter: HostAdapter, maxConcurrent: number, modelContext: ModelResolutionContext, onUpdate?: (update: SwarmProgressUpdate) => void): Promise<AgentOutput[]>;
|
|
27
33
|
//# sourceMappingURL=swarm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swarm.d.ts","sourceRoot":"","sources":["../../src/intelligence/swarm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"swarm.d.ts","sourceRoot":"","sources":["../../src/intelligence/swarm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,EAGL,KAAK,sBAAsB,EAE5B,MAAM,YAA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
2
|
// Swarm DAO Core — Swarm Dispatch
|
|
3
3
|
// ============================================================
|
|
4
|
+
import { buildModelResolutionContext, describeModelResolution, resolveAgentModel, } from "./model.js";
|
|
4
5
|
/**
|
|
5
6
|
* Build dispatch instructions for each agent.
|
|
6
7
|
* Host adapters use these to spawn sub-agents.
|
|
7
8
|
*/
|
|
8
|
-
export function buildDispatchInstructions(proposal, agents) {
|
|
9
|
+
export function buildDispatchInstructions(proposal, agents, modelContext) {
|
|
9
10
|
const basePrompt = `You are participating in DAO governance deliberation for the following proposal.
|
|
10
11
|
|
|
11
12
|
## Proposal #${proposal.id}: ${proposal.title}
|
|
@@ -21,13 +22,17 @@ ${Array.isArray(proposal.acceptanceCriteria) && proposal.acceptanceCriteria.leng
|
|
|
21
22
|
${proposal.successMetrics?.length ? `**Success Metrics:**\n${proposal.successMetrics.map((m) => `- ${m}`).join("\n")}\n\n` : ""}
|
|
22
23
|
|
|
23
24
|
Evaluate this proposal carefully. Provide your analysis, vote, and scoring.`;
|
|
24
|
-
return agents.map((agent) =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
return agents.map((agent) => {
|
|
26
|
+
const model = resolveAgentModel(agent, modelContext);
|
|
27
|
+
return {
|
|
28
|
+
agentId: agent.id,
|
|
29
|
+
agentName: agent.name,
|
|
30
|
+
prompt: `${agent.systemPrompt}\n\n${basePrompt}`,
|
|
31
|
+
model,
|
|
32
|
+
modelDescription: describeModelResolution(agent, model, modelContext),
|
|
33
|
+
timeoutMs: 120_000,
|
|
34
|
+
};
|
|
35
|
+
});
|
|
31
36
|
}
|
|
32
37
|
export function formatDispatchPlan(proposal, instructions) {
|
|
33
38
|
return `# 🐝 Swarm Dispatch Plan — Proposal #${proposal.id}
|
|
@@ -38,10 +43,10 @@ export function formatDispatchPlan(proposal, instructions) {
|
|
|
38
43
|
## Instructions
|
|
39
44
|
${instructions
|
|
40
45
|
.map((inst) => `### @${inst.agentId} (${inst.agentName})
|
|
41
|
-
- Model: ${inst.
|
|
46
|
+
- Model: ${inst.modelDescription}
|
|
42
47
|
- Timeout: ${inst.timeoutMs}ms
|
|
43
48
|
|
|
44
|
-
Spawn this sub-agent with the following task:
|
|
49
|
+
Spawn this sub-agent with the following task (use \`task\` with \`model="${inst.model}"\` when available):
|
|
45
50
|
\`\`\`
|
|
46
51
|
${inst.prompt.slice(0, 500)}${inst.prompt.length > 500 ? "..." : ""}
|
|
47
52
|
\`\`\`
|
|
@@ -51,12 +56,18 @@ ${inst.prompt.slice(0, 500)}${inst.prompt.length > 500 ? "..." : ""}
|
|
|
51
56
|
## Next Step
|
|
52
57
|
After collecting all outputs, call \`dao_record_outputs\` with the collected responses.`;
|
|
53
58
|
}
|
|
59
|
+
export function createDispatchModelContext(configDefaultModel, adapter, options) {
|
|
60
|
+
return buildModelResolutionContext(configDefaultModel, {
|
|
61
|
+
parentSessionModel: options?.parentSessionModel ?? adapter.getSessionModel?.(),
|
|
62
|
+
hostDefaultModel: options?.hostDefaultModel,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
54
65
|
/**
|
|
55
66
|
* Dispatch swarm via a host adapter.
|
|
56
67
|
* This is the host-agnostic version — adapters implement the actual spawning.
|
|
57
68
|
*/
|
|
58
|
-
export async function dispatchSwarm(proposal, agents, adapter, maxConcurrent, onUpdate) {
|
|
59
|
-
const instructions = buildDispatchInstructions(proposal, agents);
|
|
69
|
+
export async function dispatchSwarm(proposal, agents, adapter, maxConcurrent, modelContext, onUpdate) {
|
|
70
|
+
const instructions = buildDispatchInstructions(proposal, agents, modelContext);
|
|
60
71
|
const outputs = [];
|
|
61
72
|
// Process in batches based on maxConcurrent
|
|
62
73
|
for (let i = 0; i < instructions.length; i += maxConcurrent) {
|
|
@@ -75,6 +86,7 @@ export async function dispatchSwarm(proposal, agents, adapter, maxConcurrent, on
|
|
|
75
86
|
agent,
|
|
76
87
|
proposal,
|
|
77
88
|
systemPrompt: inst.prompt,
|
|
89
|
+
model: inst.model,
|
|
78
90
|
timeoutMs: inst.timeoutMs,
|
|
79
91
|
});
|
|
80
92
|
outputs.push(output);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swarm.js","sourceRoot":"","sources":["../../src/intelligence/swarm.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,kCAAkC;AAClC,+DAA+D;
|
|
1
|
+
{"version":3,"file":"swarm.js","sourceRoot":"","sources":["../../src/intelligence/swarm.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,kCAAkC;AAClC,+DAA+D;AAG/D,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,EAEvB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAmBpB;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CACvC,QAAkB,EAClB,MAAkB,EAClB,YAAoC;IAEpC,MAAM,UAAU,GAAG;;eAEN,QAAQ,CAAC,EAAE,KAAK,QAAQ,CAAC,KAAK;YACjC,QAAQ,CAAC,IAAI;;EAEvB,QAAQ,CAAC,WAAW;;EAEpB,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,2BAA2B,QAAQ,CAAC,gBAAgB,MAAM,CAAC,CAAC,CAAC,EAAE;EAC3F,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,iBAAiB,QAAQ,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE;EAE/D,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,QAAQ,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC;QAClF,CAAC,CAAC,6BAA6B,QAAQ,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,KAAK,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAA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OAAO,WAAW,CAAC;YACrB,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type LogLevel = "info" | "warn" | "error" | "debug";
|
|
2
|
+
export type LogHandler = (level: LogLevel, message: string, ...args: unknown[]) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Configure the global log handler.
|
|
5
|
+
* Set to null to disable logging.
|
|
6
|
+
*/
|
|
7
|
+
export declare function setLogHandler(handler: LogHandler | null): void;
|
|
8
|
+
export declare const logger: {
|
|
9
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
10
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
11
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
12
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=logging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../src/observability/logging.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3D,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAmBxF;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,GAAG,IAAI,CAM9D;AAED,eAAO,MAAM,MAAM;oBACD,MAAM,WAAW,OAAO,EAAE;oBAC1B,MAAM,WAAW,OAAO,EAAE;qBACzB,MAAM,WAAW,OAAO,EAAE;qBAC1B,MAAM,WAAW,OAAO,EAAE;CAC5C,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// Swarm DAO Core — Logging Utility
|
|
3
|
+
// ============================================================
|
|
4
|
+
let currentHandler = (level, message, ...args) => {
|
|
5
|
+
switch (level) {
|
|
6
|
+
case "info":
|
|
7
|
+
console.log(message, ...args);
|
|
8
|
+
break;
|
|
9
|
+
case "warn":
|
|
10
|
+
console.warn(message, ...args);
|
|
11
|
+
break;
|
|
12
|
+
case "error":
|
|
13
|
+
console.error(message, ...args);
|
|
14
|
+
break;
|
|
15
|
+
case "debug":
|
|
16
|
+
console.debug(message, ...args);
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Configure the global log handler.
|
|
22
|
+
* Set to null to disable logging.
|
|
23
|
+
*/
|
|
24
|
+
export function setLogHandler(handler) {
|
|
25
|
+
if (handler === null) {
|
|
26
|
+
currentHandler = () => { };
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
currentHandler = handler;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export const logger = {
|
|
33
|
+
info: (message, ...args) => currentHandler("info", message, ...args),
|
|
34
|
+
warn: (message, ...args) => currentHandler("warn", message, ...args),
|
|
35
|
+
error: (message, ...args) => currentHandler("error", message, ...args),
|
|
36
|
+
debug: (message, ...args) => currentHandler("debug", message, ...args),
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/observability/logging.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,mCAAmC;AACnC,+DAA+D;AAM/D,IAAI,cAAc,GAAe,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE;IAC3D,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,MAAM;YACT,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;YAC9B,MAAM;QACR,KAAK,MAAM;YACT,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;YAC/B,MAAM;QACR,KAAK,OAAO;YACV,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;YAChC,MAAM;QACR,KAAK,OAAO;YACV,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;YAChC,MAAM;IACV,CAAC;AACH,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAA0B;IACtD,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,cAAc,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;IAC5B,CAAC;SAAM,CAAC;QACN,cAAc,GAAG,OAAO,CAAC;IAC3B,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACvF,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACvF,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACzF,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAC1F,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../src/persistence.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../src/persistence.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,YAAY,EACZ,QAAQ,EAER,YAAY,EACZ,iBAAiB,EACjB,qBAAqB,EACrB,QAAQ,EACR,eAAe,EACf,cAAc,EACd,eAAe,EACf,IAAI,EACL,MAAM,kBAAkB,CAAC;AA8F1B,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAExC;AAED,wBAAgB,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MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAKxG;AAED,wBAAsB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKpE;AAID,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAIpG;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAE7E;AAID,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAI9G;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAErF;AAID,wBAAsB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/F;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAEzE;AAGD,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/persistence.js
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
// ============================================================
|
|
4
4
|
import { promises as fs } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
|
+
import { logger } from "./observability/logging.js";
|
|
6
7
|
import { recordProposalExecuted, recordVoteCast } from "./observability/metrics.js";
|
|
7
8
|
import { createInitialState } from "./types/index.js";
|
|
9
|
+
import { redactSensitiveFields, SENSITIVE_KEYS } from "./utils/security.js";
|
|
8
10
|
let state = null;
|
|
9
11
|
const STATE_FILE = "state.json";
|
|
10
12
|
const PROPOSALS_DIR = "proposals";
|
|
@@ -16,8 +18,28 @@ function isRecord(value) {
|
|
|
16
18
|
function isPositiveInteger(value) {
|
|
17
19
|
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
18
20
|
}
|
|
21
|
+
function escapeRegExp(value) {
|
|
22
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
23
|
+
}
|
|
24
|
+
function sanitizeErrorMessage(message) {
|
|
25
|
+
let sanitized = message;
|
|
26
|
+
for (const key of SENSITIVE_KEYS) {
|
|
27
|
+
const escapedKey = escapeRegExp(key);
|
|
28
|
+
const keyPattern = `(?:"|')?\\b${escapedKey}\\b(?:"|')?`;
|
|
29
|
+
const separatorPattern = "\\s*(?:=|:)\\s*";
|
|
30
|
+
const quotedValuePattern = `"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'`;
|
|
31
|
+
const bareValuePattern = "[^\\s,}\\];)\\]]+";
|
|
32
|
+
const regex = new RegExp(`(${keyPattern}${separatorPattern})(${quotedValuePattern}|${bareValuePattern})`, "gi");
|
|
33
|
+
sanitized = sanitized.replace(regex, (_match, prefix, value) => {
|
|
34
|
+
const quote = value.startsWith('"') ? '"' : value.startsWith("'") ? "'" : "";
|
|
35
|
+
return quote ? `${prefix}${quote}[REDACTED]${quote}` : `${prefix}[REDACTED]`;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return sanitized;
|
|
39
|
+
}
|
|
19
40
|
function getErrorMessage(error) {
|
|
20
|
-
|
|
41
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
42
|
+
return sanitizeErrorMessage(message);
|
|
21
43
|
}
|
|
22
44
|
function hasErrorCode(error, code) {
|
|
23
45
|
return (typeof error === "object" &&
|
|
@@ -30,8 +52,8 @@ function parseJsonText(text, context) {
|
|
|
30
52
|
try {
|
|
31
53
|
return JSON.parse(text);
|
|
32
54
|
}
|
|
33
|
-
catch (
|
|
34
|
-
throw new Error(`Invalid JSON in ${context}
|
|
55
|
+
catch (_error) {
|
|
56
|
+
throw new Error(`Invalid JSON in ${context}`);
|
|
35
57
|
}
|
|
36
58
|
}
|
|
37
59
|
function formatJson(value) {
|
|
@@ -98,34 +120,22 @@ export async function initStorage(cwd) {
|
|
|
98
120
|
return daoRoot;
|
|
99
121
|
}
|
|
100
122
|
// ── Legacy Migration ─────────────────────────────────────────
|
|
101
|
-
|
|
102
|
-
const newRoot = getDaoRoot(cwd);
|
|
103
|
-
try {
|
|
104
|
-
await fs.access(newRoot);
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
/* .dao doesn't exist */
|
|
109
|
-
}
|
|
110
|
-
let legacyRoot = null;
|
|
123
|
+
async function findLegacyRoot(cwd, legacyDirectories) {
|
|
111
124
|
for (const directory of legacyDirectories) {
|
|
112
125
|
const candidate = resolveSafeLegacyDirectory(cwd, directory);
|
|
113
126
|
if (!candidate)
|
|
114
127
|
continue;
|
|
115
128
|
try {
|
|
116
129
|
await fs.access(candidate);
|
|
117
|
-
|
|
118
|
-
break;
|
|
130
|
+
return candidate;
|
|
119
131
|
}
|
|
120
132
|
catch {
|
|
121
133
|
/* candidate doesn't exist */
|
|
122
134
|
}
|
|
123
135
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
console.log("🔄 Migrating DAO storage: legacy directory → .dao");
|
|
128
|
-
await fs.mkdir(newRoot, { recursive: true });
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
async function copyLegacyFiles(legacyRoot, newRoot) {
|
|
129
139
|
const entries = await fs.readdir(legacyRoot, { withFileTypes: true });
|
|
130
140
|
await Promise.all(entries.map(async (entry) => {
|
|
131
141
|
const srcPath = path.join(legacyRoot, entry.name);
|
|
@@ -138,17 +148,8 @@ export async function migrateFromLegacy(cwd, legacyDirectories = []) {
|
|
|
138
148
|
}
|
|
139
149
|
await fs.copyFile(srcPath, destPath);
|
|
140
150
|
}));
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
await fs.access(oldStatePath);
|
|
145
|
-
await fs.rename(oldStatePath, newStatePath);
|
|
146
|
-
console.log(" ✓ Renamed dao-state.json → state.json");
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
149
|
-
/* no old state */
|
|
150
|
-
}
|
|
151
|
-
// Migrate proposal IDs to 3-digit padding
|
|
151
|
+
}
|
|
152
|
+
async function migrateProposalIdPaddings(newRoot) {
|
|
152
153
|
try {
|
|
153
154
|
const proposalsDir = getProposalsDir(newRoot);
|
|
154
155
|
const files = await fs.readdir(proposalsDir);
|
|
@@ -162,20 +163,48 @@ export async function migrateFromLegacy(cwd, legacyDirectories = []) {
|
|
|
162
163
|
const paddedName = `${padId(id)}.json`;
|
|
163
164
|
if (file !== paddedName) {
|
|
164
165
|
await fs.rename(path.join(proposalsDir, file), path.join(proposalsDir, paddedName));
|
|
165
|
-
|
|
166
|
+
logger.info(` ✓ Renamed ${file} → ${paddedName}`);
|
|
166
167
|
}
|
|
167
168
|
}));
|
|
168
169
|
}
|
|
169
170
|
catch {
|
|
170
171
|
/* no proposals yet */
|
|
171
172
|
}
|
|
172
|
-
|
|
173
|
+
}
|
|
174
|
+
export async function migrateFromLegacy(cwd, legacyDirectories = []) {
|
|
175
|
+
const newRoot = getDaoRoot(cwd);
|
|
176
|
+
try {
|
|
177
|
+
await fs.access(newRoot);
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
/* .dao doesn't exist */
|
|
182
|
+
}
|
|
183
|
+
const legacyRoot = await findLegacyRoot(cwd, legacyDirectories);
|
|
184
|
+
if (!legacyRoot) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
logger.info("🔄 Migrating DAO storage: legacy directory → .dao");
|
|
188
|
+
await fs.mkdir(newRoot, { recursive: true });
|
|
189
|
+
await copyLegacyFiles(legacyRoot, newRoot);
|
|
190
|
+
const oldStatePath = path.join(newRoot, "dao-state.json");
|
|
191
|
+
const newStatePath = path.join(newRoot, STATE_FILE);
|
|
192
|
+
try {
|
|
193
|
+
await fs.access(oldStatePath);
|
|
194
|
+
await fs.rename(oldStatePath, newStatePath);
|
|
195
|
+
logger.info(" ✓ Renamed dao-state.json → state.json");
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
/* no old state */
|
|
199
|
+
}
|
|
200
|
+
await migrateProposalIdPaddings(newRoot);
|
|
201
|
+
logger.info(" ✓ Migration complete");
|
|
173
202
|
try {
|
|
174
203
|
await fs.rm(legacyRoot, { recursive: true, force: true });
|
|
175
|
-
|
|
204
|
+
logger.info(" ✓ Removed legacy DAO directory");
|
|
176
205
|
}
|
|
177
206
|
catch (err) {
|
|
178
|
-
|
|
207
|
+
logger.warn(" ⚠ Could not remove legacy DAO directory:", err);
|
|
179
208
|
}
|
|
180
209
|
return true;
|
|
181
210
|
}
|
|
@@ -251,7 +280,7 @@ export async function loadState(cwd, options) {
|
|
|
251
280
|
}
|
|
252
281
|
}
|
|
253
282
|
catch (error) {
|
|
254
|
-
|
|
283
|
+
logger.warn(`⚠ Failed to reconcile proposal sidecars: ${getErrorMessage(error)}`);
|
|
255
284
|
}
|
|
256
285
|
const highestProposalId = loaded.proposals.reduce((max, proposal) => Math.max(max, proposal.id), 0);
|
|
257
286
|
if (loaded.nextProposalId <= highestProposalId)
|
|
@@ -283,7 +312,7 @@ export async function loadProposalsFromDisk(daoRoot) {
|
|
|
283
312
|
return isPositiveInteger(proposal?.id) ? proposal : null;
|
|
284
313
|
}
|
|
285
314
|
catch (error) {
|
|
286
|
-
|
|
315
|
+
logger.warn(`⚠ Skipping malformed proposal sidecar ${filePath}: ${getErrorMessage(error)}`);
|
|
287
316
|
return null;
|
|
288
317
|
}
|
|
289
318
|
}));
|
|
@@ -330,7 +359,7 @@ export async function saveState() {
|
|
|
330
359
|
catch (error) {
|
|
331
360
|
if (hasErrorCode(error, "ENOENT"))
|
|
332
361
|
return;
|
|
333
|
-
|
|
362
|
+
logger.warn(`⚠ Failed to remove orphan proposal sidecar ${orphanPath}: ${getErrorMessage(error)}`);
|
|
334
363
|
}
|
|
335
364
|
}));
|
|
336
365
|
}
|
|
@@ -388,11 +417,12 @@ export async function updateStorageSettings(daoRoot, updates) {
|
|
|
388
417
|
}
|
|
389
418
|
catch (error) {
|
|
390
419
|
if (!hasErrorCode(error, "ENOENT")) {
|
|
391
|
-
|
|
420
|
+
logger.warn(`⚠ Ignoring invalid storage config at ${configPath}: ${getErrorMessage(error)}`);
|
|
392
421
|
}
|
|
393
422
|
}
|
|
394
423
|
rootConfig.storageSettings = next;
|
|
395
|
-
|
|
424
|
+
const redacted = redactSensitiveFields(rootConfig);
|
|
425
|
+
await writeJsonFile(configPath, redacted);
|
|
396
426
|
return next;
|
|
397
427
|
}
|
|
398
428
|
// ── Agent CRUD ───────────────────────────────────────────────
|