mslxdff 0.1.45 → 0.1.54

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.
@@ -1,51 +1,51 @@
1
- # Domain Docs
2
-
3
- How the engineering skills should consume this repo's domain documentation when exploring the codebase.
4
-
5
- ## Before exploring, read these
6
-
7
- - **`CONTEXT.md`** at the repo root, or
8
- - **`CONTEXT-MAP.md`** at the repo root if it exists — it points at one `CONTEXT.md` per context. Read each one relevant to the topic.
9
- - **`docs/adr/`** — read ADRs that touch the area you're about to work in. In multi-context repos, also check `src/<context>/docs/adr/` for context-scoped decisions.
10
-
11
- If any of these files don't exist, **proceed silently**. Don't flag their absence; don't suggest creating them upfront. The `/domain-modeling` skill (reached via `/grill-with-docs` and `/improve-codebase-architecture`) creates them lazily when terms or decisions actually get resolved.
12
-
13
- ## File structure
14
-
15
- Single-context repo (most repos):
16
-
17
- ```
18
- /
19
- ├── CONTEXT.md
20
- ├── docs/adr/
21
- │ ├── 0001-event-sourced-orders.md
22
- │ └── 0002-postgres-for-write-model.md
23
- └── src/
24
- ```
25
-
26
- Multi-context repo (presence of `CONTEXT-MAP.md` at the root):
27
-
28
- ```
29
- /
30
- ├── CONTEXT-MAP.md
31
- ├── docs/adr/ ← system-wide decisions
32
- └── src/
33
- ├── ordering/
34
- │ ├── CONTEXT.md
35
- │ └── docs/adr/ ← context-specific decisions
36
- └── billing/
37
- ├── CONTEXT.md
38
- └── docs/adr/
39
- ```
40
-
41
- ## Use the glossary's vocabulary
42
-
43
- When your output names a domain concept (in an issue title, a refactor proposal, a hypothesis, a test name), use the term as defined in `CONTEXT.md`. Don't drift to synonyms the glossary explicitly avoids.
44
-
45
- If the concept you need isn't in the glossary yet, that's a signal — either you're inventing language the project doesn't use (reconsider) or there's a real gap (note it for `/domain-modeling`).
46
-
47
- ## Flag ADR conflicts
48
-
49
- If your output contradicts an existing ADR, surface it explicitly rather than silently overriding:
50
-
1
+ # Domain Docs
2
+
3
+ How the engineering skills should consume this repo's domain documentation when exploring the codebase.
4
+
5
+ ## Before exploring, read these
6
+
7
+ - **`CONTEXT.md`** at the repo root, or
8
+ - **`CONTEXT-MAP.md`** at the repo root if it exists — it points at one `CONTEXT.md` per context. Read each one relevant to the topic.
9
+ - **`docs/adr/`** — read ADRs that touch the area you're about to work in. In multi-context repos, also check `src/<context>/docs/adr/` for context-scoped decisions.
10
+
11
+ If any of these files don't exist, **proceed silently**. Don't flag their absence; don't suggest creating them upfront. The `/domain-modeling` skill (reached via `/grill-with-docs` and `/improve-codebase-architecture`) creates them lazily when terms or decisions actually get resolved.
12
+
13
+ ## File structure
14
+
15
+ Single-context repo (most repos):
16
+
17
+ ```
18
+ /
19
+ ├── CONTEXT.md
20
+ ├── docs/adr/
21
+ │ ├── 0001-event-sourced-orders.md
22
+ │ └── 0002-postgres-for-write-model.md
23
+ └── src/
24
+ ```
25
+
26
+ Multi-context repo (presence of `CONTEXT-MAP.md` at the root):
27
+
28
+ ```
29
+ /
30
+ ├── CONTEXT-MAP.md
31
+ ├── docs/adr/ ← system-wide decisions
32
+ └── src/
33
+ ├── ordering/
34
+ │ ├── CONTEXT.md
35
+ │ └── docs/adr/ ← context-specific decisions
36
+ └── billing/
37
+ ├── CONTEXT.md
38
+ └── docs/adr/
39
+ ```
40
+
41
+ ## Use the glossary's vocabulary
42
+
43
+ When your output names a domain concept (in an issue title, a refactor proposal, a hypothesis, a test name), use the term as defined in `CONTEXT.md`. Don't drift to synonyms the glossary explicitly avoids.
44
+
45
+ If the concept you need isn't in the glossary yet, that's a signal — either you're inventing language the project doesn't use (reconsider) or there's a real gap (note it for `/domain-modeling`).
46
+
47
+ ## Flag ADR conflicts
48
+
49
+ If your output contradicts an existing ADR, surface it explicitly rather than silently overriding:
50
+
51
51
  > _Contradicts ADR-0007 (event-sourced orders) — but worth reopening because…_
@@ -1,30 +1,30 @@
1
- # Issue tracker: Local Markdown
2
-
3
- Issues and specs (you may know a spec as a PRD) for this repo live as markdown files in `.scratch/`.
4
-
5
- ## Conventions
6
-
7
- - One feature per directory: `.scratch/<feature-slug>/`
8
- - The spec is `.scratch/<feature-slug>/spec.md`
9
- - Implementation issues are one file per ticket at `.scratch/<feature-slug>/issues/<NN>-<slug>.md`, numbered from `01` — never a single combined tickets file
10
- - Triage state is recorded as a `Status:` line near the top of each issue file (see `triage-labels.md` for the role strings)
11
- - Comments and conversation history append to the bottom of the file under a `## Comments` heading
12
-
13
- ## When a skill says "publish to the issue tracker"
14
-
15
- Create a new file under `.scratch/<feature-slug>/` (creating the directory if needed).
16
-
17
- ## When a skill says "fetch the relevant ticket"
18
-
19
- Read the file at the referenced path. The user will normally pass the path or the issue number directly.
20
-
21
- ## Wayfinding operations
22
-
23
- Used by `/wayfinder`. The **map** is a file with one **child** file per ticket.
24
-
25
- - **Map**: `.scratch/<effort>/map.md` — the Notes / Decisions-so-far / Fog body.
26
- - **Child ticket**: `.scratch/<effort>/issues/NN-<slug>.md`, numbered from `01`, with the question in the body. A `Type:` line records the ticket type (`research`/`prototype`/`grilling`/`task`); a `Status:` line records `claimed`/`resolved`.
27
- - **Blocking**: a `Blocked by: NN, NN` line near the top. A ticket is unblocked when every file it lists is `resolved`.
28
- - **Frontier**: scan `.scratch/<effort>/issues/` for files that are open, unblocked, and unclaimed; first by number wins.
29
- - **Claim**: set `Status: claimed` and save before any work.
1
+ # Issue tracker: Local Markdown
2
+
3
+ Issues and specs (you may know a spec as a PRD) for this repo live as markdown files in `.scratch/`.
4
+
5
+ ## Conventions
6
+
7
+ - One feature per directory: `.scratch/<feature-slug>/`
8
+ - The spec is `.scratch/<feature-slug>/spec.md`
9
+ - Implementation issues are one file per ticket at `.scratch/<feature-slug>/issues/<NN>-<slug>.md`, numbered from `01` — never a single combined tickets file
10
+ - Triage state is recorded as a `Status:` line near the top of each issue file (see `triage-labels.md` for the role strings)
11
+ - Comments and conversation history append to the bottom of the file under a `## Comments` heading
12
+
13
+ ## When a skill says "publish to the issue tracker"
14
+
15
+ Create a new file under `.scratch/<feature-slug>/` (creating the directory if needed).
16
+
17
+ ## When a skill says "fetch the relevant ticket"
18
+
19
+ Read the file at the referenced path. The user will normally pass the path or the issue number directly.
20
+
21
+ ## Wayfinding operations
22
+
23
+ Used by `/wayfinder`. The **map** is a file with one **child** file per ticket.
24
+
25
+ - **Map**: `.scratch/<effort>/map.md` — the Notes / Decisions-so-far / Fog body.
26
+ - **Child ticket**: `.scratch/<effort>/issues/NN-<slug>.md`, numbered from `01`, with the question in the body. A `Type:` line records the ticket type (`research`/`prototype`/`grilling`/`task`); a `Status:` line records `claimed`/`resolved`.
27
+ - **Blocking**: a `Blocked by: NN, NN` line near the top. A ticket is unblocked when every file it lists is `resolved`.
28
+ - **Frontier**: scan `.scratch/<effort>/issues/` for files that are open, unblocked, and unclaimed; first by number wins.
29
+ - **Claim**: set `Status: claimed` and save before any work.
30
30
  - **Resolve**: append the answer under an `## Answer` heading, set `Status: resolved`, then append a context pointer (gist + link) to the map's Decisions-so-far in `map.md`.
@@ -1,15 +1,15 @@
1
- # Triage Labels
2
-
3
- The skills speak in terms of five canonical triage roles. This file maps those roles to the actual label strings used in this repo's issue tracker.
4
-
5
- | Label in mattpocock/skills | Label in our tracker | Meaning |
6
- | -------------------------- | -------------------- | ---------------------------------------- |
7
- | `needs-triage` | `needs-triage` | Maintainer needs to evaluate this issue |
8
- | `needs-info` | `needs-info` | Waiting on reporter for more information |
9
- | `ready-for-agent` | `ready-for-agent` | Fully specified, ready for an AFK agent |
10
- | `ready-for-human` | `ready-for-human` | Requires human implementation |
11
- | `wontfix` | `wontfix` | Will not be actioned |
12
-
13
- When a skill mentions a role (e.g. "apply the AFK-ready triage label"), use the corresponding label string from this table.
14
-
1
+ # Triage Labels
2
+
3
+ The skills speak in terms of five canonical triage roles. This file maps those roles to the actual label strings used in this repo's issue tracker.
4
+
5
+ | Label in mattpocock/skills | Label in our tracker | Meaning |
6
+ | -------------------------- | -------------------- | ---------------------------------------- |
7
+ | `needs-triage` | `needs-triage` | Maintainer needs to evaluate this issue |
8
+ | `needs-info` | `needs-info` | Waiting on reporter for more information |
9
+ | `ready-for-agent` | `ready-for-agent` | Fully specified, ready for an AFK agent |
10
+ | `ready-for-human` | `ready-for-human` | Requires human implementation |
11
+ | `wontfix` | `wontfix` | Will not be actioned |
12
+
13
+ When a skill mentions a role (e.g. "apply the AFK-ready triage label"), use the corresponding label string from this table.
14
+
15
15
  Edit the right-hand column to match whatever vocabulary you actually use.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mslxdff",
3
- "version": "0.1.45",
3
+ "version": "0.1.54",
4
4
  "description": "测试项目,请勿使用。",
5
5
  "type": "module",
6
6
  "bin": {
package/src/daemon.js CHANGED
@@ -1,84 +1,84 @@
1
- import { spawn } from "node:child_process";
2
- import { existsSync, mkdirSync, openSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
3
- import { join, dirname } from "node:path";
4
- import os from "node:os";
5
- import { fileURLToPath } from "node:url";
6
-
7
- export function daemonDir() {
8
- return process.env.MSLXDFF_DAEMON_DIR || join(os.homedir(), ".config", "mslxdff");
9
- }
10
-
11
- export function pidFile() {
12
- return join(daemonDir(), "daemon.pid");
13
- }
14
-
15
- export function logFile() {
16
- return join(daemonDir(), "daemon.log");
17
- }
18
-
19
- export function startDaemon(args = []) {
20
- const here = fileURLToPath(import.meta.url);
21
- const entry = here.endsWith("bin/mslxdff.js")
22
- ? here
23
- : join(dirname(here), "..", "bin", "mslxdff.js");
24
- const dir = daemonDir();
25
- mkdirSync(dir, { recursive: true });
26
- const logFd = openSync(logFile(), "a", 0o600);
27
- const env = { ...process.env, MSLXDFF_DAEMON: "1" };
28
- // a -debug foreground session wouldn't pass MSLXDFF_DEBUG to the
29
- // background daemon it restores (that flag means "print events to stdout")
30
- delete env.MSLXDFF_DEBUG;
31
- const child = spawn(process.execPath, [entry, ...args, "--daemon"], {
32
- detached: true,
33
- stdio: ["ignore", logFd, logFd],
34
- env,
35
- });
36
- child.unref();
37
- return child.pid;
38
- }
39
-
40
- export function writePid(pid, version) {
41
- const dir = daemonDir();
42
- mkdirSync(dir, { recursive: true });
43
- writeFileSync(pidFile(), version ? `${pid}\n${version}` : String(pid), { mode: 0o600 });
44
- }
45
-
46
- export function readPid() {
47
- if (!existsSync(pidFile())) return null;
48
- const raw = readFileSync(pidFile(), "utf8").trim();
49
- const n = Number(raw.split("\n")[0]);
50
- return Number.isInteger(n) && n > 0 ? n : null;
51
- }
52
-
53
- export function readPidVersion() {
54
- if (!existsSync(pidFile())) return null;
55
- const raw = readFileSync(pidFile(), "utf8");
56
- const lines = raw.split("\n");
57
- return lines.length > 1 && lines[1].trim() ? lines[1].trim() : null;
58
- }
59
-
60
- // Best-effort liveness check (signal 0); ESRCH means the process is gone.
61
- export function isPidAlive(pid) {
62
- try {
63
- process.kill(pid, 0);
64
- return true;
65
- } catch (err) {
66
- return err.code !== "ESRCH";
67
- }
68
- }
69
-
70
- export function stopDaemon() {
71
- const pid = readPid();
72
- if (!pid) return { stopped: false, reason: "no pid file" };
73
- try {
74
- process.kill(pid, "SIGTERM");
75
- } catch (err) {
76
- if (err.code !== "ESRCH") throw err;
77
- }
78
- try {
79
- unlinkSync(pidFile());
80
- } catch {
81
- // already gone
82
- }
83
- return { stopped: true, pid };
84
- }
1
+ import { spawn } from "node:child_process";
2
+ import { existsSync, mkdirSync, openSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
3
+ import { join, dirname } from "node:path";
4
+ import os from "node:os";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ export function daemonDir() {
8
+ return process.env.MSLXDFF_DAEMON_DIR || join(os.homedir(), ".config", "mslxdff");
9
+ }
10
+
11
+ export function pidFile() {
12
+ return join(daemonDir(), "daemon.pid");
13
+ }
14
+
15
+ export function logFile() {
16
+ return join(daemonDir(), "daemon.log");
17
+ }
18
+
19
+ export function startDaemon(args = []) {
20
+ const here = fileURLToPath(import.meta.url);
21
+ const entry = here.endsWith("bin/mslxdff.js")
22
+ ? here
23
+ : join(dirname(here), "..", "bin", "mslxdff.js");
24
+ const dir = daemonDir();
25
+ mkdirSync(dir, { recursive: true });
26
+ const logFd = openSync(logFile(), "a", 0o600);
27
+ const env = { ...process.env, MSLXDFF_DAEMON: "1" };
28
+ // a -debug foreground session wouldn't pass MSLXDFF_DEBUG to the
29
+ // background daemon it restores (that flag means "print events to stdout")
30
+ delete env.MSLXDFF_DEBUG;
31
+ const child = spawn(process.execPath, [entry, ...args, "--daemon"], {
32
+ detached: true,
33
+ stdio: ["ignore", logFd, logFd],
34
+ env,
35
+ });
36
+ child.unref();
37
+ return child.pid;
38
+ }
39
+
40
+ export function writePid(pid, version) {
41
+ const dir = daemonDir();
42
+ mkdirSync(dir, { recursive: true });
43
+ writeFileSync(pidFile(), version ? `${pid}\n${version}` : String(pid), { mode: 0o600 });
44
+ }
45
+
46
+ export function readPid() {
47
+ if (!existsSync(pidFile())) return null;
48
+ const raw = readFileSync(pidFile(), "utf8").trim();
49
+ const n = Number(raw.split("\n")[0]);
50
+ return Number.isInteger(n) && n > 0 ? n : null;
51
+ }
52
+
53
+ export function readPidVersion() {
54
+ if (!existsSync(pidFile())) return null;
55
+ const raw = readFileSync(pidFile(), "utf8");
56
+ const lines = raw.split("\n");
57
+ return lines.length > 1 && lines[1].trim() ? lines[1].trim() : null;
58
+ }
59
+
60
+ // Best-effort liveness check (signal 0); ESRCH means the process is gone.
61
+ export function isPidAlive(pid) {
62
+ try {
63
+ process.kill(pid, 0);
64
+ return true;
65
+ } catch (err) {
66
+ return err.code !== "ESRCH";
67
+ }
68
+ }
69
+
70
+ export function stopDaemon() {
71
+ const pid = readPid();
72
+ if (!pid) return { stopped: false, reason: "no pid file" };
73
+ try {
74
+ process.kill(pid, "SIGTERM");
75
+ } catch (err) {
76
+ if (err.code !== "ESRCH") throw err;
77
+ }
78
+ try {
79
+ unlinkSync(pidFile());
80
+ } catch {
81
+ // already gone
82
+ }
83
+ return { stopped: true, pid };
84
+ }
package/src/logs.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { appendFileSync, readFileSync, mkdirSync, existsSync, writeFileSync, statSync } from "node:fs";
2
+ import { appendFile, stat, readFile, writeFile } from "node:fs/promises";
2
3
  import { dirname, join } from "node:path";
3
4
  import os from "node:os";
4
5
  import { defaultStateFile } from "./state.js";
@@ -40,10 +41,48 @@ function trimIfOversized(file, maxBytes = MAX_BYTES) {
40
41
  }
41
42
  }
42
43
 
44
+ async function trimIfOversizedAsync(file, maxBytes = MAX_BYTES) {
45
+ try {
46
+ const st = await stat(file);
47
+ if (st.size <= maxBytes) return;
48
+ const text = await readFile(file, "utf8");
49
+ const lines = text.split("\n");
50
+ const keep = lines.slice(-100);
51
+ await writeFile(file, keep.join("\n"));
52
+ } catch {
53
+ // ignore
54
+ }
55
+ }
56
+
57
+ function shouldSync(file) {
58
+ if (process.env.MSLXDFF_LOGS_SYNC === "1") return true;
59
+ if (process.env.MSLXDFF_DAEMON_DIR) {
60
+ const dir = process.env.MSLXDFF_DAEMON_DIR;
61
+ if (file.startsWith(dir)) return true;
62
+ }
63
+ // 显式 tmp 文件(所有 test 的 mkdtemp 前缀)走同步,保证 read-after-write 可见
64
+ const low = file.toLowerCase();
65
+ if (low.includes("mslxdff-") || low.includes("tmp") || low.includes("temp")) return true;
66
+ // 非默认目录的文件一律同步(测试传入的临时路径)
67
+ try {
68
+ const def = logDir().toLowerCase();
69
+ if (!low.startsWith(def)) return true;
70
+ } catch {}
71
+ return false;
72
+ }
73
+
43
74
  function appendLine(file, entry) {
44
75
  ensureDir(dirname(file));
45
- appendFileSync(file, JSON.stringify({ ts: new Date().toISOString(), ...entry }) + "\n");
46
- trimIfOversized(file);
76
+ const line = JSON.stringify({ ts: new Date().toISOString(), ...entry }) + "\n";
77
+ if (shouldSync(file)) {
78
+ appendFileSync(file, line);
79
+ trimIfOversized(file);
80
+ return;
81
+ }
82
+ // 线上异步:不阻塞事件循环
83
+ appendFile(file, line)
84
+ .catch(() => {})
85
+ .then(() => trimIfOversizedAsync(file).catch(() => {}));
47
86
  }
48
87
 
49
88
  export function appendCall(entry, { file = callsFile() } = {}) {