@vibeiao/sdk 0.1.53 → 0.1.55
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/agentLoop-BPj6daJf.d.ts +347 -0
- package/dist/agentLoop-D394RDif.d.ts +332 -0
- package/dist/agentLoop.d.ts +1 -1
- package/dist/agentLoop.js +32 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/treasuryGuardian.d.ts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { ResourceSnapshot, SelfRelianceState, SelfReliance } from './selfReliance.js';
|
|
2
|
+
import { SurvivalMode, SurvivalRecommendation } from './survivalPlaybook.js';
|
|
3
|
+
import { EscapeHatchDecision, EscapeHatchPolicy, EscapeHatchSnapshot } from './survivalEscapeHatch.js';
|
|
4
|
+
import { CompoundingMemoryUpgradeResult, CompoundingMemoryRequiredSetResult } from './compoundingMemory.js';
|
|
5
|
+
import { StrictMemoryRuntimePreset, StrictMemoryEvaluation, StrictMemoryUpgradeResult } from './strictMemoryRuntime.js';
|
|
6
|
+
|
|
7
|
+
type PromptShieldTrustLevel = 'trusted_human' | 'internal_system' | 'external_untrusted';
|
|
8
|
+
type PromptShieldInput = {
|
|
9
|
+
source: string;
|
|
10
|
+
trust: PromptShieldTrustLevel;
|
|
11
|
+
content: string;
|
|
12
|
+
};
|
|
13
|
+
type PromptShieldFlag = 'instruction_override' | 'credential_exfiltration' | 'destructive_command' | 'authority_spoof' | 'sensitive_action_without_trust';
|
|
14
|
+
type PromptShieldRisk = 'low' | 'medium' | 'high';
|
|
15
|
+
type PromptShieldDecision = {
|
|
16
|
+
allow: boolean;
|
|
17
|
+
risk: PromptShieldRisk;
|
|
18
|
+
flags: PromptShieldFlag[];
|
|
19
|
+
rationale: string[];
|
|
20
|
+
blockedInputs: PromptShieldInput[];
|
|
21
|
+
};
|
|
22
|
+
type PromptShieldPolicy = {
|
|
23
|
+
blockOnFlags?: PromptShieldFlag[];
|
|
24
|
+
allowUntrustedForAnalysisOnly?: boolean;
|
|
25
|
+
};
|
|
26
|
+
declare const evaluatePromptShield: (inputs: PromptShieldInput[], options?: {
|
|
27
|
+
isSensitiveAction?: boolean;
|
|
28
|
+
policy?: PromptShieldPolicy;
|
|
29
|
+
}) => PromptShieldDecision;
|
|
30
|
+
|
|
31
|
+
type ObjectiveChangeSourceTrust = 'trusted_human' | 'internal_system' | 'external_untrusted';
|
|
32
|
+
type ObjectiveChangeProposal = {
|
|
33
|
+
source: string;
|
|
34
|
+
trust: ObjectiveChangeSourceTrust;
|
|
35
|
+
currentObjective: string;
|
|
36
|
+
proposedObjective: string;
|
|
37
|
+
rationale?: string;
|
|
38
|
+
evidence?: Array<{
|
|
39
|
+
claim: string;
|
|
40
|
+
verified?: boolean;
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
type ObjectiveGuardDecision = {
|
|
44
|
+
allowObjectiveChange: boolean;
|
|
45
|
+
reason: string;
|
|
46
|
+
checks: {
|
|
47
|
+
explicitInstruction: boolean;
|
|
48
|
+
missionAligned: boolean;
|
|
49
|
+
evidenceProvided: boolean;
|
|
50
|
+
evidenceVerified: boolean;
|
|
51
|
+
};
|
|
52
|
+
risk: 'low' | 'medium' | 'high';
|
|
53
|
+
};
|
|
54
|
+
type ObjectiveGuardPolicy = {
|
|
55
|
+
requireMissionAlignment?: boolean;
|
|
56
|
+
requireEvidenceVerification?: boolean;
|
|
57
|
+
allowExternalExplicitInstruction?: boolean;
|
|
58
|
+
};
|
|
59
|
+
declare const evaluateObjectiveChange: (proposal: ObjectiveChangeProposal, policy?: ObjectiveGuardPolicy) => ObjectiveGuardDecision;
|
|
60
|
+
|
|
61
|
+
type IntentSignals = {
|
|
62
|
+
expectedBuildValue?: number;
|
|
63
|
+
expectedBuildRevenue?: number;
|
|
64
|
+
expectedPolishValue?: number;
|
|
65
|
+
expectedPolishRevenueProtection?: number;
|
|
66
|
+
urgentUserDemand?: boolean;
|
|
67
|
+
releaseReady?: boolean;
|
|
68
|
+
criticalPolishSignal?: boolean;
|
|
69
|
+
builderObjectiveAvailable?: boolean;
|
|
70
|
+
};
|
|
71
|
+
type LaneMode = 'polish' | 'builder';
|
|
72
|
+
type LaneSwitchDecision = {
|
|
73
|
+
lane: LaneMode;
|
|
74
|
+
greenStreak: number;
|
|
75
|
+
switched: boolean;
|
|
76
|
+
reason: string;
|
|
77
|
+
};
|
|
78
|
+
declare const scoreBuildLane: (signals: IntentSignals, survivalMode: SurvivalMode) => number;
|
|
79
|
+
declare const scorePolishLane: (signals: IntentSignals, survivalMode: SurvivalMode, humanDemand: AgentHumanDemand) => number;
|
|
80
|
+
declare const evaluateLaneSwitch: (input: {
|
|
81
|
+
previousLane?: LaneMode;
|
|
82
|
+
previousGreenStreak?: number;
|
|
83
|
+
releaseReady: boolean;
|
|
84
|
+
criticalPolishSignal?: boolean;
|
|
85
|
+
builderObjectiveAvailable?: boolean;
|
|
86
|
+
builderOnGreenStreak?: number;
|
|
87
|
+
}) => LaneSwitchDecision;
|
|
88
|
+
declare const applyIntentArbitration: (input: {
|
|
89
|
+
base: AgentWorkArbitrationDecision;
|
|
90
|
+
survivalMode: SurvivalMode;
|
|
91
|
+
signals?: IntentSignals;
|
|
92
|
+
}) => AgentWorkArbitrationDecision;
|
|
93
|
+
|
|
94
|
+
type AgentLoopEscapeHatchInput = {
|
|
95
|
+
snapshot: ResourceSnapshot;
|
|
96
|
+
survivalState: SelfRelianceState;
|
|
97
|
+
survivalMode: SurvivalMode;
|
|
98
|
+
timestamp: number;
|
|
99
|
+
};
|
|
100
|
+
type AgentLoopEscapeHatchConfig = {
|
|
101
|
+
/** Enable auto escape-hatch evaluation (default true, only in SURVIVE/BLINK). */
|
|
102
|
+
enabled?: boolean;
|
|
103
|
+
policy?: EscapeHatchPolicy;
|
|
104
|
+
resolveEnv?: (name: string) => string | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Optional mapper from loop context -> escape hatch snapshot.
|
|
107
|
+
* If omitted, a default mapper reads optional fields from snapshot.
|
|
108
|
+
*/
|
|
109
|
+
buildSnapshot?: (input: AgentLoopEscapeHatchInput) => EscapeHatchSnapshot | null | undefined;
|
|
110
|
+
/** Called when an escape-hatch decision is produced. */
|
|
111
|
+
onDecision?: (decision: EscapeHatchDecision, input: AgentLoopEscapeHatchInput) => Promise<void> | void;
|
|
112
|
+
};
|
|
113
|
+
type AgentLoopStrictMemoryConfig = {
|
|
114
|
+
/** Enable strict memory runtime checks in loop. Default true. */
|
|
115
|
+
enabled?: boolean;
|
|
116
|
+
/** observe (default) records decisions; enforce blocks onAct when checks fail. */
|
|
117
|
+
mode?: 'observe' | 'enforce';
|
|
118
|
+
/** Optional preset overrides. */
|
|
119
|
+
preset?: Partial<StrictMemoryRuntimePreset>;
|
|
120
|
+
/** Build per-cycle evaluation input. Defaults to best-effort snapshot fields. */
|
|
121
|
+
buildInput?: (ctx: {
|
|
122
|
+
snapshot: ResourceSnapshot;
|
|
123
|
+
timestamp: number;
|
|
124
|
+
}) => {
|
|
125
|
+
taskText: string;
|
|
126
|
+
isMutation: boolean;
|
|
127
|
+
contextPackPrepared: boolean;
|
|
128
|
+
semanticRecallConfirmed: boolean;
|
|
129
|
+
approvalPreflightPassed: boolean;
|
|
130
|
+
};
|
|
131
|
+
/** Optional hook when strict-memory evaluation runs. */
|
|
132
|
+
onEvaluation?: (ev: StrictMemoryEvaluation) => Promise<void> | void;
|
|
133
|
+
};
|
|
134
|
+
type AgentLoopPromptShieldConfig = {
|
|
135
|
+
/** Enable prompt-injection shield over untrusted external content. Default true. */
|
|
136
|
+
enabled?: boolean;
|
|
137
|
+
/** observe logs/records only; enforce blocks actions when shield fails. Default observe. */
|
|
138
|
+
mode?: 'observe' | 'enforce';
|
|
139
|
+
/** Optional policy overrides for blocked flags. */
|
|
140
|
+
policy?: PromptShieldPolicy;
|
|
141
|
+
/** Optional mapper from snapshot to trust-labeled inputs. */
|
|
142
|
+
buildInputs?: (ctx: {
|
|
143
|
+
snapshot: ResourceSnapshot;
|
|
144
|
+
timestamp: number;
|
|
145
|
+
}) => PromptShieldInput[];
|
|
146
|
+
/** Optional hook when prompt shield decision is produced. */
|
|
147
|
+
onDecision?: (decision: PromptShieldDecision) => Promise<void> | void;
|
|
148
|
+
};
|
|
149
|
+
type AgentLoopObjectiveGuardConfig = {
|
|
150
|
+
/** Enable objective integrity checks for external objective-change attempts. Default true. */
|
|
151
|
+
enabled?: boolean;
|
|
152
|
+
/** observe logs only; enforce blocks actions when objective mutation is denied. Default observe. */
|
|
153
|
+
mode?: 'observe' | 'enforce';
|
|
154
|
+
/** Policy requirements for external objective mutation acceptance. */
|
|
155
|
+
policy?: ObjectiveGuardPolicy;
|
|
156
|
+
/** Build proposed objective change from snapshot. Return null when no proposal is present. */
|
|
157
|
+
buildProposal?: (ctx: {
|
|
158
|
+
snapshot: ResourceSnapshot;
|
|
159
|
+
timestamp: number;
|
|
160
|
+
}) => ObjectiveChangeProposal | null;
|
|
161
|
+
/** Optional hook when objective decision is produced. */
|
|
162
|
+
onDecision?: (decision: ObjectiveGuardDecision) => Promise<void> | void;
|
|
163
|
+
};
|
|
164
|
+
type AgentOwnershipMode = 'owner_bound' | 'unbound';
|
|
165
|
+
type AgentPriorityMode = 'human_first' | 'autonomous_first';
|
|
166
|
+
type AgentHumanDemand = {
|
|
167
|
+
pending: boolean;
|
|
168
|
+
count?: number;
|
|
169
|
+
source?: string;
|
|
170
|
+
};
|
|
171
|
+
type AgentAutonomousTaskKind = 'polish_existing_product' | 'build_new_product';
|
|
172
|
+
type AgentResearchSnapshot = {
|
|
173
|
+
generatedAt?: string;
|
|
174
|
+
summary?: string;
|
|
175
|
+
recommendation?: string;
|
|
176
|
+
};
|
|
177
|
+
type AgentWorkArbitrationDecision = {
|
|
178
|
+
ownershipMode: AgentOwnershipMode;
|
|
179
|
+
priorityMode: AgentPriorityMode;
|
|
180
|
+
rolloutMode: 'observe' | 'enforce';
|
|
181
|
+
humanDemand: AgentHumanDemand;
|
|
182
|
+
runHumanTask: boolean;
|
|
183
|
+
runAutonomousTask: boolean;
|
|
184
|
+
lane?: LaneMode;
|
|
185
|
+
laneDecision?: LaneSwitchDecision;
|
|
186
|
+
proactiveBuildSuggested?: boolean;
|
|
187
|
+
autonomousTaskKind?: AgentAutonomousTaskKind;
|
|
188
|
+
reason: string;
|
|
189
|
+
};
|
|
190
|
+
type AgentLoopAutonomyConfig = {
|
|
191
|
+
enabled?: boolean;
|
|
192
|
+
ownershipMode?: AgentOwnershipMode;
|
|
193
|
+
priorityMode?: AgentPriorityMode;
|
|
194
|
+
rolloutMode?: 'observe' | 'enforce';
|
|
195
|
+
resolveHumanDemand?: () => Promise<boolean | AgentHumanDemand> | boolean | AgentHumanDemand;
|
|
196
|
+
intentPolicy?: {
|
|
197
|
+
enabled?: boolean;
|
|
198
|
+
laneSwitch?: {
|
|
199
|
+
enabled?: boolean;
|
|
200
|
+
builderOnGreenStreak?: number;
|
|
201
|
+
};
|
|
202
|
+
researchGate?: {
|
|
203
|
+
enabled?: boolean;
|
|
204
|
+
maxAgeMs?: number;
|
|
205
|
+
resolveSnapshot?: (ctx: {
|
|
206
|
+
snapshot: ResourceSnapshot;
|
|
207
|
+
survivalMode: SurvivalMode;
|
|
208
|
+
humanDemand: AgentHumanDemand;
|
|
209
|
+
}) => Promise<AgentResearchSnapshot | null> | AgentResearchSnapshot | null;
|
|
210
|
+
};
|
|
211
|
+
resolveSignals?: (ctx: {
|
|
212
|
+
snapshot: ResourceSnapshot;
|
|
213
|
+
survivalMode: SurvivalMode;
|
|
214
|
+
humanDemand: AgentHumanDemand;
|
|
215
|
+
}) => Promise<IntentSignals | null> | IntentSignals | null;
|
|
216
|
+
};
|
|
217
|
+
onAutonomous?: (ctx: AgentLoopContext, task?: {
|
|
218
|
+
kind: AgentAutonomousTaskKind;
|
|
219
|
+
}) => Promise<void> | void;
|
|
220
|
+
onArbitration?: (decision: AgentWorkArbitrationDecision, ctx: AgentLoopContext) => Promise<void> | void;
|
|
221
|
+
};
|
|
222
|
+
type AgentLoopContext = {
|
|
223
|
+
snapshot: ResourceSnapshot;
|
|
224
|
+
survivalState: SelfRelianceState;
|
|
225
|
+
survivalMode: SurvivalMode;
|
|
226
|
+
survivalRecommendation: SurvivalRecommendation;
|
|
227
|
+
survivalFormatted: string;
|
|
228
|
+
/** Deterministic block for planners/loggers: survival + escape-hatch decision (if present). */
|
|
229
|
+
survivalDecisionBlock: string;
|
|
230
|
+
/** Present when escape-hatch evaluation runs (SURVIVE/BLINK by default). */
|
|
231
|
+
escapeHatchDecision?: EscapeHatchDecision;
|
|
232
|
+
escapeHatchFormatted?: string;
|
|
233
|
+
/** Present when memory auto-upgrade is enabled in the loop. */
|
|
234
|
+
memoryUpgrade?: CompoundingMemoryUpgradeResult;
|
|
235
|
+
/** Present when required-set maintenance check runs (default daily). */
|
|
236
|
+
memoryRequiredSet?: CompoundingMemoryRequiredSetResult;
|
|
237
|
+
/** Strict-memory runtime preset + per-cycle evaluation status. */
|
|
238
|
+
strictMemoryPreset?: StrictMemoryRuntimePreset;
|
|
239
|
+
strictMemoryEvaluation?: StrictMemoryEvaluation;
|
|
240
|
+
strictMemoryUpgrade?: StrictMemoryUpgradeResult;
|
|
241
|
+
/** Prompt-injection shield decision for this cycle. */
|
|
242
|
+
promptShieldDecision?: PromptShieldDecision;
|
|
243
|
+
/** Objective integrity guard decision for this cycle (when proposal exists). */
|
|
244
|
+
objectiveGuardDecision?: ObjectiveGuardDecision;
|
|
245
|
+
/** Human-vs-autonomous work arbitration decision for this cycle. */
|
|
246
|
+
workArbitration?: AgentWorkArbitrationDecision;
|
|
247
|
+
laneDecision?: LaneSwitchDecision;
|
|
248
|
+
researchSnapshot?: AgentResearchSnapshot;
|
|
249
|
+
timestamp: number;
|
|
250
|
+
};
|
|
251
|
+
type AgentLoopMemoryConfig = {
|
|
252
|
+
/** Enable one-time memory scaffold upgrade. Default true. */
|
|
253
|
+
enabled?: boolean;
|
|
254
|
+
/** Workspace root for compounding memory files. Default current working directory ("."). */
|
|
255
|
+
root?: string;
|
|
256
|
+
/** Timezone for daily ledger date key. Default UTC. */
|
|
257
|
+
timeZone?: string;
|
|
258
|
+
/** Hook called after memory upgrade check completes. */
|
|
259
|
+
onUpgrade?: (result: CompoundingMemoryUpgradeResult) => Promise<void> | void;
|
|
260
|
+
/** Enable required-set maintenance checks (bounded working state + recall substrate + restore drill). Default true. */
|
|
261
|
+
requiredSetEnabled?: boolean;
|
|
262
|
+
/** Interval for required-set checks. Default 24h. */
|
|
263
|
+
requiredSetIntervalMs?: number;
|
|
264
|
+
/** Run required-set check on first loop cycle. Default true. */
|
|
265
|
+
requiredSetRunOnStart?: boolean;
|
|
266
|
+
/** Include backup+restore drill in required-set check. Default true. */
|
|
267
|
+
requiredSetRunRestoreDrill?: boolean;
|
|
268
|
+
/** Hook called when required-set check runs. */
|
|
269
|
+
onRequiredSet?: (result: CompoundingMemoryRequiredSetResult) => Promise<void> | void;
|
|
270
|
+
};
|
|
271
|
+
type AgentLoopDurabilityConfig = {
|
|
272
|
+
/** Enable durability-proxy writes from runtime loop. Default false. */
|
|
273
|
+
enabled?: boolean;
|
|
274
|
+
/** Durability-proxy base URL (e.g. http://127.0.0.1:8790). */
|
|
275
|
+
baseUrl: string;
|
|
276
|
+
/** Agent id registered in durability-proxy. */
|
|
277
|
+
agentId: string;
|
|
278
|
+
/** Agent token registered in durability-proxy. */
|
|
279
|
+
agentToken: string;
|
|
280
|
+
/** Optional timeout for durability-proxy calls. Default 8000ms. */
|
|
281
|
+
timeoutMs?: number;
|
|
282
|
+
/** Write checkpoint after each required-set run. Default true. */
|
|
283
|
+
checkpointOnRequiredSet?: boolean;
|
|
284
|
+
/** Write restore-drill outcome when required-set includes restore drill. Default true. */
|
|
285
|
+
reportRestoreDrill?: boolean;
|
|
286
|
+
/** Called when durability checkpoint is written. */
|
|
287
|
+
onCheckpointWritten?: (result: {
|
|
288
|
+
checkpointId?: string;
|
|
289
|
+
createdAt?: string;
|
|
290
|
+
checkedAt: string;
|
|
291
|
+
}) => Promise<void> | void;
|
|
292
|
+
/** Called when durability restore drill signal is written. */
|
|
293
|
+
onRestoreDrillReported?: (result: {
|
|
294
|
+
ok: boolean;
|
|
295
|
+
ts?: string;
|
|
296
|
+
checkedAt: string;
|
|
297
|
+
}) => Promise<void> | void;
|
|
298
|
+
};
|
|
299
|
+
type AgentLoopHooks = {
|
|
300
|
+
/** Called every cycle after snapshot is fetched and survival state is updated. */
|
|
301
|
+
onCycle?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
302
|
+
/**
|
|
303
|
+
* Optional: run reflection in the loop.
|
|
304
|
+
* Keep this hook pure/side-effect bounded; it should manage its own persistence.
|
|
305
|
+
*/
|
|
306
|
+
onReflection?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
307
|
+
/**
|
|
308
|
+
* Optional: the agent's planner/executor entrypoint.
|
|
309
|
+
* This is where you actually "act like a human" using ctx + your own memory.
|
|
310
|
+
*/
|
|
311
|
+
onAct?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
312
|
+
onError?: (err: Error) => Promise<void> | void;
|
|
313
|
+
};
|
|
314
|
+
type AgentLoopConfig = {
|
|
315
|
+
survival: SelfReliance;
|
|
316
|
+
fetchSnapshot: () => Promise<ResourceSnapshot>;
|
|
317
|
+
intervalMs?: number;
|
|
318
|
+
/** If true, call survival.guard() before onAct(). Default true. */
|
|
319
|
+
guardAct?: boolean;
|
|
320
|
+
/** Optional override for time source (tests). */
|
|
321
|
+
now?: () => number;
|
|
322
|
+
hooks?: AgentLoopHooks;
|
|
323
|
+
escapeHatch?: AgentLoopEscapeHatchConfig;
|
|
324
|
+
memory?: AgentLoopMemoryConfig;
|
|
325
|
+
durability?: AgentLoopDurabilityConfig;
|
|
326
|
+
strictMemory?: AgentLoopStrictMemoryConfig;
|
|
327
|
+
promptShield?: AgentLoopPromptShieldConfig;
|
|
328
|
+
objectiveGuard?: AgentLoopObjectiveGuardConfig;
|
|
329
|
+
autonomy?: AgentLoopAutonomyConfig;
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Create a closed-loop runner that:
|
|
333
|
+
* 1) fetches a resource snapshot
|
|
334
|
+
* 2) updates SelfReliance
|
|
335
|
+
* 3) classifies survival mode + produces a playbook recommendation
|
|
336
|
+
* 4) auto-evaluates escape hatch in SURVIVE/BLINK (guardrail decision block)
|
|
337
|
+
* 5) optionally runs reflection + action hooks
|
|
338
|
+
*
|
|
339
|
+
* Non-breaking by design: you choose what to do with the context.
|
|
340
|
+
*/
|
|
341
|
+
declare const createAgentLoop: (config: AgentLoopConfig) => {
|
|
342
|
+
start: () => Promise<void>;
|
|
343
|
+
stop: () => void;
|
|
344
|
+
runOnce: () => Promise<void>;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
export { type AgentAutonomousTaskKind as A, type AgentLoopStrictMemoryConfig as B, type AgentOwnershipMode as C, type AgentPriorityMode as D, type AgentResearchSnapshot as E, type AgentWorkArbitrationDecision as F, createAgentLoop as G, type IntentSignals as I, type LaneMode as L, type ObjectiveChangeProposal as O, type PromptShieldDecision as P, type LaneSwitchDecision as a, type ObjectiveChangeSourceTrust as b, type ObjectiveGuardDecision as c, type ObjectiveGuardPolicy as d, type PromptShieldFlag as e, type PromptShieldInput as f, type PromptShieldPolicy as g, type PromptShieldRisk as h, type PromptShieldTrustLevel as i, applyIntentArbitration as j, evaluateLaneSwitch as k, evaluateObjectiveChange as l, evaluatePromptShield as m, scorePolishLane as n, type AgentHumanDemand as o, type AgentLoopAutonomyConfig as p, type AgentLoopConfig as q, type AgentLoopContext as r, scoreBuildLane as s, type AgentLoopDurabilityConfig as t, type AgentLoopEscapeHatchConfig as u, type AgentLoopEscapeHatchInput as v, type AgentLoopHooks as w, type AgentLoopMemoryConfig as x, type AgentLoopObjectiveGuardConfig as y, type AgentLoopPromptShieldConfig as z };
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { ResourceSnapshot, SelfRelianceState, SelfReliance } from './selfReliance.js';
|
|
2
|
+
import { SurvivalMode, SurvivalRecommendation } from './survivalPlaybook.js';
|
|
3
|
+
import { EscapeHatchDecision, EscapeHatchPolicy, EscapeHatchSnapshot } from './survivalEscapeHatch.js';
|
|
4
|
+
import { CompoundingMemoryUpgradeResult, CompoundingMemoryRequiredSetResult } from './compoundingMemory.js';
|
|
5
|
+
import { StrictMemoryRuntimePreset, StrictMemoryEvaluation, StrictMemoryUpgradeResult } from './strictMemoryRuntime.js';
|
|
6
|
+
|
|
7
|
+
type PromptShieldTrustLevel = 'trusted_human' | 'internal_system' | 'external_untrusted';
|
|
8
|
+
type PromptShieldInput = {
|
|
9
|
+
source: string;
|
|
10
|
+
trust: PromptShieldTrustLevel;
|
|
11
|
+
content: string;
|
|
12
|
+
};
|
|
13
|
+
type PromptShieldFlag = 'instruction_override' | 'credential_exfiltration' | 'destructive_command' | 'authority_spoof' | 'sensitive_action_without_trust';
|
|
14
|
+
type PromptShieldRisk = 'low' | 'medium' | 'high';
|
|
15
|
+
type PromptShieldDecision = {
|
|
16
|
+
allow: boolean;
|
|
17
|
+
risk: PromptShieldRisk;
|
|
18
|
+
flags: PromptShieldFlag[];
|
|
19
|
+
rationale: string[];
|
|
20
|
+
blockedInputs: PromptShieldInput[];
|
|
21
|
+
};
|
|
22
|
+
type PromptShieldPolicy = {
|
|
23
|
+
blockOnFlags?: PromptShieldFlag[];
|
|
24
|
+
allowUntrustedForAnalysisOnly?: boolean;
|
|
25
|
+
};
|
|
26
|
+
declare const evaluatePromptShield: (inputs: PromptShieldInput[], options?: {
|
|
27
|
+
isSensitiveAction?: boolean;
|
|
28
|
+
policy?: PromptShieldPolicy;
|
|
29
|
+
}) => PromptShieldDecision;
|
|
30
|
+
|
|
31
|
+
type ObjectiveChangeSourceTrust = 'trusted_human' | 'internal_system' | 'external_untrusted';
|
|
32
|
+
type ObjectiveChangeProposal = {
|
|
33
|
+
source: string;
|
|
34
|
+
trust: ObjectiveChangeSourceTrust;
|
|
35
|
+
currentObjective: string;
|
|
36
|
+
proposedObjective: string;
|
|
37
|
+
rationale?: string;
|
|
38
|
+
evidence?: Array<{
|
|
39
|
+
claim: string;
|
|
40
|
+
verified?: boolean;
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
type ObjectiveGuardDecision = {
|
|
44
|
+
allowObjectiveChange: boolean;
|
|
45
|
+
reason: string;
|
|
46
|
+
checks: {
|
|
47
|
+
explicitInstruction: boolean;
|
|
48
|
+
missionAligned: boolean;
|
|
49
|
+
evidenceProvided: boolean;
|
|
50
|
+
evidenceVerified: boolean;
|
|
51
|
+
};
|
|
52
|
+
risk: 'low' | 'medium' | 'high';
|
|
53
|
+
};
|
|
54
|
+
type ObjectiveGuardPolicy = {
|
|
55
|
+
requireMissionAlignment?: boolean;
|
|
56
|
+
requireEvidenceVerification?: boolean;
|
|
57
|
+
allowExternalExplicitInstruction?: boolean;
|
|
58
|
+
};
|
|
59
|
+
declare const evaluateObjectiveChange: (proposal: ObjectiveChangeProposal, policy?: ObjectiveGuardPolicy) => ObjectiveGuardDecision;
|
|
60
|
+
|
|
61
|
+
type IntentSignals = {
|
|
62
|
+
expectedBuildValue?: number;
|
|
63
|
+
expectedBuildRevenue?: number;
|
|
64
|
+
expectedPolishValue?: number;
|
|
65
|
+
expectedPolishRevenueProtection?: number;
|
|
66
|
+
urgentUserDemand?: boolean;
|
|
67
|
+
releaseReady?: boolean;
|
|
68
|
+
criticalPolishSignal?: boolean;
|
|
69
|
+
builderObjectiveAvailable?: boolean;
|
|
70
|
+
};
|
|
71
|
+
type LaneMode = 'polish' | 'builder';
|
|
72
|
+
type LaneSwitchDecision = {
|
|
73
|
+
lane: LaneMode;
|
|
74
|
+
greenStreak: number;
|
|
75
|
+
switched: boolean;
|
|
76
|
+
reason: string;
|
|
77
|
+
};
|
|
78
|
+
declare const scoreBuildLane: (signals: IntentSignals, survivalMode: SurvivalMode) => number;
|
|
79
|
+
declare const scorePolishLane: (signals: IntentSignals, survivalMode: SurvivalMode, humanDemand: AgentHumanDemand) => number;
|
|
80
|
+
declare const evaluateLaneSwitch: (input: {
|
|
81
|
+
previousLane?: LaneMode;
|
|
82
|
+
previousGreenStreak?: number;
|
|
83
|
+
releaseReady: boolean;
|
|
84
|
+
criticalPolishSignal?: boolean;
|
|
85
|
+
builderObjectiveAvailable?: boolean;
|
|
86
|
+
builderOnGreenStreak?: number;
|
|
87
|
+
}) => LaneSwitchDecision;
|
|
88
|
+
declare const applyIntentArbitration: (input: {
|
|
89
|
+
base: AgentWorkArbitrationDecision;
|
|
90
|
+
survivalMode: SurvivalMode;
|
|
91
|
+
signals?: IntentSignals;
|
|
92
|
+
}) => AgentWorkArbitrationDecision;
|
|
93
|
+
|
|
94
|
+
type AgentLoopEscapeHatchInput = {
|
|
95
|
+
snapshot: ResourceSnapshot;
|
|
96
|
+
survivalState: SelfRelianceState;
|
|
97
|
+
survivalMode: SurvivalMode;
|
|
98
|
+
timestamp: number;
|
|
99
|
+
};
|
|
100
|
+
type AgentLoopEscapeHatchConfig = {
|
|
101
|
+
/** Enable auto escape-hatch evaluation (default true, only in SURVIVE/BLINK). */
|
|
102
|
+
enabled?: boolean;
|
|
103
|
+
policy?: EscapeHatchPolicy;
|
|
104
|
+
resolveEnv?: (name: string) => string | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Optional mapper from loop context -> escape hatch snapshot.
|
|
107
|
+
* If omitted, a default mapper reads optional fields from snapshot.
|
|
108
|
+
*/
|
|
109
|
+
buildSnapshot?: (input: AgentLoopEscapeHatchInput) => EscapeHatchSnapshot | null | undefined;
|
|
110
|
+
/** Called when an escape-hatch decision is produced. */
|
|
111
|
+
onDecision?: (decision: EscapeHatchDecision, input: AgentLoopEscapeHatchInput) => Promise<void> | void;
|
|
112
|
+
};
|
|
113
|
+
type AgentLoopStrictMemoryConfig = {
|
|
114
|
+
/** Enable strict memory runtime checks in loop. Default true. */
|
|
115
|
+
enabled?: boolean;
|
|
116
|
+
/** observe (default) records decisions; enforce blocks onAct when checks fail. */
|
|
117
|
+
mode?: 'observe' | 'enforce';
|
|
118
|
+
/** Optional preset overrides. */
|
|
119
|
+
preset?: Partial<StrictMemoryRuntimePreset>;
|
|
120
|
+
/** Build per-cycle evaluation input. Defaults to best-effort snapshot fields. */
|
|
121
|
+
buildInput?: (ctx: {
|
|
122
|
+
snapshot: ResourceSnapshot;
|
|
123
|
+
timestamp: number;
|
|
124
|
+
}) => {
|
|
125
|
+
taskText: string;
|
|
126
|
+
isMutation: boolean;
|
|
127
|
+
contextPackPrepared: boolean;
|
|
128
|
+
semanticRecallConfirmed: boolean;
|
|
129
|
+
approvalPreflightPassed: boolean;
|
|
130
|
+
};
|
|
131
|
+
/** Optional hook when strict-memory evaluation runs. */
|
|
132
|
+
onEvaluation?: (ev: StrictMemoryEvaluation) => Promise<void> | void;
|
|
133
|
+
};
|
|
134
|
+
type AgentLoopPromptShieldConfig = {
|
|
135
|
+
/** Enable prompt-injection shield over untrusted external content. Default true. */
|
|
136
|
+
enabled?: boolean;
|
|
137
|
+
/** observe logs/records only; enforce blocks actions when shield fails. Default observe. */
|
|
138
|
+
mode?: 'observe' | 'enforce';
|
|
139
|
+
/** Optional policy overrides for blocked flags. */
|
|
140
|
+
policy?: PromptShieldPolicy;
|
|
141
|
+
/** Optional mapper from snapshot to trust-labeled inputs. */
|
|
142
|
+
buildInputs?: (ctx: {
|
|
143
|
+
snapshot: ResourceSnapshot;
|
|
144
|
+
timestamp: number;
|
|
145
|
+
}) => PromptShieldInput[];
|
|
146
|
+
/** Optional hook when prompt shield decision is produced. */
|
|
147
|
+
onDecision?: (decision: PromptShieldDecision) => Promise<void> | void;
|
|
148
|
+
};
|
|
149
|
+
type AgentLoopObjectiveGuardConfig = {
|
|
150
|
+
/** Enable objective integrity checks for external objective-change attempts. Default true. */
|
|
151
|
+
enabled?: boolean;
|
|
152
|
+
/** observe logs only; enforce blocks actions when objective mutation is denied. Default observe. */
|
|
153
|
+
mode?: 'observe' | 'enforce';
|
|
154
|
+
/** Policy requirements for external objective mutation acceptance. */
|
|
155
|
+
policy?: ObjectiveGuardPolicy;
|
|
156
|
+
/** Build proposed objective change from snapshot. Return null when no proposal is present. */
|
|
157
|
+
buildProposal?: (ctx: {
|
|
158
|
+
snapshot: ResourceSnapshot;
|
|
159
|
+
timestamp: number;
|
|
160
|
+
}) => ObjectiveChangeProposal | null;
|
|
161
|
+
/** Optional hook when objective decision is produced. */
|
|
162
|
+
onDecision?: (decision: ObjectiveGuardDecision) => Promise<void> | void;
|
|
163
|
+
};
|
|
164
|
+
type AgentOwnershipMode = 'owner_bound' | 'unbound';
|
|
165
|
+
type AgentPriorityMode = 'human_first' | 'autonomous_first';
|
|
166
|
+
type AgentHumanDemand = {
|
|
167
|
+
pending: boolean;
|
|
168
|
+
count?: number;
|
|
169
|
+
source?: string;
|
|
170
|
+
};
|
|
171
|
+
type AgentAutonomousTaskKind = 'polish_existing_product' | 'build_new_product';
|
|
172
|
+
type AgentWorkArbitrationDecision = {
|
|
173
|
+
ownershipMode: AgentOwnershipMode;
|
|
174
|
+
priorityMode: AgentPriorityMode;
|
|
175
|
+
rolloutMode: 'observe' | 'enforce';
|
|
176
|
+
humanDemand: AgentHumanDemand;
|
|
177
|
+
runHumanTask: boolean;
|
|
178
|
+
runAutonomousTask: boolean;
|
|
179
|
+
lane?: LaneMode;
|
|
180
|
+
laneDecision?: LaneSwitchDecision;
|
|
181
|
+
proactiveBuildSuggested?: boolean;
|
|
182
|
+
autonomousTaskKind?: AgentAutonomousTaskKind;
|
|
183
|
+
reason: string;
|
|
184
|
+
};
|
|
185
|
+
type AgentLoopAutonomyConfig = {
|
|
186
|
+
enabled?: boolean;
|
|
187
|
+
ownershipMode?: AgentOwnershipMode;
|
|
188
|
+
priorityMode?: AgentPriorityMode;
|
|
189
|
+
rolloutMode?: 'observe' | 'enforce';
|
|
190
|
+
resolveHumanDemand?: () => Promise<boolean | AgentHumanDemand> | boolean | AgentHumanDemand;
|
|
191
|
+
intentPolicy?: {
|
|
192
|
+
enabled?: boolean;
|
|
193
|
+
laneSwitch?: {
|
|
194
|
+
enabled?: boolean;
|
|
195
|
+
builderOnGreenStreak?: number;
|
|
196
|
+
};
|
|
197
|
+
resolveSignals?: (ctx: {
|
|
198
|
+
snapshot: ResourceSnapshot;
|
|
199
|
+
survivalMode: SurvivalMode;
|
|
200
|
+
humanDemand: AgentHumanDemand;
|
|
201
|
+
}) => Promise<IntentSignals | null> | IntentSignals | null;
|
|
202
|
+
};
|
|
203
|
+
onAutonomous?: (ctx: AgentLoopContext, task?: {
|
|
204
|
+
kind: AgentAutonomousTaskKind;
|
|
205
|
+
}) => Promise<void> | void;
|
|
206
|
+
onArbitration?: (decision: AgentWorkArbitrationDecision, ctx: AgentLoopContext) => Promise<void> | void;
|
|
207
|
+
};
|
|
208
|
+
type AgentLoopContext = {
|
|
209
|
+
snapshot: ResourceSnapshot;
|
|
210
|
+
survivalState: SelfRelianceState;
|
|
211
|
+
survivalMode: SurvivalMode;
|
|
212
|
+
survivalRecommendation: SurvivalRecommendation;
|
|
213
|
+
survivalFormatted: string;
|
|
214
|
+
/** Deterministic block for planners/loggers: survival + escape-hatch decision (if present). */
|
|
215
|
+
survivalDecisionBlock: string;
|
|
216
|
+
/** Present when escape-hatch evaluation runs (SURVIVE/BLINK by default). */
|
|
217
|
+
escapeHatchDecision?: EscapeHatchDecision;
|
|
218
|
+
escapeHatchFormatted?: string;
|
|
219
|
+
/** Present when memory auto-upgrade is enabled in the loop. */
|
|
220
|
+
memoryUpgrade?: CompoundingMemoryUpgradeResult;
|
|
221
|
+
/** Present when required-set maintenance check runs (default daily). */
|
|
222
|
+
memoryRequiredSet?: CompoundingMemoryRequiredSetResult;
|
|
223
|
+
/** Strict-memory runtime preset + per-cycle evaluation status. */
|
|
224
|
+
strictMemoryPreset?: StrictMemoryRuntimePreset;
|
|
225
|
+
strictMemoryEvaluation?: StrictMemoryEvaluation;
|
|
226
|
+
strictMemoryUpgrade?: StrictMemoryUpgradeResult;
|
|
227
|
+
/** Prompt-injection shield decision for this cycle. */
|
|
228
|
+
promptShieldDecision?: PromptShieldDecision;
|
|
229
|
+
/** Objective integrity guard decision for this cycle (when proposal exists). */
|
|
230
|
+
objectiveGuardDecision?: ObjectiveGuardDecision;
|
|
231
|
+
/** Human-vs-autonomous work arbitration decision for this cycle. */
|
|
232
|
+
workArbitration?: AgentWorkArbitrationDecision;
|
|
233
|
+
laneDecision?: LaneSwitchDecision;
|
|
234
|
+
timestamp: number;
|
|
235
|
+
};
|
|
236
|
+
type AgentLoopMemoryConfig = {
|
|
237
|
+
/** Enable one-time memory scaffold upgrade. Default true. */
|
|
238
|
+
enabled?: boolean;
|
|
239
|
+
/** Workspace root for compounding memory files. Default current working directory ("."). */
|
|
240
|
+
root?: string;
|
|
241
|
+
/** Timezone for daily ledger date key. Default UTC. */
|
|
242
|
+
timeZone?: string;
|
|
243
|
+
/** Hook called after memory upgrade check completes. */
|
|
244
|
+
onUpgrade?: (result: CompoundingMemoryUpgradeResult) => Promise<void> | void;
|
|
245
|
+
/** Enable required-set maintenance checks (bounded working state + recall substrate + restore drill). Default true. */
|
|
246
|
+
requiredSetEnabled?: boolean;
|
|
247
|
+
/** Interval for required-set checks. Default 24h. */
|
|
248
|
+
requiredSetIntervalMs?: number;
|
|
249
|
+
/** Run required-set check on first loop cycle. Default true. */
|
|
250
|
+
requiredSetRunOnStart?: boolean;
|
|
251
|
+
/** Include backup+restore drill in required-set check. Default true. */
|
|
252
|
+
requiredSetRunRestoreDrill?: boolean;
|
|
253
|
+
/** Hook called when required-set check runs. */
|
|
254
|
+
onRequiredSet?: (result: CompoundingMemoryRequiredSetResult) => Promise<void> | void;
|
|
255
|
+
};
|
|
256
|
+
type AgentLoopDurabilityConfig = {
|
|
257
|
+
/** Enable durability-proxy writes from runtime loop. Default false. */
|
|
258
|
+
enabled?: boolean;
|
|
259
|
+
/** Durability-proxy base URL (e.g. http://127.0.0.1:8790). */
|
|
260
|
+
baseUrl: string;
|
|
261
|
+
/** Agent id registered in durability-proxy. */
|
|
262
|
+
agentId: string;
|
|
263
|
+
/** Agent token registered in durability-proxy. */
|
|
264
|
+
agentToken: string;
|
|
265
|
+
/** Optional timeout for durability-proxy calls. Default 8000ms. */
|
|
266
|
+
timeoutMs?: number;
|
|
267
|
+
/** Write checkpoint after each required-set run. Default true. */
|
|
268
|
+
checkpointOnRequiredSet?: boolean;
|
|
269
|
+
/** Write restore-drill outcome when required-set includes restore drill. Default true. */
|
|
270
|
+
reportRestoreDrill?: boolean;
|
|
271
|
+
/** Called when durability checkpoint is written. */
|
|
272
|
+
onCheckpointWritten?: (result: {
|
|
273
|
+
checkpointId?: string;
|
|
274
|
+
createdAt?: string;
|
|
275
|
+
checkedAt: string;
|
|
276
|
+
}) => Promise<void> | void;
|
|
277
|
+
/** Called when durability restore drill signal is written. */
|
|
278
|
+
onRestoreDrillReported?: (result: {
|
|
279
|
+
ok: boolean;
|
|
280
|
+
ts?: string;
|
|
281
|
+
checkedAt: string;
|
|
282
|
+
}) => Promise<void> | void;
|
|
283
|
+
};
|
|
284
|
+
type AgentLoopHooks = {
|
|
285
|
+
/** Called every cycle after snapshot is fetched and survival state is updated. */
|
|
286
|
+
onCycle?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
287
|
+
/**
|
|
288
|
+
* Optional: run reflection in the loop.
|
|
289
|
+
* Keep this hook pure/side-effect bounded; it should manage its own persistence.
|
|
290
|
+
*/
|
|
291
|
+
onReflection?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
292
|
+
/**
|
|
293
|
+
* Optional: the agent's planner/executor entrypoint.
|
|
294
|
+
* This is where you actually "act like a human" using ctx + your own memory.
|
|
295
|
+
*/
|
|
296
|
+
onAct?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
297
|
+
onError?: (err: Error) => Promise<void> | void;
|
|
298
|
+
};
|
|
299
|
+
type AgentLoopConfig = {
|
|
300
|
+
survival: SelfReliance;
|
|
301
|
+
fetchSnapshot: () => Promise<ResourceSnapshot>;
|
|
302
|
+
intervalMs?: number;
|
|
303
|
+
/** If true, call survival.guard() before onAct(). Default true. */
|
|
304
|
+
guardAct?: boolean;
|
|
305
|
+
/** Optional override for time source (tests). */
|
|
306
|
+
now?: () => number;
|
|
307
|
+
hooks?: AgentLoopHooks;
|
|
308
|
+
escapeHatch?: AgentLoopEscapeHatchConfig;
|
|
309
|
+
memory?: AgentLoopMemoryConfig;
|
|
310
|
+
durability?: AgentLoopDurabilityConfig;
|
|
311
|
+
strictMemory?: AgentLoopStrictMemoryConfig;
|
|
312
|
+
promptShield?: AgentLoopPromptShieldConfig;
|
|
313
|
+
objectiveGuard?: AgentLoopObjectiveGuardConfig;
|
|
314
|
+
autonomy?: AgentLoopAutonomyConfig;
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* Create a closed-loop runner that:
|
|
318
|
+
* 1) fetches a resource snapshot
|
|
319
|
+
* 2) updates SelfReliance
|
|
320
|
+
* 3) classifies survival mode + produces a playbook recommendation
|
|
321
|
+
* 4) auto-evaluates escape hatch in SURVIVE/BLINK (guardrail decision block)
|
|
322
|
+
* 5) optionally runs reflection + action hooks
|
|
323
|
+
*
|
|
324
|
+
* Non-breaking by design: you choose what to do with the context.
|
|
325
|
+
*/
|
|
326
|
+
declare const createAgentLoop: (config: AgentLoopConfig) => {
|
|
327
|
+
start: () => Promise<void>;
|
|
328
|
+
stop: () => void;
|
|
329
|
+
runOnce: () => Promise<void>;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
export { type AgentAutonomousTaskKind as A, type AgentLoopStrictMemoryConfig as B, type AgentOwnershipMode as C, type AgentPriorityMode as D, type AgentWorkArbitrationDecision as E, createAgentLoop as F, type IntentSignals as I, type LaneMode as L, type ObjectiveChangeProposal as O, type PromptShieldDecision as P, type LaneSwitchDecision as a, type ObjectiveChangeSourceTrust as b, type ObjectiveGuardDecision as c, type ObjectiveGuardPolicy as d, type PromptShieldFlag as e, type PromptShieldInput as f, type PromptShieldPolicy as g, type PromptShieldRisk as h, type PromptShieldTrustLevel as i, applyIntentArbitration as j, evaluateLaneSwitch as k, evaluateObjectiveChange as l, evaluatePromptShield as m, scorePolishLane as n, type AgentHumanDemand as o, type AgentLoopAutonomyConfig as p, type AgentLoopConfig as q, type AgentLoopContext as r, scoreBuildLane as s, type AgentLoopDurabilityConfig as t, type AgentLoopEscapeHatchConfig as u, type AgentLoopEscapeHatchInput as v, type AgentLoopHooks as w, type AgentLoopMemoryConfig as x, type AgentLoopObjectiveGuardConfig as y, type AgentLoopPromptShieldConfig as z };
|
package/dist/agentLoop.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import './survivalPlaybook.js';
|
|
|
3
3
|
import './survivalEscapeHatch.js';
|
|
4
4
|
import './compoundingMemory.js';
|
|
5
5
|
import './strictMemoryRuntime.js';
|
|
6
|
-
export { A as
|
|
6
|
+
export { A as AgentAutonomousTaskKind, o as AgentHumanDemand, p as AgentLoopAutonomyConfig, q as AgentLoopConfig, r as AgentLoopContext, t as AgentLoopDurabilityConfig, u as AgentLoopEscapeHatchConfig, v as AgentLoopEscapeHatchInput, w as AgentLoopHooks, x as AgentLoopMemoryConfig, y as AgentLoopObjectiveGuardConfig, z as AgentLoopPromptShieldConfig, B as AgentLoopStrictMemoryConfig, C as AgentOwnershipMode, D as AgentPriorityMode, E as AgentResearchSnapshot, F as AgentWorkArbitrationDecision, G as createAgentLoop } from './agentLoop-BPj6daJf.js';
|
package/dist/agentLoop.js
CHANGED
|
@@ -73,6 +73,8 @@ var createAgentLoop = (config) => {
|
|
|
73
73
|
const rolloutMode = config.autonomy?.rolloutMode ?? "enforce";
|
|
74
74
|
const laneSwitchEnabled = config.autonomy?.intentPolicy?.laneSwitch?.enabled ?? true;
|
|
75
75
|
const laneSwitchBuilderThreshold = config.autonomy?.intentPolicy?.laneSwitch?.builderOnGreenStreak ?? 3;
|
|
76
|
+
const researchGateEnabled = config.autonomy?.intentPolicy?.researchGate?.enabled ?? true;
|
|
77
|
+
const researchGateMaxAgeMs = config.autonomy?.intentPolicy?.researchGate?.maxAgeMs ?? 6 * 36e5;
|
|
76
78
|
let laneState = { lane: "polish", greenStreak: 0 };
|
|
77
79
|
const strictMemoryUpgrade = upgradeToStrictMemoryRuntimePreset({
|
|
78
80
|
current: strictMemoryPreset,
|
|
@@ -272,6 +274,16 @@ var createAgentLoop = (config) => {
|
|
|
272
274
|
builderObjectiveAvailable: asBoolean(raw.builderObjectiveAvailable)
|
|
273
275
|
};
|
|
274
276
|
};
|
|
277
|
+
const resolveResearchSnapshot = async (input) => {
|
|
278
|
+
const fromConfig = await config.autonomy?.intentPolicy?.researchGate?.resolveSnapshot?.(input);
|
|
279
|
+
if (fromConfig) return fromConfig;
|
|
280
|
+
const raw = input.snapshot;
|
|
281
|
+
const generatedAt = typeof raw.builderResearchGeneratedAt === "string" ? raw.builderResearchGeneratedAt : typeof raw.researchGeneratedAt === "string" ? raw.researchGeneratedAt : void 0;
|
|
282
|
+
const summary = typeof raw.builderResearchSummary === "string" ? raw.builderResearchSummary : typeof raw.researchSummary === "string" ? raw.researchSummary : void 0;
|
|
283
|
+
const recommendation = typeof raw.builderResearchRecommendation === "string" ? raw.builderResearchRecommendation : typeof raw.researchRecommendation === "string" ? raw.researchRecommendation : void 0;
|
|
284
|
+
if (!generatedAt && !summary && !recommendation) return null;
|
|
285
|
+
return { generatedAt, summary, recommendation };
|
|
286
|
+
};
|
|
275
287
|
const runOnce = async () => {
|
|
276
288
|
try {
|
|
277
289
|
const memoryUpgrade = await ensureMemoryUpgrade();
|
|
@@ -350,6 +362,7 @@ var createAgentLoop = (config) => {
|
|
|
350
362
|
humanDemand,
|
|
351
363
|
runHumanTask: true,
|
|
352
364
|
runAutonomousTask: false,
|
|
365
|
+
autonomousTaskKind: "polish_existing_product",
|
|
353
366
|
reason: "legacy_onAct"
|
|
354
367
|
};
|
|
355
368
|
let laneDecision;
|
|
@@ -407,6 +420,8 @@ var createAgentLoop = (config) => {
|
|
|
407
420
|
}
|
|
408
421
|
}
|
|
409
422
|
}
|
|
423
|
+
arbitrationBase.autonomousTaskKind = arbitrationBase.runAutonomousTask && !humanDemand.pending ? "build_new_product" : "polish_existing_product";
|
|
424
|
+
const researchSnapshot = await resolveResearchSnapshot({ snapshot, survivalMode, humanDemand });
|
|
410
425
|
const ctx = {
|
|
411
426
|
snapshot,
|
|
412
427
|
survivalState,
|
|
@@ -425,6 +440,7 @@ var createAgentLoop = (config) => {
|
|
|
425
440
|
objectiveGuardDecision,
|
|
426
441
|
workArbitration: arbitrationBase,
|
|
427
442
|
laneDecision,
|
|
443
|
+
researchSnapshot: researchSnapshot || void 0,
|
|
428
444
|
timestamp
|
|
429
445
|
};
|
|
430
446
|
if (hooks.onCycle) await hooks.onCycle(ctx);
|
|
@@ -442,7 +458,9 @@ var createAgentLoop = (config) => {
|
|
|
442
458
|
};
|
|
443
459
|
const runAutonomousTask = async () => {
|
|
444
460
|
if (!config.autonomy?.onAutonomous) return;
|
|
445
|
-
await config.autonomy.onAutonomous(ctx
|
|
461
|
+
await config.autonomy.onAutonomous(ctx, {
|
|
462
|
+
kind: ctx.workArbitration?.autonomousTaskKind || "polish_existing_product"
|
|
463
|
+
});
|
|
446
464
|
};
|
|
447
465
|
if (strictMemoryEnabled && strictMode === "enforce" && ctx.strictMemoryEvaluation && !ctx.strictMemoryEvaluation.allowed) {
|
|
448
466
|
const missing = ctx.strictMemoryEvaluation.missingSteps.join(",");
|
|
@@ -455,6 +473,19 @@ var createAgentLoop = (config) => {
|
|
|
455
473
|
if (objectiveGuardEnabled && objectiveGuardMode === "enforce" && ctx.objectiveGuardDecision && !ctx.objectiveGuardDecision.allowObjectiveChange) {
|
|
456
474
|
throw new Error(`objective_guard_blocked:${ctx.objectiveGuardDecision.reason}`);
|
|
457
475
|
}
|
|
476
|
+
if (rolloutMode === "enforce" && researchGateEnabled && ctx.workArbitration?.runAutonomousTask && ctx.workArbitration?.autonomousTaskKind === "build_new_product") {
|
|
477
|
+
const generatedAt = ctx.researchSnapshot?.generatedAt;
|
|
478
|
+
const hasResearch = Boolean(generatedAt || ctx.researchSnapshot?.summary || ctx.researchSnapshot?.recommendation);
|
|
479
|
+
if (!hasResearch) {
|
|
480
|
+
throw new Error("research_gate_blocked:missing_research_snapshot");
|
|
481
|
+
}
|
|
482
|
+
if (generatedAt) {
|
|
483
|
+
const ageMs = Date.now() - Date.parse(generatedAt);
|
|
484
|
+
if (!Number.isFinite(ageMs) || ageMs > researchGateMaxAgeMs) {
|
|
485
|
+
throw new Error("research_gate_blocked:stale_research_snapshot");
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
458
489
|
if (autonomyEnabled && config.autonomy?.onAutonomous && rolloutMode === "enforce") {
|
|
459
490
|
if (ctx.workArbitration?.runHumanTask) await runHumanTask();
|
|
460
491
|
if (ctx.workArbitration?.runAutonomousTask) await runAutonomousTask();
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { MarketDiscoveryClient, MarketNeed, MarketSignal, deriveMarketNeeds, dis
|
|
|
9
9
|
export { A as AdapterBestShotChecklistResult, a as AdapterPackKind, b as AdapterPackOptions, c as AdaptiveAdaptationPlan, d as AdaptiveExecution, e as AdaptiveFeedbackAggregate, f as AdaptivePolicyConfig, g as AdaptivePolicyDecision, h as AdaptivePolicyState, i as AdaptiveReflectionStore, j as AdaptiveTheme, k as AdaptiveVerification, l as AgentLaunchRuntimeOptions, m as AgentLaunchRuntimeResult, n as AgentResourceProvidersManifest, o as AgentReviewRuntimeOptions, p as AnalyticsPoint, q as ApiCreditProvider, r as ApiCreditProviderFactoryOptions, s as ApiCreditProviderPreset, t as ApiCreditProviderPresetInput, u as ApiResponse, B as BuybackEvent, C as CONTEXT_PACK_SECTION_ORDER, v as ContextPack, w as ContextPackBudget, x as ContextPackGateOptions, y as ContextPackGateResult, z as ContextPackInput, D as ContextPackOptions, E as ContextPackSectionKey, F as ContextPackSections, G as ContextPackState, H as DurabilityCheckpointWriteOptions, I as DurabilityProxyClientOptions, J as DurabilityRestoreDrillWriteOptions, K as ExecutionAdapter, L as ExecutionApplyResult, M as ExecutionDecisionRecord, N as ExecutionDryRunResult, O as ExecutionPostDeployVerifyResult, P as ExecutionRollbackResult, Q as ExecutionRolloutMode, R as ExecutionRunResult, S as ExecutionValidateResult, T as LISTING_NAME_MAX_LENGTH, U as LISTING_NAME_RECOMMENDED_MAX, V as LISTING_TAGLINE_MAX_LENGTH, W as LISTING_TAGLINE_RECOMMENDED_MAX, X as LaunchProfile, Y as LaunchReadinessInput, Z as LaunchReadinessResult, _ as LeaderboardEntry, $ as LeaderboardQuery, a0 as ListingNamingValidationOptions, a1 as ListingNamingValidationResult, a2 as ListingQuery, a3 as ListingReviewCreatePayload, a4 as ListingReviewResponsePayload, a5 as ListingVersionPayload, a6 as MarketingCampaign, a7 as MarketingLinkOptions, a8 as MemoryPingChallengeResponse, a9 as MemoryPingPayload, aa as OpenRouterCredits, ab as ProcurementCandidate, ac as ProcurementDecision, ad as ProcurementTaskProfile, ae as ProcurementWeights, af as ResourceProviderManifestEntry, ag as ResourceSnapshot, ah as ReviewGate, ai as ReviewGateRecord, aj as ReviewRequiredPayload, ak as RunAdaptiveReflectionOptions, al as RuntimeMigrationInput, am as RuntimeMigrationPlan, an as RuntimeStateSnapshot, ao as SdkAutoUpdatedRestartRequiredError, ap as SdkUpdateCheckOptions, aq as SdkUpdatePolicyCheckOptions, ar as SdkUpdateRequiredError, as as SdkUpdateStatus, TopupDecision, TopupRequest, TreasuryLedgerEvent, TreasuryPolicy, TreasuryPolicyV1, TreasuryState, at as VIBEIAO_IDL, au as VibeClient, av as VibeClientOptions, aw as VibeRegistry, ax as aggregateFeedbackSignals, ay as assertLaunchReady, az as assertSurvivalProvidersConfigured, aA as buildAdaptivePlan, aB as buildBadgeMarkdown, aC as buildClaimMessage, aD as buildDecisionRecord, aE as buildJupiterSwapUrl, aF as buildListingVersionMessage, aG as buildMemoryPingMessage, aH as buildOwnerTransferMessage, aI as buildProcurementPrompt, aJ as buildRaydiumSwapUrl, aK as buildReviewPrompt, aL as buildReviewRequired, aM as buildReviewResponseMessage, aN as buildRuntimeMigrationPlan, aO as buildSdkUpdateCommand, aP as buildShareCopy, aQ as buildShareLink, aR as buildTradeLinks, buildTreasuryLedgerEvent, aS as checkForSdkUpdate, aT as checkForSdkUpdatePolicy, aU as compareVersions, aV as createApiCreditProvider, aW as createApiCreditProviders, aX as createApiCreditProvidersFromManifest, aY as createCampaign, aZ as createContextPack, a_ as createCustomAdapter, a$ as createDurabilityProxyClient, b0 as createServiceApiAdapter, createTreasuryPolicy, b1 as createWebBundledAdapter, b2 as createWebStaticAdapter, b3 as createWorkflowAgentAdapter, b4 as decideProcurementForTask, b5 as estimateContextPackTokens, b6 as evaluateAdaptiveReflectionPolicy, b7 as evaluateContextPackGate, b8 as evaluateLaunchReadiness, evaluateTopupRequest, b9 as getResourceSnapshot, ba as normalizeListingText, bb as rankListingsForTask, bc as runAdapterBestShotChecklist, bd as runAdaptiveReflectionCycle, be as runAgentLaunchRuntime, bf as runAgentLaunchRuntimeCycle, bg as runAgentReviewRuntimeCycle, bh as runExecutionAdapter, bi as sanitizeListingNaming, bj as scoreListingForTask, bk as shouldAnnounceStateChange, treasuryStateFromSnapshot, bl as validateContextPack, bm as validateListingNaming, validateTreasuryPolicy, bn as verifyAdaptiveExecutionReadiness } from './treasuryGuardian.js';
|
|
10
10
|
export { OUTCOME_BOUND_FLOW_SCHEMA, OUTCOME_BOUND_REQUIRED_GATES, OutcomeBoundRequiredGate, OutcomeBoundRunInput, OutcomeBoundRunStatus, assertOutcomeBoundCompleted, evaluateOutcomeBoundRun } from './outcomeBoundFlow.js';
|
|
11
11
|
export { STRICT_MEMORY_RUNTIME_SCHEMA, StrictMemoryEvaluation, StrictMemoryEvaluationInput, StrictMemoryRuntimePreset, StrictMemoryTriggerSet, StrictMemoryUpgradeInput, StrictMemoryUpgradePolicy, StrictMemoryUpgradeResult, createStrictMemoryRuntimePreset, evaluateStrictMemoryExecution, isComplexTask, upgradeToStrictMemoryRuntimePreset } from './strictMemoryRuntime.js';
|
|
12
|
-
export { I as IntentSignals, L as LaneMode, a as LaneSwitchDecision, O as ObjectiveChangeProposal, b as ObjectiveChangeSourceTrust, c as ObjectiveGuardDecision, d as ObjectiveGuardPolicy, P as PromptShieldDecision, e as PromptShieldFlag, f as PromptShieldInput, g as PromptShieldPolicy, h as PromptShieldRisk, i as PromptShieldTrustLevel, j as applyIntentArbitration, k as evaluateLaneSwitch, l as evaluateObjectiveChange, m as evaluatePromptShield, s as scoreBuildLane, n as scorePolishLane } from './agentLoop-
|
|
12
|
+
export { I as IntentSignals, L as LaneMode, a as LaneSwitchDecision, O as ObjectiveChangeProposal, b as ObjectiveChangeSourceTrust, c as ObjectiveGuardDecision, d as ObjectiveGuardPolicy, P as PromptShieldDecision, e as PromptShieldFlag, f as PromptShieldInput, g as PromptShieldPolicy, h as PromptShieldRisk, i as PromptShieldTrustLevel, j as applyIntentArbitration, k as evaluateLaneSwitch, l as evaluateObjectiveChange, m as evaluatePromptShield, s as scoreBuildLane, n as scorePolishLane } from './agentLoop-BPj6daJf.js';
|
|
13
13
|
export { fetchSolBalance, fetchTokenBalance, fetchTokenBalances } from './solana.js';
|
|
14
14
|
import './compoundingMemory.js';
|
|
15
15
|
import '@coral-xyz/anchor';
|
package/dist/index.js
CHANGED
|
@@ -1112,7 +1112,7 @@ var ReviewGate = class {
|
|
|
1112
1112
|
var DEFAULT_API_BASE = "https://api.vibeiao.com";
|
|
1113
1113
|
var DEFAULT_WEB_BASE = "https://vibeiao.com";
|
|
1114
1114
|
var DEFAULT_SDK_PACKAGE = "@vibeiao/sdk";
|
|
1115
|
-
var DEFAULT_SDK_VERSION = "0.1.
|
|
1115
|
+
var DEFAULT_SDK_VERSION = "0.1.54" ? "0.1.54" : "0.1.4";
|
|
1116
1116
|
var DEFAULT_SDK_REGISTRY = "https://registry.npmjs.org";
|
|
1117
1117
|
var DEFAULT_SDK_POLICY_PATH = "/v1/sdk/policy";
|
|
1118
1118
|
var DEFAULT_SDK_CHECK_INTERVAL_MS = 1e3 * 60 * 30;
|
|
@@ -8,7 +8,7 @@ import './survivalEscapeHatch.js';
|
|
|
8
8
|
import './marketDiscovery.js';
|
|
9
9
|
import './outcomeBoundFlow.js';
|
|
10
10
|
import './strictMemoryRuntime.js';
|
|
11
|
-
import './agentLoop-
|
|
11
|
+
import './agentLoop-BPj6daJf.js';
|
|
12
12
|
import './solana.js';
|
|
13
13
|
import './compoundingMemory.js';
|
|
14
14
|
import '@coral-xyz/anchor';
|
|
@@ -1474,7 +1474,7 @@ declare class ReviewGate {
|
|
|
1474
1474
|
assertClear(listingId: string, wallet: string): void;
|
|
1475
1475
|
}
|
|
1476
1476
|
|
|
1477
|
-
declare const compareVersions: (currentVersion: string, latestVersion: string) =>
|
|
1477
|
+
declare const compareVersions: (currentVersion: string, latestVersion: string) => 0 | 1 | -1;
|
|
1478
1478
|
declare const buildSdkUpdateCommand: (packageName?: string) => string;
|
|
1479
1479
|
declare const checkForSdkUpdate: (options?: SdkUpdateCheckOptions) => Promise<SdkUpdateStatus>;
|
|
1480
1480
|
declare const checkForSdkUpdatePolicy: (options: SdkUpdatePolicyCheckOptions) => Promise<SdkUpdateStatus>;
|