mini-trellis 0.1.1 → 0.2.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.
- package/README.md +108 -94
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +32 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/doctor.d.ts +18 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +197 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +34 -8
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/mem.d.ts +2 -0
- package/dist/commands/mem.d.ts.map +1 -1
- package/dist/commands/mem.js +85 -2
- package/dist/commands/mem.js.map +1 -1
- package/dist/commands/refresh.d.ts +24 -0
- package/dist/commands/refresh.d.ts.map +1 -0
- package/dist/commands/refresh.js +180 -0
- package/dist/commands/refresh.js.map +1 -0
- package/dist/configurators/shared.d.ts.map +1 -1
- package/dist/configurators/shared.js +15 -2
- package/dist/configurators/shared.js.map +1 -1
- package/dist/templates/codex/config.toml +7 -15
- package/dist/templates/codex/hooks.json +4 -1
- package/dist/templates/common/bundled-skills/mini-trellis-session-insight/SKILL.md +13 -7
- package/dist/templates/common/bundled-skills/mini-trellis-session-insight/references/cli-quick-reference.md +24 -11
- package/dist/templates/common/bundled-skills/mini-trellis-session-insight/references/triggering-patterns.md +18 -10
- package/dist/templates/common/commands/remember.md +17 -3
- package/dist/templates/common/skills/update-spec.md +4 -0
- package/dist/templates/extract.d.ts +2 -0
- package/dist/templates/extract.d.ts.map +1 -1
- package/dist/templates/extract.js +21 -0
- package/dist/templates/extract.js.map +1 -1
- package/dist/templates/markdown/agents.md +9 -1
- package/dist/templates/markdown/spec/guides/mini-memory.md.txt +15 -8
- package/dist/templates/opencode/lib/session-utils.js +13 -58
- package/dist/templates/opencode/plugins/session-start.js +6 -10
- package/dist/templates/pi/extensions/mini-trellis/index.ts.txt +27 -78
- package/dist/templates/shared-hooks/session-start.py +108 -64
- package/dist/templates/trellis/config.yaml +3 -3
- package/dist/templates/trellis/scripts/add_session.py +95 -9
- package/dist/templates/trellis/scripts/common/config.py +4 -3
- package/dist/utils/managed-manifest.d.ts +12 -0
- package/dist/utils/managed-manifest.d.ts.map +1 -0
- package/dist/utils/managed-manifest.js +48 -0
- package/dist/utils/managed-manifest.js.map +1 -0
- package/dist/utils/managed-merge.d.ts +17 -0
- package/dist/utils/managed-merge.d.ts.map +1 -0
- package/dist/utils/managed-merge.js +101 -0
- package/dist/utils/managed-merge.js.map +1 -0
- package/package.json +4 -4
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
Add a new session to journal file and update index.md.
|
|
5
5
|
|
|
6
6
|
Usage:
|
|
7
|
-
python3 add_session.py --title "Title" --commit "hash" --summary "Summary" [--
|
|
7
|
+
python3 add_session.py --title "Title" --commit "hash" --summary "Summary" [--topic .trellis/research/topic.md]
|
|
8
8
|
python3 add_session.py --title "Title" --branch "feat/my-branch"
|
|
9
9
|
|
|
10
10
|
# Pipe detailed content via stdin (use --stdin to opt in):
|
|
@@ -48,10 +48,12 @@ from __future__ import annotations
|
|
|
48
48
|
import argparse
|
|
49
49
|
import hashlib
|
|
50
50
|
import json
|
|
51
|
+
import os
|
|
51
52
|
import re
|
|
52
53
|
import sys
|
|
53
|
-
from datetime import datetime
|
|
54
|
+
from datetime import datetime, timezone
|
|
54
55
|
from pathlib import Path
|
|
56
|
+
from urllib.parse import quote
|
|
55
57
|
|
|
56
58
|
from common.paths import (
|
|
57
59
|
DIR_TASKS,
|
|
@@ -517,6 +519,29 @@ def render_marker(fingerprint: str) -> str:
|
|
|
517
519
|
return f"{MARKER_PREFIX} v={MARKER_VERSION} fp={fingerprint} -->"
|
|
518
520
|
|
|
519
521
|
|
|
522
|
+
def _append_topic_links(
|
|
523
|
+
summary: str,
|
|
524
|
+
topic_paths: list[str] | None,
|
|
525
|
+
link_base: Path | None = None,
|
|
526
|
+
repo_root: Path | None = None,
|
|
527
|
+
) -> str:
|
|
528
|
+
"""Append topic links, resolving them relative to the journal file.
|
|
529
|
+
|
|
530
|
+
The record fingerprint keeps project-relative paths stable, while the
|
|
531
|
+
rendered Markdown link must resolve from the journal's directory.
|
|
532
|
+
"""
|
|
533
|
+
if not topic_paths:
|
|
534
|
+
return summary
|
|
535
|
+
|
|
536
|
+
links: list[str] = []
|
|
537
|
+
for topic in topic_paths:
|
|
538
|
+
href = topic
|
|
539
|
+
if link_base is not None and repo_root is not None:
|
|
540
|
+
href = quote(Path(os.path.relpath(repo_root / topic, start=link_base)).as_posix())
|
|
541
|
+
links.append(f"[{topic}]({href})")
|
|
542
|
+
return summary + "\nTopics: " + ", ".join(links)
|
|
543
|
+
|
|
544
|
+
|
|
520
545
|
def render_legacy_marker(fingerprint: str) -> str:
|
|
521
546
|
"""The v1 marker form: no version tag. Read, never written."""
|
|
522
547
|
return f"{MARKER_PREFIX} fp={fingerprint} -->"
|
|
@@ -1197,6 +1222,7 @@ def add_session(
|
|
|
1197
1222
|
branch: str | None = None,
|
|
1198
1223
|
commit_subjects: list[str] | None = None,
|
|
1199
1224
|
idempotency_key: str | None = None,
|
|
1225
|
+
topic_paths: list[str] | None = None,
|
|
1200
1226
|
) -> int:
|
|
1201
1227
|
"""Add a new session, resuming an interrupted one instead of duplicating it."""
|
|
1202
1228
|
repo_root = get_repo_root()
|
|
@@ -1243,8 +1269,9 @@ def add_session(
|
|
|
1243
1269
|
index_file = dev_dir / "index.md"
|
|
1244
1270
|
today = datetime.now().strftime("%Y-%m-%d")
|
|
1245
1271
|
|
|
1272
|
+
record_summary = _append_topic_links(summary, topic_paths)
|
|
1246
1273
|
payload = _fingerprint_payload(
|
|
1247
|
-
developer, title,
|
|
1274
|
+
developer, title, record_summary, package, branch, evidence,
|
|
1248
1275
|
changes, extra_content, tests, next_steps, idempotency_key,
|
|
1249
1276
|
)
|
|
1250
1277
|
marker = render_marker(compute_record_fingerprint(payload))
|
|
@@ -1310,8 +1337,9 @@ def add_session(
|
|
|
1310
1337
|
journal_file, current_num, current_lines = get_latest_journal_info(dev_dir)
|
|
1311
1338
|
new_session = resolve_next_session(repo_root, dev_dir, index_file)
|
|
1312
1339
|
|
|
1340
|
+
rendered_summary = _append_topic_links(summary, topic_paths, dev_dir, repo_root)
|
|
1313
1341
|
session_content = generate_session_content(
|
|
1314
|
-
new_session, title, evidence,
|
|
1342
|
+
new_session, title, evidence, rendered_summary, today, marker, package, branch,
|
|
1315
1343
|
changes=changes, extra_content=extra_content, tests=tests,
|
|
1316
1344
|
next_steps=next_steps,
|
|
1317
1345
|
)
|
|
@@ -1413,12 +1441,12 @@ def add_session(
|
|
|
1413
1441
|
|
|
1414
1442
|
print("", file=sys.stderr)
|
|
1415
1443
|
print("========================================", file=sys.stderr)
|
|
1416
|
-
print(f"[OK]
|
|
1444
|
+
print(f"[OK] Journal session {new_session} and index recorded (topic content must be verified separately).", file=sys.stderr)
|
|
1417
1445
|
print("========================================", file=sys.stderr)
|
|
1418
1446
|
print("", file=sys.stderr)
|
|
1419
1447
|
print("Files updated:", file=sys.stderr)
|
|
1420
|
-
print(f" - {target_file.
|
|
1421
|
-
print(" -
|
|
1448
|
+
print(f" - {target_file.relative_to(repo_root).as_posix() if target_file else 'journal'}", file=sys.stderr)
|
|
1449
|
+
print(f" - {index_file.relative_to(repo_root).as_posix()}", file=sys.stderr)
|
|
1422
1450
|
|
|
1423
1451
|
# -------------------------------------------------------------------
|
|
1424
1452
|
# Index-recorded → committed
|
|
@@ -1478,8 +1506,12 @@ def main() -> int:
|
|
|
1478
1506
|
),
|
|
1479
1507
|
)
|
|
1480
1508
|
parser.add_argument("--summary", default="Session summary was not supplied.", help="Brief summary")
|
|
1509
|
+
parser.add_argument(
|
|
1510
|
+
"--topic", action="append", default=[], metavar="PATH",
|
|
1511
|
+
help="Existing spec/research Markdown to validate and link in the journal (repeatable); does not edit or verify its conclusions",
|
|
1512
|
+
)
|
|
1481
1513
|
parser.add_argument("--content-file", help="Path to file with detailed content")
|
|
1482
|
-
parser.add_argument("--package", help="Package name tag (e.g., cli,
|
|
1514
|
+
parser.add_argument("--package", help="Package name tag (e.g., cli, core)")
|
|
1483
1515
|
parser.add_argument("--branch", help="Branch name (auto-detected if omitted)")
|
|
1484
1516
|
parser.add_argument("--change", action="append", help="Main Changes bullet (repeatable)")
|
|
1485
1517
|
parser.add_argument("--test", action="append", help="Testing bullet (repeatable)")
|
|
@@ -1508,6 +1540,21 @@ def main() -> int:
|
|
|
1508
1540
|
|
|
1509
1541
|
# Load active task once — shared by package and branch resolution
|
|
1510
1542
|
repo_root = get_repo_root()
|
|
1543
|
+
topic_links: list[str] = []
|
|
1544
|
+
for topic in args.topic:
|
|
1545
|
+
try:
|
|
1546
|
+
candidate = (repo_root / topic).resolve(strict=True)
|
|
1547
|
+
relative = candidate.relative_to(repo_root.resolve()).as_posix()
|
|
1548
|
+
if (not relative.startswith((".trellis/spec/", ".trellis/research/"))
|
|
1549
|
+
or candidate.suffix.lower() != ".md"
|
|
1550
|
+
or not candidate.is_file()
|
|
1551
|
+
or not candidate.read_text(encoding="utf-8").strip()):
|
|
1552
|
+
raise ValueError("expected a non-empty spec/research Markdown file")
|
|
1553
|
+
except (OSError, ValueError, UnicodeError):
|
|
1554
|
+
print("Error: --topic must name a readable, non-empty spec/research Markdown inside this project; journal not written.", file=sys.stderr)
|
|
1555
|
+
return 1
|
|
1556
|
+
if relative not in topic_links:
|
|
1557
|
+
topic_links.append(relative)
|
|
1511
1558
|
current = get_current_task(repo_root)
|
|
1512
1559
|
task_data = load_task(repo_root / current) if current else None
|
|
1513
1560
|
|
|
@@ -1538,8 +1585,47 @@ def main() -> int:
|
|
|
1538
1585
|
branch=branch,
|
|
1539
1586
|
commit_subjects=args.commit_subject,
|
|
1540
1587
|
idempotency_key=args.idempotency_key,
|
|
1588
|
+
topic_paths=topic_links,
|
|
1541
1589
|
)
|
|
1542
1590
|
|
|
1543
1591
|
|
|
1592
|
+
def _write_recording_status(exit_code: int) -> None:
|
|
1593
|
+
"""Best-effort last completed attempt, with no note content or user identity.
|
|
1594
|
+
|
|
1595
|
+
Atomic replacement keeps concurrent diagnostics readable. The journal and
|
|
1596
|
+
index remain the source of truth; failure may leave a resumable checkpoint.
|
|
1597
|
+
"""
|
|
1598
|
+
try:
|
|
1599
|
+
trellis = get_repo_root() / DIR_WORKFLOW
|
|
1600
|
+
if not trellis.is_dir():
|
|
1601
|
+
return
|
|
1602
|
+
target = trellis / ".runtime" / "writes" / "latest.json"
|
|
1603
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
1604
|
+
payload: dict[str, object] = {
|
|
1605
|
+
"schema": 1,
|
|
1606
|
+
"last_write_at": datetime.now(timezone.utc).isoformat(),
|
|
1607
|
+
"last_status": "ok" if exit_code == 0 else "error",
|
|
1608
|
+
"last_exit_code": exit_code,
|
|
1609
|
+
}
|
|
1610
|
+
if exit_code != 0:
|
|
1611
|
+
payload["last_error_category"] = "recording-failed"
|
|
1612
|
+
if write_text_atomic(target, json.dumps(payload) + "\n"):
|
|
1613
|
+
return
|
|
1614
|
+
except OSError:
|
|
1615
|
+
pass
|
|
1616
|
+
print("mini-trellis: recording diagnostic write failed (state-write)", file=sys.stderr)
|
|
1617
|
+
|
|
1618
|
+
|
|
1619
|
+
def run_with_status() -> int:
|
|
1620
|
+
try:
|
|
1621
|
+
result = main()
|
|
1622
|
+
except Exception:
|
|
1623
|
+
_write_recording_status(1)
|
|
1624
|
+
raise
|
|
1625
|
+
# argparse's --help / invalid arguments exit before a recording attempt.
|
|
1626
|
+
_write_recording_status(result)
|
|
1627
|
+
return result
|
|
1628
|
+
|
|
1629
|
+
|
|
1544
1630
|
if __name__ == "__main__":
|
|
1545
|
-
sys.exit(
|
|
1631
|
+
sys.exit(run_with_status())
|
|
@@ -121,7 +121,8 @@ def get_session_auto_commit(repo_root: Path | None = None) -> bool:
|
|
|
121
121
|
Governs both ``add_session.py:_auto_commit_workspace`` and
|
|
122
122
|
``task_store.py:_auto_commit_archive``.
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
Missing-key fallback: ``True`` for existing projects. New installations
|
|
125
|
+
explicitly set ``session_auto_commit: false`` in their config template.
|
|
125
126
|
Set ``session_auto_commit: false`` in ``.trellis/config.yaml`` to skip
|
|
126
127
|
auto-staging entirely; the journal/archive files are still written to
|
|
127
128
|
disk, but the user manages ``git add`` / ``git commit`` themselves.
|
|
@@ -313,7 +314,7 @@ def get_packages(repo_root: Path | None = None) -> dict[str, dict] | None:
|
|
|
313
314
|
or None if not configured (single-repo mode).
|
|
314
315
|
|
|
315
316
|
Example return:
|
|
316
|
-
{"cli": {"path": "packages/cli"}, "docs
|
|
317
|
+
{"cli": {"path": "packages/cli"}, "docs": {"path": "docs", "type": "submodule"}}
|
|
317
318
|
"""
|
|
318
319
|
config = _load_config(repo_root)
|
|
319
320
|
packages = config.get("packages")
|
|
@@ -345,7 +346,7 @@ def get_submodule_packages(repo_root: Path | None = None) -> dict[str, str]:
|
|
|
345
346
|
Empty dict if none configured.
|
|
346
347
|
|
|
347
348
|
Example return:
|
|
348
|
-
{"docs
|
|
349
|
+
{"docs": "docs"}
|
|
349
350
|
"""
|
|
350
351
|
packages = get_packages(repo_root)
|
|
351
352
|
if packages is None:
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const MANIFEST_PATH = ".trellis/.mini-trellis-manifest.json";
|
|
2
|
+
export interface MiniTrellisManifest {
|
|
3
|
+
version: number;
|
|
4
|
+
files: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
export declare function hashContent(content: string): string;
|
|
7
|
+
export declare function hashFile(filePath: string): string | null;
|
|
8
|
+
export declare function readManifest(cwd: string): MiniTrellisManifest;
|
|
9
|
+
export declare function writeManifest(cwd: string, manifest: MiniTrellisManifest): void;
|
|
10
|
+
export declare function updateManifestForTemplates(cwd: string, templates: Map<string, string>): MiniTrellisManifest;
|
|
11
|
+
export { MANIFEST_PATH };
|
|
12
|
+
//# sourceMappingURL=managed-manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"managed-manifest.d.ts","sourceRoot":"","sources":["../../src/utils/managed-manifest.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,aAAa,yCAAyC,CAAC;AAG7D,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMxD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAgB7D;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,mBAAmB,GAC5B,IAAI,CAIN;AAED,wBAAgB,0BAA0B,CACxC,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,mBAAmB,CAQrB;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { writeFileAtomic } from "./atomic-write.js";
|
|
5
|
+
const MANIFEST_PATH = ".trellis/.mini-trellis-manifest.json";
|
|
6
|
+
const MANIFEST_VERSION = 1;
|
|
7
|
+
export function hashContent(content) {
|
|
8
|
+
return crypto.createHash("sha256").update(content).digest("hex");
|
|
9
|
+
}
|
|
10
|
+
export function hashFile(filePath) {
|
|
11
|
+
try {
|
|
12
|
+
return hashContent(fs.readFileSync(filePath, "utf8"));
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function readManifest(cwd) {
|
|
19
|
+
try {
|
|
20
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(cwd, MANIFEST_PATH), "utf8"));
|
|
21
|
+
if (parsed.version === MANIFEST_VERSION &&
|
|
22
|
+
parsed.files &&
|
|
23
|
+
typeof parsed.files === "object") {
|
|
24
|
+
return { version: MANIFEST_VERSION, files: { ...parsed.files } };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Missing or malformed manifests are treated as an empty ownership set.
|
|
29
|
+
}
|
|
30
|
+
return { version: MANIFEST_VERSION, files: {} };
|
|
31
|
+
}
|
|
32
|
+
export function writeManifest(cwd, manifest) {
|
|
33
|
+
const filePath = path.join(cwd, MANIFEST_PATH);
|
|
34
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
35
|
+
writeFileAtomic(filePath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
36
|
+
}
|
|
37
|
+
export function updateManifestForTemplates(cwd, templates) {
|
|
38
|
+
const manifest = readManifest(cwd);
|
|
39
|
+
for (const [relative, content] of templates) {
|
|
40
|
+
const actual = hashFile(path.join(cwd, ...relative.split("/")));
|
|
41
|
+
if (actual === hashContent(content))
|
|
42
|
+
manifest.files[relative] = actual;
|
|
43
|
+
}
|
|
44
|
+
writeManifest(cwd, manifest);
|
|
45
|
+
return manifest;
|
|
46
|
+
}
|
|
47
|
+
export { MANIFEST_PATH };
|
|
48
|
+
//# sourceMappingURL=managed-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"managed-manifest.js","sourceRoot":"","sources":["../../src/utils/managed-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,aAAa,GAAG,sCAAsC,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,EAAE,CAAC,CAAC;IAC1D,eAAe,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,GAAW,EACX,SAA8B;IAE9B,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IACnC,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,SAAS,EAAE,CAAC;QAC5C,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChE,IAAI,MAAM,KAAK,WAAW,CAAC,OAAO,CAAC;YAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;IACzE,CAAC;IACD,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC7B,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replace one managed marker block while preserving all user-authored text
|
|
3
|
+
* around it. If the block is absent, append it to the existing file.
|
|
4
|
+
*/
|
|
5
|
+
export declare function mergeManagedBlock(existing: string, managed: string, startMarker: string, endMarker: string): string;
|
|
6
|
+
/** Merge a managed marker block on disk and report whether bytes changed. */
|
|
7
|
+
export declare function mergeManagedBlockFile(filePath: string, managed: string, startMarker: string, endMarker: string): boolean;
|
|
8
|
+
type JsonValue = unknown;
|
|
9
|
+
/**
|
|
10
|
+
* Add missing template keys and array entries without overwriting user
|
|
11
|
+
* settings. This is intentionally conservative: existing scalar values win.
|
|
12
|
+
*/
|
|
13
|
+
export declare function mergeJsonValues(existing: JsonValue, desired: JsonValue): JsonValue;
|
|
14
|
+
/** Merge a JSON template on disk while preserving existing user values. */
|
|
15
|
+
export declare function mergeJsonFile(filePath: string, desiredContent: string): "written" | "unchanged" | "invalid";
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=managed-merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"managed-merge.d.ts","sourceRoot":"","sources":["../../src/utils/managed-merge.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,MAAM,CAsBR;AAED,6EAA6E;AAC7E,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAST;AAED,KAAK,SAAS,GAAG,OAAO,CAAC;AAWzB;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,SAAS,GACjB,SAAS,CAoBX;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,GACrB,SAAS,GAAG,WAAW,GAAG,SAAS,CA0BrC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { writeFileAtomic } from "./atomic-write.js";
|
|
4
|
+
function hasOwn(value, key) {
|
|
5
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Replace one managed marker block while preserving all user-authored text
|
|
9
|
+
* around it. If the block is absent, append it to the existing file.
|
|
10
|
+
*/
|
|
11
|
+
export function mergeManagedBlock(existing, managed, startMarker, endMarker) {
|
|
12
|
+
const managedStart = managed.indexOf(startMarker);
|
|
13
|
+
const managedEnd = managed.indexOf(endMarker, managedStart);
|
|
14
|
+
if (managedStart < 0 || managedEnd < 0) {
|
|
15
|
+
throw new Error("Managed content is missing its marker pair");
|
|
16
|
+
}
|
|
17
|
+
const block = managed
|
|
18
|
+
.slice(managedStart, managedEnd + endMarker.length)
|
|
19
|
+
.trimEnd();
|
|
20
|
+
const existingStart = existing.indexOf(startMarker);
|
|
21
|
+
const existingEnd = existingStart >= 0 ? existing.indexOf(endMarker, existingStart) : -1;
|
|
22
|
+
if (existingStart >= 0 && existingEnd >= 0) {
|
|
23
|
+
const before = existing.slice(0, existingStart).trimEnd();
|
|
24
|
+
const after = existing.slice(existingEnd + endMarker.length).trimStart();
|
|
25
|
+
return [before, block, after].filter(Boolean).join("\n\n") + "\n";
|
|
26
|
+
}
|
|
27
|
+
const trimmed = existing.trimEnd();
|
|
28
|
+
return trimmed ? `${trimmed}\n\n${block}\n` : `${block}\n`;
|
|
29
|
+
}
|
|
30
|
+
/** Merge a managed marker block on disk and report whether bytes changed. */
|
|
31
|
+
export function mergeManagedBlockFile(filePath, managed, startMarker, endMarker) {
|
|
32
|
+
const existing = fs.existsSync(filePath)
|
|
33
|
+
? fs.readFileSync(filePath, "utf8")
|
|
34
|
+
: "";
|
|
35
|
+
const merged = mergeManagedBlock(existing, managed, startMarker, endMarker);
|
|
36
|
+
if (merged === existing)
|
|
37
|
+
return false;
|
|
38
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
39
|
+
writeFileAtomic(filePath, merged);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
function isRecord(value) {
|
|
43
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
44
|
+
}
|
|
45
|
+
function jsonEqual(left, right) {
|
|
46
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Add missing template keys and array entries without overwriting user
|
|
50
|
+
* settings. This is intentionally conservative: existing scalar values win.
|
|
51
|
+
*/
|
|
52
|
+
export function mergeJsonValues(existing, desired) {
|
|
53
|
+
if (Array.isArray(existing) && Array.isArray(desired)) {
|
|
54
|
+
const merged = [...existing];
|
|
55
|
+
for (const item of desired) {
|
|
56
|
+
if (!merged.some((candidate) => jsonEqual(candidate, item)))
|
|
57
|
+
merged.push(item);
|
|
58
|
+
}
|
|
59
|
+
return merged;
|
|
60
|
+
}
|
|
61
|
+
if (isRecord(existing) && isRecord(desired)) {
|
|
62
|
+
const merged = { ...existing };
|
|
63
|
+
for (const [key, value] of Object.entries(desired)) {
|
|
64
|
+
if (!hasOwn(existing, key))
|
|
65
|
+
merged[key] = value;
|
|
66
|
+
else
|
|
67
|
+
merged[key] = mergeJsonValues(existing[key], value);
|
|
68
|
+
}
|
|
69
|
+
return merged;
|
|
70
|
+
}
|
|
71
|
+
return existing;
|
|
72
|
+
}
|
|
73
|
+
/** Merge a JSON template on disk while preserving existing user values. */
|
|
74
|
+
export function mergeJsonFile(filePath, desiredContent) {
|
|
75
|
+
let desired;
|
|
76
|
+
try {
|
|
77
|
+
desired = JSON.parse(desiredContent);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return "invalid";
|
|
81
|
+
}
|
|
82
|
+
if (!fs.existsSync(filePath)) {
|
|
83
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
84
|
+
writeFileAtomic(filePath, `${JSON.stringify(desired, null, 2)}\n`);
|
|
85
|
+
return "written";
|
|
86
|
+
}
|
|
87
|
+
let existing;
|
|
88
|
+
try {
|
|
89
|
+
existing = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return "invalid";
|
|
93
|
+
}
|
|
94
|
+
const merged = mergeJsonValues(existing, desired);
|
|
95
|
+
const rendered = `${JSON.stringify(merged, null, 2)}\n`;
|
|
96
|
+
if (rendered === fs.readFileSync(filePath, "utf8"))
|
|
97
|
+
return "unchanged";
|
|
98
|
+
writeFileAtomic(filePath, rendered);
|
|
99
|
+
return "written";
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=managed-merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"managed-merge.js","sourceRoot":"","sources":["../../src/utils/managed-merge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,SAAS,MAAM,CAAC,KAAa,EAAE,GAAW;IACxC,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC1D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,QAAgB,EAChB,OAAe,EACf,WAAmB,EACnB,SAAiB;IAEjB,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAClD,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAC5D,IAAI,YAAY,GAAG,CAAC,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,KAAK,GAAG,OAAO;SAClB,KAAK,CAAC,YAAY,EAAE,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC;SAClD,OAAO,EAAE,CAAC;IACb,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACpD,MAAM,WAAW,GACf,aAAa,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEvE,IAAI,aAAa,IAAI,CAAC,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,MAAM,GAAG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memory layer for AI coding agents: spec, research, journal, and cross-session recall.
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Minimal memory layer for AI coding agents: spec, research, journal, and cross-session recall.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/Tiger-zzZ/mini-trellis.git"
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"chalk": "^5.3.0",
|
|
35
35
|
"commander": "^12.1.0",
|
|
36
|
-
"figlet": "
|
|
36
|
+
"figlet": "1.8.2",
|
|
37
37
|
"inquirer": "^9.3.7",
|
|
38
|
-
"mini-trellis-core": "0.1
|
|
38
|
+
"mini-trellis-core": "0.2.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@eslint/js": "^9.18.0",
|