@garyr/pt-cli 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -0
- package/dist/commands/addCommand.js +37 -0
- package/dist/commands/configCommand.js +96 -0
- package/dist/commands/ignoreCommand.js +12 -0
- package/dist/commands/initCommand.js +294 -0
- package/dist/commands/learnCommand.js +473 -0
- package/dist/commands/removeCommand.js +28 -0
- package/dist/commands/variablesCommand.js +62 -0
- package/dist/config.js +283 -0
- package/dist/index.js +75 -0
- package/dist/postconfig.js +73 -0
- package/dist/substitute.js +98 -0
- package/doc/configuration.md +333 -0
- package/doc/exclusions.md +35 -0
- package/doc/usage.md +119 -0
- package/doc/variable_substitution_example.md +78 -0
- package/package.json +36 -0
- package/skills/agency-pt-operator/SKILL.md +61 -0
- package/src/commands/addCommand.ts +41 -0
- package/src/commands/configCommand.ts +102 -0
- package/src/commands/ignoreCommand.ts +17 -0
- package/src/commands/initCommand.ts +311 -0
- package/src/commands/learnCommand.ts +492 -0
- package/src/commands/removeCommand.ts +35 -0
- package/src/commands/variablesCommand.ts +67 -0
- package/src/config.ts +356 -0
- package/src/index.ts +92 -0
- package/src/postconfig.ts +87 -0
- package/src/substitute.ts +122 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
Config is stored at `~/.pt/config.yaml` and contains:
|
|
4
|
+
|
|
5
|
+
- `version`: Config version
|
|
6
|
+
- `templates`: Dictionary of learned templates with folder structure, `templateRoot`, `copy_files`, `post_copy`, and `post_config`
|
|
7
|
+
- `default_post_config`: Array of default post-config tasks to suggest when learning a template
|
|
8
|
+
- `ignore`: Global folder ignore patterns for `pt learn`
|
|
9
|
+
- `variables`: Global variable suggestions for `pt learn` (name, prompt, default, required)
|
|
10
|
+
|
|
11
|
+
## Template Variables
|
|
12
|
+
|
|
13
|
+
When learning a template, you can define variables that will be prompted during initialization:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Learn with variables
|
|
17
|
+
pt learn /path/to/project
|
|
18
|
+
# When prompted: Define template variables? (y/n)
|
|
19
|
+
# Enter variables as comma-separated names: client_name,project_name
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Automatic Detection:**
|
|
23
|
+
Instead of manual definition, `pt learn` and `pt update` automatically scan for placeholders like `{{ variable_name }}` in text files (root and 1st-level subdirectories). If found, they are automatically added to the `variables` list. This is the recommended way to manage variables for most templates.
|
|
24
|
+
|
|
25
|
+
These variables are then used during `copy_files` operations to replace `{{variable_name}}` placeholders in copied files.
|
|
26
|
+
|
|
27
|
+
## Post-Config Tasks
|
|
28
|
+
|
|
29
|
+
Post-config tasks are optional commands that run after a project is initialized. They can be defined in a template or auto-detected from the source directory.
|
|
30
|
+
|
|
31
|
+
**Auto-detection** (`pt learn`):
|
|
32
|
+
|
|
33
|
+
When learning a template, `pt` scans the source directory for common patterns and suggests post-config tasks:
|
|
34
|
+
|
|
35
|
+
| Pattern | Auto-detected task | Type filter |
|
|
36
|
+
| ------------------------------ | --------------------------------- | ----------- |
|
|
37
|
+
| `.git/` | `git init` | all |
|
|
38
|
+
| `package.json` | `npm install` | javascript |
|
|
39
|
+
| `requirements.txt` | `pip install -r requirements.txt` | python |
|
|
40
|
+
| `setup.py` or `pyproject.toml` | `pip install -e .` | python |
|
|
41
|
+
| `Makefile` | `make init` | all |
|
|
42
|
+
|
|
43
|
+
Additionally, if `pt learn` finds a `post_config.sh` or `post_config.bat` file at the root of the directory, it will parse the scripts and automatically load the tasks into the `post_config` array.
|
|
44
|
+
|
|
45
|
+
### The 80% Philosophy
|
|
46
|
+
|
|
47
|
+
`pt` is designed to get you **80% of the way there** automatically. For complex templates, you are encouraged to:
|
|
48
|
+
|
|
49
|
+
1. Use `pt learn` to capture the basic structure and key boilerplate.
|
|
50
|
+
2. Manually edit `~/.pt/config.yaml` to refine `copy_files`, `post_config` commands, or add specific `chmod` requirements.
|
|
51
|
+
3. Alternatively, initialize a temporary project from your learned template (`pt init`), refine it manually, and then use `pt update` from that directory to "re-learn" the refined state.
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
javascript: [git init, npm install]
|
|
55
|
+
python: [git init, python -m venv .venv, pip install -r requirements.txt]
|
|
56
|
+
godot: [git init, git lfs install]
|
|
57
|
+
blender: [git init, git lfs install]
|
|
58
|
+
documentation: [git init]
|
|
59
|
+
default: [git init]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Manual definition** in `config.yaml`:
|
|
63
|
+
|
|
64
|
+
```yaml
|
|
65
|
+
templates:
|
|
66
|
+
my_template:
|
|
67
|
+
name: My Project
|
|
68
|
+
type: javascript
|
|
69
|
+
post_config:
|
|
70
|
+
- command: "git init"
|
|
71
|
+
description: "Initialize git repository"
|
|
72
|
+
- command: "npm install"
|
|
73
|
+
description: "Install npm dependencies"
|
|
74
|
+
type: "javascript"
|
|
75
|
+
- command: "git lfs install"
|
|
76
|
+
description: "Install git-lfs hooks"
|
|
77
|
+
always_prompt: true
|
|
78
|
+
- script: "bin/setup.sh"
|
|
79
|
+
description: "Run custom setup script"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Each task supports:
|
|
83
|
+
|
|
84
|
+
| Field | Description |
|
|
85
|
+
| ---------------- | -------------------------------------------------------------------------------- |
|
|
86
|
+
| `command` | Shell command to run (auto-selected shell: `cmd /c` on Windows, `sh -c` on Unix) |
|
|
87
|
+
| `description` | Shown to user during prompt |
|
|
88
|
+
| `type` | Filter by project type (e.g., `javascript`) |
|
|
89
|
+
| `always_prompt` | If `true`, ask per-task even if user says "yes" |
|
|
90
|
+
| `script` | Path to script relative to template root |
|
|
91
|
+
| `cross_platform` | If `true`, use platform-safe runner |
|
|
92
|
+
|
|
93
|
+
**Interaction flow** during `pt init`:
|
|
94
|
+
|
|
95
|
+
1. Folder structure created
|
|
96
|
+
2. If template has `post_config`:
|
|
97
|
+
- Filter tasks by project type
|
|
98
|
+
- Show list: `[1/3] git init` ...
|
|
99
|
+
- Prompt: `Run post-config tasks? (y/N)`
|
|
100
|
+
- If yes: run each task, show ✓/✗ per task
|
|
101
|
+
3. If no `post_config`, suggest baked-in defaults:
|
|
102
|
+
- Prompt: `No post-config defined. Use suggested tasks?`
|
|
103
|
+
4. If `--skip-post-config` flag: skip entirely
|
|
104
|
+
|
|
105
|
+
**Error handling**:
|
|
106
|
+
|
|
107
|
+
- Missing template files: warn and skip
|
|
108
|
+
- Command not found: catch error, log `✗`, continue to next task
|
|
109
|
+
- Git already initialized: caught silently
|
|
110
|
+
- Permission errors: caught and logged
|
|
111
|
+
- If all tasks fail: warn but don't block project creation
|
|
112
|
+
|
|
113
|
+
## Default Post-Config
|
|
114
|
+
|
|
115
|
+
Default post-config tasks are defined at the top level of `~/.pt/config.yaml` under `default_post_config`. They serve as suggestions when creating or updating templates via `pt learn`.
|
|
116
|
+
|
|
117
|
+
Unlike previous versions, default tasks are **not** automatically applied during `pt init`. Instead, you select which ones to include when learning a template, and those selections are baked into the template's `post_config` list. This eliminates the need to repeat boilerplate setup (e.g. `git init`) across templates while keeping each template fully self-contained.
|
|
118
|
+
|
|
119
|
+
### Configuration
|
|
120
|
+
|
|
121
|
+
```yaml
|
|
122
|
+
default_post_config:
|
|
123
|
+
- command: "git init"
|
|
124
|
+
description: "Initialize git repository"
|
|
125
|
+
- command: "git add -A && git commit -m 'Initial commit'"
|
|
126
|
+
description: "Initial git commit"
|
|
127
|
+
checked: false # default on, but user must manually check
|
|
128
|
+
- command: "git lfs install"
|
|
129
|
+
description: "Install git-lfs hooks"
|
|
130
|
+
type: "godot" # only applies to godot projects
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Fields
|
|
134
|
+
|
|
135
|
+
Each default task supports the same fields as template post-config:
|
|
136
|
+
|
|
137
|
+
| Field | Description |
|
|
138
|
+
| ------------- | -------------------------------------------------------------------------------- |
|
|
139
|
+
| `command` | Shell command to run |
|
|
140
|
+
| `description` | Shown to user during interactive selection |
|
|
141
|
+
| `checked` | Default checkbox state (`true` by default); set `false` to require manual opt-in |
|
|
142
|
+
| `type` | Filter by project type (e.g. `"javascript"`); if set, task only applies when template type matches |
|
|
143
|
+
|
|
144
|
+
### Behavior
|
|
145
|
+
|
|
146
|
+
- **`pt learn --yes`**: all applicable default tasks are added automatically to the new template's `post_config`.
|
|
147
|
+
- **Interactive mode (`pt learn`)**: applicable default tasks are shown in a checkbox group. Default tasks default to checked; `checked: false` overrides this.
|
|
148
|
+
|
|
149
|
+
### Viewing
|
|
150
|
+
|
|
151
|
+
Default tasks cannot be added via `pt add` or `pt learn` — they must be edited directly in `~/.pt/config.yaml` or viewed with `pt config`.
|
|
152
|
+
|
|
153
|
+
## Global Variables
|
|
154
|
+
|
|
155
|
+
Global variables are defined at the root of `~/.pt/config.yaml`. They serve as **suggestions** when creating or updating templates via `pt learn`.
|
|
156
|
+
|
|
157
|
+
Unlike default post-config tasks, global variables are also **not** automatically applied during `pt init`. Instead, they are "stamped" into individual templates during the learning process. This allows you to maintain a consistent set of metadata (like `author`, `license`, or `version`) across all your project types without forcing those values onto old templates or external configurations.
|
|
158
|
+
|
|
159
|
+
### Configuration
|
|
160
|
+
|
|
161
|
+
```yaml
|
|
162
|
+
variables:
|
|
163
|
+
- name: "author"
|
|
164
|
+
prompt: "Who is the author?"
|
|
165
|
+
default: "Gary Ritchie"
|
|
166
|
+
- name: "license"
|
|
167
|
+
prompt: "Choose a license:"
|
|
168
|
+
default: "MIT"
|
|
169
|
+
required: true
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Behavior
|
|
173
|
+
|
|
174
|
+
1. **`pt learn`**: When scanning a project to create a new template, `pt` will:
|
|
175
|
+
- Detect variables from text files using `{{ name }}` syntax.
|
|
176
|
+
- Inject the **Global Variables** as additional suggestions.
|
|
177
|
+
- Prompt for each variable definition unless `--yes` is used.
|
|
178
|
+
|
|
179
|
+
2. **`pt init`**: Project initialization uses only the variables explicitly saved in the chosen template. This ensures that templates are self-contained and portable.
|
|
180
|
+
|
|
181
|
+
3. **`pt variables`**: Use this command to manage your global variables:
|
|
182
|
+
- `pt variables`: List current global variables.
|
|
183
|
+
- `pt variables --set KEY=VAL`: Set/update a global variable's default value.
|
|
184
|
+
- `pt variables --delete KEY`: Remove a global variable.
|
|
185
|
+
- `pt variables --set --json '...'`: Bulk update via JSON.
|
|
186
|
+
|
|
187
|
+
## Copy Files
|
|
188
|
+
|
|
189
|
+
Copy additional files from the template source directory with optional variable substitution and chmod:
|
|
190
|
+
|
|
191
|
+
```yaml
|
|
192
|
+
templates:
|
|
193
|
+
my_template:
|
|
194
|
+
name: My Project
|
|
195
|
+
type: javascript
|
|
196
|
+
copy_files:
|
|
197
|
+
- src: "templates/config.template"
|
|
198
|
+
dest: "config.json"
|
|
199
|
+
substitute_variables: true
|
|
200
|
+
- src: "scripts/setup.sh"
|
|
201
|
+
dest: "bin/setup.sh"
|
|
202
|
+
chmod: "0755"
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Each entry supports:
|
|
206
|
+
|
|
207
|
+
| Field | Description |
|
|
208
|
+
| ---------------------- | ----------------------------------------------------------------- |
|
|
209
|
+
| `src` | Path relative to template root (source directory from `pt learn`) |
|
|
210
|
+
| `dest` | Path relative to project root |
|
|
211
|
+
| `substitute_variables` | If `true`, replace `{{variable_name}}` placeholders |
|
|
212
|
+
| `chmod` | Octal permission string (e.g., `"0755"`) — skipped on Windows |
|
|
213
|
+
|
|
214
|
+
**How it works**:
|
|
215
|
+
|
|
216
|
+
1. Read file from `templateRoot/src`
|
|
217
|
+
2. If `substitute_variables`: replace `{{var}}` patterns with user-provided values
|
|
218
|
+
3. Write to `projectRoot/dest` (creates intermediate directories)
|
|
219
|
+
4. Apply `chmod` on Unix systems
|
|
220
|
+
|
|
221
|
+
**Edge cases**:
|
|
222
|
+
|
|
223
|
+
- Missing source file: warn and skip
|
|
224
|
+
- Template root not set: skip silently (learn stores this)
|
|
225
|
+
- Permission errors: caught and logged
|
|
226
|
+
|
|
227
|
+
### Example: Variable Substitution
|
|
228
|
+
|
|
229
|
+
A plausible scenario for customizing a new project's `package.json` and `README.md`:
|
|
230
|
+
|
|
231
|
+
**1. Define in `config.yaml`**:
|
|
232
|
+
```yaml
|
|
233
|
+
templates:
|
|
234
|
+
node_web_app:
|
|
235
|
+
description: "A standard Node.js web application"
|
|
236
|
+
variables:
|
|
237
|
+
- name: "project_name"
|
|
238
|
+
prompt: "What is the project name?"
|
|
239
|
+
default: "my-app"
|
|
240
|
+
- name: "author_name"
|
|
241
|
+
prompt: "Who is the author?"
|
|
242
|
+
required: true
|
|
243
|
+
copy_files:
|
|
244
|
+
- src: "templates/package.json.tmpl"
|
|
245
|
+
dest: "package.json"
|
|
246
|
+
substitute_variables: true
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**2. Template source (`templates/package.json.tmpl`)**:
|
|
250
|
+
```json
|
|
251
|
+
{
|
|
252
|
+
"name": "{{project_name}}",
|
|
253
|
+
"author": "{{author_name}}",
|
|
254
|
+
"version": "1.0.0"
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**3. Resulting project file**:
|
|
259
|
+
If the user enters `my-service` and `Jane Doe`, the file `package.json` will be created with:
|
|
260
|
+
```json
|
|
261
|
+
{
|
|
262
|
+
"name": "my-service",
|
|
263
|
+
"author": "Jane Doe",
|
|
264
|
+
"version": "1.0.0"
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Post-Copy
|
|
269
|
+
|
|
270
|
+
Auto-detect executable scripts during `pt learn` and copy them to the new project:
|
|
271
|
+
|
|
272
|
+
**Auto-detection** (`pt learn`):
|
|
273
|
+
|
|
274
|
+
When learning a template, `pt` scans the source directory root for executable files:
|
|
275
|
+
|
|
276
|
+
| Pattern | Description |
|
|
277
|
+
| ---------------------- | --------------------------------------------------- |
|
|
278
|
+
| `*.sh` | Shell scripts |
|
|
279
|
+
| `*.py` | Python scripts |
|
|
280
|
+
| `*.bat` / `*.cmd` | Batch files |
|
|
281
|
+
| `Makefile` | Makefiles |
|
|
282
|
+
| `*.mk` | Makefile includes |
|
|
283
|
+
| (no ext, has exec bit) | Any executable file (checks execute permission bit) |
|
|
284
|
+
|
|
285
|
+
The detected files are presented to the user for confirmation:
|
|
286
|
+
|
|
287
|
+
```
|
|
288
|
+
Auto-detected executable files:
|
|
289
|
+
- bin/deploy.sh (shell script)
|
|
290
|
+
- scripts/lint.py (Python script)
|
|
291
|
+
- Makefile (makefile)
|
|
292
|
+
|
|
293
|
+
Add to post_copy? (y/N):
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
**Manual definition** in `config.yaml`:
|
|
297
|
+
|
|
298
|
+
```yaml
|
|
299
|
+
templates:
|
|
300
|
+
my_template:
|
|
301
|
+
name: My Project
|
|
302
|
+
post_copy:
|
|
303
|
+
- src: "bin/deploy.sh"
|
|
304
|
+
dest: "bin/deploy.sh"
|
|
305
|
+
- src: "scripts/lint.py"
|
|
306
|
+
dest: "scripts/lint.py"
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Each entry supports:
|
|
310
|
+
|
|
311
|
+
| Field | Description |
|
|
312
|
+
| ------ | ----------------------------------------------------------------- |
|
|
313
|
+
| `src` | Path relative to template root (source directory from `pt learn`) |
|
|
314
|
+
| `dest` | Path relative to project root (defaults to `src` if omitted) |
|
|
315
|
+
|
|
316
|
+
**How it works**:
|
|
317
|
+
|
|
318
|
+
1. During `pt init`, copies each `post_copy` file from `templateRoot/src` to `projectRoot/dest`
|
|
319
|
+
2. Auto-applies `0755` chmod for `.sh`, `.py`, `.bash`, `.bat` files
|
|
320
|
+
3. Missing files: warn and skip, don't block project creation
|
|
321
|
+
|
|
322
|
+
**vs copy_files**: `post_copy` is a simplified variant specifically for executables/scripts, auto-detected by `pt learn`. `copy_files` is for arbitrary template files with variable substitution support.
|
|
323
|
+
|
|
324
|
+
## Order of Operations
|
|
325
|
+
|
|
326
|
+
During `pt init`:
|
|
327
|
+
|
|
328
|
+
1. **Create folder structure** — folders and `.info.md` inside directories
|
|
329
|
+
2. **Copy `copy_files`** — with optional variable substitution and chmod
|
|
330
|
+
3. **Copy `post_copy`** — executable scripts (auto-detected or manual)
|
|
331
|
+
4. **Generate sharing metadata** — root `.info.md` and `post_config.sh`/`post_config.bat` are created so the result can be easily shared as a template
|
|
332
|
+
5. **Merge post-config tasks** — evaluate the template's `post_config` tasks; filter by project type
|
|
333
|
+
6. **Execute post-config tasks** — shell commands (interactive prompt, `--yes` for all, or `--skip-post-config` to omit)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Exclusions
|
|
2
|
+
|
|
3
|
+
The following are excluded by default when learning templates:
|
|
4
|
+
|
|
5
|
+
- `.git`, `node_modules`, `dist`, `build`
|
|
6
|
+
- `.DS_Store`, `.pytest_cache`, `__pycache__`
|
|
7
|
+
- `.vscode`, `.idea`
|
|
8
|
+
- Various editor/IDE files (`.bak`, `.swp`, etc.)
|
|
9
|
+
- Compiled files (`.pyc`, `.so`, `.dll`, etc.)
|
|
10
|
+
- `.gitkeep.md`, `.info.md`, `.vale.ini`, `.gitattributes`
|
|
11
|
+
|
|
12
|
+
## Ignore Patterns
|
|
13
|
+
|
|
14
|
+
Use the top-level `ignore` key in `~/.pt/config.yaml` or the `--ignore` flag to exclude folders:
|
|
15
|
+
|
|
16
|
+
```yaml
|
|
17
|
+
ignore:
|
|
18
|
+
- DAILIES/*
|
|
19
|
+
- PARKING_LOT/*
|
|
20
|
+
- REFERENCE/*
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Patterns use wildcards for clarity:
|
|
24
|
+
|
|
25
|
+
| Pattern | Effect |
|
|
26
|
+
| ------------ | ---------------------------------------------------------------------------- |
|
|
27
|
+
| `DAILIES/*` | Ignore all contents of DAILIES (DAILIES itself is kept as a template folder) |
|
|
28
|
+
| `DAILIES/**` | Same as `DAILIES/*` (deep match) |
|
|
29
|
+
| `NODE` | Ignore this specific folder only (no wildcard = exact match) |
|
|
30
|
+
|
|
31
|
+
The CLI flag `--ignore=DAILIES/*,PARKING_LOT/*` merges with the config patterns (one-shot, not persistent).
|
|
32
|
+
|
|
33
|
+
## Custom exclusions
|
|
34
|
+
|
|
35
|
+
Additional patterns can be added to `DEFAULT_EXCLUDES` in `src/config.ts`.
|
package/doc/usage.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Usage Guide
|
|
2
|
+
|
|
3
|
+
## Learn a template
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# Learn a new template (auto-detects post-config tasks)
|
|
7
|
+
pt learn /path/to/PROJECT
|
|
8
|
+
|
|
9
|
+
# Update an existing template (use current directory if no path given)
|
|
10
|
+
pt update <template_name>
|
|
11
|
+
pt update <template_name> /path/to/PROJECT
|
|
12
|
+
|
|
13
|
+
# Ignore specific folders during learning
|
|
14
|
+
pt learn /path/to/PROJECT --ignore=DAILIES/*,PARKING_LOT/*,REFERENCE/*
|
|
15
|
+
|
|
16
|
+
# Ignore a folder name at any depth
|
|
17
|
+
pt learn /path/to/PROJECT --ignore=**/.godot/
|
|
18
|
+
|
|
19
|
+
# Non-interactive mode (useful for AI agents)
|
|
20
|
+
pt learn /path/to/PROJECT --name my_template --desc "My new template" --yes
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Automatic Variable Detection
|
|
24
|
+
|
|
25
|
+
During `pt learn` or `pt update`, the tool automatically scans text files at the root and in the first-level subdirectories for variable placeholders using the `{{ variable_name }}` syntax.
|
|
26
|
+
|
|
27
|
+
- **Detection Range:** Root files and 1st-level subfolder files (e.g., `README.md`, `.makerc`, `DOC/closedown.md`).
|
|
28
|
+
- **Registration:** Any detected variables are automatically added to the template's configuration with default prompts (e.g., `Enter variable_name:`).
|
|
29
|
+
- **Global Suggestions:** Your global variables (defined in `~/.pt/config.yaml`) are automatically injected as additional suggestions during the learn process.
|
|
30
|
+
- **Updating:** You can add new placeholders to a project folder and run `pt update <template_name>` to automatically register them in your existing template.
|
|
31
|
+
|
|
32
|
+
## Initialize a project
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Initialize from a template (auto-suggests post-config tasks)
|
|
36
|
+
pt init <template_name> /path/to/new/PROJECT
|
|
37
|
+
|
|
38
|
+
# Skip post-config tasks
|
|
39
|
+
pt init <template_name> /path/to/new/PROJECT --skip-post-config
|
|
40
|
+
|
|
41
|
+
# Dry run (preview actions without execution)
|
|
42
|
+
pt init <template_name> /path/to/new/PROJECT --dry-run
|
|
43
|
+
|
|
44
|
+
# Non-interactive mode with variables (useful for an API or AI agents)
|
|
45
|
+
pt init <template_name> /path/to/new/PROJECT --yes --vars project_name=foo,author=bar
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Remove a template
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Remove a learned template (asks for confirmation)
|
|
52
|
+
pt remove <template_name>
|
|
53
|
+
|
|
54
|
+
# Short alias
|
|
55
|
+
pt rm <template_name>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Show config and templates
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pt config
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Shows all templates, their `post_config` tasks (if any), source paths, global post-config tasks, ignore patterns, global variables, and an example post-config block.
|
|
65
|
+
|
|
66
|
+
## Manage Global Variables
|
|
67
|
+
|
|
68
|
+
Global variables serve as boilerplate suggestions during the `pt learn` process.
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# List global variables
|
|
72
|
+
pt variables
|
|
73
|
+
|
|
74
|
+
# Set/Update global variables (comma-separated pairs)
|
|
75
|
+
pt variables --set AUTHOR="Gary Ritchie",LICENSE="MIT"
|
|
76
|
+
|
|
77
|
+
# Delete a global variable
|
|
78
|
+
pt variables --delete LICENSE
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
For more details on how these are used, see the [Configuration Guide](configuration.md).
|
|
82
|
+
|
|
83
|
+
## Template Sharing & JSON
|
|
84
|
+
|
|
85
|
+
### File-based Sharing
|
|
86
|
+
|
|
87
|
+
You can share your templates with others simply by sharing a directory (or a ZIP of it). When someone else runs `pt learn` on it, `pt` will automatically detect the following files at the root:
|
|
88
|
+
|
|
89
|
+
- `.info.md`: Used to automatically set the template's name (from the first `# Heading`) and description.
|
|
90
|
+
- `post_config.sh` or `post_config.bat`: Parsed to automatically populate the `post_config` actions in the user's `config.yaml`.
|
|
91
|
+
|
|
92
|
+
These files are also automatically generated at the root of a new project whenever you run `pt init`, making it trivial to initialize a project, zip it up, and share it with teammates as a fully-featured template!
|
|
93
|
+
|
|
94
|
+
### JSON Export & Import
|
|
95
|
+
|
|
96
|
+
For a more portable, text-based approach, you can export and import templates as JSON strings or files.
|
|
97
|
+
|
|
98
|
+
#### Exporting a Template to JSON
|
|
99
|
+
To export an existing template from your configuration as JSON:
|
|
100
|
+
```bash
|
|
101
|
+
pt config <template_name> --json > my_template.json
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Importing a Template from JSON
|
|
105
|
+
To add a template from a JSON file:
|
|
106
|
+
```bash
|
|
107
|
+
pt add <template_name> --file my_template.json
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Or from a JSON string:
|
|
111
|
+
```bash
|
|
112
|
+
pt add <template_name> '{"description":"My Template","files":{...}}'
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Exporting Full Config
|
|
116
|
+
To see your entire configuration (including all templates) in JSON format:
|
|
117
|
+
```bash
|
|
118
|
+
pt config --json
|
|
119
|
+
```
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Variable Substitution Example
|
|
2
|
+
|
|
3
|
+
This example demonstrates how to define variables in your template and use them to customize files during project initialization.
|
|
4
|
+
|
|
5
|
+
## 1. Define Variables in `config.yaml`
|
|
6
|
+
|
|
7
|
+
In your `~/.pt/config.yaml`, add a `variables` section to your template and set `substitute_variables: true` in the `copy_files` entries.
|
|
8
|
+
|
|
9
|
+
```yaml
|
|
10
|
+
templates:
|
|
11
|
+
node_web_app:
|
|
12
|
+
description: "A standard Node.js web application"
|
|
13
|
+
variables:
|
|
14
|
+
- name: "project_name"
|
|
15
|
+
prompt: "What is the project name?"
|
|
16
|
+
default: "my-app"
|
|
17
|
+
- name: "author_name"
|
|
18
|
+
prompt: "Who is the author?"
|
|
19
|
+
required: true
|
|
20
|
+
copy_files:
|
|
21
|
+
- src: "templates/package.json.tmpl"
|
|
22
|
+
dest: "package.json"
|
|
23
|
+
substitute_variables: true
|
|
24
|
+
- src: "templates/README.md.tmpl"
|
|
25
|
+
dest: "README.md"
|
|
26
|
+
substitute_variables: true
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
> [!TIP]
|
|
30
|
+
> **New in v0.16.0:** You no longer need to manually define the `variables` section. During `pt learn` or `pt update`, the tool will automatically detect `{{ variable_name }}` placeholders in your files and add them to the configuration for you.
|
|
31
|
+
|
|
32
|
+
## 2. Create Template Files
|
|
33
|
+
|
|
34
|
+
Create the source files in your template directory using `{{variable_name}}` placeholders.
|
|
35
|
+
|
|
36
|
+
**`templates/package.json.tmpl`**:
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"name": "{{project_name}}",
|
|
40
|
+
"version": "1.0.0",
|
|
41
|
+
"description": "Project created by pt-cli",
|
|
42
|
+
"author": "{{author_name}}",
|
|
43
|
+
"license": "MIT"
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**`templates/README.md.tmpl`**:
|
|
48
|
+
```markdown
|
|
49
|
+
# {{project_name}}
|
|
50
|
+
|
|
51
|
+
Created by {{author_name}} using the Node Web App template.
|
|
52
|
+
|
|
53
|
+
## Getting Started
|
|
54
|
+
|
|
55
|
+
1. npm install
|
|
56
|
+
2. npm run dev
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 3. Usage
|
|
60
|
+
|
|
61
|
+
When you run `pt init node_web_app my-new-project`, the CLI will prompt you:
|
|
62
|
+
|
|
63
|
+
```text
|
|
64
|
+
? What is the project name? (my-app) my-awesome-service
|
|
65
|
+
? Who is the author? Gary Ritchie
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The resulting `package.json` in `my-new-project/` will be:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"name": "my-awesome-service",
|
|
73
|
+
"version": "1.0.0",
|
|
74
|
+
"description": "Project created by pt-cli",
|
|
75
|
+
"author": "Gary Ritchie",
|
|
76
|
+
"license": "MIT"
|
|
77
|
+
}
|
|
78
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@garyr/pt-cli",
|
|
3
|
+
"version": "0.25.0",
|
|
4
|
+
"description": "Project Template CLI - Learn structures and initialize projects",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"pt": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"start": "tsx src/index.ts",
|
|
13
|
+
"dev": "tsx src/index.ts",
|
|
14
|
+
"prepublishOnly": "npm run build",
|
|
15
|
+
"build:linux": "bun build ./src/index.ts --compile --target=bun-linux-x64 --outfile ../BUILD/pt-cli/pt-linux",
|
|
16
|
+
"build:macos": "bun build ./src/index.ts --compile --target=bun-darwin-x64 --outfile ../BUILD/pt-cli/pt-macos",
|
|
17
|
+
"build:windows": "bun build ./src/index.ts --compile --target=bun-windows-x64 --outfile ../BUILD/pt-cli/pt-win.exe",
|
|
18
|
+
"build:all": "npm run build:linux && npm run build:macos && npm run build:windows"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [],
|
|
21
|
+
"author": "",
|
|
22
|
+
"license": "ISC",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"commander": "^12.1.0",
|
|
25
|
+
"inquirer": "^12.3.0",
|
|
26
|
+
"yaml": "^2.6.1",
|
|
27
|
+
"chalk": "^5.3.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"typescript": "^5.6.0",
|
|
31
|
+
"@types/node": "^22.0.0",
|
|
32
|
+
"@types/inquirer": "^9.0.7",
|
|
33
|
+
"ts-node": "^10.9.2",
|
|
34
|
+
"tsx": "^4.21.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: agency-pt-operator
|
|
3
|
+
description: Specialist in using pt-cli to scaffold project templates, capture boilerplate, and maintain standardized directory structures. Includes knowledge of default_post_config, global variables, and automatic variable detection.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# `pt-cli` Operator Skill
|
|
7
|
+
|
|
8
|
+
As an agent equipped with this skill, you have the ability to rapidly scaffold, manage, and learn project templates using the `pt-cli` tool. You must use this capability whenever you are asked to start a new project or establish a complex boilerplate structure.
|
|
9
|
+
|
|
10
|
+
## Core Directives
|
|
11
|
+
|
|
12
|
+
1. **Discovery First:**
|
|
13
|
+
Before creating a project structure manually, always check if a template exists.
|
|
14
|
+
- Run `pt config` to view available templates, their post-config tasks, and default post-config tasks.
|
|
15
|
+
|
|
16
|
+
2. **Scaffolding (`pt init`):**
|
|
17
|
+
When a matching template exists, initialize it using the non-interactive flags.
|
|
18
|
+
- **Command:** `pt init <template_name> <destination_path> --yes`
|
|
19
|
+
- If the template requires variables, pass them: `pt init <template_name> <destination_path> --yes --vars key1=value1,key2=value2`
|
|
20
|
+
- *Never* run `pt init` without `--yes`, as interactive prompts will block you.
|
|
21
|
+
- Note any errors from auto-executed post-config tasks (like `npm install` failing) and correct them if necessary.
|
|
22
|
+
- Note any errors from auto-executed post-config tasks (like `npm install` failing) and correct them if necessary.
|
|
23
|
+
|
|
24
|
+
3. **Capturing Knowledge (`pt learn`):**
|
|
25
|
+
If you spend time establishing a new, complex directory structure or configuration (e.g., a specific flavor of an Express backend with testing hooks), save it!
|
|
26
|
+
- **Command:** `pt learn <source_path> --name <template_name> --desc "<Description>" --yes`
|
|
27
|
+
- Explain to the user that you've captured this template for future use.
|
|
28
|
+
- **Automatic Variable Detection:** `pt learn` and `pt update` automatically scan text files (at root and one level deep) for `{{ variable_name }}` placeholders. You can add these to files (e.g., `README.md`, `.makerc`) and run `pt update <template> . --yes` to have them registered as template variables without manual configuration.
|
|
29
|
+
|
|
30
|
+
4. **Template Maintenance (`pt rm`):**
|
|
31
|
+
If a template is obsolete or requested for deletion, use `pt rm`.
|
|
32
|
+
- **Command:** `pt rm <template_name> --yes`
|
|
33
|
+
|
|
34
|
+
## Default Post-Config
|
|
35
|
+
|
|
36
|
+
Default post-config tasks are stored in `~/.pt/config.yaml` under `default_post_config`. They are used as suggestions during `pt learn` to apply to the newly created template. Each task supports:
|
|
37
|
+
|
|
38
|
+
- `command` — shell command to run
|
|
39
|
+
- `description` — shown to user
|
|
40
|
+
- `checked` — default checkbox state (defaults to `true` if omitted)
|
|
41
|
+
- `type` — filter by project type (e.g., `"javascript"`); if set, the task only applies when that template's name matches the type filter
|
|
42
|
+
|
|
43
|
+
Tasks with `checked: false` stay unchecked by default in interactive mode. In `pt learn --yes` mode, **all applicable** default tasks are included.
|
|
44
|
+
|
|
45
|
+
Use `pt config` to view currently configured default tasks. To add default tasks, edit `~/.pt/config.yaml` directly or use `pt add` for template management (config is YAML-only at this time).
|
|
46
|
+
|
|
47
|
+
## Global Variables
|
|
48
|
+
|
|
49
|
+
Global variables are defined in `~/.pt/config.yaml` under `variables`. They act as **suggestions** during the `pt learn` or `pt update` process.
|
|
50
|
+
|
|
51
|
+
- **Purpose:** They ensure that common metadata fields (like `author`, `license`, `project_version`) are consistently offered for inclusion in every new template you create.
|
|
52
|
+
- **Inheritance:** When you `learn` a new project structure, these global variables are automatically merged with any detected variables (`{{ var }}`) and offered as part of the new template's variable list.
|
|
53
|
+
- **Localization:** Once a template is saved, its variables are "stamped" in. Subsequent changes to global variables in the config will **not** retroactively affect old templates, ensuring stability and portability.
|
|
54
|
+
- **Management:** Use `pt variables --set key=value` to update your global defaults. For bulk updates, use `pt variables --set --json '...'`.
|
|
55
|
+
|
|
56
|
+
## Workflow Optimization
|
|
57
|
+
|
|
58
|
+
`pt-cli` provides an "80% of the way there" solution. Your workflow for new projects should be:
|
|
59
|
+
1. Identify the closest matching template (`pt config`).
|
|
60
|
+
2. Scaffold it non-interactively (`pt init ... --yes`).
|
|
61
|
+
3. Make the specific manual code/configuration changes requested by the user on top of that scaffolded base.
|