@justjoshn/pi-snoop-tui 0.1.1 → 0.1.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.3]
4
+
5
+ - Fix every `bun lint` behavior error. The editor inset can no longer pass a negative count to `repeat()`, and the home directory is read when a path is shown instead of when the module loads.
6
+
7
+ ## [0.1.2]
8
+
9
+ - Rewrite every test as a user behavior test. Tests load the extensions the way Pi does and assert the rendered tool rows, footer, header, and editor with the snoop themes. No behavior changes.
10
+
3
11
  ## [0.1.1]
4
12
 
5
13
  - Refactor TUI components, row layout, and tests to adhere verbatim to `AGENTS.md` (immutable patterns, closure state cells, `zod` input validation, named constants, and small functions) with no behavior changes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justjoshn/pi-snoop-tui",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "A calm, compact, fast look for Pi's interactive TUI: graphite themes, one-line tool rows, a single-row footer.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/editor.ts CHANGED
@@ -80,7 +80,7 @@ abstract class RuleEditor extends CustomEditor {
80
80
  private promptText(theme: Theme): string {
81
81
  const cached = this.prompt.read();
82
82
  if (cached?.theme === theme) return cached.text;
83
- const text = `${' '.repeat(this.config.gutter)}${theme.fg('accent', '›')}${' '.repeat(PROMPT_INSET - 1)}`;
83
+ const text = `${' '.repeat(this.config.gutter)}${theme.fg('accent', '›')}${' '.repeat(Math.max(0, PROMPT_INSET - 1))}`;
84
84
  this.prompt.write({ theme, text });
85
85
  return text;
86
86
  }
package/src/rows/row.ts CHANGED
@@ -27,8 +27,11 @@ interface RowState {
27
27
  readonly body: Component;
28
28
  }
29
29
 
30
+ function isRecord(value: unknown): value is Record<string, unknown> {
31
+ return value !== null && typeof value === 'object';
32
+ }
30
33
  function parseArgs(args: unknown): Record<string, unknown> {
31
- return args !== null && typeof args === 'object' ? (args as Record<string, unknown>) : {};
34
+ return isRecord(args) ? args : {};
32
35
  }
33
36
  function createRowState(spec: ToolSpec, theme: Theme, ctx: ToolRenderContext): RowState {
34
37
  const view = cell(Object.freeze<RowView>({ phase: derivePhase(ctx), verb: spec.verb, target: spec.target(parseArgs(ctx.args), ctx.cwd), meta: undefined, body: { kind: 'none' }, pad: ctx.outputPad }));
@@ -48,10 +51,11 @@ function isRowState(value: unknown): value is RowState {
48
51
  return typeof value === 'object' && value !== null && ROW_STATE in value;
49
52
  }
50
53
  function rowState(ctx: ToolRenderContext, spec: ToolSpec, theme: Theme): RowState {
51
- const existing = ctx.state.snoop;
54
+ const bag: unknown = ctx.state;
55
+ const existing: unknown = isRecord(bag) ? Reflect.get(bag, 'snoop') : undefined;
52
56
  if (isRowState(existing)) return existing;
53
57
  const created = createRowState(spec, theme, ctx);
54
- ctx.state.snoop = created;
58
+ if (isRecord(bag)) Reflect.set(bag, 'snoop', created);
55
59
  return created;
56
60
  }
57
61
 
package/src/rows/specs.ts CHANGED
@@ -39,8 +39,10 @@ export interface ToolSpec {
39
39
  export const RUNNING_TAIL_LINES = 3;
40
40
  export const ERROR_PREVIEW_LINES = 5;
41
41
  const HomeEnv = z.object({ HOME: z.string().optional(), USERPROFILE: z.string().optional() });
42
- const homeEnv = HomeEnv.parse(process.env);
43
- const HOME = homeEnv.HOME ?? homeEnv.USERPROFILE;
42
+ function homeDir(): string | undefined {
43
+ const env = HomeEnv.parse(process.env);
44
+ return env.HOME ?? env.USERPROFILE;
45
+ }
44
46
  const STATUS_TAIL_CHARS = 200;
45
47
 
46
48
  function str(value: unknown): string {
@@ -52,7 +54,8 @@ function field(value: unknown, key: string): unknown {
52
54
  function relPath(value: unknown, cwd: string): string {
53
55
  const path = str(value);
54
56
  if (path.startsWith(`${cwd}/`)) return path.slice(cwd.length + 1);
55
- if (HOME && (path === HOME || path.startsWith(`${HOME}/`))) return `~${path.slice(HOME.length)}`;
57
+ const home = homeDir();
58
+ if (home && (path === home || path.startsWith(`${home}/`))) return `~${path.slice(home.length)}`;
56
59
  return path;
57
60
  }
58
61
  function pathTarget(args: ToolArgs | undefined, cwd: string): TargetText {