@tsuzuku/arise 0.2.0 → 0.3.0

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/lib/config.js CHANGED
@@ -53,12 +53,19 @@ function findConfigFile(searchDirs = []) {
53
53
  return null;
54
54
  }
55
55
 
56
+ function stripJsonComments(str) {
57
+ return str
58
+ .replace(/\/\*[\s\S]*?\*\//g, '')
59
+ .replace(/\/\/.*$/gm, '')
60
+ .trim();
61
+ }
62
+
56
63
  function loadConfigFile(filePath) {
57
64
  if (!filePath) return {};
58
65
  try {
59
66
  if (filePath.endsWith('.json') || filePath.endsWith('.worktreerc') || filePath.endsWith('.ariserc')) {
60
67
  const content = fs.readFileSync(filePath, 'utf8');
61
- return JSON.parse(content);
68
+ return JSON.parse(stripJsonComments(content));
62
69
  } else {
63
70
  return require(path.resolve(filePath));
64
71
  }
@@ -68,8 +75,8 @@ function loadConfigFile(filePath) {
68
75
  }
69
76
  }
70
77
 
71
- function resolveConfiguration(flags = {}, cwd = process.cwd()) {
72
- const repoRoot = git.getRepoRootDir(cwd);
78
+ function resolveConfiguration(flags = {}, cwd = process.cwd(), callerCwd = null) {
79
+ const repoRoot = git.getRepoRootDir(cwd) || (callerCwd ? git.getRepoRootDir(callerCwd) : null);
73
80
  const isBare = git.isBareRepo(repoRoot);
74
81
  const searchDirs = [];
75
82
 
@@ -102,10 +109,15 @@ function resolveConfiguration(flags = {}, cwd = process.cwd()) {
102
109
  addSearchDir(branchDir);
103
110
  }
104
111
 
105
- // 3. Current working directory
112
+ // 3. Target working directory
106
113
  addSearchDir(cwd);
107
114
 
108
- // 4. Repository root directory
115
+ // 4. Fallback working directory (caller working directory)
116
+ if (callerCwd) {
117
+ addSearchDir(callerCwd);
118
+ }
119
+
120
+ // 5. Repository root directory
109
121
  if (repoRoot) {
110
122
  addSearchDir(repoRoot);
111
123
  if (isBare) {
@@ -113,7 +125,7 @@ function resolveConfiguration(flags = {}, cwd = process.cwd()) {
113
125
  }
114
126
  }
115
127
 
116
- // 5. Fallback to existing worktrees (prioritizing primary branches like main, master, develop)
128
+ // 6. Fallback to existing worktrees (prioritizing primary branches like main, master, develop)
117
129
  const primaryBranches = ['main', 'master', 'develop', 'prod', 'staging'];
118
130
  const primaryWts = worktrees.filter((wt) => !wt.isBare && wt.branch && primaryBranches.includes(wt.branch));
119
131
  for (const wt of primaryWts) {
package/lib/git.js CHANGED
@@ -12,6 +12,17 @@ function isBareRepo(repoPath) {
12
12
  }
13
13
  }
14
14
 
15
+ function getLocalBranches(options = {}) {
16
+ const gitCmd = getGitPrefix(options);
17
+ try {
18
+ const output = execSync(`${gitCmd} branch --format="%(refname:short)"`, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
19
+ if (!output) return [];
20
+ return output.split('\n').map(b => b.trim()).filter(Boolean);
21
+ } catch (err) {
22
+ return [];
23
+ }
24
+ }
25
+
15
26
  function getGitPrefix(options = {}) {
16
27
  if (options.bareRepo) {
17
28
  return `git --git-dir="${options.bareRepo}"`;
@@ -302,5 +313,6 @@ module.exports = {
302
313
  pruneWorktrees,
303
314
  deleteLocalBranch,
304
315
  deleteRemoteBranch,
316
+ getLocalBranches,
305
317
  isBareRepo,
306
318
  };
package/lib/herdr.js CHANGED
@@ -176,15 +176,50 @@ function runInPane(paneId, command) {
176
176
  }
177
177
  }
178
178
 
179
- function closeWorkspacesMatching(matchTargets = []) {
180
- const targets = matchTargets.filter(Boolean);
181
- if (!targets.length) return;
179
+ function listPanes() {
180
+ try {
181
+ const listOutput = execSync('herdr pane list', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
182
+ const data = parseJsonFromOutput(listOutput);
183
+ return (data && data.result && data.result.panes) || [];
184
+ } catch (err) {
185
+ return [];
186
+ }
187
+ }
188
+
189
+ function closeWorkspacesForWorktree(worktreePath, matchTargets = []) {
190
+ const matchedWorkspaceIds = new Set();
191
+ const normalizedPath = worktreePath ? path.resolve(worktreePath) : null;
182
192
 
193
+ // 1. Path-based matching via herdr pane list (highest fidelity, immune to prefix/label changes)
194
+ if (normalizedPath) {
195
+ const panes = listPanes();
196
+ for (const pane of panes) {
197
+ if (pane.workspace_id) {
198
+ const paneCwd = pane.cwd ? path.resolve(pane.cwd) : null;
199
+ const fgCwd = pane.foreground_cwd ? path.resolve(pane.foreground_cwd) : null;
200
+ if (
201
+ (paneCwd && (paneCwd === normalizedPath || paneCwd.startsWith(normalizedPath + path.sep))) ||
202
+ (fgCwd && (fgCwd === normalizedPath || fgCwd.startsWith(normalizedPath + path.sep)))
203
+ ) {
204
+ matchedWorkspaceIds.add(pane.workspace_id);
205
+ }
206
+ }
207
+ }
208
+ }
209
+
210
+ // 2. Exact label matching if matchTargets are provided
211
+ const targets = (Array.isArray(matchTargets) ? matchTargets : [matchTargets]).filter(Boolean);
183
212
  const workspaces = listWorkspaces();
184
- const matchingWorkspaces = workspaces.filter(w => targets.includes(w.label));
213
+ if (targets.length > 0) {
214
+ for (const ws of workspaces) {
215
+ if (ws.label && targets.includes(ws.label)) {
216
+ matchedWorkspaceIds.add(ws.workspace_id);
217
+ }
218
+ }
219
+ }
185
220
 
186
- for (const ws of matchingWorkspaces) {
187
- if (ws.workspace_id) {
221
+ for (const ws of workspaces) {
222
+ if (matchedWorkspaceIds.has(ws.workspace_id)) {
188
223
  console.log(`Closing Herdr workspace "${ws.label}" (ID: ${ws.workspace_id}) and terminating panes...`);
189
224
  closeWorkspace(ws.workspace_id);
190
225
  console.log(`Herdr workspace "${ws.label}" closed.`);
@@ -192,6 +227,10 @@ function closeWorkspacesMatching(matchTargets = []) {
192
227
  }
193
228
  }
194
229
 
230
+ function closeWorkspacesMatching(matchTargets = [], worktreePath = null) {
231
+ return closeWorkspacesForWorktree(worktreePath, matchTargets);
232
+ }
233
+
195
234
  function attachOrSwitchSession(sessionName) {
196
235
  if (process.env.HERDR_ENV === '1') {
197
236
  console.log(`Already inside herdr. Workspace "${sessionName}" created and focused!`);
@@ -206,6 +245,7 @@ module.exports = {
206
245
  getRecommendedInstallCommand,
207
246
  ensureHerdrInstalled,
208
247
  listWorkspaces,
248
+ listPanes,
209
249
  createWorkspace,
210
250
  closeWorkspace,
211
251
  focusWorkspace,
@@ -213,5 +253,6 @@ module.exports = {
213
253
  renamePane,
214
254
  runInPane,
215
255
  closeWorkspacesMatching,
256
+ closeWorkspacesForWorktree,
216
257
  attachOrSwitchSession,
217
258
  };