@joripspace/cli 0.5.0 → 0.5.1

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,87 +1,87 @@
1
- const fs = require('node:fs');
2
- const path = require('node:path');
1
+ const fs = require('node:fs');
2
+ const path = require('node:path');
3
3
  const { resolveProjectRoot, startProject, createStartOnboarding } = require('./start');
4
- const { ensureProjectEnvIgnored, readProjectEnv } = require('./project-env');
5
-
6
- function createStartProjectCommand(
7
- apiRequest,
8
- output,
9
- resolveConnection,
10
- stringFlag,
11
- pullDeploymentSource,
12
- projectWorkspaceDir,
13
- persistConnection,
14
- connectForStart
15
- ) {
16
- return async function startProjectCommand(rest, flags) {
17
- const positionalProject = rest[0] || '';
18
- const flaggedProject = stringFlag(flags, 'project');
19
- if (positionalProject && flaggedProject && positionalProject !== flaggedProject) {
20
- throw new Error('start positional project and --project must match');
21
- }
22
- const project = flaggedProject || positionalProject;
23
- if (!project) throw new Error('start requires PROJECT');
24
- if (rest.length > 1) throw new Error('start accepts exactly one PROJECT');
25
- const requestedCwd = stringFlag(flags, 'cwd')
26
- ? path.resolve(stringFlag(flags, 'cwd'))
27
- : projectWorkspaceDir(flags);
28
- const cwd = resolveProjectRoot(requestedCwd, 'git');
29
- readProjectEnv(cwd);
30
- if (fs.existsSync(path.join(cwd, '.env.joripspace'))) {
31
- ensureProjectEnvIgnored(cwd);
32
- }
33
- const executable = path.resolve(
34
- process.env.JORIPSPACE_CLI_EXECUTABLE ||
35
- (process.pkg ? process.execPath : process.argv[1] || process.execPath)
36
- );
37
- const resolvedFlags = { ...flags, cwd };
38
- let connection = resolveConnection(resolvedFlags);
39
- if (!connection.apiToken) {
40
- connection = connectForStart
41
- ? await connectForStart(resolvedFlags, { cwd, executable, project })
42
- : connection;
43
- }
44
- if (!connection?.apiToken) {
45
- const apiUrlArgument = connection?.apiBaseUrl
46
- ? ` --api-url ${quoteCliArgument(connection.apiBaseUrl)}`
47
- : '';
4
+ const { ensureProjectEnvIgnored, readProjectEnv } = require('./project-env');
5
+
6
+ function createStartProjectCommand(
7
+ apiRequest,
8
+ output,
9
+ resolveConnection,
10
+ stringFlag,
11
+ pullDeploymentSource,
12
+ projectWorkspaceDir,
13
+ persistConnection,
14
+ connectForStart
15
+ ) {
16
+ return async function startProjectCommand(rest, flags) {
17
+ const positionalProject = rest[0] || '';
18
+ const flaggedProject = stringFlag(flags, 'project');
19
+ if (positionalProject && flaggedProject && positionalProject !== flaggedProject) {
20
+ throw new Error('start positional project and --project must match');
21
+ }
22
+ const project = flaggedProject || positionalProject;
23
+ if (!project) throw new Error('start requires PROJECT');
24
+ if (rest.length > 1) throw new Error('start accepts exactly one PROJECT');
25
+ const requestedCwd = stringFlag(flags, 'cwd')
26
+ ? path.resolve(stringFlag(flags, 'cwd'))
27
+ : projectWorkspaceDir(flags);
28
+ const cwd = resolveProjectRoot(requestedCwd, 'git');
29
+ readProjectEnv(cwd);
30
+ if (fs.existsSync(path.join(cwd, '.env.joripspace'))) {
31
+ ensureProjectEnvIgnored(cwd);
32
+ }
33
+ const executable = path.resolve(
34
+ process.env.JORIPSPACE_CLI_EXECUTABLE ||
35
+ (process.pkg ? process.execPath : process.argv[1] || process.execPath)
36
+ );
37
+ const resolvedFlags = { ...flags, cwd };
38
+ let connection = resolveConnection(resolvedFlags);
39
+ if (!connection.apiToken) {
40
+ connection = connectForStart
41
+ ? await connectForStart(resolvedFlags, { cwd, executable, project })
42
+ : connection;
43
+ }
44
+ if (!connection?.apiToken) {
45
+ const apiUrlArgument = connection?.apiBaseUrl
46
+ ? ` --api-url ${quoteCliArgument(connection.apiBaseUrl)}`
47
+ : '';
48
48
  const invocation = `${!process.pkg && executable === path.resolve(process.argv[1] || '') ? quoteCliArgument(process.execPath) + ' ' : ''}${quoteCliArgument(executable)}`;
49
49
  const loginCommand = `${invocation} login --code "CONNECTION_CODE" --cwd ${quoteCliArgument(cwd)}${apiUrlArgument} --json`;
50
50
  const resumeCommand = `${invocation} start ${quoteCliArgument(project)} --cwd ${quoteCliArgument(cwd)} --json`;
51
- const value = {
52
- ok: false,
53
- status: 'connection_required',
54
- project,
55
- cwd,
56
- executable,
57
- connect_url: 'https://joripspace.com/connect/',
58
- message: '브라우저에서 연결을 승인하고 표시된 5분 일회용 연결 코드를 먼저 교환하세요.',
59
- login_command: loginCommand,
60
- resume_command: resumeCommand,
61
- next_action: 'run-login-command-then-resume-command',
51
+ const value = {
52
+ ok: false,
53
+ status: 'connection_required',
54
+ project,
55
+ cwd,
56
+ executable,
57
+ connect_url: 'https://joripspace.com/connect/',
58
+ message: '브라우저에서 연결을 승인하고 표시된 5분 일회용 연결 코드를 먼저 교환하세요.',
59
+ login_command: loginCommand,
60
+ resume_command: resumeCommand,
61
+ next_action: 'run-login-command-then-resume-command',
62
62
  continue_with: 'cli',
63
63
  onboarding: createStartOnboarding(executable, cwd, project, false, connection?.apiBaseUrl),
64
- };
65
- throw startCommandError(value.status, value.message, value);
66
- }
67
- const apiToken = connection.apiToken;
68
- const connectionFlags = {
69
- ...flags,
70
- cwd,
71
- 'api-token': connection.apiToken,
72
- 'api-url': connection.apiBaseUrl,
73
- };
74
-
75
- const value = await startProject({
76
- projectId: project,
77
- cwd,
78
- apiToken,
79
- apiRequest: (apiPath, options) => apiRequest(connectionFlags, apiPath, options),
80
- executable,
81
- allowLegacyCredentialSession: connection.source === 'legacy-project-session',
82
- beforeWorkspaceMigration: persistConnection
83
- ? () => persistConnection(resolvedFlags, connection)
84
- : undefined,
64
+ };
65
+ throw startCommandError(value.status, value.message, value);
66
+ }
67
+ const apiToken = connection.apiToken;
68
+ const connectionFlags = {
69
+ ...flags,
70
+ cwd,
71
+ 'api-token': connection.apiToken,
72
+ 'api-url': connection.apiBaseUrl,
73
+ };
74
+
75
+ const value = await startProject({
76
+ projectId: project,
77
+ cwd,
78
+ apiToken,
79
+ apiRequest: (apiPath, options) => apiRequest(connectionFlags, apiPath, options),
80
+ executable,
81
+ allowLegacyCredentialSession: connection.source === 'legacy-project-session',
82
+ beforeWorkspaceMigration: persistConnection
83
+ ? () => persistConnection(resolvedFlags, connection)
84
+ : undefined,
85
85
  }).catch((error) => {
86
86
  error.details = {
87
87
  ...error.details,
@@ -90,54 +90,54 @@ function createStartProjectCommand(
90
90
  throw error;
91
91
  });
92
92
  if (value.ok && value.context?.source_sync?.status === 'latest_deployment_restore_required') {
93
- const deploymentId = value.context.source_sync.deployment_id;
94
- const deploymentRestore = await pullDeploymentSource(
95
- { ...connectionFlags, project: value.project, deployment: deploymentId },
96
- { output: false, backupConflicts: true }
97
- );
98
- value.context.source_sync = {
99
- status: 'synchronized',
100
- operation: 'deployment_restore',
101
- deployment_id: deploymentId,
102
- restore: deploymentRestore.restore,
103
- };
104
- }
93
+ const deploymentId = value.context.source_sync.deployment_id;
94
+ const deploymentRestore = await pullDeploymentSource(
95
+ { ...connectionFlags, project: value.project, deployment: deploymentId },
96
+ { output: false, backupConflicts: true }
97
+ );
98
+ value.context.source_sync = {
99
+ status: 'synchronized',
100
+ operation: 'deployment_restore',
101
+ deployment_id: deploymentId,
102
+ restore: deploymentRestore.restore,
103
+ };
104
+ }
105
105
  if (!value.ok) {
106
106
  value.onboarding = createStartOnboarding(executable, cwd, project, false, connection.apiBaseUrl);
107
- throw startCommandError(
108
- value.status || 'start_incomplete',
109
- `JoripSpace start stopped: ${value.status || 'incomplete'}`,
110
- value
111
- );
112
- }
113
- output(flags, value, (result) => {
114
- console.log(`Started project: ${result.project}`);
115
- console.log(`CLI: ${result.executable}`);
116
- console.log('Session transport: CLI');
107
+ throw startCommandError(
108
+ value.status || 'start_incomplete',
109
+ `JoripSpace start stopped: ${value.status || 'incomplete'}`,
110
+ value
111
+ );
112
+ }
113
+ output(flags, value, (result) => {
114
+ console.log(`Started project: ${result.project}`);
115
+ console.log(`CLI: ${result.executable}`);
116
+ console.log('Session transport: CLI');
117
117
  console.log(`Next action: ${result.next_action}`);
118
118
  console.log('Read the project instructions now, even if your agent does not automatically load them:');
119
119
  for (const file of result.onboarding.read_files) console.log(file);
120
120
  console.log('Use --json for the inline guide and executable/argument objects for this session.');
121
- if (result.template_choice?.status === 'ready') {
122
- console.log(`Templates: ${result.template_choice.templates.length} available plus no-template option`);
123
- }
124
- if (result.context?.source_sync?.operation === 'deployment_restore') {
125
- console.log('Latest deployment source restored with conflict backups.');
126
- }
127
- });
128
- };
129
- }
130
-
131
- function startCommandError(code, message, details) {
132
- const error = new Error(message);
133
- error.code = code;
134
- error.exitCode = 2;
135
- error.details = details;
136
- return error;
137
- }
138
-
139
- function quoteCliArgument(value) {
140
- return `"${String(value).replace(/"/g, '\\"')}"`;
141
- }
142
-
143
- module.exports = { createStartProjectCommand };
121
+ if (result.template_choice?.status === 'ready') {
122
+ console.log(`Templates: ${result.template_choice.templates.length} available plus no-template option`);
123
+ }
124
+ if (result.context?.source_sync?.operation === 'deployment_restore') {
125
+ console.log('Latest deployment source restored with conflict backups.');
126
+ }
127
+ });
128
+ };
129
+ }
130
+
131
+ function startCommandError(code, message, details) {
132
+ const error = new Error(message);
133
+ error.code = code;
134
+ error.exitCode = 2;
135
+ error.details = details;
136
+ return error;
137
+ }
138
+
139
+ function quoteCliArgument(value) {
140
+ return `"${String(value).replace(/"/g, '\\"')}"`;
141
+ }
142
+
143
+ module.exports = { createStartProjectCommand };