instar 0.24.27 → 0.24.29

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 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAyPH,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAimCD,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CA4pGtE;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuD5E"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAyPH,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAimCD,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAurGtE;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuD5E"}
@@ -2227,19 +2227,34 @@ export async function startServer(options) {
2227
2227
  const ctxPath = path.join(tmpDir, `ctx-${channelId}-${Date.now()}.txt`);
2228
2228
  const history = slackAdapter.getChannelMessages(channelId, 30);
2229
2229
  const unansweredCount = slackAdapter.getUnansweredCount(channelId);
2230
- const contextData = JSON.stringify({
2231
- topicId: channelId,
2232
- channelName: channelId,
2233
- messages: history.map(m => ({
2234
- ts: m.ts,
2235
- sender: m.user,
2236
- senderId: m.user,
2237
- fromUser: true,
2238
- text: m.text,
2239
- })),
2240
- unansweredCount,
2241
- relayInstructions: `cat <<'EOF' | .claude/scripts/slack-reply.sh ${channelId}\nYour response text here\nEOF`,
2242
- }, null, 2);
2230
+ const botUserId = slackAdapter.getBotUserId?.() ?? null;
2231
+ // Build human-readable thread history (matches Telegram's context format)
2232
+ const lines = [];
2233
+ lines.push(`--- Thread History (last ${history.length} messages) ---`);
2234
+ lines.push('IMPORTANT: Read this history carefully before taking any action.');
2235
+ lines.push('Your task is to continue THIS conversation, not start something new.');
2236
+ lines.push(`Channel: ${channelId}`);
2237
+ lines.push('');
2238
+ for (const m of history) {
2239
+ const date = new Date(parseFloat(m.ts) * 1000);
2240
+ const time = date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
2241
+ const isBot = botUserId && m.user === botUserId;
2242
+ const label = isBot ? 'Agent' : (senderName || m.user);
2243
+ lines.push(`[${time}] ${label}: ${m.text}`);
2244
+ }
2245
+ lines.push('');
2246
+ lines.push('--- End Thread History ---');
2247
+ lines.push('');
2248
+ lines.push('CRITICAL: You MUST relay your response back to Slack after responding.');
2249
+ lines.push('Use the relay script:');
2250
+ lines.push('');
2251
+ lines.push(`cat <<'EOF' | .claude/scripts/slack-reply.sh ${channelId}`);
2252
+ lines.push('Your response text here');
2253
+ lines.push('EOF');
2254
+ lines.push('');
2255
+ lines.push('Strip the [slack:] prefix before interpreting the message.');
2256
+ lines.push('Only relay conversational text — not tool output or internal reasoning.');
2257
+ const contextData = lines.join('\n');
2243
2258
  fs.writeFileSync(ctxPath, contextData);
2244
2259
  // Transform [image:path] and [document:path] tags into explicit read instructions
2245
2260
  let transformedContent = message.content.replace(/\[image:([^\]]+)\]/g, (_, imagePath) => {
@@ -2265,21 +2280,32 @@ export async function startServer(options) {
2265
2280
  // Wait for Claude to be ready (handles race with recently spawned sessions)
2266
2281
  const ready = await sessionManager.waitForClaudeReady(existingSession, 15000);
2267
2282
  if (!ready) {
2268
- console.warn(`[slack→session] Session ${existingSession} not ready after 15s injecting anyway`);
2269
- }
2270
- // Use tmux send-keys to inject the message (same as Telegram's injection pattern)
2271
- try {
2272
- const { execSync } = await import('node:child_process');
2273
- // Write to a temp file and send via tmux to avoid escaping issues
2274
- const msgFile = path.join(tmpDir, `inject-${Date.now()}.txt`);
2275
- fs.writeFileSync(msgFile, bootstrapMessage);
2276
- execSync(`tmux send-keys -t '=${existingSession}:' "$(cat '${msgFile}')" Enter`, { timeout: 5000 });
2277
- fs.unlinkSync(msgFile);
2283
+ // Session is stuck (permissions prompt, tool hang, etc.)
2284
+ // Kill it and fall through to spawn a fresh session — never silently lose messages
2285
+ console.warn(`[slack→session] Session ${existingSession} not ready after 15s killing and respawning`);
2286
+ try {
2287
+ const stuckSession = sessionManager.listRunningSessions().find(s => s.tmuxSession === existingSession);
2288
+ if (stuckSession) {
2289
+ sessionManager.killSession(stuckSession.id);
2290
+ }
2291
+ }
2292
+ catch { /* ok if already dead */ }
2293
+ // Fall through to respawn below — registerChannelSession will be called with new session name
2278
2294
  }
2279
- catch (injectErr) {
2280
- console.error(`[slack→session] Injection failed: ${injectErr instanceof Error ? injectErr.message : injectErr}`);
2295
+ else {
2296
+ // Session is ready inject the message
2297
+ try {
2298
+ const { execSync } = await import('node:child_process');
2299
+ const msgFile = path.join(tmpDir, `inject-${Date.now()}.txt`);
2300
+ fs.writeFileSync(msgFile, bootstrapMessage);
2301
+ execSync(`tmux send-keys -t '=${existingSession}:' "$(cat '${msgFile}')" Enter`, { timeout: 5000 });
2302
+ fs.unlinkSync(msgFile);
2303
+ }
2304
+ catch (injectErr) {
2305
+ console.error(`[slack→session] Injection failed: ${injectErr instanceof Error ? injectErr.message : injectErr}`);
2306
+ }
2307
+ return;
2281
2308
  }
2282
- return;
2283
2309
  }
2284
2310
  console.log(`[slack→session] Session "${existingSession}" died, respawning...`);
2285
2311
  }
@@ -3210,6 +3236,7 @@ export async function startServer(options) {
3210
3236
  if (!entry.channelId)
3211
3237
  return;
3212
3238
  const syntheticId = slackChannelToSyntheticId(String(entry.channelId));
3239
+ console.log(`[slack-proxy] onMessageLogged: channel=${entry.channelId} syntheticId=${syntheticId} fromUser=${entry.fromUser} text="${(entry.text || '').slice(0, 40)}"`);
3213
3240
  presenceProxy.onMessageLogged({
3214
3241
  messageId: typeof entry.messageId === 'number' ? entry.messageId : parseInt(String(entry.messageId), 10) || 0,
3215
3242
  channelId: syntheticId.toString(),