@jackjtaylor/pi-sdlc-modes 0.1.0 → 0.2.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/DEFAULTS.json CHANGED
@@ -1,48 +1,54 @@
1
1
  {
2
- "cycleShortcut": "ctrl+alt+m",
2
+ "cycleShortcut": "ctrl+shift+m",
3
3
  "initialMode": "explore",
4
4
  "modes": [
5
5
  {
6
6
  "id": "explore",
7
- "name": "Explore",
8
- "description": "Explore how the code works and how systems are designed before suggesting any changes.",
9
- "instructions": "Explain the system's purpose, main components, and how they interact or move data; inspect the code and cite relevant files or symbols, using a diagram when it clarifies the design. Keep the overview focused, answer follow-up questions, and distinguish verified facts from assumptions. For bug reports, describe the behavior and symptoms without diagnosing causes or proposing fixes unless asked. Delegate bounded, independent research when a suitable route is available; otherwise investigate directly and never claim delegation."
7
+ "name": "Explore and Explain",
8
+ "description": "Research and explain a topic, technology, system, or change to build understanding.",
9
+ "instructions": "Research and explain topics, technologies, stacks, code, systems, or changes to help the user understand them. Choose appropriate sources, check version-sensitive or current claims where relevant, cite evidence, and distinguish verified facts from assumptions. For systems, explain their purpose, entry points, main components, and how data and control flow between them. For changes or pull requests, inspect the available description and relevant context, then explain what changed, how it works, why, and what it affects in a logical order. Cite relevant files or symbols, use a diagram when it clarifies the flow, and start with a focused overview before going deeper on request. Understanding is the goal: do not evaluate options, recommend a solution, hunt for issues, or propose fixes unless asked. If you notice a significant concern, briefly flag it and suggest review when appropriate. For bug reports, describe the behavior and symptoms without diagnosing causes or proposing fixes unless asked. Do not edit code or post comments unless requested. Delegate bounded, independent research when a suitable route is available; otherwise investigate directly and never claim delegation."
10
10
  },
11
11
  {
12
12
  "id": "specification-and-acceptance-criteria",
13
- "name": "Specification and Acceptance Criteria",
14
- "description": "Describe the problem, scope, user experience, and testable acceptance criteria.",
15
- "instructions": "Work with the user to describe the problem, intended users, desired experience, scope, and constraints. Ask focused questions about unclear behavior, including important edge, error, and recovery cases. Summarize the agreement as user stories and observable acceptance criteria; call out unresolved assumptions instead of guessing. Do not begin design or implementation until the scope and criteria are clear."
13
+ "name": "Define Specification and Acceptance Criteria",
14
+ "description": "Define the problem, users, scope, expected behavior, and observable acceptance criteria for a change.",
15
+ "instructions": "Define a specification and observable acceptance criteria with the user, starting with the problem, intended users, desired outcome, constraints, and what is in and out of scope. Inspect existing behavior when useful to ground the discussion. Ask focused questions about unclear behavior, including relevant edge, empty, permission, error, and recovery cases; do not guess unresolved answers. Consider who will use the feature and how its impact can be measured. Favor work close to the mission and work that repairs user trust; avoid jumping between unused features that add tech debt and limit future options. Summarise the agreement as user stories and observable acceptance criteria, with success measures where practical and any open assumptions. Do not begin design or implementation until the scope and criteria are clear."
16
16
  },
17
17
  {
18
18
  "id": "design-and-plan",
19
- "name": "Design and Plan",
20
- "description": "Select an approach and turn the criteria into an actionable plan.",
21
- "instructions": "Inspect the relevant code and compare feasible approaches against the agreed criteria. Explain the recommended design, key trade-offs, risks, and compatibility effects, and confirm the direction with the user. Then give an ordered plan naming files, relevant locations, intended changes, and verification steps; note open questions and tests. Do not edit files in this mode."
19
+ "name": "Design and Plan a Solution",
20
+ "description": "Compare approaches, design a solution, and produce an actionable implementation and verification plan for approval.",
21
+ "instructions": "Design a solution and create an actionable plan against the agreed criteria. If important criteria are unclear, clarify them with the user. Inspect relevant code and compare feasible approaches in proportion to the decision. Explain the recommended design, trade-offs, risks, compatibility, and any relevant migration or rollout effects, and confirm the direction with the user. Provide an ordered plan naming files, relevant locations, intended changes, and verification steps, with concrete code or signatures when useful. Include appropriate tests, observability, reliability, and underlying plumbing, as well as relevant rollout or rollback steps and open questions. Weigh tech debt, pipeline work, and new features against each other; do not add unused features. Do not implement or edit project code in this mode; writing a plan document is allowed. Obtain approval before building when required."
22
22
  },
23
23
  {
24
- "id": "build",
25
- "name": "Build",
26
- "description": "Implement the approved design or plan, preserve existing work, and verify the result.",
27
- "instructions": "Implement the approved design or plan within the agreed scope. Follow repository conventions, keep the diff focused, and preserve unrelated user changes. Add or update relevant tests and run appropriate checks. When a suitable sub-agent or CLI-based Pi route is available, delegate bounded tasks that avoid conflicting edits; coordinate, integrate, and verify the result, and tell child agents not to delegate further. Otherwise work directly and do not claim delegation."
24
+ "id": "build-and-test",
25
+ "name": "Build and Test Changes",
26
+ "description": "Implement the requested or approved change, add appropriate tests, and run relevant checks.",
27
+ "instructions": "Build and test the requested or approved change within the agreed scope. Follow repository conventions, keep the diff focused, and preserve unrelated user changes. If a material change to the agreed scope or approach is needed, discuss it with the user. Add or update relevant tests, build in appropriate observability and reliability, and run the applicable checks; fix failures caused by your changes and report checks that could not run. When a suitable subagent or CLI-based Pi route is available, delegate bounded tasks that avoid conflicting edits, tell child agents not to delegate further, then coordinate, integrate, and verify their work. Otherwise work directly and do not claim delegation. Leave time for verification and judgement. Summarise what changed, the checks performed, and any remaining risks."
28
28
  },
29
29
  {
30
30
  "id": "review",
31
- "name": "Review",
32
- "description": "Review changes for concrete defects, regressions, security risks, and missing tests.",
33
- "instructions": "Review the changes without modifying files. Prioritize concrete defects, regressions, security risks, and missing tests; support each finding with a file and line reference and explain its impact. Separate confirmed findings from uncertainty, and state clearly if you find none. For substantial changes, delegate bounded, independent review areas when a suitable route is available; otherwise review directly."
31
+ "name": "Find Issues and Risks (Review)",
32
+ "description": "Critically review code or changes to identify substantiated, actionable issues, bugs, risks, and gaps.",
33
+ "instructions": "Independently review code or changes for actionable issues and misalignment with the intended goals. Establish the intent from available context, then inspect the diff and relevant surrounding code, callers, contracts, and tests. Consider correctness, regressions, edge cases, security, compatibility, performance, and relevant testing, observability, reliability, and rollout gaps. Consider whether new features are likely to be used. Verify candidate findings against the code; do not present speculation as fact. Report significant findings first, ordered by severity, with a precise file and location, evidence, concrete impact, and a suggested fix when useful. Provide enough context for a reader unfamiliar with the changes and distinguish known reasons from assumptions. If no significant issues are found, say so and note remaining uncertainties or coverage gaps. Use subagents for bounded, independent review when available; otherwise review directly and never claim delegation. Do not change code or submit a review unless the user asks."
34
34
  },
35
35
  {
36
36
  "id": "release",
37
- "name": "Release",
38
- "description": "Assess release readiness and prepare verification, rollout, and rollback checks.",
39
- "instructions": "Prepare release-readiness checks and a practical rollout, verification, and rollback checklist. Base conclusions on available evidence; use only accessible tools, services, logs, and metrics, and state what could not be checked. Do not claim readiness without evidence or deploy, alter production, or take another consequential release action without explicit approval."
37
+ "name": "Prepare and Release Changes",
38
+ "description": "Assess release readiness, prepare a safe rollout and rollback, and carry out approved release actions.",
39
+ "instructions": "Prepare changes for release and help carry out the rollout safely. Assess readiness against available evidence, including relevant checks, approvals, dependencies, configuration, migrations, flags, and compatibility. Summarise readiness, blockers, and what could not be checked; do not claim readiness without evidence. Prepare ordered rollout, verification, monitoring, and rollback or roll-forward steps appropriate to the change. Explain consequential actions and their effects, and deploy, alter production, or take another consequential release action only with explicit approval and required human checkpoints. Stop and report unexpected results. After shipping, suggest monitoring and hold a short mini-retro to consider whether the next work should be tech debt, pipeline and reliability work, or a new feature. Check whether shipped features are actually used, and avoid placing features on prominent surfaces just to make them visible."
40
40
  },
41
41
  {
42
- "id": "debug-and-log",
43
- "name": "Debug and Log",
44
- "description": "Investigate failures using reproducible evidence and available logs to identify likely causes.",
45
- "instructions": "Clarify expected versus observed behavior, reproduce the failure when practical, and inspect relevant code plus only logs or diagnostics you can access. Use evidence to trace likely causes; separate confirmed facts from hypotheses and state useful next steps. Do not imply access to unavailable systems or expose secrets or unnecessary personal data from logs. Do not change code or systems unless asked."
42
+ "id": "monitor",
43
+ "name": "Monitor Release, Analyze Logs",
44
+ "description": "Monitor release or system health and adoption using available logs, metrics, traces, alerts, and other signals.",
45
+ "instructions": "Assess whether a release, change, or system is healthy and working as intended. Establish the time window, affected services, expected behavior, and an appropriate baseline where possible. Analyze available logs, metrics, traces, alerts, and relevant usage or adoption signals. Report the observed status, signals checked, trends or anomalies compared with the baseline, potential user impact, and access or coverage gaps; include numbers and time windows where available. Cite evidence and distinguish observations and correlations from hypotheses. Recommend whether to keep watching, investigate a possible bug, or consider rollback; do not claim a root cause without evidence. Do not imply access to unavailable systems or expose secrets or unnecessary personal data. Do not change code, production, monitoring configuration, or issue states unless the user asks and any required approval is given."
46
+ },
47
+ {
48
+ "id": "debug",
49
+ "name": "Diagnose and Fix Bugs (Debug)",
50
+ "description": "Investigate a failure, identify its cause using evidence, and make and verify a fix when requested.",
51
+ "instructions": "Diagnose a bug using code, logs, and other available evidence, and fix it when the user asks. Clarify expected versus observed behavior and scope, then try to reproduce the failure before fixing it. If reproduction is unavailable, state the limitation and evidence needed. Test hypotheses methodically, separating confirmed facts from assumptions; establish the root cause before making a fix. Change one thing at a time and check the result, cleaning up failed experiments without disturbing unrelated work. When a fix is requested, make the smallest logical change that addresses the cause, and add a regression test or other verification where practical. Report the diagnosis, supporting evidence, changes, checks, and unresolved uncertainty. If the fix requires a broader design decision, discuss it with the user. Do not imply access to unavailable systems or expose secrets or unnecessary personal data. Do not change code or systems unless the user has asked you to fix the issue."
46
52
  }
47
53
  ]
48
54
  }
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @jackjtaylor/pi-sdlc-modes
2
2
 
3
- This packages has modes to guide Pi through the stages of software development, from exploring a codebase to preparing a release.
3
+ This package has modes to guide Pi through the stages of software development, from exploring a codebase to preparing a release.
4
4
 
5
5
  ## Install
6
6
 
@@ -10,25 +10,40 @@ pi install npm:@jackjtaylor/pi-sdlc-modes
10
10
 
11
11
  You can update this package with `pi update --extensions`.
12
12
 
13
- ```bash
14
- pi remove npm:@jackjtaylor/pi-sdlc-modes
15
- ```
16
-
17
13
  ## Select Modes
18
14
 
19
- - Press `Ctrl+Alt+M` to cycle through the modes (or create your own in a configuration file).
20
- - Run `/sdlc` to pick a mode, or `/sdlc <mode>` to select one by name.
21
- - Run `/sdlc next` to move to the next mode.
22
-
23
- The selected mode appears above the editor in the terminal user interface. Your new sessions start in `Explore` by default. Pi remembers the mode you selected, even when you're resuming a session later.
15
+ - Press `Ctrl+Shift+M` to cycle through the modes (or configure another shortcut).
16
+ - Run `/sdlc` to choose a mode from the interactive picker.
17
+ - Run `/sdlc off` to disable the extension for this session, or `/sdlc on` to re-enable the extension. The extension is enabled for new sessions by default.
24
18
 
25
19
  The modes guide Pi's responses and how it should work. They don't forbid tools, restrict context, or change what Pi has access to. The modes are also not extension or package-specific, so you can ask Pi to, for example, create plans using an extension, or by creating files.
26
20
 
21
+ When the extension is off, Pi won't be able to change modes, and it won't see any system prompt info or context about the extension. If you re-enable the extension, the tool will be available again for Pi to use, and it'll see context about the selected mode.
22
+
23
+ ### Start Sessions in a Mode
24
+
25
+ You can set flags when starting Pi, for example, with a subagent.
26
+
27
+ ```bash
28
+ pi -p --sdlc-mode build-and-test "Please read the plan and..."
29
+ pi -p --sdlc-off "Please answer my question..."
30
+ ```
31
+
32
+ - `--sdlc-mode <id>` starts a new session in that mode.
33
+ - `--sdlc-off` starts a new session with the extension disabled.
34
+
35
+ The flags apply only to new sessions. If you resume a session, it'll keep its mode and enabled or disabled state.
36
+
27
37
  ## Configure
28
38
 
29
39
  The defaults are in `DEFAULTS.json`.
30
40
  To customise the modes or shortcut, create `~/.pi/agent/extensions/pi-sdlc-modes/config.json` and use the same schema as in `DEFAULTS.json`.
41
+ If you find a better prompt or a mode that would be useful, please let me know!
31
42
 
32
43
  ## Security
33
44
 
34
45
  In this very early stage of development, I haven't reviewed or verified the code line-by-line, so keep that in mind when using this package.
46
+
47
+ ## Stability
48
+
49
+ As this is a very early version, I'm actively developing and changing this, so it's possible in the future some of the tools or modes may change. If so, you should be able to ask Pi and it'll help update your workflows or configuration accordingly.
package/index.ts CHANGED
@@ -2,24 +2,27 @@ import { Type } from "typebox";
2
2
  import { Value } from "typebox/value";
3
3
  import { type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
4
4
  import { Text } from "@earendil-works/pi-tui";
5
- import { loadConfig, ModeStateEntrySchema, type ModeDefinition, type ModeStateEntry } from "./mode-config.ts";
5
+ import { loadConfig, ModeStateEntrySchema, type ModeDefinition, type ModeStateEntry } from "./modeConfig.ts";
6
6
 
7
7
  const STATE_ENTRY_TYPE = "sdlc-mode-state";
8
+ const ENABLED_STATE_ENTRY_TYPE = "sdlc-mode-enabled-state";
8
9
  const WIDGET_ID = "sdlc-mode";
9
10
  const SYSTEM_PROMPT_SECTION = "sdlc_mode";
10
-
11
- function normalizeModeSelector(value: string): string {
12
- return value
13
- .trim()
14
- .toLowerCase()
15
- .replace(/&/g, " ")
16
- .replace(/[^a-z0-9]+/g, "-")
17
- .replace(/^-|-$/g, "");
18
- }
11
+ const SET_MODE_TOOL_NAME = "sdlc_set_mode";
12
+ const EnabledStateEntrySchema = Type.Object({
13
+ enabled: Type.Boolean(),
14
+ changedAt: Type.Number(),
15
+ });
16
+ type EnabledStateEntry = { enabled: boolean; changedAt: number };
19
17
 
20
18
  export default function sdlcModesExtension(pi: ExtensionAPI): void {
21
19
  const config = loadConfig();
22
20
  let activeModeId = config.initialMode;
21
+ let sdlcEnabled = true;
22
+ // The tool list from --tools is process-wide, so exclusion is decided once, on the first
23
+ // session start, before SDLC has touched the tools. Later sessions reuse that decision.
24
+ let modeToolExclusionChecked = false;
25
+ let modeToolExcludedByUser = false;
23
26
 
24
27
  const firstConfiguredMode = config.modes[0];
25
28
  if (!firstConfiguredMode) throw new Error("SDLC configuration must contain at least one mode.");
@@ -42,7 +45,25 @@ export default function sdlcModesExtension(pi: ExtensionAPI): void {
42
45
  activeModeId = config.initialMode;
43
46
  };
44
47
 
48
+ const restoreEnabledStateFromBranch = (ctx: ExtensionContext): void => {
49
+ const entries = ctx.sessionManager.getBranch();
50
+ for (let index = entries.length - 1; index >= 0; index--) {
51
+ const entry = entries[index];
52
+ if (!entry || entry.type !== "custom" || entry.customType !== ENABLED_STATE_ENTRY_TYPE) continue;
53
+ const stateData: unknown = entry.data;
54
+ if (!Value.Check(EnabledStateEntrySchema, stateData)) continue;
55
+ sdlcEnabled = stateData.enabled;
56
+ return;
57
+ }
58
+ sdlcEnabled = true;
59
+ };
60
+
45
61
  const updateModeIndicator = (ctx: ExtensionContext): void => {
62
+ if (!sdlcEnabled) {
63
+ ctx.ui.setWidget(WIDGET_ID, undefined);
64
+ ctx.ui.setStatus(WIDGET_ID, undefined);
65
+ return;
66
+ }
46
67
  const mode = getActiveMode();
47
68
  if (ctx.mode === "tui") {
48
69
  ctx.ui.setWidget(
@@ -89,43 +110,109 @@ export default function sdlcModesExtension(pi: ExtensionAPI): void {
89
110
  };
90
111
 
91
112
  const cycleMode = (ctx: ExtensionContext): void => {
113
+ if (!sdlcEnabled) return;
92
114
  const activeIndex = config.modes.findIndex((mode) => mode.id === activeModeId);
93
115
  const nextMode = config.modes[(activeIndex + 1 + config.modes.length) % config.modes.length] ?? firstConfiguredMode;
94
116
  setMode(nextMode.id, ctx);
95
117
  };
96
118
 
97
- const selectMode = async (args: string, ctx: ExtensionContext): Promise<void> => {
98
- const selector = args.trim();
99
- if (selector.length === 0) {
100
- if (!ctx.hasUI) {
101
- ctx.ui.notify(`Current mode: ${getActiveMode().name}. Use /sdlc next or /sdlc <mode>.`, "info");
119
+ const hasSdlcHistory = (ctx: ExtensionContext): boolean =>
120
+ ctx.sessionManager
121
+ .getBranch()
122
+ .some(
123
+ (entry) =>
124
+ entry.type === "custom" &&
125
+ (entry.customType === STATE_ENTRY_TYPE || entry.customType === ENABLED_STATE_ENTRY_TYPE),
126
+ );
127
+
128
+ const updateModeToolExclusion = (): void => {
129
+ if (modeToolExclusionChecked) return;
130
+ modeToolExclusionChecked = true;
131
+ // Inactive is not the same as excluded: a resumed branch may have turned SDLC off.
132
+ // getAllTools omits tools filtered out by --tools / --exclude-tools.
133
+ modeToolExcludedByUser = !pi.getAllTools().some((tool) => tool.name === SET_MODE_TOOL_NAME);
134
+ };
135
+
136
+ // --sdlc-mode and --sdlc-off set the starting state of a new session only. Resumed or
137
+ // branched sessions keep their saved state. The chosen values are recorded in the session.
138
+ // A startup error (an unknown --sdlc-mode) is kept and blocks every prompt. Pi has no
139
+ // startup abort, and ctx.shutdown() is a no-op in print mode, so input is refused instead.
140
+ let startupError: string | undefined;
141
+
142
+ const applyStartupFlags = (ctx: ExtensionContext): void => {
143
+ startupError = undefined;
144
+ if (hasSdlcHistory(ctx)) return;
145
+
146
+ const requestedModeId = pi.getFlag("sdlc-mode");
147
+ if (typeof requestedModeId === "string" && requestedModeId.length > 0) {
148
+ const requestedMode = config.modes.find((mode) => mode.id === requestedModeId);
149
+ if (!requestedMode) {
150
+ const availableModes = config.modes.map((mode) => mode.id).join(", ");
151
+ startupError = `Unknown SDLC mode "${requestedModeId}" for --sdlc-mode. Available: ${availableModes}.`;
152
+ ctx.ui.notify(startupError, "error");
102
153
  return;
103
154
  }
104
- const selectedName = await ctx.ui.select(
105
- "Choose an SDLC mode",
106
- config.modes.map((mode) => mode.name),
107
- );
108
- if (!selectedName) return;
109
- const selectedMode = config.modes.find((mode) => mode.name === selectedName);
110
- if (selectedMode) setMode(selectedMode.id, ctx);
111
- return;
155
+ activeModeId = requestedMode.id;
156
+ pi.appendEntry<ModeStateEntry>(STATE_ENTRY_TYPE, {
157
+ modeId: requestedMode.id,
158
+ modeName: requestedMode.name,
159
+ description: requestedMode.description,
160
+ changedAt: Date.now(),
161
+ });
162
+ }
163
+
164
+ if (pi.getFlag("sdlc-off") === true) {
165
+ sdlcEnabled = false;
166
+ pi.appendEntry<EnabledStateEntry>(ENABLED_STATE_ENTRY_TYPE, { enabled: false, changedAt: Date.now() });
112
167
  }
168
+ };
169
+
170
+ // Pi only declares a tool's guidelines to the model while the tool is active, so
171
+ // disabling SDLC also removes the mode-switch tool and its rules from the prompt.
172
+ // A tool the user excluded stays excluded, even when SDLC is on.
173
+ const syncModeToolActivation = (): void => {
174
+ const otherActiveToolNames = pi.getActiveTools().filter((name) => name !== SET_MODE_TOOL_NAME);
175
+ const includeModeTool = sdlcEnabled && !modeToolExcludedByUser;
176
+ pi.setActiveTools(includeModeTool ? [...otherActiveToolNames, SET_MODE_TOOL_NAME] : otherActiveToolNames);
177
+ };
113
178
 
114
- if (selector.toLowerCase() === "next") {
115
- cycleMode(ctx);
179
+ const setSdlcEnabled = (enabled: boolean, ctx: ExtensionContext): void => {
180
+ if (sdlcEnabled === enabled) {
181
+ ctx.ui.notify(`SDLC is already ${enabled ? "on" : "off"}.`, "info");
182
+ return;
183
+ }
184
+ sdlcEnabled = enabled;
185
+ syncModeToolActivation();
186
+ pi.appendEntry<EnabledStateEntry>(ENABLED_STATE_ENTRY_TYPE, { enabled, changedAt: Date.now() });
187
+ updateModeIndicator(ctx);
188
+ if (enabled && modeToolExcludedByUser) {
189
+ ctx.ui.notify(`SDLC turned on, but ${SET_MODE_TOOL_NAME} is excluded from the session's tools.`, "warning");
116
190
  return;
117
191
  }
192
+ ctx.ui.notify(`SDLC turned ${enabled ? "on" : "off"}.`, "info");
193
+ };
118
194
 
119
- const normalizedSelector = normalizeModeSelector(selector);
120
- const selectedMode = config.modes.find(
121
- (mode) => mode.id === normalizedSelector || normalizeModeSelector(mode.name) === normalizedSelector,
122
- );
123
- if (!selectedMode) {
124
- const availableModes = config.modes.map((mode) => mode.id).join(", ");
125
- ctx.ui.notify(`Unknown SDLC mode "${selector}". Available: ${availableModes}, next.`, "error");
195
+ const selectMode = async (args: string, ctx: ExtensionContext): Promise<void> => {
196
+ const selector = args.trim().toLowerCase();
197
+ if (selector === "on" || selector === "off") {
198
+ setSdlcEnabled(selector === "on", ctx);
199
+ return;
200
+ }
201
+ if (selector.length > 0) {
202
+ ctx.ui.notify("Use /sdlc to choose a mode, or /sdlc on|off to enable or disable SDLC.", "error");
203
+ return;
204
+ }
205
+ if (!ctx.hasUI) {
206
+ ctx.ui.notify(`Current mode: ${getActiveMode().name}. The mode picker requires an interactive UI.`, "info");
126
207
  return;
127
208
  }
128
- setMode(selectedMode.id, ctx);
209
+ const selectedName = await ctx.ui.select(
210
+ "Choose an SDLC mode",
211
+ config.modes.map((mode) => mode.name),
212
+ );
213
+ if (!selectedName) return;
214
+ const selectedMode = config.modes.find((mode) => mode.name === selectedName);
215
+ if (selectedMode) setMode(selectedMode.id, ctx);
129
216
  };
130
217
 
131
218
  pi.registerEntryRenderer<ModeStateEntry>(STATE_ENTRY_TYPE, (entry, _options, theme) => {
@@ -134,8 +221,14 @@ export default function sdlcModesExtension(pi: ExtensionAPI): void {
134
221
  return new Text(theme.fg("dim", `SDLC · ${data.modeName} — ${data.description}`), 0, 0);
135
222
  });
136
223
 
224
+ pi.registerEntryRenderer<EnabledStateEntry>(ENABLED_STATE_ENTRY_TYPE, (entry, _options, theme) => {
225
+ const data = Value.Check(EnabledStateEntrySchema, entry.data) ? entry.data : undefined;
226
+ if (!data) return new Text(theme.fg("dim", "SDLC availability changed"), 0, 0);
227
+ return new Text(theme.fg("dim", `SDLC turned ${data.enabled ? "on" : "off"}`), 0, 0);
228
+ });
229
+
137
230
  pi.registerTool({
138
- name: "sdlc_set_mode",
231
+ name: SET_MODE_TOOL_NAME,
139
232
  label: "Set SDLC Mode",
140
233
  description:
141
234
  "Change the active SDLC mode after the user explicitly requests or clearly authorizes that phase change. If the user's intent is unclear, ask and wait for confirmation instead of switching.",
@@ -162,19 +255,11 @@ export default function sdlcModesExtension(pi: ExtensionAPI): void {
162
255
  });
163
256
 
164
257
  pi.registerCommand("sdlc", {
165
- description: "Choose an SDLC mode, use /sdlc next, or select /sdlc <mode>",
258
+ description: "Choose an SDLC mode or turn SDLC on or off",
166
259
  getArgumentCompletions: (prefix) => {
167
260
  const choices = [
168
- {
169
- value: "next",
170
- label: "next",
171
- description: "Advance to the next SDLC mode",
172
- },
173
- ...config.modes.map((mode) => ({
174
- value: mode.id,
175
- label: mode.name,
176
- description: mode.description,
177
- })),
261
+ { value: "on", label: "on", description: "Enable SDLC for this session" },
262
+ { value: "off", label: "off", description: "Disable SDLC for this session" },
178
263
  ];
179
264
  const matches = choices.filter((choice) => choice.value.startsWith(prefix.toLowerCase()));
180
265
  return matches.length > 0 ? matches : null;
@@ -182,22 +267,51 @@ export default function sdlcModesExtension(pi: ExtensionAPI): void {
182
267
  handler: async (args, ctx) => selectMode(args, ctx),
183
268
  });
184
269
 
270
+ pi.registerFlag("sdlc-mode", {
271
+ description: "Start a new session in this SDLC mode ID",
272
+ type: "string",
273
+ });
274
+
275
+ pi.registerFlag("sdlc-off", {
276
+ description: "Start a new session with SDLC turned off",
277
+ type: "boolean",
278
+ default: false,
279
+ });
280
+
185
281
  pi.registerShortcut(config.cycleShortcut, {
186
- description: "Advance to the next SDLC mode",
282
+ description: "Advance to the next SDLC mode when SDLC is on",
187
283
  handler: async (ctx) => cycleMode(ctx),
188
284
  });
189
285
 
190
286
  pi.on("session_start", async (_event, ctx) => {
191
287
  restoreModeFromBranch(ctx);
288
+ restoreEnabledStateFromBranch(ctx);
289
+ updateModeToolExclusion();
290
+ applyStartupFlags(ctx);
291
+ syncModeToolActivation();
192
292
  updateModeIndicator(ctx);
193
293
  });
194
294
 
195
295
  pi.on("session_tree", async (_event, ctx) => {
196
296
  restoreModeFromBranch(ctx);
297
+ restoreEnabledStateFromBranch(ctx);
298
+ updateModeToolExclusion();
299
+ syncModeToolActivation();
197
300
  updateModeIndicator(ctx);
198
301
  });
199
302
 
303
+ pi.on("input", (_event, ctx) => {
304
+ if (startupError === undefined) return { action: "continue" };
305
+ ctx.ui.notify(startupError, "error");
306
+ process.exitCode = 1;
307
+ return { action: "handled" };
308
+ });
309
+
200
310
  pi.on("before_agent_start", (event) => {
311
+ if (!sdlcEnabled) {
312
+ delete event.systemPromptOptions.sections[SYSTEM_PROMPT_SECTION];
313
+ return;
314
+ }
201
315
  const mode = getActiveMode();
202
316
  event.systemPromptOptions.sections[SYSTEM_PROMPT_SECTION] = [
203
317
  `## Active SDLC Mode: ${mode.name}`,
@@ -205,9 +319,13 @@ export default function sdlcModesExtension(pi: ExtensionAPI): void {
205
319
  "",
206
320
  mode.instructions,
207
321
  "",
208
- "## Changing SDLC Modes",
209
- "Use sdlc_set_mode only when the user explicitly requests a mode change or clearly authorizes moving to that phase.",
210
- "Do not switch merely because another mode seems useful. If the user's intent is unclear, ask and wait for confirmation.",
322
+ ...(modeToolExcludedByUser
323
+ ? []
324
+ : [
325
+ "## Changing SDLC Modes",
326
+ "Use sdlc_set_mode only when the user explicitly requests a mode change or clearly authorizes moving to that phase.",
327
+ "Do not switch merely because another mode seems useful. If the user's intent is unclear, ask and wait for confirmation.",
328
+ ]),
211
329
  ].join("\n");
212
330
  });
213
331
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jackjtaylor/pi-sdlc-modes",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Guide Pi through the Software Development Lifecycle (SDLC) with customisable modes.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -14,7 +14,7 @@
14
14
  ],
15
15
  "files": [
16
16
  "index.ts",
17
- "mode-config.ts",
17
+ "modeConfig.ts",
18
18
  "DEFAULTS.json",
19
19
  "README.md"
20
20
  ],
File without changes