@sublang/spex 2.1.0 → 2.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.
@@ -17,6 +17,7 @@ export interface AgentInteraction {
17
17
  interactive: boolean;
18
18
  ask(prompt: string): string | null;
19
19
  }
20
+ export declare const terminalInteraction: AgentInteraction;
20
21
  export declare function parseAgentNames(value: string): AgentName[];
21
22
  /** Resolve the desired instruction targets without writing the project. */
22
23
  export declare function resolveAgentTargets(basePath: string, explicitAgents?: readonly AgentName[], interaction?: AgentInteraction): AgentTargetFile[];
@@ -2,6 +2,7 @@
2
2
  // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
3
  import { existsSync, readFileSync, readSync, unlinkSync, writeFileSync, } from "node:fs";
4
4
  import { join } from "node:path";
5
+ import { isatty } from "node:tty";
5
6
  import { getScaffoldDir } from "./bundled-scaffold.js";
6
7
  import { headingText, parseMarkdown, startOffset } from "./markdown.js";
7
8
  const SECTION_TITLE = "Specs (Source of Truth)";
@@ -24,15 +25,33 @@ export const AGENT_TARGETS = [
24
25
  ];
25
26
  const AGENT_NAMES = AGENT_TARGETS.flatMap((target) => target.agents);
26
27
  const AGENT_FILES = AGENT_TARGETS.map((target) => target.file);
27
- const terminalInteraction = {
28
- interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
28
+ // fd-level probes and a raw fd read, never process.stdin: materializing
29
+ // the stdin stream (even just reading .isTTY) switches fd 0 to
30
+ // non-blocking behind this reader's back.
31
+ export const terminalInteraction = {
32
+ interactive: isatty(0) && isatty(2),
29
33
  ask(prompt) {
30
34
  process.stderr.write(prompt);
31
35
  const buffer = Buffer.alloc(1024);
32
- const bytes = readSync(0, buffer, 0, buffer.length, null);
33
- if (bytes === 0)
34
- return null;
35
- return buffer.toString("utf-8", 0, bytes).trim();
36
+ for (;;) {
37
+ let bytes;
38
+ try {
39
+ bytes = readSync(0, buffer, 0, buffer.length, null);
40
+ }
41
+ catch (error) {
42
+ // A non-blocking fd 0 — inherited from the spawning process, or
43
+ // a side effect of an import materializing process.stdin —
44
+ // reports EAGAIN instead of waiting for the reply.
45
+ if (error.code === "EAGAIN") {
46
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
47
+ continue;
48
+ }
49
+ throw error;
50
+ }
51
+ if (bytes === 0)
52
+ return null;
53
+ return buffer.toString("utf-8", 0, bytes).trim();
54
+ }
36
55
  },
37
56
  };
38
57
  /**
@@ -185,9 +204,17 @@ function removeManagedSection(filePath) {
185
204
  // Infer the seam from the content that survives, never from the
186
205
  // whole file: the managed section carries the bundle's line endings
187
206
  // (CRLF where git checked agent-specs.txt out on Windows), and a
188
- // section being deleted must not impose them on what remains.
189
- const surviving = before !== "" ? before : after;
190
- const lineEnding = surviving.includes("\r\n") ? "\r\n" : "\n";
207
+ // section being deleted must not impose them on what remains. A
208
+ // surviving side may be a single line carrying no evidence, so take
209
+ // the first side that has any, then the whitespace trimmed off
210
+ // beside the survivors — their own line terminators.
211
+ const evidence = [
212
+ before,
213
+ after,
214
+ existing.slice(0, start),
215
+ existing.slice(end),
216
+ ].find((text) => text.includes("\n"));
217
+ const lineEnding = evidence?.includes("\r\n") ? "\r\n" : "\n";
191
218
  const updated = before !== "" && after !== ""
192
219
  ? `${before}${lineEnding}${lineEnding}${after}`
193
220
  : before !== ""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sublang/spex",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "The essential spec layer AI agents need to build software reliably",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",