@evomap/evolver 1.70.0 → 1.72.0
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/assets/gep/candidates.jsonl +4 -6
- package/index.js +76 -6
- package/package.json +1 -1
- package/scripts/validate-suite.js +21 -6
- package/src/adapters/hookAdapter.js +3 -1
- package/src/adapters/kiro.js +203 -0
- package/src/adapters/scripts/evolver-session-start.js +62 -0
- package/src/atp/autoBuyer.js +12 -6
- package/src/atp/autoDeliver.js +199 -0
- package/src/atp/cliAutobuyPrompt.js +4 -3
- package/src/atp/hubClient.js +20 -0
- package/src/atp/index.js +4 -1
- package/src/evolve.js +1 -1
- package/src/gep/.integrity +0 -0
- package/src/gep/a2aProtocol.js +1 -1
- package/src/gep/candidateEval.js +1 -1
- package/src/gep/candidates.js +1 -1
- package/src/gep/contentHash.js +1 -1
- package/src/gep/crypto.js +1 -1
- package/src/gep/curriculum.js +1 -1
- package/src/gep/deviceId.js +1 -1
- package/src/gep/envFingerprint.js +1 -1
- package/src/gep/explore.js +1 -1
- package/src/gep/hubReview.js +1 -1
- package/src/gep/hubSearch.js +1 -1
- package/src/gep/hubVerify.js +1 -1
- package/src/gep/integrityCheck.js +1 -1
- package/src/gep/learningSignals.js +1 -1
- package/src/gep/memoryGraph.js +1 -1
- package/src/gep/memoryGraphAdapter.js +1 -1
- package/src/gep/mutation.js +1 -1
- package/src/gep/narrativeMemory.js +1 -1
- package/src/gep/personality.js +1 -1
- package/src/gep/policyCheck.js +1 -1
- package/src/gep/prompt.js +1 -1
- package/src/gep/reflection.js +1 -1
- package/src/gep/selector.js +1 -1
- package/src/gep/shield.js +1 -1
- package/src/gep/skillDistiller.js +1 -1
- package/src/gep/solidify.js +1 -1
- package/src/gep/strategy.js +1 -1
- package/src/gep/validator/sandboxExecutor.js +11 -2
- package/src/proxy/lifecycle/manager.js +5 -1
- package/src/proxy/mailbox/store.js +5 -0
- package/src/proxy/server/http.js +47 -4
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// ATP Auto-Deliver (opt-out, merchant-side)
|
|
2
|
+
// Closes the ATP settlement loop for Evolver merchants by auto-calling
|
|
3
|
+
// submitDelivery for every claimed task that carries an atp_order_id.
|
|
4
|
+
//
|
|
5
|
+
// Without this module, an ATP order sits in `pending` until the 7-day escrow
|
|
6
|
+
// timeout refunds the buyer: the Hub routes the task to a merchant node and
|
|
7
|
+
// marks it claimed, but nothing in the Evolver runtime actually calls
|
|
8
|
+
// /a2a/atp/deliver. This was the root cause of the 0-settled-in-13-days
|
|
9
|
+
// pipeline stall observed in prod on 2026-04-27.
|
|
10
|
+
//
|
|
11
|
+
// Integration contract:
|
|
12
|
+
// 1) Call start({ pollMs }) once at Evolver boot. Default ON.
|
|
13
|
+
// Disable by setting EVOLVER_ATP_AUTODELIVER=off.
|
|
14
|
+
// 2) The module polls /a2a/task/my every pollMs milliseconds, finds tasks
|
|
15
|
+
// with atp_order_id + a `result_asset_id` (meaning the task already
|
|
16
|
+
// completed through solidify), and submits a minimal proofPayload.
|
|
17
|
+
// 3) Each submitted order is remembered in a local ledger so we never
|
|
18
|
+
// double-submit, even across restarts.
|
|
19
|
+
//
|
|
20
|
+
// Dedup ledger lives alongside autoBuyer's ledger under memory/.
|
|
21
|
+
// Failure modes are non-fatal: network errors are logged, not thrown.
|
|
22
|
+
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
const path = require('path');
|
|
25
|
+
|
|
26
|
+
const { getMemoryDir } = require('../gep/paths');
|
|
27
|
+
const hubClient = require('./hubClient');
|
|
28
|
+
|
|
29
|
+
const DEFAULT_POLL_MS = 60 * 1000; // 1 min
|
|
30
|
+
const MIN_POLL_MS = 15 * 1000;
|
|
31
|
+
const LEDGER_FILENAME = 'atp-autodeliver-ledger.json';
|
|
32
|
+
const LEDGER_MAX_ENTRIES = 500;
|
|
33
|
+
|
|
34
|
+
let _started = false;
|
|
35
|
+
let _pollInterval = null;
|
|
36
|
+
let _pollMs = DEFAULT_POLL_MS;
|
|
37
|
+
let _inflight = false;
|
|
38
|
+
|
|
39
|
+
function _ledgerPath() {
|
|
40
|
+
return path.join(getMemoryDir(), LEDGER_FILENAME);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function _isEnabled() {
|
|
44
|
+
const raw = (process.env.EVOLVER_ATP_AUTODELIVER || 'on').toLowerCase().trim();
|
|
45
|
+
return raw !== 'off' && raw !== '0' && raw !== 'false';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function _emptyLedger() {
|
|
49
|
+
return { version: 1, submitted: {} };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function _readLedger() {
|
|
53
|
+
try {
|
|
54
|
+
const p = _ledgerPath();
|
|
55
|
+
if (!fs.existsSync(p)) return _emptyLedger();
|
|
56
|
+
const raw = fs.readFileSync(p, 'utf8');
|
|
57
|
+
const parsed = JSON.parse(raw);
|
|
58
|
+
if (!parsed || typeof parsed !== 'object' || !parsed.submitted) return _emptyLedger();
|
|
59
|
+
return parsed;
|
|
60
|
+
} catch (_) {
|
|
61
|
+
return _emptyLedger();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function _writeLedger(ledger) {
|
|
66
|
+
try {
|
|
67
|
+
const dir = getMemoryDir();
|
|
68
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
69
|
+
// Bound the ledger size so it cannot grow without limit on long-running
|
|
70
|
+
// merchants. Keep the most-recent entries by insertion order.
|
|
71
|
+
const entries = Object.entries(ledger.submitted || {});
|
|
72
|
+
if (entries.length > LEDGER_MAX_ENTRIES) {
|
|
73
|
+
const trimmed = Object.fromEntries(entries.slice(-LEDGER_MAX_ENTRIES));
|
|
74
|
+
ledger.submitted = trimmed;
|
|
75
|
+
}
|
|
76
|
+
const tmp = _ledgerPath() + '.tmp';
|
|
77
|
+
fs.writeFileSync(tmp, JSON.stringify(ledger, null, 2));
|
|
78
|
+
fs.renameSync(tmp, _ledgerPath());
|
|
79
|
+
} catch (_) {
|
|
80
|
+
// Non-fatal: next poll will re-attempt from Hub state. Hub-side
|
|
81
|
+
// submitDelivery is itself idempotent per order id.
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function _buildProofPayload(task) {
|
|
86
|
+
// Minimal evidence the Hub's auto verifier will accept. Matches the shape
|
|
87
|
+
// documented in /a2a/atp/deliver: result/output/pass_rate/signals.
|
|
88
|
+
const now = new Date().toISOString();
|
|
89
|
+
return {
|
|
90
|
+
result: 'completed',
|
|
91
|
+
asset_id: task.result_asset_id || null,
|
|
92
|
+
completed_at: task.claimed_at || now,
|
|
93
|
+
pass_rate: 1.0,
|
|
94
|
+
signals: Array.isArray(task.signals) ? task.signals.slice(0, 10) : [],
|
|
95
|
+
submitter: 'evolver_auto_deliver',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function _tick() {
|
|
100
|
+
if (_inflight) return;
|
|
101
|
+
_inflight = true;
|
|
102
|
+
try {
|
|
103
|
+
const result = await hubClient.listMyTasks(20);
|
|
104
|
+
if (!result || !result.ok || !result.data) return;
|
|
105
|
+
const tasks = Array.isArray(result.data.tasks) ? result.data.tasks : [];
|
|
106
|
+
if (tasks.length === 0) return;
|
|
107
|
+
|
|
108
|
+
const ledger = _readLedger();
|
|
109
|
+
let wroteLedger = false;
|
|
110
|
+
|
|
111
|
+
for (const task of tasks) {
|
|
112
|
+
const orderId = task && task.atp_order_id;
|
|
113
|
+
if (!orderId) continue;
|
|
114
|
+
if (ledger.submitted[orderId]) continue;
|
|
115
|
+
// Only deliver once the task has a result asset (i.e. solidify finished).
|
|
116
|
+
if (!task.result_asset_id) continue;
|
|
117
|
+
// Don't try to deliver on already-terminal statuses.
|
|
118
|
+
if (task.status && task.status !== 'claimed' && task.status !== 'completed') continue;
|
|
119
|
+
|
|
120
|
+
const proofPayload = _buildProofPayload(task);
|
|
121
|
+
const resp = await hubClient.submitDelivery(orderId, proofPayload);
|
|
122
|
+
if (resp && resp.ok) {
|
|
123
|
+
ledger.submitted[orderId] = Date.now();
|
|
124
|
+
wroteLedger = true;
|
|
125
|
+
console.log('[ATP-AutoDeliver] Delivered order=' + orderId + ' asset=' + (task.result_asset_id || 'none'));
|
|
126
|
+
} else {
|
|
127
|
+
// Record terminal-ish errors in the ledger so we do not hammer the
|
|
128
|
+
// same order every minute. Everything else (transient network) is
|
|
129
|
+
// retried on the next tick.
|
|
130
|
+
const err = (resp && resp.error) || 'unknown_error';
|
|
131
|
+
const status = resp && resp.status;
|
|
132
|
+
const terminal = status === 400 || status === 404 || status === 409;
|
|
133
|
+
if (terminal) {
|
|
134
|
+
ledger.submitted[orderId] = -Date.now();
|
|
135
|
+
wroteLedger = true;
|
|
136
|
+
}
|
|
137
|
+
console.log('[ATP-AutoDeliver] Delivery failed order=' + orderId + ' status=' + (status || 'n/a') + ' err=' + String(err).slice(0, 120));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (wroteLedger) _writeLedger(ledger);
|
|
142
|
+
} catch (err) {
|
|
143
|
+
console.log('[ATP-AutoDeliver] Tick threw (non-fatal): ' + (err && err.message || err));
|
|
144
|
+
} finally {
|
|
145
|
+
_inflight = false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function start(opts) {
|
|
150
|
+
if (_started) return;
|
|
151
|
+
if (!_isEnabled()) return;
|
|
152
|
+
const requested = Number((opts && opts.pollMs) || process.env.ATP_AUTODELIVER_POLL_MS || DEFAULT_POLL_MS);
|
|
153
|
+
_pollMs = Math.max(MIN_POLL_MS, Math.floor(requested) || DEFAULT_POLL_MS);
|
|
154
|
+
_started = true;
|
|
155
|
+
_pollInterval = setInterval(function () {
|
|
156
|
+
_tick().catch(function () { /* swallowed in _tick */ });
|
|
157
|
+
}, _pollMs);
|
|
158
|
+
// Do not await -- fire the first tick asynchronously so start() returns
|
|
159
|
+
// immediately. This matches the autoBuyer start() semantics.
|
|
160
|
+
_tick().catch(function () { /* swallowed in _tick */ });
|
|
161
|
+
console.log('[ATP-AutoDeliver] Started (pollMs=' + _pollMs + ')');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function stop() {
|
|
165
|
+
if (_pollInterval) {
|
|
166
|
+
clearInterval(_pollInterval);
|
|
167
|
+
_pollInterval = null;
|
|
168
|
+
}
|
|
169
|
+
_started = false;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function isStarted() {
|
|
173
|
+
return _started;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function _resetForTests() {
|
|
177
|
+
stop();
|
|
178
|
+
_inflight = false;
|
|
179
|
+
_pollMs = DEFAULT_POLL_MS;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
module.exports = {
|
|
183
|
+
start,
|
|
184
|
+
stop,
|
|
185
|
+
isStarted,
|
|
186
|
+
__internals: {
|
|
187
|
+
tick: _tick,
|
|
188
|
+
readLedger: _readLedger,
|
|
189
|
+
writeLedger: _writeLedger,
|
|
190
|
+
buildProofPayload: _buildProofPayload,
|
|
191
|
+
resetForTests: _resetForTests,
|
|
192
|
+
constants: {
|
|
193
|
+
DEFAULT_POLL_MS,
|
|
194
|
+
MIN_POLL_MS,
|
|
195
|
+
LEDGER_FILENAME,
|
|
196
|
+
LEDGER_MAX_ENTRIES,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
};
|
|
@@ -117,10 +117,10 @@ async function runPrompt(opts) {
|
|
|
117
117
|
try {
|
|
118
118
|
output.write("\n");
|
|
119
119
|
output.write("[ATP-AutoBuyer] Your evolver can automatically place small-priced\n");
|
|
120
|
-
output.write("ATP orders when it detects a capability gap (default
|
|
120
|
+
output.write("ATP orders when it detects a capability gap (default ON).\n");
|
|
121
121
|
output.write(" - daily hard cap: ATP_AUTOBUY_DAILY_CAP_CREDITS (default applies)\n");
|
|
122
122
|
output.write(" - per-order cap: ATP_AUTOBUY_PER_ORDER_CAP_CREDITS\n");
|
|
123
|
-
output.write(" -
|
|
123
|
+
output.write(" - set EVOLVER_ATP_AUTOBUY=off and restart to disable at any time.\n");
|
|
124
124
|
output.write("\n");
|
|
125
125
|
} catch (_) {
|
|
126
126
|
return { prompted: false, decision: null, reason: "io_error" };
|
|
@@ -128,7 +128,7 @@ async function runPrompt(opts) {
|
|
|
128
128
|
|
|
129
129
|
let answer;
|
|
130
130
|
try {
|
|
131
|
-
answer = await ask("
|
|
131
|
+
answer = await ask("Keep autoBuyer enabled for this session? [y/n/later] ", {
|
|
132
132
|
input,
|
|
133
133
|
output,
|
|
134
134
|
});
|
|
@@ -143,6 +143,7 @@ async function runPrompt(opts) {
|
|
|
143
143
|
}
|
|
144
144
|
if (answer === "n" || answer === "no") {
|
|
145
145
|
_writeAck(false);
|
|
146
|
+
env.EVOLVER_ATP_AUTOBUY = "off";
|
|
146
147
|
return { prompted: true, decision: "no", reason: "user_declined" };
|
|
147
148
|
}
|
|
148
149
|
return { prompted: true, decision: "later", reason: "user_postponed" };
|
package/src/atp/hubClient.js
CHANGED
|
@@ -240,6 +240,25 @@ function getAtpPolicy() {
|
|
|
240
240
|
return _get('/atp/policy', '/a2a/atp/policy');
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
/**
|
|
244
|
+
* GET /a2a/task/my?node_id=... -- list this node's claimed tasks
|
|
245
|
+
*
|
|
246
|
+
* ATP-originated tasks include an `atp_order_id` field on each task so the
|
|
247
|
+
* merchant side can pair a completed task with its DeliveryProof and call
|
|
248
|
+
* submitDelivery. Non-ATP tasks simply omit the field. This is NOT an
|
|
249
|
+
* /atp/* endpoint so it never routes through the proxy passthrough.
|
|
250
|
+
*
|
|
251
|
+
* @param {number} [limit]
|
|
252
|
+
*/
|
|
253
|
+
function listMyTasks(limit) {
|
|
254
|
+
const nid = getNodeId();
|
|
255
|
+
const params = new URLSearchParams();
|
|
256
|
+
params.set('node_id', nid);
|
|
257
|
+
if (limit) params.set('limit', String(limit));
|
|
258
|
+
const suffix = '/a2a/task/my?' + params.toString();
|
|
259
|
+
return _hubGet(suffix);
|
|
260
|
+
}
|
|
261
|
+
|
|
243
262
|
module.exports = {
|
|
244
263
|
placeOrder,
|
|
245
264
|
submitDelivery,
|
|
@@ -250,6 +269,7 @@ module.exports = {
|
|
|
250
269
|
getOrderStatus,
|
|
251
270
|
listProofs,
|
|
252
271
|
getAtpPolicy,
|
|
272
|
+
listMyTasks,
|
|
253
273
|
// exported for tests only
|
|
254
274
|
_isProxyMode: _isProxyMode,
|
|
255
275
|
};
|
package/src/atp/index.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
// consumerAgent - ready-to-use consumer agent template
|
|
8
8
|
// serviceHelper - service publishing helper
|
|
9
9
|
// defaultHandler - default order handler + config helpers for auto-ATP
|
|
10
|
-
// autoBuyer - opt-
|
|
10
|
+
// autoBuyer - opt-out capability-gap auto order helper with budget caps
|
|
11
|
+
// autoDeliver - opt-out merchant-side submitDelivery daemon
|
|
11
12
|
// cli - parsers and runners for the `buy`/`orders`/`verify` subcommands
|
|
12
13
|
|
|
13
14
|
const hubClient = require('./hubClient');
|
|
@@ -16,6 +17,7 @@ const consumerAgent = require('./consumerAgent');
|
|
|
16
17
|
const serviceHelper = require('./serviceHelper');
|
|
17
18
|
const defaultHandler = require('./defaultHandler');
|
|
18
19
|
const autoBuyer = require('./autoBuyer');
|
|
20
|
+
const autoDeliver = require('./autoDeliver');
|
|
19
21
|
const cli = require('./cli');
|
|
20
22
|
|
|
21
23
|
module.exports = {
|
|
@@ -25,5 +27,6 @@ module.exports = {
|
|
|
25
27
|
serviceHelper,
|
|
26
28
|
defaultHandler,
|
|
27
29
|
autoBuyer,
|
|
30
|
+
autoDeliver,
|
|
28
31
|
cli,
|
|
29
32
|
};
|