pinokiod 3.19.62 → 3.19.65

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/kernel/util.js CHANGED
@@ -159,27 +159,32 @@ const exists= (abspath) => {
159
159
  return new Promise(r=>fs.access(abspath, fs.constants.F_OK, e => r(!e)))
160
160
  }
161
161
  const log = async (filepath, str, session) => {
162
- try {
163
- await fs.promises.mkdir(filepath, { recursive: true })
164
- } catch (e) {
165
- }
162
+ if (str && str.trim().length > 0) {
163
+ try {
164
+ await fs.promises.mkdir(filepath, { recursive: true })
165
+ } catch (e) {
166
+ }
166
167
 
167
- let output = '';
168
- for (let line of str.split('\n')) {
169
- line = line.split('\r').pop(); // handle overwriting lines
170
- output += line + '\n';
171
- }
168
+ let output = '';
169
+ for (let line of str.split('\n')) {
170
+ line = line.split('\r').pop(); // handle overwriting lines
171
+ output += line + '\n';
172
+ }
172
173
 
173
- const pattern = [
174
- '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
175
- '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-Za-z=><~]))'
176
- ].join('|');
177
- const regex = new RegExp(pattern, 'gi')
178
- let stripped = str.replaceAll(regex, '');
179
- let logpath = path.resolve(filepath, session)
180
- await fs.promises.writeFile(logpath, stripped)
181
- let latest_logpath = path.resolve(filepath, "latest")
182
- await fs.promises.writeFile(latest_logpath, stripped)
174
+ const pattern = [
175
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
176
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-Za-z=><~]))'
177
+ ].join('|');
178
+ const regex = new RegExp(pattern, 'gi')
179
+ let stripped = str.replaceAll(regex, '');
180
+ let logpath = path.resolve(filepath, session)
181
+ console.log("> write log", logpath)
182
+ await fs.promises.writeFile(logpath, stripped)
183
+ let latest_logpath = path.resolve(filepath, "latest")
184
+ console.log("> write latest log", latest_logpath)
185
+ await fs.promises.writeFile(latest_logpath, stripped)
186
+ console.log("> all logs written")
187
+ }
183
188
  }
184
189
  const run = (cmd, cwd, kernel) => {
185
190
  // console.log("Util.run", { cmd, cwd })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.19.62",
3
+ "version": "3.19.65",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/socket.js CHANGED
@@ -176,74 +176,7 @@ class Socket {
176
176
  for(let key in this.buffer) {
177
177
  let buf = this.buffer[key]
178
178
  if (this.old_buffer[key] !== buf) {
179
-
180
- /*
181
-
182
- dev
183
- /Users/x/pinokio/plugin/dev/claude.json?cwd=/Users/x/pinokio/api/audioplay
184
- /Users/x/pinokio/plugin/dev/gemini.json?cwd=/Users/x/pinokio/api/audioplay
185
-
186
- api
187
- /Users/x/pinokio/api/audioplay/start.json
188
-
189
- shell
190
- facefusion-pinokio.git_0.0_a56eb7d48c9e96d8a5217d625d83d204
191
- facefusion-pinokio.git_0.0_a56eb7d48c9e96d8a5217d625d83d204
192
- audioplay_0.0_a56eb7d48c9e96d8a5217d625d83d204
193
- */
194
-
195
- // 1. dev
196
- if (path.isAbsolute(key)) {
197
- let p = key.replace(/\?.*$/, '')
198
- let relative = path.relative(this.parent.kernel.homedir, p)
199
- if (relative.startsWith("plugin")) {
200
- // dev
201
- let m = /\?.*$/.exec(key)
202
- if (m && m.length > 0) {
203
- /*
204
- DEV Changed {
205
- cwd: '/Users/x/pinokio/api/audioplay',
206
- relative: 'plugin/dev/claude.json'
207
- }
208
- */
209
- let paramStr = m[0]
210
- let cwd = new URL("http://localhost" + paramStr).searchParams.get("cwd")
211
- let session = this.sessions[key]
212
- let logpath = path.resolve(cwd, "logs/dev", path.parse(relative).base)
213
- await Util.log(logpath, buf, session)
214
-
215
- }
216
- } else if (relative.startsWith("api")) {
217
- // api
218
- /*
219
- API Changed {
220
- cwd: '/Users/x/pinokio/api/audioplay/start.json',
221
- filepath: [ 'start.json' ]
222
- }
223
- */
224
- let filepath_chunks = relative.split(path.sep).slice(2)
225
- let cwd = this.parent.kernel.path(...relative.split(path.sep).slice(0, 2))
226
- let session = this.sessions[key]
227
- let logpath = path.resolve(cwd, "logs/api", ...filepath_chunks)
228
- await Util.log(logpath, buf, session)
229
- }
230
- } else {
231
- // Only log SHELL
232
- /*
233
- SHELL Changed { cwd: '/Users/x/pinokio/api/kernel.api.stop', key: 'kernel.api.stop' }
234
- */
235
- if (key.startsWith("kernel.")) {
236
- // do not log since these are not shell operations
237
- // need to refactor later to make this logic cleaner
238
- } else {
239
- let cwd = this.parent.kernel.path("api", key.split("_")[0])
240
- let session = this.sessions[key]
241
- let logpath = path.resolve(cwd, "logs/shell")
242
- await Util.log(logpath, buf, session)
243
- }
244
-
245
-
246
- }
179
+ this.log_buffer(key, buf)
247
180
  } else {
248
181
  // console.log(`State hasn't changed: ${key}`)
249
182
  }
@@ -298,9 +231,11 @@ class Socket {
298
231
  }
299
232
 
300
233
  if (e.data && e.data.type === "shell.kill") {
301
- // when shell is killed, reset the buffer
302
- delete this.buffer[id]
303
- delete this.sessions[id]
234
+ this.log_buffer(id, this.buffer[id]).then(() => {
235
+ // when shell is killed, reset the buffer
236
+ delete this.buffer[id]
237
+ delete this.sessions[id]
238
+ })
304
239
  }
305
240
 
306
241
  if (!this.buffer[id]) {
@@ -356,5 +291,75 @@ class Socket {
356
291
  }
357
292
  }
358
293
  }
294
+ async log_buffer(key, buf) {
295
+
296
+ /*
297
+
298
+ dev
299
+ /Users/x/pinokio/plugin/dev/claude.json?cwd=/Users/x/pinokio/api/audioplay
300
+ /Users/x/pinokio/plugin/dev/gemini.json?cwd=/Users/x/pinokio/api/audioplay
301
+
302
+ api
303
+ /Users/x/pinokio/api/audioplay/start.json
304
+
305
+ shell
306
+ facefusion-pinokio.git_0.0_a56eb7d48c9e96d8a5217d625d83d204
307
+ facefusion-pinokio.git_0.0_a56eb7d48c9e96d8a5217d625d83d204
308
+ audioplay_0.0_a56eb7d48c9e96d8a5217d625d83d204
309
+ */
310
+
311
+ // 1. dev
312
+ if (path.isAbsolute(key)) {
313
+ let p = key.replace(/\?.*$/, '')
314
+ let relative = path.relative(this.parent.kernel.homedir, p)
315
+ if (relative.startsWith("plugin")) {
316
+ // dev
317
+ let m = /\?.*$/.exec(key)
318
+ if (m && m.length > 0) {
319
+ /*
320
+ DEV Changed {
321
+ cwd: '/Users/x/pinokio/api/audioplay',
322
+ relative: 'plugin/dev/claude.json'
323
+ }
324
+ */
325
+ let paramStr = m[0]
326
+ let cwd = new URL("http://localhost" + paramStr).searchParams.get("cwd")
327
+ let session = this.sessions[key]
328
+ let logpath = path.resolve(cwd, "logs/dev", path.parse(relative).base)
329
+ await Util.log(logpath, buf, session)
330
+
331
+ }
332
+ } else if (relative.startsWith("api")) {
333
+ // api
334
+ /*
335
+ API Changed {
336
+ cwd: '/Users/x/pinokio/api/audioplay/start.json',
337
+ filepath: [ 'start.json' ]
338
+ }
339
+ */
340
+ let filepath_chunks = relative.split(path.sep).slice(2)
341
+ let cwd = this.parent.kernel.path(...relative.split(path.sep).slice(0, 2))
342
+ let session = this.sessions[key]
343
+ let logpath = path.resolve(cwd, "logs/api", ...filepath_chunks)
344
+ await Util.log(logpath, buf, session)
345
+ }
346
+ } else {
347
+ // Only log SHELL
348
+ /*
349
+ SHELL Changed { cwd: '/Users/x/pinokio/api/kernel.api.stop', key: 'kernel.api.stop' }
350
+ */
351
+ if (key.startsWith("kernel.")) {
352
+ // do not log since these are not shell operations
353
+ // need to refactor later to make this logic cleaner
354
+ } else {
355
+ let cwd = this.parent.kernel.path("api", key.split("_")[0])
356
+ let session = this.sessions[key]
357
+ let logpath = path.resolve(cwd, "logs/shell")
358
+ await Util.log(logpath, buf, session)
359
+ }
360
+
361
+
362
+ }
363
+ }
359
364
  }
360
365
  module.exports = Socket