chewcw-ai-path 0.2.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.
- chewcw_ai_path-0.2.0/LICENSE +21 -0
- chewcw_ai_path-0.2.0/PKG-INFO +105 -0
- chewcw_ai_path-0.2.0/README.md +90 -0
- chewcw_ai_path-0.2.0/ai_path/__init__.py +1 -0
- chewcw_ai_path-0.2.0/ai_path/cli.py +178 -0
- chewcw_ai_path-0.2.0/ai_path/config.py +56 -0
- chewcw_ai_path-0.2.0/ai_path/paths.py +88 -0
- chewcw_ai_path-0.2.0/ai_path/write.py +67 -0
- chewcw_ai_path-0.2.0/chewcw_ai_path.egg-info/PKG-INFO +105 -0
- chewcw_ai_path-0.2.0/chewcw_ai_path.egg-info/SOURCES.txt +13 -0
- chewcw_ai_path-0.2.0/chewcw_ai_path.egg-info/dependency_links.txt +1 -0
- chewcw_ai_path-0.2.0/chewcw_ai_path.egg-info/entry_points.txt +2 -0
- chewcw_ai_path-0.2.0/chewcw_ai_path.egg-info/top_level.txt +1 -0
- chewcw_ai_path-0.2.0/pyproject.toml +30 -0
- chewcw_ai_path-0.2.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 chew cw
|
|
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,105 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chewcw-ai-path
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: One command that owns where agent artefacts are written
|
|
5
|
+
Author: chew cw
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/chewcw/skills/tree/main/dev-tools/ai-path
|
|
8
|
+
Project-URL: Repository, https://github.com/chewcw/skills
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# ai-path
|
|
17
|
+
|
|
18
|
+
The one owner of where an agent artefact is written. Python 3, standard library only, `git` as the
|
|
19
|
+
only external call, no third-party dependency.
|
|
20
|
+
|
|
21
|
+
A skill asks this command for a directory instead of naming one. A repository that keeps its
|
|
22
|
+
artefacts somewhere else edits one file, and no skill changes.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
From a checkout, without installing anything:
|
|
27
|
+
|
|
28
|
+
bin/ai-path --version
|
|
29
|
+
|
|
30
|
+
As a command on `PATH`, editable, so a checkout edit takes effect immediately:
|
|
31
|
+
|
|
32
|
+
uv tool install --editable ./ai-path
|
|
33
|
+
|
|
34
|
+
From the remote, pinned to a tag:
|
|
35
|
+
|
|
36
|
+
uv tool install "git+https://github.com/chewcw/dev-tools.git@ai-path-v0.1.0#subdirectory=ai-path"
|
|
37
|
+
|
|
38
|
+
`uv tool install` writes its shim to `~/.local/bin`. If a non-interactive shell cannot find
|
|
39
|
+
`ai-path`, that directory is the reason — it has to be on `PATH`.
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
ai-path <kind> [--name NAME] [--root DIR] print the absolute directory, creating it
|
|
44
|
+
ai-path env print every directory as KEY=value
|
|
45
|
+
ai-path docs kind, default directory, writer, reader
|
|
46
|
+
ai-path ai-write <kind> --name FILE [--field KEY=VALUE]... [--force]
|
|
47
|
+
write the frontmatter and the body from stdin
|
|
48
|
+
ai-path --version
|
|
49
|
+
|
|
50
|
+
Kinds: `specs`, `plans`, `sdd`, `inbox`, `intent`, `retros`, `out-of-scope`, `mockups`,
|
|
51
|
+
`research`, `ideas`, `roadmap`, `plan-pack`, `decisions`, `study`, `scratch`. `ai-path docs` is
|
|
52
|
+
the single description of them.
|
|
53
|
+
|
|
54
|
+
`ai-write` covers `specs`, `inbox`, and `intent`, the three kinds whose frontmatter a gate reads.
|
|
55
|
+
A kind without a frontmatter contract is refused, because inventing fields no gate reads is
|
|
56
|
+
ceremony.
|
|
57
|
+
|
|
58
|
+
Exit codes: 0 ok, 1 refused (unknown kind, a name that would leave the directory, an existing
|
|
59
|
+
file without `--force`), 2 no environment (no git checkout, missing argument).
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
One file at the git root, `.ai-paths`, as `key = value` lines. A blank value is not a value.
|
|
64
|
+
Precedence: environment, then `.ai-paths`, then the default.
|
|
65
|
+
|
|
66
|
+
| Key | Default | Environment variable |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| `specs` | `.ai/specs` | `QUEUE_SPECS_DIR` |
|
|
69
|
+
| `plans` | `.ai/plans` | `QUEUE_PLANS_DIR` |
|
|
70
|
+
| `sdd` | `.ai/sdd` | `AI_SDD_DIR` |
|
|
71
|
+
| `inbox` | `.ai/inbox` | `QUEUE_INBOX_DIR` |
|
|
72
|
+
| `intent` | `.ai/intent` | `AI_INTENT_DIR` |
|
|
73
|
+
| `retros` | `.ai/retros` | `AI_RETROS_DIR` |
|
|
74
|
+
| `out-of-scope` | `.ai/out-of-scope` | `AI_OUT_OF_SCOPE_DIR` |
|
|
75
|
+
| `plan_index` | `00-index.md` | `QUEUE_PLAN_INDEX` |
|
|
76
|
+
| `seal` | `SEAL.sha256` | `QUEUE_SEAL_FILE` |
|
|
77
|
+
| `shared` | `true` | `AI_PATHS_SHARED` |
|
|
78
|
+
|
|
79
|
+
`AI_PATHS_FILE` names a different configuration file.
|
|
80
|
+
|
|
81
|
+
The environment names are the ones `work-queue` already uses, so one setting moves both tools.
|
|
82
|
+
|
|
83
|
+
## Worktrees
|
|
84
|
+
|
|
85
|
+
A gitignored directory under `.ai/` is shared: it resolves to the main checkout, found from
|
|
86
|
+
`git worktree list`, because a copy written inside a worktree is deleted with the worktree and
|
|
87
|
+
the queue in the main checkout can never see it. `shared = false` keeps a per-worktree copy. A
|
|
88
|
+
`docs/`-style path is never shared, because those files belong to the branch.
|
|
89
|
+
|
|
90
|
+
## Testing
|
|
91
|
+
|
|
92
|
+
tests/test.sh
|
|
93
|
+
|
|
94
|
+
Self-contained: builds scratch git repos, asserts on printed paths and exit codes, touches no
|
|
95
|
+
network. Needs `bash`, `python3`, `git`.
|
|
96
|
+
|
|
97
|
+
## Releasing
|
|
98
|
+
|
|
99
|
+
1. Bump `__version__` in `ai_path/__init__.py`. That is the only place the version lives;
|
|
100
|
+
`pyproject.toml` reads it from there.
|
|
101
|
+
2. Commit, then tag that commit with the tool's name in front:
|
|
102
|
+
`git tag ai-path-v<version> && git push origin ai-path-v<version>`.
|
|
103
|
+
|
|
104
|
+
The prefix must match the tool's directory name, and the version in the tag must match
|
|
105
|
+
`__version__` — a tag is also the integrity check, because a commit cannot change.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# ai-path
|
|
2
|
+
|
|
3
|
+
The one owner of where an agent artefact is written. Python 3, standard library only, `git` as the
|
|
4
|
+
only external call, no third-party dependency.
|
|
5
|
+
|
|
6
|
+
A skill asks this command for a directory instead of naming one. A repository that keeps its
|
|
7
|
+
artefacts somewhere else edits one file, and no skill changes.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
From a checkout, without installing anything:
|
|
12
|
+
|
|
13
|
+
bin/ai-path --version
|
|
14
|
+
|
|
15
|
+
As a command on `PATH`, editable, so a checkout edit takes effect immediately:
|
|
16
|
+
|
|
17
|
+
uv tool install --editable ./ai-path
|
|
18
|
+
|
|
19
|
+
From the remote, pinned to a tag:
|
|
20
|
+
|
|
21
|
+
uv tool install "git+https://github.com/chewcw/dev-tools.git@ai-path-v0.1.0#subdirectory=ai-path"
|
|
22
|
+
|
|
23
|
+
`uv tool install` writes its shim to `~/.local/bin`. If a non-interactive shell cannot find
|
|
24
|
+
`ai-path`, that directory is the reason — it has to be on `PATH`.
|
|
25
|
+
|
|
26
|
+
## Commands
|
|
27
|
+
|
|
28
|
+
ai-path <kind> [--name NAME] [--root DIR] print the absolute directory, creating it
|
|
29
|
+
ai-path env print every directory as KEY=value
|
|
30
|
+
ai-path docs kind, default directory, writer, reader
|
|
31
|
+
ai-path ai-write <kind> --name FILE [--field KEY=VALUE]... [--force]
|
|
32
|
+
write the frontmatter and the body from stdin
|
|
33
|
+
ai-path --version
|
|
34
|
+
|
|
35
|
+
Kinds: `specs`, `plans`, `sdd`, `inbox`, `intent`, `retros`, `out-of-scope`, `mockups`,
|
|
36
|
+
`research`, `ideas`, `roadmap`, `plan-pack`, `decisions`, `study`, `scratch`. `ai-path docs` is
|
|
37
|
+
the single description of them.
|
|
38
|
+
|
|
39
|
+
`ai-write` covers `specs`, `inbox`, and `intent`, the three kinds whose frontmatter a gate reads.
|
|
40
|
+
A kind without a frontmatter contract is refused, because inventing fields no gate reads is
|
|
41
|
+
ceremony.
|
|
42
|
+
|
|
43
|
+
Exit codes: 0 ok, 1 refused (unknown kind, a name that would leave the directory, an existing
|
|
44
|
+
file without `--force`), 2 no environment (no git checkout, missing argument).
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
One file at the git root, `.ai-paths`, as `key = value` lines. A blank value is not a value.
|
|
49
|
+
Precedence: environment, then `.ai-paths`, then the default.
|
|
50
|
+
|
|
51
|
+
| Key | Default | Environment variable |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| `specs` | `.ai/specs` | `QUEUE_SPECS_DIR` |
|
|
54
|
+
| `plans` | `.ai/plans` | `QUEUE_PLANS_DIR` |
|
|
55
|
+
| `sdd` | `.ai/sdd` | `AI_SDD_DIR` |
|
|
56
|
+
| `inbox` | `.ai/inbox` | `QUEUE_INBOX_DIR` |
|
|
57
|
+
| `intent` | `.ai/intent` | `AI_INTENT_DIR` |
|
|
58
|
+
| `retros` | `.ai/retros` | `AI_RETROS_DIR` |
|
|
59
|
+
| `out-of-scope` | `.ai/out-of-scope` | `AI_OUT_OF_SCOPE_DIR` |
|
|
60
|
+
| `plan_index` | `00-index.md` | `QUEUE_PLAN_INDEX` |
|
|
61
|
+
| `seal` | `SEAL.sha256` | `QUEUE_SEAL_FILE` |
|
|
62
|
+
| `shared` | `true` | `AI_PATHS_SHARED` |
|
|
63
|
+
|
|
64
|
+
`AI_PATHS_FILE` names a different configuration file.
|
|
65
|
+
|
|
66
|
+
The environment names are the ones `work-queue` already uses, so one setting moves both tools.
|
|
67
|
+
|
|
68
|
+
## Worktrees
|
|
69
|
+
|
|
70
|
+
A gitignored directory under `.ai/` is shared: it resolves to the main checkout, found from
|
|
71
|
+
`git worktree list`, because a copy written inside a worktree is deleted with the worktree and
|
|
72
|
+
the queue in the main checkout can never see it. `shared = false` keeps a per-worktree copy. A
|
|
73
|
+
`docs/`-style path is never shared, because those files belong to the branch.
|
|
74
|
+
|
|
75
|
+
## Testing
|
|
76
|
+
|
|
77
|
+
tests/test.sh
|
|
78
|
+
|
|
79
|
+
Self-contained: builds scratch git repos, asserts on printed paths and exit codes, touches no
|
|
80
|
+
network. Needs `bash`, `python3`, `git`.
|
|
81
|
+
|
|
82
|
+
## Releasing
|
|
83
|
+
|
|
84
|
+
1. Bump `__version__` in `ai_path/__init__.py`. That is the only place the version lives;
|
|
85
|
+
`pyproject.toml` reads it from there.
|
|
86
|
+
2. Commit, then tag that commit with the tool's name in front:
|
|
87
|
+
`git tag ai-path-v<version> && git push origin ai-path-v<version>`.
|
|
88
|
+
|
|
89
|
+
The prefix must match the tool's directory name, and the version in the tag must match
|
|
90
|
+
`__version__` — a tag is also the integrity check, because a commit cannot change.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.0"
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"""The command line: one kind in, one absolute directory out."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import PurePath
|
|
6
|
+
|
|
7
|
+
from . import __version__, config, paths, write
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def usage():
|
|
11
|
+
return "\n".join(
|
|
12
|
+
[
|
|
13
|
+
"usage: ai-path <kind> [--name NAME] [--root DIR]",
|
|
14
|
+
" ai-path env",
|
|
15
|
+
" ai-path docs",
|
|
16
|
+
" ai-path ai-write <kind> --name FILE [--field KEY=VALUE]... [--force]",
|
|
17
|
+
" ai-path --version",
|
|
18
|
+
"",
|
|
19
|
+
"kinds: " + ", ".join(paths.kind_names()),
|
|
20
|
+
]
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def die(msg, code=1):
|
|
25
|
+
print(f"error: {msg}", file=sys.stderr)
|
|
26
|
+
return code
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def opt(args, name, default=None):
|
|
30
|
+
value = default
|
|
31
|
+
i = 0
|
|
32
|
+
while i < len(args):
|
|
33
|
+
if args[i] == name:
|
|
34
|
+
value = args[i + 1] if i + 1 < len(args) else None
|
|
35
|
+
i += 2
|
|
36
|
+
continue
|
|
37
|
+
i += 1
|
|
38
|
+
return value
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def opts_all(args, name):
|
|
42
|
+
values = []
|
|
43
|
+
i = 0
|
|
44
|
+
while i < len(args):
|
|
45
|
+
if args[i] == name:
|
|
46
|
+
if i + 1 < len(args):
|
|
47
|
+
values.append(args[i + 1])
|
|
48
|
+
i += 2
|
|
49
|
+
continue
|
|
50
|
+
i += 1
|
|
51
|
+
return values
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def safe_name(name):
|
|
55
|
+
"""One path segment, or empty when the name would leave the directory."""
|
|
56
|
+
if not name or name in (".", ".."):
|
|
57
|
+
return ""
|
|
58
|
+
parts = PurePath(name).parts
|
|
59
|
+
if len(parts) != 1 or PurePath(name).is_absolute():
|
|
60
|
+
return ""
|
|
61
|
+
return name
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def cmd_env(args):
|
|
65
|
+
if args:
|
|
66
|
+
return die(f"unknown option: {args[0]}")
|
|
67
|
+
found = paths.git_root()
|
|
68
|
+
if not found:
|
|
69
|
+
return die("not a git repository; run this inside a checkout", 2)
|
|
70
|
+
root = os.path.realpath(found)
|
|
71
|
+
for key, variable in config.ENV_KEYS.items():
|
|
72
|
+
if key in paths.KINDS:
|
|
73
|
+
print(f"{variable}={paths.directory(root, key).as_posix()}")
|
|
74
|
+
elif key == "plan_index":
|
|
75
|
+
print(f"{variable}={config.setting(root, key, paths.PLAN_INDEX)}")
|
|
76
|
+
elif key == "seal":
|
|
77
|
+
print(f"{variable}={config.setting(root, key, paths.SEAL)}")
|
|
78
|
+
return 0
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def cmd_write(rest):
|
|
82
|
+
if not rest:
|
|
83
|
+
return die("usage: ai-path ai-write <kind> --name FILE")
|
|
84
|
+
kind, args = rest[0], rest[1:]
|
|
85
|
+
if kind not in write.DEFAULTS:
|
|
86
|
+
return die(f"ai-write does not write {kind}; it writes: " + ", ".join(sorted(write.DEFAULTS)))
|
|
87
|
+
name = opt(args, "--name", "") or ""
|
|
88
|
+
given_root = opt(args, "--root", "") or ""
|
|
89
|
+
pairs = opts_all(args, "--field")
|
|
90
|
+
known = {"--force", "--name", name, "--root", given_root, "--field"} | set(pairs)
|
|
91
|
+
for a in args:
|
|
92
|
+
if a not in known:
|
|
93
|
+
return die(f"unknown option: {a}")
|
|
94
|
+
if not name:
|
|
95
|
+
return die("usage: ai-path ai-write <kind> --name FILE")
|
|
96
|
+
safe = safe_name(name)
|
|
97
|
+
if not safe:
|
|
98
|
+
return die(f"--name must be one path segment: {name}")
|
|
99
|
+
allowed = {key for key, _default in write.DEFAULTS[kind]}
|
|
100
|
+
fields = {}
|
|
101
|
+
for pair in pairs:
|
|
102
|
+
key, sep, value = pair.partition("=")
|
|
103
|
+
key = key.strip()
|
|
104
|
+
if not sep or key not in allowed:
|
|
105
|
+
return die(f"--field needs KEY=VALUE with one of {sorted(allowed)}: {pair}")
|
|
106
|
+
fields[key] = value.strip()
|
|
107
|
+
found = given_root or paths.git_root()
|
|
108
|
+
if not found:
|
|
109
|
+
return die("not a git repository; run this inside a checkout", 2)
|
|
110
|
+
root = os.path.realpath(os.path.expanduser(found))
|
|
111
|
+
body = sys.stdin.read()
|
|
112
|
+
if not body.strip():
|
|
113
|
+
return die("empty body on stdin")
|
|
114
|
+
target = paths.directory(root, kind, safe, config.shared(root))
|
|
115
|
+
if target.exists() and "--force" not in args:
|
|
116
|
+
return die(f"{target.as_posix()} exists; pass --force")
|
|
117
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
118
|
+
target.write_text(write.frontmatter(kind, safe, body, root, fields) + "\n" + body)
|
|
119
|
+
print(target.as_posix())
|
|
120
|
+
return 0
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def cmd_docs():
|
|
124
|
+
for kind in paths.kind_names():
|
|
125
|
+
default, writer, reader = paths.KINDS[kind]
|
|
126
|
+
print(f"{kind}\t{default}\t{writer}\t{reader}")
|
|
127
|
+
return 0
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def cmd_kind(kind, args):
|
|
131
|
+
name = opt(args, "--name", "") or ""
|
|
132
|
+
given_root = opt(args, "--root", "") or ""
|
|
133
|
+
known = {"--name", name, "--root", given_root}
|
|
134
|
+
for a in args:
|
|
135
|
+
if a not in known:
|
|
136
|
+
return die(f"unknown option: {a}")
|
|
137
|
+
if kind not in paths.KINDS:
|
|
138
|
+
return die(f"unknown kind: {kind}. Run `ai-path docs` to see them.")
|
|
139
|
+
safe = ""
|
|
140
|
+
if name:
|
|
141
|
+
safe = safe_name(name)
|
|
142
|
+
if not safe:
|
|
143
|
+
return die(f"--name must be one path segment: {name}")
|
|
144
|
+
root = ""
|
|
145
|
+
if kind != "scratch":
|
|
146
|
+
if given_root:
|
|
147
|
+
root = os.path.realpath(os.path.expanduser(given_root))
|
|
148
|
+
else:
|
|
149
|
+
found = paths.git_root()
|
|
150
|
+
if not found:
|
|
151
|
+
return die("not a git repository; run this inside a checkout", 2)
|
|
152
|
+
root = os.path.realpath(found)
|
|
153
|
+
directory = paths.directory(root, kind, safe, config.shared(root) if root else True)
|
|
154
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
155
|
+
print(directory.as_posix())
|
|
156
|
+
return 0
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def main(argv=None):
|
|
160
|
+
args = list(sys.argv[1:] if argv is None else argv)
|
|
161
|
+
if not args:
|
|
162
|
+
print(usage(), file=sys.stderr)
|
|
163
|
+
return 1
|
|
164
|
+
if args[0] in ("-h", "--help"):
|
|
165
|
+
print(usage())
|
|
166
|
+
return 0
|
|
167
|
+
if args[0] == "--version":
|
|
168
|
+
print(__version__)
|
|
169
|
+
return 0
|
|
170
|
+
sub = args[0]
|
|
171
|
+
rest = args[1:]
|
|
172
|
+
if sub == "docs":
|
|
173
|
+
return cmd_docs()
|
|
174
|
+
if sub == "env":
|
|
175
|
+
return cmd_env(rest)
|
|
176
|
+
if sub == "ai-write":
|
|
177
|
+
return cmd_write(rest)
|
|
178
|
+
return cmd_kind(sub, rest)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""The repository's directory map, and the environment variable that beats it."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
FILE_NAME = ".ai-paths"
|
|
7
|
+
|
|
8
|
+
ENV_KEYS = {
|
|
9
|
+
"specs": "QUEUE_SPECS_DIR",
|
|
10
|
+
"plans": "QUEUE_PLANS_DIR",
|
|
11
|
+
"plan_index": "QUEUE_PLAN_INDEX",
|
|
12
|
+
"seal": "QUEUE_SEAL_FILE",
|
|
13
|
+
"inbox": "QUEUE_INBOX_DIR",
|
|
14
|
+
"intent": "AI_INTENT_DIR",
|
|
15
|
+
"retros": "AI_RETROS_DIR",
|
|
16
|
+
"sdd": "AI_SDD_DIR",
|
|
17
|
+
"out-of-scope": "AI_OUT_OF_SCOPE_DIR",
|
|
18
|
+
"shared": "AI_PATHS_SHARED",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def file_for(root):
|
|
23
|
+
override = os.environ.get("AI_PATHS_FILE", "")
|
|
24
|
+
if override:
|
|
25
|
+
return Path(override).expanduser()
|
|
26
|
+
return Path(root) / FILE_NAME
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def read(path):
|
|
30
|
+
"""`key = value` lines. A blank value is not a value."""
|
|
31
|
+
values = {}
|
|
32
|
+
try:
|
|
33
|
+
text = Path(path).read_text()
|
|
34
|
+
except OSError:
|
|
35
|
+
return values
|
|
36
|
+
for line in text.splitlines():
|
|
37
|
+
line = line.split("#", 1)[0].strip()
|
|
38
|
+
if "=" not in line:
|
|
39
|
+
continue
|
|
40
|
+
key, value = line.split("=", 1)
|
|
41
|
+
if key.strip() and value.strip():
|
|
42
|
+
values[key.strip()] = value.strip()
|
|
43
|
+
return values
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def setting(root, key, default):
|
|
47
|
+
from_env = os.environ.get(ENV_KEYS.get(key, ""), "")
|
|
48
|
+
if from_env:
|
|
49
|
+
return from_env
|
|
50
|
+
return read(file_for(root)).get(key, "") or default
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def shared(root):
|
|
54
|
+
"""Whether a gitignored artefact directory belongs to the main checkout."""
|
|
55
|
+
value = setting(root, "shared", "true").strip().lower()
|
|
56
|
+
return value not in ("false", "no", "0")
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Where each artefact kind lives: one table, one resolver.
|
|
2
|
+
|
|
3
|
+
A skill asks this module for a directory instead of naming one, so a repository
|
|
4
|
+
that keeps its artefacts somewhere else edits one file and no skill changes.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import subprocess
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from . import config
|
|
12
|
+
|
|
13
|
+
PLAN_INDEX = "00-index.md"
|
|
14
|
+
SEAL = "SEAL.sha256"
|
|
15
|
+
|
|
16
|
+
# kind -> (default directory, who writes it, who reads it)
|
|
17
|
+
KINDS = {
|
|
18
|
+
"specs": (".ai/specs", "grill-to-spec, spec-from-issue, brainstorming", "work-queue move --spec, writing-plans"),
|
|
19
|
+
"plans": (".ai/plans", "writing-plans", "work-queue move --plan, executing-plans"),
|
|
20
|
+
"sdd": (".ai/sdd", "subagent-driven-development", "subagent-driven-development"),
|
|
21
|
+
"inbox": (".ai/inbox", "capture", "work-queue promote, triage"),
|
|
22
|
+
"intent": (".ai/intent", "intent-to-scopes", "grill-to-spec, spec-from-issue"),
|
|
23
|
+
"retros": (".ai/retros", "retrospective", "intent-to-scopes"),
|
|
24
|
+
"out-of-scope": (".ai/out-of-scope", "work-queue close", "triage"),
|
|
25
|
+
"mockups": (".ai/mockups", "design-mockups", "the human"),
|
|
26
|
+
"research": (".ai/research", "research-and-report", "the human"),
|
|
27
|
+
"ideas": (".ai/ideas", "idea-refine", "the human"),
|
|
28
|
+
"roadmap": ("docs/roadmap", "project-roadmap", "the human"),
|
|
29
|
+
"plan-pack": ("docs/plan", "master-plan", "the receiving team"),
|
|
30
|
+
"decisions": ("docs/decisions", "documentation-and-adrs", "the human"),
|
|
31
|
+
"study": (".study", "study-codebase", "the human"),
|
|
32
|
+
"scratch": ("/tmp", "triage, executing-plans, code-review, judgment-day", "the tool that wrote it"),
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def kind_names():
|
|
37
|
+
return sorted(KINDS)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def default_dir(kind):
|
|
41
|
+
return KINDS[kind][0]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def git_root(start=None):
|
|
45
|
+
"""Top level of the checkout that holds `start`. Empty when there is none."""
|
|
46
|
+
result = subprocess.run(
|
|
47
|
+
["git", "-C", str(start or Path.cwd()), "rev-parse", "--show-toplevel"],
|
|
48
|
+
capture_output=True,
|
|
49
|
+
text=True,
|
|
50
|
+
)
|
|
51
|
+
if result.returncode != 0:
|
|
52
|
+
return ""
|
|
53
|
+
return result.stdout.strip()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def main_worktree(root):
|
|
57
|
+
"""The main checkout. The first `worktree` line of the porcelain listing."""
|
|
58
|
+
result = subprocess.run(
|
|
59
|
+
["git", "-C", str(root), "worktree", "list", "--porcelain"],
|
|
60
|
+
capture_output=True,
|
|
61
|
+
text=True,
|
|
62
|
+
)
|
|
63
|
+
if result.returncode != 0:
|
|
64
|
+
return ""
|
|
65
|
+
for line in result.stdout.splitlines():
|
|
66
|
+
if line.startswith("worktree "):
|
|
67
|
+
return line[len("worktree "):].strip()
|
|
68
|
+
return ""
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _is_our_artefact_dir(path):
|
|
72
|
+
"""A relative path under .ai/ is gitignored, so one copy serves every worktree."""
|
|
73
|
+
parts = Path(path).parts
|
|
74
|
+
return not Path(path).is_absolute() and parts[:1] == (".ai",)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def directory(root, kind, name="", shared=True):
|
|
78
|
+
"""Absolute directory for a kind. Creates nothing."""
|
|
79
|
+
if kind == "scratch":
|
|
80
|
+
path = Path(os.environ.get("TMPDIR") or default_dir(kind))
|
|
81
|
+
return path / name if name else path
|
|
82
|
+
configured = config.setting(root, kind, default_dir(kind))
|
|
83
|
+
base = Path(root)
|
|
84
|
+
if shared and _is_our_artefact_dir(configured):
|
|
85
|
+
base = Path(main_worktree(root) or root)
|
|
86
|
+
path = Path(configured)
|
|
87
|
+
path = path if path.is_absolute() else base / path
|
|
88
|
+
return path / name if name else path
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""The frontmatter a kind must carry, written for the caller.
|
|
2
|
+
|
|
3
|
+
A slug and a date are the caller's judgement. The keys, their order, and their
|
|
4
|
+
defaults are not, because a gate reads them.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import subprocess
|
|
8
|
+
from datetime import date
|
|
9
|
+
|
|
10
|
+
# kind -> ordered (key, value). A value of None means derive it.
|
|
11
|
+
DEFAULTS = {
|
|
12
|
+
"specs": [("topic", None), ("status", "draft"), ("repo", None), ("issue", "0"), ("spec_in", "body")],
|
|
13
|
+
"inbox": [("status", "local-only"), ("captured", None), ("title", None), ("kind", "task")],
|
|
14
|
+
"intent": [("slug", None), ("revision", "1"), ("updated", None), ("epic", "0"), ("triage", "open")],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def slug_of(name):
|
|
19
|
+
"""Drop a leading YYYY-MM-DD- and a trailing -design, then the extension."""
|
|
20
|
+
stem = name[:-3] if name.endswith(".md") else name
|
|
21
|
+
if len(stem) > 11 and stem[4:5] == "-" and stem[7:8] == "-" and stem[10:11] == "-":
|
|
22
|
+
stem = stem[11:]
|
|
23
|
+
if stem.endswith("-design"):
|
|
24
|
+
stem = stem[: -len("-design")]
|
|
25
|
+
return stem
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def repo_of(root):
|
|
29
|
+
"""owner/name from origin, or empty when the remote names nothing usable."""
|
|
30
|
+
result = subprocess.run(
|
|
31
|
+
["git", "-C", str(root), "remote", "get-url", "origin"],
|
|
32
|
+
capture_output=True,
|
|
33
|
+
text=True,
|
|
34
|
+
)
|
|
35
|
+
if result.returncode != 0:
|
|
36
|
+
return ""
|
|
37
|
+
url = result.stdout.strip()
|
|
38
|
+
if ":" in url and "//" not in url:
|
|
39
|
+
url = url.split(":", 1)[1]
|
|
40
|
+
url = url.removesuffix(".git")
|
|
41
|
+
parts = [p for p in url.split("/") if p]
|
|
42
|
+
return "/".join(parts[-2:]) if len(parts) >= 2 else ""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def derive(key, name, body, root):
|
|
46
|
+
"""The value for a None in DEFAULTS."""
|
|
47
|
+
if key in ("topic", "slug"):
|
|
48
|
+
return slug_of(name)
|
|
49
|
+
if key in ("captured", "updated"):
|
|
50
|
+
return date.today().isoformat()
|
|
51
|
+
if key == "repo":
|
|
52
|
+
return repo_of(root)
|
|
53
|
+
if key == "title":
|
|
54
|
+
for line in body.splitlines():
|
|
55
|
+
if line.startswith("# "):
|
|
56
|
+
return line[2:].strip()
|
|
57
|
+
return slug_of(name)
|
|
58
|
+
return ""
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def frontmatter(kind, name, body, root, fields):
|
|
62
|
+
lines = ["---"]
|
|
63
|
+
for key, default in DEFAULTS[kind]:
|
|
64
|
+
value = fields.get(key) or (default if default is not None else derive(key, name, body, root))
|
|
65
|
+
lines.append(f"{key}: {value}".rstrip())
|
|
66
|
+
lines.append("---")
|
|
67
|
+
return "\n".join(lines) + "\n"
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chewcw-ai-path
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: One command that owns where agent artefacts are written
|
|
5
|
+
Author: chew cw
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/chewcw/skills/tree/main/dev-tools/ai-path
|
|
8
|
+
Project-URL: Repository, https://github.com/chewcw/skills
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# ai-path
|
|
17
|
+
|
|
18
|
+
The one owner of where an agent artefact is written. Python 3, standard library only, `git` as the
|
|
19
|
+
only external call, no third-party dependency.
|
|
20
|
+
|
|
21
|
+
A skill asks this command for a directory instead of naming one. A repository that keeps its
|
|
22
|
+
artefacts somewhere else edits one file, and no skill changes.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
From a checkout, without installing anything:
|
|
27
|
+
|
|
28
|
+
bin/ai-path --version
|
|
29
|
+
|
|
30
|
+
As a command on `PATH`, editable, so a checkout edit takes effect immediately:
|
|
31
|
+
|
|
32
|
+
uv tool install --editable ./ai-path
|
|
33
|
+
|
|
34
|
+
From the remote, pinned to a tag:
|
|
35
|
+
|
|
36
|
+
uv tool install "git+https://github.com/chewcw/dev-tools.git@ai-path-v0.1.0#subdirectory=ai-path"
|
|
37
|
+
|
|
38
|
+
`uv tool install` writes its shim to `~/.local/bin`. If a non-interactive shell cannot find
|
|
39
|
+
`ai-path`, that directory is the reason — it has to be on `PATH`.
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
ai-path <kind> [--name NAME] [--root DIR] print the absolute directory, creating it
|
|
44
|
+
ai-path env print every directory as KEY=value
|
|
45
|
+
ai-path docs kind, default directory, writer, reader
|
|
46
|
+
ai-path ai-write <kind> --name FILE [--field KEY=VALUE]... [--force]
|
|
47
|
+
write the frontmatter and the body from stdin
|
|
48
|
+
ai-path --version
|
|
49
|
+
|
|
50
|
+
Kinds: `specs`, `plans`, `sdd`, `inbox`, `intent`, `retros`, `out-of-scope`, `mockups`,
|
|
51
|
+
`research`, `ideas`, `roadmap`, `plan-pack`, `decisions`, `study`, `scratch`. `ai-path docs` is
|
|
52
|
+
the single description of them.
|
|
53
|
+
|
|
54
|
+
`ai-write` covers `specs`, `inbox`, and `intent`, the three kinds whose frontmatter a gate reads.
|
|
55
|
+
A kind without a frontmatter contract is refused, because inventing fields no gate reads is
|
|
56
|
+
ceremony.
|
|
57
|
+
|
|
58
|
+
Exit codes: 0 ok, 1 refused (unknown kind, a name that would leave the directory, an existing
|
|
59
|
+
file without `--force`), 2 no environment (no git checkout, missing argument).
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
One file at the git root, `.ai-paths`, as `key = value` lines. A blank value is not a value.
|
|
64
|
+
Precedence: environment, then `.ai-paths`, then the default.
|
|
65
|
+
|
|
66
|
+
| Key | Default | Environment variable |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| `specs` | `.ai/specs` | `QUEUE_SPECS_DIR` |
|
|
69
|
+
| `plans` | `.ai/plans` | `QUEUE_PLANS_DIR` |
|
|
70
|
+
| `sdd` | `.ai/sdd` | `AI_SDD_DIR` |
|
|
71
|
+
| `inbox` | `.ai/inbox` | `QUEUE_INBOX_DIR` |
|
|
72
|
+
| `intent` | `.ai/intent` | `AI_INTENT_DIR` |
|
|
73
|
+
| `retros` | `.ai/retros` | `AI_RETROS_DIR` |
|
|
74
|
+
| `out-of-scope` | `.ai/out-of-scope` | `AI_OUT_OF_SCOPE_DIR` |
|
|
75
|
+
| `plan_index` | `00-index.md` | `QUEUE_PLAN_INDEX` |
|
|
76
|
+
| `seal` | `SEAL.sha256` | `QUEUE_SEAL_FILE` |
|
|
77
|
+
| `shared` | `true` | `AI_PATHS_SHARED` |
|
|
78
|
+
|
|
79
|
+
`AI_PATHS_FILE` names a different configuration file.
|
|
80
|
+
|
|
81
|
+
The environment names are the ones `work-queue` already uses, so one setting moves both tools.
|
|
82
|
+
|
|
83
|
+
## Worktrees
|
|
84
|
+
|
|
85
|
+
A gitignored directory under `.ai/` is shared: it resolves to the main checkout, found from
|
|
86
|
+
`git worktree list`, because a copy written inside a worktree is deleted with the worktree and
|
|
87
|
+
the queue in the main checkout can never see it. `shared = false` keeps a per-worktree copy. A
|
|
88
|
+
`docs/`-style path is never shared, because those files belong to the branch.
|
|
89
|
+
|
|
90
|
+
## Testing
|
|
91
|
+
|
|
92
|
+
tests/test.sh
|
|
93
|
+
|
|
94
|
+
Self-contained: builds scratch git repos, asserts on printed paths and exit codes, touches no
|
|
95
|
+
network. Needs `bash`, `python3`, `git`.
|
|
96
|
+
|
|
97
|
+
## Releasing
|
|
98
|
+
|
|
99
|
+
1. Bump `__version__` in `ai_path/__init__.py`. That is the only place the version lives;
|
|
100
|
+
`pyproject.toml` reads it from there.
|
|
101
|
+
2. Commit, then tag that commit with the tool's name in front:
|
|
102
|
+
`git tag ai-path-v<version> && git push origin ai-path-v<version>`.
|
|
103
|
+
|
|
104
|
+
The prefix must match the tool's directory name, and the version in the tag must match
|
|
105
|
+
`__version__` — a tag is also the integrity check, because a commit cannot change.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
ai_path/__init__.py
|
|
5
|
+
ai_path/cli.py
|
|
6
|
+
ai_path/config.py
|
|
7
|
+
ai_path/paths.py
|
|
8
|
+
ai_path/write.py
|
|
9
|
+
chewcw_ai_path.egg-info/PKG-INFO
|
|
10
|
+
chewcw_ai_path.egg-info/SOURCES.txt
|
|
11
|
+
chewcw_ai_path.egg-info/dependency_links.txt
|
|
12
|
+
chewcw_ai_path.egg-info/entry_points.txt
|
|
13
|
+
chewcw_ai_path.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ai_path
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "chewcw-ai-path"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "One command that owns where agent artefacts are written"
|
|
9
|
+
requires-python = ">=3.9"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{name = "chew cw"}]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://github.com/chewcw/skills/tree/main/dev-tools/ai-path"
|
|
21
|
+
Repository = "https://github.com/chewcw/skills"
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
ai-path = "ai_path.cli:main"
|
|
25
|
+
|
|
26
|
+
[tool.setuptools]
|
|
27
|
+
packages = ["ai_path"]
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.dynamic]
|
|
30
|
+
version = {attr = "ai_path.__version__"}
|