Skip to content

Commit a3b9f87

Browse files
committed
Add runner for iam update agent
Add /bin/main.py to the iam update tool to orchestrate the 4 steps.
1 parent f98ca8a commit a3b9f87

File tree

7 files changed

+406
-155
lines changed

7 files changed

+406
-155
lines changed
Lines changed: 42 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,74 @@
11
# Ailly Prompt Workflow
22

3-
This project provides three scripts to **generate** Ailly prompts, **run** them, **parse** the results, and **update** a DocGen instance.
4-
5-
## Overview
6-
7-
1. **Generate** Ailly prompts from DocGen snippets (`make_prompts.py`).
8-
2. **Run** the Ailly CLI on the generated prompts (`npx @ailly/cli`).
9-
3. **Parse** the Ailly outputs into structured JSON (`parse_json_files.py`).
10-
4. **Update** your DocGen project with the parsed results (`update_doc_gen.py`).
11-
12-
---
13-
14-
## Prerequisites
15-
16-
- Python 3.8+
17-
- Node.js & npm (for `npx`)
3+
This project automates the process of generating, running, parsing, and applying [Ailly](https://www.npmjs.com/package/@ailly/cli) prompt outputs to an AWS DocGen project. It combines all steps into one streamlined command using a single Python script.
184

195
---
206

21-
## Step 1: Generate Ailly prompts
22-
23-
Use `make_prompts.py` to create a directory of Markdown files and a `.aillyrc` configuration file.
7+
## 📦 Overview
248

25-
```bash
26-
python make_prompts.py \
27-
--doc-gen-root /path/to/your/docgen/project \
28-
--system-prompts "You are a helpful assistant..." \
29-
--out .ailly_prompts
30-
```
9+
This tool:
10+
1. **Generates** Ailly prompts from DocGen snippets.
11+
2. **Runs** Ailly CLI to get enhanced metadata.
12+
3. **Parses** Ailly responses into structured JSON.
13+
4. **Updates** your DocGen examples with the new metadata.
3114

32-
**Arguments:**
33-
- `--doc-gen-root`: Path to your DocGen project root.
34-
- `--system-prompts`: One or more system prompts, either as strings or file paths.
35-
- `--out`: (Optional) Output directory. Defaults to `.ailly_prompts`.
15+
All of this is done with one command.
3616

3717
---
3818

39-
## Step 2: Run Ailly CLI
19+
## ✅ Prerequisites
4020

41-
Run Ailly on the generated prompts:
42-
43-
```bash
44-
npx @ailly/cli --root .ailly_prompts
45-
```
46-
47-
This will create `{file}.ailly.md` output files in the `.ailly_prompts` directory (or whatever output directory you specified).
21+
- Python 3.8+
22+
- Node.js and npm (for `npx`)
23+
- A DocGen project directory
4824

4925
---
5026

51-
## Step 3: Parse Ailly output
27+
## 🚀 Usage
5228

53-
Parse the `{name}.ailly.md` files into JSON using `parse_json_files.py`:
29+
From your project root, run:
5430

5531
```bash
56-
python parse_json_files.py .ailly_prompts/*.ailly.md --out example_updates.json
32+
python -m aws_doc_sdk_examples_tools.agent.bin.main \
33+
/path/to/your/docgen/project \
34+
--system-prompts path/to/system_prompt.txt
5735
```
5836

59-
**Arguments:**
60-
- Positional: List of files to parse (e.g., `*.ailly.md`).
61-
- `--out`: (Optional) Path for the JSON output. Defaults to `out.json`.
37+
### 🔧 Arguments
38+
39+
Run `python -m aws_doc_sdk_examples_tools.agent.bin.main --help` for more info.
6240

6341
---
6442

65-
## Step 4: Update DocGen with Ailly results
43+
## 🗂 What This Does
6644

67-
Use `update_doc_gen.py` to load the parsed data back into your `DocGen` project:
45+
Under the hood, this script:
6846

69-
```bash
70-
python update_doc_gen.py \
71-
--doc-gen-root /path/to/your/docgen/project \
72-
--updates-path example_updates.json
73-
```
47+
1. Creates a directory `.ailly_iam_policy` containing:
48+
- One Markdown file per snippet.
49+
- A `.aillyrc` configuration file.
7450

75-
**Arguments:**
76-
- `--doc-gen-root`: Path to the root of your DocGen project.
77-
- `--updates-path`: JSON file generated in Step 3 (default: `example_updates.json`).
51+
2. Runs `npx @ailly/cli` to generate `.ailly.md` outputs.
7852

79-
This will update the `title`, `title_abbrev`, and `synopsis` fields in the corresponding DocGen examples.
53+
3. Parses the Ailly `.ailly.md` files into a single `iam_updates.json` file.
54+
55+
4. Updates each matching `Example` in the DocGen instance with:
56+
- `title`
57+
- `title_abbrev`
58+
- `synopsis`
8059

8160
---
8261

83-
## Example Full Workflow
62+
## 💡 Example
8463

8564
```bash
86-
# Step 1: Generate prompts
87-
python make_prompts.py \
88-
--doc-gen-root ~/projects/aws-docgen-root \
89-
--system-prompts system_prompt.txt \
90-
--out .ailly_prompts
91-
92-
# Step 2: Run Ailly
93-
npx @ailly/cli --root .ailly_prompts
94-
95-
# Step 3: Parse results
96-
python parse_json_files.py .ailly_prompts/*.ailly.md --out example_updates.json
97-
98-
# Step 4: Update DocGen
99-
python update_doc_gen.py \
100-
--doc-gen-root ~/projects/aws-docgen-root \
101-
--updates-path example_updates.json
65+
python -m aws_doc_sdk_examples_tools.agent.bin.main \
66+
~/projects/AWSIAMPolicyExampleReservoir \
67+
--system-prompts prompts/system_prompt.txt
10268
```
69+
70+
This will:
71+
- Write prompts and config to `.ailly_iam_policy/`
72+
- Run Ailly and capture results
73+
- Parse and save output as `.ailly_iam_policy/iam_updates.json`
74+
- Apply updates to your DocGen examples
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from pathlib import Path
2+
from subprocess import run
3+
from typing import List
4+
5+
import typer
6+
7+
from aws_doc_sdk_examples_tools.agent.make_prompts import main as make_prompts
8+
from aws_doc_sdk_examples_tools.agent.parse_json_files import main as parse_json_files
9+
from aws_doc_sdk_examples_tools.agent.update_doc_gen import main as update_doc_gen
10+
11+
app = typer.Typer()
12+
13+
AILLY_DIR = ".ailly_iam_policy"
14+
AILLY_DIR_PATH = Path(AILLY_DIR)
15+
IAM_UPDATES_PATH = AILLY_DIR_PATH / "iam_updates.json"
16+
17+
18+
def get_ailly_files(dir: Path):
19+
return [
20+
file
21+
for file in dir.iterdir()
22+
if file.is_file() and file.name.endswith(".ailly.md")
23+
]
24+
25+
26+
@app.command()
27+
def update(iam_tributary_root: str, system_prompts: List[str] = []):
28+
doc_gen_root = Path(iam_tributary_root)
29+
make_prompts(
30+
doc_gen_root=doc_gen_root, system_prompts=system_prompts, out=AILLY_DIR_PATH
31+
)
32+
run(["npx", "@ailly/cli", "--root", AILLY_DIR])
33+
file_paths = get_ailly_files(AILLY_DIR_PATH)
34+
parse_json_files(file_paths=file_paths, out=IAM_UPDATES_PATH)
35+
update_doc_gen(doc_gen_root=doc_gen_root, iam_updates_path=IAM_UPDATES_PATH)
36+
37+
38+
if __name__ == "__main__":
39+
app()

0 commit comments

Comments
 (0)