@allternit/gizzi-code 1.0.0 → 1.0.1

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 (158) hide show
  1. package/bin/gizzi +4 -0
  2. package/bin/gizzi-ink +5 -0
  3. package/package.json +137 -31
  4. package/src/Tool.ts +26 -0
  5. package/src/bootstrap/state.ts +165 -322
  6. package/src/commands.ts +209 -0
  7. package/src/context/QueuedMessageContext.tsx +63 -0
  8. package/src/context/fpsMetrics.tsx +30 -0
  9. package/src/context/mailbox.tsx +38 -0
  10. package/src/context/modalContext.tsx +58 -0
  11. package/src/context/notifications.tsx +240 -0
  12. package/src/context/overlayContext.tsx +151 -0
  13. package/src/context/promptOverlayContext.tsx +125 -0
  14. package/src/context/stats.tsx +220 -0
  15. package/src/context/voice.tsx +88 -0
  16. package/src/hooks/useCanUseTool.ts +11 -0
  17. package/src/hooks/useExitOnCtrlCD.ts +40 -187
  18. package/src/hooks/useExitOnCtrlCDWithKeybindings.ts +68 -0
  19. package/src/hooks/useKeybinding.ts +68 -209
  20. package/src/hooks/useTerminalSize.ts +31 -99
  21. package/src/hooks.ts +37 -0
  22. package/src/ink.ts +204 -0
  23. package/src/main.ts +7 -0
  24. package/src/types/command.ts +216 -0
  25. package/src/types/connectorText.ts +39 -0
  26. package/src/types/fileSuggestion.ts +15 -0
  27. package/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.ts +865 -0
  28. package/src/types/generated/events_mono/common/v1/auth.ts +100 -0
  29. package/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.ts +223 -0
  30. package/src/types/generated/google/protobuf/timestamp.ts +187 -0
  31. package/src/types/hooks.ts +319 -0
  32. package/src/types/ids.ts +44 -0
  33. package/src/types/logs.ts +331 -0
  34. package/src/types/merged/index.ts +5 -0
  35. package/src/types/merged/message.ts +552 -0
  36. package/src/types/message.ts +927 -186
  37. package/src/types/messageQueueTypes.ts +21 -0
  38. package/src/types/notebook.ts +72 -0
  39. package/src/types/permissions.ts +447 -0
  40. package/src/types/plugin.ts +363 -0
  41. package/src/types/statusLine.ts +15 -0
  42. package/src/types/textInputTypes.ts +387 -0
  43. package/src/types/tools.ts +149 -0
  44. package/src/types/utils.ts +20 -0
  45. package/src/utils/advisor.ts +12 -0
  46. package/src/utils/api.ts +29 -0
  47. package/src/utils/array.ts +7 -0
  48. package/src/utils/attachments.ts +60 -0
  49. package/src/utils/auth.ts +3 -0
  50. package/src/utils/claudeInChrome/chromeNativeHost.ts +15 -0
  51. package/src/utils/claudeInChrome/common.ts +12 -0
  52. package/src/utils/claudeInChrome/mcpServer.ts +15 -0
  53. package/src/utils/computerUse/common.ts +19 -0
  54. package/src/utils/computerUse/mcpServer.ts +15 -0
  55. package/src/utils/config.ts +35 -0
  56. package/src/utils/context.ts +19 -0
  57. package/src/utils/cwd.ts +3 -0
  58. package/src/utils/debug.ts +3 -0
  59. package/src/utils/earlyInput.ts +7 -0
  60. package/src/utils/effort.ts +13 -0
  61. package/src/utils/embeddedTools.ts +12 -0
  62. package/src/utils/envUtils.ts +3 -0
  63. package/src/utils/errors.ts +3 -0
  64. package/src/utils/execFileNoThrow.ts +24 -0
  65. package/src/utils/feature-flags.ts +112 -0
  66. package/src/utils/file.ts +3 -0
  67. package/src/utils/fileHistory.ts +17 -0
  68. package/src/utils/fingerprint.ts +7 -0
  69. package/src/utils/format.ts +75 -305
  70. package/src/utils/frontmatterParser.ts +33 -0
  71. package/src/utils/fsOperations.ts +31 -0
  72. package/src/utils/fullscreen.ts +40 -350
  73. package/src/utils/git.ts +15 -0
  74. package/src/utils/imageResizer.ts +30 -0
  75. package/src/utils/lazySchema.ts +9 -0
  76. package/src/utils/log.ts +3 -0
  77. package/src/utils/markdownConfigLoader.ts +12 -0
  78. package/src/utils/messages.ts +13 -0
  79. package/src/utils/migration.ts +137 -0
  80. package/src/utils/model/providers.ts +15 -0
  81. package/src/utils/path.ts +3 -0
  82. package/src/utils/permissions/PermissionResult.ts +14 -0
  83. package/src/utils/permissions/autoModeState.ts +12 -0
  84. package/src/utils/permissions/filesystem.ts +12 -0
  85. package/src/utils/plugins/loadPluginOutputStyles.ts +12 -0
  86. package/src/utils/plugins/schemas.ts +25 -0
  87. package/src/utils/process.ts +16 -0
  88. package/src/utils/sandbox/sandbox-adapter.ts +19 -0
  89. package/src/utils/sessionStorage.ts +238 -472
  90. package/src/utils/settings/constants.ts +10 -0
  91. package/src/utils/settings/settings.ts +19 -0
  92. package/src/utils/settings/types.ts +18 -0
  93. package/src/utils/shell/shellToolUtils.ts +9 -0
  94. package/src/utils/sinks.ts +11 -0
  95. package/src/utils/sleep.ts +7 -0
  96. package/src/utils/sliceAnsi.ts +7 -0
  97. package/src/utils/slowOperations.ts +3 -0
  98. package/src/utils/startupProfiler.ts +11 -0
  99. package/src/utils/stringUtils.ts +106 -0
  100. package/src/utils/systemPromptType.ts +9 -0
  101. package/src/utils/teleport/api.ts +15 -0
  102. package/src/utils/textHighlighting.ts +16 -0
  103. package/src/utils/theme.ts +17 -0
  104. package/src/utils/thinking.ts +58 -0
  105. package/src/utils/tokens.ts +11 -0
  106. package/src/utils/toolResultStorage.ts +17 -0
  107. package/src/utils/worktreeModeEnabled.ts +7 -0
  108. package/WORKSPACE_INTEGRATION.md +0 -290
  109. package/chat-sessions/sessions-index.json +0 -98
  110. package/package.json.original +0 -31
  111. package/package.json.publish +0 -47
  112. package/src/bootstrap/state.d.ts +0 -169
  113. package/src/bootstrap/state.js +0 -261
  114. package/src/context/pack-builder.d.ts +0 -24
  115. package/src/context/pack-builder.js +0 -281
  116. package/src/hooks/useExitOnCtrlCD.d.ts +0 -86
  117. package/src/hooks/useExitOnCtrlCD.js +0 -130
  118. package/src/hooks/useKeybinding.d.ts +0 -89
  119. package/src/hooks/useKeybinding.js +0 -163
  120. package/src/hooks/useTerminalSize.d.ts +0 -41
  121. package/src/hooks/useTerminalSize.js +0 -90
  122. package/src/index.d.ts +0 -23
  123. package/src/index.js +0 -24
  124. package/src/runtime/brand/brand.d.ts +0 -488
  125. package/src/runtime/brand/brand.js +0 -464
  126. package/src/runtime/brand/brand.ts +0 -667
  127. package/src/runtime/services/tokenEstimation.d.ts +0 -187
  128. package/src/runtime/services/tokenEstimation.js +0 -423
  129. package/src/runtime/services/tokenEstimation.ts +0 -547
  130. package/src/runtime/tools/Tool.d.ts +0 -239
  131. package/src/runtime/tools/Tool.js +0 -285
  132. package/src/runtime/tools/Tool.ts +0 -524
  133. package/src/scheduler/TaskScheduler.d.ts +0 -98
  134. package/src/scheduler/TaskScheduler.js +0 -201
  135. package/src/scheduler/TaskScheduler.ts +0 -259
  136. package/src/state/AppStateStore.d.ts +0 -347
  137. package/src/state/AppStateStore.js +0 -439
  138. package/src/state/AppStateStore.ts +0 -658
  139. package/src/state/WorkspaceStateStore.d.ts +0 -43
  140. package/src/state/WorkspaceStateStore.js +0 -224
  141. package/src/state/WorkspaceStateStore.ts +0 -297
  142. package/src/types/message.d.ts +0 -190
  143. package/src/types/message.js +0 -77
  144. package/src/utils/format.d.ts +0 -126
  145. package/src/utils/format.js +0 -230
  146. package/src/utils/fullscreen.d.ts +0 -161
  147. package/src/utils/fullscreen.js +0 -277
  148. package/src/utils/sessionStorage.d.ts +0 -210
  149. package/src/utils/sessionStorage.js +0 -435
  150. package/src/watcher/WorkspaceWatcher.d.ts +0 -70
  151. package/src/watcher/WorkspaceWatcher.js +0 -191
  152. package/src/watcher/WorkspaceWatcher.ts +0 -251
  153. package/src/workspace/loader.d.ts +0 -30
  154. package/src/workspace/loader.js +0 -117
  155. package/src/workspace/types.d.ts +0 -91
  156. package/src/workspace/types.js +0 -7
  157. package/threads/thread_1775361175022.json +0 -9
  158. package/tsconfig.json +0 -14
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Settings Constants
3
+ */
4
+
5
+ export type SettingSource = 'config' | 'env' | 'default'
6
+
7
+ export const DEFAULT_SETTINGS = {
8
+ theme: 'default',
9
+ autoCompact: true,
10
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Settings Utilities
3
+ */
4
+
5
+ import type { Settings } from './types.js'
6
+
7
+ let cachedSettings: Settings = {}
8
+
9
+ export function getSettings(): Settings {
10
+ return cachedSettings
11
+ }
12
+
13
+ export function getInitialSettings(): Settings {
14
+ return {}
15
+ }
16
+
17
+ export function updateSettings(settings: Partial<Settings>): void {
18
+ cachedSettings = { ...cachedSettings, ...settings }
19
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Settings Types
3
+ */
4
+
5
+ export interface Settings {
6
+ theme?: string
7
+ autoCompact?: boolean
8
+ [key: string]: unknown
9
+ }
10
+
11
+ export interface PluginHookMatcher {
12
+ plugin: string
13
+ hook: string
14
+ }
15
+
16
+ export interface HooksSettings {
17
+ [hook: string]: unknown
18
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shell Tool Utilities
3
+ */
4
+
5
+ export const SHELL_TOOL_NAMES = {
6
+ bash: 'BashTool',
7
+ glob: 'GlobTool',
8
+ grep: 'GrepTool',
9
+ } as const
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Output Sinks
3
+ */
4
+
5
+ export interface Sink {
6
+ write(data: string): void
7
+ }
8
+
9
+ export function getSinks(): Sink[] {
10
+ return []
11
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Sleep Utility
3
+ */
4
+
5
+ export function sleep(ms: number): Promise<void> {
6
+ return new Promise(resolve => setTimeout(resolve, ms))
7
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * ANSI String Slicing
3
+ */
4
+
5
+ export function sliceAnsi(str: string, start: number, end?: number): string {
6
+ return str.slice(start, end)
7
+ }
@@ -0,0 +1,3 @@
1
+ // Re-export from shared/utils
2
+ export * from '../shared/utils/slowOperations.js'
3
+ export { default } from '../shared/utils/slowOperations.js'
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Startup Profiler
3
+ */
4
+
5
+ export function profileCheckpoint(label: string): void {
6
+ // Implementation
7
+ }
8
+
9
+ export function getStartupProfile(): Record<string, number> {
10
+ return {}
11
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * String utilities
3
+ * Production implementation with all required exports
4
+ */
5
+
6
+ // Escape special regex characters
7
+ export function escapeRegExp(str: string): string {
8
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
9
+ }
10
+
11
+ // Capitalize first letter
12
+ export function capitalize(str: string): string {
13
+ if (!str) return str
14
+ return str.charAt(0).toUpperCase() + str.slice(1)
15
+ }
16
+
17
+ // Pluralize a word
18
+ export function plural(
19
+ count: number,
20
+ singular: string,
21
+ plural?: string,
22
+ includeCount = true,
23
+ ): string {
24
+ const p = plural ?? `${singular}s`
25
+ const word = count === 1 ? singular : p
26
+ return includeCount ? `${count} ${word}` : word
27
+ }
28
+
29
+ // Get first line of a string
30
+ export function firstLineOf(s: string): string {
31
+ const idx = s.indexOf('\n')
32
+ return idx === -1 ? s : s.slice(0, idx)
33
+ }
34
+
35
+ // Count occurrences of a character in a string
36
+ export function countCharInString(str: string, char: string): number {
37
+ let count = 0
38
+ for (let i = 0; i < str.length; i++) {
39
+ if (str[i] === char) count++
40
+ }
41
+ return count
42
+ }
43
+
44
+ // Normalize full-width digits to ASCII
45
+ export function normalizeFullWidthDigits(input: string): string {
46
+ return input.replace(/[\uFF10-\uFF19]/g, (c) =>
47
+ String.fromCharCode(c.charCodeAt(0) - 0xfee0),
48
+ )
49
+ }
50
+
51
+ // Normalize full-width space to ASCII space
52
+ export function normalizeFullWidthSpace(input: string): string {
53
+ return input.replace(/\u3000/g, ' ')
54
+ }
55
+
56
+ // Join lines with safe handling of undefined values
57
+ export function safeJoinLines(
58
+ lines: (string | undefined | null)[],
59
+ separator = '\n',
60
+ ): string {
61
+ return lines.filter((l): l is string => l != null && l !== '').join(separator)
62
+ }
63
+
64
+ // Truncate text to a maximum number of lines
65
+ export function truncateToLines(text: string, maxLines: number): string {
66
+ const lines = text.split('\n')
67
+ if (lines.length <= maxLines) return text
68
+ return lines.slice(0, maxLines).join('\n') + '\n… (truncated)'
69
+ }
70
+
71
+ // Truncating accumulator that builds text line by line
72
+ export class EndTruncatingAccumulator {
73
+ private lines: string[] = []
74
+ private _truncated = false
75
+
76
+ constructor(
77
+ private maxLines: number,
78
+ private overflowIndicator = '\n… (truncated)',
79
+ ) {}
80
+
81
+ add(line: string): this {
82
+ if (!this._truncated) {
83
+ if (this.lines.length >= this.maxLines) {
84
+ this._truncated = true
85
+ } else {
86
+ this.lines.push(line)
87
+ }
88
+ }
89
+ return this
90
+ }
91
+
92
+ get truncated(): boolean {
93
+ return this._truncated
94
+ }
95
+
96
+ toString(): string {
97
+ const lines = this._truncated
98
+ ? [...this.lines, this.overflowIndicator]
99
+ : this.lines
100
+ return lines.join('\n')
101
+ }
102
+
103
+ get lineCount(): number {
104
+ return this.lines.length
105
+ }
106
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * System Prompt Type
3
+ */
4
+
5
+ export type SystemPrompt = string
6
+
7
+ export function asSystemPrompt(prompt: string): SystemPrompt {
8
+ return prompt
9
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Teleport API Utilities
3
+ */
4
+
5
+ export interface TeleportApiConfig {
6
+ baseUrl: string
7
+ token?: string
8
+ }
9
+
10
+ export async function teleportRequest<T>(
11
+ endpoint: string,
12
+ config?: TeleportApiConfig
13
+ ): Promise<T> {
14
+ return {} as T
15
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Text Highlighting Utilities
3
+ */
4
+
5
+ export interface HighlightOptions {
6
+ language?: string
7
+ theme?: string
8
+ }
9
+
10
+ export function highlightText(text: string, options?: HighlightOptions): string {
11
+ return text
12
+ }
13
+
14
+ export function highlightCode(code: string, language?: string): string {
15
+ return code
16
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Theme Utilities
3
+ */
4
+
5
+ export interface Theme {
6
+ name: string
7
+ colors: Record<string, string>
8
+ }
9
+
10
+ export const defaultTheme: Theme = {
11
+ name: 'default',
12
+ colors: {},
13
+ }
14
+
15
+ export function getTheme(): Theme {
16
+ return defaultTheme
17
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Thinking/thought process utilities
3
+ */
4
+
5
+ export interface Thought {
6
+ id: string
7
+ content: string
8
+ timestamp: number
9
+ category?: string
10
+ }
11
+
12
+ export class ThinkingSession {
13
+ private thoughts: Thought[] = []
14
+ private isActive = false
15
+
16
+ start(): void {
17
+ this.isActive = true
18
+ this.thoughts = []
19
+ }
20
+
21
+ stop(): Thought[] {
22
+ this.isActive = false
23
+ return [...this.thoughts]
24
+ }
25
+
26
+ addThought(content: string, category?: string): void {
27
+ if (!this.isActive) return
28
+ this.thoughts.push({
29
+ id: `thought_${Date.now()}_${Math.random().toString(36).slice(2)}`,
30
+ content,
31
+ timestamp: Date.now(),
32
+ category,
33
+ })
34
+ }
35
+
36
+ getThoughts(): Thought[] {
37
+ return [...this.thoughts]
38
+ }
39
+
40
+ clear(): void {
41
+ this.thoughts = []
42
+ }
43
+
44
+ isThinking(): boolean {
45
+ return this.isActive
46
+ }
47
+ }
48
+
49
+ export function formatThought(thought: Thought): string {
50
+ const time = new Date(thought.timestamp).toLocaleTimeString()
51
+ const category = thought.category ? `[${thought.category}] ` : ''
52
+ return `${time} ${category}${thought.content}`
53
+ }
54
+
55
+ export default {
56
+ ThinkingSession,
57
+ formatThought,
58
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Token Utilities
3
+ */
4
+
5
+ export function estimateTokens(text: string): number {
6
+ return Math.ceil(text.length / 4)
7
+ }
8
+
9
+ export function countTokens(text: string): number {
10
+ return estimateTokens(text)
11
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Tool Result Storage
3
+ */
4
+
5
+ export interface ToolResultEntry {
6
+ tool: string
7
+ result: unknown
8
+ timestamp: number
9
+ }
10
+
11
+ export async function storeToolResult(entry: ToolResultEntry): Promise<void> {
12
+ // Implementation
13
+ }
14
+
15
+ export async function getToolResults(tool: string): Promise<ToolResultEntry[]> {
16
+ return []
17
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Worktree Mode Check
3
+ */
4
+
5
+ export function isWorktreeModeEnabled(): boolean {
6
+ return false
7
+ }
@@ -1,290 +0,0 @@
1
- # Gizzi Code - Workspace Integration
2
-
3
- ## Overview
4
-
5
- Gizzi Code now supports **agent workspace files** - the same production-quality implementation as the Allternit Platform.
6
-
7
- ## Features
8
-
9
- ### ✅ Workspace File Loading
10
- - SOUL.md (trust tiers, self-awareness)
11
- - HEARTBEAT.md (periodic tasks)
12
- - IDENTITY.md (core identity)
13
- - PLAYBOOK.md (execution rules)
14
- - TOOLS.md (tool inventory)
15
- - VOICE.md (communication style)
16
- - BRAIN.md, MEMORY.md (memory system)
17
- - And all other workspace files
18
-
19
- ### ✅ Trust Tier Enforcement
20
- SOUL.md trust tiers are parsed and enforced:
21
- - **Tier 1**: Always apply (hard rules)
22
- - **Tier 2**: Context-dependent (apply when relevant)
23
- - **Tier 3**: Permission required (ask user first)
24
-
25
- ### ✅ HEARTBEAT Task Execution
26
- HEARTBEAT.md tasks are executed on session start:
27
- - `on-session-start` tasks run immediately
28
- - Future: `daily`, `weekly`, `monthly` scheduled tasks
29
-
30
- ### ✅ Context Sent with Every Message
31
- Full context pack sent to AI on every interaction:
32
- ```typescript
33
- {
34
- systemPrompt: 'Complete agent identity and rules',
35
- trustTiers: { tier1, tier2, tier3 },
36
- governance: { playbook, tools, hardBans },
37
- heartbeat: { tasks },
38
- memory: { brain, activeTasks, lessons }
39
- }
40
- ```
41
-
42
- ## Usage
43
-
44
- ### Basic Setup
45
-
46
- ```typescript
47
- import { getWorkspaceStore, loadWorkspace } from '@gizzi/code';
48
-
49
- // Get the workspace-enabled store
50
- const store = getWorkspaceStore();
51
-
52
- // Configure filesystem
53
- store.setFileSystem({
54
- readFile: async (path) => { /* ... */ },
55
- listDirectory: async (path) => { /* ... */ },
56
- exists: async (path) => { /* ... */ },
57
- }, '/path/to/agent/workspace');
58
- ```
59
-
60
- ### Activate Agent Mode
61
-
62
- ```typescript
63
- // Activate agent with workspace
64
- const success = await store.activateAgentMode('my-agent', 'My Custom Agent');
65
-
66
- if (success) {
67
- console.log('Agent mode activated with workspace context');
68
-
69
- // Send message with automatic context inclusion
70
- await store.sendMessageWithContext('Hello!');
71
- }
72
- ```
73
-
74
- ### Check Trust Tiers
75
-
76
- ```typescript
77
- // Before executing sensitive actions
78
- if (store.requiresPermission('deploy_to_production')) {
79
- await askUserPermission('Deploy to production?');
80
- }
81
-
82
- // Get full trust tiers
83
- const tiers = store.getTrustTiers();
84
- console.log('Tier 1 rules:', tiers?.tier1.rules);
85
- ```
86
-
87
- ### Get System Prompt
88
-
89
- ```typescript
90
- // Get the complete system prompt built from workspace
91
- const systemPrompt = store.getSystemPrompt();
92
- console.log(systemPrompt);
93
- ```
94
-
95
- ## Workspace File Structure
96
-
97
- ```
98
- agents/{agent-id}/
99
- └── .allternit/
100
- ├── manifest.json
101
- ├── brain/BRAIN.md
102
- ├── memory/
103
- │ ├── MEMORY.md
104
- │ ├── active-tasks.md
105
- │ ├── daily.md
106
- │ ├── lessons.md
107
- │ └── self-review.md
108
- ├── identity/
109
- │ ├── IDENTITY.md
110
- │ ├── SOUL.md ← Trust tiers (CRITICAL)
111
- │ ├── USER.md
112
- │ ├── VOICE.md
113
- │ └── POLICY.md
114
- ├── governance/
115
- │ ├── PLAYBOOK.md
116
- │ ├── TOOLS.md
117
- │ ├── HEARTBEAT.md ← Scheduled tasks (CRITICAL)
118
- │ ├── SYSTEM.md
119
- │ └── CHANNELS.md
120
- ├── skills/
121
- │ └── _template/
122
- │ ├── SKILL.md
123
- │ └── contract.json
124
- └── business/
125
- └── CLIENTS.md
126
- ```
127
-
128
- ## SOUL.md Example
129
-
130
- ```markdown
131
- # SOUL.md — Agent's Soul Configuration
132
-
133
- ## Tier 1 — Foundation
134
- ✅ Always apply:
135
- - Respect user privacy
136
- - Be transparent about capabilities
137
- - Never execute code without permission
138
-
139
- ## Tier 2 — Contextual
140
- - Adapt tone to user's expertise level
141
- - Offer alternatives when uncertain
142
-
143
- ## Tier 3 — Permission Required
144
- - Access external APIs
145
- - Execute shell commands
146
- - Modify production systems
147
- - Access sensitive user data
148
-
149
- ## Self-Awareness
150
- I am {agent_name}, an AI assistant specialized in {specialty}.
151
- I aim to be helpful while respecting safety boundaries.
152
- ```
153
-
154
- ## HEARTBEAT.md Example
155
-
156
- ```markdown
157
- # HEARTBEAT.md — Periodic Tasks
158
-
159
- ## On Session Start
160
- - [ ] Load recent context from memory
161
- - [ ] Check for pending user requests
162
- - [ ] Initialize tool connections
163
-
164
- ## Daily
165
- - [ ] Memory compaction
166
- - [ ] Self-review of recent interactions
167
-
168
- ## Weekly
169
- - [ ] Performance analysis
170
- - [ ] Update knowledge base
171
- ```
172
-
173
- ## API Reference
174
-
175
- ### WorkspaceStateStore
176
-
177
- ```typescript
178
- class WorkspaceStateStore extends AppStateStore {
179
- // Configuration
180
- setFileSystem(fs: FileSystem, basePath: string): void
181
-
182
- // Agent Mode
183
- activateAgentMode(agentId: string, agentName: string): Promise<boolean>
184
- resetAgentMode(): void
185
-
186
- // Messaging with Context
187
- sendMessageWithContext(
188
- content: string,
189
- options?: { skipContext?: boolean }
190
- ): Promise<void>
191
-
192
- // Context Access
193
- getContextPack(): ContextPack | null
194
- getSystemPrompt(): string
195
- getTrustTiers(): TrustTiers | null
196
- requiresPermission(action: string): boolean
197
- isAgentMode(): boolean
198
- }
199
- ```
200
-
201
- ### Context Pack
202
-
203
- ```typescript
204
- interface ContextPack {
205
- version: '1.0.0';
206
- agentId: string;
207
- agentName: string;
208
- sessionId: string;
209
-
210
- identity: {
211
- name: string;
212
- purpose: string;
213
- backstory: string;
214
- personalityTraits: string[];
215
- };
216
-
217
- trustTiers: {
218
- tier1: TrustTier; // Always apply
219
- tier2: TrustTier; // Context-dependent
220
- tier3: TrustTier; // Permission required
221
- };
222
-
223
- governance: {
224
- playbook: string;
225
- availableTools: ToolDefinition[];
226
- hardBans: string[];
227
- };
228
-
229
- heartbeat: {
230
- tasks: ScheduledTask[];
231
- lastCheck: string;
232
- };
233
-
234
- systemPrompt: string; // Complete prompt for AI
235
- hash: string; // For caching
236
- }
237
- ```
238
-
239
- ## Integration Example
240
-
241
- ```typescript
242
- import { getWorkspaceStore } from '@gizzi/code';
243
-
244
- async function main() {
245
- const store = getWorkspaceStore();
246
-
247
- // Setup filesystem (example using Node.js fs)
248
- store.setFileSystem(
249
- {
250
- readFile: async (path) => await fs.readFile(path, 'utf-8'),
251
- listDirectory: async (path) => await fs.readdir(path, { withFileTypes: true })
252
- .then(entries => entries.map(e => ({ name: e.name, type: e.isDirectory() ? 'directory' : 'file' }))),
253
- exists: async (path) => await fs.access(path).then(() => true).catch(() => false),
254
- },
255
- '/Users/me/agents/my-agent'
256
- );
257
-
258
- // Activate agent
259
- await store.activateAgentMode('my-agent', 'Code Assistant');
260
-
261
- // Check permissions before action
262
- if (store.requiresPermission('execute_shell_command')) {
263
- const approved = await confirm('Execute: rm -rf /?');
264
- if (!approved) return;
265
- }
266
-
267
- // Send message (context automatically included)
268
- await store.sendMessageWithContext('Help me refactor this code');
269
- }
270
- ```
271
-
272
- ## Determinism
273
-
274
- The workspace system is **deterministic**:
275
- 1. Files are loaded in a specific order
276
- 2. Context pack is built with consistent structure
277
- 3. Same workspace files → same system prompt → same AI behavior
278
- 4. Context hash ensures cache consistency
279
-
280
- ## Next Steps
281
-
282
- 1. Implement backend AI integration that accepts context packs
283
- 2. ~~Add file watcher for automatic context refresh~~ ✅ Done
284
- 3. ~~Implement scheduled task execution (cron)~~ ✅ Done
285
- 4. Add context pack versioning
286
-
287
- ## See Also
288
-
289
- - Allternit Platform Workspace Implementation (mirrors this)
290
- - `WORKSPACE_PRODUCTION_IMPLEMENTATION.md` in Allternit codebase