Skip to content

Commit be80d2c

Browse files
authored
Merge pull request #17 from f1shy-dev/implement-server
server: Implement distracted server for Claude Code integration
2 parents 31a3f3c + 4e6208d commit be80d2c

20 files changed

Lines changed: 956 additions & 8 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: release server
2+
3+
on:
4+
push:
5+
tags:
6+
- '@distracted/server@*'
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: 'Version to release (e.g., @distracted/server@1.0.0)'
11+
required: true
12+
type: string
13+
14+
jobs:
15+
release:
16+
runs-on: ubuntu-latest
17+
environment: Deploy
18+
permissions:
19+
contents: write
20+
id-token: write
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Bun
27+
uses: oven-sh/setup-bun@v2
28+
with:
29+
bun-version: latest
30+
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: '20'
35+
registry-url: 'https://registry.npmjs.org'
36+
37+
- name: Install dependencies
38+
run: bun install --frozen-lockfile
39+
40+
- name: Determine version
41+
id: version
42+
run: |
43+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
44+
VERSION="${{ github.event.inputs.version }}"
45+
elif [[ "${{ github.ref }}" == refs/tags/@distracted/server@* ]]; then
46+
# Extract version from tag format: @distracted/server@X.X.X
47+
VERSION="${GITHUB_REF#refs/tags/@distracted/server@}"
48+
else
49+
echo "Unable to determine version"
50+
exit 1
51+
fi
52+
53+
# Validate version format
54+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
55+
echo "Invalid version format: $VERSION (expected semver, e.g., 1.0.0)"
56+
exit 1
57+
fi
58+
59+
echo "version=$VERSION" >> $GITHUB_OUTPUT
60+
61+
- name: Update package version
62+
if: github.event_name == 'workflow_dispatch'
63+
working-directory: packages/server
64+
run: |
65+
npm version ${{ steps.version.outputs.version }} --no-git-tag-version
66+
67+
- name: Build server package
68+
working-directory: packages/server
69+
run: bun run build
70+
71+
- name: Verify build output
72+
working-directory: packages/server
73+
run: |
74+
if [ ! -f "dist/bin.js" ]; then
75+
echo "Build failed: dist/bin.js not found"
76+
exit 1
77+
fi
78+
79+
- name: Publish to NPM
80+
working-directory: packages/server
81+
env:
82+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
83+
run: |
84+
npm publish --access public
85+
86+
- name: Commit version change
87+
if: github.event_name == 'workflow_dispatch'
88+
run: |
89+
git config user.name "github-actions[bot]"
90+
git config user.email "github-actions[bot]@users.noreply.github.com"
91+
git add packages/server/package.json
92+
git commit -m "chore(server): bump version to ${{ steps.version.outputs.version }}" || exit 0
93+
git push origin HEAD || true

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
name: release
1+
name: release extension
22

33
on:
44
push:
55
tags:
6-
- "v*"
6+
- '@distracted/extension@*'
77
workflow_dispatch:
88
inputs:
99
tag:
10-
description: "Tag to build and attach to release (e.g., v0.0.0-beta.1)"
10+
description: "Tag to build and attach to release (e.g., @distracted/extension@1.0.0)"
1111
required: true
1212
type: string
1313

.github/workflows/validate.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ jobs:
3737
run: |
3838
bun run --cwd packages/extension build
3939
bun run --cwd packages/extension build:firefox
40+
41+
- name: build server
42+
run: bun run --cwd packages/server build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ web-ext.config.ts
3131
.env.*
3232
!.env.example
3333
.tmp
34+
dist/

bun.lock

Lines changed: 45 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"@typescript/native-preview": "^7.0.0-dev",
1414
"oxfmt": "^0.21.0",
1515
"oxlint": "^1.36.0",
16-
"oxlint-tsgolint": "^0.10.1"
16+
"oxlint-tsgolint": "^0.10.1",
17+
"knip": "^5.79.0"
1718
}
1819
},
1920
"scripts": {
@@ -26,6 +27,8 @@
2627
"clean": "rm -rf node_modules && rm -rf packages/*/node_modules && bun run --workspaces --if-present clean"
2728
},
2829
"devDependencies": {
30+
"@types/node": "^24.10.1",
31+
"bun-types": "^1.2.0",
2932
"oxfmt": "catalog:",
3033
"oxlint": "catalog:",
3134
"oxlint-tsgolint": "catalog:",

packages/extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"@types/react-dom": "^19.2.3",
6161
"@typescript/native-preview": "catalog:",
6262
"@wxt-dev/module-react": "^1.1.5",
63-
"knip": "^5.79.0",
63+
"knip": "catalog:",
6464
"oxfmt": "catalog:",
6565
"oxlint": "catalog:",
6666
"oxlint-tsgolint": "catalog:",

packages/extension/src/lib/challenges/definitions/claude.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const claudeDefinition = {
1212
"Keep the server running while you work in Claude Code.",
1313
"If you change the server port, update the Server URL below.",
1414
],
15-
commands: ["npx claude-blocker --setup"],
15+
commands: ["bunx @distracted/server --setup"],
1616
note: "If the server is offline or Claude is idle, the site stays locked.",
1717
},
1818
options: {

packages/server/.oxlintrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"browser": false,
5+
"es2022": true
6+
}
7+
}

packages/server/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
![distracted! - "block distracting websites! do mini tasks to get back on them..."](../extension/public/readme-banner.png)
2+
3+
[![Chrome Web Store](https://img.shields.io/chrome-web-store/v/ggimjhcfchbfdhpehdekdiblbfmijngf?label=chrome%20web%20store&style=for-the-badge)](https://chromewebstore.google.com/detail/distracted/ggimjhcfchbfdhpehdekdiblbfmijngf)
4+
[![Firefox Add-ons](https://img.shields.io/amo/v/distracted?label=firefox%20add-ons&style=for-the-badge)](https://addons.mozilla.org/en-GB/firefox/addon/distracted/)
5+
[![GitHub stars](https://img.shields.io/github/stars/f1shy-dev/distracted?style=for-the-badge&color=yellow)](https://github.com/f1shy-dev/distracted)
6+
7+
## what is this package?
8+
9+
local server that integrates with claude code hooks to enable real-time distraction blocking. receives hook events from claude code and forwards them to the extension via websocket.
10+
11+
## how to use
12+
13+
### setup
14+
15+
install the extension first! then run the server:
16+
17+
```bash
18+
bunx @distracted/server
19+
```
20+
21+
when ran for the first time, the CLI will add hooks to `~/.claude/settings.json` to forward events to the local server.
22+
23+
then the server will start on port 8765 by default (or use `--port <port>` to specify a different port).
24+
25+
in the extension, setup a distraction with Claude Blocker as the unlock method.
26+
27+
to remove the claude code hooks:
28+
29+
```bash
30+
bunx @distracted/server --remove
31+
```
32+
33+
## how it works
34+
35+
- claude code sends hook events (UserPromptSubmit, PreToolUse, SessionStart/End, etc.) to the local server via http post
36+
- the server processes these events and maintains state about claude code activity
37+
- the extension connects via websocket and receives real-time updates
38+
- when claude code is inactive, the extension can activate distraction blocking
39+
40+
## credits
41+
42+
- @t3dotgg/[@theo](https://x.com/theo) for the original [claude-blocker](https://github.com/t3dotgg/claude-blocker)
43+
- [opencode](https://github.com/anomalyco/opencode) for some small bits of CLI code ([`lib/ui.ts`](src/lib/ui.ts), [`lib/error.ts`](src/lib/error.ts))

0 commit comments

Comments
 (0)