project-mgr 0.1.1 → 0.1.2

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/.env_sample CHANGED
@@ -1,5 +1,7 @@
1
- # SQLite database path. Relative paths are resolved from the current directory.
2
- PMGR_DB_PATH=./data/project-mgr.sqlite
1
+ # Optional SQLite database override. When unset, the database is stored at
2
+ # ~/.local/share/project-mgr/project-mgr.sqlite.
3
+ # Use a literal absolute path here; .env files do not expand ~ or $HOME.
4
+ # PMGR_DB_PATH=/absolute/path/to/project-mgr.sqlite
3
5
 
4
6
  # For isolated manual testing, use a separate database instead:
5
- # PMGR_DB_PATH=./data/manual-test.sqlite
7
+ # PMGR_DB_PATH=/tmp/project-mgr-manual-test.sqlite
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.1.2 - 2026-08-03
6
+
7
+ ### Changed
8
+
9
+ - Moved the default database from the command's working directory to the stable per-user path `~/.local/share/project-mgr/project-mgr.sqlite`.
10
+
5
11
  ## 0.1.1 - 2026-08-03
6
12
 
7
13
  ### Changed
package/README.md CHANGED
@@ -23,7 +23,9 @@ npm install --global project-mgr
23
23
  pmgr current
24
24
  ```
25
25
 
26
- The database defaults to `./data/project-mgr.sqlite` in the current working directory. Set `PMGR_DB_PATH` to use another location:
26
+ The database defaults to `~/.local/share/project-mgr/project-mgr.sqlite`, regardless of the directory where `pmgr` is executed. The CLI resolves this to an absolute path using the current user's home directory and creates the parent directory automatically.
27
+
28
+ Set `PMGR_DB_PATH` to use another location:
27
29
 
28
30
  ```bash
29
31
  PMGR_DB_PATH=/absolute/path/projects.sqlite npx --yes project-mgr current
@@ -53,26 +55,26 @@ During development, run the TypeScript CLI directly:
53
55
  pnpm pmgr current
54
56
  ```
55
57
 
56
- The default configuration in `.env_sample` is:
58
+ The default database path is:
57
59
 
58
- ```dotenv
59
- PMGR_DB_PATH=./data/project-mgr.sqlite
60
+ ```text
61
+ ~/.local/share/project-mgr/project-mgr.sqlite
60
62
  ```
61
63
 
62
- Set `PMGR_DB_PATH` in `.env` to use another location, or override it for one command:
64
+ `PMGR_DB_PATH` is optional in `.env_sample`. Set it in `.env` to use another location, or override it for one command:
63
65
 
64
66
  ```bash
65
67
  PMGR_DB_PATH=/absolute/path/projects.sqlite pnpm start current
66
68
  ```
67
69
 
68
- Relative paths are resolved from the working directory of the command. When `pnpm start ...` runs from this project's root, the default database is `./data/project-mgr.sqlite`. It is created automatically when the first valid command runs.
70
+ Use a literal absolute path in `.env`; `.env` files do not expand `~` or `$HOME`. The database is created automatically when the first valid command runs.
69
71
 
70
72
  ### Use an isolated test database
71
73
 
72
74
  For manual testing, set a persistent path in `.env` that is separate from production data:
73
75
 
74
76
  ```dotenv
75
- PMGR_DB_PATH=./data/manual-test.sqlite
77
+ PMGR_DB_PATH=/tmp/project-mgr-manual-test.sqlite
76
78
  ```
77
79
 
78
80
  Then run commands normally:
@@ -88,7 +90,7 @@ pnpm start history --project test-project
88
90
 
89
91
  Project keys must match exactly: a record added to `test-project` is not part of `project-mgr` history. Empty human-readable list queries print `No entries found.`; with `--json`, they print `[]`.
90
92
 
91
- `data/` is ignored by Git, so test data is not committed. Delete `data/manual-test.sqlite` when it is no longer needed.
93
+ Delete `/tmp/project-mgr-manual-test.sqlite` when it is no longer needed.
92
94
 
93
95
  Automated tests use an in-memory database or SQLite files in the system temporary directory; they do not read or write the default database. `PMGR_DB_PATH=:memory:` also works for one command, but each CLI command runs in a separate process and its data disappears when the command exits, so it is not suitable for consecutive manual tests.
94
96
 
@@ -189,7 +191,7 @@ Exports omit the database-internal `id` and `recordedAt` fields and can be impor
189
191
  ```bash
190
192
  pnpm start export --format jsonl > project-statuses.jsonl
191
193
 
192
- PMGR_DB_PATH=./data/restored.sqlite \
194
+ PMGR_DB_PATH=/tmp/project-mgr-restored.sqlite \
193
195
  pnpm start import project-statuses.jsonl
194
196
  ```
195
197
 
package/README_CN.md CHANGED
@@ -23,7 +23,9 @@ npm install --global project-mgr
23
23
  pmgr current
24
24
  ```
25
25
 
26
- 数据库默认位于当前工作目录下的 `./data/project-mgr.sqlite`。通过 `PMGR_DB_PATH` 指定其他位置:
26
+ 无论在哪个目录执行 `pmgr`,数据库都默认位于 `~/.local/share/project-mgr/project-mgr.sqlite`。CLI 会根据当前用户的主目录将其解析为绝对路径,并自动创建父目录。
27
+
28
+ 通过 `PMGR_DB_PATH` 指定其他位置:
27
29
 
28
30
  ```bash
29
31
  PMGR_DB_PATH=/absolute/path/projects.sqlite npx --yes project-mgr current
@@ -53,26 +55,26 @@ pnpm start current
53
55
  pnpm pmgr current
54
56
  ```
55
57
 
56
- 默认配置位于 `.env_sample`:
58
+ 默认数据库路径是:
57
59
 
58
- ```dotenv
59
- PMGR_DB_PATH=./data/project-mgr.sqlite
60
+ ```text
61
+ ~/.local/share/project-mgr/project-mgr.sqlite
60
62
  ```
61
63
 
62
- 通过 `.env` 中的 `PMGR_DB_PATH` 指定其他位置,也可以为单条命令临时覆盖:
64
+ `.env_sample` 中的 `PMGR_DB_PATH` 是可选配置。可以在 `.env` 中指定其他位置,也可以为单条命令临时覆盖:
63
65
 
64
66
  ```bash
65
67
  PMGR_DB_PATH=/absolute/path/projects.sqlite pnpm start current
66
68
  ```
67
69
 
68
- 路径基于启动命令的当前工作目录计算。从本项目根目录执行 `pnpm start ...` 时,默认位置就是 `./data/project-mgr.sqlite`。数据库会在第一次执行有效命令时自动创建。
70
+ 在 `.env` 中应填写字面量绝对路径;`.env` 文件不会展开 `~` 或 `$HOME`。数据库会在第一次执行有效命令时自动创建。
69
71
 
70
72
  ### 使用独立测试数据库
71
73
 
72
74
  手工测试时,建议在 `.env` 中固定设置一个与正式数据分离的路径:
73
75
 
74
76
  ```dotenv
75
- PMGR_DB_PATH=./data/manual-test.sqlite
77
+ PMGR_DB_PATH=/tmp/project-mgr-manual-test.sqlite
76
78
  ```
77
79
 
78
80
  随后正常执行命令:
@@ -88,7 +90,7 @@ pnpm start history --project test-project
88
90
 
89
91
  项目键必须完全一致:写入 `test-project` 的记录不会出现在 `project-mgr` 的历史中。人类可读的空列表查询会输出 `No entries found.`;使用 `--json` 时则输出 `[]`。
90
92
 
91
- `data/` 已加入 Git ignore,测试数据不会进入版本库。不需要保留时,可以删除 `data/manual-test.sqlite`。
93
+ 不需要保留时,可以删除 `/tmp/project-mgr-manual-test.sqlite`。
92
94
 
93
95
  自动化测试会使用内存数据库或系统临时目录中的 SQLite 文件,不会读写默认数据库。`PMGR_DB_PATH=:memory:` 也可用于单条命令,但每个 CLI 命令都是独立进程,命令结束后数据就会消失,不适合连续手工测试。
94
96
 
@@ -189,7 +191,7 @@ pnpm start import --file statuses.jsonl --json
189
191
  ```bash
190
192
  pnpm start export --format jsonl > project-statuses.jsonl
191
193
 
192
- PMGR_DB_PATH=./data/restored.sqlite \
194
+ PMGR_DB_PATH=/tmp/project-mgr-restored.sqlite \
193
195
  pnpm start import project-statuses.jsonl
194
196
  ```
195
197
 
package/dist/db.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import Database from "better-sqlite3";
2
2
  import { mkdirSync } from "node:fs";
3
+ import { homedir } from "node:os";
3
4
  import { dirname, resolve } from "node:path";
4
5
  import { validateStatusEntry, ValidationError, } from "./domain.js";
5
6
  const migration = `
@@ -28,7 +29,7 @@ CREATE INDEX IF NOT EXISTS idx_status_entries_project_occurred ON status_entries
28
29
  `;
29
30
  export function databasePath() {
30
31
  return (process.env.PMGR_DB_PATH ||
31
- resolve(process.cwd(), "data", "project-mgr.sqlite"));
32
+ resolve(homedir(), ".local", "share", "project-mgr", "project-mgr.sqlite"));
32
33
  }
33
34
  export function openLedger(path = databasePath()) {
34
35
  if (path !== ":memory:")
@@ -57,7 +57,7 @@ The `project_id, occurred_at DESC, id DESC` index supports current-status and hi
57
57
 
58
58
  After opening the database, `openLedger()` enables foreign keys, creates the migration table, and checks for and applies migration 1 within a `BEGIN IMMEDIATE` transaction. The immediate transaction prevents migration checks and writes from interleaving when several local processes open the database for the first time at once.
59
59
 
60
- The database path is read from `PMGR_DB_PATH` first; otherwise, it uses `data/project-mgr.sqlite` in the process working directory. Non-memory databases create their parent directory automatically.
60
+ The database path is read from `PMGR_DB_PATH` first; otherwise, it uses the absolute path `~/.local/share/project-mgr/project-mgr.sqlite`, resolved from the current user's home directory. Non-memory databases create their parent directory automatically.
61
61
 
62
62
  ## Write flow
63
63
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-mgr",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Local-first append-only project status ledger",
5
5
  "type": "module",
6
6
  "bin": {
package/src/db.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import Database from "better-sqlite3";
2
2
  import { mkdirSync } from "node:fs";
3
+ import { homedir } from "node:os";
3
4
  import { dirname, resolve } from "node:path";
4
5
  import {
5
6
  type Source,
@@ -46,7 +47,7 @@ CREATE INDEX IF NOT EXISTS idx_status_entries_project_occurred ON status_entries
46
47
  export function databasePath(): string {
47
48
  return (
48
49
  process.env.PMGR_DB_PATH ||
49
- resolve(process.cwd(), "data", "project-mgr.sqlite")
50
+ resolve(homedir(), ".local", "share", "project-mgr", "project-mgr.sqlite")
50
51
  );
51
52
  }
52
53
 
package/test/core.test.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
- import { tmpdir } from "node:os";
3
+ import { homedir, tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import test from "node:test";
6
6
  import { run } from "../src/cli.js";
@@ -171,7 +171,7 @@ test("import validates before transaction and default source is import", () => {
171
171
  db.close();
172
172
  });
173
173
 
174
- test("database path uses environment override and file migration creates parent directory", () => {
174
+ test("database path has a stable default and environment override creates its parent directory", () => {
175
175
  const directory = mkdtempSync(join(tmpdir(), "pmgr-"));
176
176
  const previous = process.env.PMGR_DB_PATH;
177
177
  process.env.PMGR_DB_PATH = join(directory, "nested", "ledger.sqlite");
@@ -180,7 +180,10 @@ test("database path uses environment override and file migration creates parent
180
180
  db.close();
181
181
  if (previous === undefined) delete process.env.PMGR_DB_PATH;
182
182
  else process.env.PMGR_DB_PATH = previous;
183
- assert.match(databasePath(), /data\/project-mgr\.sqlite$/);
183
+ assert.equal(
184
+ databasePath(),
185
+ join(homedir(), ".local", "share", "project-mgr", "project-mgr.sqlite"),
186
+ );
184
187
  rmSync(directory, { recursive: true, force: true });
185
188
  });
186
189