Skip to content

Commit 615046f

Browse files
committed
Update extension name to sagemaker-idle-extension and Add CONTRIBUTING.md
1 parent d537581 commit 615046f

File tree

15 files changed

+112
-54
lines changed

15 files changed

+112
-54
lines changed

patched-vscode/build/gulpfile.extensions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const compilations = [
6161
'extensions/search-result/tsconfig.json',
6262
'extensions/simple-browser/tsconfig.json',
6363
'extensions/sagemaker-extension/tsconfig.json',
64-
'extensions/code-editor-idle-extension/tsconfig.json',
64+
'extensions/sagemaker-idle-extension/tsconfig.json',
6565
'extensions/tunnel-forwarding/tsconfig.json',
6666
'extensions/typescript-language-features/test-workspace/tsconfig.json',
6767
'extensions/typescript-language-features/web/tsconfig.json',

patched-vscode/build/npm/dirs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const dirs = [
4040
'extensions/php-language-features',
4141
'extensions/references-view',
4242
'extensions/sagemaker-extension',
43-
'extensions/code-editor-idle-extension',
43+
'extensions/sagemaker-idle-extension',
4444
'extensions/search-result',
4545
'extensions/simple-browser',
4646
'extensions/tunnel-forwarding',

patched-vscode/extensions/code-editor-idle-extension/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Contributing to the Sagemaker Idle Extension
2+
This guide explains how to make changes to this extension and test them.
3+
## How to Make Changes
4+
Changes to the sagemaker-idle-extension are managed by creating patches using the Quilt tool. Follow these steps:
5+
1. Create a new patch:
6+
```
7+
quilt new sagemaker-idle-extension-v<n>.patch # Replace <n> with the next version number
8+
```
9+
2. Make changes and add file
10+
```
11+
quilt add sagemaker-idle-extension-v<n>.patch
12+
```
13+
3. Refresh the patch to include your changes:
14+
```
15+
quilt refresh
16+
```
17+
4. Update the changes in the patched-vsode folder
18+
5. Commit your changes and submit a pull request from your personal fork.
19+
20+
## How to Test
21+
1. Launch the Extension with Code Editor in local environment:
22+
1. Install Prerequisite tools described [here](https://web.archive.org/web/20231012223533/https://github.com/microsoft/vscode/wiki/How-to-Contribute#prerequisites) for your operating system.
23+
2. Run sh ./scripts/install.sh
24+
3. Run yarn watch from within the vscode folder
25+
4. Open a new terminal and run ./vscode/scripts/code-server.sh --launch
26+
27+
2. Perform user activity such as file changes, cursor editor movements, and terminal activity
28+
3. Verify `lastActiveTimestamp` is updated in the `.sagemaker-last-active-timestamp` file.
29+
4. Verify that the `/api/idle` endpoint returns the same `lastActiveTimestamp.
30+
31+
### Test Cases
32+
1. File change Detectcion
33+
- Modify a file and ensure the timestamp updates.
34+
- Delete a file and verify the timestamp updates.
35+
2. Text Editor Movement
36+
- Move the text cursor within a file and check for timestamp updates.
37+
- Switch between files and verify updates.
38+
3. Terminal Activity
39+
- Open a new terminal, run a command, and ensure the timestamp updates.
40+
- Close the terminal and verify updates.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Code Editor Idle Extension
2+
3+
The Code Editor Idle Extension tracks user activity and logs the last active timestamp (in UTC) to a local file. User activities monitored include file changes, text editor selection changes, and terminal interactions. Additionally, it provides an API endpoint `/api/idle` that returns the lastActiveTimestamp.

patched-vscode/extensions/code-editor-idle-extension/package.json renamed to patched-vscode/extensions/sagemaker-idle-extension/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "code-editor-idle-extension",
3-
"displayName": "Code Editor Idle Extension",
2+
"name": "sagemaker-idle-extension",
3+
"displayName": "Sagemaker Idle Extension",
44
"description": "Expose an API called /idle that returns latest activity timestamp",
55
"extensionKind": [
66
"workspace"
@@ -27,16 +27,16 @@
2727
"contributes": {
2828
"configuration": {
2929
"type": "object",
30-
"title": "Code Editor Idle Extension",
30+
"title": "Sagemaker Idle Extension",
3131
"properties": {}
3232
},
3333
"commands": []
3434
},
3535
"scripts": {
36-
"compile": "gulp compile-extension:code-editor-idle-extension",
37-
"watch": "npm run build-preview && gulp watch-extension:code-editor-idle-extension",
36+
"compile": "gulp compile-extension:sagemaker-idle-extension",
37+
"watch": "npm run build-preview && gulp watch-extension:sagemaker-idle-extension",
3838
"vscode:prepublish": "npm run build-ext",
39-
"build-ext": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:code-editor-idle-extension ./tsconfig.json"
39+
"build-ext": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:sagemaker-idle-extension ./tsconfig.json"
4040
},
4141
"dependencies": {},
4242
"repository": {}

patched-vscode/extensions/code-editor-idle-extension/src/extension.ts renamed to patched-vscode/extensions/sagemaker-idle-extension/src/extension.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "path";
44

55
let idleFilePath: string
66
let terminalActivityInterval: NodeJS.Timeout | undefined
7+
const LOG_PREFIX = "[sagemaker-idle-extension]"
78
const CHECK_INTERVAL = 60000; // 60 seconds interval
89

910
export function activate(context: vscode.ExtensionContext) {
@@ -25,10 +26,10 @@ export function deactivate() {
2526
function initializeIdleFilePath() {
2627
const homeDirectory = process.env.HOME || process.env.USERPROFILE;
2728
if (!homeDirectory) {
28-
console.log("Unable to determine the home directory.");
29+
console.log(`${LOG_PREFIX} Unable to determine the home directory.`);
2930
return;
3031
}
31-
idleFilePath = path.join(homeDirectory, ".code-editor-last-active-timestamp");
32+
idleFilePath = path.join(homeDirectory, ".sagemaker-last-active-timestamp");
3233
}
3334

3435
/**
@@ -66,12 +67,20 @@ const startMonitoringTerminalActivity = () => {
6667

6768
/**
6869
* Checks for terminal activity by reading the /dev/pts directory and comparing modification times of the files.
69-
* If activity is detected, it updates the last activity timestamp.
70+
*
71+
* The /dev/pts directory is used in Unix-like operating systems to represent pseudo-terminal (PTY) devices.
72+
* Each active terminal session is assigned a PTY device. These devices are represented as files within the /dev/pts directory.
73+
* When a terminal session has activity, such as when a user inputs commands or output is written to the terminal,
74+
* the modification time (mtime) of the corresponding PTY device file is updated. By monitoring the modification
75+
* times of the files in the /dev/pts directory, we can detect terminal activity.
76+
*
77+
* If activity is detected (i.e., if any PTY device file was modified within the CHECK_INTERVAL), this function
78+
* updates the last activity timestamp.
7079
*/
7180
const checkTerminalActivity = () => {
7281
fs.readdir("/dev/pts", (err, files) => {
7382
if (err) {
74-
console.error("Error reading /dev/pts directory:", err);
83+
console.error(`${LOG_PREFIX} Error reading /dev/pts directory:`, err);
7584
return;
7685
}
7786

@@ -83,7 +92,7 @@ const checkTerminalActivity = () => {
8392
const mtime = new Date(stats.mtime).getTime();
8493
return now - mtime < CHECK_INTERVAL;
8594
} catch (error) {
86-
console.error("Error reading file stats:", error);
95+
console.error(`${LOG_PREFIX}}Error reading file stats:`, error);
8796
return false;
8897
}
8998
});
@@ -95,7 +104,7 @@ const checkTerminalActivity = () => {
95104
};
96105

97106
/**
98-
* Updates the last activity timestamp by writing the current timestamp to the idle file and updating the status bar.
107+
* Updates the last activity timestamp by writing the current timestamp to the idle file.
99108
*/
100109
function updateLastActivityTimestamp() {
101110
const timestamp = new Date().toISOString();

0 commit comments

Comments
 (0)