Skip to content

Commit 0d17f10

Browse files
committed
generalize chinese_plan to alternative_plan_language with multi-language support
1 parent 0d26581 commit 0d17f10

File tree

2 files changed

+75
-38
lines changed

2 files changed

+75
-38
lines changed

commands/gen-plan.md

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ This command MUST ONLY generate a plan document during the planning phases. It M
2424

2525
Permitted writes (before any optional auto-start) are limited to:
2626
- The plan output file (`--output`)
27-
- Optional `_zh` translated plan (only when `CHINESE_PLAN_ENABLED=true`)
27+
- Optional translated language variant (only when `ALT_PLAN_LANGUAGE` is configured)
28+
- `.humanize/config.json` (created with defaults only when the file does not already exist)
2829

2930
If `--auto-start-rlcr-if-converged` is enabled, the command MAY immediately start the RLCR loop by running `/humanize:start-rlcr-loop <output-plan-path>`, but only in `discussion` mode when `PLAN_CONVERGENCE_STATUS=converged` and there are no pending user decisions. All coding happens in that subsequent command/loop, not during plan generation.
3031

@@ -35,15 +36,15 @@ This command transforms a user's draft document into a well-structured implement
3536
> **Sequential Execution Constraint**: All phases below MUST execute strictly in order. Do NOT parallelize tool calls across different phases. Each phase must fully complete before the next one begins.
3637
3738
1. **Execution Mode Setup**: Parse optional behaviors from command arguments
38-
2. **Load Project Config**: Read `.humanize/config.json` and extract `chinese_plan` flag
39+
2. **Load Project Config**: Read `.humanize/config.json` and extract `alternative_plan_language` setting
3940
3. **IO Validation**: Validate input and output paths
4041
4. **Relevance Check**: Verify draft is relevant to the repository
4142
5. **Codex First-Pass Analysis**: Use one planning Codex before Claude synthesizes plan details
4243
6. **Claude Candidate Plan (v1)**: Claude builds an initial plan from draft + Codex findings
4344
7. **Iterative Convergence Loop**: Claude and a second Codex iteratively challenge/refine plan reasonability
4445
8. **Issue and Disagreement Resolution**: Resolve unresolved opposite opinions (or skip manual review if converged, auto-start mode is enabled, and `GEN_PLAN_MODE=discussion`)
4546
9. **Final Plan Generation**: Generate the converged structured plan.md with task routing tags
46-
10. **Write and Complete**: Write output file, optionally write `_zh` Chinese variant, optionally auto-start implementation, and report results
47+
10. **Write and Complete**: Write output file, optionally write translated language variant, optionally auto-start implementation, and report results
4748

4849
---
4950

@@ -65,20 +66,54 @@ Parse `$ARGUMENTS` and set:
6566
After setting execution mode flags, load the project-level configuration:
6667

6768
1. Attempt to read `.humanize/config.json` from the project root (the repository root where the command was invoked).
68-
2. If the file does not exist, treat all config fields as absent. This is NOT an error; continue normally.
69-
3. If the file exists, parse it as JSON and extract the `chinese_plan` field:
70-
- If `chinese_plan` is `true` (boolean), set `CHINESE_PLAN_ENABLED=true`.
71-
- Otherwise (field absent, `false`, or any non-true value), set `CHINESE_PLAN_ENABLED=false`.
72-
4. Also extract the `gen_plan_mode` field from the same config:
69+
2. If the file does not exist:
70+
- Create the `.humanize/` directory if it does not already exist.
71+
- Write a default `.humanize/config.json` with the following content:
72+
```json
73+
{
74+
"alternative_plan_language": "",
75+
"gen_plan_mode": "discussion"
76+
}
77+
```
78+
- Log: `No .humanize/config.json found. Created default config at .humanize/config.json`
79+
- If directory creation or file write fails, log a warning and continue with defaults (do not block execution).
80+
- Continue with the default values (`ALT_PLAN_LANGUAGE=""`, `ALT_PLAN_LANG_CODE=""`, `GEN_PLAN_MODE=discussion`).
81+
3. If the file exists, parse it as JSON and resolve `alternative_plan_language`:
82+
- **If `alternative_plan_language` is present** (even if empty string), use its value. If deprecated `chinese_plan` field is also present, log: `Warning: deprecated "chinese_plan" field ignored; "alternative_plan_language" takes precedence. Remove "chinese_plan" from .humanize/config.json.`
83+
- **If `alternative_plan_language` is absent but `chinese_plan` is present** (backward compatibility):
84+
- If `chinese_plan` is `true` (boolean), treat as `alternative_plan_language="Chinese"`. Log: `Warning: deprecated "chinese_plan" field detected. Replace with "alternative_plan_language": "Chinese" in .humanize/config.json.`
85+
- Otherwise (`false`, absent, or any non-true value), treat as `alternative_plan_language=""` (disabled).
86+
- **If neither field is present**, set `alternative_plan_language=""` (disabled).
87+
4. Resolve `ALT_PLAN_LANGUAGE` and `ALT_PLAN_LANG_CODE` from the effective `alternative_plan_language` value using the built-in mapping table below. Matching is **case-insensitive**.
88+
89+
| Language | Code | Suffix |
90+
|------------|------|--------|
91+
| Chinese | zh | `_zh` |
92+
| Korean | ko | `_ko` |
93+
| Japanese | ja | `_ja` |
94+
| Spanish | es | `_es` |
95+
| French | fr | `_fr` |
96+
| German | de | `_de` |
97+
| Portuguese | pt | `_pt` |
98+
| Russian | ru | `_ru` |
99+
| Arabic | ar | `_ar` |
100+
101+
Matching accepts both the language name (e.g. `"Chinese"`) and the ISO 639-1 code (e.g. `"zh"`), both case-insensitive. Non-string JSON values are treated as absent. Leading/trailing whitespace is trimmed before matching.
102+
103+
- If the value is empty or absent: set `ALT_PLAN_LANGUAGE=""` and `ALT_PLAN_LANG_CODE=""` (disabled).
104+
- If the value is `"English"` or `"en"` (case-insensitive): set `ALT_PLAN_LANGUAGE=""` and `ALT_PLAN_LANG_CODE=""` (no-op; the plan is already in English).
105+
- If the value matches a language name or code in the table: set `ALT_PLAN_LANGUAGE` to the matched language name and `ALT_PLAN_LANG_CODE` to the corresponding code.
106+
- If the value does NOT match any language name or code in the table: set `ALT_PLAN_LANGUAGE=""` and `ALT_PLAN_LANG_CODE=""` (disabled). Log: `Warning: unsupported alternative_plan_language "<value>". Supported values: Chinese (zh), Korean (ko), Japanese (ja), Spanish (es), French (fr), German (de), Portuguese (pt), Russian (ru), Arabic (ar). Translation variant will not be generated.`
107+
5. Also extract the `gen_plan_mode` field from the same config:
73108
- Valid values: `"discussion"` or `"direct"` (case-insensitive).
74109
- Invalid or absent values: treat as absent (fall back to default) and log a warning if the value is present but invalid.
75-
5. Resolve `GEN_PLAN_MODE` using the following priority (highest to lowest), with CLI flags taking priority over project config:
110+
6. Resolve `GEN_PLAN_MODE` using the following priority (highest to lowest), with CLI flags taking priority over project config:
76111
- CLI flag: if `GEN_PLAN_MODE_DISCUSSION=true`, set `GEN_PLAN_MODE=discussion`; if `GEN_PLAN_MODE_DIRECT=true`, set `GEN_PLAN_MODE=direct`
77112
- Config file `gen_plan_mode` field (if valid)
78113
- Default: `discussion`
79-
6. A malformed JSON file should be reported as a warning but must NOT stop execution; fall back to `CHINESE_PLAN_ENABLED=false` and `GEN_PLAN_MODE=discussion`.
114+
7. A malformed JSON file should be reported as a warning but must NOT stop execution; fall back to `ALT_PLAN_LANGUAGE=""`, `ALT_PLAN_LANG_CODE=""`, and `GEN_PLAN_MODE=discussion`.
80115

81-
`CHINESE_PLAN_ENABLED` controls whether a `_zh` Chinese variant of the output file is written in Phase 8.
116+
`ALT_PLAN_LANGUAGE` and `ALT_PLAN_LANG_CODE` control whether a translated language variant of the output file is written in Phase 8. When `ALT_PLAN_LANGUAGE` is non-empty, a variant file with the `_<ALT_PLAN_LANG_CODE>` suffix is generated.
82117

83118
---
84119

@@ -432,17 +467,17 @@ Each task must include exactly one routing tag:
432467
433468
This template is used to produce the main output file (e.g., `plan.md`).
434469
435-
### Chinese Variant (`_zh` file)
470+
### Translated Language Variant
436471
437-
When `chinese_plan=true` is set in `.humanize/config.json`, a `_zh` variant of the output file is also written after the main file. The `_zh` filename is constructed by inserting `_zh` immediately before the file extension:
472+
When `alternative_plan_language` is set to a supported language name in `.humanize/config.json`, a translated variant of the output file is also written after the main file. The variant filename is constructed by inserting `_<code>` (the ISO 639-1 code from the built-in mapping table) immediately before the file extension:
438473
439-
- `plan.md` becomes `plan_zh.md`
440-
- `docs/my-plan.md` becomes `docs/my-plan_zh.md`
441-
- `output` (no extension) becomes `output_zh`
474+
- `plan.md` becomes `plan_<code>.md` (e.g. `plan_zh.md` for Chinese, `plan_ko.md` for Korean)
475+
- `docs/my-plan.md` becomes `docs/my-plan_<code>.md`
476+
- `output` (no extension) becomes `output_<code>`
442477
443-
The `_zh` file contains a full Chinese translation of the English plan. All identifiers (`AC-*`, task IDs, file paths, API names, command flags) remain unchanged, as they are language-neutral.
478+
The translated variant file contains a full translation of the main plan file's current content in the configured language. All identifiers (`AC-*`, task IDs, file paths, API names, command flags) remain unchanged, as they are language-neutral.
444479
445-
When `chinese_plan=false` (the default), or when `.humanize/config.json` does not exist, or when the `chinese_plan` field is absent, the `_zh` file is NOT written. A missing config file is not an error.
480+
When `alternative_plan_language` is empty, absent, set to `"English"`, or set to an unsupported language, no translated variant is written. If `.humanize/config.json` does not exist at startup, a default config with `alternative_plan_language=""` is created automatically.
446481
```
447482
448483
### Generation Rules
@@ -513,28 +548,30 @@ If multiple languages are detected:
513548
- Use the Edit tool to apply the translations
514549
3. If the user declines, leave the document as-is
515550
516-
### Step 4: Write Chinese Variant (Conditional)
551+
### Step 4: Write Translated Language Variant (Conditional)
552+
553+
If `ALT_PLAN_LANGUAGE` is non-empty (translation enabled), write a translated variant of the output file.
517554
518-
If `CHINESE_PLAN_ENABLED=true`, write a `_zh` variant of the output file containing a full Chinese translation of the English plan:
555+
**Language Unification guard**: If the main plan file was unified to `ALT_PLAN_LANGUAGE` in Step 3 (Language Unification), skip this step. Log: `Main plan file is already in <ALT_PLAN_LANGUAGE>; translated variant not needed.`
519556
520-
**Filename construction rule** - insert `_zh` immediately before the file extension:
521-
- `plan.md` becomes `plan_zh.md`
522-
- `docs/my-plan.md` becomes `docs/my-plan_zh.md`
523-
- `output` (no extension) becomes `output_zh`
557+
**Filename construction rule** - insert `_<ALT_PLAN_LANG_CODE>` immediately before the file extension:
558+
- `plan.md` becomes `plan_<code>.md` (e.g. `plan_zh.md`, `plan_ko.md`)
559+
- `docs/my-plan.md` becomes `docs/my-plan_<code>.md`
560+
- `output` (no extension) becomes `output_<code>`
524561
525562
Algorithm:
526563
1. Find the last `.` in the base filename.
527-
2. If a `.` is found, insert `_zh` before it: `<stem>_zh.<extension>`.
528-
3. If no `.` is found (no extension), append `_zh` to the filename: `<filename>_zh`.
529-
4. The `_zh` file is placed in the same directory as the main output file.
564+
2. If a `.` is found, insert `_<ALT_PLAN_LANG_CODE>` before it: `<stem>_<code>.<extension>`.
565+
3. If no `.` is found (no extension), append `_<ALT_PLAN_LANG_CODE>` to the filename: `<filename>_<code>`.
566+
4. The variant file is placed in the same directory as the main output file.
530567
531-
**Content of the `_zh` file**:
532-
- Translate the English plan content into Simplified Chinese.
568+
**Content of the variant file**:
569+
- Translate the main plan file's current content (after any Language Unification from Step 3) into `ALT_PLAN_LANGUAGE`. For Chinese, default to Simplified Chinese.
533570
- Section headings, AC labels, task IDs, file paths, API names, and command flags MUST remain unchanged (identifiers are language-neutral).
534-
- The `_zh` file is a Chinese reading view of the same plan; it must not add new information not present in the main file.
571+
- The variant file is a translated reading view of the same plan; it must not add new information not present in the main file.
535572
- The original draft section at the bottom should be kept as-is (not re-translated).
536573
537-
If `CHINESE_PLAN_ENABLED=false` (the default), do NOT create the `_zh` file. The absence of `.humanize/config.json` or the absence of the `chinese_plan` field both imply `CHINESE_PLAN_ENABLED=false`; no error is raised.
574+
If `ALT_PLAN_LANGUAGE` is empty (the default), do NOT create a translated variant file.
538575
539576
### Step 5: Optional Direct Work Start
540577

prompt-template/plan/gen-plan-template.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ Each task must include exactly one routing tag:
107107

108108
This template is used to produce the main output file (e.g., `plan.md`).
109109

110-
### Chinese Variant (`_zh` file)
110+
### Translated Language Variant
111111

112-
When `chinese_plan=true` is set in `.humanize/config.json`, a `_zh` variant of the output file is also written after the main file. The `_zh` filename is constructed by inserting `_zh` immediately before the file extension:
112+
When `alternative_plan_language` is set to a supported language name in `.humanize/config.json`, a translated variant of the output file is also written after the main file. The variant filename is constructed by inserting `_<code>` (the ISO 639-1 code from the built-in mapping table) immediately before the file extension:
113113

114-
- `plan.md` becomes `plan_zh.md`
115-
- `docs/my-plan.md` becomes `docs/my-plan_zh.md`
116-
- `output` (no extension) becomes `output_zh`
114+
- `plan.md` becomes `plan_<code>.md` (e.g. `plan_zh.md` for Chinese, `plan_ko.md` for Korean)
115+
- `docs/my-plan.md` becomes `docs/my-plan_<code>.md`
116+
- `output` (no extension) becomes `output_<code>`
117117

118-
The `_zh` file contains a full Chinese translation of the English plan. All identifiers (`AC-*`, task IDs, file paths, API names, command flags) remain unchanged, as they are language-neutral.
118+
The translated variant file contains a full translation of the main plan file's current content in the configured language. All identifiers (`AC-*`, task IDs, file paths, API names, command flags) remain unchanged, as they are language-neutral.
119119

120-
When `chinese_plan=false` (the default), or when `.humanize/config.json` does not exist, or when the `chinese_plan` field is absent, the `_zh` file is NOT written. A missing config file is not an error.
120+
When `alternative_plan_language` is empty, absent, set to `"English"`, or set to an unsupported language, no translated variant is written. If `.humanize/config.json` does not exist at startup, a default config with `alternative_plan_language=""` is created automatically.

0 commit comments

Comments
 (0)