ai-policy-pack-cli 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,7 +26,7 @@ npx ai-policy-pack-cli install --targets cursor,copilot,antigravity,claude --yes
26
26
  ### Install
27
27
 
28
28
  ```bash
29
- npx ai-policy-pack-cli install [--targets cursor,copilot,antigravity,claude] [--preset karpathy] [--yes] [--dry-run]
29
+ npx ai-policy-pack-cli install [--targets cursor,copilot,antigravity,claude] [--preset anhtdq] [--yes] [--dry-run]
30
30
  ```
31
31
 
32
32
  - Generates target files from preset
@@ -45,7 +45,7 @@ npx ai-policy-pack-cli verify
45
45
  ### Update
46
46
 
47
47
  ```bash
48
- npx ai-policy-pack-cli update [--preset karpathy] [--yes] [--dry-run]
48
+ npx ai-policy-pack-cli update [--preset anhtdq] [--yes] [--dry-run]
49
49
  ```
50
50
 
51
51
  - Re-applies current targets from manifest
@@ -55,7 +55,7 @@ npx ai-policy-pack-cli update [--preset karpathy] [--yes] [--dry-run]
55
55
 
56
56
  Current default preset:
57
57
 
58
- - `presets/karpathy/policy.yml`
58
+ - `presets/anhtdq/policy.yml`
59
59
 
60
60
  Preset layout:
61
61
 
package/dist/src/cli.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { promises as fs } from "node:fs";
3
3
  import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
4
5
  import { parseArgs } from "./core/args.js";
5
6
  import { logger } from "./core/logger.js";
6
7
  import { CliError } from "./core/errors.js";
@@ -9,17 +10,18 @@ import { runVerifyCommand } from "./commands/verify.js";
9
10
  import { runUpdateCommand } from "./commands/update.js";
10
11
  async function main() {
11
12
  const cwd = process.cwd();
12
- const packageVersion = await readPackageVersion(cwd);
13
+ const packageRoot = resolvePackageRoot();
14
+ const packageVersion = await readPackageVersion(packageRoot);
13
15
  const args = parseArgs(process.argv.slice(2));
14
16
  switch (args.command) {
15
17
  case "install":
16
- await runInstallCommand(args, { cwd, packageVersion, logger });
18
+ await runInstallCommand(args, { cwd, packageRoot, packageVersion, logger });
17
19
  return;
18
20
  case "verify":
19
- await runVerifyCommand(args, { cwd, logger });
21
+ await runVerifyCommand(args, { cwd, packageRoot, logger });
20
22
  return;
21
23
  case "update":
22
- await runUpdateCommand(args, { cwd, packageVersion, logger });
24
+ await runUpdateCommand(args, { cwd, packageRoot, packageVersion, logger });
23
25
  return;
24
26
  default:
25
27
  throw new CliError(`Unsupported command: ${String(args.command)}`);
@@ -30,6 +32,10 @@ async function readPackageVersion(cwd) {
30
32
  const parsed = JSON.parse(await fs.readFile(packagePath, "utf8"));
31
33
  return parsed.version ?? "0.0.0";
32
34
  }
35
+ function resolvePackageRoot() {
36
+ const currentFile = fileURLToPath(import.meta.url);
37
+ return path.resolve(path.dirname(currentFile), "..", "..");
38
+ }
33
39
  main().catch((error) => {
34
40
  if (error instanceof CliError) {
35
41
  logger.error(error.message);
@@ -6,8 +6,8 @@ import { renderForTargets } from "../core/render.js";
6
6
  import { CliError } from "../core/errors.js";
7
7
  export async function runInstallCommand(args, deps) {
8
8
  const targets = await resolveTargets(args);
9
- const presetName = args.preset ?? "karpathy";
10
- const policy = await loadPolicyPreset(deps.cwd, presetName);
9
+ const presetName = args.preset ?? "anhtdq";
10
+ const policy = await loadPolicyPreset(deps.cwd, presetName, deps.packageRoot);
11
11
  const files = renderForTargets(policy, targets);
12
12
  deps.logger.info(`Preset: ${policy.name}`);
13
13
  deps.logger.info(`Targets: ${targets.join(", ")}`);
@@ -10,7 +10,7 @@ export async function runUpdateCommand(args, deps) {
10
10
  throw new CliError("Manifest not found. Run install first.");
11
11
  }
12
12
  const presetName = args.preset || manifest.preset;
13
- const preset = await loadPolicyPreset(deps.cwd, presetName);
13
+ const preset = await loadPolicyPreset(deps.cwd, presetName, deps.packageRoot);
14
14
  const files = renderForTargets(preset, manifest.targets);
15
15
  deps.logger.info(`Updating preset: ${preset.name}`);
16
16
  for (const file of files) {
@@ -9,7 +9,7 @@ export async function runVerifyCommand(args, deps) {
9
9
  if (!manifest) {
10
10
  throw new CliError("Manifest not found. Run install first.");
11
11
  }
12
- const preset = await loadPolicyPreset(deps.cwd, manifest.preset);
12
+ const preset = await loadPolicyPreset(deps.cwd, manifest.preset, deps.packageRoot);
13
13
  const rendered = renderForTargets(preset, manifest.targets);
14
14
  const renderedMap = new Map(rendered.map((file) => [file.path, file.content]));
15
15
  const mismatches = [];
@@ -2,9 +2,28 @@ import path from "node:path";
2
2
  import { promises as fs } from "node:fs";
3
3
  import yaml from "js-yaml";
4
4
  import { validatePolicyPreset } from "./policy-schema.js";
5
- export async function loadPolicyPreset(cwd, presetName) {
6
- const presetPath = path.join(cwd, "presets", presetName, "policy.yml");
7
- const raw = await fs.readFile(presetPath, "utf8");
8
- const parsed = yaml.load(raw);
5
+ import { CliError } from "./errors.js";
6
+ export async function loadPolicyPreset(projectCwd, presetName, packageRoot) {
7
+ const projectPresetPath = path.join(projectCwd, "presets", presetName, "policy.yml");
8
+ const packagePresetPath = path.join(packageRoot, "presets", presetName, "policy.yml");
9
+ const source = await readFirstExisting([projectPresetPath, packagePresetPath]);
10
+ if (!source) {
11
+ throw new CliError(`Preset '${presetName}' not found. Checked: ${projectPresetPath} and ${packagePresetPath}`);
12
+ }
13
+ const parsed = yaml.load(source);
9
14
  return validatePolicyPreset(parsed);
10
15
  }
16
+ async function readFirstExisting(paths) {
17
+ for (const filePath of paths) {
18
+ try {
19
+ return await fs.readFile(filePath, "utf8");
20
+ }
21
+ catch (error) {
22
+ if (error.code === "ENOENT") {
23
+ continue;
24
+ }
25
+ throw error;
26
+ }
27
+ }
28
+ return undefined;
29
+ }
@@ -4,7 +4,7 @@ import { renderForTargets } from "../src/core/render.js";
4
4
  const CWD = "d:/ATS/Project/AI/rulecusor";
5
5
  describe("adapters render", () => {
6
6
  it("renders target-specific files", async () => {
7
- const policy = await loadPolicyPreset(CWD, "karpathy");
7
+ const policy = await loadPolicyPreset(CWD, "anhtdq", CWD);
8
8
  const files = renderForTargets(policy, ["cursor", "copilot", "antigravity", "claude"]);
9
9
  const paths = files.map((item) => item.path).sort();
10
10
  expect(paths).toContain(".cursor/rules/global-policy.mdc");
@@ -8,7 +8,7 @@ describe("parseArgs", () => {
8
8
  "--targets",
9
9
  "cursor,copilot",
10
10
  "--preset",
11
- "karpathy",
11
+ "anhtdq",
12
12
  "--yes",
13
13
  "--dry-run",
14
14
  "--force"
@@ -16,7 +16,7 @@ describe("parseArgs", () => {
16
16
  expect(parsed).toEqual({
17
17
  command: "install",
18
18
  targets: ["cursor", "copilot"],
19
- preset: "karpathy",
19
+ preset: "anhtdq",
20
20
  yes: true,
21
21
  dryRun: true,
22
22
  force: true
@@ -18,25 +18,30 @@ describe("install -> verify -> drift -> update flow", () => {
18
18
  await copyFixtureSourceToWorkspace(root, workspace);
19
19
  await runInstallCommand(parseArgs(["install", "--targets", "cursor,copilot,antigravity,claude", "--yes"]), {
20
20
  cwd: workspace,
21
+ packageRoot: workspace,
21
22
  packageVersion: "0.1.0",
22
23
  logger: silentLogger
23
24
  });
24
25
  await runVerifyCommand(parseArgs(["verify"]), {
25
26
  cwd: workspace,
27
+ packageRoot: workspace,
26
28
  logger: silentLogger
27
29
  });
28
30
  await fs.appendFile(path.join(workspace, "AGENTS.md"), "\nmanual drift\n", "utf8");
29
31
  await expect(runVerifyCommand(parseArgs(["verify"]), {
30
32
  cwd: workspace,
33
+ packageRoot: workspace,
31
34
  logger: silentLogger
32
35
  })).rejects.toThrow();
33
36
  await runUpdateCommand(parseArgs(["update", "--yes"]), {
34
37
  cwd: workspace,
38
+ packageRoot: workspace,
35
39
  packageVersion: "0.1.1",
36
40
  logger: silentLogger
37
41
  });
38
42
  await runVerifyCommand(parseArgs(["verify"]), {
39
43
  cwd: workspace,
44
+ packageRoot: workspace,
40
45
  logger: silentLogger
41
46
  });
42
47
  });
@@ -0,0 +1,29 @@
1
+ import path from "node:path";
2
+ import { promises as fs } from "node:fs";
3
+ import { describe, expect, it } from "vitest";
4
+ import { runInstallCommand } from "../src/commands/install.js";
5
+ import { parseArgs } from "../src/core/args.js";
6
+ import { createTempWorkspace, copyFixtureSourceToWorkspace } from "./helpers.js";
7
+ const silentLogger = {
8
+ info: (_message) => undefined,
9
+ warn: (_message) => undefined,
10
+ error: (_message) => undefined
11
+ };
12
+ describe("runtime path behavior", () => {
13
+ it("installs into workspace without local package.json or presets", async () => {
14
+ const sourceRoot = "d:/ATS/Project/AI/rulecusor";
15
+ const packageRoot = await createTempWorkspace("policy-pack-runtime");
16
+ const projectWorkspace = await createTempWorkspace("policy-pack-project");
17
+ // Simulate npm package root with presets available.
18
+ await copyFixtureSourceToWorkspace(sourceRoot, packageRoot);
19
+ await fs.rm(path.join(projectWorkspace, "presets"), { recursive: true, force: true });
20
+ await fs.rm(path.join(projectWorkspace, "package.json"), { force: true });
21
+ await runInstallCommand(parseArgs(["install", "--targets", "cursor", "--yes"]), {
22
+ cwd: projectWorkspace,
23
+ packageRoot,
24
+ packageVersion: "0.1.0",
25
+ logger: silentLogger
26
+ });
27
+ await expect(fs.readFile(path.join(projectWorkspace, ".cursor/rules/global-policy.mdc"), "utf8")).resolves.toContain("Team Global Rules");
28
+ });
29
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-policy-pack-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Multi-IDE AI policy pack generator for Cursor, Copilot, Antigravity, and Claude",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,38 @@
1
+ name: anhtdq
2
+ description: Behavioral guardrails to reduce common LLM coding mistakes across all code
3
+ globalRules:
4
+ - Before implementing, state assumptions explicitly. If uncertain, ask instead of guessing.
5
+ - If multiple interpretations exist, surface them and confirm direction before coding.
6
+ - If a simpler approach exists, recommend it and explain the tradeoff.
7
+ - If requirements are unclear or contradictory, stop and ask a focused clarification question.
8
+ - Implement the minimum code that solves the requested problem.
9
+ - Do not add speculative features or future-proof abstractions unless explicitly requested.
10
+ - Do not add configurability that is not required by the task.
11
+ - Do not add error handling for impossible scenarios.
12
+ - If implementation feels overcomplicated, simplify until it is easy to reason about.
13
+ - Touch only lines required by the requested change.
14
+ - Do not refactor unrelated modules or formatting during focused tasks.
15
+ - Match existing project patterns and style unless user asks to change conventions.
16
+ - If unrelated dead code is discovered, mention it but do not delete it automatically.
17
+ - Remove only orphaned code introduced by your own change.
18
+ - Define clear success criteria before implementation.
19
+ - Convert requests into verifiable goals with checks or tests.
20
+ - For bug fixes, reproduce with a failing test/check first, then fix, then verify pass.
21
+ - For refactors, verify behavior before and after with stable checks.
22
+ - For multi-step work, provide a short step plan with explicit verification at each step.
23
+ - Do not claim completion until verification actually passes.
24
+ fileRules:
25
+ - name: universal-code-rules
26
+ patterns:
27
+ - "**/*"
28
+ rules:
29
+ - Apply these standards to all code and configuration files unless the user explicitly narrows scope.
30
+ - Prefer readable, straightforward code and avoid hidden magic.
31
+ - Keep changes cohesive, easy to review, and directly traceable to the request.
32
+ targetOverrides:
33
+ antigravity:
34
+ geminiRules:
35
+ - Keep AGENTS.md as shared cross-tool policy and use GEMINI.md only for Antigravity-specific overrides.
36
+ copilot:
37
+ repoIntro:
38
+ - Follow repository build, test, and lint commands from project documentation before submitting changes.
@@ -1,30 +0,0 @@
1
- name: karpathy
2
- description: Karpathy-inspired guardrails adapted for multi-IDE agents
3
- globalRules:
4
- - State assumptions and ask clarifying questions before coding when requirements are ambiguous.
5
- - Prefer the simplest implementation that solves the user's request; avoid speculative abstractions.
6
- - Keep changes surgical and scoped to the requested task; avoid unrelated refactors.
7
- - Define explicit success criteria and verify changes with tests or commands before claiming completion.
8
- - Remove dead code created by your own change but do not clean unrelated legacy code unless asked.
9
- fileRules:
10
- - name: typescript-standards
11
- patterns:
12
- - "**/*.ts"
13
- - "**/*.tsx"
14
- rules:
15
- - Favor strict typing and avoid any unless there is a documented reason.
16
- - Keep functions focused and small; split logic when a function mixes responsibilities.
17
- - Add concise comments only when code intent is not obvious.
18
- - name: python-standards
19
- patterns:
20
- - "**/*.py"
21
- rules:
22
- - Prefer explicit names over abbreviations and keep functions single-purpose.
23
- - Handle expected exceptions explicitly and include actionable error messages.
24
- targetOverrides:
25
- antigravity:
26
- geminiRules:
27
- - Use GEMINI.md for tool-specific overrides and AGENTS.md for shared team policy.
28
- copilot:
29
- repoIntro:
30
- - Follow repository build, test, and lint commands from project docs before submitting changes.