@poa-box/agent 0.1.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 (139) hide show
  1. package/.env.agent.template +20 -0
  2. package/README.md +46 -0
  3. package/brain/Config/agent-config.json +14 -0
  4. package/brain/Config/brain-allowlist.json +20 -0
  5. package/brain/Identity/goals.template.md +23 -0
  6. package/brain/Identity/how-i-think.md +406 -0
  7. package/brain/Identity/who-i-am.template.md +34 -0
  8. package/brain/Knowledge/BOOTSTRAP.md +66 -0
  9. package/brain/Knowledge/audit-corpus-index.json +406 -0
  10. package/brain/Knowledge/discussions.json +245 -0
  11. package/brain/Knowledge/pop.brain.brainstorms.generated.md +48 -0
  12. package/brain/Knowledge/pop.brain.brainstorms.genesis.bin +0 -0
  13. package/brain/Knowledge/pop.brain.heuristics.snapshot.bin +0 -0
  14. package/brain/Knowledge/pop.brain.projects.generated.md +16 -0
  15. package/brain/Knowledge/pop.brain.projects.genesis.bin +0 -0
  16. package/brain/Knowledge/pop.brain.retros.generated.md +91 -0
  17. package/brain/Knowledge/pop.brain.retros.genesis.bin +0 -0
  18. package/brain/Knowledge/pop.brain.shared.generated.md +3811 -0
  19. package/brain/Knowledge/pop.brain.shared.genesis.bin +0 -0
  20. package/brain/Knowledge/projects.md +181 -0
  21. package/brain/Knowledge/risk-framework.md +90 -0
  22. package/brain/Knowledge/shared.md +416 -0
  23. package/brain/Knowledge/sprint-priorities.md +439 -0
  24. package/brain/Memory/.gitkeep +0 -0
  25. package/dist/commands/agent/daily-digest.d.ts +24 -0
  26. package/dist/commands/agent/daily-digest.js +336 -0
  27. package/dist/commands/agent/delegate.d.ts +12 -0
  28. package/dist/commands/agent/delegate.js +91 -0
  29. package/dist/commands/agent/deploy-to-org.d.ts +20 -0
  30. package/dist/commands/agent/deploy-to-org.js +154 -0
  31. package/dist/commands/agent/index.d.ts +2 -0
  32. package/dist/commands/agent/index.js +27 -0
  33. package/dist/commands/agent/init.d.ts +19 -0
  34. package/dist/commands/agent/init.js +303 -0
  35. package/dist/commands/agent/onboard.d.ts +22 -0
  36. package/dist/commands/agent/onboard.js +192 -0
  37. package/dist/commands/agent/paymaster-status.d.ts +14 -0
  38. package/dist/commands/agent/paymaster-status.js +130 -0
  39. package/dist/commands/agent/register.d.ts +21 -0
  40. package/dist/commands/agent/register.js +116 -0
  41. package/dist/commands/agent/setup-sponsorship.d.ts +22 -0
  42. package/dist/commands/agent/setup-sponsorship.js +154 -0
  43. package/dist/commands/agent/status.d.ts +12 -0
  44. package/dist/commands/agent/status.js +171 -0
  45. package/dist/commands/agent/triage.d.ts +12 -0
  46. package/dist/commands/agent/triage.js +503 -0
  47. package/dist/commands/brain/advance-stage.d.ts +42 -0
  48. package/dist/commands/brain/advance-stage.js +206 -0
  49. package/dist/commands/brain/allowlist.d.ts +30 -0
  50. package/dist/commands/brain/allowlist.js +274 -0
  51. package/dist/commands/brain/append-lesson.d.ts +55 -0
  52. package/dist/commands/brain/append-lesson.js +245 -0
  53. package/dist/commands/brain/brainstorm.d.ts +154 -0
  54. package/dist/commands/brain/brainstorm.js +573 -0
  55. package/dist/commands/brain/daemon.d.ts +31 -0
  56. package/dist/commands/brain/daemon.js +348 -0
  57. package/dist/commands/brain/doctor.d.ts +27 -0
  58. package/dist/commands/brain/doctor.js +497 -0
  59. package/dist/commands/brain/edit-lesson.d.ts +51 -0
  60. package/dist/commands/brain/edit-lesson.js +248 -0
  61. package/dist/commands/brain/import-snapshot.d.ts +68 -0
  62. package/dist/commands/brain/import-snapshot.js +177 -0
  63. package/dist/commands/brain/index.d.ts +2 -0
  64. package/dist/commands/brain/index.js +67 -0
  65. package/dist/commands/brain/list.d.ts +21 -0
  66. package/dist/commands/brain/list.js +83 -0
  67. package/dist/commands/brain/migrate-projects.d.ts +44 -0
  68. package/dist/commands/brain/migrate-projects.js +209 -0
  69. package/dist/commands/brain/migrate.d.ts +74 -0
  70. package/dist/commands/brain/migrate.js +306 -0
  71. package/dist/commands/brain/new-project.d.ts +53 -0
  72. package/dist/commands/brain/new-project.js +226 -0
  73. package/dist/commands/brain/read.d.ts +24 -0
  74. package/dist/commands/brain/read.js +81 -0
  75. package/dist/commands/brain/remove-lesson.d.ts +47 -0
  76. package/dist/commands/brain/remove-lesson.js +206 -0
  77. package/dist/commands/brain/remove-project.d.ts +36 -0
  78. package/dist/commands/brain/remove-project.js +177 -0
  79. package/dist/commands/brain/retro-file-tasks.d.ts +84 -0
  80. package/dist/commands/brain/retro-file-tasks.js +372 -0
  81. package/dist/commands/brain/retro-list.d.ts +28 -0
  82. package/dist/commands/brain/retro-list.js +125 -0
  83. package/dist/commands/brain/retro-mark-change.d.ts +58 -0
  84. package/dist/commands/brain/retro-mark-change.js +176 -0
  85. package/dist/commands/brain/retro-remove.d.ts +36 -0
  86. package/dist/commands/brain/retro-remove.js +142 -0
  87. package/dist/commands/brain/retro-respond.d.ts +56 -0
  88. package/dist/commands/brain/retro-respond.js +250 -0
  89. package/dist/commands/brain/retro-show.d.ts +23 -0
  90. package/dist/commands/brain/retro-show.js +100 -0
  91. package/dist/commands/brain/retro-start.d.ts +55 -0
  92. package/dist/commands/brain/retro-start.js +311 -0
  93. package/dist/commands/brain/search.d.ts +48 -0
  94. package/dist/commands/brain/search.js +190 -0
  95. package/dist/commands/brain/snapshot.d.ts +32 -0
  96. package/dist/commands/brain/snapshot.js +243 -0
  97. package/dist/commands/brain/status.d.ts +15 -0
  98. package/dist/commands/brain/status.js +166 -0
  99. package/dist/commands/brain/subscribe.d.ts +28 -0
  100. package/dist/commands/brain/subscribe.js +90 -0
  101. package/dist/commands/brain/tag.d.ts +46 -0
  102. package/dist/commands/brain/tag.js +192 -0
  103. package/dist/index.d.ts +17 -0
  104. package/dist/index.js +22 -0
  105. package/dist/lib/brain-daemon.d.ts +126 -0
  106. package/dist/lib/brain-daemon.js +811 -0
  107. package/dist/lib/brain-membership.d.ts +58 -0
  108. package/dist/lib/brain-membership.js +115 -0
  109. package/dist/lib/brain-migrate-projects.d.ts +43 -0
  110. package/dist/lib/brain-migrate-projects.js +247 -0
  111. package/dist/lib/brain-migrate.d.ts +77 -0
  112. package/dist/lib/brain-migrate.js +328 -0
  113. package/dist/lib/brain-ops.d.ts +271 -0
  114. package/dist/lib/brain-ops.js +571 -0
  115. package/dist/lib/brain-paths.d.ts +15 -0
  116. package/dist/lib/brain-paths.js +33 -0
  117. package/dist/lib/brain-projections.d.ts +216 -0
  118. package/dist/lib/brain-projections.js +829 -0
  119. package/dist/lib/brain-schemas.d.ts +36 -0
  120. package/dist/lib/brain-schemas.js +316 -0
  121. package/dist/lib/brain-signing.d.ts +103 -0
  122. package/dist/lib/brain-signing.js +256 -0
  123. package/dist/lib/brain.d.ts +198 -0
  124. package/dist/lib/brain.js +1057 -0
  125. package/dist/pop-agent.d.ts +1 -0
  126. package/dist/pop-agent.js +18 -0
  127. package/docs/agent.md +126 -0
  128. package/docs/agents/brain-anti-entropy.md +127 -0
  129. package/docs/agents/brain-cross-device-onboarding.md +210 -0
  130. package/docs/agents/brain-cross-machine-smoke.md +241 -0
  131. package/docs/agents/brain-layer-setup.md +725 -0
  132. package/docs/agents/offboarding-protocol.md +188 -0
  133. package/docs/agents/onboarding-protocol.md +243 -0
  134. package/docs/agents/running-an-agent.md +200 -0
  135. package/docs/brain.md +560 -0
  136. package/package.json +61 -0
  137. package/scripts/apply.sh +140 -0
  138. package/scripts/onboard.sh +205 -0
  139. package/scripts/setup-agent.ts +272 -0
@@ -0,0 +1,21 @@
1
+ import type { Argv, ArgumentsCamelCase } from 'yargs';
2
+ interface RegisterArgs {
3
+ name: string;
4
+ description?: string;
5
+ capabilities?: string;
6
+ chain?: number;
7
+ rpc?: string;
8
+ 'private-key'?: string;
9
+ 'dry-run'?: boolean;
10
+ }
11
+ export declare const registerHandler: {
12
+ builder: (yargs: Argv) => Argv<{
13
+ name: string;
14
+ } & {
15
+ description: string;
16
+ } & {
17
+ capabilities: string | undefined;
18
+ }>;
19
+ handler: (argv: ArgumentsCamelCase<RegisterArgs>) => Promise<void>;
20
+ };
21
+ export {};
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.registerHandler = void 0;
37
+ const ethers_1 = require("ethers");
38
+ const signer_1 = require("@poa-box/cli/lib/signer");
39
+ const ipfs_1 = require("@poa-box/cli/lib/ipfs");
40
+ const networks_1 = require("@poa-box/cli/config/networks");
41
+ const output = __importStar(require("@poa-box/cli/lib/output"));
42
+ // ERC-8004 Identity Registry — same address on all chains
43
+ const IDENTITY_REGISTRY = '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432';
44
+ const REGISTRY_ABI = [
45
+ 'function register(string agentURI) external returns (uint256)',
46
+ 'function balanceOf(address) view returns (uint256)',
47
+ ];
48
+ exports.registerHandler = {
49
+ builder: (yargs) => yargs
50
+ .option('name', { type: 'string', demandOption: true, describe: 'Agent name' })
51
+ .option('description', { type: 'string', default: '', describe: 'Agent description' })
52
+ .option('capabilities', { type: 'string', describe: 'Comma-separated capabilities (e.g. "governance,code-review,treasury")' }),
53
+ handler: async (argv) => {
54
+ const spin = output.spinner('Registering agent on ERC-8004...');
55
+ spin.start();
56
+ try {
57
+ const networkConfig = (0, networks_1.resolveNetworkConfig)(argv.chain);
58
+ const { signer } = (0, signer_1.createSigner)({ privateKey: argv.privateKey, chainId: argv.chain, rpcUrl: argv.rpc });
59
+ // Check if already registered
60
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(networkConfig.resolvedRpc);
61
+ const registry = new ethers_1.ethers.Contract(IDENTITY_REGISTRY, REGISTRY_ABI, provider);
62
+ const balance = await registry.balanceOf(signer.address);
63
+ if (balance.gt(0)) {
64
+ spin.stop();
65
+ output.info(`Already registered (${balance.toString()} identity NFT${balance.gt(1) ? 's' : ''})`);
66
+ return;
67
+ }
68
+ // Build registration file
69
+ const capabilities = argv.capabilities
70
+ ? argv.capabilities.split(',').map(s => s.trim())
71
+ : ['governance', 'task-completion'];
72
+ const regFile = {
73
+ name: argv.name,
74
+ description: argv.description || `AI agent operating on ${networkConfig.name}`,
75
+ services: [
76
+ { type: 'wallet', address: signer.address, chain: `eip155:${networkConfig.chainId}` },
77
+ ],
78
+ capabilities,
79
+ active: true,
80
+ registeredAt: new Date().toISOString(),
81
+ };
82
+ // Pin to IPFS
83
+ spin.text = 'Pinning registration file to IPFS...';
84
+ const cid = await (0, ipfs_1.pinJson)(JSON.stringify(regFile));
85
+ const uri = `https://ipfs.io/ipfs/${cid}`;
86
+ if (argv.dryRun) {
87
+ spin.stop();
88
+ output.success('Registration prepared (dry-run)', { uri, cid, address: signer.address });
89
+ return;
90
+ }
91
+ // Register on-chain
92
+ spin.text = 'Sending registration transaction...';
93
+ const registryWrite = new ethers_1.ethers.Contract(IDENTITY_REGISTRY, REGISTRY_ABI, signer);
94
+ const tx = await registryWrite.register(uri);
95
+ const receipt = await tx.wait();
96
+ // Extract agent ID from Transfer event
97
+ const transferLog = receipt.logs.find((l) => l.topics.length === 4);
98
+ const agentId = transferLog
99
+ ? ethers_1.ethers.BigNumber.from(transferLog.topics[3]).toString()
100
+ : 'unknown';
101
+ spin.stop();
102
+ output.success(`Agent registered as #${agentId}`, {
103
+ agentId,
104
+ txHash: receipt.transactionHash,
105
+ explorerUrl: `${networkConfig.blockExplorer}/tx/${receipt.transactionHash}`,
106
+ registrationUri: uri,
107
+ registry: IDENTITY_REGISTRY,
108
+ });
109
+ }
110
+ catch (err) {
111
+ spin.stop();
112
+ output.error(err.message);
113
+ process.exit(1);
114
+ }
115
+ },
116
+ };
@@ -0,0 +1,22 @@
1
+ import type { Argv, ArgumentsCamelCase } from 'yargs';
2
+ interface SetupSponsorshipArgs {
3
+ org: string;
4
+ 'hat-id': string;
5
+ 'org-id': string;
6
+ 'budget-per-day'?: number;
7
+ chain?: number;
8
+ rpc?: string;
9
+ 'private-key'?: string;
10
+ 'dry-run'?: boolean;
11
+ }
12
+ export declare const setupSponsorshipHandler: {
13
+ builder: (yargs: Argv) => Argv<{
14
+ "org-id": string;
15
+ } & {
16
+ "hat-id": string;
17
+ } & {
18
+ "budget-per-day": number;
19
+ }>;
20
+ handler: (argv: ArgumentsCamelCase<SetupSponsorshipArgs>) => Promise<void>;
21
+ };
22
+ export {};
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.setupSponsorshipHandler = void 0;
37
+ const viem_1 = require("viem");
38
+ const chains_1 = require("viem/chains");
39
+ const accounts_1 = require("viem/accounts");
40
+ const sponsored_1 = require("@poa-box/cli/lib/sponsored");
41
+ const output = __importStar(require("@poa-box/cli/lib/output"));
42
+ exports.setupSponsorshipHandler = {
43
+ builder: (yargs) => yargs
44
+ .option('org-id', { type: 'string', demandOption: true, describe: 'Org ID (bytes32 hex)' })
45
+ .option('hat-id', { type: 'string', demandOption: true, describe: 'Agent hat ID (decimal or hex)' })
46
+ .option('budget-per-day', { type: 'number', default: 0.1, describe: 'Gas budget per day in xDAI' }),
47
+ handler: async (argv) => {
48
+ const spin = output.spinner('Setting up gas sponsorship...');
49
+ spin.start();
50
+ try {
51
+ const privateKey = argv.privateKey || process.env.POP_PRIVATE_KEY;
52
+ if (!privateKey)
53
+ throw new Error('No private key. Set POP_PRIVATE_KEY or pass --private-key.');
54
+ const pk = (privateKey.startsWith('0x') ? privateKey : `0x${privateKey}`);
55
+ const account = (0, accounts_1.privateKeyToAccount)(pk);
56
+ const rpcUrl = argv.rpc || 'https://rpc.gnosischain.com';
57
+ const publicClient = (0, viem_1.createPublicClient)({ chain: chains_1.gnosis, transport: (0, viem_1.http)(rpcUrl) });
58
+ const walletClient = (0, viem_1.createWalletClient)({ account, chain: chains_1.gnosis, transport: (0, viem_1.http)(rpcUrl) });
59
+ const orgId = argv.orgId;
60
+ const hatId = BigInt(argv.hatId);
61
+ const subjectKey = (0, viem_1.pad)((0, viem_1.toHex)(hatId), { size: 32 });
62
+ const budgetWei = BigInt(Math.floor(argv.budgetPerDay * 1e18));
63
+ const pmAbi = require('../../abi/PaymasterHub.json');
64
+ const results = {};
65
+ // Step 1: Check and set up EIP-7702 delegation
66
+ spin.text = 'Step 1/3: Checking EIP-7702 delegation...';
67
+ const delegated = await (0, sponsored_1.isDelegated)(account.address);
68
+ if (delegated) {
69
+ results.delegation = 'already delegated';
70
+ }
71
+ else {
72
+ if (argv.dryRun) {
73
+ results.delegation = 'would delegate (dry-run)';
74
+ }
75
+ else {
76
+ const hash = await (0, sponsored_1.delegateEOA)(pk, rpcUrl);
77
+ await publicClient.waitForTransactionReceipt({ hash });
78
+ results.delegation = `delegated (tx: ${hash})`;
79
+ }
80
+ }
81
+ // Step 2: Check and set hat budget
82
+ spin.text = 'Step 2/3: Checking hat budget...';
83
+ const budget = await publicClient.readContract({
84
+ address: sponsored_1.PAYMASTER_HUB,
85
+ abi: pmAbi,
86
+ functionName: 'getBudget',
87
+ args: [orgId, subjectKey],
88
+ });
89
+ if (budget.capPerEpoch > 0n) {
90
+ results.budget = `already set (${(Number(budget.capPerEpoch) / 1e18).toFixed(4)} xDAI/epoch, ${budget.epochLen}s epoch)`;
91
+ }
92
+ else {
93
+ if (argv.dryRun) {
94
+ results.budget = `would set ${(Number(budgetWei) / 1e18).toFixed(4)} xDAI/day (dry-run)`;
95
+ }
96
+ else {
97
+ const hash = await walletClient.writeContract({
98
+ address: sponsored_1.PAYMASTER_HUB,
99
+ abi: pmAbi,
100
+ functionName: 'setBudget',
101
+ args: [orgId, subjectKey, budgetWei, 86400],
102
+ });
103
+ await publicClient.waitForTransactionReceipt({ hash });
104
+ results.budget = `set to ${(Number(budgetWei) / 1e18).toFixed(4)} xDAI/day (tx: ${hash})`;
105
+ }
106
+ }
107
+ // Step 3: Check and raise fee caps if needed
108
+ spin.text = 'Step 3/3: Checking fee caps...';
109
+ const caps = await publicClient.readContract({
110
+ address: sponsored_1.PAYMASTER_HUB,
111
+ abi: pmAbi,
112
+ functionName: 'getFeeCaps',
113
+ args: [orgId],
114
+ });
115
+ const needsRaise = caps.maxCallGas < 1000000 || caps.maxVerificationGas < 1000000 || caps.maxPreVerificationGas < 200000;
116
+ if (!needsRaise) {
117
+ results.feeCaps = `OK (callGas: ${caps.maxCallGas}, verGas: ${caps.maxVerificationGas}, preVerGas: ${caps.maxPreVerificationGas})`;
118
+ }
119
+ else {
120
+ const newCaps = {
121
+ maxFeePerGas: caps.maxFeePerGas > 50000000000n ? caps.maxFeePerGas : 50000000000n,
122
+ maxPriorityFeePerGas: caps.maxPriorityFeePerGas > 10000000000n ? caps.maxPriorityFeePerGas : 10000000000n,
123
+ maxCallGas: Math.max(caps.maxCallGas, 2000000),
124
+ maxVerificationGas: Math.max(caps.maxVerificationGas, 1500000),
125
+ maxPreVerificationGas: Math.max(caps.maxPreVerificationGas, 500000),
126
+ };
127
+ if (argv.dryRun) {
128
+ results.feeCaps = `would raise caps (dry-run)`;
129
+ }
130
+ else {
131
+ const hash = await walletClient.writeContract({
132
+ address: sponsored_1.PAYMASTER_HUB,
133
+ abi: pmAbi,
134
+ functionName: 'setFeeCaps',
135
+ args: [orgId, newCaps.maxFeePerGas, newCaps.maxPriorityFeePerGas, newCaps.maxCallGas, newCaps.maxVerificationGas, newCaps.maxPreVerificationGas],
136
+ });
137
+ await publicClient.waitForTransactionReceipt({ hash });
138
+ results.feeCaps = `raised (tx: ${hash})`;
139
+ }
140
+ }
141
+ spin.stop();
142
+ output.success('Gas sponsorship setup complete', {
143
+ agent: account.address,
144
+ ...results,
145
+ nextStep: 'Add POP_ORG_ID, POP_HAT_ID, and PIMLICO_API_KEY to .env',
146
+ });
147
+ }
148
+ catch (err) {
149
+ spin.stop();
150
+ output.error(err.message);
151
+ process.exit(1);
152
+ }
153
+ },
154
+ };
@@ -0,0 +1,12 @@
1
+ import type { Argv, ArgumentsCamelCase } from 'yargs';
2
+ interface StatusArgs {
3
+ org?: string;
4
+ chain?: number;
5
+ rpc?: string;
6
+ 'private-key'?: string;
7
+ }
8
+ export declare const agentStatusHandler: {
9
+ builder: (yargs: Argv) => Argv<{}>;
10
+ handler: (argv: ArgumentsCamelCase<StatusArgs>) => Promise<void>;
11
+ };
12
+ export {};
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.agentStatusHandler = void 0;
37
+ const ethers_1 = require("ethers");
38
+ const subgraph_1 = require("@poa-box/cli/lib/subgraph");
39
+ const resolve_1 = require("@poa-box/cli/lib/resolve");
40
+ const networks_1 = require("@poa-box/cli/config/networks");
41
+ const output = __importStar(require("@poa-box/cli/lib/output"));
42
+ const FETCH_AGENT_DATA = `
43
+ query FetchAgentData($orgId: Bytes!) {
44
+ organization(id: $orgId) {
45
+ name
46
+ participationToken { totalSupply }
47
+ users(first: 100) {
48
+ address
49
+ participationTokenBalance
50
+ membershipStatus
51
+ totalTasksCompleted
52
+ totalVotes
53
+ account { username }
54
+ }
55
+ hybridVoting {
56
+ proposals(where: { status: "Active" }, first: 50) {
57
+ proposalId
58
+ title
59
+ status
60
+ votes { voter }
61
+ }
62
+ }
63
+ taskManager {
64
+ projects(where: { deleted: false }, first: 100) {
65
+ tasks(first: 1000) {
66
+ id
67
+ status
68
+ assignee
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+ `;
75
+ exports.agentStatusHandler = {
76
+ builder: (yargs) => yargs,
77
+ handler: async (argv) => {
78
+ const spin = output.spinner('Fetching agent status...');
79
+ spin.start();
80
+ try {
81
+ // Get wallet address
82
+ const key = argv.privateKey || process.env.POP_PRIVATE_KEY;
83
+ if (!key)
84
+ throw new Error('No private key configured');
85
+ const wallet = new ethers_1.ethers.Wallet(key);
86
+ const myAddr = wallet.address.toLowerCase();
87
+ // Get gas balance
88
+ const networkConfig = (0, networks_1.resolveNetworkConfig)(argv.chain);
89
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(networkConfig.resolvedRpc);
90
+ const gasBalance = await provider.getBalance(wallet.address);
91
+ // Get org data
92
+ const modules = await (0, resolve_1.resolveOrgModules)(argv.org, argv.chain);
93
+ const result = await (0, subgraph_1.query)(FETCH_AGENT_DATA, { orgId: modules.orgId }, argv.chain);
94
+ const org = result.organization;
95
+ if (!org)
96
+ throw new Error('Organization not found');
97
+ // Find my user
98
+ const me = org.users.find((u) => u.address?.toLowerCase() === myAddr);
99
+ const totalSupply = ethers_1.ethers.BigNumber.from(org.participationToken?.totalSupply || '0');
100
+ const myPT = ethers_1.ethers.BigNumber.from(me?.participationTokenBalance || '0');
101
+ const sharePercent = totalSupply.gt(0) ? myPT.mul(10000).div(totalSupply).toNumber() / 100 : 0;
102
+ // Count active proposals I haven't voted on
103
+ const activeProposals = org.hybridVoting?.proposals || [];
104
+ const unvoted = activeProposals.filter((p) => !(p.votes || []).some((v) => v.voter?.toLowerCase() === myAddr));
105
+ // Count my tasks
106
+ const allTasks = (org.taskManager?.projects || []).flatMap((p) => p.tasks || []);
107
+ const myAssigned = allTasks.filter((t) => t.assignee?.toLowerCase() === myAddr && t.status === 'Assigned');
108
+ const mySubmitted = allTasks.filter((t) => t.assignee?.toLowerCase() === myAddr && t.status === 'Submitted');
109
+ const awaitingMyReview = allTasks.filter((t) => t.status === 'Submitted' && t.assignee?.toLowerCase() !== myAddr);
110
+ const data = {
111
+ wallet: wallet.address,
112
+ username: me?.account?.username || 'unregistered',
113
+ org: org.name,
114
+ gas: ethers_1.ethers.utils.formatEther(gasBalance),
115
+ gasCurrency: networkConfig.nativeCurrency.symbol,
116
+ pt: ethers_1.ethers.utils.formatEther(myPT),
117
+ ptShare: `${sharePercent.toFixed(1)}%`,
118
+ tasksCompleted: parseInt(me?.totalTasksCompleted || '0'),
119
+ votesCast: parseInt(me?.totalVotes || '0'),
120
+ memberStatus: me?.membershipStatus || 'Not a member',
121
+ unvotedProposals: unvoted.length,
122
+ myAssigned: myAssigned.length,
123
+ mySubmitted: mySubmitted.length,
124
+ awaitingMyReview: awaitingMyReview.length,
125
+ };
126
+ spin.stop();
127
+ if (output.isJsonMode()) {
128
+ output.json(data);
129
+ }
130
+ else {
131
+ console.log('');
132
+ console.log(` Agent Status — ${data.username}`);
133
+ console.log(' ─────────────────────────────');
134
+ console.log(` Wallet: ${data.wallet}`);
135
+ console.log(` Org: ${data.org}`);
136
+ console.log(` Status: ${data.memberStatus}`);
137
+ console.log(` Gas: ${data.gas} ${data.gasCurrency}`);
138
+ console.log('');
139
+ console.log(` PT: ${data.pt} (${data.ptShare} of supply)`);
140
+ console.log(` Tasks done: ${data.tasksCompleted}`);
141
+ console.log(` Votes cast: ${data.votesCast}`);
142
+ console.log('');
143
+ // Action items
144
+ const actions = [];
145
+ if (data.unvotedProposals > 0)
146
+ actions.push(`${data.unvotedProposals} proposal(s) need your vote`);
147
+ if (data.awaitingMyReview > 0)
148
+ actions.push(`${data.awaitingMyReview} task(s) await your review`);
149
+ if (data.myAssigned > 0)
150
+ actions.push(`${data.myAssigned} task(s) assigned to you`);
151
+ if (data.mySubmitted > 0)
152
+ actions.push(`${data.mySubmitted} task(s) submitted, awaiting review`);
153
+ if (parseFloat(data.gas) < 0.01)
154
+ actions.push('LOW GAS — fund wallet');
155
+ if (actions.length > 0) {
156
+ console.log(' Action items:');
157
+ actions.forEach(a => console.log(` - ${a}`));
158
+ }
159
+ else {
160
+ console.log(' No pending actions.');
161
+ }
162
+ console.log('');
163
+ }
164
+ }
165
+ catch (err) {
166
+ spin.stop();
167
+ output.error(err.message);
168
+ process.exit(1);
169
+ }
170
+ },
171
+ };
@@ -0,0 +1,12 @@
1
+ import type { Argv, ArgumentsCamelCase } from 'yargs';
2
+ interface TriageArgs {
3
+ org?: string;
4
+ chain?: number;
5
+ rpc?: string;
6
+ 'private-key'?: string;
7
+ }
8
+ export declare const triageHandler: {
9
+ builder: (yargs: Argv) => Argv<{}>;
10
+ handler: (argv: ArgumentsCamelCase<TriageArgs>) => Promise<void>;
11
+ };
12
+ export {};