replify/strchain: Fluent String Building & Indentation
Purpose
Replaces strings.Builder and manual string concatenation with strchain for readable, thread-safe, and strictly formatted string generation, especially for code, HTML, SQL, or configuration files. Responsibility boundary: edits string-building code within the named scope only; does NOT change generated output content or migrate unrelated string utilities.
When to Use / When NOT to Use
- Use: Generating multi-line text, code generation, SQL building, or HTML where indentation and layout matter.
- NOT: Simple single-line messages (use
fmt.Sprintf or strutil.Join).
- NOT: String validation, slugify or transformation helpers (use
replify-strutil).
Prerequisites & Assumptions
github.com/polarixa/replify/pkg/strchain imported.
Scope & Context Resolution
- Supported scopes: repository, package/directory, file, function/method. Default: the function or file the user names; if none, the string-building snippet under discussion.
- Rule 1 - Explicit context: user-stated requirements, constraints, versions, targets and scope are authoritative. Apply this skill strictly within them. MUST NOT add assumptions or expand beyond them. If a user instruction conflicts with a skill rule, follow the user and state the deviation in one line, EXCEPT security/data-loss rules, which stay mandatory (flag the conflict instead).
- Rule 2 - No extra context: use this skill's Purpose, workflow and rules as the sole context, at the default scope. MUST NOT import unrelated requirements or assumptions.
- Rule 3 - Explicit scope: operate ONLY inside the named scope. Out-of-scope files MAY be read as evidence but MUST NOT be modified; report out-of-scope observations as notes, never as changes. Widening scope requires explicit user approval.
- Mutation boundary: edits limited to string-building code inside the resolved scope; output text MUST stay byte-identical unless the user asks otherwise.
Step-by-Step Workflow
- Resolve scope and context: apply the section above; state the resolved scope and mutation boundary in one line at the start of the output.
- Initialize with
strchain.New() (single-goroutine) or strchain.NewSafe() (concurrent).
- Use
.Append(), .Line(), .LineF() for content addition.
- Use
.Indent(level, text) or .Spaces(n) for strict whitespace management.
- Call
.Build() or .Bytes() or .String() to finalize the output.
Enterprise Rules & Standards (MUST / SHOULD / MUST NOT)
- MUST: Eliminate all
strings.Builder in favor of strchain.Weaver interface (within the resolved scope).
- MUST: Never hardcode leading spaces or tabs in string literals; use
.Indent() or .Spaces() exclusively.
- MUST: Stay within the resolved scope; MUST NOT modify or expand beyond it without explicit user approval.
- SHOULD: Use
strchain.C(s) to transform existing strings fluently without creating a new weaver.
- MUST NOT: Use
s = s + "..." in loops or complex formatting logic.
- MUST NOT: Migrate
strings.Builder usages in files outside the named scope.
Examples (good vs. bad, with realistic code or output)
- Bad:
b.WriteString(" <div>\n") (Hardcoded indentation)
- Good:
weaver.IndentLine(1, "<div>") (Managed indentation)
- Good (scope): Prompt "migrate only
renderHTML in render.go" -> replace the builder in that function; list remaining strings.Builder usages as notes.
- Bad (scope): Same prompt -> removing
strings.Builder across the whole repository.
Checklist (verifiable, copy-pasteable)
Common Pitfalls
- Using the non-thread-safe
StringWeaver in concurrent HTTP handlers.
- Forgetting to call
.Build() or .String() to materialize the final string.
- Scope creep: migrating every
strings.Builder in the repo when one function was named.
References (official docs, standards)
1---2name: replify-strchain3description: 'Enforces fluent, chainable string building and indentation management using replify/pkg/strchain. Trigger: "use strchain", "string builder replify", "indentation management", "migrate strings.Builder".'4metadata:5 source: https://skillmd.com/skills/pnguyen215/replify-strchain6 category: ecosystem-replify7 tags: "replify, golang, strings, fluent-api, string-builder"8---910# replify/strchain: Fluent String Building & Indentation1112## Purpose1314Replaces `strings.Builder` and manual string concatenation with `strchain` for readable, thread-safe, and strictly formatted string generation, especially for code, HTML, SQL, or configuration files. Responsibility boundary: edits string-building code within the named scope only; does NOT change generated output content or migrate unrelated string utilities.1516## When to Use / When NOT to Use1718- **Use**: Generating multi-line text, code generation, SQL building, or HTML where indentation and layout matter.19- **NOT**: Simple single-line messages (use `fmt.Sprintf` or `strutil.Join`).20- **NOT**: String validation, slugify or transformation helpers (use `replify-strutil`).2122## Prerequisites & Assumptions2324- `github.com/polarixa/replify/pkg/strchain` imported.2526### Scope & Context Resolution2728- **Supported scopes**: repository, package/directory, file, function/method. Default: the function or file the user names; if none, the string-building snippet under discussion.29- **Rule 1 - Explicit context**: user-stated requirements, constraints, versions, targets and scope are authoritative. Apply this skill strictly within them. MUST NOT add assumptions or expand beyond them. If a user instruction conflicts with a skill rule, follow the user and state the deviation in one line, EXCEPT security/data-loss rules, which stay mandatory (flag the conflict instead).30- **Rule 2 - No extra context**: use this skill's Purpose, workflow and rules as the sole context, at the default scope. MUST NOT import unrelated requirements or assumptions.31- **Rule 3 - Explicit scope**: operate ONLY inside the named scope. Out-of-scope files MAY be read as evidence but MUST NOT be modified; report out-of-scope observations as notes, never as changes. Widening scope requires explicit user approval.32- **Mutation boundary**: edits limited to string-building code inside the resolved scope; output text MUST stay byte-identical unless the user asks otherwise.3334## Step-by-Step Workflow35361. **Resolve scope and context**: apply the section above; state the resolved scope and mutation boundary in one line at the start of the output.372. Initialize with `strchain.New()` (single-goroutine) or `strchain.NewSafe()` (concurrent).383. Use `.Append()`, `.Line()`, `.LineF()` for content addition.394. Use `.Indent(level, text)` or `.Spaces(n)` for strict whitespace management.405. Call `.Build()` or `.Bytes()` or `.String()` to finalize the output.4142## Enterprise Rules & Standards (MUST / SHOULD / MUST NOT)4344- **MUST**: Eliminate all `strings.Builder` in favor of `strchain.Weaver` interface (within the resolved scope).45- **MUST**: Never hardcode leading spaces or tabs in string literals; use `.Indent()` or `.Spaces()` exclusively.46- **MUST**: Stay within the resolved scope; MUST NOT modify or expand beyond it without explicit user approval.47- **SHOULD**: Use `strchain.C(s)` to transform existing strings fluently without creating a new weaver.48- **MUST NOT**: Use `s = s + "..."` in loops or complex formatting logic.49- **MUST NOT**: Migrate `strings.Builder` usages in files outside the named scope.5051## Examples (good vs. bad, with realistic code or output)5253- **Bad**: `b.WriteString(" <div>\n")` (Hardcoded indentation)54- **Good**: `weaver.IndentLine(1, "<div>")` (Managed indentation)55- **Good (scope)**: Prompt "migrate only `renderHTML` in `render.go`" -> replace the builder in that function; list remaining `strings.Builder` usages as notes.56- **Bad (scope)**: Same prompt -> removing `strings.Builder` across the whole repository.5758## Checklist (verifiable, copy-pasteable)5960- [ ] Scope and context resolved and stated.61- [ ] No changes outside the resolved scope.62- [ ] `strings.Builder` removed from the resolved scope.63- [ ] Hardcoded indentation replaced with `.Indent()` or `.Spaces()`.64- [ ] Thread-safe weaver (`NewSafe`) used if shared across goroutines.6566## Common Pitfalls6768- Using the non-thread-safe `StringWeaver` in concurrent HTTP handlers.69- Forgetting to call `.Build()` or `.String()` to materialize the final string.70- Scope creep: migrating every `strings.Builder` in the repo when one function was named.7172## References (official docs, standards)7374- `github.com/polarixa/replify/pkg/strchain` Migration Guide75- [strings.Builder (Go standard library)](https://pkg.go.dev/strings#Builder)