@vibeiao/sdk 0.1.35 → 0.1.37

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,20 @@ 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
+ ```ts
589
+ const loop = createAgentLoop({
590
+ survival,
591
+ fetchSnapshot,
592
+ strictMemory: {
593
+ enabled: true,
594
+ mode: 'enforce',
595
+ },
596
+ });
597
+ ```
598
+
585
599
  Disable only if you already run an equivalent external memory-control plane:
586
600
 
587
601
  ```ts
@@ -2,6 +2,7 @@ import { SelfReliance, ResourceSnapshot, SelfRelianceState } from './selfRelianc
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,27 @@ 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
+ };
25
47
  type AgentLoopContext = {
26
48
  snapshot: ResourceSnapshot;
27
49
  survivalState: SelfRelianceState;
@@ -37,6 +59,10 @@ type AgentLoopContext = {
37
59
  memoryUpgrade?: CompoundingMemoryUpgradeResult;
38
60
  /** Present when required-set maintenance check runs (default daily). */
39
61
  memoryRequiredSet?: CompoundingMemoryRequiredSetResult;
62
+ /** Strict-memory runtime preset + per-cycle evaluation status. */
63
+ strictMemoryPreset?: StrictMemoryRuntimePreset;
64
+ strictMemoryEvaluation?: StrictMemoryEvaluation;
65
+ strictMemoryUpgrade?: StrictMemoryUpgradeResult;
40
66
  timestamp: number;
41
67
  };
42
68
  type AgentLoopMemoryConfig = {
@@ -114,6 +140,7 @@ type AgentLoopConfig = {
114
140
  escapeHatch?: AgentLoopEscapeHatchConfig;
115
141
  memory?: AgentLoopMemoryConfig;
116
142
  durability?: AgentLoopDurabilityConfig;
143
+ strictMemory?: AgentLoopStrictMemoryConfig;
117
144
  };
118
145
  /**
119
146
  * Create a closed-loop runner that:
@@ -131,4 +158,4 @@ declare const createAgentLoop: (config: AgentLoopConfig) => {
131
158
  runOnce: () => Promise<void>;
132
159
  };
133
160
 
134
- export { type AgentLoopConfig, type AgentLoopContext, type AgentLoopDurabilityConfig, type AgentLoopEscapeHatchConfig, type AgentLoopEscapeHatchInput, type AgentLoopHooks, type AgentLoopMemoryConfig, createAgentLoop };
161
+ export { type AgentLoopConfig, type AgentLoopContext, type AgentLoopDurabilityConfig, type AgentLoopEscapeHatchConfig, type AgentLoopEscapeHatchInput, type AgentLoopHooks, type AgentLoopMemoryConfig, type AgentLoopStrictMemoryConfig, createAgentLoop };
package/dist/agentLoop.js CHANGED
@@ -5,6 +5,14 @@ import {
5
5
  import {
6
6
  createDurabilityProxyClient
7
7
  } from "./chunk-PVCW4MAY.js";
8
+ import {
9
+ createSelfRelianceMonitor
10
+ } from "./chunk-M7DQTU5R.js";
11
+ import {
12
+ createStrictMemoryRuntimePreset,
13
+ evaluateStrictMemoryExecution,
14
+ upgradeToStrictMemoryRuntimePreset
15
+ } from "./chunk-RUKN3KQ2.js";
8
16
  import {
9
17
  evaluateEscapeHatch,
10
18
  formatEscapeHatchDecision
@@ -14,9 +22,6 @@ import {
14
22
  formatSurvivalRecommendation,
15
23
  getSurvivalRecommendation
16
24
  } from "./chunk-JQE72P4C.js";
17
- import {
18
- createSelfRelianceMonitor
19
- } from "./chunk-M7DQTU5R.js";
20
25
 
21
26
  // src/agentLoop.ts
22
27
  var asFiniteNumber = (value) => {
@@ -51,6 +56,16 @@ 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 strictMemoryUpgrade = upgradeToStrictMemoryRuntimePreset({
63
+ current: strictMemoryPreset,
64
+ targetMode: strictMode,
65
+ backupCreated: true,
66
+ healthcheckPassed: true,
67
+ recentBlockRate: 0
68
+ });
54
69
  const durabilityEnabled = config.durability?.enabled ?? false;
55
70
  const durabilityClient = durabilityEnabled ? createDurabilityProxyClient({
56
71
  baseUrl: config.durability?.baseUrl || "",
@@ -149,6 +164,16 @@ var createAgentLoop = (config) => {
149
164
  }
150
165
  lastDurabilitySyncCheckedAt = memoryRequiredSet.checkedAt;
151
166
  };
167
+ const defaultStrictInputBuilder = (ctx) => {
168
+ const raw = ctx.snapshot;
169
+ return {
170
+ taskText: String(raw.taskText || raw.objective || ""),
171
+ isMutation: Boolean(raw.isMutation),
172
+ contextPackPrepared: Boolean(raw.contextPackPrepared),
173
+ semanticRecallConfirmed: Boolean(raw.semanticRecallConfirmed),
174
+ approvalPreflightPassed: Boolean(raw.approvalPreflightPassed)
175
+ };
176
+ };
152
177
  const runOnce = async () => {
153
178
  try {
154
179
  const memoryUpgrade = await ensureMemoryUpgrade();
@@ -190,6 +215,14 @@ var createAgentLoop = (config) => {
190
215
  }
191
216
  }
192
217
  const survivalDecisionBlock = [survivalFormatted, escapeHatchFormatted].filter(Boolean).join("\n\n");
218
+ let strictMemoryEvaluation;
219
+ if (strictMemoryEnabled) {
220
+ const strictInput = (config.strictMemory?.buildInput || defaultStrictInputBuilder)({ snapshot, timestamp });
221
+ strictMemoryEvaluation = evaluateStrictMemoryExecution(strictInput, strictMemoryPreset);
222
+ if (config.strictMemory?.onEvaluation) {
223
+ await config.strictMemory.onEvaluation(strictMemoryEvaluation);
224
+ }
225
+ }
193
226
  const ctx = {
194
227
  snapshot,
195
228
  survivalState,
@@ -201,11 +234,18 @@ var createAgentLoop = (config) => {
201
234
  escapeHatchFormatted,
202
235
  memoryUpgrade: memoryUpgrade ?? void 0,
203
236
  memoryRequiredSet: memoryRequiredSet ?? void 0,
237
+ strictMemoryPreset: strictMemoryEnabled ? strictMemoryPreset : void 0,
238
+ strictMemoryEvaluation,
239
+ strictMemoryUpgrade: strictMemoryEnabled ? strictMemoryUpgrade : void 0,
204
240
  timestamp
205
241
  };
206
242
  if (hooks.onCycle) await hooks.onCycle(ctx);
207
243
  if (hooks.onReflection) await hooks.onReflection(ctx);
208
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
+ }
209
249
  if (guardAct) {
210
250
  const allowed = await config.survival.guard();
211
251
  if (allowed) {
@@ -0,0 +1,63 @@
1
+ // src/outcomeBoundFlow.ts
2
+ var OUTCOME_BOUND_FLOW_SCHEMA = "outcome-bound-autonomous-flow/v1";
3
+ var OUTCOME_BOUND_REQUIRED_GATES = [
4
+ "public_deploy_url",
5
+ "listing_updated",
6
+ "external_smoke_check",
7
+ "evidence_log",
8
+ "context_pack_preflight"
9
+ ];
10
+ var isNonEmpty = (v) => typeof v === "string" && v.trim().length > 0;
11
+ var evaluateOutcomeBoundRun = (input) => {
12
+ const failedGates = [];
13
+ const reasons = [];
14
+ if (!isNonEmpty(input.publicDeployUrl)) {
15
+ failedGates.push("public_deploy_url");
16
+ reasons.push("Missing public deploy URL.");
17
+ }
18
+ if (!input.listingUpdated || !isNonEmpty(input.listingId)) {
19
+ failedGates.push("listing_updated");
20
+ reasons.push("Listing update is incomplete (listingUpdated/listingId required).");
21
+ }
22
+ if (!input.externalSmokeCheck?.passed) {
23
+ failedGates.push("external_smoke_check");
24
+ reasons.push("External smoke check did not pass.");
25
+ }
26
+ if (!isNonEmpty(input.evidenceLogPath)) {
27
+ failedGates.push("evidence_log");
28
+ reasons.push("Missing evidence log path.");
29
+ }
30
+ if (!input.contextPackPreflight?.passed) {
31
+ failedGates.push("context_pack_preflight");
32
+ reasons.push("Context-pack preflight did not pass.");
33
+ }
34
+ const passedCount = OUTCOME_BOUND_REQUIRED_GATES.length - failedGates.length;
35
+ const score = Number((passedCount / OUTCOME_BOUND_REQUIRED_GATES.length).toFixed(2));
36
+ const completed = failedGates.length === 0;
37
+ return {
38
+ schema: OUTCOME_BOUND_FLOW_SCHEMA,
39
+ runId: input.runId,
40
+ objective: input.objective,
41
+ completed,
42
+ failedGates,
43
+ score,
44
+ status: completed ? "pass" : "fail",
45
+ reasons,
46
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
47
+ };
48
+ };
49
+ var assertOutcomeBoundCompleted = (input) => {
50
+ const status = evaluateOutcomeBoundRun(input);
51
+ if (!status.completed) {
52
+ const details = status.reasons.join(" ");
53
+ throw new Error(`outcome_bound_incomplete:${status.failedGates.join(",")}${details ? `:${details}` : ""}`);
54
+ }
55
+ return status;
56
+ };
57
+
58
+ export {
59
+ OUTCOME_BOUND_FLOW_SCHEMA,
60
+ OUTCOME_BOUND_REQUIRED_GATES,
61
+ evaluateOutcomeBoundRun,
62
+ assertOutcomeBoundCompleted
63
+ };
@@ -0,0 +1,158 @@
1
+ // src/strictMemoryRuntime.ts
2
+ var STRICT_MEMORY_RUNTIME_SCHEMA = "strict-memory-runtime/v1";
3
+ var DEFAULT_MUTATION_KEYWORDS = [
4
+ "deploy",
5
+ "restart",
6
+ "install",
7
+ "delete",
8
+ "remove",
9
+ "push",
10
+ "publish",
11
+ "release",
12
+ "migrate",
13
+ "config",
14
+ "cron",
15
+ "service",
16
+ "production",
17
+ "prod"
18
+ ];
19
+ var DEFAULT_COMPLEX_KEYWORDS = [
20
+ "multi-step",
21
+ "cross-day",
22
+ "production",
23
+ "owner",
24
+ "id",
25
+ "listing",
26
+ "migration",
27
+ "incident",
28
+ "release",
29
+ "rollout",
30
+ "infra",
31
+ "security"
32
+ ];
33
+ var uniq = (arr) => [...new Set(arr.map((s) => String(s).trim()).filter(Boolean))];
34
+ var createStrictMemoryRuntimePreset = (overrides = {}) => {
35
+ const base = {
36
+ schema: STRICT_MEMORY_RUNTIME_SCHEMA,
37
+ enabled: true,
38
+ requireContextPackForComplex: true,
39
+ requireSemanticRecallForComplex: true,
40
+ requireApprovalPreflightForMutations: true,
41
+ maxContextPackAgeMin: 180,
42
+ mutationKeywords: [...DEFAULT_MUTATION_KEYWORDS],
43
+ complexTaskTrigger: {
44
+ keywords: [...DEFAULT_COMPLEX_KEYWORDS],
45
+ minTaskChars: 80
46
+ },
47
+ upgradePolicy: {
48
+ mode: "observe",
49
+ safeUpgrade: {
50
+ backupBeforeEnable: true,
51
+ requireHealthcheckPass: true,
52
+ rollbackOnBlockRateAbove: 0.35
53
+ }
54
+ }
55
+ };
56
+ return {
57
+ ...base,
58
+ ...overrides,
59
+ mutationKeywords: uniq(overrides.mutationKeywords || base.mutationKeywords),
60
+ complexTaskTrigger: {
61
+ ...base.complexTaskTrigger,
62
+ ...overrides.complexTaskTrigger || {},
63
+ keywords: uniq(overrides.complexTaskTrigger?.keywords || base.complexTaskTrigger.keywords)
64
+ },
65
+ upgradePolicy: {
66
+ ...base.upgradePolicy,
67
+ ...overrides.upgradePolicy || {},
68
+ safeUpgrade: {
69
+ ...base.upgradePolicy.safeUpgrade,
70
+ ...overrides.upgradePolicy?.safeUpgrade || {}
71
+ }
72
+ }
73
+ };
74
+ };
75
+ var includesAny = (text, words) => {
76
+ const low = text.toLowerCase();
77
+ return words.some((w) => low.includes(w.toLowerCase()));
78
+ };
79
+ var isComplexTask = (taskText, preset = createStrictMemoryRuntimePreset()) => {
80
+ const text = String(taskText || "").trim();
81
+ if (!text) return false;
82
+ if (text.length >= preset.complexTaskTrigger.minTaskChars) return true;
83
+ return includesAny(text, preset.complexTaskTrigger.keywords);
84
+ };
85
+ var evaluateStrictMemoryExecution = (input, preset = createStrictMemoryRuntimePreset()) => {
86
+ const complex = isComplexTask(input.taskText, preset);
87
+ const shouldEnforce = preset.enabled && (complex || input.isMutation);
88
+ const requiredSteps = [];
89
+ const missingSteps = [];
90
+ const reasons = [];
91
+ if (!shouldEnforce) {
92
+ return { complex, shouldEnforce, allowed: true, requiredSteps, missingSteps, reasons };
93
+ }
94
+ if (preset.requireContextPackForComplex && complex) {
95
+ requiredSteps.push("context_pack_prepared");
96
+ if (!input.contextPackPrepared) {
97
+ missingSteps.push("context_pack_prepared");
98
+ reasons.push("Missing context pack for complex task.");
99
+ }
100
+ }
101
+ if (preset.requireSemanticRecallForComplex && complex) {
102
+ requiredSteps.push("semantic_recall_confirmed");
103
+ if (!input.semanticRecallConfirmed) {
104
+ missingSteps.push("semantic_recall_confirmed");
105
+ reasons.push("Missing semantic recall confirmation for complex task.");
106
+ }
107
+ }
108
+ if (preset.requireApprovalPreflightForMutations && input.isMutation) {
109
+ requiredSteps.push("approval_preflight_passed");
110
+ if (!input.approvalPreflightPassed) {
111
+ missingSteps.push("approval_preflight_passed");
112
+ reasons.push("Mutation preflight approval did not pass.");
113
+ }
114
+ }
115
+ return {
116
+ complex,
117
+ shouldEnforce,
118
+ allowed: missingSteps.length === 0,
119
+ requiredSteps,
120
+ missingSteps,
121
+ reasons
122
+ };
123
+ };
124
+ var upgradeToStrictMemoryRuntimePreset = (input = {}) => {
125
+ const current = createStrictMemoryRuntimePreset(input.current || {});
126
+ const targetMode = input.targetMode || current.upgradePolicy.mode || "observe";
127
+ const next = createStrictMemoryRuntimePreset({
128
+ ...current,
129
+ upgradePolicy: {
130
+ ...current.upgradePolicy,
131
+ mode: targetMode
132
+ }
133
+ });
134
+ const reasons = [];
135
+ const safeCfg = next.upgradePolicy.safeUpgrade;
136
+ if (safeCfg.backupBeforeEnable && !input.backupCreated) {
137
+ reasons.push("Backup not confirmed.");
138
+ }
139
+ if (safeCfg.requireHealthcheckPass && !input.healthcheckPassed) {
140
+ reasons.push("Healthcheck not confirmed.");
141
+ }
142
+ if (typeof input.recentBlockRate === "number" && input.recentBlockRate > safeCfg.rollbackOnBlockRateAbove && targetMode === "enforce") {
143
+ reasons.push("Recent block rate is too high for enforce mode; keep observe mode first.");
144
+ }
145
+ return {
146
+ next,
147
+ safe: reasons.length === 0,
148
+ reasons
149
+ };
150
+ };
151
+
152
+ export {
153
+ STRICT_MEMORY_RUNTIME_SCHEMA,
154
+ createStrictMemoryRuntimePreset,
155
+ isComplexTask,
156
+ evaluateStrictMemoryExecution,
157
+ upgradeToStrictMemoryRuntimePreset
158
+ };
@@ -0,0 +1,73 @@
1
+ declare const HUMAN_APP_LOOP_SCHEMA = "human-app-reflective-loop/v1";
2
+ declare const HUMAN_APP_LOOP_PHASES: readonly ["research", "hypothesis", "build", "launch", "observe", "reflect", "iterate"];
3
+ type HumanAppLoopPhase = (typeof HUMAN_APP_LOOP_PHASES)[number];
4
+ type HumanAppPhaseContract = {
5
+ phase: HumanAppLoopPhase;
6
+ requiredInputs: string[];
7
+ requiredOutputs: string[];
8
+ goNoGoCriteria: string[];
9
+ stopOrRollbackConditions: string[];
10
+ kpis: string[];
11
+ };
12
+ type HumanAppLoopSpec = {
13
+ schema: typeof HUMAN_APP_LOOP_SCHEMA;
14
+ createdAt: string;
15
+ phases: HumanAppPhaseContract[];
16
+ optionalToolUsePolicy: {
17
+ enabled: true;
18
+ rules: string[];
19
+ };
20
+ overlapWithAgentListingLoops: {
21
+ overlap: string[];
22
+ differences: string[];
23
+ };
24
+ evaluationRubric: {
25
+ dimensions: Array<{
26
+ id: 'researchDepth' | 'iterationQuality' | 'outcomeUsefulness';
27
+ description: string;
28
+ weight: number;
29
+ passThreshold: number;
30
+ }>;
31
+ overallPassThreshold: number;
32
+ };
33
+ };
34
+ type HumanAppTrialInput = {
35
+ id: string;
36
+ summary?: string;
37
+ evidence: {
38
+ researchNotesCount: number;
39
+ hypothesisCount: number;
40
+ experimentsRun: number;
41
+ measurableKpiCount: number;
42
+ rollbackPlanPresent: boolean;
43
+ shippedArtifactPresent: boolean;
44
+ iterationSteps: number;
45
+ };
46
+ };
47
+ type HumanAppTrialEvaluation = {
48
+ id: string;
49
+ scores: {
50
+ researchDepth: number;
51
+ iterationQuality: number;
52
+ outcomeUsefulness: number;
53
+ };
54
+ weightedScore: number;
55
+ pass: boolean;
56
+ notes: string[];
57
+ };
58
+ declare const createHumanAppLoopSpec: (createdAt?: string) => HumanAppLoopSpec;
59
+ declare const evaluateHumanAppTrial: (trial: HumanAppTrialInput, spec?: HumanAppLoopSpec) => HumanAppTrialEvaluation;
60
+ type ScaffoldHumanAppLoopPackOptions = {
61
+ root?: string;
62
+ outputDir?: string;
63
+ overwrite?: boolean;
64
+ };
65
+ type ScaffoldHumanAppLoopPackResult = {
66
+ root: string;
67
+ outputDir: string;
68
+ files: string[];
69
+ createdAt: string;
70
+ };
71
+ declare const scaffoldHumanAppLoopPack: (options?: ScaffoldHumanAppLoopPackOptions) => Promise<ScaffoldHumanAppLoopPackResult>;
72
+
73
+ export { HUMAN_APP_LOOP_PHASES, HUMAN_APP_LOOP_SCHEMA, type HumanAppLoopPhase, type HumanAppLoopSpec, type HumanAppPhaseContract, type HumanAppTrialEvaluation, type HumanAppTrialInput, type ScaffoldHumanAppLoopPackOptions, type ScaffoldHumanAppLoopPackResult, createHumanAppLoopSpec, evaluateHumanAppTrial, scaffoldHumanAppLoopPack };