server-handbook 0.1.0__tar.gz

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 (59) hide show
  1. server_handbook-0.1.0/.gitattributes +5 -0
  2. server_handbook-0.1.0/.github/CODEOWNERS +2 -0
  3. server_handbook-0.1.0/.github/ISSUE_TEMPLATE/bug_report.yml +30 -0
  4. server_handbook-0.1.0/.github/ISSUE_TEMPLATE/config.yml +1 -0
  5. server_handbook-0.1.0/.github/ISSUE_TEMPLATE/feature_request.yml +18 -0
  6. server_handbook-0.1.0/.github/pull_request_template.md +11 -0
  7. server_handbook-0.1.0/.github/workflows/ci.yml +55 -0
  8. server_handbook-0.1.0/.github/workflows/publish-pypi.yml +78 -0
  9. server_handbook-0.1.0/.gitignore +17 -0
  10. server_handbook-0.1.0/AGENTS.md +9 -0
  11. server_handbook-0.1.0/CONTRIBUTING.md +17 -0
  12. server_handbook-0.1.0/LICENSE +21 -0
  13. server_handbook-0.1.0/MANIFEST.in +7 -0
  14. server_handbook-0.1.0/PKG-INFO +144 -0
  15. server_handbook-0.1.0/README.md +114 -0
  16. server_handbook-0.1.0/README.zh-CN.md +106 -0
  17. server_handbook-0.1.0/SECURITY.md +11 -0
  18. server_handbook-0.1.0/docs/architecture.md +46 -0
  19. server_handbook-0.1.0/docs/cli.md +37 -0
  20. server_handbook-0.1.0/docs/descriptor-format.md +105 -0
  21. server_handbook-0.1.0/docs/mcp-evaluation.xml +82 -0
  22. server_handbook-0.1.0/docs/mcp.md +66 -0
  23. server_handbook-0.1.0/docs/pypi-publishing.zh-CN.md +69 -0
  24. server_handbook-0.1.0/docs/releasing.md +16 -0
  25. server_handbook-0.1.0/docs/verification.md +28 -0
  26. server_handbook-0.1.0/examples/compose-web/README.md +18 -0
  27. server_handbook-0.1.0/examples/compose-web/compose.yaml +6 -0
  28. server_handbook-0.1.0/examples/compose-web/service.json +31 -0
  29. server_handbook-0.1.0/pyproject.toml +56 -0
  30. server_handbook-0.1.0/setup.cfg +4 -0
  31. server_handbook-0.1.0/src/server_handbook/__init__.py +3 -0
  32. server_handbook-0.1.0/src/server_handbook/__main__.py +3 -0
  33. server_handbook-0.1.0/src/server_handbook/assets/schemas/service.schema.json +391 -0
  34. server_handbook-0.1.0/src/server_handbook/assets/skills/server-handbook/SKILL.md +24 -0
  35. server_handbook-0.1.0/src/server_handbook/assets/skills/server-handbook/references/workflow.md +39 -0
  36. server_handbook-0.1.0/src/server_handbook/cli.py +157 -0
  37. server_handbook-0.1.0/src/server_handbook/config.py +205 -0
  38. server_handbook-0.1.0/src/server_handbook/documents.py +217 -0
  39. server_handbook-0.1.0/src/server_handbook/errors.py +5 -0
  40. server_handbook-0.1.0/src/server_handbook/mcp.py +227 -0
  41. server_handbook-0.1.0/src/server_handbook/operations.py +383 -0
  42. server_handbook-0.1.0/src/server_handbook/registry.py +450 -0
  43. server_handbook-0.1.0/src/server_handbook/runtime.py +133 -0
  44. server_handbook-0.1.0/src/server_handbook.egg-info/PKG-INFO +144 -0
  45. server_handbook-0.1.0/src/server_handbook.egg-info/SOURCES.txt +57 -0
  46. server_handbook-0.1.0/src/server_handbook.egg-info/dependency_links.txt +1 -0
  47. server_handbook-0.1.0/src/server_handbook.egg-info/entry_points.txt +3 -0
  48. server_handbook-0.1.0/src/server_handbook.egg-info/requires.txt +8 -0
  49. server_handbook-0.1.0/src/server_handbook.egg-info/top_level.txt +1 -0
  50. server_handbook-0.1.0/tests/test_cli_assets.py +45 -0
  51. server_handbook-0.1.0/tests/test_docker_integration.py +136 -0
  52. server_handbook-0.1.0/tests/test_mcp.py +207 -0
  53. server_handbook-0.1.0/tests/test_operations.py +250 -0
  54. server_handbook-0.1.0/tests/test_registry.py +280 -0
  55. server_handbook-0.1.0/tests/test_schema.py +140 -0
  56. server_handbook-0.1.0/tests/test_workspace.py +311 -0
  57. server_handbook-0.1.0/tests/test_write_boundaries.py +124 -0
  58. server_handbook-0.1.0/tools/verify_installed.py +145 -0
  59. server_handbook-0.1.0/tools/verify_linux_base.py +60 -0
@@ -0,0 +1,5 @@
1
+ * text=auto eol=lf
2
+ *.png binary
3
+ *.jpg binary
4
+ *.whl binary
5
+ *.gz binary
@@ -0,0 +1,2 @@
1
+ # Changes are proposals until the repository owner reviews and merges them.
2
+ * @zzy1136660162
@@ -0,0 +1,30 @@
1
+ name: Bug report / 问题反馈
2
+ description: Report a reproducible problem with Server Handbook.
3
+ title: "[Bug]: "
4
+ body:
5
+ - type: input
6
+ id: version
7
+ attributes:
8
+ label: Version / 版本
9
+ description: Output of server-handbook --version.
10
+ validations:
11
+ required: true
12
+ - type: textarea
13
+ id: environment
14
+ attributes:
15
+ label: Environment / 运行环境
16
+ description: OS, Python, Docker/Compose or systemd versions, and CLI or MCP usage.
17
+ validations:
18
+ required: true
19
+ - type: textarea
20
+ id: steps
21
+ attributes:
22
+ label: Reproduction / 复现步骤
23
+ description: Use a small anonymous example. Include the command, expected behavior and actual result.
24
+ validations:
25
+ required: true
26
+ - type: textarea
27
+ id: evidence
28
+ attributes:
29
+ label: Relevant output / 相关结果
30
+ description: Include the smallest useful error or check result. Remove passwords, tokens and private server data.
@@ -0,0 +1 @@
1
+ blank_issues_enabled: true
@@ -0,0 +1,18 @@
1
+ name: Feature request / 功能建议
2
+ description: Explain a server-maintenance task this project could support.
3
+ title: "[Feature]: "
4
+ body:
5
+ - type: textarea
6
+ id: task
7
+ attributes:
8
+ label: User task / 使用场景
9
+ description: What are you trying to accomplish, and what currently gets in the way?
10
+ validations:
11
+ required: true
12
+ - type: textarea
13
+ id: outcome
14
+ attributes:
15
+ label: Expected outcome / 期望结果
16
+ description: Describe the observable behavior that would solve the task.
17
+ validations:
18
+ required: true
@@ -0,0 +1,11 @@
1
+ ## Problem and resulting behavior
2
+
3
+ Describe the user task and what changes after this PR.
4
+
5
+ ## Validation
6
+
7
+ List the checks actually performed, and distinguish simulated service tests from real execution.
8
+
9
+ ## Limits
10
+
11
+ State any unverified behavior or migration requirements. Pull requests are proposals; only the maintainer decides what is merged into the original repository.
@@ -0,0 +1,55 @@
1
+ name: checks
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ concurrency:
12
+ group: checks-${{ github.workflow }}-${{ github.ref }}
13
+ cancel-in-progress: true
14
+
15
+ jobs:
16
+ unit-and-package:
17
+ strategy:
18
+ matrix:
19
+ os: [ubuntu-24.04, windows-latest]
20
+ python: ["3.11", "3.13"]
21
+ runs-on: ${{ matrix.os }}
22
+ steps:
23
+ - uses: actions/checkout@v7.0.1
24
+ - uses: actions/setup-python@v7.1.0
25
+ with:
26
+ python-version: ${{ matrix.python }}
27
+ - run: python -m pip install -e ".[mcp,dev]"
28
+ - run: python -m pytest -q
29
+ - run: python -m build
30
+
31
+ real-compose:
32
+ runs-on: ubuntu-24.04
33
+ steps:
34
+ - uses: actions/checkout@v7.0.1
35
+ - uses: actions/setup-python@v7.1.0
36
+ with:
37
+ python-version: "3.13"
38
+ - run: python -m pip install -e ".[mcp,dev]"
39
+ - run: docker pull nginx:alpine
40
+ - run: python -m pytest -q -s tests/test_docker_integration.py
41
+ env:
42
+ SERVER_HANDBOOK_DOCKER_TESTS: "1"
43
+
44
+ ci-success:
45
+ if: always()
46
+ needs: [unit-and-package, real-compose]
47
+ runs-on: ubuntu-24.04
48
+ steps:
49
+ - name: Require all validation jobs
50
+ env:
51
+ UNIT_RESULT: ${{ needs['unit-and-package'].result }}
52
+ COMPOSE_RESULT: ${{ needs['real-compose'].result }}
53
+ run: |
54
+ test "$UNIT_RESULT" = success
55
+ test "$COMPOSE_RESULT" = success
@@ -0,0 +1,78 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ version:
7
+ description: Exact version already committed in server_handbook.__version__
8
+ required: true
9
+ type: string
10
+ default: "0.1.0"
11
+
12
+ permissions:
13
+ contents: read
14
+
15
+ concurrency:
16
+ group: pypi-publish
17
+ cancel-in-progress: false
18
+
19
+ jobs:
20
+ build:
21
+ if: github.repository == 'zzy1136660162/server-handbook' && github.ref == 'refs/heads/main'
22
+ runs-on: ubuntu-24.04
23
+ steps:
24
+ - uses: actions/checkout@v7.0.1
25
+ with:
26
+ persist-credentials: false
27
+ - uses: actions/setup-python@v7.1.0
28
+ with:
29
+ python-version: "3.13"
30
+ - name: Install build and test tools
31
+ run: python -m pip install -e ".[mcp,dev]" twine
32
+ - name: Check the requested version
33
+ env:
34
+ RELEASE_VERSION: ${{ inputs.version }}
35
+ run: |
36
+ python - <<'PY'
37
+ import os
38
+ from server_handbook import __version__
39
+ requested = os.environ["RELEASE_VERSION"]
40
+ if requested != __version__:
41
+ raise SystemExit("Requested version does not match the committed package version.")
42
+ print("Building Server Handbook", __version__)
43
+ PY
44
+ - name: Run package tests
45
+ run: python -m pytest -q
46
+ - name: Build and validate distributions
47
+ run: |
48
+ python -m build
49
+ python -m twine check dist/*
50
+ - name: Verify installed wheel and stdio MCP
51
+ run: |
52
+ python -m pip install --force-reinstall --no-deps dist/*.whl
53
+ python tools/verify_installed.py --output verification/pypi-wheel-check.json
54
+ - uses: actions/upload-artifact@v7.0.2
55
+ with:
56
+ name: pypi-distributions
57
+ path: |
58
+ dist/*.whl
59
+ dist/*.tar.gz
60
+ if-no-files-found: error
61
+ retention-days: 7
62
+
63
+ publish:
64
+ needs: build
65
+ if: github.repository == 'zzy1136660162/server-handbook' && github.ref == 'refs/heads/main'
66
+ runs-on: ubuntu-24.04
67
+ environment:
68
+ name: pypi
69
+ url: https://pypi.org/project/server-handbook/
70
+ permissions:
71
+ id-token: write
72
+ steps:
73
+ - uses: actions/download-artifact@v8.0.2
74
+ with:
75
+ name: pypi-distributions
76
+ path: dist/
77
+ - name: Publish through PyPI Trusted Publishing
78
+ uses: pypa/gh-action-pypi-publish@v1.14.3
@@ -0,0 +1,17 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .pytest_cache/
4
+ .ruff_cache/
5
+ .venv*/
6
+ build/
7
+ dist/
8
+ *.egg-info/
9
+ .server-handbook/
10
+ *.sqlite3
11
+ *.sqlite3-journal
12
+ *.sqlite3-wal
13
+ *.sqlite3-shm
14
+ verification/
15
+ .env
16
+ .env.*
17
+ !.env.example
@@ -0,0 +1,9 @@
1
+ # Server Handbook development
2
+
3
+ Users are self-hosted Linux server owners and their authorized coding agents. The core tasks are zero-context handoff, adopting existing directories, and recording managed deployments. Success means real checks and durable records agree, existing data/manual documentation remain intact, and unfinished work is visible.
4
+
5
+ This is an independent local open-source project. Do not connect to or modify the existing family server, copy private files, or import its real inventory. Use anonymous temporary fixtures. No package/repository publication without explicit instructions.
6
+
7
+ Use Python standard library for the CLI and local SQLite state; MCP is an optional extra. All entry points share validation and persistence. Declarations, live observations, and operation receipts are distinct. Never execute descriptor `commands` strings. Failures and interruptions must not become success. Preserve user-authored README/AGENTS content outside clearly managed blocks. No shell=True, automatic data deletion, generic shell MCP tools, or global root daemon.
8
+
9
+ Run meaningful tests, build wheel/sdist, inspect package contents, install a wheel into an isolated environment, and test real stdio MCP. Report simulated service tests separately from real Linux/Docker checks.
@@ -0,0 +1,17 @@
1
+ # Contributing
2
+
3
+ Issues and pull requests are welcome. Public visitors have read access and can propose changes from a fork; they cannot push to this repository or merge their own proposals. The repository owner reviews and decides what enters `main`. Write access is granted only through an explicit maintainer invitation. The MIT license also permits modifying and distributing a separate copy; repository access controls protect this original repository.
4
+
5
+ 欢迎提交 Issue 或通过 Fork 提交 PR。普通访客不能直接推送、合并或修改本仓库;是否采纳由维护者决定。MIT 开源允许修改自己的副本,并不意味着取得原仓库写入权限。
6
+
7
+ Use Python 3.11 or newer. Create an isolated environment, install `.[mcp,dev]`, run `python -m pytest` and `python -m build`. CLI logic belongs in the shared core; MCP and CLI must not develop different registration or execution rules.
8
+
9
+ Start changes with the user task and the observable result. Use temporary workspaces and anonymous fixtures. Do not copy a real server's credentials, inventory, application data, user documents, or operation transcripts into the repository.
10
+
11
+ Keep declarations, observations and receipts distinct. Add meaningful tests for failed writes, stale revisions, interruptions and pre-existing manual content when those behaviors change. Unknown database versions require an explicit migration design; never silently recreate state.
12
+
13
+ Default tests must not affect the developer's Docker or system services. The explicit optional Docker test uses its own unique project with no persistent mounts and must clean up only that project. Report real and simulated execution separately.
14
+
15
+ Generated documentation must preserve user-authored content outside managed markers. Do not add arbitrary shell MCP tools, automatic data resets, secret-returning document tools or generic root daemons as shortcuts.
16
+
17
+ Before a release, inspect both wheel and sdist, install the wheel in a fresh environment, exercise stdio MCP, and verify bundled schema/Skill assets. Public publishing is a maintainer action with the chosen account and package name; local build does not publish anything.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Server Handbook contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ include LICENSE README.md README.zh-CN.md CONTRIBUTING.md SECURITY.md AGENTS.md .gitignore .gitattributes
2
+ recursive-include .github *.yml *.md CODEOWNERS
3
+ recursive-include docs *.md *.xml
4
+ recursive-include examples *.md *.json *.yaml
5
+ recursive-include tests *.py
6
+ recursive-include tools *.py
7
+ recursive-include src/server_handbook/assets *
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: server-handbook
3
+ Version: 0.1.0
4
+ Summary: Durable server context, deployment registry, and tracked operations for humans and AI agents
5
+ Author: Server Handbook contributors
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/zzy1136660162/server-handbook
8
+ Project-URL: Repository, https://github.com/zzy1136660162/server-handbook
9
+ Project-URL: Issues, https://github.com/zzy1136660162/server-handbook/issues
10
+ Project-URL: Documentation, https://github.com/zzy1136660162/server-handbook/blob/main/README.zh-CN.md
11
+ Keywords: mcp,devops,self-hosted,deployment,agents,handoff
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: System :: Systems Administration
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Provides-Extra: mcp
24
+ Requires-Dist: mcp==2.3.0; extra == "mcp"
25
+ Provides-Extra: dev
26
+ Requires-Dist: build>=1.2; extra == "dev"
27
+ Requires-Dist: pytest>=8; extra == "dev"
28
+ Requires-Dist: jsonschema>=4.20; extra == "dev"
29
+ Dynamic: license-file
30
+
31
+ # Server Handbook
32
+
33
+ Server context, deployment registration, and tracked operations for humans and AI agents.
34
+
35
+ [中文说明](README.zh-CN.md) · [Architecture](docs/architecture.md) · [CLI reference](docs/cli.md) · [MCP setup](docs/mcp.md)
36
+
37
+ [Source](https://github.com/zzy1136660162/server-handbook) · [Report an issue](https://github.com/zzy1136660162/server-handbook/issues) · [PyPI publishing guide](docs/pypi-publishing.zh-CN.md)
38
+
39
+ Server Handbook gives a new agent a predictable place to start, records where services live, and saves actual results from managed Compose/systemd actions. Existing projects can stay in their current directories. Manual README and AGENTS content outside marked blocks is preserved.
40
+
41
+ **Status:** 0.1.0 alpha. The source and local distributions are usable; this project has not been published to PyPI. Core commands use only the Python standard library. MCP is an optional extra. Service execution targets Linux/Compose; clients and registry operations are portable.
42
+
43
+ ## Install from this checkout
44
+
45
+ Python 3.11 or newer is required. Use an isolated environment:
46
+
47
+ ```bash
48
+ python3 -m venv .venv
49
+ . .venv/bin/activate
50
+ python -m pip install '.[mcp]'
51
+ server-handbook --help
52
+ ```
53
+
54
+ To obtain the source first:
55
+
56
+ ```bash
57
+ git clone https://github.com/zzy1136660162/server-handbook.git
58
+ cd server-handbook
59
+ ```
60
+
61
+ On Windows activate `.venv\Scripts\Activate.ps1`, or call `.venv\Scripts\python.exe` directly. For an installed application with pipx, use `pipx install '.[mcp]'` from this checkout or install a supplied local wheel with the MCP extra. There is no npm wrapper and no second runtime.
62
+
63
+ ## Start a workspace
64
+
65
+ ```bash
66
+ # Default is a preview: no directories or files are created.
67
+ server-handbook init --workspace /srv/workspace
68
+ server-handbook init --workspace /srv/workspace --apply
69
+ cd /srv/workspace
70
+ server-handbook handoff
71
+ server-handbook project new demo --name 'Demo application' --kind compose
72
+ server-handbook project new demo --name 'Demo application' --kind compose --apply
73
+ ```
74
+
75
+ The generated declaration is `projects/demo/deploy/registry/demo.json`. It starts as `prepared`. Add the actual Compose project, service, files, ports, data references, and optional HTTP checks. Review the project README and existing rules. Preparation does not deploy an application.
76
+
77
+ ```bash
78
+ server-handbook register /srv/workspace/projects/demo/deploy/registry/demo.json \
79
+ --note 'Initial reviewed deployment declaration; service not yet started'
80
+ server-handbook plan demo --action up
81
+ server-handbook apply demo --action up --expect-revision 1 \
82
+ --note 'Start the reviewed demo service and run its declared checks'
83
+ server-handbook operations --service demo
84
+ server-handbook doctor
85
+ ```
86
+
87
+ Use `show demo` to read the current revision instead of copying the example number for an existing service. `apply` automatically retains real execution/check results and refreshes the managed README block. A process check alone is not business acceptance; configured HTTP probes are recorded separately.
88
+
89
+ ## Adopt an existing project
90
+
91
+ Configure additional roots during initialization. Existing source, data and runtime directories are not moved:
92
+
93
+ ```bash
94
+ server-handbook init --workspace /srv/workspace --project-root /opt/apps --apply
95
+ server-handbook --config /srv/workspace/.server-handbook/config.json adopt \
96
+ --home /opt/apps/example --id example --name 'Existing application' --kind compose \
97
+ --compose-file /opt/apps/example/compose.yaml \
98
+ --compose-project example --compose-service web
99
+ ```
100
+
101
+ Review the preview, then repeat with `--apply`. Adoption prepares files and instructions; registration is explicit. Existing declarations are never silently replaced. `discover` produces unconfirmed candidates without reading configuration values or auto-registering containers.
102
+
103
+ ## One source for each kind of information
104
+
105
+ - `<service-home>/deploy/registry/<id>.json`: the editable service declaration.
106
+ - `<workspace>/.server-handbook/config.json`: host name, directory roots and records location.
107
+ - `<records-dir>/state.sqlite3`: registered snapshots/history and managed operation receipts, committed transactionally.
108
+ - `AGENTS.md` and service `README.md`: human/agent guidance; generated content stays between `server-handbook` markers.
109
+ - Runtime observations: queried on request, timestamped, and distinct from declarations and old receipts.
110
+
111
+ SQLite state is local application metadata, not an application business database. It needs no MySQL, cloud account, server daemon, or model API key. The tool never starts an LLM itself.
112
+
113
+ ## MCP
114
+
115
+ ```bash
116
+ server-handbook-mcp --config /srv/workspace/.server-handbook/config.json
117
+ ```
118
+
119
+ The default interface is read-only stdio. Configure the client to launch this command, locally or through your existing SSH connection. Installing the server alone does not enroll every AI client automatically. `--allow-write` explicitly adds only registration and managed apply tools; it does not expose an arbitrary shell. See [MCP setup](docs/mcp.md).
120
+
121
+ ## What is recorded
122
+
123
+ Managed operations record their plan and input hashes before commands execute, then save bounded step outcomes, actual check scope, status, timestamps, and documentation status. A service can have only one active managed operation. Failed preflight/commands/checks remain failed; interrupted work stays visible and is never automatically replayed.
124
+
125
+ ```bash
126
+ server-handbook operation OPERATION_ID
127
+ server-handbook recover OPERATION_ID --note 'Reviewed abandoned work; inspect live state before a fresh plan'
128
+ ```
129
+
130
+ Recovery refuses a live owner and marks abandoned work interrupted; it neither rolls back external effects nor repeats commands. Compose operations manage the named service with dependencies left to the existing deployment process. No `down`, volume deletion, automatic database initialization, generic shell tool, or global privileged daemon is provided.
131
+
132
+ Direct shell changes outside this tool are not fully attributable. Source drift may be detected later, but the tool cannot reconstruct every change or its purpose. A registered `deployed` state is not proof of current health. Paths in `secret_refs` are references, not a channel for returning credentials.
133
+
134
+ ## Develop and build
135
+
136
+ ```bash
137
+ python -m pip install -e '.[mcp,dev]'
138
+ python -m pytest
139
+ python -m build
140
+ ```
141
+
142
+ Most service-runner tests use isolated temporary workspaces and mocked commands; real loopback HTTP and stdio MCP tests are included. The optional Docker integration test is explicitly enabled with `SERVER_HANDBOOK_DOCKER_TESTS=1`; it uses only its own unique project and cleans it up. See [verification](docs/verification.md) for the checks actually performed and their limits.
143
+
144
+ Contributions: [CONTRIBUTING.md](CONTRIBUTING.md). License: [MIT](LICENSE).
@@ -0,0 +1,114 @@
1
+ # Server Handbook
2
+
3
+ Server context, deployment registration, and tracked operations for humans and AI agents.
4
+
5
+ [中文说明](README.zh-CN.md) · [Architecture](docs/architecture.md) · [CLI reference](docs/cli.md) · [MCP setup](docs/mcp.md)
6
+
7
+ [Source](https://github.com/zzy1136660162/server-handbook) · [Report an issue](https://github.com/zzy1136660162/server-handbook/issues) · [PyPI publishing guide](docs/pypi-publishing.zh-CN.md)
8
+
9
+ Server Handbook gives a new agent a predictable place to start, records where services live, and saves actual results from managed Compose/systemd actions. Existing projects can stay in their current directories. Manual README and AGENTS content outside marked blocks is preserved.
10
+
11
+ **Status:** 0.1.0 alpha. The source and local distributions are usable; this project has not been published to PyPI. Core commands use only the Python standard library. MCP is an optional extra. Service execution targets Linux/Compose; clients and registry operations are portable.
12
+
13
+ ## Install from this checkout
14
+
15
+ Python 3.11 or newer is required. Use an isolated environment:
16
+
17
+ ```bash
18
+ python3 -m venv .venv
19
+ . .venv/bin/activate
20
+ python -m pip install '.[mcp]'
21
+ server-handbook --help
22
+ ```
23
+
24
+ To obtain the source first:
25
+
26
+ ```bash
27
+ git clone https://github.com/zzy1136660162/server-handbook.git
28
+ cd server-handbook
29
+ ```
30
+
31
+ On Windows activate `.venv\Scripts\Activate.ps1`, or call `.venv\Scripts\python.exe` directly. For an installed application with pipx, use `pipx install '.[mcp]'` from this checkout or install a supplied local wheel with the MCP extra. There is no npm wrapper and no second runtime.
32
+
33
+ ## Start a workspace
34
+
35
+ ```bash
36
+ # Default is a preview: no directories or files are created.
37
+ server-handbook init --workspace /srv/workspace
38
+ server-handbook init --workspace /srv/workspace --apply
39
+ cd /srv/workspace
40
+ server-handbook handoff
41
+ server-handbook project new demo --name 'Demo application' --kind compose
42
+ server-handbook project new demo --name 'Demo application' --kind compose --apply
43
+ ```
44
+
45
+ The generated declaration is `projects/demo/deploy/registry/demo.json`. It starts as `prepared`. Add the actual Compose project, service, files, ports, data references, and optional HTTP checks. Review the project README and existing rules. Preparation does not deploy an application.
46
+
47
+ ```bash
48
+ server-handbook register /srv/workspace/projects/demo/deploy/registry/demo.json \
49
+ --note 'Initial reviewed deployment declaration; service not yet started'
50
+ server-handbook plan demo --action up
51
+ server-handbook apply demo --action up --expect-revision 1 \
52
+ --note 'Start the reviewed demo service and run its declared checks'
53
+ server-handbook operations --service demo
54
+ server-handbook doctor
55
+ ```
56
+
57
+ Use `show demo` to read the current revision instead of copying the example number for an existing service. `apply` automatically retains real execution/check results and refreshes the managed README block. A process check alone is not business acceptance; configured HTTP probes are recorded separately.
58
+
59
+ ## Adopt an existing project
60
+
61
+ Configure additional roots during initialization. Existing source, data and runtime directories are not moved:
62
+
63
+ ```bash
64
+ server-handbook init --workspace /srv/workspace --project-root /opt/apps --apply
65
+ server-handbook --config /srv/workspace/.server-handbook/config.json adopt \
66
+ --home /opt/apps/example --id example --name 'Existing application' --kind compose \
67
+ --compose-file /opt/apps/example/compose.yaml \
68
+ --compose-project example --compose-service web
69
+ ```
70
+
71
+ Review the preview, then repeat with `--apply`. Adoption prepares files and instructions; registration is explicit. Existing declarations are never silently replaced. `discover` produces unconfirmed candidates without reading configuration values or auto-registering containers.
72
+
73
+ ## One source for each kind of information
74
+
75
+ - `<service-home>/deploy/registry/<id>.json`: the editable service declaration.
76
+ - `<workspace>/.server-handbook/config.json`: host name, directory roots and records location.
77
+ - `<records-dir>/state.sqlite3`: registered snapshots/history and managed operation receipts, committed transactionally.
78
+ - `AGENTS.md` and service `README.md`: human/agent guidance; generated content stays between `server-handbook` markers.
79
+ - Runtime observations: queried on request, timestamped, and distinct from declarations and old receipts.
80
+
81
+ SQLite state is local application metadata, not an application business database. It needs no MySQL, cloud account, server daemon, or model API key. The tool never starts an LLM itself.
82
+
83
+ ## MCP
84
+
85
+ ```bash
86
+ server-handbook-mcp --config /srv/workspace/.server-handbook/config.json
87
+ ```
88
+
89
+ The default interface is read-only stdio. Configure the client to launch this command, locally or through your existing SSH connection. Installing the server alone does not enroll every AI client automatically. `--allow-write` explicitly adds only registration and managed apply tools; it does not expose an arbitrary shell. See [MCP setup](docs/mcp.md).
90
+
91
+ ## What is recorded
92
+
93
+ Managed operations record their plan and input hashes before commands execute, then save bounded step outcomes, actual check scope, status, timestamps, and documentation status. A service can have only one active managed operation. Failed preflight/commands/checks remain failed; interrupted work stays visible and is never automatically replayed.
94
+
95
+ ```bash
96
+ server-handbook operation OPERATION_ID
97
+ server-handbook recover OPERATION_ID --note 'Reviewed abandoned work; inspect live state before a fresh plan'
98
+ ```
99
+
100
+ Recovery refuses a live owner and marks abandoned work interrupted; it neither rolls back external effects nor repeats commands. Compose operations manage the named service with dependencies left to the existing deployment process. No `down`, volume deletion, automatic database initialization, generic shell tool, or global privileged daemon is provided.
101
+
102
+ Direct shell changes outside this tool are not fully attributable. Source drift may be detected later, but the tool cannot reconstruct every change or its purpose. A registered `deployed` state is not proof of current health. Paths in `secret_refs` are references, not a channel for returning credentials.
103
+
104
+ ## Develop and build
105
+
106
+ ```bash
107
+ python -m pip install -e '.[mcp,dev]'
108
+ python -m pytest
109
+ python -m build
110
+ ```
111
+
112
+ Most service-runner tests use isolated temporary workspaces and mocked commands; real loopback HTTP and stdio MCP tests are included. The optional Docker integration test is explicitly enabled with `SERVER_HANDBOOK_DOCKER_TESTS=1`; it uses only its own unique project and cleans it up. See [verification](docs/verification.md) for the checks actually performed and their limits.
113
+
114
+ Contributions: [CONTRIBUTING.md](CONTRIBUTING.md). License: [MIT](LICENSE).
@@ -0,0 +1,106 @@
1
+ # Server Handbook · 服务器工作手册
2
+
3
+ 让人和 AI 从固定入口接手服务器,按约定维护项目,并为通过工具执行的变更自动留下实际记录。
4
+
5
+ [English](README.md) · [架构与数据归属](docs/architecture.md) · [完整命令](docs/cli.md) · [MCP 接入](docs/mcp.md)
6
+
7
+ [GitHub 源码](https://github.com/zzy1136660162/server-handbook) · [提交 Issue](https://github.com/zzy1136660162/server-handbook/issues) · [发布到 PyPI](docs/pypi-publishing.zh-CN.md)
8
+
9
+ 当前为 **0.1.0 Alpha**,已提供源码和本地构建包,尚未发布到 PyPI。适合个人开发者、小团队、自托管服务器维护者。现有项目可以保留原来的位置;工具保留 README、AGENTS 中人工编写的内容。
10
+
11
+ ## 安装
12
+
13
+ 需要 Python 3.11 以上。进入本项目目录,使用独立环境安装:
14
+
15
+ ```bash
16
+ python3 -m venv .venv
17
+ source .venv/bin/activate
18
+ python -m pip install '.[mcp]'
19
+ server-handbook --help
20
+ ```
21
+
22
+ Windows 可使用 `.venv\Scripts\Activate.ps1`,也可直接调用环境内的 Python。已安装 pipx 时,可以从源码目录执行 `pipx install '.[mcp]'`。基础 CLI 没有第三方依赖,MCP 是可选附加功能。
23
+
24
+ 源码可先从 GitHub 获取:
25
+
26
+ ```bash
27
+ git clone https://github.com/zzy1136660162/server-handbook.git
28
+ cd server-handbook
29
+ ```
30
+
31
+ 仓库公开,欢迎提 Issue 或通过 Fork 提交 PR。普通访客不能直接推送或合并到原仓库;是否采纳由维护者决定。
32
+
33
+ ## 第一次使用
34
+
35
+ ```bash
36
+ # 默认只预览;加 --apply 才创建目录和工具文件。
37
+ server-handbook init --workspace /srv/workspace
38
+ server-handbook init --workspace /srv/workspace --apply
39
+ cd /srv/workspace
40
+ server-handbook handoff
41
+ server-handbook project new demo --name '演示项目' --kind compose --apply
42
+ ```
43
+
44
+ 新项目生成 `README.md`、`AGENTS.md`、`src/deploy/config/data/logs/docs` 的说明,以及 `deploy/registry/demo.json`。数据目录顶层可以放说明,数据库真实存储应使用 `data/store` 等程序专用目录;工具不会向现有程序存储目录塞 README。
45
+
46
+ 生成的声明默认 `prepared`,不表示已部署。填写实际 Compose 文件、project、service、端口、数据位置和需要执行的 HTTP 检查后,再登记和部署:
47
+
48
+ ```bash
49
+ server-handbook register /srv/workspace/projects/demo/deploy/registry/demo.json \
50
+ --note '首次登记已核对的部署声明;尚未执行启动'
51
+ server-handbook plan demo --action up
52
+ server-handbook apply demo --action up --expect-revision 1 \
53
+ --note '启动已核对的服务并执行声明中的检查'
54
+ server-handbook operations --service demo
55
+ server-handbook doctor
56
+ ```
57
+
58
+ 已有记录先用 `show demo` 查当前 revision,不能照抄示例中的 `1`。登记失败不会覆盖旧快照;部署失败会保留失败凭条,CLI 返回非零退出码。执行检查、保存操作记录和刷新文档均由工具完成,不依赖 AI 最后记得手写总结。
59
+
60
+ ## 接入原有项目
61
+
62
+ 初始化时用重复的 `--project-root`、`--service-root` 声明实际根目录,用 `--records-dir` 指定台账位置。配置保存在工作区 `.server-handbook/config.json`。已有配置不同则拒绝覆盖,不会因重跑 init 改写目录规划。
63
+
64
+ ```bash
65
+ server-handbook --config /srv/workspace/.server-handbook/config.json adopt \
66
+ --home /opt/apps/example --id example --name '已有项目' --kind compose \
67
+ --compose-file /opt/apps/example/compose.yaml \
68
+ --compose-project example --compose-service web
69
+ ```
70
+
71
+ 先检查预览,再加 `--apply`。`adopt` 不搬动源代码或数据,不自动启动服务,也不自动把候选变成已验证部署。`discover` 只读发现常见 Compose 文件和容器候选,用途、归属、备份方式等仍需核实。
72
+
73
+ `project new --profile generic|python|node|java` 提供不同开发指导,不生成整套业务框架;已有项目自己的规范和用户当前指令优先。
74
+
75
+ ## 信息登记在哪里
76
+
77
+ | 信息 | 位置 |
78
+ | --- | --- |
79
+ | 固定接手入口 | `<workspace>/AGENTS.md`、`README.md` |
80
+ | 主机目录配置 | `<workspace>/.server-handbook/config.json` |
81
+ | 服务声明源文件 | `<service-home>/deploy/registry/<id>.json` |
82
+ | 已登记快照、历史、实际操作凭条 | `<records-dir>/state.sqlite3` |
83
+ | 服务的人读维护说明 | 服务声明中的 `readme` 路径 |
84
+
85
+ 声明、现场观察和历史凭条分开。`state=deployed` 表示登记声明,当前是否运行用现场查询判断;“进程已运行”与“HTTP 检查通过”也分别记录。没有配置业务检查时,会明确标为进程检查,不能据此宣称完整业务验收通过。
86
+
87
+ ## AI 接入和中断恢复
88
+
89
+ MCP 与 CLI 使用同一套核心:
90
+
91
+ ```bash
92
+ server-handbook-mcp --config /srv/workspace/.server-handbook/config.json
93
+ ```
94
+
95
+ 默认只读。客户端需要单独配置启动命令;安装服务器端程序不会让所有 AI 客户端自动接入。按需添加 `--allow-write` 后,仅开放登记和受管理操作,不提供任意 shell。可分发的 Skill 位于 `src/server_handbook/assets/skills/server-handbook/`,安装后可用 `server-handbook skill export 目标目录 --apply` 导出。SSH 登录提示示例见 [MCP 文档](docs/mcp.md),本包安装不会自动修改 SSH。
96
+
97
+ ```bash
98
+ server-handbook operation 操作ID
99
+ server-handbook recover 操作ID --note '已检查中断位置,下一步先核对现场'
100
+ ```
101
+
102
+ 操作开始前会落盘;中断后保留进行中记录。`recover` 拒绝仍在运行的操作,将已无执行者的操作标为中断,不自动重放,也不回滚外部副作用。通过普通 SSH 绕过工具修改时,只能尽量发现漂移,不能保证还原修改者和原因。
103
+
104
+ Compose 只操作明确登记的 service;依赖服务需要预先启动。不会删除卷、重装系统、重新初始化数据库或启动全局 root 守护进程。
105
+
106
+ 验证范围见 [验证记录](docs/verification.md)。开源贡献见 [CONTRIBUTING.md](CONTRIBUTING.md),许可证为 [MIT](LICENSE)。