ai-push-hooks 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 (36) hide show
  1. ai_push_hooks-0.1.0/LICENSE +21 -0
  2. ai_push_hooks-0.1.0/PKG-INFO +256 -0
  3. ai_push_hooks-0.1.0/README.md +234 -0
  4. ai_push_hooks-0.1.0/pyproject.toml +38 -0
  5. ai_push_hooks-0.1.0/setup.cfg +4 -0
  6. ai_push_hooks-0.1.0/src/ai_push_hooks/__init__.py +6 -0
  7. ai_push_hooks-0.1.0/src/ai_push_hooks/__main__.py +3 -0
  8. ai_push_hooks-0.1.0/src/ai_push_hooks/artifacts.py +86 -0
  9. ai_push_hooks-0.1.0/src/ai_push_hooks/cli.py +49 -0
  10. ai_push_hooks-0.1.0/src/ai_push_hooks/config.py +356 -0
  11. ai_push_hooks-0.1.0/src/ai_push_hooks/engine.py +172 -0
  12. ai_push_hooks-0.1.0/src/ai_push_hooks/executors/__init__.py +1 -0
  13. ai_push_hooks-0.1.0/src/ai_push_hooks/executors/apply.py +55 -0
  14. ai_push_hooks-0.1.0/src/ai_push_hooks/executors/assertions.py +44 -0
  15. ai_push_hooks-0.1.0/src/ai_push_hooks/executors/exec.py +413 -0
  16. ai_push_hooks-0.1.0/src/ai_push_hooks/executors/llm.py +308 -0
  17. ai_push_hooks-0.1.0/src/ai_push_hooks/hook.py +130 -0
  18. ai_push_hooks-0.1.0/src/ai_push_hooks/modules/__init__.py +11 -0
  19. ai_push_hooks-0.1.0/src/ai_push_hooks/modules/beads.py +46 -0
  20. ai_push_hooks-0.1.0/src/ai_push_hooks/modules/docs.py +159 -0
  21. ai_push_hooks-0.1.0/src/ai_push_hooks/modules/pr.py +73 -0
  22. ai_push_hooks-0.1.0/src/ai_push_hooks/prompts_builtin.py +135 -0
  23. ai_push_hooks-0.1.0/src/ai_push_hooks/types.py +236 -0
  24. ai_push_hooks-0.1.0/src/ai_push_hooks.egg-info/PKG-INFO +256 -0
  25. ai_push_hooks-0.1.0/src/ai_push_hooks.egg-info/SOURCES.txt +34 -0
  26. ai_push_hooks-0.1.0/src/ai_push_hooks.egg-info/dependency_links.txt +1 -0
  27. ai_push_hooks-0.1.0/src/ai_push_hooks.egg-info/entry_points.txt +2 -0
  28. ai_push_hooks-0.1.0/src/ai_push_hooks.egg-info/requires.txt +3 -0
  29. ai_push_hooks-0.1.0/src/ai_push_hooks.egg-info/top_level.txt +1 -0
  30. ai_push_hooks-0.1.0/tests/test_beads_module.py +84 -0
  31. ai_push_hooks-0.1.0/tests/test_config.py +58 -0
  32. ai_push_hooks-0.1.0/tests/test_docs_module.py +120 -0
  33. ai_push_hooks-0.1.0/tests/test_init_command.py +24 -0
  34. ai_push_hooks-0.1.0/tests/test_pr_module.py +80 -0
  35. ai_push_hooks-0.1.0/tests/test_prompt_resolution.py +56 -0
  36. ai_push_hooks-0.1.0/tests/test_scheduler.py +107 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ai-push-hooks 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,256 @@
1
+ Metadata-Version: 2.4
2
+ Name: ai-push-hooks
3
+ Version: 0.1.0
4
+ Summary: Modular AI push-hook workflow runner
5
+ Author: ai-push-hooks contributors
6
+ License-Expression: MIT
7
+ Keywords: git,lefthook,docs,ai,pre-push
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Software Development :: Version Control :: Git
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest>=8.0; extra == "dev"
21
+ Dynamic: license-file
22
+
23
+ # ai-push-hooks
24
+
25
+ AI-assisted pre-push workflow runner for modular repo checks, docs sync, Beads alignment, and PR creation.
26
+
27
+ ## Install
28
+
29
+ ### Python / uv
30
+
31
+ ```bash
32
+ uv tool install ai-push-hooks
33
+ # or
34
+ pipx install ai-push-hooks
35
+ ```
36
+
37
+ ### npm
38
+
39
+ ```bash
40
+ npm install --save-dev ai-push-hooks
41
+ # or
42
+ pnpm add -D ai-push-hooks
43
+ ```
44
+
45
+ The npm binary wraps the bundled Python module, so `python3` (or `python`) must be available.
46
+
47
+ ## Maintainer Release
48
+
49
+ This repo supports automated dual publishing to PyPI and npm from a git tag.
50
+
51
+ 1. Bump `version` in `pyproject.toml` and `package.json` to the same value.
52
+ 2. Commit and tag: `git tag vX.Y.Z`.
53
+ 3. Push commit + tag: `git push && git push --tags`.
54
+
55
+ The GitHub Actions release workflow then:
56
+
57
+ - verifies the tag matches both package versions
58
+ - runs tests
59
+ - builds and validates Python distributions
60
+ - smoke-tests the installed Python CLI
61
+ - publishes to PyPI (Trusted Publishing)
62
+ - publishes to npm (`NPM_TOKEN` secret)
63
+
64
+ Required one-time setup:
65
+
66
+ - Configure PyPI Trusted Publisher for this repository.
67
+ - Add repository secret `NPM_TOKEN` with publish access to `ai-push-hooks`.
68
+
69
+ ## Commands
70
+
71
+ ```bash
72
+ ai-push-hooks hook <remote-name> <remote-url>
73
+ ai-push-hooks init --template minimal-docs
74
+ ```
75
+
76
+ `init` supports exactly one template: `minimal-docs`. Use `--force` to overwrite an existing config.
77
+
78
+ ## Lefthook Usage
79
+
80
+ ```yaml
81
+ pre-push:
82
+ commands:
83
+ ai-push-hooks:
84
+ run: ai-push-hooks hook {1} {2}
85
+ ```
86
+
87
+ For local source checkout usage, `./run.sh` works as a wrapper entrypoint.
88
+
89
+ ## Configuration
90
+
91
+ Put `.ai-push-hooks.toml` in the target repo root. If no file is present, built-in modular defaults are used.
92
+
93
+ Prompt resolution precedence is:
94
+
95
+ 1. inline `prompt`
96
+ 2. `prompt_file`
97
+ 3. built-in `fallback_prompt_id`
98
+
99
+ Minimal docs example:
100
+
101
+ ```toml
102
+ [workflow]
103
+ modules = ["docs"]
104
+
105
+ [modules.docs]
106
+ enabled = true
107
+
108
+ [[modules.docs.steps]]
109
+ id = "collect"
110
+ type = "collect"
111
+ collector = "docs_context"
112
+
113
+ [[modules.docs.steps]]
114
+ id = "query"
115
+ type = "llm"
116
+ prompt = "Return a JSON array of documentation search queries. JSON only."
117
+ inputs = ["collect/push.diff", "collect/changed-files.txt"]
118
+ output = "queries.json"
119
+ schema = "string_array"
120
+
121
+ [[modules.docs.steps]]
122
+ id = "analyze"
123
+ type = "llm"
124
+ prompt = "Return JSON issues only for factual documentation drift."
125
+ inputs = ["collect/push.diff", "collect/docs-context.txt", "query/queries.json", "collect/recent-commits.txt"]
126
+ output = "issues.json"
127
+ schema = "docs_issue_array"
128
+
129
+ [[modules.docs.steps]]
130
+ id = "apply"
131
+ type = "apply"
132
+ prompt = "Apply the minimum Markdown fixes required."
133
+ inputs = ["collect/push.diff", "collect/docs-context.txt", "analyze/issues.json"]
134
+ allow_paths = ["README.md", "docs/**/*.md"]
135
+
136
+ [[modules.docs.steps]]
137
+ id = "assert"
138
+ type = "assert"
139
+ assertion = "docs_apply_requires_manual_commit"
140
+ inputs = ["apply/result.json"]
141
+ ```
142
+
143
+ Example config that recreates the current docs + beads + PR behavior through configuration only:
144
+
145
+ The sample below is runnable as-is because each `prompt_file` step also declares a built-in `fallback_prompt_id`. If you add local prompt files, they override the built-ins.
146
+
147
+ ```toml
148
+ [workflow]
149
+ modules = ["beads", "docs", "pr"]
150
+
151
+ [modules.beads]
152
+ enabled = true
153
+
154
+ [[modules.beads.steps]]
155
+ id = "collect"
156
+ type = "collect"
157
+ collector = "beads_status_context"
158
+
159
+ [[modules.beads.steps]]
160
+ id = "plan"
161
+ type = "llm"
162
+ prompt_file = ".ai-push-hooks.prompts/beads-status.txt"
163
+ fallback_prompt_id = "beads-plan-basic"
164
+ inputs = ["collect/branch-context.txt", "collect/changed-files.txt", "collect/push.diff", "collect/commits.txt"]
165
+ output = "beads-plan.json"
166
+ schema = "beads_alignment_result"
167
+
168
+ [[modules.beads.steps]]
169
+ id = "apply"
170
+ type = "exec"
171
+ executor = "beads_alignment"
172
+ inputs = ["plan/beads-plan.json"]
173
+
174
+ [[modules.beads.steps]]
175
+ id = "assert"
176
+ type = "assert"
177
+ assertion = "beads_alignment_clean"
178
+ inputs = ["plan/beads-plan.json"]
179
+
180
+ [modules.docs]
181
+ enabled = true
182
+
183
+ [[modules.docs.steps]]
184
+ id = "collect"
185
+ type = "collect"
186
+ collector = "docs_context"
187
+
188
+ [[modules.docs.steps]]
189
+ id = "query"
190
+ type = "llm"
191
+ prompt_file = ".ai-push-hooks.prompts/query.txt"
192
+ fallback_prompt_id = "docs-query-basic"
193
+ inputs = ["collect/push.diff", "collect/changed-files.txt"]
194
+ output = "queries.json"
195
+ schema = "string_array"
196
+
197
+ [[modules.docs.steps]]
198
+ id = "analyze"
199
+ type = "llm"
200
+ prompt_file = ".ai-push-hooks.prompts/analysis.txt"
201
+ fallback_prompt_id = "docs-analysis-basic"
202
+ inputs = ["collect/push.diff", "collect/docs-context.txt", "query/queries.json", "collect/recent-commits.txt"]
203
+ output = "issues.json"
204
+ schema = "docs_issue_array"
205
+
206
+ [[modules.docs.steps]]
207
+ id = "apply"
208
+ type = "apply"
209
+ prompt_file = ".ai-push-hooks.prompts/apply.txt"
210
+ fallback_prompt_id = "docs-apply-basic"
211
+ inputs = ["collect/push.diff", "collect/docs-context.txt", "analyze/issues.json"]
212
+ allow_paths = ["README.md", "docs/**/*.md"]
213
+
214
+ [[modules.docs.steps]]
215
+ id = "assert"
216
+ type = "assert"
217
+ assertion = "docs_apply_requires_manual_commit"
218
+ inputs = ["apply/result.json"]
219
+
220
+ [modules.pr]
221
+ enabled = true
222
+
223
+ [[modules.pr.steps]]
224
+ id = "collect"
225
+ type = "collect"
226
+ collector = "pr_context"
227
+
228
+ [[modules.pr.steps]]
229
+ id = "compose"
230
+ type = "llm"
231
+ prompt_file = ".ai-push-hooks.prompts/create-pr.txt"
232
+ fallback_prompt_id = "pr-compose-basic"
233
+ inputs = ["collect/pr-context.txt", "collect/changed-files.txt", "collect/push.diff", "collect/commits.txt"]
234
+ output = "pr-draft.json"
235
+ schema = "pr_create_payload"
236
+
237
+ [[modules.pr.steps]]
238
+ id = "create"
239
+ type = "exec"
240
+ executor = "gh_pr_create"
241
+ when_env = "AI_PUSH_HOOKS_CREATE_PR"
242
+ inputs = ["compose/pr-draft.json"]
243
+ ```
244
+
245
+ ## Layout
246
+
247
+ - `src/ai_push_hooks/cli.py` - CLI entrypoint
248
+ - `src/ai_push_hooks/config.py` - config loading and validation
249
+ - `src/ai_push_hooks/engine.py` - scheduler and workflow runtime
250
+ - `src/ai_push_hooks/artifacts.py` - run-directory artifact store
251
+ - `src/ai_push_hooks/prompts_builtin.py` - built-in fallback prompts
252
+ - `src/ai_push_hooks/modules/` - docs, beads, and PR collectors
253
+ - `src/ai_push_hooks/executors/` - LLM, apply, exec, and assertion handlers
254
+ - `run.sh` - source checkout wrapper
255
+ - `bin/ai-push-hooks.js` - npm bin wrapper
256
+ - `.ai-push-hooks.toml` - sample config
@@ -0,0 +1,234 @@
1
+ # ai-push-hooks
2
+
3
+ AI-assisted pre-push workflow runner for modular repo checks, docs sync, Beads alignment, and PR creation.
4
+
5
+ ## Install
6
+
7
+ ### Python / uv
8
+
9
+ ```bash
10
+ uv tool install ai-push-hooks
11
+ # or
12
+ pipx install ai-push-hooks
13
+ ```
14
+
15
+ ### npm
16
+
17
+ ```bash
18
+ npm install --save-dev ai-push-hooks
19
+ # or
20
+ pnpm add -D ai-push-hooks
21
+ ```
22
+
23
+ The npm binary wraps the bundled Python module, so `python3` (or `python`) must be available.
24
+
25
+ ## Maintainer Release
26
+
27
+ This repo supports automated dual publishing to PyPI and npm from a git tag.
28
+
29
+ 1. Bump `version` in `pyproject.toml` and `package.json` to the same value.
30
+ 2. Commit and tag: `git tag vX.Y.Z`.
31
+ 3. Push commit + tag: `git push && git push --tags`.
32
+
33
+ The GitHub Actions release workflow then:
34
+
35
+ - verifies the tag matches both package versions
36
+ - runs tests
37
+ - builds and validates Python distributions
38
+ - smoke-tests the installed Python CLI
39
+ - publishes to PyPI (Trusted Publishing)
40
+ - publishes to npm (`NPM_TOKEN` secret)
41
+
42
+ Required one-time setup:
43
+
44
+ - Configure PyPI Trusted Publisher for this repository.
45
+ - Add repository secret `NPM_TOKEN` with publish access to `ai-push-hooks`.
46
+
47
+ ## Commands
48
+
49
+ ```bash
50
+ ai-push-hooks hook <remote-name> <remote-url>
51
+ ai-push-hooks init --template minimal-docs
52
+ ```
53
+
54
+ `init` supports exactly one template: `minimal-docs`. Use `--force` to overwrite an existing config.
55
+
56
+ ## Lefthook Usage
57
+
58
+ ```yaml
59
+ pre-push:
60
+ commands:
61
+ ai-push-hooks:
62
+ run: ai-push-hooks hook {1} {2}
63
+ ```
64
+
65
+ For local source checkout usage, `./run.sh` works as a wrapper entrypoint.
66
+
67
+ ## Configuration
68
+
69
+ Put `.ai-push-hooks.toml` in the target repo root. If no file is present, built-in modular defaults are used.
70
+
71
+ Prompt resolution precedence is:
72
+
73
+ 1. inline `prompt`
74
+ 2. `prompt_file`
75
+ 3. built-in `fallback_prompt_id`
76
+
77
+ Minimal docs example:
78
+
79
+ ```toml
80
+ [workflow]
81
+ modules = ["docs"]
82
+
83
+ [modules.docs]
84
+ enabled = true
85
+
86
+ [[modules.docs.steps]]
87
+ id = "collect"
88
+ type = "collect"
89
+ collector = "docs_context"
90
+
91
+ [[modules.docs.steps]]
92
+ id = "query"
93
+ type = "llm"
94
+ prompt = "Return a JSON array of documentation search queries. JSON only."
95
+ inputs = ["collect/push.diff", "collect/changed-files.txt"]
96
+ output = "queries.json"
97
+ schema = "string_array"
98
+
99
+ [[modules.docs.steps]]
100
+ id = "analyze"
101
+ type = "llm"
102
+ prompt = "Return JSON issues only for factual documentation drift."
103
+ inputs = ["collect/push.diff", "collect/docs-context.txt", "query/queries.json", "collect/recent-commits.txt"]
104
+ output = "issues.json"
105
+ schema = "docs_issue_array"
106
+
107
+ [[modules.docs.steps]]
108
+ id = "apply"
109
+ type = "apply"
110
+ prompt = "Apply the minimum Markdown fixes required."
111
+ inputs = ["collect/push.diff", "collect/docs-context.txt", "analyze/issues.json"]
112
+ allow_paths = ["README.md", "docs/**/*.md"]
113
+
114
+ [[modules.docs.steps]]
115
+ id = "assert"
116
+ type = "assert"
117
+ assertion = "docs_apply_requires_manual_commit"
118
+ inputs = ["apply/result.json"]
119
+ ```
120
+
121
+ Example config that recreates the current docs + beads + PR behavior through configuration only:
122
+
123
+ The sample below is runnable as-is because each `prompt_file` step also declares a built-in `fallback_prompt_id`. If you add local prompt files, they override the built-ins.
124
+
125
+ ```toml
126
+ [workflow]
127
+ modules = ["beads", "docs", "pr"]
128
+
129
+ [modules.beads]
130
+ enabled = true
131
+
132
+ [[modules.beads.steps]]
133
+ id = "collect"
134
+ type = "collect"
135
+ collector = "beads_status_context"
136
+
137
+ [[modules.beads.steps]]
138
+ id = "plan"
139
+ type = "llm"
140
+ prompt_file = ".ai-push-hooks.prompts/beads-status.txt"
141
+ fallback_prompt_id = "beads-plan-basic"
142
+ inputs = ["collect/branch-context.txt", "collect/changed-files.txt", "collect/push.diff", "collect/commits.txt"]
143
+ output = "beads-plan.json"
144
+ schema = "beads_alignment_result"
145
+
146
+ [[modules.beads.steps]]
147
+ id = "apply"
148
+ type = "exec"
149
+ executor = "beads_alignment"
150
+ inputs = ["plan/beads-plan.json"]
151
+
152
+ [[modules.beads.steps]]
153
+ id = "assert"
154
+ type = "assert"
155
+ assertion = "beads_alignment_clean"
156
+ inputs = ["plan/beads-plan.json"]
157
+
158
+ [modules.docs]
159
+ enabled = true
160
+
161
+ [[modules.docs.steps]]
162
+ id = "collect"
163
+ type = "collect"
164
+ collector = "docs_context"
165
+
166
+ [[modules.docs.steps]]
167
+ id = "query"
168
+ type = "llm"
169
+ prompt_file = ".ai-push-hooks.prompts/query.txt"
170
+ fallback_prompt_id = "docs-query-basic"
171
+ inputs = ["collect/push.diff", "collect/changed-files.txt"]
172
+ output = "queries.json"
173
+ schema = "string_array"
174
+
175
+ [[modules.docs.steps]]
176
+ id = "analyze"
177
+ type = "llm"
178
+ prompt_file = ".ai-push-hooks.prompts/analysis.txt"
179
+ fallback_prompt_id = "docs-analysis-basic"
180
+ inputs = ["collect/push.diff", "collect/docs-context.txt", "query/queries.json", "collect/recent-commits.txt"]
181
+ output = "issues.json"
182
+ schema = "docs_issue_array"
183
+
184
+ [[modules.docs.steps]]
185
+ id = "apply"
186
+ type = "apply"
187
+ prompt_file = ".ai-push-hooks.prompts/apply.txt"
188
+ fallback_prompt_id = "docs-apply-basic"
189
+ inputs = ["collect/push.diff", "collect/docs-context.txt", "analyze/issues.json"]
190
+ allow_paths = ["README.md", "docs/**/*.md"]
191
+
192
+ [[modules.docs.steps]]
193
+ id = "assert"
194
+ type = "assert"
195
+ assertion = "docs_apply_requires_manual_commit"
196
+ inputs = ["apply/result.json"]
197
+
198
+ [modules.pr]
199
+ enabled = true
200
+
201
+ [[modules.pr.steps]]
202
+ id = "collect"
203
+ type = "collect"
204
+ collector = "pr_context"
205
+
206
+ [[modules.pr.steps]]
207
+ id = "compose"
208
+ type = "llm"
209
+ prompt_file = ".ai-push-hooks.prompts/create-pr.txt"
210
+ fallback_prompt_id = "pr-compose-basic"
211
+ inputs = ["collect/pr-context.txt", "collect/changed-files.txt", "collect/push.diff", "collect/commits.txt"]
212
+ output = "pr-draft.json"
213
+ schema = "pr_create_payload"
214
+
215
+ [[modules.pr.steps]]
216
+ id = "create"
217
+ type = "exec"
218
+ executor = "gh_pr_create"
219
+ when_env = "AI_PUSH_HOOKS_CREATE_PR"
220
+ inputs = ["compose/pr-draft.json"]
221
+ ```
222
+
223
+ ## Layout
224
+
225
+ - `src/ai_push_hooks/cli.py` - CLI entrypoint
226
+ - `src/ai_push_hooks/config.py` - config loading and validation
227
+ - `src/ai_push_hooks/engine.py` - scheduler and workflow runtime
228
+ - `src/ai_push_hooks/artifacts.py` - run-directory artifact store
229
+ - `src/ai_push_hooks/prompts_builtin.py` - built-in fallback prompts
230
+ - `src/ai_push_hooks/modules/` - docs, beads, and PR collectors
231
+ - `src/ai_push_hooks/executors/` - LLM, apply, exec, and assertion handlers
232
+ - `run.sh` - source checkout wrapper
233
+ - `bin/ai-push-hooks.js` - npm bin wrapper
234
+ - `.ai-push-hooks.toml` - sample config
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=69", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ai-push-hooks"
7
+ version = "0.1.0"
8
+ description = "Modular AI push-hook workflow runner"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [{ name = "ai-push-hooks contributors" }]
13
+ keywords = ["git", "lefthook", "docs", "ai", "pre-push"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3 :: Only",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Topic :: Software Development :: Version Control :: Git",
23
+ ]
24
+
25
+ [project.scripts]
26
+ ai-push-hooks = "ai_push_hooks.cli:main"
27
+
28
+ [project.optional-dependencies]
29
+ dev = ["pytest>=8.0"]
30
+
31
+ [tool.setuptools]
32
+ include-package-data = true
33
+
34
+ [tool.setuptools.packages.find]
35
+ where = ["src"]
36
+
37
+ [tool.pytest.ini_options]
38
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ """ai-push-hooks package."""
2
+
3
+ from .cli import main
4
+ from .hook import run_hook
5
+
6
+ __all__ = ["main", "run_hook"]
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,86 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import pathlib
5
+ from datetime import datetime, timezone
6
+ from typing import Any
7
+ from uuid import uuid4
8
+
9
+ from .types import HookError, ModuleRuntimeState
10
+
11
+
12
+ def generate_run_id() -> str:
13
+ timestamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%S%fZ")
14
+ return f"{timestamp}-{uuid4().hex[:8]}"
15
+
16
+
17
+ class ArtifactStore:
18
+ def __init__(self, run_dir: pathlib.Path) -> None:
19
+ self.run_dir = run_dir
20
+
21
+ def prepare(self) -> pathlib.Path:
22
+ self.run_dir.mkdir(parents=True, exist_ok=True)
23
+ return self.run_dir
24
+
25
+ def step_dir(self, module_id: str, step_index: int, step_id: str) -> pathlib.Path:
26
+ path = self.run_dir / module_id / f"{step_index:02d}-{step_id}"
27
+ path.mkdir(parents=True, exist_ok=True)
28
+ return path
29
+
30
+ def register(
31
+ self,
32
+ state: ModuleRuntimeState,
33
+ step_id: str,
34
+ artifact_name: str,
35
+ path: pathlib.Path,
36
+ ) -> pathlib.Path:
37
+ state.artifacts[f"{step_id}/{artifact_name}"] = path
38
+ return path
39
+
40
+ def write_text(
41
+ self,
42
+ state: ModuleRuntimeState,
43
+ step_index: int,
44
+ step_id: str,
45
+ artifact_name: str,
46
+ content: str,
47
+ ) -> pathlib.Path:
48
+ path = self.step_dir(state.module.id, step_index, step_id) / artifact_name
49
+ path.write_text(content, encoding="utf-8")
50
+ return self.register(state, step_id, artifact_name, path)
51
+
52
+ def write_json(
53
+ self,
54
+ state: ModuleRuntimeState,
55
+ step_index: int,
56
+ step_id: str,
57
+ artifact_name: str,
58
+ payload: Any,
59
+ ) -> pathlib.Path:
60
+ path = self.step_dir(state.module.id, step_index, step_id) / artifact_name
61
+ path.write_text(json.dumps(payload, ensure_ascii=True, indent=2) + "\n", encoding="utf-8")
62
+ return self.register(state, step_id, artifact_name, path)
63
+
64
+ def resolve_input(self, state: ModuleRuntimeState, reference: str) -> pathlib.Path:
65
+ if ":" in reference:
66
+ module_and_step, artifact_name = reference.split("/", 1)
67
+ module_id, step_id = module_and_step.split(":", 1)
68
+ key = f"{module_id}:{step_id}/{artifact_name}"
69
+ else:
70
+ key = reference
71
+ path = state.artifacts.get(key)
72
+ if path is None:
73
+ path = state.artifacts.get(reference)
74
+ if path is None:
75
+ raise HookError(f"Unknown artifact reference: {reference}")
76
+ return path
77
+
78
+ def register_external(
79
+ self,
80
+ state: ModuleRuntimeState,
81
+ module_id: str,
82
+ step_id: str,
83
+ artifact_name: str,
84
+ path: pathlib.Path,
85
+ ) -> None:
86
+ state.artifacts[f"{module_id}:{step_id}/{artifact_name}"] = path
@@ -0,0 +1,49 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import pathlib
5
+ import sys
6
+
7
+ from .hook import run_hook
8
+ from .prompts_builtin import MINIMAL_DOCS_TEMPLATE
9
+ from .types import HookError
10
+
11
+
12
+ def _build_parser() -> argparse.ArgumentParser:
13
+ parser = argparse.ArgumentParser(description="AI push hooks workflow runner")
14
+ subparsers = parser.add_subparsers(dest="command", required=True)
15
+
16
+ hook_parser = subparsers.add_parser("hook", help="Run the hook workflow")
17
+ hook_parser.add_argument("remote_name", nargs="?", default="")
18
+ hook_parser.add_argument("remote_url", nargs="?", default="")
19
+
20
+ init_parser = subparsers.add_parser("init", help="Write a starter config")
21
+ init_parser.add_argument("--template", default="minimal-docs")
22
+ init_parser.add_argument("--force", action="store_true")
23
+ return parser
24
+
25
+
26
+ def init_config(template: str, force: bool, cwd: pathlib.Path | None = None) -> int:
27
+ if template != "minimal-docs":
28
+ raise HookError("Only `minimal-docs` is supported")
29
+ target_dir = cwd or pathlib.Path.cwd()
30
+ config_path = target_dir / ".ai-push-hooks.toml"
31
+ if config_path.exists() and not force:
32
+ raise HookError(f"Refusing to overwrite existing config without --force: {config_path}")
33
+ config_path.write_text(MINIMAL_DOCS_TEMPLATE, encoding="utf-8")
34
+ sys.stdout.write(str(config_path) + "\n")
35
+ return 0
36
+
37
+
38
+ def main(argv: list[str] | None = None) -> int:
39
+ parser = _build_parser()
40
+ args = parser.parse_args(argv)
41
+ try:
42
+ if args.command == "hook":
43
+ return run_hook(args.remote_name, args.remote_url)
44
+ if args.command == "init":
45
+ return init_config(args.template, args.force)
46
+ raise HookError(f"Unknown command: {args.command}")
47
+ except HookError as exc:
48
+ sys.stderr.write(f"[ai-push-hooks] {exc}\n")
49
+ return 1