@zihanw/pi-forge 0.2.0 → 0.3.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/src/storage.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { isAbsolute, join, relative, resolve } from "node:path";
2
+
3
+ export function promptStacksDir(cwd: string): string {
4
+ return join(cwd, ".pi", "forge", "prompt-stacks");
5
+ }
6
+
7
+ export function legacyPromptStacksDir(cwd: string): string {
8
+ return join(cwd, ".pi", "prompt-stacks");
9
+ }
10
+
11
+ export function promptStackReadDirs(cwd: string): string[] {
12
+ return [promptStacksDir(cwd), legacyPromptStacksDir(cwd)];
13
+ }
14
+
15
+ export function promptStackPath(cwd: string, id: string): string {
16
+ return join(promptStacksDir(cwd), `${id}.json`);
17
+ }
18
+
19
+ export function isInsidePromptStackStorage(cwd: string, filePath: string): boolean {
20
+ return promptStackReadDirs(cwd).some((dir) => isInsideDir(dir, filePath));
21
+ }
22
+
23
+ function isInsideDir(rootDir: string, filePath: string): boolean {
24
+ const root = resolve(rootDir);
25
+ const target = resolve(filePath);
26
+ const rel = relative(root, target);
27
+ return !!rel && !rel.startsWith("..") && !isAbsolute(rel);
28
+ }
package/src/types.ts CHANGED
@@ -19,6 +19,42 @@ export type PromptStackSlot =
19
19
  | "pi-docs"
20
20
  | "variables";
21
21
 
22
+ export type PromptStackSlotFormat = "xml" | "json" | "plain";
23
+
24
+ export type PromptRegexStage = "history" | "compiled";
25
+
26
+ export type PromptRegexEffect = "outgoing" | "display" | "both" | "finalize";
27
+
28
+ export type PromptRegexTarget = "system" | "messages";
29
+
30
+ export interface PromptRegexRule {
31
+ id: string;
32
+ name?: string;
33
+ enabled?: boolean;
34
+ stage: PromptRegexStage;
35
+ effect?: PromptRegexEffect;
36
+ pattern: string;
37
+ flags?: string;
38
+ replace?: string;
39
+ trimStrings?: string[];
40
+ roles?: string[];
41
+ targets?: PromptRegexTarget[];
42
+ maxMessages?: number;
43
+ maxChars?: number;
44
+ minDepth?: number;
45
+ maxDepth?: number;
46
+ source?: Record<string, unknown>;
47
+ }
48
+
49
+ export interface PromptRegexConfig {
50
+ schemaVersion?: 1;
51
+ rules?: PromptRegexRule[];
52
+ }
53
+
54
+ export type PromptResourcePolicy =
55
+ | { allow?: string[]; deny?: never }
56
+ | { allow?: never; deny?: string[] };
57
+
22
58
  export interface PromptStackDefaults {
23
59
  syntheticMessagesVisible?: boolean;
24
60
  unresolvedMacroPolicy?: "warn" | "keep" | "error";
@@ -50,33 +86,40 @@ export interface VariablesSlotOptions {
50
86
  includeSession?: boolean;
51
87
  /** Include turn variables. Default: true. */
52
88
  includeTurn?: boolean;
53
- /** Include only these scopes. Overrides includeStatic/includeSession/includeTurn when present. */
54
- includeScopes?: PromptStateScope[];
55
- /** Include variable names matching these exact names or wildcard prefixes, e.g. agent.*. */
56
- includeNamespaces?: string[];
57
- /** Exclude variable names matching these exact names or wildcard prefixes. */
58
- excludeNamespaces?: string[];
59
- /** Include type and description metadata from stack.state.definitions. Default: false. */
60
- includeMetadata?: boolean;
61
89
  /** Render format. Default: xml. */
62
- format?: "xml" | "json";
63
- /** Truncate each rendered value after this many characters. */
64
- maxValueChars?: number;
90
+ format?: Exclude<PromptStackSlotFormat, "json">;
65
91
  }
66
92
 
67
93
  export interface PromptStackSlotOptions {
68
94
  /** For chat-history: include the latest user message in the expanded history. Default: true. */
69
95
  includeLastUserMessage?: boolean;
96
+ /** For chat-history: remove assistant thinking content blocks from inserted history. Default: false. */
97
+ stripAssistantThinking?: boolean;
98
+ /** For chat-history: keep only messages with these roles. Default: all roles. */
99
+ roles?: string[];
100
+ /** For chat-history: include Pi branch/compaction summaries. Default: true. */
101
+ includeSummaries?: boolean;
102
+ /** For chat-history: keep or drop tool-call/tool-result history. Default: keep. */
103
+ toolMode?: "keep" | "drop";
104
+ /** For chat-history: keep only the most recent N messages after filtering. */
105
+ maxMessages?: number;
106
+ /** For chat-history: keep only the most recent messages within an approximate character budget. */
107
+ maxChars?: number;
70
108
  /** For variables: control which variable scopes are included. */
71
109
  includeStatic?: boolean;
72
110
  includeSession?: boolean;
73
111
  includeTurn?: boolean;
74
- includeScopes?: PromptStateScope[];
75
- includeNamespaces?: string[];
76
- excludeNamespaces?: string[];
77
- includeMetadata?: boolean;
78
- format?: "xml" | "json";
79
- maxValueChars?: number;
112
+ format?: PromptStackSlotFormat;
113
+ /** For tools: only render tools that provide prompt snippets, matching Pi's default prompt builder. */
114
+ onlyWithSnippets?: boolean;
115
+ /** For tool-guidelines: override the plain-format section heading. */
116
+ heading?: string;
117
+ /** For tool-guidelines: include Pi's default concise/file-path guideline bullets. */
118
+ includePiDefaultGuidelines?: boolean;
119
+ /** For tool-guidelines: match Pi's default wording where it differs from pi-forge's generic wording. */
120
+ piStyle?: boolean;
121
+ /** For skills: omit the skills section unless the read tool is active, matching Pi's default prompt builder. */
122
+ requireReadTool?: boolean;
80
123
  [key: string]: unknown;
81
124
  }
82
125
 
@@ -88,25 +131,9 @@ export interface PromptStackSlotItem extends PromptStackBaseItem {
88
131
 
89
132
  export type PromptStackItem = PromptStackBlockItem | PromptStackSlotItem;
90
133
 
91
- export type PromptStatePrimitive = string | number | boolean | null;
92
-
93
- export type PromptStateValue = PromptStatePrimitive | PromptStateValue[] | { [key: string]: PromptStateValue };
94
-
95
- export type PromptStateScope = "static" | "session" | "turn";
96
-
97
- export interface PromptStateDefinition {
98
- type?: string;
99
- scope?: PromptStateScope;
100
- description?: string;
101
- agentWritable?: boolean;
102
- userWritable?: boolean;
103
- default?: PromptStateValue;
104
- }
134
+ export type PromptVariablePrimitive = string | number | boolean | null;
105
135
 
106
- export interface PromptStateConfig {
107
- schemaVersion?: 1;
108
- definitions?: Record<string, PromptStateDefinition>;
109
- }
136
+ export type PromptVariableValue = PromptVariablePrimitive | PromptVariableValue[] | { [key: string]: PromptVariableValue };
110
137
 
111
138
  export interface PromptStack {
112
139
  schemaVersion: 1;
@@ -118,8 +145,10 @@ export interface PromptStack {
118
145
  mode?: PromptStackMode;
119
146
  defaults?: PromptStackDefaults;
120
147
  context?: PromptStackContextOptions;
148
+ tools?: PromptResourcePolicy;
149
+ skills?: PromptResourcePolicy;
121
150
  variables?: Record<string, string>;
122
- state?: PromptStateConfig;
151
+ regex?: PromptRegexConfig;
123
152
  items: PromptStackItem[];
124
153
  import?: Record<string, unknown>;
125
154
  }
@@ -139,8 +168,8 @@ export interface PromptStackDiagnostic {
139
168
  }
140
169
 
141
170
  export interface PromptVariableStore {
142
- turn: Record<string, PromptStateValue>;
143
- session: Record<string, PromptStateValue>;
171
+ turn: Record<string, PromptVariableValue>;
172
+ session: Record<string, PromptVariableValue>;
144
173
  sessionDirty?: boolean;
145
174
  }
146
175
 
@@ -157,8 +186,21 @@ export interface CompileSystemPromptResult {
157
186
  diagnostics: PromptStackDiagnostic[];
158
187
  }
159
188
 
189
+ export type CompileMessageSourceKind = "stack-item" | "chat-history" | "implicit-history";
190
+
191
+ export interface CompileMessageSource {
192
+ kind: CompileMessageSourceKind;
193
+ itemId?: string;
194
+ itemName?: string;
195
+ slot?: string;
196
+ historyIndex?: number;
197
+ historyCount?: number;
198
+ role?: string;
199
+ }
200
+
160
201
  export interface CompileMessagesResult {
161
202
  messages: AgentMessage[];
203
+ messageSources: CompileMessageSource[];
162
204
  diagnostics: PromptStackDiagnostic[];
163
205
  }
164
206
 
@@ -0,0 +1,2 @@
1
+ export { DEFAULT_WEB_EDITOR_PORT, startWebEditorServer } from "./server.ts";
2
+ export type * from "./types.ts";