observal-pi 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.
package/LICENSE ADDED
@@ -0,0 +1,727 @@
1
+ Copyright (c) 2026-present Observal (BlazeUp AI LLP)
2
+ Registered Office: Chennai, Tamil Nadu, India
3
+ Contact: contact@observal.io
4
+
5
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
6
+
7
+ DUAL LICENSE STRUCTURE
8
+ ━━━━━━━━━━━━━━━━━━━━━━
9
+
10
+ This repository uses a dual-license structure:
11
+
12
+ 1. All content in this repository is licensed under the GNU Affero
13
+ General Public License v3.0 ("AGPL"), as published by the Free
14
+ Software Foundation - EXCEPT content residing under the "ee/"
15
+ directory.
16
+
17
+ 2. Content under the "ee/" directory is licensed under the Observal
18
+ Enterprise License defined in "ee/LICENSE". That code is
19
+ source-available but requires a paid commercial license for any
20
+ production, internal enterprise, or commercial use.
21
+
22
+ The open-source core (everything outside "ee/") is fully functional
23
+ on its own and does not require any code in the "ee/" directory to
24
+ operate.
25
+
26
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
27
+
28
+ IMPORTANT — AGPL SECTION 7 NOTICE (ee/ boundary)
29
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
30
+
31
+ Pursuant to AGPL Section 7, the following additional permissions
32
+ apply to the AGPL-licensed core (code outside "ee/"):
33
+
34
+ (a) You may combine or link the AGPL-licensed core with the
35
+ "ee/" directory code ONLY if you hold a valid Observal
36
+ Commercial License. Using the "ee/" features without a
37
+ commercial license, even if you have built the project
38
+ successfully, constitutes a violation of the "ee/LICENSE".
39
+
40
+ (b) The "ee/" directory code is NOT covered by the AGPL and
41
+ does NOT grant you any AGPL rights. The AGPL Section 7
42
+ additional permissions here apply only to the core code
43
+ (outside "ee/") and do not extend any license to "ee/".
44
+
45
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
46
+
47
+ COMMERCIAL LICENSE
48
+ ━━━━━━━━━━━━━━━━━━
49
+
50
+ If you or your organization:
51
+
52
+ • Cannot comply with the AGPL (e.g., cannot open-source your
53
+ internal modifications or network-facing deployments),
54
+ • Want to use Observal in a proprietary product or internal
55
+ enterprise deployment without AGPL obligations,
56
+ • Want access to the enterprise features in the "ee/" directory,
57
+ • Require an SLA, IP indemnification, or compliance documentation,
58
+
59
+ → A commercial license is available from BlazeUp AI LLP.
60
+
61
+ Website : https://observal.io/
62
+ Email : contact@observal.io
63
+
64
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
65
+
66
+ GNU AFFERO GENERAL PUBLIC LICENSE
67
+ Version 3, 19 November 2007
68
+
69
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
70
+ Everyone is permitted to copy and distribute verbatim copies
71
+ of this license document, but changing it is not allowed.
72
+
73
+ Preamble
74
+
75
+ The GNU Affero General Public License is a free, copyleft license for
76
+ software and other kinds of works, specifically designed to ensure
77
+ cooperation with the community in the case of network server software.
78
+
79
+ The licenses for most software and other practical works are designed
80
+ to take away your freedom to share and change the works. By contrast,
81
+ our General Public Licenses are intended to guarantee your freedom to
82
+ share and change all versions of a program--to make sure it remains free
83
+ software for all its users.
84
+
85
+ When we speak of free software, we are referring to freedom, not
86
+ price. Our General Public Licenses are designed to make sure that you
87
+ have the freedom to distribute copies of free software (and charge for
88
+ them if you wish), that you receive source code or can get it if you
89
+ want it, that you can change the software or use pieces of it in new
90
+ free programs, and that you know you can do these things.
91
+
92
+ Developers that use our General Public Licenses protect your rights
93
+ with two steps: (1) assert copyright on the software, and (2) offer
94
+ you this License which gives you legal permission to copy, distribute
95
+ and/or modify the software.
96
+
97
+ A secondary benefit of defending all users' freedom is that
98
+ improvements made in alternate versions of the program, if they
99
+ receive widespread use, become available for other developers to
100
+ incorporate. Many developers of free software are heartened and
101
+ encouraged by the resulting cooperation. However, in the case of
102
+ software used on network servers, this result may fail to come about.
103
+ The GNU General Public License permits making a modified version and
104
+ letting the public access it on a server without ever releasing its
105
+ source code to the public.
106
+
107
+ The GNU Affero General Public License is designed specifically to
108
+ ensure that, in such cases, the modified source code becomes available
109
+ to the community. It requires the operator of a network server to
110
+ provide the source code of the modified version running there to the
111
+ users of that server. Therefore, public use of a modified version, on
112
+ a publicly accessible server, gives the public access to the source
113
+ code of the modified version.
114
+
115
+ An older license, called the Affero General Public License and
116
+ published by Affero, was designed to accomplish similar goals. This is
117
+ a different license, not a version of the Affero GPL, but Affero has
118
+ released a new version of the Affero GPL which permits relicensing under
119
+ this license.
120
+
121
+ The precise terms and conditions for copying, distribution and
122
+ modification follow.
123
+
124
+ TERMS AND CONDITIONS
125
+
126
+ 0. Definitions.
127
+
128
+ "This License" refers to version 3 of the GNU Affero General Public License.
129
+
130
+ "Copyright" also means copyright-like laws that apply to other kinds of
131
+ works, such as semiconductor masks.
132
+
133
+ "The Program" refers to any copyrightable work licensed under this
134
+ License. Each licensee is addressed as "you". "Licensees" and
135
+ "recipients" may be individuals or organizations.
136
+
137
+ To "modify" a work means to copy from or adapt all or part of the work
138
+ in a fashion requiring copyright permission, other than the making of an
139
+ exact copy. The resulting work is called a "modified version" of the
140
+ earlier work or a work "based on" the earlier work.
141
+
142
+ A "covered work" means either the unmodified Program or a work based
143
+ on the Program.
144
+
145
+ To "propagate" a work means to do anything with it that, without
146
+ permission, would make you directly or secondarily liable for
147
+ infringement under applicable copyright law, except executing it on a
148
+ computer or modifying a private copy. Propagation includes copying,
149
+ distribution (with or without modification), making available to the
150
+ public, and in some countries other activities as well.
151
+
152
+ To "convey" a work means any kind of propagation that enables other
153
+ parties to make or receive copies. Mere interaction with a user through
154
+ a computer network, with no transfer of a copy, is not conveying.
155
+
156
+ An interactive user interface displays "Appropriate Legal Notices"
157
+ to the extent that it includes a convenient and prominently visible
158
+ feature that (1) displays an appropriate copyright notice, and (2)
159
+ tells the user that there is no warranty for the work (except to the
160
+ extent that warranties are provided), that licensees may convey the
161
+ work under this License, and how to view a copy of this License. If
162
+ the interface presents a list of user commands or options, such as a
163
+ menu, a prominent item in the list meets this criterion.
164
+
165
+ 1. Source Code.
166
+
167
+ The "source code" for a work means the preferred form of the work
168
+ for making modifications to it. "Object code" means any non-source
169
+ form of a work.
170
+
171
+ A "Standard Interface" means an interface that either is an official
172
+ standard defined by a recognized standards body, or, in the case of
173
+ interfaces specified for a particular programming language, one that
174
+ is widely used among developers working in that language.
175
+
176
+ The "System Libraries" of an executable work include anything, other
177
+ than the work as a whole, that (a) is included in the normal form of
178
+ packaging a Major Component, but which is not part of that Major
179
+ Component, and (b) serves only to enable use of the work with that
180
+ Major Component, or to implement a Standard Interface for which an
181
+ implementation is available to the public in source code form. A
182
+ "Major Component", in this context, means a major essential component
183
+ (kernel, window system, and so on) of the specific operating system
184
+ (if any) on which the executable work runs, or a compiler used to
185
+ produce the work, or an object code interpreter used to run it.
186
+
187
+ The "Corresponding Source" for a work in object code form means all
188
+ the source code needed to generate, install, and (for an executable
189
+ work) run the object code and to modify the work, including scripts to
190
+ control those activities. However, it does not include the work's
191
+ System Libraries, or general-purpose tools or generally available free
192
+ programs which are used unmodified in performing those activities but
193
+ which are not part of the work. For example, Corresponding Source
194
+ includes interface definition files associated with source files for
195
+ the work, and the source code for shared libraries and dynamically
196
+ linked subprograms that the work is specifically designed to require,
197
+ such as by intimate data communication or control flow between those
198
+ subprograms and other parts of the work.
199
+
200
+ The Corresponding Source need not include anything that users
201
+ can regenerate automatically from other parts of the Corresponding
202
+ Source.
203
+
204
+ The Corresponding Source for a work in source code form is that
205
+ same work.
206
+
207
+ 2. Basic Permissions.
208
+
209
+ All rights granted under this License are granted for the term of
210
+ copyright on the Program, and are irrevocable provided the stated
211
+ conditions are met. This License explicitly affirms your unlimited
212
+ permission to run the unmodified Program. The output from running a
213
+ covered work is covered by this License only if the output, given its
214
+ content, constitutes a covered work. This License acknowledges your
215
+ rights of fair use or other equivalent, as provided by copyright law.
216
+
217
+ You may make, run and propagate covered works that you do not
218
+ convey, without conditions so long as your license otherwise remains
219
+ in force. You may convey covered works to others for the sole purpose
220
+ of having them make modifications exclusively for you, or provide you
221
+ with facilities for running those works, provided that you comply with
222
+ the terms of this License in conveying all material for which you do
223
+ not control copyright. Those thus making or running the covered works
224
+ for you must do so exclusively on your behalf, under your direction
225
+ and control, on terms that prohibit them from making any copies of
226
+ your copyrighted material outside their relationship with you.
227
+
228
+ Conveying under any other circumstances is permitted solely under
229
+ the conditions stated below. Sublicensing is not allowed; section 10
230
+ makes it unnecessary.
231
+
232
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
233
+
234
+ No covered work shall be deemed part of an effective technological
235
+ measure under any applicable law fulfilling obligations under article
236
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
237
+ similar laws prohibiting or restricting circumvention of such
238
+ measures.
239
+
240
+ When you convey a covered work, you waive any legal power to forbid
241
+ circumvention of technological measures to the extent such circumvention
242
+ is effected by exercising rights under this License with respect to
243
+ the covered work, and you disclaim any intention to limit operation or
244
+ modification of the work as a means of enforcing, against the work's
245
+ users, your or third parties' legal rights to forbid circumvention of
246
+ technological measures.
247
+
248
+ 4. Conveying Verbatim Copies.
249
+
250
+ You may convey verbatim copies of the Program's source code as you
251
+ receive it, in any medium, provided that you conspicuously and
252
+ appropriately publish on each copy an appropriate copyright notice;
253
+ keep intact all notices stating that this License and any
254
+ non-permissive terms added in accord with section 7 apply to the code;
255
+ keep intact all notices of the absence of any warranty; and give all
256
+ recipients a copy of this License along with the Program.
257
+
258
+ You may charge any price or no price for each copy that you convey,
259
+ and you may offer support or warranty protection for a fee.
260
+
261
+ 5. Conveying Modified Source Versions.
262
+
263
+ You may convey a work based on the Program, or the modifications to
264
+ produce it from the Program, in the form of source code under the
265
+ terms of section 4, provided that you also meet all of these conditions:
266
+
267
+ a) The work must carry prominent notices stating that you modified
268
+ it, and giving a relevant date.
269
+
270
+ b) The work must carry prominent notices stating that it is
271
+ released under this License and any conditions added under section
272
+ 7. This requirement modifies the requirement in section 4 to
273
+ "keep intact all notices".
274
+
275
+ c) You must license the entire work, as a whole, under this
276
+ License to anyone who comes into possession of a copy. This
277
+ License will therefore apply, along with any applicable section 7
278
+ additional terms, to the whole of the work, and all its parts,
279
+ regardless of how they are packaged. This License gives no
280
+ permission to license the work in any other way, but it does not
281
+ invalidate such permission if you have separately received it.
282
+
283
+ d) If the work has interactive user interfaces, each must display
284
+ Appropriate Legal Notices; however, if the Program has interactive
285
+ interfaces that do not display Appropriate Legal Notices, your
286
+ work need not make them do so.
287
+
288
+ A compilation of a covered work with other separate and independent
289
+ works, which are not by their nature extensions of the covered work,
290
+ and which are not combined with it such as to form a larger program,
291
+ in or on a volume of a storage or distribution medium, is called an
292
+ "aggregate" if the compilation and its resulting copyright are not
293
+ used to limit the access or legal rights of the compilation's users
294
+ beyond what the individual works permit. Inclusion of a covered work
295
+ in an aggregate does not cause this License to apply to the other
296
+ parts of the aggregate.
297
+
298
+ 6. Conveying Non-Source Forms.
299
+
300
+ You may convey a covered work in object code form under the terms
301
+ of sections 4 and 5, provided that you also convey the
302
+ machine-readable Corresponding Source under the terms of this License,
303
+ in one of these ways:
304
+
305
+ a) Convey the object code in, or embodied in, a physical product
306
+ (including a physical distribution medium), accompanied by the
307
+ Corresponding Source fixed on a durable physical medium
308
+ customarily used for software interchange.
309
+
310
+ b) Convey the object code in, or embodied in, a physical product
311
+ (including a physical distribution medium), accompanied by a
312
+ written offer, valid for at least three years and valid for as
313
+ long as you offer spare parts or customer support for that product
314
+ model, to give anyone who possesses the object code either (1) a
315
+ copy of the Corresponding Source for all the software in the
316
+ product that is covered by this License, on a durable physical
317
+ medium customarily used for software interchange, for a price no
318
+ more than your reasonable cost of physically performing this
319
+ conveying of source, or (2) access to copy the
320
+ Corresponding Source from a network server at no charge.
321
+
322
+ c) Convey individual copies of the object code with a copy of the
323
+ written offer to provide the Corresponding Source. This
324
+ alternative is allowed only occasionally and noncommercially, and
325
+ only if you received the object code with such an offer, in accord
326
+ with subsection 6b.
327
+
328
+ d) Convey the object code by offering access from a designated
329
+ place (gratis or for a charge), and offer equivalent access to the
330
+ Corresponding Source in the same way through the same place at no
331
+ further charge. You need not require recipients to copy the
332
+ Corresponding Source along with the object code. If the place to
333
+ copy the object code is a network server, the Corresponding Source
334
+ may be on a different server (operated by you or a third party)
335
+ that supports equivalent copying facilities, provided you maintain
336
+ clear directions next to the object code saying where to find the
337
+ Corresponding Source. Regardless of what server hosts the
338
+ Corresponding Source, you remain obligated to ensure that it is
339
+ available for as long as needed to satisfy these requirements.
340
+
341
+ e) Convey the object code using peer-to-peer transmission, provided
342
+ you inform other peers where the object code and Corresponding
343
+ Source of the work are being offered to the general public at no
344
+ charge under subsection 6d.
345
+
346
+ A separable portion of the object code, whose source code is excluded
347
+ from the Corresponding Source as a System Library, need not be
348
+ included in conveying the object code work.
349
+
350
+ A "User Product" is either (1) a "consumer product", which means any
351
+ tangible personal property which is normally used for personal, family,
352
+ or household purposes, or (2) anything designed or sold for incorporation
353
+ into a dwelling. In determining whether a product is a consumer product,
354
+ doubtful cases shall be resolved in favor of coverage. For a particular
355
+ product received by a particular user, "normally used" refers to a
356
+ typical or common use of that class of product, regardless of the status
357
+ of the particular user or of the way in which the particular user
358
+ actually uses, or expects or is expected to use, the product. A product
359
+ is a consumer product regardless of whether the product has substantial
360
+ commercial, industrial or non-consumer uses, unless such uses represent
361
+ the only significant mode of use of the product.
362
+
363
+ "Installation Information" for a User Product means any methods,
364
+ procedures, authorization keys, or other information required to install
365
+ and execute modified versions of a covered work in that User Product from
366
+ a modified version of its Corresponding Source. The information must
367
+ suffice to ensure that the continued functioning of the modified object
368
+ code is in no case prevented or interfered with solely because
369
+ modification has been made.
370
+
371
+ If you convey an object code work under this section in, or with, or
372
+ specifically for use in, a User Product, and the conveying occurs as
373
+ part of a transaction in which the right of possession and use of the
374
+ User Product is transferred to the recipient in perpetuity or for a
375
+ fixed term (regardless of how the transaction is characterized), the
376
+ Corresponding Source conveyed under this section must be accompanied
377
+ by the Installation Information. But this requirement does not apply
378
+ if neither you nor any third party retains the ability to install
379
+ modified object code on the User Product (for example, the work has
380
+ been installed in ROM).
381
+
382
+ The requirement to provide Installation Information does not include a
383
+ requirement to continue to provide support service, warranty, or updates
384
+ for a work that has been modified or installed by the recipient, or for
385
+ the User Product in which it has been modified or installed. Access to a
386
+ network may be denied when the modification itself materially and
387
+ adversely affects the operation of the network or violates the rules and
388
+ protocols for communication across the network.
389
+
390
+ Corresponding Source conveyed, and Installation Information provided,
391
+ in accord with this section must be in a format that is publicly
392
+ documented (and with an implementation available to the public in
393
+ source code form), and must require no special password or key for
394
+ unpacking, reading or copying.
395
+
396
+ 7. Additional Terms.
397
+
398
+ "Additional permissions" are terms that supplement the terms of this
399
+ License by making exceptions from one or more of its conditions.
400
+ Additional permissions that are applicable to the entire Program shall
401
+ be treated as though they were included in this License, to the extent
402
+ that they are valid under applicable law. If additional permissions
403
+ apply only to part of the Program, that part may be used separately
404
+ under those permissions, but the entire Program remains governed by
405
+ this License without regard to the additional permissions.
406
+
407
+ When you convey a copy of a covered work, you may at your option
408
+ remove any additional permissions from that copy, or from any part of
409
+ it. (Additional permissions may be written to require their own
410
+ removal in certain cases when you modify the work.) You may place
411
+ additional permissions on material, added by you to a covered work,
412
+ for which you have or can give appropriate copyright permission.
413
+
414
+ Notwithstanding any other provision of this License, for material you
415
+ add to a covered work, you may (if authorized by the copyright holders of
416
+ that material) supplement the terms of this License with terms:
417
+
418
+ a) Disclaiming warranty or limiting liability differently from the
419
+ terms of sections 15 and 16 of this License; or
420
+
421
+ b) Requiring preservation of specified reasonable legal notices or
422
+ author attributions in that material or in the Appropriate Legal
423
+ Notices displayed by works containing it; or
424
+
425
+ c) Prohibiting misrepresentation of the origin of that material, or
426
+ requiring that modified versions of such material be marked in
427
+ reasonable ways as different from the original version; or
428
+
429
+ d) Limiting the use for publicity purposes of names of licensors or
430
+ authors of the material; or
431
+
432
+ e) Declining to grant rights under trademark law for use of some
433
+ trade names, trademarks, or service marks; or
434
+
435
+ f) Requiring indemnification of licensors and authors of that
436
+ material by anyone who conveys the material (or modified versions of
437
+ it) with contractual assumptions of liability to the recipient, for
438
+ any liability that these contractual assumptions directly impose on
439
+ those licensors and authors.
440
+
441
+ All other non-permissive additional terms are considered "further
442
+ restrictions" within the meaning of section 10. If the Program as you
443
+ received it, or any part of it, contains a notice stating that it is
444
+ governed by this License along with a term that is a further
445
+ restriction, you may remove that term. If a license document contains
446
+ a further restriction but permits relicensing or conveying under this
447
+ License, you may add to a covered work material governed by the terms
448
+ of that license document, provided that the further restriction does
449
+ not survive such relicensing or conveying.
450
+
451
+ If you add terms to a covered work in accord with this section, you
452
+ must place, in the relevant source files, a statement of the
453
+ additional terms that apply to those files, or a notice indicating
454
+ where to find the applicable terms.
455
+
456
+ Additional terms, permissive or non-permissive, may be stated in the
457
+ form of a separately written license, or stated as exceptions;
458
+ the above requirements apply either way.
459
+
460
+ 8. Termination.
461
+
462
+ You may not propagate or modify a covered work except as expressly
463
+ provided under this License. Any attempt otherwise to propagate or
464
+ modify it is void, and will automatically terminate your rights under
465
+ this License (including any patent licenses granted under the third
466
+ paragraph of section 11).
467
+
468
+ However, if you cease all violation of this License, then your
469
+ license from a particular copyright holder is reinstated (a)
470
+ provisionally, unless and until the copyright holder explicitly and
471
+ finally terminates your license, and (b) permanently, if the copyright
472
+ holder fails to notify you of the violation by some reasonable means
473
+ prior to 60 days after the cessation.
474
+
475
+ Moreover, your license from a particular copyright holder is
476
+ reinstated permanently if the copyright holder notifies you of the
477
+ violation by some reasonable means, this is the first time you have
478
+ received notice of violation of this License (for any work) from that
479
+ copyright holder, and you cure the violation prior to 30 days after
480
+ your receipt of the notice.
481
+
482
+ Termination of your rights under this section does not terminate the
483
+ licenses of parties who have received copies or rights from you under
484
+ this License. If your rights have been terminated and not permanently
485
+ reinstated, you do not qualify to receive new licenses for the same
486
+ material under section 10.
487
+
488
+ 9. Acceptance Not Required for Having Copies.
489
+
490
+ You are not required to accept this License in order to receive or
491
+ run a copy of the Program. Ancillary propagation of a covered work
492
+ occurring solely as a consequence of using peer-to-peer transmission
493
+ to receive a copy likewise does not require acceptance. However,
494
+ nothing other than this License grants you permission to propagate or
495
+ modify any covered work. These actions infringe copyright if you do
496
+ not accept this License. Therefore, by modifying or propagating a
497
+ covered work, you indicate your acceptance of this License to do so.
498
+
499
+ 10. Automatic Licensing of Downstream Recipients.
500
+
501
+ Each time you convey a covered work, the recipient automatically
502
+ receives a license from the original licensors, to run, modify and
503
+ propagate that work, subject to this License. You are not responsible
504
+ for enforcing compliance by third parties with this License.
505
+
506
+ An "entity transaction" is a transaction transferring control of an
507
+ organization, or substantially all assets of one, or subdividing an
508
+ organization, or merging organizations. If propagation of a covered
509
+ work results from an entity transaction, each party to that
510
+ transaction who receives a copy of the work also receives whatever
511
+ licenses to the work the party's predecessor in interest had or could
512
+ give under the previous paragraph, plus a right to possession of the
513
+ Corresponding Source of the work from the predecessor in interest, if
514
+ the predecessor has it or can get it with reasonable efforts.
515
+
516
+ You may not impose any further restrictions on the exercise of the
517
+ rights granted or affirmed under this License. For example, you may
518
+ not impose a license fee, royalty, or other charge for exercise of
519
+ rights granted under this License, and you may not initiate litigation
520
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
521
+ any patent claim is infringed by making, using, selling, offering for
522
+ sale, or importing the Program or any portion of it.
523
+
524
+ 11. Patents.
525
+
526
+ A "contributor" is a copyright holder who authorizes use under this
527
+ License of the Program or a work on which the Program is based. The
528
+ work thus licensed is called the contributor's "contributor version".
529
+
530
+ A contributor's "essential patent claims" are all patent claims
531
+ owned or controlled by the contributor, whether already acquired or
532
+ hereafter acquired, that would be infringed by some manner, permitted
533
+ by this License, of making, using, or selling its contributor version,
534
+ but do not include claims that would be infringed only as a
535
+ consequence of further modification of the contributor version. For
536
+ purposes of this definition, "control" includes the right to grant
537
+ patent sublicenses in a manner consistent with the requirements of
538
+ this License.
539
+
540
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
541
+ patent license under the contributor's essential patent claims, to
542
+ make, use, sell, offer for sale, import and otherwise run, modify and
543
+ propagate the contents of its contributor version.
544
+
545
+ In the following three paragraphs, a "patent license" is any express
546
+ agreement or commitment, however denominated, not to enforce a patent
547
+ (such as an express permission to practice a patent or covenant not to
548
+ sue for patent infringement). To "grant" such a patent license to a
549
+ party means to make such an agreement or commitment not to enforce a
550
+ patent against the party.
551
+
552
+ If you convey a covered work, knowingly relying on a patent license,
553
+ and the Corresponding Source of the work is not available for anyone
554
+ to copy, free of charge and under the terms of this License, through a
555
+ publicly available network server or other readily accessible means,
556
+ then you must either (1) cause the Corresponding Source to be so
557
+ available, or (2) arrange to deprive yourself of the benefit of the
558
+ patent license for this particular work, or (3) arrange, in a manner
559
+ consistent with the requirements of this License, to extend the patent
560
+ license to downstream recipients. "Knowingly relying" means you have
561
+ actual knowledge that, but for the patent license, your conveying the
562
+ covered work in a country, or your recipient's use of the covered work
563
+ in a country, would infringe one or more identifiable patents in that
564
+ country that you have reason to believe are valid.
565
+
566
+ If, pursuant to or in connection with a single transaction or
567
+ arrangement, you convey, or propagate by procuring conveyance of, a
568
+ covered work, and grant a patent license to some of the parties
569
+ receiving the covered work authorizing them to use, propagate, modify
570
+ or convey a specific copy of the covered work, then the patent license
571
+ you grant is automatically extended to all recipients of the covered
572
+ work and works based on it.
573
+
574
+ A patent license is "discriminatory" if it does not include within
575
+ the scope of its coverage, prohibits the exercise of, or is
576
+ conditioned on the non-exercise of one or more of the rights that are
577
+ specifically granted under this License. You may not convey a covered
578
+ work if you are a party to an arrangement with a third party that is
579
+ in the business of distributing software, under which you make payment
580
+ to the third party based on the extent of your activity of conveying
581
+ the work, and under which the third party grants, to any of the
582
+ parties who would receive the covered work from you, a discriminatory
583
+ patent license (a) in connection with copies of the covered work
584
+ conveyed by you (or copies made from those copies), or (b) primarily
585
+ for and in connection with specific products or compilations that
586
+ contain the covered work, unless you entered into that arrangement,
587
+ or that patent license was granted, prior to 28 March 2007.
588
+
589
+ Nothing in this License shall be construed as excluding or limiting
590
+ any implied license or other defenses to infringement that may
591
+ otherwise be available to you under applicable patent law.
592
+
593
+ 12. No Surrender of Others' Freedom.
594
+
595
+ If conditions are imposed on you (whether by court order, agreement or
596
+ otherwise) that contradict the conditions of this License, they do not
597
+ excuse you from the conditions of this License. If you cannot convey a
598
+ covered work so as to satisfy simultaneously your obligations under this
599
+ License and any other pertinent obligations, then as a consequence you may
600
+ not convey it at all. For example, if you agree to terms that obligate you
601
+ to collect a royalty for further conveying from those to whom you convey
602
+ the Program, the only way you could satisfy both those terms and this
603
+ License would be to refrain entirely from conveying the Program.
604
+
605
+ 13. Remote Network Interaction; Use with the GNU General Public License.
606
+
607
+ Notwithstanding any other provision of this License, if you modify the
608
+ Program, your modified version must prominently offer all users
609
+ interacting with it remotely through a computer network (if your version
610
+ supports such interaction) an opportunity to receive the Corresponding
611
+ Source of your version by providing access to the Corresponding Source
612
+ from a network server at no charge, through some standard or customary
613
+ means of facilitating copying of software. This Corresponding Source
614
+ shall include the Corresponding Source for any work covered by version 3
615
+ of the GNU General Public License that is incorporated pursuant to the
616
+ following paragraph.
617
+
618
+ Notwithstanding any other provision of this License, you have
619
+ permission to link or combine any covered work with a work licensed
620
+ under version 3 of the GNU General Public License into a single
621
+ combined work, and to convey the resulting work. The terms of this
622
+ License will continue to apply to the part which is the covered work,
623
+ but the work with which it is combined will remain governed by version
624
+ 3 of the GNU General Public License.
625
+
626
+ 14. Revised Versions of this License.
627
+
628
+ The Free Software Foundation may publish revised and/or new versions of
629
+ the GNU Affero General Public License from time to time. Such new versions
630
+ will be similar in spirit to the present version, but may differ in detail to
631
+ address new problems or concerns.
632
+
633
+ Each version is given a distinguishing version number. If the
634
+ Program specifies that a certain numbered version of the GNU Affero General
635
+ Public License "or any later version" applies to it, you have the
636
+ option of following the terms and conditions either of that numbered
637
+ version or of any later version published by the Free Software
638
+ Foundation. If the Program does not specify a version number of the
639
+ GNU Affero General Public License, you may choose any version ever published
640
+ by the Free Software Foundation.
641
+
642
+ If the Program specifies that a proxy can decide which future
643
+ versions of the GNU Affero General Public License can be used, that proxy's
644
+ public statement of acceptance of a version permanently authorizes you
645
+ to choose that version for the Program.
646
+
647
+ Later license versions may give you additional or different
648
+ permissions. However, no additional obligations are imposed on any
649
+ author or copyright holder as a result of your choosing to follow a
650
+ later version.
651
+
652
+ 15. Disclaimer of Warranty.
653
+
654
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
655
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
656
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
657
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
658
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
659
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
660
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
661
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
662
+
663
+ 16. Limitation of Liability.
664
+
665
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
666
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
667
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
668
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
669
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
670
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
671
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
672
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
673
+ SUCH DAMAGES.
674
+
675
+ 17. Interpretation of Sections 15 and 16.
676
+
677
+ If the disclaimer of warranty and limitation of liability provided
678
+ above cannot be given local legal effect according to their terms,
679
+ reviewing courts shall apply local law that most closely approximates
680
+ an absolute waiver of all civil liability in connection with the
681
+ Program, unless a warranty or assumption of liability accompanies a
682
+ copy of the Program in return for a fee.
683
+
684
+ END OF TERMS AND CONDITIONS
685
+
686
+ How to Apply These Terms to Your New Programs
687
+
688
+ If you develop a new program, and you want it to be of the greatest
689
+ possible use to the public, the best way to achieve this is to make it
690
+ free software which everyone can redistribute and change under these terms.
691
+
692
+ To do so, attach the following notices to the program. It is safest
693
+ to attach them to the start of each source file to most effectively
694
+ state the exclusion of warranty; and each file should have at least
695
+ the "copyright" line and a pointer to where the full notice is found.
696
+
697
+ <one line to give the program's name and a brief idea of what it does.>
698
+
699
+ Copyright (C) <year> <organization>
700
+
701
+ This program is free software: you can redistribute it and/or modify
702
+ it under the terms of the GNU Affero General Public License as published by
703
+ the Free Software Foundation, either version 3 of the License, or
704
+ (at your option) any later version.
705
+
706
+ This program is distributed in the hope that it will be useful,
707
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
708
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
709
+ GNU Affero General Public License for more details.
710
+
711
+ You should have received a copy of the GNU Affero General Public License
712
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
713
+
714
+ Also add information on how to contact you by electronic and paper mail.
715
+
716
+ If your software can interact with users remotely through a computer
717
+ network, you should also make sure that it provides a way for users to
718
+ get its source. For example, if your program is a web application, its
719
+ interface could display a "Source" link that leads users to an archive
720
+ of the code. There are many ways you could offer source, and different
721
+ solutions will be better for different programs; see section 13 for the
722
+ specific requirements.
723
+
724
+ You should also get your employer (if you work as a programmer) or school,
725
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
726
+ For more information on this, and how to apply and follow the GNU AGPL, see
727
+ <http://www.gnu.org/licenses/>.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ <!--
2
+ SPDX-FileCopyrightText: 2026 Shaan Narendran <shaannaren06@gmail.com>
3
+ SPDX-License-Identifier: AGPL-3.0-only
4
+ -->
5
+
6
+ # observal-pi
7
+
8
+ Session telemetry extension for [Pi](https://pi.dev) that pushes conversation traces to your [Observal](https://obs-sync.dev) server.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pi install npm:observal-pi
14
+ ```
15
+
16
+ ## Prerequisites
17
+
18
+ 1. An Observal account — run `observal auth login` to authenticate
19
+ 2. Pi installed (`>=0.74.0`)
20
+
21
+ ## What it does
22
+
23
+ - **Incremental push:** After each user prompt (`agent_end`), reads new JSONL lines from the session file and POSTs them to your Observal server
24
+ - **Final push:** On session exit, sends remaining lines with integrity metadata
25
+ - **Crash recovery:** On startup, detects sessions that weren't cleanly finalized and pushes their remaining data
26
+ - **Status indicator:** Shows `● observal` in the footer with line count
27
+
28
+ ## Commands
29
+
30
+ | Command | Description |
31
+ |---------|-------------|
32
+ | `/obs-sync` | Show sync status (lines pushed, server URL) |
33
+ | `/obs-sync flush` | Force push pending lines now |
34
+ | `/obs-sync config` | Show config file path and server URL |
35
+
36
+ ## Design
37
+
38
+ - **Zero dependencies** — only `node:*` built-ins
39
+ - **Fail-open** — never throws, never crashes pi. If the server is unreachable, pi continues normally
40
+ - **5s timeout** — all HTTP calls abort after 5 seconds
41
+ - **Chunked uploads** — batches of 500 lines max per request
42
+ - **Dedup-safe** — server deduplicates by `(session_id, line_offset, line_hash)`
43
+
44
+ ## Configuration
45
+
46
+ The extension reads credentials from `~/.observal/config.json` (written by `observal auth login`):
47
+
48
+ ```json
49
+ {
50
+ "server_url": "https://your-server.observal.dev",
51
+ "access_token": "..."
52
+ }
53
+ ```
54
+
55
+ Sync state is tracked in `~/.observal/sync_state.json` (per-session byte offsets).
56
+
57
+ ## License
58
+
59
+ AGPL-3.0-only — see [LICENSE](./LICENSE)
@@ -0,0 +1,383 @@
1
+ // SPDX-FileCopyrightText: 2026 Shaan Narendran <shaannaren06@gmail.com>
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ /**
5
+ * Observal session telemetry extension for Pi.
6
+ *
7
+ * Reads the session JSONL file incrementally on lifecycle events and POSTs
8
+ * raw lines to the Observal ingest API. Zero runtime dependencies - uses
9
+ * only node:* built-ins.
10
+ *
11
+ * Design principles:
12
+ * - Fail-open: never throw, never crash pi
13
+ * - 5s timeout on all HTTP calls
14
+ * - Generation counter for async safety
15
+ * - Byte offset tracking (same model as CLI hooks)
16
+ * - Chunk at 500 lines per POST to avoid 413
17
+ */
18
+
19
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
20
+ import * as fs from "node:fs";
21
+ import * as http from "node:http";
22
+ import * as https from "node:https";
23
+ import * as os from "node:os";
24
+ import * as path from "node:path";
25
+
26
+ // ─── Types ───────────────────────────────────────────────────────────────────
27
+
28
+ interface ObservalConfig {
29
+ server_url: string;
30
+ access_token: string;
31
+ }
32
+
33
+ interface CursorEntry {
34
+ offset: number;
35
+ line_count: number;
36
+ finalized?: boolean;
37
+ }
38
+
39
+ interface ObservalState {
40
+ config: ObservalConfig | null;
41
+ sessionFile: string | null;
42
+ sessionId: string;
43
+ byteOffset: number;
44
+ lineCount: number;
45
+ generation: number;
46
+ }
47
+
48
+ // ─── Constants ───────────────────────────────────────────────────────────────
49
+
50
+ const OBSERVAL_DIR = path.join(os.homedir(), ".observal");
51
+ const CONFIG_PATH = path.join(OBSERVAL_DIR, "config.json");
52
+ const SYNC_STATE_PATH = path.join(OBSERVAL_DIR, "sync_state.json");
53
+ const TIMEOUT_MS = 5_000;
54
+ const MAX_LINES_PER_CHUNK = 500;
55
+ const RECOVERY_MAX_SESSIONS = 5;
56
+ const RECOVERY_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
57
+
58
+ // ─── Extension Entry ─────────────────────────────────────────────────────────
59
+
60
+ export default function (pi: ExtensionAPI) {
61
+ let state: ObservalState | null = null;
62
+
63
+ pi.on("session_start", async (event, ctx) => {
64
+ state = initState(ctx);
65
+
66
+ // On fresh startup, attempt crash recovery (fire-and-forget)
67
+ if (event.reason === "startup" && state.config) {
68
+ recoverStaleSessions(state, ctx).catch(() => {});
69
+ }
70
+
71
+ if (state.config && ctx.hasUI) {
72
+ const theme = ctx.ui.theme;
73
+ ctx.ui.setStatus("observal", theme.fg("dim", "● observal"));
74
+ }
75
+ });
76
+
77
+ pi.on("agent_end", async (_event, _ctx) => {
78
+ if (!state?.config || !state.sessionFile) return;
79
+ await pushNewLines(state, { final: false });
80
+ });
81
+
82
+ pi.on("session_shutdown", async (_event, _ctx) => {
83
+ if (!state?.config || !state.sessionFile) return;
84
+ await pushNewLines(state, { final: true });
85
+ state = null;
86
+ });
87
+
88
+ // ─── /obs-sync command ─────────────────────────────────────────────────
89
+
90
+ pi.registerCommand("obs-sync", {
91
+ description: "Observal telemetry sync status",
92
+ handler: async (args, ctx) => {
93
+ const sub = args.trim();
94
+ if (sub === "flush") {
95
+ if (!state?.config || !state.sessionFile) {
96
+ ctx.ui.notify("No active session or config", "warning");
97
+ return;
98
+ }
99
+ await pushNewLines(state, { final: false });
100
+ ctx.ui.notify(`Flushed (${state.lineCount} lines total)`, "info");
101
+ } else if (sub === "config") {
102
+ ctx.ui.notify(
103
+ `Config: ${CONFIG_PATH}\nServer: ${state?.config?.server_url ?? "not configured"}`,
104
+ "info",
105
+ );
106
+ } else {
107
+ const synced = state?.lineCount ?? 0;
108
+ const server = state?.config?.server_url ?? "not configured";
109
+ ctx.ui.notify(`Observal: ${synced} lines pushed\nServer: ${server}`, "info");
110
+ }
111
+ },
112
+ });
113
+
114
+ // ─── Helpers ─────────────────────────────────────────────────────────────
115
+
116
+ function initState(ctx: ExtensionContext): ObservalState {
117
+ const config = loadConfig();
118
+ const sessionFile = ctx.sessionManager.getSessionFile() ?? null;
119
+ const sessionId = ctx.sessionManager.getSessionId();
120
+
121
+ let byteOffset = 0;
122
+ let lineCount = 0;
123
+
124
+ if (sessionId) {
125
+ const cursor = readCursor(sessionId);
126
+ byteOffset = cursor.offset;
127
+ lineCount = cursor.line_count;
128
+ }
129
+
130
+ return { config, sessionFile, sessionId, byteOffset, lineCount, generation: 0 };
131
+ }
132
+
133
+ function loadConfig(): ObservalConfig | null {
134
+ try {
135
+ if (!fs.existsSync(CONFIG_PATH)) return null;
136
+ const raw = fs.readFileSync(CONFIG_PATH, "utf-8");
137
+ const data = JSON.parse(raw);
138
+ if (!data.server_url || !data.access_token) return null;
139
+ return { server_url: data.server_url, access_token: data.access_token };
140
+ } catch {
141
+ return null;
142
+ }
143
+ }
144
+
145
+ function readCursor(sessionId: string): CursorEntry {
146
+ try {
147
+ if (!fs.existsSync(SYNC_STATE_PATH)) return { offset: 0, line_count: 0 };
148
+ const data = JSON.parse(fs.readFileSync(SYNC_STATE_PATH, "utf-8"));
149
+ return data[sessionId] ?? { offset: 0, line_count: 0 };
150
+ } catch {
151
+ return { offset: 0, line_count: 0 };
152
+ }
153
+ }
154
+
155
+ function writeCursor(sessionId: string, offset: number, lineCount: number, finalized = false): void {
156
+ try {
157
+ fs.mkdirSync(OBSERVAL_DIR, { recursive: true });
158
+ let data: Record<string, CursorEntry> = {};
159
+ if (fs.existsSync(SYNC_STATE_PATH)) {
160
+ data = JSON.parse(fs.readFileSync(SYNC_STATE_PATH, "utf-8"));
161
+ }
162
+ data[sessionId] = { offset, line_count: lineCount, finalized };
163
+ fs.writeFileSync(SYNC_STATE_PATH, JSON.stringify(data, null, 2));
164
+ } catch {
165
+ // Fail-open
166
+ }
167
+ }
168
+
169
+ async function pushNewLines(s: ObservalState, opts: { final: boolean }): Promise<void> {
170
+ if (!s.config || !s.sessionFile) return;
171
+
172
+ const gen = ++s.generation;
173
+
174
+ try {
175
+ const stat = fs.statSync(s.sessionFile);
176
+ const newBytes = stat.size - s.byteOffset;
177
+
178
+ if (newBytes <= 0) {
179
+ if (opts.final) writeCursor(s.sessionId, s.byteOffset, s.lineCount, true);
180
+ return;
181
+ }
182
+
183
+ const buffer = Buffer.alloc(newBytes);
184
+ const fd = fs.openSync(s.sessionFile, "r");
185
+ fs.readSync(fd, buffer, 0, newBytes, s.byteOffset);
186
+ fs.closeSync(fd);
187
+
188
+ if (s.generation !== gen) return; // stale
189
+
190
+ const text = buffer.toString("utf-8");
191
+ const rawLines = text.split("\n");
192
+
193
+ // Only consume complete lines (discard partial last line)
194
+ const lines: string[] = [];
195
+ let consumedBytes = 0;
196
+ for (let i = 0; i < rawLines.length; i++) {
197
+ const line = rawLines[i]!;
198
+ if (i === rawLines.length - 1 && !text.endsWith("\n")) {
199
+ break; // incomplete line
200
+ }
201
+ if (line.trim()) {
202
+ lines.push(line);
203
+ }
204
+ consumedBytes += Buffer.byteLength(line, "utf-8") + 1; // +1 for \n
205
+ }
206
+
207
+ if (lines.length === 0 && !opts.final) return;
208
+
209
+ // Chunk large batches
210
+ for (let offset = 0; offset < lines.length; offset += MAX_LINES_PER_CHUNK) {
211
+ if (s.generation !== gen) return; // stale
212
+
213
+ const chunk = lines.slice(offset, offset + MAX_LINES_PER_CHUNK);
214
+ const isLastChunk = offset + MAX_LINES_PER_CHUNK >= lines.length;
215
+
216
+ const payload = JSON.stringify({
217
+ session_id: s.sessionId,
218
+ ide: "pi",
219
+ lines: chunk,
220
+ start_offset: s.lineCount + offset,
221
+ hook_event: opts.final && isLastChunk ? "SessionShutdown" : "AgentEnd",
222
+ final: opts.final && isLastChunk,
223
+ ...(opts.final && isLastChunk
224
+ ? {
225
+ total_line_count: s.lineCount + lines.length,
226
+ total_offset: s.byteOffset + consumedBytes,
227
+ }
228
+ : {}),
229
+ });
230
+
231
+ const ok = await postWithTimeout(s.config!, "/api/v1/ingest/session", payload);
232
+ if (!ok) break; // stop chunking on failure, retry next time
233
+ }
234
+
235
+ if (s.generation !== gen) return; // stale
236
+
237
+ // Update state
238
+ s.byteOffset += consumedBytes;
239
+ s.lineCount += lines.length;
240
+ writeCursor(s.sessionId, s.byteOffset, s.lineCount, opts.final);
241
+ } catch {
242
+ // Fail-open
243
+ }
244
+ }
245
+
246
+ function postWithTimeout(config: ObservalConfig, urlPath: string, body: string): Promise<boolean> {
247
+ return new Promise((resolve) => {
248
+ try {
249
+ const url = new URL(urlPath, config.server_url);
250
+ const mod = url.protocol === "https:" ? https : http;
251
+ const timer = setTimeout(() => {
252
+ req.destroy();
253
+ resolve(false);
254
+ }, TIMEOUT_MS);
255
+
256
+ const req = mod.request(
257
+ url,
258
+ {
259
+ method: "POST",
260
+ headers: {
261
+ "Content-Type": "application/json",
262
+ Authorization: `Bearer ${config.access_token}`,
263
+ "Content-Length": String(Buffer.byteLength(body)),
264
+ },
265
+ },
266
+ (res) => {
267
+ clearTimeout(timer);
268
+ res.resume(); // drain response
269
+ resolve(res.statusCode === 200);
270
+ },
271
+ );
272
+
273
+ req.on("error", () => {
274
+ clearTimeout(timer);
275
+ resolve(false);
276
+ });
277
+
278
+ req.write(body);
279
+ req.end();
280
+ } catch {
281
+ resolve(false);
282
+ }
283
+ });
284
+ }
285
+
286
+ async function recoverStaleSessions(s: ObservalState, ctx: ExtensionContext): Promise<void> {
287
+ try {
288
+ if (!fs.existsSync(SYNC_STATE_PATH) || !s.config) return;
289
+ const data: Record<string, CursorEntry> = JSON.parse(
290
+ fs.readFileSync(SYNC_STATE_PATH, "utf-8"),
291
+ );
292
+
293
+ const cwd = ctx.cwd;
294
+ const projectKey = cwd.replace(/\//g, "-");
295
+ const sessionsDir = path.join(os.homedir(), ".pi", "agent", "sessions");
296
+ // Pi uses --<path>-- format for directory names
297
+ const fullDir = path.join(sessionsDir, `-${projectKey}-`);
298
+
299
+ if (!fs.existsSync(fullDir)) return;
300
+
301
+ let recovered = 0;
302
+ const now = Date.now();
303
+
304
+ for (const [sessionId, entry] of Object.entries(data)) {
305
+ if (entry.finalized) continue;
306
+ if (sessionId === s.sessionId) continue; // current session
307
+ if (recovered >= RECOVERY_MAX_SESSIONS) break;
308
+
309
+ // Find the JSONL file for this session
310
+ const files = fs.readdirSync(fullDir).filter((f) => f.includes(sessionId));
311
+ if (files.length === 0) continue;
312
+
313
+ const filePath = path.join(fullDir, files[0]!);
314
+ if (!fs.existsSync(filePath)) continue;
315
+
316
+ // Skip sessions older than 7 days
317
+ const fileStat = fs.statSync(filePath);
318
+ if (now - fileStat.mtimeMs > RECOVERY_MAX_AGE_MS) {
319
+ writeCursor(sessionId, entry.offset, entry.line_count, true);
320
+ continue;
321
+ }
322
+
323
+ if (fileStat.size <= entry.offset) {
324
+ writeCursor(sessionId, entry.offset, entry.line_count, true);
325
+ continue;
326
+ }
327
+
328
+ const fd = fs.openSync(filePath, "r");
329
+ const buffer = Buffer.alloc(fileStat.size - entry.offset);
330
+ fs.readSync(fd, buffer, 0, buffer.length, entry.offset);
331
+ fs.closeSync(fd);
332
+
333
+ const lines = buffer
334
+ .toString("utf-8")
335
+ .split("\n")
336
+ .filter((l) => l.trim());
337
+
338
+ if (lines.length > 0) {
339
+ const payload = JSON.stringify({
340
+ session_id: sessionId,
341
+ ide: "pi",
342
+ lines,
343
+ start_offset: entry.line_count,
344
+ hook_event: "CrashRecovery",
345
+ final: true,
346
+ total_line_count: entry.line_count + lines.length,
347
+ total_offset: fileStat.size,
348
+ });
349
+ await postWithTimeout(s.config!, "/api/v1/ingest/session", payload);
350
+ }
351
+
352
+ writeCursor(sessionId, fileStat.size, entry.line_count + lines.length, true);
353
+ recovered++;
354
+ }
355
+
356
+ // Prune old finalized entries from sync_state.json
357
+ pruneSyncState();
358
+ } catch {
359
+ // Fail-open
360
+ }
361
+ }
362
+
363
+ function pruneSyncState(): void {
364
+ try {
365
+ if (!fs.existsSync(SYNC_STATE_PATH)) return;
366
+ const data: Record<string, CursorEntry> = JSON.parse(
367
+ fs.readFileSync(SYNC_STATE_PATH, "utf-8"),
368
+ );
369
+ const entries = Object.entries(data);
370
+ if (entries.length <= 50) return; // No pruning needed
371
+
372
+ // Keep only the 50 most recent entries (by offset as proxy for recency)
373
+ const sorted = entries.sort((a, b) => b[1].offset - a[1].offset);
374
+ const pruned: Record<string, CursorEntry> = {};
375
+ for (const [key, value] of sorted.slice(0, 50)) {
376
+ pruned[key] = value;
377
+ }
378
+ fs.writeFileSync(SYNC_STATE_PATH, JSON.stringify(pruned, null, 2));
379
+ } catch {
380
+ // Fail-open
381
+ }
382
+ }
383
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "observal-pi",
3
+ "version": "0.1.0",
4
+ "description": "Observal session telemetry for Pi — zero-dependency extension that pushes session traces to your Observal server",
5
+ "keywords": ["pi-package", "pi-extension", "observal", "telemetry", "tracing"],
6
+ "license": "AGPL-3.0-only",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/BlazeUp-AI/Observal.git",
10
+ "directory": "packages/pi-extension"
11
+ },
12
+ "pi": {
13
+ "extensions": ["./extensions/observal.ts"]
14
+ },
15
+ "peerDependencies": {
16
+ "@earendil-works/pi-coding-agent": ">=0.74.0"
17
+ },
18
+ "files": [
19
+ "extensions/",
20
+ "README.md",
21
+ "LICENSE"
22
+ ]
23
+ }