Community코딩 & 개발github.com

segment-change-guard

Safely inspect, compare, and review Flagsmith segment rule trees. Live updates and recovery remain blocked unless server-enforced conditional writes are verified.

segment-change-guard란 무엇인가요?

segment-change-guard is a Claude Code agent skill that safely inspect, compare, and review Flagsmith segment rule trees. Live updates and recovery remain blocked unless server-enforced conditional writes are verified.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/hollowlink123/segment-change-guard/tree/HEAD/skills/segment-change-guard

Installed? Explore more 코딩 & 개발 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

Segment Change Guard

Use this skill to inspect, compare, back up, and review Flagsmith segment rules. An ACCEPT is a human review decision; it must never trigger a live update.

Non-negotiable safety gates

Live segment-rule updates and recovery are BLOCKED. The server-enforced conditional update required by policy is not verified. Do not write, recover, or ask for execution approval. A backup, final re-read, local hash, confirmation, or delay does not close the read/write race.

Do not open, print, copy, or modify flagsmith.json. Never ask the user to paste or otherwise provide credentials, or ask them to read, inspect, print, reveal, or log credentials. Never access or expose credentials yourself, including by reading files, environment variables, or keychain contents. Do not run Flagsmith CLI/API commands without the user's explicit authorization for that task. Do not run login, config, auth-status, or token commands.

The read-only adapter's api_key parameter requires an explicit Flagsmith Admin API Master key. A trusted host may inject the key directly as an opaque value, without exposing it to the agent or conversation; do not request, retrieve, or inspect it. The adapter passes it only as FLAGSMITH_API_KEY in the child process environment (never in argv) and removes ambient Flagsmith settings. If trusted injection is unavailable, stop. This safeguard does not authorize live access.

Segments are project-level. A rule change may affect targeting in every environment, including Production; choosing Development does not isolate it. Do not infer an Environment Name condition or its effects: inspect the actual rule tree.

Local validation checks JSON-compatible values and basic rule structure only. It is not complete Flagsmith schema validation and does not prove service acceptance. No authoritative non-mutating validation method has been confirmed.

Never use --yes. A rejected or ambiguous review decision is not approval. Recovery always requires separate approval in any future eligible workflow.

Inputs and authorization

Before any authorized read-only retrieval, obtain the organisation ID, project ID, exact segment name, proposed rules file, intended impact, and whether Production could be affected. Use explicit numeric organisation/project IDs. The CLI accepts a segment ID or name, but the adapter requires the requested identifier to equal the returned name; use the exact name. The adapter returns the segment ID but does not bind it to a caller-supplied expected ID. The CLI response does not include a segment type; if target identity, type, or feature scope cannot be confirmed from authoritative authorized evidence, stop. Do not guess.

Do not access Flagsmith to fill missing inputs. Authorization to inspect does not authorize a write. A request to prepare a change is not approval to apply it.

Current CLI integration

The installed executable's embedded build metadata identifies Flagsmith CLI v2.0.0. Its matching official source and command references confirm:

  • segment get <segment> and inherited --organisation, --project, --config-path, --jq, --json, and --no-input options.
  • --jq implies JSON output. The adapter filters to id, name, feature, and the entire rules tree; it does not prune rule data. The CLI response shape does not include segment type.
  • --config-path= selects an empty config path in v2.0.0, bypassing project-file discovery. The adapter also uses a temporary working directory and temporary home/cache variables, with a restricted child environment.
  • FLAGSMITH_API_KEY is a supported Admin API credential environment variable. In v2.0.0 source it takes precedence over access-token and keychain credentials. The adapter strips other inherited FLAGSMITH_* variables, so it cannot silently use a saved login or flagsmith.json.
  • The adapter uses the CLI's default Flagsmith API URL. Custom/self-hosted API URLs are not supported by this interface; stop rather than inheriting an ambient URL.

These are source/documentation checks, not a live CLI/API test. Adapter tests mock the process. Re-check the installed version and version-matched documentation before future CLI changes; if behavior differs, stop. The read-only adapter does not prove server-side conditional-write protection.

References: segment get, root options, and versioned root source, segment source, auth source, context source.

Workflow

1. Inspect (authorized read-only only)

The host must provide Python 3.10+ and the actual Skill scripts/ directory. Import get_segment_response from that directory and call it with the requested segment, organisation ID, project ID, and a host-injected API key. Never substitute a guessed CLI command or parse a live response separately.

The adapter:

  • Runs flagsmith --organisation <id> --project <id> --config-path= segment get <segment> --jq '{id: .id, name: .name, feature: .feature, rules: .rules}' --json --no-input.
  • Requires non-empty IDs/name/key, avoids shell execution, has a timeout, suppresses raw process output from errors, and does not put the key in command arguments.
  • Returns the filtered metadata and the full root SegmentRule object. It rejects duplicate JSON keys, malformed rules, and a returned name that differs from the requested name.

This confirms neither segment type nor all target context. Stop if target identity or feature scope is ambiguous. Do not claim a live inspection unless the authorized command actually completed.

2. Back up

Before comparison, create a new local backup of the complete segment.rules root object, including $schema and nested rules. Use create_verified_json_backup from rule_backup.py with an absolute path whose parent already exists. It uses exclusive creation, reads the backup back, and checks JSON equivalence. Never overwrite or automatically delete a partial/unverified backup. On any failure, stop.

Compare from the verified backup, not from an unverified in-memory original. This is the CLI's root-rule representation, not a raw Flagsmith API rules array.

3. Compare

Read the proposal file once as bytes. Hash those exact bytes, parse the same bytes with load_json_no_duplicate_keys, validate the root object with validate_segment_rules, and retain the bytes unchanged. The proposal must use the same root SegmentRule representation as the adapter response.

Use compare_segment_rules(verified_original_root, proposed_root). It ignores $schema only on root/nested rule objects in deep copies; it preserves input values. The response is a root-rule summary, not per-rule findings, and returns changes, added/removed top-level conditions, changed fields, and condition-order status. A nested condition replacement appears as an old condition removed and a new one added; do not describe an inferred nested edit.

If imports, parsing, backup verification, or comparison fail, stop. Do not replace failed tooling with manual comparison or claim completion. Detailed local backup/comparison instructions are in references/local-review.md.

4. Explain the review

Separate confirmed local comparison facts from possible effects. State:

  • Whether the result is an offline fixture/local review or an authorized live read-only review; exact project/segment name; confirmed organisation/project IDs, segment ID, and feature ID only when the evidence establishes them. Do not invent a segment type.
  • has_changes; every added/removed condition; every changed top-level field with old/new values and presence on each side; and condition order. Say “None” for empty findings. If order changed, show both sequences.
  • Backup location and status. Say created and verified only after successful readback verification.
  • Any directly observed Environment Name condition, or that none was found in the inspected rules.
  • Possible consequences only. Segment rules are project-level and can affect Production; this comparison does not establish identities, counts, membership changes, or environment/Production impact.

For a completed review assign exactly one risk:

  • LOW: evidence is sufficient to conclude no meaningful targeting risk.
  • MEDIUM: a meaningful change exists but targeting consequences are uncertain or incompletely understood.
  • HIGH: understood rule semantics and findings support a potentially broader audience or weaker restriction.

Removing a condition alone does not prove broader targeting. Never assign LOW because evidence is missing. If review prerequisites fail, report BLOCKED and do not assign risk from incomplete findings. If review succeeds, report the risk separately from live-write status: BLOCKED.

5. Human review decision

After presenting a complete comparison, ask the user to ACCEPT or REJECT the proposal as a review decision. ACCEPT never performs, authorizes, or schedules a live update. Under the closed write gate, acknowledge the decision, state that no live change was made, and stop. A new proposal or changed fingerprint requires a fresh review.

Offline demo

Run scripts/demo_segment_change_guard.py with local fixtures to demonstrate local backup and comparison. It does not contact Flagsmith, establish live membership, or authorize a write. Do not describe the demo as a live inspection.

Future live operations

The live-write gate stays closed until authoritative, version-matched documentation/source verifies that the exact operation reads a resource version, submits that version as a write condition, checks it atomically server-side, rejects stale writes without applying them, documents exact request/response behavior, and the CLI/API operation actually uses it.

Do not apply, verify, or recover under the present status. If the gate is ever independently verified open, use the complete separate review, approval, apply, verification, and recovery protocol in references/future-write-protocol.md. The reference does not override the gate or authorize an operation.

관련 스킬