@c4roa0/agentpay-user 0.0.0-stage → 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 (173) hide show
  1. package/AGENTS.md +137 -0
  2. package/CONTRIBUTING.md +16 -0
  3. package/LICENSE +373 -0
  4. package/NOTICE.md +20 -0
  5. package/README.md +84 -2
  6. package/SECURITY.md +16 -0
  7. package/doc/README.md +52 -0
  8. package/doc/TODO.md +97 -0
  9. package/doc/architecture.md +96 -0
  10. package/doc/design.md +60 -0
  11. package/doc/develope.md +68 -0
  12. package/doc/plans/user-wallet-distribution.md +91 -0
  13. package/doc/reference/harness-skill-runtime.md +120 -0
  14. package/doc/reference/local-cache-foundation.md +176 -0
  15. package/doc/reference/local-safe-owner-ui.md +25 -0
  16. package/doc/reference/local-update.md +18 -0
  17. package/doc/reference/multi-service-runtime.md +119 -0
  18. package/doc/reference/npm-integration-verification.md +67 -0
  19. package/doc/reference/onboarding-writing.md +48 -0
  20. package/doc/reference/original-order-recovery.md +97 -0
  21. package/doc/reference/private-anvil-onboarding-config.example.json +18 -0
  22. package/doc/reference/public-deployment-settings.md +56 -0
  23. package/doc/reference/random-skill-contract.md +18 -0
  24. package/doc/reference/result-file-cache.md +166 -0
  25. package/doc/reference/runtime-address-recovery.md +42 -0
  26. package/doc/reference/runtime-result-cache.md +157 -0
  27. package/doc/reference/runtime-startup-recovery.md +141 -0
  28. package/doc/reference/skill-input-output-cache.md +93 -0
  29. package/doc/reference/wallet-identity-policy-history.md +23 -0
  30. package/doc/runbooks/commands.md +89 -0
  31. package/doc/runbooks/deployment-authorization-update.md +42 -0
  32. package/doc/runbooks/emergency-payment-stop.md +80 -0
  33. package/doc/runbooks/local-autostart.md +212 -0
  34. package/doc/runbooks/local-cache.md +115 -0
  35. package/doc/runbooks/local-update.md +84 -0
  36. package/doc/runbooks/market-connection.md +73 -0
  37. package/doc/runbooks/npm-publication.md +56 -0
  38. package/doc/runbooks/official-test-package.md +62 -0
  39. package/doc/runbooks/order-cancellation.md +56 -0
  40. package/doc/runbooks/order-support.md +41 -0
  41. package/doc/runbooks/policy-renewal.md +80 -0
  42. package/doc/runbooks/private-anvil-terminal-setup.md +58 -0
  43. package/doc/runbooks/runtime-skill-client.md +155 -0
  44. package/doc/runbooks/safe-owner-web.md +104 -0
  45. package/doc/runbooks/safe-policy-migration.md +36 -0
  46. package/doc/runbooks/safe-policy-setup.md +52 -0
  47. package/doc/runbooks/terminal-authorization-preview.md +38 -0
  48. package/doc/runbooks/unlock-wallet.md +68 -0
  49. package/doc/runbooks/user-onboarding.md +87 -0
  50. package/doc/runbooks/wallet-identity.md +59 -0
  51. package/doc/security/public-source-review-2026-11-06.md +71 -0
  52. package/doc/usage.md +54 -0
  53. package/package.json +49 -4
  54. package/progress.md +178 -0
  55. package/run +29 -0
  56. package/scripts/agentpay-cli.mjs +11 -0
  57. package/scripts/authorize-existing-safe.mjs +211 -0
  58. package/scripts/autostart.mjs +186 -0
  59. package/scripts/cancel-order.mjs +76 -0
  60. package/scripts/check-installation.mjs +26 -0
  61. package/scripts/check-official-test-package.mjs +35 -0
  62. package/scripts/check-purchase-readiness.mjs +275 -0
  63. package/scripts/configure-runtime-client.mjs +16 -0
  64. package/scripts/guide-policy.mjs +64 -0
  65. package/scripts/initialize-caller-credential.mjs +11 -0
  66. package/scripts/install-skill-bundle.mjs +176 -0
  67. package/scripts/install-user.mjs +24 -0
  68. package/scripts/local-service.mjs +60 -0
  69. package/scripts/lock.mjs +11 -0
  70. package/scripts/login-notify.mjs +39 -0
  71. package/scripts/migrate-safe-policy.mjs +165 -0
  72. package/scripts/official-paid-test.mjs +9 -0
  73. package/scripts/poll-unconfirmed-notice.mjs +75 -0
  74. package/scripts/prepare-onboarding.mjs +33 -0
  75. package/scripts/preview-policy.mjs +65 -0
  76. package/scripts/random-model-ack-smoke.mjs +235 -0
  77. package/scripts/random-reject-smoke.mjs +147 -0
  78. package/scripts/renew.mjs +9 -0
  79. package/scripts/repair.mjs +10 -0
  80. package/scripts/revoke.mjs +9 -0
  81. package/scripts/select-skill-bundle.mjs +39 -0
  82. package/scripts/setup-local.mjs +199 -0
  83. package/scripts/status.mjs +13 -0
  84. package/scripts/test-package.mjs +35 -0
  85. package/scripts/unlock.mjs +13 -0
  86. package/scripts/update.mjs +7 -0
  87. package/scripts/user-setup.mjs +219 -0
  88. package/scripts/verify-npm-release.mjs +32 -0
  89. package/src/active-skill.mjs +160 -0
  90. package/src/anvil-onboarding-state.mjs +96 -0
  91. package/src/anvil-onboarding.mjs +1036 -0
  92. package/src/authorization-question-checkpoint.mjs +114 -0
  93. package/src/autostart-files.mjs +50 -0
  94. package/src/cache-management-cli.mjs +302 -0
  95. package/src/cache-management.mjs +47 -0
  96. package/src/caller-auth.mjs +58 -0
  97. package/src/client-request-lock.mjs +44 -0
  98. package/src/connect-market.mjs +408 -0
  99. package/src/demo-unlock-secret.mjs +64 -0
  100. package/src/deployment-status.mjs +198 -0
  101. package/src/file-cache-cli.mjs +83 -0
  102. package/src/file-cache-owner.mjs +74 -0
  103. package/src/file-cache-settings.mjs +50 -0
  104. package/src/file-cache.mjs +790 -0
  105. package/src/file-download.mjs +281 -0
  106. package/src/finalization-disclosure.mjs +16 -0
  107. package/src/guided-setup.mjs +194 -0
  108. package/src/index.mjs +1231 -0
  109. package/src/install-and-setup.mjs +38 -0
  110. package/src/install-preflight.mjs +201 -0
  111. package/src/install-user.mjs +279 -0
  112. package/src/installation-paths.mjs +31 -0
  113. package/src/invocation-result.mjs +148 -0
  114. package/src/invocation-store.mjs +385 -0
  115. package/src/local-data-directory.mjs +117 -0
  116. package/src/local-info.mjs +181 -0
  117. package/src/local-services.mjs +156 -0
  118. package/src/local-time.mjs +36 -0
  119. package/src/local-update.mjs +306 -0
  120. package/src/local-wallet-ipc.mjs +93 -0
  121. package/src/login-reminder.mjs +28 -0
  122. package/src/market-download-url.mjs +21 -0
  123. package/src/node-version.mjs +12 -0
  124. package/src/npm-update.mjs +126 -0
  125. package/src/official-paid-test.mjs +407 -0
  126. package/src/official-test-package.mjs +41 -0
  127. package/src/official-test-update.mjs +162 -0
  128. package/src/order-cancellation.mjs +241 -0
  129. package/src/order-closure.mjs +42 -0
  130. package/src/order-list-panel.mjs +110 -0
  131. package/src/order-review.mjs +424 -0
  132. package/src/order-status-panel.mjs +65 -0
  133. package/src/order-support.mjs +365 -0
  134. package/src/owner-approval-server.mjs +332 -0
  135. package/src/owner-signer.mjs +67 -0
  136. package/src/policy-info.mjs +38 -0
  137. package/src/policy-migration.mjs +84 -0
  138. package/src/policy-operations.mjs +67 -0
  139. package/src/policy-preview-server.mjs +236 -0
  140. package/src/policy-terminal-guide.mjs +377 -0
  141. package/src/prepare-local-services.mjs +143 -0
  142. package/src/prepare-onboarding.mjs +210 -0
  143. package/src/private-journal-files.mjs +29 -0
  144. package/src/readiness-profile.mjs +30 -0
  145. package/src/renew-policy.mjs +605 -0
  146. package/src/repair-market-wallet.mjs +137 -0
  147. package/src/restore-wallet.mjs +255 -0
  148. package/src/result-cache-view.mjs +276 -0
  149. package/src/runtime-client.mjs +1145 -0
  150. package/src/runtime-connection-settings.mjs +101 -0
  151. package/src/runtime-recovery.mjs +667 -0
  152. package/src/runtime-status.mjs +32 -0
  153. package/src/safe-owner-anvil.mjs +115 -0
  154. package/src/safe-policy-plan.mjs +195 -0
  155. package/src/service-reference.mjs +233 -0
  156. package/src/service-url.mjs +52 -0
  157. package/src/settlement-response.mjs +69 -0
  158. package/src/setup-autostart.mjs +197 -0
  159. package/src/setup-demo.mjs +152 -0
  160. package/src/skill-bundle.mjs +142 -0
  161. package/src/skill-client.mjs +198 -0
  162. package/src/skill-install-prompt.mjs +31 -0
  163. package/src/skill-package.mjs +50 -0
  164. package/src/skill-zip.mjs +220 -0
  165. package/src/status-panel.mjs +589 -0
  166. package/src/transport.mjs +48 -0
  167. package/src/uninstall-local.mjs +299 -0
  168. package/src/user-cli.mjs +354 -0
  169. package/src/user-setup-guide.mjs +193 -0
  170. package/src/wallet-control.mjs +182 -0
  171. package/src/wallet-ipc-error.mjs +16 -0
  172. package/src/wallet-package.mjs +22 -0
  173. package/update-pair.json +6 -0
@@ -0,0 +1,83 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
3
+ // If a copy was not distributed with this file, see https://mozilla.org/MPL/2.0/.
4
+ import { join } from "node:path";
5
+ import { createInterface } from "node:readline/promises";
6
+ import { resolveUserDataDir } from "./local-data-directory.mjs";
7
+ import {
8
+ loadRuntimeConnection,
9
+ listResultFiles,
10
+ removeResultFile,
11
+ } from "./runtime-client.mjs";
12
+ export async function runFileCache(
13
+ args,
14
+ {
15
+ write = console.log,
16
+ ask = async (message) => {
17
+ const r = createInterface({
18
+ input: process.stdin,
19
+ output: process.stdout,
20
+ });
21
+ try {
22
+ return await r.question(message + "\n> ");
23
+ } finally {
24
+ r.close();
25
+ }
26
+ },
27
+ } = {},
28
+ ) {
29
+ const dataDir = await resolveUserDataDir(),
30
+ state = join(dataDir, "runtime/invocations.json");
31
+ const [orderId, action = "list", key] = args;
32
+ if (
33
+ !/^0x[a-f0-9]{64}$/.test(orderId || "") ||
34
+ !["list", "remove"].includes(action) ||
35
+ (action === "list"
36
+ ? args.length > 3 || (key !== undefined && !/^[1-9][0-9]{0,5}$/.test(key))
37
+ : args.length !== 3)
38
+ ) {
39
+ write(
40
+ "Usage: agentpay orders files ORDER_ID [list PAGE]\n agentpay orders files ORDER_ID remove FILE_KEY\nUse the full Order ID from agentpay orders details ID.",
41
+ );
42
+ return 2;
43
+ }
44
+ const connection = await loadRuntimeConnection({ dataDir });
45
+ if (action === "remove") {
46
+ if (
47
+ (
48
+ await ask(
49
+ "Remove this local file copy? Order history and payment are unchanged.\nType confirm to remove, or q to return.",
50
+ )
51
+ ).trim() !== "confirm"
52
+ )
53
+ return 0;
54
+ await removeResultFile(connection, {
55
+ orderId,
56
+ fileKey: key,
57
+ confirmed: true,
58
+ });
59
+ write("Local file removed. Its history is kept.");
60
+ return 0;
61
+ }
62
+ const page = Number(key || 1),
63
+ rows = await listResultFiles(connection, orderId, {
64
+ offset: (page - 1) * 100,
65
+ });
66
+ write("\n> Saved result files\n");
67
+ if (!rows.length)
68
+ write(
69
+ "No file copies saved for this Order. A link in a result is not automatically downloaded.",
70
+ );
71
+ for (const row of rows) {
72
+ const safe = (v) => String(v || "").replace(/[\x00-\x1f\x7f-\x9f]/g, "");
73
+ write(
74
+ ` ${safe(row.fileKey)} · ${row.state} · ${row.bytes} bytes\n ${safe(row.filename)}${row.localPath ? "\n " + safe(row.localPath) : ""}${row.error ? "\n " + safe(row.error) : ""}`,
75
+ );
76
+ }
77
+ if (rows.length === 100)
78
+ write(`Next page: agentpay orders files ${orderId} list ${page + 1}`);
79
+ write(
80
+ "\nRuntime must be running; Wallet unlock is not required. File operations never make a payment.",
81
+ );
82
+ return 0;
83
+ }
@@ -0,0 +1,74 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
3
+ // If a copy was not distributed with this file, see https://mozilla.org/MPL/2.0/.
4
+ import { constants } from "node:fs";
5
+ import { realpath, open, lstat } from "node:fs/promises";
6
+ import { join } from "node:path";
7
+ import { fileError } from "./file-download.mjs";
8
+ const owners = new Map();
9
+ // Keep the descriptor open for this Runtime's lifetime. OS file locks release on
10
+ // exit, including a crash. The empty lock file remains: never unlink or replace it,
11
+ // since another process may already have opened that same file to acquire its lock.
12
+ export async function cacheOwner(directory) {
13
+ const canonical = await realpath(directory);
14
+ if (owners.has(canonical)) return owners.get(canonical);
15
+ const pending = (async () => {
16
+ let handle;
17
+ try {
18
+ // Load only when file caching is used. An unavailable native binding must not
19
+ // prevent Runtime startup, original Order checks or structured-result recovery.
20
+ let tryLock;
21
+ try {
22
+ ({ tryLock } = await import("fs-native-extensions"));
23
+ } catch {
24
+ throw fileError(
25
+ "FILE_CACHE_LOCK_UNAVAILABLE",
26
+ "File cache support is not installed for this system. Run npm ci in User, then restart Runtime.",
27
+ );
28
+ }
29
+ const path = join(canonical, "owner.lock");
30
+ handle = await open(
31
+ path,
32
+ constants.O_CREAT | constants.O_RDWR | (constants.O_NOFOLLOW || 0),
33
+ 0o600,
34
+ );
35
+ const stat = await handle.stat(),
36
+ entry = await lstat(path);
37
+ if (
38
+ !stat.isFile() ||
39
+ entry.isSymbolicLink() ||
40
+ stat.nlink !== 1 ||
41
+ stat.dev !== entry.dev ||
42
+ stat.ino !== entry.ino ||
43
+ (typeof process.getuid === "function" &&
44
+ (stat.uid !== process.getuid() || stat.mode & 0o077))
45
+ ) {
46
+ throw fileError(
47
+ "FILE_CACHE_UNSAFE",
48
+ "File cache lock ownership or permissions need review.",
49
+ );
50
+ }
51
+ if (!tryLock(handle.fd))
52
+ throw fileError(
53
+ "FILE_CACHE_IN_USE",
54
+ "Another Runtime owns this file cache. Stop that Runtime before retrying.",
55
+ );
56
+ // Retaining handle also prevents FileHandle garbage collection closing the lock.
57
+ return { handle, tail: Promise.resolve(), initialized: false };
58
+ } catch (error) {
59
+ await handle?.close();
60
+ if (error.code?.startsWith("FILE_")) throw error;
61
+ throw fileError(
62
+ "FILE_CACHE_LOCK_UNAVAILABLE",
63
+ "Could not lock this cache directory. Check local filesystem support and permissions before retrying.",
64
+ );
65
+ }
66
+ })();
67
+ owners.set(canonical, pending);
68
+ try {
69
+ return await pending;
70
+ } catch (error) {
71
+ owners.delete(canonical);
72
+ throw error;
73
+ }
74
+ }
@@ -0,0 +1,50 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
3
+ // If a copy was not distributed with this file, see https://mozilla.org/MPL/2.0/.
4
+ import { readPrivateJson } from "./order-review.mjs";
5
+ export const fileCacheLimits = Object.freeze({
6
+ singleBytes: 100 * 1048576,
7
+ totalBytes: 512 * 1048576,
8
+ filesPerResult: 20,
9
+ concurrent: 2,
10
+ records: 10000,
11
+ timeoutMs: 900000,
12
+ });
13
+ export function validateCacheLimits(input = {}) {
14
+ if (
15
+ !input ||
16
+ typeof input !== "object" ||
17
+ Array.isArray(input) ||
18
+ Object.keys(input).some((k) => !Object.hasOwn(fileCacheLimits, k))
19
+ )
20
+ throw Error("Invalid file cache settings.");
21
+ const limits = { ...fileCacheLimits, ...input };
22
+ for (const [key, value] of Object.entries(limits))
23
+ if (!Number.isSafeInteger(value) || value < 1)
24
+ throw Error(`File cache ${key} must be a positive integer.`);
25
+ if (
26
+ limits.singleBytes > limits.totalBytes ||
27
+ limits.totalBytes > 1024 ** 4 ||
28
+ limits.concurrent > 16 ||
29
+ limits.records > 100000 ||
30
+ limits.filesPerResult > limits.records ||
31
+ limits.timeoutMs > 86400000
32
+ )
33
+ throw Error("File cache settings exceed supported bounds.");
34
+ return limits;
35
+ }
36
+ export async function readCacheLimits(statePath) {
37
+ try {
38
+ return validateCacheLimits(
39
+ (await readPrivateJson(statePath + ".file-cache-settings.json", 16384)) ||
40
+ {},
41
+ );
42
+ } catch {
43
+ throw Object.assign(
44
+ Error(
45
+ "File cache settings could not be read. Check the private JSON file shown by agentpay cache settings.",
46
+ ),
47
+ { code: "FILE_SETTINGS_INVALID", status: 409 },
48
+ );
49
+ }
50
+ }