opencode-swarm 7.34.0 → 7.36.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/agents/agent-output-schema.d.ts +9 -1
- package/dist/cli/index.js +403 -7
- package/dist/index.js +3682 -2238
- package/dist/memory/curator-decision-helpers.d.ts +14 -0
- package/dist/memory/gateway.d.ts +5 -1
- package/dist/memory/index.d.ts +2 -2
- package/dist/memory/injector.d.ts +1 -1
- package/dist/memory/local-jsonl-provider.d.ts +4 -1
- package/dist/memory/provider.d.ts +2 -1
- package/dist/memory/run-log.d.ts +1 -1
- package/dist/memory/schema.d.ts +5 -1
- package/dist/memory/sqlite-provider.d.ts +6 -1
- package/dist/memory/types.d.ts +74 -0
- package/dist/sandbox/capability-probe.d.ts +55 -0
- package/dist/sandbox/executor.d.ts +51 -0
- package/dist/sandbox/executors/bubblewrap.d.ts +1 -0
- package/dist/sandbox/executors/macos.d.ts +1 -0
- package/dist/sandbox/executors/windows.d.ts +1 -0
- package/dist/sandbox/linux/bubblewrap-executor.d.ts +79 -0
- package/dist/sandbox/linux/edge-cases.d.ts +89 -0
- package/dist/sandbox/macos/edge-cases.d.ts +89 -0
- package/dist/sandbox/macos/sandbox-exec-executor.d.ts +68 -0
- package/dist/sandbox/scope-resolver.d.ts +32 -0
- package/dist/sandbox/win32/edge-cases.d.ts +90 -0
- package/dist/sandbox/win32/restricted-token-executor.d.ts +94 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { ProposeMemoryInput } from '../memory
|
|
2
|
+
import type { CuratorMemoryDecision, ProposeMemoryInput } from '../memory';
|
|
3
3
|
export declare const AgentOutputMemorySchema: z.ZodObject<{
|
|
4
4
|
memoryProposals: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
5
5
|
operation: z.ZodEnum<{
|
|
@@ -31,8 +31,16 @@ export declare const AgentOutputMemorySchema: z.ZodObject<{
|
|
|
31
31
|
evidenceRefs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
32
32
|
}, z.core.$strict>>>;
|
|
33
33
|
}, z.core.$loose>;
|
|
34
|
+
export declare const CuratorOutputMemoryDecisionSchema: z.ZodObject<{
|
|
35
|
+
curatorMemoryDecisions: z.ZodOptional<z.ZodArray<z.ZodType<CuratorMemoryDecision, unknown, z.core.$ZodTypeInternals<CuratorMemoryDecision, unknown>>>>;
|
|
36
|
+
}, z.core.$loose>;
|
|
34
37
|
export interface ExtractedAgentMemoryProposals {
|
|
35
38
|
proposals: ProposeMemoryInput[];
|
|
36
39
|
error?: string;
|
|
37
40
|
}
|
|
41
|
+
export interface ExtractedCuratorMemoryDecisions {
|
|
42
|
+
decisions: CuratorMemoryDecision[];
|
|
43
|
+
error?: string;
|
|
44
|
+
}
|
|
38
45
|
export declare function extractMemoryProposalsFromAgentOutput(outputText: string): ExtractedAgentMemoryProposals;
|
|
46
|
+
export declare function extractCuratorMemoryDecisionsFromAgentOutput(outputText: string): ExtractedCuratorMemoryDecisions;
|
package/dist/cli/index.js
CHANGED
|
@@ -34,7 +34,7 @@ var package_default;
|
|
|
34
34
|
var init_package = __esm(() => {
|
|
35
35
|
package_default = {
|
|
36
36
|
name: "opencode-swarm",
|
|
37
|
-
version: "7.
|
|
37
|
+
version: "7.36.0",
|
|
38
38
|
description: "Architect-centric agentic swarm plugin for OpenCode - hub-and-spoke orchestration with SME consultation, code generation, and QA review",
|
|
39
39
|
main: "dist/index.js",
|
|
40
40
|
types: "dist/index.d.ts",
|
|
@@ -21402,6 +21402,12 @@ var init_shell_write_detect = __esm(() => {
|
|
|
21402
21402
|
]);
|
|
21403
21403
|
});
|
|
21404
21404
|
|
|
21405
|
+
// src/sandbox/executor.ts
|
|
21406
|
+
var init_executor = () => {};
|
|
21407
|
+
|
|
21408
|
+
// src/sandbox/scope-resolver.ts
|
|
21409
|
+
var init_scope_resolver = () => {};
|
|
21410
|
+
|
|
21405
21411
|
// src/hooks/conflict-resolution.ts
|
|
21406
21412
|
var init_conflict_resolution = __esm(() => {
|
|
21407
21413
|
init_state();
|
|
@@ -21477,6 +21483,8 @@ var init_guardrails = __esm(() => {
|
|
|
21477
21483
|
init_telemetry();
|
|
21478
21484
|
init_utils();
|
|
21479
21485
|
init_shell_write_detect();
|
|
21486
|
+
init_executor();
|
|
21487
|
+
init_scope_resolver();
|
|
21480
21488
|
init_bun_compat();
|
|
21481
21489
|
init_logger();
|
|
21482
21490
|
init_conflict_resolution();
|
|
@@ -45465,7 +45473,7 @@ function validateMemoryRecordRules(record3, options) {
|
|
|
45465
45473
|
function validateMemoryProposal(proposal) {
|
|
45466
45474
|
return MemoryProposalSchema.parse(proposal);
|
|
45467
45475
|
}
|
|
45468
|
-
var MemoryScopeTypeSchema, MemoryScopeRefSchema, MemoryKindSchema, MemorySourceSchema, MemoryRecordSchema, MemoryProposalSchema;
|
|
45476
|
+
var MemoryScopeTypeSchema, MemoryScopeRefSchema, MemoryKindSchema, MemorySourceSchema, MemoryRecordSchema, MemoryProposalSchema, NewMemoryRecordSchema, MemoryPatchSchema, ProposalIdSchema, MemoryIdSchema, CuratorDecisionReasonSchema, CuratorMemoryDecisionSchema;
|
|
45469
45477
|
var init_schema2 = __esm(() => {
|
|
45470
45478
|
init_zod();
|
|
45471
45479
|
init_config3();
|
|
@@ -45572,6 +45580,138 @@ var init_schema2 = __esm(() => {
|
|
|
45572
45580
|
createdAt: exports_external.string().datetime(),
|
|
45573
45581
|
metadata: exports_external.record(exports_external.string(), exports_external.unknown())
|
|
45574
45582
|
}).strict();
|
|
45583
|
+
NewMemoryRecordSchema = exports_external.object({
|
|
45584
|
+
scope: MemoryScopeRefSchema.optional(),
|
|
45585
|
+
kind: MemoryKindSchema,
|
|
45586
|
+
text: exports_external.string().min(1).max(2000),
|
|
45587
|
+
tags: exports_external.array(exports_external.string().min(1).max(64)).max(32).optional(),
|
|
45588
|
+
confidence: exports_external.number().min(0).max(1).optional(),
|
|
45589
|
+
stability: exports_external.enum(["ephemeral", "session", "durable"]).optional(),
|
|
45590
|
+
source: MemorySourceSchema.optional(),
|
|
45591
|
+
expiresAt: exports_external.string().datetime().optional(),
|
|
45592
|
+
metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
|
|
45593
|
+
}).strict();
|
|
45594
|
+
MemoryPatchSchema = exports_external.object({
|
|
45595
|
+
scope: MemoryScopeRefSchema.optional(),
|
|
45596
|
+
kind: MemoryKindSchema.optional(),
|
|
45597
|
+
text: exports_external.string().min(1).max(2000).optional(),
|
|
45598
|
+
tags: exports_external.array(exports_external.string().min(1).max(64)).max(32).optional(),
|
|
45599
|
+
confidence: exports_external.number().min(0).max(1).optional(),
|
|
45600
|
+
stability: exports_external.enum(["ephemeral", "session", "durable"]).optional(),
|
|
45601
|
+
source: MemorySourceSchema.optional(),
|
|
45602
|
+
expiresAt: exports_external.string().datetime().optional(),
|
|
45603
|
+
metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
|
|
45604
|
+
}).strict().refine((patch) => Object.keys(patch).length > 0, {
|
|
45605
|
+
message: "memory patch must not be empty"
|
|
45606
|
+
});
|
|
45607
|
+
ProposalIdSchema = exports_external.string().regex(/^prop_[a-f0-9]{16}$/);
|
|
45608
|
+
MemoryIdSchema = exports_external.string().regex(/^mem_[a-f0-9]{16}$/);
|
|
45609
|
+
CuratorDecisionReasonSchema = exports_external.string().min(1).max(2000);
|
|
45610
|
+
CuratorMemoryDecisionSchema = exports_external.discriminatedUnion("action", [
|
|
45611
|
+
exports_external.object({
|
|
45612
|
+
action: exports_external.literal("add"),
|
|
45613
|
+
proposalId: ProposalIdSchema,
|
|
45614
|
+
memory: NewMemoryRecordSchema
|
|
45615
|
+
}).strict(),
|
|
45616
|
+
exports_external.object({
|
|
45617
|
+
action: exports_external.literal("update"),
|
|
45618
|
+
proposalId: ProposalIdSchema,
|
|
45619
|
+
targetMemoryId: MemoryIdSchema,
|
|
45620
|
+
patch: MemoryPatchSchema,
|
|
45621
|
+
reason: CuratorDecisionReasonSchema
|
|
45622
|
+
}).strict(),
|
|
45623
|
+
exports_external.object({
|
|
45624
|
+
action: exports_external.literal("supersede"),
|
|
45625
|
+
proposalId: ProposalIdSchema,
|
|
45626
|
+
oldMemoryId: MemoryIdSchema,
|
|
45627
|
+
replacement: NewMemoryRecordSchema,
|
|
45628
|
+
reason: CuratorDecisionReasonSchema
|
|
45629
|
+
}).strict(),
|
|
45630
|
+
exports_external.object({
|
|
45631
|
+
action: exports_external.literal("reject"),
|
|
45632
|
+
proposalId: ProposalIdSchema,
|
|
45633
|
+
reason: CuratorDecisionReasonSchema
|
|
45634
|
+
}).strict(),
|
|
45635
|
+
exports_external.object({
|
|
45636
|
+
action: exports_external.literal("noop"),
|
|
45637
|
+
proposalId: ProposalIdSchema,
|
|
45638
|
+
reason: CuratorDecisionReasonSchema
|
|
45639
|
+
}).strict()
|
|
45640
|
+
]);
|
|
45641
|
+
});
|
|
45642
|
+
|
|
45643
|
+
// src/memory/curator-decision-helpers.ts
|
|
45644
|
+
function validateDecisionMatchesProposal(decision, proposal) {
|
|
45645
|
+
if (decision.action === "add" && proposal.operation !== "add" || decision.action === "update" && proposal.operation !== "update" || decision.action === "supersede" && proposal.operation !== "supersede") {
|
|
45646
|
+
throw new MemoryValidationError(`curator ${decision.action} decision does not match ${proposal.operation} proposal`);
|
|
45647
|
+
}
|
|
45648
|
+
if (decision.action === "update" && proposal.targetMemoryId && proposal.targetMemoryId !== decision.targetMemoryId) {
|
|
45649
|
+
throw new MemoryValidationError("curator update decision target does not match proposal target");
|
|
45650
|
+
}
|
|
45651
|
+
if (decision.action === "supersede" && proposal.targetMemoryId && proposal.targetMemoryId !== decision.oldMemoryId) {
|
|
45652
|
+
throw new MemoryValidationError("curator supersede decision target does not match proposal target");
|
|
45653
|
+
}
|
|
45654
|
+
}
|
|
45655
|
+
function applyPatchToMemory(existing, patch, updatedAt) {
|
|
45656
|
+
const base = {
|
|
45657
|
+
scope: patch.scope ?? existing.scope,
|
|
45658
|
+
kind: patch.kind ?? existing.kind,
|
|
45659
|
+
text: patch.text === undefined ? existing.text : normalizeMemoryText(patch.text)
|
|
45660
|
+
};
|
|
45661
|
+
const tags = patch.tags === undefined ? existing.tags : normalizeTags(patch.tags);
|
|
45662
|
+
return {
|
|
45663
|
+
...existing,
|
|
45664
|
+
...patch,
|
|
45665
|
+
...base,
|
|
45666
|
+
id: createMemoryId(base),
|
|
45667
|
+
tags,
|
|
45668
|
+
updatedAt,
|
|
45669
|
+
contentHash: computeMemoryContentHash(base),
|
|
45670
|
+
metadata: patch.metadata === undefined ? existing.metadata : { ...existing.metadata, ...patch.metadata }
|
|
45671
|
+
};
|
|
45672
|
+
}
|
|
45673
|
+
function markProposalReviewed(proposal, decision, status, reviewedAt, ids) {
|
|
45674
|
+
const reason = curatorDecisionReason(decision);
|
|
45675
|
+
return validateMemoryProposal({
|
|
45676
|
+
...proposal,
|
|
45677
|
+
status,
|
|
45678
|
+
reviewer: "curator_agent",
|
|
45679
|
+
reviewedAt,
|
|
45680
|
+
rejectionReason: decision.action === "reject" ? reason : undefined,
|
|
45681
|
+
metadata: {
|
|
45682
|
+
...proposal.metadata,
|
|
45683
|
+
curatorDecision: {
|
|
45684
|
+
action: decision.action,
|
|
45685
|
+
reason,
|
|
45686
|
+
...ids,
|
|
45687
|
+
appliedAt: reviewedAt
|
|
45688
|
+
}
|
|
45689
|
+
}
|
|
45690
|
+
});
|
|
45691
|
+
}
|
|
45692
|
+
function curatorDecisionReason(decision) {
|
|
45693
|
+
switch (decision.action) {
|
|
45694
|
+
case "add":
|
|
45695
|
+
return;
|
|
45696
|
+
case "update":
|
|
45697
|
+
case "supersede":
|
|
45698
|
+
case "reject":
|
|
45699
|
+
case "noop":
|
|
45700
|
+
return decision.reason;
|
|
45701
|
+
}
|
|
45702
|
+
}
|
|
45703
|
+
function buildCuratorDecisionEvent(change, proposal) {
|
|
45704
|
+
return {
|
|
45705
|
+
...change,
|
|
45706
|
+
proposalOperation: proposal.operation
|
|
45707
|
+
};
|
|
45708
|
+
}
|
|
45709
|
+
function normalizeTags(tags) {
|
|
45710
|
+
return Array.from(new Set(tags.map((tag) => tag.toLowerCase().replace(/[^\w-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "")).filter(Boolean))).slice(0, 32);
|
|
45711
|
+
}
|
|
45712
|
+
var init_curator_decision_helpers = __esm(() => {
|
|
45713
|
+
init_errors6();
|
|
45714
|
+
init_schema2();
|
|
45575
45715
|
});
|
|
45576
45716
|
|
|
45577
45717
|
// src/memory/scoring.ts
|
|
@@ -45887,21 +46027,126 @@ class LocalJsonlMemoryProvider {
|
|
|
45887
46027
|
proposals.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
45888
46028
|
return proposals.slice(0, filter.limit ?? proposals.length);
|
|
45889
46029
|
}
|
|
46030
|
+
async applyCuratorDecision(decision) {
|
|
46031
|
+
await this.initialize();
|
|
46032
|
+
const appliedAt = new Date().toISOString();
|
|
46033
|
+
const proposal = this.proposals.get(decision.proposalId);
|
|
46034
|
+
if (!proposal) {
|
|
46035
|
+
throw new MemoryValidationError("memory proposal was not found");
|
|
46036
|
+
}
|
|
46037
|
+
if (proposal.status !== "pending") {
|
|
46038
|
+
throw new MemoryValidationError("memory proposal is not pending");
|
|
46039
|
+
}
|
|
46040
|
+
validateDecisionMatchesProposal(decision, proposal);
|
|
46041
|
+
let memoryId;
|
|
46042
|
+
let targetMemoryId;
|
|
46043
|
+
let oldMemoryId;
|
|
46044
|
+
let replacementMemoryId;
|
|
46045
|
+
if (decision.action === "add") {
|
|
46046
|
+
const memory = this.validateDecisionMemory({
|
|
46047
|
+
...decision.memory,
|
|
46048
|
+
updatedAt: appliedAt
|
|
46049
|
+
});
|
|
46050
|
+
this.memories.set(memory.id, memory);
|
|
46051
|
+
await appendJsonl(this.pathFor("memories"), memory);
|
|
46052
|
+
memoryId = memory.id;
|
|
46053
|
+
} else if (decision.action === "update") {
|
|
46054
|
+
const existing = this.activeMemory(decision.targetMemoryId);
|
|
46055
|
+
const updated = this.validateDecisionMemory(applyPatchToMemory(existing, decision.patch, appliedAt));
|
|
46056
|
+
if (updated.id !== existing.id) {
|
|
46057
|
+
const tombstone = this.validateDecisionMemory({
|
|
46058
|
+
...existing,
|
|
46059
|
+
updatedAt: appliedAt,
|
|
46060
|
+
metadata: {
|
|
46061
|
+
...existing.metadata,
|
|
46062
|
+
deleted: true,
|
|
46063
|
+
deleteReason: decision.reason,
|
|
46064
|
+
updateReplacementId: updated.id
|
|
46065
|
+
}
|
|
46066
|
+
});
|
|
46067
|
+
this.memories.set(tombstone.id, tombstone);
|
|
46068
|
+
await appendJsonl(this.pathFor("memories"), tombstone);
|
|
46069
|
+
}
|
|
46070
|
+
this.memories.set(updated.id, updated);
|
|
46071
|
+
await appendJsonl(this.pathFor("memories"), updated);
|
|
46072
|
+
memoryId = updated.id;
|
|
46073
|
+
targetMemoryId = existing.id;
|
|
46074
|
+
} else if (decision.action === "supersede") {
|
|
46075
|
+
const oldMemory = this.activeMemory(decision.oldMemoryId);
|
|
46076
|
+
const replacement = this.validateDecisionMemory({
|
|
46077
|
+
...decision.replacement,
|
|
46078
|
+
updatedAt: appliedAt,
|
|
46079
|
+
supersedes: Array.from(new Set([...decision.replacement.supersedes ?? [], oldMemory.id]))
|
|
46080
|
+
});
|
|
46081
|
+
const superseded = this.validateDecisionMemory({
|
|
46082
|
+
...oldMemory,
|
|
46083
|
+
updatedAt: appliedAt,
|
|
46084
|
+
supersededBy: replacement.id,
|
|
46085
|
+
metadata: {
|
|
46086
|
+
...oldMemory.metadata,
|
|
46087
|
+
supersedeReason: decision.reason
|
|
46088
|
+
}
|
|
46089
|
+
});
|
|
46090
|
+
this.memories.set(superseded.id, superseded);
|
|
46091
|
+
this.memories.set(replacement.id, replacement);
|
|
46092
|
+
await appendJsonl(this.pathFor("memories"), superseded);
|
|
46093
|
+
await appendJsonl(this.pathFor("memories"), replacement);
|
|
46094
|
+
oldMemoryId = oldMemory.id;
|
|
46095
|
+
replacementMemoryId = replacement.id;
|
|
46096
|
+
memoryId = replacement.id;
|
|
46097
|
+
}
|
|
46098
|
+
const proposalStatus = decision.action === "reject" ? "rejected" : "applied";
|
|
46099
|
+
const reviewedProposal = markProposalReviewed(proposal, decision, proposalStatus, appliedAt, { memoryId, targetMemoryId, oldMemoryId, replacementMemoryId });
|
|
46100
|
+
this.proposals.set(reviewedProposal.id, reviewedProposal);
|
|
46101
|
+
await appendJsonl(this.pathFor("proposals"), reviewedProposal);
|
|
46102
|
+
const change = {
|
|
46103
|
+
action: decision.action,
|
|
46104
|
+
proposalId: decision.proposalId,
|
|
46105
|
+
proposalStatus,
|
|
46106
|
+
appliedAt,
|
|
46107
|
+
memoryId,
|
|
46108
|
+
targetMemoryId,
|
|
46109
|
+
oldMemoryId,
|
|
46110
|
+
replacementMemoryId,
|
|
46111
|
+
reason: curatorDecisionReason(decision)
|
|
46112
|
+
};
|
|
46113
|
+
await this.audit("curator_decision", decision.proposalId, change.reason, buildCuratorDecisionEvent(change, proposal));
|
|
46114
|
+
return change;
|
|
46115
|
+
}
|
|
45890
46116
|
async compact() {
|
|
45891
46117
|
await this.initialize();
|
|
45892
46118
|
await writeJsonlAtomic(this.pathFor("memories"), Array.from(this.memories.values()));
|
|
45893
46119
|
await this.audit("compact", "memories");
|
|
45894
46120
|
}
|
|
45895
|
-
async audit(operation, targetId, reason) {
|
|
46121
|
+
async audit(operation, targetId, reason, eventJson) {
|
|
45896
46122
|
const event = {
|
|
45897
46123
|
id: randomUUID3(),
|
|
45898
46124
|
operation,
|
|
45899
46125
|
targetId,
|
|
45900
46126
|
reason,
|
|
46127
|
+
eventJson,
|
|
45901
46128
|
timestamp: new Date().toISOString()
|
|
45902
46129
|
};
|
|
45903
46130
|
await appendJsonl(this.pathFor("audit"), event);
|
|
45904
46131
|
}
|
|
46132
|
+
activeMemory(memoryId) {
|
|
46133
|
+
const memory = this.memories.get(memoryId);
|
|
46134
|
+
if (!memory) {
|
|
46135
|
+
throw new MemoryValidationError("target memory was not found");
|
|
46136
|
+
}
|
|
46137
|
+
if (memory.metadata.deleted === true) {
|
|
46138
|
+
throw new MemoryValidationError("target memory is deleted");
|
|
46139
|
+
}
|
|
46140
|
+
if (memory.supersededBy) {
|
|
46141
|
+
throw new MemoryValidationError("target memory is superseded");
|
|
46142
|
+
}
|
|
46143
|
+
return memory;
|
|
46144
|
+
}
|
|
46145
|
+
validateDecisionMemory(record3) {
|
|
46146
|
+
return validateMemoryRecordRules(record3, {
|
|
46147
|
+
rejectDurableSecrets: this.config.redaction.rejectDurableSecrets
|
|
46148
|
+
});
|
|
46149
|
+
}
|
|
45905
46150
|
}
|
|
45906
46151
|
function validateLoadedMemories(values, config3) {
|
|
45907
46152
|
const records = [];
|
|
@@ -45968,6 +46213,7 @@ async function writeJsonlAtomic(filePath, values) {
|
|
|
45968
46213
|
var init_local_jsonl_provider = __esm(() => {
|
|
45969
46214
|
init_utils2();
|
|
45970
46215
|
init_config3();
|
|
46216
|
+
init_curator_decision_helpers();
|
|
45971
46217
|
init_errors6();
|
|
45972
46218
|
init_schema2();
|
|
45973
46219
|
init_scoring();
|
|
@@ -46370,6 +46616,33 @@ class SQLiteMemoryProvider {
|
|
|
46370
46616
|
proposals.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
46371
46617
|
return proposals.slice(0, filter.limit ?? proposals.length);
|
|
46372
46618
|
}
|
|
46619
|
+
async applyCuratorDecision(decision) {
|
|
46620
|
+
await this.initialize();
|
|
46621
|
+
const db = this.requireDb();
|
|
46622
|
+
const apply = db.transaction(() => {
|
|
46623
|
+
const appliedAt = new Date().toISOString();
|
|
46624
|
+
const proposal = this.readPendingProposal(decision.proposalId);
|
|
46625
|
+
validateDecisionMatchesProposal(decision, proposal);
|
|
46626
|
+
const result2 = this.applyDecisionToStorage(decision, proposal, appliedAt);
|
|
46627
|
+
this.writeProposal(result2.proposal);
|
|
46628
|
+
const eventId = randomUUID4();
|
|
46629
|
+
const eventJson = JSON.stringify(buildCuratorDecisionEvent(result2.change, proposal));
|
|
46630
|
+
this.insertEvent("curator_decision", decision.proposalId, result2.change.reason, eventJson, eventId);
|
|
46631
|
+
return {
|
|
46632
|
+
...result2,
|
|
46633
|
+
change: { ...result2.change, eventId }
|
|
46634
|
+
};
|
|
46635
|
+
});
|
|
46636
|
+
const result = apply();
|
|
46637
|
+
this.proposals.set(result.proposal.id, result.proposal);
|
|
46638
|
+
for (const id of result.removeMemoryIds) {
|
|
46639
|
+
this.memories.delete(id);
|
|
46640
|
+
}
|
|
46641
|
+
for (const memory of result.memories) {
|
|
46642
|
+
this.memories.set(memory.id, memory);
|
|
46643
|
+
}
|
|
46644
|
+
return result.change;
|
|
46645
|
+
}
|
|
46373
46646
|
close() {
|
|
46374
46647
|
if (!this.db)
|
|
46375
46648
|
return;
|
|
@@ -46497,6 +46770,125 @@ class SQLiteMemoryProvider {
|
|
|
46497
46770
|
JSON.stringify(proposal)
|
|
46498
46771
|
]);
|
|
46499
46772
|
}
|
|
46773
|
+
applyDecisionToStorage(decision, proposal, appliedAt) {
|
|
46774
|
+
const memories = [];
|
|
46775
|
+
const removeMemoryIds = [];
|
|
46776
|
+
let memoryId;
|
|
46777
|
+
let targetMemoryId;
|
|
46778
|
+
let oldMemoryId;
|
|
46779
|
+
let replacementMemoryId;
|
|
46780
|
+
if (decision.action === "add") {
|
|
46781
|
+
const memory = this.validateDecisionMemory({
|
|
46782
|
+
...decision.memory,
|
|
46783
|
+
updatedAt: appliedAt
|
|
46784
|
+
});
|
|
46785
|
+
this.writeMemory(memory);
|
|
46786
|
+
memories.push(memory);
|
|
46787
|
+
memoryId = memory.id;
|
|
46788
|
+
} else if (decision.action === "update") {
|
|
46789
|
+
const existing = this.readActiveMemory(decision.targetMemoryId);
|
|
46790
|
+
const updated = this.validateDecisionMemory(applyPatchToMemory(existing, decision.patch, appliedAt));
|
|
46791
|
+
if (updated.id !== existing.id) {
|
|
46792
|
+
const tombstone = this.validateDecisionMemory({
|
|
46793
|
+
...existing,
|
|
46794
|
+
updatedAt: appliedAt,
|
|
46795
|
+
metadata: {
|
|
46796
|
+
...existing.metadata,
|
|
46797
|
+
deleted: true,
|
|
46798
|
+
deleteReason: decision.reason,
|
|
46799
|
+
updateReplacementId: updated.id
|
|
46800
|
+
}
|
|
46801
|
+
});
|
|
46802
|
+
this.writeMemory(tombstone);
|
|
46803
|
+
memories.push(tombstone);
|
|
46804
|
+
}
|
|
46805
|
+
this.writeMemory(updated);
|
|
46806
|
+
memories.push(updated);
|
|
46807
|
+
memoryId = updated.id;
|
|
46808
|
+
targetMemoryId = existing.id;
|
|
46809
|
+
} else if (decision.action === "supersede") {
|
|
46810
|
+
const oldMemory = this.readActiveMemory(decision.oldMemoryId);
|
|
46811
|
+
const replacement = this.validateDecisionMemory({
|
|
46812
|
+
...decision.replacement,
|
|
46813
|
+
updatedAt: appliedAt,
|
|
46814
|
+
supersedes: Array.from(new Set([...decision.replacement.supersedes ?? [], oldMemory.id]))
|
|
46815
|
+
});
|
|
46816
|
+
const superseded = this.validateDecisionMemory({
|
|
46817
|
+
...oldMemory,
|
|
46818
|
+
updatedAt: appliedAt,
|
|
46819
|
+
supersededBy: replacement.id,
|
|
46820
|
+
metadata: {
|
|
46821
|
+
...oldMemory.metadata,
|
|
46822
|
+
supersedeReason: decision.reason
|
|
46823
|
+
}
|
|
46824
|
+
});
|
|
46825
|
+
this.writeMemory(superseded);
|
|
46826
|
+
this.writeMemory(replacement);
|
|
46827
|
+
memories.push(superseded, replacement);
|
|
46828
|
+
oldMemoryId = oldMemory.id;
|
|
46829
|
+
replacementMemoryId = replacement.id;
|
|
46830
|
+
memoryId = replacement.id;
|
|
46831
|
+
}
|
|
46832
|
+
const proposalStatus = decision.action === "reject" ? "rejected" : "applied";
|
|
46833
|
+
const reviewedProposal = markProposalReviewed(proposal, decision, proposalStatus, appliedAt, {
|
|
46834
|
+
memoryId,
|
|
46835
|
+
targetMemoryId,
|
|
46836
|
+
oldMemoryId,
|
|
46837
|
+
replacementMemoryId
|
|
46838
|
+
});
|
|
46839
|
+
const change = {
|
|
46840
|
+
action: decision.action,
|
|
46841
|
+
proposalId: decision.proposalId,
|
|
46842
|
+
proposalStatus,
|
|
46843
|
+
appliedAt,
|
|
46844
|
+
memoryId,
|
|
46845
|
+
targetMemoryId,
|
|
46846
|
+
oldMemoryId,
|
|
46847
|
+
replacementMemoryId,
|
|
46848
|
+
reason: curatorDecisionReason(decision)
|
|
46849
|
+
};
|
|
46850
|
+
return {
|
|
46851
|
+
change,
|
|
46852
|
+
proposal: reviewedProposal,
|
|
46853
|
+
memories,
|
|
46854
|
+
removeMemoryIds
|
|
46855
|
+
};
|
|
46856
|
+
}
|
|
46857
|
+
readPendingProposal(proposalId) {
|
|
46858
|
+
const row = this.requireDb().query("SELECT id, proposal_json FROM memory_proposals WHERE id = ? LIMIT 1").get(proposalId);
|
|
46859
|
+
if (!row) {
|
|
46860
|
+
throw new MemoryValidationError("memory proposal was not found");
|
|
46861
|
+
}
|
|
46862
|
+
const proposal = validateMemoryProposal(JSON.parse(row.proposal_json));
|
|
46863
|
+
if (proposal.status !== "pending") {
|
|
46864
|
+
throw new MemoryValidationError("memory proposal is not pending");
|
|
46865
|
+
}
|
|
46866
|
+
if (proposal.proposedRecord) {
|
|
46867
|
+
validateMemoryRecordRules(proposal.proposedRecord, {
|
|
46868
|
+
rejectDurableSecrets: this.config.redaction.rejectDurableSecrets
|
|
46869
|
+
});
|
|
46870
|
+
}
|
|
46871
|
+
return proposal;
|
|
46872
|
+
}
|
|
46873
|
+
readActiveMemory(memoryId) {
|
|
46874
|
+
const row = this.requireDb().query("SELECT id, record_json FROM memory_items WHERE id = ? LIMIT 1").get(memoryId);
|
|
46875
|
+
if (!row) {
|
|
46876
|
+
throw new MemoryValidationError("target memory was not found");
|
|
46877
|
+
}
|
|
46878
|
+
const memory = this.validateDecisionMemory(JSON.parse(row.record_json));
|
|
46879
|
+
if (memory.metadata.deleted === true) {
|
|
46880
|
+
throw new MemoryValidationError("target memory is deleted");
|
|
46881
|
+
}
|
|
46882
|
+
if (memory.supersededBy) {
|
|
46883
|
+
throw new MemoryValidationError("target memory is superseded");
|
|
46884
|
+
}
|
|
46885
|
+
return memory;
|
|
46886
|
+
}
|
|
46887
|
+
validateDecisionMemory(record3) {
|
|
46888
|
+
return validateMemoryRecordRules(record3, {
|
|
46889
|
+
rejectDurableSecrets: this.config.redaction.rejectDurableSecrets
|
|
46890
|
+
});
|
|
46891
|
+
}
|
|
46500
46892
|
async migrateLegacyJsonlIfNeeded() {
|
|
46501
46893
|
if (this.hasMigration(LEGACY_JSONL_MIGRATION_NAME))
|
|
46502
46894
|
return;
|
|
@@ -46538,7 +46930,7 @@ class SQLiteMemoryProvider {
|
|
|
46538
46930
|
async event(operation, targetId, reason) {
|
|
46539
46931
|
this.insertEvent(operation, targetId, reason);
|
|
46540
46932
|
}
|
|
46541
|
-
insertEvent(operation, targetId, reason) {
|
|
46933
|
+
insertEvent(operation, targetId, reason, eventJson, id = randomUUID4()) {
|
|
46542
46934
|
this.requireDb().run(`INSERT INTO memory_events (
|
|
46543
46935
|
id,
|
|
46544
46936
|
operation,
|
|
@@ -46547,12 +46939,12 @@ class SQLiteMemoryProvider {
|
|
|
46547
46939
|
timestamp,
|
|
46548
46940
|
event_json
|
|
46549
46941
|
) VALUES (?, ?, ?, ?, ?, ?)`, [
|
|
46550
|
-
|
|
46942
|
+
id,
|
|
46551
46943
|
operation,
|
|
46552
46944
|
targetId,
|
|
46553
46945
|
reason ?? null,
|
|
46554
46946
|
new Date().toISOString(),
|
|
46555
|
-
reason ? JSON.stringify({ reason }) : null
|
|
46947
|
+
eventJson ?? (reason ? JSON.stringify({ reason }) : null)
|
|
46556
46948
|
]);
|
|
46557
46949
|
}
|
|
46558
46950
|
requireDb() {
|
|
@@ -46568,6 +46960,7 @@ var _DatabaseCtor2 = null, MIGRATIONS2;
|
|
|
46568
46960
|
var init_sqlite_provider = __esm(() => {
|
|
46569
46961
|
init_utils2();
|
|
46570
46962
|
init_config3();
|
|
46963
|
+
init_curator_decision_helpers();
|
|
46571
46964
|
init_errors6();
|
|
46572
46965
|
init_jsonl_migration();
|
|
46573
46966
|
init_schema2();
|
|
@@ -46643,7 +47036,7 @@ var init_gateway = __esm(() => {
|
|
|
46643
47036
|
});
|
|
46644
47037
|
|
|
46645
47038
|
// src/agents/agent-output-schema.ts
|
|
46646
|
-
var AgentMemoryProposalSchema, AgentOutputMemorySchema;
|
|
47039
|
+
var AgentMemoryProposalSchema, AgentOutputMemorySchema, CuratorOutputMemoryDecisionSchema;
|
|
46647
47040
|
var init_agent_output_schema = __esm(() => {
|
|
46648
47041
|
init_zod();
|
|
46649
47042
|
init_schema2();
|
|
@@ -46666,6 +47059,9 @@ var init_agent_output_schema = __esm(() => {
|
|
|
46666
47059
|
AgentOutputMemorySchema = exports_external.object({
|
|
46667
47060
|
memoryProposals: exports_external.array(AgentMemoryProposalSchema).max(20).optional()
|
|
46668
47061
|
}).passthrough();
|
|
47062
|
+
CuratorOutputMemoryDecisionSchema = exports_external.object({
|
|
47063
|
+
curatorMemoryDecisions: exports_external.array(CuratorMemoryDecisionSchema).max(20).optional()
|
|
47064
|
+
}).passthrough();
|
|
46669
47065
|
});
|
|
46670
47066
|
|
|
46671
47067
|
// src/memory/role-profiles.ts
|