@agjs/tsforge 0.2.4 → 0.2.5

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@agjs/tsforge",
3
3
  "type": "module",
4
- "version": "0.2.4",
4
+ "version": "0.2.5",
5
5
  "license": "MIT",
6
6
  "description": "TypeScript coding harness with a deterministic gate, stack-aware guardrails, and stream-level correction.",
7
7
  "repository": {
@@ -478,6 +478,47 @@ export function buildCoreFix(): string {
478
478
  return `${lintFix} ; ${format}`;
479
479
  }
480
480
 
481
+ /**
482
+ * Auto-format ONE just-written file in place: `eslint --fix` (squashes the
483
+ * auto-fixable mechanical rules — padding-line, curly, prefer-template, quotes)
484
+ * then `prettier --write` (whitespace/quotes/width). Run at WRITE time (in the
485
+ * write guard) so the model never sees — nor hand-chases — formatting noise.
486
+ * Deferring all of this to the settle-time gate let the model self-run eslint
487
+ * mid-build, see the un-squashed mechanical lint, and spiral fixing blank lines
488
+ * and braces by hand to the turn cap. Best-effort + per-file (cheap): any failure
489
+ * is swallowed and the settle gate stays the authority.
490
+ */
491
+ export async function formatFile(cwd: string, file: string): Promise<void> {
492
+ const abs = join(cwd, file);
493
+
494
+ try {
495
+ await Bun.spawn(
496
+ [
497
+ "bun",
498
+ ESLINT_BIN,
499
+ "--no-config-lookup",
500
+ "-c",
501
+ STRICT_CONFIG,
502
+ "--fix",
503
+ abs,
504
+ ],
505
+ { cwd, stdout: "ignore", stderr: "ignore" }
506
+ ).exited;
507
+ } catch {
508
+ // best-effort — the settle gate still fixes + validates
509
+ }
510
+
511
+ try {
512
+ await Bun.spawn(["bun", PRETTIER_BIN, "--write", abs], {
513
+ cwd,
514
+ stdout: "ignore",
515
+ stderr: "ignore",
516
+ }).exited;
517
+ } catch {
518
+ // best-effort
519
+ }
520
+ }
521
+
481
522
  async function ensureFile(
482
523
  cwd: string,
483
524
  name: string,
@@ -11,6 +11,7 @@ export const SYSTEM = [
11
11
  "Tools: `read` (inspect a file), `edit` (replace an exact, unique snippet), `create` (a new file), `run` (execute any shell command and see its output).",
12
12
  "Lead with action: write the implementation FIRST (one `create`/`edit`) — do NOT deliberate at length before writing any code.",
13
13
  "After every edit the harness AUTOMATICALLY runs the gate and gives you the result (the errors + fix guidance for the failing rules). You do NOT need to run the acceptance command yourself — read that result and fix exactly what it reports, then edit again. Keep going until it reports green; the harness ends the task at that point.",
14
+ "The harness also AUTO-FIXES mechanical formatting on every file you write — blank lines, braces, quotes, semicolons, import order, `prefer-template`. NEVER hand-fix or chase those, and do NOT run `tsc`/`eslint`/the gate yourself to look for them. Fix only what the gate explicitly hands back (`as`/`any`/`!`, `I`-prefix, real type errors), then stop.",
14
15
  "Test hypotheses by RUNNING them, never by reasoning them out. Unsure about an edge case, rounding, or ordering (`Math.floor(100/3)`, largest-remainder ties)? `run` a quick `bun -e '…console.log(…)'`, or write a throwaway `scratch/check.ts` importing your impl and `run` it. `scratch/` is yours — the gate ignores it.",
15
16
  "The gate is `tsc` strict + eslint with every rule an error, so write TypeScript that satisfies it: interfaces are `I`-prefixed; `===`; no `var`; never the non-null `!` — guard index access (`const x = arr[i]; if (x === undefined) {...}`); no `any` and no `as` — type every parameter (e.g. `.reduce((acc: number, r: number) => …, 0)`); explicit boolean conditions. When the gate flags errors in read-only files (tests/types), they come from your editable file being missing or wrong-shaped and vanish once it's correct — don't edit them.",
16
17
  ].join("\n");
package/src/loop/turn.ts CHANGED
@@ -34,6 +34,7 @@ import {
34
34
  import { TsService, type ITsDiagnostic } from "../lsp";
35
35
  import type { McpRegistry } from "../mcp";
36
36
  import type { FileLinter, IFileLintProblem } from "../detect-gate";
37
+ import { formatFile } from "../detect-gate";
37
38
  import {
38
39
  buildMetaRuleContext,
39
40
  runMetaRules,
@@ -322,6 +323,12 @@ async function writeGuard(
322
323
  });
323
324
  }
324
325
 
326
+ // Auto-format this file NOW (eslint --fix + prettier) — not at the settle
327
+ // gate. Otherwise the mechanical lint (blank lines, braces, quotes) sits
328
+ // unfixed between writes, and when the model self-runs the gate it sees the
329
+ // noise and hand-chases it to the turn cap. Best-effort; gate stays authority.
330
+ await formatFile(cwd, file);
331
+
325
332
  tsService.refresh(file);
326
333
 
327
334
  const typeErrors = tsService