implto-tos-axi 0.1.1

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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +255 -0
  3. package/dist/bin/implto-tos-axi.d.ts +2 -0
  4. package/dist/bin/implto-tos-axi.js +16 -0
  5. package/dist/bin/implto-tos-axi.js.map +1 -0
  6. package/dist/src/auth/loopback.d.ts +29 -0
  7. package/dist/src/auth/loopback.js +110 -0
  8. package/dist/src/auth/loopback.js.map +1 -0
  9. package/dist/src/auth/open-browser.d.ts +9 -0
  10. package/dist/src/auth/open-browser.js +24 -0
  11. package/dist/src/auth/open-browser.js.map +1 -0
  12. package/dist/src/auth/provider.d.ts +39 -0
  13. package/dist/src/auth/provider.js +106 -0
  14. package/dist/src/auth/provider.js.map +1 -0
  15. package/dist/src/cli.d.ts +2 -0
  16. package/dist/src/cli.js +183 -0
  17. package/dist/src/cli.js.map +1 -0
  18. package/dist/src/commands/components.d.ts +40 -0
  19. package/dist/src/commands/components.js +417 -0
  20. package/dist/src/commands/components.js.map +1 -0
  21. package/dist/src/commands/context.d.ts +10 -0
  22. package/dist/src/commands/context.js +46 -0
  23. package/dist/src/commands/context.js.map +1 -0
  24. package/dist/src/commands/guide.d.ts +16 -0
  25. package/dist/src/commands/guide.js +203 -0
  26. package/dist/src/commands/guide.js.map +1 -0
  27. package/dist/src/commands/home.d.ts +9 -0
  28. package/dist/src/commands/home.js +33 -0
  29. package/dist/src/commands/home.js.map +1 -0
  30. package/dist/src/commands/init.d.ts +12 -0
  31. package/dist/src/commands/init.js +65 -0
  32. package/dist/src/commands/init.js.map +1 -0
  33. package/dist/src/commands/login.d.ts +13 -0
  34. package/dist/src/commands/login.js +137 -0
  35. package/dist/src/commands/login.js.map +1 -0
  36. package/dist/src/commands/tasks.d.ts +8 -0
  37. package/dist/src/commands/tasks.js +344 -0
  38. package/dist/src/commands/tasks.js.map +1 -0
  39. package/dist/src/commands/tools.d.ts +66 -0
  40. package/dist/src/commands/tools.js +401 -0
  41. package/dist/src/commands/tools.js.map +1 -0
  42. package/dist/src/commands/whoami.d.ts +5 -0
  43. package/dist/src/commands/whoami.js +66 -0
  44. package/dist/src/commands/whoami.js.map +1 -0
  45. package/dist/src/config/binding.d.ts +29 -0
  46. package/dist/src/config/binding.js +42 -0
  47. package/dist/src/config/binding.js.map +1 -0
  48. package/dist/src/config/credentials.d.ts +39 -0
  49. package/dist/src/config/credentials.js +62 -0
  50. package/dist/src/config/credentials.js.map +1 -0
  51. package/dist/src/config/profiles.d.ts +24 -0
  52. package/dist/src/config/profiles.js +64 -0
  53. package/dist/src/config/profiles.js.map +1 -0
  54. package/dist/src/errors.d.ts +21 -0
  55. package/dist/src/errors.js +40 -0
  56. package/dist/src/errors.js.map +1 -0
  57. package/dist/src/flags.d.ts +50 -0
  58. package/dist/src/flags.js +143 -0
  59. package/dist/src/flags.js.map +1 -0
  60. package/dist/src/index.d.ts +6 -0
  61. package/dist/src/index.js +7 -0
  62. package/dist/src/index.js.map +1 -0
  63. package/dist/src/mcp/client.d.ts +85 -0
  64. package/dist/src/mcp/client.js +130 -0
  65. package/dist/src/mcp/client.js.map +1 -0
  66. package/dist/src/output.d.ts +8 -0
  67. package/dist/src/output.js +2 -0
  68. package/dist/src/output.js.map +1 -0
  69. package/dist/src/resolve.d.ts +16 -0
  70. package/dist/src/resolve.js +48 -0
  71. package/dist/src/resolve.js.map +1 -0
  72. package/dist/src/scopes.d.ts +9 -0
  73. package/dist/src/scopes.js +16 -0
  74. package/dist/src/scopes.js.map +1 -0
  75. package/dist/src/session.d.ts +40 -0
  76. package/dist/src/session.js +75 -0
  77. package/dist/src/session.js.map +1 -0
  78. package/dist/src/skill.d.ts +32 -0
  79. package/dist/src/skill.js +149 -0
  80. package/dist/src/skill.js.map +1 -0
  81. package/dist/src/version.d.ts +5 -0
  82. package/dist/src/version.js +6 -0
  83. package/dist/src/version.js.map +1 -0
  84. package/package.json +70 -0
  85. package/skills/implto-tos-delivery/SKILL.md +45 -0
  86. package/skills/implto-tos-tasks/SKILL.md +48 -0
  87. package/skills/implto-tos-workspace/SKILL.md +45 -0
@@ -0,0 +1,62 @@
1
+ import { chmodSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { homedir, platform } from "node:os";
3
+ import { dirname, join } from "node:path";
4
+ export function credentialsPath() {
5
+ if (platform() === "win32") {
6
+ const appData = process.env["APPDATA"] ?? join(homedir(), "AppData", "Roaming");
7
+ return join(appData, "implto-tos-axi", "credentials.json");
8
+ }
9
+ const base = process.env["XDG_CONFIG_HOME"] ?? join(homedir(), ".config");
10
+ return join(base, "implto-tos-axi", "credentials.json");
11
+ }
12
+ function readFile() {
13
+ try {
14
+ const parsed = JSON.parse(readFileSync(credentialsPath(), "utf8"));
15
+ if (parsed && typeof parsed === "object" && parsed.profiles)
16
+ return parsed;
17
+ }
18
+ catch {
19
+ // A missing or unreadable file is "not signed in", which every caller
20
+ // already handles. Failing here would make a corrupt file unrecoverable
21
+ // without knowing the path.
22
+ }
23
+ return { version: 1, profiles: {} };
24
+ }
25
+ function writeFile(file) {
26
+ const path = credentialsPath();
27
+ const dir = dirname(path);
28
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
29
+ writeFileSync(path, `${JSON.stringify(file, null, 2)}\n`, { mode: 0o600 });
30
+ if (platform() !== "win32") {
31
+ // mkdirSync's mode is masked by umask, so it is set again explicitly.
32
+ try {
33
+ chmodSync(dir, 0o700);
34
+ chmodSync(path, 0o600);
35
+ }
36
+ catch {
37
+ // A filesystem without POSIX modes is not a reason to refuse to work.
38
+ }
39
+ }
40
+ }
41
+ export function readCredential(profile) {
42
+ return readFile().profiles[profile] ?? null;
43
+ }
44
+ export function writeCredential(profile, credential) {
45
+ const file = readFile();
46
+ file.profiles[profile] = credential;
47
+ writeFile(file);
48
+ }
49
+ export function clearCredential(profile) {
50
+ const file = readFile();
51
+ if (!file.profiles[profile])
52
+ return false;
53
+ delete file.profiles[profile];
54
+ writeFile(file);
55
+ return true;
56
+ }
57
+ /** A token from the environment, which outranks anything on disk. */
58
+ export function envToken() {
59
+ const token = process.env["TOS_TOKEN"]?.trim();
60
+ return token ? token : null;
61
+ }
62
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../../src/config/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAuC1C,MAAM,UAAU,eAAe;IAC7B,IAAI,QAAQ,EAAE,KAAK,OAAO,EAAE,CAAC;QAC3B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;QAChF,OAAO,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;IAC7D,CAAC;IACD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC,IAAI,EAAE,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,QAAQ;IACf,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,eAAe,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;QACnE,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ;YAAE,OAAO,MAAwB,CAAC;IAC/F,CAAC;IAAC,MAAM,CAAC;QACP,sEAA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O,KAAK,CAAC;IAC1C,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9B,SAAS,CAAC,IAAI,CAAC,CAAC;IAChB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,QAAQ;IACtB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,CAAC;IAC/C,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Where a deployment lives.
3
+ *
4
+ * One origin per profile, and every other address is derived from it - the MCP
5
+ * endpoint, the OAuth documents, the consent page. That is not a convenience:
6
+ * the origin *is* the OAuth issuer and the `resource` a token is minted for, so
7
+ * a client that talks to one address and authorizes against another has a
8
+ * credential that is valid for somebody else's server.
9
+ *
10
+ * The MCP path is the Hosting rewrite rather than the Cloud Run hostname behind
11
+ * it, for the same reason.
12
+ */
13
+ export interface Profile {
14
+ readonly name: string;
15
+ readonly origin: string;
16
+ readonly mcpUrl: string;
17
+ }
18
+ export declare const PROFILE_NAMES: string[];
19
+ export declare const DEFAULT_PROFILE = "prod";
20
+ export declare function resolveProfile(input?: {
21
+ profile?: string | undefined;
22
+ url?: string | undefined;
23
+ mcpUrl?: string | undefined;
24
+ }): Profile;
@@ -0,0 +1,64 @@
1
+ import { TosError } from "../errors.js";
2
+ const MCP_PATH = "/mcp/transformation-os";
3
+ const ORIGINS = {
4
+ prod: "https://implto-transformation-os.web.app",
5
+ dev: "https://digital-transformation-os-dev.web.app",
6
+ local: "http://localhost:4000",
7
+ };
8
+ export const PROFILE_NAMES = Object.keys(ORIGINS);
9
+ export const DEFAULT_PROFILE = "prod";
10
+ /**
11
+ * The headless equivalents of `--url` and `--mcp-url`.
12
+ *
13
+ * `TOS_TOKEN` alone is not enough for a machine pointed at anything but prod:
14
+ * without these it would have to repeat the address on every invocation, and
15
+ * the address is a property of the environment, not of the call. Flags still
16
+ * win, so a deliberate `--profile dev` is never overridden by a stale export.
17
+ */
18
+ const envUrl = () => process.env["TOS_URL"]?.trim() || undefined;
19
+ const envMcpUrl = () => process.env["TOS_MCP_URL"]?.trim() || undefined;
20
+ export function resolveProfile(input) {
21
+ const url = input?.url ?? envUrl();
22
+ const mcpUrl = input?.mcpUrl ?? envMcpUrl();
23
+ const configured = input?.profile ? ORIGINS[input.profile] : undefined;
24
+ if (input?.profile && !configured && !url) {
25
+ throw new TosError(`Unknown profile "${input.profile}".`, "VALIDATION_ERROR", [
26
+ `Profiles: ${PROFILE_NAMES.join(", ")}`,
27
+ `Or point at a deployment directly: --url https://…`,
28
+ ]);
29
+ }
30
+ const origin = normalizeOrigin(url ?? configured ?? ORIGINS[DEFAULT_PROFILE] ?? "");
31
+ return {
32
+ // An address given without a profile is still named after the deployment
33
+ // it turns out to be, because the name is the key a credential is stored
34
+ // under: calling dev "prod" filed a dev token where the prod one belongs.
35
+ name: input?.profile ?? nameOf(origin),
36
+ origin,
37
+ // `--mcp-url` exists for the local case, where the MCP server runs as its
38
+ // own process on another port instead of behind the Hosting rewrite.
39
+ mcpUrl: mcpUrl ?? `${origin}${MCP_PATH}`,
40
+ };
41
+ }
42
+ /** The profile an origin belongs to, or its host when it is not one of ours. */
43
+ function nameOf(origin) {
44
+ const known = Object.entries(ORIGINS).find(([, o]) => normalizeOrigin(o) === origin);
45
+ if (known)
46
+ return known[0];
47
+ try {
48
+ return new URL(origin).host;
49
+ }
50
+ catch {
51
+ return DEFAULT_PROFILE;
52
+ }
53
+ }
54
+ function normalizeOrigin(raw) {
55
+ try {
56
+ return new URL(raw).origin;
57
+ }
58
+ catch {
59
+ throw new TosError(`"${raw}" is not a URL.`, "VALIDATION_ERROR", [
60
+ "Pass an origin, e.g. --url https://transformation.example",
61
+ ]);
62
+ }
63
+ }
64
+ //# sourceMappingURL=profiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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CAAC,GAAG,IAAI,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC;IACpF,OAAO;QACL,yEAAyE;QACzE,yEAAyE;QACzE,0EAA0E;QAC1E,IAAI,EAAE,KAAK,EAAE,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC;QACtC,MAAM;QACN,0EAA0E;QAC1E,qEAAqE;QACrE,MAAM,EAAE,MAAM,IAAI,GAAG,MAAM,GAAG,QAAQ,EAAE;KACzC,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,SAAS,MAAM,CAAC,MAAc;IAC5B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;IACrF,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC,CAAC,CAAW,CAAC;IACrC,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,eAAe,CAAC;IACzB,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,GAAW;IAClC,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,QAAQ,CAAC,IAAI,GAAG,iBAAiB,EAAE,kBAAkB,EAAE;YAC/D,2DAA2D;SAC5D,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The CLI's own error type. Zero dependencies, on purpose: `axi-sdk-js` is
3
+ * ESM-only with an import-only export map, so it stays behind the CLI boundary
4
+ * and everything else throws this. `cli.ts` converts it on the way out, and the
5
+ * structure matches what the SDK renders - a message, a machine-readable code
6
+ * and actionable suggestions - so nothing is lost.
7
+ *
8
+ * Every error names the fix. An agent that cannot see what to do next will
9
+ * either guess or give up, and both are worse than a sentence.
10
+ */
11
+ export declare class TosError extends Error {
12
+ readonly code: string;
13
+ readonly suggestions: string[];
14
+ constructor(message: string, code: string, suggestions?: string[]);
15
+ }
16
+ export declare function isTosError(value: unknown): value is TosError;
17
+ export declare const notSignedIn: (profile: string) => TosError;
18
+ export declare const credentialRejected: (profile: string) => TosError;
19
+ export declare const noBinding: () => TosError;
20
+ export declare const noWorkspace: () => TosError;
21
+ export declare const ambiguous: (what: string, candidates: string[]) => TosError;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The CLI's own error type. Zero dependencies, on purpose: `axi-sdk-js` is
3
+ * ESM-only with an import-only export map, so it stays behind the CLI boundary
4
+ * and everything else throws this. `cli.ts` converts it on the way out, and the
5
+ * structure matches what the SDK renders - a message, a machine-readable code
6
+ * and actionable suggestions - so nothing is lost.
7
+ *
8
+ * Every error names the fix. An agent that cannot see what to do next will
9
+ * either guess or give up, and both are worse than a sentence.
10
+ */
11
+ export class TosError extends Error {
12
+ code;
13
+ suggestions;
14
+ constructor(message, code, suggestions = []) {
15
+ super(message);
16
+ this.name = "TosError";
17
+ this.code = code;
18
+ this.suggestions = suggestions;
19
+ }
20
+ }
21
+ export function isTosError(value) {
22
+ return value instanceof TosError;
23
+ }
24
+ export const notSignedIn = (profile) => new TosError(`No credential for the "${profile}" profile.`, "AUTH_MISSING", [
25
+ `implto-tos-axi login --profile ${profile}`,
26
+ `Or set TOS_TOKEN to a personal key from Settings, Personal credentials.`,
27
+ ]);
28
+ export const credentialRejected = (profile) => new TosError(`The credential for "${profile}" was refused. It may have been revoked, or it may have expired.`, "AUTH_INVALID", [`implto-tos-axi login --profile ${profile}`]);
29
+ export const noBinding = () => new TosError("This directory is not bound to a Transformation OS project.", "NO_BINDING", [
30
+ "implto-tos-axi init --workspace <name> --project <key>",
31
+ "implto-tos-axi init # run it bare to list what you can reach",
32
+ ]);
33
+ export const noWorkspace = () => new TosError("No workspace: this directory is not bound, and --workspace was not given.", "NO_BINDING", [
34
+ 'implto-tos-axi components list --workspace "<name>"',
35
+ "implto-tos-axi init --workspace <name> --project <key> # to bind this directory",
36
+ ]);
37
+ export const ambiguous = (what, candidates) => new TosError(`"${what}" matches more than one: ${candidates.join(", ")}.`, "AMBIGUOUS", [
38
+ "Name it exactly, or pass the id.",
39
+ ]);
40
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAS;IACb,WAAW,CAAW;IAE/B,YAAY,OAAe,EAAE,IAAY,EAAE,cAAwB,EAAE;QACnE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CACF;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,KAAK,YAAY,QAAQ,CAAC;AACnC,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,EAAE,CAC7C,IAAI,QAAQ,CAAC,0BAA0B,OAAO,YAAY,EAAE,cAAc,EAAE;IAC1E,kCAAkC,OAAO,EAAE;IAC3C,yEAAyE;CAC1E,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,EAAE,CACpD,IAAI,QAAQ,CACV,uBAAuB,OAAO,kEAAkE,EAChG,cAAc,EACd,CAAC,kCAAkC,OAAO,EAAE,CAAC,CAC9C,CAAC;AAEJ,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE,CAC5B,IAAI,QAAQ,CAAC,6DAA6D,EAAE,YAAY,EAAE;IACxF,wDAAwD;IACxD,gEAAgE;CACjE,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE,CAC9B,IAAI,QAAQ,CACV,2EAA2E,EAC3E,YAAY,EACZ;IACE,qDAAqD;IACrD,mFAAmF;CACpF,CACF,CAAC;AAEJ,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,UAAoB,EAAE,EAAE,CAC9D,IAAI,QAAQ,CAAC,IAAI,IAAI,4BAA4B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE;IACtF,kCAAkC;CACnC,CAAC,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Spec-driven flag parsing.
3
+ *
4
+ * The SDK owns the shape of the invocation (`<bin> <command> ...`) but not the
5
+ * flags inside a command, so this fills that gap with one rule: an unknown
6
+ * flag is a usage error, never a silently dropped argument. A dropped flag is
7
+ * worse than an error - the command appears to succeed while doing something
8
+ * the caller did not ask for - and an agent that cannot see the mistake will
9
+ * repeat it.
10
+ *
11
+ * Errors are self-correcting in one turn: they name the offending flag, the
12
+ * nearest real one when there is a plausible match, and the full list of what
13
+ * this command accepts, so nothing has to go and read `--help` to recover.
14
+ */
15
+ export type FlagValue = string | number | boolean | string[];
16
+ export interface FlagSpec {
17
+ readonly kind: "boolean" | "string" | "number";
18
+ readonly description: string;
19
+ /** Placeholder shown in help, e.g. `dir` renders as `--out <dir>`. */
20
+ readonly placeholder?: string;
21
+ /**
22
+ * A value that makes sense for this flag, shown when parsing fails.
23
+ *
24
+ * Every numeric flag used to be illustrated with `30`, which for a playback
25
+ * multiplier is not a typo away from right - it is thirty times speed, and
26
+ * reads as though the flag takes seconds.
27
+ */
28
+ readonly example?: string | number;
29
+ /** Bounds for a numeric flag. Outside them the value produces nothing usable. */
30
+ readonly min?: number;
31
+ readonly max?: number;
32
+ /** Collect every occurrence instead of keeping the last. String flags only. */
33
+ readonly repeat?: boolean;
34
+ }
35
+ export type FlagSpecs = Record<string, FlagSpec>;
36
+ export interface ParsedArgs {
37
+ readonly positionals: readonly string[];
38
+ readonly flags: Readonly<Record<string, FlagValue>>;
39
+ }
40
+ /** The closest known flag to `input`, when one is close enough to mean it. */
41
+ export declare function nearestFlag(input: string, known: readonly string[]): string | null;
42
+ /**
43
+ * Parses `args` against `specs`.
44
+ *
45
+ * Supports `--flag value`, `--flag=value`, `--no-flag` for booleans, and `--`
46
+ * to stop flag parsing. Everything else is a positional.
47
+ */
48
+ export declare function parseFlags(args: readonly string[], specs: FlagSpecs): ParsedArgs;
49
+ /** Renders a command's flags for its `--help` block. */
50
+ export declare function renderFlagHelp(specs: FlagSpecs): string[];
@@ -0,0 +1,143 @@
1
+ import { TosError } from "./errors.js";
2
+ /**
3
+ * Levenshtein distance, bounded by the shorter string. Used only to decide
4
+ * whether a typo is close enough to a real flag to be worth suggesting.
5
+ */
6
+ function distance(a, b) {
7
+ const rows = a.length + 1;
8
+ const cols = b.length + 1;
9
+ let prev = Array.from({ length: cols }, (_, i) => i);
10
+ for (let i = 1; i < rows; i++) {
11
+ const curr = [i, ...Array(cols - 1).fill(0)];
12
+ for (let j = 1; j < cols; j++) {
13
+ const substitution = (prev[j - 1] ?? 0) + (a[i - 1] === b[j - 1] ? 0 : 1);
14
+ const deletion = (prev[j] ?? 0) + 1;
15
+ const insertion = (curr[j - 1] ?? 0) + 1;
16
+ curr[j] = Math.min(substitution, deletion, insertion);
17
+ }
18
+ prev = curr;
19
+ }
20
+ return prev[cols - 1] ?? Math.max(a.length, b.length);
21
+ }
22
+ /** The closest known flag to `input`, when one is close enough to mean it. */
23
+ export function nearestFlag(input, known) {
24
+ let best = null;
25
+ let bestDistance = Infinity;
26
+ for (const candidate of known) {
27
+ const d = distance(input, candidate);
28
+ if (d < bestDistance) {
29
+ bestDistance = d;
30
+ best = candidate;
31
+ }
32
+ }
33
+ // Two edits on a short flag is already a different flag, not a typo.
34
+ return best !== null && bestDistance <= Math.max(2, Math.floor(input.length / 3)) ? best : null;
35
+ }
36
+ function usage(specs) {
37
+ const names = Object.keys(specs);
38
+ return names.length > 0 ? `Accepts: ${names.map((n) => `--${n}`).join(", ")}` : "";
39
+ }
40
+ function unknownFlag(name, specs) {
41
+ const known = Object.keys(specs);
42
+ const near = nearestFlag(name, known);
43
+ const help = [
44
+ ...(near ? [`Did you mean \`--${near}\`?`] : []),
45
+ ...(known.length > 0 ? [usage(specs)] : ["This command accepts no flags"]),
46
+ ];
47
+ throw new TosError(`Unknown flag: --${name}`, "VALIDATION_ERROR", help);
48
+ }
49
+ function numeric(name, raw, spec) {
50
+ const example = `Example: --${name} ${spec.example ?? 30}`;
51
+ const value = Number(raw);
52
+ if (!Number.isFinite(value)) {
53
+ throw new TosError(`--${name} expects a number, got \`${raw}\``, "VALIDATION_ERROR", [example]);
54
+ }
55
+ // Checked here rather than wherever the value lands, so a nonsensical one is
56
+ // refused before a browser opens. `--pace 0` used to record a zero-second
57
+ // clip and then advise re-cutting it slower.
58
+ const { min, max } = spec;
59
+ if ((min !== undefined && value < min) || (max !== undefined && value > max)) {
60
+ throw new TosError(`--${name} has to be ${describeRange(min, max)}, got ${value}`, "VALIDATION_ERROR", [example]);
61
+ }
62
+ return value;
63
+ }
64
+ function describeRange(min, max) {
65
+ if (min !== undefined && max !== undefined)
66
+ return `between ${min} and ${max}`;
67
+ if (min !== undefined)
68
+ return `at least ${min}`;
69
+ return `at most ${max}`;
70
+ }
71
+ /**
72
+ * Parses `args` against `specs`.
73
+ *
74
+ * Supports `--flag value`, `--flag=value`, `--no-flag` for booleans, and `--`
75
+ * to stop flag parsing. Everything else is a positional.
76
+ */
77
+ export function parseFlags(args, specs) {
78
+ const positionals = [];
79
+ const flags = {};
80
+ let literal = false;
81
+ for (let i = 0; i < args.length; i++) {
82
+ const arg = args[i];
83
+ if (literal || !arg.startsWith("--")) {
84
+ positionals.push(arg);
85
+ continue;
86
+ }
87
+ if (arg === "--") {
88
+ literal = true;
89
+ continue;
90
+ }
91
+ const eq = arg.indexOf("=");
92
+ const name = (eq === -1 ? arg.slice(2) : arg.slice(2, eq)).trim();
93
+ const inlineValue = eq === -1 ? null : arg.slice(eq + 1);
94
+ // `--no-x` turns off a boolean `x`. Only meaningful for booleans, so an
95
+ // unknown `--no-y` still reports the flag the caller actually typed.
96
+ if (!specs[name] && name.startsWith("no-") && specs[name.slice(3)]?.kind === "boolean") {
97
+ flags[name.slice(3)] = false;
98
+ continue;
99
+ }
100
+ const spec = specs[name];
101
+ if (!spec)
102
+ unknownFlag(name, specs);
103
+ if (spec.kind === "boolean") {
104
+ if (inlineValue !== null && inlineValue !== "true" && inlineValue !== "false") {
105
+ throw new TosError(`--${name} is a switch and takes no value`, "VALIDATION_ERROR", [
106
+ `Pass \`--${name}\` on its own, or \`--no-${name}\` to turn it off`,
107
+ ]);
108
+ }
109
+ flags[name] = inlineValue !== "false";
110
+ continue;
111
+ }
112
+ const raw = inlineValue ?? args[++i];
113
+ if (raw === undefined) {
114
+ throw new TosError(`--${name} expects a value`, "VALIDATION_ERROR", [
115
+ `Pass it as \`--${name} <${spec.placeholder ?? "value"}>\``,
116
+ ]);
117
+ }
118
+ if (spec.kind === "number") {
119
+ flags[name] = numeric(name, raw, spec);
120
+ }
121
+ else if (spec.repeat) {
122
+ const existing = flags[name];
123
+ flags[name] = Array.isArray(existing) ? [...existing, raw] : [raw];
124
+ }
125
+ else {
126
+ flags[name] = raw;
127
+ }
128
+ }
129
+ return { positionals, flags };
130
+ }
131
+ /** Renders a command's flags for its `--help` block. */
132
+ export function renderFlagHelp(specs) {
133
+ const entries = Object.entries(specs);
134
+ if (entries.length === 0)
135
+ return [];
136
+ const rendered = entries.map(([name, spec]) => ({
137
+ left: spec.kind === "boolean" ? `--${name}` : `--${name} <${spec.placeholder ?? "value"}>`,
138
+ description: spec.description,
139
+ }));
140
+ const width = Math.max(...rendered.map((r) => r.left.length));
141
+ return rendered.map((r) => ` ${r.left.padEnd(width)} ${r.description}`);
142
+ }
143
+ //# sourceMapping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C,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { DESCRIPTION } from "./cli.js";
2
+ export { VERSION } from "./version.js";
3
+ export { TosError, isTosError } from "./errors.js";
4
+ export { MCP_SCOPES } from "./scopes.js";
5
+ export { BINDING_FILENAME, findBinding, type Binding } from "./config/binding.js";
6
+ export { PROFILE_NAMES, DEFAULT_PROFILE, resolveProfile, type Profile } from "./config/profiles.js";
@@ -0,0 +1,7 @@
1
+ export { DESCRIPTION } from "./cli.js";
2
+ export { VERSION } from "./version.js";
3
+ export { TosError, isTosError } from "./errors.js";
4
+ export { MCP_SCOPES } from "./scopes.js";
5
+ export { BINDING_FILENAME, findBinding } from "./config/binding.js";
6
+ export { PROFILE_NAMES, DEFAULT_PROFILE, resolveProfile } from "./config/profiles.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAgB,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAgB,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,85 @@
1
+ import type { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
2
+ /**
3
+ * One exchange with the MCP server.
4
+ *
5
+ * The server is stateless, so every invocation does its own `initialize` and
6
+ * then one request. Two round trips per command is the cost of not holding a
7
+ * session between processes, and it is the right trade for a CLI that an agent
8
+ * shells out to.
9
+ *
10
+ * No tool is described here. The point of reaching the server this way rather
11
+ * than mounting it is that no tool schema ever enters a model's prompt: the
12
+ * catalog is fetched on demand by `tools list` and `tools show`, for the one
13
+ * tool a task turns out to need.
14
+ */
15
+ export interface CallOptions {
16
+ mcpUrl: string;
17
+ /** A bearer token, for a pasted key or `TOS_TOKEN`. */
18
+ token?: string | undefined;
19
+ /** An OAuth provider, which renews on its own. Mutually exclusive with token. */
20
+ authProvider?: OAuthClientProvider | undefined;
21
+ profile: string;
22
+ }
23
+ /** A JSON Schema property, in the shapes this server actually emits. */
24
+ export interface SchemaProperty {
25
+ type?: string | string[];
26
+ description?: string;
27
+ enum?: readonly (string | number)[];
28
+ nullable?: boolean;
29
+ items?: {
30
+ type?: string;
31
+ };
32
+ }
33
+ export interface ToolSchema {
34
+ type?: string;
35
+ properties?: Record<string, SchemaProperty>;
36
+ required?: readonly string[];
37
+ }
38
+ export interface McpTool {
39
+ name: string;
40
+ description?: string;
41
+ inputSchema?: ToolSchema;
42
+ /**
43
+ * No `domain` here, although the server sends one: the SDK drops annotation
44
+ * keys it does not know. Areas come from the catalog - see `grouping()`.
45
+ */
46
+ annotations?: {
47
+ title?: string;
48
+ };
49
+ }
50
+ export interface DomainEntry {
51
+ id: string;
52
+ title: string;
53
+ description: string;
54
+ keywords?: string[];
55
+ instructions?: string;
56
+ toolCount?: number;
57
+ tools?: string[];
58
+ }
59
+ export interface DomainCatalog {
60
+ version?: number;
61
+ domains: DomainEntry[];
62
+ }
63
+ /**
64
+ * Where the server publishes its domain catalog. A constant rather than a
65
+ * lookup through `resources/list`: one name, and a server that does not serve
66
+ * it answers with an error we turn into `null`.
67
+ */
68
+ export declare const TOOL_DOMAINS_URI = "transformation-os://tool-domains";
69
+ export declare function callTool(options: CallOptions, name: string, args?: Record<string, unknown>): Promise<unknown>;
70
+ /**
71
+ * The tools this credential may call.
72
+ *
73
+ * Already narrowed by the server to the domains the credential was granted, so
74
+ * what comes back is what will actually run - not a catalog with holes in it
75
+ * that only show up as a refusal.
76
+ */
77
+ export declare function listTools(options: CallOptions): Promise<McpTool[]>;
78
+ /**
79
+ * The domain catalog, or null when this server does not group its tools.
80
+ *
81
+ * Unlike `tools/list` the catalog is not narrowed by the grant, which is what
82
+ * lets `tools domains` say "this exists and you do not have it" rather than
83
+ * leaving a credential's holder wondering where an area went.
84
+ */
85
+ export declare function readDomains(options: CallOptions): Promise<DomainCatalog | null>;