@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.
- package/AGENTS.md +137 -0
- package/CONTRIBUTING.md +16 -0
- package/LICENSE +373 -0
- package/NOTICE.md +20 -0
- package/README.md +84 -2
- package/SECURITY.md +16 -0
- package/doc/README.md +52 -0
- package/doc/TODO.md +97 -0
- package/doc/architecture.md +96 -0
- package/doc/design.md +60 -0
- package/doc/develope.md +68 -0
- package/doc/plans/user-wallet-distribution.md +91 -0
- package/doc/reference/harness-skill-runtime.md +120 -0
- package/doc/reference/local-cache-foundation.md +176 -0
- package/doc/reference/local-safe-owner-ui.md +25 -0
- package/doc/reference/local-update.md +18 -0
- package/doc/reference/multi-service-runtime.md +119 -0
- package/doc/reference/npm-integration-verification.md +67 -0
- package/doc/reference/onboarding-writing.md +48 -0
- package/doc/reference/original-order-recovery.md +97 -0
- package/doc/reference/private-anvil-onboarding-config.example.json +18 -0
- package/doc/reference/public-deployment-settings.md +56 -0
- package/doc/reference/random-skill-contract.md +18 -0
- package/doc/reference/result-file-cache.md +166 -0
- package/doc/reference/runtime-address-recovery.md +42 -0
- package/doc/reference/runtime-result-cache.md +157 -0
- package/doc/reference/runtime-startup-recovery.md +141 -0
- package/doc/reference/skill-input-output-cache.md +93 -0
- package/doc/reference/wallet-identity-policy-history.md +23 -0
- package/doc/runbooks/commands.md +89 -0
- package/doc/runbooks/deployment-authorization-update.md +42 -0
- package/doc/runbooks/emergency-payment-stop.md +80 -0
- package/doc/runbooks/local-autostart.md +212 -0
- package/doc/runbooks/local-cache.md +115 -0
- package/doc/runbooks/local-update.md +84 -0
- package/doc/runbooks/market-connection.md +73 -0
- package/doc/runbooks/npm-publication.md +56 -0
- package/doc/runbooks/official-test-package.md +62 -0
- package/doc/runbooks/order-cancellation.md +56 -0
- package/doc/runbooks/order-support.md +41 -0
- package/doc/runbooks/policy-renewal.md +80 -0
- package/doc/runbooks/private-anvil-terminal-setup.md +58 -0
- package/doc/runbooks/runtime-skill-client.md +155 -0
- package/doc/runbooks/safe-owner-web.md +104 -0
- package/doc/runbooks/safe-policy-migration.md +36 -0
- package/doc/runbooks/safe-policy-setup.md +52 -0
- package/doc/runbooks/terminal-authorization-preview.md +38 -0
- package/doc/runbooks/unlock-wallet.md +68 -0
- package/doc/runbooks/user-onboarding.md +87 -0
- package/doc/runbooks/wallet-identity.md +59 -0
- package/doc/security/public-source-review-2026-11-06.md +71 -0
- package/doc/usage.md +54 -0
- package/package.json +49 -4
- package/progress.md +178 -0
- package/run +29 -0
- package/scripts/agentpay-cli.mjs +11 -0
- package/scripts/authorize-existing-safe.mjs +211 -0
- package/scripts/autostart.mjs +186 -0
- package/scripts/cancel-order.mjs +76 -0
- package/scripts/check-installation.mjs +26 -0
- package/scripts/check-official-test-package.mjs +35 -0
- package/scripts/check-purchase-readiness.mjs +275 -0
- package/scripts/configure-runtime-client.mjs +16 -0
- package/scripts/guide-policy.mjs +64 -0
- package/scripts/initialize-caller-credential.mjs +11 -0
- package/scripts/install-skill-bundle.mjs +176 -0
- package/scripts/install-user.mjs +24 -0
- package/scripts/local-service.mjs +60 -0
- package/scripts/lock.mjs +11 -0
- package/scripts/login-notify.mjs +39 -0
- package/scripts/migrate-safe-policy.mjs +165 -0
- package/scripts/official-paid-test.mjs +9 -0
- package/scripts/poll-unconfirmed-notice.mjs +75 -0
- package/scripts/prepare-onboarding.mjs +33 -0
- package/scripts/preview-policy.mjs +65 -0
- package/scripts/random-model-ack-smoke.mjs +235 -0
- package/scripts/random-reject-smoke.mjs +147 -0
- package/scripts/renew.mjs +9 -0
- package/scripts/repair.mjs +10 -0
- package/scripts/revoke.mjs +9 -0
- package/scripts/select-skill-bundle.mjs +39 -0
- package/scripts/setup-local.mjs +199 -0
- package/scripts/status.mjs +13 -0
- package/scripts/test-package.mjs +35 -0
- package/scripts/unlock.mjs +13 -0
- package/scripts/update.mjs +7 -0
- package/scripts/user-setup.mjs +219 -0
- package/scripts/verify-npm-release.mjs +32 -0
- package/src/active-skill.mjs +160 -0
- package/src/anvil-onboarding-state.mjs +96 -0
- package/src/anvil-onboarding.mjs +1036 -0
- package/src/authorization-question-checkpoint.mjs +114 -0
- package/src/autostart-files.mjs +50 -0
- package/src/cache-management-cli.mjs +302 -0
- package/src/cache-management.mjs +47 -0
- package/src/caller-auth.mjs +58 -0
- package/src/client-request-lock.mjs +44 -0
- package/src/connect-market.mjs +408 -0
- package/src/demo-unlock-secret.mjs +64 -0
- package/src/deployment-status.mjs +198 -0
- package/src/file-cache-cli.mjs +83 -0
- package/src/file-cache-owner.mjs +74 -0
- package/src/file-cache-settings.mjs +50 -0
- package/src/file-cache.mjs +790 -0
- package/src/file-download.mjs +281 -0
- package/src/finalization-disclosure.mjs +16 -0
- package/src/guided-setup.mjs +194 -0
- package/src/index.mjs +1231 -0
- package/src/install-and-setup.mjs +38 -0
- package/src/install-preflight.mjs +201 -0
- package/src/install-user.mjs +279 -0
- package/src/installation-paths.mjs +31 -0
- package/src/invocation-result.mjs +148 -0
- package/src/invocation-store.mjs +385 -0
- package/src/local-data-directory.mjs +117 -0
- package/src/local-info.mjs +181 -0
- package/src/local-services.mjs +156 -0
- package/src/local-time.mjs +36 -0
- package/src/local-update.mjs +306 -0
- package/src/local-wallet-ipc.mjs +93 -0
- package/src/login-reminder.mjs +28 -0
- package/src/market-download-url.mjs +21 -0
- package/src/node-version.mjs +12 -0
- package/src/npm-update.mjs +126 -0
- package/src/official-paid-test.mjs +407 -0
- package/src/official-test-package.mjs +41 -0
- package/src/official-test-update.mjs +162 -0
- package/src/order-cancellation.mjs +241 -0
- package/src/order-closure.mjs +42 -0
- package/src/order-list-panel.mjs +110 -0
- package/src/order-review.mjs +424 -0
- package/src/order-status-panel.mjs +65 -0
- package/src/order-support.mjs +365 -0
- package/src/owner-approval-server.mjs +332 -0
- package/src/owner-signer.mjs +67 -0
- package/src/policy-info.mjs +38 -0
- package/src/policy-migration.mjs +84 -0
- package/src/policy-operations.mjs +67 -0
- package/src/policy-preview-server.mjs +236 -0
- package/src/policy-terminal-guide.mjs +377 -0
- package/src/prepare-local-services.mjs +143 -0
- package/src/prepare-onboarding.mjs +210 -0
- package/src/private-journal-files.mjs +29 -0
- package/src/readiness-profile.mjs +30 -0
- package/src/renew-policy.mjs +605 -0
- package/src/repair-market-wallet.mjs +137 -0
- package/src/restore-wallet.mjs +255 -0
- package/src/result-cache-view.mjs +276 -0
- package/src/runtime-client.mjs +1145 -0
- package/src/runtime-connection-settings.mjs +101 -0
- package/src/runtime-recovery.mjs +667 -0
- package/src/runtime-status.mjs +32 -0
- package/src/safe-owner-anvil.mjs +115 -0
- package/src/safe-policy-plan.mjs +195 -0
- package/src/service-reference.mjs +233 -0
- package/src/service-url.mjs +52 -0
- package/src/settlement-response.mjs +69 -0
- package/src/setup-autostart.mjs +197 -0
- package/src/setup-demo.mjs +152 -0
- package/src/skill-bundle.mjs +142 -0
- package/src/skill-client.mjs +198 -0
- package/src/skill-install-prompt.mjs +31 -0
- package/src/skill-package.mjs +50 -0
- package/src/skill-zip.mjs +220 -0
- package/src/status-panel.mjs +589 -0
- package/src/transport.mjs +48 -0
- package/src/uninstall-local.mjs +299 -0
- package/src/user-cli.mjs +354 -0
- package/src/user-setup-guide.mjs +193 -0
- package/src/wallet-control.mjs +182 -0
- package/src/wallet-ipc-error.mjs +16 -0
- package/src/wallet-package.mjs +22 -0
- package/update-pair.json +6 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { atomicWritePrivate } from "./private-journal-files.mjs";
|
|
2
|
+
import { isAbsolute } from "node:path";
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
5
|
+
// If a copy was not distributed with this file, see https://mozilla.org/MPL/2.0/.
|
|
6
|
+
// Reconstruct only the client locator from verified local service settings.
|
|
7
|
+
// Keys, caller credentials, authorization and request history are never changed.
|
|
8
|
+
import { constants } from "node:fs";
|
|
9
|
+
import { open, link, unlink } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
import { randomUUID } from "node:crypto";
|
|
13
|
+
import { readServiceSettings } from "./local-services.mjs";
|
|
14
|
+
|
|
15
|
+
export async function ensureRuntimeConnection({ dataDir, write = () => {}, refreshClientModule = false, checkOnly = false }) {
|
|
16
|
+
const settings = await readServiceSettings(dataDir);
|
|
17
|
+
const directory = join(dataDir, "runtime"),
|
|
18
|
+
path = join(directory, "connection.json");
|
|
19
|
+
const expected = {
|
|
20
|
+
version: "agentpay.runtime-connection.v1",
|
|
21
|
+
runtimeUrl: new URL(settings.runtimeUrl).href,
|
|
22
|
+
callerTokenFile: join(directory, "caller.token"),
|
|
23
|
+
clientModule: fileURLToPath(
|
|
24
|
+
new URL("./runtime-client.mjs", import.meta.url),
|
|
25
|
+
),
|
|
26
|
+
};
|
|
27
|
+
async function check() {
|
|
28
|
+
let h;
|
|
29
|
+
try {
|
|
30
|
+
h = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
31
|
+
const st = await h.stat();
|
|
32
|
+
if (
|
|
33
|
+
!st.isFile() ||
|
|
34
|
+
st.uid !== process.getuid() ||
|
|
35
|
+
st.mode & 0o077 ||
|
|
36
|
+
st.size > 16384
|
|
37
|
+
)
|
|
38
|
+
throw Error("unsafe");
|
|
39
|
+
const saved = JSON.parse(await h.readFile("utf8"));
|
|
40
|
+
if (
|
|
41
|
+
saved.version !== expected.version ||
|
|
42
|
+
new URL(saved.runtimeUrl).href !== expected.runtimeUrl ||
|
|
43
|
+
saved.callerTokenFile !== expected.callerTokenFile
|
|
44
|
+
)
|
|
45
|
+
throw Error("conflict");
|
|
46
|
+
if (saved.clientModule !== expected.clientModule) {
|
|
47
|
+
if (!refreshClientModule || typeof saved.clientModule !== 'string' || !isAbsolute(saved.clientModule) || !saved.clientModule.endsWith('/src/runtime-client.mjs')) throw Error('conflict');
|
|
48
|
+
// Explicit repair after stopping services can relocate trusted client code.
|
|
49
|
+
// URL, credential, request identities and authorization remain unchanged.
|
|
50
|
+
if (!checkOnly) {
|
|
51
|
+
await atomicWritePrivate(path, JSON.stringify(expected) + '\n');
|
|
52
|
+
write('Local Skill client path updated to this User installation.');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
if (e.code === "ENOENT") return false;
|
|
58
|
+
throw Error(
|
|
59
|
+
"The saved Runtime connection is invalid or conflicts with local service settings. It was kept for review: " +
|
|
60
|
+
path,
|
|
61
|
+
);
|
|
62
|
+
} finally {
|
|
63
|
+
await h?.close();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (await check()) return { created: false };
|
|
67
|
+
if (checkOnly) return { created: false, missing: true };
|
|
68
|
+
const temporary = path + "." + randomUUID() + ".tmp";
|
|
69
|
+
let h,
|
|
70
|
+
created = false;
|
|
71
|
+
try {
|
|
72
|
+
h = await open(temporary, "wx", 0o600);
|
|
73
|
+
await h.writeFile(JSON.stringify(expected) + "\n");
|
|
74
|
+
await h.sync();
|
|
75
|
+
await h.close();
|
|
76
|
+
h = null;
|
|
77
|
+
// Do not replace a connection published by another process during preparation.
|
|
78
|
+
try {
|
|
79
|
+
await link(temporary, path);
|
|
80
|
+
created = true;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
if (e.code !== "EEXIST") throw e;
|
|
83
|
+
if (!(await check()))
|
|
84
|
+
throw Error("Runtime connection changed during preparation. Retry.");
|
|
85
|
+
}
|
|
86
|
+
const d = await open(directory, constants.O_RDONLY | constants.O_DIRECTORY);
|
|
87
|
+
try {
|
|
88
|
+
await d.sync();
|
|
89
|
+
} finally {
|
|
90
|
+
await d.close();
|
|
91
|
+
}
|
|
92
|
+
} finally {
|
|
93
|
+
await h?.close();
|
|
94
|
+
await unlink(temporary).catch((e) => {
|
|
95
|
+
if (e.code !== "ENOENT") throw e;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (created)
|
|
99
|
+
write("Local Skill connection restored from your Runtime settings.");
|
|
100
|
+
return { created };
|
|
101
|
+
}
|