@time-machine-lab/tmlbrain 0.1.0

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.
Files changed (42) hide show
  1. package/README.md +152 -0
  2. package/bin/tmlbrain.js +1653 -0
  3. package/docs/.gitkeep +0 -0
  4. package/docs/api/.gitkeep +0 -0
  5. package/docs/architecture.md +84 -0
  6. package/docs/backup.md +76 -0
  7. package/docs/decisions/.gitkeep +1 -0
  8. package/docs/decisions/0001-core-runtime.md +18 -0
  9. package/docs/design/.gitkeep +0 -0
  10. package/docs/fixtures/knowledge-sample/alpha-reference.md +14 -0
  11. package/docs/fixtures/knowledge-sample/project-alpha.md +18 -0
  12. package/docs/fixtures/patches/update-alpha-reference.patch +9 -0
  13. package/docs/indexing.md +32 -0
  14. package/docs/install.md +166 -0
  15. package/docs/preview/.gitkeep +0 -0
  16. package/docs/roadmap.md +27 -0
  17. package/docs/runtime.md +95 -0
  18. package/docs/server-api.md +120 -0
  19. package/docs/spec/.gitkeep +0 -0
  20. package/docs/spikes/cocoindex-local-indexing.md +31 -0
  21. package/docs/spikes/lightrag-retrieval.md +27 -0
  22. package/docs/sql/.gitkeep +0 -0
  23. package/docs/sync.md +110 -0
  24. package/knowledge/README.md +71 -0
  25. package/knowledge/_templates/area.md +18 -0
  26. package/knowledge/_templates/decision.md +18 -0
  27. package/knowledge/_templates/meeting.md +18 -0
  28. package/knowledge/_templates/project.md +18 -0
  29. package/knowledge/_templates/reference.md +18 -0
  30. package/knowledge/_templates/resource.md +18 -0
  31. package/package.json +41 -0
  32. package/scripts/README.md +12 -0
  33. package/scripts/backup/server-to-github.ps1 +20 -0
  34. package/scripts/backup/server-to-github.sh +13 -0
  35. package/scripts/docker/server-entrypoint.sh +84 -0
  36. package/scripts/install/install.ps1 +44 -0
  37. package/scripts/install/install.sh +41 -0
  38. package/scripts/release/parse-auto-release.js +166 -0
  39. package/scripts/sync/.gitkeep +1 -0
  40. package/scripts/sync/post-receive.sample +8 -0
  41. package/skills/tmlbrain/SKILL.md +192 -0
  42. package/skills/tmlbrain/agents/openai.yaml +7 -0
package/docs/.gitkeep ADDED
File without changes
File without changes
@@ -0,0 +1,84 @@
1
+ # TMLBrain Architecture
2
+
3
+ ## Storage Layers
4
+
5
+ ```text
6
+ Local Snapshot <- Server Knowledge Base -> Dedicated Knowledge Repo
7
+ | |
8
+ | +-> Optional Online Reader
9
+ |
10
+ +-> AI Search Skill / Server Write Requests
11
+ ```
12
+
13
+ The TMLBrain tool repository and the team knowledge repository are separate.
14
+ The tool repository contains CLI code, Docker packaging, Skill instructions,
15
+ docs, templates, and release workflows. Real team knowledge lives in a
16
+ dedicated Git repository that contains `knowledge/` at its root.
17
+
18
+ ## Local Snapshot
19
+
20
+ The local snapshot is optimized for fast reading, searching, indexing, and AI
21
+ retrieval. Users and AI agents work against the local copy for search, then
22
+ request server-side writes when knowledge must change. Clients do not mutate the
23
+ remote Git repository and do not need Git in the HTTP-only workflow.
24
+
25
+ ## Server Knowledge Base
26
+
27
+ The server copy is the shared operational source. It receives write requests
28
+ through the TMLBrain server API, mutates Markdown, validates the knowledge base,
29
+ commits repository changes, and is periodically backed up to the dedicated
30
+ knowledge repository.
31
+
32
+ In Docker deployments, the server stores runtime data under the mounted
33
+ `/data` volume:
34
+
35
+ ```text
36
+ /data/worktree server worktree used by the API
37
+ /data/tmlbrain.git local bare repository used by the server
38
+ ```
39
+
40
+ On first boot, if `/data/worktree` does not exist and
41
+ `TMLBRAIN_KNOWLEDGE_REPO` is configured, the server clones that dedicated
42
+ knowledge repository instead of starting from an empty knowledge base.
43
+
44
+ ## Dedicated Knowledge Repository
45
+
46
+ The dedicated knowledge repository is used for first-boot restore, disaster
47
+ recovery, version history, and reviewable snapshots. It is not the primary
48
+ editing interface, and clients do not push to it.
49
+
50
+ The Docker image intentionally contains only the TMLBrain tool and knowledge
51
+ templates. It must not contain real team knowledge.
52
+
53
+ ## Release Workflow
54
+
55
+ The npm client package, Docker server image, and server deployment are handled
56
+ by one main-branch workflow, `.github/workflows/auto-release.yml`. The workflow
57
+ reads the HEAD commit message and only releases when `<Auto>` is present.
58
+
59
+ The commit message provides:
60
+
61
+ - `-v:<semver>` for both npm and Docker versions;
62
+ - `-rp:<port>` for the Docker image default server port;
63
+ - optional `-de:<...>` runtime Docker metadata in the commit message.
64
+
65
+ The workflow does not commit release logs back to the repository. Maintainers
66
+ can update `prod_deploy.log` manually before committing an auto-release
67
+ instruction when they want an explicit production release trail.
68
+
69
+ Docker publishing uses `DOCKER_USERNAME`, `DOCKER_PASSWORD`, and `DOCKER_REPO`.
70
+ After pushing the image, the workflow logs in to the configured server with
71
+ `SERVER_HOST`, `SERVER_USER`, and `SERVER_PWD`, pulls the new image, and
72
+ restarts the `tmlbrain-server` container. Runtime knowledge repository
73
+ credentials are passed to the server as mounted secrets or environment
74
+ configuration; they are never baked into the image. Knowledge repository URLs
75
+ must be HTTPS URLs and use `TMLBRAIN_KNOWLEDGE_TOKEN`.
76
+
77
+ ## Search And Graph Layer
78
+
79
+ The first implementation can combine:
80
+
81
+ - full-text search over Markdown files;
82
+ - metadata search using front matter;
83
+ - backlink extraction from Markdown links;
84
+ - later semantic embeddings for natural-language retrieval.
package/docs/backup.md ADDED
@@ -0,0 +1,76 @@
1
+ # Backup And Recovery
2
+
3
+ ## Backup Role
4
+
5
+ The dedicated knowledge repository is used for disaster recovery, reviewable
6
+ history, first-boot restore, and off-server backup. It is not the primary
7
+ editing surface.
8
+
9
+ The server needs a dedicated knowledge repository credential only if it is
10
+ expected to push backup state to a private GitHub repository. Clients never
11
+ need repository write credentials.
12
+
13
+ If TMLBrain must upload modified server knowledge back to GitHub, the running
14
+ server needs write authorization for the dedicated knowledge repository. GitHub
15
+ will not accept anonymous pushes, even if the repository is public. A public
16
+ repository may allow unauthenticated clone/read, but push/backup still requires
17
+ a credential.
18
+
19
+ Recommended credential option:
20
+
21
+ - GitHub token with repository write permission, injected as a runtime secret.
22
+ Fine-grained tokens are preferred; classic tokens also work with the right
23
+ scope: use `repo` for private repositories, or `public_repo` only for public
24
+ repositories. Use it with HTTPS repository URLs such as
25
+ `https://github.com/org/repo.git`.
26
+
27
+ Do not bake knowledge repository credentials into the Docker image. Do not
28
+ commit them to the project configuration. GitHub Actions secrets can be used to
29
+ deploy the credential to the server or create a Docker secret, but the running
30
+ server still needs access to a credential when it performs `tmlbrain backup`.
31
+
32
+ The auto-release workflow supports this deployment pattern with:
33
+
34
+ ```text
35
+ TMLBRAIN_KNOWLEDGE_REPO
36
+ TMLBRAIN_KNOWLEDGE_TOKEN
37
+ TMLBRAIN_KNOWLEDGE_REF
38
+ ```
39
+
40
+ `TMLBRAIN_KNOWLEDGE_REPO` must be an HTTPS repository URL. The workflow writes
41
+ `TMLBRAIN_KNOWLEDGE_TOKEN` to a mounted secret file and uses `GIT_ASKPASS`
42
+ inside the container, so Git can clone on first boot and push backups later.
43
+
44
+ ## Dry Run
45
+
46
+ Use:
47
+
48
+ ```text
49
+ tmlbrain backup --dry-run --remote backup
50
+ ```
51
+
52
+ The command reports the source commit, target remote, and whether the target remote exists. Backup attempts are logged under `.tmlbrain/logs/backup.log`.
53
+
54
+ For Docker deployments, keep Git inside the server image or sidecar because the
55
+ server write path still commits and pushes. The client runtime can remain
56
+ HTTP-only and does not need Git.
57
+
58
+ ## Recovery
59
+
60
+ For Docker deployments, first-boot restore can be handled by:
61
+
62
+ ```text
63
+ TMLBRAIN_KNOWLEDGE_REPO=https://github.com/Time-Machine-Lab/TMLBrainKnowledge.git
64
+ ```
65
+
66
+ If `/data/worktree` is missing, the container clones that repository. If the
67
+ mounted data volume already contains `/data/worktree`, the server reuses it and
68
+ does not overwrite it.
69
+
70
+ To recover a failed non-Docker server:
71
+
72
+ 1. Provision a new server with Git.
73
+ 2. Clone the dedicated knowledge repository as a bare repository.
74
+ 3. Recreate the server worktree from the bare repository.
75
+ 4. Reconfigure TMLBrain clients to use the new server remote.
76
+ 5. Run `tmlbrain sync` from clients to refresh local state.
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,18 @@
1
+ # 0001 Core Runtime Choice
2
+
3
+ ## Decision
4
+
5
+ Use a dependency-light Node CLI for the TMLBrain core runtime.
6
+
7
+ ## Rationale
8
+
9
+ The default user path must support npm/npx client install, validation, exact search, document creation, read-only snapshot synchronization, server API write requests, conflict-aware retries, backup dry-runs, and Skill command recipes without requiring Python.
10
+
11
+ Node is already available in the TmlUs/Codex workflow used by this project, and the core CLI can rely on built-in Node modules plus external Git. Python remains optional and is activated only for graph retrieval features such as CocoIndex and LightRAG.
12
+
13
+ ## Consequences
14
+
15
+ - Core TMLBrain remains usable immediately after default client installation.
16
+ - HTTP-only clients do not require Git; Git remains a server, backup, or legacy migration dependency.
17
+ - CocoIndex and LightRAG are graph-runtime enhancements, not core sync dependencies.
18
+ - Markdown parsing is intentionally simple in the MVP and can be replaced with a structured parser later.
File without changes
@@ -0,0 +1,14 @@
1
+ ---
2
+ title: Alpha Reference
3
+ type: reference
4
+ status: active
5
+ owner: TML
6
+ tags: [alpha, reference]
7
+ updated: 2026-06-16
8
+ ---
9
+
10
+ # Alpha Reference
11
+
12
+ ## Facts
13
+
14
+ This fixture is used to validate exact search, metadata extraction, and backlink generation.
@@ -0,0 +1,18 @@
1
+ ---
2
+ title: Project Alpha
3
+ type: project
4
+ status: active
5
+ owner: TML
6
+ tags: [alpha]
7
+ updated: 2026-06-16
8
+ ---
9
+
10
+ # Project Alpha
11
+
12
+ ## Purpose
13
+
14
+ Project Alpha validates local indexing, deterministic graph extraction, and retrieval behavior.
15
+
16
+ ## Links
17
+
18
+ See [Alpha Reference](alpha-reference.md) and [[Operations Area]].
@@ -0,0 +1,9 @@
1
+ diff --git a/docs/fixtures/knowledge-sample/alpha-reference.md b/docs/fixtures/knowledge-sample/alpha-reference.md
2
+ --- a/docs/fixtures/knowledge-sample/alpha-reference.md
3
+ +++ b/docs/fixtures/knowledge-sample/alpha-reference.md
4
+ @@ -12,4 +12,4 @@ updated: 2026-06-16
5
+
6
+ ## Facts
7
+
8
+ -This fixture is used to validate exact search, metadata extraction, and backlink generation.
9
+ +This fixture validates exact search, metadata extraction, and backlink generation.
@@ -0,0 +1,32 @@
1
+ # Local Indexing And Retrieval
2
+
3
+ ## Layers
4
+
5
+ TMLBrain retrieval is local-first:
6
+
7
+ 1. Exact search with ripgrep or the CLI fallback.
8
+ 2. Deterministic Markdown index generated by `tmlbrain index`.
9
+ 3. Optional CocoIndex incremental pipeline.
10
+ 4. Optional LightRAG graph and semantic retrieval.
11
+
12
+ ## Deterministic Index
13
+
14
+ `tmlbrain index` writes local artifacts under `.tmlbrain/index/`:
15
+
16
+ - `documents.json`: file path, metadata, headings, hashes, and timestamps.
17
+ - `chunks.json`: heading-based chunks with line ranges and hashes.
18
+ - `graph.json`: deterministic links, tags, owner, and status edges.
19
+ - `manifest.json`: index summary and degraded-mode status.
20
+
21
+ These files are local generated artifacts and must not be pushed to the server.
22
+
23
+ ## Graph Runtime
24
+
25
+ CocoIndex and LightRAG are preferred for the fuller graph retrieval pipeline, but exact search and the deterministic index remain available when the graph runtime is disabled.
26
+
27
+ Optional adapter entrypoints live in:
28
+
29
+ - `scripts/index/cocoindex_pipeline.py`
30
+ - `scripts/index/lightrag_retrieval.py`
31
+
32
+ They intentionally return degraded status when the Python graph packages are not installed. A later implementation pass should wire them to a real CocoIndex flow and provider-configured LightRAG storage/retrieval setup.
@@ -0,0 +1,166 @@
1
+ # TMLBrain Install
2
+
3
+ ## Client
4
+
5
+ Recommended interactive install:
6
+
7
+ ```text
8
+ npx @time-machine-lab/tmlbrain client install
9
+ ```
10
+
11
+ The installer asks for:
12
+
13
+ - server URL, optional;
14
+ - server token, only when a server URL is provided;
15
+ - optional graph runtime setup.
16
+
17
+ Leave the server URL empty to start in local-only mode. Local-only clients can
18
+ search, index, and save Markdown under the local `knowledge/` folder. They can
19
+ connect to a team server later:
20
+
21
+ ```text
22
+ tmlbrain config set-server http://server-host:7389 --token <token>
23
+ tmlbrain sync --pull
24
+ ```
25
+
26
+ Non-interactive client install:
27
+
28
+ ```text
29
+ npx @time-machine-lab/tmlbrain client install --server http://server-host:7389 --token <token> --yes
30
+ ```
31
+
32
+ Global install is also supported after the npm package is published:
33
+
34
+ ```text
35
+ npm install -g @time-machine-lab/tmlbrain
36
+ tmlbrain client install
37
+ ```
38
+
39
+ ## Server
40
+
41
+ The server is installed separately and should run in Docker. The token is
42
+ required. Team deployments should also provide `TMLBRAIN_KNOWLEDGE_REPO` so the
43
+ server restores the real knowledge base instead of starting from a template-only
44
+ skeleton.
45
+
46
+ ```text
47
+ docker run -d --name tmlbrain-server \
48
+ -p 7389:7389 \
49
+ -e TMLBRAIN_SERVER_TOKEN=<required-token> \
50
+ -e TMLBRAIN_KNOWLEDGE_REPO=https://github.com/Time-Machine-Lab/TMLBrainKnowledge.git \
51
+ -e TMLBRAIN_KNOWLEDGE_REF=main \
52
+ -v tmlbrain-data:/data \
53
+ <DOCKER_REPO>:latest
54
+ ```
55
+
56
+ Compose:
57
+
58
+ ```text
59
+ TMLBRAIN_SERVER_TOKEN=<required-token> docker compose up -d
60
+ ```
61
+
62
+ The container initializes or reuses:
63
+
64
+ ```text
65
+ /data/worktree server worktree used by the API
66
+ /data/tmlbrain.git server bare repository
67
+ ```
68
+
69
+ ## Dedicated Knowledge Repository
70
+
71
+ The Docker image does not contain real team knowledge. Real knowledge should be
72
+ stored in a separate private repository, for example:
73
+
74
+ ```text
75
+ https://github.com/Time-Machine-Lab/TMLBrainKnowledge.git
76
+ ```
77
+
78
+ That repository must contain the TMLBrain `knowledge/` directory at its root.
79
+ On first server boot:
80
+
81
+ 1. If `/data/worktree` already exists, the container reuses it.
82
+ 2. Else if `TMLBRAIN_KNOWLEDGE_REPO` is configured, the container clones that
83
+ repository and registers it as the `backup` remote.
84
+ 3. Else the container initializes a template-only skeleton for development or
85
+ blank starts.
86
+
87
+ The image is published by `.github/workflows/auto-release.yml` to the Docker
88
+ repository configured in GitHub Actions secret `DOCKER_REPO`. The npm client
89
+ package is published by the same workflow with the `NPM_TOKEN` repository
90
+ secret. The workflow then logs in to the target server with
91
+ `SERVER_HOST`, `SERVER_USER`, and `SERVER_PWD`, pulls the new image, and
92
+ restarts the `tmlbrain-server` container.
93
+
94
+ ```text
95
+ <DOCKER_REPO>:latest
96
+ <DOCKER_REPO>:<version>
97
+ <DOCKER_REPO>:v<version>
98
+ ```
99
+
100
+ Required GitHub Actions secrets:
101
+
102
+ ```text
103
+ NPM_TOKEN
104
+ DOCKER_USERNAME
105
+ DOCKER_PASSWORD
106
+ DOCKER_REPO
107
+ SERVER_HOST
108
+ SERVER_USER
109
+ SERVER_PWD
110
+ TMLBRAIN_SERVER_TOKEN
111
+ ```
112
+
113
+ Knowledge repository secrets for private GitHub backup/restore:
114
+
115
+ ```text
116
+ TMLBRAIN_KNOWLEDGE_REPO
117
+ TMLBRAIN_KNOWLEDGE_TOKEN
118
+ TMLBRAIN_KNOWLEDGE_REF
119
+ ```
120
+
121
+ `TMLBRAIN_KNOWLEDGE_REPO` must be an HTTPS URL, for example
122
+ `https://github.com/Time-Machine-Lab/TMLBrainKnowledge.git`.
123
+ `TMLBRAIN_KNOWLEDGE_TOKEN` must be a GitHub token with write access to that
124
+ dedicated knowledge repository. Fine-grained tokens are preferred; classic
125
+ tokens also work when they have the right repository scope: use `repo` for
126
+ private repositories, or `public_repo` only for public repositories. This
127
+ credential belongs to the server runtime, not to clients and not to the Docker
128
+ image.
129
+
130
+ ## Release Command Format
131
+
132
+ Releases are driven by the HEAD commit message on `main`. The workflow skips
133
+ commits that do not contain `<Auto>`.
134
+
135
+ Example:
136
+
137
+ ```text
138
+ [tml-brain]<Auto> release server and client -v:0.1.0 -rp:7389 -de:<-e KEY=value>
139
+ ```
140
+
141
+ Fields:
142
+
143
+ - `<Auto>` is required to trigger publishing.
144
+ - `-v:<semver>` is required and is used for both npm and Docker versions. Use a
145
+ Docker-compatible value such as `0.1.0` or `0.1.0-beta.1`.
146
+ - `-rp:<port>` is optional and defaults to `7389`; it becomes the Docker image
147
+ default `TMLBRAIN_PORT`.
148
+ - `-de:<...>` is optional single-line Docker runtime metadata, such as
149
+ additional `docker run -e` arguments. It stays in the commit message and is
150
+ not baked as a secret into the image.
151
+
152
+ The workflow does not update repository files. If maintainers want a production
153
+ release trail, update `prod_deploy.log` manually in the same local change set
154
+ before committing the auto-release instruction. Before publishing artifacts,
155
+ the workflow runs tests. If the requested npm version already exists, npm
156
+ publishing is skipped so Docker image publishing and server deployment can be
157
+ retried with the same release commit.
158
+
159
+ ## Runtime Split
160
+
161
+ - Clients use npm/npx and only need Node.
162
+ - Clients may run local-only without a server.
163
+ - Team sync and writes require a server URL and token.
164
+ - Servers use Docker and require `TMLBRAIN_SERVER_TOKEN`.
165
+ - Git and dedicated knowledge repository credentials belong to the server side,
166
+ not clients.
File without changes
@@ -0,0 +1,27 @@
1
+ # Roadmap
2
+
3
+ ## Phase 1: Project Foundation
4
+
5
+ - Create repository structure.
6
+ - Define knowledge folder rules.
7
+ - Define AI skill responsibilities.
8
+ - Decide sync direction and conflict policy.
9
+
10
+ ## Phase 2: Sync And Backup
11
+
12
+ - Add local-to-server sync script.
13
+ - Add server-to-local refresh script.
14
+ - Add scheduled server-to-dedicated-knowledge-repository backup script.
15
+ - Add dry-run and conflict detection.
16
+
17
+ ## Phase 3: Retrieval
18
+
19
+ - Add Markdown full-text search.
20
+ - Add metadata index.
21
+ - Add document relation graph.
22
+ - Add optional semantic search.
23
+
24
+ ## Phase 4: Online Reading
25
+
26
+ - Generate a static reading site from `knowledge/`.
27
+ - Optionally sync selected documents to Feishu for team browsing.
@@ -0,0 +1,95 @@
1
+ # TMLBrain Runtime
2
+
3
+ ## Goal
4
+
5
+ TMLBrain should feel like one product to the user:
6
+
7
+ ```text
8
+ npx @time-machine-lab/tmlbrain client install
9
+ @TMLBrain search or update knowledge
10
+ ```
11
+
12
+ Git, indexing, patches, and conflict handling are implementation details hidden
13
+ behind TMLBrain CLI, server API, MCP tools, and Skill instructions.
14
+
15
+ ## Core Runtime
16
+
17
+ The core runtime must work without Python:
18
+
19
+ - TMLBrain CLI.
20
+ - TMLBrain Skill registration.
21
+ - Local workspace state under `.tmlbrain/`.
22
+ - Exact search.
23
+ - Markdown validation.
24
+ - Document creation.
25
+ - Server API write requests.
26
+ - Read-only snapshot sync.
27
+
28
+ HTTP-only clients do not require Git. Git detection/provisioning belongs to the
29
+ server runtime and legacy migration flows.
30
+
31
+ ## Optional Graph Runtime
32
+
33
+ CocoIndex and LightRAG are optional graph retrieval features. They are enabled by:
34
+
35
+ ```text
36
+ tmlbrain graph setup
37
+ ```
38
+
39
+ If Python, CocoIndex, or LightRAG cannot be activated, core TMLBrain remains usable in degraded search mode.
40
+
41
+ ## Installer Entry Points
42
+
43
+ Recommended npm client entry:
44
+
45
+ ```text
46
+ npx @time-machine-lab/tmlbrain client install
47
+ ```
48
+
49
+ The client installer asks for a server URL. Leaving it empty starts local-only
50
+ mode; providing a server URL also asks for the server token.
51
+
52
+ Windows:
53
+
54
+ ```powershell
55
+ powershell -ExecutionPolicy Bypass -File scripts/install/install.ps1
56
+ ```
57
+
58
+ macOS/Linux:
59
+
60
+ ```sh
61
+ sh scripts/install/install.sh
62
+ ```
63
+
64
+ Both scripts call the same CLI bootstrap flow and keep the user away from raw Git commands.
65
+
66
+ Non-interactive client install:
67
+
68
+ ```text
69
+ npx @time-machine-lab/tmlbrain client install --server http://server-host:7389 --token secret --yes
70
+ ```
71
+
72
+ ## Server Runtime
73
+
74
+ Run with Docker:
75
+
76
+ ```text
77
+ docker run -d --name tmlbrain-server -p 7389:7389 -e TMLBRAIN_SERVER_TOKEN=secret -e TMLBRAIN_KNOWLEDGE_REPO=https://github.com/Time-Machine-Lab/TMLBrainKnowledge.git -v tmlbrain-data:/data <DOCKER_REPO>:latest
78
+ ```
79
+
80
+ The image contains tooling and templates only. Real knowledge is restored from
81
+ `TMLBRAIN_KNOWLEDGE_REPO` on first boot or reused from the mounted data volume.
82
+ Released images get their default `TMLBRAIN_PORT` from the `-rp` value in the
83
+ `<Auto>` release commit message. Runtime deployments can still override the
84
+ port with `-e TMLBRAIN_PORT=<port>` and the corresponding Docker `-p` mapping.
85
+
86
+ Manual development mode from the server worktree:
87
+
88
+ ```text
89
+ node bin/tmlbrain.js serve --host 0.0.0.0 --port 7389
90
+ ```
91
+
92
+ Only the server runtime should mutate Markdown, commit repository changes, or
93
+ push to the dedicated knowledge repository. Clients should use `tmlbrain sync
94
+ --pull` for snapshots, `tmlbrain find` for local search, and `tmlbrain save` or
95
+ `tmlbrain remote update` for write requests.
@@ -0,0 +1,120 @@
1
+ # TMLBrain Server API
2
+
3
+ TMLBrain uses a server-owned write boundary.
4
+
5
+ Clients keep a read-only local snapshot for search and indexing. Clients request
6
+ knowledge mutations through the TMLBrain server API. The server mutates
7
+ Markdown, validates the knowledge base, commits the repository change, and then
8
+ pushes from the server worktree to the server bare repository.
9
+
10
+ ## Run The Server
11
+
12
+ Recommended Docker deployment:
13
+
14
+ ```text
15
+ docker run -d --name tmlbrain-server \
16
+ -p 7389:7389 \
17
+ -e TMLBRAIN_SERVER_TOKEN=secret \
18
+ -e TMLBRAIN_KNOWLEDGE_REPO=https://github.com/Time-Machine-Lab/TMLBrainKnowledge.git \
19
+ -v tmlbrain-data:/data \
20
+ <DOCKER_REPO>:latest
21
+ ```
22
+
23
+ `TMLBRAIN_KNOWLEDGE_REPO` points at the dedicated knowledge repository. If the
24
+ data volume already contains `/data/worktree`, the container reuses that
25
+ worktree instead of cloning again.
26
+
27
+ Run from the server worktree:
28
+
29
+ ```text
30
+ node bin/tmlbrain.js serve --host 0.0.0.0 --port 7389
31
+ ```
32
+
33
+ Optional token protection:
34
+
35
+ ```text
36
+ TMLBRAIN_SERVER_TOKEN=secret node bin/tmlbrain.js serve --host 0.0.0.0 --port 7389
37
+ ```
38
+
39
+ Clients then install with:
40
+
41
+ ```text
42
+ npx @time-machine-lab/tmlbrain client install --server http://server-host:7389 --token secret --yes
43
+ ```
44
+
45
+ The client stores this in `.tmlbrain/state.json`. The token is not shown by
46
+ normal config commands.
47
+
48
+ Show the active client server:
49
+
50
+ ```text
51
+ node bin/tmlbrain.js config show
52
+ ```
53
+
54
+ Switch a client to a different server:
55
+
56
+ ```text
57
+ node bin/tmlbrain.js config set-server http://new-server-host:7389 --token secret
58
+ node bin/tmlbrain.js sync --pull
59
+ ```
60
+
61
+ `--server` and `--token` can also be passed to one command for temporary
62
+ overrides.
63
+
64
+ If the cloud security group does not expose port `7389`, keep the API private
65
+ and use a tunnel from the client machine:
66
+
67
+ ```text
68
+ ssh -N -L 7390:127.0.0.1:7389 tmlbrain-1007
69
+ npx @time-machine-lab/tmlbrain client install --server http://127.0.0.1:7390 --token secret --yes
70
+ ```
71
+
72
+ ## Client Commands
73
+
74
+ Pull a read-only snapshot:
75
+
76
+ ```text
77
+ node bin/tmlbrain.js sync --pull
78
+ ```
79
+
80
+ Search locally:
81
+
82
+ ```text
83
+ node bin/tmlbrain.js find "keyword"
84
+ ```
85
+
86
+ Save text through the server:
87
+
88
+ ```text
89
+ node bin/tmlbrain.js save --title "Title" --content "Content"
90
+ ```
91
+
92
+ Save a local file through the server:
93
+
94
+ ```text
95
+ node bin/tmlbrain.js save ./note.md
96
+ ```
97
+
98
+ Ask the server to update a precise text region:
99
+
100
+ ```text
101
+ node bin/tmlbrain.js remote update --file knowledge/00-inbox/note.md --replace "old text" --with "new text"
102
+ ```
103
+
104
+ ## API Endpoints
105
+
106
+ - `GET /health`: server health and current head.
107
+ - `GET /capabilities`: machine-readable command and boundary description.
108
+ - `GET /snapshot`: read-only Markdown snapshot for clients.
109
+ - `POST /knowledge/add`: server-side add, validate, commit, and push.
110
+ - `POST /knowledge/update`: server-side replace or content-file update, validate, commit, and push.
111
+
112
+ ## Boundary
113
+
114
+ Clients MUST NOT push to the server Git repository or dedicated knowledge
115
+ repository. Backing up to that repository remains a server-side operation
116
+ through `tmlbrain backup`.
117
+
118
+ HTTP-only clients do not need Git installed. The server runtime still needs Git
119
+ because it validates, commits, pushes to the server bare repository, and runs
120
+ dedicated knowledge repository backup jobs.
File without changes