@hasnaxyz/hook-checktasks 1.0.1 → 1.0.3

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/dist/cli.js CHANGED
@@ -59,7 +59,8 @@ function getSessionName(transcriptPath) {
59
59
  return null;
60
60
  try {
61
61
  const content = readFileSync(transcriptPath, "utf-8");
62
- let lastTitle = null;
62
+ let customTitle = null;
63
+ let slug = null;
63
64
  let searchStart = 0;
64
65
  while (true) {
65
66
  const titleIndex = content.indexOf('"custom-title"', searchStart);
@@ -73,12 +74,18 @@ function getSessionName(transcriptPath) {
73
74
  try {
74
75
  const entry = JSON.parse(line);
75
76
  if (entry.type === "custom-title" && entry.customTitle) {
76
- lastTitle = entry.customTitle;
77
+ customTitle = entry.customTitle;
77
78
  }
78
79
  } catch {}
79
80
  searchStart = titleIndex + 1;
80
81
  }
81
- return lastTitle;
82
+ if (!customTitle) {
83
+ const slugMatch = content.match(/"slug"\s*:\s*"([^"]+)"/);
84
+ if (slugMatch) {
85
+ slug = slugMatch[1];
86
+ }
87
+ }
88
+ return customTitle || slug;
82
89
  } catch {
83
90
  return null;
84
91
  }
@@ -140,20 +147,33 @@ function run() {
140
147
  if (hookInput?.transcript_path) {
141
148
  sessionName = getSessionName(hookInput.transcript_path);
142
149
  }
143
- const nameToCheck = sessionName || config.taskListId || "";
144
150
  const keywords = config.keywords || ["dev"];
145
- const matchesKeyword = keywords.some((keyword) => nameToCheck.toLowerCase().includes(keyword.toLowerCase()));
146
- if (!matchesKeyword && keywords.length > 0 && nameToCheck) {
147
- approve();
148
- }
151
+ const matchesKeywords = (name) => {
152
+ if (!name)
153
+ return false;
154
+ if (keywords.length === 0)
155
+ return true;
156
+ return keywords.some((keyword) => name.toLowerCase().includes(keyword.toLowerCase()));
157
+ };
149
158
  let listsToCheck = [];
150
159
  if (config.taskListId) {
160
+ const taskListMatches = matchesKeywords(config.taskListId);
161
+ const sessionMatches = matchesKeywords(sessionName);
162
+ if (keywords.length > 0 && !taskListMatches && !sessionMatches) {
163
+ approve();
164
+ }
151
165
  listsToCheck = [config.taskListId];
152
166
  } else {
153
167
  const projectLists = getProjectTaskLists(cwd);
154
168
  if (projectLists.length > 0) {
155
169
  if (keywords.length > 0) {
156
- listsToCheck = projectLists.filter((list) => keywords.some((keyword) => list.toLowerCase().includes(keyword.toLowerCase())));
170
+ const sessionMatches = matchesKeywords(sessionName);
171
+ const matchingLists = projectLists.filter((list) => matchesKeywords(list));
172
+ if (sessionMatches || matchingLists.length > 0) {
173
+ listsToCheck = matchingLists.length > 0 ? matchingLists : projectLists;
174
+ } else {
175
+ approve();
176
+ }
157
177
  } else {
158
178
  listsToCheck = projectLists;
159
179
  }
package/dist/hook.js CHANGED
@@ -55,7 +55,8 @@ function getSessionName(transcriptPath) {
55
55
  return null;
56
56
  try {
57
57
  const content = readFileSync(transcriptPath, "utf-8");
58
- let lastTitle = null;
58
+ let customTitle = null;
59
+ let slug = null;
59
60
  let searchStart = 0;
60
61
  while (true) {
61
62
  const titleIndex = content.indexOf('"custom-title"', searchStart);
@@ -69,12 +70,18 @@ function getSessionName(transcriptPath) {
69
70
  try {
70
71
  const entry = JSON.parse(line);
71
72
  if (entry.type === "custom-title" && entry.customTitle) {
72
- lastTitle = entry.customTitle;
73
+ customTitle = entry.customTitle;
73
74
  }
74
75
  } catch {}
75
76
  searchStart = titleIndex + 1;
76
77
  }
77
- return lastTitle;
78
+ if (!customTitle) {
79
+ const slugMatch = content.match(/"slug"\s*:\s*"([^"]+)"/);
80
+ if (slugMatch) {
81
+ slug = slugMatch[1];
82
+ }
83
+ }
84
+ return customTitle || slug;
78
85
  } catch {
79
86
  return null;
80
87
  }
@@ -136,20 +143,33 @@ function run() {
136
143
  if (hookInput?.transcript_path) {
137
144
  sessionName = getSessionName(hookInput.transcript_path);
138
145
  }
139
- const nameToCheck = sessionName || config.taskListId || "";
140
146
  const keywords = config.keywords || ["dev"];
141
- const matchesKeyword = keywords.some((keyword) => nameToCheck.toLowerCase().includes(keyword.toLowerCase()));
142
- if (!matchesKeyword && keywords.length > 0 && nameToCheck) {
143
- approve();
144
- }
147
+ const matchesKeywords = (name) => {
148
+ if (!name)
149
+ return false;
150
+ if (keywords.length === 0)
151
+ return true;
152
+ return keywords.some((keyword) => name.toLowerCase().includes(keyword.toLowerCase()));
153
+ };
145
154
  let listsToCheck = [];
146
155
  if (config.taskListId) {
156
+ const taskListMatches = matchesKeywords(config.taskListId);
157
+ const sessionMatches = matchesKeywords(sessionName);
158
+ if (keywords.length > 0 && !taskListMatches && !sessionMatches) {
159
+ approve();
160
+ }
147
161
  listsToCheck = [config.taskListId];
148
162
  } else {
149
163
  const projectLists = getProjectTaskLists(cwd);
150
164
  if (projectLists.length > 0) {
151
165
  if (keywords.length > 0) {
152
- listsToCheck = projectLists.filter((list) => keywords.some((keyword) => list.toLowerCase().includes(keyword.toLowerCase())));
166
+ const sessionMatches = matchesKeywords(sessionName);
167
+ const matchingLists = projectLists.filter((list) => matchesKeywords(list));
168
+ if (sessionMatches || matchingLists.length > 0) {
169
+ listsToCheck = matchingLists.length > 0 ? matchingLists : projectLists;
170
+ } else {
171
+ approve();
172
+ }
153
173
  } else {
154
174
  listsToCheck = projectLists;
155
175
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasnaxyz/hook-checktasks",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Claude Code hook that prevents stopping when there are pending tasks",
5
5
  "type": "module",
6
6
  "bin": {