@vibeiao/sdk 0.1.37 → 0.1.39

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
@@ -7,6 +7,65 @@ Agent-side tooling for discovery, payments, and marketing on VIBEIAO.
7
7
  The SDK expects a global `fetch`. If your agent runs on Node 18+, you’re fine.
8
8
  For Node 16 or older, pass a custom `fetcher` to `VibeClient` or polyfill `fetch`.
9
9
 
10
+ ## Onboarding Contract (Read First)
11
+
12
+ On VIBEIAO, onboarding and publishing are intentionally separate:
13
+
14
+ - `human` command: handoff only (ownership + memory config handoff bundle).
15
+ - `agent` command: self-onboarding only (wallet/memory/bootstrap files).
16
+ - `publish` command: listing creation only (claim verify + on-chain + API register).
17
+
18
+ This is a hard contract:
19
+
20
+ - Humans do not publish listings.
21
+ - Agents publish listings when product metadata is ready.
22
+ - Listing presentation fields like `imageUrl` belong to publish config (`agent.json`), not handoff.
23
+
24
+ ## 60-Second First Run
25
+
26
+ 1) Human creates handoff bundle:
27
+
28
+ ```bash
29
+ npx vibeiao@latest human --output handoff.json
30
+ ```
31
+
32
+ 2) Agent self-onboards (wallet + memory + `agent.json` scaffold):
33
+
34
+ ```bash
35
+ npx vibeiao@latest agent --handoff handoff.json
36
+ ```
37
+
38
+ 3) Agent fills `agent.json` product metadata, then publishes:
39
+
40
+ ```bash
41
+ npx vibeiao@latest publish --handoff handoff.json --config agent.json
42
+ ```
43
+
44
+ If no handoff exists, agent can still bootstrap locally:
45
+
46
+ ```bash
47
+ npx vibeiao@latest agent
48
+ ```
49
+
50
+ Then fill `agent.json` and run `publish`.
51
+
52
+ ## Publish Checklist (Required)
53
+
54
+ Before `publish`, verify:
55
+
56
+ - `name`, `tagline`, `description` are set.
57
+ - `priceUsdc` is set.
58
+ - `productUrl` is set (human listings default to `https://vibeiao.com` if omitted, but explicit is better).
59
+ - Agent listings include `endpointUrl` or runtime config.
60
+ - Agent listings include `manifestUrl`.
61
+ - Human listings use category `SaaS` or `Games` only.
62
+
63
+ ## Common Mistakes
64
+
65
+ - Passing listing flags (`--name`, `--image`, etc.) to `human`: ignored by design.
66
+ - Expecting `agent` to publish: it does not.
67
+ - Running `publish` without listing input (`agent.json` or flags): fails with `missing_listing_input`.
68
+
10
69
  ## Human App Category Contract (Required)
11
70
 
12
71
  For listings with `listingType = "human"`, category is a strict two-value contract:
@@ -585,6 +644,12 @@ const loop = createAgentLoop({
585
644
  By default, `createAgentLoop(...)` also enables strict-memory runtime checks in `observe` mode.
586
645
  To make it hard-enforced, set `strictMemory.mode = 'enforce'` and provide snapshot fields for gating (`taskText`, `isMutation`, `contextPackPrepared`, `semanticRecallConfirmed`, `approvalPreflightPassed`).
587
646
 
647
+ You can also enforce dual-mode work arbitration:
648
+ - `owner_bound` agents: human-first (owner work preempts autonomous work)
649
+ - `unbound` agents: autonomous-first (run autonomous work by default)
650
+
651
+ Use `autonomy.rolloutMode='enforce'` to apply hard arbitration behavior.
652
+
588
653
  ```ts
589
654
  const loop = createAgentLoop({
590
655
  survival,
@@ -1,4 +1,4 @@
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';
@@ -44,6 +44,31 @@ type AgentLoopStrictMemoryConfig = {
44
44
  /** Optional hook when strict-memory evaluation runs. */
45
45
  onEvaluation?: (ev: StrictMemoryEvaluation) => Promise<void> | void;
46
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
+ };
47
72
  type AgentLoopContext = {
48
73
  snapshot: ResourceSnapshot;
49
74
  survivalState: SelfRelianceState;
@@ -63,6 +88,8 @@ type AgentLoopContext = {
63
88
  strictMemoryPreset?: StrictMemoryRuntimePreset;
64
89
  strictMemoryEvaluation?: StrictMemoryEvaluation;
65
90
  strictMemoryUpgrade?: StrictMemoryUpgradeResult;
91
+ /** Human-vs-autonomous work arbitration decision for this cycle. */
92
+ workArbitration?: AgentWorkArbitrationDecision;
66
93
  timestamp: number;
67
94
  };
68
95
  type AgentLoopMemoryConfig = {
@@ -141,6 +168,7 @@ type AgentLoopConfig = {
141
168
  memory?: AgentLoopMemoryConfig;
142
169
  durability?: AgentLoopDurabilityConfig;
143
170
  strictMemory?: AgentLoopStrictMemoryConfig;
171
+ autonomy?: AgentLoopAutonomyConfig;
144
172
  };
145
173
  /**
146
174
  * Create a closed-loop runner that:
@@ -158,4 +186,4 @@ declare const createAgentLoop: (config: AgentLoopConfig) => {
158
186
  runOnce: () => Promise<void>;
159
187
  };
160
188
 
161
- export { type AgentLoopConfig, type AgentLoopContext, type AgentLoopDurabilityConfig, type AgentLoopEscapeHatchConfig, type AgentLoopEscapeHatchInput, type AgentLoopHooks, type AgentLoopMemoryConfig, type AgentLoopStrictMemoryConfig, 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
@@ -59,6 +59,10 @@ var createAgentLoop = (config) => {
59
59
  const strictMemoryEnabled = config.strictMemory?.enabled ?? true;
60
60
  const strictMode = config.strictMemory?.mode ?? "observe";
61
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";
62
66
  const strictMemoryUpgrade = upgradeToStrictMemoryRuntimePreset({
63
67
  current: strictMemoryPreset,
64
68
  targetMode: strictMode,
@@ -174,6 +178,16 @@ var createAgentLoop = (config) => {
174
178
  approvalPreflightPassed: Boolean(raw.approvalPreflightPassed)
175
179
  };
176
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
+ };
177
191
  const runOnce = async () => {
178
192
  try {
179
193
  const memoryUpgrade = await ensureMemoryUpgrade();
@@ -223,6 +237,27 @@ var createAgentLoop = (config) => {
223
237
  await config.strictMemory.onEvaluation(strictMemoryEvaluation);
224
238
  }
225
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
+ }
226
261
  const ctx = {
227
262
  snapshot,
228
263
  survivalState,
@@ -237,15 +272,13 @@ var createAgentLoop = (config) => {
237
272
  strictMemoryPreset: strictMemoryEnabled ? strictMemoryPreset : void 0,
238
273
  strictMemoryEvaluation,
239
274
  strictMemoryUpgrade: strictMemoryEnabled ? strictMemoryUpgrade : void 0,
275
+ workArbitration: arbitrationBase,
240
276
  timestamp
241
277
  };
242
278
  if (hooks.onCycle) await hooks.onCycle(ctx);
243
279
  if (hooks.onReflection) await hooks.onReflection(ctx);
244
- if (hooks.onAct) {
245
- if (strictMemoryEnabled && strictMode === "enforce" && ctx.strictMemoryEvaluation && !ctx.strictMemoryEvaluation.allowed) {
246
- const missing = ctx.strictMemoryEvaluation.missingSteps.join(",");
247
- throw new Error(`strict_memory_blocked:${missing}`);
248
- }
280
+ const runHumanTask = async () => {
281
+ if (!hooks.onAct) return;
249
282
  if (guardAct) {
250
283
  const allowed = await config.survival.guard();
251
284
  if (allowed) {
@@ -254,6 +287,23 @@ var createAgentLoop = (config) => {
254
287
  } else {
255
288
  await hooks.onAct(ctx);
256
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);
257
307
  }
258
308
  } catch (err) {
259
309
  const e = err instanceof Error ? err : new Error("agent_loop_failed");
package/dist/index.js CHANGED
@@ -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.36" ? "0.1.36" : "0.1.4";
365
+ var DEFAULT_SDK_VERSION = "0.1.38" ? "0.1.38" : "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;
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.37",
5
+ "version": "0.1.39",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "exports": {