Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | 1x 1x 1x 1x 20x 1x 1x 1x 1x 1x 1x 1x 1x 16x 1x 1x 1x 1x 1x 1x 3x 1x 1x 5x 5x 5x 5x 1x 1x 1x 5x 5x 5x 4x 5x 1x 4x 4x 1x 2x 2x 2x 2x 1x 4x 4x 4x 4x 4x 2x 2x 2x 5x 5x 1x 5x 3x 3x 5x 3x 5x 3x 7x 1x 4x 1x 1x 2x | import * as fs from "fs";
import * as path from "path";
// ─── Extension Imports ─────────────────────────────────────────────────────
import {
run as runIntegrityGuard,
} from "./extensions/integrity-guard";
import {
run as runProgressTracker,
} from "./extensions/progress-tracker";
// ─── Types ─────────────────────────────────────────────────────────────────
export type { PiscesConfig } from "./extensions/lib/config";
export { loadConfig, validateConfig, deepMerge, getConfigSearchPaths } from "./extensions/lib/config";
import type { PiscesConfig } from "./extensions/lib/config";
import { loadConfig, getConfigSearchPaths } from "./extensions/lib/config";
export interface SessionState {
startTime: Date;
skillsUsed: string[];
topicsWorked: string[];
warningIssuedAt: number | null;
}
export interface SkillCallContext {
skillName: string;
userInput: string;
sessionState: SessionState;
}
export interface StartupResult {
contextInjection: string;
config: PiscesConfig;
}
export interface SkillCallResult {
proceed: boolean;
injection: string;
}
export interface SessionEndResult {
nudge: string | null;
summary: string | null;
}
// ─── Package Metadata ──────────────────────────────────────────────────────
export const PACKAGE_NAME = "pisces";
export const PACKAGE_VERSION = ((): string => {
try {
const pkg = JSON.parse(
fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf-8")
) as { version: string };
return pkg.version;
} catch {
return "0.0.0";
}
})();
export const SKILLS = ["attempt"] as const;
export type SkillName = (typeof SKILLS)[number];
// ─── Session State ─────────────────────────────────────────────────────────
export function createSessionState(): SessionState {
return {
startTime: new Date(),
skillsUsed: [],
topicsWorked: [],
warningIssuedAt: null,
};
}
// ─── Lifecycle Hooks ────────────────────────────────────────────────────────
export function onLoad(): { ok: boolean; message: string } {
const nodeVersion = process.version;
const major = parseInt(nodeVersion.slice(1).split(".")[0], 10);
Iif (major < 18) {
return {
ok: false,
message: `Pisces requires Node.js >= 18. Current: ${nodeVersion}. Please upgrade.`,
};
}
const config = loadConfig();
const configSource = getConfigSearchPaths().find((p: string) => {
try { return fs.existsSync(p); } catch { return false; }
}) ?? "defaults";
return {
ok: true,
message: `Pisces ${PACKAGE_VERSION} loaded. Config: ${configSource}. Integrity guard: ${
config.integrity?.enabled !== false ? "on" : "off"
}.`,
};
}
export function onStartup(state: SessionState): StartupResult {
const config = loadConfig();
const injection = buildConfigInjection(config);
// state is retained for future extensions that accumulate context
void state;
return {
contextInjection: injection,
config,
};
}
export function onDirectoryChange(_state: SessionState): {
contextInjection: string;
message: string | null;
} {
return { contextInjection: "", message: null };
}
export function onSkillCall(context: SkillCallContext): SkillCallResult {
const { skillName, userInput, sessionState } = context;
const config = loadConfig();
if (!sessionState.skillsUsed.includes(skillName)) {
sessionState.skillsUsed.push(skillName);
}
if (config.integrity?.enabled === false) {
return { proceed: true, injection: "" };
}
const guardResult = runIntegrityGuard({ skillName, userInput, strictness: config.integrity?.strictness });
return {
proceed: true,
injection: guardResult.inject,
};
}
export function onSessionEnd(state: SessionState): SessionEndResult {
const config = loadConfig();
const durationMinutes = Math.round(
(Date.now() - state.startTime.getTime()) / 60_000
);
const trackerResult = runProgressTracker({
sessionDurationMinutes: durationMinutes,
skillsUsed: state.skillsUsed,
topicsWorked: state.topicsWorked,
});
return {
nudge: config.productivity?.burnout_nudges !== false ? trackerResult.nudge : null,
summary: config.productivity?.weekly_summary !== false ? trackerResult.weeklySummary : null,
};
}
export function onMidSession(state: SessionState): { warning: string | null } {
const config = loadConfig();
const warnAt = config.productivity?.session_warning_minutes ?? 180;
Iif (!config.productivity?.burnout_nudges) return { warning: null };
const elapsedMinutes = Math.round(
(Date.now() - state.startTime.getTime()) / 60_000
);
if (elapsedMinutes >= warnAt && state.warningIssuedAt === null) {
state.warningIssuedAt = elapsedMinutes;
return {
warning: `🐠 You've been at this for ${elapsedMinutes} minutes. Time for a short break — your brain will thank you.`,
};
}
return { warning: null };
}
// ─── Context Injection Helpers ─────────────────────────────────────────────
function buildConfigInjection(config: PiscesConfig): string {
const hints: string[] = [];
if (config.student?.name) {
hints.push(`Student name: ${config.student.name}`);
}
if (config.student?.year_of_study) {
const yearLabels: Record<number, string> = {
1: "Freshman (1st year)",
2: "Sophomore (2nd year)",
3: "Junior (3rd year)",
4: "Senior (4th year)",
5: "Graduate (1st year)",
6: "Graduate (2nd year+)",
};
hints.push(
`Year of study: ${yearLabels[config.student.year_of_study] ?? config.student.year_of_study}`
);
}
if (config.explanations?.default_depth) {
hints.push(`Explanation depth preference: ${config.explanations.default_depth}`);
}
if (!hints.length) return "";
return [
"<!-- USER CONFIG PREFERENCES -->",
...hints.map((h) => `<!-- ${h} -->`),
].join("\n");
}
// ─── Public Utility API ────────────────────────────────────────────────────
export function isValidSkill(name: string): name is SkillName {
return (SKILLS as readonly string[]).includes(name);
}
// ─── Workspace API (re-exported for packages/cli) ──────────────────────────
export { findWorkspace, getWorkspaceState, syncWorkspaceState } from "./workspace-detector";
export function describe(): string {
return [
`🐠 Pisces v${PACKAGE_VERSION}`,
` Domain-agnostic learning engine for Pi Coding Agent`,
``,
` Skills: /${SKILLS.join(", /")}`,
` Extensions: workspace-gate, integrity-guard, progress-tracker, input-revamp`,
` Config: ~/.pi/pisces.json`,
``,
` Run any skill with /<name>, e.g. /attempt`,
].join("\n");
}
|