Skip to content

fix: add policy pull command#72

Merged
Mr-Lucky merged 1 commit into
mainfrom
fix/issue-71-policy-pull
May 18, 2026
Merged

fix: add policy pull command#72
Mr-Lucky merged 1 commit into
mainfrom
fix/issue-71-policy-pull

Conversation

@Mr-Lucky
Copy link
Copy Markdown
Contributor

Summary

Fixes #71.

This adds the missing agentguard policy pull command referenced by AgentGuard Cloud's runtime policy refresh instructions.

Changes

  • Add agentguard policy pull under the CLI policy command group.
  • Fetch the latest effective runtime policy from /api/v1/policies/effective.
  • Save the pulled policy to the configured local policy cache path.
  • Add --json output for automation-friendly usage.
  • Add a CLI regression test covering policy pull and cache writes.
  • Document the fix under Unreleased.

Type

  • [✅] Bug fix
  • New feature / detection rule
  • Refactoring
  • Documentation

Testing

  • [✅] npm run build passes
  • [✅] npm test passes (32 tests)
  • Manually tested the change

Related Issues

Closes #71

@github-actions
Copy link
Copy Markdown

AgentGuard PR Review

This patch adds a new policy pull command, but there are a couple of concrete issues that could break behavior or weaken security.

  1. medium — src/cli.ts (policy pull command): no validation of the fetched policy before caching

    • What can go wrong: The command writes whatever fetchEffectivePolicy() returns directly to the local cache. If the cloud endpoint is misconfigured, compromised, or returns malformed/malicious policy data, the CLI will persist it and downstream agents may apply unsafe rules.
    • Fix suggestion: Validate the response against the runtime policy schema before calling saveCachedPolicy(), and reject/exit non-zero on schema violations.
  2. medium — src/tests/cli-policy.test.ts: test only exercises the happy path and can miss build/runtime regressions in the new CLI flow

    • What can go wrong: The new command depends on dist/cli.js, but the test never verifies behavior when the cache path is unwritable, the cloud returns invalid JSON, or connected is false. A regression in those paths could ship unnoticed, including cases where the CLI exits success after a partial failure.
    • Fix suggestion: Add tests for failure cases: disconnected config, non-200 response, invalid policy payload, and unwritable cache path, asserting non-zero exit codes and that no cache file is written.

@Mr-Lucky Mr-Lucky merged commit a874e48 into main May 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

策略更新:执行agentguard policy pull 提示当前版本没有此命令

1 participant