@sangyaahub/pi-marg 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 (71) hide show
  1. package/.mcp.json +12 -0
  2. package/.omp-plugin/marketplace.json +42 -0
  3. package/BRAND.md +25 -0
  4. package/CHANGELOG.md +11 -0
  5. package/CODE_OF_CONDUCT.md +9 -0
  6. package/CONTRIBUTING.md +11 -0
  7. package/LICENSE +21 -0
  8. package/MODEL-SETUP.md +73 -0
  9. package/PUBLISHING.md +53 -0
  10. package/README.md +191 -0
  11. package/SECURITY.md +11 -0
  12. package/SUPPORT.md +7 -0
  13. package/adapters/omp/extensions/approval-guard.ts +43 -0
  14. package/adapters/omp/extensions/model-router.ts +56 -0
  15. package/adapters/omp/extensions/runtime-capabilities.ts +24 -0
  16. package/adapters/pi/extensions/approval-guard.ts +39 -0
  17. package/adapters/pi/extensions/model-router.ts +61 -0
  18. package/adapters/pi/extensions/runtime-capabilities.ts +25 -0
  19. package/adapters/pi/extensions/workflow-bootstrap.ts +7 -0
  20. package/adapters/pi/prompts/auto-close.md +11 -0
  21. package/adapters/pi/prompts/auto-commit.md +7 -0
  22. package/adapters/pi/prompts/auto-models.md +12 -0
  23. package/adapters/pi/prompts/auto-reset.md +8 -0
  24. package/adapters/pi/prompts/auto-review.md +11 -0
  25. package/adapters/pi/prompts/auto-runtime.md +13 -0
  26. package/adapters/pi/prompts/auto-status.md +17 -0
  27. package/adapters/pi/prompts/auto.md +12 -0
  28. package/agents/auto-builder.md +10 -0
  29. package/agents/auto-business-analyst.md +9 -0
  30. package/agents/auto-debugger.md +10 -0
  31. package/agents/auto-intake.md +10 -0
  32. package/agents/auto-lessons-writer.md +10 -0
  33. package/agents/auto-qa.md +9 -0
  34. package/agents/auto-reviewer.md +9 -0
  35. package/agents/auto-security-reviewer.md +9 -0
  36. package/agents/auto-strategist.md +10 -0
  37. package/assets/brand/sangyaa-mark.png +0 -0
  38. package/assets/pi-marg-banner-source.html +106 -0
  39. package/assets/pi-marg-banner.png +0 -0
  40. package/commands/auto-close.md +11 -0
  41. package/commands/auto-commit.md +7 -0
  42. package/commands/auto-models.md +12 -0
  43. package/commands/auto-reset.md +8 -0
  44. package/commands/auto-review.md +11 -0
  45. package/commands/auto-runtime.md +13 -0
  46. package/commands/auto-status.md +17 -0
  47. package/commands/auto.md +12 -0
  48. package/core/approval-policy.ts +109 -0
  49. package/core/model-routing.ts +348 -0
  50. package/core/runtime-capabilities.ts +77 -0
  51. package/core/workflow-policy.ts +3 -0
  52. package/package.json +84 -0
  53. package/rules/auto-mode.md +32 -0
  54. package/scripts/check-prerequisites.sh +37 -0
  55. package/scripts/install.sh +74 -0
  56. package/scripts/setup-codegraph.sh +62 -0
  57. package/scripts/validate.sh +75 -0
  58. package/skills/auto-mode-addons/SKILL.md +15 -0
  59. package/skills/auto-mode-addons/references/cost-control.md +24 -0
  60. package/skills/auto-mode-addons/references/hindsight.md +54 -0
  61. package/skills/auto-mode-addons/references/language-skills.md +54 -0
  62. package/skills/auto-mode-addons/references/ponytail.md +41 -0
  63. package/skills/auto-mode-router/SKILL.md +22 -0
  64. package/skills/auto-mode-router/references/intake-and-state.md +124 -0
  65. package/skills/auto-mode-router/references/models-and-tools.md +74 -0
  66. package/skills/auto-mode-router/references/native-omp-runtime.md +88 -0
  67. package/skills/auto-mode-router/references/native-pi-runtime.md +52 -0
  68. package/skills/auto-mode-router/references/routing-matrix.md +99 -0
  69. package/skills/auto-mode-router/references/session-ledger.md +92 -0
  70. package/skills/codegraph-first/SKILL.md +34 -0
  71. package/skills/session-lessons/SKILL.md +34 -0
package/.mcp.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "mcpServers": {
3
+ "codegraph": {
4
+ "type": "stdio",
5
+ "command": "codegraph",
6
+ "args": [
7
+ "serve",
8
+ "--mcp"
9
+ ]
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "$schema": "https://anthropic.com/claude-code/marketplace.schema.json",
3
+ "name": "pi-marg-marketplace",
4
+ "owner": {
5
+ "name": "Sangyaa",
6
+ "email": "contact@sangyaa.co"
7
+ },
8
+ "metadata": {
9
+ "description": "PiMarg — a governed development path for Pi Agent and Oh My Pi.",
10
+ "version": "1.0.0"
11
+ },
12
+ "plugins": [
13
+ {
14
+ "name": "pi-marg",
15
+ "description": "Intent-led development workflow with live A/B/C/D routing, capability detection, verification, and approval gates.",
16
+ "source": "./",
17
+ "version": "1.0.0",
18
+ "author": {
19
+ "name": "Sangyaa",
20
+ "email": "contact@sangyaa.co"
21
+ },
22
+ "homepage": "https://github.com/sangyaahub/pi-marg",
23
+ "repository": "https://github.com/sangyaahub/pi-marg.git",
24
+ "license": "MIT",
25
+ "category": "development",
26
+ "keywords": [
27
+ "pi",
28
+ "omp",
29
+ "workflow",
30
+ "model-routing",
31
+ "codegraph",
32
+ "approvals"
33
+ ],
34
+ "tags": [
35
+ "pi-agent",
36
+ "oh-my-pi",
37
+ "multi-model",
38
+ "governed-workflow"
39
+ ]
40
+ }
41
+ ]
42
+ }
package/BRAND.md ADDED
@@ -0,0 +1,25 @@
1
+ # PiMarg brand
2
+
3
+ PiMarg is an open-source project by [Sangyaa](https://sangyaa.co).
4
+
5
+ ## Assets
6
+
7
+ - `assets/pi-marg-banner.png` is the public repository and Pi catalog preview.
8
+ - `assets/brand/sangyaa-mark.png` is the official Sangyaa mark sourced from `sangyaa.co` on 2026-09-09.
9
+ - `assets/pi-marg-banner-source.html` is the editable, offline source for the banner.
10
+
11
+ ## Palette
12
+
13
+ | Use | Colour |
14
+ |---|---|
15
+ | Sangyaa blue | `#0451F7` |
16
+ | Deep blue | `#021E5C` |
17
+ | Gold | `#C27B1A` |
18
+ | Warm white | `#FAFAF7` |
19
+ | Ink | `#161614` |
20
+
21
+ The product name is written **PiMarg** in prose and `pi-marg` in package, plugin, and repository identifiers.
22
+
23
+ ## Permission
24
+
25
+ The software is licensed under MIT. The Sangyaa name and logo remain brand identifiers of Sangyaa; the MIT license does not grant permission to imply Sangyaa endorsement of a modified or unrelated product. Forks may accurately describe their origin and should make material modifications clear.
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 — 2026-09-08
4
+
5
+ - First PiMarg release for Pi Agent and Oh My Pi.
6
+ - Sangyaa visual identity, public repository metadata, npm package metadata, and OMP marketplace catalog.
7
+ - Shared A/B/C/D model-routing core with distinct-reviewer enforcement.
8
+ - Runtime-specific adapters for schemas, session events, model discovery, protected inputs, and automatic Pi workflow entry.
9
+ - Capability-gated CodeGraph, LSP, task, Advisor, review, memory, UI, debugger, and security routes.
10
+ - One-use approval guard for destructive actions, pushes, merges, sharing, and web publication.
11
+ - Responsive, offline interactive workflow demo.
@@ -0,0 +1,9 @@
1
+ # Code of Conduct
2
+
3
+ PiMarg welcomes people of every background and experience level. Be respectful, assume good intent while checking facts, critique ideas rather than people, and keep discussions focused on improving the project.
4
+
5
+ Harassment, discrimination, threats, doxxing, sexualized attention, and deliberately disruptive conduct are not accepted in project spaces.
6
+
7
+ Report conduct concerns privately to `contact@sangyaa.co`. Maintainers may edit or remove content, restrict participation, or take other proportionate action to protect the community. Reports will be handled as privately as practical.
8
+
9
+ This policy applies in repository spaces and when someone is representing PiMarg or Sangyaa in public project activity.
@@ -0,0 +1,11 @@
1
+ # Contributing
2
+
3
+ Thank you for improving PiMarg.
4
+
5
+ 1. Open an issue or discussion for material workflow or compatibility changes.
6
+ 2. Keep shared decisions in `core/` and runtime differences in `adapters/pi/` or `adapters/omp/`.
7
+ 3. Do not weaken the A/C or B/D separation rule, evidence gates, or protected-action defaults without an explicit security rationale.
8
+ 4. Run `./scripts/validate.sh` and `bun test tests`.
9
+ 5. Describe which Pi and OMP versions you tested and any capability left unverified.
10
+
11
+ By submitting a contribution, you agree that it may be distributed under this repository's MIT License.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sangyaa and PiMarg contributors
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/MODEL-SETUP.md ADDED
@@ -0,0 +1,73 @@
1
+ # Model setup
2
+
3
+ PiMarg reads the active Pi or OMP model registry whenever `auto_model_route` runs. Exact selectors are deliberately absent from this document because providers rename and replace models.
4
+
5
+ ```text
6
+ LIVE AUTHENTICATED CATALOG
7
+ │
8
+ ┌──────┴──────┐
9
+ ▼ ▼
10
+ frontier execution
11
+ A / C B / D
12
+ │ │
13
+ └─ different ─┘ within each pair
14
+ ```
15
+
16
+ ## Roles
17
+
18
+ | Stage | Purpose | Preferred class |
19
+ |---|---|---|
20
+ | A | Discovery and difficult reasoning | Latest eligible Claude frontier, OpenAI frontier, or Grok frontier |
21
+ | C | Independent plan review | A different frontier model/family from A |
22
+ | B | Execute the accepted plan | Claude/OpenAI mid-layer, Cursor Composer, eligible zero-metered route, or Devin SWE |
23
+ | D | Independent implementation review | A different execution model/family from B |
24
+
25
+ “Zero-metered” means the runtime reports zero token price for that route. Subscription quotas and pool limits can still apply.
26
+
27
+ ## Pi Agent
28
+
29
+ Use Pi's normal provider configuration or environment variables, then verify availability with:
30
+
31
+ ```bash
32
+ pi --list-models
33
+ ```
34
+
35
+ The Pi adapter reads `ctx.scopedModels` when the session has a model allowlist; otherwise it reads `ctx.modelRegistry.getAvailable()`. This respects both authentication and an intentional session scope.
36
+
37
+ ## Oh My Pi
38
+
39
+ Use OMP `/login`, then inspect `/model` or:
40
+
41
+ ```bash
42
+ omp models list
43
+ ```
44
+
45
+ The OMP adapter reads `ctx.models.list()` and activates an exact catalog entry with `pi.setModel()`.
46
+
47
+ ## Selection workflow
48
+
49
+ 1. Run `/auto-models choose`.
50
+ 2. Request `action: catalog` with the confirmed work type.
51
+ 3. Select A and C from frontier candidates.
52
+ 4. Select B and D when implementation is required.
53
+ 5. Resolve any A=C or B=D identity conflict before continuing.
54
+ 6. Activate the saved selector immediately before its stage.
55
+
56
+ The normalized identity check treats the same underlying model reached through different providers as the same candidate when their identifiers normalize equally.
57
+
58
+ ## Devin
59
+
60
+ Native Devin model entries are ordinary B/D candidates when the runtime catalog exposes them. A separate external Devin session appears only when a Devin tool is detected. Creating that session is a web mutation and requires one-use `post-web` approval.
61
+
62
+ ## Advisor and supplemental reviewers
63
+
64
+ The selected C and D models are the authoritative reviewers. OMP Advisor, a Pi reviewer extension, or another watcher may supplement them only when detected; it must not replace the distinct-model contract.
65
+
66
+ ## Cost defaults
67
+
68
+ - Give A one bounded discovery pass.
69
+ - Give C the plan, acceptance criteria, assumptions, and risks—not the whole repository.
70
+ - Use a capable mid-layer or included route for routine B execution.
71
+ - Give D the diff, CodeGraph impact, decisions, and test evidence.
72
+ - Escalate B or D to a frontier model only after concrete failure or for genuinely high-risk work.
73
+ - Record model, stage, outcome, and available usage data so optimization measures cost per accepted result.
package/PUBLISHING.md ADDED
@@ -0,0 +1,53 @@
1
+ # Publishing PiMarg
2
+
3
+ This checklist is for maintainers. Public mutations remain subject to PiMarg's one-use approval gates.
4
+
5
+ ## Before a release
6
+
7
+ 1. Update `package.json`, `.omp-plugin/marketplace.json`, and `CHANGELOG.md` to the same version.
8
+ 2. Run `./scripts/validate.sh`, `bun test tests`, and `npm pack --dry-run`.
9
+ 3. Smoke-test the package root with the supported Pi and OMP versions.
10
+ 4. Inspect the packed file list for secrets, generated debris, and missing runtime files.
11
+
12
+ ## GitHub and OMP
13
+
14
+ The public `sangyaahub/pi-marg` repository is itself an OMP marketplace because it contains `.omp-plugin/marketplace.json`.
15
+
16
+ Users add and install it with:
17
+
18
+ ```bash
19
+ omp plugin marketplace add sangyaahub/pi-marg
20
+ omp plugin install --scope user pi-marg@pi-marg-marketplace
21
+ ```
22
+
23
+ Create an annotated `v<version>` tag and GitHub release only after the matching commit is on `main` and the checks pass.
24
+
25
+ ## Pi package catalog
26
+
27
+ Pi's package catalog discovers public npm packages carrying the `pi-package` keyword. PiMarg is published under SangyaaHub's npm scope as `@sangyaahub/pi-marg`.
28
+
29
+ First publication requires an npm-authenticated maintainer:
30
+
31
+ ```bash
32
+ npm whoami
33
+ npm publish --access public
34
+ ```
35
+
36
+ After npm indexes the package, search for `@sangyaahub/pi-marg` at `https://pi.dev/packages` and verify:
37
+
38
+ ```bash
39
+ pi install npm:@sangyaahub/pi-marg
40
+ ```
41
+
42
+ For later releases, prefer npm trusted publishing with GitHub OIDC and provenance instead of a long-lived repository token. Never commit npm credentials.
43
+
44
+ ## Approval order
45
+
46
+ Use a fresh, exact one-use approval immediately before each public action:
47
+
48
+ ```text
49
+ APPROVE ACTION: post-web
50
+ APPROVE ACTION: push-main
51
+ ```
52
+
53
+ Repository creation, GitHub release creation, and npm publication are separate `post-web` actions. A main-branch push uses `push-main`.
package/README.md ADDED
@@ -0,0 +1,191 @@
1
+ <p align="center">
2
+ <img src="assets/pi-marg-banner.png" alt="PiMarg by Sangyaa — the governed development path for Pi Agent and Oh My Pi" width="100%">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://github.com/sangyaahub/pi-marg/releases"><img alt="Version 1.0.0" src="https://img.shields.io/badge/version-1.0.0-0451F7"></a>
7
+ <a href="LICENSE"><img alt="MIT License" src="https://img.shields.io/badge/license-MIT-C27B1A"></a>
8
+ <a href="https://pi.dev/packages?name=pi-marg"><img alt="Pi package" src="https://img.shields.io/badge/Pi-package-0338A8"></a>
9
+ <a href="https://omp.sh"><img alt="Oh My Pi plugin" src="https://img.shields.io/badge/OMP-plugin-021E5C"></a>
10
+ </p>
11
+
12
+ # PiMarg
13
+
14
+ **Version 1.0.0 · MIT licensed · Pi Agent + Oh My Pi · by [Sangyaa](https://sangyaa.co)**
15
+
16
+ PiMarg turns an ordinary prompt into a governed development path. It identifies the work boundary, selects one engineering method, discovers the models and tools the active runtime really provides, separates thinking from execution, records evidence, and stops before protected actions.
17
+
18
+ ```text
19
+ shared workflow core
20
+ intent · models · approvals · evidence
21
+ │
22
+ ┌────────────┴────────────┐
23
+ ▼ ▼
24
+ Pi adapter OMP adapter
25
+ TypeBox · Pi events Zod · OMP events
26
+ │ │
27
+ └────────────┬────────────┘
28
+ ▼
29
+ A discover → C plan review → plan gate
30
+ │
31
+ ▼
32
+ B build → verify → D review
33
+ │
34
+ ▼
35
+ security when needed → lessons
36
+ ```
37
+
38
+ The same model-selection and approval logic lives in `core/`. Runtime-specific code is limited to `adapters/pi/` and `adapters/omp/`.
39
+
40
+ ## Why PiMarg
41
+
42
+ - Confirms job/client versus personal work; job/client mode suppresses Sangyaa branding by default.
43
+ - Routes seven work types: idea, new feature, improvement, proactive bug fix, security, repository analysis, and business/sales analysis.
44
+ - Uses one primary Compound Engineering, Superpowers, GSD Core, or automatically selected workflow spine.
45
+ - Discovers current authenticated model selectors instead of pinning dated model names.
46
+ - Enforces that A and C use different underlying models, and B and D use different underlying models.
47
+ - Uses CodeGraph for repository architecture and impact when available, with LSP/AST or repository-native tools for exact code questions.
48
+ - Adds conditional testing, debugger, browser/desktop, security, Advisor, task, and memory routes only when detected.
49
+ - Tracks the plan, decisions, evidence, and one lesson under `.agent-work/sessions/`.
50
+ - Requires a one-use approval before delete/remove, push, merge, web publication, session sharing, or external-agent creation.
51
+
52
+ ## Compatibility
53
+
54
+ | Capability | Pi Agent | Oh My Pi |
55
+ |---|---|---|
56
+ | Ordinary prompts enter the workflow | Pi bootstrap hook | OMP global rule |
57
+ | Shared skills and decision flow | Yes | Yes |
58
+ | Dynamic A/B/C/D model routing | Pi model registry | OMP model registry |
59
+ | Approval guard | Pi event adapter | OMP event adapter |
60
+ | Slash workflow entry points | Pi prompt templates | OMP commands |
61
+ | CodeGraph | CLI/integration when detected | MCP integration when configured |
62
+ | Advisor, checkpoint, security scan, Hindsight | Extension/fallback when detected | Native capability when enabled |
63
+ | Parallel agents | Only when a compatible task extension exists | Native `task`/workflow routes when available |
64
+
65
+ Tested locally against Pi Agent `0.85.1` and OMP `18.1.14`. Optional features are always capability-detected, so their absence produces a recorded fallback rather than a false success claim.
66
+
67
+ ## Try the demo
68
+
69
+ Open [`demo/pi-marg-v1.0.html`](demo/pi-marg-v1.0.html) in a modern browser. It is self-contained and offline. Use **Play Flow** for a walkthrough or **Presenter Mode** to hide the configuration panel.
70
+
71
+ ## Install
72
+
73
+ Review extensions before installation: both Pi and OMP packages execute with your local user permissions.
74
+
75
+ Preview the local installation commands:
76
+
77
+ ```bash
78
+ ./scripts/install.sh --runtime pi
79
+ ./scripts/install.sh --runtime omp
80
+ ```
81
+
82
+ Apply one runtime:
83
+
84
+ ```bash
85
+ ./scripts/install.sh --runtime pi --apply
86
+ ./scripts/install.sh --runtime omp --apply
87
+ ```
88
+
89
+ Install both only when you use both CLIs:
90
+
91
+ ```bash
92
+ ./scripts/install.sh --runtime both --apply
93
+ ```
94
+
95
+ Install PiMarg from the Pi package catalog/npm:
96
+
97
+ ```bash
98
+ pi install npm:@sangyaahub/pi-marg
99
+ ```
100
+
101
+ Or install Pi and OMP directly from this GitHub repository:
102
+
103
+ ```bash
104
+ pi install https://github.com/sangyaahub/pi-marg
105
+ omp plugin marketplace add sangyaahub/pi-marg
106
+ omp plugin install --scope user pi-marg@pi-marg-marketplace
107
+ ```
108
+
109
+ ## Configure models
110
+
111
+ Authenticate providers using the active runtime's normal login flow, then run:
112
+
113
+ ```text
114
+ /auto-models choose
115
+ ```
116
+
117
+ The router builds choices from the live authenticated registry. It does not promise that a subscription route is free or unlimited. See [MODEL-SETUP.md](MODEL-SETUP.md).
118
+
119
+ ## Start a workflow
120
+
121
+ Type a normal request or invoke:
122
+
123
+ ```text
124
+ /auto add CSV export to this repository
125
+ ```
126
+
127
+ Useful entry points:
128
+
129
+ - `/auto-models choose` — refresh A/B/C/D choices.
130
+ - `/auto-runtime status` — show detected capabilities and fallbacks.
131
+ - `/auto-review plan|code` — run the independent review contract.
132
+ - `/auto-status` — show the current ledger and evidence.
133
+ - `/auto-close` — verify completion and write the session lesson once.
134
+
135
+ On Pi these are prompt templates. On OMP they are command files. Ordinary new substantive prompts also enter the workflow automatically: Pi uses a lightweight bootstrap hook, while OMP loads the packaged global rule. The workflow instructions and state contract are shared.
136
+
137
+ ## Protected actions
138
+
139
+ The default policy is `ask`. A protected action remains blocked until the complete next user message is exactly one of:
140
+
141
+ ```text
142
+ APPROVE ACTION: delete-remove
143
+ APPROVE ACTION: push-main
144
+ APPROVE ACTION: merge-pr
145
+ APPROVE ACTION: post-web
146
+ ```
147
+
148
+ Each phrase permits one matching call and is then consumed. Set `PIMARG_APPROVAL_POLICY=allow` before starting the runtime only when intentionally enabling automated protected actions. `UNIVERSAL_AUTO_MODE_APPROVAL_POLICY` and `OMP_AUTO_MODE_APPROVAL_POLICY` remain recognized for migration.
149
+
150
+ ## CodeGraph policy
151
+
152
+ For an existing repository, preview setup first:
153
+
154
+ ```bash
155
+ ./scripts/setup-codegraph.sh /absolute/path/to/repository
156
+ ```
157
+
158
+ Apply after reviewing the preview:
159
+
160
+ ```bash
161
+ ./scripts/setup-codegraph.sh --apply /absolute/path/to/repository
162
+ ```
163
+
164
+ OMP can expose CodeGraph through `.mcp.json`. Pi uses a detected CodeGraph CLI or another installed integration. When CodeGraph is missing, the workflow may use precise repository-native tools, but it must not claim a repository-wide architecture or impact scan occurred.
165
+
166
+ ## Project structure
167
+
168
+ ```text
169
+ core/ shared policy and routing logic
170
+ adapters/pi/ Pi extensions and prompt templates
171
+ adapters/omp/ OMP extensions
172
+ skills/ shared workflow skills
173
+ commands/ agents/ rules/ OMP-native resources
174
+ demo/ offline interactive presentation
175
+ tests/ shared core and adapter contract tests
176
+ ```
177
+
178
+ ## Validate
179
+
180
+ ```bash
181
+ ./scripts/validate.sh
182
+ bun test tests
183
+ ```
184
+
185
+ ## License
186
+
187
+ PiMarg is an open-source project by [Sangyaa](https://sangyaa.co). Product branding uses Sangyaa's official mark and palette; see [BRAND.md](BRAND.md) for permitted use.
188
+
189
+ Copyright © 2026 Sangyaa and PiMarg contributors. Released under the [MIT License](LICENSE). Everyone may use, copy, modify, merge, publish, distribute, sublicense, or sell copies subject to the license notice and warranty disclaimer.
190
+
191
+ Contributions are welcome; see [CONTRIBUTING.md](CONTRIBUTING.md). Report vulnerabilities using [SECURITY.md](SECURITY.md).
package/SECURITY.md ADDED
@@ -0,0 +1,11 @@
1
+ # Security policy
2
+
3
+ ## Reporting a vulnerability
4
+
5
+ Do not disclose exploitable vulnerabilities in a public issue. Use [GitHub private vulnerability reporting](https://github.com/sangyaahub/pi-marg/security/advisories/new). If that is unavailable, email `contact@sangyaa.co` with the subject `PiMarg security report`.
6
+
7
+ Include the affected version, runtime, reproduction steps, impact, and any suggested countermeasure. Never include live credentials, client data, or personal information.
8
+
9
+ ## Scope
10
+
11
+ The approval guard is defense in depth, not an operating-system sandbox. Pi and OMP extensions execute with the user's local permissions. Users must review source code and install only trusted releases.
package/SUPPORT.md ADDED
@@ -0,0 +1,7 @@
1
+ # Support
2
+
3
+ Use [GitHub Discussions](https://github.com/sangyaahub/pi-marg/discussions) for setup questions and workflow ideas.
4
+
5
+ Use [GitHub Issues](https://github.com/sangyaahub/pi-marg/issues) for reproducible bugs and feature requests. Include your operating system, Pi or OMP version, installation source, relevant commands, and redacted output.
6
+
7
+ For vulnerabilities, follow [SECURITY.md](SECURITY.md) instead of opening a public issue.
@@ -0,0 +1,43 @@
1
+ import {
2
+ OneUseApprovals,
3
+ approvalInstruction,
4
+ approvalPolicyFromEnvironment,
5
+ classifyInput,
6
+ classifyToolCall,
7
+ parseApproval,
8
+ } from "../../../core/approval-policy";
9
+
10
+ export default function approvalGuard(pi: any) {
11
+ const approvals = new OneUseApprovals();
12
+ const clear = () => approvals.clear();
13
+
14
+ pi.on("session_start", clear);
15
+ pi.on("session_switch", clear);
16
+ pi.on("session_branch", clear);
17
+
18
+ pi.on("input", async (event: any, ctx: any) => {
19
+ if (event.source === "extension") return;
20
+ const granted = parseApproval(event.text);
21
+ if (granted) {
22
+ approvals.grant(granted);
23
+ if (ctx.hasUI) ctx.ui.notify(`One ${granted} action is approved for this session.`, "warning");
24
+ return;
25
+ }
26
+
27
+ const action = classifyInput(event.text);
28
+ if (!action || approvalPolicyFromEnvironment() === "allow") return;
29
+ if (approvals.consume(action)) return;
30
+ if (ctx.hasUI) ctx.ui.notify(`Blocked ${event.text.trim()}. Approve once with: ${approvalInstruction(action)}`, "warning");
31
+ return { handled: true };
32
+ });
33
+
34
+ pi.on("tool_call", async (event: any) => {
35
+ if (approvalPolicyFromEnvironment() === "allow") return;
36
+ const action = classifyToolCall(event.toolName, event.input);
37
+ if (!action || approvals.consume(action)) return;
38
+ return {
39
+ block: true,
40
+ reason: `PiMarg blocked a protected ${action} action. Show the exact action and consequence, then ask for exactly:\n${approvalInstruction(action)}\nThe approval permits one matching call only.`,
41
+ };
42
+ });
43
+ }
@@ -0,0 +1,56 @@
1
+ import {
2
+ MODEL_STATE_TYPE,
3
+ STAGES,
4
+ emptyModelRouteState,
5
+ executeModelRoute,
6
+ restoreModelRouteState,
7
+ type ModelLike,
8
+ type ModelRouteParams,
9
+ } from "../../../core/model-routing";
10
+
11
+ function toolNames(pi: any): string[] {
12
+ return (pi.getAllTools?.() ?? [])
13
+ .map((tool: any) => typeof tool === "string" ? tool : String(tool?.name ?? ""))
14
+ .filter(Boolean);
15
+ }
16
+
17
+ function hasExternalDevin(pi: any): boolean {
18
+ return toolNames(pi).some((name) => /(?:^|[_-])devin(?:[_-]|$)/i.test(name));
19
+ }
20
+
21
+ export default function modelRouter(pi: any) {
22
+ const z = pi.zod;
23
+ let state = emptyModelRouteState();
24
+ const restore = (_event: unknown, ctx: any) => {
25
+ state = restoreModelRouteState(ctx.sessionManager.getBranch());
26
+ };
27
+
28
+ pi.on("session_start", restore);
29
+ pi.on("session_switch", restore);
30
+ pi.on("session_branch", restore);
31
+ pi.on("session_tree", restore);
32
+
33
+ pi.registerTool({
34
+ name: "auto_model_route",
35
+ label: "PiMarg Model Router",
36
+ description: "Discover, select, and activate live A/B/C/D model choices while enforcing A different from C and B different from D.",
37
+ parameters: z.object({
38
+ action: z.enum(["catalog", "select", "activate", "status"]),
39
+ stage: z.enum(STAGES).optional(),
40
+ target: z.string().optional(),
41
+ workType: z.number().optional(),
42
+ }),
43
+ async execute(_toolCallId: string, params: ModelRouteParams, _signal: unknown, _onUpdate: unknown, ctx: any) {
44
+ const models = ctx.models.list() as ModelLike[];
45
+ const execution = await executeModelRoute(state, params, {
46
+ runtimeName: "OMP",
47
+ models,
48
+ hasExternalDevin: hasExternalDevin(pi),
49
+ activate: (model) => pi.setModel(model),
50
+ persist: (nextState) => pi.appendEntry(MODEL_STATE_TYPE, nextState),
51
+ });
52
+ state = execution.state;
53
+ return execution.response;
54
+ },
55
+ });
56
+ }
@@ -0,0 +1,24 @@
1
+ import {
2
+ buildRuntimeCapabilityReport,
3
+ normalizeCapabilityNames,
4
+ } from "../../../core/runtime-capabilities";
5
+
6
+ function response(report: unknown) {
7
+ return { content: [{ type: "text" as const, text: JSON.stringify(report, null, 2) }], details: report };
8
+ }
9
+
10
+ export default function runtimeCapabilities(pi: any) {
11
+ const z = pi.zod;
12
+ pi.registerTool({
13
+ name: "auto_runtime_status",
14
+ label: "PiMarg Runtime Status",
15
+ description: "Detect OMP tools, commands, and memory hooks before routing optional workflow stages.",
16
+ parameters: z.object({}),
17
+ async execute(_toolCallId: string, _params: unknown, _signal: unknown, _onUpdate: unknown, ctx: any) {
18
+ const tools = normalizeCapabilityNames(pi.getAllTools?.() ?? []);
19
+ const commands = normalizeCapabilityNames(pi.getCommands?.() ?? []);
20
+ const memoryConfigured = Boolean(ctx.memory) || tools.some((name) => ["recall", "retain", "reflect", "learn"].includes(name));
21
+ return response(buildRuntimeCapabilityReport("OMP", tools, commands, memoryConfigured));
22
+ },
23
+ });
24
+ }
@@ -0,0 +1,39 @@
1
+ import {
2
+ OneUseApprovals,
3
+ approvalInstruction,
4
+ approvalPolicyFromEnvironment,
5
+ classifyInput,
6
+ classifyToolCall,
7
+ parseApproval,
8
+ } from "../../../core/approval-policy";
9
+
10
+ export default function approvalGuard(pi: any) {
11
+ const approvals = new OneUseApprovals();
12
+ pi.on("session_start", () => approvals.clear());
13
+
14
+ pi.on("input", async (event: any, ctx: any) => {
15
+ if (event.source === "extension") return;
16
+ const granted = parseApproval(event.text);
17
+ if (granted) {
18
+ approvals.grant(granted);
19
+ if (ctx.hasUI) ctx.ui.notify(`One ${granted} action is approved for this session.`, "warning");
20
+ return { action: "handled" };
21
+ }
22
+
23
+ const action = classifyInput(event.text);
24
+ if (!action || approvalPolicyFromEnvironment() === "allow") return;
25
+ if (approvals.consume(action)) return;
26
+ if (ctx.hasUI) ctx.ui.notify(`Blocked ${event.text.trim()}. Approve once with: ${approvalInstruction(action)}`, "warning");
27
+ return { action: "handled" };
28
+ });
29
+
30
+ pi.on("tool_call", async (event: any) => {
31
+ if (approvalPolicyFromEnvironment() === "allow") return;
32
+ const action = classifyToolCall(event.toolName, event.input);
33
+ if (!action || approvals.consume(action)) return;
34
+ return {
35
+ block: true,
36
+ reason: `PiMarg blocked a protected ${action} action. Show the exact action and consequence, then ask for exactly:\n${approvalInstruction(action)}\nThe approval permits one matching call only.`,
37
+ };
38
+ });
39
+ }