@hk_net/pi-timestamp 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 (4) hide show
  1. package/LICENSE +277 -0
  2. package/README.md +27 -0
  3. package/package.json +37 -0
  4. package/timestamp.ts +80 -0
package/LICENSE ADDED
@@ -0,0 +1,277 @@
1
+ EUROPEAN UNION PUBLIC LICENCE v. 1.2
2
+ EUPL © the European Union 2007, 2016
3
+
4
+ This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined
5
+ below) which is provided under the terms of this Licence. Any use of the Work,
6
+ other than as authorised under this Licence is prohibited (to the extent such
7
+ use is covered by a right of the copyright holder of the Work).
8
+
9
+ The Work is provided under the terms of this Licence when the Licensor (as
10
+ defined below) has placed the following notice immediately following the
11
+ copyright notice for the Work:
12
+
13
+ Licensed under the EUPL
14
+
15
+ or has expressed by any other means his willingness to license under the EUPL.
16
+
17
+ 1. Definitions
18
+
19
+ In this Licence, the following terms have the following meaning:
20
+
21
+ - ‘The Licence’: this Licence.
22
+ - ‘The Original Work’: the work or software distributed or communicated by the
23
+ Licensor under this Licence, available as Source Code and also as Executable
24
+ Code as the case may be.
25
+ - ‘Derivative Works’: the works or software that could be created by the
26
+ Licensee, based upon the Original Work or modifications thereof. This Licence
27
+ does not define the extent of modification or dependence on the Original Work
28
+ required in order to classify a work as a Derivative Work; this extent is
29
+ determined by copyright law applicable in the country mentioned in Article 15.
30
+ - ‘The Work’: the Original Work or its Derivative Works.
31
+ - ‘The Source Code’: the human-readable form of the Work which is the most
32
+ convenient for people to study and modify.
33
+ - ‘The Executable Code’: any code which has generally been compiled and which
34
+ is meant to be interpreted by a computer as a program.
35
+ - ‘The Licensor’: the natural or legal person that distributes or communicates
36
+ the Work under the Licence.
37
+ - ‘Contributor(s)’: any natural or legal person who modifies the Work under
38
+ the Licence, or otherwise contributes to the creation of a Derivative Work.
39
+ - ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
40
+ the Work under the terms of this Licence.
41
+ - ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
42
+ renting, distributing, communicating, transmitting, or otherwise making
43
+ available, online or offline, copies of the Work or providing access to its
44
+ essential functionalities at the disposal of any other natural or legal
45
+ person.
46
+
47
+ 2. Scope of the rights granted by the Licence
48
+
49
+ The Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
50
+ sublicensable licence to do the following, for the duration of copyright vested
51
+ in the Original Work:
52
+
53
+ - use the Work in any circumstance and for all usage,
54
+ - reproduce the Work,
55
+ - modify the Work, and make Derivative Works based upon the Work,
56
+ - communicate to the public, including the right to make available or display
57
+ the Work or copies thereof to the public and perform publicly, as the case may
58
+ be, the Work,
59
+ - distribute the Work or copies thereof,
60
+ - lend and rent the Work or copies thereof.
61
+
62
+ Those rights can be exercised on any media, supports and formats, whether now
63
+ known or later invented, as far as the applicable law permits so.
64
+
65
+ In the countries where moral rights apply, the Licensor waives his right to
66
+ exercise his moral right to the extent allowed by law in order to make effective
67
+ the licence of the economic rights here above granted.
68
+
69
+ The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to
70
+ any patents held by the Licensor, to the extent necessary to make use of the
71
+ rights granted on the Work under this Licence.
72
+
73
+ 3. Communication of the Source Code
74
+
75
+ The Licensor may provide the Work either in its Source Code form, or as
76
+ Executable Code. If the Work is provided as Executable Code, the Licensor
77
+ provides in addition a machine-readable copy of the Source Code of the Work
78
+ along with each copy of the Work that the Licensor distributes or indicates, in
79
+ a notice following the copyright notice attached to the Work, a repository where
80
+ the Source Code is easily and freely accessible for as long as the Licensor
81
+ continues to distribute or communicate the Work.
82
+
83
+ 4. Limitations on copyright
84
+
85
+ Nothing in this Licence is intended to deprive the Licensee of the benefits from
86
+ any exception or limitation to the exclusive rights of the rights owners in the
87
+ Work, of the exhaustion of those rights or of other applicable limitations
88
+ thereto.
89
+
90
+ 5. Obligations of the Licensee
91
+
92
+ The grant of the rights mentioned above is subject to some restrictions and
93
+ obligations imposed on the Licensee. Those obligations are the following:
94
+
95
+ Attribution right: The Licensee shall keep intact all copyright, patent or
96
+ trademarks notices and all notices that refer to the Licence and to the
97
+ disclaimer of warranties. The Licensee must include a copy of such notices and a
98
+ copy of the Licence with every copy of the Work he/she distributes or
99
+ communicates. The Licensee must cause any Derivative Work to carry prominent
100
+ notices stating that the Work has been modified and the date of modification.
101
+
102
+ Copyleft clause: If the Licensee distributes or communicates copies of the
103
+ Original Works or Derivative Works, this Distribution or Communication will be
104
+ done under the terms of this Licence or of a later version of this Licence
105
+ unless the Original Work is expressly distributed only under this version of the
106
+ Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee
107
+ (becoming Licensor) cannot offer or impose any additional terms or conditions on
108
+ the Work or Derivative Work that alter or restrict the terms of the Licence.
109
+
110
+ Compatibility clause: If the Licensee Distributes or Communicates Derivative
111
+ Works or copies thereof based upon both the Work and another work licensed under
112
+ a Compatible Licence, this Distribution or Communication can be done under the
113
+ terms of this Compatible Licence. For the sake of this clause, ‘Compatible
114
+ Licence’ refers to the licences listed in the appendix attached to this Licence.
115
+ Should the Licensee's obligations under the Compatible Licence conflict with
116
+ his/her obligations under this Licence, the obligations of the Compatible
117
+ Licence shall prevail.
118
+
119
+ Provision of Source Code: When distributing or communicating copies of the Work,
120
+ the Licensee will provide a machine-readable copy of the Source Code or indicate
121
+ a repository where this Source will be easily and freely available for as long as
122
+ the Licensee continues to distribute or communicate the Work.
123
+
124
+ Legal Protection: This Licence does not grant permission to use the trade names,
125
+ trademarks, service marks, or names of the Licensor, except as required for
126
+ reasonable and customary use in describing the origin of the Work and
127
+ reproducing the content of the copyright notice.
128
+
129
+ 6. Chain of Authorship
130
+
131
+ The original Licensor warrants that the copyright in the Original Work granted
132
+ hereunder is owned by him/her or licensed to him/her and that he/she has the
133
+ power and authority to grant the Licence.
134
+
135
+ Each Contributor warrants that the copyright in the modifications he/she brings
136
+ to the Work are owned by him/her or licensed to him/her and that he/she has the
137
+ power and authority to grant the Licence.
138
+
139
+ Each time You accept the Licence, the original Licensor and subsequent
140
+ Contributors grant You a licence to their contributions to the Work, under the
141
+ terms of this Licence.
142
+
143
+ 7. Disclaimer of Warranty
144
+
145
+ The Work is a work in progress, which is continuously improved by numerous
146
+ Contributors. It is not a finished work and may therefore contain defects or
147
+ ‘bugs’ inherent to this type of development.
148
+
149
+ For the above reason, the Work is provided under the Licence on an ‘as is’ basis
150
+ and without warranties of any kind concerning the Work, including without
151
+ limitation merchantability, fitness for a particular purpose, absence of defects
152
+ or errors, accuracy, non-infringement of intellectual property rights other than
153
+ copyright as stated in Article 6 of this Licence.
154
+
155
+ This disclaimer of warranty is an essential part of the Licence and a condition
156
+ for the grant of any rights to the Work.
157
+
158
+ 8. Disclaimer of Liability
159
+
160
+ Except in the cases of wilful misconduct or damages directly caused to natural
161
+ persons, the Licensor will in no event be liable for any direct or indirect,
162
+ material or moral, damages of any kind, arising out of the Licence or of the use
163
+ of the Work, including without limitation, damages for loss of goodwill, work
164
+ stoppage, computer failure or malfunction, loss of data or any commercial
165
+ damage, even if the Licensor has been advised of the possibility of such damage.
166
+ However, the Licensor will be liable under statutory product liability laws as
167
+ far such laws apply to the Work.
168
+
169
+ 9. Additional agreements
170
+
171
+ While distributing the Work, You may choose to conclude an additional agreement,
172
+ defining obligations or services consistent with this Licence. However, if
173
+ accepting obligations, You may act only on your own behalf and on your sole
174
+ responsibility, not on behalf of the original Licensor or any other Contributor,
175
+ and only if You agree to indemnify, defend, and hold each Contributor harmless
176
+ for any liability incurred by, or claims asserted against such Contributor by the
177
+ fact You have accepted any warranty or additional liability.
178
+
179
+ 10. Acceptance of the Licence
180
+
181
+ The provisions of this Licence can be accepted by clicking on an icon ‘I agree’
182
+ placed under the bottom of a window displaying the text of this Licence or by
183
+ affirming consent in any other similar way, in accordance with the rules of
184
+ applicable law. Clicking on that icon indicates your clear and irrevocable
185
+ acceptance of this Licence and all of its terms and conditions.
186
+
187
+ Similarly, you irrevocably accept this Licence and all of its terms and
188
+ conditions by exercising any rights granted to You by Article 2 of this Licence,
189
+ such as the use of the Work, the creation by You of a Derivative Work or the
190
+ Distribution or Communication by You of the Work or copies thereof.
191
+
192
+ 11. Information to the public
193
+
194
+ In case of any Distribution or Communication of the Work by means of electronic
195
+ communication by You (for example, by offering to download the Work from a
196
+ remote location) the distribution channel or media (for example, a website) must
197
+ at least provide to the public the information requested by the applicable law
198
+ regarding the Licensor, the Licence and the way it may be accessible, concluded,
199
+ stored and reproduced by the Licensee.
200
+
201
+ 12. Termination of the Licence
202
+
203
+ The Licence and the rights granted hereunder will terminate automatically upon
204
+ any breach by the Licensee of the terms of the Licence.
205
+
206
+ Such a termination will not terminate the licences of any person who has
207
+ received the Work from the Licensee under the Licence, provided such persons
208
+ remain in full compliance with the Licence.
209
+
210
+ 13. Miscellaneous
211
+
212
+ Without prejudice of Article 9 above, the Licence represents the complete
213
+ agreement between the Parties as to the Work.
214
+
215
+ If any provision of the Licence is invalid or unenforceable under applicable
216
+ law, this will not affect the validity or enforceability of the Licence as a
217
+ whole. Such provision will be construed or reformed so as necessary to make it
218
+ valid and enforceable.
219
+
220
+ The European Commission may publish other linguistic versions or new versions of
221
+ this Licence or updated versions of the Appendix, so far this is required and
222
+ reasonable, without reducing the scope of the rights granted by the Licence. New
223
+ versions of the Licence will be published with a unique version number.
224
+
225
+ All linguistic versions of this Licence, approved by the European Commission,
226
+ have identical value. Parties can take advantage of the linguistic version of
227
+ their choice.
228
+
229
+ 14. Jurisdiction
230
+
231
+ Without prejudice to specific agreement between parties,
232
+
233
+ - any litigation resulting from the interpretation of this License, arising
234
+ between the European Union institutions, bodies, offices or agencies, as a
235
+ Licensor, and any Licensee, will be subject to the jurisdiction of the Court
236
+ of Justice of the European Union, as laid down in article 272 of the Treaty on
237
+ the Functioning of the European Union,
238
+
239
+ - any litigation arising between other parties and resulting from the
240
+ interpretation of this License, will be subject to the exclusive jurisdiction
241
+ of the competent court where the Licensor resides or conducts its primary
242
+ business.
243
+
244
+ 15. Applicable Law
245
+
246
+ Without prejudice to specific agreement between parties,
247
+
248
+ - this Licence shall be governed by the law of the European Union Member State
249
+ where the Licensor has his seat, resides or has his registered office,
250
+
251
+ - this licence shall be governed by Belgian law if the Licensor has no seat,
252
+ residence or registered office inside a European Union Member State.
253
+
254
+ Appendix
255
+
256
+ ‘Compatible Licences’ according to Article 5 EUPL are:
257
+
258
+ - GNU General Public License (GPL) v. 2, v. 3
259
+ - GNU Affero General Public License (AGPL) v. 3
260
+ - Open Software License (OSL) v. 2.1, v. 3.0
261
+ - Eclipse Public License (EPL) v. 1.0, v. 2.0
262
+ - CeCILL v. 2.0, v. 2.1
263
+ - Mozilla Public Licence (MPL) v. 2
264
+ - GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
265
+ - Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
266
+ works other than software
267
+ - European Union Public Licence (EUPL) v. 1.1, v. 1.2
268
+ - Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
269
+ Reciprocity (LiLiQ-R+).
270
+
271
+ The European Commission may update this Appendix to later versions of the above
272
+ licences without producing a new version of the EUPL, as long as they provide
273
+ the rights granted in Article 2 of this Licence and protect the covered Source
274
+ Code from exclusive appropriation.
275
+
276
+ All other changes or additions to this Appendix require the production of a new
277
+ EUPL version.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # pi-timestamp
2
+
3
+ Shows timestamps for user input and agent completion timing.
4
+
5
+ ## What it does
6
+
7
+ - **User input**: Shows `Sent HH:MM:SS` after each user message
8
+ - **Agent completion**: Shows `Done at HH:MM:SS · duration` after each agent turn (e.g., `Done at 14:32:05 · 3.2s`)
9
+
10
+ All timestamps are **display-only** — they are sent as custom messages that never enter the LLM context.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pi install npm:@hk_net/pi-timestamp
16
+ ```
17
+
18
+ Or copy manually:
19
+
20
+ ```bash
21
+ mkdir -p ~/.pi/agent/extensions
22
+ cp packages/pi-timestamp/timestamp.ts ~/.pi/agent/extensions/timestamp.ts
23
+ ```
24
+
25
+ ## Duration measurement
26
+
27
+ Captured from `agent_start` (when the model starts processing) to `agent_end` (when all tool calls and model processing are done).
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@hk_net/pi-timestamp",
3
+ "version": "0.1.0",
4
+ "description": "Pi extension that shows timestamps for user input and agent completion timing",
5
+ "type": "module",
6
+ "private": false,
7
+ "keywords": [
8
+ "pi-package",
9
+ "pi",
10
+ "extension",
11
+ "timestamp"
12
+ ],
13
+ "license": "EUPL-1.2",
14
+ "author": "hknet",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/hknet/pi-extensions.git",
18
+ "directory": "packages/pi-timestamp"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/hknet/pi-extensions/issues"
22
+ },
23
+ "homepage": "https://github.com/hknet/pi-extensions/tree/main/packages/pi-timestamp#readme",
24
+ "files": [
25
+ "timestamp.ts",
26
+ "README.md"
27
+ ],
28
+ "peerDependencies": {
29
+ "@earendil-works/pi-coding-agent": "*",
30
+ "@earendil-works/pi-tui": "*"
31
+ },
32
+ "pi": {
33
+ "extensions": [
34
+ "./timestamp.ts"
35
+ ]
36
+ }
37
+ }
package/timestamp.ts ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Timestamp Extension
3
+ *
4
+ * Displays timestamps for user input and agent completion timing.
5
+ * All timestamps are display-only — they never enter the LLM context.
6
+ *
7
+ * - Shows `[Sent HH:MM:SS]` after each user message
8
+ * - Shows `Done at HH:MM:SS · duration` after each agent turn
9
+ */
10
+
11
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
12
+ import { Text } from "@earendil-works/pi-tui";
13
+
14
+ function formatTime(ts: number): string {
15
+ const d = new Date(ts);
16
+ const hh = String(d.getHours()).padStart(2, "0");
17
+ const mm = String(d.getMinutes()).padStart(2, "0");
18
+ const ss = String(d.getSeconds()).padStart(2, "0");
19
+ return `${hh}:${mm}:${ss}`;
20
+ }
21
+
22
+ function formatDuration(ms: number): string {
23
+ if (ms < 1000) return `${ms}ms`;
24
+ const totalSecs = ms / 1000;
25
+ if (totalSecs < 60) return `${totalSecs.toFixed(1)}s`;
26
+ const totalMins = totalSecs / 60;
27
+ if (totalMins < 60) {
28
+ const m = Math.floor(totalMins);
29
+ const s = (totalSecs % 60).toFixed(1);
30
+ return `${m}m ${s}s`;
31
+ }
32
+ const hrs = totalMins / 60;
33
+ return `${Math.floor(hrs)}h ${Math.floor(totalMins % 60)}m`;
34
+ }
35
+
36
+ export default function (pi: ExtensionAPI) {
37
+ let taskStartTime: number | undefined;
38
+
39
+ // Track when the agent starts processing (first turn of this prompt)
40
+ pi.on("agent_start", async (_event, _ctx) => {
41
+ taskStartTime = Date.now();
42
+ });
43
+
44
+ // Show "Sent HH:MM:SS" after each user message
45
+ pi.on("message_end", async (event, _ctx) => {
46
+ if (event.message.role !== "user") return;
47
+
48
+ const ts = event.message.timestamp;
49
+ if (!ts) return;
50
+
51
+ pi.sendMessage({
52
+ customType: "timestamp",
53
+ content: `Sent ${formatTime(ts)}`,
54
+ display: true,
55
+ }, { triggerTurn: false });
56
+ });
57
+
58
+ // Show completion timing after agent finishes
59
+ pi.on("agent_end", async (_event, _ctx) => {
60
+ const startTime = taskStartTime;
61
+ taskStartTime = undefined;
62
+
63
+ if (startTime === undefined) return;
64
+
65
+ const endTime = Date.now();
66
+ const duration = endTime - startTime;
67
+
68
+ pi.sendMessage({
69
+ customType: "timestamp",
70
+ content: `Done at ${formatTime(endTime)} · ${formatDuration(duration)}`,
71
+ display: true,
72
+ }, { triggerTurn: false });
73
+ });
74
+
75
+ // Render all timestamp lines in a muted/dim style
76
+ pi.registerMessageRenderer("timestamp", (message, _options, theme) => {
77
+ const text = typeof message.content === "string" ? message.content : "";
78
+ return new Text(theme.fg("dim", text), 0, 0);
79
+ });
80
+ }