pi-stacked-context 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stephen Zhang
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,157 @@
1
- # Temporary Holding Version
1
+ # pi-stacked-context
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
+ `pi-stacked-context` is a Pi extension that reuses skills you already keep for other agent harnesses.
4
+ It discovers skill roots on disk and hands the physical directories to Pi, which owns parsing, deduplication, name resolution, and invocation.
5
+
6
+ **Milestone status.** Configured skill discovery and its shared configuration layer are implemented in `master`.
7
+ Directory instructions, additive rule packs, the settings dialog, and the operational commands are not released yet; see the support matrix below.
8
+ The npm registry currently serves the `0.0.0-stage` placeholder that reserved the package name, so the next release-please release is the first installable version of this behavior.
9
+
10
+ ## Install
11
+
12
+ Pi installs the extension with any Pi package source:
13
+
14
+ ```bash
15
+ pi install npm:pi-stacked-context
16
+ ```
17
+
18
+ Start Pi in the project you want to enrich.
19
+ Startup and the native `/reload` command both run a fresh discovery pass, so no extra command is needed after changing settings or directories.
20
+
21
+ ## What skills discovery does
22
+
23
+ - Discovers existing harness directories instead of copying, converting, or synchronizing skills.
24
+ - Returns native physical paths as Pi `skillPaths` through the `resources_discover` event.
25
+ - Never reads `SKILL.md`, skill frontmatter, hooks, or bundled scripts.
26
+ - Deduplicates candidates by physical path, so one directory is never submitted twice.
27
+ - Sorts results deterministically for reproducible output; that order is not skill-name precedence.
28
+
29
+ Pi performs the rest of the work: recursive discovery below each root, frontmatter validation, duplicate-name handling, prompt listing, and skill loading.
30
+
31
+ ## Zero configuration
32
+
33
+ With no settings files the extension uses four built-in adapters.
34
+
35
+ | Adapter | Global directory | Project pattern |
36
+ | --- | --- | --- |
37
+ | `agents` | `$HOME/.agents` | `**/.agents` |
38
+ | `claude` | `$HOME/.claude` | `**/.claude` |
39
+ | `opencode` | `$HOME/.config/opencode` | `**/.opencode` |
40
+ | `dsh` | `${DSH_HOME:-~/.dsh}` | `**/.dsh` |
41
+
42
+ Every resolved or matched directory receives exactly one `skills` child unless its basename is already `skills`.
43
+ `.claude` and `.claude/skills` are therefore both accepted, and `skills/skills` is never produced.
44
+ Global values accept `$NAME`, `${NAME}`, `${NAME:-default}`, and `~` expansion without invoking a shell.
45
+ Project patterns are workspace-root globs and are never resolved relative to `~/.pi/agent`.
46
+
47
+ ## Workspace roots
48
+
49
+ Project patterns are evaluated from the nearest workspace marker, not from the current directory depth.
50
+
51
+ - `discovery.rootPatterns` defaults to `[".git", ".repo"]`.
52
+ - A marker may be a file or a directory, so worktrees and submodules work.
53
+ - An empty list disables the upward search and keeps discovery at the session cwd.
54
+ - Patterns identify a marker basename; absolute paths, separators, `..`, and wildcard-only patterns such as `*`, `**`, or `?*` are rejected.
55
+
56
+ With root `repo` and cwd `repo/A/B`, `.claude` matches only `repo/.claude` while `**/.claude` matches `.claude` at every depth below `repo`.
57
+
58
+ ## Ignores
59
+
60
+ Project scans always skip `.git`, `node_modules`, `dist`, `build`, `out`, `target`, `coverage`, `.next`, and `.turbo`.
61
+ `discovery.additionalIgnorePaths` appends workspace-relative directory patterns for generated or vendor trees, and it cannot remove a built-in ignore.
62
+ Ignore and adapter patterns must contain literal path text and must not start with `!`, so a wildcard-only or negated entry cannot prune the whole scan.
63
+ Directory symlinks are never followed during project scans, so recursive cycles cannot hang discovery and project candidates that resolve outside the workspace are skipped.
64
+ Explicit user-level global directories may resolve through symlinks.
65
+
66
+ ## Configuration
67
+
68
+ ```text
69
+ Global: ~/.pi/agent/stacked-context/settings.json
70
+ Project: <cwd>/.pi/stacked-context/settings.json
71
+ ```
72
+
73
+ Examples:
74
+
75
+ ```json
76
+ {
77
+ "version": 1,
78
+ "discovery": {
79
+ "rootPatterns": [".git", ".repo"],
80
+ "additionalIgnorePaths": ["vendor/generated"]
81
+ },
82
+ "skills": {
83
+ "enabled": true,
84
+ "adapters": {
85
+ "claude": { "global": null, "project": "packages/**/.claude" },
86
+ "company": { "global": "$HOME/.company", "project": "**/.company" }
87
+ }
88
+ },
89
+ "instructions": { "enabled": true, "maxFileBytes": 32768 },
90
+ "rules": { "enabled": true, "maxBundleBytes": 65536 },
91
+ "ui": { "showStatus": true, "showWarnings": true }
92
+ }
93
+ ```
94
+
95
+ Merging rules:
96
+
97
+ - Adapter fields are independent: an absent field inherits, `null` or a blank string disables that channel, and a non-empty string overrides.
98
+ - Feature switches use `global && project`, so a project can disable a feature but never re-enable a globally disabled one.
99
+ - Budgets select the smallest configured value; every budget is an integer from 1 through 1048576 bytes.
100
+ - `discovery.rootPatterns` replaces the list atomically, while `discovery.additionalIgnorePaths` appends.
101
+ - `ui` settings are global-only.
102
+ - An unsupported `version`, an unknown field, or an invalid field type is reported per field without discarding unrelated valid settings.
103
+ - Persistence is delegated to `pi-extension-settings-tui`, which owns atomic writes, size limits, and symlink refusal.
104
+
105
+ ## Project trust
106
+
107
+ Project settings are read only when Pi reports the project as trusted through `ctx.isProjectTrusted()`.
108
+ An untrusted project keeps the global configuration, and the extension records that the project layer was not loaded.
109
+ Project settings cannot raise a global budget, re-enable a disabled feature, or change user-level `ui` settings.
110
+
111
+ ## Reload
112
+
113
+ Native `/reload` reconstructs configuration and candidates from disk.
114
+ There is no extension reload command and no filesystem watcher; every discovery pass recomputes its result, so added directories appear and removed directories disappear after reload.
115
+
116
+ ## Diagnostics
117
+
118
+ Each discovery pass collects diagnostics for settings problems, adapter values, workspace root and ignore policy, unreadable scan directories, missing or unreadable candidates, glob evaluation failures, duplicates, and candidates outside the workspace.
119
+ Sensitive environment values are never printed; a missing variable is reported by name only.
120
+ A read-only `/stacked-context status` command that renders these diagnostics is not released yet.
121
+
122
+ ## Support matrix
123
+
124
+ | Area | Status |
125
+ | --- | --- |
126
+ | Configured skill discovery (`resources_discover` / `skillPaths`) | Released in this milestone |
127
+ | Shared configuration: adapters, root patterns, ignores, budgets, trust | Released in this milestone |
128
+ | Directory instructions (`AGENTS.md` / `CLAUDE.md` injection) | Not yet released |
129
+ | Additive rule packs (`.agents/rules`, `.claude/rules`) | Not yet released |
130
+ | `/stacked-context settings`, `/stacked-context status`, `/stacked-context explain` | Not yet released |
131
+ | Settings dialog and provenance display | Not yet released |
132
+ | Repository text policy check (`npm run check:text`) | Available for contributors |
133
+
134
+ ## Development
135
+
136
+ Requires Node.js 22.19 or newer.
137
+
138
+ ```bash
139
+ npm ci
140
+ npm run check
141
+ ```
142
+
143
+ `npm run check` runs the text policy check, Biome formatting and linting, TypeScript typechecking, and the Vitest suite.
144
+
145
+ See `CONTRIBUTING.md` and `AGENTS.md` for engineering and release rules.
146
+ Accepted behavior is documented under [`docs/superpowers/specs/`](./docs/superpowers/specs/), and execution status is indexed by [`docs/superpowers/STATUS.md`](./docs/superpowers/STATUS.md).
147
+
148
+ ## Release process
149
+
150
+ Versions, tags, changelogs, and GitHub releases are owned by release-please.
151
+ Functional milestones are released serially.
152
+ Each milestone updates this README, waits for CI, and merges only its corresponding release PR with `gh pr merge <release-pr> --rebase --delete-branch`.
153
+ GitHub Actions verifies the tagged package and publishes through npm Trusted Publishing using the official npm registry.
154
+ The next milestone starts only after publication is verified.
155
+
156
+ The one-time `0.0.0-stage` registry-only placeholder was manually published to reserve the npm name.
157
+ It contains only a stub `package.json` and README, has no tag, and leaves the release-please manifest at `0.0.0`.
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "pi-stacked-context",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Pi extension that discovers cross-harness skill roots and applies layered global and project settings",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "sideEffects": false,
8
+ "keywords": [
9
+ "pi-package",
10
+ "pi-extension",
11
+ "pi-coding-agent",
12
+ "context",
13
+ "skills"
14
+ ],
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/zhang-stephen/pi-stacked-context.git"
19
+ },
20
+ "engines": {
21
+ "node": ">=22.19.0"
22
+ },
23
+ "files": [
24
+ "src/",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "pi": {
29
+ "extensions": [
30
+ "./src/index.ts"
31
+ ]
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "provenance": true,
36
+ "registry": "https://registry.npmjs.org"
37
+ },
38
+ "scripts": {
39
+ "check:text": "node scripts/check-text.mjs",
40
+ "format": "biome format --write .",
41
+ "format:check": "biome format .",
42
+ "lint": "biome lint .",
43
+ "typecheck": "tsc --noEmit",
44
+ "test": "vitest run",
45
+ "check": "npm run check:text && npm run format:check && npm run lint && npm run typecheck && npm test"
46
+ },
47
+ "peerDependencies": {
48
+ "@earendil-works/pi-coding-agent": "*"
49
+ },
50
+ "devDependencies": {
51
+ "@biomejs/biome": "^2.0.0",
52
+ "@earendil-works/pi-coding-agent": "^1.8.0",
53
+ "@types/node": "^24.0.0",
54
+ "typescript": "^5.9.0",
55
+ "vitest": "^4.0.0",
56
+ "yaml": "^2.9.1"
57
+ },
58
+ "dependencies": {
59
+ "pi-extension-settings-tui": "^0.9.1",
60
+ "tinyglobby": "^0.2.17"
61
+ }
62
+ }
@@ -0,0 +1,76 @@
1
+ import type { EffectiveConfig, SkillAdapter } from "../shared/types.js";
2
+
3
+ export const CONFIG_VERSION = 1;
4
+
5
+ /** Schema-level budget bounds. Values outside this range are rejected or clamped. */
6
+ export const BUDGET_MIN_BYTES = 1;
7
+ export const BUDGET_MAX_BYTES = 1048576;
8
+
9
+ export const DEFAULT_ROOT_PATTERNS = [".git", ".repo"];
10
+
11
+ /**
12
+ * Built-in scan ignores. Additional ignore settings are appended and cannot
13
+ * remove these entries.
14
+ */
15
+ export const BUILT_IN_IGNORE_PATHS = [
16
+ ".git",
17
+ "node_modules",
18
+ "dist",
19
+ "build",
20
+ "out",
21
+ "target",
22
+ "coverage",
23
+ ".next",
24
+ ".turbo",
25
+ ];
26
+
27
+ /**
28
+ * Raw adapter defaults. `global` values keep their documented `$HOME` and
29
+ * `${VAR:-default}` forms; they are expanded during discovery, not here.
30
+ */
31
+ export const DEFAULT_ADAPTERS: Record<string, SkillAdapter> = {
32
+ agents: { global: "$HOME/.agents", project: "**/.agents" },
33
+ claude: { global: "$HOME/.claude", project: "**/.claude" },
34
+ opencode: { global: "$HOME/.config/opencode", project: "**/.opencode" },
35
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: raw default keeps the documented environment form.
36
+ dsh: { global: "${DSH_HOME:-~/.dsh}", project: "**/.dsh" },
37
+ };
38
+
39
+ export function createDefaultConfig(): EffectiveConfig {
40
+ return {
41
+ version: CONFIG_VERSION,
42
+ discovery: {
43
+ rootPatterns: [...DEFAULT_ROOT_PATTERNS],
44
+ additionalIgnorePaths: [],
45
+ },
46
+ skills: {
47
+ enabled: true,
48
+ adapters: cloneAdapters(DEFAULT_ADAPTERS),
49
+ },
50
+ instructions: {
51
+ enabled: true,
52
+ maxFileBytes: 32768,
53
+ maxInjectionBytes: 65536,
54
+ maxVisibleBytes: 65536,
55
+ },
56
+ rules: {
57
+ enabled: true,
58
+ maxBundleBytes: 65536,
59
+ },
60
+ ui: {
61
+ showStatus: true,
62
+ showWarnings: true,
63
+ },
64
+ };
65
+ }
66
+
67
+ function cloneAdapters(adapters: Record<string, SkillAdapter>): Record<string, SkillAdapter> {
68
+ const cloned: Record<string, SkillAdapter> = {};
69
+ for (const [name, adapter] of Object.entries(adapters)) {
70
+ cloned[name] = { global: adapter.global, project: adapter.project };
71
+ }
72
+ return cloned;
73
+ }
74
+
75
+ /** The zero-configuration effective settings, used as the merge base. */
76
+ export const defaults: EffectiveConfig = createDefaultConfig();