agent-sin 0.1.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.
Files changed (150) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +21 -0
  3. package/README.md +81 -0
  4. package/assets/logo.png +0 -0
  5. package/builtin-skills/_shared/_models_lib.py +227 -0
  6. package/builtin-skills/_shared/_profile_lib.py +98 -0
  7. package/builtin-skills/_shared/_schedules_lib.py +313 -0
  8. package/builtin-skills/_shared/_skill_settings_lib.py +153 -0
  9. package/builtin-skills/_shared/i18n.py +26 -0
  10. package/builtin-skills/memo-delete/main.py +155 -0
  11. package/builtin-skills/memo-delete/skill.yaml +57 -0
  12. package/builtin-skills/memo-index/main.py +178 -0
  13. package/builtin-skills/memo-index/skill.yaml +53 -0
  14. package/builtin-skills/memo-save/README.md +5 -0
  15. package/builtin-skills/memo-save/main.py +74 -0
  16. package/builtin-skills/memo-save/skill.yaml +52 -0
  17. package/builtin-skills/memo-search/README.md +10 -0
  18. package/builtin-skills/memo-search/main.py +97 -0
  19. package/builtin-skills/memo-search/skill.yaml +51 -0
  20. package/builtin-skills/memo-vector-search/main.py +121 -0
  21. package/builtin-skills/memo-vector-search/skill.yaml +53 -0
  22. package/builtin-skills/model-add/main.py +180 -0
  23. package/builtin-skills/model-add/skill.yaml +112 -0
  24. package/builtin-skills/model-list/main.py +93 -0
  25. package/builtin-skills/model-list/skill.yaml +48 -0
  26. package/builtin-skills/model-set/main.py +123 -0
  27. package/builtin-skills/model-set/skill.yaml +69 -0
  28. package/builtin-skills/profile-delete/_profile_lib.py +98 -0
  29. package/builtin-skills/profile-delete/main.py +98 -0
  30. package/builtin-skills/profile-delete/skill.yaml +64 -0
  31. package/builtin-skills/profile-edit/_profile_lib.py +98 -0
  32. package/builtin-skills/profile-edit/main.py +97 -0
  33. package/builtin-skills/profile-edit/skill.yaml +72 -0
  34. package/builtin-skills/profile-save/main.py +52 -0
  35. package/builtin-skills/profile-save/skill.yaml +69 -0
  36. package/builtin-skills/schedule-add/_schedules_lib.py +303 -0
  37. package/builtin-skills/schedule-add/main.py +137 -0
  38. package/builtin-skills/schedule-add/skill.yaml +94 -0
  39. package/builtin-skills/schedule-list/_schedules_lib.py +303 -0
  40. package/builtin-skills/schedule-list/main.py +86 -0
  41. package/builtin-skills/schedule-list/skill.yaml +45 -0
  42. package/builtin-skills/schedule-remove/_schedules_lib.py +303 -0
  43. package/builtin-skills/schedule-remove/main.py +69 -0
  44. package/builtin-skills/schedule-remove/skill.yaml +49 -0
  45. package/builtin-skills/schedule-toggle/_schedules_lib.py +303 -0
  46. package/builtin-skills/schedule-toggle/main.py +78 -0
  47. package/builtin-skills/schedule-toggle/skill.yaml +61 -0
  48. package/builtin-skills/skills-disable/main.py +63 -0
  49. package/builtin-skills/skills-disable/skill.yaml +52 -0
  50. package/builtin-skills/skills-enable/main.py +62 -0
  51. package/builtin-skills/skills-enable/skill.yaml +51 -0
  52. package/builtin-skills/todo-add/main.py +68 -0
  53. package/builtin-skills/todo-add/skill.yaml +53 -0
  54. package/builtin-skills/todo-delete/main.py +65 -0
  55. package/builtin-skills/todo-delete/skill.yaml +47 -0
  56. package/builtin-skills/todo-done/main.py +75 -0
  57. package/builtin-skills/todo-done/skill.yaml +47 -0
  58. package/builtin-skills/todo-list/main.py +91 -0
  59. package/builtin-skills/todo-list/skill.yaml +48 -0
  60. package/builtin-skills/todo-tick/main.py +125 -0
  61. package/builtin-skills/todo-tick/skill.yaml +48 -0
  62. package/dist/builder/build-action-classifier.d.ts +18 -0
  63. package/dist/builder/build-action-classifier.js +142 -0
  64. package/dist/builder/build-commands.d.ts +19 -0
  65. package/dist/builder/build-commands.js +133 -0
  66. package/dist/builder/build-flow.d.ts +72 -0
  67. package/dist/builder/build-flow.js +416 -0
  68. package/dist/builder/builder-session.d.ts +117 -0
  69. package/dist/builder/builder-session.js +1129 -0
  70. package/dist/builder/conversation-router.d.ts +22 -0
  71. package/dist/builder/conversation-router.js +69 -0
  72. package/dist/builder/intent-runtime-store.d.ts +7 -0
  73. package/dist/builder/intent-runtime-store.js +60 -0
  74. package/dist/builder/progress-format.d.ts +7 -0
  75. package/dist/builder/progress-format.js +46 -0
  76. package/dist/cli/index.d.ts +2 -0
  77. package/dist/cli/index.js +2835 -0
  78. package/dist/cli/spinner.d.ts +30 -0
  79. package/dist/cli/spinner.js +164 -0
  80. package/dist/core/ai-provider.d.ts +75 -0
  81. package/dist/core/ai-provider.js +678 -0
  82. package/dist/core/builtin-skills.d.ts +27 -0
  83. package/dist/core/builtin-skills.js +120 -0
  84. package/dist/core/chat-engine.d.ts +70 -0
  85. package/dist/core/chat-engine.js +812 -0
  86. package/dist/core/config.d.ts +127 -0
  87. package/dist/core/config.js +1379 -0
  88. package/dist/core/daily-memory-promotion.d.ts +21 -0
  89. package/dist/core/daily-memory-promotion.js +422 -0
  90. package/dist/core/i18n.d.ts +23 -0
  91. package/dist/core/i18n.js +167 -0
  92. package/dist/core/info-lines.d.ts +5 -0
  93. package/dist/core/info-lines.js +39 -0
  94. package/dist/core/input-schema.d.ts +2 -0
  95. package/dist/core/input-schema.js +156 -0
  96. package/dist/core/intent-router.d.ts +27 -0
  97. package/dist/core/intent-router.js +160 -0
  98. package/dist/core/logger.d.ts +60 -0
  99. package/dist/core/logger.js +240 -0
  100. package/dist/core/memory.d.ts +10 -0
  101. package/dist/core/memory.js +72 -0
  102. package/dist/core/message-utils.d.ts +13 -0
  103. package/dist/core/message-utils.js +104 -0
  104. package/dist/core/notifier.d.ts +17 -0
  105. package/dist/core/notifier.js +424 -0
  106. package/dist/core/output-writer.d.ts +13 -0
  107. package/dist/core/output-writer.js +100 -0
  108. package/dist/core/plan-decision.d.ts +16 -0
  109. package/dist/core/plan-decision.js +88 -0
  110. package/dist/core/profile-memory.d.ts +17 -0
  111. package/dist/core/profile-memory.js +142 -0
  112. package/dist/core/runtime.d.ts +50 -0
  113. package/dist/core/runtime.js +187 -0
  114. package/dist/core/scheduler.d.ts +28 -0
  115. package/dist/core/scheduler.js +155 -0
  116. package/dist/core/secrets.d.ts +31 -0
  117. package/dist/core/secrets.js +214 -0
  118. package/dist/core/service.d.ts +35 -0
  119. package/dist/core/service.js +479 -0
  120. package/dist/core/skill-planner.d.ts +24 -0
  121. package/dist/core/skill-planner.js +100 -0
  122. package/dist/core/skill-registry.d.ts +98 -0
  123. package/dist/core/skill-registry.js +319 -0
  124. package/dist/core/skill-scaffold.d.ts +33 -0
  125. package/dist/core/skill-scaffold.js +256 -0
  126. package/dist/core/skill-settings.d.ts +11 -0
  127. package/dist/core/skill-settings.js +63 -0
  128. package/dist/core/transfer.d.ts +31 -0
  129. package/dist/core/transfer.js +270 -0
  130. package/dist/core/update-notifier.d.ts +2 -0
  131. package/dist/core/update-notifier.js +140 -0
  132. package/dist/discord/bot.d.ts +96 -0
  133. package/dist/discord/bot.js +2424 -0
  134. package/dist/runtimes/codex-app-server.d.ts +53 -0
  135. package/dist/runtimes/codex-app-server.js +305 -0
  136. package/dist/runtimes/python-runner.d.ts +7 -0
  137. package/dist/runtimes/python-runner.js +302 -0
  138. package/dist/runtimes/typescript-runner.d.ts +5 -0
  139. package/dist/runtimes/typescript-runner.js +172 -0
  140. package/dist/skills-sdk/types.d.ts +38 -0
  141. package/dist/skills-sdk/types.js +1 -0
  142. package/dist/telegram/bot.d.ts +94 -0
  143. package/dist/telegram/bot.js +1219 -0
  144. package/install.ps1 +132 -0
  145. package/install.sh +130 -0
  146. package/package.json +60 -0
  147. package/templates/skill-python/main.py +74 -0
  148. package/templates/skill-python/skill.yaml +48 -0
  149. package/templates/skill-typescript/main.ts +87 -0
  150. package/templates/skill-typescript/skill.yaml +42 -0
@@ -0,0 +1,140 @@
1
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import https from "node:https";
5
+ import { defaultWorkspace } from "./config.js";
6
+ import { l } from "./i18n.js";
7
+ const PACKAGE_NAME = "agent-sin";
8
+ const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
9
+ const FETCH_TIMEOUT_MS = 5000;
10
+ function packageJsonPath() {
11
+ const here = path.dirname(fileURLToPath(import.meta.url));
12
+ return path.resolve(here, "..", "..", "package.json");
13
+ }
14
+ let cachedCurrentVersion = null;
15
+ async function readCurrentVersion() {
16
+ if (cachedCurrentVersion)
17
+ return cachedCurrentVersion;
18
+ try {
19
+ const raw = await readFile(packageJsonPath(), "utf8");
20
+ const pkg = JSON.parse(raw);
21
+ cachedCurrentVersion = pkg.version || "0.0.0";
22
+ }
23
+ catch {
24
+ cachedCurrentVersion = "0.0.0";
25
+ }
26
+ return cachedCurrentVersion;
27
+ }
28
+ function cachePath(workspace) {
29
+ return path.join(workspace, "update-check.json");
30
+ }
31
+ async function loadCache(workspace) {
32
+ try {
33
+ const raw = await readFile(cachePath(workspace), "utf8");
34
+ const parsed = JSON.parse(raw);
35
+ return {
36
+ lastCheckedAt: parsed.lastCheckedAt ?? null,
37
+ latestVersion: parsed.latestVersion ?? null,
38
+ bannerShownDate: parsed.bannerShownDate ?? null,
39
+ };
40
+ }
41
+ catch {
42
+ return { lastCheckedAt: null, latestVersion: null, bannerShownDate: null };
43
+ }
44
+ }
45
+ async function saveCache(workspace, cache) {
46
+ try {
47
+ await mkdir(workspace, { recursive: true });
48
+ await writeFile(cachePath(workspace), JSON.stringify(cache, null, 2), "utf8");
49
+ }
50
+ catch {
51
+ // ignore - non-critical
52
+ }
53
+ }
54
+ function fetchLatestVersion() {
55
+ return new Promise((resolve) => {
56
+ const req = https.get(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, { timeout: FETCH_TIMEOUT_MS, headers: { accept: "application/json" } }, (res) => {
57
+ if (res.statusCode !== 200) {
58
+ res.resume();
59
+ resolve(null);
60
+ return;
61
+ }
62
+ let body = "";
63
+ res.setEncoding("utf8");
64
+ res.on("data", (chunk) => {
65
+ body += chunk;
66
+ });
67
+ res.on("end", () => {
68
+ try {
69
+ const parsed = JSON.parse(body);
70
+ resolve(parsed.version ?? null);
71
+ }
72
+ catch {
73
+ resolve(null);
74
+ }
75
+ });
76
+ });
77
+ req.on("timeout", () => {
78
+ req.destroy();
79
+ resolve(null);
80
+ });
81
+ req.on("error", () => resolve(null));
82
+ });
83
+ }
84
+ function compareSemver(a, b) {
85
+ const pa = a.split(/[.+-]/)[0].split(".").map((s) => parseInt(s, 10) || 0);
86
+ const pb = b.split(/[.+-]/)[0].split(".").map((s) => parseInt(s, 10) || 0);
87
+ const len = Math.max(pa.length, pb.length);
88
+ for (let i = 0; i < len; i += 1) {
89
+ const av = pa[i] ?? 0;
90
+ const bv = pb[i] ?? 0;
91
+ if (av !== bv)
92
+ return av - bv;
93
+ }
94
+ return 0;
95
+ }
96
+ function todayKey() {
97
+ const d = new Date();
98
+ const y = d.getFullYear();
99
+ const m = String(d.getMonth() + 1).padStart(2, "0");
100
+ const day = String(d.getDate()).padStart(2, "0");
101
+ return `${y}-${m}-${day}`;
102
+ }
103
+ function isDisabled() {
104
+ const flag = (process.env.AGENT_SIN_DISABLE_UPDATE_CHECK || "").trim().toLowerCase();
105
+ return flag === "1" || flag === "true" || flag === "yes";
106
+ }
107
+ export function scheduleUpdateCheck(workspace = defaultWorkspace()) {
108
+ if (isDisabled())
109
+ return;
110
+ void (async () => {
111
+ const cache = await loadCache(workspace);
112
+ const now = Date.now();
113
+ const lastChecked = cache.lastCheckedAt ? Date.parse(cache.lastCheckedAt) : 0;
114
+ if (Number.isFinite(lastChecked) && now - lastChecked < CHECK_INTERVAL_MS)
115
+ return;
116
+ const latest = await fetchLatestVersion();
117
+ if (!latest)
118
+ return;
119
+ await saveCache(workspace, {
120
+ ...cache,
121
+ lastCheckedAt: new Date().toISOString(),
122
+ latestVersion: latest,
123
+ });
124
+ })();
125
+ }
126
+ export async function consumeUpdateBanner(workspace = defaultWorkspace()) {
127
+ if (isDisabled())
128
+ return null;
129
+ const cache = await loadCache(workspace);
130
+ if (!cache.latestVersion)
131
+ return null;
132
+ const current = await readCurrentVersion();
133
+ if (compareSemver(cache.latestVersion, current) <= 0)
134
+ return null;
135
+ const today = todayKey();
136
+ if (cache.bannerShownDate === today)
137
+ return null;
138
+ await saveCache(workspace, { ...cache, bannerShownDate: today });
139
+ return l(`A new version v${cache.latestVersion} is available (current v${current}). Update: npm i -g ${PACKAGE_NAME}@latest`, `新しいバージョン v${cache.latestVersion} があります(現在 v${current})。更新: npm i -g ${PACKAGE_NAME}@latest`);
140
+ }
@@ -0,0 +1,96 @@
1
+ import { type AppConfig } from "../core/config.js";
2
+ import { type ChatTurn } from "../core/chat-engine.js";
3
+ import type { AiProgressEvent } from "../core/ai-provider.js";
4
+ import { type IntentRuntime } from "../builder/build-flow.js";
5
+ import { type SkillManifest } from "../core/skill-registry.js";
6
+ declare const STATUS_EMOJI: {
7
+ readonly received: "👀";
8
+ readonly thinking: "🤔";
9
+ readonly tool: "🛠️";
10
+ readonly done: "✅";
11
+ readonly error: "⚠️";
12
+ };
13
+ export type StatusKind = keyof typeof STATUS_EMOJI;
14
+ export interface DiscordUser {
15
+ id: string;
16
+ username: string;
17
+ bot?: boolean;
18
+ }
19
+ export interface DiscordMessage {
20
+ id: string;
21
+ channel_id: string;
22
+ guild_id?: string;
23
+ author: DiscordUser;
24
+ content: string;
25
+ mentions: DiscordUser[];
26
+ attachments?: DiscordAttachment[];
27
+ }
28
+ export interface DiscordAttachment {
29
+ id?: string;
30
+ filename?: string;
31
+ title?: string;
32
+ description?: string;
33
+ content_type?: string;
34
+ size?: number;
35
+ url?: string;
36
+ proxy_url?: string;
37
+ }
38
+ export interface MessageContext {
39
+ isDirect: boolean;
40
+ isMentioned: boolean;
41
+ isAllowed: boolean;
42
+ isListenChannel: boolean;
43
+ isBotThread: boolean;
44
+ }
45
+ export declare function shouldRespond(ctx: MessageContext): boolean;
46
+ export declare function renderModeBadge(_intentRuntime: IntentRuntime): string;
47
+ export declare function withModeBadge(intentRuntime: IntentRuntime, lines: string[], options?: {
48
+ userText?: string;
49
+ isBuildEntry?: boolean;
50
+ }): string[];
51
+ export declare function runDiscordBot(config: AppConfig): Promise<number>;
52
+ export declare function parseSnowflakeList(raw: string): Set<string>;
53
+ /** @deprecated use parseSnowflakeList */
54
+ export declare const parseAllowedUserIds: typeof parseSnowflakeList;
55
+ export declare function classifyMessage(message: DiscordMessage, botUserId: string | null, allowedUserIds: Set<string>, listenChannelIds?: Set<string>, botThreadIds?: Set<string>): MessageContext;
56
+ export declare function stripBotMention(content: string, botUserId: string): string;
57
+ export declare function stripBadgePrefix(content: string): string;
58
+ export declare function buildChatHistoryFromMessages(messages: DiscordMessage[], botUserId: string | null, allowedUserIds: Set<string>): ChatTurn[];
59
+ export declare function formatDiscordUserMessageForHistory(message: DiscordMessage, botUserId: string | null): string;
60
+ export declare function formatDiscordAttachmentSummary(attachments: DiscordAttachment[] | undefined): string;
61
+ export declare function shouldResetDiscordHistory(ctx: MessageContext): boolean;
62
+ export declare function chunkMessage(text: string, max?: number): string[];
63
+ export declare function formatDiscordBuildProgress(event: AiProgressEvent, options?: {
64
+ detail?: boolean;
65
+ }): string | null;
66
+ export type TodoSlashParse = {
67
+ kind: "help";
68
+ lines: string[];
69
+ } | {
70
+ kind: "error";
71
+ lines: string[];
72
+ } | {
73
+ kind: "run";
74
+ skillId: "todo-add" | "todo-list" | "todo-done" | "todo-delete";
75
+ args: Record<string, unknown>;
76
+ };
77
+ export declare function parseTodoSlashCommand(text: string): TodoSlashParse | null;
78
+ export type ModelSlashParse = {
79
+ kind: "help";
80
+ lines: string[];
81
+ } | {
82
+ kind: "list";
83
+ } | {
84
+ kind: "set";
85
+ id: string;
86
+ };
87
+ export declare function parseModelSlashCommand(text: string): ModelSlashParse | null;
88
+ export declare function manifestToSlashDefinition(manifest: SkillManifest): ({
89
+ name: string;
90
+ } & Record<string, unknown>) | null;
91
+ export declare function composeSlashCommandDefinitions(config: AppConfig): Promise<ReadonlyArray<{
92
+ name: string;
93
+ } & Record<string, unknown>>>;
94
+ export declare function makeThreadName(text: string): string;
95
+ export declare function loadIntentRuntimes(filePath: string): Promise<Map<string, IntentRuntime>>;
96
+ export {};