pi-one-instruction 0.0.0-stage → 0.1.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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -2
  3. package/index.ts +49 -0
  4. package/package.json +25 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dundun6x
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,27 @@
1
- # Temporary Holding Version
1
+ # pi-one-instruction
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
+ [![npm version](https://img.shields.io/npm/v/pi-one-instruction)](https://www.npmjs.com/package/pi-one-instruction)
4
+ [![npm downloads](https://img.shields.io/npm/dm/pi-one-instruction)](https://www.npmjs.com/package/pi-one-instruction)
5
+ [![license](https://img.shields.io/github/license/dundun6x/pi-one-instruction)](LICENSE)
6
+
7
+ Overwrite Pi's instructions with a single `INSTRUCTION.md`.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ $ pi install npm:pi-one-instruction
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Create an `INSTRUCTION.md` in your project-level or user-level configuration directory (`./.pi/` or `~/.pi/agent/`). If both exist, the former takes precedence.
18
+
19
+ - `/one-instruction on` — Enable the custom instruction
20
+ - `/one-instruction off` — Disable the custom instruction
21
+ - `/one-instruction view` — View the custom instruction
22
+
23
+ When enabled (by default), the content of `INSTRUCTION.md` replaces the final assembled instructions, overwriting any modifications made by Pi or extensions.
24
+
25
+ ## License
26
+
27
+ [MIT](LICENSE)
package/index.ts ADDED
@@ -0,0 +1,49 @@
1
+ import { join } from "node:path"
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { getAgentDir, getMarkdownTheme, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
+ import { Markdown, type AutocompleteItem } from "@earendil-works/pi-tui";
5
+
6
+ export default function (pi: ExtensionAPI) {
7
+ const conf = join(getAgentDir(), "INSTRUCTION.md");
8
+ const local_conf = join(process.cwd(), ".pi", "INSTRUCTION.md");
9
+ const path = [local_conf, conf].find(existsSync);
10
+ const instr = path ? readFileSync(path, "utf8") : null;
11
+ let enabled = true;
12
+ pi.registerEntryRenderer<{ content: string }>(
13
+ "one-instruction-view",
14
+ (entry, _options, _theme) => {
15
+ return new Markdown(entry.data?.content ?? "", 1, 1, getMarkdownTheme());
16
+ }
17
+ );
18
+ pi.registerCommand("one-instruction", {
19
+ description: "Toggle one instruction",
20
+ getArgumentCompletions: (prefix): AutocompleteItem[] => {
21
+ return ["on", "off", "view"]
22
+ .filter((value) => value.startsWith(prefix.trim()))
23
+ .map((value) => ({ value, label: value }));
24
+ },
25
+ handler: async (args, ctx) => {
26
+ const value = args.trim().toLowerCase();
27
+ if (value === "on") {
28
+ enabled = true;
29
+ ctx.ui.notify("One instruction enabled", "info");
30
+ } else if (value === "off") {
31
+ enabled = false;
32
+ ctx.ui.notify("One instruction disabled", "info");
33
+ } else if (value === "view") {
34
+ if (!instr) {
35
+ ctx.ui.notify("INSTRUCTION.md not found in project or user configuration", "warning");
36
+ return;
37
+ }
38
+ ctx.ui.notify("View INSTRUCTION.md", "info");
39
+ pi.appendEntry("one-instruction-view", { content: instr });
40
+ } else {
41
+ ctx.ui.notify("Usage: /one-instruction on|off|view", "warning");
42
+ }
43
+ },
44
+ });
45
+ pi.on("before_provider_request", (event) => {
46
+ if (!(instr && enabled)) return;
47
+ (event.payload as Record<string, unknown>).instructions = instr;
48
+ });
49
+ }
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "pi-one-instruction",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Overwrite Pi's instructions with a single INSTRUCTION.md",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/dundun6x/pi-one-instruction.git"
9
+ },
10
+ "keywords": ["pi-package", "pi-extension", "instructions"],
11
+ "files": [
12
+ "index.ts",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "type": "module",
17
+ "pi": {
18
+ "extensions": ["./index.ts"]
19
+ },
20
+ "peerDependencies": {
21
+ "@earendil-works/pi-coding-agent": "*"
22
+ },
23
+ "devDependencies": {
24
+ "@earendil-works/pi-coding-agent": "latest",
25
+ "typescript": "latest"
26
+ }
27
+ }