bioscode 0.1.5

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 (142) hide show
  1. package/LICENSE +306 -0
  2. package/NOTICE +45 -0
  3. package/README.md +277 -0
  4. package/dist/auth/index.d.ts +202 -0
  5. package/dist/brand/index.d.ts +7 -0
  6. package/dist/brand/loader.d.ts +463 -0
  7. package/dist/brand/rules.d.ts +25 -0
  8. package/dist/brand/schema.d.ts +246 -0
  9. package/dist/bus/bus-event.d.ts +10 -0
  10. package/dist/bus/global.d.ts +7 -0
  11. package/dist/bus/index.d.ts +26 -0
  12. package/dist/cli/auth.d.ts +23 -0
  13. package/dist/cli/brand.d.ts +6 -0
  14. package/dist/cli/index.d.ts +1 -0
  15. package/dist/cli/ui.d.ts +26 -0
  16. package/dist/command/index.d.ts +54 -0
  17. package/dist/config/config.d.ts +6036 -0
  18. package/dist/config/index.d.ts +2 -0
  19. package/dist/config/markdown.d.ts +415 -0
  20. package/dist/constants/index.d.ts +6 -0
  21. package/dist/constants/version.d.ts +5 -0
  22. package/dist/diff/engine.d.ts +15 -0
  23. package/dist/diff/index.d.ts +8 -0
  24. package/dist/diff/types.d.ts +66 -0
  25. package/dist/file/ignore.d.ts +7 -0
  26. package/dist/flag/index.d.ts +19 -0
  27. package/dist/gateway/bridge.d.ts +11 -0
  28. package/dist/gateway/handlers/llm.d.ts +7 -0
  29. package/dist/gateway/handlers/permission.d.ts +15 -0
  30. package/dist/gateway/handlers/session.d.ts +7 -0
  31. package/dist/gateway/handlers/system.d.ts +7 -0
  32. package/dist/gateway/handlers/tool.d.ts +7 -0
  33. package/dist/gateway/index.d.ts +18 -0
  34. package/dist/gateway/protocol.d.ts +159 -0
  35. package/dist/gateway/router.d.ts +7 -0
  36. package/dist/gateway/server.d.ts +24 -0
  37. package/dist/global/index.d.ts +23 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.js +34 -0
  40. package/dist/permission/index.d.ts +2 -0
  41. package/dist/permission/permission.d.ts +172 -0
  42. package/dist/permission/types.d.ts +109 -0
  43. package/dist/project/index.d.ts +3 -0
  44. package/dist/project/instance.d.ts +33 -0
  45. package/dist/project/project.d.ts +82 -0
  46. package/dist/project/state.d.ts +4 -0
  47. package/dist/prompt/index.d.ts +5 -0
  48. package/dist/prompt/system.d.ts +29 -0
  49. package/dist/prompt/template.d.ts +24 -0
  50. package/dist/provider/index.d.ts +3 -0
  51. package/dist/provider/models.d.ts +14 -0
  52. package/dist/provider/provider.d.ts +848 -0
  53. package/dist/provider/types.d.ts +328 -0
  54. package/dist/server/index.d.ts +21 -0
  55. package/dist/server/routes/api.d.ts +2 -0
  56. package/dist/server/routes/auth.d.ts +2 -0
  57. package/dist/server/routes/events.d.ts +2 -0
  58. package/dist/server/routes/health.d.ts +2 -0
  59. package/dist/server/routes/sessions.d.ts +2 -0
  60. package/dist/server/services/agent.d.ts +40 -0
  61. package/dist/server/services/permission.d.ts +43 -0
  62. package/dist/server/sse/emitter.d.ts +57 -0
  63. package/dist/session/context-cache.d.ts +75 -0
  64. package/dist/session/context-optimization.d.ts +165 -0
  65. package/dist/session/index.d.ts +5 -0
  66. package/dist/session/llm.d.ts +68 -0
  67. package/dist/session/message-optimizer.d.ts +32 -0
  68. package/dist/session/session.d.ts +524 -0
  69. package/dist/session/title-generator.d.ts +11 -0
  70. package/dist/session/types.d.ts +713 -0
  71. package/dist/snapshot/index.d.ts +40 -0
  72. package/dist/storage/index.d.ts +1 -0
  73. package/dist/storage/storage.d.ts +34 -0
  74. package/dist/theme.d.ts +64 -0
  75. package/dist/tool/bash.d.ts +19 -0
  76. package/dist/tool/edit.d.ts +21 -0
  77. package/dist/tool/glob.d.ts +15 -0
  78. package/dist/tool/grep.d.ts +20 -0
  79. package/dist/tool/image.d.ts +22 -0
  80. package/dist/tool/index.d.ts +11 -0
  81. package/dist/tool/ls.d.ts +14 -0
  82. package/dist/tool/read.d.ts +17 -0
  83. package/dist/tool/registry.d.ts +30 -0
  84. package/dist/tool/think.d.ts +11 -0
  85. package/dist/tool/todo.d.ts +76 -0
  86. package/dist/tool/tool.d.ts +65 -0
  87. package/dist/tool/webfetch.d.ts +15 -0
  88. package/dist/tool/write.d.ts +16 -0
  89. package/dist/tui/App.d.ts +10 -0
  90. package/dist/tui/components/Header.d.ts +13 -0
  91. package/dist/tui/components/LoadingIndicator.d.ts +26 -0
  92. package/dist/tui/components/Message/AssistantMessage.d.ts +11 -0
  93. package/dist/tui/components/Message/ReasoningMessage.d.ts +21 -0
  94. package/dist/tui/components/Message/ToolCallMessage.d.ts +26 -0
  95. package/dist/tui/components/Message/UserMessage.d.ts +12 -0
  96. package/dist/tui/components/Message/index.d.ts +16 -0
  97. package/dist/tui/components/PermissionPrompt.d.ts +6 -0
  98. package/dist/tui/components/PromptInput.d.ts +33 -0
  99. package/dist/tui/components/REPL.d.ts +22 -0
  100. package/dist/tui/components/Spinner.d.ts +13 -0
  101. package/dist/tui/components/StatusBar.d.ts +13 -0
  102. package/dist/tui/components/TodoList.d.ts +17 -0
  103. package/dist/tui/components/WelcomeBox.d.ts +13 -0
  104. package/dist/tui/components/dialogs/DiagnosticsPanel.d.ts +12 -0
  105. package/dist/tui/components/dialogs/HelpPanel.d.ts +11 -0
  106. package/dist/tui/components/dialogs/ModelSelector.d.ts +14 -0
  107. package/dist/tui/components/dialogs/PermissionPrompt.d.ts +17 -0
  108. package/dist/tui/components/dialogs/SessionPicker.d.ts +20 -0
  109. package/dist/tui/components/dialogs/index.d.ts +10 -0
  110. package/dist/tui/components/diff/DiffHunk.d.ts +12 -0
  111. package/dist/tui/components/diff/DiffLine.d.ts +14 -0
  112. package/dist/tui/components/diff/DiffStats.d.ts +12 -0
  113. package/dist/tui/components/diff/DiffView.d.ts +15 -0
  114. package/dist/tui/components/diff/index.d.ts +9 -0
  115. package/dist/tui/hooks/useAnimatedLabel.d.ts +12 -0
  116. package/dist/tui/hooks/usePermission.d.ts +34 -0
  117. package/dist/tui/hooks/useTermWidth.d.ts +13 -0
  118. package/dist/tui/index.d.ts +20 -0
  119. package/dist/tui/theme.d.ts +8 -0
  120. package/dist/tui/utils/Cursor.d.ts +37 -0
  121. package/dist/tui/utils/clipboard.d.ts +3 -0
  122. package/dist/tui/utils/keypress.d.ts +39 -0
  123. package/dist/tui/utils/markdown.d.ts +13 -0
  124. package/dist/tui/utils/openContent.d.ts +22 -0
  125. package/dist/util/ascii.d.ts +22 -0
  126. package/dist/util/bell.d.ts +14 -0
  127. package/dist/util/color.d.ts +28 -0
  128. package/dist/util/context.d.ts +10 -0
  129. package/dist/util/debug.d.ts +51 -0
  130. package/dist/util/error.d.ts +294 -0
  131. package/dist/util/example-commands.d.ts +18 -0
  132. package/dist/util/filesystem.d.ts +17 -0
  133. package/dist/util/id.d.ts +24 -0
  134. package/dist/util/iife.d.ts +1 -0
  135. package/dist/util/index.d.ts +7 -0
  136. package/dist/util/lazy.d.ts +1 -0
  137. package/dist/util/log.d.ts +26 -0
  138. package/dist/util/paths.d.ts +45 -0
  139. package/dist/util/shell.d.ts +36 -0
  140. package/dist/util/timeout.d.ts +1 -0
  141. package/dist/util/wildcard.d.ts +8 -0
  142. package/package.json +87 -0
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Context Optimization Module
3
+ *
4
+ * Handles context overflow detection, pruning, and auto-compaction.
5
+ * Based on code-cli/opencode methodology:
6
+ * - Overflow: triggers when tokens > (context_limit - output_max)
7
+ * - Pruning: removes old tool outputs (20k min savings, 40k protected)
8
+ * - Compaction: generates summary to reduce context
9
+ */
10
+ export interface TokenUsage {
11
+ input: number;
12
+ output: number;
13
+ cacheRead?: number;
14
+ cacheWrite?: number;
15
+ }
16
+ export interface OverflowCheckOptions {
17
+ tokens: TokenUsage;
18
+ contextLimit: number;
19
+ outputLimit?: number;
20
+ autoEnabled: boolean;
21
+ }
22
+ export interface ContextPercentageOptions {
23
+ tokens: TokenUsage;
24
+ contextLimit: number;
25
+ }
26
+ export interface ToolResultPart {
27
+ type: "tool-result";
28
+ id: string;
29
+ messageId: string;
30
+ sessionId: string;
31
+ toolCallId: string;
32
+ toolName?: string;
33
+ output: string;
34
+ metadata?: {
35
+ tokenEstimate?: number;
36
+ [key: string]: unknown;
37
+ };
38
+ }
39
+ export interface PrunablePartInfo {
40
+ part: ToolResultPart;
41
+ tokens: number;
42
+ }
43
+ export interface PruningAnalysis {
44
+ prunableParts: PrunablePartInfo[];
45
+ potentialSavings: number;
46
+ totalTokens: number;
47
+ }
48
+ export interface CompactionCheckOptions {
49
+ isOverflow: boolean;
50
+ potentialPruneSavings: number;
51
+ }
52
+ export interface SimpleMessage {
53
+ role: "user" | "assistant" | "system";
54
+ content: string;
55
+ }
56
+ export interface CompactedMessage {
57
+ role: "user";
58
+ content: string;
59
+ isCompacted: true;
60
+ }
61
+ /**
62
+ * Context Optimization - Static utilities for managing context window
63
+ */
64
+ export declare const ContextOptimization: {
65
+ /**
66
+ * Minimum token savings required to trigger pruning
67
+ * Must save at least 20,000 tokens to be worth pruning
68
+ */
69
+ PRUNE_MINIMUM: number;
70
+ /**
71
+ * Token threshold for protecting recent content from pruning
72
+ * Last 40,000 tokens are protected from removal
73
+ */
74
+ PRUNE_PROTECT: number;
75
+ /**
76
+ * Maximum output tokens to reserve for model response
77
+ * Matches Claude's typical max output
78
+ */
79
+ OUTPUT_TOKEN_MAX: number;
80
+ /**
81
+ * Tools whose outputs should never be pruned
82
+ * Skills are protected because they may contain important state
83
+ */
84
+ PROTECTED_TOOLS: readonly ["skill"];
85
+ /**
86
+ * Warning threshold percentage (60%)
87
+ */
88
+ WARNING_THRESHOLD: number;
89
+ /**
90
+ * Critical threshold percentage (80%)
91
+ */
92
+ CRITICAL_THRESHOLD: number;
93
+ /**
94
+ * Check if context is overflowing
95
+ * Overflow occurs when total tokens exceed usable context
96
+ * (context_limit - output_reserved)
97
+ */
98
+ isOverflow(options: OverflowCheckOptions): boolean;
99
+ /**
100
+ * Calculate usable context after reserving space for output
101
+ * Uses the smaller of OUTPUT_TOKEN_MAX or model's output limit
102
+ */
103
+ calculateUsableContext(contextLimit: number, outputLimit?: number): number;
104
+ /**
105
+ * Calculate percentage of context window used
106
+ */
107
+ getContextPercentage(options: ContextPercentageOptions): number;
108
+ /**
109
+ * Check if we should show a warning (60%+ usage)
110
+ */
111
+ shouldWarn(percentage: number): boolean;
112
+ /**
113
+ * Check if we should show critical warning (80%+ usage)
114
+ */
115
+ shouldShowCritical(percentage: number): boolean;
116
+ /**
117
+ * Check if pruning would be worthwhile
118
+ * Only prune if we can save at least PRUNE_MINIMUM tokens
119
+ */
120
+ shouldPrune(potentialSavings: number): boolean;
121
+ /**
122
+ * Check if a tool's output should be protected from pruning
123
+ */
124
+ isProtectedTool(toolName: string): boolean;
125
+ /**
126
+ * Calculate total tokens from usage object
127
+ * Includes input, output, and cache tokens
128
+ */
129
+ calculateTotalTokens(tokens: TokenUsage): number;
130
+ /**
131
+ * Estimate tokens from text content
132
+ * Uses ~4 characters per token as a rough estimate
133
+ */
134
+ estimateTokens(text: string): number;
135
+ /**
136
+ * Analyze parts to find prunable tool results
137
+ * Protects recent content (within PRUNE_PROTECT threshold)
138
+ * and outputs from protected tools
139
+ */
140
+ analyzePrunableParts(parts: ToolResultPart[]): PruningAnalysis;
141
+ /**
142
+ * Prune content by truncating long outputs
143
+ * Keeps first few and last few lines for context
144
+ */
145
+ pruneContent(output: string, maxLength?: number): string;
146
+ /**
147
+ * Determine if compaction is needed
148
+ * Returns true if overflow and pruning won't save enough
149
+ */
150
+ shouldCompact(options: CompactionCheckOptions): boolean;
151
+ /**
152
+ * Generate the prompt for creating a conversation summary
153
+ */
154
+ getCompactionPrompt(messages: SimpleMessage[]): string;
155
+ /**
156
+ * Create a compacted message from a summary
157
+ */
158
+ createCompactedMessage(summary: string): CompactedMessage;
159
+ /**
160
+ * Generate a summary of messages using LLM
161
+ * Always uses Sonnet 4.5 for cost efficiency
162
+ */
163
+ compact(messages: SimpleMessage[]): Promise<CompactedMessage>;
164
+ };
165
+ export type { OverflowCheckOptions as ContextOverflowOptions };
@@ -0,0 +1,5 @@
1
+ export * from "./types";
2
+ export { Session } from "./session";
3
+ export { LLM } from "./llm";
4
+ export { ContextOptimization } from "./context-optimization";
5
+ export { TitleGenerator } from "./title-generator";
@@ -0,0 +1,68 @@
1
+ import { streamText, type ModelMessage, type Tool } from "ai";
2
+ import { type OperationMode } from "../prompt";
3
+ import type { ModelInfo } from "../provider/types";
4
+ export declare namespace LLM {
5
+ interface StreamOptions {
6
+ sessionId: string;
7
+ model: ModelInfo;
8
+ messages: ModelMessage[];
9
+ system?: string[];
10
+ tools?: Record<string, Tool>;
11
+ temperature?: number;
12
+ maxTokens?: number;
13
+ signal?: AbortSignal;
14
+ mode?: OperationMode;
15
+ }
16
+ interface StreamResult {
17
+ stream: AsyncIterable<any>;
18
+ response: Promise<any>;
19
+ }
20
+ /**
21
+ * Stream a response from the LLM
22
+ */
23
+ function stream(options: StreamOptions): Promise<ReturnType<typeof streamText>>;
24
+ /**
25
+ * Token usage breakdown including cache-specific counts
26
+ */
27
+ interface TokenUsage {
28
+ /** Regular input tokens (not from cache) */
29
+ input: number;
30
+ /** Output tokens generated */
31
+ output: number;
32
+ /** Tokens read from cache (cache hits) */
33
+ cacheRead: number;
34
+ /** Tokens written to cache (cache creation) */
35
+ cacheWrite: number;
36
+ /** Total tokens (input + output + cache operations) */
37
+ total: number;
38
+ }
39
+ /**
40
+ * Count tokens including cache-specific breakdown
41
+ */
42
+ function countTokens(usage: {
43
+ inputTokens?: number;
44
+ outputTokens?: number;
45
+ cachedInputTokens?: number;
46
+ cacheCreationInputTokens?: number;
47
+ }): TokenUsage;
48
+ /**
49
+ * Count only cached tokens (reads and writes)
50
+ */
51
+ function countCachedTokens(usage: {
52
+ cachedInputTokens?: number;
53
+ cacheCreationInputTokens?: number;
54
+ }): {
55
+ read: number;
56
+ write: number;
57
+ total: number;
58
+ };
59
+ /**
60
+ * Calculate token usage cost including cache tokens
61
+ */
62
+ function calculateCost(model: ModelInfo, usage: {
63
+ inputTokens?: number;
64
+ outputTokens?: number;
65
+ cachedInputTokens?: number;
66
+ cacheCreationInputTokens?: number;
67
+ }): number;
68
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Message Optimization Module
3
+ *
4
+ * Optimizes messages before sending to LLM:
5
+ * - Merges consecutive tool_results to reduce message count
6
+ * - Filters out progress messages that add noise
7
+ */
8
+ import type { ModelMessage } from "ai";
9
+ /**
10
+ * Merge consecutive tool result messages
11
+ */
12
+ export declare function mergeToolResults(messages: ModelMessage[]): ModelMessage[];
13
+ /**
14
+ * Filter out progress messages
15
+ */
16
+ export declare function filterProgressMessages(messages: ModelMessage[]): ModelMessage[];
17
+ /**
18
+ * Optimize messages for LLM
19
+ */
20
+ export declare function optimizeMessages(messages: ModelMessage[], options?: {
21
+ mergeToolResults?: boolean;
22
+ filterProgress?: boolean;
23
+ }): ModelMessage[];
24
+ /**
25
+ * Statistics about message optimization
26
+ */
27
+ export declare function getOptimizationStats(original: ModelMessage[], optimized: ModelMessage[]): {
28
+ originalCount: number;
29
+ optimizedCount: number;
30
+ reduction: number;
31
+ reductionPercent: number;
32
+ };