@fureworks/scope 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 (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -0
  3. package/dist/cli/config.d.ts +2 -0
  4. package/dist/cli/config.d.ts.map +1 -0
  5. package/dist/cli/config.js +54 -0
  6. package/dist/cli/config.js.map +1 -0
  7. package/dist/cli/context.d.ts +6 -0
  8. package/dist/cli/context.d.ts.map +1 -0
  9. package/dist/cli/context.js +76 -0
  10. package/dist/cli/context.js.map +1 -0
  11. package/dist/cli/daemon.d.ts +2 -0
  12. package/dist/cli/daemon.d.ts.map +1 -0
  13. package/dist/cli/daemon.js +190 -0
  14. package/dist/cli/daemon.js.map +1 -0
  15. package/dist/cli/onboard.d.ts +2 -0
  16. package/dist/cli/onboard.d.ts.map +1 -0
  17. package/dist/cli/onboard.js +286 -0
  18. package/dist/cli/onboard.js.map +1 -0
  19. package/dist/cli/status.d.ts +6 -0
  20. package/dist/cli/status.d.ts.map +1 -0
  21. package/dist/cli/status.js +57 -0
  22. package/dist/cli/status.js.map +1 -0
  23. package/dist/cli/switch.d.ts +2 -0
  24. package/dist/cli/switch.d.ts.map +1 -0
  25. package/dist/cli/switch.js +78 -0
  26. package/dist/cli/switch.js.map +1 -0
  27. package/dist/cli/today.d.ts +7 -0
  28. package/dist/cli/today.d.ts.map +1 -0
  29. package/dist/cli/today.js +80 -0
  30. package/dist/cli/today.js.map +1 -0
  31. package/dist/engine/prioritize.d.ts +21 -0
  32. package/dist/engine/prioritize.d.ts.map +1 -0
  33. package/dist/engine/prioritize.js +204 -0
  34. package/dist/engine/prioritize.js.map +1 -0
  35. package/dist/index.d.ts +3 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +48 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/notifications/index.d.ts +2 -0
  40. package/dist/notifications/index.d.ts.map +1 -0
  41. package/dist/notifications/index.js +41 -0
  42. package/dist/notifications/index.js.map +1 -0
  43. package/dist/sources/calendar.d.ts +17 -0
  44. package/dist/sources/calendar.d.ts.map +1 -0
  45. package/dist/sources/calendar.js +120 -0
  46. package/dist/sources/calendar.js.map +1 -0
  47. package/dist/sources/git.d.ts +20 -0
  48. package/dist/sources/git.d.ts.map +1 -0
  49. package/dist/sources/git.js +124 -0
  50. package/dist/sources/git.js.map +1 -0
  51. package/dist/sources/issues.d.ts +14 -0
  52. package/dist/sources/issues.d.ts.map +1 -0
  53. package/dist/sources/issues.js +34 -0
  54. package/dist/sources/issues.js.map +1 -0
  55. package/dist/store/config.d.ts +22 -0
  56. package/dist/store/config.d.ts.map +1 -0
  57. package/dist/store/config.js +74 -0
  58. package/dist/store/config.js.map +1 -0
  59. package/package.json +45 -0
  60. package/src/cli/config.ts +66 -0
  61. package/src/cli/context.ts +109 -0
  62. package/src/cli/daemon.ts +217 -0
  63. package/src/cli/onboard.ts +335 -0
  64. package/src/cli/status.ts +77 -0
  65. package/src/cli/switch.ts +93 -0
  66. package/src/cli/today.ts +114 -0
  67. package/src/engine/prioritize.ts +257 -0
  68. package/src/index.ts +58 -0
  69. package/src/notifications/index.ts +42 -0
  70. package/src/sources/calendar.ts +170 -0
  71. package/src/sources/git.ts +168 -0
  72. package/src/sources/issues.ts +62 -0
  73. package/src/store/config.ts +104 -0
  74. package/tsconfig.json +19 -0
@@ -0,0 +1,62 @@
1
+ export interface IssueSignal {
2
+ number: number;
3
+ title: string;
4
+ url: string;
5
+ repo: string;
6
+ ageDays: number;
7
+ labels: string[];
8
+ }
9
+
10
+ export interface IssueScanResult {
11
+ available: boolean;
12
+ issues: IssueSignal[];
13
+ }
14
+
15
+ export async function scanAssignedIssues(): Promise<IssueScanResult> {
16
+ try {
17
+ const { execSync } = await import("node:child_process");
18
+
19
+ try {
20
+ execSync("which gh", { stdio: "pipe" });
21
+ } catch {
22
+ return { available: false, issues: [] };
23
+ }
24
+
25
+ const result = execSync(
26
+ "gh issue list --assignee @me --state open --json number,title,url,createdAt,labels,repository --limit 20",
27
+ {
28
+ encoding: "utf-8",
29
+ timeout: 10000,
30
+ stdio: ["pipe", "pipe", "pipe"],
31
+ }
32
+ );
33
+
34
+ const parsed = JSON.parse(result) as Array<{
35
+ number: number;
36
+ title: string;
37
+ url: string;
38
+ createdAt: string;
39
+ labels?: Array<{ name?: string }>;
40
+ repository?: { nameWithOwner?: string; name?: string };
41
+ }>;
42
+
43
+ const issues: IssueSignal[] = parsed.map((issue) => {
44
+ const ageDays =
45
+ (Date.now() - new Date(issue.createdAt).getTime()) /
46
+ (1000 * 60 * 60 * 24);
47
+
48
+ return {
49
+ number: issue.number,
50
+ title: issue.title,
51
+ url: issue.url,
52
+ repo: issue.repository?.nameWithOwner || issue.repository?.name || "unknown",
53
+ ageDays: Math.round(ageDays * 10) / 10,
54
+ labels: (issue.labels ?? []).map((label) => label.name || "").filter(Boolean),
55
+ };
56
+ });
57
+
58
+ return { available: true, issues };
59
+ } catch {
60
+ return { available: true, issues: [] };
61
+ }
62
+ }
@@ -0,0 +1,104 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { parse as parseToml } from "toml";
5
+
6
+ export interface ScopeConfig {
7
+ repos: string[];
8
+ projects: Record<
9
+ string,
10
+ {
11
+ path: string;
12
+ repos?: string[];
13
+ description?: string;
14
+ }
15
+ >;
16
+ calendar: {
17
+ enabled: boolean;
18
+ backend: "gws";
19
+ };
20
+ daemon: {
21
+ enabled: boolean;
22
+ intervalMinutes: number;
23
+ };
24
+ }
25
+
26
+ const SCOPE_DIR = join(homedir(), ".scope");
27
+ const CONFIG_PATH = join(SCOPE_DIR, "config.toml");
28
+
29
+ export function getScopeDir(): string {
30
+ return SCOPE_DIR;
31
+ }
32
+
33
+ export function ensureScopeDir(): void {
34
+ if (!existsSync(SCOPE_DIR)) {
35
+ mkdirSync(SCOPE_DIR, { recursive: true });
36
+ }
37
+ const contextsDir = join(SCOPE_DIR, "contexts");
38
+ if (!existsSync(contextsDir)) {
39
+ mkdirSync(contextsDir, { recursive: true });
40
+ }
41
+ }
42
+
43
+ export function configExists(): boolean {
44
+ return existsSync(CONFIG_PATH);
45
+ }
46
+
47
+ export function loadConfig(): ScopeConfig {
48
+ if (!configExists()) {
49
+ return {
50
+ repos: [],
51
+ projects: {},
52
+ calendar: { enabled: false, backend: "gws" },
53
+ daemon: { enabled: false, intervalMinutes: 15 },
54
+ };
55
+ }
56
+
57
+ const raw = readFileSync(CONFIG_PATH, "utf-8");
58
+ const parsed = parseToml(raw) as Partial<ScopeConfig>;
59
+
60
+ return {
61
+ repos: parsed.repos ?? [],
62
+ projects: parsed.projects ?? {},
63
+ calendar: {
64
+ enabled: parsed.calendar?.enabled ?? false,
65
+ backend: parsed.calendar?.backend ?? "gws",
66
+ },
67
+ daemon: {
68
+ enabled: parsed.daemon?.enabled ?? false,
69
+ intervalMinutes: parsed.daemon?.intervalMinutes ?? 15,
70
+ },
71
+ };
72
+ }
73
+
74
+ export function saveConfig(config: ScopeConfig): void {
75
+ ensureScopeDir();
76
+
77
+ const lines: string[] = [];
78
+ lines.push("# Scope configuration");
79
+ lines.push("");
80
+ lines.push(`repos = [${config.repos.map((r) => `"${r}"`).join(", ")}]`);
81
+ lines.push("");
82
+ lines.push("[calendar]");
83
+ lines.push(`enabled = ${config.calendar.enabled}`);
84
+ lines.push(`backend = "${config.calendar.backend}"`);
85
+ lines.push("");
86
+ lines.push("[daemon]");
87
+ lines.push(`enabled = ${config.daemon.enabled}`);
88
+ lines.push(`intervalMinutes = ${config.daemon.intervalMinutes}`);
89
+ lines.push("");
90
+
91
+ for (const [name, project] of Object.entries(config.projects)) {
92
+ lines.push(`[projects.${name}]`);
93
+ lines.push(`path = "${project.path}"`);
94
+ if (project.repos && project.repos.length > 0) {
95
+ lines.push(`repos = [${project.repos.map((r) => `"${r}"`).join(", ")}]`);
96
+ }
97
+ if (project.description) {
98
+ lines.push(`description = "${project.description}"`);
99
+ }
100
+ lines.push("");
101
+ }
102
+
103
+ writeFileSync(CONFIG_PATH, lines.join("\n"), "utf-8");
104
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "Node16",
5
+ "moduleResolution": "Node16",
6
+ "outDir": "dist",
7
+ "rootDir": "src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }