@palettelab/cli 0.3.70 → 0.3.71
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/README.md +103 -0
- package/backend-sdk/palette_sdk/__init__.py +3 -2
- package/backend-sdk/palette_sdk/jobs.py +18 -0
- package/backend-sdk/pyproject.toml +1 -1
- package/lib/acp.js +267 -0
- package/lib/agent-client.js +176 -0
- package/lib/cli.js +8 -1
- package/lib/commands/agent.js +763 -0
- package/lib/commands/check.js +106 -0
- package/package.json +1 -1
- package/template-fallback/package.json +1 -1
- package/template-fallback/templates/consumer-app/package.json +1 -1
- package/template-fallback/templates/dashboard/package.json +1 -1
- package/template-fallback/templates/database/package.json +1 -1
- package/template-fallback/templates/external-service/package.json +1 -1
- package/template-fallback/templates/frontend-only/package.json +1 -1
- package/template-fallback/templates/next/package.json +1 -1
- package/template-fallback/templates/palette-app/package.json +1 -1
- package/template-fallback/templates/provider-app/package.json +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
// `pltt check`: the contract gate of `pltt test` as structured diagnostics — one entry per problem, with a stable id,
|
|
4
|
+
// severity, file, line and column where the check knows them — for coding agents and editors. It runs `pltt test
|
|
5
|
+
// --json` (the same child `pltt publish` runs as its preflight) and splits what that report holds as text: each
|
|
6
|
+
// esbuild error ("file:line:col: ERROR: text") becomes its own diagnostic, a Python traceback's innermost project
|
|
7
|
+
// frame gives the file and line of an import failure, and migration-lint and forbidden-import entries keep the file
|
|
8
|
+
// they name. `--files a b` keeps the diagnostics about those files (and the project-wide ones).
|
|
9
|
+
|
|
10
|
+
const path = require("path")
|
|
11
|
+
const { spawnSync } = require("child_process")
|
|
12
|
+
|
|
13
|
+
const USAGE = "usage: pltt check [--json] [--publish-type preview|release] [--files <path> ...]"
|
|
14
|
+
|
|
15
|
+
const IDS = [
|
|
16
|
+
[/^could not (create Python|install pyproject)/i, "toolchain.python"],
|
|
17
|
+
[/^manifest invalid/i, "manifest.invalid"],
|
|
18
|
+
[/^frontend bundle failed/i, "bundle.syntax"],
|
|
19
|
+
[/^backend import failed/i, "py.import"],
|
|
20
|
+
[/^forbidden platform import/i, "import.forbidden"],
|
|
21
|
+
[/has no require_permission/i, "route.ungated"],
|
|
22
|
+
[/^route uses undeclared permission/i, "permission.undeclared"],
|
|
23
|
+
[/^unknown permission/i, "permission.unknown"],
|
|
24
|
+
[/unused backend permissions/i, "permission.unused"],
|
|
25
|
+
[/capabilit|agent-exposable/i, "capability.parity"],
|
|
26
|
+
[/migration/i, "migration.lint"],
|
|
27
|
+
[/contains local secret/i, "secret.leak"],
|
|
28
|
+
[/secret .* (is missing|has no local value)|no local \.env/i, "secret.missing"],
|
|
29
|
+
[/lifecycle script|unsafe spec|broad spec|^pyproject dependency|package\.json/i, "deps.policy"],
|
|
30
|
+
[/SDK compatibility|platform compatibility/i, "compat.sdk"],
|
|
31
|
+
[/bundle exceeds size limit/i, "bundle.size"],
|
|
32
|
+
[/must be sandboxed|public route must start|backend entry not found/i, "manifest.invalid"],
|
|
33
|
+
[/is not newer than last release|semver bump/i, "version.bump"],
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
function idFor(result) {
|
|
37
|
+
if (result.code) return `migration.${result.code}`
|
|
38
|
+
const message = String(result.message || "")
|
|
39
|
+
const match = IDS.find(([pattern]) => pattern.test(message))
|
|
40
|
+
return match ? match[1] : "contract.check"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const ESBUILD = /([\w./@-]+\.(?:tsx|ts|jsx|js|css)):(\d+):(\d+): (?:ERROR|error): ([^\n]+)/g
|
|
44
|
+
const PY_FRAME = /File "([^"]+)", line (\d+)/g
|
|
45
|
+
|
|
46
|
+
function diagnosticsFor(result, cwd) {
|
|
47
|
+
const severity = result.status === "fail" ? "error" : result.status === "warn" ? "warning" : null
|
|
48
|
+
if (!severity) return []
|
|
49
|
+
const base = { id: idFor(result), severity, message: String(result.message || ""), ...(result.fix ? { fix: result.fix } : {}) }
|
|
50
|
+
const text = `${result.message || ""}\n${result.details || ""}`
|
|
51
|
+
const bundle = [...text.matchAll(ESBUILD)]
|
|
52
|
+
if (bundle.length) {
|
|
53
|
+
return bundle.map((m) => ({ ...base, file: m[1], line: Number(m[2]), column: Number(m[3]), message: m[4].trim() }))
|
|
54
|
+
}
|
|
55
|
+
if (base.id === "py.import" && result.stderr) {
|
|
56
|
+
const frames = [...String(result.stderr).matchAll(PY_FRAME)]
|
|
57
|
+
.map((m) => ({ file: path.relative(cwd, m[1]), line: Number(m[2]) }))
|
|
58
|
+
.filter((f) => !f.file.startsWith("..") && !f.file.includes("site-packages") && !path.isAbsolute(f.file))
|
|
59
|
+
const inner = frames[frames.length - 1]
|
|
60
|
+
const last = String(result.stderr).trim().split("\n").pop()
|
|
61
|
+
return [{ ...base, ...(inner || {}), message: last ? `${base.message}: ${last}` : base.message }]
|
|
62
|
+
}
|
|
63
|
+
if (result.file) {
|
|
64
|
+
const file = String(result.file).includes("/") || !result.code ? String(result.file) : `backend/migrations/versions/${result.file}`
|
|
65
|
+
return [{ ...base, file }]
|
|
66
|
+
}
|
|
67
|
+
return [base]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function runTest(cwd, publishType) {
|
|
71
|
+
const cliBin = path.resolve(__dirname, "..", "..", "bin", "pltt.js")
|
|
72
|
+
const res = spawnSync(process.execPath, [cliBin, "test", "--json", "--publish-type", publishType], { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 })
|
|
73
|
+
const out = res.stdout || ""
|
|
74
|
+
const start = out.indexOf("{")
|
|
75
|
+
if (start < 0) {
|
|
76
|
+
return { ok: false, results: [{ status: "fail", message: (res.stderr || out || "pltt test produced no report").trim().split("\n")[0] }] }
|
|
77
|
+
}
|
|
78
|
+
return JSON.parse(out.slice(start, out.lastIndexOf("}") + 1))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function run(argv, { cwd = process.cwd(), log = console.log, test = runTest } = {}) {
|
|
82
|
+
const json = argv.includes("--json")
|
|
83
|
+
const typeAt = argv.indexOf("--publish-type")
|
|
84
|
+
const publishType = typeAt >= 0 ? argv[typeAt + 1] : "preview"
|
|
85
|
+
if (!["preview", "release"].includes(publishType)) throw new Error(USAGE)
|
|
86
|
+
const filesAt = argv.indexOf("--files")
|
|
87
|
+
const files = filesAt >= 0 ? argv.slice(filesAt + 1).filter((a) => !a.startsWith("--")) : null
|
|
88
|
+
const report = test(cwd, publishType)
|
|
89
|
+
let diagnostics = (report.results || []).flatMap((result) => diagnosticsFor(result, cwd))
|
|
90
|
+
if (files && files.length) diagnostics = diagnostics.filter((d) => !d.file || files.includes(d.file))
|
|
91
|
+
const errors = diagnostics.filter((d) => d.severity === "error").length
|
|
92
|
+
const summary = { errors, warnings: diagnostics.length - errors }
|
|
93
|
+
if (json) {
|
|
94
|
+
log(JSON.stringify({ ok: errors === 0, diagnostics, summary }, null, 2))
|
|
95
|
+
} else {
|
|
96
|
+
for (const d of diagnostics) {
|
|
97
|
+
const where = d.file ? `${d.file}${d.line ? `:${d.line}${d.column ? `:${d.column}` : ""}` : ""}: ` : ""
|
|
98
|
+
log(`${where}${d.severity} ${d.id}: ${d.message}${d.fix ? `\n fix: ${d.fix}` : ""}`)
|
|
99
|
+
}
|
|
100
|
+
log(errors ? `[pltt] ${errors} error(s), ${summary.warnings} warning(s)` : `[pltt] check passed (${summary.warnings} warning(s))`)
|
|
101
|
+
}
|
|
102
|
+
if (errors) process.exitCode = 1
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
module.exports = run
|
|
106
|
+
module.exports.diagnosticsFor = diagnosticsFor
|
package/package.json
CHANGED