@palettelab/cli 0.3.61 → 0.3.63

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 (39) hide show
  1. package/README.md +80 -5
  2. package/backend-sdk/palette_sdk/__init__.py +21 -1
  3. package/backend-sdk/palette_sdk/capabilities.py +126 -0
  4. package/backend-sdk/palette_sdk/connections.py +49 -11
  5. package/backend-sdk/palette_sdk/connections_generated.py +246 -0
  6. package/backend-sdk/palette_sdk/manifest.py +78 -3
  7. package/backend-sdk/palette_sdk/platform_services.py +122 -0
  8. package/backend-sdk/palette_sdk/plugin_context.py +14 -0
  9. package/backend-sdk/palette_sdk/services.py +45 -6
  10. package/backend-sdk/palette_sdk/talk.py +65 -0
  11. package/backend-sdk/pyproject.toml +1 -1
  12. package/docs/python-backend-sdk.md +64 -1
  13. package/lib/bundler.js +64 -0
  14. package/lib/cli.js +27 -2
  15. package/lib/commands/capabilities.js +151 -0
  16. package/lib/commands/connections.js +234 -0
  17. package/lib/commands/dev.js +75 -1
  18. package/lib/commands/doctor.js +70 -0
  19. package/lib/commands/init.js +3 -2
  20. package/lib/commands/open.js +43 -0
  21. package/lib/commands/services.js +74 -8
  22. package/lib/commands/test.js +89 -1
  23. package/lib/connection-catalog.json +1185 -0
  24. package/lib/dev-simulator.js +137 -3
  25. package/lib/manifest.js +90 -6
  26. package/package.json +1 -1
  27. package/template-fallback/package.json +1 -1
  28. package/template-fallback/templates/agent-tool/README.md +6 -2
  29. package/template-fallback/templates/agent-tool/backend/api/main.py +27 -6
  30. package/template-fallback/templates/agent-tool/palette-plugin.json +35 -4
  31. package/template-fallback/templates/consumer-app/package.json +1 -1
  32. package/template-fallback/templates/dashboard/package.json +1 -1
  33. package/template-fallback/templates/database/package.json +1 -1
  34. package/template-fallback/templates/external-service/package.json +1 -1
  35. package/template-fallback/templates/frontend-only/package.json +1 -1
  36. package/template-fallback/templates/next/package.json +1 -1
  37. package/template-fallback/templates/palette-app/package.json +1 -1
  38. package/template-fallback/templates/provider-app/package.json +1 -1
  39. package/template-fallback/templates/agent-tool/backend/tools/echo.py +0 -15
package/lib/cli.js CHANGED
@@ -12,8 +12,11 @@ const status = require("./commands/status")
12
12
  const logs = require("./commands/logs")
13
13
  const secrets = require("./commands/secrets")
14
14
  const services = require("./commands/services")
15
+ const open = require("./commands/open")
15
16
  const version = require("./commands/version")
16
17
  const update = require("./commands/update")
18
+ const capabilities = require("./commands/capabilities")
19
+ const connections = require("./commands/connections")
17
20
 
18
21
  const COMMANDS = {
19
22
  init: { run: init, help: "Scaffold a new plugin directory from the template" },
@@ -49,14 +52,30 @@ const COMMANDS = {
49
52
  run: logs,
50
53
  help: "Tail telemetry events for a plugin (--follow to stream)",
51
54
  },
55
+ open: {
56
+ run: open,
57
+ help: "Open the last publish's preview URL in the browser",
58
+ },
52
59
  secrets: {
53
60
  run: secrets,
54
61
  help: "Initialize local env files and manage plugin-scope secrets",
55
62
  },
63
+ connections: {
64
+ run: connections,
65
+ help: "Use the OS service connections (list, add, pull, mock) — no OAuth of your own",
66
+ },
56
67
  services: {
57
68
  run: services,
58
69
  help: "Inspect / pull / scaffold OS-broker services (list, pull, scaffold)",
59
70
  },
71
+ capability: {
72
+ run: capabilities,
73
+ help: "Add, list, or inspect agent-callable app capabilities",
74
+ },
75
+ capabilities: {
76
+ run: capabilities,
77
+ help: "Add, list, or inspect agent-callable app capabilities",
78
+ },
60
79
  version: { run: version, help: "Show the installed pltt CLI version" },
61
80
  update: { run: update, help: "Update the globally installed pltt CLI" },
62
81
  }
@@ -77,13 +96,14 @@ function printHelp() {
77
96
  console.log("\nDev flags:")
78
97
  console.log(" --sandbox Publish a reviewable preview to a configured Palette sandbox (no Docker)")
79
98
  console.log(" --cloud Alias for --sandbox")
99
+ console.log(" --watch With --sandbox: live-push frontend changes onto the preview (no republish)")
80
100
  console.log(" --platform Internal only: run the Docker platform-dev parity container")
81
101
  console.log("\nLogin flags:")
82
102
  console.log(" --url <url> Palette platform URL for pltt login")
83
103
  console.log(" --token <token> Publish token for pltt login")
84
104
  console.log(" --no-default Do not make this environment the default")
85
105
  console.log("\nInit flags:")
86
- console.log(" --template <name> One of: dashboard, agent-tool, external-service, database, frontend-only, next")
106
+ console.log(" --template <name> One of: dashboard, agent-ready, agent-tool, external-service, database, frontend-only, next")
87
107
  console.log("\nLogs flags:")
88
108
  console.log(" --tail <n> Tail last n events (default 50)")
89
109
  console.log(" -f, --follow Stream events (poll every 3s)")
@@ -92,6 +112,10 @@ function printHelp() {
92
112
  console.log(" pltt services add TARGET # add a consumed service/event target")
93
113
  console.log(" pltt services pull # generate typed TS+Python clients from consumes")
94
114
  console.log(" pltt services scaffold NAME # add a provider method (schemas + handler stub)")
115
+ console.log("\nAgent capabilities:")
116
+ console.log(" pltt capabilities list")
117
+ console.log(" pltt capabilities inspect CAPABILITY_ID")
118
+ console.log(" pltt capabilities add creative.poster.generate --risk write --idempotent")
95
119
  console.log("\nSecrets:")
96
120
  console.log(" pltt secrets init")
97
121
  console.log(" pltt secrets set NAME --value <secret> --env staging")
@@ -103,7 +127,8 @@ function printHelp() {
103
127
  console.log(" cd my-app && pltt dev")
104
128
  console.log(" pltt sandbox --env staging")
105
129
  console.log(" pltt preview --env staging")
106
- console.log(" pltt dev --sandbox --env staging")
130
+ console.log(" pltt dev --sandbox --watch --env staging")
131
+ console.log(" pltt open")
107
132
  console.log(" pltt package")
108
133
  console.log(" pltt publish --env staging")
109
134
  console.log(" pltt status")
@@ -0,0 +1,151 @@
1
+ "use strict"
2
+
3
+ const { loadManifest } = require("../manifest")
4
+ const servicesCommand = require("./services")
5
+
6
+ function valueAfter(args, flag) {
7
+ const index = args.indexOf(flag)
8
+ return index === -1 ? null : args[index + 1] || null
9
+ }
10
+
11
+ function methodFromCapabilityId(capabilityId) {
12
+ const parts = String(capabilityId || "").split(".").filter(Boolean)
13
+ return parts.slice(-2).join(".") || "agent.action"
14
+ }
15
+
16
+ function collect(manifest) {
17
+ const out = []
18
+ for (const service of manifest.provides?.services || []) {
19
+ for (const method of service.methods || []) {
20
+ if (!method.agent_exposable) continue
21
+ out.push({
22
+ capability_id: method.capability_id || "app." + manifest.id + "." + method.name,
23
+ runtime_target: (manifest.provides?.namespace || manifest.id) + "/" + (service.version || "v1") + "#" + method.name,
24
+ name: method.name,
25
+ description: method.description || service.description || "",
26
+ risk: method.risk || (method.annotations?.readOnlyHint ? "read" : "write"),
27
+ effects: method.effects || [],
28
+ supports_scheduling: method.supports_scheduling !== false,
29
+ idempotent: method.idempotent === true,
30
+ timeout_seconds: method.timeout_seconds || 60,
31
+ tags: method.tags || [],
32
+ artifact_inputs: method.artifact_inputs || [],
33
+ artifact_outputs: method.artifact_outputs || [],
34
+ examples: method.examples || [],
35
+ cost_class: method.cost_class || null,
36
+ latency_class: method.latency_class || null,
37
+ deprecated: method.deprecated === true,
38
+ replacement: method.replacement || null,
39
+ input_schema: method.input_schema || method.input || null,
40
+ output_schema: method.output_schema || method.output || null,
41
+ source: "service",
42
+ })
43
+ }
44
+ }
45
+ for (const tool of manifest.mcp?.provides?.tools || []) {
46
+ if (!tool.agent_exposable) continue
47
+ out.push({
48
+ capability_id: tool.capability_id || "app." + manifest.id + "." + tool.name,
49
+ runtime_target: (manifest.provides?.namespace || manifest.id) + "/v1#" + tool.name,
50
+ name: tool.name,
51
+ description: tool.description || "",
52
+ risk: tool.risk || (tool.annotations?.readOnlyHint ? "read" : "write"),
53
+ effects: tool.effects || [],
54
+ supports_scheduling: tool.supports_scheduling !== false,
55
+ idempotent: tool.idempotent === true,
56
+ timeout_seconds: tool.timeout_seconds || 60,
57
+ tags: tool.tags || [],
58
+ artifact_inputs: tool.artifact_inputs || [],
59
+ artifact_outputs: tool.artifact_outputs || [],
60
+ examples: tool.examples || [],
61
+ cost_class: tool.cost_class || null,
62
+ latency_class: tool.latency_class || null,
63
+ deprecated: tool.deprecated === true,
64
+ replacement: tool.replacement || null,
65
+ input_schema: tool.input_schema || null,
66
+ output_schema: tool.output_schema || null,
67
+ source: "mcp",
68
+ })
69
+ }
70
+ for (const tool of manifest.tools || []) {
71
+ out.push({
72
+ capability_id: "app." + manifest.id + "." + tool.name,
73
+ name: tool.name,
74
+ description: tool.description || "",
75
+ risk: "unknown",
76
+ effects: [],
77
+ supports_scheduling: false,
78
+ idempotent: false,
79
+ timeout_seconds: null,
80
+ tags: [],
81
+ artifact_inputs: [],
82
+ artifact_outputs: [],
83
+ examples: [],
84
+ cost_class: null,
85
+ latency_class: null,
86
+ deprecated: true,
87
+ replacement: "@capability plus provides.services",
88
+ input_schema: null,
89
+ output_schema: null,
90
+ source: "legacy",
91
+ })
92
+ }
93
+ return out
94
+ }
95
+
96
+ async function run(args, { cwd }) {
97
+ const manifest = loadManifest(cwd)
98
+ const json = args.includes("--json")
99
+ const positional = args.filter((arg) => !arg.startsWith("-"))
100
+ const command = positional[0] || "list"
101
+ const id = command === "inspect" ? positional[1] : null
102
+ if (command === "add") {
103
+ const capabilityId = positional[1]
104
+ if (!capabilityId || !/^[a-z][a-z0-9_-]*(\.[a-z0-9_-]+){2,}$/.test(capabilityId)) {
105
+ throw new Error("usage: pltt capabilities add <domain.resource.action> [--method name] [--risk read|write|destructive|controlled] [--effects a,b] [--idempotent] [--no-scheduling]")
106
+ }
107
+ const method = valueAfter(args, "--method") || methodFromCapabilityId(capabilityId)
108
+ const risk = valueAfter(args, "--risk") || "read"
109
+ if (["write", "destructive"].includes(risk) && !args.includes("--idempotent") && !args.includes("--no-scheduling")) {
110
+ throw new Error("scheduled write capabilities require --idempotent, or use --no-scheduling for interactive-only actions")
111
+ }
112
+ const forwarded = [method, "--agent", "--capability-id", capabilityId]
113
+ for (const flag of ["--risk", "--effects"]) {
114
+ const value = valueAfter(args, flag)
115
+ if (value) forwarded.push(flag, value)
116
+ }
117
+ for (const flag of ["--idempotent", "--no-scheduling"]) {
118
+ if (args.includes(flag)) forwarded.push(flag)
119
+ }
120
+ await servicesCommand.runScaffold(forwarded, { cwd })
121
+ console.log("[pltt] agent capability ready; implement the generated handler, then run `pltt test --agent`")
122
+ return
123
+ }
124
+ const capabilities = collect(manifest)
125
+
126
+ if (command === "inspect") {
127
+ const item = capabilities.find((entry) => entry.capability_id === id || entry.name === id)
128
+ if (!item) throw new Error("capability not found: " + (id || "(missing id)"))
129
+ console.log(JSON.stringify(item, null, 2))
130
+ return
131
+ }
132
+ if (command !== "list") throw new Error("usage: pltt capabilities [list | inspect <id> | add <id>] [--json]")
133
+ if (json) {
134
+ console.log(JSON.stringify({ app_id: manifest.id, capabilities }, null, 2))
135
+ return
136
+ }
137
+ if (!capabilities.length) {
138
+ console.log("[pltt] no agent-exposable capabilities declared")
139
+ console.log("[pltt] expose a provides.services method with agent_exposable=true and a stable capability_id")
140
+ return
141
+ }
142
+ console.log("Capabilities for " + manifest.id + "@" + manifest.version)
143
+ for (const item of capabilities) {
144
+ const scheduling = item.supports_scheduling ? "scheduled" : "interactive-only"
145
+ console.log(" " + item.capability_id + " " + item.risk + ", " + scheduling)
146
+ console.log(" " + item.name + (item.description ? " - " + item.description : ""))
147
+ }
148
+ }
149
+
150
+ module.exports = run
151
+ module.exports.collect = collect
@@ -0,0 +1,234 @@
1
+ "use strict"
2
+
3
+ /**
4
+ * pltt connections — use the OS service connections from your app.
5
+ *
6
+ * Your app never does its own OAuth and never holds a provider token. The user
7
+ * connects Google/Slack/… once in Palette Connect; your app declares the tools
8
+ * it needs, the user grants them, and the platform proxies every call (keeping
9
+ * the scope check, write approval and audit trail).
10
+ *
11
+ * pltt connections list — providers + tools, and what you declare
12
+ * pltt connections add <provider> [--tools a,b]
13
+ * — write the connections block
14
+ * pltt connections pull — generate typed stubs for your app
15
+ * pltt connections mock <provider>.<tool> [--result '{...}']
16
+ * — seed a pltt dev response
17
+ */
18
+
19
+ const fs = require("fs")
20
+ const path = require("path")
21
+
22
+ const CATALOG = require("../connection-catalog.json")
23
+
24
+ function readManifest(cwd) {
25
+ const p = path.join(cwd, "palette-plugin.json")
26
+ if (!fs.existsSync(p)) throw new Error("no palette-plugin.json found in current directory")
27
+ return JSON.parse(fs.readFileSync(p, "utf8"))
28
+ }
29
+
30
+ function writeManifest(cwd, manifest) {
31
+ fs.writeFileSync(path.join(cwd, "palette-plugin.json"), JSON.stringify(manifest, null, 2) + "\n")
32
+ }
33
+
34
+ function provider(slug) {
35
+ return CATALOG.providers.find((p) => p.slug === slug) || null
36
+ }
37
+
38
+ function declaredTools(spec) {
39
+ const known = provider(spec.provider)
40
+ if (!known) return []
41
+ const asked = (spec.tools || []).filter((t) => known.tools.some((k) => k.name === t))
42
+ if (asked.length) return asked
43
+ return known.tools.filter((t) => !t.mutating).map((t) => t.name)
44
+ }
45
+
46
+ function valueAfter(argv, flag) {
47
+ const i = argv.indexOf(flag)
48
+ return i >= 0 ? argv[i + 1] : undefined
49
+ }
50
+
51
+ // ---- list --------------------------------------------------------------------
52
+
53
+ async function runList(argv, { cwd }) {
54
+ let declared = new Map()
55
+ try {
56
+ for (const spec of readManifest(cwd).connections || []) {
57
+ declared.set(spec.provider, new Set(declaredTools(spec)))
58
+ }
59
+ } catch {
60
+ // Outside an app directory — just print the catalog.
61
+ }
62
+ const verbose = argv.includes("--tools") || argv.includes("-v")
63
+ for (const p of CATALOG.providers) {
64
+ const mine = declared.get(p.slug)
65
+ const mark = mine ? `declared (${mine.size} tool${mine.size === 1 ? "" : "s"})` : "not declared"
66
+ console.log(`\n${p.slug.padEnd(10)} ${p.label.padEnd(22)} ${p.auth_type.padEnd(10)} ${mark}`)
67
+ if (!verbose && !mine) {
68
+ console.log(` ${p.tools.length} tools — pltt connections list --tools to see them`)
69
+ continue
70
+ }
71
+ for (const tool of p.tools) {
72
+ const flag = mine?.has(tool.name) ? "✓" : " "
73
+ const write = tool.mutating ? " [write]" : ""
74
+ console.log(` ${flag} ${tool.name}${write}`)
75
+ }
76
+ }
77
+ console.log("\nWrite tools stage for approval unless an org admin allows them for your app.")
78
+ }
79
+
80
+ // ---- add ---------------------------------------------------------------------
81
+
82
+ async function runAdd(argv, { cwd }) {
83
+ const slug = argv.find((a) => !a.startsWith("-"))
84
+ const known = provider(slug)
85
+ if (!known) {
86
+ console.error(
87
+ `[pltt] usage: pltt connections add <${CATALOG.providers.map((p) => p.slug).join("|")}> [--tools a,b]`,
88
+ )
89
+ process.exit(1)
90
+ }
91
+ const requested = (valueAfter(argv, "--tools") || "")
92
+ .split(",")
93
+ .map((t) => t.trim())
94
+ .filter(Boolean)
95
+ const unknown = requested.filter((t) => !known.tools.some((k) => k.name === t))
96
+ if (unknown.length) {
97
+ console.error(`[pltt] unknown ${slug} tool(s): ${unknown.join(", ")}`)
98
+ console.error(`[pltt] see: pltt connections list --tools`)
99
+ process.exit(1)
100
+ }
101
+
102
+ const manifest = readManifest(cwd)
103
+ manifest.connections = manifest.connections || []
104
+ // The platform resolves a grant by provider, so one entry per provider.
105
+ let spec = manifest.connections.find((c) => c && c.provider === slug)
106
+ if (!spec) {
107
+ spec = { id: slug, provider: slug, label: known.label, auth: known.auth_type === "bot_token" ? "api_key" : "oauth2" }
108
+ manifest.connections.push(spec)
109
+ }
110
+ if (requested.length) {
111
+ spec.tools = Array.from(new Set([...(spec.tools || []), ...requested]))
112
+ }
113
+ writeManifest(cwd, manifest)
114
+ const effective = declaredTools(spec)
115
+ console.log(`[pltt] ${slug}: ${effective.length} tool(s) declared`)
116
+ if (!spec.tools) console.log(`[pltt] no --tools given — defaults to every read-only ${slug} tool`)
117
+ console.log(`[pltt] next: pltt connections pull`)
118
+ }
119
+
120
+ // ---- pull --------------------------------------------------------------------
121
+
122
+ function tsType(schemaType) {
123
+ return { integer: "number", number: "number", boolean: "boolean", array: "unknown[]", object: "Record<string, unknown>" }[schemaType] || "string"
124
+ }
125
+
126
+ function camel(value) {
127
+ const [head, ...rest] = value.split("_")
128
+ return head + rest.map((p) => p[0].toUpperCase() + p.slice(1)).join("")
129
+ }
130
+
131
+ function renderStubs(specs) {
132
+ const lines = [
133
+ "// GENERATED by `pltt connections pull` — do not edit by hand.",
134
+ "//",
135
+ "// Only the tools your palette-plugin.json declares. The platform holds the",
136
+ "// OAuth token and enforces scopes, write approval and audit on every call.",
137
+ "",
138
+ 'import { palette } from "@palettelab/sdk"',
139
+ "",
140
+ ]
141
+ for (const spec of specs) {
142
+ const known = provider(spec.provider)
143
+ const allowed = new Set(declaredTools(spec))
144
+ for (const tool of known.tools.filter((t) => allowed.has(t.name))) {
145
+ const props = Object.entries(tool.input_schema?.properties || {})
146
+ const required = new Set(tool.input_schema?.required || [])
147
+ const fields = props
148
+ .sort(([a], [b]) => (required.has(b) ? 1 : 0) - (required.has(a) ? 1 : 0) || a.localeCompare(b))
149
+ .map(([name, s]) => `${camel(name)}${required.has(name) ? "" : "?"}: ${tsType(s.type)}`)
150
+ const argMap = props.map(([name]) => `"${name}": args.${camel(name)}`).join(", ")
151
+ const fn = camel(`${tool.namespace}_${tool.method}`)
152
+ lines.push(
153
+ `/** ${tool.description.replace(/\*\//g, "*\\/")}${tool.mutating ? " [write — stages for approval]" : ""} */`,
154
+ `export function ${fn}(${fields.length ? `args: { ${fields.join("; ")} }` : ""}): Promise<unknown> {`,
155
+ ` return palette.connections.call("${spec.provider}", "${tool.name}", ${fields.length ? `{ ${argMap} }` : "{}"})`,
156
+ "}",
157
+ "",
158
+ )
159
+ }
160
+ }
161
+ return lines.join("\n")
162
+ }
163
+
164
+ async function runPull(_argv, { cwd }) {
165
+ const specs = (readManifest(cwd).connections || []).filter((c) => provider(c.provider))
166
+ if (!specs.length) {
167
+ console.log("[pltt] no live connections declared — pltt connections add <provider>")
168
+ return
169
+ }
170
+ const outDir = path.join(cwd, ".palette", "types")
171
+ fs.mkdirSync(outDir, { recursive: true })
172
+ const outFile = path.join(outDir, "connections.ts")
173
+ fs.writeFileSync(outFile, renderStubs(specs))
174
+ const count = specs.reduce((n, s) => n + declaredTools(s).length, 0)
175
+ console.log(`[pltt] wrote ${count} typed helper(s) -> ${path.relative(cwd, outFile)}`)
176
+ console.log("[pltt] python: ctx.connections.<namespace>.<tool>(...) is already typed by palette-sdk")
177
+ }
178
+
179
+ // ---- mock --------------------------------------------------------------------
180
+
181
+ async function runMock(argv, { cwd }) {
182
+ const target = argv.find((a) => !a.startsWith("-"))
183
+ const [slug, ...rest] = (target || "").split(".")
184
+ const toolName = rest.join(".")
185
+ const known = provider(slug)
186
+ const tool = known?.tools.find((t) => t.name === toolName || t.method === toolName)
187
+ if (!tool) {
188
+ console.error("[pltt] usage: pltt connections mock <provider>.<tool> e.g. google.gmail.search")
189
+ process.exit(1)
190
+ }
191
+ let result = { ok: true, mocked: tool.name }
192
+ const raw = valueAfter(argv, "--result")
193
+ if (raw) {
194
+ try {
195
+ result = JSON.parse(raw)
196
+ } catch (err) {
197
+ console.error(`[pltt] --result must be JSON: ${err.message}`)
198
+ process.exit(1)
199
+ }
200
+ }
201
+
202
+ const mockPath = path.join(cwd, ".palette", "connections.local.json")
203
+ fs.mkdirSync(path.dirname(mockPath), { recursive: true })
204
+ const current = fs.existsSync(mockPath) ? JSON.parse(fs.readFileSync(mockPath, "utf8")) : {}
205
+ // Keyed by the manifest connection id so it merges with the status overrides
206
+ // the dev simulator already reads.
207
+ const spec = (readManifest(cwd).connections || []).find((c) => c.provider === slug)
208
+ const key = spec?.id || slug
209
+ current[key] = { ...(current[key] || {}), provider: slug, status: "connected" }
210
+ current[key].tools = { ...(current[key].tools || {}), [tool.name]: result }
211
+ fs.writeFileSync(mockPath, JSON.stringify(current, null, 2) + "\n")
212
+ console.log(`[pltt] mocked ${slug}.${tool.name} -> ${path.relative(cwd, mockPath)}`)
213
+ }
214
+
215
+ // ---- entry -------------------------------------------------------------------
216
+
217
+ module.exports = async function connections(argv, ctx) {
218
+ const [sub, ...rest] = argv
219
+ if (sub === "list") return runList(rest, ctx)
220
+ if (sub === "add") return runAdd(rest, ctx)
221
+ if (sub === "pull") return runPull(rest, ctx)
222
+ if (sub === "mock") return runMock(rest, ctx)
223
+ console.log("pltt connections <command>\n")
224
+ console.log(" list Show OS providers + tools, and which your app declares.")
225
+ console.log(" add Declare a provider (and tools) in palette-plugin.json.")
226
+ console.log(" pull Generate typed helpers for the tools you declared.")
227
+ console.log(" mock Seed a local response for pltt dev.")
228
+ console.log("\nYour app never does its own OAuth: the user connects once in Palette")
229
+ console.log("Connect, grants your app, and the platform proxies every call.")
230
+ if (sub && !["help", "--help", "-h"].includes(sub)) {
231
+ console.error(`\n[pltt] unknown subcommand: ${sub}`)
232
+ process.exit(1)
233
+ }
234
+ }
@@ -3,8 +3,9 @@
3
3
  const fs = require("fs")
4
4
  const path = require("path")
5
5
  const { spawn, spawnSync } = require("child_process")
6
+ const crypto = require("crypto")
6
7
  const { loadManifest } = require("../manifest")
7
- const { watchFrontend } = require("../bundler")
8
+ const { watchFrontend, watchFrontendBuffer } = require("../bundler")
8
9
  const { parseFlags, resolveEnvironment } = require("../environments")
9
10
  const { resolveDevPorts } = require("../ports")
10
11
  const { startSimulator } = require("../dev-simulator")
@@ -127,6 +128,70 @@ function writePlatformEnvFile(cwd, localEnv) {
127
128
  return envPath
128
129
  }
129
130
 
131
+ // `pltt dev --sandbox --watch`: keep rebuilding the frontend and PUT each
132
+ // bundle onto the preview publish. Frontend-only — backend changes still need
133
+ // a full re-run. Watch iterations skip `pltt test` by design (the initial
134
+ // publish already ran it).
135
+ async function startPreviewWatch({ cwd, flags, record, json }) {
136
+ const manifest = loadManifest(cwd)
137
+ if (!manifest.frontend?.entry) {
138
+ console.log("[pltt] --watch: manifest has no frontend entry; nothing to watch")
139
+ return
140
+ }
141
+ const envName = flags.env || process.env.PALETTE_ENV || "staging"
142
+ const env = resolveEnvironment({ cwd, flags: { ...flags, env: envName } })
143
+ let lastSha = null
144
+ let stopped = false
145
+ const pluginId = record.plugin_id || manifest.id
146
+
147
+ if (!json) {
148
+ console.log(`[pltt] watching ${manifest.frontend.entry} — frontend-only live updates (backend changes need a re-run)`)
149
+ }
150
+
151
+ await watchFrontendBuffer(
152
+ cwd,
153
+ manifest.frontend.entry,
154
+ { ...manifest.frontend, pluginId },
155
+ (bundle) => {
156
+ if (stopped) return
157
+ const sha = crypto.createHash("sha256").update(bundle).digest("hex")
158
+ if (lastSha === null) {
159
+ // Initial watch build — identical to the bundle just published.
160
+ lastSha = sha
161
+ return
162
+ }
163
+ if (sha === lastSha) return
164
+ fetch(`${env.url}/api/v1/appstore/previews/${record.id}/frontend`, {
165
+ method: "PUT",
166
+ headers: {
167
+ Authorization: `Bearer ${env.token}`,
168
+ "Content-Type": "application/javascript",
169
+ },
170
+ body: bundle,
171
+ })
172
+ .then(async (res) => {
173
+ if (res.ok) {
174
+ lastSha = sha
175
+ console.log(`[pltt] frontend pushed (${sha.slice(0, 12)}…) — preview reloads within ~4s`)
176
+ return
177
+ }
178
+ const body = await res.json().catch(() => ({}))
179
+ const detail = typeof body.detail === "string" ? body.detail : res.statusText
180
+ if (res.status === 410) {
181
+ console.error("[pltt] preview expired — re-run `pltt dev --sandbox --watch` to publish a fresh one")
182
+ stopped = true
183
+ return
184
+ }
185
+ console.error(`[pltt] frontend push failed (${res.status}): ${detail}`)
186
+ if (res.status === 403) stopped = true
187
+ })
188
+ .catch((err) => {
189
+ console.error(`[pltt] frontend push failed: ${err instanceof Error ? err.message : String(err)}`)
190
+ })
191
+ },
192
+ )
193
+ }
194
+
130
195
  async function run(args, { cwd }) {
131
196
  notifyIfUpdateAvailable(args).catch(() => {})
132
197
  const { flags, rest } = parseFlags(args)
@@ -154,6 +219,10 @@ async function run(args, { cwd }) {
154
219
  if (!json && record?.preview_url) {
155
220
  console.log(`[pltt] preview URL: ${record.preview_url}`)
156
221
  }
222
+ const watching = rest.includes("--watch") && record?.id
223
+ if (watching) {
224
+ await startPreviewWatch({ cwd, flags, record, json })
225
+ }
157
226
  if (!json && record?.id) {
158
227
  const envName = flags.env || process.env.PALETTE_ENV || "staging"
159
228
  console.log(`[pltt] status: pltt status ${record.id} --env ${envName}`)
@@ -172,6 +241,11 @@ async function run(args, { cwd }) {
172
241
  console.warn(`[pltt] run manually: pltt logs ${logPluginId} --follow --env ${envName}`)
173
242
  }
174
243
  }
244
+ if (watching) {
245
+ // Keep the process (and the frontend watcher) alive even when log
246
+ // streaming is unavailable or --json suppressed it. Ctrl+C to stop.
247
+ await new Promise(() => {})
248
+ }
175
249
  return
176
250
  }
177
251
 
@@ -28,6 +28,74 @@ function fail(message, fix) {
28
28
  return 1
29
29
  }
30
30
 
31
+ // What the platform lends this app, and what it looks like under `pltt dev`.
32
+ const PLATFORM_SERVICE_DEV_NOTES = {
33
+ llm: (cwd) =>
34
+ process.env.OPENAI_API_KEY || localEnvHas(cwd, "OPENAI_API_KEY")
35
+ ? "pltt dev: live via your OPENAI_API_KEY"
36
+ : "pltt dev: stubbed — set OPENAI_API_KEY for real calls (hosted uses the platform key)",
37
+ web: () => "pltt dev: keyless DuckDuckGo (hosted uses the platform search key)",
38
+ redis: () => "pltt dev: in-memory",
39
+ vector: () => "pltt dev: in-memory hash embeddings",
40
+ storage: () => "pltt dev: .palette/dev-storage",
41
+ }
42
+
43
+ function localEnvHas(cwd, name) {
44
+ try {
45
+ return Boolean(loadLocalEnvDetails(cwd, { apply: false }).values[name])
46
+ } catch {
47
+ return false
48
+ }
49
+ }
50
+
51
+ function reportPlatformServices(manifest, cwd) {
52
+ const declared = manifest.platform_services
53
+ const names = Array.isArray(declared) ? declared : Object.keys(declared || {})
54
+ if (!names.length) {
55
+ ok("no platform services declared")
56
+ } else {
57
+ ok(`manifest declares ${names.length} platform service(s): ${names.join(", ")}`)
58
+ for (const name of names) {
59
+ const note = PLATFORM_SERVICE_DEV_NOTES[name]
60
+ if (note) console.log(` ctx.${name} — ${note(cwd)}`)
61
+ }
62
+ }
63
+
64
+ const conns = manifest.connections || []
65
+ if (!conns.length) {
66
+ ok("no service connections declared")
67
+ return
68
+ }
69
+ const catalog = require("../connection-catalog.json")
70
+ const mockPath = path.join(cwd, ".palette", "connections.local.json")
71
+ let mocks = {}
72
+ try {
73
+ mocks = fs.existsSync(mockPath) ? JSON.parse(fs.readFileSync(mockPath, "utf8")) : {}
74
+ } catch {
75
+ mocks = {}
76
+ }
77
+ for (const spec of conns) {
78
+ const known = catalog.providers.find((p) => p.slug === spec.provider)
79
+ if (!known) {
80
+ warn(
81
+ `connection '${spec.id}' uses legacy provider '${spec.provider}'`,
82
+ "Legacy providers have no OS connection — the app must supply its own credentials.",
83
+ )
84
+ continue
85
+ }
86
+ const asked = (spec.tools || []).length
87
+ const label = asked ? `${asked} tool(s)` : `every read-only ${spec.provider} tool`
88
+ ok(`connection '${spec.id}' → ${known.label}, ${label}`)
89
+ const mocked = Object.keys(mocks[spec.id]?.tools || {}).length
90
+ if (!mocked) {
91
+ warn(
92
+ `no local responses mocked for ${spec.provider}`,
93
+ `pltt connections mock ${spec.provider}.<tool> — otherwise pltt dev raises on the call.`,
94
+ )
95
+ }
96
+ }
97
+ }
98
+
31
99
  function nodeMajor() {
32
100
  return Number(process.versions.node.split(".")[0])
33
101
  }
@@ -121,6 +189,8 @@ async function run(args, { cwd }) {
121
189
  failures += checkEntry(cwd, `tool[${tool.name}]`, tool.entry)
122
190
  }
123
191
 
192
+ reportPlatformServices(manifest, cwd)
193
+
124
194
  const secrets = declaredSecrets(manifest)
125
195
  const localEnv = loadLocalEnvDetails(cwd, { apply: false })
126
196
  const localSecrets = localEnv.values
@@ -10,7 +10,7 @@ const DEFAULT_TEMPLATE_REPO = "palette-lab/plugin-template"
10
10
  const TEMPLATE_REPO = process.env.PALETTE_TEMPLATE_REPO || DEFAULT_TEMPLATE_REPO
11
11
  const TEMPLATE_REF = process.env.PALETTE_TEMPLATE_REF || "main"
12
12
 
13
- const KNOWN_TEMPLATES = ["frontend-only", "palette-app", "next", "dashboard", "agent-tool", "external-service", "database", "provider-app", "consumer-app"]
13
+ const KNOWN_TEMPLATES = ["frontend-only", "palette-app", "next", "dashboard", "agent-tool", "agent-ready", "external-service", "database", "provider-app", "consumer-app"]
14
14
 
15
15
  function toSlug(name) {
16
16
  return name
@@ -39,7 +39,8 @@ function fetchTemplate(destDir) {
39
39
 
40
40
  function copyLocalFallback(destDir, template) {
41
41
  if (template) {
42
- const tplDir = path.resolve(__dirname, "..", "..", "template-fallback", "templates", template)
42
+ const resolvedTemplate = template === "agent-ready" ? "agent-tool" : template
43
+ const tplDir = path.resolve(__dirname, "..", "..", "template-fallback", "templates", resolvedTemplate)
43
44
  if (!fs.existsSync(tplDir)) return false
44
45
  fs.cpSync(tplDir, destDir, { recursive: true })
45
46
  return true