@irvingdinh/porygon-z 0.1.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/LICENSE +21 -0
- package/README.md +162 -0
- package/dist/app.module.d.ts +2 -0
- package/dist/app.module.js +21 -0
- package/dist/app.module.js.map +1 -0
- package/dist/core/config/config.d.ts +13 -0
- package/dist/core/config/config.js +67 -0
- package/dist/core/config/config.js.map +1 -0
- package/dist/core/core.module.d.ts +2 -0
- package/dist/core/core.module.js +24 -0
- package/dist/core/core.module.js.map +1 -0
- package/dist/core/modules/config.module.d.ts +1 -0
- package/dist/core/modules/config.module.js +10 -0
- package/dist/core/modules/config.module.js.map +1 -0
- package/dist/core/modules/index.d.ts +1 -0
- package/dist/core/modules/index.js +6 -0
- package/dist/core/modules/index.js.map +1 -0
- package/dist/core/services/index.d.ts +2 -0
- package/dist/core/services/index.js +6 -0
- package/dist/core/services/index.js.map +1 -0
- package/dist/core/services/template.service.d.ts +7 -0
- package/dist/core/services/template.service.js +93 -0
- package/dist/core/services/template.service.js.map +1 -0
- package/dist/core/templates/slack/commands/command-cd-error-escape.handlebars +1 -0
- package/dist/core/templates/slack/commands/command-cd-error-not-found.handlebars +1 -0
- package/dist/core/templates/slack/commands/command-cd-ok.handlebars +1 -0
- package/dist/core/templates/slack/commands/command-cd-show.handlebars +1 -0
- package/dist/core/templates/slack/commands/command-kill-ok.handlebars +1 -0
- package/dist/core/templates/slack/commands/command-ll-error.handlebars +2 -0
- package/dist/core/templates/slack/commands/command-ll-ok.handlebars +1 -0
- package/dist/core/templates/slack/commands/command-sh-error-usage.handlebars +1 -0
- package/dist/core/templates/slack/commands/command-workspace-ok-created.handlebars +9 -0
- package/dist/core/templates/slack/commands/command-workspace-ok.handlebars +7 -0
- package/dist/core/templates/slack/listeners/listener-message-attachments.handlebars +13 -0
- package/dist/core/templates/slack/listeners/listener-message-error.handlebars +1 -0
- package/dist/core/templates/slack/listeners/listener-message-follow-up-prompt.handlebars +26 -0
- package/dist/core/templates/slack/listeners/listener-message-session-corrupted.handlebars +1 -0
- package/dist/core/templates/slack/listeners/listener-message-session-expired.handlebars +1 -0
- package/dist/core/templates/slack/listeners/listener-message-system-prompt.handlebars +79 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +11 -0
- package/dist/main.js.map +1 -0
- package/dist/slack/services/attachment.service.d.ts +23 -0
- package/dist/slack/services/attachment.service.js +113 -0
- package/dist/slack/services/attachment.service.js.map +1 -0
- package/dist/slack/services/bot.service.d.ts +16 -0
- package/dist/slack/services/bot.service.js +61 -0
- package/dist/slack/services/bot.service.js.map +1 -0
- package/dist/slack/services/claude-formatter.service.d.ts +9 -0
- package/dist/slack/services/claude-formatter.service.js +116 -0
- package/dist/slack/services/claude-formatter.service.js.map +1 -0
- package/dist/slack/services/claude.service.d.ts +48 -0
- package/dist/slack/services/claude.service.js +97 -0
- package/dist/slack/services/claude.service.js.map +1 -0
- package/dist/slack/services/commands/command-cd.service.d.ts +12 -0
- package/dist/slack/services/commands/command-cd.service.js +88 -0
- package/dist/slack/services/commands/command-cd.service.js.map +1 -0
- package/dist/slack/services/commands/command-kill.service.d.ts +12 -0
- package/dist/slack/services/commands/command-kill.service.js +40 -0
- package/dist/slack/services/commands/command-kill.service.js.map +1 -0
- package/dist/slack/services/commands/command-ll.service.d.ts +12 -0
- package/dist/slack/services/commands/command-ll.service.js +52 -0
- package/dist/slack/services/commands/command-ll.service.js.map +1 -0
- package/dist/slack/services/commands/command-sh.service.d.ts +10 -0
- package/dist/slack/services/commands/command-sh.service.js +38 -0
- package/dist/slack/services/commands/command-sh.service.js.map +1 -0
- package/dist/slack/services/commands/command-workspace.service.d.ts +15 -0
- package/dist/slack/services/commands/command-workspace.service.js +302 -0
- package/dist/slack/services/commands/command-workspace.service.js.map +1 -0
- package/dist/slack/services/commands/index.d.ts +13 -0
- package/dist/slack/services/commands/index.js +26 -0
- package/dist/slack/services/commands/index.js.map +1 -0
- package/dist/slack/services/commands/registry.service.d.ts +13 -0
- package/dist/slack/services/commands/registry.service.js +38 -0
- package/dist/slack/services/commands/registry.service.js.map +1 -0
- package/dist/slack/services/index.d.ts +15 -0
- package/dist/slack/services/index.js +22 -0
- package/dist/slack/services/index.js.map +1 -0
- package/dist/slack/services/listeners/index.d.ts +9 -0
- package/dist/slack/services/listeners/index.js +16 -0
- package/dist/slack/services/listeners/index.js.map +1 -0
- package/dist/slack/services/listeners/listener-message.service.d.ts +28 -0
- package/dist/slack/services/listeners/listener-message.service.js +297 -0
- package/dist/slack/services/listeners/listener-message.service.js.map +1 -0
- package/dist/slack/services/listeners/registry.service.d.ts +13 -0
- package/dist/slack/services/listeners/registry.service.js +38 -0
- package/dist/slack/services/listeners/registry.service.js.map +1 -0
- package/dist/slack/services/thread.service.d.ts +22 -0
- package/dist/slack/services/thread.service.js +125 -0
- package/dist/slack/services/thread.service.js.map +1 -0
- package/dist/slack/services/workspace.service.d.ts +21 -0
- package/dist/slack/services/workspace.service.js +98 -0
- package/dist/slack/services/workspace.service.js.map +1 -0
- package/dist/slack/slack.module.d.ts +2 -0
- package/dist/slack/slack.module.js +23 -0
- package/dist/slack/slack.module.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
You received a new message from a user via Slack. Your response will be posted back to the same Slack thread by the Porygon-Z bot. Read and follow the instructions below, then process the user's message at the end of this prompt.
|
|
2
|
+
|
|
3
|
+
## Execution Mode
|
|
4
|
+
|
|
5
|
+
You are running in non-interactive mode via `--print`. You cannot pause mid-execution to ask questions or wait for input.
|
|
6
|
+
- If you need user input or approval before proceeding, clearly state what you need and *end your response*. The user will reply in a follow-up message and you will be resumed with full conversation context.
|
|
7
|
+
- Do NOT use interactive tools such as `AskUserQuestion`. They are unavailable in this execution mode.
|
|
8
|
+
- Do NOT use the `EnterPlanMode` or `ExitPlanMode` tools — they are not compatible with this execution mode.
|
|
9
|
+
|
|
10
|
+
### Planning
|
|
11
|
+
|
|
12
|
+
For non-trivial tasks — those requiring code changes across multiple files, multi-step operations, or architectural decisions — you MUST plan before executing:
|
|
13
|
+
1. Analyze the request and present a concise plan as text in your response, describing what you intend to do and why.
|
|
14
|
+
2. End your response after presenting the plan. Do NOT begin execution.
|
|
15
|
+
3. The user will approve, adjust, or reject the plan via a follow-up message. You will be resumed with full context.
|
|
16
|
+
4. Once approved, execute the plan.
|
|
17
|
+
|
|
18
|
+
Skip planning and execute immediately for simple tasks: answering questions, reading files, single-file edits with obvious intent, running a single command, or lookups.
|
|
19
|
+
|
|
20
|
+
## Output Format
|
|
21
|
+
|
|
22
|
+
Your text output will be posted directly as a Slack message. Use Slack mrkdwn formatting:
|
|
23
|
+
- *bold* text with `*asterisks*`
|
|
24
|
+
- _italic_ text with `_underscores_`
|
|
25
|
+
- `inline code` with single backticks
|
|
26
|
+
- Code blocks with triple backticks (no language tag — Slack does not support syntax highlighting; a language name after the backticks renders as visible text)
|
|
27
|
+
- > block quotes with `>`
|
|
28
|
+
|
|
29
|
+
DO NOT use standard Markdown syntax — it renders as raw text in Slack:
|
|
30
|
+
- No `[text](url)` links — use raw URLs or Slack's `<url|display text>` format
|
|
31
|
+
- No `# heading` syntax — use *bold text* on its own line instead
|
|
32
|
+
- No `` image embeds
|
|
33
|
+
- No HTML tags (`<b>`, `<i>`, `<a>`, etc.)
|
|
34
|
+
|
|
35
|
+
Keep messages under 4000 characters when possible. Slack supports up to 40,000 characters but long messages are difficult to read in a chat interface.
|
|
36
|
+
|
|
37
|
+
## Safety
|
|
38
|
+
|
|
39
|
+
You are running with `--dangerously-skip-permissions`. All tool permissions are bypassed.
|
|
40
|
+
|
|
41
|
+
Before performing any dangerous or destructive action (e.g., deleting files, force-pushing, dropping databases, modifying production configs, running irreversible commands), you MUST:
|
|
42
|
+
1. Clearly describe what you are about to do and why it is dangerous.
|
|
43
|
+
2. Check the earlier conversation history for an explicit approval from the user (e.g., "yes", "go ahead", "approved").
|
|
44
|
+
3. If no prior approval exists, *end your response immediately* and ask the user to approve in a follow-up message. Do NOT proceed with the dangerous action — you will be resumed once they reply.
|
|
45
|
+
|
|
46
|
+
Stay within the current working directory unless the user explicitly asks you to operate elsewhere. Do not read, modify, or delete files outside the working directory without explicit instruction.
|
|
47
|
+
|
|
48
|
+
Do not send, upload, or transmit workspace content to external services, URLs, or APIs unless the user explicitly requests it.
|
|
49
|
+
|
|
50
|
+
## Response Guidelines
|
|
51
|
+
|
|
52
|
+
- Lead with the answer or conclusion. Put supporting details after.
|
|
53
|
+
- Keep your Slack reply concise. If your output would exceed ~4000 characters, write the detailed content to the upload directory (see below) and summarize in your message with a reference to the file.
|
|
54
|
+
- When you produce files (reports, diffs, generated code, configs), write them to the upload directory rather than pasting full contents inline.
|
|
55
|
+
|
|
56
|
+
{{#if workspacePrompt}}
|
|
57
|
+
## Workspace Instructions
|
|
58
|
+
|
|
59
|
+
{{{workspacePrompt}}}
|
|
60
|
+
|
|
61
|
+
{{/if}}
|
|
62
|
+
## Attachments
|
|
63
|
+
|
|
64
|
+
{{#if attachmentsSection}}
|
|
65
|
+
### Inbound
|
|
66
|
+
|
|
67
|
+
{{{attachmentsSection}}}
|
|
68
|
+
|
|
69
|
+
{{/if}}
|
|
70
|
+
### Outbound
|
|
71
|
+
|
|
72
|
+
If you want to share files with the user, write them to: {{uploadDir}}
|
|
73
|
+
The bot will automatically upload anything placed in that directory after you finish.
|
|
74
|
+
|
|
75
|
+
## User's Message
|
|
76
|
+
|
|
77
|
+
<UserMessage>
|
|
78
|
+
{{userMessage}}
|
|
79
|
+
</UserMessage>
|
package/dist/main.d.ts
ADDED
package/dist/main.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const core_1 = require("@nestjs/core");
|
|
5
|
+
const app_module_1 = require("./app.module");
|
|
6
|
+
async function bootstrap() {
|
|
7
|
+
const app = await core_1.NestFactory.create(app_module_1.AppModule);
|
|
8
|
+
await app.listen(0);
|
|
9
|
+
}
|
|
10
|
+
void bootstrap();
|
|
11
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;AACA,uCAA2C;AAE3C,6CAAyC;AAEzC,KAAK,UAAU,SAAS;IACtB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,sBAAS,CAAC,CAAC;IAChD,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACtB,CAAC;AAED,KAAK,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import { TemplateService } from '../../core/services/template.service';
|
|
3
|
+
export interface SlackFile {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
url_private_download: string;
|
|
7
|
+
mimetype?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface DownloadedAttachment {
|
|
10
|
+
originalName: string;
|
|
11
|
+
savedName: string;
|
|
12
|
+
path: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class AttachmentService {
|
|
15
|
+
private readonly configService;
|
|
16
|
+
private readonly template;
|
|
17
|
+
private readonly logger;
|
|
18
|
+
private readonly botToken;
|
|
19
|
+
constructor(configService: ConfigService, template: TemplateService);
|
|
20
|
+
download(files: SlackFile[], destDir: string): Promise<DownloadedAttachment[]>;
|
|
21
|
+
buildPromptSection(attachments: DownloadedAttachment[], attachmentsDirPath: string): string;
|
|
22
|
+
private buildSafeName;
|
|
23
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var AttachmentService_1;
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.AttachmentService = void 0;
|
|
47
|
+
const fs = __importStar(require("node:fs"));
|
|
48
|
+
const path = __importStar(require("node:path"));
|
|
49
|
+
const common_1 = require("@nestjs/common");
|
|
50
|
+
const config_1 = require("@nestjs/config");
|
|
51
|
+
const template_service_1 = require("../../core/services/template.service");
|
|
52
|
+
let AttachmentService = AttachmentService_1 = class AttachmentService {
|
|
53
|
+
configService;
|
|
54
|
+
template;
|
|
55
|
+
logger = new common_1.Logger(AttachmentService_1.name);
|
|
56
|
+
botToken;
|
|
57
|
+
constructor(configService, template) {
|
|
58
|
+
this.configService = configService;
|
|
59
|
+
this.template = template;
|
|
60
|
+
const config = this.configService.get('root');
|
|
61
|
+
this.botToken = config.slack.botToken;
|
|
62
|
+
}
|
|
63
|
+
async download(files, destDir) {
|
|
64
|
+
const results = [];
|
|
65
|
+
for (const file of files) {
|
|
66
|
+
const savedName = this.buildSafeName(destDir, file.name);
|
|
67
|
+
const destPath = path.join(destDir, savedName);
|
|
68
|
+
const res = await fetch(file.url_private_download, {
|
|
69
|
+
headers: { Authorization: `Bearer ${this.botToken}` },
|
|
70
|
+
});
|
|
71
|
+
if (!res.ok) {
|
|
72
|
+
this.logger.error(`Failed to download ${file.name}: ${res.status} ${res.statusText}`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const buffer = Buffer.from(await res.arrayBuffer());
|
|
76
|
+
fs.writeFileSync(destPath, buffer);
|
|
77
|
+
this.logger.log(`Downloaded ${file.name} -> ${savedName} (${buffer.byteLength} bytes)`);
|
|
78
|
+
results.push({
|
|
79
|
+
originalName: file.name,
|
|
80
|
+
savedName,
|
|
81
|
+
path: destPath,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
86
|
+
buildPromptSection(attachments, attachmentsDirPath) {
|
|
87
|
+
return this.template.render('slack.listeners.listener-message-attachments', {
|
|
88
|
+
attachments: attachments.map((a) => ({
|
|
89
|
+
...a,
|
|
90
|
+
renamed: a.originalName !== a.savedName,
|
|
91
|
+
})),
|
|
92
|
+
attachmentsDirPath,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
buildSafeName(dir, name) {
|
|
96
|
+
const ext = path.extname(name);
|
|
97
|
+
const base = name.slice(0, name.length - ext.length);
|
|
98
|
+
let candidate = name;
|
|
99
|
+
let counter = 2;
|
|
100
|
+
while (fs.existsSync(path.join(dir, candidate))) {
|
|
101
|
+
candidate = `${base}_${counter}${ext}`;
|
|
102
|
+
counter++;
|
|
103
|
+
}
|
|
104
|
+
return candidate;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
exports.AttachmentService = AttachmentService;
|
|
108
|
+
exports.AttachmentService = AttachmentService = AttachmentService_1 = __decorate([
|
|
109
|
+
(0, common_1.Injectable)(),
|
|
110
|
+
__metadata("design:paramtypes", [config_1.ConfigService,
|
|
111
|
+
template_service_1.TemplateService])
|
|
112
|
+
], AttachmentService);
|
|
113
|
+
//# sourceMappingURL=attachment.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment.service.js","sourceRoot":"","sources":["../../../src/slack/services/attachment.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,2CAAoD;AACpD,2CAA+C;AAG/C,2EAAuE;AAoBhE,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAKT;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16 @@
|
|
|
1
|
+
import { OnApplicationBootstrap, OnApplicationShutdown } from '@nestjs/common';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { CommandWorkspaceService } from './commands/command-workspace.service';
|
|
4
|
+
import { RegistryService as CommandRegistryService } from './commands/registry.service';
|
|
5
|
+
import { RegistryService as ListenerRegistryService } from './listeners/registry.service';
|
|
6
|
+
export declare class BotService implements OnApplicationBootstrap, OnApplicationShutdown {
|
|
7
|
+
private readonly configService;
|
|
8
|
+
private readonly commandRegistry;
|
|
9
|
+
private readonly listenerRegistry;
|
|
10
|
+
private readonly commandWorkspace;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
private app;
|
|
13
|
+
constructor(configService: ConfigService, commandRegistry: CommandRegistryService, listenerRegistry: ListenerRegistryService, commandWorkspace: CommandWorkspaceService);
|
|
14
|
+
onApplicationBootstrap(): Promise<void>;
|
|
15
|
+
onApplicationShutdown(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var BotService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.BotService = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const config_1 = require("@nestjs/config");
|
|
16
|
+
const bolt_1 = require("@slack/bolt");
|
|
17
|
+
const command_workspace_service_1 = require("./commands/command-workspace.service");
|
|
18
|
+
const registry_service_1 = require("./commands/registry.service");
|
|
19
|
+
const registry_service_2 = require("./listeners/registry.service");
|
|
20
|
+
let BotService = BotService_1 = class BotService {
|
|
21
|
+
configService;
|
|
22
|
+
commandRegistry;
|
|
23
|
+
listenerRegistry;
|
|
24
|
+
commandWorkspace;
|
|
25
|
+
logger = new common_1.Logger(BotService_1.name);
|
|
26
|
+
app;
|
|
27
|
+
constructor(configService, commandRegistry, listenerRegistry, commandWorkspace) {
|
|
28
|
+
this.configService = configService;
|
|
29
|
+
this.commandRegistry = commandRegistry;
|
|
30
|
+
this.listenerRegistry = listenerRegistry;
|
|
31
|
+
this.commandWorkspace = commandWorkspace;
|
|
32
|
+
}
|
|
33
|
+
async onApplicationBootstrap() {
|
|
34
|
+
const config = this.configService.get('root');
|
|
35
|
+
this.app = new bolt_1.App({
|
|
36
|
+
token: config.slack.botToken,
|
|
37
|
+
appToken: config.slack.appToken,
|
|
38
|
+
socketMode: true,
|
|
39
|
+
});
|
|
40
|
+
this.commandRegistry.registerAll(this.app);
|
|
41
|
+
this.listenerRegistry.registerAll(this.app);
|
|
42
|
+
this.app.view(this.commandWorkspace.callbackId, (args) => this.commandWorkspace.handleSubmission(args));
|
|
43
|
+
await this.app.start();
|
|
44
|
+
this.logger.log('Porygon-Z is running!');
|
|
45
|
+
}
|
|
46
|
+
async onApplicationShutdown() {
|
|
47
|
+
if (this.app) {
|
|
48
|
+
await this.app.stop();
|
|
49
|
+
this.logger.log('Porygon-Z stopped.');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.BotService = BotService;
|
|
54
|
+
exports.BotService = BotService = BotService_1 = __decorate([
|
|
55
|
+
(0, common_1.Injectable)(),
|
|
56
|
+
__metadata("design:paramtypes", [config_1.ConfigService,
|
|
57
|
+
registry_service_1.RegistryService,
|
|
58
|
+
registry_service_2.RegistryService,
|
|
59
|
+
command_workspace_service_1.CommandWorkspaceService])
|
|
60
|
+
], BotService);
|
|
61
|
+
//# sourceMappingURL=bot.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot.service.js","sourceRoot":"","sources":["../../../src/slack/services/bot.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAKwB;AACxB,2CAA+C;AAC/C,sCAAkC;AAGlC,oFAA+E;AAC/E,kEAAwF;AACxF,mEAA0F;AAGnF,IAAM,UAAU,kBAAhB,MAAM,UAAU;IAOF;IACA;IACA;IACA;IAPF,MAAM,GAAG,IAAI,eAAM,CAAC,YAAU,CAAC,IAAI,CAAC,CAAC;IAC9C,GAAG,CAAO;IAElB,YACmB,aAA4B,EAC5B,eAAuC,EACvC,gBAAyC,EACzC,gBAAyC;QAHzC,kBAAa,GAAb,aAAa,CAAe;QAC5B,oBAAe,GAAf,eAAe,CAAwB;QACvC,qBAAgB,GAAhB,gBAAgB,CAAyB;QACzC,qBAAgB,GAAhB,gBAAgB,CAAyB;IACzD,CAAC;IAEJ,KAAK,CAAC,sBAAsB;QAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAY,MAAM,CAAE,CAAC;QAE1D,IAAI,CAAC,GAAG,GAAG,IAAI,UAAG,CAAC;YACjB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ;YAC5B,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ;YAC/B,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE5C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CACvD,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAC7C,CAAC;QAEF,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACtB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF,CAAA;AAvCY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;qCAQuB,sBAAa;QACX,kCAAsB;QACrB,kCAAuB;QACvB,mDAAuB;GAVjD,UAAU,CAuCtB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ContentBlock } from './claude.service';
|
|
2
|
+
export declare class ClaudeFormatterService {
|
|
3
|
+
formatStreaming(blocks: ContentBlock[], activeToolName?: string): string;
|
|
4
|
+
formatFinal(resultText: string): string;
|
|
5
|
+
private formatBlock;
|
|
6
|
+
private summarizeToolInput;
|
|
7
|
+
private truncate;
|
|
8
|
+
private quoteLines;
|
|
9
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ClaudeFormatterService = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const MAX_MESSAGE_LENGTH = 3800;
|
|
12
|
+
const MAX_BLOCKS_SHOWN = 8;
|
|
13
|
+
let ClaudeFormatterService = class ClaudeFormatterService {
|
|
14
|
+
formatStreaming(blocks, activeToolName) {
|
|
15
|
+
const recentBlocks = blocks.slice(-MAX_BLOCKS_SHOWN);
|
|
16
|
+
const skipped = blocks.length - recentBlocks.length;
|
|
17
|
+
const parts = [];
|
|
18
|
+
if (skipped > 0) {
|
|
19
|
+
parts.push(`_...${skipped} earlier steps hidden..._`);
|
|
20
|
+
}
|
|
21
|
+
parts.push(...recentBlocks.map((b) => this.formatBlock(b)).filter(Boolean));
|
|
22
|
+
if (activeToolName) {
|
|
23
|
+
parts.push(`> :hourglass: _Running \`${activeToolName}\`..._`);
|
|
24
|
+
}
|
|
25
|
+
const joined = parts.join('\n\n');
|
|
26
|
+
return this.truncate(joined, MAX_MESSAGE_LENGTH);
|
|
27
|
+
}
|
|
28
|
+
formatFinal(resultText) {
|
|
29
|
+
return resultText || '';
|
|
30
|
+
}
|
|
31
|
+
formatBlock(block) {
|
|
32
|
+
switch (block.type) {
|
|
33
|
+
case 'thinking': {
|
|
34
|
+
const snippet = this.truncate(block.thinking.trim(), 200);
|
|
35
|
+
return `> :brain: *Thinking*\n${this.quoteLines(snippet)}`;
|
|
36
|
+
}
|
|
37
|
+
case 'tool_use': {
|
|
38
|
+
const summary = this.summarizeToolInput(block.name, block.input);
|
|
39
|
+
const detail = summary ? `\n> ${summary}` : '';
|
|
40
|
+
return `> :hammer_and_wrench: *${block.name}*${detail}`;
|
|
41
|
+
}
|
|
42
|
+
case 'tool_result': {
|
|
43
|
+
const raw = typeof block.content === 'string'
|
|
44
|
+
? block.content
|
|
45
|
+
: block.content
|
|
46
|
+
.map((c) => c.text ?? '')
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.join('\n');
|
|
49
|
+
const snippet = this.truncate(raw.trim(), 200);
|
|
50
|
+
return `> :white_check_mark: *Tool result*\n${this.quoteLines(snippet)}`;
|
|
51
|
+
}
|
|
52
|
+
case 'text': {
|
|
53
|
+
const t = block.text.trim();
|
|
54
|
+
if (!t)
|
|
55
|
+
return '';
|
|
56
|
+
return this.truncate(t, 1500);
|
|
57
|
+
}
|
|
58
|
+
default:
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
summarizeToolInput(name, input) {
|
|
63
|
+
switch (name) {
|
|
64
|
+
case 'Bash': {
|
|
65
|
+
const cmd = typeof input.command === 'string' ? input.command : '';
|
|
66
|
+
return `\`${this.truncate(cmd, 120)}\``;
|
|
67
|
+
}
|
|
68
|
+
case 'Read':
|
|
69
|
+
case 'Write':
|
|
70
|
+
case 'Edit': {
|
|
71
|
+
const filePath = typeof input.file_path === 'string' ? input.file_path : '';
|
|
72
|
+
return `\`${filePath}\``;
|
|
73
|
+
}
|
|
74
|
+
case 'Glob':
|
|
75
|
+
case 'Grep': {
|
|
76
|
+
const pattern = typeof input.pattern === 'string' ? input.pattern : '';
|
|
77
|
+
return `\`${pattern}\``;
|
|
78
|
+
}
|
|
79
|
+
case 'WebFetch':
|
|
80
|
+
case 'WebSearch': {
|
|
81
|
+
const url = typeof input.url === 'string'
|
|
82
|
+
? input.url
|
|
83
|
+
: typeof input.query === 'string'
|
|
84
|
+
? input.query
|
|
85
|
+
: '';
|
|
86
|
+
return this.truncate(url, 120);
|
|
87
|
+
}
|
|
88
|
+
case 'Agent': {
|
|
89
|
+
const desc = typeof input.description === 'string' ? input.description : '';
|
|
90
|
+
return desc ? `_${desc}_` : '';
|
|
91
|
+
}
|
|
92
|
+
case 'TodoWrite':
|
|
93
|
+
return '';
|
|
94
|
+
default: {
|
|
95
|
+
const raw = JSON.stringify(input);
|
|
96
|
+
return raw.length > 2 ? `\`${this.truncate(raw, 100)}\`` : '';
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
truncate(text, maxLen) {
|
|
101
|
+
if (text.length <= maxLen)
|
|
102
|
+
return text;
|
|
103
|
+
return text.slice(0, maxLen) + '...';
|
|
104
|
+
}
|
|
105
|
+
quoteLines(text) {
|
|
106
|
+
return text
|
|
107
|
+
.split('\n')
|
|
108
|
+
.map((line) => `> ${line}`)
|
|
109
|
+
.join('\n');
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
exports.ClaudeFormatterService = ClaudeFormatterService;
|
|
113
|
+
exports.ClaudeFormatterService = ClaudeFormatterService = __decorate([
|
|
114
|
+
(0, common_1.Injectable)()
|
|
115
|
+
], ClaudeFormatterService);
|
|
116
|
+
//# sourceMappingURL=claude-formatter.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-formatter.service.js","sourceRoot":"","sources":["../../../src/slack/services/claude-formatter.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAI5C,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAGpB,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,eAAe,CAAC,MAAsB,EAAE,cAAuB;QAC7D,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAC,CAAC;QACrD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC;QAEpD,MAAM,KAAK,GAAa,EAAE,CAAC;QAE3B,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YAChB,KAAK,CAAC,IAAI,CAAC,OAAO,OAAO,2BAA2B,CAAC,CAAC;QACxD,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,GAAG,YAAY,C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AAI,CAAC,MAAM,IAAI,MAAM;YAAE,OAAO,IAAI,CAAC;QACvC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;IACvC,CAAC;IAEO,UAAU,CAAC,IAAY;QAC7B,OAAO,IAAI;aACR,KAAK,CAAC,IAAI,CAAC;aACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC;aAC1B,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;CACF,CAAA;AAvHY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;GACA,sBAAsB,CAuHlC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { OnApplicationShutdown } from '@nestjs/common';
|
|
2
|
+
import type { EffortLevel, PermissionMode } from './workspace.service';
|
|
3
|
+
export interface ThinkingBlock {
|
|
4
|
+
type: 'thinking';
|
|
5
|
+
thinking: string;
|
|
6
|
+
}
|
|
7
|
+
export interface TextBlock {
|
|
8
|
+
type: 'text';
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ToolUseBlock {
|
|
12
|
+
type: 'tool_use';
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
input: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
export interface ToolResultBlock {
|
|
18
|
+
type: 'tool_result';
|
|
19
|
+
tool_use_id: string;
|
|
20
|
+
content: string | Array<{
|
|
21
|
+
type: string;
|
|
22
|
+
text?: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
export type ContentBlock = ThinkingBlock | TextBlock | ToolUseBlock | ToolResultBlock;
|
|
26
|
+
export interface StreamEvent {
|
|
27
|
+
type: string;
|
|
28
|
+
subtype?: string;
|
|
29
|
+
session_id?: string;
|
|
30
|
+
message?: {
|
|
31
|
+
content: ContentBlock[];
|
|
32
|
+
};
|
|
33
|
+
result?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare class ClaudeService implements OnApplicationShutdown {
|
|
36
|
+
private readonly logger;
|
|
37
|
+
private readonly processes;
|
|
38
|
+
onApplicationShutdown(): void;
|
|
39
|
+
run(options: {
|
|
40
|
+
prompt: string;
|
|
41
|
+
cwd: string;
|
|
42
|
+
resumeSessionId?: string;
|
|
43
|
+
model?: string;
|
|
44
|
+
effort?: EffortLevel;
|
|
45
|
+
permissionMode?: PermissionMode;
|
|
46
|
+
}): AsyncGenerator<StreamEvent>;
|
|
47
|
+
killAll(): number;
|
|
48
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var ClaudeService_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ClaudeService = void 0;
|
|
11
|
+
const node_child_process_1 = require("node:child_process");
|
|
12
|
+
const node_readline_1 = require("node:readline");
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
let ClaudeService = ClaudeService_1 = class ClaudeService {
|
|
15
|
+
logger = new common_1.Logger(ClaudeService_1.name);
|
|
16
|
+
processes = new Set();
|
|
17
|
+
onApplicationShutdown() {
|
|
18
|
+
this.killAll();
|
|
19
|
+
}
|
|
20
|
+
async *run(options) {
|
|
21
|
+
const model = options.model ?? 'opus[1m]';
|
|
22
|
+
const effort = options.effort ?? 'max';
|
|
23
|
+
const permissionMode = options.permissionMode ?? 'bypassPermissions';
|
|
24
|
+
this.logger.log(`Spawning process, cwd: ${options.cwd}, prompt length: ${options.prompt.length}, resume: ${options.resumeSessionId ?? 'none'}, model: ${model}, effort: ${effort}, permission: ${permissionMode}`);
|
|
25
|
+
const args = [];
|
|
26
|
+
if (options.resumeSessionId) {
|
|
27
|
+
args.push('--resume', options.resumeSessionId);
|
|
28
|
+
}
|
|
29
|
+
args.push('--print', '--output-format', 'stream-json', '--verbose');
|
|
30
|
+
if (permissionMode === 'bypassPermissions') {
|
|
31
|
+
args.push('--dangerously-skip-permissions');
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
args.push('--permission-mode', permissionMode);
|
|
35
|
+
}
|
|
36
|
+
args.push('--model', model, '--effort', effort);
|
|
37
|
+
const proc = (0, node_child_process_1.spawn)('claude', args, {
|
|
38
|
+
cwd: options.cwd,
|
|
39
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
40
|
+
});
|
|
41
|
+
this.logger.log(`Process started, pid: ${proc.pid}`);
|
|
42
|
+
this.processes.add(proc);
|
|
43
|
+
proc.on('exit', (code) => {
|
|
44
|
+
this.logger.log(`Process ${proc.pid} exited with code: ${code}`);
|
|
45
|
+
this.processes.delete(proc);
|
|
46
|
+
});
|
|
47
|
+
if (proc.stderr) {
|
|
48
|
+
proc.stderr.on('data', (chunk) => {
|
|
49
|
+
const text = chunk.toString().trim();
|
|
50
|
+
if (text) {
|
|
51
|
+
this.logger.warn(`[stderr:${proc.pid}] ${text}`);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
proc.stdin.write(options.prompt);
|
|
56
|
+
proc.stdin.end();
|
|
57
|
+
const rl = (0, node_readline_1.createInterface)({ input: proc.stdout });
|
|
58
|
+
try {
|
|
59
|
+
for await (const line of rl) {
|
|
60
|
+
if (line.trim() === '')
|
|
61
|
+
continue;
|
|
62
|
+
try {
|
|
63
|
+
const event = JSON.parse(line);
|
|
64
|
+
this.logger.debug(`[stdout:${proc.pid}] type=${event.type} subtype=${event.subtype ?? '-'}`);
|
|
65
|
+
yield event;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
this.logger.debug(`[stdout:${proc.pid}] (unparseable) ${line.slice(0, 200)}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
await new Promise((resolve) => {
|
|
74
|
+
if (proc.exitCode !== null) {
|
|
75
|
+
resolve();
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
proc.on('exit', () => resolve());
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
this.processes.delete(proc);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
killAll() {
|
|
85
|
+
const count = this.processes.size;
|
|
86
|
+
for (const proc of this.processes) {
|
|
87
|
+
proc.kill('SIGKILL');
|
|
88
|
+
}
|
|
89
|
+
this.processes.clear();
|
|
90
|
+
return count;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
exports.ClaudeService = ClaudeService;
|
|
94
|
+
exports.ClaudeService = ClaudeService = ClaudeService_1 = __decorate([
|
|
95
|
+
(0, common_1.Injectable)()
|
|
96
|
+
], ClaudeService);
|
|
97
|
+
//# sourceMappingURL=claude.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude.service.js","sourceRoot":"","sources":["../../../src/slack/services/claude.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2DAA8D;AAC9D,iDAAgD;AAEhD,2CAA2E;AAgDpE,IAAM,aAAa,qBAAnB,MAAM,aAAa;IACP,MAAM,GAAG,IAAI,eAAM,CAAC,eAAa,CAAC,IAAI,CAAC,CAAC;IAExC,SAAS,GAAG,IAAI,GAAG,EAAgB,CAAC;IAErD,qBAAqB;QACnB,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,CAAC,GAAG,CAAC,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BACF,MAAM,KAAK,CAAC;gBACd,CAAC;gBAAC,MAAM,CAAC;oBACP,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,WAAW,IAAI,CAAC,GAAG,mBAAmB,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAC3D,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBAClC,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;oBAC3B,OAAO,EAAE,CAAC;gBACZ,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;gBACnC,CAAC;YACH,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;QAElC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YAClC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvB,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QAEvB,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AA1GY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;GACA,aAAa,CA0GzB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AllMiddlewareArgs, SlackCommandMiddlewareArgs } from '@slack/bolt';
|
|
2
|
+
import { TemplateService } from '../../../core/services/template.service';
|
|
3
|
+
import { WorkspaceService } from '../workspace.service';
|
|
4
|
+
import { SlackCommand } from './registry.service';
|
|
5
|
+
export declare class CommandCdService implements SlackCommand {
|
|
6
|
+
private readonly workspace;
|
|
7
|
+
private readonly template;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
readonly command = "/cd";
|
|
10
|
+
constructor(workspace: WorkspaceService, template: TemplateService);
|
|
11
|
+
handle({ ack, command, }: SlackCommandMiddlewareArgs & AllMiddlewareArgs): Promise<void>;
|
|
12
|
+
}
|