byterover-cli 0.1.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.
Files changed (193) hide show
  1. package/README.md +781 -0
  2. package/bin/dev.cmd +4 -0
  3. package/bin/dev.js +7 -0
  4. package/bin/run.cmd +4 -0
  5. package/bin/run.js +7 -0
  6. package/dist/commands/add.d.ts +60 -0
  7. package/dist/commands/add.js +230 -0
  8. package/dist/commands/clear.d.ts +13 -0
  9. package/dist/commands/clear.js +57 -0
  10. package/dist/commands/complete.d.ts +108 -0
  11. package/dist/commands/complete.js +340 -0
  12. package/dist/commands/gen-rules.d.ts +26 -0
  13. package/dist/commands/gen-rules.js +89 -0
  14. package/dist/commands/init.d.ts +24 -0
  15. package/dist/commands/init.js +135 -0
  16. package/dist/commands/login.d.ts +22 -0
  17. package/dist/commands/login.js +103 -0
  18. package/dist/commands/push.d.ts +33 -0
  19. package/dist/commands/push.js +150 -0
  20. package/dist/commands/retrieve.d.ts +26 -0
  21. package/dist/commands/retrieve.js +101 -0
  22. package/dist/commands/space/list.d.ts +22 -0
  23. package/dist/commands/space/list.js +105 -0
  24. package/dist/commands/space/switch.d.ts +20 -0
  25. package/dist/commands/space/switch.js +110 -0
  26. package/dist/commands/status.d.ts +22 -0
  27. package/dist/commands/status.js +116 -0
  28. package/dist/config/auth.config.d.ts +32 -0
  29. package/dist/config/auth.config.js +35 -0
  30. package/dist/config/environment.d.ts +35 -0
  31. package/dist/config/environment.js +39 -0
  32. package/dist/constants.d.ts +11 -0
  33. package/dist/constants.js +12 -0
  34. package/dist/core/domain/entities/agent.d.ts +5 -0
  35. package/dist/core/domain/entities/agent.js +23 -0
  36. package/dist/core/domain/entities/auth-token.d.ts +43 -0
  37. package/dist/core/domain/entities/auth-token.js +70 -0
  38. package/dist/core/domain/entities/br-config.d.ts +25 -0
  39. package/dist/core/domain/entities/br-config.js +58 -0
  40. package/dist/core/domain/entities/bullet.d.ts +51 -0
  41. package/dist/core/domain/entities/bullet.js +94 -0
  42. package/dist/core/domain/entities/curator-output.d.ts +14 -0
  43. package/dist/core/domain/entities/curator-output.js +23 -0
  44. package/dist/core/domain/entities/delta-batch.d.ts +30 -0
  45. package/dist/core/domain/entities/delta-batch.js +52 -0
  46. package/dist/core/domain/entities/delta-operation.d.ts +31 -0
  47. package/dist/core/domain/entities/delta-operation.js +50 -0
  48. package/dist/core/domain/entities/event.d.ts +8 -0
  49. package/dist/core/domain/entities/event.js +15 -0
  50. package/dist/core/domain/entities/executor-output.d.ts +27 -0
  51. package/dist/core/domain/entities/executor-output.js +33 -0
  52. package/dist/core/domain/entities/memory.d.ts +55 -0
  53. package/dist/core/domain/entities/memory.js +90 -0
  54. package/dist/core/domain/entities/oauth-token-data.d.ts +13 -0
  55. package/dist/core/domain/entities/oauth-token-data.js +20 -0
  56. package/dist/core/domain/entities/playbook.d.ts +97 -0
  57. package/dist/core/domain/entities/playbook.js +275 -0
  58. package/dist/core/domain/entities/presigned-url.d.ts +9 -0
  59. package/dist/core/domain/entities/presigned-url.js +18 -0
  60. package/dist/core/domain/entities/presigned-urls-response.d.ts +10 -0
  61. package/dist/core/domain/entities/presigned-urls-response.js +18 -0
  62. package/dist/core/domain/entities/reflector-output.d.ts +38 -0
  63. package/dist/core/domain/entities/reflector-output.js +44 -0
  64. package/dist/core/domain/entities/retrieve-result.d.ts +35 -0
  65. package/dist/core/domain/entities/retrieve-result.js +35 -0
  66. package/dist/core/domain/entities/space.d.ts +24 -0
  67. package/dist/core/domain/entities/space.js +52 -0
  68. package/dist/core/domain/entities/team.d.ts +42 -0
  69. package/dist/core/domain/entities/team.js +89 -0
  70. package/dist/core/domain/entities/user.d.ts +20 -0
  71. package/dist/core/domain/entities/user.js +32 -0
  72. package/dist/core/domain/errors/ace-error.d.ts +34 -0
  73. package/dist/core/domain/errors/ace-error.js +53 -0
  74. package/dist/core/domain/errors/auth-error.d.ts +10 -0
  75. package/dist/core/domain/errors/auth-error.js +20 -0
  76. package/dist/core/domain/errors/discovery-error.d.ts +21 -0
  77. package/dist/core/domain/errors/discovery-error.js +33 -0
  78. package/dist/core/domain/errors/rule-error.d.ts +6 -0
  79. package/dist/core/domain/errors/rule-error.js +12 -0
  80. package/dist/core/interfaces/i-ace-prompt-builder.d.ts +48 -0
  81. package/dist/core/interfaces/i-ace-prompt-builder.js +1 -0
  82. package/dist/core/interfaces/i-auth-service.d.ts +35 -0
  83. package/dist/core/interfaces/i-auth-service.js +1 -0
  84. package/dist/core/interfaces/i-browser-launcher.d.ts +11 -0
  85. package/dist/core/interfaces/i-browser-launcher.js +1 -0
  86. package/dist/core/interfaces/i-bullet-content-store.d.ts +36 -0
  87. package/dist/core/interfaces/i-bullet-content-store.js +1 -0
  88. package/dist/core/interfaces/i-callback-handler.d.ts +35 -0
  89. package/dist/core/interfaces/i-callback-handler.js +1 -0
  90. package/dist/core/interfaces/i-delta-store.d.ts +15 -0
  91. package/dist/core/interfaces/i-delta-store.js +1 -0
  92. package/dist/core/interfaces/i-executor-output-store.d.ts +14 -0
  93. package/dist/core/interfaces/i-executor-output-store.js +1 -0
  94. package/dist/core/interfaces/i-file-service.d.ts +34 -0
  95. package/dist/core/interfaces/i-file-service.js +1 -0
  96. package/dist/core/interfaces/i-http-client.d.ts +33 -0
  97. package/dist/core/interfaces/i-http-client.js +1 -0
  98. package/dist/core/interfaces/i-memory-retrieval-service.d.ts +40 -0
  99. package/dist/core/interfaces/i-memory-retrieval-service.js +1 -0
  100. package/dist/core/interfaces/i-memory-storage-service.d.ts +55 -0
  101. package/dist/core/interfaces/i-memory-storage-service.js +1 -0
  102. package/dist/core/interfaces/i-oidc-discovery-service.d.ts +20 -0
  103. package/dist/core/interfaces/i-oidc-discovery-service.js +1 -0
  104. package/dist/core/interfaces/i-playbook-service.d.ts +69 -0
  105. package/dist/core/interfaces/i-playbook-service.js +1 -0
  106. package/dist/core/interfaces/i-playbook-store.d.ts +38 -0
  107. package/dist/core/interfaces/i-playbook-store.js +1 -0
  108. package/dist/core/interfaces/i-project-config-store.d.ts +26 -0
  109. package/dist/core/interfaces/i-project-config-store.js +1 -0
  110. package/dist/core/interfaces/i-reflection-store.d.ts +21 -0
  111. package/dist/core/interfaces/i-reflection-store.js +1 -0
  112. package/dist/core/interfaces/i-rule-template-service.d.ts +17 -0
  113. package/dist/core/interfaces/i-rule-template-service.js +4 -0
  114. package/dist/core/interfaces/i-rule-writer-service.d.ts +13 -0
  115. package/dist/core/interfaces/i-rule-writer-service.js +1 -0
  116. package/dist/core/interfaces/i-space-service.d.ts +28 -0
  117. package/dist/core/interfaces/i-space-service.js +1 -0
  118. package/dist/core/interfaces/i-team-service.d.ts +29 -0
  119. package/dist/core/interfaces/i-team-service.js +1 -0
  120. package/dist/core/interfaces/i-template-loader.d.ts +29 -0
  121. package/dist/core/interfaces/i-template-loader.js +1 -0
  122. package/dist/core/interfaces/i-token-store.d.ts +22 -0
  123. package/dist/core/interfaces/i-token-store.js +1 -0
  124. package/dist/core/interfaces/i-tracking-service.d.ts +21 -0
  125. package/dist/core/interfaces/i-tracking-service.js +1 -0
  126. package/dist/core/interfaces/i-user-service.d.ts +14 -0
  127. package/dist/core/interfaces/i-user-service.js +1 -0
  128. package/dist/index.d.ts +1 -0
  129. package/dist/index.js +1 -0
  130. package/dist/infra/ace/ace-file-utils.d.ts +46 -0
  131. package/dist/infra/ace/ace-file-utils.js +83 -0
  132. package/dist/infra/ace/ace-prompt-templates.d.ts +13 -0
  133. package/dist/infra/ace/ace-prompt-templates.js +177 -0
  134. package/dist/infra/ace/file-bullet-content-store.d.ts +27 -0
  135. package/dist/infra/ace/file-bullet-content-store.js +89 -0
  136. package/dist/infra/ace/file-delta-store.d.ts +9 -0
  137. package/dist/infra/ace/file-delta-store.js +26 -0
  138. package/dist/infra/ace/file-executor-output-store.d.ts +9 -0
  139. package/dist/infra/ace/file-executor-output-store.js +26 -0
  140. package/dist/infra/ace/file-playbook-store.d.ts +29 -0
  141. package/dist/infra/ace/file-playbook-store.js +107 -0
  142. package/dist/infra/ace/file-reflection-store.d.ts +10 -0
  143. package/dist/infra/ace/file-reflection-store.js +55 -0
  144. package/dist/infra/auth/oauth-service.d.ts +49 -0
  145. package/dist/infra/auth/oauth-service.js +126 -0
  146. package/dist/infra/auth/oidc-discovery-service.d.ts +51 -0
  147. package/dist/infra/auth/oidc-discovery-service.js +145 -0
  148. package/dist/infra/browser/system-browser-launcher.d.ts +10 -0
  149. package/dist/infra/browser/system-browser-launcher.js +18 -0
  150. package/dist/infra/config/file-config-store.d.ts +21 -0
  151. package/dist/infra/config/file-config-store.js +57 -0
  152. package/dist/infra/file/fs-file-service.d.ts +28 -0
  153. package/dist/infra/file/fs-file-service.js +57 -0
  154. package/dist/infra/http/authenticated-http-client.d.ts +46 -0
  155. package/dist/infra/http/authenticated-http-client.js +99 -0
  156. package/dist/infra/http/callback-handler.d.ts +13 -0
  157. package/dist/infra/http/callback-handler.js +24 -0
  158. package/dist/infra/http/callback-server.d.ts +18 -0
  159. package/dist/infra/http/callback-server.js +93 -0
  160. package/dist/infra/memory/http-memory-retrieval-service.d.ts +18 -0
  161. package/dist/infra/memory/http-memory-retrieval-service.js +63 -0
  162. package/dist/infra/memory/http-memory-storage-service.d.ts +18 -0
  163. package/dist/infra/memory/http-memory-storage-service.js +67 -0
  164. package/dist/infra/memory/memory-to-playbook-mapper.d.ts +33 -0
  165. package/dist/infra/memory/memory-to-playbook-mapper.js +51 -0
  166. package/dist/infra/playbook/file-playbook-service.d.ts +43 -0
  167. package/dist/infra/playbook/file-playbook-service.js +133 -0
  168. package/dist/infra/rule/agent-rule-config.d.ts +19 -0
  169. package/dist/infra/rule/agent-rule-config.js +77 -0
  170. package/dist/infra/rule/rule-template-service.d.ts +18 -0
  171. package/dist/infra/rule/rule-template-service.js +80 -0
  172. package/dist/infra/rule/rule-writer-service.d.ts +19 -0
  173. package/dist/infra/rule/rule-writer-service.js +43 -0
  174. package/dist/infra/space/http-space-service.d.ts +20 -0
  175. package/dist/infra/space/http-space-service.js +67 -0
  176. package/dist/infra/storage/keychain-token-store.d.ts +10 -0
  177. package/dist/infra/storage/keychain-token-store.js +40 -0
  178. package/dist/infra/team/http-team-service.d.ts +21 -0
  179. package/dist/infra/team/http-team-service.js +71 -0
  180. package/dist/infra/template/fs-template-loader.d.ts +33 -0
  181. package/dist/infra/template/fs-template-loader.js +62 -0
  182. package/dist/infra/tracking/mixpanel-tracking-service.d.ts +14 -0
  183. package/dist/infra/tracking/mixpanel-tracking-service.js +44 -0
  184. package/dist/infra/user/http-user-service.d.ts +12 -0
  185. package/dist/infra/user/http-user-service.js +26 -0
  186. package/dist/templates/README.md +103 -0
  187. package/dist/templates/base.md +3 -0
  188. package/dist/templates/sections/command-reference.md +141 -0
  189. package/dist/templates/sections/workflow.md +46 -0
  190. package/dist/utils/file-helpers.d.ts +15 -0
  191. package/dist/utils/file-helpers.js +45 -0
  192. package/oclif.manifest.json +476 -0
  193. package/package.json +82 -0
@@ -0,0 +1,97 @@
1
+ import type { IBulletContentStore } from '../../interfaces/i-bullet-content-store.js';
2
+ import type { DeltaBatch } from './delta-batch.js';
3
+ import { Bullet, type BulletJson, type BulletMetadata } from './bullet.js';
4
+ export interface PlaybookJson {
5
+ bullets: Record<string, BulletJson>;
6
+ nextId: number;
7
+ sections: Record<string, string[]>;
8
+ }
9
+ export interface PlaybookStats {
10
+ bullets: number;
11
+ sections: number;
12
+ tags: string[];
13
+ }
14
+ /**
15
+ * The central knowledge repository that stores and manages bullets.
16
+ * Playbooks are organized into sections and support delta operations.
17
+ * Playbooks are used as an temporary notes then will be pushed to byterover for usage
18
+ */
19
+ export declare class Playbook {
20
+ private readonly bullets;
21
+ private nextId;
22
+ private readonly sections;
23
+ constructor(bullets?: Map<string, Bullet>, sections?: Map<string, string[]>, nextId?: number);
24
+ /**
25
+ * Creates a Playbook instance from a JSON object
26
+ * @param json The playbook JSON data
27
+ * @param contentStore Optional content store for loading bullet content from files
28
+ * @param directory Optional directory for loading content files
29
+ */
30
+ static fromJson(json: PlaybookJson, contentStore: IBulletContentStore, directory?: string): Promise<Playbook>;
31
+ /**
32
+ * Deserializes from JSON string
33
+ * @param data The JSON string
34
+ * @param contentStore Optional content store for loading bullet content from files
35
+ * @param directory Optional directory for loading content files
36
+ */
37
+ static loads(data: string, contentStore: IBulletContentStore, directory?: string): Promise<Playbook>;
38
+ /**
39
+ * Adds a new bullet to the playbook
40
+ */
41
+ addBullet(section: string, content: string, bulletId?: string, metadata?: BulletMetadata): Bullet;
42
+ /**
43
+ * Adds a tag to a bullet
44
+ */
45
+ addTagToBullet(bulletId: string, tag: string): Bullet | undefined;
46
+ /**
47
+ * Applies a batch of delta operations to the playbook
48
+ */
49
+ applyDelta(delta: DeltaBatch): void;
50
+ /**
51
+ * Converts playbook to markdown format for LLM prompts
52
+ */
53
+ asPrompt(): string;
54
+ /**
55
+ * Serializes to JSON string (pretty-printed)
56
+ * @param includeContent If false, content field is omitted from bullets (for file-based storage)
57
+ */
58
+ dumps(includeContent?: boolean): string;
59
+ /**
60
+ * Retrieves a single bullet by ID
61
+ */
62
+ getBullet(bulletId: string): Bullet | undefined;
63
+ /**
64
+ * Returns all bullets as an array
65
+ */
66
+ getBullets(): Bullet[];
67
+ /**
68
+ * Returns bullets in a specific section
69
+ */
70
+ getBulletsInSection(section: string): Bullet[];
71
+ /**
72
+ * Returns all section names
73
+ */
74
+ getSections(): string[];
75
+ /**
76
+ * Removes a bullet from the playbook
77
+ */
78
+ removeBullet(bulletId: string): void;
79
+ /**
80
+ * Removes a tag from a bullet
81
+ */
82
+ removeTagFromBullet(bulletId: string, tag: string): Bullet | undefined;
83
+ /**
84
+ * Returns playbook statistics
85
+ */
86
+ stats(): PlaybookStats;
87
+ toJson(includeContent?: boolean): PlaybookJson;
88
+ /**
89
+ * Updates an existing bullet's content and/or metadata
90
+ */
91
+ updateBullet(bulletId: string, options: {
92
+ content?: string;
93
+ metadata?: BulletMetadata;
94
+ }): Bullet | undefined;
95
+ private _applyOperation;
96
+ private _generateId;
97
+ }
@@ -0,0 +1,275 @@
1
+ import { Bullet } from './bullet.js';
2
+ /**
3
+ * The central knowledge repository that stores and manages bullets.
4
+ * Playbooks are organized into sections and support delta operations.
5
+ * Playbooks are used as an temporary notes then will be pushed to byterover for usage
6
+ */
7
+ export class Playbook {
8
+ bullets;
9
+ nextId;
10
+ sections;
11
+ constructor(bullets = new Map(), sections = new Map(), nextId = 1) {
12
+ this.bullets = new Map(bullets);
13
+ this.sections = new Map(sections);
14
+ this.nextId = nextId;
15
+ }
16
+ // ===== Static Factory Methods =====
17
+ /**
18
+ * Creates a Playbook instance from a JSON object
19
+ * @param json The playbook JSON data
20
+ * @param contentStore Optional content store for loading bullet content from files
21
+ * @param directory Optional directory for loading content files
22
+ */
23
+ static async fromJson(json, contentStore, directory) {
24
+ const bullets = new Map();
25
+ const sections = new Map();
26
+ // Deserialize bullets
27
+ const bulletEntries = Object.entries(json.bullets ?? {});
28
+ // Load all content in parallel if needed
29
+ const contentPromises = bulletEntries.map(async ([id, bulletData]) => {
30
+ if (bulletData.content) {
31
+ return bulletData.content;
32
+ }
33
+ return contentStore.load(id, directory);
34
+ });
35
+ const contents = await Promise.all(contentPromises);
36
+ // Create bullets with loaded content
37
+ for (const [index, [id, bulletData]] of bulletEntries.entries()) {
38
+ bullets.set(id, Bullet.fromJson(bulletData, contents[index]));
39
+ }
40
+ // Deserialize sections
41
+ for (const [section, bulletIds] of Object.entries(json.sections ?? {})) {
42
+ sections.set(section, bulletIds);
43
+ }
44
+ return new Playbook(bullets, sections, json.nextId ?? 1);
45
+ }
46
+ /**
47
+ * Deserializes from JSON string
48
+ * @param data The JSON string
49
+ * @param contentStore Optional content store for loading bullet content from files
50
+ * @param directory Optional directory for loading content files
51
+ */
52
+ static async loads(data, contentStore, directory) {
53
+ const json = JSON.parse(data);
54
+ return Playbook.fromJson(json, contentStore, directory);
55
+ }
56
+ // ===== CRUD Operations =====
57
+ /**
58
+ * Adds a new bullet to the playbook
59
+ */
60
+ addBullet(section, content, bulletId, metadata) {
61
+ const id = bulletId ?? this._generateId(section);
62
+ const now = new Date().toISOString();
63
+ // Create metadata with defaults if not provided
64
+ const bulletMetadata = metadata ?? {
65
+ relatedFiles: [],
66
+ tags: [],
67
+ timestamp: now,
68
+ };
69
+ const bullet = new Bullet(id, section, content, bulletMetadata, undefined);
70
+ // Add to bullets map
71
+ this.bullets.set(id, bullet);
72
+ // Add to sections map
73
+ if (!this.sections.has(section)) {
74
+ this.sections.set(section, []);
75
+ }
76
+ this.sections.get(section).push(id);
77
+ return bullet;
78
+ }
79
+ /**
80
+ * Adds a tag to a bullet
81
+ */
82
+ addTagToBullet(bulletId, tag) {
83
+ const bullet = this.bullets.get(bulletId);
84
+ if (!bullet)
85
+ return undefined;
86
+ // Check if tag already exists
87
+ if (bullet.metadata.tags.includes(tag)) {
88
+ return bullet;
89
+ }
90
+ const updatedMetadata = {
91
+ ...bullet.metadata,
92
+ tags: [...bullet.metadata.tags, tag],
93
+ timestamp: new Date().toISOString(),
94
+ };
95
+ const updatedBullet = new Bullet(bullet.id, bullet.section, bullet.content, updatedMetadata, bullet.memoryId);
96
+ this.bullets.set(bulletId, updatedBullet);
97
+ return updatedBullet;
98
+ }
99
+ /**
100
+ * Applies a batch of delta operations to the playbook
101
+ */
102
+ applyDelta(delta) {
103
+ for (const operation of delta.operations) {
104
+ this._applyOperation(operation);
105
+ }
106
+ }
107
+ /**
108
+ * Converts playbook to markdown format for LLM prompts
109
+ */
110
+ asPrompt() {
111
+ const sections = this.getSections();
112
+ if (sections.length === 0) {
113
+ return '(Empty playbook)';
114
+ }
115
+ const lines = [];
116
+ for (const section of sections) {
117
+ lines.push(`## ${section}`);
118
+ const bullets = this.getBulletsInSection(section);
119
+ for (const bullet of bullets) {
120
+ lines.push(bullet.toDisplayString());
121
+ }
122
+ lines.push(''); // Empty line between sections
123
+ }
124
+ return lines.join('\n').trim();
125
+ }
126
+ /**
127
+ * Serializes to JSON string (pretty-printed)
128
+ * @param includeContent If false, content field is omitted from bullets (for file-based storage)
129
+ */
130
+ dumps(includeContent = true) {
131
+ return JSON.stringify(this.toJson(includeContent), null, 2);
132
+ }
133
+ /**
134
+ * Retrieves a single bullet by ID
135
+ */
136
+ getBullet(bulletId) {
137
+ return this.bullets.get(bulletId);
138
+ }
139
+ /**
140
+ * Returns all bullets as an array
141
+ */
142
+ getBullets() {
143
+ return [...this.bullets.values()];
144
+ }
145
+ /**
146
+ * Returns bullets in a specific section
147
+ */
148
+ getBulletsInSection(section) {
149
+ const bulletIds = this.sections.get(section) ?? [];
150
+ return bulletIds.map((id) => this.bullets.get(id)).filter((b) => b !== undefined);
151
+ }
152
+ /**
153
+ * Returns all section names
154
+ */
155
+ getSections() {
156
+ return [...this.sections.keys()].sort();
157
+ }
158
+ // ===== Delta Operations =====
159
+ /**
160
+ * Removes a bullet from the playbook
161
+ */
162
+ removeBullet(bulletId) {
163
+ const bullet = this.bullets.get(bulletId);
164
+ if (!bullet)
165
+ return;
166
+ // Remove from bullets map
167
+ this.bullets.delete(bulletId);
168
+ // Remove from sections map
169
+ const sectionBullets = this.sections.get(bullet.section);
170
+ if (sectionBullets) {
171
+ const index = sectionBullets.indexOf(bulletId);
172
+ if (index !== -1) {
173
+ sectionBullets.splice(index, 1);
174
+ }
175
+ // Clean up empty sections
176
+ if (sectionBullets.length === 0) {
177
+ this.sections.delete(bullet.section);
178
+ }
179
+ }
180
+ }
181
+ /**
182
+ * Removes a tag from a bullet
183
+ */
184
+ removeTagFromBullet(bulletId, tag) {
185
+ const bullet = this.bullets.get(bulletId);
186
+ if (!bullet)
187
+ return undefined;
188
+ const updatedMetadata = {
189
+ ...bullet.metadata,
190
+ tags: bullet.metadata.tags.filter((t) => t !== tag),
191
+ timestamp: new Date().toISOString(),
192
+ };
193
+ const updatedBullet = new Bullet(bullet.id, bullet.section, bullet.content, updatedMetadata, bullet.memoryId);
194
+ this.bullets.set(bulletId, updatedBullet);
195
+ return updatedBullet;
196
+ }
197
+ // ===== Presentation =====
198
+ /**
199
+ * Returns playbook statistics
200
+ */
201
+ stats() {
202
+ const tagsSet = new Set();
203
+ for (const bullet of this.bullets.values()) {
204
+ for (const tag of bullet.metadata.tags) {
205
+ tagsSet.add(tag);
206
+ }
207
+ }
208
+ return {
209
+ bullets: this.bullets.size,
210
+ sections: this.sections.size,
211
+ tags: [...tagsSet].sort(),
212
+ };
213
+ }
214
+ toJson(includeContent = true) {
215
+ const bulletsObj = {};
216
+ for (const [id, bullet] of this.bullets) {
217
+ bulletsObj[id] = bullet.toJson(includeContent);
218
+ }
219
+ const sectionsObj = {};
220
+ for (const [section, bulletIds] of this.sections) {
221
+ sectionsObj[section] = [...bulletIds];
222
+ }
223
+ return {
224
+ bullets: bulletsObj,
225
+ nextId: this.nextId,
226
+ sections: sectionsObj,
227
+ };
228
+ }
229
+ // ===== Serialization =====
230
+ /**
231
+ * Updates an existing bullet's content and/or metadata
232
+ */
233
+ updateBullet(bulletId, options) {
234
+ const bullet = this.bullets.get(bulletId);
235
+ if (!bullet)
236
+ return undefined;
237
+ const updatedMetadata = options.metadata ?? {
238
+ ...bullet.metadata,
239
+ timestamp: new Date().toISOString(),
240
+ };
241
+ const updatedBullet = new Bullet(bullet.id, bullet.section, options.content ?? bullet.content, updatedMetadata, bullet.memoryId);
242
+ this.bullets.set(bulletId, updatedBullet);
243
+ return updatedBullet;
244
+ }
245
+ _applyOperation(operation) {
246
+ switch (operation.type) {
247
+ case 'ADD': {
248
+ this.addBullet(operation.section, operation.content, operation.bulletId, operation.metadata);
249
+ break;
250
+ }
251
+ case 'REMOVE': {
252
+ this.removeBullet(operation.bulletId);
253
+ break;
254
+ }
255
+ case 'UPDATE': {
256
+ this.updateBullet(operation.bulletId, {
257
+ content: operation.content,
258
+ metadata: operation.metadata,
259
+ });
260
+ break;
261
+ }
262
+ }
263
+ }
264
+ // ===== Private Helpers =====
265
+ _generateId(section) {
266
+ // Convert section to prefix: "Common Errors" -> "common"
267
+ const prefix = section
268
+ .toLowerCase()
269
+ .split(' ')[0]
270
+ .replaceAll(/[^a-z0-9]/g, '');
271
+ const id = `${prefix}-${String(this.nextId).padStart(5, '0')}`;
272
+ this.nextId++;
273
+ return id;
274
+ }
275
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Represents a presigned URL for uploading files to cloud storage.
3
+ * Contains the file name and the temporary upload URL with embedded credentials.
4
+ */
5
+ export declare class PresignedUrl {
6
+ readonly fileName: string;
7
+ readonly uploadUrl: string;
8
+ constructor(fileName: string, uploadUrl: string);
9
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Represents a presigned URL for uploading files to cloud storage.
3
+ * Contains the file name and the temporary upload URL with embedded credentials.
4
+ */
5
+ export class PresignedUrl {
6
+ fileName;
7
+ uploadUrl;
8
+ constructor(fileName, uploadUrl) {
9
+ if (fileName.trim().length === 0) {
10
+ throw new Error('File name cannot be empty');
11
+ }
12
+ if (uploadUrl.trim().length === 0) {
13
+ throw new Error('Upload URL cannot be empty');
14
+ }
15
+ this.fileName = fileName;
16
+ this.uploadUrl = uploadUrl;
17
+ }
18
+ }
@@ -0,0 +1,10 @@
1
+ import type { PresignedUrl } from './presigned-url.js';
2
+ /**
3
+ * Represents the response from requesting presigned URLs.
4
+ * Contains both the presigned URLs for file upload and the request ID for confirmation.
5
+ */
6
+ export declare class PresignedUrlsResponse {
7
+ readonly presignedUrls: ReadonlyArray<PresignedUrl>;
8
+ readonly requestId: string;
9
+ constructor(presignedUrls: PresignedUrl[], requestId: string);
10
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Represents the response from requesting presigned URLs.
3
+ * Contains both the presigned URLs for file upload and the request ID for confirmation.
4
+ */
5
+ export class PresignedUrlsResponse {
6
+ presignedUrls;
7
+ requestId;
8
+ constructor(presignedUrls, requestId) {
9
+ if (presignedUrls.length === 0) {
10
+ throw new Error('Presigned URLs array cannot be empty');
11
+ }
12
+ if (requestId.trim().length === 0) {
13
+ throw new Error('Request ID cannot be empty');
14
+ }
15
+ this.presignedUrls = Object.freeze([...presignedUrls]);
16
+ this.requestId = requestId;
17
+ }
18
+ }
@@ -0,0 +1,38 @@
1
+ export interface BulletTag {
2
+ id: string;
3
+ tag: string;
4
+ }
5
+ export interface ReflectorOutputInput {
6
+ bulletTags: BulletTag[];
7
+ correctApproach: string;
8
+ errorIdentification: string;
9
+ hint: string;
10
+ keyInsight: string;
11
+ reasoning: string;
12
+ rootCauseAnalysis: string;
13
+ }
14
+ export interface ReflectorOutputJson {
15
+ bulletTags: BulletTag[];
16
+ correctApproach: string;
17
+ errorIdentification: string;
18
+ hint: string;
19
+ keyInsight: string;
20
+ reasoning: string;
21
+ rootCauseAnalysis: string;
22
+ }
23
+ /**
24
+ * Output from the reflector phase.
25
+ * Contains error analysis and bullet tagging.
26
+ */
27
+ export declare class ReflectorOutput {
28
+ readonly bulletTags: BulletTag[];
29
+ readonly correctApproach: string;
30
+ readonly errorIdentification: string;
31
+ readonly hint: string;
32
+ readonly keyInsight: string;
33
+ readonly reasoning: string;
34
+ readonly rootCauseAnalysis: string;
35
+ constructor(input: ReflectorOutputInput);
36
+ static fromJson(json: ReflectorOutputJson): ReflectorOutput;
37
+ toJson(): ReflectorOutputJson;
38
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Output from the reflector phase.
3
+ * Contains error analysis and bullet tagging.
4
+ */
5
+ export class ReflectorOutput {
6
+ bulletTags;
7
+ correctApproach;
8
+ errorIdentification;
9
+ hint;
10
+ keyInsight;
11
+ reasoning;
12
+ rootCauseAnalysis;
13
+ constructor(input) {
14
+ this.reasoning = input.reasoning;
15
+ this.errorIdentification = input.errorIdentification;
16
+ this.rootCauseAnalysis = input.rootCauseAnalysis;
17
+ this.correctApproach = input.correctApproach;
18
+ this.keyInsight = input.keyInsight;
19
+ this.hint = input.hint;
20
+ this.bulletTags = [...input.bulletTags];
21
+ }
22
+ static fromJson(json) {
23
+ return new ReflectorOutput({
24
+ bulletTags: json.bulletTags,
25
+ correctApproach: json.correctApproach,
26
+ errorIdentification: json.errorIdentification,
27
+ hint: json.hint || '',
28
+ keyInsight: json.keyInsight,
29
+ reasoning: json.reasoning,
30
+ rootCauseAnalysis: json.rootCauseAnalysis,
31
+ });
32
+ }
33
+ toJson() {
34
+ return {
35
+ bulletTags: this.bulletTags,
36
+ correctApproach: this.correctApproach,
37
+ errorIdentification: this.errorIdentification,
38
+ hint: this.hint,
39
+ keyInsight: this.keyInsight,
40
+ reasoning: this.reasoning,
41
+ rootCauseAnalysis: this.rootCauseAnalysis,
42
+ };
43
+ }
44
+ }
@@ -0,0 +1,35 @@
1
+ import { Memory, MemoryParams } from './memory.js';
2
+ /**
3
+ * Parameters for creating a RetrieveResult instance.
4
+ */
5
+ export type RetrieveResultParams = {
6
+ memories: Memory[];
7
+ relatedMemories: Memory[];
8
+ };
9
+ /**
10
+ * JSON representation of a RetrieveResult.
11
+ */
12
+ export type RetrieveResultJson = {
13
+ memories: MemoryParams[];
14
+ relatedMemories: MemoryParams[];
15
+ };
16
+ /**
17
+ * Represents the result of a memory retrieval operation from the ByteRover Memora service.
18
+ * Contains both directly matching memories and related memories.
19
+ */
20
+ export declare class RetrieveResult {
21
+ readonly memories: readonly Memory[];
22
+ readonly relatedMemories: readonly Memory[];
23
+ constructor(params: RetrieveResultParams);
24
+ /**
25
+ * Creates a RetrieveResult instance from a JSON object.
26
+ * @param json JSON object representing the RetrieveResult
27
+ * @returns An instance of RetrieveResult
28
+ */
29
+ static fromJson(json: RetrieveResultJson): RetrieveResult;
30
+ /**
31
+ * Converts the RetrieveResult instance to a JSON object.
32
+ * @returns A JSON object representing the RetrieveResult
33
+ */
34
+ toJson(): RetrieveResultJson;
35
+ }
@@ -0,0 +1,35 @@
1
+ import { Memory } from './memory.js';
2
+ /**
3
+ * Represents the result of a memory retrieval operation from the ByteRover Memora service.
4
+ * Contains both directly matching memories and related memories.
5
+ */
6
+ export class RetrieveResult {
7
+ memories;
8
+ relatedMemories;
9
+ constructor(params) {
10
+ // Defensive copy to prevent external mutation
11
+ this.memories = [...params.memories];
12
+ this.relatedMemories = [...params.relatedMemories];
13
+ }
14
+ /**
15
+ * Creates a RetrieveResult instance from a JSON object.
16
+ * @param json JSON object representing the RetrieveResult
17
+ * @returns An instance of RetrieveResult
18
+ */
19
+ static fromJson(json) {
20
+ return new RetrieveResult({
21
+ memories: json.memories.map((m) => Memory.fromJson(m)),
22
+ relatedMemories: json.relatedMemories.map((m) => Memory.fromJson(m)),
23
+ });
24
+ }
25
+ /**
26
+ * Converts the RetrieveResult instance to a JSON object.
27
+ * @returns A JSON object representing the RetrieveResult
28
+ */
29
+ toJson() {
30
+ return {
31
+ memories: this.memories.map((m) => m.toJson()),
32
+ relatedMemories: this.relatedMemories.map((m) => m.toJson()),
33
+ };
34
+ }
35
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Represents a ByteRover space that belongs to a team.
3
+ * A space corresponds to a user's codebase and contains memories for that codebase.
4
+ */
5
+ export declare class Space {
6
+ readonly id: string;
7
+ readonly name: string;
8
+ readonly teamId: string;
9
+ readonly teamName: string;
10
+ constructor(id: string, name: string, teamId: string, teamName: string);
11
+ /**
12
+ * Deserializes a space from JSON format
13
+ */
14
+ static fromJson(json: Record<string, string>): Space;
15
+ /**
16
+ * Returns the display name in the format: teamName/spaceName
17
+ * Example: "acme-corp/frontend-app"
18
+ */
19
+ getDisplayName(): string;
20
+ /**
21
+ * Serializes the space to JSON format
22
+ */
23
+ toJson(): Record<string, string>;
24
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Represents a ByteRover space that belongs to a team.
3
+ * A space corresponds to a user's codebase and contains memories for that codebase.
4
+ */
5
+ export class Space {
6
+ id;
7
+ name;
8
+ teamId;
9
+ teamName;
10
+ constructor(id, name, teamId, teamName) {
11
+ if (id.trim().length === 0) {
12
+ throw new Error('Space ID cannot be empty');
13
+ }
14
+ if (name.trim().length === 0) {
15
+ throw new Error('Space name cannot be empty');
16
+ }
17
+ if (teamId.trim().length === 0) {
18
+ throw new Error('Team ID cannot be empty');
19
+ }
20
+ if (teamName.trim().length === 0) {
21
+ throw new Error('Team name cannot be empty');
22
+ }
23
+ this.id = id;
24
+ this.name = name;
25
+ this.teamId = teamId;
26
+ this.teamName = teamName;
27
+ }
28
+ /**
29
+ * Deserializes a space from JSON format
30
+ */
31
+ static fromJson(json) {
32
+ return new Space(json.id, json.name, json.teamId, json.teamName);
33
+ }
34
+ /**
35
+ * Returns the display name in the format: teamName/spaceName
36
+ * Example: "acme-corp/frontend-app"
37
+ */
38
+ getDisplayName() {
39
+ return `${this.teamName}/${this.name}`;
40
+ }
41
+ /**
42
+ * Serializes the space to JSON format
43
+ */
44
+ toJson() {
45
+ return {
46
+ id: this.id,
47
+ name: this.name,
48
+ teamId: this.teamId,
49
+ teamName: this.teamName,
50
+ };
51
+ }
52
+ }