@vibeiao/sdk 0.1.49 → 0.1.50
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/README.md +1 -0
- package/dist/agentLoop-Dn6aMtRD.d.ts +302 -0
- package/dist/agentLoop.d.ts +6 -226
- package/dist/agentLoop.js +26 -1
- package/dist/chunk-WFOLCIJC.js +294 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +9 -3
- package/dist/treasuryGuardian.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -697,6 +697,7 @@ Adapter packs + migration helpers:
|
|
|
697
697
|
- use `runAgentLaunchRuntimeCycle` (alias of launch runtime) to enforce launch gate before publish execution
|
|
698
698
|
- use `buildRuntimeMigrationPlan` to migrate legacy runtime scripts to adapter-based review runtime
|
|
699
699
|
- use `shouldAnnounceStateChange` to suppress repetitive green cron/runtime notifications and only emit meaningful changes
|
|
700
|
+
- use intent arbitration in `createAgentLoop` autonomy config to balance build lane (new value) and polish lane (review-driven fixes) against survival mode
|
|
700
701
|
|
|
701
702
|
You can also enforce dual-mode work arbitration:
|
|
702
703
|
- `owner_bound` agents: human-first (owner work preempts autonomous work)
|
|
@@ -0,0 +1,302 @@
|
|
|
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
|
+
};
|
|
68
|
+
declare const scoreBuildLane: (signals: IntentSignals, survivalMode: SurvivalMode) => number;
|
|
69
|
+
declare const scorePolishLane: (signals: IntentSignals, survivalMode: SurvivalMode, humanDemand: AgentHumanDemand) => number;
|
|
70
|
+
declare const applyIntentArbitration: (input: {
|
|
71
|
+
base: AgentWorkArbitrationDecision;
|
|
72
|
+
survivalMode: SurvivalMode;
|
|
73
|
+
signals?: IntentSignals;
|
|
74
|
+
}) => AgentWorkArbitrationDecision;
|
|
75
|
+
|
|
76
|
+
type AgentLoopEscapeHatchInput = {
|
|
77
|
+
snapshot: ResourceSnapshot;
|
|
78
|
+
survivalState: SelfRelianceState;
|
|
79
|
+
survivalMode: SurvivalMode;
|
|
80
|
+
timestamp: number;
|
|
81
|
+
};
|
|
82
|
+
type AgentLoopEscapeHatchConfig = {
|
|
83
|
+
/** Enable auto escape-hatch evaluation (default true, only in SURVIVE/BLINK). */
|
|
84
|
+
enabled?: boolean;
|
|
85
|
+
policy?: EscapeHatchPolicy;
|
|
86
|
+
resolveEnv?: (name: string) => string | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Optional mapper from loop context -> escape hatch snapshot.
|
|
89
|
+
* If omitted, a default mapper reads optional fields from snapshot.
|
|
90
|
+
*/
|
|
91
|
+
buildSnapshot?: (input: AgentLoopEscapeHatchInput) => EscapeHatchSnapshot | null | undefined;
|
|
92
|
+
/** Called when an escape-hatch decision is produced. */
|
|
93
|
+
onDecision?: (decision: EscapeHatchDecision, input: AgentLoopEscapeHatchInput) => Promise<void> | void;
|
|
94
|
+
};
|
|
95
|
+
type AgentLoopStrictMemoryConfig = {
|
|
96
|
+
/** Enable strict memory runtime checks in loop. Default true. */
|
|
97
|
+
enabled?: boolean;
|
|
98
|
+
/** observe (default) records decisions; enforce blocks onAct when checks fail. */
|
|
99
|
+
mode?: 'observe' | 'enforce';
|
|
100
|
+
/** Optional preset overrides. */
|
|
101
|
+
preset?: Partial<StrictMemoryRuntimePreset>;
|
|
102
|
+
/** Build per-cycle evaluation input. Defaults to best-effort snapshot fields. */
|
|
103
|
+
buildInput?: (ctx: {
|
|
104
|
+
snapshot: ResourceSnapshot;
|
|
105
|
+
timestamp: number;
|
|
106
|
+
}) => {
|
|
107
|
+
taskText: string;
|
|
108
|
+
isMutation: boolean;
|
|
109
|
+
contextPackPrepared: boolean;
|
|
110
|
+
semanticRecallConfirmed: boolean;
|
|
111
|
+
approvalPreflightPassed: boolean;
|
|
112
|
+
};
|
|
113
|
+
/** Optional hook when strict-memory evaluation runs. */
|
|
114
|
+
onEvaluation?: (ev: StrictMemoryEvaluation) => Promise<void> | void;
|
|
115
|
+
};
|
|
116
|
+
type AgentLoopPromptShieldConfig = {
|
|
117
|
+
/** Enable prompt-injection shield over untrusted external content. Default true. */
|
|
118
|
+
enabled?: boolean;
|
|
119
|
+
/** observe logs/records only; enforce blocks actions when shield fails. Default observe. */
|
|
120
|
+
mode?: 'observe' | 'enforce';
|
|
121
|
+
/** Optional policy overrides for blocked flags. */
|
|
122
|
+
policy?: PromptShieldPolicy;
|
|
123
|
+
/** Optional mapper from snapshot to trust-labeled inputs. */
|
|
124
|
+
buildInputs?: (ctx: {
|
|
125
|
+
snapshot: ResourceSnapshot;
|
|
126
|
+
timestamp: number;
|
|
127
|
+
}) => PromptShieldInput[];
|
|
128
|
+
/** Optional hook when prompt shield decision is produced. */
|
|
129
|
+
onDecision?: (decision: PromptShieldDecision) => Promise<void> | void;
|
|
130
|
+
};
|
|
131
|
+
type AgentLoopObjectiveGuardConfig = {
|
|
132
|
+
/** Enable objective integrity checks for external objective-change attempts. Default true. */
|
|
133
|
+
enabled?: boolean;
|
|
134
|
+
/** observe logs only; enforce blocks actions when objective mutation is denied. Default observe. */
|
|
135
|
+
mode?: 'observe' | 'enforce';
|
|
136
|
+
/** Policy requirements for external objective mutation acceptance. */
|
|
137
|
+
policy?: ObjectiveGuardPolicy;
|
|
138
|
+
/** Build proposed objective change from snapshot. Return null when no proposal is present. */
|
|
139
|
+
buildProposal?: (ctx: {
|
|
140
|
+
snapshot: ResourceSnapshot;
|
|
141
|
+
timestamp: number;
|
|
142
|
+
}) => ObjectiveChangeProposal | null;
|
|
143
|
+
/** Optional hook when objective decision is produced. */
|
|
144
|
+
onDecision?: (decision: ObjectiveGuardDecision) => Promise<void> | void;
|
|
145
|
+
};
|
|
146
|
+
type AgentOwnershipMode = 'owner_bound' | 'unbound';
|
|
147
|
+
type AgentPriorityMode = 'human_first' | 'autonomous_first';
|
|
148
|
+
type AgentHumanDemand = {
|
|
149
|
+
pending: boolean;
|
|
150
|
+
count?: number;
|
|
151
|
+
source?: string;
|
|
152
|
+
};
|
|
153
|
+
type AgentWorkArbitrationDecision = {
|
|
154
|
+
ownershipMode: AgentOwnershipMode;
|
|
155
|
+
priorityMode: AgentPriorityMode;
|
|
156
|
+
rolloutMode: 'observe' | 'enforce';
|
|
157
|
+
humanDemand: AgentHumanDemand;
|
|
158
|
+
runHumanTask: boolean;
|
|
159
|
+
runAutonomousTask: boolean;
|
|
160
|
+
reason: string;
|
|
161
|
+
};
|
|
162
|
+
type AgentLoopAutonomyConfig = {
|
|
163
|
+
enabled?: boolean;
|
|
164
|
+
ownershipMode?: AgentOwnershipMode;
|
|
165
|
+
priorityMode?: AgentPriorityMode;
|
|
166
|
+
rolloutMode?: 'observe' | 'enforce';
|
|
167
|
+
resolveHumanDemand?: () => Promise<boolean | AgentHumanDemand> | boolean | AgentHumanDemand;
|
|
168
|
+
intentPolicy?: {
|
|
169
|
+
enabled?: boolean;
|
|
170
|
+
resolveSignals?: (ctx: {
|
|
171
|
+
snapshot: ResourceSnapshot;
|
|
172
|
+
survivalMode: SurvivalMode;
|
|
173
|
+
humanDemand: AgentHumanDemand;
|
|
174
|
+
}) => Promise<IntentSignals | null> | IntentSignals | null;
|
|
175
|
+
};
|
|
176
|
+
onAutonomous?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
177
|
+
onArbitration?: (decision: AgentWorkArbitrationDecision, ctx: AgentLoopContext) => Promise<void> | void;
|
|
178
|
+
};
|
|
179
|
+
type AgentLoopContext = {
|
|
180
|
+
snapshot: ResourceSnapshot;
|
|
181
|
+
survivalState: SelfRelianceState;
|
|
182
|
+
survivalMode: SurvivalMode;
|
|
183
|
+
survivalRecommendation: SurvivalRecommendation;
|
|
184
|
+
survivalFormatted: string;
|
|
185
|
+
/** Deterministic block for planners/loggers: survival + escape-hatch decision (if present). */
|
|
186
|
+
survivalDecisionBlock: string;
|
|
187
|
+
/** Present when escape-hatch evaluation runs (SURVIVE/BLINK by default). */
|
|
188
|
+
escapeHatchDecision?: EscapeHatchDecision;
|
|
189
|
+
escapeHatchFormatted?: string;
|
|
190
|
+
/** Present when memory auto-upgrade is enabled in the loop. */
|
|
191
|
+
memoryUpgrade?: CompoundingMemoryUpgradeResult;
|
|
192
|
+
/** Present when required-set maintenance check runs (default daily). */
|
|
193
|
+
memoryRequiredSet?: CompoundingMemoryRequiredSetResult;
|
|
194
|
+
/** Strict-memory runtime preset + per-cycle evaluation status. */
|
|
195
|
+
strictMemoryPreset?: StrictMemoryRuntimePreset;
|
|
196
|
+
strictMemoryEvaluation?: StrictMemoryEvaluation;
|
|
197
|
+
strictMemoryUpgrade?: StrictMemoryUpgradeResult;
|
|
198
|
+
/** Prompt-injection shield decision for this cycle. */
|
|
199
|
+
promptShieldDecision?: PromptShieldDecision;
|
|
200
|
+
/** Objective integrity guard decision for this cycle (when proposal exists). */
|
|
201
|
+
objectiveGuardDecision?: ObjectiveGuardDecision;
|
|
202
|
+
/** Human-vs-autonomous work arbitration decision for this cycle. */
|
|
203
|
+
workArbitration?: AgentWorkArbitrationDecision;
|
|
204
|
+
timestamp: number;
|
|
205
|
+
};
|
|
206
|
+
type AgentLoopMemoryConfig = {
|
|
207
|
+
/** Enable one-time memory scaffold upgrade. Default true. */
|
|
208
|
+
enabled?: boolean;
|
|
209
|
+
/** Workspace root for compounding memory files. Default current working directory ("."). */
|
|
210
|
+
root?: string;
|
|
211
|
+
/** Timezone for daily ledger date key. Default UTC. */
|
|
212
|
+
timeZone?: string;
|
|
213
|
+
/** Hook called after memory upgrade check completes. */
|
|
214
|
+
onUpgrade?: (result: CompoundingMemoryUpgradeResult) => Promise<void> | void;
|
|
215
|
+
/** Enable required-set maintenance checks (bounded working state + recall substrate + restore drill). Default true. */
|
|
216
|
+
requiredSetEnabled?: boolean;
|
|
217
|
+
/** Interval for required-set checks. Default 24h. */
|
|
218
|
+
requiredSetIntervalMs?: number;
|
|
219
|
+
/** Run required-set check on first loop cycle. Default true. */
|
|
220
|
+
requiredSetRunOnStart?: boolean;
|
|
221
|
+
/** Include backup+restore drill in required-set check. Default true. */
|
|
222
|
+
requiredSetRunRestoreDrill?: boolean;
|
|
223
|
+
/** Hook called when required-set check runs. */
|
|
224
|
+
onRequiredSet?: (result: CompoundingMemoryRequiredSetResult) => Promise<void> | void;
|
|
225
|
+
};
|
|
226
|
+
type AgentLoopDurabilityConfig = {
|
|
227
|
+
/** Enable durability-proxy writes from runtime loop. Default false. */
|
|
228
|
+
enabled?: boolean;
|
|
229
|
+
/** Durability-proxy base URL (e.g. http://127.0.0.1:8790). */
|
|
230
|
+
baseUrl: string;
|
|
231
|
+
/** Agent id registered in durability-proxy. */
|
|
232
|
+
agentId: string;
|
|
233
|
+
/** Agent token registered in durability-proxy. */
|
|
234
|
+
agentToken: string;
|
|
235
|
+
/** Optional timeout for durability-proxy calls. Default 8000ms. */
|
|
236
|
+
timeoutMs?: number;
|
|
237
|
+
/** Write checkpoint after each required-set run. Default true. */
|
|
238
|
+
checkpointOnRequiredSet?: boolean;
|
|
239
|
+
/** Write restore-drill outcome when required-set includes restore drill. Default true. */
|
|
240
|
+
reportRestoreDrill?: boolean;
|
|
241
|
+
/** Called when durability checkpoint is written. */
|
|
242
|
+
onCheckpointWritten?: (result: {
|
|
243
|
+
checkpointId?: string;
|
|
244
|
+
createdAt?: string;
|
|
245
|
+
checkedAt: string;
|
|
246
|
+
}) => Promise<void> | void;
|
|
247
|
+
/** Called when durability restore drill signal is written. */
|
|
248
|
+
onRestoreDrillReported?: (result: {
|
|
249
|
+
ok: boolean;
|
|
250
|
+
ts?: string;
|
|
251
|
+
checkedAt: string;
|
|
252
|
+
}) => Promise<void> | void;
|
|
253
|
+
};
|
|
254
|
+
type AgentLoopHooks = {
|
|
255
|
+
/** Called every cycle after snapshot is fetched and survival state is updated. */
|
|
256
|
+
onCycle?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
257
|
+
/**
|
|
258
|
+
* Optional: run reflection in the loop.
|
|
259
|
+
* Keep this hook pure/side-effect bounded; it should manage its own persistence.
|
|
260
|
+
*/
|
|
261
|
+
onReflection?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
262
|
+
/**
|
|
263
|
+
* Optional: the agent's planner/executor entrypoint.
|
|
264
|
+
* This is where you actually "act like a human" using ctx + your own memory.
|
|
265
|
+
*/
|
|
266
|
+
onAct?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
267
|
+
onError?: (err: Error) => Promise<void> | void;
|
|
268
|
+
};
|
|
269
|
+
type AgentLoopConfig = {
|
|
270
|
+
survival: SelfReliance;
|
|
271
|
+
fetchSnapshot: () => Promise<ResourceSnapshot>;
|
|
272
|
+
intervalMs?: number;
|
|
273
|
+
/** If true, call survival.guard() before onAct(). Default true. */
|
|
274
|
+
guardAct?: boolean;
|
|
275
|
+
/** Optional override for time source (tests). */
|
|
276
|
+
now?: () => number;
|
|
277
|
+
hooks?: AgentLoopHooks;
|
|
278
|
+
escapeHatch?: AgentLoopEscapeHatchConfig;
|
|
279
|
+
memory?: AgentLoopMemoryConfig;
|
|
280
|
+
durability?: AgentLoopDurabilityConfig;
|
|
281
|
+
strictMemory?: AgentLoopStrictMemoryConfig;
|
|
282
|
+
promptShield?: AgentLoopPromptShieldConfig;
|
|
283
|
+
objectiveGuard?: AgentLoopObjectiveGuardConfig;
|
|
284
|
+
autonomy?: AgentLoopAutonomyConfig;
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Create a closed-loop runner that:
|
|
288
|
+
* 1) fetches a resource snapshot
|
|
289
|
+
* 2) updates SelfReliance
|
|
290
|
+
* 3) classifies survival mode + produces a playbook recommendation
|
|
291
|
+
* 4) auto-evaluates escape hatch in SURVIVE/BLINK (guardrail decision block)
|
|
292
|
+
* 5) optionally runs reflection + action hooks
|
|
293
|
+
*
|
|
294
|
+
* Non-breaking by design: you choose what to do with the context.
|
|
295
|
+
*/
|
|
296
|
+
declare const createAgentLoop: (config: AgentLoopConfig) => {
|
|
297
|
+
start: () => Promise<void>;
|
|
298
|
+
stop: () => void;
|
|
299
|
+
runOnce: () => Promise<void>;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
export { type AgentHumanDemand as A, type AgentWorkArbitrationDecision as B, createAgentLoop as C, type IntentSignals as I, type ObjectiveChangeProposal as O, type PromptShieldDecision as P, type ObjectiveChangeSourceTrust as a, type ObjectiveGuardDecision as b, type ObjectiveGuardPolicy as c, type PromptShieldFlag as d, type PromptShieldInput as e, type PromptShieldPolicy as f, type PromptShieldRisk as g, type PromptShieldTrustLevel as h, applyIntentArbitration as i, evaluateObjectiveChange as j, evaluatePromptShield as k, scorePolishLane as l, type AgentLoopAutonomyConfig as m, type AgentLoopConfig as n, type AgentLoopContext as o, type AgentLoopDurabilityConfig as p, type AgentLoopEscapeHatchConfig as q, type AgentLoopEscapeHatchInput as r, scoreBuildLane as s, type AgentLoopHooks as t, type AgentLoopMemoryConfig as u, type AgentLoopObjectiveGuardConfig as v, type AgentLoopPromptShieldConfig as w, type AgentLoopStrictMemoryConfig as x, type AgentOwnershipMode as y, type AgentPriorityMode as z };
|
package/dist/agentLoop.d.ts
CHANGED
|
@@ -1,226 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type AgentLoopEscapeHatchInput = {
|
|
9
|
-
snapshot: ResourceSnapshot;
|
|
10
|
-
survivalState: SelfRelianceState;
|
|
11
|
-
survivalMode: SurvivalMode;
|
|
12
|
-
timestamp: number;
|
|
13
|
-
};
|
|
14
|
-
type AgentLoopEscapeHatchConfig = {
|
|
15
|
-
/** Enable auto escape-hatch evaluation (default true, only in SURVIVE/BLINK). */
|
|
16
|
-
enabled?: boolean;
|
|
17
|
-
policy?: EscapeHatchPolicy;
|
|
18
|
-
resolveEnv?: (name: string) => string | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Optional mapper from loop context -> escape hatch snapshot.
|
|
21
|
-
* If omitted, a default mapper reads optional fields from snapshot.
|
|
22
|
-
*/
|
|
23
|
-
buildSnapshot?: (input: AgentLoopEscapeHatchInput) => EscapeHatchSnapshot | null | undefined;
|
|
24
|
-
/** Called when an escape-hatch decision is produced. */
|
|
25
|
-
onDecision?: (decision: EscapeHatchDecision, input: AgentLoopEscapeHatchInput) => Promise<void> | void;
|
|
26
|
-
};
|
|
27
|
-
type AgentLoopStrictMemoryConfig = {
|
|
28
|
-
/** Enable strict memory runtime checks in loop. Default true. */
|
|
29
|
-
enabled?: boolean;
|
|
30
|
-
/** observe (default) records decisions; enforce blocks onAct when checks fail. */
|
|
31
|
-
mode?: 'observe' | 'enforce';
|
|
32
|
-
/** Optional preset overrides. */
|
|
33
|
-
preset?: Partial<StrictMemoryRuntimePreset>;
|
|
34
|
-
/** Build per-cycle evaluation input. Defaults to best-effort snapshot fields. */
|
|
35
|
-
buildInput?: (ctx: {
|
|
36
|
-
snapshot: ResourceSnapshot;
|
|
37
|
-
timestamp: number;
|
|
38
|
-
}) => {
|
|
39
|
-
taskText: string;
|
|
40
|
-
isMutation: boolean;
|
|
41
|
-
contextPackPrepared: boolean;
|
|
42
|
-
semanticRecallConfirmed: boolean;
|
|
43
|
-
approvalPreflightPassed: boolean;
|
|
44
|
-
};
|
|
45
|
-
/** Optional hook when strict-memory evaluation runs. */
|
|
46
|
-
onEvaluation?: (ev: StrictMemoryEvaluation) => Promise<void> | void;
|
|
47
|
-
};
|
|
48
|
-
type AgentLoopPromptShieldConfig = {
|
|
49
|
-
/** Enable prompt-injection shield over untrusted external content. Default true. */
|
|
50
|
-
enabled?: boolean;
|
|
51
|
-
/** observe logs/records only; enforce blocks actions when shield fails. Default observe. */
|
|
52
|
-
mode?: 'observe' | 'enforce';
|
|
53
|
-
/** Optional policy overrides for blocked flags. */
|
|
54
|
-
policy?: PromptShieldPolicy;
|
|
55
|
-
/** Optional mapper from snapshot to trust-labeled inputs. */
|
|
56
|
-
buildInputs?: (ctx: {
|
|
57
|
-
snapshot: ResourceSnapshot;
|
|
58
|
-
timestamp: number;
|
|
59
|
-
}) => PromptShieldInput[];
|
|
60
|
-
/** Optional hook when prompt shield decision is produced. */
|
|
61
|
-
onDecision?: (decision: PromptShieldDecision) => Promise<void> | void;
|
|
62
|
-
};
|
|
63
|
-
type AgentLoopObjectiveGuardConfig = {
|
|
64
|
-
/** Enable objective integrity checks for external objective-change attempts. Default true. */
|
|
65
|
-
enabled?: boolean;
|
|
66
|
-
/** observe logs only; enforce blocks actions when objective mutation is denied. Default observe. */
|
|
67
|
-
mode?: 'observe' | 'enforce';
|
|
68
|
-
/** Policy requirements for external objective mutation acceptance. */
|
|
69
|
-
policy?: ObjectiveGuardPolicy;
|
|
70
|
-
/** Build proposed objective change from snapshot. Return null when no proposal is present. */
|
|
71
|
-
buildProposal?: (ctx: {
|
|
72
|
-
snapshot: ResourceSnapshot;
|
|
73
|
-
timestamp: number;
|
|
74
|
-
}) => ObjectiveChangeProposal | null;
|
|
75
|
-
/** Optional hook when objective decision is produced. */
|
|
76
|
-
onDecision?: (decision: ObjectiveGuardDecision) => Promise<void> | void;
|
|
77
|
-
};
|
|
78
|
-
type AgentOwnershipMode = 'owner_bound' | 'unbound';
|
|
79
|
-
type AgentPriorityMode = 'human_first' | 'autonomous_first';
|
|
80
|
-
type AgentHumanDemand = {
|
|
81
|
-
pending: boolean;
|
|
82
|
-
count?: number;
|
|
83
|
-
source?: string;
|
|
84
|
-
};
|
|
85
|
-
type AgentWorkArbitrationDecision = {
|
|
86
|
-
ownershipMode: AgentOwnershipMode;
|
|
87
|
-
priorityMode: AgentPriorityMode;
|
|
88
|
-
rolloutMode: 'observe' | 'enforce';
|
|
89
|
-
humanDemand: AgentHumanDemand;
|
|
90
|
-
runHumanTask: boolean;
|
|
91
|
-
runAutonomousTask: boolean;
|
|
92
|
-
reason: string;
|
|
93
|
-
};
|
|
94
|
-
type AgentLoopAutonomyConfig = {
|
|
95
|
-
enabled?: boolean;
|
|
96
|
-
ownershipMode?: AgentOwnershipMode;
|
|
97
|
-
priorityMode?: AgentPriorityMode;
|
|
98
|
-
rolloutMode?: 'observe' | 'enforce';
|
|
99
|
-
resolveHumanDemand?: () => Promise<boolean | AgentHumanDemand> | boolean | AgentHumanDemand;
|
|
100
|
-
onAutonomous?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
101
|
-
onArbitration?: (decision: AgentWorkArbitrationDecision, ctx: AgentLoopContext) => Promise<void> | void;
|
|
102
|
-
};
|
|
103
|
-
type AgentLoopContext = {
|
|
104
|
-
snapshot: ResourceSnapshot;
|
|
105
|
-
survivalState: SelfRelianceState;
|
|
106
|
-
survivalMode: SurvivalMode;
|
|
107
|
-
survivalRecommendation: SurvivalRecommendation;
|
|
108
|
-
survivalFormatted: string;
|
|
109
|
-
/** Deterministic block for planners/loggers: survival + escape-hatch decision (if present). */
|
|
110
|
-
survivalDecisionBlock: string;
|
|
111
|
-
/** Present when escape-hatch evaluation runs (SURVIVE/BLINK by default). */
|
|
112
|
-
escapeHatchDecision?: EscapeHatchDecision;
|
|
113
|
-
escapeHatchFormatted?: string;
|
|
114
|
-
/** Present when memory auto-upgrade is enabled in the loop. */
|
|
115
|
-
memoryUpgrade?: CompoundingMemoryUpgradeResult;
|
|
116
|
-
/** Present when required-set maintenance check runs (default daily). */
|
|
117
|
-
memoryRequiredSet?: CompoundingMemoryRequiredSetResult;
|
|
118
|
-
/** Strict-memory runtime preset + per-cycle evaluation status. */
|
|
119
|
-
strictMemoryPreset?: StrictMemoryRuntimePreset;
|
|
120
|
-
strictMemoryEvaluation?: StrictMemoryEvaluation;
|
|
121
|
-
strictMemoryUpgrade?: StrictMemoryUpgradeResult;
|
|
122
|
-
/** Prompt-injection shield decision for this cycle. */
|
|
123
|
-
promptShieldDecision?: PromptShieldDecision;
|
|
124
|
-
/** Objective integrity guard decision for this cycle (when proposal exists). */
|
|
125
|
-
objectiveGuardDecision?: ObjectiveGuardDecision;
|
|
126
|
-
/** Human-vs-autonomous work arbitration decision for this cycle. */
|
|
127
|
-
workArbitration?: AgentWorkArbitrationDecision;
|
|
128
|
-
timestamp: number;
|
|
129
|
-
};
|
|
130
|
-
type AgentLoopMemoryConfig = {
|
|
131
|
-
/** Enable one-time memory scaffold upgrade. Default true. */
|
|
132
|
-
enabled?: boolean;
|
|
133
|
-
/** Workspace root for compounding memory files. Default current working directory ("."). */
|
|
134
|
-
root?: string;
|
|
135
|
-
/** Timezone for daily ledger date key. Default UTC. */
|
|
136
|
-
timeZone?: string;
|
|
137
|
-
/** Hook called after memory upgrade check completes. */
|
|
138
|
-
onUpgrade?: (result: CompoundingMemoryUpgradeResult) => Promise<void> | void;
|
|
139
|
-
/** Enable required-set maintenance checks (bounded working state + recall substrate + restore drill). Default true. */
|
|
140
|
-
requiredSetEnabled?: boolean;
|
|
141
|
-
/** Interval for required-set checks. Default 24h. */
|
|
142
|
-
requiredSetIntervalMs?: number;
|
|
143
|
-
/** Run required-set check on first loop cycle. Default true. */
|
|
144
|
-
requiredSetRunOnStart?: boolean;
|
|
145
|
-
/** Include backup+restore drill in required-set check. Default true. */
|
|
146
|
-
requiredSetRunRestoreDrill?: boolean;
|
|
147
|
-
/** Hook called when required-set check runs. */
|
|
148
|
-
onRequiredSet?: (result: CompoundingMemoryRequiredSetResult) => Promise<void> | void;
|
|
149
|
-
};
|
|
150
|
-
type AgentLoopDurabilityConfig = {
|
|
151
|
-
/** Enable durability-proxy writes from runtime loop. Default false. */
|
|
152
|
-
enabled?: boolean;
|
|
153
|
-
/** Durability-proxy base URL (e.g. http://127.0.0.1:8790). */
|
|
154
|
-
baseUrl: string;
|
|
155
|
-
/** Agent id registered in durability-proxy. */
|
|
156
|
-
agentId: string;
|
|
157
|
-
/** Agent token registered in durability-proxy. */
|
|
158
|
-
agentToken: string;
|
|
159
|
-
/** Optional timeout for durability-proxy calls. Default 8000ms. */
|
|
160
|
-
timeoutMs?: number;
|
|
161
|
-
/** Write checkpoint after each required-set run. Default true. */
|
|
162
|
-
checkpointOnRequiredSet?: boolean;
|
|
163
|
-
/** Write restore-drill outcome when required-set includes restore drill. Default true. */
|
|
164
|
-
reportRestoreDrill?: boolean;
|
|
165
|
-
/** Called when durability checkpoint is written. */
|
|
166
|
-
onCheckpointWritten?: (result: {
|
|
167
|
-
checkpointId?: string;
|
|
168
|
-
createdAt?: string;
|
|
169
|
-
checkedAt: string;
|
|
170
|
-
}) => Promise<void> | void;
|
|
171
|
-
/** Called when durability restore drill signal is written. */
|
|
172
|
-
onRestoreDrillReported?: (result: {
|
|
173
|
-
ok: boolean;
|
|
174
|
-
ts?: string;
|
|
175
|
-
checkedAt: string;
|
|
176
|
-
}) => Promise<void> | void;
|
|
177
|
-
};
|
|
178
|
-
type AgentLoopHooks = {
|
|
179
|
-
/** Called every cycle after snapshot is fetched and survival state is updated. */
|
|
180
|
-
onCycle?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
181
|
-
/**
|
|
182
|
-
* Optional: run reflection in the loop.
|
|
183
|
-
* Keep this hook pure/side-effect bounded; it should manage its own persistence.
|
|
184
|
-
*/
|
|
185
|
-
onReflection?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
186
|
-
/**
|
|
187
|
-
* Optional: the agent's planner/executor entrypoint.
|
|
188
|
-
* This is where you actually "act like a human" using ctx + your own memory.
|
|
189
|
-
*/
|
|
190
|
-
onAct?: (ctx: AgentLoopContext) => Promise<void> | void;
|
|
191
|
-
onError?: (err: Error) => Promise<void> | void;
|
|
192
|
-
};
|
|
193
|
-
type AgentLoopConfig = {
|
|
194
|
-
survival: SelfReliance;
|
|
195
|
-
fetchSnapshot: () => Promise<ResourceSnapshot>;
|
|
196
|
-
intervalMs?: number;
|
|
197
|
-
/** If true, call survival.guard() before onAct(). Default true. */
|
|
198
|
-
guardAct?: boolean;
|
|
199
|
-
/** Optional override for time source (tests). */
|
|
200
|
-
now?: () => number;
|
|
201
|
-
hooks?: AgentLoopHooks;
|
|
202
|
-
escapeHatch?: AgentLoopEscapeHatchConfig;
|
|
203
|
-
memory?: AgentLoopMemoryConfig;
|
|
204
|
-
durability?: AgentLoopDurabilityConfig;
|
|
205
|
-
strictMemory?: AgentLoopStrictMemoryConfig;
|
|
206
|
-
promptShield?: AgentLoopPromptShieldConfig;
|
|
207
|
-
objectiveGuard?: AgentLoopObjectiveGuardConfig;
|
|
208
|
-
autonomy?: AgentLoopAutonomyConfig;
|
|
209
|
-
};
|
|
210
|
-
/**
|
|
211
|
-
* Create a closed-loop runner that:
|
|
212
|
-
* 1) fetches a resource snapshot
|
|
213
|
-
* 2) updates SelfReliance
|
|
214
|
-
* 3) classifies survival mode + produces a playbook recommendation
|
|
215
|
-
* 4) auto-evaluates escape hatch in SURVIVE/BLINK (guardrail decision block)
|
|
216
|
-
* 5) optionally runs reflection + action hooks
|
|
217
|
-
*
|
|
218
|
-
* Non-breaking by design: you choose what to do with the context.
|
|
219
|
-
*/
|
|
220
|
-
declare const createAgentLoop: (config: AgentLoopConfig) => {
|
|
221
|
-
start: () => Promise<void>;
|
|
222
|
-
stop: () => void;
|
|
223
|
-
runOnce: () => Promise<void>;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
export { type AgentHumanDemand, type AgentLoopAutonomyConfig, type AgentLoopConfig, type AgentLoopContext, type AgentLoopDurabilityConfig, type AgentLoopEscapeHatchConfig, type AgentLoopEscapeHatchInput, type AgentLoopHooks, type AgentLoopMemoryConfig, type AgentLoopObjectiveGuardConfig, type AgentLoopPromptShieldConfig, type AgentLoopStrictMemoryConfig, type AgentOwnershipMode, type AgentPriorityMode, type AgentWorkArbitrationDecision, createAgentLoop };
|
|
1
|
+
import './selfReliance.js';
|
|
2
|
+
import './survivalPlaybook.js';
|
|
3
|
+
import './survivalEscapeHatch.js';
|
|
4
|
+
import './compoundingMemory.js';
|
|
5
|
+
import './strictMemoryRuntime.js';
|
|
6
|
+
export { A as AgentHumanDemand, m as AgentLoopAutonomyConfig, n as AgentLoopConfig, o as AgentLoopContext, p as AgentLoopDurabilityConfig, q as AgentLoopEscapeHatchConfig, r as AgentLoopEscapeHatchInput, t as AgentLoopHooks, u as AgentLoopMemoryConfig, v as AgentLoopObjectiveGuardConfig, w as AgentLoopPromptShieldConfig, x as AgentLoopStrictMemoryConfig, y as AgentOwnershipMode, z as AgentPriorityMode, B as AgentWorkArbitrationDecision, C as createAgentLoop } from './agentLoop-Dn6aMtRD.js';
|
package/dist/agentLoop.js
CHANGED
|
@@ -3,10 +3,11 @@ import {
|
|
|
3
3
|
upgradeCompoundingMemorySystem
|
|
4
4
|
} from "./chunk-JJNRDU7F.js";
|
|
5
5
|
import {
|
|
6
|
+
applyIntentArbitration,
|
|
6
7
|
createDurabilityProxyClient,
|
|
7
8
|
evaluateObjectiveChange,
|
|
8
9
|
evaluatePromptShield
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-WFOLCIJC.js";
|
|
10
11
|
import {
|
|
11
12
|
createSelfRelianceMonitor
|
|
12
13
|
} from "./chunk-M7DQTU5R.js";
|
|
@@ -252,6 +253,18 @@ var createAgentLoop = (config) => {
|
|
|
252
253
|
source: raw.source
|
|
253
254
|
};
|
|
254
255
|
};
|
|
256
|
+
const resolveIntentSignals = async (input) => {
|
|
257
|
+
const fromConfig = await config.autonomy?.intentPolicy?.resolveSignals?.(input);
|
|
258
|
+
if (fromConfig) return fromConfig;
|
|
259
|
+
const raw = input.snapshot;
|
|
260
|
+
return {
|
|
261
|
+
expectedBuildValue: asFiniteNumber(raw.expectedBuildValue),
|
|
262
|
+
expectedBuildRevenue: asFiniteNumber(raw.expectedBuildRevenue),
|
|
263
|
+
expectedPolishValue: asFiniteNumber(raw.expectedPolishValue),
|
|
264
|
+
expectedPolishRevenueProtection: asFiniteNumber(raw.expectedPolishRevenueProtection),
|
|
265
|
+
urgentUserDemand: asBoolean(raw.urgentUserDemand)
|
|
266
|
+
};
|
|
267
|
+
};
|
|
255
268
|
const runOnce = async () => {
|
|
256
269
|
try {
|
|
257
270
|
const memoryUpgrade = await ensureMemoryUpgrade();
|
|
@@ -342,6 +355,18 @@ var createAgentLoop = (config) => {
|
|
|
342
355
|
arbitrationBase.runAutonomousTask = true;
|
|
343
356
|
arbitrationBase.reason = humanDemand.pending ? "autonomous_first_with_human_pending" : "autonomous_first_idle";
|
|
344
357
|
}
|
|
358
|
+
const intentEnabled = config.autonomy?.intentPolicy?.enabled ?? true;
|
|
359
|
+
if (intentEnabled) {
|
|
360
|
+
const intentSignals = await resolveIntentSignals({ snapshot, survivalMode, humanDemand });
|
|
361
|
+
Object.assign(
|
|
362
|
+
arbitrationBase,
|
|
363
|
+
applyIntentArbitration({
|
|
364
|
+
base: arbitrationBase,
|
|
365
|
+
survivalMode,
|
|
366
|
+
signals: intentSignals || void 0
|
|
367
|
+
})
|
|
368
|
+
);
|
|
369
|
+
}
|
|
345
370
|
}
|
|
346
371
|
const ctx = {
|
|
347
372
|
snapshot,
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// src/durabilityProxy.ts
|
|
2
|
+
var withTimeout = async (fetcher, input, init, timeoutMs) => {
|
|
3
|
+
const controller = new AbortController();
|
|
4
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
5
|
+
try {
|
|
6
|
+
return await fetcher(input, { ...init, signal: controller.signal });
|
|
7
|
+
} finally {
|
|
8
|
+
clearTimeout(timer);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var readJson = async (response) => {
|
|
12
|
+
const text = await response.text();
|
|
13
|
+
if (!text) return null;
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(text);
|
|
16
|
+
} catch {
|
|
17
|
+
return { raw: text };
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var createDurabilityProxyClient = (options) => {
|
|
21
|
+
const fetcher = options.fetcher || fetch;
|
|
22
|
+
const timeoutMs = Number.isFinite(Number(options.timeoutMs)) ? Math.max(500, Number(options.timeoutMs)) : 8e3;
|
|
23
|
+
const base = String(options.baseUrl || "").replace(/\/+$/, "");
|
|
24
|
+
const agentId = String(options.agentId || "").trim();
|
|
25
|
+
const agentToken = String(options.agentToken || "").trim();
|
|
26
|
+
if (!base) throw new Error("durability_proxy_base_missing");
|
|
27
|
+
if (!agentId) throw new Error("durability_proxy_agent_id_missing");
|
|
28
|
+
if (!agentToken) throw new Error("durability_proxy_agent_token_missing");
|
|
29
|
+
const headers = {
|
|
30
|
+
"content-type": "application/json",
|
|
31
|
+
"x-agent-id": agentId,
|
|
32
|
+
"x-agent-token": agentToken
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
async writeCheckpoint(payloadJson, opts = {}) {
|
|
36
|
+
const response = await withTimeout(
|
|
37
|
+
fetcher,
|
|
38
|
+
`${base}/v1/checkpoints`,
|
|
39
|
+
{
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers,
|
|
42
|
+
body: JSON.stringify({
|
|
43
|
+
payloadJson,
|
|
44
|
+
sha256: opts.sha256,
|
|
45
|
+
contentType: opts.contentType,
|
|
46
|
+
metadata: opts.metadata
|
|
47
|
+
})
|
|
48
|
+
},
|
|
49
|
+
timeoutMs
|
|
50
|
+
);
|
|
51
|
+
const body = await readJson(response);
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const detail = body?.error || `http_${response.status}`;
|
|
54
|
+
throw new Error(`durability_checkpoint_write_failed:${detail}`);
|
|
55
|
+
}
|
|
56
|
+
return body;
|
|
57
|
+
},
|
|
58
|
+
async latestCheckpoint() {
|
|
59
|
+
const response = await withTimeout(
|
|
60
|
+
fetcher,
|
|
61
|
+
`${base}/v1/checkpoints/latest`,
|
|
62
|
+
{ method: "GET", headers: { "x-agent-id": agentId, "x-agent-token": agentToken } },
|
|
63
|
+
timeoutMs
|
|
64
|
+
);
|
|
65
|
+
const body = await readJson(response);
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
const detail = body?.error || `http_${response.status}`;
|
|
68
|
+
throw new Error(`durability_checkpoint_latest_failed:${detail}`);
|
|
69
|
+
}
|
|
70
|
+
return body;
|
|
71
|
+
},
|
|
72
|
+
async writeRestoreDrill(ok, opts = {}) {
|
|
73
|
+
const response = await withTimeout(
|
|
74
|
+
fetcher,
|
|
75
|
+
`${base}/v1/checkpoints/restore-drill`,
|
|
76
|
+
{
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers,
|
|
79
|
+
body: JSON.stringify({
|
|
80
|
+
checkpointId: opts.checkpointId,
|
|
81
|
+
ok,
|
|
82
|
+
details: opts.details
|
|
83
|
+
})
|
|
84
|
+
},
|
|
85
|
+
timeoutMs
|
|
86
|
+
);
|
|
87
|
+
const body = await readJson(response);
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
const detail = body?.error || `http_${response.status}`;
|
|
90
|
+
throw new Error(`durability_restore_drill_write_failed:${detail}`);
|
|
91
|
+
}
|
|
92
|
+
return body;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// src/promptShield.ts
|
|
98
|
+
var RULES = [
|
|
99
|
+
{
|
|
100
|
+
flag: "instruction_override",
|
|
101
|
+
risk: "high",
|
|
102
|
+
test: [/ignore\s+(all\s+)?previous/i, /disregard\s+instructions/i, /new\s+system\s+prompt/i]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
flag: "credential_exfiltration",
|
|
106
|
+
risk: "high",
|
|
107
|
+
test: [/api\s*key/i, /private\s*key/i, /seed\s*phrase/i, /wallet\s*secret/i, /send\s+me\s+your\s+token/i]
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
flag: "destructive_command",
|
|
111
|
+
risk: "high",
|
|
112
|
+
test: [/\brm\s+-rf\b/i, /drop\s+database/i, /delete\s+all/i, /overwrite\s+memory/i]
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
flag: "authority_spoof",
|
|
116
|
+
risk: "medium",
|
|
117
|
+
test: [/as\s+your\s+owner/i, /authorized\s+admin/i, /from\s+charles/i]
|
|
118
|
+
}
|
|
119
|
+
];
|
|
120
|
+
var rankRisk = (a, b) => {
|
|
121
|
+
const w = { low: 1, medium: 2, high: 3 };
|
|
122
|
+
return w[a] >= w[b] ? a : b;
|
|
123
|
+
};
|
|
124
|
+
var toDefaultBlockSet = () => /* @__PURE__ */ new Set(["instruction_override", "credential_exfiltration", "destructive_command", "authority_spoof", "sensitive_action_without_trust"]);
|
|
125
|
+
var evaluatePromptShield = (inputs, options = {}) => {
|
|
126
|
+
const policy = options.policy || {};
|
|
127
|
+
const blockSet = policy.blockOnFlags ? new Set(policy.blockOnFlags) : toDefaultBlockSet();
|
|
128
|
+
const rationale = [];
|
|
129
|
+
const blockedInputs = [];
|
|
130
|
+
const flags = /* @__PURE__ */ new Set();
|
|
131
|
+
let risk = "low";
|
|
132
|
+
for (const input of inputs) {
|
|
133
|
+
if (input.trust !== "external_untrusted") continue;
|
|
134
|
+
const text = String(input.content || "");
|
|
135
|
+
for (const rule of RULES) {
|
|
136
|
+
if (rule.test.some((rx) => rx.test(text))) {
|
|
137
|
+
flags.add(rule.flag);
|
|
138
|
+
risk = rankRisk(risk, rule.risk);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (options.isSensitiveAction) {
|
|
143
|
+
const hasTrusted = inputs.some((i) => i.trust === "trusted_human" || i.trust === "internal_system");
|
|
144
|
+
if (!hasTrusted) {
|
|
145
|
+
flags.add("sensitive_action_without_trust");
|
|
146
|
+
risk = rankRisk(risk, "high");
|
|
147
|
+
rationale.push("Sensitive action lacks trusted human/system intent; external input cannot authorize mutation.");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const blocked = [...flags].some((f) => blockSet.has(f));
|
|
151
|
+
if (blocked) {
|
|
152
|
+
for (const input of inputs) {
|
|
153
|
+
if (input.trust === "external_untrusted") blockedInputs.push(input);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (!flags.size) {
|
|
157
|
+
rationale.push("No injection indicators detected in untrusted sources.");
|
|
158
|
+
} else {
|
|
159
|
+
rationale.push(`Detected prompt-shield flags: ${[...flags].join(",")}`);
|
|
160
|
+
}
|
|
161
|
+
if (policy.allowUntrustedForAnalysisOnly && blocked) {
|
|
162
|
+
rationale.push("Untrusted content may be used for analysis only; execution remains blocked.");
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
allow: !blocked,
|
|
166
|
+
risk,
|
|
167
|
+
flags: [...flags],
|
|
168
|
+
rationale,
|
|
169
|
+
blockedInputs
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// src/objectiveGuard.ts
|
|
174
|
+
var normalize = (v) => String(v || "").trim().toLowerCase();
|
|
175
|
+
var isExplicitInstruction = (text) => /\b(do this instead|switch objective|change objective|stop current objective|ignore current objective)\b/i.test(
|
|
176
|
+
text || ""
|
|
177
|
+
);
|
|
178
|
+
var missionAlignment = (currentObjective, proposedObjective) => {
|
|
179
|
+
const a = new Set(normalize(currentObjective).split(/\W+/).filter(Boolean));
|
|
180
|
+
const b = new Set(normalize(proposedObjective).split(/\W+/).filter(Boolean));
|
|
181
|
+
if (!a.size || !b.size) return false;
|
|
182
|
+
let overlap = 0;
|
|
183
|
+
for (const tok of b) if (a.has(tok)) overlap += 1;
|
|
184
|
+
return overlap / Math.max(1, b.size) >= 0.2;
|
|
185
|
+
};
|
|
186
|
+
var evaluateObjectiveChange = (proposal, policy = {}) => {
|
|
187
|
+
const requireMissionAlignment = policy.requireMissionAlignment ?? true;
|
|
188
|
+
const requireEvidenceVerification = policy.requireEvidenceVerification ?? true;
|
|
189
|
+
const allowExternalExplicitInstruction = policy.allowExternalExplicitInstruction ?? false;
|
|
190
|
+
const explicitInstruction = isExplicitInstruction(proposal.proposedObjective) || isExplicitInstruction(proposal.rationale || "");
|
|
191
|
+
const missionAligned = missionAlignment(proposal.currentObjective, proposal.proposedObjective);
|
|
192
|
+
const evidence = Array.isArray(proposal.evidence) ? proposal.evidence : [];
|
|
193
|
+
const evidenceProvided = evidence.length > 0;
|
|
194
|
+
const evidenceVerified = evidenceProvided && evidence.every((e) => e.verified === true);
|
|
195
|
+
if (proposal.trust === "trusted_human" || proposal.trust === "internal_system") {
|
|
196
|
+
return {
|
|
197
|
+
allowObjectiveChange: true,
|
|
198
|
+
reason: "trusted_source_override",
|
|
199
|
+
checks: { explicitInstruction, missionAligned, evidenceProvided, evidenceVerified },
|
|
200
|
+
risk: "low"
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
if (explicitInstruction && !allowExternalExplicitInstruction) {
|
|
204
|
+
return {
|
|
205
|
+
allowObjectiveChange: false,
|
|
206
|
+
reason: "external_explicit_instruction_blocked",
|
|
207
|
+
checks: { explicitInstruction, missionAligned, evidenceProvided, evidenceVerified },
|
|
208
|
+
risk: "high"
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
if (requireMissionAlignment && !missionAligned) {
|
|
212
|
+
return {
|
|
213
|
+
allowObjectiveChange: false,
|
|
214
|
+
reason: "mission_alignment_failed",
|
|
215
|
+
checks: { explicitInstruction, missionAligned, evidenceProvided, evidenceVerified },
|
|
216
|
+
risk: "high"
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
if (!evidenceProvided) {
|
|
220
|
+
return {
|
|
221
|
+
allowObjectiveChange: false,
|
|
222
|
+
reason: "evidence_missing",
|
|
223
|
+
checks: { explicitInstruction, missionAligned, evidenceProvided, evidenceVerified },
|
|
224
|
+
risk: "medium"
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
if (requireEvidenceVerification && !evidenceVerified) {
|
|
228
|
+
return {
|
|
229
|
+
allowObjectiveChange: false,
|
|
230
|
+
reason: "evidence_unverified",
|
|
231
|
+
checks: { explicitInstruction, missionAligned, evidenceProvided, evidenceVerified },
|
|
232
|
+
risk: "high"
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
allowObjectiveChange: true,
|
|
237
|
+
reason: "reasoned_external_change_allowed",
|
|
238
|
+
checks: { explicitInstruction, missionAligned, evidenceProvided, evidenceVerified },
|
|
239
|
+
risk: "low"
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// src/intentArbitration.ts
|
|
244
|
+
var clamp = (n) => Math.max(0, Math.min(1, n));
|
|
245
|
+
var scoreBuildLane = (signals, survivalMode) => {
|
|
246
|
+
const value = clamp(signals.expectedBuildValue ?? 0.5);
|
|
247
|
+
const revenue = clamp(signals.expectedBuildRevenue ?? 0.5);
|
|
248
|
+
const base = value * 0.55 + revenue * 0.45;
|
|
249
|
+
if (survivalMode === "SURVIVE") return clamp(base + 0.1 * revenue);
|
|
250
|
+
if (survivalMode === "BLINK") return clamp(base * 0.6);
|
|
251
|
+
return base;
|
|
252
|
+
};
|
|
253
|
+
var scorePolishLane = (signals, survivalMode, humanDemand) => {
|
|
254
|
+
const value = clamp(signals.expectedPolishValue ?? (humanDemand.pending ? 0.8 : 0.4));
|
|
255
|
+
const protect = clamp(signals.expectedPolishRevenueProtection ?? (humanDemand.pending ? 0.7 : 0.4));
|
|
256
|
+
const demandBoost = humanDemand.pending || signals.urgentUserDemand ? 0.2 : 0;
|
|
257
|
+
const base = clamp(value * 0.6 + protect * 0.4 + demandBoost);
|
|
258
|
+
if (survivalMode === "BLINK") return clamp(base * 0.8);
|
|
259
|
+
return base;
|
|
260
|
+
};
|
|
261
|
+
var applyIntentArbitration = (input) => {
|
|
262
|
+
const { base, survivalMode } = input;
|
|
263
|
+
const signals = input.signals || {};
|
|
264
|
+
const buildScore = scoreBuildLane(signals, survivalMode);
|
|
265
|
+
const polishScore = scorePolishLane(signals, survivalMode, base.humanDemand);
|
|
266
|
+
const out = { ...base };
|
|
267
|
+
if (base.ownershipMode === "owner_bound" && base.humanDemand.pending) {
|
|
268
|
+
out.runHumanTask = true;
|
|
269
|
+
out.runAutonomousTask = base.priorityMode === "autonomous_first" ? buildScore >= 0.5 : buildScore >= 0.65;
|
|
270
|
+
out.reason = out.runAutonomousTask ? "intent_parallel_build_and_polish" : "intent_polish_preempts_build";
|
|
271
|
+
return out;
|
|
272
|
+
}
|
|
273
|
+
if (!base.humanDemand.pending) {
|
|
274
|
+
out.runHumanTask = false;
|
|
275
|
+
out.runAutonomousTask = buildScore >= 0.45 || polishScore >= 0.45;
|
|
276
|
+
out.reason = out.runAutonomousTask ? "intent_build_or_polish_window" : "intent_hold_low_expected_value";
|
|
277
|
+
return out;
|
|
278
|
+
}
|
|
279
|
+
if (base.ownershipMode === "unbound") {
|
|
280
|
+
out.runAutonomousTask = true;
|
|
281
|
+
out.runHumanTask = true;
|
|
282
|
+
out.reason = "intent_unbound_parallel";
|
|
283
|
+
}
|
|
284
|
+
return out;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
export {
|
|
288
|
+
createDurabilityProxyClient,
|
|
289
|
+
evaluatePromptShield,
|
|
290
|
+
evaluateObjectiveChange,
|
|
291
|
+
scoreBuildLane,
|
|
292
|
+
scorePolishLane,
|
|
293
|
+
applyIntentArbitration
|
|
294
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +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 ExecutionRollbackResult, P as ExecutionRolloutMode, Q as ExecutionRunResult, R as ExecutionValidateResult, S as LISTING_NAME_MAX_LENGTH, T as LISTING_NAME_RECOMMENDED_MAX, U as LISTING_TAGLINE_MAX_LENGTH, V as LISTING_TAGLINE_RECOMMENDED_MAX, W as LaunchProfile, X as LaunchReadinessInput, Y as LaunchReadinessResult, Z as LeaderboardEntry, _ as LeaderboardQuery, $ as ListingNamingValidationOptions, a0 as ListingNamingValidationResult, a1 as ListingQuery, a2 as ListingReviewCreatePayload, a3 as ListingReviewResponsePayload, a4 as ListingVersionPayload, a5 as MarketingCampaign, a6 as MarketingLinkOptions, a7 as MemoryPingChallengeResponse, a8 as MemoryPingPayload, a9 as OpenRouterCredits, aa as ProcurementCandidate, ab as ProcurementDecision, ac as ProcurementTaskProfile, ad as ProcurementWeights, ae as ResourceProviderManifestEntry, af as ResourceSnapshot, ag as ReviewGate, ah as ReviewGateRecord, ai as ReviewRequiredPayload, aj as RunAdaptiveReflectionOptions, ak as RuntimeMigrationInput, al as RuntimeMigrationPlan, am as RuntimeStateSnapshot, an as SdkAutoUpdatedRestartRequiredError, ao as SdkUpdateCheckOptions, ap as SdkUpdatePolicyCheckOptions, aq as SdkUpdateRequiredError, ar as SdkUpdateStatus, TopupDecision, TopupRequest, TreasuryLedgerEvent, TreasuryPolicy, TreasuryPolicyV1, TreasuryState, as as VIBEIAO_IDL, at as VibeClient, au as VibeClientOptions, av as VibeRegistry, aw as aggregateFeedbackSignals, ax as assertLaunchReady, ay as assertSurvivalProvidersConfigured, az as buildAdaptivePlan, aA as buildBadgeMarkdown, aB as buildClaimMessage, aC as buildDecisionRecord, aD as buildJupiterSwapUrl, aE as buildListingVersionMessage, aF as buildMemoryPingMessage, aG as buildOwnerTransferMessage, aH as buildProcurementPrompt, aI as buildRaydiumSwapUrl, aJ as buildReviewPrompt, aK as buildReviewRequired, aL as buildReviewResponseMessage, aM as buildRuntimeMigrationPlan, aN as buildSdkUpdateCommand, aO as buildShareCopy, aP as buildShareLink, aQ as buildTradeLinks, buildTreasuryLedgerEvent, aR as checkForSdkUpdate, aS as checkForSdkUpdatePolicy, aT as compareVersions, aU as createApiCreditProvider, aV as createApiCreditProviders, aW as createApiCreditProvidersFromManifest, aX as createCampaign, aY as createContextPack, aZ as createCustomAdapter, a_ as createDurabilityProxyClient, a$ as createServiceApiAdapter, createTreasuryPolicy, b0 as createWebBundledAdapter, b1 as createWebStaticAdapter, b2 as createWorkflowAgentAdapter, b3 as decideProcurementForTask, b4 as estimateContextPackTokens, b5 as evaluateAdaptiveReflectionPolicy, b6 as evaluateContextPackGate, b7 as evaluateLaunchReadiness, evaluateTopupRequest, b8 as getResourceSnapshot, b9 as normalizeListingText, ba as rankListingsForTask, bb as runAdapterBestShotChecklist, bc as runAdaptiveReflectionCycle, bd as runAgentLaunchRuntime, be as runAgentLaunchRuntimeCycle, bf as runAgentReviewRuntimeCycle, bg as runExecutionAdapter, bh as sanitizeListingNaming, bi as scoreListingForTask, bj as shouldAnnounceStateChange, treasuryStateFromSnapshot, bk as validateContextPack, bl as validateListingNaming, validateTreasuryPolicy, bm 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 {
|
|
12
|
+
export { I as IntentSignals, O as ObjectiveChangeProposal, a as ObjectiveChangeSourceTrust, b as ObjectiveGuardDecision, c as ObjectiveGuardPolicy, P as PromptShieldDecision, d as PromptShieldFlag, e as PromptShieldInput, f as PromptShieldPolicy, g as PromptShieldRisk, h as PromptShieldTrustLevel, i as applyIntentArbitration, j as evaluateObjectiveChange, k as evaluatePromptShield, s as scoreBuildLane, l as scorePolishLane } from './agentLoop-Dn6aMtRD.js';
|
|
13
13
|
export { fetchSolBalance, fetchTokenBalance, fetchTokenBalances } from './solana.js';
|
|
14
|
+
import './compoundingMemory.js';
|
|
14
15
|
import '@coral-xyz/anchor';
|
package/dist/index.js
CHANGED
|
@@ -17,10 +17,13 @@ import {
|
|
|
17
17
|
validateTreasuryPolicy
|
|
18
18
|
} from "./chunk-RNPCT2MS.js";
|
|
19
19
|
import {
|
|
20
|
+
applyIntentArbitration,
|
|
20
21
|
createDurabilityProxyClient,
|
|
21
22
|
evaluateObjectiveChange,
|
|
22
|
-
evaluatePromptShield
|
|
23
|
-
|
|
23
|
+
evaluatePromptShield,
|
|
24
|
+
scoreBuildLane,
|
|
25
|
+
scorePolishLane
|
|
26
|
+
} from "./chunk-WFOLCIJC.js";
|
|
24
27
|
import {
|
|
25
28
|
SelfReliance,
|
|
26
29
|
createAutoSelfReliance,
|
|
@@ -1085,7 +1088,7 @@ var ReviewGate = class {
|
|
|
1085
1088
|
var DEFAULT_API_BASE = "https://api.vibeiao.com";
|
|
1086
1089
|
var DEFAULT_WEB_BASE = "https://vibeiao.com";
|
|
1087
1090
|
var DEFAULT_SDK_PACKAGE = "@vibeiao/sdk";
|
|
1088
|
-
var DEFAULT_SDK_VERSION = "0.1.
|
|
1091
|
+
var DEFAULT_SDK_VERSION = "0.1.49" ? "0.1.49" : "0.1.4";
|
|
1089
1092
|
var DEFAULT_SDK_REGISTRY = "https://registry.npmjs.org";
|
|
1090
1093
|
var DEFAULT_SDK_POLICY_PATH = "/v1/sdk/policy";
|
|
1091
1094
|
var DEFAULT_SDK_CHECK_INTERVAL_MS = 1e3 * 60 * 30;
|
|
@@ -2217,6 +2220,7 @@ export {
|
|
|
2217
2220
|
VibeClient,
|
|
2218
2221
|
VibeRegistry,
|
|
2219
2222
|
aggregateFeedbackSignals,
|
|
2223
|
+
applyIntentArbitration,
|
|
2220
2224
|
assertLaunchReady,
|
|
2221
2225
|
assertOutcomeBoundCompleted,
|
|
2222
2226
|
assertSurvivalProvidersConfigured,
|
|
@@ -2300,7 +2304,9 @@ export {
|
|
|
2300
2304
|
runMarketDiscovery,
|
|
2301
2305
|
runReflectionCycle,
|
|
2302
2306
|
sanitizeListingNaming,
|
|
2307
|
+
scoreBuildLane,
|
|
2303
2308
|
scoreListingForTask,
|
|
2309
|
+
scorePolishLane,
|
|
2304
2310
|
scoreReviewPriority,
|
|
2305
2311
|
shouldAnnounceStateChange,
|
|
2306
2312
|
treasuryStateFromSnapshot,
|
|
@@ -8,8 +8,9 @@ import './survivalEscapeHatch.js';
|
|
|
8
8
|
import './marketDiscovery.js';
|
|
9
9
|
import './outcomeBoundFlow.js';
|
|
10
10
|
import './strictMemoryRuntime.js';
|
|
11
|
-
import './
|
|
11
|
+
import './agentLoop-Dn6aMtRD.js';
|
|
12
12
|
import './solana.js';
|
|
13
|
+
import './compoundingMemory.js';
|
|
13
14
|
import '@coral-xyz/anchor';
|
|
14
15
|
|
|
15
16
|
declare const VIBEIAO_IDL: {
|