@asecret/cli 0.0.0-stage → 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.
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +72 -2
- package/bin/asecret-mcp.js +4 -0
- package/bin/asecret.js +12 -0
- package/core/spec/0.2/messages.schema.json +751 -0
- package/core/src/agent-crypto.js +191 -0
- package/core/src/agent.js +237 -0
- package/core/src/assistant-instructions.js +64 -0
- package/core/src/authorization.js +266 -0
- package/core/src/credentials.js +149 -0
- package/core/src/host-login.js +110 -0
- package/core/src/mcp-tools.js +130 -0
- package/core/src/wire.js +76 -0
- package/package.json +68 -4
- package/skill/SKILL.md +66 -0
- package/src/agents.js +140 -0
- package/src/api.js +188 -0
- package/src/commands.js +864 -0
- package/src/config.js +76 -0
- package/src/core.d.ts +55 -0
- package/src/core.js +19 -0
- package/src/errors.js +11 -0
- package/src/main.js +520 -0
- package/src/mcp.js +107 -0
- package/src/output.js +93 -0
- package/src/server.js +242 -0
- package/src/storage.js +137 -0
package/src/config.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Where this machine keeps the agent token aSecret issued on connect.
|
|
2
|
+
// One entry per API, so a local development API never borrows the real token.
|
|
3
|
+
|
|
4
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A setting from the environment, always named `ASECRET_<NAME>`. Empty when unset.
|
|
9
|
+
* @param {NodeJS.ProcessEnv} env
|
|
10
|
+
* @param {string} name
|
|
11
|
+
*/
|
|
12
|
+
export function setting(env, name) {
|
|
13
|
+
return env[`ASECRET_${name}`]?.trim() || "";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* `server` holds the linked server's origin.
|
|
18
|
+
* @typedef {{ agent_id: string, token: string, connected_at: string, keys?: { agent: string }, server?: string }} Credentials
|
|
19
|
+
* @param {NodeJS.ProcessEnv} env
|
|
20
|
+
* @param {string} home
|
|
21
|
+
*/
|
|
22
|
+
export function configDir(env, home) {
|
|
23
|
+
const chosen = setting(env, "CONFIG_DIR");
|
|
24
|
+
if (chosen) return chosen;
|
|
25
|
+
if (process.platform === "win32" && env.APPDATA?.trim()) return join(env.APPDATA.trim(), "asecret");
|
|
26
|
+
return join(env.XDG_CONFIG_HOME?.trim() || join(home, ".config"), "asecret");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @param {NodeJS.ProcessEnv} env @param {string} home */
|
|
30
|
+
export function credentialsFile(env, home) {
|
|
31
|
+
return join(configDir(env, home), "credentials.json");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @param {string} file @returns {Promise<Record<string, Credentials>>} */
|
|
35
|
+
async function readAll(file) {
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(await readFile(file, "utf8"));
|
|
38
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (/** @type {NodeJS.ErrnoException} */ (error).code === "ENOENT") return {};
|
|
41
|
+
throw new Error(`Could not read ${file}. Fix or delete it, then try again.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @param {string} file @param {Record<string, Credentials>} all */
|
|
46
|
+
async function writeAll(file, all) {
|
|
47
|
+
const dir = join(file, "..");
|
|
48
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
49
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
50
|
+
await writeFile(temporary, `${JSON.stringify(all, null, 2)}\n`, { mode: 0o600 });
|
|
51
|
+
await rename(temporary, file);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @param {string} file @param {string} api @returns {Promise<Credentials | null>} */
|
|
55
|
+
export async function loadCredentials(file, api) {
|
|
56
|
+
const entry = (await readAll(file))[api];
|
|
57
|
+
if (!entry?.token) return null;
|
|
58
|
+
return entry;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @param {string} file @param {string} api @param {Credentials} credentials */
|
|
62
|
+
export async function saveCredentials(file, api, credentials) {
|
|
63
|
+
const all = await readAll(file);
|
|
64
|
+
all[api] = credentials;
|
|
65
|
+
await writeAll(file, all);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** @param {string} file @param {string} api */
|
|
69
|
+
export async function forgetCredentials(file, api) {
|
|
70
|
+
const all = await readAll(file);
|
|
71
|
+
if (!all[api]) return false;
|
|
72
|
+
delete all[api];
|
|
73
|
+
if (Object.keys(all).length) await writeAll(file, all);
|
|
74
|
+
else await rm(file, { force: true });
|
|
75
|
+
return true;
|
|
76
|
+
}
|
package/src/core.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Types for the aSecret modules the CLI reaches through core.js. Those modules are plain
|
|
2
|
+
// JavaScript checked by aSecret's own tests, so the CLI's type check stops at this boundary.
|
|
3
|
+
|
|
4
|
+
export function toBase64url(bytes: Uint8Array): string;
|
|
5
|
+
export function fromBase64url(text: string): Uint8Array;
|
|
6
|
+
export function newKey(): string;
|
|
7
|
+
export function sha256Hex(bytes: Uint8Array): Promise<string>;
|
|
8
|
+
export function newReceiveKeys(): Promise<{ public: string; private: string }>;
|
|
9
|
+
export function sealToReceiveKey(publicKey: string, bytes: Uint8Array): Promise<string>;
|
|
10
|
+
export function wrapItemKey(agentKey: string, itemKey: Uint8Array): Promise<string>;
|
|
11
|
+
export function itemKeyOf(item: { wrap: string; wrapped_key: string }, keys: { agentKey?: string; receivePrivate?: string; receivePublic?: string }): Promise<Uint8Array>;
|
|
12
|
+
export function sealMeta(itemKey: Uint8Array, meta: unknown): Promise<string>;
|
|
13
|
+
export function openMeta(itemKey: Uint8Array, sealedMeta: string): Promise<any>;
|
|
14
|
+
export function sealContent(itemKey: Uint8Array, bytes: Uint8Array): Promise<Uint8Array>;
|
|
15
|
+
export function openContent(itemKey: Uint8Array, sealedBytes: Uint8Array): Promise<Uint8Array>;
|
|
16
|
+
export function sealItem(agentKey: string, meta: unknown, bytes: Uint8Array): Promise<{ itemKey: Uint8Array; wrap: "agent"; wrapped_key: string; meta: string; content: Uint8Array }>;
|
|
17
|
+
export const ITEM_TYPE: string;
|
|
18
|
+
export function frameItem(fields: Record<string, unknown>, content: Uint8Array): Uint8Array;
|
|
19
|
+
export function unframeItem(bytes: Uint8Array): { fields: any; content: Uint8Array };
|
|
20
|
+
|
|
21
|
+
export class ServerError extends Error {
|
|
22
|
+
status: number;
|
|
23
|
+
code: string;
|
|
24
|
+
}
|
|
25
|
+
type Lookup = { fetcher?: typeof fetch };
|
|
26
|
+
export function discover(origin: string, options?: Lookup): Promise<any>;
|
|
27
|
+
export function getPublicDirectory(origin: string, options?: Lookup): Promise<any>;
|
|
28
|
+
export function privateSaveLink(origin: string, detailType: string, options?: Lookup): Promise<string>;
|
|
29
|
+
export function privateWebsiteFormLink(origin: string, options?: Lookup): Promise<{ private_form_url: string }>;
|
|
30
|
+
export function privateOwnerSetupLink(origin: string, options?: Lookup): Promise<{ owner_setup_url: string }>;
|
|
31
|
+
export function assistantInstructions(origin?: string, options?: Lookup): Promise<string>;
|
|
32
|
+
type Expected = { operation: string; orderId?: string } | undefined;
|
|
33
|
+
export interface Server {
|
|
34
|
+
requestSetup(options: { idempotencyKey?: string }): Promise<any>;
|
|
35
|
+
requestSave(options: { detailType: string; idempotencyKey?: string }): Promise<any>;
|
|
36
|
+
requestOrderStatus(options: { recipient: string; orderId: string; idempotencyKey?: string }): Promise<any>;
|
|
37
|
+
requestAddress(options: { recipient: string; orderId: string; reference?: string; idempotencyKey?: string }): Promise<any>;
|
|
38
|
+
status(id: string, expected?: Expected): Promise<any>;
|
|
39
|
+
cancel(id: string, expected?: Expected): Promise<any>;
|
|
40
|
+
disconnect(id: string): Promise<{ state: "disconnected" }>;
|
|
41
|
+
}
|
|
42
|
+
export function connectServer(origin: string, options: { accessToken: string; fetcher?: typeof fetch }): Promise<Server>;
|
|
43
|
+
|
|
44
|
+
export function validateAgentName(name: string): string;
|
|
45
|
+
export function loopbackCallback(address: string): URL;
|
|
46
|
+
export function login(
|
|
47
|
+
origin: string,
|
|
48
|
+
options: { name?: string; file?: string; clientId?: string; redirectUri?: string; showURL: (url: string) => void; fetcher?: typeof fetch; timeout?: number },
|
|
49
|
+
): Promise<any>;
|
|
50
|
+
export function readCredential(file: string, origin: string): Promise<any>;
|
|
51
|
+
export function saveCredential(file: string, grant: any, previous?: any): Promise<void>;
|
|
52
|
+
export function usableCredential(file: string, origin: string, options?: any): Promise<any>;
|
|
53
|
+
export function clearDisconnectedCredential(file: string, session: any, options?: { requireSameToken?: boolean }): Promise<boolean>;
|
|
54
|
+
export function registerServerTools(mcp: any, use: (action: (server: Server) => Promise<any>) => Promise<any>, options?: Record<string, unknown>): void;
|
|
55
|
+
export const detailTypes: readonly string[];
|
package/src/core.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// The parts of aSecret this CLI shares with the SDK, the MCP adapter and the server's pages.
|
|
2
|
+
// They live in cli/core, copied from aSecret's own server, so cli/ stands on its own.
|
|
3
|
+
|
|
4
|
+
export * from "../core/src/agent-crypto.js";
|
|
5
|
+
export {
|
|
6
|
+
ServerError,
|
|
7
|
+
assistantInstructions,
|
|
8
|
+
connectServer,
|
|
9
|
+
discover,
|
|
10
|
+
getPublicDirectory,
|
|
11
|
+
privateOwnerSetupLink,
|
|
12
|
+
privateSaveLink,
|
|
13
|
+
privateWebsiteFormLink,
|
|
14
|
+
} from "../core/src/agent.js";
|
|
15
|
+
export { validateAgentName } from "../core/src/authorization.js";
|
|
16
|
+
export { login, loopbackCallback } from "../core/src/host-login.js";
|
|
17
|
+
export { clearDisconnectedCredential, readCredential, saveCredential, usableCredential } from "../core/src/credentials.js";
|
|
18
|
+
export { registerServerTools } from "../core/src/mcp-tools.js";
|
|
19
|
+
export { detailTypes } from "../core/src/wire.js";
|
package/src/errors.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Mistakes and refusals every part of the CLI can raise.
|
|
2
|
+
|
|
3
|
+
/** A mistake in how a command was typed. */
|
|
4
|
+
export class UsageError extends Error {}
|
|
5
|
+
|
|
6
|
+
/** This agent has no link to a person's aSecret server yet, or the link has ended. */
|
|
7
|
+
export class NotLinked extends Error {
|
|
8
|
+
constructor(message = "This agent is not linked to a person's aSecret server yet.") {
|
|
9
|
+
super(message);
|
|
10
|
+
}
|
|
11
|
+
}
|