@krisada-m/ksd-intelligence 0.0.0-stage → 1.0.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.
Files changed (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +167 -2
  3. package/dist/adapters/agy/skills.js +252 -0
  4. package/dist/adapters/cli/check-changed.js +3 -0
  5. package/dist/adapters/cli/main.js +1002 -0
  6. package/dist/adapters/cli/policy-bin.js +10 -0
  7. package/dist/adapters/cli/review-verdict.js +3 -0
  8. package/dist/adapters/omp/extension.js +893 -0
  9. package/dist/adapters/omp/skills.js +130 -0
  10. package/dist/adapters/ui/hud.js +318 -0
  11. package/dist/adapters/ui/tree.js +460 -0
  12. package/dist/core/audit/index.js +2 -0
  13. package/dist/core/audit/log.js +505 -0
  14. package/dist/core/audit/summary.js +188 -0
  15. package/dist/core/changes/changes.js +591 -0
  16. package/dist/core/changes/git.js +266 -0
  17. package/dist/core/changes/plan.js +109 -0
  18. package/dist/core/changes/render.js +356 -0
  19. package/dist/core/engine/build.js +178 -0
  20. package/dist/core/engine/child.js +389 -0
  21. package/dist/core/engine/host.js +206 -0
  22. package/dist/core/engine/lock.js +133 -0
  23. package/dist/core/engine/protocol.js +43 -0
  24. package/dist/core/engine/runtime.js +44 -0
  25. package/dist/core/engine/status.js +381 -0
  26. package/dist/core/engine/typescript.js +194 -0
  27. package/dist/core/engine/workspace.js +72 -0
  28. package/dist/core/graph/graph.js +127 -0
  29. package/dist/core/graph/limits.js +16 -0
  30. package/dist/core/impact/query.js +1292 -0
  31. package/dist/core/impact/render.js +590 -0
  32. package/dist/core/impact/session.js +694 -0
  33. package/dist/core/indexing/declarations.js +455 -0
  34. package/dist/core/indexing/differential.js +345 -0
  35. package/dist/core/indexing/doctor.js +120 -0
  36. package/dist/core/indexing/indexer.js +792 -0
  37. package/dist/core/indexing/keys.js +451 -0
  38. package/dist/core/indexing/lexical.js +212 -0
  39. package/dist/core/indexing/packages.js +57 -0
  40. package/dist/core/indexing/program.js +171 -0
  41. package/dist/core/indexing/resolve.js +1004 -0
  42. package/dist/core/indexing/stamp.js +52 -0
  43. package/dist/core/indexing/surface.js +335 -0
  44. package/dist/core/indexing/ui-progress.js +37 -0
  45. package/dist/core/indexing/verify.js +76 -0
  46. package/dist/core/kernel/config.js +383 -0
  47. package/dist/core/kernel/glob.js +105 -0
  48. package/dist/core/kernel/guards.js +4 -0
  49. package/dist/core/kernel/types.js +3 -0
  50. package/dist/core/kernel/verdict.js +142 -0
  51. package/dist/core/knowledge/anchors.js +139 -0
  52. package/dist/core/knowledge/knowledge.js +95 -0
  53. package/dist/core/knowledge/learning.js +102 -0
  54. package/dist/core/knowledge/render.js +76 -0
  55. package/dist/core/knowledge/store.js +109 -0
  56. package/dist/core/knowledge/yaml.js +87 -0
  57. package/dist/core/search/lexical.js +382 -0
  58. package/dist/core/search/render.js +98 -0
  59. package/dist/core/search/segments.js +118 -0
  60. package/dist/core/verify/parse.js +127 -0
  61. package/dist/core/verify/render.js +67 -0
  62. package/dist/core/verify/report.js +40 -0
  63. package/dist/core/verify/revision.js +79 -0
  64. package/dist/core/verify/run.js +117 -0
  65. package/dist/core/verify/store.js +66 -0
  66. package/dist/core/verify/verify.js +173 -0
  67. package/dist/core/workspace/init.js +267 -0
  68. package/dist/core/workspace/probe.js +56 -0
  69. package/dist/core/workspace/scan.js +420 -0
  70. package/dist/index.js +20 -0
  71. package/dist/policy/change-scope.js +500 -0
  72. package/dist/policy/check-changed.js +40 -0
  73. package/dist/policy/config.js +106 -0
  74. package/dist/policy/dist/policy.d.ts +17 -0
  75. package/dist/policy/dist/policy.js +147 -0
  76. package/dist/policy/dist/runtime.d.ts +40 -0
  77. package/dist/policy/dist/runtime.js +75 -0
  78. package/dist/policy/dist/sdlc.d.ts +7 -0
  79. package/dist/policy/dist/sdlc.js +27 -0
  80. package/dist/policy/eslint-rules/index.js +107 -0
  81. package/dist/policy/index.d.ts +2 -0
  82. package/dist/policy/index.js +241 -0
  83. package/dist/policy/package.json +33 -0
  84. package/dist/policy/policy.d.ts +2 -0
  85. package/dist/policy/policy.js +2 -0
  86. package/dist/policy/review-verdict.js +262 -0
  87. package/dist/policy/sdlc.js +2 -0
  88. package/dist/storage/records.js +245 -0
  89. package/dist/storage/sqlite.js +314 -0
  90. package/dist/workflow/catalog.js +69 -0
  91. package/dist/workflow/classify.js +55 -0
  92. package/dist/workflow/loader.js +140 -0
  93. package/dist/workflow/packs.js +469 -0
  94. package/dist/workflow/registry.js +359 -0
  95. package/dist/workflow/render.js +61 -0
  96. package/dist/workflow/router.js +141 -0
  97. package/dist/workflow/sources.js +229 -0
  98. package/dist/workflow/types.js +44 -0
  99. package/dist/workflow/updates.js +532 -0
  100. package/package.json +74 -4
  101. package/scripts/agy-mcp.mjs +27 -0
  102. package/scripts/mcp/stdio.mjs +304 -0
  103. package/scripts/mcp/tools.mjs +451 -0
  104. package/skills/ksd-intelligence/SKILL.md +54 -0
  105. package/skills/matt-sdlc/SKILL.md +42 -0
  106. package/skills/osmani-quality/SKILL.md +38 -0
  107. package/skills/poteto-mode/SKILL.md +40 -0
  108. package/skills/pstack-analysis/SKILL.md +36 -0
  109. package/skills.lock.json +71 -0
  110. package/skills.registry.json +181 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Krisada M.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,168 @@
1
- # Temporary Holding Version
1
+ # ksd-intelligence
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ KSD helps you find TypeScript and JavaScript code, see what depends on a symbol before editing it, and review what an actual Git diff affects. It builds a private local SQLite index. It suggests checks; it does not run your tests, edit source, approve changes, or deploy. In Oh My Pi (OMP) it also supplies the KSD engineering policy and a skill workflow. Antigravity (AGY) uses the same analysis through local MCP stdio, without the OMP policy.
4
+
5
+ ## Install
6
+
7
+ Requirements: Git and **Node ≥ 22.5**; use Node 24 LTS. On Node 22.5–22.12 or 23.0–23.3, `node:sqlite` requires `NODE_OPTIONS=--experimental-sqlite`. Install project dependencies before indexing if the code relies on their types.
8
+
9
+ ### OMP: marketplace
10
+
11
+ If you already use `engineering-proxy@engineering-proxy`, uninstall it first (`omp plugin uninstall engineering-proxy@engineering-proxy`). Running both plugins can inject the policy twice.
12
+
13
+ ```sh
14
+ omp plugin marketplace add Krisada-M/ksd-intelligence
15
+ omp plugin install ksd-intelligence@ksd-intelligence
16
+ omp plugin list
17
+ ```
18
+
19
+ Restart OMP. Run `/engineering-proxy status` and check the KSD status segment. To get the `ei` shell command, install the npm package below; it does not replace the marketplace install. From a built checkout you can instead run `node dist/adapters/cli/main.js` in place of `ei`.
20
+
21
+ ### AGY and terminal: npm
22
+
23
+ After 1.0.0 is published:
24
+
25
+ ```sh
26
+ npm install -g @krisada-m/ksd-intelligence
27
+ ei setup
28
+ ```
29
+
30
+ The setup command provisions a pinned TypeScript runtime in your user cache and may contact the package registry. Verify it later with `ei setup --check`.
31
+
32
+ Configure AGY to launch `ei mcp --root /absolute/path/to/project`. In AGY's MCP settings, use:
33
+
34
+ ```json
35
+ {
36
+ "mcpServers": {
37
+ "ksd-intelligence": {
38
+ "command": "ei",
39
+ "args": ["mcp", "--root", "/absolute/path/to/project"],
40
+ "enabledTools": ["ei_status", "ei_impact", "ei_changes", "ei_search"]
41
+ }
42
+ }
43
+ }
44
+ ```
45
+
46
+ Use the absolute path to `ei` if AGY does not inherit your npm bin `PATH`. This is a stdio process, not an HTTP server. The root cannot change through a tool call; use a separate server entry for each project. To expose workflow, append `--workflow`, add `ei_workflow` to `enabledTools`, and set the skill roots below. See the [AGY guide](https://github.com/Krisada-M/ksd-intelligence/blob/main/docs/integrations/antigravity.md).
47
+
48
+ ## Set up a repository
49
+
50
+ Run from the project root:
51
+
52
+ ```sh
53
+ ei setup # once per runtime version
54
+ ei init --dry-run # inspect proposed paths and tsconfig coverage
55
+ ei init # skip existing config; review any new ei.config.json
56
+ ei index # publish first index
57
+ ei status
58
+ ```
59
+
60
+ The nearest `ei.config.json` sets the root; otherwise KSD uses the Git worktree root. Status reports the scanned/indexed/orphan/unindexed counts. An orphan has no owning TypeScript project. Edit `impact.include` to cover your sources **and tests**; add an appropriate `tsconfig.json` or `jsconfig.json` for unowned code. Review any extra paths before committing configuration.
61
+
62
+ ### Workflow skill sources
63
+
64
+ `ei_workflow` reads approved `SKILL.md` files from local checkouts; it does not fetch repositories or run skill scripts. Clone, inspect, and pin the sources yourself before enabling the workflow:
65
+
66
+ ```sh
67
+ mkdir -p "$HOME/ei-skill-sources"
68
+ git clone https://github.com/mattpocock/skills.git "$HOME/ei-skill-sources/matt"
69
+ git clone https://github.com/cursor/plugins.git "$HOME/ei-skill-sources/cursor-plugins"
70
+ git clone https://github.com/addyosmani/agent-skills.git "$HOME/ei-skill-sources/osmani"
71
+ git -C "$HOME/ei-skill-sources/matt" checkout 4ae2317ddb22b046e26455e4f9c9b3aaaf62212d
72
+ git -C "$HOME/ei-skill-sources/cursor-plugins" checkout 6b0300214a09fd6029cfb7077043125758cd1fd2
73
+ git -C "$HOME/ei-skill-sources/osmani" checkout 301b02b12bff98e4688e6984af6556802322bbde
74
+ export EI_MATT_ROOT="$HOME/ei-skill-sources/matt"
75
+ export EI_POTETO_ROOT="$HOME/ei-skill-sources/cursor-plugins"
76
+ export EI_OSMANI_ROOT="$HOME/ei-skill-sources/osmani"
77
+ ei sources check
78
+ ```
79
+
80
+ Set the variables in the host's environment and restart the host. Each points to a checkout root, not a `skills` directory. Treat skill text as untrusted instructions. Do not enable a second automatic workflow router.
81
+
82
+ ## Five tools
83
+
84
+ Actual output excerpts from the installed marketplace extension, invoked directly through OMP's extension loader. The CLI provides the same analysis and has the equivalents below. AGY exposes workflow only when opted in. See the [tool contract](https://github.com/Krisada-M/ksd-intelligence/blob/main/docs/TOOLS.md).
85
+
86
+ | Use | OMP tool | CLI equivalent |
87
+ |---|---|---|
88
+ | Check coverage and runtime | `ei_status` | `ei status` |
89
+ | Find an implementation | `ei_search` | `ei search 'sanitize audit text' --limit 2` |
90
+ | Check a symbol before editing | `ei_impact` | `ei impact 'src/core/kernel/glob.ts#matchGlob'` |
91
+ | Review the actual diff before saying done | `ei_changes` | `ei changes --base HEAD` |
92
+ | Get stage instructions from approved skills | `ei_workflow` | `ei load --task 'fix bug' --stage investigate --type bug` |
93
+
94
+ ```text
95
+ STATUS ready
96
+ ```
97
+
98
+ ```text
99
+ SEARCH "sanitize audit text" — 2 of 172 matches
100
+ ```
101
+
102
+ ```text
103
+ IMPACT matchGlob — src/core/kernel/glob.ts:96
104
+ ACTION check-gaps · level unknown · picture partial (2 gaps)
105
+ ```
106
+
107
+ ```text
108
+ CHANGES vs HEAD — nothing changed in the working tree.
109
+ ```
110
+
111
+ ```text
112
+ # KSD Workflow
113
+ KSD/project policy and explicit owner decisions take precedence over any skill text below.
114
+ Never merge or deploy without explicit approval. Report verification evidence.
115
+ ```
116
+
117
+ Workflow fails closed without the configured skill sources. For indexed work, follow the verdict: `run-tests` means run the listed tests; `check-gaps` means inspect the gaps; `ask-owner` means stop before editing. `proceed` is not proof of safety.
118
+
119
+ ## Configuration and privacy
120
+
121
+ | `ei.config.json` | Controls |
122
+ |---|---|
123
+ | `impact.include`, `impact.exclude` | Scope of compiler-backed TS/JS analysis |
124
+ | `impact.routes` | Explicit route path globs; no framework auto-detection |
125
+ | `impact.freshness` | `stat` (default) or `hash`. `ei_changes` always hashes |
126
+ | `impact.manyCallers`, `impact.commonName` | Verdict thresholds (default 10 each) |
127
+ | `impact.maxMemoryMb`, `impact.useWorkspaceTypescript` | Child memory limit; explicit opt-in to running the workspace's Compiler API instead of the pinned runtime |
128
+ | `riskZones` | `"default"` (payments, auth, migrations, production config), custom `{zone,floor,match}` entries, or `[]`. Zones only raise risk |
129
+ | `search.enabled` | Lexical search only |
130
+
131
+ Set `EI_DISABLED=1` before launching OMP or AGY to disable EI tools. Set `ENGINEERING_PROXY_DISABLED=1` before launching OMP to disable KSD policy injection and delegated review; KSD status remains available. Use both to disable both surfaces. KSD mode has separate configuration in `~/.omp/agent/engineering-proxy.json` and project `.engineering-proxy.json`.
132
+
133
+ Index and audit are local under `~/.cache/ksd-intelligence/`. SQLite keeps symbols, references, capped signature text and first JSDoc paragraphs, not whole source files. `ei audit --since 7d` summarizes tool use. `ei cache clear` deletes the current project's index and audit, **not** the shared runtime; it refuses during a live build.
134
+
135
+ ## KNOWN LIMITS
136
+
137
+ - `unknown` or `partial` means the indexed evidence cannot resolve the whole picture. Read the named gap sites. Report a wrong `low` immediately; stop relying on it until fixed.
138
+ - No runtime data flow, reflection/DI, external consumers, SQL schema effects, native effects, or arbitrary non-TS/JS caller analysis. TypeScript project coverage matters. Changed non-code paths can still be listed and raise a risk-zone verdict.
139
+ - `.env*`, private key files, default excluded trees, and non-code secret-named files are not read as source. Other code filenames are not screened for hard-coded secrets. Scoped-out code can produce lexical name hints without compiler-grade edges.
140
+ - A same-size edit with unchanged mtime can evade the stat probe. Use `impact.freshness: "hash"` or `ei index`, then `ei doctor --deep --differential 300` when checking suspect results.
141
+ - Worktrees have separate caches. Orphan-name guidance may only say `NOT FOUND`; comment-only changes can still list adjacent tests. A large excluded-code census can produce noisy name matches. Check status when `ei init --dry-run` does not display all expected configurations.
142
+ - Large repos can take minutes and several GB. The historical oh-my-pi cold build took 145 s and about 7.1 GB peak RSS on Linux. The default child memory cap is the smaller of 8192 MiB or half of RAM; narrow scope before raising it. These are not latency promises.
143
+ - **PLANNED (V2), not shipped:** golden `ei doctor` canary / `engine-self-check-failed`, automatic OMP-version mismatch warning, general per-capability `enabled` flags, standalone `ei symbol`, and a hard 5 s query budget. Also not shipped: automatic route discovery, heuristic bridges, watcher/worktree seeding, semantic search, context packs, GitLab, verification, learnings and compression. Existing config placeholders do not turn them on.
144
+
145
+ ## Troubleshoot, remove, or roll back
146
+
147
+ | Symptom | Action |
148
+ |---|---|
149
+ | `typescript runtime missing` | Run `ei setup`, then `ei setup --check`. |
150
+ | `NOT INDEXED`, zero callers, or `NOT FOUND` in mixed repositories | Check `ei status`, effective scope, project config ownership, and installed dependencies. Rails importmap resolution is not analyzed. |
151
+ | Stale result or slow build | Check the lock and memory in `ei status`. Run `ei index --full` if the index needs rebuilding. |
152
+ | `SKILLS_UNAVAILABLE` or hash mismatch | Check all three checkout roots, reviewed commits, and hashes with `ei sources check`. Do not re-pin unexplained changes. |
153
+ | No AGY tools | Confirm the MCP command starts, root is absolute, and host tool filter is correct. Inspect startup output in AGY rather than typing at the stdio process. |
154
+
155
+ ```sh
156
+ # Upgrade marketplace install; restart OMP afterward.
157
+ omp plugin marketplace update ksd-intelligence
158
+ omp plugin upgrade ksd-intelligence@ksd-intelligence
159
+
160
+ # Remove; optionally restore the old OMP policy plugin, never both at once.
161
+ omp plugin uninstall ksd-intelligence@ksd-intelligence
162
+ omp plugin install engineering-proxy@engineering-proxy
163
+
164
+ # Remove the AGY MCP entry and reload AGY, then remove the CLI.
165
+ npm uninstall -g @krisada-m/ksd-intelligence
166
+ ```
167
+
168
+ For npm rollback, reinstall a previous approved version or saved tarball, then run `ei setup` and `ei index --full`. Do not use the old index as evidence for the new version. Back up the audit log before `ei cache clear` if you need it. See the [changelog](CHANGELOG.md) and [release checklist](https://github.com/Krisada-M/ksd-intelligence/blob/main/docs/release-checklist.md) for verification and owner gates.
@@ -0,0 +1,252 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import { isAbsolute, join, relative, resolve } from 'node:path';
5
+ import { defaultSkillsDir, discoverSkillsForPlatform, } from '../../workflow/packs.js';
6
+ function isStringArray(value) {
7
+ return Array.isArray(value) && value.every((item) => typeof item === 'string');
8
+ }
9
+ function uniquePaths(paths) {
10
+ const seen = new Set();
11
+ const out = [];
12
+ for (const raw of paths) {
13
+ if (!raw)
14
+ continue;
15
+ const normalized = resolve(raw);
16
+ if (seen.has(normalized))
17
+ continue;
18
+ seen.add(normalized);
19
+ out.push(normalized);
20
+ }
21
+ return out;
22
+ }
23
+ // Resolves AGY workspace, Snap, global, shared, and KSD catalog paths dynamically
24
+ // using OS/Snap environment variables without hardcoding any username.
25
+ export function detectAgyPaths(options = {}) {
26
+ const env = options.env ?? process.env;
27
+ const realHome = options.homeDir ?? env.SNAP_REAL_HOME ?? env.HOME ?? homedir();
28
+ const ksdCatalogDir = resolve(options.skillsDir ?? defaultSkillsDir());
29
+ const workspaceSkillsDir = options.workspaceRoot
30
+ ? resolve(options.workspaceRoot, '.agents', 'skills')
31
+ : null;
32
+ const workspaceSkillsConfig = options.workspaceRoot
33
+ ? resolve(options.workspaceRoot, '.agents', 'skills.json')
34
+ : null;
35
+ const snapCandidates = [];
36
+ if (env.ANTIGRAVITY_APP_DATA_DIR) {
37
+ snapCandidates.push(join(env.ANTIGRAVITY_APP_DATA_DIR, 'skills'));
38
+ }
39
+ if (env.SNAP_USER_COMMON) {
40
+ snapCandidates.push(join(env.SNAP_USER_COMMON, '.gemini', 'antigravity-cli', 'skills'));
41
+ }
42
+ snapCandidates.push(join(realHome, 'snap', 'antigravity-cli', 'common', '.gemini', 'antigravity-cli', 'skills'));
43
+ const snapSkillsDirs = uniquePaths(snapCandidates);
44
+ const globalSkillsDirs = uniquePaths([
45
+ join(realHome, '.gemini', 'config', 'skills'),
46
+ join(realHome, '.gemini', 'antigravity-cli', 'skills'),
47
+ ]);
48
+ const sharedSkillsDir = resolve(realHome, '.agents', 'skills');
49
+ const detected = [];
50
+ if (workspaceSkillsDir) {
51
+ detected.push({
52
+ scope: 'workspace',
53
+ label: 'agy:workspace',
54
+ path: workspaceSkillsDir,
55
+ exists: existsSync(workspaceSkillsDir),
56
+ });
57
+ }
58
+ for (const dir of snapSkillsDirs) {
59
+ detected.push({ scope: 'snap', label: 'agy:snap', path: dir, exists: existsSync(dir) });
60
+ }
61
+ for (const dir of globalSkillsDirs) {
62
+ detected.push({ scope: 'global', label: 'agy:global', path: dir, exists: existsSync(dir) });
63
+ }
64
+ detected.push({
65
+ scope: 'shared',
66
+ label: 'agy:shared',
67
+ path: sharedSkillsDir,
68
+ exists: existsSync(sharedSkillsDir),
69
+ });
70
+ detected.push({
71
+ scope: 'catalog',
72
+ label: 'ksd:catalog',
73
+ path: ksdCatalogDir,
74
+ exists: existsSync(ksdCatalogDir),
75
+ });
76
+ const snapDetected = Boolean(env.SNAP_USER_COMMON || env.ANTIGRAVITY_APP_DATA_DIR) ||
77
+ snapSkillsDirs.some((dir) => existsSync(dir));
78
+ return {
79
+ realHome,
80
+ snapDetected,
81
+ workspaceSkillsDir,
82
+ workspaceSkillsConfig,
83
+ snapSkillsDirs,
84
+ globalSkillsDirs,
85
+ sharedSkillsDir,
86
+ ksdCatalogDir,
87
+ detected,
88
+ };
89
+ }
90
+ function resolveAgyConfigPath(rawPath, workspaceRoot, realHome) {
91
+ const trimmed = rawPath.trim();
92
+ if (!trimmed)
93
+ return null;
94
+ if (trimmed.startsWith('~/'))
95
+ return resolve(realHome, trimmed.slice(2));
96
+ return isAbsolute(trimmed) ? trimmed : resolve(workspaceRoot, trimmed);
97
+ }
98
+ async function readDeclaredAgyEntries(workspaceRoot, realHome) {
99
+ const configPath = join(workspaceRoot, '.agents', 'skills.json');
100
+ let raw;
101
+ try {
102
+ raw = await readFile(configPath, 'utf8');
103
+ }
104
+ catch {
105
+ return [];
106
+ }
107
+ let parsed;
108
+ try {
109
+ parsed = JSON.parse(raw);
110
+ }
111
+ catch {
112
+ return [];
113
+ }
114
+ if (typeof parsed !== 'object' || parsed === null || !('entries' in parsed))
115
+ return [];
116
+ const entries = parsed.entries;
117
+ if (!Array.isArray(entries))
118
+ return [];
119
+ const roots = [];
120
+ for (const item of entries) {
121
+ if (typeof item !== 'object' || item === null || !('path' in item))
122
+ continue;
123
+ const rawPath = item.path;
124
+ if (typeof rawPath !== 'string')
125
+ continue;
126
+ const resolved = resolveAgyConfigPath(rawPath, workspaceRoot, realHome);
127
+ if (!resolved)
128
+ continue;
129
+ const includeOnly = isStringArray(item.include_only)
130
+ ? item.include_only
131
+ : undefined;
132
+ const exclude = isStringArray(item.exclude)
133
+ ? item.exclude
134
+ : undefined;
135
+ roots.push({
136
+ path: resolved,
137
+ label: `agy:skills.json(${rawPath})`,
138
+ optional: false,
139
+ includeOnly,
140
+ exclude,
141
+ });
142
+ }
143
+ return roots;
144
+ }
145
+ // Builds a portable AGY `.agents/skills.json` entry without hardcoded user-home paths.
146
+ export function buildAgySkillsConfig(options = {}) {
147
+ const target = options.skillsDir ?? defaultSkillsDir();
148
+ const entryPath = options.workspaceRoot ? relative(options.workspaceRoot, target) || '.' : target;
149
+ const entry = { path: entryPath };
150
+ if (options.exclude && options.exclude.length > 0)
151
+ entry.exclude = [...options.exclude];
152
+ return { entries: [entry] };
153
+ }
154
+ // Native AGY skill discovery honoring AGY precedence:
155
+ // workspace `.agents/skills` > `.agents/skills.json` > snap > global/user > shared > KSD catalog.
156
+ export async function discoverAgySkills(options = {}) {
157
+ const paths = detectAgyPaths({
158
+ workspaceRoot: options.workspaceRoot,
159
+ env: options.env,
160
+ homeDir: options.homeDir,
161
+ skillsDir: options.skillsDir,
162
+ });
163
+ const roots = [];
164
+ const seenPaths = new Set();
165
+ const addRoot = (root) => {
166
+ const key = resolve(root.path);
167
+ if (seenPaths.has(key))
168
+ return;
169
+ seenPaths.add(key);
170
+ roots.push(root);
171
+ };
172
+ if (options.workspaceRoot) {
173
+ addRoot({
174
+ path: join(options.workspaceRoot, '.agents', 'skills'),
175
+ label: 'agy:workspace',
176
+ optional: true,
177
+ });
178
+ for (const declared of await readDeclaredAgyEntries(options.workspaceRoot, paths.realHome)) {
179
+ addRoot(declared);
180
+ }
181
+ }
182
+ if (options.snapSkillsDir) {
183
+ addRoot({
184
+ path: options.snapSkillsDir,
185
+ label: 'agy:snap',
186
+ optional: true,
187
+ allowExternalSymlinks: true,
188
+ auditContent: false,
189
+ });
190
+ }
191
+ else if (options.detectHostPaths) {
192
+ for (const snapDir of paths.snapSkillsDirs) {
193
+ addRoot({
194
+ path: snapDir,
195
+ label: 'agy:snap',
196
+ optional: true,
197
+ allowExternalSymlinks: true,
198
+ auditContent: false,
199
+ });
200
+ }
201
+ }
202
+ if (options.userSkillsDir) {
203
+ addRoot({
204
+ path: options.userSkillsDir,
205
+ label: 'agy:user',
206
+ optional: true,
207
+ allowExternalSymlinks: true,
208
+ auditContent: false,
209
+ });
210
+ }
211
+ else if (options.detectHostPaths) {
212
+ for (const globalDir of paths.globalSkillsDirs) {
213
+ addRoot({
214
+ path: globalDir,
215
+ label: 'agy:global',
216
+ optional: true,
217
+ allowExternalSymlinks: true,
218
+ auditContent: false,
219
+ });
220
+ }
221
+ }
222
+ if (options.sharedSkillsDir) {
223
+ addRoot({
224
+ path: options.sharedSkillsDir,
225
+ label: 'agy:shared',
226
+ optional: true,
227
+ allowExternalSymlinks: true,
228
+ auditContent: false,
229
+ });
230
+ }
231
+ else if (options.detectHostPaths) {
232
+ addRoot({
233
+ path: paths.sharedSkillsDir,
234
+ label: 'agy:shared',
235
+ optional: true,
236
+ allowExternalSymlinks: true,
237
+ auditContent: false,
238
+ });
239
+ }
240
+ addRoot({
241
+ path: paths.ksdCatalogDir,
242
+ label: 'ksd:catalog',
243
+ optional: false,
244
+ auditContent: true,
245
+ });
246
+ const discovery = await discoverSkillsForPlatform({
247
+ platform: 'agy',
248
+ roots,
249
+ requireCatalog: options.requireCatalog ?? true,
250
+ });
251
+ return { ...discovery, paths };
252
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { runPolicyBin } from './policy-bin.js';
3
+ await runPolicyBin(new URL('../../policy/check-changed.js', import.meta.url), 'ksd-check-changed --diff git.patch --eslint-report eslint.json');