@topolo/cli 0.1.32 → 0.2.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.
package/package.json CHANGED
@@ -1,19 +1,24 @@
1
1
  {
2
2
  "name": "@topolo/cli",
3
- "version": "0.1.32",
3
+ "version": "0.2.1",
4
4
  "description": "Command-line interface for Topolo developers, operators, and agents, with internal first-party scaffolding available under the topolo platform namespace.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "topolo": "dist/index.js"
8
8
  },
9
9
  "files": [
10
- "dist"
10
+ "dist",
11
+ "skills"
11
12
  ],
12
13
  "scripts": {
14
+ "build:sdk": "pnpm --dir ../topolo-sdk build",
15
+ "prebuild": "pnpm run build:sdk",
13
16
  "build": "tsup",
14
17
  "dev": "tsup --watch",
18
+ "pretypecheck": "pnpm run build:sdk",
15
19
  "typecheck": "tsc --noEmit",
16
20
  "start": "node dist/index.js",
21
+ "pretest": "pnpm run build:sdk",
17
22
  "test": "vitest run",
18
23
  "test:watch": "vitest",
19
24
  "coverage": "vitest run --coverage"
@@ -22,7 +27,7 @@
22
27
  "commander": "^12.1.0"
23
28
  },
24
29
  "devDependencies": {
25
- "@topolo/sdk": "workspace:*",
30
+ "@topolo/sdk": "file:../topolo-sdk",
26
31
  "@types/node": "^20.12.0",
27
32
  "@vitest/coverage-v8": "^2.1.0",
28
33
  "tsup": "^8.0.0",
@@ -0,0 +1,155 @@
1
+ # Topolo — agent guide (Codex / general-purpose agents)
2
+
3
+ This file teaches an agent how to interact with the Topolo platform via the `topolo` CLI and, when available, the Topolo MCP server. It is intentionally short, shell-first, and stable across Codex, Cursor, and any other agent that reads `AGENTS.md`.
4
+
5
+ ## What the platform is
6
+
7
+ Topolo is a multi-app SaaS platform. The CLI and MCP server both use `@topolo/sdk`; bundled app IDs come from the generated registry, and newly registered API/technical services can be resolved from the live Auth catalog.
8
+
9
+ - Use `topolo apps --json` or the MCP `topolo_search_applications` tool to discover platform applications, including browser-only Worker apps.
10
+ - Use `topolo apps requirements <application_id> --json` or the MCP `topolo_list_application_requirements` tool before creating or expanding a Topolo app.
11
+ - Use `topolo apps audit <application_id> --json` or the MCP `topolo_audit_applications` tool to inspect current requirement conformance and migration work.
12
+ - Use `topolo services --json` or the MCP `topolo_search_applications` tool to discover callable app ids and effective URLs.
13
+ - Use `topolo actions --service <app> --json` or MCP `topolo_search_actions` to discover callable operations granted to the current credential; invoke automatic reads with `topolo_read_action` and confirmation-gated operations with `topolo_call_action`.
14
+ - The generic `api` command and MCP `topolo_api_call` tool can reach bundled SDK services and live Auth-catalog API/technical services when no action contract exists yet.
15
+
16
+ Every call is scoped to the organization embedded in the credential. There is no `--org` flag anywhere — attempting to target another org will fail.
17
+
18
+ ## Invocation contract
19
+
20
+ Always call `topolo` with `--json` from an agent. JSON schemas are stable; human text is not.
21
+
22
+ ```bash
23
+ topolo <command> [args] --json
24
+ ```
25
+
26
+ Production is the default CLI environment. Use `--env staging` anywhere in the
27
+ command, or set `TOPOLO_ENV=staging`, for internal staging auth, staging service
28
+ discovery, or staging scaffold provisioning. Staging credentials are stored
29
+ separately from production credentials.
30
+
31
+ On success the command prints JSON to stdout and exits 0. On failure it prints `{"error":{"message","code","hint","exitCode"}}` to stderr and exits non-zero. Branch on `code` (not on message text).
32
+
33
+ Exit codes:
34
+
35
+ - `0` success
36
+ - `1` generic error
37
+ - `2` auth error → run `topolo auth login` and retry
38
+ - `3` permission denied → the user's role/scopes are insufficient; surface to user, do not retry
39
+
40
+ ## Setup flow
41
+
42
+ 1. Check install: `command -v topolo || npm install -g @topolo/cli` (requires Node ≥ 20). To wire the skill + MCP into this agent, run `topolo skills install` (credential-free — the MCP reads the `topolo auth login` credential).
43
+ 2. Check credential: `topolo auth status --json`.
44
+ 3. For staging work, check credential with `topolo auth status --env staging --json`.
45
+ 4. If `source` is `none`, run `topolo auth login` (add `--env staging` for staging) and wait for the user to approve in the browser tab that opens. **No `--client-id` is needed** — the CLI has a built-in first-party client, so any Topolo user can sign in; capabilities are decided by their permissions. (`--client-id=<doac_…>` is only for advanced/self-hosted OAuth clients.) For service-agent / headless installs, use an API key with `topolo auth login --api-key=<key>` or set `TOPOLO_API_KEY` for a single invocation.
46
+ 5. Confirm identity once: `topolo whoami --json`. Reference the returned `organization.name` when explaining results to the user.
47
+ 6. To act in a different org or personal space: `topolo context ls --json` then `topolo context use <organization-name|personal> --json`. Each context has its own credential; the CLI + MCP run in the active one. This does not change the user's web context, and later web switches do not alter the issued credential.
48
+
49
+ ## Command surface
50
+
51
+ ### Identity
52
+
53
+ ```bash
54
+ topolo whoami --json
55
+ #=> { "user": {...}, "organization": {...}, "kind": "access_token" | "api_key" }
56
+
57
+ topolo auth status --json
58
+ topolo auth login [--api-key=...] [--client-id=... (advanced)] [--scope="..."]
59
+ topolo auth logout
60
+ ```
61
+
62
+ ### Contexts (personal + multiple organizations)
63
+
64
+ ```bash
65
+ topolo context ls --json # personal + your orgs; marks the active one
66
+ topolo context use <organization-name|personal> --json # switch the active context (validated server-side)
67
+ ```
68
+
69
+ There is no `--org` flag — switch context to act in a different organization. `topolo whoami` reflects the active context.
70
+ The switch is local to the CLI/MCP credential store and its token refresh chain;
71
+ it never changes the shared web preference.
72
+
73
+ ### Application and service discovery
74
+
75
+ ```bash
76
+ topolo apps --json
77
+ topolo apps get <application_id> --json
78
+ topolo apps requirements <application_id> --json
79
+ topolo apps audit <application_id> --json
80
+ topolo services --json
81
+ ```
82
+
83
+ Use `topolo apps` to understand which Topolo application you are dealing with.
84
+ Use `topolo apps requirements` before building so the current platform contract
85
+ is in the agent context.
86
+ Use `topolo services` before `topolo api` so you pass an exact SDK app id
87
+ such as `auth`, `crm`, `mail`, `calendar`, `web`, or `quro.redirect`.
88
+ In staging, `topolo services --env staging --json` also shows
89
+ `environmentSafe`; false means the service still resolves to a production SDK
90
+ URL and the CLI will refuse `topolo api` calls until a staging override is set.
91
+
92
+ ### Credential-scoped actions
93
+
94
+ ```bash
95
+ topolo actions --service mail --json
96
+ topolo actions get app_topolo_mail.messages.send --json
97
+ topolo actions call app_topolo_mail.messages.send \
98
+ --data '{"mailboxId":"primary","subject":"Hello","text":"..."}' \
99
+ --confirm --json
100
+ ```
101
+
102
+ `topolo actions` is the normal agent entrypoint for application-specific
103
+ operations. It is filtered by the signed-in organization and the exact service
104
+ permissions on the credential. Actions marked `authorizationMode: "runtime"`
105
+ have input-dependent policy and are definitively authorized by the target app
106
+ for the supplied organization, application, and resource at invocation time.
107
+
108
+ ### Generic passthrough
109
+
110
+ For any endpoint without a typed subcommand:
111
+
112
+ ```bash
113
+ topolo api <service> <GET|POST|PUT|PATCH|DELETE> <path> [--data '<json>'] [--query key=value] [--confirm] --json
114
+ ```
115
+
116
+ - `<path>` begins with `/api/…` (no host).
117
+ - Discover `<service>` with `topolo services --json`.
118
+ - **Mutating methods require `--confirm`**. If omitted, the CLI refuses.
119
+
120
+ ## Write safety — mandatory
121
+
122
+ Before any mutating call, you MUST:
123
+
124
+ 1. Print the exact method, path, and body you're about to send.
125
+ 2. Get explicit user confirmation.
126
+ 3. Only then run with `--confirm`.
127
+
128
+ Do not batch writes. Do not retry a failed write without re-confirming. The `--confirm` flag exists so a mis-generated write fails loudly instead of silently mutating production data.
129
+
130
+ ## Credential handling
131
+
132
+ - Never commit credentials. If a user shares an API key inline, use it for a single invocation via env var (`TOPOLO_API_KEY=… topolo whoami --json`) rather than writing it anywhere.
133
+ - Prefer `TOPOLO_STAGING_API_KEY`, `TOPOLO_STAGING_ACCESS_TOKEN`, `TOPOLO_PRODUCTION_API_KEY`, or `TOPOLO_PRODUCTION_ACCESS_TOKEN` when a credential is meant for only one environment.
134
+ - The stored config lives at `$XDG_CONFIG_HOME/topolo/config.json` (mode 0600). Don't read or modify it directly — use `topolo auth` commands.
135
+ - Stored OAuth access tokens refresh automatically when the config contains a refresh token and OAuth client id. On `auth_error`, prompt the user to re-run `topolo auth login`.
136
+
137
+ ## Org isolation — do not try to bypass
138
+
139
+ - There is no `orgId` argument on any command.
140
+ - Do not add org hints to `topolo api` request bodies; the backend rederives org from the credential.
141
+ - If the user asks you to access "another org's data", the correct response is: "I can only act as the signed-in user. Sign in with a credential for that org first."
142
+
143
+ ## Debugging
144
+
145
+ - `--no-json` gives human-readable output (useful when showing something to the user directly).
146
+ - `TOPOLO_DEBUG=1` writes request/response traces to stderr while keeping JSON stdout clean.
147
+ - Every request carries `X-Topolo-Request-Id`; if the user reports a failure, ask them for the request-id so support can grep logs.
148
+ - If you set `TOPOLO_AGENT_NAME=<yourAgentLabel>` in the shell before running `topolo`, it's recorded in `X-Topolo-Agent` for audit traceability.
149
+
150
+ ## Reference
151
+
152
+ - Documentation: `https://docs.topolo.app` (guides, authentication, API reference).
153
+ - Developers console (register apps / OAuth clients): `https://developers.topolo.app`
154
+ - CLI README: the `README.md` alongside this file.
155
+ - Schemas: `packages/topolo-sdk/src/modules/` in the monorepo.
@@ -0,0 +1,248 @@
1
+ ---
2
+ name: topolo
3
+ description: Read and write Topolo platform data (identity, application/service discovery, credential-scoped actions, and any SDK-registered Topolo API) from the shell via the `topolo` CLI. Use whenever the user references their Topolo organization, a Topolo app/service, or asks to mint/inspect Topolo credentials.
4
+ ---
5
+
6
+ # Topolo platform
7
+
8
+ The `topolo` CLI is the agent-friendly entry point to the Topolo platform. Every command runs in the **active context** embedded in the current credential — the user's personal space or a specific organization. You cannot bypass the credential or forge a context; to act in a different organization (or personal), switch with `topolo context use` (see Contexts).
9
+
10
+ ## When this skill fires
11
+
12
+ Use `topolo` whenever the user:
13
+
14
+ - References records, messages, customers, or any other data stored in a Topolo app.
15
+ - Asks about their Topolo identity ("who am I logged in as", "what org am I in", "what scopes do I have").
16
+ - Wants to call an endpoint under a Topolo service from the shell.
17
+ - Mentions a Topolo OAuth client (`doac_…`) or API key.
18
+
19
+ If the user asks a platform question and `topolo` is not installed, install it: `npm install -g @topolo/cli`. Requires Node ≥ 20. To wire this skill and the MCP server into Claude Code / Codex in one step, run `topolo skills install` (copies the skill file, registers the `topolo` MCP; no API key needed — the MCP reads the same credential `topolo auth login` writes).
20
+
21
+ ## Credentials — always check first
22
+
23
+ Before any data command, confirm a credential is configured:
24
+
25
+ ```bash
26
+ topolo auth status --json
27
+ ```
28
+
29
+ Production is the default environment. Use `--env staging` anywhere in the
30
+ command, or set `TOPOLO_ENV=staging`, when the user is testing internal staging
31
+ or provisioning a staging-only first-party app:
32
+
33
+ ```bash
34
+ topolo auth status --env staging --json
35
+ topolo auth login --env staging
36
+ ```
37
+
38
+ Possible `source` values:
39
+
40
+ | source | meaning |
41
+ | --- | --- |
42
+ | `env:TOPOLO_STAGING_API_KEY` / `env:TOPOLO_PRODUCTION_API_KEY` | Environment-specific service-scoped API key in env |
43
+ | `env:TOPOLO_STAGING_ACCESS_TOKEN` / `env:TOPOLO_PRODUCTION_ACCESS_TOKEN` | Environment-specific short-lived access token in env |
44
+ | `env:TOPOLO_API_KEY` | Shared service-scoped API key in env |
45
+ | `env:TOPOLO_ACCESS_TOKEN` | Shared short-lived access token in env (dev/testing) |
46
+ | `config-file` | Token stored in the selected environment profile at `$XDG_CONFIG_HOME/topolo/config.json` |
47
+ | `none` | Not signed in — call `topolo auth login` |
48
+
49
+ If `source: none`, run `topolo auth login` (add `--env staging` for staging) and
50
+ tell the user to approve the device in the browser tab that opens. The CLI uses
51
+ its **built-in first-party client**, so **no `--client-id` is needed** — any
52
+ Topolo user can sign in; what they can then do is decided by their permissions.
53
+ The CLI blocks until they approve, then stores the token in that environment's
54
+ active-context profile. (`--client-id=<doac_…>` is only for advanced/self-hosted
55
+ setups that register their own OAuth client.)
56
+
57
+ For service-agent / headless installs, use an API key with
58
+ `topolo auth login --api-key=<key>` or set `TOPOLO_API_KEY` only for the single
59
+ command that needs it.
60
+
61
+ ## Output modes
62
+
63
+ All commands support `--json` (machine) and `--no-json` (human). The CLI autodetects: pretty when stdout is a TTY, JSON when piped. **When you call `topolo` from an agent, always pass `--json`** — the JSON shape is stable; the pretty text is not.
64
+
65
+ ## Command reference
66
+
67
+ ### Identity
68
+
69
+ ```bash
70
+ topolo whoami --json
71
+ ```
72
+
73
+ Returns `{ user: { email, name, role, permissions }, organization: { name, slug } | null, kind }`.
74
+
75
+ Use this once at the start of a session to confirm the active user + org — then reference that org context in subsequent explanations so the user doesn't have to re-orient.
76
+
77
+ ### Contexts (personal + multiple organizations)
78
+
79
+ A user can act in their **personal** space or in any **organization** they belong to. Each context has its own credential; the CLI and MCP always operate in the **active** one.
80
+
81
+ CLI/MCP context is credential-bound and independent from the user's web
82
+ switcher preference. `topolo context use` does not move the browser session;
83
+ switching in the browser does not alter any issued CLI/MCP token or refresh
84
+ chain. Multiple cached personal/org credentials can therefore coexist safely.
85
+
86
+ ```bash
87
+ topolo context ls --json # personal + your orgs, and which is active
88
+ topolo context use <organization-name|personal> --json # switch the active context
89
+ ```
90
+
91
+ `topolo context use` activates a cached context or exchanges the current credential for a fresh token scoped to the target (membership is validated server-side). After switching, `topolo whoami` and every subsequent command run in that context. There is **no `--org` flag** — switch context instead. If a command returns a permission error, the user may need to switch to the org that owns the resource, or be granted access there.
92
+
93
+ ### Application and service discovery
94
+
95
+ ```bash
96
+ topolo apps --json
97
+ topolo apps get <application_id> --json
98
+ topolo apps requirements <application_id> --json
99
+ topolo apps audit <application_id> --json
100
+ topolo services --json
101
+ topolo actions --service <application_id_or_slug> --json
102
+ ```
103
+
104
+ `topolo apps` returns every cataloged Topolo application, including browser-only
105
+ Worker apps that do not expose a callable API. `topolo services` returns every
106
+ SDK-app id with its default and effective URL. In staging, a
107
+ service with `environmentSafe: false` still resolves to a production SDK URL and
108
+ the CLI refuses `topolo api` calls for it until a staging URL override is set.
109
+ `topolo apps requirements` returns the current versioned app-build contract and should be run
110
+ before creating or expanding a Topolo app. `topolo apps audit` returns
111
+ catalog-backed requirement scores and migration work. Run `topolo services`
112
+ before `topolo api` when you are not using a cataloged action.
113
+
114
+ ### Credential-scoped actions
115
+
116
+ ```bash
117
+ topolo actions --service mail --json
118
+ topolo actions get app_topolo_mail.messages.send --json
119
+ topolo actions call app_topolo_mail.messages.send \
120
+ --data '{"mailboxId":"primary","subject":"Hello","text":"..."}' \
121
+ --confirm --json
122
+ ```
123
+
124
+ `topolo actions` returns the credential-scoped action catalog. Static actions
125
+ are filtered by the current organization and permissions. An action with
126
+ `authorizationMode: "runtime"` has input-dependent policy; it remains
127
+ discoverable, and the target app authorizes the concrete organization,
128
+ application, and resource on every call. Prefer catalog actions over `topolo
129
+ api` when the target app has published a machine contract through Topolo
130
+ Developers. Writes require `--confirm`.
131
+
132
+ For an app-local workspace or other resource boundary, pass the resource
133
+ separately from the action input. Resource selection is per invocation: it does
134
+ not switch the personal/organization credential context or the browser session.
135
+
136
+ ```bash
137
+ topolo actions call app_topolo_inventory.dashboard.get \
138
+ --resource-type workspace \
139
+ --resource-id <workspace_id> \
140
+ --data '{}' --json
141
+ ```
142
+
143
+ Use a published workspace-list action to discover IDs when the app has multiple
144
+ workspaces. For a single default workspace, use the active organization ID from
145
+ `topolo whoami --json` when that app defines its workspace as the organization
146
+ boundary. Always provide `--resource-type` and `--resource-id` together.
147
+
148
+ ### Generic API passthrough
149
+
150
+ For any endpoint that doesn't yet have a typed subcommand:
151
+
152
+ ```bash
153
+ topolo api <service> <method> <path> [--data '<json>'] [--query key=value] [--confirm]
154
+ ```
155
+
156
+ - `<service>`: any id from `topolo services --json`.
157
+ - `<method>`: `GET` | `POST` | `PUT` | `PATCH` | `DELETE`.
158
+ - `<path>`: starts with `/api/…` — don't include the host.
159
+ - **Mutating calls require `--confirm`**. If you omit it, the CLI refuses and exits non-zero. This is intentional: confirm before sending writes.
160
+
161
+ Examples:
162
+
163
+ ```bash
164
+ # Read current user via auth service
165
+ topolo api auth GET /api/me --json
166
+
167
+ # Send mail through a published action (requires confirm)
168
+ topolo actions call app_topolo_mail.messages.send \
169
+ --data '{"mailboxId":"primary","subject":"Hello","text":"..."}' \
170
+ --confirm --json
171
+ ```
172
+
173
+ ## Error handling
174
+
175
+ Exit codes:
176
+
177
+ | Code | Meaning | Action |
178
+ | --- | --- | --- |
179
+ | 0 | Success | — |
180
+ | 1 | Generic error | Surface message to user |
181
+ | 2 | Auth error (expired, invalid token) | Run `topolo auth login` and retry |
182
+ | 3 | Permission denied | User's role/scopes lack the capability — point them to the Developers console |
183
+
184
+ In `--json` mode, errors come on stderr as `{"error":{"message","code","hint","exitCode"}}`. Parse `code` first when branching.
185
+
186
+ Stored OAuth access tokens refresh automatically when the config contains both a refresh token and the OAuth client id used at login. If `whoami` still returns `auth_error`, have the user re-run `topolo auth login`.
187
+
188
+ ## Safety rules
189
+
190
+ 1. **Never run a mutating `topolo actions call …` or `topolo api … POST|PUT|PATCH|DELETE …` without surfacing the exact body to the user first** and confirming. The `--confirm` flag is a guardrail, not your approval.
191
+ 2. **Never write credentials to tracked files.** If a user pastes an API key inline, use it via env var for that invocation (`TOPOLO_API_KEY=… topolo whoami`) rather than committing it.
192
+ 3. **Cross-org isolation is built-in** — there is no `--org` flag anywhere, and the backend rederives the org from the credential (it ignores org hints in a request body). To act in a different organization, use `topolo context use <org>` to switch the active context — never try to fake one via the passthrough.
193
+ 4. Audit headers (`X-Topolo-Client`, `X-Topolo-Request-Id`, optional `X-Topolo-Agent`) are set by the CLI automatically. If `TOPOLO_AGENT_NAME` is already exported in the user's shell, leave it alone — it's the audit trail.
194
+
195
+ ## Common flows
196
+
197
+ **"Show me the available Mail actions"**
198
+ ```bash
199
+ topolo whoami --json # confirm org
200
+ topolo actions --service mail --json
201
+ ```
202
+
203
+ **"Send a message through Mail"**
204
+ ```bash
205
+ topolo actions call app_topolo_mail.messages.send \
206
+ --data '{"mailboxId":"primary","subject":"Hello","text":"..."}' \
207
+ --confirm --json
208
+ ```
209
+
210
+ **"What scopes does my CLI token have?"**
211
+ ```bash
212
+ topolo whoami --json | jq '.user.permissions'
213
+ ```
214
+
215
+ **"What app id should I use?"**
216
+ ```bash
217
+ topolo apps --json
218
+ topolo apps requirements <application_id> --json
219
+ topolo apps audit <application_id> --json
220
+ topolo services --json
221
+ topolo actions --service mail --json
222
+ ```
223
+
224
+ **"Sign me in fresh"**
225
+ ```bash
226
+ topolo auth logout
227
+ topolo auth login # no --client-id needed; approve in the browser
228
+ ```
229
+
230
+ **"Sign me in to staging"**
231
+ ```bash
232
+ topolo auth logout --env staging
233
+ topolo auth login --env staging
234
+ topolo whoami --env staging --json
235
+ ```
236
+
237
+ **"Switch to my <Acme> organization" / "work in my personal space"**
238
+ ```bash
239
+ topolo context ls --json
240
+ topolo context use acme --json # or: topolo context use personal
241
+ ```
242
+
243
+ ## Where to learn more
244
+
245
+ - **Topolo documentation:** https://docs.topolo.app — guides (authentication, quick start), API reference, and per-app docs. (Staging: https://docs.stg.topolo.us)
246
+ - Register apps / OAuth clients: the Developers console at https://developers.topolo.app
247
+ - CLI source (for an undocumented flag): `packages/topolo-cli/src/commands/` in the topolo-platform monorepo.
248
+ - SDK package: `packages/topolo-sdk/src/` — authoritative client, dynamic action catalog, and shared response contracts.