create-metamynd-agent 0.2.0 → 0.3.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.
Files changed (2) hide show
  1. package/index.mjs +73 -9
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -189,6 +189,7 @@ function exampleIndex(scope, perTxnMax) {
189
189
  // Every governed tool call is checked (allow / block / escalate) before it runs.
190
190
  import { createGuardFromConfig } from '${GUARD_PKG}';
191
191
 
192
+ // Loads agent.metamynd.json: the agent's DID, its signing key, and the gate to call.
192
193
  const guard = await createGuardFromConfig('./agent.metamynd.json'); // no env vars
193
194
 
194
195
  // --- Your real tool. Replace the body with your actual implementation. ---
@@ -208,22 +209,85 @@ const gatedBookFlight = guard.guardTool(
208
209
  }),
209
210
  );
210
211
 
211
- async function ask(label, args) {
212
+ const dim = (t) => '\\x1b[2m' + t + '\\x1b[0m';
213
+ const bold = (t) => '\\x1b[1m' + t + '\\x1b[0m';
214
+ const rule = (n) => ' ' + '-'.repeat(n);
215
+
216
+ // Plain-English meaning for the reason codes this demo can produce.
217
+ const WHY = {
218
+ AUTHORIZED: 'inside the mandate and under the SOP spend cap',
219
+ SOP_SPEND_CAP: 'your SOP caps a single transaction at $${perTxnMax}',
220
+ RISK_REVIEW: 'your SOP sends high-risk actions to a human first',
221
+ MERCHANT_NOT_ALLOWED: 'the mandate lists which merchants this agent may pay',
222
+ };
223
+
224
+ // ---------------------------------------------------------------- 1. CONTEXT
225
+ console.log('');
226
+ console.log(bold(' What this simulation shows'));
227
+ console.log('');
228
+ console.log(' An agent should not be the thing that decides what it is allowed to do.');
229
+ console.log(' This run makes that concrete: the SAME code path is attempted three times');
230
+ console.log(' and produces three different outcomes, because the decision is made');
231
+ console.log(' outside your program - and cannot be argued with from inside it.');
232
+
233
+ // ---------------------------------------------------------------- 2. MECHANISM
234
+ console.log('');
235
+ console.log(bold(' How it does that'));
236
+ console.log('');
237
+ console.log(dim(' 1. this project holds an agent identity (a DID) and its signing key'));
238
+ console.log(dim(' 2. that agent has a mandate - a scope it may act in, and a spend cap'));
239
+ console.log(dim(' 3. guardTool() wraps your tool, so nothing calls the raw handler'));
240
+ console.log(dim(' 4. each attempt is signed here, then decided by MetaMynd remotely'));
241
+ console.log(dim(' 5. your tool runs ONLY if that decision is ALLOW'));
242
+ console.log('');
243
+ console.log(dim(' scope ${scope}'));
244
+ console.log(dim(' cap $${perTxnMax} per transaction, set by your SOP'));
245
+
246
+ // ---------------------------------------------------------------- 3. THE STEPS
247
+ async function attempt(n, intent, args) {
248
+ console.log('');
249
+ console.log(bold(' Step ' + n + ' of 3') + ' - ' + intent);
250
+ console.log(dim(' signing the request locally, then asking the gate to decide...'));
212
251
  try {
213
252
  const r = await gatedBookFlight(args);
214
- console.log(' \\x1b[32m✅ ALLOW\\x1b[0m ' + label.padEnd(26) + ' → booked ' + r.pnr);
253
+ console.log('\\x1b[32m ALLOWED\\x1b[0m your tool ran and returned ' + r.pnr);
254
+ console.log(dim(' ' + WHY.AUTHORIZED));
215
255
  } catch (e) {
216
256
  const g = e.governance ?? {};
217
- const tag = g.decision === 'escalate' ? '\\x1b[33m⚠ ESCALATE\\x1b[0m' : '\\x1b[31m⛔ BLOCK\\x1b[0m';
218
- console.log(' ' + tag + ' ' + label.padEnd(26) + ' → ' + (g.reasonCode ?? e.message));
257
+ const why = WHY[g.reasonCode] ?? e.message;
258
+ if (g.decision === 'escalate') {
259
+ console.log('\\x1b[33m ESCALATED\\x1b[0m held for a human - ' + g.reasonCode);
260
+ console.log(dim(' ' + why));
261
+ console.log(dim(' not a failure: approve it in the dashboard and the action resumes.'));
262
+ } else {
263
+ console.log('\\x1b[31m BLOCKED\\x1b[0m ' + (g.reasonCode ?? 'refused'));
264
+ console.log(dim(' ' + why));
265
+ console.log(dim(' your tool never ran - the gate refused before execution.'));
266
+ }
219
267
  }
220
268
  }
221
269
 
222
- console.log('\\n ${scope} — every action passes through the MetaMynd gate\\n ' + '─'.repeat(58));
223
- await ask('$${under} low risk', { amount: ${under}, merchant: 'skyward-air', riskLevel: 'low' });
224
- await ask('$${over} over cap', { amount: ${over}, merchant: 'skyward-air', riskLevel: 'low' });
225
- await ask('$${under} high risk', { amount: ${under}, merchant: 'skyward-air', riskLevel: 'high' });
226
- console.log('\\n Change the rules any time in the dashboard (Legal Entity SOPs) no redeploy.\\n');
270
+ console.log('');
271
+ console.log(rule(66));
272
+ await attempt(1, 'a $${under} booking, low risk. Expected to pass.', { amount: ${under}, merchant: 'skyward-air', riskLevel: 'low' });
273
+ await attempt(2, 'a $${over} booking, deliberately over the cap.', { amount: ${over}, merchant: 'skyward-air', riskLevel: 'low' });
274
+ await attempt(3, 'a $${under} booking, but flagged high risk.', { amount: ${under}, merchant: 'skyward-air', riskLevel: 'high' });
275
+ console.log('');
276
+ console.log(rule(66));
277
+
278
+ // ---------------------------------------------------------------- 4. RESULT
279
+ console.log('');
280
+ console.log(bold(' What this proved'));
281
+ console.log('');
282
+ console.log(dim(' - one code path, three outcomes. The rules decided, not this file'));
283
+ console.log(dim(' and not the model driving it.'));
284
+ console.log(dim(' - the blocked call never reached your tool at all.'));
285
+ console.log(dim(' - every decision was recorded as tamper-evident evidence.'));
286
+ console.log(dim(' - if the gate were unreachable the guard fails CLOSED: it blocks.'));
287
+ console.log('');
288
+ console.log(' Change the cap in the dashboard (Legal Entity -> SOPs) and run again.');
289
+ console.log(dim(' The outcome changes. This file does not. That is the point.'));
290
+ console.log('');
227
291
  `;
228
292
  }
229
293
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-metamynd-agent",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Scaffold a MetaMynd/AgentSafe-governed AI agent in one command — logs in, provisions the agent (identity + mandate + SOP + Standards) in a single call, writes agent.metamynd.json, and drops a runnable example.",
5
5
  "type": "module",
6
6
  "bin": {