@vibeiao/sdk 0.1.36 → 0.1.38

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 CHANGED
@@ -582,6 +582,26 @@ const loop = createAgentLoop({
582
582
  });
583
583
  ```
584
584
 
585
+ By default, `createAgentLoop(...)` also enables strict-memory runtime checks in `observe` mode.
586
+ To make it hard-enforced, set `strictMemory.mode = 'enforce'` and provide snapshot fields for gating (`taskText`, `isMutation`, `contextPackPrepared`, `semanticRecallConfirmed`, `approvalPreflightPassed`).
587
+
588
+ You can also enforce dual-mode work arbitration:
589
+ - `owner_bound` agents: human-first (owner work preempts autonomous work)
590
+ - `unbound` agents: autonomous-first (run autonomous work by default)
591
+
592
+ Use `autonomy.rolloutMode='enforce'` to apply hard arbitration behavior.
593
+
594
+ ```ts
595
+ const loop = createAgentLoop({
596
+ survival,
597
+ fetchSnapshot,
598
+ strictMemory: {
599
+ enabled: true,
600
+ mode: 'enforce',
601
+ },
602
+ });
603
+ ```
604
+
585
605
  Disable only if you already run an equivalent external memory-control plane:
586
606
 
587
607
  ```ts
@@ -1,7 +1,8 @@
1
- import { SelfReliance, ResourceSnapshot, SelfRelianceState } from './selfReliance.js';
1
+ import { ResourceSnapshot, SelfRelianceState, SelfReliance } from './selfReliance.js';
2
2
  import { SurvivalMode, SurvivalRecommendation } from './survivalPlaybook.js';
3
3
  import { EscapeHatchDecision, EscapeHatchPolicy, EscapeHatchSnapshot } from './survivalEscapeHatch.js';
4
4
  import { CompoundingMemoryUpgradeResult, CompoundingMemoryRequiredSetResult } from './compoundingMemory.js';
5
+ import { StrictMemoryRuntimePreset, StrictMemoryEvaluation, StrictMemoryUpgradeResult } from './strictMemoryRuntime.js';
5
6
 
6
7
  type AgentLoopEscapeHatchInput = {
7
8
  snapshot: ResourceSnapshot;
@@ -22,6 +23,52 @@ type AgentLoopEscapeHatchConfig = {
22
23
  /** Called when an escape-hatch decision is produced. */
23
24
  onDecision?: (decision: EscapeHatchDecision, input: AgentLoopEscapeHatchInput) => Promise<void> | void;
24
25
  };
26
+ type AgentLoopStrictMemoryConfig = {
27
+ /** Enable strict memory runtime checks in loop. Default true. */
28
+ enabled?: boolean;
29
+ /** observe (default) records decisions; enforce blocks onAct when checks fail. */
30
+ mode?: 'observe' | 'enforce';
31
+ /** Optional preset overrides. */
32
+ preset?: Partial<StrictMemoryRuntimePreset>;
33
+ /** Build per-cycle evaluation input. Defaults to best-effort snapshot fields. */
34
+ buildInput?: (ctx: {
35
+ snapshot: ResourceSnapshot;
36
+ timestamp: number;
37
+ }) => {
38
+ taskText: string;
39
+ isMutation: boolean;
40
+ contextPackPrepared: boolean;
41
+ semanticRecallConfirmed: boolean;
42
+ approvalPreflightPassed: boolean;
43
+ };
44
+ /** Optional hook when strict-memory evaluation runs. */
45
+ onEvaluation?: (ev: StrictMemoryEvaluation) => Promise<void> | void;
46
+ };
47
+ type AgentOwnershipMode = 'owner_bound' | 'unbound';
48
+ type AgentPriorityMode = 'human_first' | 'autonomous_first';
49
+ type AgentHumanDemand = {
50
+ pending: boolean;
51
+ count?: number;
52
+ source?: string;
53
+ };
54
+ type AgentWorkArbitrationDecision = {
55
+ ownershipMode: AgentOwnershipMode;
56
+ priorityMode: AgentPriorityMode;
57
+ rolloutMode: 'observe' | 'enforce';
58
+ humanDemand: AgentHumanDemand;
59
+ runHumanTask: boolean;
60
+ runAutonomousTask: boolean;
61
+ reason: string;
62
+ };
63
+ type AgentLoopAutonomyConfig = {
64
+ enabled?: boolean;
65
+ ownershipMode?: AgentOwnershipMode;
66
+ priorityMode?: AgentPriorityMode;
67
+ rolloutMode?: 'observe' | 'enforce';
68
+ resolveHumanDemand?: () => Promise<boolean | AgentHumanDemand> | boolean | AgentHumanDemand;
69
+ onAutonomous?: (ctx: AgentLoopContext) => Promise<void> | void;
70
+ onArbitration?: (decision: AgentWorkArbitrationDecision, ctx: AgentLoopContext) => Promise<void> | void;
71
+ };
25
72
  type AgentLoopContext = {
26
73
  snapshot: ResourceSnapshot;
27
74
  survivalState: SelfRelianceState;
@@ -37,6 +84,12 @@ type AgentLoopContext = {
37
84
  memoryUpgrade?: CompoundingMemoryUpgradeResult;
38
85
  /** Present when required-set maintenance check runs (default daily). */
39
86
  memoryRequiredSet?: CompoundingMemoryRequiredSetResult;
87
+ /** Strict-memory runtime preset + per-cycle evaluation status. */
88
+ strictMemoryPreset?: StrictMemoryRuntimePreset;
89
+ strictMemoryEvaluation?: StrictMemoryEvaluation;
90
+ strictMemoryUpgrade?: StrictMemoryUpgradeResult;
91
+ /** Human-vs-autonomous work arbitration decision for this cycle. */
92
+ workArbitration?: AgentWorkArbitrationDecision;
40
93
  timestamp: number;
41
94
  };
42
95
  type AgentLoopMemoryConfig = {
@@ -114,6 +167,8 @@ type AgentLoopConfig = {
114
167
  escapeHatch?: AgentLoopEscapeHatchConfig;
115
168
  memory?: AgentLoopMemoryConfig;
116
169
  durability?: AgentLoopDurabilityConfig;
170
+ strictMemory?: AgentLoopStrictMemoryConfig;
171
+ autonomy?: AgentLoopAutonomyConfig;
117
172
  };
118
173
  /**
119
174
  * Create a closed-loop runner that:
@@ -131,4 +186,4 @@ declare const createAgentLoop: (config: AgentLoopConfig) => {
131
186
  runOnce: () => Promise<void>;
132
187
  };
133
188
 
134
- export { type AgentLoopConfig, type AgentLoopContext, type AgentLoopDurabilityConfig, type AgentLoopEscapeHatchConfig, type AgentLoopEscapeHatchInput, type AgentLoopHooks, type AgentLoopMemoryConfig, createAgentLoop };
189
+ export { type AgentHumanDemand, type AgentLoopAutonomyConfig, type AgentLoopConfig, type AgentLoopContext, type AgentLoopDurabilityConfig, type AgentLoopEscapeHatchConfig, type AgentLoopEscapeHatchInput, type AgentLoopHooks, type AgentLoopMemoryConfig, type AgentLoopStrictMemoryConfig, type AgentOwnershipMode, type AgentPriorityMode, type AgentWorkArbitrationDecision, createAgentLoop };
package/dist/agentLoop.js CHANGED
@@ -8,6 +8,11 @@ import {
8
8
  import {
9
9
  createSelfRelianceMonitor
10
10
  } from "./chunk-M7DQTU5R.js";
11
+ import {
12
+ createStrictMemoryRuntimePreset,
13
+ evaluateStrictMemoryExecution,
14
+ upgradeToStrictMemoryRuntimePreset
15
+ } from "./chunk-RUKN3KQ2.js";
11
16
  import {
12
17
  evaluateEscapeHatch,
13
18
  formatEscapeHatchDecision
@@ -51,6 +56,20 @@ var createAgentLoop = (config) => {
51
56
  const requiredSetIntervalMs = Math.max(6e4, config.memory?.requiredSetIntervalMs ?? 24 * 60 * 60 * 1e3);
52
57
  const requiredSetRunOnStart = config.memory?.requiredSetRunOnStart ?? true;
53
58
  const requiredSetRunRestoreDrill = config.memory?.requiredSetRunRestoreDrill ?? true;
59
+ const strictMemoryEnabled = config.strictMemory?.enabled ?? true;
60
+ const strictMode = config.strictMemory?.mode ?? "observe";
61
+ const strictMemoryPreset = createStrictMemoryRuntimePreset(config.strictMemory?.preset || {});
62
+ const autonomyEnabled = config.autonomy?.enabled ?? true;
63
+ const ownershipMode = config.autonomy?.ownershipMode ?? "owner_bound";
64
+ const priorityMode = config.autonomy?.priorityMode ?? (ownershipMode === "unbound" ? "autonomous_first" : "human_first");
65
+ const rolloutMode = config.autonomy?.rolloutMode ?? "enforce";
66
+ const strictMemoryUpgrade = upgradeToStrictMemoryRuntimePreset({
67
+ current: strictMemoryPreset,
68
+ targetMode: strictMode,
69
+ backupCreated: true,
70
+ healthcheckPassed: true,
71
+ recentBlockRate: 0
72
+ });
54
73
  const durabilityEnabled = config.durability?.enabled ?? false;
55
74
  const durabilityClient = durabilityEnabled ? createDurabilityProxyClient({
56
75
  baseUrl: config.durability?.baseUrl || "",
@@ -149,6 +168,26 @@ var createAgentLoop = (config) => {
149
168
  }
150
169
  lastDurabilitySyncCheckedAt = memoryRequiredSet.checkedAt;
151
170
  };
171
+ const defaultStrictInputBuilder = (ctx) => {
172
+ const raw = ctx.snapshot;
173
+ return {
174
+ taskText: String(raw.taskText || raw.objective || ""),
175
+ isMutation: Boolean(raw.isMutation),
176
+ contextPackPrepared: Boolean(raw.contextPackPrepared),
177
+ semanticRecallConfirmed: Boolean(raw.semanticRecallConfirmed),
178
+ approvalPreflightPassed: Boolean(raw.approvalPreflightPassed)
179
+ };
180
+ };
181
+ const resolveHumanDemand = async () => {
182
+ const raw = await config.autonomy?.resolveHumanDemand?.();
183
+ if (typeof raw === "boolean") return { pending: raw };
184
+ if (!raw || typeof raw !== "object") return { pending: false };
185
+ return {
186
+ pending: Boolean(raw.pending),
187
+ count: raw.count,
188
+ source: raw.source
189
+ };
190
+ };
152
191
  const runOnce = async () => {
153
192
  try {
154
193
  const memoryUpgrade = await ensureMemoryUpgrade();
@@ -190,6 +229,35 @@ var createAgentLoop = (config) => {
190
229
  }
191
230
  }
192
231
  const survivalDecisionBlock = [survivalFormatted, escapeHatchFormatted].filter(Boolean).join("\n\n");
232
+ let strictMemoryEvaluation;
233
+ if (strictMemoryEnabled) {
234
+ const strictInput = (config.strictMemory?.buildInput || defaultStrictInputBuilder)({ snapshot, timestamp });
235
+ strictMemoryEvaluation = evaluateStrictMemoryExecution(strictInput, strictMemoryPreset);
236
+ if (config.strictMemory?.onEvaluation) {
237
+ await config.strictMemory.onEvaluation(strictMemoryEvaluation);
238
+ }
239
+ }
240
+ const humanDemand = autonomyEnabled ? await resolveHumanDemand() : { pending: false };
241
+ const arbitrationBase = {
242
+ ownershipMode,
243
+ priorityMode,
244
+ rolloutMode,
245
+ humanDemand,
246
+ runHumanTask: true,
247
+ runAutonomousTask: false,
248
+ reason: "legacy_onAct"
249
+ };
250
+ if (autonomyEnabled && config.autonomy?.onAutonomous) {
251
+ if (priorityMode === "human_first") {
252
+ arbitrationBase.runHumanTask = humanDemand.pending;
253
+ arbitrationBase.runAutonomousTask = !humanDemand.pending;
254
+ arbitrationBase.reason = humanDemand.pending ? "human_pending_preempts_autonomous" : "idle_autonomous_window";
255
+ } else {
256
+ arbitrationBase.runHumanTask = humanDemand.pending;
257
+ arbitrationBase.runAutonomousTask = true;
258
+ arbitrationBase.reason = humanDemand.pending ? "autonomous_first_with_human_pending" : "autonomous_first_idle";
259
+ }
260
+ }
193
261
  const ctx = {
194
262
  snapshot,
195
263
  survivalState,
@@ -201,11 +269,16 @@ var createAgentLoop = (config) => {
201
269
  escapeHatchFormatted,
202
270
  memoryUpgrade: memoryUpgrade ?? void 0,
203
271
  memoryRequiredSet: memoryRequiredSet ?? void 0,
272
+ strictMemoryPreset: strictMemoryEnabled ? strictMemoryPreset : void 0,
273
+ strictMemoryEvaluation,
274
+ strictMemoryUpgrade: strictMemoryEnabled ? strictMemoryUpgrade : void 0,
275
+ workArbitration: arbitrationBase,
204
276
  timestamp
205
277
  };
206
278
  if (hooks.onCycle) await hooks.onCycle(ctx);
207
279
  if (hooks.onReflection) await hooks.onReflection(ctx);
208
- if (hooks.onAct) {
280
+ const runHumanTask = async () => {
281
+ if (!hooks.onAct) return;
209
282
  if (guardAct) {
210
283
  const allowed = await config.survival.guard();
211
284
  if (allowed) {
@@ -214,6 +287,23 @@ var createAgentLoop = (config) => {
214
287
  } else {
215
288
  await hooks.onAct(ctx);
216
289
  }
290
+ };
291
+ const runAutonomousTask = async () => {
292
+ if (!config.autonomy?.onAutonomous) return;
293
+ await config.autonomy.onAutonomous(ctx);
294
+ };
295
+ if (strictMemoryEnabled && strictMode === "enforce" && ctx.strictMemoryEvaluation && !ctx.strictMemoryEvaluation.allowed) {
296
+ const missing = ctx.strictMemoryEvaluation.missingSteps.join(",");
297
+ throw new Error(`strict_memory_blocked:${missing}`);
298
+ }
299
+ if (autonomyEnabled && config.autonomy?.onAutonomous && rolloutMode === "enforce") {
300
+ if (ctx.workArbitration?.runHumanTask) await runHumanTask();
301
+ if (ctx.workArbitration?.runAutonomousTask) await runAutonomousTask();
302
+ } else {
303
+ await runHumanTask();
304
+ }
305
+ if (config.autonomy?.onArbitration) {
306
+ await config.autonomy.onArbitration(ctx.workArbitration, ctx);
217
307
  }
218
308
  } catch (err) {
219
309
  const e = err instanceof Error ? err : new Error("agent_loop_failed");
package/dist/index.js CHANGED
@@ -5,13 +5,6 @@ import {
5
5
  fetchTokenBalances,
6
6
  normalizeHumanAppCategory
7
7
  } from "./chunk-2U6HLZEF.js";
8
- import {
9
- STRICT_MEMORY_RUNTIME_SCHEMA,
10
- createStrictMemoryRuntimePreset,
11
- evaluateStrictMemoryExecution,
12
- isComplexTask,
13
- upgradeToStrictMemoryRuntimePreset
14
- } from "./chunk-RUKN3KQ2.js";
15
8
  import {
16
9
  getSurvivalPlaybookDecision,
17
10
  getSurvivalPlaybookDecisionFromSelfReliance
@@ -34,6 +27,13 @@ import {
34
27
  createSurvivalMiddleware,
35
28
  withSurvival
36
29
  } from "./chunk-M7DQTU5R.js";
30
+ import {
31
+ STRICT_MEMORY_RUNTIME_SCHEMA,
32
+ createStrictMemoryRuntimePreset,
33
+ evaluateStrictMemoryExecution,
34
+ isComplexTask,
35
+ upgradeToStrictMemoryRuntimePreset
36
+ } from "./chunk-RUKN3KQ2.js";
37
37
  import {
38
38
  evaluateEscapeHatch,
39
39
  formatEscapeHatchDecision
@@ -362,7 +362,7 @@ var ReviewGate = class {
362
362
  var DEFAULT_API_BASE = "https://api.vibeiao.com";
363
363
  var DEFAULT_WEB_BASE = "https://vibeiao.com";
364
364
  var DEFAULT_SDK_PACKAGE = "@vibeiao/sdk";
365
- var DEFAULT_SDK_VERSION = "0.1.35" ? "0.1.35" : "0.1.4";
365
+ var DEFAULT_SDK_VERSION = "0.1.37" ? "0.1.37" : "0.1.4";
366
366
  var DEFAULT_SDK_REGISTRY = "https://registry.npmjs.org";
367
367
  var DEFAULT_SDK_POLICY_PATH = "/v1/sdk/policy";
368
368
  var DEFAULT_SDK_CHECK_INTERVAL_MS = 1e3 * 60 * 30;
@@ -1105,7 +1105,7 @@ declare class ReviewGate {
1105
1105
  assertClear(listingId: string, wallet: string): void;
1106
1106
  }
1107
1107
 
1108
- declare const compareVersions: (currentVersion: string, latestVersion: string) => 0 | 1 | -1;
1108
+ declare const compareVersions: (currentVersion: string, latestVersion: string) => 1 | 0 | -1;
1109
1109
  declare const buildSdkUpdateCommand: (packageName?: string) => string;
1110
1110
  declare const checkForSdkUpdate: (options?: SdkUpdateCheckOptions) => Promise<SdkUpdateStatus>;
1111
1111
  declare const checkForSdkUpdatePolicy: (options: SdkUpdatePolicyCheckOptions) => Promise<SdkUpdateStatus>;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@vibeiao/sdk",
3
3
  "private": false,
4
4
  "type": "module",
5
- "version": "0.1.36",
5
+ "version": "0.1.38",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "exports": {