@autotelic/joggle 0.0.0-stage → 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.
- package/JOGGLE.md +634 -0
- package/LICENSE +21 -0
- package/README.md +88 -2
- package/bin/joggle.js +6 -0
- package/dist/answer-store.js +305 -0
- package/dist/architecture.js +190 -0
- package/dist/ask.js +184 -0
- package/dist/astro.js +75 -0
- package/dist/atoms.js +76 -0
- package/dist/bundles.js +156 -0
- package/dist/calibration.js +60 -0
- package/dist/candidates.js +561 -0
- package/dist/canonical.js +24 -0
- package/dist/cascade.js +98 -0
- package/dist/check.js +854 -0
- package/dist/cluster.js +69 -0
- package/dist/config.js +195 -0
- package/dist/content-mappers.js +83 -0
- package/dist/decision.js +203 -0
- package/dist/fingerprint.js +61 -0
- package/dist/git.js +127 -0
- package/dist/gitignore.js +65 -0
- package/dist/glob.js +51 -0
- package/dist/imports.js +153 -0
- package/dist/jsonc.js +95 -0
- package/dist/main.js +630 -0
- package/dist/manifest.js +42 -0
- package/dist/meta.js +170 -0
- package/dist/moves.js +47 -0
- package/dist/operation.js +133 -0
- package/dist/parsecache.js +264 -0
- package/dist/plans.js +425 -0
- package/dist/plugin.js +71 -0
- package/dist/plugins.js +136 -0
- package/dist/policy.js +676 -0
- package/dist/presets/composition.js +32 -0
- package/dist/report.js +474 -0
- package/dist/reporting.js +132 -0
- package/dist/result.js +28 -0
- package/dist/roles.js +303 -0
- package/dist/rule.js +194 -0
- package/dist/rules/append-only-honoured.js +190 -0
- package/dist/rules/bundle-conformance.js +245 -0
- package/dist/rules/call-pattern.js +209 -0
- package/dist/rules/cluster-verdict.js +700 -0
- package/dist/rules/compose-types.js +250 -0
- package/dist/rules/data-error-as-outage.js +482 -0
- package/dist/rules/declared-staleness.js +242 -0
- package/dist/rules/dependency-fit.js +297 -0
- package/dist/rules/deviation-has-a-shape.js +225 -0
- package/dist/rules/doc-matches-code.js +191 -0
- package/dist/rules/duplicate-call-run.js +240 -0
- package/dist/rules/duplicate-implementation.js +89 -0
- package/dist/rules/duplicate-meaning.js +130 -0
- package/dist/rules/fact-or-derivation.js +202 -0
- package/dist/rules/field-type-drift.js +373 -0
- package/dist/rules/generic-carries-a-caller.js +198 -0
- package/dist/rules/hoist-to-domain.js +288 -0
- package/dist/rules/import-architecture.js +393 -0
- package/dist/rules/index.js +105 -0
- package/dist/rules/inferred-over-recorded.js +214 -0
- package/dist/rules/intent-drift.js +286 -0
- package/dist/rules/invariant-has-a-reconciler.js +190 -0
- package/dist/rules/language-drift.js +234 -0
- package/dist/rules/meaning-switched-by-flag.js +189 -0
- package/dist/rules/module-direction.js +231 -0
- package/dist/rules/name-as-address.js +216 -0
- package/dist/rules/name-the-primitive.js +203 -0
- package/dist/rules/naming-drift.js +218 -0
- package/dist/rules/nullability-drift.js +220 -0
- package/dist/rules/object-shape.js +280 -0
- package/dist/rules/one-concept-one-type.js +243 -0
- package/dist/rules/page-needs-composition.js +227 -0
- package/dist/rules/reimplemented-primitive.js +283 -0
- package/dist/rules/reversal.js +264 -0
- package/dist/rules/rule-judgment.js +252 -0
- package/dist/rules/schema-excludes-domain-value.js +190 -0
- package/dist/rules/shallow-module.js +204 -0
- package/dist/rules/single-path.js +237 -0
- package/dist/rules/structural-collapse.js +198 -0
- package/dist/rules/temporal-coupling.js +205 -0
- package/dist/rules/types-over-logic.js +198 -0
- package/dist/rules/unaccounted-drop.js +190 -0
- package/dist/rules/unbounded-default-read.js +227 -0
- package/dist/run-cache.js +132 -0
- package/dist/schema.js +285 -0
- package/dist/similarity.js +119 -0
- package/dist/source.js +30 -0
- package/dist/sql.js +34 -0
- package/dist/stages.js +39 -0
- package/dist/state.js +65 -0
- package/dist/testing.js +131 -0
- package/dist/tsconfig-scope.js +32 -0
- package/dist/tsgo.js +127 -0
- package/dist/typefacts.js +455 -0
- package/dist/typetrace.js +283 -0
- package/dist/verdict.js +65 -0
- package/dist/vocabulary.js +365 -0
- package/dist/workspace.js +1963 -0
- package/extensions/joggle.ts +454 -0
- package/package.json +85 -3
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* joggle as a pi extension.
|
|
3
|
+
*
|
|
4
|
+
* joggle is a cross-file linter: it runs in a repository and reports the
|
|
5
|
+
* duplication, naming drift and architecture breaks a single file cannot see.
|
|
6
|
+
* This extension is a thin shell over the CLI in this repository, so pi can run
|
|
7
|
+
* it in whatever repository pi is working in:
|
|
8
|
+
*
|
|
9
|
+
* joggle_check run a scoped check and return the findings
|
|
10
|
+
* joggle_rules list what the current repository enforces
|
|
11
|
+
* /joggle run a check from the prompt line
|
|
12
|
+
*
|
|
13
|
+
* The extension is a pi package. `pi install /absolute/path/to/joggle` adds it
|
|
14
|
+
* globally, and `pi -e /absolute/path/to/joggle` loads it for one run.
|
|
15
|
+
*
|
|
16
|
+
* The report is built from the files on disk, never from a remote, so the
|
|
17
|
+
* changed scope is git's view of the local checkout. That is what makes "cut a
|
|
18
|
+
* PR, then iterate" work: the second run sees the edits made after the first.
|
|
19
|
+
*/
|
|
20
|
+
import { createHash } from "node:crypto"
|
|
21
|
+
import { existsSync } from "node:fs"
|
|
22
|
+
import { homedir } from "node:os"
|
|
23
|
+
import { dirname, join, resolve } from "node:path"
|
|
24
|
+
import { fileURLToPath } from "node:url"
|
|
25
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent"
|
|
26
|
+
import { Type } from "typebox"
|
|
27
|
+
|
|
28
|
+
/** The package this extension ships in: the directory above `extensions/`. */
|
|
29
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..")
|
|
30
|
+
|
|
31
|
+
/** The first `name` on PATH, if any. */
|
|
32
|
+
const onPath = (name: string): string | undefined => {
|
|
33
|
+
for (const dir of (process.env.PATH ?? "").split(":")) {
|
|
34
|
+
if (dir === "") continue
|
|
35
|
+
const candidate = join(dir, name)
|
|
36
|
+
if (existsSync(candidate)) return candidate
|
|
37
|
+
}
|
|
38
|
+
return undefined
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* How to invoke joggle.
|
|
43
|
+
*
|
|
44
|
+
* A `joggle` on PATH is the machine's own command, so it is preferred and pi and the shell
|
|
45
|
+
* get the same judged results. Otherwise the build in this checkout is used, falling back to
|
|
46
|
+
* the source with the `development` export condition. `JOGGLE_BIN` overrides all of it.
|
|
47
|
+
*
|
|
48
|
+
* The model key is not supplied here: this extension inherits pi's environment, and
|
|
49
|
+
* `pi.exec` children inherit it in turn, so the key belongs in the environment of whatever
|
|
50
|
+
* started pi (see SECRETS.md). With no key, judged rules replay the committed verdicts.
|
|
51
|
+
*/
|
|
52
|
+
const cli = (): { readonly command: string; readonly args: ReadonlyArray<string> } => {
|
|
53
|
+
const override = process.env.JOGGLE_BIN
|
|
54
|
+
if (override !== undefined && override !== "") return { command: override, args: [] }
|
|
55
|
+
const global = onPath("joggle")
|
|
56
|
+
if (global !== undefined) return { command: global, args: [] }
|
|
57
|
+
const built = join(root, "dist", "main.js")
|
|
58
|
+
if (existsSync(built)) return { command: process.execPath, args: [built] }
|
|
59
|
+
return {
|
|
60
|
+
command: process.execPath,
|
|
61
|
+
args: ["--conditions=development", join(root, "src", "main.ts")],
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface ExecOutcome {
|
|
66
|
+
readonly stdout: string
|
|
67
|
+
readonly stderr: string
|
|
68
|
+
readonly code: number
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const run = async (
|
|
72
|
+
pi: ExtensionAPI,
|
|
73
|
+
cwd: string,
|
|
74
|
+
args: ReadonlyArray<string>,
|
|
75
|
+
signal: AbortSignal | undefined,
|
|
76
|
+
): Promise<ExecOutcome> => {
|
|
77
|
+
const { command, args: prefix } = cli()
|
|
78
|
+
const result = await pi.exec(command, [...prefix, ...args], {
|
|
79
|
+
cwd,
|
|
80
|
+
...(signal === undefined ? {} : { signal }),
|
|
81
|
+
timeout: 120_000,
|
|
82
|
+
})
|
|
83
|
+
return { stdout: result.stdout, stderr: result.stderr, code: result.code }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The machine cache directory for one analysed root, matching the CLI's own
|
|
88
|
+
* layout so answers and the run cache sit together.
|
|
89
|
+
*/
|
|
90
|
+
const machineCache = (target: string): string => {
|
|
91
|
+
const base =
|
|
92
|
+
process.env.XDG_CACHE_HOME !== undefined && process.env.XDG_CACHE_HOME !== ""
|
|
93
|
+
? process.env.XDG_CACHE_HOME
|
|
94
|
+
: process.platform === "darwin"
|
|
95
|
+
? join(homedir(), "Library", "Caches")
|
|
96
|
+
: join(homedir(), ".cache")
|
|
97
|
+
const key = createHash("sha1").update(target).digest("hex").slice(0, 16)
|
|
98
|
+
return join(base, "joggle", key)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Where this run's answers go.
|
|
103
|
+
*
|
|
104
|
+
* `.joggle/answers/` is a committed artifact in a repository being
|
|
105
|
+
* onboarded, and a side effect in one being inspected. The extension is global
|
|
106
|
+
* and pi runs it in repositories it does not own, so it only writes the
|
|
107
|
+
* committed cache where one already exists; otherwise the answers go to the
|
|
108
|
+
* machine cache, beside the run cache the CLI already keeps there. Pass an
|
|
109
|
+
* explicit `cacheDir` to override.
|
|
110
|
+
*/
|
|
111
|
+
const answerCache = (target: string): string | undefined =>
|
|
112
|
+
existsSync(join(target, ".joggle")) ? undefined : machineCache(target)
|
|
113
|
+
|
|
114
|
+
/* -------------------------------------------------------------------------- */
|
|
115
|
+
/* Reading the report */
|
|
116
|
+
/* -------------------------------------------------------------------------- */
|
|
117
|
+
|
|
118
|
+
interface JsonLocation {
|
|
119
|
+
readonly file: string
|
|
120
|
+
readonly line: number
|
|
121
|
+
readonly column: number
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
interface JsonRepair {
|
|
125
|
+
readonly operation: string
|
|
126
|
+
readonly keep?: JsonLocation | undefined
|
|
127
|
+
readonly cascade: ReadonlyArray<unknown>
|
|
128
|
+
readonly settled: string
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
interface JsonDiagnostic {
|
|
132
|
+
readonly ruleId: string
|
|
133
|
+
readonly severity: string
|
|
134
|
+
readonly message: string
|
|
135
|
+
readonly help?: string | undefined
|
|
136
|
+
readonly location: JsonLocation
|
|
137
|
+
readonly judged: boolean
|
|
138
|
+
readonly repair?: JsonRepair | undefined
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface JsonNote {
|
|
142
|
+
readonly ruleId: string
|
|
143
|
+
readonly reason: string
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
interface JsonReport {
|
|
147
|
+
readonly diagnostics: ReadonlyArray<JsonDiagnostic>
|
|
148
|
+
readonly summary: {
|
|
149
|
+
readonly problems: number
|
|
150
|
+
readonly errors: number
|
|
151
|
+
readonly warnings: number
|
|
152
|
+
readonly infos: number
|
|
153
|
+
readonly files: number
|
|
154
|
+
readonly skipped: ReadonlyArray<JsonNote>
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The JSON report, rendered for a model.
|
|
160
|
+
*
|
|
161
|
+
* The default text format is for a person reading a terminal: it carries a
|
|
162
|
+
* census, a provenance line and a funnel of notes, and a model pays for all of
|
|
163
|
+
* it on every call. This keeps the finding, the help that says what to do about
|
|
164
|
+
* it, and the repair the rule proposes -- which is the material an agent needs
|
|
165
|
+
* in order to act -- and drops the rest.
|
|
166
|
+
*/
|
|
167
|
+
const render = (report: JsonReport, limit: number): string => {
|
|
168
|
+
const { summary } = report
|
|
169
|
+
const shown = limit > 0 ? report.diagnostics.slice(0, limit) : report.diagnostics
|
|
170
|
+
const lines = [
|
|
171
|
+
`${summary.problems} problem(s) (${summary.errors} error(s), ${summary.warnings} warning(s), ${summary.infos} notice(s)) across ${summary.files} file(s)`,
|
|
172
|
+
]
|
|
173
|
+
shown.forEach((diagnostic, index) => {
|
|
174
|
+
const { file, line, column } = diagnostic.location
|
|
175
|
+
const verified = diagnostic.judged ? "" : " (unverified)"
|
|
176
|
+
lines.push("")
|
|
177
|
+
lines.push(
|
|
178
|
+
`${index + 1}. [${diagnostic.severity}] ${diagnostic.ruleId} ${file}:${line}:${column}${verified}`,
|
|
179
|
+
)
|
|
180
|
+
lines.push(` ${diagnostic.message}`)
|
|
181
|
+
if (diagnostic.help !== undefined) lines.push(` help: ${diagnostic.help}`)
|
|
182
|
+
const repair = diagnostic.repair
|
|
183
|
+
if (repair !== undefined) {
|
|
184
|
+
const keep =
|
|
185
|
+
repair.keep === undefined ? "" : ` keep ${repair.keep.file}:${repair.keep.line}`
|
|
186
|
+
lines.push(
|
|
187
|
+
` repair: ${repair.operation}${keep} (${repair.cascade.length} edit(s); ${repair.settled})`,
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
// A tool result is context a model pays for on every call. A full-repository
|
|
192
|
+
// run can be thousands of findings; the total is the fact, the first N are
|
|
193
|
+
// the work.
|
|
194
|
+
if (shown.length < report.diagnostics.length) {
|
|
195
|
+
lines.push("")
|
|
196
|
+
lines.push(
|
|
197
|
+
`showing ${shown.length} of ${report.diagnostics.length} findings; narrow the scope, pass rule, or raise limit to see the rest`,
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
// A judged rule that never ran is the difference between "clean" and "not
|
|
201
|
+
// looked at", and a model reading the findings cannot tell the two apart.
|
|
202
|
+
if (summary.skipped.length > 0) {
|
|
203
|
+
lines.push("")
|
|
204
|
+
for (const skip of summary.skipped) lines.push(`note: ${skip.ruleId} skipped - ${skip.reason}`)
|
|
205
|
+
}
|
|
206
|
+
return lines.join("\n").trimEnd()
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const parse = (stdout: string): JsonReport | undefined => {
|
|
210
|
+
try {
|
|
211
|
+
const value = JSON.parse(stdout) as unknown
|
|
212
|
+
if (typeof value === "object" && value !== null && "diagnostics" in value) {
|
|
213
|
+
return value as JsonReport
|
|
214
|
+
}
|
|
215
|
+
return undefined
|
|
216
|
+
} catch {
|
|
217
|
+
return undefined
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* -------------------------------------------------------------------------- */
|
|
222
|
+
/* Tool results */
|
|
223
|
+
/* -------------------------------------------------------------------------- */
|
|
224
|
+
|
|
225
|
+
interface ToolResult {
|
|
226
|
+
readonly content: ReadonlyArray<{ readonly type: "text"; readonly text: string }>
|
|
227
|
+
readonly details: Record<string, unknown>
|
|
228
|
+
readonly isError?: boolean
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const ok = (text: string, details: Record<string, unknown>): ToolResult => ({
|
|
232
|
+
content: [{ type: "text", text }],
|
|
233
|
+
details,
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
const failed = (text: string, details: Record<string, unknown>): ToolResult => ({
|
|
237
|
+
content: [{ type: "text", text }],
|
|
238
|
+
details,
|
|
239
|
+
isError: true,
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
const reason = (error: unknown): string => (error instanceof Error ? error.message : String(error))
|
|
243
|
+
|
|
244
|
+
/* -------------------------------------------------------------------------- */
|
|
245
|
+
/* The check tool */
|
|
246
|
+
/* -------------------------------------------------------------------------- */
|
|
247
|
+
|
|
248
|
+
const scope = Type.Union(
|
|
249
|
+
[Type.Literal("changed"), Type.Literal("pr"), Type.Literal("since"), Type.Literal("all")],
|
|
250
|
+
{
|
|
251
|
+
description:
|
|
252
|
+
"What to scope the check to. 'changed' (default) is what moved since joggle last ran here; 'pr' is the current branch's pull request; 'since' needs a git revision; 'all' is the whole project.",
|
|
253
|
+
},
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
const checkParameters = Type.Object({
|
|
257
|
+
scope: Type.Optional(scope),
|
|
258
|
+
since: Type.Optional(
|
|
259
|
+
Type.String({ description: "Git revision to scope against when scope is 'since' (for example origin/main)." }),
|
|
260
|
+
),
|
|
261
|
+
prNumber: Type.Optional(
|
|
262
|
+
Type.String({ description: "A specific pull request, by number or URL, instead of the current branch's." }),
|
|
263
|
+
),
|
|
264
|
+
paths: Type.Optional(
|
|
265
|
+
Type.Array(Type.String(), {
|
|
266
|
+
description: "Files or directories to analyse. Default: whatever tsgo says the project is.",
|
|
267
|
+
}),
|
|
268
|
+
),
|
|
269
|
+
cwd: Type.Optional(
|
|
270
|
+
Type.String({
|
|
271
|
+
description:
|
|
272
|
+
"Repository to analyse, absolute or relative to pi's working directory. Default: the working directory pi is running in.",
|
|
273
|
+
}),
|
|
274
|
+
),
|
|
275
|
+
cacheDir: Type.Optional(
|
|
276
|
+
Type.String({
|
|
277
|
+
description:
|
|
278
|
+
"Where the answer cache lives. Default: the target's .joggle if it already has one, otherwise the machine cache, so a repository without one is never modified.",
|
|
279
|
+
}),
|
|
280
|
+
),
|
|
281
|
+
rule: Type.Optional(
|
|
282
|
+
Type.String({ description: "Only run these rule ids, comma-separated." }),
|
|
283
|
+
),
|
|
284
|
+
offline: Type.Optional(
|
|
285
|
+
Type.Boolean({ description: "Answer only from the committed judgement cache; never call the model." }),
|
|
286
|
+
),
|
|
287
|
+
maxWarnings: Type.Optional(
|
|
288
|
+
Type.Number({ description: "Treat more than this many warnings as a failing run." }),
|
|
289
|
+
),
|
|
290
|
+
limit: Type.Optional(
|
|
291
|
+
Type.Number({
|
|
292
|
+
description:
|
|
293
|
+
"Maximum findings to return; the total is always reported. Default 50, and 0 returns all of them.",
|
|
294
|
+
}),
|
|
295
|
+
),
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
interface CheckParameters {
|
|
299
|
+
readonly scope?: "changed" | "pr" | "since" | "all" | undefined
|
|
300
|
+
readonly since?: string | undefined
|
|
301
|
+
readonly prNumber?: string | undefined
|
|
302
|
+
readonly paths?: ReadonlyArray<string> | undefined
|
|
303
|
+
readonly cwd?: string | undefined
|
|
304
|
+
readonly cacheDir?: string | undefined
|
|
305
|
+
readonly rule?: string | undefined
|
|
306
|
+
readonly offline?: boolean | undefined
|
|
307
|
+
readonly maxWarnings?: number | undefined
|
|
308
|
+
readonly limit?: number | undefined
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const checkArgs = (params: CheckParameters, target: string): ReadonlyArray<string> => {
|
|
312
|
+
const args = ["check", "--format", "json"]
|
|
313
|
+
const chosen = params.scope ?? "changed"
|
|
314
|
+
if (chosen === "changed") {
|
|
315
|
+
args.push("--changed")
|
|
316
|
+
} else if (chosen === "pr") {
|
|
317
|
+
if (params.prNumber !== undefined) args.push("--pr-number", params.prNumber)
|
|
318
|
+
else args.push("--pr")
|
|
319
|
+
} else if (chosen === "since") {
|
|
320
|
+
if (params.since === undefined) throw new Error("scope 'since' needs a `since` revision")
|
|
321
|
+
args.push("--since", params.since)
|
|
322
|
+
}
|
|
323
|
+
if (params.paths !== undefined && params.paths.length > 0) args.push(...params.paths)
|
|
324
|
+
if (params.rule !== undefined) args.push("--rule", params.rule)
|
|
325
|
+
if (params.offline === true) args.push("--offline")
|
|
326
|
+
if (params.maxWarnings !== undefined) args.push("--max-warnings", String(params.maxWarnings))
|
|
327
|
+
// Non-invasive by default: a repository that has never been onboarded gets no
|
|
328
|
+
// `.joggle/` from a tool call.
|
|
329
|
+
if (params.cacheDir !== undefined) {
|
|
330
|
+
args.push("--cache-dir", params.cacheDir)
|
|
331
|
+
} else {
|
|
332
|
+
const fallback = answerCache(target)
|
|
333
|
+
if (fallback !== undefined) args.push("--cache-dir", fallback)
|
|
334
|
+
}
|
|
335
|
+
return args
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** The repository a tool call is about: its `cwd`, or pi's working directory. */
|
|
339
|
+
const targetFor = (params: { readonly cwd?: string | undefined }, ctx: ExtensionContext): string =>
|
|
340
|
+
params.cwd === undefined ? ctx.cwd : resolve(ctx.cwd, params.cwd)
|
|
341
|
+
|
|
342
|
+
/* -------------------------------------------------------------------------- */
|
|
343
|
+
/* The extension */
|
|
344
|
+
/* -------------------------------------------------------------------------- */
|
|
345
|
+
|
|
346
|
+
export default function (pi: ExtensionAPI): void {
|
|
347
|
+
pi.registerTool({
|
|
348
|
+
name: "joggle_check",
|
|
349
|
+
label: "joggle Check",
|
|
350
|
+
description:
|
|
351
|
+
"Run joggle over this repository and return cross-file duplication, naming drift and architecture findings. Scoped to what changed by default, so it answers what the current batch of work introduced. Returns at most 50 findings; pass `limit` to change that (`0` returns all of them) and the total is always reported.",
|
|
352
|
+
promptSnippet: "Find cross-file duplication and naming drift with joggle",
|
|
353
|
+
promptGuidelines: [
|
|
354
|
+
"Use joggle_check after a batch of edits to find new cross-file duplication and naming drift; it defaults to the changed scope.",
|
|
355
|
+
"Use joggle_check with scope 'pr' after cutting a pull request to see only what the pull request introduced.",
|
|
356
|
+
],
|
|
357
|
+
parameters: checkParameters,
|
|
358
|
+
async execute(
|
|
359
|
+
_toolCallId: string,
|
|
360
|
+
params: CheckParameters,
|
|
361
|
+
signal: AbortSignal | undefined,
|
|
362
|
+
_onUpdate: unknown,
|
|
363
|
+
ctx: ExtensionContext,
|
|
364
|
+
): Promise<ToolResult> {
|
|
365
|
+
try {
|
|
366
|
+
const target = targetFor(params, ctx)
|
|
367
|
+
const args = checkArgs(params, target)
|
|
368
|
+
const result = await run(pi, target, args, signal)
|
|
369
|
+
const report = parse(result.stdout)
|
|
370
|
+
if (report === undefined) {
|
|
371
|
+
const detail = (result.stderr.trim() === "" ? result.stdout : result.stderr).trim()
|
|
372
|
+
return failed(`joggle failed (exit ${result.code}): ${detail || "no output"}`, {
|
|
373
|
+
code: result.code,
|
|
374
|
+
command: args.join(" "),
|
|
375
|
+
})
|
|
376
|
+
}
|
|
377
|
+
const warning = result.stderr.trim()
|
|
378
|
+
const body = render(report, params.limit ?? 50)
|
|
379
|
+
return ok(warning === "" ? body : body + "\n\nnote: " + warning, {
|
|
380
|
+
code: result.code,
|
|
381
|
+
problems: report.summary.problems,
|
|
382
|
+
errors: report.summary.errors,
|
|
383
|
+
warnings: report.summary.warnings,
|
|
384
|
+
cwd: target,
|
|
385
|
+
command: args.join(" "),
|
|
386
|
+
})
|
|
387
|
+
} catch (error) {
|
|
388
|
+
return failed(`joggle could not run: ${reason(error)}`, { command: "joggle check" })
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
pi.registerTool({
|
|
394
|
+
name: "joggle_rules",
|
|
395
|
+
label: "joggle Rules",
|
|
396
|
+
description: "List the rules a repository enforces, with their severities.",
|
|
397
|
+
promptSnippet: "List the rules joggle enforces here",
|
|
398
|
+
parameters: Type.Object({
|
|
399
|
+
cwd: Type.Optional(
|
|
400
|
+
Type.String({
|
|
401
|
+
description:
|
|
402
|
+
"Repository to read, absolute or relative to pi's working directory. Default: the working directory pi is running in.",
|
|
403
|
+
}),
|
|
404
|
+
),
|
|
405
|
+
}),
|
|
406
|
+
async execute(
|
|
407
|
+
_toolCallId: string,
|
|
408
|
+
params: { readonly cwd?: string | undefined },
|
|
409
|
+
signal: AbortSignal | undefined,
|
|
410
|
+
_onUpdate: unknown,
|
|
411
|
+
ctx: ExtensionContext,
|
|
412
|
+
): Promise<ToolResult> {
|
|
413
|
+
try {
|
|
414
|
+
const target = targetFor(params, ctx)
|
|
415
|
+
const result = await run(pi, target, ["rules"], signal)
|
|
416
|
+
const text = (result.stdout.trim() === "" ? result.stderr : result.stdout).trim()
|
|
417
|
+
if (result.code !== 0) return failed(`joggle rules failed (exit ${result.code}): ${text}`, {})
|
|
418
|
+
const warning = result.stdout.trim() === "" ? "" : result.stderr.trim()
|
|
419
|
+
const body = text === "" ? "no rules configured" : text
|
|
420
|
+
return ok(warning === "" ? body : body + "\n\nnote: " + warning, {
|
|
421
|
+
cwd: target,
|
|
422
|
+
command: "joggle rules",
|
|
423
|
+
})
|
|
424
|
+
} catch (error) {
|
|
425
|
+
return failed(`joggle could not run: ${reason(error)}`, { command: "joggle rules" })
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
pi.registerCommand("joggle", {
|
|
431
|
+
description:
|
|
432
|
+
"Run a joggle check on this repository. Arguments pass through, e.g. /joggle --pr or /joggle --cwd ../other-repo --since origin/main.",
|
|
433
|
+
handler: async (args: string, ctx: ExtensionContext) => {
|
|
434
|
+
const extra = args.trim() === "" ? ["--changed"] : args.trim().split(/\s+/)
|
|
435
|
+
// `--cwd` names the repository the check is about; the cache rule follows
|
|
436
|
+
// it, so the command does not litter a checkout it was pointed at either.
|
|
437
|
+
const cwdIndex = extra.indexOf("--cwd")
|
|
438
|
+
const named = cwdIndex === -1 ? undefined : extra[cwdIndex + 1]
|
|
439
|
+
const target = named === undefined ? ctx.cwd : resolve(ctx.cwd, named)
|
|
440
|
+
const argv = [...extra]
|
|
441
|
+
if (!argv.includes("--cache-dir")) {
|
|
442
|
+
const fallback = answerCache(target)
|
|
443
|
+
if (fallback !== undefined) argv.push("--cache-dir", fallback)
|
|
444
|
+
}
|
|
445
|
+
try {
|
|
446
|
+
const result = await run(pi, ctx.cwd, ["check", ...argv], ctx.signal)
|
|
447
|
+
const text = (result.stdout.trim() === "" ? result.stderr : result.stdout).trim()
|
|
448
|
+
ctx.ui.notify(text === "" ? "joggle: no output" : text, result.code === 0 ? "info" : "error")
|
|
449
|
+
} catch (error) {
|
|
450
|
+
ctx.ui.notify(`joggle could not run: ${reason(error)}`, "error")
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
})
|
|
454
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,88 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autotelic/joggle",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Cross-file patterns and idioms for TypeScript — the layer above the linter and the typechecker.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/autotelic/tackle/tree/main/packages/joggle#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/autotelic/tackle.git",
|
|
11
|
+
"directory": "packages/joggle"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/autotelic/tackle/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"typescript",
|
|
18
|
+
"linter",
|
|
19
|
+
"static-analysis",
|
|
20
|
+
"cross-file",
|
|
21
|
+
"oxc",
|
|
22
|
+
"effect",
|
|
23
|
+
"code-quality",
|
|
24
|
+
"pi-package"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=24.18.0"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"pi": {
|
|
33
|
+
"extensions": [
|
|
34
|
+
"./extensions"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"exports": {
|
|
38
|
+
"./plugin": {
|
|
39
|
+
"development": "./src/plugin.ts",
|
|
40
|
+
"default": "./dist/plugin.js"
|
|
41
|
+
},
|
|
42
|
+
"./testing": {
|
|
43
|
+
"development": "./src/testing.ts",
|
|
44
|
+
"default": "./dist/testing.js"
|
|
45
|
+
},
|
|
46
|
+
"./presets/composition": {
|
|
47
|
+
"development": "./src/presets/composition.ts",
|
|
48
|
+
"default": "./dist/presets/composition.js"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist",
|
|
53
|
+
"bin",
|
|
54
|
+
"extensions",
|
|
55
|
+
"JOGGLE.md"
|
|
56
|
+
],
|
|
57
|
+
"bin": {
|
|
58
|
+
"joggle": "./bin/joggle.js"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@effect/ai-typesafe": "4.0.5",
|
|
62
|
+
"@effect/platform-node": "4.0.5",
|
|
63
|
+
"effect": "4.0.5",
|
|
64
|
+
"oxc-parser": "0.150.0"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@autotelic/plumb": "0.6.1",
|
|
68
|
+
"@effect/tsgo": "0.56.0",
|
|
69
|
+
"@effect/vitest": "4.0.5",
|
|
70
|
+
"@types/node": "24.13.5",
|
|
71
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
72
|
+
"oxlint": "1.89.0",
|
|
73
|
+
"oxlint-tsgolint": "7.0.2004",
|
|
74
|
+
"typebox": "1.3.34",
|
|
75
|
+
"vitest": "5.0.1"
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"joggle": "node --conditions=development src/main.ts",
|
|
79
|
+
"joggle:elsewhere": "sh scripts/joggle-elsewhere.sh",
|
|
80
|
+
"build": "tsc -p tsconfig.build.json",
|
|
81
|
+
"typecheck": "tsc --noEmit",
|
|
82
|
+
"test": "vitest run",
|
|
83
|
+
"lint": "node scripts/lint-baseline.mjs",
|
|
84
|
+
"lint:update": "node scripts/lint-baseline.mjs --update",
|
|
85
|
+
"diagram:rules": "node scripts/diagram-rules.mjs",
|
|
86
|
+
"check": "pnpm typecheck && pnpm test && pnpm lint"
|
|
87
|
+
}
|
|
6
88
|
}
|