clavarium 0.1.4 → 0.1.5

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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.1.4",
9
+ "version": "0.1.5",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
@@ -9,6 +9,7 @@
9
9
  import { isConversationName } from './names.mjs';
10
10
  import { attachCommand, SOCKET } from './tmux.mjs';
11
11
  import { WORK, VM_USER, SHARING_STEP } from './vm.mjs';
12
+ import { resumeOrFresh } from './tools.mjs';
12
13
 
13
14
  export const SESSION = 'main';
14
15
  export const STOP_DELAY_MS = 60_000;
@@ -424,7 +425,7 @@ export class Conversations {
424
425
  first: added at EVERY start, a resume included (a tool does not
425
426
  keep it from its last session). */
426
427
  const rights = tool.rights ? (c.askFirst === true ? tool.rights.ask : tool.rights.full) : [];
427
- return [...(resume ? tool.resume : tool.command), ...rights];
428
+ return resume ? resumeOrFresh([...tool.resume, ...rights], [...tool.command, ...rights]) : [...tool.command, ...rights];
428
429
  }
429
430
 
430
431
  /* Whether its tool asks before acting (true), or acts without asking in
package/server/tools.mjs CHANGED
@@ -107,3 +107,16 @@ export function readTools(text) {
107
107
  export function loadTools(path = new URL('../config/tools.json', import.meta.url)) {
108
108
  return readTools(readFileSync(path, 'utf8'));
109
109
  }
110
+
111
+ /* TAKING UP ITS LAST SESSION, OR A NEW ONE: a tool told to resume where it has
112
+ no session of its own (never spoken to, its session files gone) may just say
113
+ so and stop ("No conversation found"), leaving a dead terminal. If the resume
114
+ fails within RESUME_GRACE_S, the tool starts fresh, in the same terminal. A
115
+ tool that ran and is quit stays quit. One argument vector, for tmux. */
116
+ export const RESUME_GRACE_S = 20;
117
+ const shq = (a) => `'${String(a).replace(/'/g, `'\\''`)}'`;
118
+ export function resumeOrFresh(resume, fresh) {
119
+ const script = `t=$(date +%s); ${resume.map(shq).join(' ')}; c=$?; `
120
+ + `if [ "$c" -ne 0 ] && [ $(( $(date +%s) - t )) -lt ${RESUME_GRACE_S} ]; then echo; echo 'No session to take up here: a new one starts.'; exec ${fresh.map(shq).join(' ')}; fi; exit "$c"`;
121
+ return ['sh', '-c', script];
122
+ }