@hasna/instructions 0.6.0 → 0.7.0
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 +149 -8
- package/dist/chunks/apply-7svah2qm.js +25 -0
- package/dist/chunks/apply-jp13sa1e.js +25 -0
- package/dist/chunks/database-wstmr56z.js +23 -0
- package/dist/chunks/index-1cnyjnd7.js +623 -0
- package/dist/chunks/index-35z65jsa.js +198 -0
- package/dist/chunks/index-3djthcm6.js +117 -0
- package/dist/chunks/index-4pfq42t5.js +7300 -0
- package/dist/chunks/index-5d7zdftc.js +186 -0
- package/dist/chunks/index-7m4j8a33.js +12578 -0
- package/dist/chunks/index-8rb7ng2y.js +148 -0
- package/dist/chunks/index-arrrx0ed.js +344 -0
- package/dist/chunks/index-bsan4c16.js +48 -0
- package/dist/chunks/index-bzyxvwcd.js +625 -0
- package/dist/chunks/index-fpeyzn3n.js +186 -0
- package/dist/chunks/index-fwbs6tma.js +534 -0
- package/dist/chunks/index-ma2xmp6c.js +14 -0
- package/dist/chunks/index-n3fjspr0.js +119 -0
- package/dist/chunks/index-nnwp92tk.js +19 -0
- package/dist/chunks/index-z3ma4aqk.js +532 -0
- package/dist/chunks/legacy-store-migration-z2m5yzyk.js +322 -0
- package/dist/chunks/local-5wvv5xv3.js +694 -0
- package/dist/chunks/local-zxa5dpf4.js +518 -0
- package/dist/chunks/package-manager-guard-x70xrwk2.js +391 -0
- package/dist/chunks/redact-hnq4sc4r.js +16 -0
- package/dist/chunks/s3-backup-n2z4fwyh.js +240 -0
- package/dist/chunks/s3-config-hhght91k.js +14 -0
- package/dist/chunks/s3-object-store-90tgbh6k.js +14 -0
- package/dist/chunks/sync-2075deve.js +34 -0
- package/dist/chunks/sync-r8t7zsp3.js +34 -0
- package/dist/chunks/template-fsfxpe4p.js +16 -0
- package/dist/chunks/template-wgnzdn7h.js +16 -0
- package/dist/cli/index.js +1681 -15643
- package/dist/data/config-store.d.ts +2 -1
- package/dist/data/config-store.d.ts.map +1 -1
- package/dist/db/database.d.ts +3 -5
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/local.d.ts +38 -0
- package/dist/db/local.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13809 -12998
- package/dist/lib/apply.d.ts +7 -0
- package/dist/lib/apply.d.ts.map +1 -1
- package/dist/lib/compact-output.d.ts +1 -0
- package/dist/lib/compact-output.d.ts.map +1 -1
- package/dist/lib/export.d.ts +22 -3
- package/dist/lib/export.d.ts.map +1 -1
- package/dist/lib/ids.d.ts +4 -0
- package/dist/lib/ids.d.ts.map +1 -0
- package/dist/lib/import.d.ts +18 -0
- package/dist/lib/import.d.ts.map +1 -1
- package/dist/lib/instruction-graph.d.ts.map +1 -1
- package/dist/lib/legacy-store-migration.d.ts +39 -0
- package/dist/lib/legacy-store-migration.d.ts.map +1 -0
- package/dist/lib/managed-skill-runtimes.d.ts +1 -0
- package/dist/lib/managed-skill-runtimes.d.ts.map +1 -1
- package/dist/lib/session-render.d.ts +3 -0
- package/dist/lib/session-render.d.ts.map +1 -1
- package/dist/lib/sync-dir.d.ts.map +1 -1
- package/dist/mcp/index.js +73 -9462
- package/dist/sdk/index.d.ts +2 -0
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +205 -10
- package/dist/sdk/resolve.d.ts +1 -1
- package/dist/sdk/resolve.d.ts.map +1 -1
- package/dist/sdk/v1-client.d.ts +57 -0
- package/dist/sdk/v1-client.d.ts.map +1 -0
- package/dist/sdk/v1.generated.d.ts +212 -21
- package/dist/sdk/v1.generated.d.ts.map +1 -1
- package/dist/server/cloud.d.ts.map +1 -1
- package/dist/server/index.d.ts +13 -5
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +8337 -7495
- package/dist/server/openapi.d.ts +1264 -92
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/v1.d.ts +25 -1
- package/dist/server/v1.d.ts.map +1 -1
- package/dist/status.d.ts +12 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/storage/cloud-store.d.ts +57 -1
- package/dist/storage/cloud-store.d.ts.map +1 -1
- package/dist/storage/index.d.ts +7 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +725 -0
- package/dist/storage/s3-backup.d.ts +76 -0
- package/dist/storage/s3-backup.d.ts.map +1 -0
- package/dist/storage/s3-config.d.ts +46 -0
- package/dist/storage/s3-config.d.ts.map +1 -0
- package/dist/storage/s3-object-store.d.ts +70 -0
- package/dist/storage/s3-object-store.d.ts.map +1 -0
- package/dist/types/index.d.ts +65 -3
- package/dist/types/index.d.ts.map +1 -1
- package/hasna.contract.json +110 -0
- package/migrations/0001_instructions.sql +63 -0
- package/migrations/0002_api_keys.sql +20 -0
- package/migrations/0003_idempotency_receipts.sql +24 -0
- package/package.json +29 -14
- package/assets/skills/inbox/SKILL.md +0 -86
- package/dist/cli/add-duplicate-target.test.d.ts +0 -2
- package/dist/cli/add-duplicate-target.test.d.ts.map +0 -1
- package/dist/cli/add-reference-update.test.d.ts +0 -2
- package/dist/cli/add-reference-update.test.d.ts.map +0 -1
- package/dist/cli/apply-unchanged-snapshot-bloat.test.d.ts +0 -2
- package/dist/cli/apply-unchanged-snapshot-bloat.test.d.ts.map +0 -1
- package/dist/cli/doctor-reference-duplicates.test.d.ts +0 -2
- package/dist/cli/doctor-reference-duplicates.test.d.ts.map +0 -1
- package/dist/cli/fail-closed-no-env.test.d.ts +0 -2
- package/dist/cli/fail-closed-no-env.test.d.ts.map +0 -1
- package/dist/cli/output.test.d.ts +0 -2
- package/dist/cli/output.test.d.ts.map +0 -1
- package/dist/cli/profile-binding.test.d.ts +0 -2
- package/dist/cli/profile-binding.test.d.ts.map +0 -1
- package/dist/cli/profile-reads.test.d.ts +0 -2
- package/dist/cli/profile-reads.test.d.ts.map +0 -1
- package/dist/cli/profile-update.test.d.ts +0 -2
- package/dist/cli/profile-update.test.d.ts.map +0 -1
- package/dist/cli/project-context.test.d.ts +0 -2
- package/dist/cli/project-context.test.d.ts.map +0 -1
- package/dist/cli/raw-store-root.test.d.ts +0 -2
- package/dist/cli/raw-store-root.test.d.ts.map +0 -1
- package/dist/cli/session-apply-managed-input-bound.test.d.ts +0 -2
- package/dist/cli/session-apply-managed-input-bound.test.d.ts.map +0 -1
- package/dist/cli/session.test.d.ts +0 -2
- package/dist/cli/session.test.d.ts.map +0 -1
- package/dist/cli/station-profile.test.d.ts +0 -2
- package/dist/cli/station-profile.test.d.ts.map +0 -1
- package/dist/data/config-store.test.d.ts +0 -2
- package/dist/data/config-store.test.d.ts.map +0 -1
- package/dist/db/configs.test.d.ts +0 -2
- package/dist/db/configs.test.d.ts.map +0 -1
- package/dist/db/database.test.d.ts +0 -2
- package/dist/db/database.test.d.ts.map +0 -1
- package/dist/db/machines.test.d.ts +0 -2
- package/dist/db/machines.test.d.ts.map +0 -1
- package/dist/db/profile-assets.test.d.ts +0 -2
- package/dist/db/profile-assets.test.d.ts.map +0 -1
- package/dist/db/profile-config-bindings.test.d.ts +0 -2
- package/dist/db/profile-config-bindings.test.d.ts.map +0 -1
- package/dist/db/profiles.test.d.ts +0 -2
- package/dist/db/profiles.test.d.ts.map +0 -1
- package/dist/db/snapshots.test.d.ts +0 -2
- package/dist/db/snapshots.test.d.ts.map +0 -1
- package/dist/lib/app-home.test.d.ts +0 -2
- package/dist/lib/app-home.test.d.ts.map +0 -1
- package/dist/lib/apply-batch.test.d.ts +0 -2
- package/dist/lib/apply-batch.test.d.ts.map +0 -1
- package/dist/lib/apply-dry-run-verdict.test.d.ts +0 -2
- package/dist/lib/apply-dry-run-verdict.test.d.ts.map +0 -1
- package/dist/lib/apply-secret-placeholder-guard.test.d.ts +0 -2
- package/dist/lib/apply-secret-placeholder-guard.test.d.ts.map +0 -1
- package/dist/lib/apply-text-format-credential-guard.test.d.ts +0 -2
- package/dist/lib/apply-text-format-credential-guard.test.d.ts.map +0 -1
- package/dist/lib/apply.test.d.ts +0 -2
- package/dist/lib/apply.test.d.ts.map +0 -1
- package/dist/lib/asset-plan.test.d.ts +0 -2
- package/dist/lib/asset-plan.test.d.ts.map +0 -1
- package/dist/lib/client-types.test.d.ts +0 -2
- package/dist/lib/client-types.test.d.ts.map +0 -1
- package/dist/lib/codewith-shared-todos-storage-standard.test.d.ts +0 -2
- package/dist/lib/codewith-shared-todos-storage-standard.test.d.ts.map +0 -1
- package/dist/lib/compact-output.test.d.ts +0 -2
- package/dist/lib/compact-output.test.d.ts.map +0 -1
- package/dist/lib/config-target-identity.test.d.ts +0 -2
- package/dist/lib/config-target-identity.test.d.ts.map +0 -1
- package/dist/lib/cursor-authority.test.d.ts +0 -2
- package/dist/lib/cursor-authority.test.d.ts.map +0 -1
- package/dist/lib/dangerous-operation-guard-standard.test.d.ts +0 -2
- package/dist/lib/dangerous-operation-guard-standard.test.d.ts.map +0 -1
- package/dist/lib/diff-redaction.test.d.ts +0 -2
- package/dist/lib/diff-redaction.test.d.ts.map +0 -1
- package/dist/lib/export-import.test.d.ts +0 -2
- package/dist/lib/export-import.test.d.ts.map +0 -1
- package/dist/lib/global-agent-rules-render-integration.test.d.ts +0 -2
- package/dist/lib/global-agent-rules-render-integration.test.d.ts.map +0 -1
- package/dist/lib/global-agent-rules-standard.test.d.ts +0 -2
- package/dist/lib/global-agent-rules-standard.test.d.ts.map +0 -1
- package/dist/lib/global-agent-rules-stored-content.test.d.ts +0 -2
- package/dist/lib/global-agent-rules-stored-content.test.d.ts.map +0 -1
- package/dist/lib/global-source-coverage.test.d.ts +0 -2
- package/dist/lib/global-source-coverage.test.d.ts.map +0 -1
- package/dist/lib/instruction-graph-apply.test.d.ts +0 -2
- package/dist/lib/instruction-graph-apply.test.d.ts.map +0 -1
- package/dist/lib/instruction-graph.test.d.ts +0 -2
- package/dist/lib/instruction-graph.test.d.ts.map +0 -1
- package/dist/lib/machine.test.d.ts +0 -2
- package/dist/lib/machine.test.d.ts.map +0 -1
- package/dist/lib/managed-skill-runtimes.test.d.ts +0 -2
- package/dist/lib/managed-skill-runtimes.test.d.ts.map +0 -1
- package/dist/lib/package-manager-guard.test.d.ts +0 -2
- package/dist/lib/package-manager-guard.test.d.ts.map +0 -1
- package/dist/lib/project-context-prepared-file.test.d.ts +0 -2
- package/dist/lib/project-context-prepared-file.test.d.ts.map +0 -1
- package/dist/lib/project-context.test.d.ts +0 -2
- package/dist/lib/project-context.test.d.ts.map +0 -1
- package/dist/lib/project-dashboard-standard.test.d.ts +0 -2
- package/dist/lib/project-dashboard-standard.test.d.ts.map +0 -1
- package/dist/lib/provider-assets-adapters.test.d.ts +0 -2
- package/dist/lib/provider-assets-adapters.test.d.ts.map +0 -1
- package/dist/lib/provider-context.test.d.ts +0 -2
- package/dist/lib/provider-context.test.d.ts.map +0 -1
- package/dist/lib/provider-version-adapters.test.d.ts +0 -2
- package/dist/lib/provider-version-adapters.test.d.ts.map +0 -1
- package/dist/lib/redact.test.d.ts +0 -2
- package/dist/lib/redact.test.d.ts.map +0 -1
- package/dist/lib/session-apply.test.d.ts +0 -2
- package/dist/lib/session-apply.test.d.ts.map +0 -1
- package/dist/lib/session-authority.test.d.ts +0 -2
- package/dist/lib/session-authority.test.d.ts.map +0 -1
- package/dist/lib/session-render-managed-output-bound.test.d.ts +0 -2
- package/dist/lib/session-render-managed-output-bound.test.d.ts.map +0 -1
- package/dist/lib/session-render-ownership.test.d.ts +0 -2
- package/dist/lib/session-render-ownership.test.d.ts.map +0 -1
- package/dist/lib/session-render-rule-currency-floor.test.d.ts +0 -2
- package/dist/lib/session-render-rule-currency-floor.test.d.ts.map +0 -1
- package/dist/lib/session-render-silent-source-drop.test.d.ts +0 -2
- package/dist/lib/session-render-silent-source-drop.test.d.ts.map +0 -1
- package/dist/lib/session-render-state-hermeticity.test.d.ts +0 -2
- package/dist/lib/session-render-state-hermeticity.test.d.ts.map +0 -1
- package/dist/lib/session-render-state.test.d.ts +0 -2
- package/dist/lib/session-render-state.test.d.ts.map +0 -1
- package/dist/lib/session-render.test.d.ts +0 -2
- package/dist/lib/session-render.test.d.ts.map +0 -1
- package/dist/lib/station-profile.test.d.ts +0 -2
- package/dist/lib/station-profile.test.d.ts.map +0 -1
- package/dist/lib/sync-dir.test.d.ts +0 -2
- package/dist/lib/sync-dir.test.d.ts.map +0 -1
- package/dist/lib/sync-dry-run-unchanged.test.d.ts +0 -2
- package/dist/lib/sync-dry-run-unchanged.test.d.ts.map +0 -1
- package/dist/lib/sync-known.test.d.ts +0 -2
- package/dist/lib/sync-known.test.d.ts.map +0 -1
- package/dist/lib/sync.test.d.ts +0 -2
- package/dist/lib/sync.test.d.ts.map +0 -1
- package/dist/lib/template.test.d.ts +0 -2
- package/dist/lib/template.test.d.ts.map +0 -1
- package/dist/lib/transforms.test.d.ts +0 -2
- package/dist/lib/transforms.test.d.ts.map +0 -1
- package/dist/lib/transport-resolver.test.d.ts +0 -2
- package/dist/lib/transport-resolver.test.d.ts.map +0 -1
- package/dist/mcp/create-config-target-guard.test.d.ts +0 -2
- package/dist/mcp/create-config-target-guard.test.d.ts.map +0 -1
- package/dist/mcp/early-args.test.d.ts +0 -2
- package/dist/mcp/early-args.test.d.ts.map +0 -1
- package/dist/mcp/http.test.d.ts +0 -2
- package/dist/mcp/http.test.d.ts.map +0 -1
- package/dist/mcp/mcp.test.d.ts +0 -2
- package/dist/mcp/mcp.test.d.ts.map +0 -1
- package/dist/sdk/resolve.test.d.ts +0 -2
- package/dist/sdk/resolve.test.d.ts.map +0 -1
- package/dist/sdk/sdk-bundle-self-contained.test.d.ts +0 -2
- package/dist/sdk/sdk-bundle-self-contained.test.d.ts.map +0 -1
- package/dist/server/cloud-auth.test.d.ts +0 -2
- package/dist/server/cloud-auth.test.d.ts.map +0 -1
- package/dist/server/cloud.test.d.ts +0 -2
- package/dist/server/cloud.test.d.ts.map +0 -1
- package/dist/server/early-args.test.d.ts +0 -2
- package/dist/server/early-args.test.d.ts.map +0 -1
- package/dist/server/profile-contract.test.d.ts +0 -2
- package/dist/server/profile-contract.test.d.ts.map +0 -1
- package/dist/status.test.d.ts +0 -2
- package/dist/status.test.d.ts.map +0 -1
- package/dist/storage/cloud-store.test.d.ts +0 -2
- package/dist/storage/cloud-store.test.d.ts.map +0 -1
- package/dist/test-support/preload-state-home.d.ts +0 -2
- package/dist/test-support/preload-state-home.d.ts.map +0 -1
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
applyConfigsWithReport,
|
|
4
|
+
compactPathForConfigHome,
|
|
5
|
+
expandPath,
|
|
6
|
+
getConfigHome,
|
|
7
|
+
normalizeTargetPath
|
|
8
|
+
} from "./index-z3ma4aqk.js";
|
|
9
|
+
import {
|
|
10
|
+
applyTransform,
|
|
11
|
+
detectMachineContext,
|
|
12
|
+
isRetiredOrUnsupportedConfigAgent,
|
|
13
|
+
isSecretVarName,
|
|
14
|
+
redactContent,
|
|
15
|
+
redactFormatForTarget,
|
|
16
|
+
resolveConfigStore,
|
|
17
|
+
retiredOrUnsupportedAgentReason,
|
|
18
|
+
templateizeMachineContent
|
|
19
|
+
} from "./index-7m4j8a33.js";
|
|
20
|
+
|
|
21
|
+
// src/lib/sync.ts
|
|
22
|
+
import { existsSync as existsSync2, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "fs";
|
|
23
|
+
import { basename, extname, join as join2 } from "path";
|
|
24
|
+
|
|
25
|
+
// src/lib/sync-dir.ts
|
|
26
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "fs";
|
|
27
|
+
import { join, relative } from "path";
|
|
28
|
+
var SKIP = [".db", ".db-shm", ".db-wal", ".log", ".lock", ".DS_Store", "node_modules", ".git"];
|
|
29
|
+
function shouldSkip(p) {
|
|
30
|
+
return SKIP.some((s) => p.includes(s));
|
|
31
|
+
}
|
|
32
|
+
async function syncFromDir(dir, opts = {}) {
|
|
33
|
+
const store = opts.store ?? resolveConfigStore();
|
|
34
|
+
const absDir = expandPath(dir);
|
|
35
|
+
if (!existsSync(absDir))
|
|
36
|
+
return { added: 0, updated: 0, unchanged: 0, skipped: [`Not found: ${absDir}`] };
|
|
37
|
+
const files = opts.recursive !== false ? walkDir(absDir) : readdirSync(absDir).map((f) => join(absDir, f)).filter((f) => statSync(f).isFile());
|
|
38
|
+
const result = { added: 0, updated: 0, unchanged: 0, skipped: [] };
|
|
39
|
+
const allConfigs = await store.listConfigs();
|
|
40
|
+
for (const file of files) {
|
|
41
|
+
if (shouldSkip(file)) {
|
|
42
|
+
result.skipped.push(file);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const content = readFileSync(file, "utf-8");
|
|
47
|
+
if (content.length > 500000) {
|
|
48
|
+
result.skipped.push(file + " (too large)");
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const targetPath = compactPathForConfigHome(file);
|
|
52
|
+
const redacted = redactContent(content, redactFormatForTarget(targetPath, detectFormat(file)));
|
|
53
|
+
const existing = allConfigs.find((c) => c.target_path === targetPath);
|
|
54
|
+
if (!existing) {
|
|
55
|
+
if (!opts.dryRun)
|
|
56
|
+
await store.createConfig({ name: relative(absDir, file), category: detectCategory(file), agent: detectAgent(file), target_path: targetPath, format: detectFormat(file), content: redacted.content });
|
|
57
|
+
result.added++;
|
|
58
|
+
} else if (existing.content !== redacted.content) {
|
|
59
|
+
if (!opts.dryRun)
|
|
60
|
+
await store.updateConfig(existing.id, { content: redacted.content });
|
|
61
|
+
result.updated++;
|
|
62
|
+
} else {
|
|
63
|
+
result.unchanged++;
|
|
64
|
+
}
|
|
65
|
+
} catch {
|
|
66
|
+
result.skipped.push(file);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
async function syncToDir(dir, opts = {}) {
|
|
72
|
+
const store = opts.store ?? resolveConfigStore();
|
|
73
|
+
const absDir = expandPath(dir);
|
|
74
|
+
const normalized = dir.startsWith("~/") ? dir : compactPathForConfigHome(absDir);
|
|
75
|
+
const configs = (await store.listConfigs()).filter((c) => c.target_path && (c.target_path.startsWith(normalized) || c.target_path.startsWith(absDir)));
|
|
76
|
+
const result = { added: 0, updated: 0, unchanged: 0, skipped: [] };
|
|
77
|
+
for (const config of configs) {
|
|
78
|
+
if (config.kind === "reference")
|
|
79
|
+
continue;
|
|
80
|
+
try {
|
|
81
|
+
const report = await applyConfigsWithReport([config], { dryRun: opts.dryRun, store });
|
|
82
|
+
result.skipped.push(...report.skipped.map((entry) => `${entry.path} (${entry.owner})`));
|
|
83
|
+
if (report.failures.length > 0)
|
|
84
|
+
throw new Error(report.failures[0].message);
|
|
85
|
+
for (const applied of report.results) {
|
|
86
|
+
applied.changed ? result.updated++ : result.unchanged++;
|
|
87
|
+
}
|
|
88
|
+
} catch {
|
|
89
|
+
result.skipped.push(config.target_path || config.id);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
function walkDir(dir, files = []) {
|
|
95
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
96
|
+
const full = join(dir, entry.name);
|
|
97
|
+
if (shouldSkip(full))
|
|
98
|
+
continue;
|
|
99
|
+
if (entry.isDirectory())
|
|
100
|
+
walkDir(full, files);
|
|
101
|
+
else if (entry.isFile())
|
|
102
|
+
files.push(full);
|
|
103
|
+
}
|
|
104
|
+
return files;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/lib/sync.ts
|
|
108
|
+
var CLAUDE_PROMPT_OUTPUTS = [
|
|
109
|
+
{ agent: "codex", target_path: "~/.codex/AGENTS.md", transform: "codex-flat" },
|
|
110
|
+
{ agent: "codewith", target_path: "~/.codewith/CODEWITH.md", transform: "codex-flat" },
|
|
111
|
+
{ agent: "opencode", target_path: "~/.config/opencode/AGENTS.md", transform: "opencode-flat" },
|
|
112
|
+
{ agent: "aicopilot", target_path: "~/.config/aicopilot/AICOPILOT.md", transform: "codex-flat" },
|
|
113
|
+
{ agent: "antigravity", target_path: "~/.gemini/GEMINI.md", transform: "codex-flat" },
|
|
114
|
+
{ agent: "cursor", target_path: "~/.cursor/rules/claude.mdc", transform: "cursor-mdc" },
|
|
115
|
+
{ agent: "qwen", target_path: "~/.qwen/QWEN.md", transform: "codex-flat" }
|
|
116
|
+
];
|
|
117
|
+
function claudeRuleOutputs(fileName) {
|
|
118
|
+
const stem = basename(fileName, extname(fileName));
|
|
119
|
+
return [
|
|
120
|
+
{ agent: "cursor", target_path: `~/.cursor/rules/${stem}.mdc`, transform: "cursor-mdc" }
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
function normalizeOutputs(outputs) {
|
|
124
|
+
return outputs ?? [];
|
|
125
|
+
}
|
|
126
|
+
function outputsEqual(a, b) {
|
|
127
|
+
return JSON.stringify(normalizeOutputs(a)) === JSON.stringify(normalizeOutputs(b));
|
|
128
|
+
}
|
|
129
|
+
var UNGUARDED_LOCAL_ENV_HELPER = '. "$HOME/.local/bin/env"';
|
|
130
|
+
var GUARDED_LOCAL_ENV_HELPER = '[ -r "$HOME/.local/bin/env" ] && . "$HOME/.local/bin/env"';
|
|
131
|
+
function normalizeKnownConfigSource(known, content) {
|
|
132
|
+
if (known.name !== "bash-profile")
|
|
133
|
+
return content;
|
|
134
|
+
return content.split(`
|
|
135
|
+
`).map((line) => line === UNGUARDED_LOCAL_ENV_HELPER ? GUARDED_LOCAL_ENV_HELPER : line).join(`
|
|
136
|
+
`);
|
|
137
|
+
}
|
|
138
|
+
function outputOwnerIdsByTarget(configs) {
|
|
139
|
+
const owners = new Map;
|
|
140
|
+
for (const config of configs) {
|
|
141
|
+
for (const output of config.outputs) {
|
|
142
|
+
const targetPath = normalizeTargetPath(output.target_path);
|
|
143
|
+
const existing = owners.get(targetPath) ?? new Set;
|
|
144
|
+
existing.add(config.id);
|
|
145
|
+
owners.set(targetPath, existing);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return owners;
|
|
149
|
+
}
|
|
150
|
+
function isGeneratedOutputTarget(config, owners) {
|
|
151
|
+
if (!config.target_path)
|
|
152
|
+
return false;
|
|
153
|
+
const ownerIds = owners.get(normalizeTargetPath(config.target_path));
|
|
154
|
+
return !!ownerIds && !ownerIds.has(config.id);
|
|
155
|
+
}
|
|
156
|
+
function hasClaudePromptSource() {
|
|
157
|
+
return existsSync2(expandPath("~/.claude/CLAUDE.md"));
|
|
158
|
+
}
|
|
159
|
+
function hasClaudeRuleSourceForCursorTarget(targetPath) {
|
|
160
|
+
const absoluteTargetPath = expandPath(targetPath);
|
|
161
|
+
const absolutePrefix = expandPath("~/.cursor/rules");
|
|
162
|
+
if (!absoluteTargetPath.startsWith(`${absolutePrefix}/`) || !absoluteTargetPath.endsWith(".mdc"))
|
|
163
|
+
return false;
|
|
164
|
+
const stem = basename(absoluteTargetPath, ".mdc");
|
|
165
|
+
return existsSync2(expandPath(`~/.claude/rules/${stem}.md`)) || existsSync2(expandPath(`~/.claude/rules/${stem}.mdc`));
|
|
166
|
+
}
|
|
167
|
+
function isKnownGeneratedTargetPath(targetPath) {
|
|
168
|
+
const normalizedTargetPath = normalizeTargetPath(targetPath);
|
|
169
|
+
const promptTargets = new Set(CLAUDE_PROMPT_OUTPUTS.map((output) => normalizeTargetPath(output.target_path)));
|
|
170
|
+
if (promptTargets.has(normalizedTargetPath))
|
|
171
|
+
return hasClaudePromptSource();
|
|
172
|
+
return hasClaudeRuleSourceForCursorTarget(targetPath);
|
|
173
|
+
}
|
|
174
|
+
var KNOWN_CONFIGS = [
|
|
175
|
+
{ path: "~/.claude/CLAUDE.md", name: "claude-claude-md", category: "rules", agent: "claude", format: "markdown", outputs: CLAUDE_PROMPT_OUTPUTS },
|
|
176
|
+
{ path: "~/.claude/settings.json", name: "claude-settings", category: "agent", agent: "claude", format: "json" },
|
|
177
|
+
{ path: "~/.claude/settings.local.json", name: "claude-settings-local", category: "agent", agent: "claude", format: "json" },
|
|
178
|
+
{ path: "~/.claude/keybindings.json", name: "claude-keybindings", category: "agent", agent: "claude", format: "json", optional: true },
|
|
179
|
+
{ path: "~/.claude/rules", name: "claude-rules", category: "rules", agent: "claude", rulesDir: "~/.claude/rules", rulesExtensions: [".md", ".mdc"] },
|
|
180
|
+
{ path: "~/.codex/config.toml", name: "codex-config", category: "agent", agent: "codex", format: "toml" },
|
|
181
|
+
{ path: "~/.codex/AGENTS.md", name: "codex-agents-md", category: "rules", agent: "codex", format: "markdown" },
|
|
182
|
+
{ path: "~/.config/opencode/AGENTS.md", name: "opencode-agents-md", category: "rules", agent: "opencode", format: "markdown", optional: true },
|
|
183
|
+
{ path: "~/.config/opencode/opencode.json", name: "opencode-config", category: "mcp", agent: "opencode", format: "json", optional: true, description: "OpenCode config (includes Skills MCP server entries)" },
|
|
184
|
+
{ path: "~/.cursor/rules", name: "cursor-rules", category: "rules", agent: "cursor", rulesDir: "~/.cursor/rules", rulesExtensions: [".md", ".mdc"] },
|
|
185
|
+
{ path: "~/.cursor/mcp.json", name: "cursor-mcp", category: "mcp", agent: "cursor", format: "json", optional: true, description: "Cursor MCP config (includes Skills MCP server entries)" },
|
|
186
|
+
{ path: "~/.codewith/CODEWITH.md", name: "codewith-codewith-md", category: "rules", agent: "codewith", format: "markdown", optional: true },
|
|
187
|
+
{ path: "~/.codewith/config.toml", name: "codewith-config", category: "mcp", agent: "codewith", format: "toml", optional: true, description: "codewith config (Codex fork, includes Skills MCP server entries)" },
|
|
188
|
+
{ path: "~/.config/aicopilot/AICOPILOT.md", name: "aicopilot-aicopilot-md", category: "rules", agent: "aicopilot", format: "markdown", optional: true },
|
|
189
|
+
{ path: "~/.config/aicopilot/aicopilot.json", name: "aicopilot-config", category: "mcp", agent: "aicopilot", format: "json", optional: true, description: "AI Copilot config (includes instructions and MCP server entries)" },
|
|
190
|
+
{ path: "~/.gemini/GEMINI.md", name: "antigravity-global-rules", category: "rules", agent: "antigravity", format: "markdown", optional: true, description: "Google Antigravity global rules file" },
|
|
191
|
+
{ path: "~/.gemini/config/mcp_config.json", name: "antigravity-global-mcp", category: "mcp", agent: "antigravity", format: "json", optional: true, description: "Google Antigravity global MCP server entries" },
|
|
192
|
+
{ path: "~/.qwen/QWEN.md", name: "qwen-qwen-md", category: "rules", agent: "qwen", format: "markdown", optional: true, description: "Qwen Code global instructional context" },
|
|
193
|
+
{ path: "~/.qwen/settings.json", name: "qwen-settings", category: "agent", agent: "qwen", format: "json", optional: true, description: "Qwen Code settings.json, including native hooks" },
|
|
194
|
+
{ path: "~/.claude.json", name: "claude-json", category: "mcp", agent: "claude", format: "json", description: "Claude Code global config (includes MCP server entries)" },
|
|
195
|
+
{ path: "~/.zshrc", name: "zshrc", category: "shell", agent: "zsh" },
|
|
196
|
+
{ path: "~/.zprofile", name: "zprofile", category: "shell", agent: "zsh", optional: true },
|
|
197
|
+
{ path: "~/.bashrc", name: "bashrc", category: "shell", agent: "zsh", optional: true },
|
|
198
|
+
{ path: "~/.bash_profile", name: "bash-profile", category: "shell", agent: "zsh", optional: true },
|
|
199
|
+
{ path: "~/.gitconfig", name: "gitconfig", category: "git", agent: "git", format: "ini" },
|
|
200
|
+
{ path: "~/.gitignore_global", name: "gitignore-global", category: "git", agent: "git", optional: true },
|
|
201
|
+
{ path: "~/.npmrc", name: "npmrc", category: "tools", agent: "npm", format: "ini" },
|
|
202
|
+
{ path: "~/.bunfig.toml", name: "bunfig", category: "tools", agent: "global", format: "toml", optional: true }
|
|
203
|
+
];
|
|
204
|
+
var PROJECT_CONFIG_FILES = [
|
|
205
|
+
{ file: "CLAUDE.md", category: "rules", agent: "claude", format: "markdown" },
|
|
206
|
+
{ file: ".claude/settings.json", category: "agent", agent: "claude", format: "json" },
|
|
207
|
+
{ file: ".claude/settings.local.json", category: "agent", agent: "claude", format: "json" },
|
|
208
|
+
{ file: ".mcp.json", category: "mcp", agent: "claude", format: "json" },
|
|
209
|
+
{ file: "AGENTS.md", category: "rules", agent: "codex", format: "markdown" },
|
|
210
|
+
{ file: ".codex/AGENTS.md", category: "rules", agent: "codex", format: "markdown" },
|
|
211
|
+
{ file: ".opencode/AGENTS.md", category: "rules", agent: "opencode", format: "markdown" },
|
|
212
|
+
{ file: "CODEWITH.md", category: "rules", agent: "codewith", format: "markdown" },
|
|
213
|
+
{ file: ".codewith/CODEWITH.md", category: "rules", agent: "codewith", format: "markdown" },
|
|
214
|
+
{ file: ".aicopilot/AICOPILOT.md", category: "rules", agent: "aicopilot", format: "markdown" },
|
|
215
|
+
{ file: "AICOPILOT.md", category: "rules", agent: "aicopilot", format: "markdown" },
|
|
216
|
+
{ file: ".cursor/mcp.json", category: "mcp", agent: "cursor", format: "json" },
|
|
217
|
+
{ file: ".github/copilot-instructions.md", category: "rules", agent: "copilot", format: "markdown" },
|
|
218
|
+
{ file: "QWEN.md", category: "rules", agent: "qwen", format: "markdown" },
|
|
219
|
+
{ file: ".agents/mcp_config.json", category: "mcp", agent: "antigravity", format: "json" },
|
|
220
|
+
{ file: ".qwen/settings.json", category: "agent", agent: "qwen", format: "json" }
|
|
221
|
+
];
|
|
222
|
+
async function syncProject(opts) {
|
|
223
|
+
const store = opts.store ?? resolveConfigStore();
|
|
224
|
+
const absDir = expandPath(opts.projectDir);
|
|
225
|
+
const projectName = absDir.split("/").pop() || "project";
|
|
226
|
+
const result = { added: 0, updated: 0, unchanged: 0, skipped: [] };
|
|
227
|
+
const allConfigs = await store.listConfigs();
|
|
228
|
+
const machine = detectMachineContext();
|
|
229
|
+
for (const pf of PROJECT_CONFIG_FILES) {
|
|
230
|
+
const abs = join2(absDir, pf.file);
|
|
231
|
+
if (!existsSync2(abs))
|
|
232
|
+
continue;
|
|
233
|
+
try {
|
|
234
|
+
const rawContent = readFileSync2(abs, "utf-8");
|
|
235
|
+
if (rawContent.length > 500000) {
|
|
236
|
+
result.skipped.push(pf.file);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const redacted = redactContent(rawContent, pf.format);
|
|
240
|
+
const machineAware = templateizeMachineContent(redacted.content, machine);
|
|
241
|
+
const content = machineAware.content;
|
|
242
|
+
const isTemplate = redacted.isTemplate || machineAware.changed;
|
|
243
|
+
const name = `${projectName}/${pf.file}`;
|
|
244
|
+
const targetPath = abs.startsWith(getConfigHome()) ? abs.replace(getConfigHome(), "~") : abs;
|
|
245
|
+
const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
246
|
+
const existing = allConfigs.find((c) => c.target_path === targetPath || c.slug === slug);
|
|
247
|
+
if (!existing) {
|
|
248
|
+
if (!opts.dryRun)
|
|
249
|
+
await store.createConfig({ name, category: pf.category, agent: pf.agent, format: pf.format, content, target_path: targetPath, is_template: isTemplate });
|
|
250
|
+
result.added++;
|
|
251
|
+
} else if (existing.content !== content) {
|
|
252
|
+
if (!opts.dryRun)
|
|
253
|
+
await store.updateConfig(existing.id, { content, is_template: isTemplate });
|
|
254
|
+
result.updated++;
|
|
255
|
+
} else {
|
|
256
|
+
result.unchanged++;
|
|
257
|
+
}
|
|
258
|
+
} catch {
|
|
259
|
+
result.skipped.push(pf.file);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
for (const ruleDir of [
|
|
263
|
+
{ dir: join2(absDir, ".claude", "rules"), agent: "claude", namePrefix: "rules" },
|
|
264
|
+
{ dir: join2(absDir, ".agents", "rules"), agent: "antigravity", namePrefix: "antigravity-rules" },
|
|
265
|
+
{ dir: join2(absDir, ".cursor", "rules"), agent: "cursor", namePrefix: "cursor-rules" },
|
|
266
|
+
{ dir: join2(absDir, ".github", "instructions"), agent: "copilot", namePrefix: "copilot-instructions" },
|
|
267
|
+
{ dir: join2(absDir, ".devin", "rules"), agent: "devin", namePrefix: "devin-rules" },
|
|
268
|
+
{ dir: join2(absDir, ".windsurf", "rules"), agent: "windsurf-legacy", namePrefix: "windsurf-rules" },
|
|
269
|
+
{ dir: join2(absDir, ".clinerules"), agent: "cline", namePrefix: "cline-rules" }
|
|
270
|
+
]) {
|
|
271
|
+
if (!existsSync2(ruleDir.dir))
|
|
272
|
+
continue;
|
|
273
|
+
const mdFiles = readdirSync2(ruleDir.dir).filter((f) => f.endsWith(".md") || f.endsWith(".mdc"));
|
|
274
|
+
for (const f of mdFiles) {
|
|
275
|
+
const abs = join2(ruleDir.dir, f);
|
|
276
|
+
const raw = readFileSync2(abs, "utf-8");
|
|
277
|
+
const redacted = redactContent(raw, "markdown");
|
|
278
|
+
const machineAware = templateizeMachineContent(redacted.content, machine);
|
|
279
|
+
const content = machineAware.content;
|
|
280
|
+
const isTemplate = redacted.isTemplate || machineAware.changed;
|
|
281
|
+
const name = `${projectName}/${ruleDir.namePrefix}/${f}`;
|
|
282
|
+
const targetPath = abs.startsWith(getConfigHome()) ? abs.replace(getConfigHome(), "~") : abs;
|
|
283
|
+
const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
284
|
+
const existing = allConfigs.find((c) => c.target_path === targetPath || c.slug === slug);
|
|
285
|
+
if (!existing) {
|
|
286
|
+
if (!opts.dryRun)
|
|
287
|
+
await store.createConfig({ name, category: "rules", agent: ruleDir.agent, format: "markdown", content, target_path: targetPath, is_template: isTemplate });
|
|
288
|
+
result.added++;
|
|
289
|
+
} else if (existing.content !== content) {
|
|
290
|
+
if (!opts.dryRun)
|
|
291
|
+
await store.updateConfig(existing.id, { content, is_template: isTemplate });
|
|
292
|
+
result.updated++;
|
|
293
|
+
} else {
|
|
294
|
+
result.unchanged++;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return result;
|
|
299
|
+
}
|
|
300
|
+
async function syncKnown(opts = {}) {
|
|
301
|
+
const store = opts.store ?? resolveConfigStore();
|
|
302
|
+
const result = { added: 0, updated: 0, unchanged: 0, skipped: [] };
|
|
303
|
+
const home = getConfigHome();
|
|
304
|
+
const machine = detectMachineContext();
|
|
305
|
+
let targets = KNOWN_CONFIGS;
|
|
306
|
+
if (opts.agent)
|
|
307
|
+
targets = targets.filter((k) => k.agent === opts.agent);
|
|
308
|
+
if (opts.category)
|
|
309
|
+
targets = targets.filter((k) => k.category === opts.category);
|
|
310
|
+
const allConfigs = await store.listConfigs();
|
|
311
|
+
const existingOutputOwners = outputOwnerIdsByTarget(allConfigs);
|
|
312
|
+
for (const known of targets) {
|
|
313
|
+
if (known.rulesDir) {
|
|
314
|
+
const absDir = expandPath(known.rulesDir);
|
|
315
|
+
if (!existsSync2(absDir)) {
|
|
316
|
+
result.skipped.push(known.rulesDir);
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
const extensions = known.rulesExtensions ?? [".md", ".mdc"];
|
|
320
|
+
const ruleFiles = readdirSync2(absDir).filter((f) => extensions.some((ext) => f.endsWith(ext)));
|
|
321
|
+
for (const f of ruleFiles) {
|
|
322
|
+
const abs2 = join2(absDir, f);
|
|
323
|
+
const targetPath = abs2.replace(home, "~");
|
|
324
|
+
if (existingOutputOwners.has(normalizeTargetPath(targetPath)) || isKnownGeneratedTargetPath(targetPath)) {
|
|
325
|
+
result.skipped.push(`${targetPath} (generated output)`);
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const raw = readFileSync2(abs2, "utf-8");
|
|
329
|
+
const redacted = redactContent(raw, "markdown");
|
|
330
|
+
const machineAware = templateizeMachineContent(redacted.content, machine);
|
|
331
|
+
const content = machineAware.content;
|
|
332
|
+
const isTemplate = redacted.isTemplate || machineAware.changed;
|
|
333
|
+
const name = `${known.name}-${f}`;
|
|
334
|
+
const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
335
|
+
const existing = allConfigs.find((c) => c.target_path === targetPath || c.slug === slug);
|
|
336
|
+
const outputs = known.agent === "claude" ? claudeRuleOutputs(f) : known.outputs;
|
|
337
|
+
if (!existing) {
|
|
338
|
+
if (!opts.dryRun)
|
|
339
|
+
await store.createConfig({ name, category: known.category, agent: known.agent, format: "markdown", content, target_path: targetPath, is_template: isTemplate, outputs });
|
|
340
|
+
result.added++;
|
|
341
|
+
} else if (existing.content !== content) {
|
|
342
|
+
if (!opts.dryRun)
|
|
343
|
+
await store.updateConfig(existing.id, { content, is_template: isTemplate, outputs });
|
|
344
|
+
result.updated++;
|
|
345
|
+
} else if (!outputsEqual(existing.outputs, outputs)) {
|
|
346
|
+
if (!opts.dryRun)
|
|
347
|
+
await store.updateConfig(existing.id, { outputs });
|
|
348
|
+
result.updated++;
|
|
349
|
+
} else {
|
|
350
|
+
result.unchanged++;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const abs = expandPath(known.path);
|
|
356
|
+
if (!existsSync2(abs)) {
|
|
357
|
+
result.skipped.push(known.path);
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
try {
|
|
361
|
+
const rawContent = normalizeKnownConfigSource(known, readFileSync2(abs, "utf-8"));
|
|
362
|
+
if (rawContent.length > 500000) {
|
|
363
|
+
result.skipped.push(known.path + " (too large)");
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
const fmt = known.format ?? detectFormat(abs);
|
|
367
|
+
const redacted = redactContent(rawContent, redactFormatForTarget(abs, fmt));
|
|
368
|
+
const machineAware = templateizeMachineContent(redacted.content, machine);
|
|
369
|
+
const content = machineAware.content;
|
|
370
|
+
const isTemplate = redacted.isTemplate || machineAware.changed;
|
|
371
|
+
const targetPath = abs.replace(home, "~");
|
|
372
|
+
if (existingOutputOwners.has(normalizeTargetPath(targetPath)) || isKnownGeneratedTargetPath(targetPath)) {
|
|
373
|
+
result.skipped.push(`${targetPath} (generated output)`);
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
const existing = allConfigs.find((c) => c.target_path === targetPath || c.slug === known.name);
|
|
377
|
+
if (!existing) {
|
|
378
|
+
if (!opts.dryRun) {
|
|
379
|
+
await store.createConfig({
|
|
380
|
+
name: known.name,
|
|
381
|
+
category: known.category,
|
|
382
|
+
agent: known.agent,
|
|
383
|
+
format: fmt,
|
|
384
|
+
content,
|
|
385
|
+
target_path: known.kind === "reference" ? null : targetPath,
|
|
386
|
+
kind: known.kind ?? "file",
|
|
387
|
+
description: known.description,
|
|
388
|
+
is_template: isTemplate,
|
|
389
|
+
outputs: known.outputs
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
result.added++;
|
|
393
|
+
} else if (existing.content !== content) {
|
|
394
|
+
if (!opts.dryRun)
|
|
395
|
+
await store.updateConfig(existing.id, { content, is_template: isTemplate, outputs: known.outputs });
|
|
396
|
+
result.updated++;
|
|
397
|
+
} else if (!outputsEqual(existing.outputs, known.outputs)) {
|
|
398
|
+
if (!opts.dryRun)
|
|
399
|
+
await store.updateConfig(existing.id, { outputs: known.outputs });
|
|
400
|
+
result.updated++;
|
|
401
|
+
} else {
|
|
402
|
+
result.unchanged++;
|
|
403
|
+
}
|
|
404
|
+
} catch {
|
|
405
|
+
result.skipped.push(known.path);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return result;
|
|
409
|
+
}
|
|
410
|
+
async function syncToDisk(opts = {}) {
|
|
411
|
+
const store = opts.store ?? resolveConfigStore();
|
|
412
|
+
const result = { added: 0, updated: 0, unchanged: 0, skipped: [] };
|
|
413
|
+
const allFileConfigs = await store.listConfigs({ kind: "file", ...opts.category ? { category: opts.category } : {} });
|
|
414
|
+
const outputOwners = outputOwnerIdsByTarget(allFileConfigs);
|
|
415
|
+
let configs = allFileConfigs.filter((config) => {
|
|
416
|
+
return !isGeneratedOutputTarget(config, outputOwners);
|
|
417
|
+
}).filter((config) => {
|
|
418
|
+
if (!opts.agent)
|
|
419
|
+
return true;
|
|
420
|
+
return config.agent === opts.agent || config.outputs.some((output) => output.agent === opts.agent);
|
|
421
|
+
});
|
|
422
|
+
for (const config of configs) {
|
|
423
|
+
if (!config.target_path && config.outputs.length === 0)
|
|
424
|
+
continue;
|
|
425
|
+
if (isRetiredOrUnsupportedConfigAgent(config.agent)) {
|
|
426
|
+
result.skipped.push(`${config.slug} (${retiredOrUnsupportedAgentReason(config.agent)})`);
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
try {
|
|
430
|
+
const report = await applyConfigsWithReport([config], {
|
|
431
|
+
dryRun: opts.dryRun,
|
|
432
|
+
store,
|
|
433
|
+
outputAgent: opts.agent
|
|
434
|
+
});
|
|
435
|
+
result.skipped.push(...report.skipped.map((entry) => `${entry.path} (${entry.owner})`));
|
|
436
|
+
if (report.failures.length > 0)
|
|
437
|
+
throw new Error(report.failures[0].message);
|
|
438
|
+
for (const applied of report.results) {
|
|
439
|
+
applied.changed ? result.updated++ : result.unchanged++;
|
|
440
|
+
}
|
|
441
|
+
} catch {
|
|
442
|
+
result.skipped.push(config.target_path ?? config.id);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return result;
|
|
446
|
+
}
|
|
447
|
+
var CERTAIN_PLACEHOLDER_RE = /\{\{[A-Za-z_][A-Za-z0-9_]*\}\}/g;
|
|
448
|
+
var ASSIGNED_PLACEHOLDER_RE = /[=:]\s*(["']?)(\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Z][A-Z0-9_]*)|%([A-Za-z_][A-Za-z0-9_]*)%)\1\s*,?\s*$/;
|
|
449
|
+
function redactionPlaceholders(storedLine) {
|
|
450
|
+
const found = [...storedLine.match(CERTAIN_PLACEHOLDER_RE) ?? []];
|
|
451
|
+
const assigned = storedLine.match(ASSIGNED_PLACEHOLDER_RE);
|
|
452
|
+
if (assigned) {
|
|
453
|
+
const name = assigned[3] ?? assigned[4] ?? assigned[5];
|
|
454
|
+
if (name && isSecretVarName(name))
|
|
455
|
+
found.push(assigned[2]);
|
|
456
|
+
}
|
|
457
|
+
return found;
|
|
458
|
+
}
|
|
459
|
+
function storedPlaceholderIsLiteralOnDisk(storedLine, diskLine) {
|
|
460
|
+
return redactionPlaceholders(storedLine).some((p) => !diskLine.includes(p));
|
|
461
|
+
}
|
|
462
|
+
function buildDiff(expectedContent, targetPath, storedFormat, showSecrets) {
|
|
463
|
+
const path = expandPath(targetPath);
|
|
464
|
+
if (!existsSync2(path))
|
|
465
|
+
return `(file not found on disk: ${path})`;
|
|
466
|
+
const diskContent = readFileSync2(path, "utf-8");
|
|
467
|
+
if (diskContent === expectedContent)
|
|
468
|
+
return "(no diff \u2014 identical)";
|
|
469
|
+
const format = redactFormatForTarget(targetPath, storedFormat);
|
|
470
|
+
const stored = expectedContent.split(`
|
|
471
|
+
`);
|
|
472
|
+
const disk = diskContent.split(`
|
|
473
|
+
`);
|
|
474
|
+
const { content: redactedDiskContent, redacted } = showSecrets ? { content: diskContent, redacted: [] } : redactContent(diskContent, format);
|
|
475
|
+
const redactedDisk = redactedDiskContent.split(`
|
|
476
|
+
`);
|
|
477
|
+
const reasonByLine = new Map;
|
|
478
|
+
for (const r of redacted)
|
|
479
|
+
if (!reasonByLine.has(r.line))
|
|
480
|
+
reasonByLine.set(r.line, r.reason);
|
|
481
|
+
const lines = [`--- stored (DB)`, `+++ disk (${path})`];
|
|
482
|
+
const maxLen = Math.max(stored.length, disk.length);
|
|
483
|
+
for (let i = 0;i < maxLen; i++) {
|
|
484
|
+
const lineNo = i + 1;
|
|
485
|
+
const s = stored[i];
|
|
486
|
+
const dk = disk[i];
|
|
487
|
+
if (s === dk) {
|
|
488
|
+
if (s !== undefined)
|
|
489
|
+
lines.push(` ${s}`);
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
if (showSecrets || dk === undefined) {
|
|
493
|
+
if (s !== undefined)
|
|
494
|
+
lines.push(`-${s}`);
|
|
495
|
+
if (dk !== undefined)
|
|
496
|
+
lines.push(`+${dk}`);
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
const structural = s !== undefined && storedPlaceholderIsLiteralOnDisk(s, dk);
|
|
500
|
+
const patterned = reasonByLine.has(lineNo);
|
|
501
|
+
if (!structural && !patterned) {
|
|
502
|
+
if (s !== undefined)
|
|
503
|
+
lines.push(`-${s}`);
|
|
504
|
+
lines.push(`+${dk}`);
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
if (structural) {
|
|
508
|
+
const placeholder = redactionPlaceholders(s).find((p) => !dk.includes(p)) ?? "a placeholder";
|
|
509
|
+
lines.push(`~line ${lineNo} differs: stored \`${s}\`, disk holds a literal value for ${placeholder} \u2014 redacted (use --show-secrets on a TTY to reveal)`);
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
const safe = redactedDisk[i] ?? "";
|
|
513
|
+
const reason = reasonByLine.get(lineNo);
|
|
514
|
+
if (s !== undefined && safe === s) {
|
|
515
|
+
lines.push(`~line ${lineNo} differs: stored \`${s}\`, disk holds a literal value (${reason}) \u2014 redacted (use --show-secrets on a TTY to reveal)`);
|
|
516
|
+
} else {
|
|
517
|
+
if (s !== undefined)
|
|
518
|
+
lines.push(`-${s}`);
|
|
519
|
+
lines.push(`+${safe}`);
|
|
520
|
+
lines.push(`~line ${lineNo}: disk value redacted (${reason}) \u2014 use --show-secrets on a TTY to reveal`);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return lines.join(`
|
|
524
|
+
`);
|
|
525
|
+
}
|
|
526
|
+
async function diffConfig(config, opts = {}) {
|
|
527
|
+
if (!config.target_path && config.outputs.length === 0)
|
|
528
|
+
return "(reference \u2014 no target path)";
|
|
529
|
+
const diffs = [];
|
|
530
|
+
const store = opts.store ?? resolveConfigStore();
|
|
531
|
+
const contextConfigs = config.outputs.length > 0 || config.target_path ? await store.listConfigs() : [config];
|
|
532
|
+
if (isGeneratedOutputTarget(config, outputOwnerIdsByTarget(contextConfigs))) {
|
|
533
|
+
return "(generated output \u2014 managed by fan-out)";
|
|
534
|
+
}
|
|
535
|
+
const showSecrets = opts.showSecrets ?? false;
|
|
536
|
+
if (config.target_path) {
|
|
537
|
+
const diff = buildDiff(config.content, config.target_path, config.format, showSecrets);
|
|
538
|
+
if (!diff.includes("no diff"))
|
|
539
|
+
diffs.push(diff);
|
|
540
|
+
}
|
|
541
|
+
if (config.outputs.length > 0) {
|
|
542
|
+
for (const output of config.outputs) {
|
|
543
|
+
const expected = applyTransform(config, output, { configs: contextConfigs });
|
|
544
|
+
const diff = buildDiff(expected, output.target_path, detectFormat(output.target_path), showSecrets);
|
|
545
|
+
if (!diff.includes("no diff"))
|
|
546
|
+
diffs.push(diff);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return diffs.length > 0 ? diffs.join(`
|
|
550
|
+
|
|
551
|
+
`) : "(no diff \u2014 identical)";
|
|
552
|
+
}
|
|
553
|
+
function detectCategory(filePath) {
|
|
554
|
+
const p = filePath.toLowerCase().replace(getConfigHome(), "~");
|
|
555
|
+
if (p.includes("/.claude/rules/") || p.includes("/.cursor/rules/") || p.includes("/.agents/rules/") || p.endsWith("claude.md") || p.endsWith("agents.md") || p.endsWith("codewith.md") || p.endsWith("aicopilot.md") || p.endsWith("/.gemini/gemini.md") || p.endsWith(".mdc"))
|
|
556
|
+
return "rules";
|
|
557
|
+
if (p.includes(".mcp.json") || p.includes("mcp"))
|
|
558
|
+
return "mcp";
|
|
559
|
+
if (p.includes("/.claude/") || p.includes("/.codex/") || p.includes("/.antigravity/") || p.includes("/.agents/") || p.includes("/.cursor/") || p.includes("/.config/opencode/") || p.includes("/.codewith/") || p.includes("/.config/aicopilot/") || p.includes("/.qwen/"))
|
|
560
|
+
return "agent";
|
|
561
|
+
if (p.includes(".zshrc") || p.includes(".zprofile") || p.includes(".bashrc") || p.includes(".bash_profile"))
|
|
562
|
+
return "shell";
|
|
563
|
+
if (p.includes(".gitconfig") || p.includes(".gitignore"))
|
|
564
|
+
return "git";
|
|
565
|
+
if (p.includes(".npmrc") || p.includes("tsconfig") || p.includes("bunfig"))
|
|
566
|
+
return "tools";
|
|
567
|
+
if (p.includes(".secrets"))
|
|
568
|
+
return "secrets_schema";
|
|
569
|
+
return "tools";
|
|
570
|
+
}
|
|
571
|
+
function detectAgent(filePath) {
|
|
572
|
+
const p = filePath.toLowerCase().replace(getConfigHome(), "~");
|
|
573
|
+
if (p.includes("/.github/instructions/") || p.endsWith("/.github/copilot-instructions.md"))
|
|
574
|
+
return "copilot";
|
|
575
|
+
if (p.includes("/.devin/rules/"))
|
|
576
|
+
return "devin";
|
|
577
|
+
if (p.includes("/.windsurf/rules/"))
|
|
578
|
+
return "windsurf-legacy";
|
|
579
|
+
if (p.includes("/.clinerules/"))
|
|
580
|
+
return "cline";
|
|
581
|
+
if (p.endsWith("/.gemini/gemini.md") || p.endsWith("/.gemini/config/mcp_config.json"))
|
|
582
|
+
return "antigravity";
|
|
583
|
+
if (p.includes("/.agents/rules/") || p.endsWith("/.agents/mcp_config.json"))
|
|
584
|
+
return "antigravity";
|
|
585
|
+
if (p.includes("/.claude/") || p.endsWith("claude.md"))
|
|
586
|
+
return "claude";
|
|
587
|
+
if (p.includes("/.config/opencode/"))
|
|
588
|
+
return "opencode";
|
|
589
|
+
if (p.includes("/.cursor/") || p.endsWith(".mdc"))
|
|
590
|
+
return "cursor";
|
|
591
|
+
if (p.includes("/.codewith/") || p.endsWith("codewith.md"))
|
|
592
|
+
return "codewith";
|
|
593
|
+
if (p.includes("/.config/aicopilot/"))
|
|
594
|
+
return "aicopilot";
|
|
595
|
+
if (p.includes("/.qwen/"))
|
|
596
|
+
return "qwen";
|
|
597
|
+
if (p.includes("/.antigravity/"))
|
|
598
|
+
return "antigravity";
|
|
599
|
+
if (p.includes("/.codex/") || p.endsWith("agents.md"))
|
|
600
|
+
return "codex";
|
|
601
|
+
if (p.includes(".zshrc") || p.includes(".zprofile") || p.includes(".bashrc"))
|
|
602
|
+
return "zsh";
|
|
603
|
+
if (p.includes(".gitconfig") || p.includes(".gitignore"))
|
|
604
|
+
return "git";
|
|
605
|
+
if (p.includes(".npmrc"))
|
|
606
|
+
return "npm";
|
|
607
|
+
return "global";
|
|
608
|
+
}
|
|
609
|
+
function detectFormat(filePath) {
|
|
610
|
+
const ext = extname(filePath).toLowerCase();
|
|
611
|
+
if (ext === ".json")
|
|
612
|
+
return "json";
|
|
613
|
+
if (ext === ".toml")
|
|
614
|
+
return "toml";
|
|
615
|
+
if (ext === ".yaml" || ext === ".yml")
|
|
616
|
+
return "yaml";
|
|
617
|
+
if (ext === ".md" || ext === ".mdc" || ext === ".markdown")
|
|
618
|
+
return "markdown";
|
|
619
|
+
if (ext === ".ini" || ext === ".cfg")
|
|
620
|
+
return "ini";
|
|
621
|
+
return "text";
|
|
622
|
+
}
|
|
623
|
+
export { syncFromDir, syncToDir, CLAUDE_PROMPT_OUTPUTS, KNOWN_CONFIGS, PROJECT_CONFIG_FILES, syncProject, syncKnown, syncToDisk, diffConfig, detectCategory, detectAgent, detectFormat };
|