instar 0.6.11 → 0.6.13

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.
@@ -0,0 +1,68 @@
1
+ /**
2
+ * AnthropicIntelligenceProvider — OPTIONAL IntelligenceProvider using the Anthropic Messages API.
3
+ *
4
+ * ⚠️ This provider uses API tokens (extra cost). For most Instar agents, the
5
+ * ClaudeCliIntelligenceProvider (which uses the Claude subscription) is the
6
+ * correct default. Only use this provider when:
7
+ * - The user explicitly sets intelligenceProvider: "anthropic-api" in config
8
+ * - The Claude CLI is not available
9
+ * - The user has a specific reason to prefer direct API access
10
+ *
11
+ * No SDK dependency — direct fetch calls, following the TelegramAdapter pattern.
12
+ */
13
+ const ANTHROPIC_API_URL = 'https://api.anthropic.com/v1/messages';
14
+ const ANTHROPIC_API_VERSION = '2023-06-01';
15
+ /** Model mapping: abstract tiers → concrete Anthropic model IDs */
16
+ const MODEL_MAP = {
17
+ fast: 'claude-haiku-4-5-20251001',
18
+ balanced: 'claude-sonnet-4-5-20250514',
19
+ capable: 'claude-opus-4-0-20250514',
20
+ };
21
+ const DEFAULT_MODEL = 'fast';
22
+ export class AnthropicIntelligenceProvider {
23
+ apiKey;
24
+ constructor(apiKey) {
25
+ this.apiKey = apiKey;
26
+ }
27
+ /**
28
+ * Create a provider from environment variables, or null if no key available.
29
+ * Follows the same graceful degradation pattern as TelegramAdapter's voice providers.
30
+ */
31
+ static fromEnv() {
32
+ const apiKey = process.env['ANTHROPIC_API_KEY'];
33
+ if (!apiKey) {
34
+ return null;
35
+ }
36
+ return new AnthropicIntelligenceProvider(apiKey);
37
+ }
38
+ async evaluate(prompt, options) {
39
+ const model = MODEL_MAP[options?.model ?? DEFAULT_MODEL] ?? MODEL_MAP[DEFAULT_MODEL];
40
+ const maxTokens = options?.maxTokens ?? 100;
41
+ const temperature = options?.temperature ?? 0;
42
+ const response = await fetch(ANTHROPIC_API_URL, {
43
+ method: 'POST',
44
+ headers: {
45
+ 'Content-Type': 'application/json',
46
+ 'x-api-key': this.apiKey,
47
+ 'anthropic-version': ANTHROPIC_API_VERSION,
48
+ },
49
+ body: JSON.stringify({
50
+ model,
51
+ max_tokens: maxTokens,
52
+ temperature,
53
+ messages: [
54
+ { role: 'user', content: prompt },
55
+ ],
56
+ }),
57
+ });
58
+ if (!response.ok) {
59
+ const errorText = await response.text().catch(() => 'unknown error');
60
+ throw new Error(`Anthropic API error ${response.status}: ${errorText}`);
61
+ }
62
+ const data = await response.json();
63
+ // Extract text from the response
64
+ const textBlock = data.content?.find((block) => block.type === 'text');
65
+ return textBlock?.text ?? '';
66
+ }
67
+ }
68
+ //# sourceMappingURL=AnthropicIntelligenceProvider.js.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * ClaudeCliIntelligenceProvider — Default IntelligenceProvider using the Claude CLI.
3
+ *
4
+ * Uses `claude -p` (print mode) to make judgment calls via the user's existing
5
+ * Claude subscription. Zero extra cost — the subscription is already paid for.
6
+ *
7
+ * This is the DEFAULT provider for Instar agents. The Anthropic API provider
8
+ * (AnthropicIntelligenceProvider) is an explicit opt-in alternative for users
9
+ * who intentionally choose direct API access.
10
+ *
11
+ * Preference hierarchy:
12
+ * 1. Claude CLI (subscription) — default, always available
13
+ * 2. Anthropic API — explicit user choice only
14
+ */
15
+ import type { IntelligenceProvider, IntelligenceOptions } from './types.js';
16
+ export declare class ClaudeCliIntelligenceProvider implements IntelligenceProvider {
17
+ private claudePath;
18
+ constructor(claudePath: string);
19
+ evaluate(prompt: string, options?: IntelligenceOptions): Promise<string>;
20
+ }
21
+ //# sourceMappingURL=ClaudeCliIntelligenceProvider.d.ts.map
@@ -0,0 +1,59 @@
1
+ /**
2
+ * ClaudeCliIntelligenceProvider — Default IntelligenceProvider using the Claude CLI.
3
+ *
4
+ * Uses `claude -p` (print mode) to make judgment calls via the user's existing
5
+ * Claude subscription. Zero extra cost — the subscription is already paid for.
6
+ *
7
+ * This is the DEFAULT provider for Instar agents. The Anthropic API provider
8
+ * (AnthropicIntelligenceProvider) is an explicit opt-in alternative for users
9
+ * who intentionally choose direct API access.
10
+ *
11
+ * Preference hierarchy:
12
+ * 1. Claude CLI (subscription) — default, always available
13
+ * 2. Anthropic API — explicit user choice only
14
+ */
15
+ import { execFile } from 'node:child_process';
16
+ /** Model mapping: abstract tiers → Claude CLI model flags */
17
+ const MODEL_MAP = {
18
+ fast: 'haiku',
19
+ balanced: 'sonnet',
20
+ capable: 'opus',
21
+ };
22
+ const DEFAULT_MODEL = 'fast';
23
+ const DEFAULT_TIMEOUT_MS = 30_000;
24
+ export class ClaudeCliIntelligenceProvider {
25
+ claudePath;
26
+ constructor(claudePath) {
27
+ this.claudePath = claudePath;
28
+ }
29
+ async evaluate(prompt, options) {
30
+ const model = MODEL_MAP[options?.model ?? DEFAULT_MODEL] ?? MODEL_MAP[DEFAULT_MODEL];
31
+ const maxTokens = options?.maxTokens ?? 100;
32
+ return new Promise((resolve, reject) => {
33
+ const args = [
34
+ '-p', prompt,
35
+ '--model', model,
36
+ '--max-turns', '1',
37
+ '--output-format', 'text',
38
+ ];
39
+ if (maxTokens) {
40
+ args.push('--max-tokens', String(maxTokens));
41
+ }
42
+ const child = execFile(this.claudePath, args, {
43
+ timeout: DEFAULT_TIMEOUT_MS,
44
+ maxBuffer: 1024 * 1024, // 1MB
45
+ env: { ...process.env },
46
+ }, (error, stdout, stderr) => {
47
+ if (error) {
48
+ // Timeout or other error — return empty so caller can fall back
49
+ reject(new Error(`Claude CLI error: ${error.message}${stderr ? ` — ${stderr.slice(0, 200)}` : ''}`));
50
+ return;
51
+ }
52
+ resolve(stdout.trim());
53
+ });
54
+ // Write prompt via stdin for very long prompts (belt and suspenders)
55
+ child.stdin?.end();
56
+ });
57
+ }
58
+ }
59
+ //# sourceMappingURL=ClaudeCliIntelligenceProvider.js.map
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Evolution Manager — the feedback loop that turns running into evolving.
3
+ *
4
+ * Four subsystems, one principle: every interaction is an opportunity
5
+ * to improve. Not during batch reflection hours later, but at the
6
+ * moment the insight is freshest.
7
+ *
8
+ * Subsystems:
9
+ * 1. Evolution Queue — staged self-improvement proposals
10
+ * 2. Learning Registry — structured, searchable insights
11
+ * 3. Capability Gap Tracker — "what am I missing?"
12
+ * 4. Action Queue — commitment tracking with stale detection
13
+ *
14
+ * Born from Portal's engagement pipeline (Steps 8-11) and proven
15
+ * across 100+ evolution proposals and 10 platform engagement skills.
16
+ */
17
+ import type { EvolutionProposal, EvolutionType, EvolutionStatus, LearningEntry, LearningSource, CapabilityGap, GapCategory, ActionItem, EvolutionManagerConfig } from './types.js';
18
+ interface EvolutionState {
19
+ proposals: EvolutionProposal[];
20
+ stats: {
21
+ totalProposals: number;
22
+ byStatus: Record<string, number>;
23
+ byType: Record<string, number>;
24
+ lastUpdated: string;
25
+ };
26
+ }
27
+ interface LearningState {
28
+ learnings: LearningEntry[];
29
+ stats: {
30
+ totalLearnings: number;
31
+ applied: number;
32
+ pending: number;
33
+ byCategory: Record<string, number>;
34
+ lastUpdated: string;
35
+ };
36
+ }
37
+ interface GapState {
38
+ gaps: CapabilityGap[];
39
+ stats: {
40
+ totalGaps: number;
41
+ bySeverity: Record<string, number>;
42
+ byCategory: Record<string, number>;
43
+ addressed: number;
44
+ lastUpdated: string;
45
+ };
46
+ }
47
+ interface ActionState {
48
+ actions: ActionItem[];
49
+ stats: {
50
+ totalActions: number;
51
+ pending: number;
52
+ completed: number;
53
+ overdue: number;
54
+ lastUpdated: string;
55
+ };
56
+ }
57
+ export declare class EvolutionManager {
58
+ private stateDir;
59
+ private config;
60
+ constructor(config: EvolutionManagerConfig);
61
+ private filePath;
62
+ private readFile;
63
+ private writeFile;
64
+ private now;
65
+ private loadEvolution;
66
+ private saveEvolution;
67
+ private nextProposalId;
68
+ addProposal(opts: {
69
+ title: string;
70
+ source: string;
71
+ description: string;
72
+ type: EvolutionType;
73
+ impact?: 'high' | 'medium' | 'low';
74
+ effort?: 'high' | 'medium' | 'low';
75
+ proposedBy?: string;
76
+ tags?: string[];
77
+ }): EvolutionProposal;
78
+ updateProposalStatus(id: string, status: EvolutionStatus, resolution?: string): boolean;
79
+ listProposals(filter?: {
80
+ status?: EvolutionStatus;
81
+ type?: EvolutionType;
82
+ }): EvolutionProposal[];
83
+ getEvolutionStats(): EvolutionState['stats'];
84
+ private loadLearnings;
85
+ private saveLearnings;
86
+ private nextLearningId;
87
+ addLearning(opts: {
88
+ title: string;
89
+ category: string;
90
+ description: string;
91
+ source: LearningSource;
92
+ tags?: string[];
93
+ evolutionRelevance?: string;
94
+ }): LearningEntry;
95
+ markLearningApplied(id: string, appliedTo: string): boolean;
96
+ listLearnings(filter?: {
97
+ category?: string;
98
+ applied?: boolean;
99
+ }): LearningEntry[];
100
+ getLearningStats(): LearningState['stats'];
101
+ private loadGaps;
102
+ private saveGaps;
103
+ private nextGapId;
104
+ addGap(opts: {
105
+ title: string;
106
+ category: GapCategory;
107
+ severity: 'critical' | 'high' | 'medium' | 'low';
108
+ description: string;
109
+ context: string;
110
+ platform?: string;
111
+ session?: string;
112
+ currentState?: string;
113
+ proposedSolution?: string;
114
+ }): CapabilityGap;
115
+ addressGap(id: string, resolution: string): boolean;
116
+ listGaps(filter?: {
117
+ severity?: string;
118
+ category?: GapCategory;
119
+ status?: string;
120
+ }): CapabilityGap[];
121
+ getGapStats(): GapState['stats'];
122
+ private loadActions;
123
+ private saveActions;
124
+ private nextActionId;
125
+ addAction(opts: {
126
+ title: string;
127
+ description: string;
128
+ priority?: 'critical' | 'high' | 'medium' | 'low';
129
+ commitTo?: string;
130
+ dueBy?: string;
131
+ source?: ActionItem['source'];
132
+ tags?: string[];
133
+ }): ActionItem;
134
+ updateAction(id: string, updates: {
135
+ status?: ActionItem['status'];
136
+ resolution?: string;
137
+ }): boolean;
138
+ listActions(filter?: {
139
+ status?: ActionItem['status'];
140
+ priority?: string;
141
+ }): ActionItem[];
142
+ getOverdueActions(): ActionItem[];
143
+ getActionStats(): ActionState['stats'];
144
+ /**
145
+ * Get a full dashboard of evolution health.
146
+ * Useful for session-start orientation and status reporting.
147
+ */
148
+ getDashboard(): {
149
+ evolution: EvolutionState['stats'];
150
+ learnings: LearningState['stats'];
151
+ gaps: GapState['stats'];
152
+ actions: ActionState['stats'];
153
+ highlights: string[];
154
+ };
155
+ }
156
+ export {};
157
+ //# sourceMappingURL=EvolutionManager.d.ts.map